Add bitwise or

This commit is contained in:
2026-03-25 21:04:44 +11:00
parent be7db9d837
commit 5c5b0bd26f
6 changed files with 48 additions and 2 deletions

View File

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

View File

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

View File

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

View File

@@ -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 {

2
tests/end.grnd Normal file
View File

@@ -0,0 +1,2 @@
set &x 10
end $x

View File

@@ -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"