diff --git a/crates/codegen/tests/linker/fixtures/link_errors/gv_error_a.sntn b/crates/codegen/tests/linker/fixtures/link_errors/gv_error_a.sntn index e9f2af6a..d524f05f 100644 --- a/crates/codegen/tests/linker/fixtures/link_errors/gv_error_a.sntn +++ b/crates/codegen/tests/linker/fixtures/link_errors/gv_error_a.sntn @@ -1,3 +1,3 @@ target = "evm-ethereum-cancun" -global public *i256 $PTR = 1 +global public *i256 $PTR = 1; diff --git a/crates/codegen/tests/linker/fixtures/link_errors/gv_error_b.sntn b/crates/codegen/tests/linker/fixtures/link_errors/gv_error_b.sntn index be0504a7..8a19ca0a 100644 --- a/crates/codegen/tests/linker/fixtures/link_errors/gv_error_b.sntn +++ b/crates/codegen/tests/linker/fixtures/link_errors/gv_error_b.sntn @@ -1,3 +1,3 @@ target = "evm-ethereum-cancun" -global public *i256 $PTR = 2 +global public *i256 $PTR = 2; diff --git a/crates/codegen/tests/linker/fixtures/link_ok/module.snap b/crates/codegen/tests/linker/fixtures/link_ok/module.snap index 3313ca1e..8aaa8e6d 100644 --- a/crates/codegen/tests/linker/fixtures/link_ok/module.snap +++ b/crates/codegen/tests/linker/fixtures/link_ok/module.snap @@ -7,8 +7,8 @@ target = evm-ethereum-cancun type @foo = {i8, i16, *i64}; type @bar = {i8, [i8; 31]}; -global public const i256 $ZERO = 0 -global external const i256 $ONE +global public const i256 $ZERO = 0; +global external const i256 $ONE; declare func external %f_outer(i8) -> i8; diff --git a/crates/codegen/tests/linker/fixtures/link_ok/module_a.sntn b/crates/codegen/tests/linker/fixtures/link_ok/module_a.sntn index 1100a702..4c3ec75d 100644 --- a/crates/codegen/tests/linker/fixtures/link_ok/module_a.sntn +++ b/crates/codegen/tests/linker/fixtures/link_ok/module_a.sntn @@ -7,8 +7,8 @@ declare external %f_b(i8, i8) -> i8; declare external %f_outer(i8) -> i8; -global public const i256 $ZERO = 0 -global external const i256 $ONE +global public const i256 $ZERO = 0; +global external const i256 $ONE; func public %f_a(v0.i8) -> i8 { diff --git a/crates/codegen/tests/linker/fixtures/link_ok/module_b.sntn b/crates/codegen/tests/linker/fixtures/link_ok/module_b.sntn index 14eb796d..d0e4d886 100644 --- a/crates/codegen/tests/linker/fixtures/link_ok/module_b.sntn +++ b/crates/codegen/tests/linker/fixtures/link_ok/module_b.sntn @@ -7,8 +7,8 @@ type @bar = <{ i8, [i8; 31] }>; declare external %f_a(i8) -> i8; declare external %f_outer(i8) -> i8; -global external const i256 $ZERO -global external const i256 $ONE +global external const i256 $ZERO; +global external const i256 $ONE; func public %f_b(v0.i8, v1.i8) -> i8 { block0: diff --git a/crates/ir/src/global_variable.rs b/crates/ir/src/global_variable.rs index e213dd9a..388a70b5 100644 --- a/crates/ir/src/global_variable.rs +++ b/crates/ir/src/global_variable.rs @@ -156,7 +156,8 @@ where write!(w, " = ")?; initializer.write(w, ctx)?; } - Ok(()) + + write!(w, ";") } } @@ -235,7 +236,7 @@ mod test { )) }); - assert_eq!(gv.dump_string(&ctx), "global public const i32 $foo = 1618"); + assert_eq!(gv.dump_string(&ctx), "global public const i32 $foo = 1618;"); } #[test] @@ -259,7 +260,7 @@ mod test { assert_eq!( gv.dump_string(&ctx), - "global private const [i32; 3] $foo = [8, 4, 2]" + "global private const [i32; 3] $foo = [8, 4, 2];" ); } } diff --git a/crates/parser/src/sonatina.pest b/crates/parser/src/sonatina.pest index 2574d91a..ef40acbe 100644 --- a/crates/parser/src/sonatina.pest +++ b/crates/parser/src/sonatina.pest @@ -33,7 +33,7 @@ function_body = _{ "{" ~ (NEWLINE+ ~ block?)* ~ "}" } block = { block_ident ~ ":" ~ (NEWLINE+ ~ stmt)* } _stmts = _{ (stmt ~ NEWLINE+)* } -gv_declaration = { "global" ~ linkage ~ gv_const? ~ type_name ~ gv_identifier ~ ("=" ~ gv_initializer)? } +gv_declaration = { "global" ~ linkage ~ gv_const? ~ type_name ~ gv_identifier ~ ("=" ~ gv_initializer)? ~ ";" } gv_identifier = ${ "$" ~ gv_name } gv_name = @{ ident_start_char ~ ident_body_char* } gv_const = { "const" } diff --git a/crates/parser/test_files/errors/duplicated_declaration.snap b/crates/parser/test_files/errors/duplicated_declaration.snap index c7071809..3305c9fe 100644 --- a/crates/parser/test_files/errors/duplicated_declaration.snap +++ b/crates/parser/test_files/errors/duplicated_declaration.snap @@ -5,7 +5,7 @@ input_file: test_files/errors/duplicated_declaration.sntn error: parse error --> duplicated_declaration.sntn:3:27 | -3 | global public const *i256 $ZERO = 0 +3 | global public const *i256 $ZERO = 0; | ^^^^^ ZERO is already declared |error: parse error --> duplicated_declaration.sntn:10:14 diff --git a/crates/parser/test_files/errors/duplicated_declaration.sntn b/crates/parser/test_files/errors/duplicated_declaration.sntn index 07ce1ccf..3edc7adc 100644 --- a/crates/parser/test_files/errors/duplicated_declaration.sntn +++ b/crates/parser/test_files/errors/duplicated_declaration.sntn @@ -1,7 +1,7 @@ target = "evm-ethereum-cancun" -global private const i256 $ZERO = 0 -global public const *i256 $ZERO = 0 +global private const i256 $ZERO = 0; +global public const *i256 $ZERO = 0; func private %foo(v0.i32) { block0: diff --git a/crates/parser/test_files/errors/global_declaration.snap b/crates/parser/test_files/errors/global_declaration.snap index e3ea1599..05602ada 100644 --- a/crates/parser/test_files/errors/global_declaration.snap +++ b/crates/parser/test_files/errors/global_declaration.snap @@ -5,21 +5,21 @@ input_file: test_files/errors/global_declaration.sntn error: parse error --> global_declaration.sntn:5:28 | -5 | global private i256 $IMM = [0] +5 | global private i256 $IMM = [0]; | ^^^ type error: expected `i256` here |error: parse error --> global_declaration.sntn:6:38 | -6 | global public const [i8; 1] $ARRAY = [1, 2] +6 | global public const [i8; 1] $ARRAY = [1, 2]; | ^^^^^^ type error: expected `i8` here |error: parse error --> global_declaration.sntn:7:33 | -7 | global public const @foo $FOO = { 1, 2 } +7 | global public const @foo $FOO = { 1, 2 }; | ^^^^^^^^ type error: expected `@foo` here |error: parse error --> global_declaration.sntn:8:38 | -8 | global public const @bar $BAR = { 1, {1, 2} } +8 | global public const @bar $BAR = { 1, {1, 2} }; | ^^^^^^ type error: expected `@foo` here | diff --git a/crates/parser/test_files/errors/global_declaration.sntn b/crates/parser/test_files/errors/global_declaration.sntn index 59ac4630..220f3d3d 100644 --- a/crates/parser/test_files/errors/global_declaration.sntn +++ b/crates/parser/test_files/errors/global_declaration.sntn @@ -3,7 +3,7 @@ target = "evm-ethereum-cancun" type @foo = { i8, i16, *i64 }; type @bar = { i16, @foo }; -global private i256 $IMM = [0] -global public const [i8; 1] $ARRAY = [1, 2] -global public const @foo $FOO = { 1, 2 } -global public const @bar $BAR = { 1, {1, 2} } +global private i256 $IMM = [0]; +global public const [i8; 1] $ARRAY = [1, 2]; +global public const @foo $FOO = { 1, 2 }; +global public const @bar $BAR = { 1, {1, 2} }; diff --git a/crates/parser/test_files/syntax/module/global_variable.ir.snap b/crates/parser/test_files/syntax/module/global_variable.ir.snap index 73a60f32..b5750b16 100644 --- a/crates/parser/test_files/syntax/module/global_variable.ir.snap +++ b/crates/parser/test_files/syntax/module/global_variable.ir.snap @@ -6,11 +6,11 @@ target = evm-ethereum-cancun type @foo = {i8, i16, *i64}; -global private const i256 $ZERO = 0 -global public *i256 $PTR = 1 -global private [i8; 4] $ARRAY = [0, 1, 2, 3] -global private @foo $FOO = {1, 2, 3} -global private [@foo; 2] $FOO_ARRAY = [{1, 2, 3}, {3, 4, 5}] +global private const i256 $ZERO = 0; +global public *i256 $PTR = 1; +global private [i8; 4] $ARRAY = [0, 1, 2, 3]; +global private @foo $FOO = {1, 2, 3}; +global private [@foo; 2] $FOO_ARRAY = [{1, 2, 3}, {3, 4, 5}]; func public %main() { block0: diff --git a/crates/parser/test_files/syntax/module/global_variable.snap b/crates/parser/test_files/syntax/module/global_variable.snap index 507a6920..1c47e599 100644 --- a/crates/parser/test_files/syntax/module/global_variable.snap +++ b/crates/parser/test_files/syntax/module/global_variable.snap @@ -6,11 +6,11 @@ module "target = "evm-ethereum-cancun" type @foo = { i8, i16, *i64 }; -global private const i256 $ZERO = 0 -global public *i256 $PTR = 1 -global private [i8; 4] $ARRAY = [0, 1, 2, 3] -global private @foo $FOO = {1, 2, 3} -global private [@foo; 2] $FOO_ARRAY = [{1, 2, 3}, {3, 4, 5}] +global private const i256 $ZERO = 0; +global public *i256 $PTR = 1; +global private [i8; 4] $ARRAY = [0, 1, 2, 3]; +global private @foo $FOO = {1, 2, 3}; +global private [@foo; 2] $FOO_ARRAY = [{1, 2, 3}, {3, 4, 5}]; func public %main() -> unit { block0: @@ -31,7 +31,7 @@ func public %main() -> unit { ptr_type "*i64" type_name "i64" primitive_type "i64" - gv_declaration "global private const i256 $ZERO = 0" + gv_declaration "global private const i256 $ZERO = 0;" linkage "private" gv_const "const" type_name "i256" @@ -41,7 +41,7 @@ func public %main() -> unit { gv_initializer "0" gv_value_imm "0" decimal "0" - gv_declaration "global public *i256 $PTR = 1" + gv_declaration "global public *i256 $PTR = 1;" linkage "public" type_name "*i256" ptr_type "*i256" @@ -52,7 +52,7 @@ func public %main() -> unit { gv_initializer "1" gv_value_imm "1" decimal "1" - gv_declaration "global private [i8; 4] $ARRAY = [0, 1, 2, 3]" + gv_declaration "global private [i8; 4] $ARRAY = [0, 1, 2, 3];" linkage "private" type_name "[i8; 4]" array_type "[i8; 4]" @@ -75,7 +75,7 @@ func public %main() -> unit { gv_initializer "3" gv_value_imm "3" decimal "3" - gv_declaration "global private @foo $FOO = {1, 2, 3}" + gv_declaration "global private @foo $FOO = {1, 2, 3};" linkage "private" type_name "@foo" struct_identifier "@foo" @@ -93,7 +93,7 @@ func public %main() -> unit { gv_initializer "3" gv_value_imm "3" decimal "3" - gv_declaration "global private [@foo; 2] $FOO_ARRAY = [{1, 2, 3}, {3, 4, 5}]" + gv_declaration "global private [@foo; 2] $FOO_ARRAY = [{1, 2, 3}, {3, 4, 5}];" linkage "private" type_name "[@foo; 2]" array_type "[@foo; 2]" diff --git a/crates/parser/test_files/syntax/module/global_variable.sntn b/crates/parser/test_files/syntax/module/global_variable.sntn index 12d36a1e..2aedf331 100644 --- a/crates/parser/test_files/syntax/module/global_variable.sntn +++ b/crates/parser/test_files/syntax/module/global_variable.sntn @@ -2,11 +2,11 @@ target = "evm-ethereum-cancun" type @foo = { i8, i16, *i64 }; -global private const i256 $ZERO = 0 -global public *i256 $PTR = 1 -global private [i8; 4] $ARRAY = [0, 1, 2, 3] -global private @foo $FOO = {1, 2, 3} -global private [@foo; 2] $FOO_ARRAY = [{1, 2, 3}, {3, 4, 5}] +global private const i256 $ZERO = 0; +global public *i256 $PTR = 1; +global private [i8; 4] $ARRAY = [0, 1, 2, 3]; +global private @foo $FOO = {1, 2, 3}; +global private [@foo; 2] $FOO_ARRAY = [{1, 2, 3}, {3, 4, 5}]; func public %main() -> unit { block0: