diff options
author | Russ Cox <rsc@golang.org> | 2009-09-03 16:20:49 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-09-03 16:20:49 -0700 |
commit | b423697aee32aedb8695c271528486389e39c403 (patch) | |
tree | 088f49d2c54ed11c91730055b08d5cbabe0e88c6 /usr/austin/eval/scope.go | |
parent | 5468e41da2c2f71875fffc94e8914b312e689707 (diff) | |
download | golang-b423697aee32aedb8695c271528486389e39c403.tar.gz |
convert testing to World.
start on Decl, but not working yet
R=austin
DELTA=762 (201 added, 205 deleted, 356 changed)
OCL=34335
CL=34349
Diffstat (limited to 'usr/austin/eval/scope.go')
-rw-r--r-- | usr/austin/eval/scope.go | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/usr/austin/eval/scope.go b/usr/austin/eval/scope.go index 1c0acb640..3fe94e4be 100644 --- a/usr/austin/eval/scope.go +++ b/usr/austin/eval/scope.go @@ -56,6 +56,10 @@ type block struct { offset int; // The number of Variables defined in this block. numVars int; + // If global, do not allocate new vars and consts in + // the frame; assume that the refs will be compiled in + // using defs[name].Init. + global bool; } // A Scope is the compile-time analogue of a Frame, which captures @@ -112,21 +116,25 @@ func (b *block) DefineVar(name string, pos token.Position, t Type) (*Variable, D if prev, ok := b.defs[name]; ok { return nil, prev; } - v := b.DefineSlot(t); + v := b.defineSlot(t, false); v.Position = pos; b.defs[name] = v; return v, nil; } -func (b *block) DefineSlot(t Type) *Variable { +func (b *block) DefineTemp(t Type) *Variable { + return b.defineSlot(t, true) +} + +func (b *block) defineSlot(t Type, temp bool) *Variable { if b.inner != nil && b.inner.scope == b.scope { log.Crash("Failed to exit child block before defining variable"); } index := -1; - if b.offset >= 0 { + if !b.global || temp { index = b.offset+b.numVars; b.numVars++; - if index+1 > b.scope.maxVars { + if index >= b.scope.maxVars { b.scope.maxVars = index+1; } } @@ -169,18 +177,7 @@ func (b *block) Lookup(name string) (bl *block, level int, def Def) { } func (s *Scope) NewFrame(outer *Frame) *Frame { - fr := outer.child(s.maxVars); - // TODO(rsc): Take this loop out once eval_test.go - // no longer fiddles with init. - for _, v := range s.defs { - switch v := v.(type) { - case *Variable: - if v.Index >= 0 { - fr.Vars[v.Index] = v.Init; - } - } - } - return fr; + return outer.child(s.maxVars); } /* |