1
0
mirror of https://github.com/golang/go synced 2024-11-14 14:50:23 -07:00

Thread Thread into Value Get/Set/Assign so other Value

implementations can abort.  Make genConstant get values lazily
since we need the Thread now.

R=rsc
APPROVED=rsc
DELTA=299  (8 added, 19 deleted, 272 changed)
OCL=34353
CL=34353
This commit is contained in:
Austin Clements 2009-09-03 17:14:49 -07:00
parent 45eadcf4b8
commit 851497bc65
6 changed files with 210 additions and 221 deletions

View File

@ -213,11 +213,11 @@ func (*testFunc) NewFrame() *Frame {
} }
func (*testFunc) Call(t *Thread) { func (*testFunc) Call(t *Thread) {
n := t.f.Vars[0].(IntValue).Get(); n := t.f.Vars[0].(IntValue).Get(t);
res := n + 1; res := n + 1;
t.f.Vars[1].(IntValue).Set(res); t.f.Vars[1].(IntValue).Set(t, res);
} }
type oneTwoFunc struct {}; type oneTwoFunc struct {};
@ -227,8 +227,8 @@ func (*oneTwoFunc) NewFrame() *Frame {
} }
func (*oneTwoFunc) Call(t *Thread) { func (*oneTwoFunc) Call(t *Thread) {
t.f.Vars[0].(IntValue).Set(1); t.f.Vars[0].(IntValue).Set(t, 1);
t.f.Vars[1].(IntValue).Set(2); t.f.Vars[1].(IntValue).Set(t, 2);
} }
type voidFunc struct {}; type voidFunc struct {};

View File

@ -346,7 +346,7 @@ func (a *assignCompiler) compile(b *block, lt Type) (func(Value, *Thread)) {
vt := a.rmt.Elems[0]; vt := a.rmt.Elems[0];
effect = func(t *Thread) { effect = func(t *Thread) {
m, k := rf(t); m, k := rf(t);
v := m.Elem(k); v := m.Elem(t, k);
found := boolV(true); found := boolV(true);
if v == nil { if v == nil {
found = boolV(false); found = boolV(false);
@ -902,7 +902,7 @@ func (a *exprInfo) compileSelectorExpr(v *expr, name string) *expr {
expr := a.newExpr(ft, "selector expression"); expr := a.newExpr(ft, "selector expression");
pf := parent.asStruct(); pf := parent.asStruct();
evalAddr := func(t *Thread) Value { evalAddr := func(t *Thread) Value {
return pf(t).Field(index); return pf(t).Field(t, index);
}; };
expr.genValue(evalAddr); expr.genValue(evalAddr);
return sub(expr); return sub(expr);
@ -990,7 +990,7 @@ func (a *exprInfo) compileIndexExpr(l, r *expr) *expr {
if r < 0 || r >= bound { if r < 0 || r >= bound {
t.Abort(IndexError{r, bound}); t.Abort(IndexError{r, bound});
} }
return l.Elem(r); return l.Elem(t, r);
}); });
case *SliceType: case *SliceType:
@ -1004,7 +1004,7 @@ func (a *exprInfo) compileIndexExpr(l, r *expr) *expr {
if r < 0 || r >= l.Len { if r < 0 || r >= l.Len {
t.Abort(IndexError{r, l.Len}); t.Abort(IndexError{r, l.Len});
} }
return l.Base.Elem(r); return l.Base.Elem(t, r);
}); });
case *stringType: case *stringType:
@ -1029,7 +1029,7 @@ func (a *exprInfo) compileIndexExpr(l, r *expr) *expr {
if m == nil { if m == nil {
t.Abort(NilPointerError{}); t.Abort(NilPointerError{});
} }
e := m.Elem(k); e := m.Elem(t, k);
if e == nil { if e == nil {
t.Abort(KeyError{k}); t.Abort(KeyError{k});
} }
@ -1197,7 +1197,7 @@ func (a *exprInfo) compileBuiltinCallExpr(b *block, ft *FuncType, as []*expr) *e
if m == nil { if m == nil {
return 0; return 0;
} }
return m.Len(); return m.Len(t);
}; };
//case *ChanType: //case *ChanType:

View File

@ -97,44 +97,33 @@ func (a *expr) asInterface() (func(*Thread) interface{}) {
func (a *expr) genConstant(v Value) { func (a *expr) genConstant(v Value) {
switch _ := a.t.lit().(type) { switch _ := a.t.lit().(type) {
case *boolType: case *boolType:
val := v.(BoolValue).Get(); a.eval = func(t *Thread) bool { return v.(BoolValue).Get(t) }
a.eval = func(t *Thread) bool { return val }
case *uintType: case *uintType:
val := v.(UintValue).Get(); a.eval = func(t *Thread) uint64 { return v.(UintValue).Get(t) }
a.eval = func(t *Thread) uint64 { return val }
case *intType: case *intType:
val := v.(IntValue).Get(); a.eval = func(t *Thread) int64 { return v.(IntValue).Get(t) }
a.eval = func(t *Thread) int64 { return val }
case *idealIntType: case *idealIntType:
val := v.(IdealIntValue).Get(); val := v.(IdealIntValue).Get();
a.eval = func() *bignum.Integer { return val } a.eval = func() *bignum.Integer { return val }
case *floatType: case *floatType:
val := v.(FloatValue).Get(); a.eval = func(t *Thread) float64 { return v.(FloatValue).Get(t) }
a.eval = func(t *Thread) float64 { return val }
case *idealFloatType: case *idealFloatType:
val := v.(IdealFloatValue).Get(); val := v.(IdealFloatValue).Get();
a.eval = func() *bignum.Rational { return val } a.eval = func() *bignum.Rational { return val }
case *stringType: case *stringType:
val := v.(StringValue).Get(); a.eval = func(t *Thread) string { return v.(StringValue).Get(t) }
a.eval = func(t *Thread) string { return val }
case *ArrayType: case *ArrayType:
val := v.(ArrayValue).Get(); a.eval = func(t *Thread) ArrayValue { return v.(ArrayValue).Get(t) }
a.eval = func(t *Thread) ArrayValue { return val }
case *StructType: case *StructType:
val := v.(StructValue).Get(); a.eval = func(t *Thread) StructValue { return v.(StructValue).Get(t) }
a.eval = func(t *Thread) StructValue { return val }
case *PtrType: case *PtrType:
val := v.(PtrValue).Get(); a.eval = func(t *Thread) Value { return v.(PtrValue).Get(t) }
a.eval = func(t *Thread) Value { return val }
case *FuncType: case *FuncType:
val := v.(FuncValue).Get(); a.eval = func(t *Thread) Func { return v.(FuncValue).Get(t) }
a.eval = func(t *Thread) Func { return val }
case *SliceType: case *SliceType:
val := v.(SliceValue).Get(); a.eval = func(t *Thread) Slice { return v.(SliceValue).Get(t) }
a.eval = func(t *Thread) Slice { return val }
case *MapType: case *MapType:
val := v.(MapValue).Get(); a.eval = func(t *Thread) Map { return v.(MapValue).Get(t) }
a.eval = func(t *Thread) Map { return val }
default: default:
log.Crashf("unexpected constant type %v at %v", a.t, a.pos); log.Crashf("unexpected constant type %v at %v", a.t, a.pos);
} }
@ -144,27 +133,27 @@ func (a *expr) genIdentOp(level, index int) {
a.evalAddr = func(t *Thread) Value { return t.f.Get(level, index) }; a.evalAddr = func(t *Thread) Value { return t.f.Get(level, index) };
switch _ := a.t.lit().(type) { switch _ := a.t.lit().(type) {
case *boolType: case *boolType:
a.eval = func(t *Thread) bool { return t.f.Get(level, index).(BoolValue).Get() } a.eval = func(t *Thread) bool { return t.f.Get(level, index).(BoolValue).Get(t) }
case *uintType: case *uintType:
a.eval = func(t *Thread) uint64 { return t.f.Get(level, index).(UintValue).Get() } a.eval = func(t *Thread) uint64 { return t.f.Get(level, index).(UintValue).Get(t) }
case *intType: case *intType:
a.eval = func(t *Thread) int64 { return t.f.Get(level, index).(IntValue).Get() } a.eval = func(t *Thread) int64 { return t.f.Get(level, index).(IntValue).Get(t) }
case *floatType: case *floatType:
a.eval = func(t *Thread) float64 { return t.f.Get(level, index).(FloatValue).Get() } a.eval = func(t *Thread) float64 { return t.f.Get(level, index).(FloatValue).Get(t) }
case *stringType: case *stringType:
a.eval = func(t *Thread) string { return t.f.Get(level, index).(StringValue).Get() } a.eval = func(t *Thread) string { return t.f.Get(level, index).(StringValue).Get(t) }
case *ArrayType: case *ArrayType:
a.eval = func(t *Thread) ArrayValue { return t.f.Get(level, index).(ArrayValue).Get() } a.eval = func(t *Thread) ArrayValue { return t.f.Get(level, index).(ArrayValue).Get(t) }
case *StructType: case *StructType:
a.eval = func(t *Thread) StructValue { return t.f.Get(level, index).(StructValue).Get() } a.eval = func(t *Thread) StructValue { return t.f.Get(level, index).(StructValue).Get(t) }
case *PtrType: case *PtrType:
a.eval = func(t *Thread) Value { return t.f.Get(level, index).(PtrValue).Get() } a.eval = func(t *Thread) Value { return t.f.Get(level, index).(PtrValue).Get(t) }
case *FuncType: case *FuncType:
a.eval = func(t *Thread) Func { return t.f.Get(level, index).(FuncValue).Get() } a.eval = func(t *Thread) Func { return t.f.Get(level, index).(FuncValue).Get(t) }
case *SliceType: case *SliceType:
a.eval = func(t *Thread) Slice { return t.f.Get(level, index).(SliceValue).Get() } a.eval = func(t *Thread) Slice { return t.f.Get(level, index).(SliceValue).Get(t) }
case *MapType: case *MapType:
a.eval = func(t *Thread) Map { return t.f.Get(level, index).(MapValue).Get() } a.eval = func(t *Thread) Map { return t.f.Get(level, index).(MapValue).Get(t) }
default: default:
log.Crashf("unexpected identifier type %v at %v", a.t, a.pos); log.Crashf("unexpected identifier type %v at %v", a.t, a.pos);
} }
@ -174,27 +163,27 @@ func (a *expr) genFuncCall(call func(t *Thread) []Value) {
a.exec = func(t *Thread) { call(t)}; a.exec = func(t *Thread) { call(t)};
switch _ := a.t.lit().(type) { switch _ := a.t.lit().(type) {
case *boolType: case *boolType:
a.eval = func(t *Thread) bool { return call(t)[0].(BoolValue).Get() } a.eval = func(t *Thread) bool { return call(t)[0].(BoolValue).Get(t) }
case *uintType: case *uintType:
a.eval = func(t *Thread) uint64 { return call(t)[0].(UintValue).Get() } a.eval = func(t *Thread) uint64 { return call(t)[0].(UintValue).Get(t) }
case *intType: case *intType:
a.eval = func(t *Thread) int64 { return call(t)[0].(IntValue).Get() } a.eval = func(t *Thread) int64 { return call(t)[0].(IntValue).Get(t) }
case *floatType: case *floatType:
a.eval = func(t *Thread) float64 { return call(t)[0].(FloatValue).Get() } a.eval = func(t *Thread) float64 { return call(t)[0].(FloatValue).Get(t) }
case *stringType: case *stringType:
a.eval = func(t *Thread) string { return call(t)[0].(StringValue).Get() } a.eval = func(t *Thread) string { return call(t)[0].(StringValue).Get(t) }
case *ArrayType: case *ArrayType:
a.eval = func(t *Thread) ArrayValue { return call(t)[0].(ArrayValue).Get() } a.eval = func(t *Thread) ArrayValue { return call(t)[0].(ArrayValue).Get(t) }
case *StructType: case *StructType:
a.eval = func(t *Thread) StructValue { return call(t)[0].(StructValue).Get() } a.eval = func(t *Thread) StructValue { return call(t)[0].(StructValue).Get(t) }
case *PtrType: case *PtrType:
a.eval = func(t *Thread) Value { return call(t)[0].(PtrValue).Get() } a.eval = func(t *Thread) Value { return call(t)[0].(PtrValue).Get(t) }
case *FuncType: case *FuncType:
a.eval = func(t *Thread) Func { return call(t)[0].(FuncValue).Get() } a.eval = func(t *Thread) Func { return call(t)[0].(FuncValue).Get(t) }
case *SliceType: case *SliceType:
a.eval = func(t *Thread) Slice { return call(t)[0].(SliceValue).Get() } a.eval = func(t *Thread) Slice { return call(t)[0].(SliceValue).Get(t) }
case *MapType: case *MapType:
a.eval = func(t *Thread) Map { return call(t)[0].(MapValue).Get() } a.eval = func(t *Thread) Map { return call(t)[0].(MapValue).Get(t) }
case *MultiType: case *MultiType:
a.eval = func(t *Thread) []Value { return call(t) } a.eval = func(t *Thread) []Value { return call(t) }
default: default:
@ -206,27 +195,27 @@ func (a *expr) genValue(vf func(*Thread) Value) {
a.evalAddr = vf; a.evalAddr = vf;
switch _ := a.t.lit().(type) { switch _ := a.t.lit().(type) {
case *boolType: case *boolType:
a.eval = func(t *Thread) bool { return vf(t).(BoolValue).Get() } a.eval = func(t *Thread) bool { return vf(t).(BoolValue).Get(t) }
case *uintType: case *uintType:
a.eval = func(t *Thread) uint64 { return vf(t).(UintValue).Get() } a.eval = func(t *Thread) uint64 { return vf(t).(UintValue).Get(t) }
case *intType: case *intType:
a.eval = func(t *Thread) int64 { return vf(t).(IntValue).Get() } a.eval = func(t *Thread) int64 { return vf(t).(IntValue).Get(t) }
case *floatType: case *floatType:
a.eval = func(t *Thread) float64 { return vf(t).(FloatValue).Get() } a.eval = func(t *Thread) float64 { return vf(t).(FloatValue).Get(t) }
case *stringType: case *stringType:
a.eval = func(t *Thread) string { return vf(t).(StringValue).Get() } a.eval = func(t *Thread) string { return vf(t).(StringValue).Get(t) }
case *ArrayType: case *ArrayType:
a.eval = func(t *Thread) ArrayValue { return vf(t).(ArrayValue).Get() } a.eval = func(t *Thread) ArrayValue { return vf(t).(ArrayValue).Get(t) }
case *StructType: case *StructType:
a.eval = func(t *Thread) StructValue { return vf(t).(StructValue).Get() } a.eval = func(t *Thread) StructValue { return vf(t).(StructValue).Get(t) }
case *PtrType: case *PtrType:
a.eval = func(t *Thread) Value { return vf(t).(PtrValue).Get() } a.eval = func(t *Thread) Value { return vf(t).(PtrValue).Get(t) }
case *FuncType: case *FuncType:
a.eval = func(t *Thread) Func { return vf(t).(FuncValue).Get() } a.eval = func(t *Thread) Func { return vf(t).(FuncValue).Get(t) }
case *SliceType: case *SliceType:
a.eval = func(t *Thread) Slice { return vf(t).(SliceValue).Get() } a.eval = func(t *Thread) Slice { return vf(t).(SliceValue).Get(t) }
case *MapType: case *MapType:
a.eval = func(t *Thread) Map { return vf(t).(MapValue).Get() } a.eval = func(t *Thread) Map { return vf(t).(MapValue).Get(t) }
default: default:
log.Crashf("unexpected result type %v at %v", a.t, a.pos); log.Crashf("unexpected result type %v at %v", a.t, a.pos);
} }
@ -767,37 +756,37 @@ func genAssign(lt Type, r *expr) (func(lv Value, t *Thread)) {
switch _ := lt.lit().(type) { switch _ := lt.lit().(type) {
case *boolType: case *boolType:
rf := r.asBool(); rf := r.asBool();
return func(lv Value, t *Thread) { lv.(BoolValue).Set(rf(t)) } return func(lv Value, t *Thread) { lv.(BoolValue).Set(t, rf(t)) }
case *uintType: case *uintType:
rf := r.asUint(); rf := r.asUint();
return func(lv Value, t *Thread) { lv.(UintValue).Set(rf(t)) } return func(lv Value, t *Thread) { lv.(UintValue).Set(t, rf(t)) }
case *intType: case *intType:
rf := r.asInt(); rf := r.asInt();
return func(lv Value, t *Thread) { lv.(IntValue).Set(rf(t)) } return func(lv Value, t *Thread) { lv.(IntValue).Set(t, rf(t)) }
case *floatType: case *floatType:
rf := r.asFloat(); rf := r.asFloat();
return func(lv Value, t *Thread) { lv.(FloatValue).Set(rf(t)) } return func(lv Value, t *Thread) { lv.(FloatValue).Set(t, rf(t)) }
case *stringType: case *stringType:
rf := r.asString(); rf := r.asString();
return func(lv Value, t *Thread) { lv.(StringValue).Set(rf(t)) } return func(lv Value, t *Thread) { lv.(StringValue).Set(t, rf(t)) }
case *ArrayType: case *ArrayType:
rf := r.asArray(); rf := r.asArray();
return func(lv Value, t *Thread) { lv.Assign(rf(t)) } return func(lv Value, t *Thread) { lv.Assign(t, rf(t)) }
case *StructType: case *StructType:
rf := r.asStruct(); rf := r.asStruct();
return func(lv Value, t *Thread) { lv.Assign(rf(t)) } return func(lv Value, t *Thread) { lv.Assign(t, rf(t)) }
case *PtrType: case *PtrType:
rf := r.asPtr(); rf := r.asPtr();
return func(lv Value, t *Thread) { lv.(PtrValue).Set(rf(t)) } return func(lv Value, t *Thread) { lv.(PtrValue).Set(t, rf(t)) }
case *FuncType: case *FuncType:
rf := r.asFunc(); rf := r.asFunc();
return func(lv Value, t *Thread) { lv.(FuncValue).Set(rf(t)) } return func(lv Value, t *Thread) { lv.(FuncValue).Set(t, rf(t)) }
case *SliceType: case *SliceType:
rf := r.asSlice(); rf := r.asSlice();
return func(lv Value, t *Thread) { lv.(SliceValue).Set(rf(t)) } return func(lv Value, t *Thread) { lv.(SliceValue).Set(t, rf(t)) }
case *MapType: case *MapType:
rf := r.asMap(); rf := r.asMap();
return func(lv Value, t *Thread) { lv.(MapValue).Set(rf(t)) } return func(lv Value, t *Thread) { lv.(MapValue).Set(t, rf(t)) }
default: default:
log.Crashf("unexpected left operand type %v at %v", lt, r.pos); log.Crashf("unexpected left operand type %v at %v", lt, r.pos);
} }

View File

@ -184,11 +184,11 @@ func (a *expr) genConstant(v Value) {
switch _ := a.t.lit().(type) { switch _ := a.t.lit().(type) {
«.repeated section Types» «.repeated section Types»
case «Repr»: case «Repr»:
val := v.(«Value»).Get();
«.section IsIdeal» «.section IsIdeal»
val := v.(«Value»).Get();
a.eval = func() «Native» { return val } a.eval = func() «Native» { return val }
«.or» «.or»
a.eval = func(t *Thread) «Native» { return val } a.eval = func(t *Thread) «Native» { return v.(«Value»).Get(t) }
«.end» «.end»
«.end» «.end»
default: default:
@ -203,7 +203,7 @@ func (a *expr) genIdentOp(level, index int) {
«.section IsIdeal» «.section IsIdeal»
«.or» «.or»
case «Repr»: case «Repr»:
a.eval = func(t *Thread) «Native» { return t.f.Get(level, index).(«Value»).Get() } a.eval = func(t *Thread) «Native» { return t.f.Get(level, index).(«Value»).Get(t) }
«.end» «.end»
«.end» «.end»
default: default:
@ -218,7 +218,7 @@ func (a *expr) genFuncCall(call func(t *Thread) []Value) {
«.section IsIdeal» «.section IsIdeal»
«.or» «.or»
case «Repr»: case «Repr»:
a.eval = func(t *Thread) «Native» { return call(t)[0].(«Value»).Get() } a.eval = func(t *Thread) «Native» { return call(t)[0].(«Value»).Get(t) }
«.end» «.end»
«.end» «.end»
case *MultiType: case *MultiType:
@ -235,7 +235,7 @@ func (a *expr) genValue(vf func(*Thread) Value) {
«.section IsIdeal» «.section IsIdeal»
«.or» «.or»
case «Repr»: case «Repr»:
a.eval = func(t *Thread) «Native» { return vf(t).(«Value»).Get() } a.eval = func(t *Thread) «Native» { return vf(t).(«Value»).Get(t) }
«.end» «.end»
«.end» «.end»
default: default:
@ -296,7 +296,7 @@ func genAssign(lt Type, r *expr) (func(lv Value, t *Thread)) {
«.or» «.or»
case «Repr»: case «Repr»:
rf := r.«As»(); rf := r.«As»();
return func(lv Value, t *Thread) { «.section HasAssign»lv.Assign(rf(t))«.or»lv.(«Value»).Set(rf(t))«.end» } return func(lv Value, t *Thread) { «.section HasAssign»lv.Assign(t, rf(t))«.or»lv.(«Value»).Set(t, rf(t))«.end» }
«.end» «.end»
«.end» «.end»
default: default:

View File

@ -402,7 +402,7 @@ func (a *stmtCompiler) compileDecl(decl ast.Decl) {
return; return;
} }
var zeroThread Thread; var zeroThread Thread;
c.Value.(FuncValue).Set(fn(&zeroThread)); c.Value.(FuncValue).Set(nil, fn(&zeroThread));
case *ast.GenDecl: case *ast.GenDecl:
switch d.Tok { switch d.Tok {
@ -649,10 +649,10 @@ func (a *stmtCompiler) doAssign(lhs []ast.Expr, rhs []ast.Expr, tok token.Token,
et := sub.t; et := sub.t;
ls[i].evalAddr = func(t *Thread) Value { ls[i].evalAddr = func(t *Thread) Value {
m, k := mvf(t); m, k := mvf(t);
e := m.Elem(k); e := m.Elem(t, k);
if e == nil { if e == nil {
e = et.Zero(); e = et.Zero();
m.SetElem(k, e); m.SetElem(t, k, e);
} }
return e; return e;
}; };
@ -736,7 +736,7 @@ func (a *stmtCompiler) doAssign(lhs []ast.Expr, rhs []ast.Expr, tok token.Token,
for i := 0; i < n; i ++ { for i := 0; i < n; i ++ {
// TODO(austin) Need to evaluate LHS // TODO(austin) Need to evaluate LHS
// before RHS // before RHS
lfs[i](t).Assign(temp[i]); lfs[i](t).Assign(t, temp[i]);
} }
}); });
} }

View File

@ -15,25 +15,25 @@ type Value interface {
// assume that the other value satisfies the same specific // assume that the other value satisfies the same specific
// value interface (BoolValue, etc.), but must not assume // value interface (BoolValue, etc.), but must not assume
// anything about its specific type. // anything about its specific type.
Assign(o Value); Assign(t *Thread, o Value);
} }
type BoolValue interface { type BoolValue interface {
Value; Value;
Get() bool; Get(*Thread) bool;
Set(bool); Set(*Thread, bool);
} }
type UintValue interface { type UintValue interface {
Value; Value;
Get() uint64; Get(*Thread) uint64;
Set(uint64); Set(*Thread, uint64);
} }
type IntValue interface { type IntValue interface {
Value; Value;
Get() int64; Get(*Thread) int64;
Set(int64); Set(*Thread, int64);
} }
// TODO(austin) IdealIntValue and IdealFloatValue should not exist // TODO(austin) IdealIntValue and IdealFloatValue should not exist
@ -45,8 +45,8 @@ type IdealIntValue interface {
type FloatValue interface { type FloatValue interface {
Value; Value;
Get() float64; Get(*Thread) float64;
Set(float64); Set(*Thread, float64);
} }
type IdealFloatValue interface { type IdealFloatValue interface {
@ -56,8 +56,8 @@ type IdealFloatValue interface {
type StringValue interface { type StringValue interface {
Value; Value;
Get() string; Get(*Thread) string;
Set(string); Set(*Thread, string);
} }
type ArrayValue interface { type ArrayValue interface {
@ -65,24 +65,24 @@ type ArrayValue interface {
// TODO(austin) Get() is here for uniformity, but is // TODO(austin) Get() is here for uniformity, but is
// completely useless. If a lot of other types have similarly // completely useless. If a lot of other types have similarly
// useless Get methods, just special-case these uses. // useless Get methods, just special-case these uses.
Get() ArrayValue; Get(*Thread) ArrayValue;
Elem(i int64) Value; Elem(*Thread, int64) Value;
// From returns an ArrayValue backed by the same array that // Sub returns an ArrayValue backed by the same array that
// starts from element i. // starts from element i and has length len.
From(i int64) ArrayValue; Sub(i int64, len int64) ArrayValue;
} }
type StructValue interface { type StructValue interface {
Value; Value;
// TODO(austin) This is another useless Get() // TODO(austin) This is another useless Get()
Get() StructValue; Get(*Thread) StructValue;
Field(i int) Value; Field(*Thread, int) Value;
} }
type PtrValue interface { type PtrValue interface {
Value; Value;
Get() Value; Get(*Thread) Value;
Set(Value); Set(*Thread, Value);
} }
type Func interface { type Func interface {
@ -92,8 +92,8 @@ type Func interface {
type FuncValue interface { type FuncValue interface {
Value; Value;
Get() Func; Get(*Thread) Func;
Set(Func); Set(*Thread, Func);
} }
type Slice struct { type Slice struct {
@ -103,25 +103,25 @@ type Slice struct {
type SliceValue interface { type SliceValue interface {
Value; Value;
Get() Slice; Get(*Thread) Slice;
Set(Slice); Set(*Thread, Slice);
} }
type Map interface { type Map interface {
Len() int64; Len(*Thread) int64;
// Retrieve an element from the map, returning nil if it does // Retrieve an element from the map, returning nil if it does
// not exist. // not exist.
Elem(key interface{}) Value; Elem(t *Thread, key interface{}) Value;
// Set an entry in the map. If val is nil, delete the entry. // Set an entry in the map. If val is nil, delete the entry.
SetElem(key interface{}, val Value); SetElem(t *Thread, key interface{}, val Value);
// TODO(austin) Perhaps there should be an iterator interface instead. // TODO(austin) Perhaps there should be an iterator interface instead.
Iter(func(key interface{}, val Value) bool); Iter(func(key interface{}, val Value) bool);
} }
type MapValue interface { type MapValue interface {
Value; Value;
Get() Map; Get(*Thread) Map;
Set(Map); Set(*Thread, Map);
} }
/* /*
@ -134,15 +134,15 @@ func (v *boolV) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *boolV) Assign(o Value) { func (v *boolV) Assign(t *Thread, o Value) {
*v = boolV(o.(BoolValue).Get()); *v = boolV(o.(BoolValue).Get(t));
} }
func (v *boolV) Get() bool { func (v *boolV) Get(*Thread) bool {
return bool(*v); return bool(*v);
} }
func (v *boolV) Set(x bool) { func (v *boolV) Set(t *Thread, x bool) {
*v = boolV(x); *v = boolV(x);
} }
@ -156,15 +156,15 @@ func (v *uint8V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *uint8V) Assign(o Value) { func (v *uint8V) Assign(t *Thread, o Value) {
*v = uint8V(o.(UintValue).Get()); *v = uint8V(o.(UintValue).Get(t));
} }
func (v *uint8V) Get() uint64 { func (v *uint8V) Get(*Thread) uint64 {
return uint64(*v); return uint64(*v);
} }
func (v *uint8V) Set(x uint64) { func (v *uint8V) Set(t *Thread, x uint64) {
*v = uint8V(x); *v = uint8V(x);
} }
@ -174,15 +174,15 @@ func (v *uint16V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *uint16V) Assign(o Value) { func (v *uint16V) Assign(t *Thread, o Value) {
*v = uint16V(o.(UintValue).Get()); *v = uint16V(o.(UintValue).Get(t));
} }
func (v *uint16V) Get() uint64 { func (v *uint16V) Get(*Thread) uint64 {
return uint64(*v); return uint64(*v);
} }
func (v *uint16V) Set(x uint64) { func (v *uint16V) Set(t *Thread, x uint64) {
*v = uint16V(x); *v = uint16V(x);
} }
@ -192,15 +192,15 @@ func (v *uint32V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *uint32V) Assign(o Value) { func (v *uint32V) Assign(t *Thread, o Value) {
*v = uint32V(o.(UintValue).Get()); *v = uint32V(o.(UintValue).Get(t));
} }
func (v *uint32V) Get() uint64 { func (v *uint32V) Get(*Thread) uint64 {
return uint64(*v); return uint64(*v);
} }
func (v *uint32V) Set(x uint64) { func (v *uint32V) Set(t *Thread, x uint64) {
*v = uint32V(x); *v = uint32V(x);
} }
@ -210,15 +210,15 @@ func (v *uint64V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *uint64V) Assign(o Value) { func (v *uint64V) Assign(t *Thread, o Value) {
*v = uint64V(o.(UintValue).Get()); *v = uint64V(o.(UintValue).Get(t));
} }
func (v *uint64V) Get() uint64 { func (v *uint64V) Get(*Thread) uint64 {
return uint64(*v); return uint64(*v);
} }
func (v *uint64V) Set(x uint64) { func (v *uint64V) Set(t *Thread, x uint64) {
*v = uint64V(x); *v = uint64V(x);
} }
@ -228,15 +228,15 @@ func (v *uintV) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *uintV) Assign(o Value) { func (v *uintV) Assign(t *Thread, o Value) {
*v = uintV(o.(UintValue).Get()); *v = uintV(o.(UintValue).Get(t));
} }
func (v *uintV) Get() uint64 { func (v *uintV) Get(*Thread) uint64 {
return uint64(*v); return uint64(*v);
} }
func (v *uintV) Set(x uint64) { func (v *uintV) Set(t *Thread, x uint64) {
*v = uintV(x); *v = uintV(x);
} }
@ -246,15 +246,15 @@ func (v *uintptrV) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *uintptrV) Assign(o Value) { func (v *uintptrV) Assign(t *Thread, o Value) {
*v = uintptrV(o.(UintValue).Get()); *v = uintptrV(o.(UintValue).Get(t));
} }
func (v *uintptrV) Get() uint64 { func (v *uintptrV) Get(*Thread) uint64 {
return uint64(*v); return uint64(*v);
} }
func (v *uintptrV) Set(x uint64) { func (v *uintptrV) Set(t *Thread, x uint64) {
*v = uintptrV(x); *v = uintptrV(x);
} }
@ -268,15 +268,15 @@ func (v *int8V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *int8V) Assign(o Value) { func (v *int8V) Assign(t *Thread, o Value) {
*v = int8V(o.(IntValue).Get()); *v = int8V(o.(IntValue).Get(t));
} }
func (v *int8V) Get() int64 { func (v *int8V) Get(*Thread) int64 {
return int64(*v); return int64(*v);
} }
func (v *int8V) Set(x int64) { func (v *int8V) Set(t *Thread, x int64) {
*v = int8V(x); *v = int8V(x);
} }
@ -286,15 +286,15 @@ func (v *int16V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *int16V) Assign(o Value) { func (v *int16V) Assign(t *Thread, o Value) {
*v = int16V(o.(IntValue).Get()); *v = int16V(o.(IntValue).Get(t));
} }
func (v *int16V) Get() int64 { func (v *int16V) Get(*Thread) int64 {
return int64(*v); return int64(*v);
} }
func (v *int16V) Set(x int64) { func (v *int16V) Set(t *Thread, x int64) {
*v = int16V(x); *v = int16V(x);
} }
@ -304,15 +304,15 @@ func (v *int32V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *int32V) Assign(o Value) { func (v *int32V) Assign(t *Thread, o Value) {
*v = int32V(o.(IntValue).Get()); *v = int32V(o.(IntValue).Get(t));
} }
func (v *int32V) Get() int64 { func (v *int32V) Get(*Thread) int64 {
return int64(*v); return int64(*v);
} }
func (v *int32V) Set(x int64) { func (v *int32V) Set(t *Thread, x int64) {
*v = int32V(x); *v = int32V(x);
} }
@ -322,15 +322,15 @@ func (v *int64V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *int64V) Assign(o Value) { func (v *int64V) Assign(t *Thread, o Value) {
*v = int64V(o.(IntValue).Get()); *v = int64V(o.(IntValue).Get(t));
} }
func (v *int64V) Get() int64 { func (v *int64V) Get(*Thread) int64 {
return int64(*v); return int64(*v);
} }
func (v *int64V) Set(x int64) { func (v *int64V) Set(t *Thread, x int64) {
*v = int64V(x); *v = int64V(x);
} }
@ -340,15 +340,15 @@ func (v *intV) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *intV) Assign(o Value) { func (v *intV) Assign(t *Thread, o Value) {
*v = intV(o.(IntValue).Get()); *v = intV(o.(IntValue).Get(t));
} }
func (v *intV) Get() int64 { func (v *intV) Get(*Thread) int64 {
return int64(*v); return int64(*v);
} }
func (v *intV) Set(x int64) { func (v *intV) Set(t *Thread, x int64) {
*v = intV(x); *v = intV(x);
} }
@ -364,7 +364,7 @@ func (v *idealIntV) String() string {
return v.V.String(); return v.V.String();
} }
func (v *idealIntV) Assign(o Value) { func (v *idealIntV) Assign(t *Thread, o Value) {
v.V = o.(IdealIntValue).Get(); v.V = o.(IdealIntValue).Get();
} }
@ -382,15 +382,15 @@ func (v *float32V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *float32V) Assign(o Value) { func (v *float32V) Assign(t *Thread, o Value) {
*v = float32V(o.(FloatValue).Get()); *v = float32V(o.(FloatValue).Get(t));
} }
func (v *float32V) Get() float64 { func (v *float32V) Get(*Thread) float64 {
return float64(*v); return float64(*v);
} }
func (v *float32V) Set(x float64) { func (v *float32V) Set(t *Thread, x float64) {
*v = float32V(x); *v = float32V(x);
} }
@ -400,15 +400,15 @@ func (v *float64V) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *float64V) Assign(o Value) { func (v *float64V) Assign(t *Thread, o Value) {
*v = float64V(o.(FloatValue).Get()); *v = float64V(o.(FloatValue).Get(t));
} }
func (v *float64V) Get() float64 { func (v *float64V) Get(*Thread) float64 {
return float64(*v); return float64(*v);
} }
func (v *float64V) Set(x float64) { func (v *float64V) Set(t *Thread, x float64) {
*v = float64V(x); *v = float64V(x);
} }
@ -418,15 +418,15 @@ func (v *floatV) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *floatV) Assign(o Value) { func (v *floatV) Assign(t *Thread, o Value) {
*v = floatV(o.(FloatValue).Get()); *v = floatV(o.(FloatValue).Get(t));
} }
func (v *floatV) Get() float64 { func (v *floatV) Get(*Thread) float64 {
return float64(*v); return float64(*v);
} }
func (v *floatV) Set(x float64) { func (v *floatV) Set(t *Thread, x float64) {
*v = floatV(x); *v = floatV(x);
} }
@ -442,7 +442,7 @@ func (v *idealFloatV) String() string {
return ratToString(v.V); return ratToString(v.V);
} }
func (v *idealFloatV) Assign(o Value) { func (v *idealFloatV) Assign(t *Thread, o Value) {
v.V = o.(IdealFloatValue).Get(); v.V = o.(IdealFloatValue).Get();
} }
@ -460,15 +460,15 @@ func (v *stringV) String() string {
return fmt.Sprint(*v); return fmt.Sprint(*v);
} }
func (v *stringV) Assign(o Value) { func (v *stringV) Assign(t *Thread, o Value) {
*v = stringV(o.(StringValue).Get()); *v = stringV(o.(StringValue).Get(t));
} }
func (v *stringV) Get() string { func (v *stringV) Get(*Thread) string {
return string(*v); return string(*v);
} }
func (v *stringV) Set(x string) { func (v *stringV) Set(t *Thread, x string) {
*v = stringV(x); *v = stringV(x);
} }
@ -479,27 +479,34 @@ func (v *stringV) Set(x string) {
type arrayV []Value type arrayV []Value
func (v *arrayV) String() string { func (v *arrayV) String() string {
return fmt.Sprint(*v); res := "{";
for i, e := range *v {
if i > 0 {
res += ", ";
}
res += e.String();
}
return res + "}";
} }
func (v *arrayV) Assign(o Value) { func (v *arrayV) Assign(t *Thread, o Value) {
oa := o.(ArrayValue); oa := o.(ArrayValue);
l := int64(len(*v)); l := int64(len(*v));
for i := int64(0); i < l; i++ { for i := int64(0); i < l; i++ {
(*v)[i].Assign(oa.Elem(i)); (*v)[i].Assign(t, oa.Elem(t, i));
} }
} }
func (v *arrayV) Get() ArrayValue { func (v *arrayV) Get(*Thread) ArrayValue {
return v; return v;
} }
func (v *arrayV) Elem(i int64) Value { func (v *arrayV) Elem(t *Thread, i int64) Value {
return (*v)[i]; return (*v)[i];
} }
func (v *arrayV) From(i int64) ArrayValue { func (v *arrayV) Sub(i int64, len int64) ArrayValue {
res := (*v)[i:len(*v)]; res := (*v)[i:i+len];
return &res; return &res;
} }
@ -522,19 +529,19 @@ func (v *structV) String() string {
return res + "}"; return res + "}";
} }
func (v *structV) Assign(o Value) { func (v *structV) Assign(t *Thread, o Value) {
oa := o.(StructValue); oa := o.(StructValue);
l := len(*v); l := len(*v);
for i := 0; i < l; i++ { for i := 0; i < l; i++ {
(*v)[i].Assign(oa.Field(i)); (*v)[i].Assign(t, oa.Field(t, i));
} }
} }
func (v *structV) Get() StructValue { func (v *structV) Get(*Thread) StructValue {
return v; return v;
} }
func (v *structV) Field(i int) Value { func (v *structV) Field(t *Thread, i int) Value {
return (*v)[i]; return (*v)[i];
} }
@ -554,15 +561,15 @@ func (v *ptrV) String() string {
return "&" + v.target.String(); return "&" + v.target.String();
} }
func (v *ptrV) Assign(o Value) { func (v *ptrV) Assign(t *Thread, o Value) {
v.target = o.(PtrValue).Get(); v.target = o.(PtrValue).Get(t);
} }
func (v *ptrV) Get() Value { func (v *ptrV) Get(*Thread) Value {
return v.target; return v.target;
} }
func (v *ptrV) Set(x Value) { func (v *ptrV) Set(t *Thread, x Value) {
v.target = x; v.target = x;
} }
@ -579,15 +586,15 @@ func (v *funcV) String() string {
return "func {...}"; return "func {...}";
} }
func (v *funcV) Assign(o Value) { func (v *funcV) Assign(t *Thread, o Value) {
v.target = o.(FuncValue).Get(); v.target = o.(FuncValue).Get(t);
} }
func (v *funcV) Get() Func { func (v *funcV) Get(*Thread) Func {
return v.target; return v.target;
} }
func (v *funcV) Set(x Func) { func (v *funcV) Set(t *Thread, x Func) {
v.target = x; v.target = x;
} }
@ -603,25 +610,18 @@ func (v *sliceV) String() string {
if v.Base == nil { if v.Base == nil {
return "<nil>"; return "<nil>";
} }
res := "{"; return v.Base.Sub(0, v.Len).String();
for i := int64(0); i < v.Len; i++ {
if i > 0 {
res += ", ";
}
res += v.Base.Elem(i).String();
}
return res + "}";
} }
func (v *sliceV) Assign(o Value) { func (v *sliceV) Assign(t *Thread, o Value) {
v.Slice = o.(SliceValue).Get(); v.Slice = o.(SliceValue).Get(t);
} }
func (v *sliceV) Get() Slice { func (v *sliceV) Get(*Thread) Slice {
return v.Slice; return v.Slice;
} }
func (v *sliceV) Set(x Slice) { func (v *sliceV) Set(t *Thread, x Slice) {
v.Slice = x; v.Slice = x;
} }
@ -650,32 +650,32 @@ func (v *mapV) String() string {
return res + "]"; return res + "]";
} }
func (v *mapV) Assign(o Value) { func (v *mapV) Assign(t *Thread, o Value) {
v.target = o.(MapValue).Get(); v.target = o.(MapValue).Get(t);
} }
func (v *mapV) Get() Map { func (v *mapV) Get(*Thread) Map {
return v.target; return v.target;
} }
func (v *mapV) Set(x Map) { func (v *mapV) Set(t *Thread, x Map) {
v.target = x; v.target = x;
} }
type evalMap map[interface{}] Value type evalMap map[interface{}] Value
func (m evalMap) Len() int64 { func (m evalMap) Len(t *Thread) int64 {
return int64(len(m)); return int64(len(m));
} }
func (m evalMap) Elem(key interface{}) Value { func (m evalMap) Elem(t *Thread, key interface{}) Value {
if v, ok := m[key]; ok { if v, ok := m[key]; ok {
return v; return v;
} }
return nil; return nil;
} }
func (m evalMap) SetElem(key interface{}, val Value) { func (m evalMap) SetElem(t *Thread, key interface{}, val Value) {
if val == nil { if val == nil {
m[key] = nil, false; m[key] = nil, false;
} else { } else {
@ -708,10 +708,10 @@ func (v multiV) String() string {
return res + ")"; return res + ")";
} }
func (v multiV) Assign(o Value) { func (v multiV) Assign(t *Thread, o Value) {
omv := o.(multiV); omv := o.(multiV);
for i := range v { for i := range v {
v[i].Assign(omv[i]); v[i].Assign(t, omv[i]);
} }
} }