-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.go
46 lines (37 loc) · 909 Bytes
/
context.go
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
package mruby
type CallinfoStack interface {
Cursor() int
Push(*callinfo)
Pop() *callinfo
Peek() *callinfo
}
type ContextStack interface {
Get(int) Value
Slice(int, int) []Value
Set(int, Value)
}
type context struct {
stack ContextStack
callinfo CallinfoStack
}
func (ctx *context) IsTop() bool {
return ctx.callinfo.Cursor() == 0
}
func (ctx *context) GetCallinfo() *callinfo {
return ctx.callinfo.Peek()
}
func (ctx *context) SetSequenceCursor(pc int) {
ctx.GetCallinfo().SetSequnceCursor(pc)
}
func (ctx *context) Get(idx int) Value {
offset := ctx.GetCallinfo().stackOffset
return ctx.stack.Get(offset + idx)
}
func (ctx *context) Slice(start, end int) []Value {
offset := ctx.GetCallinfo().stackOffset
return ctx.stack.Slice(offset+start, offset+start+end)
}
func (ctx *context) Set(idx int, v Value) {
offset := ctx.GetCallinfo().stackOffset
ctx.stack.Set(offset+idx, v)
}