Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sargun committed Mar 16, 2017
1 parent 23dc8e6 commit 8d09c00
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/cli/gravity.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ static void gravity_repl (void) {

// MARK: -

int x = 0;
int icounter = 0;

static bool should_preempt(void *xdata) {
x++;
if (x % 3 == 0) {
static bool should_preempt(gravity_vm *vm, void *xdata) {
icounter++;
// Preempt ever 5 ins
if (icounter % 5 == 0) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/gravity_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ static bool gravity_vm_exec(gravity_vm *vm, bool preemptable) {

return true;

PREEMPT:
DO_PREEMPT:
vm->preempted = true;
vm->vm_state.delegate = delegate;
vm->vm_state.fiber = fiber;
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/gravity_vmmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@
#define FN_COUNTREG(_f,_nargs) (MAXNUM(_f->nparams,_nargs) + _f->nlocals + _f->ntemps)

#if GRAVITY_VM_PREEMPTION
#define SHOULD_PREEMPT if (preempt_cb && preempt_cb(vm->delegate->xdata)) goto PREEMPT;
#define MAYBE_PREEMPT if (preempt_cb && preempt_cb(vm, vm->delegate->xdata)) goto DO_PREEMPT;
#else
#define SHOULD_PREEMPT
#define MAYBE_PREEMPT
#endif
#if GRAVITY_COMPUTED_GOTO
#define DECLARE_DISPATCH_TABLE static void* dispatchTable[] = { \
Expand All @@ -141,9 +141,9 @@
#define INTERPRET_LOOP DISPATCH();
#define CASE_CODE(name) START_MICROBENCH(vm); name
#if GRAVITY_VM_STATS
#define DISPATCH() DEBUG_STACK();SHOULD_PREEMPT;INC_PC;inst = *ip++;op = (opcode_t)OPCODE_GET_OPCODE(inst);UPDATE_STATS(vm,op);goto *dispatchTable[op];
#define DISPATCH() DEBUG_STACK();MAYBE_PREEMPT;INC_PC;inst = *ip++;op = (opcode_t)OPCODE_GET_OPCODE(inst);UPDATE_STATS(vm,op);goto *dispatchTable[op];
#else
#define DISPATCH() DEBUG_STACK();SHOULD_PREEMPT;INC_PC;inst = *ip++;goto *dispatchTable[op = (opcode_t)OPCODE_GET_OPCODE(inst)];
#define DISPATCH() DEBUG_STACK();MAYBE_PREEMPT;INC_PC;inst = *ip++;goto *dispatchTable[op = (opcode_t)OPCODE_GET_OPCODE(inst)];
#endif
#else
#define DECLARE_DISPATCH_TABLE
Expand Down
2 changes: 1 addition & 1 deletion src/shared/gravity_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef void (*gravity_parser_callback) (void *token, void *xdata);
typedef const char* (*gravity_precode_callback) (void *xdata);
typedef const char* (*gravity_loadfile_callback) (const char *file, size_t *size, uint32_t *fileid, void *xdata);
typedef const char* (*gravity_filename_callback) (uint32_t fileid, void *xdata);
typedef bool (*gravity_preempt_callback) (void *xdata);
typedef bool (*gravity_preempt_callback) (gravity_vm *vm, void *xdata);

typedef bool (*gravity_bridge_initinstance) (gravity_vm *vm, void *xdata, gravity_instance_t *instance, gravity_value_t args[], int16_t nargs);
typedef bool (*gravity_bridge_setvalue) (gravity_vm *vm, void *xdata, gravity_value_t target, const char *key, gravity_value_t value);
Expand Down

0 comments on commit 8d09c00

Please sign in to comment.