Some echo()/print() fixes. (0.37.12)
This commit is contained in:
parent
87f540797b
commit
b16a42a4a7
6 changed files with 36 additions and 6 deletions
|
|
@ -1,12 +1,22 @@
|
|||
/**
|
||||
* Implements OP_ECHO: print top-of-stack value without trailing newline.
|
||||
* Does not store into VM output buffer; writes directly to stdout and flushes.
|
||||
* Now stores the value into the VM's output buffer and marks it as partial,
|
||||
* so the CLI can render echo output together with following print output.
|
||||
*/
|
||||
|
||||
case OP_ECHO: {
|
||||
Value v = pop_value(vm);
|
||||
print_value(&v);
|
||||
fflush(stdout);
|
||||
Value snap = deep_copy_value(&v);
|
||||
free_value(v);
|
||||
if (vm->output_count < OUTPUT_SIZE) {
|
||||
int idx = vm->output_count;
|
||||
vm->output[idx] = snap;
|
||||
vm->output_is_partial[idx] = 1; // ECHO does not end the line
|
||||
vm->output_count++;
|
||||
} else {
|
||||
free_value(snap);
|
||||
fprintf(stderr, "Runtime error: output buffer overflow\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,10 @@ case OP_PRINT: {
|
|||
Value snap = deep_copy_value(&v);
|
||||
free_value(v);
|
||||
if (vm->output_count < OUTPUT_SIZE) {
|
||||
vm->output[vm->output_count++] = snap;
|
||||
int idx = vm->output_count;
|
||||
vm->output[idx] = snap;
|
||||
vm->output_is_partial[idx] = 0; // PRINT terminates the line
|
||||
vm->output_count++;
|
||||
} else {
|
||||
free_value(snap);
|
||||
fprintf(stderr, "Runtime error: output buffer overflow\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue