@@ -42,6 +42,7 @@ void compileCall(const VregPtr &destination, Function &function, const Context &
42
42
auto *expr = std::get<Expr *>(argument);
43
43
auto argument_type = expr->getType (context);
44
44
argument_register->setType (*argument_type);
45
+
45
46
if (fn_arg_type->isReference ()) {
46
47
function.addComment (" compileCall: compiling address into reference argument" );
47
48
if (!expr->compileAddress (argument_register, function, context))
@@ -51,6 +52,7 @@ void compileCall(const VregPtr &destination, Function &function, const Context &
51
52
" Structs cannot be directly passed to functions; use a pointer" );
52
53
} else
53
54
expr->compile (argument_register, function, context, 1 );
55
+
54
56
try {
55
57
typeCheck (*argument_type, *fn_arg_type, argument_register, function, expr->getLocation ());
56
58
} catch (std::out_of_range &err) {
@@ -947,11 +949,15 @@ bool VariableExpr::compileAddress(const VregPtr &destination, Function &function
947
949
} else {
948
950
const size_t offset = function.stackOffsets .at (var);
949
951
function.addComment (" Get variable lvalue for " + name);
950
- function.add <SubIInstruction>(function.precolored (Why::framePointerOffset), destination,
951
- immLikeReg (destination, static_cast <int >(offset)))->setDebug (*this );
952
952
if (var->getType ()->isReference ()) {
953
+ auto temp = function.newVar (destination->getType ());
954
+ function.add <SubIInstruction>(function.precolored (Why::framePointerOffset), temp,
955
+ immLikeReg (temp, static_cast <int >(offset)))->setDebug (*this );
953
956
function.addComment (" Load reference lvalue for " + name);
954
- function.add <LoadRInstruction>(destination, destination)->setDebug (*this );
957
+ function.add <LoadRInstruction>(temp, destination)->setDebug (*this );
958
+ } else {
959
+ function.add <SubIInstruction>(function.precolored (Why::framePointerOffset), destination,
960
+ immLikeReg (destination, static_cast <int >(offset)))->setDebug (*this );
955
961
}
956
962
}
957
963
} else if (const auto fn = context.scope ->lookupFunction (name, getLocation ())) {
@@ -1058,10 +1064,17 @@ std::string StringExpr::getID(Program &program) const {
1058
1064
void DerefExpr::compile (VregPtr destination, Function &function, const Context &context, size_t multiplier) {
1059
1065
if (auto fnptr = getOperator (context)) {
1060
1066
compileCall (destination, function, context, fnptr, {subexpr.get ()}, getLocation (), multiplier);
1061
- } else {
1067
+ } else if (destination) {
1062
1068
checkType (context);
1063
- subexpr->compile (destination, function, context, multiplier);
1064
- function.add <LoadRInstruction>(destination, destination)->setDebug (*this );
1069
+ auto type = TypePtr (getType (context));
1070
+ auto temp = function.newVar (type);
1071
+ subexpr->compile (temp, function, context, multiplier);
1072
+ function.addComment (" Loading in DerefExpr::compile" );
1073
+ if (auto ref = type->ptrcast <ReferenceType>()) // Pointers to references really shouldn't be a thing..
1074
+ destination->setType (*ref->subtype );
1075
+ else
1076
+ destination->setType (*type);
1077
+ function.add <LoadRInstruction>(temp, destination)->setDebug (*this );
1065
1078
}
1066
1079
}
1067
1080
@@ -1419,14 +1432,20 @@ void AssignExpr::compile(VregPtr destination, Function &function, const Context
1419
1432
if (auto fnptr = function.program .getOperator ({left_type.get (), right_type.get ()}, CPMTOK_ASSIGN, getLocation ())) {
1420
1433
compileCall (destination, function, context, fnptr, {left.get (), right.get ()}, getLocation (), multiplier);
1421
1434
} else {
1435
+ function.addComment (" Begin assignment" );
1422
1436
auto addr_var = function.newVar ();
1423
1437
if (!destination)
1424
1438
destination = function.newVar ();
1425
1439
TypePtr right_type = right->getType (context);
1440
+
1426
1441
if (!left->compileAddress (addr_var, function, context))
1427
1442
throw LvalueError (std::string (*left->getType (context)));
1428
- if (destination)
1443
+
1444
+ if (destination) {
1445
+ info () << getLocation () << " : " << *addr_var->getType () << ' \n ' ;
1429
1446
destination->setType (*addr_var->getType ());
1447
+ }
1448
+
1430
1449
if (right_type->isInitializer ()) {
1431
1450
auto *initializer_expr = right->cast <InitializerExpr>();
1432
1451
if (initializer_expr->isConstructor ) {
@@ -1462,6 +1481,7 @@ void AssignExpr::compile(VregPtr destination, Function &function, const Context
1462
1481
function.add <MultIInstruction>(destination, destination, immLikeReg (destination,
1463
1482
static_cast <int >(multiplier)))->setDebug (*this );
1464
1483
}
1484
+ function.addComment (" End assignment" );
1465
1485
}
1466
1486
}
1467
1487
0 commit comments