@@ -12,24 +12,25 @@ var (
1212)
1313
1414type Function struct {
15- Name string
16- Func func (args ... interface {}) (interface {}, error )
17- Types []reflect. Type
18- Validate func ( args []reflect.Type ) (reflect. Type , error )
19- BuiltinId int
15+ Name string
16+ Func func (args ... interface {}) (interface {}, error )
17+ Opcode byte
18+ Types []reflect.Type
19+ Validate func ( args []reflect. Type ) (reflect. Type , error )
2020}
2121
2222const (
23- Len = iota + 1
23+ Opcode byte = iota + 100
24+ Len
2425 Abs
2526 Int
2627 Float
2728)
2829
29- var Builtins = [ ]* Function {
30- {
31- Name : "len" ,
32- BuiltinId : Len ,
30+ var Builtins = map [ byte ]* Function {
31+ Len : {
32+ Name : "len" ,
33+ Opcode : Len ,
3334 Validate : func (args []reflect.Type ) (reflect.Type , error ) {
3435 if len (args ) != 1 {
3536 return anyType , fmt .Errorf ("invalid number of arguments for len (expected 1, got %d)" , len (args ))
@@ -41,9 +42,9 @@ var Builtins = []*Function{
4142 return anyType , fmt .Errorf ("invalid argument for len (type %s)" , args [0 ])
4243 },
4344 },
44- {
45- Name : "abs" ,
46- BuiltinId : Abs ,
45+ Abs : {
46+ Name : "abs" ,
47+ Opcode : Abs ,
4748 Validate : func (args []reflect.Type ) (reflect.Type , error ) {
4849 if len (args ) != 1 {
4950 return anyType , fmt .Errorf ("invalid number of arguments for abs (expected 1, got %d)" , len (args ))
@@ -55,9 +56,9 @@ var Builtins = []*Function{
5556 return anyType , fmt .Errorf ("invalid argument for abs (type %s)" , args [0 ])
5657 },
5758 },
58- {
59- Name : "int" ,
60- BuiltinId : Int ,
59+ Int : {
60+ Name : "int" ,
61+ Opcode : Int ,
6162 Validate : func (args []reflect.Type ) (reflect.Type , error ) {
6263 if len (args ) != 1 {
6364 return anyType , fmt .Errorf ("invalid number of arguments for int (expected 1, got %d)" , len (args ))
@@ -73,9 +74,9 @@ var Builtins = []*Function{
7374 return anyType , fmt .Errorf ("invalid argument for int (type %s)" , args [0 ])
7475 },
7576 },
76- {
77- Name : "float" ,
78- BuiltinId : Float ,
77+ Float : {
78+ Name : "float" ,
79+ Opcode : Float ,
7980 Validate : func (args []reflect.Type ) (reflect.Type , error ) {
8081 if len (args ) != 1 {
8182 return anyType , fmt .Errorf ("invalid number of arguments for float (expected 1, got %d)" , len (args ))
0 commit comments