changeset 350:a3b06d53bcb9

Make il and x86 modules cope with dict hash instead of dict linear for the program definition
author Michael Pavone <pavone@retrodev.com>
date Fri, 10 Apr 2015 01:19:46 -0700
parents 60292f131de9
children 04ba2118c5fe
files modules/il.tp modules/x86.tp
diffstat 2 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/il.tp	Fri Apr 10 01:19:10 2015 -0700
+++ b/modules/il.tp	Fri Apr 10 01:19:46 2015 -0700
@@ -705,7 +705,7 @@
 			}
 			outprog <- #[]
 			foreach: prepped :name instarr {
-				outprog append: (labels get: name)
+				outprog append: (labels get: name else: { false })
 				foreach: instarr :_ inst {
 					print: "Translating: " . inst . "\n"
 					backend convertIL: inst to: outprog withLabels: labels
--- a/modules/x86.tp	Fri Apr 10 01:19:10 2015 -0700
+++ b/modules/x86.tp	Fri Apr 10 01:19:46 2015 -0700
@@ -764,9 +764,7 @@
 				{
 					//call
 					arguments <- inst args
-					cur <- (arguments length) - 1
-					while: { cur >= 0 } do: {
-						src <- (arguments get: cur)
+					arguments foldr: (arguments length) - 1 with: :cur src {
 						if: cur < (_argregs length) {
 							dst <- _argregs get: cur
 							if: (not: dst = src) {
@@ -778,12 +776,19 @@
 						} else: {
 							outarr append: (push: src)
 						}
-						cur <- cur - 1
+						cur - 1
 					}
+					
 					toCall <- inst target
 					if: (toCall isString?) {
 						//TODO: Handle call to undefined label
-						toCall <- labels get: toCall
+						toCall <- labels get: toCall else: { 
+							print: "Could not find label " . toCall . "\nDefined labels:\n"
+							foreach: labels :key _ {
+								print: "\t" . key . "\n"
+							}
+							false 
+						}
 					}
 					outarr append: (call: toCall)
 				}