Skip to content

Commit

Permalink
Require ; at the end of global variable declaration for consistency
Browse files Browse the repository at this point in the history
Y-Nak committed Dec 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e28e898 commit 62cdb07
Showing 14 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
target = "evm-ethereum-cancun"

global public *i256 $PTR = 1
global public *i256 $PTR = 1;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
target = "evm-ethereum-cancun"

global public *i256 $PTR = 2
global public *i256 $PTR = 2;
4 changes: 2 additions & 2 deletions crates/codegen/tests/linker/fixtures/link_ok/module.snap
Original file line number Diff line number Diff line change
@@ -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;

4 changes: 2 additions & 2 deletions crates/codegen/tests/linker/fixtures/link_ok/module_a.sntn
Original file line number Diff line number Diff line change
@@ -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 {
4 changes: 2 additions & 2 deletions crates/codegen/tests/linker/fixtures/link_ok/module_b.sntn
Original file line number Diff line number Diff line change
@@ -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:
7 changes: 4 additions & 3 deletions crates/ir/src/global_variable.rs
Original file line number Diff line number Diff line change
@@ -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];"
);
}
}
2 changes: 1 addition & 1 deletion crates/parser/src/sonatina.pest
Original file line number Diff line number Diff line change
@@ -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" }
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions crates/parser/test_files/errors/duplicated_declaration.sntn
Original file line number Diff line number Diff line change
@@ -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:
8 changes: 4 additions & 4 deletions crates/parser/test_files/errors/global_declaration.snap
Original file line number Diff line number Diff line change
@@ -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
|
8 changes: 4 additions & 4 deletions crates/parser/test_files/errors/global_declaration.sntn
Original file line number Diff line number Diff line change
@@ -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} };
10 changes: 5 additions & 5 deletions crates/parser/test_files/syntax/module/global_variable.ir.snap
Original file line number Diff line number Diff line change
@@ -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:
20 changes: 10 additions & 10 deletions crates/parser/test_files/syntax/module/global_variable.snap
Original file line number Diff line number Diff line change
@@ -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]"
10 changes: 5 additions & 5 deletions crates/parser/test_files/syntax/module/global_variable.sntn
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 62cdb07

Please sign in to comment.