blob: d25c20f91adf8dd6570d44d0720a301efbab470d (
plain)
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
|
package value
type TypeKind int
const (
NullType TypeKind = iota
IntType
FloatType
StringType
BoolType
ArrayType
FunctionType
TypeRefType
ObjectType
)
func (t TypeKind) String() string {
switch t {
case IntType:
return "int"
case FloatType:
return "float"
case StringType:
return "string"
case BoolType:
return "bool"
case ArrayType:
return "array"
case NullType:
return "null"
case FunctionType:
return "function"
case TypeRefType:
return "type"
case ObjectType:
return "object"
}
panic("invalid type kind")
}
type Type struct {
Kind TypeKind
Name string
Methods map[string]FunctionData
Statics map[string]Value
}
func (t *Type) GetMethod(name string) (FunctionData, bool) {
if t.Methods == nil {
return FunctionData{}, false
}
method, ok := t.Methods[name]
return method, ok
}
|