From 74d5135b8cac808e90a8b858c27e1bc8d3f0ddd1 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 14 Nov 2024 18:12:49 -0600 Subject: [PATCH] Implement `stdout` and `stderr` --- alan/src/compile/integration_tests.rs | 20 ++++++++++++++++++++ alan/src/std/root.ln | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/alan/src/compile/integration_tests.rs b/alan/src/compile/integration_tests.rs index 5d190e82..71e2fda3 100644 --- a/alan/src/compile/integration_tests.rs +++ b/alan/src/compile/integration_tests.rs @@ -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 diff --git a/alan/src/std/root.ln b/alan/src/std/root.ln index 5af7833a..df6c7fa8 100644 --- a/alan/src/std/root.ln +++ b/alan/src/std/root.ln @@ -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;