forked from ground/ground
Add bitwise or
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user