|
|
@ -991,28 +991,33 @@ void runtimeError(char *msg) |
|
|
|
|
|
|
|
oop addOperation(oop ast, oop lhs, oop rhs) |
|
|
|
{ |
|
|
|
if (getType(lhs) == Integer && getType(rhs) == Integer) { |
|
|
|
return makeInteger(getInteger(lhs) + getInteger(rhs)); |
|
|
|
} else if (getType(lhs) == String && getType(rhs) == String) { |
|
|
|
return string_concat(lhs, rhs); |
|
|
|
} else { |
|
|
|
runtimeError("addition between two incompatible types"); |
|
|
|
assert(0); // to prevent: control may reach end of non-void function |
|
|
|
switch (TYPESIG(getType(lhs), getType(rhs))) { |
|
|
|
CASE(Integer, Integer): { |
|
|
|
return makeInteger(getInteger(lhs) + getInteger(rhs)); |
|
|
|
} |
|
|
|
CASE(String, String): { |
|
|
|
return string_concat(lhs, rhs); |
|
|
|
} |
|
|
|
} |
|
|
|
runtimeError("addition between two incompatible types"); |
|
|
|
assert(0); // to prevent: control may reach end of non-void function |
|
|
|
} |
|
|
|
|
|
|
|
oop mulOperation(oop ast, oop lhs, oop rhs) |
|
|
|
{ |
|
|
|
if (getType(lhs) == Integer && getType(rhs) == Integer) { |
|
|
|
return makeInteger(getInteger(lhs) * getInteger(rhs)); |
|
|
|
} else if (getType(lhs) == String && getType(rhs) == Integer) { |
|
|
|
return string_mul(lhs, rhs); |
|
|
|
} else if (getType(lhs) == Integer && getType(rhs) == String) { |
|
|
|
return string_mul(rhs, lhs); |
|
|
|
} else { |
|
|
|
runtimeError("multiplication between two incompatible types"); |
|
|
|
assert(0); |
|
|
|
switch (TYPESIG(getType(lhs), getType(rhs))) { |
|
|
|
CASE(Integer, Integer): { |
|
|
|
return makeInteger(getInteger(lhs) * getInteger(rhs)); |
|
|
|
} |
|
|
|
CASE(String, Integer): { |
|
|
|
return string_mul(lhs, rhs); |
|
|
|
} |
|
|
|
CASE(Integer, String): { |
|
|
|
return string_mul(rhs, lhs); |
|
|
|
} |
|
|
|
} |
|
|
|
runtimeError("multiplication between two incompatible types"); |
|
|
|
assert(0); |
|
|
|
} |
|
|
|
|
|
|
|
oop expandUnquotes(oop scope, oop obj) |
|
|
|