diff options
| author | Marc Vertes <marc.vertes@tendermint.com> | 2023-10-12 10:51:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-12 10:51:58 +0200 |
| commit | 37b9da32d3b911091deb254f6cba2a137c471287 (patch) | |
| tree | b4451de0fa0473a937a77d39fd1f8a4f87c8f60d /codegen/expression.go | |
| parent | a21b9b12ad865a19ff687645082f9093c4101039 (diff) | |
move to a direct byte code compiler (#8)
* chore: refactor to keep only the new parser and bytecode vm
* scanner: remove Token.value field
* scanner: remove scanner.kind field
* chore: move language specification in lang package
This avoid a cyclic dependency in scanner_test which can now use
the golang/GoSpec language specification for Go.
* clean code
* scanner: export scanner fields
Also parser now generate function calls, including externals.
* chore: fix lint issues
* parser: handle strings
* wip
* parser: implement support for 'if, else, else if' statements
Resolving labels in the compiler still in progress.
* parser: support if statements, improve compiler
* improve handling of functions
* improve support of local variables
* scanner: trim leading and trailing spaces
* fixes to make fibonacci work
* parser: improve README, fix function parameters parsing
Diffstat (limited to 'codegen/expression.go')
| -rw-r--r-- | codegen/expression.go | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/codegen/expression.go b/codegen/expression.go deleted file mode 100644 index f3eb38a..0000000 --- a/codegen/expression.go +++ /dev/null @@ -1,41 +0,0 @@ -package codegen - -import ( - "fmt" - "reflect" - - "github.com/gnolang/parscan/parser" - "github.com/gnolang/parscan/vm1" -) - -func postCallExpr(x extNode) error { - switch x.Child[0].Kind { - case parser.Ident: - var numOut int - s, _, ok := x.getSym(x.Child[0].Content(), "") - if !ok { - return fmt.Errorf("invalid symbol %s", x.Child[0].Content()) - } - if i, ok := x.codeIndex(s); ok { - // Internal call is always relative to instruction pointer. - x.Emit(x.Node, vm1.Call, int64(i-len(x.Code))) - } else { - // External call, using absolute addr in symtable. - x.Emit(x.Node, vm1.CallX, int64(len(x.Child[1].Child))) - numOut = reflect.TypeOf(x.Data[s.index]).NumOut() - } - if !usedRet(x.anc) { - x.Emit(x.Node, vm1.Pop, int64(numOut)) - } - } - return nil -} - -func usedRet(n *parser.Node) bool { - switch n.Kind { - case parser.Undefined, parser.BlockStmt: - return false - default: - return true - } -} |
