diff options
Diffstat (limited to 'parser/symbol.go')
| -rw-r--r-- | parser/symbol.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/parser/symbol.go b/parser/symbol.go index d32bb59..d7c05f1 100644 --- a/parser/symbol.go +++ b/parser/symbol.go @@ -17,6 +17,8 @@ const ( symFunc // a Go function, located in the VM code ) +const unsetAddr = -65535 + type symbol struct { kind symKind index int // address of symbol in frame @@ -29,6 +31,7 @@ type symbol struct { func (p *Parser) AddSym(i int, name string, v any) { p.addSym(i, name, v, symValue, nil, false) } func (p *Parser) addSym(i int, name string, v any, k symKind, t reflect.Type, local bool) { + name = strings.TrimPrefix(name, "/") p.symbols[name] = &symbol{kind: k, index: i, local: local, value: v, Type: t, used: true} } @@ -52,17 +55,17 @@ func (p *Parser) getSym(name, scope string) (sym *symbol, sc string, ok bool) { func initUniverse() map[string]*symbol { return map[string]*symbol{ - "any": {kind: symType, index: -1, Type: reflect.TypeOf((*any)(nil)).Elem()}, - "bool": {kind: symType, index: -1, Type: reflect.TypeOf((*bool)(nil)).Elem()}, - "error": {kind: symType, index: -1, Type: reflect.TypeOf((*error)(nil)).Elem()}, - "int": {kind: symType, index: -1, Type: reflect.TypeOf((*int)(nil)).Elem()}, - "string": {kind: symType, index: -1, Type: reflect.TypeOf((*string)(nil)).Elem()}, + "any": {kind: symType, index: unsetAddr, Type: reflect.TypeOf((*any)(nil)).Elem()}, + "bool": {kind: symType, index: unsetAddr, Type: reflect.TypeOf((*bool)(nil)).Elem()}, + "error": {kind: symType, index: unsetAddr, Type: reflect.TypeOf((*error)(nil)).Elem()}, + "int": {kind: symType, index: unsetAddr, Type: reflect.TypeOf((*int)(nil)).Elem()}, + "string": {kind: symType, index: unsetAddr, Type: reflect.TypeOf((*string)(nil)).Elem()}, - "nil": {index: -1}, - "iota": {index: -1, value: 0}, - "true": {index: -1, value: true, Type: reflect.TypeOf(true)}, - "false": {index: -1, value: false, Type: reflect.TypeOf(false)}, + "nil": {index: unsetAddr}, + "iota": {index: unsetAddr, value: 0}, + "true": {index: unsetAddr, value: true, Type: reflect.TypeOf(true)}, + "false": {index: unsetAddr, value: false, Type: reflect.TypeOf(false)}, - "println": {index: -1, value: func(v ...any) { fmt.Println(v...) }}, + "println": {index: unsetAddr, value: func(v ...any) { fmt.Println(v...) }}, } } |
