initialize standard pipes in vm init to keep them rooted
This commit is contained in:
parent
45e2c0d406
commit
b98af7bdde
3 changed files with 16 additions and 10 deletions
10
src/file.c
10
src/file.c
|
|
@ -14,18 +14,12 @@ Ut userdata_file = {
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
I prim_file_stdout(Vm *vm) {
|
I prim_file_stdout(Vm *vm) {
|
||||||
static O stdout_object = NIL;
|
vm_push(vm, vm->stdout);
|
||||||
if (stdout_object == NIL)
|
|
||||||
stdout_object = userdata_make(vm, (void *)stdout, &userdata_file);
|
|
||||||
vm_push(vm, stdout_object);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
I prim_file_stderr(Vm *vm) {
|
I prim_file_stderr(Vm *vm) {
|
||||||
static O stderr_object = NIL;
|
vm_push(vm, vm->stderr);
|
||||||
if (stderr_object == NIL)
|
|
||||||
stderr_object = userdata_make(vm, (void *)stderr, &userdata_file);
|
|
||||||
vm_push(vm, stderr_object);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
13
src/vm.c
13
src/vm.c
|
|
@ -7,8 +7,9 @@
|
||||||
#include "dictionary.h"
|
#include "dictionary.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "print.h"
|
#include "primitive.h"
|
||||||
#include "src/primitive.h"
|
#include "userdata.h"
|
||||||
|
#include "file.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
|
|
||||||
|
|
@ -47,6 +48,14 @@ V vm_init(Vm *vm) {
|
||||||
gc_addroot(&vm->gc, &vm->stack[i]);
|
gc_addroot(&vm->gc, &vm->stack[i]);
|
||||||
gc_addroot(&vm->gc, &vm->tstack[i]);
|
gc_addroot(&vm->gc, &vm->tstack[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vm->stdin = userdata_make(vm, (void *)stdin, &userdata_file);
|
||||||
|
vm->stdout = userdata_make(vm, (void *)stdout, &userdata_file);
|
||||||
|
vm->stderr = userdata_make(vm, (void *)stderr, &userdata_file);
|
||||||
|
|
||||||
|
gc_addroot(&vm->gc, &vm->stdin);
|
||||||
|
gc_addroot(&vm->gc, &vm->stdout);
|
||||||
|
gc_addroot(&vm->gc, &vm->stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
V vm_deinit(Vm *vm) {
|
V vm_deinit(Vm *vm) {
|
||||||
|
|
|
||||||
3
src/vm.h
3
src/vm.h
|
|
@ -68,6 +68,9 @@ typedef struct Vm {
|
||||||
Dt *dictionary;
|
Dt *dictionary;
|
||||||
Ar arena;
|
Ar arena;
|
||||||
jmp_buf error;
|
jmp_buf error;
|
||||||
|
|
||||||
|
// These objects need to stay as roots!
|
||||||
|
O stdin, stdout, stderr;
|
||||||
} Vm;
|
} Vm;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue