|
@ -461,9 +461,16 @@ static int ink_lex(struct context *pContext, char* buffer) { |
|
|
int end; |
|
|
int end; |
|
|
int err; |
|
|
int err; |
|
|
end = 0; |
|
|
end = 0; |
|
|
|
|
|
|
|
|
|
|
|
restart_after_comment: |
|
|
while(*buffer != 0) { |
|
|
while(*buffer != 0) { |
|
|
if(isspace(*buffer)) { |
|
|
if(isspace(*buffer)) { |
|
|
|
|
|
if(end == 1 && r[0] == '#') { |
|
|
|
|
|
while(*buffer != '\n' && *buffer != 0) { |
|
|
|
|
|
++buffer; |
|
|
|
|
|
} |
|
|
|
|
|
end = 0; |
|
|
|
|
|
goto restart_after_comment; |
|
|
|
|
|
} |
|
|
err = ink_consume_one(&end, pContext, &buffer, r); |
|
|
err = ink_consume_one(&end, pContext, &buffer, r); |
|
|
if(err < 0) { |
|
|
if(err < 0) { |
|
|
pContext->panic = 1; |
|
|
pContext->panic = 1; |
|
@ -1084,7 +1091,7 @@ static void print_stacktrace(struct context* _) { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
case INK_FUNCTION:{ |
|
|
case INK_FUNCTION:{ |
|
|
n = _->native_words[thing.value].name; |
|
|
|
|
|
|
|
|
n = _->words[thing.value].name; |
|
|
while (*n) { |
|
|
while (*n) { |
|
|
_->putchar(*n); |
|
|
_->putchar(*n); |
|
|
++n; |
|
|
++n; |
|
@ -1095,7 +1102,6 @@ static void print_stacktrace(struct context* _) { |
|
|
_->putchar(*n); |
|
|
_->putchar(*n); |
|
|
++n; |
|
|
++n; |
|
|
} |
|
|
} |
|
|
_->free(n); |
|
|
|
|
|
_->putchar(10); |
|
|
_->putchar(10); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
@ -1197,7 +1203,7 @@ static void is_equal(struct context* ctx) { |
|
|
ink_pop(ctx); |
|
|
ink_pop(ctx); |
|
|
ret.type = INK_INTEGER; |
|
|
ret.type = INK_INTEGER; |
|
|
ret.value = a.value == b.value && a.type == b.type; |
|
|
ret.value = a.value == b.value && a.type == b.type; |
|
|
|
|
|
|
|
|
|
|
|
ink_push(ctx, ret); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void is_different(struct context* ctx) { |
|
|
static void is_different(struct context* ctx) { |
|
@ -1216,7 +1222,7 @@ static void is_different(struct context* ctx) { |
|
|
ink_pop(ctx); |
|
|
ink_pop(ctx); |
|
|
ret.type = INK_INTEGER; |
|
|
ret.type = INK_INTEGER; |
|
|
ret.value = !(a.value == b.value && a.type == b.type); |
|
|
ret.value = !(a.value == b.value && a.type == b.type); |
|
|
|
|
|
|
|
|
|
|
|
ink_push(ctx, ret); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#ifndef NOEXTRAARITHMETIC |
|
|
#ifndef NOEXTRAARITHMETIC |
|
@ -1404,24 +1410,26 @@ static void return_if(struct context* ctx) { |
|
|
|
|
|
|
|
|
static void jump_if(struct context* ctx) { |
|
|
static void jump_if(struct context* ctx) { |
|
|
struct ink_routine* currentRoutine; |
|
|
struct ink_routine* currentRoutine; |
|
|
struct elem a; |
|
|
|
|
|
|
|
|
struct elem label; |
|
|
|
|
|
struct elem condition; |
|
|
currentRoutine = ctx->routines + ctx->routine_current; |
|
|
currentRoutine = ctx->routines + ctx->routine_current; |
|
|
if(currentRoutine->top < 1) { |
|
|
|
|
|
|
|
|
if(currentRoutine->top < 2) { |
|
|
ctx->panic = -1; |
|
|
ctx->panic = -1; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
a = currentRoutine->stack[currentRoutine->top-1]; |
|
|
|
|
|
if(a.type != INK_INTEGER) { |
|
|
|
|
|
|
|
|
label = currentRoutine->stack[currentRoutine->top-1]; |
|
|
|
|
|
condition = currentRoutine->stack[currentRoutine->top-2]; |
|
|
|
|
|
if(label.type != INK_INTEGER || condition.type != INK_INTEGER) { |
|
|
ctx->panic = -1; |
|
|
ctx->panic = -1; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
ink_pop(ctx); |
|
|
ink_pop(ctx); |
|
|
if(a.value) { |
|
|
|
|
|
ink_pop_fn(ctx); |
|
|
|
|
|
a = currentRoutine->stack[currentRoutine->top-1]; |
|
|
|
|
|
currentRoutine->function_stack[currentRoutine->function_stack_top - 1].index += a.value - 3; |
|
|
|
|
|
} |
|
|
|
|
|
ink_pop(ctx); |
|
|
ink_pop(ctx); |
|
|
|
|
|
ink_pop_fn(ctx); |
|
|
|
|
|
if(condition.value) { |
|
|
|
|
|
currentRoutine->function_stack[currentRoutine->function_stack_top - 1].index += label.value - 2; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1681,6 +1689,42 @@ static void index_array(struct context* ctx) { |
|
|
ink_push(ctx, ary->elements[idx.value]); |
|
|
ink_push(ctx, ary->elements[idx.value]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void set_array(struct context* ctx) { |
|
|
|
|
|
int tid; |
|
|
|
|
|
struct ink_routine *currentRoutine; |
|
|
|
|
|
struct elem a; |
|
|
|
|
|
struct ink_array *ary; |
|
|
|
|
|
struct elem idx; |
|
|
|
|
|
struct elem value; |
|
|
|
|
|
|
|
|
|
|
|
tid = get_type_by_name(ctx, "array"); |
|
|
|
|
|
currentRoutine = ctx->routines + ctx->routine_current; |
|
|
|
|
|
if (currentRoutine->top < 3 || currentRoutine->stack[currentRoutine->top - 1].type != tid || currentRoutine->stack[currentRoutine->top - 2].type != INK_INTEGER) { |
|
|
|
|
|
currentRoutine->panic = -1; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
a = currentRoutine->stack[currentRoutine->top - 1]; |
|
|
|
|
|
ary = ink_get_value(ctx, a); |
|
|
|
|
|
if (ary == NULL) { |
|
|
|
|
|
currentRoutine->panic = -1; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
idx = currentRoutine->stack[currentRoutine->top - 2]; |
|
|
|
|
|
value = currentRoutine->stack[currentRoutine->top - 3]; |
|
|
|
|
|
|
|
|
|
|
|
if(ary->top <= idx.value) { |
|
|
|
|
|
currentRoutine->panic = -1; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
ink_pop(ctx); |
|
|
|
|
|
ink_pop(ctx); |
|
|
|
|
|
ink_pop(ctx); |
|
|
|
|
|
|
|
|
|
|
|
ary->elements[idx.value] = value; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static void get_size_array(struct context* ctx) { |
|
|
static void get_size_array(struct context* ctx) { |
|
|
int tid; |
|
|
int tid; |
|
|
struct ink_routine *currentRoutine; |
|
|
struct ink_routine *currentRoutine; |
|
@ -1799,6 +1843,7 @@ int ink_std_library(struct context* ctx) { |
|
|
v += ink_add_native(ctx, "array.new", new_array); |
|
|
v += ink_add_native(ctx, "array.new", new_array); |
|
|
v += ink_add_native(ctx, "array.push", push_array); |
|
|
v += ink_add_native(ctx, "array.push", push_array); |
|
|
v += ink_add_native(ctx, "array.index", index_array); |
|
|
v += ink_add_native(ctx, "array.index", index_array); |
|
|
|
|
|
v += ink_add_native(ctx, "array.set", set_array); |
|
|
v += ink_add_native(ctx, "array.size", get_size_array); |
|
|
v += ink_add_native(ctx, "array.size", get_size_array); |
|
|
v += ink_add_native(ctx, "array.print_utf8", print_array_of_codepoints); |
|
|
v += ink_add_native(ctx, "array.print_utf8", print_array_of_codepoints); |
|
|
v += ink_add_native(ctx, "stack.to_array", arrayify_stack); |
|
|
v += ink_add_native(ctx, "stack.to_array", arrayify_stack); |
|
|