# HG changeset patch # User Michael Pavone # Date 1429632056 25200 # Node ID 0b83f15e819d9b498e695c6908dd89a3bff618bb # Parent 023c29e1f5952b4336d288e29a995f9d06f89aaa Update llcompile for changes to llFun syntax diff -r 023c29e1f595 -r 0b83f15e819d modules/llcompile.tp --- 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,61 +388,63 @@ } } - 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 - } - 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 - } - syms define: varname #{ - val <- v - size <- (type size) - signed? <- (type signed?) + + 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 } - acc - } else: :err { - err | acc } - } - 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 + + + + + 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 } - } else: { - option none + last <- option value: (_compileExpr: expr syms: syms ilfun: ilf dest: asn) } - 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: { + argErrors } - last value: :v { - ilf add: (il return: (v val) (v size)) - } none: { - ilf add: (il return: 0 (il l)) - } - ilf - } else: { - varErrors } } @@ -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: { diff -r 023c29e1f595 -r 0b83f15e819d modules/parser.tp --- 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: { [] } ]