# HG changeset patch # User Michael Pavone # Date 1399774261 25200 # Node ID 0049467436781d3ed7f9b460912a37bf53043339 # Parent 2557ce4e671f244b69932942116a3af785d6c014 Added code for building a method symbol table diff -r 2557ce4e671f -r 004946743678 modules/ast.tp --- a/modules/ast.tp Fri Apr 11 22:29:32 2014 -0700 +++ b/modules/ast.tp Sat May 10 19:11:01 2014 -0700 @@ -36,6 +36,11 @@ string <- { stringIndent: "" } + fold:with <- :acc :fun { + acc <- fun: acc self + acc <- _left fold: acc with: fun + _right fold: acc with: fun + } } } @@ -49,6 +54,9 @@ string <- { stringIndent: "" } + fold:with <- :acc :fun { + fun: acc self + } } } @@ -89,6 +97,9 @@ string <- { stringIndent: "" } + fold:with <- :acc :fun { + fun: acc self + } } } @@ -102,11 +113,15 @@ string <- { stringIndent: "" } + fold:with <- :acc :fun { + fun: acc self + } } } funcall:withArgs:hasReceiver? <- :_tocall :_args :_receiver? { #{ + nodeType <- { _call } tocall <- _tocall args <- _args hasReceiver? <- _receiver? @@ -139,6 +154,12 @@ string <- { stringIndent: "" } + fold:with <- :acc :fun { + acc <- fun: acc self + _args fold: acc with: :acc el { + fun: acc el + } + } } } @@ -155,6 +176,12 @@ string <- { stringIndent: "" } + fold:with <- :acc :fun { + acc <- fun: acc self + messages fold: acc with: :acc el { + fun: acc el + } + } } } @@ -172,6 +199,12 @@ string <- { stringIndent: "" } + fold:with <- :acc :fun { + acc <- fun: acc self + els fold: acc with: :acc el { + fun: acc el + } + } } } @@ -186,6 +219,11 @@ string <- { stringIndent: "" } + fold:with <- :acc :fun { + acc <- fun: acc self + acc <- fun: acc _sym + fun: acc _expr + } } } @@ -207,6 +245,12 @@ string <- { stringIndent: "" } + fold:with <- :acc :fun { + acc <- fun: acc self + expressions fold: acc with: :acc el { + fun: acc el + } + } } } } diff -r 2557ce4e671f -r 004946743678 modules/compiler.tp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/compiler.tp Sat May 10 19:11:01 2014 -0700 @@ -0,0 +1,25 @@ +#{ + main <- :args { + if: (args length) > 1 { + file <- os open: (args get: 1) (os O_RDONLY) + + code <- "" + chunksize <- 1024 + readsize <- chunksize + while: { readsize = chunksize} do: { + seg <- os read: file chunksize + code <- code . seg + readsize <- seg byte_length + } + res <- parser top: code + if: res { + methods <- symbols buildMethodTable: (res yield) + print: methods + } else: { + print: "Parse failed!\n" + } + } else: { + print: "Usage compiler FILE\n" + } + } +} diff -r 2557ce4e671f -r 004946743678 modules/parser.tp --- a/modules/parser.tp Fri Apr 11 22:29:32 2014 -0700 +++ b/modules/parser.tp Sat May 10 19:11:01 2014 -0700 @@ -12,6 +12,7 @@ byte_length <- { _len } string <- { if: _needsflat? { + _needsflat? <- false _flat <- _base from: _start withLength: _len } _flat diff -r 2557ce4e671f -r 004946743678 modules/symbols.tp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/symbols.tp Sat May 10 19:11:01 2014 -0700 @@ -0,0 +1,70 @@ +{ + _null <- #{ + find:else <- :_ :else { + else: + } + } + _local <- 0 + _closedover <- 1 + _upvar <- 2 + _method <- 3 + _self <- 4 + _parent <- 5 + + _nextMethodId <- 0 + _method <- :_name { + _id <- _nextMethodId + _nextMethodId <- _id + 1 + #{ + name <- { _name } + id <- { _id } + string <- { "method " . _name . "(" . _id . ")" } + } + } + #{ + nullTable <- { _null } + + tablewithParent <- :_parent { + _symbols <- dict hash + #{ + find:else <- :name :else { + _symbols get: name else: { + _parent find: name else: else + } + } + defineMethod <- :name { + _symbols get: name else: { + _symbols set: name (_method: name) + } + self + } + print <- { + foreach: _symbols :name info { + print: name . ": " . info . "\n" + } + } + } + } + + table <- { + tablewithParent: _null + } + + buildMethodTable <- :tree { + _object <- ast obj + _assignment <- ast assignment + tree fold: table with: :acc el { + if: (el nodeType) = _object { + (el messages) fold: acc with: :acc msg { + if: (msg nodeType) = _assignment { + acc defineMethod: ((msg to) name) + } + acc + } + } else: { + acc + } + } + } + } +}