Skip to content

Commit

Permalink
Constructor function naming pattern (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfellis authored Feb 27, 2024
1 parent 2a2066c commit 047aca5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ test!(hello_world => r#"

test!(normal_exit_code => r#"
export fn main(): ExitCode {
return toExitCode(0);
return ExitCode(0);
}"#;
status 0;
);
test!(error_exit_code => r#"
export fn main(): ExitCode = toExitCode(1);"#;
export fn main(): ExitCode = ExitCode(1);"#;
status 1;
);
test!(non_global_memory_exit_code => r#"
export fn main(): ExitCode {
let x: i64 = 0;
return toExitCode(x);
return ExitCode(x);
}"#;
status 0;
);
Expand All @@ -151,7 +151,7 @@ test!(passing_ints_from_global_memory => r#"
test!(print_function => r#"
export fn main(): ExitCode {
print('Hello, World');
return toExitCode(0);
return ExitCode(0);
}"#;
stdout "Hello, World\n";
status 0;
Expand All @@ -169,27 +169,27 @@ test!(stdout_event => r#"
// Basic Math Tests

test!(int8_add => r#"
export fn main(): ExitCode = toExitCode(getOrExit(add(toI8(1), toI8(2))));"#;
export fn main(): ExitCode = ExitCode(getOrExit(add(toI8(1), toI8(2))));"#;
status 3;
);
test!(int8_sub => r#"
export fn main(): ExitCode = toExitCode(getOrExit(sub(toI8(2), toI8(1))));"#;
export fn main(): ExitCode = ExitCode(getOrExit(sub(toI8(2), toI8(1))));"#;
status 1;
);
test!(int8_mul => r#"
export fn main(): ExitCode = toExitCode(getOrExit(mul(toI8(2), toI8(1))));"#;
export fn main(): ExitCode = ExitCode(getOrExit(mul(toI8(2), toI8(1))));"#;
status 2;
);
test!(int8_div => r#"
export fn main(): ExitCode = toExitCode(getOrExit(div(toI8(6), toI8(2))));"#;
export fn main(): ExitCode = ExitCode(getOrExit(div(toI8(6), toI8(2))));"#;
status 3;
);
test!(int8_mod => r#"
export fn main(): ExitCode = toExitCode(getOrExit(mod(toI8(6), toI8(4))));"#;
export fn main(): ExitCode = ExitCode(getOrExit(mod(toI8(6), toI8(4))));"#;
status 2;
);
test!(int8_pow => r#"
export fn main(): ExitCode = toExitCode(getOrExit(pow(toI8(6), toI8(2))));"#;
export fn main(): ExitCode = ExitCode(getOrExit(pow(toI8(6), toI8(2))));"#;
status 36;
);
test!(int8_min => r#"
Expand Down
4 changes: 2 additions & 2 deletions src/std/root.ln
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export fn max(a: i8, b: i8): i8 binds maxi8;

// Process exit-related bindings
export type ExitCode binds std::process::ExitCode;
export fn toExitCode(e: i64): ExitCode binds to_exit_code_i64;
export fn toExitCode(e: i8): ExitCode binds to_exit_code_i8;
export fn ExitCode(e: i64): ExitCode binds to_exit_code_i64;
export fn ExitCode(e: i8): ExitCode binds to_exit_code_i8;
export fn getOrExit(a: Result<i8>): i8 binds get_or_exit; // TODO: Support real generics

// Stdout/stderr-related bindings
Expand Down

0 comments on commit 047aca5

Please sign in to comment.