changeset 360:0b83f15e819d

Update llcompile for changes to llFun syntax
author Michael Pavone <pavone@retrodev.com>
date Tue, 21 Apr 2015 09:00:56 -0700
parents 023c29e1f595
children 06dceff348ea
files modules/llcompile.tp modules/parser.tp
diffstat 2 files changed, 87 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/modules/llcompile.tp	Fri Apr 17 17:52:22 2015 -0700
+++ b/modules/llcompile.tp	Tue Apr 21 09:00:56 2015 -0700
@@ -314,7 +314,18 @@
 	}
 
 	_compileAssign <- :expr syms ilf assignTo {
-		dest <- _compileExpr: (expr to) syms: syms ilfun: ilf dest: (option none)
+		dest <- ((expr to) type) value: :typeexpr {
+			type <- _parseType: typeexpr
+			_notError: [type] {
+				syms define: ((expr to) name) #{
+					val <- ilf getReg
+					size <- type size
+					signed? <- type signed?
+				}
+			}
+		} none: {
+			_compileExpr: (expr to) syms: syms ilfun: ilf dest: (option none)
+		}
 		_notError: [dest] {
 			value <- _compileExpr: (expr assign) syms: syms ilfun: ilf dest: dest
 			_notError: [value] {
@@ -377,62 +388,64 @@
 			}
 		}
 
-		llFun:syms:vars:code <- :name :syms :vars :code{
+		llFun:syms:code:returns <- :name :syms :code :returnType{
 			_initHandlers:
 			syms <- symbols tableWithParent: syms
-			argnames <- dict hash
-			foreach: (code args) :idx arg {
-				if: (arg startsWith?: ":") {
-					arg <- arg from: 1
+			
+			rType <- _parseType: returnType
+			_notError: [rType] {
+				argErrors <- []
+				foreach: (code args) :argnum argsym {
+					(argsym type) value: :typeexpr {
+						type <- _parseType: typeexpr
+						_notError: [type] {
+							arg <- argsym name
+							if: (arg startsWith?: ":") {
+								arg <- arg from: 1
+							}
+							syms define: arg #{
+								val <- il arg: argnum
+								size <- type size
+								signed? <- type signed?
+							}
+						} else: :err {
+							argErrors <- err | argErrors
+						}
+					} none: {
+						argErrors <- (_compileError: "Arguments to llFun must have type declarations" 0) | argErrors
+					}
 				}
-				argnames set: arg idx
-			}
-			ilf <- _ilFun: name
-			_nextReg <- 0
-			varErrors <- (vars expressions) fold: [] with: :acc var {
-				type <- _parseType: (var assign)
-				_notError: [type] {
-					varname <- ((var to) name)
-					v <- argnames ifget: varname :argnum {
-						il arg: argnum
-					} else: {
-						ilf getReg
+				
+				
+				
+				
+				if: (argErrors empty?) {
+					ilf <- _ilFun: name
+					last <- option none
+					numexprs <- (code expressions) length
+					foreach: (code expressions) :idx expr {
+						asn <- if: idx = numexprs - 1 {
+							option value: #{
+								val <- ilf getReg
+								//TODO: FIxme
+								size <- il q
+								signed? <- true
+							}
+						} else: {
+							option none
+						}
+						last <- option value: (_compileExpr: expr syms: syms ilfun: ilf dest: asn)
 					}
-					syms define: varname #{
-						val <- v
-						size <- (type size)
-						signed? <- (type signed?)
+					last value: :v {
+						ilf add: (il return: (v val) (v size))
+					} none: {
+						ilf add: (il return: 0 (il l))
 					}
-					acc
-				} else: :err {
-					err | acc
+					ilf
+				} else: {
+					argErrors
 				}
 			}
-			if: (varErrors empty?) {
-				last <- option none
-				numexprs <- (code expressions) length
-				foreach: (code expressions) :idx expr {
-					asn <- if: idx = numexprs - 1 {
-						option value: #{
-							val <- ilf getReg
-							//TODO: FIxme
-							size <- il q
-							signed? <- true
-						}
-					} else: {
-						option none
-					}
-					last <- option value: (_compileExpr: expr syms: syms ilfun: ilf dest: asn)
-				}
-				last value: :v {
-					ilf add: (il return: (v val) (v size))
-				} none: {
-					ilf add: (il return: 0 (il l))
-				}
-				ilf
-			} else: {
-				varErrors
-			}
 		}
 
 		compileText <- :text {
@@ -443,34 +456,41 @@
 					errors <- []
 					syms <- symbols table
 					functions <- (tree messages) fold: [] with: :curfuncs msg {
-						if: (msg nodeType) = call {
-							if: ((msg tocall) name) = "llFun:withVars:andCode" {
-								if: ((msg args) length) = 3 {
-									fname <- ((msg args) value) name
-									syms define: fname #{
-										type <- "topfun"
+						if: (msg nodeType) = assignment {
+							def <- msg assign
+							if: (def nodeType) = call {
+								if: ((def tocall) name) = "llFun:returns" {
+									if: ((def args) length) = 2 {
+										fname <- (msg to) name
+										syms define: fname #{
+											type <- "topfun"
+										}
+										#{
+											name <- fname
+											body <- (def args) value
+											returnType <- ((def args) tail) value
+										} | curfuncs
+									} else: {
+										errors <- (
+											_compileError: "llFun:returns takes exactly 2 arguments" 0
+										) | errors
+										curfuncs
 									}
-									rest <- (msg args) tail
-									#{
-										name <- fname
-										vars <- rest value
-										body <- (rest tail) value
-									} | curfuncs
 								} else: {
 									errors <- (
-										_compileError: "llFun:withVars:andCode takes exactly 3 arguments" 0
+										_compileError: "Top level definitions must be a call to llFun:returns" 0
 									) | errors
 									curfuncs
 								}
 							} else: {
 								errors <- (
-									_compileError: "Only llFun:withVars:andCode expressions are allowed in top level object" 0
+									_compileError: "Right side of top-level assignment must be a call expression" 0
 								) | errors
 								curfuncs
 							}
 						} else: {
 							errors <- (
-								_compileError: "Only call expresions are allowed in top level object" 0
+								_compileError: "Only assignment expresions are allowed in top level object" 0
 							) | errors
 							curfuncs
 						}
@@ -478,7 +498,7 @@
 					if: (errors empty?) {
 						errors <- []
 						fmap <- functions fold: (dict hash) with: :acc func {
-							ilf <- llFun: (func name) syms: syms vars: (func vars) code: (func body)
+							ilf <- llFun: (func name) syms: syms code: (func body) returns: (func returnType)
 							_notError: ilf {
 								acc set: (func name) (ilf buffer)
 							} else: {
--- a/modules/parser.tp	Fri Apr 17 17:52:22 2015 -0700
+++ b/modules/parser.tp	Tue Apr 21 09:00:56 2015 -0700
@@ -941,7 +941,7 @@
 				if: (Rest length) = 0 {
 					Rest <- []
 				}
-				":" . First | Rest
+				First | Rest
 			}
 			match: "" yield: { [] }
 		]