summaryrefslogtreecommitdiff
path: root/usr/austin/eval/compiler.go
blob: 641e6a293b7de07d410559b03a5d53894daf6c98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2009 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package eval

import (
	"eval";
	"fmt";
	"go/ast";
	"go/scanner";
	"go/token";
)


type positioned interface {
	Pos() token.Position;
}


// A compiler captures information used throughout an entire
// compilation.  Currently it includes only the error handler.
//
// TODO(austin) This might actually represent package level, in which
// case it should be package compiler.
type compiler struct {
	errors scanner.ErrorHandler;
}

func (a *compiler) diagAt(pos positioned, format string, args ...) {
	a.errors.Error(pos.Pos(), fmt.Sprintf(format, args));
}

type FuncDecl struct
func (a *compiler) compileFunc(b *block, decl *FuncDecl, body *ast.BlockStmt) (func (f *Frame) Func)
type exprCompiler struct
func (a *compiler) compileExpr(b *block, expr ast.Expr, constant bool) *exprCompiler
type assignCompiler struct
func (a *compiler) checkAssign(pos token.Position, rs []*exprCompiler, errOp, errPosName string) (*assignCompiler, bool)
func (a *compiler) compileAssign(pos token.Position, lt Type, rs []*exprCompiler, errOp, errPosName string) (func(lv Value, f *Frame))
func (a *compiler) compileType(b *block, typ ast.Expr) Type
func (a *compiler) compileFuncType(b *block, typ *ast.FuncType) *FuncDecl

func (a *compiler) compileArrayLen(b *block, expr ast.Expr) (int64, bool)


type codeBuf struct
type FuncType struct
// A funcCompiler captures information used throughout the compilation
// of a single function body.
type funcCompiler struct {
	*compiler;
	fnType *FuncType;
	// Whether the out variables are named.  This affects what
	// kinds of return statements are legal.
	outVarsNamed bool;
	*codeBuf;
	err bool;
}


// A blockCompiler captures information used throughout the compilation
// of a single block within a function.
type blockCompiler struct {
	*funcCompiler;
	block *block;
	returned bool;
	// The PC break statements should jump to, or nil if a break
	// statement is invalid.
	breakPC *uint;
	// The PC continue statements should jump to, or nil if a
	// continue statement is invalid.
	continuePC *uint;
	// The blockCompiler for the block enclosing this one, or nil
	// for a function-level block.
	parent *blockCompiler;
}

func (a *blockCompiler) compileStmt(s ast.Stmt)
func (a *blockCompiler) compileStmts(body *ast.BlockStmt)
func (a *blockCompiler) enterChild() *blockCompiler
func (a *blockCompiler) exit()

// An exprContext stores information used throughout the compilation
// of a single expression.  It does not embed funcCompiler because
// expressions can appear at top level.
//
// TODO(austin) Rename exprCompiler to exprNodeCompiler and rename
// this to exprCompiler.
type exprContext struct {
	*compiler;
	block *block;
	constant bool;
}