-
Notifications
You must be signed in to change notification settings - Fork 1
/
mruby.go
58 lines (45 loc) · 859 Bytes
/
mruby.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
47
48
49
50
51
52
53
54
55
56
57
58
package mruby
import (
"github.com/elct9620/mruby-go/stack"
)
const (
CallinfoInitSize = 32
StackInitSize = 128
)
type (
Value = any
)
type State struct {
context *context
ObjectClass RClass
ModuleClass RClass
ClassClass RClass
FalseClass RClass
TrueClass RClass
ArrayClass RClass
KernelModule RClass
topSelf RObject
symbolTable map[string]Symbol
symbolIndex int
}
func New() (*State, error) {
state := &State{
context: &context{
callinfo: stack.New[*callinfo](CallinfoInitSize),
},
symbolTable: make(map[string]Symbol),
symbolIndex: 0,
}
err := initCore(state)
if err != nil {
return nil, err
}
return state, nil
}
func (s *State) GetArgc() int {
return s.context.GetCallinfo().numArgs
}
func (s *State) GetArgv() []Value {
ci := s.context.GetCallinfo()
return s.context.Slice(1, ci.numArgs)
}