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/interpreter_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'parser/interpreter_test.go') diff --git a/parser/interpreter_test.go b/parser/interpreter_test.go index 3a5598e..7ac1212 100644 --- a/parser/interpreter_test.go +++ b/parser/interpreter_test.go @@ -164,6 +164,21 @@ func TestSwitch(t *testing.T) { }) } +func TestConst(t *testing.T) { + src0 := `const ( + a = iota + b + c +) +` + run(t, []etest{ + {src: "const a = 1+2; a", res: "3"}, + {src: "const a, b = 1, 2; a+b", res: "3"}, + + {src: src0 + "c", res: "2"}, + }) +} + func TestType(t *testing.T) { run(t, []etest{ {src: "type t int; var a t = 1; a", res: "1"}, -- cgit v1.2.3