VM: new primitive free-callback which is able to free a callback

previously allocated using <callback>
db4
Björn Lindqvist 2014-09-15 18:20:22 +02:00 committed by John Benediktsson
parent a338fa08e7
commit e00798cd2a
5 changed files with 26 additions and 16 deletions

View File

@ -418,6 +418,7 @@ M: object infer-call* \ call bad-macro-input ;
\ fpu-state { } { } define-primitive \ fpu-state { } { } define-primitive
\ fputc { object alien } { } define-primitive \ fputc { object alien } { } define-primitive
\ fread-unsafe { integer c-ptr alien } { integer } define-primitive \ fread-unsafe { integer c-ptr alien } { integer } define-primitive
\ free-callback { alien } { } define-primitive
\ fseek { integer integer alien } { } define-primitive \ fseek { integer integer alien } { } define-primitive
\ ftell { alien } { integer } define-primitive \ ftell { alien } { integer } define-primitive
\ fwrite { c-ptr integer alien } { } define-primitive \ fwrite { c-ptr integer alien } { } define-primitive

View File

@ -450,6 +450,7 @@ tuple
{ "fgetc" "io.streams.c" "primitive_fgetc" ( alien -- byte/f ) } { "fgetc" "io.streams.c" "primitive_fgetc" ( alien -- byte/f ) }
{ "fputc" "io.streams.c" "primitive_fputc" ( byte alien -- ) } { "fputc" "io.streams.c" "primitive_fputc" ( byte alien -- ) }
{ "fread-unsafe" "io.streams.c" "primitive_fread" ( n buf alien -- count ) } { "fread-unsafe" "io.streams.c" "primitive_fread" ( n buf alien -- count ) }
{ "free-callback" "alien" "primitive_free_callback" ( alien -- ) }
{ "fseek" "io.streams.c" "primitive_fseek" ( alien offset whence -- ) } { "fseek" "io.streams.c" "primitive_fseek" ( alien offset whence -- ) }
{ "ftell" "io.streams.c" "primitive_ftell" ( alien -- n ) } { "ftell" "io.streams.c" "primitive_ftell" ( alien -- n ) }
{ "fwrite" "io.streams.c" "primitive_fwrite" ( data length alien -- ) } { "fwrite" "io.streams.c" "primitive_fwrite" ( data length alien -- ) }

View File

