diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libgo/go/exp/eval/func.go | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libgo/go/exp/eval/func.go')
-rw-r--r-- | libgo/go/exp/eval/func.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/libgo/go/exp/eval/func.go b/libgo/go/exp/eval/func.go new file mode 100644 index 000000000..cb1b579e4 --- /dev/null +++ b/libgo/go/exp/eval/func.go @@ -0,0 +1,70 @@ +// 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 "os" + +/* + * Virtual machine + */ + +type Thread struct { + abort chan os.Error + pc uint + // The execution frame of this function. This remains the + // same throughout a function invocation. + f *Frame +} + +type code []func(*Thread) + +func (i code) exec(t *Thread) { + opc := t.pc + t.pc = 0 + l := uint(len(i)) + for t.pc < l { + pc := t.pc + t.pc++ + i[pc](t) + } + t.pc = opc +} + +/* + * Code buffer + */ + +type codeBuf struct { + instrs code +} + +func newCodeBuf() *codeBuf { return &codeBuf{make(code, 0, 16)} } + +func (b *codeBuf) push(instr func(*Thread)) { + b.instrs = append(b.instrs, instr) +} + +func (b *codeBuf) nextPC() uint { return uint(len(b.instrs)) } + +func (b *codeBuf) get() code { + // Freeze this buffer into an array of exactly the right size + a := make(code, len(b.instrs)) + copy(a, b.instrs) + return code(a) +} + +/* + * User-defined functions + */ + +type evalFunc struct { + outer *Frame + frameSize int + code code +} + +func (f *evalFunc) NewFrame() *Frame { return f.outer.child(f.frameSize) } + +func (f *evalFunc) Call(t *Thread) { f.code.exec(t) } |