소스 검색

added a xor operation

main
Ludovic 'Archivist' Lagouardette 6 달 전
부모
커밋
1a3b1f89f7
1개의 변경된 파일38개의 추가작업 그리고 18개의 파일을 삭제
  1. +38
    -18
      lib.c

+ 38
- 18
lib.c 파일 보기

@ -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);

불러오는 중...
취소
저장