@ -136,6 +136,12 @@ void factor_vm::primitive_callback() {
ctx->push(allot_alien(func)); ctx->push(allot_alien(func));
} }
void factor_vm::primitive_free_callback() {
void* entry_point = alien_offset(ctx->pop());
code_block* stub = (code_block*)entry_point - 1;
callbacks->allocator->free(stub);
}
/* Allocates memory */ /* Allocates memory */
void factor_vm::primitive_callback_room() { void factor_vm::primitive_callback_room() {
allocator_room room = callbacks->allocator->as_allocator_room(); allocator_room room = callbacks->allocator->as_allocator_room();

View File

@ -9,9 +9,9 @@ namespace factor {
_(bignum_less) _(bignum_lesseq) _(bignum_log2) _(bignum_mod) \ _(bignum_less) _(bignum_lesseq) _(bignum_log2) _(bignum_mod) \
_(bignum_gcd) _(bignum_multiply) _(bignum_not) _(bignum_or) \ _(bignum_gcd) _(bignum_multiply) _(bignum_not) _(bignum_or) \
_(bignum_shift) _(bignum_subtract) _(bignum_to_fixnum) \ _(bignum_shift) _(bignum_subtract) _(bignum_to_fixnum) \
_(bignum_to_fixnum_strict) _(bignum_xor) \ _(bignum_to_fixnum_strict) _(bignum_xor) _(bits_double) _(bits_float) \
_(bits_double) _(bits_float) _(byte_array) _(callback) _(callback_room) \ _(byte_array) _(callback) _(callback_room) _(callstack) \
_(callstack) _(callstack_bounds) _(callstack_for) _(callstack_to_array) \ _(callstack_bounds) _(callstack_for) _(callstack_to_array) \
_(check_datastack) _(clear_samples) _(clone) _(code_blocks) _(code_room) \ _(check_datastack) _(clear_samples) _(clone) _(code_blocks) _(code_room) \
_(compact_gc) _(compute_identity_hashcode) _(context_object) \ _(compact_gc) _(compute_identity_hashcode) _(context_object) \
_(context_object_for) _(current_callback) _(data_room) _(datastack) \ _(context_object_for) _(current_callback) _(data_room) _(datastack) \
@ -23,19 +23,20 @@ namespace factor {
_(float_bits) _(float_divfloat) _(float_eq) _(float_greater) \ _(float_bits) _(float_divfloat) _(float_eq) _(float_greater) \
_(float_greatereq) _(float_less) _(float_lesseq) _(float_multiply) \ _(float_greatereq) _(float_less) _(float_lesseq) _(float_multiply) \
_(float_subtract) _(float_to_bignum) _(float_to_fixnum) _(fopen) \ _(float_subtract) _(float_to_bignum) _(float_to_fixnum) _(fopen) \
_(format_float) _(fputc) _(fread) _(fseek) _(ftell) _(full_gc) _(fwrite) \ _(format_float) _(fputc) _(fread) _(free_callback) _(fseek) _(ftell) \
_(get_samples) _(identity_hashcode) _(innermost_stack_frame_executing) \ _(full_gc) _(fwrite) _(get_samples) _(identity_hashcode) \
_(innermost_stack_frame_scan) _(jit_compile) _(load_locals) \ _(innermost_stack_frame_executing) _(innermost_stack_frame_scan) \
_(lookup_method) _(mega_cache_miss) _(minor_gc) _(modify_code_heap) \ _(jit_compile) _(load_locals) _(lookup_method) _(mega_cache_miss) \
_(nano_count) _(optimized_p) _(quot_compiled_p) _(quotation_code) \ _(minor_gc) _(modify_code_heap) _(nano_count) _(optimized_p) \
_(reset_dispatch_stats) _(resize_array) _(resize_byte_array) \ _(quot_compiled_p) _(quotation_code) _(reset_dispatch_stats) \
_(resize_string) _(retainstack) _(retainstack_for) _(sampling_profiler) \ _(resize_array) _(resize_byte_array) _(resize_string) _(retainstack) \
_(save_image) _(save_image_and_exit) _(set_context_object) \ _(retainstack_for) _(sampling_profiler) _(save_image) \
_(set_datastack) _(set_innermost_stack_frame_quot) _(set_retainstack) \ _(save_image_and_exit) _(set_context_object) _(set_datastack) \
_(set_slot) _(set_special_object) _(set_string_nth_fast) _(size) \ _(set_innermost_stack_frame_quot) _(set_retainstack) _(set_slot) \
_(sleep) _(special_object) _(string) _(strip_stack_traces) _(tuple) \ _(set_special_object) _(set_string_nth_fast) _(size) _(sleep) \
_(tuple_boa) _(unimplemented) _(uninitialized_byte_array) _(word) \ _(special_object) _(string) _(strip_stack_traces) _(tuple) _(tuple_boa) \
_(word_code) _(wrapper) _(unimplemented) _(uninitialized_byte_array) _(word) _(word_code) \
_(wrapper)
#define EACH_ALIEN_PRIMITIVE(_) \ #define EACH_ALIEN_PRIMITIVE(_) \
_(signed_cell, fixnum, from_signed_cell, to_fixnum) \ _(signed_cell, fixnum, from_signed_cell, to_fixnum) \

View File

@ -612,6 +612,7 @@ struct factor_vm {
// callbacks // callbacks
void init_callbacks(cell size); void init_callbacks(cell size);
void primitive_free_callback();
void primitive_callback(); void primitive_callback();
void primitive_callback_room(); void primitive_callback_room();