Fun
0.41.5
The programming language that makes you have fun!
Main Page
Data Structures
Files
File List
Globals
Loading...
Searching...
No Matches
src
vm
echo.c
Go to the documentation of this file.
1
/*
2
* This file is part of the Fun programming language.
3
* https://fun-lang.xyz/
4
*
5
* Copyright 2025 Johannes Findeisen <you@hanez.org>
6
* Licensed under the terms of the Apache-2.0 license.
7
* https://opensource.org/license/apache-2-0
8
*/
9
10
/**
11
* @file echo.c
12
* @brief Implements the OP_ECHO opcode for printing without a trailing newline.
13
*
14
* This snippet is included into the VM dispatch loop and handles OP_ECHO.
15
* It pops the top value from the stack and appends it to the VM's output buffer
16
* but marks the entry as partial so that subsequent OP_PRINT may continue the
17
* same line.
18
*
19
* Stack contract:
20
* - Pops: value (any)
21
* - Pushes: (none)
22
*/
23
24
case
OP_ECHO
: {
25
Value
v
=
pop_value
(vm);
26
Value
snap
=
deep_copy_value
(&
v
);
27
free_value
(
v
);
28
if
(vm->output_count <
OUTPUT_SIZE
) {
29
int
idx
= vm->output_count;
30
vm->output[
idx
] =
snap
;
31
vm->output_is_partial[
idx
] = 1;
// ECHO does not end the line
32
vm->output_count++;
33
}
else
{
34
free_value
(
snap
);
35
fprintf
(stderr,
"Runtime error: output buffer overflow\n"
);
36
exit
(1);
37
}
38
break
;
39
}
OP_ECHO
@ OP_ECHO
Definition
bytecode.h:64
v
Value v
Definition
cast.c:22
snap
Value snap
Definition
echo.c:26
free_value
free_value(v)
idx
int idx
Definition
index_of.c:38
Value
Tagged union representing a Fun value.
Definition
value.h:68
deep_copy_value
Value deep_copy_value(const Value *v)
Deep copy a Value, recursively copying arrays and maps.
Definition
value.c:463
pop_value
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition
vm.c:580
fprintf
#define fprintf
Definition
vm.c:200
exit
#define exit(code)
Definition
vm.c:230
OUTPUT_SIZE
#define OUTPUT_SIZE
Definition
vm.h:38
Generated on
for Fun by
1.16.1