|
|
@ -821,6 +821,7 @@ void ink_compile(struct context *pContext, const char* buffer) { |
|
|
|
frame.executing.type = INK_FUNCTION; |
|
|
|
frame.index = 0; |
|
|
|
err = ink_push_fn(pContext, frame); |
|
|
|
pContext->routines[pContext->routine_current].top = 0; |
|
|
|
if (err < 0) { |
|
|
|
pContext->panic = 1; |
|
|
|
return; |
|
|
@ -1523,12 +1524,39 @@ static void run_gc(struct context* ctx) { |
|
|
|
} |
|
|
|
|
|
|
|
static void clear_stack(struct context* ctx) { |
|
|
|
struct ink_routine* currentRoutine; |
|
|
|
currentRoutine = ctx->routines + ctx->routine_current; |
|
|
|
while (currentRoutine->top >= 1) { |
|
|
|
ink_pop(ctx); |
|
|
|
} |
|
|
|
return; |
|
|
|
struct ink_routine* currentRoutine; |
|
|
|
currentRoutine = ctx->routines + ctx->routine_current; |
|
|
|
while (currentRoutine->top >= 1) { |
|
|
|
ink_pop(ctx); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
static void dump_stack(struct context* ctx) { |
|
|
|
struct ink_routine* currentRoutine; |
|
|
|
int index; |
|
|
|
char* idx; |
|
|
|
char* type; |
|
|
|
char* value; |
|
|
|
char* it; |
|
|
|
currentRoutine = ctx->routines + ctx->routine_current; |
|
|
|
index = currentRoutine->top; |
|
|
|
while (index) { |
|
|
|
--index; |
|
|
|
idx = ink_itoa(ctx,index); |
|
|
|
type = ink_itoa(ctx, currentRoutine->stack[index].type); |
|
|
|
value = ink_itoa(ctx,currentRoutine->stack[index].value); |
|
|
|
for(it = idx; *it; ++it) ctx->putchar(*it); |
|
|
|
ctx->putchar(' ');ctx->putchar('|');ctx->putchar(' '); |
|
|
|
for(it = type; *it; ++it) ctx->putchar(*it); |
|
|
|
ctx->putchar(' ');ctx->putchar('|');ctx->putchar(' '); |
|
|
|
for(it = value; *it; ++it) ctx->putchar(*it); |
|
|
|
ctx->putchar('\n'); |
|
|
|
ctx->free(value); |
|
|
|
ctx->free(type); |
|
|
|
ctx->free(idx); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
static void collect_noop(struct context* _1, void* _2) {} |
|
|
@ -1885,6 +1913,7 @@ int ink_std_library(struct context* ctx) { |
|
|
|
v += ink_add_native(ctx, "dup", dupe_elem); |
|
|
|
v += ink_add_native(ctx, "drop", drop_elem); |
|
|
|
v += ink_add_native(ctx, "stack.clear", clear_stack); |
|
|
|
v += ink_add_native(ctx, "stack.dump", dump_stack); |
|
|
|
v += ink_add_native(ctx, "pluck", pluck_elem); |
|
|
|
v += ink_add_native(ctx, "return_if", return_if); |
|
|
|
v += ink_add_native(ctx, "jump_if", jump_if); |
|
|
|