Browse Source

added a xor operation

main
Ludovic 'Archivist' Lagouardette 3 months ago
parent
commit
1a3b1f89f7
1 changed files with 38 additions and 18 deletions
  1. +38
    -18
      lib.c

+ 38
- 18
lib.c View File

@ -455,7 +455,7 @@ static int ink_consume_one(int* end, struct context* pContext, char** buffer, ch
return 0;
}
static int ink_lex(struct context *pContext, char* buffer) {
static int ink_lex(struct context *pContext, ">const char* buffer) {
/* Limits the token size to 127 chars */
char r[128];
int end;
@ -1233,22 +1233,41 @@ static void is_different(struct context* ctx) {
#ifndef NOEXTRAARITHMETIC
static void rem_int(struct context* ctx) {
struct ink_routine* currentRoutine;
struct elem a;
struct elem b;
currentRoutine = ctx->routines + ctx->routine_current;
if(currentRoutine->top < 2) {
currentRoutine->panic = -1;
return;
}
a = currentRoutine->stack[currentRoutine->top-1];
b = currentRoutine->stack[currentRoutine->top-2];
if(!(a.type == INK_INTEGER && b.type == INK_INTEGER)) {
currentRoutine->panic = -1;
return;
}
ink_pop(ctx);
currentRoutine->stack[currentRoutine->top-1].value = b.value % a.value;
struct ink_routine* currentRoutine;
struct elem a;
struct elem b;
currentRoutine = ctx->routines + ctx->routine_current;
if(currentRoutine->top < 2) {
currentRoutine->panic = -1;
return;
}
a = currentRoutine->stack[currentRoutine->top-1];
b = currentRoutine->stack[currentRoutine->top-2];
if(!(a.type == INK_INTEGER && b.type == INK_INTEGER)) {
currentRoutine->panic = -1;
return;
}
ink_pop(ctx);
currentRoutine->stack[currentRoutine->top-1].value = b.value % a.value;
}
static void xor_int(struct context* ctx) {
struct ink_routine* currentRoutine;
struct elem a;
struct elem b;
currentRoutine = ctx->routines + ctx->routine_current;
if(currentRoutine->top < 2) {
currentRoutine->panic = -1;
return;
}
a = currentRoutine->stack[currentRoutine->top-1];
b = currentRoutine->stack[currentRoutine->top-2];
if(!(a.type == INK_INTEGER && b.type == INK_INTEGER)) {
currentRoutine->panic = -1;
return;
}
ink_pop(ctx);
currentRoutine->stack[currentRoutine->top-1].value = b.value ^ a.value;
}
static void gt_int(struct context* ctx) {
@ -1874,7 +1893,8 @@ int ink_std_library(struct context* ctx) {
v += ink_add_native(ctx, ">", gt_int);
v += ink_add_native(ctx, ">=", gte_int);
v += ink_add_native(ctx, "=<", lte_int);
v += ink_add_native(ctx, "%", rem_int);
v += ink_add_native(ctx, "%", rem_int);
v += ink_add_native(ctx, "int.xor", xor_int);
#endif // NOEXTRAARITHMETIC
#ifndef NOARRAYLIB
ink_new_type(ctx, "array", sizeof(struct ink_array), collect_array, gc_array);

Loading…
Cancel
Save