Add more features
This commit is contained in:
10
README.md
10
README.md
@@ -23,17 +23,17 @@ Progress marker:
|
|||||||
- [x] References
|
- [x] References
|
||||||
- [ ] Interpreter
|
- [ ] Interpreter
|
||||||
- [x] Labels
|
- [x] Labels
|
||||||
- [ ] Console I/O
|
- [x] Console I/O
|
||||||
- [x] Control flow
|
- [x] Control flow
|
||||||
- [ ] Data
|
- [ ] Data
|
||||||
- [ ] Variable creation
|
- [x] Variable creation
|
||||||
- [ ] Variable access
|
- [x] Variable access
|
||||||
- [ ] Lists
|
- [ ] Lists
|
||||||
- [ ] Creation
|
- [ ] Creation
|
||||||
- [ ] Access
|
- [ ] Access
|
||||||
- [ ] String operations
|
- [ ] String operations
|
||||||
- [ ] Maths
|
- [x] Maths
|
||||||
- [ ] Comparisions
|
- [x] Comparisions
|
||||||
- [ ] Type conversions
|
- [ ] Type conversions
|
||||||
- [ ] Functions
|
- [ ] Functions
|
||||||
- [ ] Custom data structures
|
- [ ] Custom data structures
|
||||||
|
|||||||
@@ -474,7 +474,15 @@ void interpretGroundInstruction(GroundInstruction inst, GroundScope* scope) {
|
|||||||
GroundValue* right = &in->args.args[1].value.value;
|
GroundValue* right = &in->args.args[1].value.value;
|
||||||
|
|
||||||
if (left->type != right->type) {
|
if (left->type != right->type) {
|
||||||
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(false));
|
if (left->type == INT && right->type == DOUBLE) {
|
||||||
|
bool cond = (left->data.intVal == right->data.doubleVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
} else if (left->type == DOUBLE && right->type == INT) {
|
||||||
|
bool cond = (left->data.doubleVal == right->data.intVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
} else {
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(false));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (left->type) {
|
switch (left->type) {
|
||||||
case INT: {
|
case INT: {
|
||||||
@@ -510,6 +518,201 @@ void interpretGroundInstruction(GroundInstruction inst, GroundScope* scope) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case INEQUAL: {
|
||||||
|
if (in->args.length < 3) {
|
||||||
|
runtimeError(TOO_FEW_ARGS, "Expecting 3 args", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.length > 3) {
|
||||||
|
runtimeError(TOO_MANY_ARGS, "Expecting 3 args", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[0].type != VALUE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a Value for arg 1", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[1].type != VALUE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a Value for arg 2", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[2].type != DIRREF) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a DirectRef for arg 3", in, currentInstruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroundValue* left = &in->args.args[0].value.value;
|
||||||
|
GroundValue* right = &in->args.args[1].value.value;
|
||||||
|
|
||||||
|
if (left->type != right->type) {
|
||||||
|
if (left->type == INT && right->type == DOUBLE) {
|
||||||
|
bool cond = (left->data.intVal != right->data.doubleVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
} else if (left->type == DOUBLE && right->type == INT) {
|
||||||
|
bool cond = (left->data.doubleVal != right->data.intVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
} else {
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(false));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (left->type) {
|
||||||
|
case INT: {
|
||||||
|
bool cond = (left->data.intVal != right->data.intVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DOUBLE: {
|
||||||
|
bool cond = (left->data.doubleVal != right->data.doubleVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case STRING: {
|
||||||
|
bool cond = (strcmp(left->data.stringVal, right->data.stringVal) != 0);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CHAR: {
|
||||||
|
bool cond = (left->data.charVal != right->data.charVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BOOL: {
|
||||||
|
bool cond = (left->data.boolVal != right->data.boolVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(true));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GREATER: {
|
||||||
|
if (in->args.length < 3) {
|
||||||
|
runtimeError(TOO_FEW_ARGS, "Expecting 3 args", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.length > 3) {
|
||||||
|
runtimeError(TOO_MANY_ARGS, "Expecting 3 args", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[0].type != VALUE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a Value for arg 1", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[1].type != VALUE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a Value for arg 2", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[2].type != DIRREF) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a DirectRef for arg 3", in, currentInstruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroundValue* left = &in->args.args[0].value.value;
|
||||||
|
GroundValue* right = &in->args.args[1].value.value;
|
||||||
|
|
||||||
|
if (left->type != INT && left->type != DOUBLE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting an Int or Double for arg 1", in, currentInstruction);
|
||||||
|
} else if (right->type != INT && right->type != DOUBLE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting an Int or Double for arg 2", in, currentInstruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (left->type != right->type) {
|
||||||
|
if (left->type == INT && right->type == DOUBLE) {
|
||||||
|
bool cond = (left->data.intVal > right->data.doubleVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
} else if (left->type == DOUBLE && right->type == INT) {
|
||||||
|
bool cond = (left->data.doubleVal > right->data.intVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
} else {
|
||||||
|
runtimeError(FIXME, "Uncaught invalid type", in, currentInstruction);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (left->type) {
|
||||||
|
case INT: {
|
||||||
|
bool cond = (left->data.intVal > right->data.intVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DOUBLE: {
|
||||||
|
bool cond = (left->data.doubleVal > right->data.doubleVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
runtimeError(FIXME, "Uncaught invalid type", in, currentInstruction);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LESSER: {
|
||||||
|
if (in->args.length < 3) {
|
||||||
|
runtimeError(TOO_FEW_ARGS, "Expecting 3 args", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.length > 3) {
|
||||||
|
runtimeError(TOO_MANY_ARGS, "Expecting 3 args", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[0].type != VALUE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a Value for arg 1", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[1].type != VALUE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a Value for arg 2", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[2].type != DIRREF) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a DirectRef for arg 3", in, currentInstruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroundValue* left = &in->args.args[0].value.value;
|
||||||
|
GroundValue* right = &in->args.args[1].value.value;
|
||||||
|
|
||||||
|
if (left->type != INT && left->type != DOUBLE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting an Int or Double for arg 1", in, currentInstruction);
|
||||||
|
} else if (right->type != INT && right->type != DOUBLE) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting an Int or Double for arg 2", in, currentInstruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (left->type != right->type) {
|
||||||
|
if (left->type == INT && right->type == DOUBLE) {
|
||||||
|
bool cond = (left->data.intVal < right->data.doubleVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
} else if (left->type == DOUBLE && right->type == INT) {
|
||||||
|
bool cond = (left->data.doubleVal < right->data.intVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
} else {
|
||||||
|
runtimeError(FIXME, "Uncaught invalid type", in, currentInstruction);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (left->type) {
|
||||||
|
case INT: {
|
||||||
|
bool cond = (left->data.intVal < right->data.intVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DOUBLE: {
|
||||||
|
bool cond = (left->data.doubleVal < right->data.doubleVal);
|
||||||
|
addVariable(scope->variables, in->args.args[2].value.refName, createBoolGroundValue(cond));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
runtimeError(FIXME, "Uncaught invalid type", in, currentInstruction);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NOT: {
|
||||||
|
if (in->args.length < 2) {
|
||||||
|
runtimeError(TOO_FEW_ARGS, "Expecting 2 args", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.length > 2) {
|
||||||
|
runtimeError(TOO_MANY_ARGS, "Expecting 2 args", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[0].type != VALUE && in->args.args[0].value.value.type != BOOL) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a Bool for arg 1", in, currentInstruction);
|
||||||
|
}
|
||||||
|
if (in->args.args[1].type != DIRREF) {
|
||||||
|
runtimeError(ARG_TYPE_MISMATCH, "Expecting a DirectRef for arg 2", in, currentInstruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool condition = !in->args.args[1].value.value.data.boolVal;
|
||||||
|
|
||||||
|
addVariable(scope->variables, in->args.args[1].value.refName, createBoolGroundValue(condition));
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
runtimeError(FIXME, "Currently unimplemented instruction", in, currentInstruction);
|
runtimeError(FIXME, "Currently unimplemented instruction", in, currentInstruction);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user