From 9fabf86e61c3ca5c040e72d6b4ee12aceb884bc6 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 10 Dec 2025 00:31:07 +0100 Subject: [PATCH] Added echo to output data wthout a newline. (0.36.2) --- examples/echo_example.fun | 23 +++++++++++++++++++++++ src/vm/echo.c | 12 ++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 examples/echo_example.fun create mode 100644 src/vm/echo.c diff --git a/examples/echo_example.fun b/examples/echo_example.fun new file mode 100755 index 0000000..017e89c --- /dev/null +++ b/examples/echo_example.fun @@ -0,0 +1,23 @@ +#!/usr/bin/env fun + +/* + * This file is part of the Fun programming language. + * https://fun-lang.xyz/ + * + * Copyright 2025 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2025-12-10 + */ + +// echo_example.fun +// Demonstrates echo(expr) which prints without a trailing newline. + +// Build a line without newline using echo, then finish with print to add newline +echo("Hello, ") +echo("world") +print("!") + +// Expected output: +// Hello, world! diff --git a/src/vm/echo.c b/src/vm/echo.c new file mode 100644 index 0000000..626bd7d --- /dev/null +++ b/src/vm/echo.c @@ -0,0 +1,12 @@ +/** + * Implements OP_ECHO: print top-of-stack value without trailing newline. + * Does not store into VM output buffer; writes directly to stdout and flushes. + */ + +case OP_ECHO: { + Value v = pop_value(vm); + print_value(&v); + fflush(stdout); + free_value(v); + break; +}