forked from ground/ground
Add bitwise or
This commit is contained in:
@@ -1451,6 +1451,29 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
|
|||||||
}
|
}
|
||||||
break;
|
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
|
* STRING OPERATIONS
|
||||||
|
|||||||
@@ -176,6 +176,11 @@ static GroundInstType getInstructionType(const char* inst) {
|
|||||||
if (strcmp(inst, "not") == 0) return NOT;
|
if (strcmp(inst, "not") == 0) return NOT;
|
||||||
if (strcmp(inst, "greater") == 0) return GREATER;
|
if (strcmp(inst, "greater") == 0) return GREATER;
|
||||||
if (strcmp(inst, "lesser") == 0) return LESSER;
|
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, "stoi") == 0) return STOI;
|
||||||
if (strcmp(inst, "stod") == 0) return STOD;
|
if (strcmp(inst, "stod") == 0) return STOD;
|
||||||
if (strcmp(inst, "ctoi") == 0) return CTOI;
|
if (strcmp(inst, "ctoi") == 0) return CTOI;
|
||||||
|
|||||||
15
src/types.c
15
src/types.c
@@ -486,6 +486,21 @@ void printGroundInstruction(GroundInstruction* gi) {
|
|||||||
case LESSER:
|
case LESSER:
|
||||||
printf("lesser");
|
printf("lesser");
|
||||||
break;
|
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:
|
case STOI:
|
||||||
printf("stoi");
|
printf("stoi");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void wasm_print(const char* str);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum GroundInstType {
|
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;
|
} GroundInstType;
|
||||||
|
|
||||||
typedef enum GroundValueType {
|
typedef enum GroundValueType {
|
||||||
|
|||||||
2
tests/end.grnd
Normal file
2
tests/end.grnd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
set &x 10
|
||||||
|
end $x
|
||||||
@@ -8,7 +8,8 @@ for f in *.grnd; do
|
|||||||
[[ "$f" == "string.grnd" ]] ||
|
[[ "$f" == "string.grnd" ]] ||
|
||||||
[[ "$f" == "test.grnd" ]] ||
|
[[ "$f" == "test.grnd" ]] ||
|
||||||
[[ "$f" == "to1000.grnd" ]] ||
|
[[ "$f" == "to1000.grnd" ]] ||
|
||||||
[[ "$f" == "uhoh.grnd" ]];
|
[[ "$f" == "uhoh.grnd" ]] ||
|
||||||
|
[[ "$f" == "pause.grnd" ]];
|
||||||
then continue
|
then continue
|
||||||
fi
|
fi
|
||||||
echo "Running $f"
|
echo "Running $f"
|
||||||
|
|||||||
Reference in New Issue
Block a user