From a4d7fb2da6a8390b818dae8d07391c7d76e365e9 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 15 Nov 2023 11:59:15 +0100 Subject: parser: hande const declarations Only symbols are produced, no bytecode is emitted. The constant expressions are evaluated at compile time using the stdlib package go/constant. The parser handles implicit repetition of the last non-empty expression list. The iota symbol is reset to 0 and incremented for each line of a const block. To be done in a next commit: type conversions. --- parser/symbol.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'parser/symbol.go') diff --git a/parser/symbol.go b/parser/symbol.go index d7c05f1..f707feb 100644 --- a/parser/symbol.go +++ b/parser/symbol.go @@ -2,6 +2,7 @@ package parser import ( "fmt" + "go/constant" "reflect" "strings" ) @@ -23,6 +24,7 @@ type symbol struct { kind symKind index int // address of symbol in frame value any + cval constant.Value Type reflect.Type local bool // if true address is relative to local frame, otherwise global used bool @@ -62,7 +64,7 @@ func initUniverse() map[string]*symbol { "string": {kind: symType, index: unsetAddr, Type: reflect.TypeOf((*string)(nil)).Elem()}, "nil": {index: unsetAddr}, - "iota": {index: unsetAddr, value: 0}, + "iota": {kind: symConst, index: unsetAddr}, "true": {index: unsetAddr, value: true, Type: reflect.TypeOf(true)}, "false": {index: unsetAddr, value: false, Type: reflect.TypeOf(false)}, -- cgit v1.2.3