Skip to content

Commit

Permalink
Implement stdout and stderr (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfellis authored Nov 15, 2024
1 parent b8917c9 commit bce100c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions alan/src/compile/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,26 @@ test_full!(print_compile_time_string => r#"
}"#;
stdout "FooBar\n";
);
test_full!(stdout_and_stderr => r#"
export fn main {
let hello = 'Hello';
let goodbye = 'Goodbye';
let comma = ', ';
let world = 'World';
let end = '!\n';
stdout(hello);
stdout(comma);
stdout(world);
stdout(end);
goodbye.stderr;
comma.stderr;
world.stderr;
end.stderr;
}"#;
stdout "Hello, World!\n";
stderr "Goodbye, World!\n";
);

// Basic Math Tests

Expand Down
5 changes: 5 additions & 0 deletions alan/src/std/root.ln
Original file line number Diff line number Diff line change
Expand Up @@ -4892,6 +4892,11 @@ export fn{Rs} eprint{T}(v: T!) = if({T}(v).exists,
fn = v.getOrExit.eprint,
fn = v.Error.getOrExit.eprint);

export fn{Rs} stdout "print!" :: ("{}", string);
export fn{Js} stdout "((s) => process.stdout.write(s.val))" :: string;
export fn{Rs} stderr "eprint!" :: ("{}", string);
export fn{Js} stderr "((s) => process.stderr.write(s.val))" :: string;

/// Built-in operator definitions
export infix add as + precedence 3;
export infix sub as - precedence 3;
Expand Down

0 comments on commit bce100c

Please sign in to comment.