void factor_vm::primitive_fopen() { data_root<byte_array> mode(ctx->pop(), this); data_root<byte_array> path(ctx->pop(), this); check_tagged(mode); check_tagged(path); FILE* file; file = safe_fopen((char*)(path.untagged() + 1), (char*)(mode.untagged() + 1)); ctx->push(allot_alien((cell)file)); }
// word-code ( word -- start end ) // Allocates memory (from_unsigned_cell allocates) void factor_vm::primitive_word_code() { data_root<word> w(ctx->pop(), this); check_tagged(w); ctx->push(from_unsigned_cell(w->entry_point)); ctx->push(from_unsigned_cell((cell)w->code() + w->code()->size())); }
// open a native library and push a handle // Allocates memory void factor_vm::primitive_dlopen() { data_root<byte_array> path(ctx->pop(), this); check_tagged(path); data_root<dll> library(allot<dll>(sizeof(dll)), this); library->path = path.value(); ffi_dlopen(library.untagged()); ctx->push(library.value()); }
// look up a symbol in a native library // Allocates memory void factor_vm::primitive_dlsym_raw() { data_root<object> library(ctx->pop(), this); data_root<byte_array> name(ctx->peek(), this); check_tagged(name); symbol_char* sym = name->data<symbol_char>(); if (to_boolean(library.value())) { dll* d = untag_check<dll>(library.value()); if (d->handle == NULL) ctx->replace(false_object); else ctx->replace(allot_alien(ffi_dlsym_raw(d, sym))); } else ctx->replace(allot_alien(ffi_dlsym_raw(NULL, sym))); }
// Allocates memory void factor_vm::primitive_resize_array() { data_root<array> a(ctx->pop(), this); check_tagged(a); cell capacity = unbox_array_size(); ctx->push(tag<array>(reallot_array(a.untagged(), capacity))); }