diff options
author | Russ Cox <rsc@golang.org> | 2009-10-11 02:35:53 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-10-11 02:35:53 -0700 |
commit | 81355af7a117fb5e2ea9293fc571a5e5ec1f46fe (patch) | |
tree | 9fb3f570f0c3533494624200fd6a8fb871931d8c /usr/austin/eval/world.go | |
parent | 109a270f65b3de37aba729a3a558fe2d64484ce1 (diff) | |
download | golang-81355af7a117fb5e2ea9293fc571a5e5ec1f46fe.tar.gz |
interpreter checkpoint.
* generate different versions of binary operators
for each size of int and float, so that proper
truncating happens after each operation to
simulate the various sized ops.
* add slice expressions
* publish World.CompileStmtList, CompileDeclList, CompileExpr
* handle type-less expressions in CompileExpr
R=austin
DELTA=1459 (1327 added, 11 deleted, 121 changed)
OCL=34382
CL=35581
Diffstat (limited to 'usr/austin/eval/world.go')
-rw-r--r-- | usr/austin/eval/world.go | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/usr/austin/eval/world.go b/usr/austin/eval/world.go index 397da097a..6d547f6e8 100644 --- a/usr/austin/eval/world.go +++ b/usr/austin/eval/world.go @@ -12,9 +12,6 @@ import ( "os"; ) -// TODO: Make CompileExpr and CompileStmts -// methods on World. - type World struct { scope *Scope; frame *Frame; @@ -41,10 +38,10 @@ type stmtCode struct { code code; } -func (w *World) compileStmts(stmts []ast.Stmt) (Code, os.Error) { +func (w *World) CompileStmtList(stmts []ast.Stmt) (Code, os.Error) { if len(stmts) == 1 { if s, ok := stmts[0].(*ast.ExprStmt); ok { - return w.compileExpr(s.X); + return w.CompileExpr(s.X); } } errors := scanner.NewErrorVector(); @@ -73,12 +70,12 @@ func (w *World) compileStmts(stmts []ast.Stmt) (Code, os.Error) { return &stmtCode{w, fc.get()}, nil; } -func (w *World) compileDecls(decls []ast.Decl) (Code, os.Error) { +func (w *World) CompileDeclList(decls []ast.Decl) (Code, os.Error) { stmts := make([]ast.Stmt, len(decls)); for i, d := range decls { stmts[i] = &ast.DeclStmt{d}; } - return w.compileStmts(stmts); + return w.CompileStmtList(stmts); } func (s *stmtCode) Type() Type { @@ -97,7 +94,7 @@ type exprCode struct { eval func(Value, *Thread); } -func (w *World) compileExpr(e ast.Expr) (Code, os.Error) { +func (w *World) CompileExpr(e ast.Expr) (Code, os.Error) { errors := scanner.NewErrorVector(); cc := &compiler{errors, 0, 0}; @@ -144,13 +141,13 @@ func (e *exprCode) Run() (Value, os.Error) { func (w *World) Compile(text string) (Code, os.Error) { stmts, err := parser.ParseStmtList("input", text); if err == nil { - return w.compileStmts(stmts); + return w.CompileStmtList(stmts); } // Otherwise try as DeclList. decls, err1 := parser.ParseDeclList("input", text); if err1 == nil { - return w.compileDecls(decls); + return w.CompileDeclList(decls); } // Have to pick an error. |