diff --git a/src/interpreter.c b/src/interpreter.c index 09a16cf..3222ee8 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -1451,6 +1451,29 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop } break; } + case OR: { + if (in->args.length < 2) { + runtimeError(TOO_FEW_ARGS, "Expecting at least 2 args", in, currentInstruction); + } + for (size_t i = 0; i < in->args.length - 1; i++) { + if (in->args.args[i].type != VALUE) { + runtimeError(ARG_TYPE_MISMATCH, "Expecting a value for all args except last", in, currentInstruction); + } + if (in->args.args[i].value.value.type != INT) { + runtimeError(ARG_TYPE_MISMATCH, "Expecting an int for all args except last", in, currentInstruction); + } + } + if (in->args.args[in->args.length-1].type != DIRREF) { + runtimeError(ARG_TYPE_MISMATCH, "Expecting a direct reference for last argument", in, currentInstruction); + } + + int64_t result = 0; + for (size_t i = 0; i < in->args.length - 1; i++) { + result |= in->args.args[i].value.value.data.intVal; + } + addVariable(scope->variables, in->args.args[in->args.length-1].value.refName, createIntGroundValue(result)); + break; + } /* * STRING OPERATIONS diff --git a/src/parser.c b/src/parser.c index 9447e8a..84d84e7 100644 --- a/src/parser.c +++ b/src/parser.c @@ -176,6 +176,11 @@ static GroundInstType getInstructionType(const char* inst) { if (strcmp(inst, "not") == 0) return NOT; if (strcmp(inst, "greater") == 0) return GREATER; if (strcmp(inst, "lesser") == 0) return LESSER; + if (strcmp(inst, "and") == 0) return AND; + if (strcmp(inst, "or") == 0) return OR; + if (strcmp(inst, "xor") == 0) return XOR; + if (strcmp(inst, "neg") == 0) return NEG; + if (strcmp(inst, "shift") == 0) return SHIFT; if (strcmp(inst, "stoi") == 0) return STOI; if (strcmp(inst, "stod") == 0) return STOD; if (strcmp(inst, "ctoi") == 0) return CTOI; diff --git a/src/types.c b/src/types.c index 4eb15c2..20ee2e7 100644 --- a/src/types.c +++ b/src/types.c @@ -486,6 +486,21 @@ void printGroundInstruction(GroundInstruction* gi) { case LESSER: printf("lesser"); break; + case AND: + printf("and"); + break; + case OR: + printf("or"); + break; + case XOR: + printf("xor"); + break; + case NEG: + printf("neg"); + break; + case SHIFT: + printf("shift"); + break; case STOI: printf("stoi"); break; diff --git a/src/types.h b/src/types.h index 6530f9e..2774b45 100644 --- a/src/types.h +++ b/src/types.h @@ -29,7 +29,7 @@ void wasm_print(const char* str); #endif typedef enum GroundInstType { - IF, JUMP, END, INPUT, PRINT, PRINTLN, SET, GETTYPE, EXISTS, SETLIST, SETLISTAT, GETLISTAT, GETLISTSIZE, LISTAPPEND, GETSTRSIZE, GETSTRCHARAT, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, NOT, GREATER, LESSER, STOI, STOD, ITOC, CTOI, TOSTRING, FUN, RETURN, ENDFUN, PUSHARG, CALL, STRUCT, ENDSTRUCT, INIT, GETFIELD, SETFIELD, USE, EXTERN, CREATELABEL, PAUSE, DROP, LICENSE, ERRORCMD + IF, JUMP, END, INPUT, PRINT, PRINTLN, SET, GETTYPE, EXISTS, SETLIST, SETLISTAT, GETLISTAT, GETLISTSIZE, LISTAPPEND, GETSTRSIZE, GETSTRCHARAT, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, NOT, GREATER, LESSER, AND, OR, XOR, NEG, SHIFT, STOI, STOD, ITOC, CTOI, TOSTRING, FUN, RETURN, ENDFUN, PUSHARG, CALL, STRUCT, ENDSTRUCT, INIT, GETFIELD, SETFIELD, USE, EXTERN, CREATELABEL, PAUSE, DROP, LICENSE, ERRORCMD } GroundInstType; typedef enum GroundValueType { diff --git a/tests/end.grnd b/tests/end.grnd new file mode 100644 index 0000000..b144a17 --- /dev/null +++ b/tests/end.grnd @@ -0,0 +1,2 @@ +set &x 10 +end $x \ No newline at end of file diff --git a/tests/unit.sh b/tests/unit.sh index 42d0c0a..512ae83 100755 --- a/tests/unit.sh +++ b/tests/unit.sh @@ -8,7 +8,8 @@ for f in *.grnd; do [[ "$f" == "string.grnd" ]] || [[ "$f" == "test.grnd" ]] || [[ "$f" == "to1000.grnd" ]] || - [[ "$f" == "uhoh.grnd" ]]; + [[ "$f" == "uhoh.grnd" ]] || + [[ "$f" == "pause.grnd" ]]; then continue fi echo "Running $f"