/* Allocates memory */ F_COMPILED *compile_profiling_stub(F_WORD *word) { CELL literals = allot_array_1(tag_object(word)); REGISTER_ROOT(literals); F_ARRAY *quadruple = untag_object(userenv[JIT_PROFILING]); CELL code = array_nth(quadruple,0); REGISTER_ROOT(code); F_REL rel; rel.type = to_fixnum(array_nth(quadruple,2)) | (to_fixnum(array_nth(quadruple,1)) << 8); rel.offset = to_fixnum(array_nth(quadruple,3)) * compiled_code_format(); F_BYTE_ARRAY *relocation = allot_byte_array(sizeof(F_REL)); memcpy((void *)BREF(relocation,0),&rel,sizeof(F_REL)); UNREGISTER_ROOT(code); UNREGISTER_ROOT(literals); return add_compiled_block( WORD_TYPE, untag_object(code), NULL, /* no labels */ tag_object(relocation), untag_object(literals)); }
/* Allocates memory */ F_COMPILED *compile_profiling_stub(F_WORD *word) { CELL literals = allot_array_1(tag_object(word)); REGISTER_ROOT(literals); F_ARRAY *quadruple = untag_object(userenv[JIT_PROFILING]); CELL code = array_nth(quadruple,0); REGISTER_ROOT(code); CELL rel_type = allot_cell(to_fixnum(array_nth(quadruple,2)) | (to_fixnum(array_nth(quadruple,1)) << 8)); CELL rel_offset = array_nth(quadruple,3) * compiled_code_format(); CELL relocation = allot_array_2(rel_type,rel_offset); UNREGISTER_ROOT(code); UNREGISTER_ROOT(literals); return add_compiled_block( WORD_TYPE, untag_object(code), NULL, /* no labels */ untag_object(relocation), untag_object(literals)); }
/* Used to implement call( */ void factor_vm::primitive_check_datastack() { fixnum out = to_fixnum(ctx->pop()); fixnum in = to_fixnum(ctx->pop()); fixnum height = out - in; array* saved_datastack = untag_check<array>(ctx->pop()); fixnum saved_height = array_capacity(saved_datastack); fixnum current_height = (ctx->datastack - ctx->datastack_seg->start + sizeof(cell)) / sizeof(cell); if (current_height - height != saved_height) ctx->push(false_object); else { cell* ds_bot = (cell*)ctx->datastack_seg->start; for (fixnum i = 0; i < saved_height - in; i++) { if (ds_bot[i] != array_nth(saved_datastack, i)) { ctx->push(false_object); return; } } ctx->push(true_object); } }
/* Used to implement call( */ void factor_vm::primitive_check_datastack() { fixnum out = to_fixnum(dpop()); fixnum in = to_fixnum(dpop()); fixnum height = out - in; array *saved_datastack = untag_check<array>(dpop()); fixnum saved_height = array_capacity(saved_datastack); fixnum current_height = (ds - ds_bot + sizeof(cell)) / sizeof(cell); if(current_height - height != saved_height) dpush(false_object); else { fixnum i; for(i = 0; i < saved_height - in; i++) { if(((cell *)ds_bot)[i] != array_nth(saved_datastack,i)) { dpush(false_object); return; } } dpush(true_object); } }
void primitive_fputc(void) { FILE *file = unbox_alien(); F_FIXNUM ch = to_fixnum(dpop()); for(;;) { if(fputc(ch,file) == EOF) { io_error(); /* Still here? EINTR */ } else break; } }
void print_ptr_rec(ptr x) { /*printf("%u\n", x);*/ if (is_fixnum(x)) { printf("%d", to_fixnum(x)); } else if (x == bool_f) { printf("#f"); } else if (x == bool_t) { printf("#t"); } else if (is_null(x)) { print_null(); } else if (is_char(x)) { printf("%s", beautify(to_char(x))); } else if (is_pair(x)) { printf("("); print_pair(x); printf(")"); } else { printf("#<unknown 0x%08x>", x); } }
// pop ( alien n ) from datastack, return alien's address plus n void* factor_vm::alien_pointer() { fixnum offset = to_fixnum(ctx->pop()); return alien_offset(ctx->pop()) + offset; }
void factor_vm::primitive_sampling_profiler() { set_sampling_profiler(to_fixnum(ctx->pop())); }
/* pop ( alien n ) from datastack, return alien's address plus n */ INLINE void *alien_pointer(void) { F_FIXNUM offset = to_fixnum(dpop()); return unbox_alien() + offset; }
CELL to_cell(CELL tagged) { return (CELL)to_fixnum(tagged); }
void factor_vm::primitive_fseek() { FILE* file = pop_file_handle(); int whence = (int)to_fixnum(ctx->pop()); off_t offset = (off_t)to_signed_8(ctx->pop()); safe_fseek(file, offset, whence); }
void factor_vm::primitive_fputc() { FILE* file = pop_file_handle(); fixnum ch = to_fixnum(ctx->pop()); safe_fputc((int)ch, file); }
/* pop ( alien n ) from datastack, return alien's address plus n */ void *factorvm::alien_pointer() { fixnum offset = to_fixnum(dpop()); return unbox_alien() + offset; }