|
@@ -208,12 +208,20 @@ static DataType cCallFunction(const char* name) {
|
|
|
return found->returnType;
|
|
|
}
|
|
|
|
|
|
+static DataType cLoadRef(Variable* v, Operation op, DataType dt) {
|
|
|
+ cAddOperation(OP_LOAD_INT);
|
|
|
+ cAddInt(v->address);
|
|
|
+ cAddOperation(op);
|
|
|
+ return dt;
|
|
|
+}
|
|
|
+
|
|
|
static DataType cLoadVariable(Variable* v) {
|
|
|
if(dtCompare(v->type, dtToReference(dtInt()))) {
|
|
|
- cAddOperation(OP_LOAD_INT);
|
|
|
- cAddInt(v->address);
|
|
|
- cAddOperation(OP_LOAD_INT_REF);
|
|
|
- return dtInt();
|
|
|
+ return cLoadRef(v, OP_REF_LOAD_INT, dtInt());
|
|
|
+ } else if(dtCompare(v->type, dtToReference(dtFloat()))) {
|
|
|
+ return cLoadRef(v, OP_REF_LOAD_FLOAT, dtFloat());
|
|
|
+ } else if(dtCompare(v->type, dtToReference(dtBool()))) {
|
|
|
+ return cLoadRef(v, OP_REF_LOAD_BOOL, dtBool());
|
|
|
}
|
|
|
switch(dtAsInt(v->type)) {
|
|
|
case DT_INT: cAddOperation(OP_LOAD_INT); break;
|
|
@@ -225,17 +233,24 @@ static DataType cLoadVariable(Variable* v) {
|
|
|
return v->type;
|
|
|
}
|
|
|
|
|
|
-static void cStoreVariable(Variable* v, DataType dt, const char* name) {
|
|
|
- if(dtCompare(v->type, dtToReference(dtInt())) && dtCompare(dt, dtInt())) {
|
|
|
+static bool cStoreRef(Variable* v, DataType should, DataType dt, Operation op) {
|
|
|
+ if(dtCompare(v->type, dtToReference(should)) && dtCompare(dt, should)) {
|
|
|
cAddOperation(OP_LOAD_INT);
|
|
|
cAddInt(v->address);
|
|
|
- cAddOperation(OP_STORE_INT_REF);
|
|
|
- return;
|
|
|
+ cAddOperation(op);
|
|
|
+ return true;
|
|
|
}
|
|
|
- if(!dtCompare(v->type, dt)) {
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+static void cStoreVariable(Variable* v, DataType dt, const char* name) {
|
|
|
+ if(cStoreRef(v, dtInt(), dt, OP_REF_STORE_INT) ||
|
|
|
+ cStoreRef(v, dtFloat(), dt, OP_REF_STORE_FLOAT) ||
|
|
|
+ cStoreRef(v, dtBool(), dt, OP_REF_STORE_BOOL)) {
|
|
|
+ return;
|
|
|
+ } else if(!dtCompare(v->type, dt)) {
|
|
|
cInvalidOperation(v->type, dt, name);
|
|
|
- }
|
|
|
- if(v->type.reference) {
|
|
|
+ } else if(v->type.reference) {
|
|
|
cAddOperation(OP_STORE_INT);
|
|
|
cAddInt(v->address);
|
|
|
return;
|