Browse Source

Added type test functions

main
Ludovic 'Archivist' Lagouardette 3 months ago
parent
commit
8f7c7b2c6c
1 changed files with 37 additions and 0 deletions
  1. +37
    -0
      lib.c

+ 37
- 0
lib.c View File

@ -1757,6 +1757,41 @@ static void get_size_array(struct context* ctx) {
ink_push(ctx, sz);
}
static void is_array(struct context* ctx) {
int tid;
struct ink_routine *currentRoutine;
struct elem a;
tid = get_type_by_name(ctx, "array");
currentRoutine = ctx->routines + ctx->routine_current;
if (currentRoutine->top < 1) {
currentRoutine->panic = -1;
return;
}
a.type = INK_INTEGER;
a.value = currentRoutine->stack[currentRoutine->top - 1].type == tid;
ink_pop(ctx);
ink_push(ctx, a);
}
static void is_int(struct context* ctx) {
int tid;
struct ink_routine *currentRoutine;
struct elem a;
currentRoutine = ctx->routines + ctx->routine_current;
if (currentRoutine->top < 1) {
currentRoutine->panic = -1;
return;
}
a.type = INK_INTEGER;
a.value = currentRoutine->stack[currentRoutine->top - 1].type == INK_INTEGER;
ink_pop(ctx);
ink_push(ctx, a);
}
static void print_array_of_codepoints(struct context* ctx) {
int tid, i;
struct ink_routine *currentRoutine;
@ -1834,6 +1869,7 @@ int ink_std_library(struct context* ctx) {
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);
v += ink_add_native(ctx, "is.int", is_int);
#ifndef NOEXTRAARITHMETIC
v += ink_add_native(ctx, ">", gt_int);
v += ink_add_native(ctx, ">=", gte_int);
@ -1851,6 +1887,7 @@ int ink_std_library(struct context* ctx) {
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.print_utf8", print_array_of_codepoints);
v += ink_add_native(ctx, "is.array", is_array);
v += ink_add_native(ctx, "stack.to_array", arrayify_stack);
#endif // NOARRAYLIB

Loading…
Cancel
Save