diff --git a/core/stl.c b/core/stl.c index 81e91d88..6fca43e0 100644 --- a/core/stl.c +++ b/core/stl.c @@ -145,6 +145,12 @@ int gst_stl_length(Gst *vm) { } } +/* Get hash of a value */ +int gst_stl_hash(Gst *vm) { + GstInteger h = gst_hash(gst_arg(vm, 0)); + gst_c_return(vm, gst_wrap_integer(h)); +} + /* Convert to integer */ int gst_stl_to_int(Gst *vm) { GstValue x = gst_arg(vm, 0); @@ -569,6 +575,7 @@ static const GstModuleItem const std_module[] = { {">=", gst_stl_greaterthaneq}, {"not", gst_stl_not}, {"length", gst_stl_length}, + {"hash", gst_stl_hash}, {"to-integer", gst_stl_to_int}, {"to-real", gst_stl_to_real}, {"type", gst_stl_type}, diff --git a/core/vm.c b/core/vm.c index 9cea56f0..1432c4f8 100644 --- a/core/vm.c +++ b/core/vm.c @@ -417,9 +417,9 @@ int gst_run(Gst *vm, GstValue callee) { } /* Get an argument from the stack */ -GstValue gst_arg(Gst *vm, uint16_t index) { +GstValue gst_arg(Gst *vm, uint32_t index) { GstValue *stack = gst_thread_stack(vm->thread); - uint16_t frameSize = gst_frame_size(stack); + uint32_t frameSize = gst_frame_size(stack); if (frameSize <= index) { GstValue ret; ret.type = GST_NIL; @@ -429,15 +429,15 @@ GstValue gst_arg(Gst *vm, uint16_t index) { } /* Put a value on the stack */ -void gst_set_arg(Gst* vm, uint16_t index, GstValue x) { +void gst_set_arg(Gst* vm, uint32_t index, GstValue x) { GstValue *stack = gst_thread_stack(vm->thread); - uint16_t frameSize = gst_frame_size(stack); + uint32_t frameSize = gst_frame_size(stack); if (frameSize <= index) return; stack[index] = x; } /* Get the size of the VMStack */ -uint16_t gst_count_args(Gst *vm) { +uint32_t gst_count_args(Gst *vm) { GstValue *stack = gst_thread_stack(vm->thread); return gst_frame_size(stack); } diff --git a/include/gst/gst.h b/include/gst/gst.h index 6bc68ed9..f4e12610 100644 --- a/include/gst/gst.h +++ b/include/gst/gst.h @@ -79,16 +79,16 @@ /* Stack frame manipulation */ /* Size of stack frame in number of values */ -#define GST_FRAME_SIZE 4 +#define GST_FRAME_SIZE 5 /* Macros for referencing a stack frame given a stack */ #define gst_frame_callee(s) (*(s - 1)) -#define gst_frame_size(s) ((s - 2)->data.words[0]) -#define gst_frame_prevsize(s) ((s - 2)->data.words[1]) -#define gst_frame_args(s) ((s - 2)->data.words[2]) -#define gst_frame_ret(s) ((s - 2)->data.words[3]) -#define gst_frame_pc(s) ((s - 3)->data.u16p) -#define gst_frame_env(s) ((s - 4)->data.env) +#define gst_frame_size(s) ((s - 2)->data.dwords[0]) +#define gst_frame_prevsize(s) ((s - 2)->data.dwords[1]) +#define gst_frame_args(s) ((s - 3)->data.dwords[0]) +#define gst_frame_ret(s) ((s - 3)->data.dwords[1]) +#define gst_frame_pc(s) ((s - 4)->data.u16p) +#define gst_frame_env(s) ((s - 5)->data.env) /* C function helpers */ @@ -492,9 +492,9 @@ void gst_init(Gst *vm); void gst_deinit(Gst *vm); int gst_run(Gst *vm, GstValue func); int gst_continue(Gst *vm); -GstValue gst_arg(Gst *vm, uint16_t index); -void gst_set_arg(Gst *vm, uint16_t index, GstValue x); -uint16_t gst_count_args(Gst *vm); +GstValue gst_arg(Gst *vm, uint32_t index); +void gst_set_arg(Gst *vm, uint32_t index, GstValue x); +uint32_t gst_count_args(Gst *vm); /****/ /* C Api */