Added in the cast function and fixed type promotion (so it would work with pointer arithmatic)
This commit is contained in:
@@ -14,7 +14,7 @@ class ASTData;
|
||||
#include "ASTData.h"
|
||||
#include "util.h"
|
||||
|
||||
enum ValueType {none, template_type, template_type_type, void_type, boolean, integer, floating, double_percision, character, function_type };
|
||||
enum ValueType {none, template_type, template_type_type, void_type, boolean, character, integer, floating, double_percision, function_type };
|
||||
|
||||
|
||||
class Type {
|
||||
|
||||
@@ -893,7 +893,19 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
|
||||
// because of the . operator, etc
|
||||
if (newNode->getDataRef()->valueType == NULL) {
|
||||
std::cout << "The value type from doFunction was null! (for " << lookup << ")" << std::endl;
|
||||
newNode->getDataRef()->valueType = oldTypes[oldTypes.size()-1].clone();
|
||||
Type* newType = nullptr;
|
||||
if (lookup == "->")
|
||||
newType = oldTypes.back().clone();
|
||||
else if (oldTypes.front().getIndirection())
|
||||
newType = oldTypes.front().clone();
|
||||
else if (oldTypes.back().getIndirection())
|
||||
newType = oldTypes.back().clone();
|
||||
else
|
||||
newType = (oldTypes.front().baseType > oldTypes.back().baseType) ? oldTypes.front().clone() : oldTypes.back().clone();
|
||||
//if (!newType)
|
||||
//newType = oldTypes.back().clone();
|
||||
|
||||
newNode->getDataRef()->valueType = newType;
|
||||
std::cout << "function call to " << lookup << " - " << newNode->getName() << " is now " << newNode->getDataRef()->valueType << std::endl;
|
||||
}
|
||||
return newNode;
|
||||
|
||||
@@ -542,7 +542,7 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
||||
// std::cout << name << " == " << children[0]->getData().symbol.getName() << std::endl;
|
||||
std::string name = children[0]->getDataRef()->symbol.getName();
|
||||
ASTType funcType = children[0]->getDataRef()->type;
|
||||
std::cout << "Doing function: " << name << std::endl;
|
||||
//std::cout << "Doing function: " << name << std::endl;
|
||||
//Test for special functions only if what we're testing is, indeed, the definition, not a function call that returns a callable function pointer
|
||||
if (funcType == function) {
|
||||
if (name == "++" || name == "--")
|
||||
|
||||
@@ -137,6 +137,8 @@ std::string Type::toString(bool showTraits) {
|
||||
}
|
||||
for (int i = 0; i < indirection; i++)
|
||||
typeString += "*";
|
||||
if (indirection < 0)
|
||||
typeString += "negative indirection: " + intToString(indirection);
|
||||
if (traits.size() && showTraits) {
|
||||
typeString += "[ ";
|
||||
for (auto i : traits)
|
||||
|
||||
@@ -18,4 +18,11 @@ fun to_int<T>(in: T) : int {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
fun cast<T,U>(in: T*):U* {
|
||||
var out:U*
|
||||
simple_passthrough(in:out:) """
|
||||
void* out = (void*)in;
|
||||
"""
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
A
|
||||
66
|
||||
57
|
||||
5
|
||||
0
|
||||
0
|
||||
|
||||
57
|
||||
5
|
||||
0
|
||||
0
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
import io:*
|
||||
import conversions:*
|
||||
|
||||
|
||||
fun main():int {
|
||||
println(to_char(65))
|
||||
println(to_int('B'))
|
||||
|
||||
var a = 1337
|
||||
var b = &a
|
||||
var c = cast<int, char>(b)
|
||||
//var d = c + 1
|
||||
//var e = 1 + c
|
||||
println(to_int(*(c+0)))
|
||||
println(to_int(*(c+1)))
|
||||
println(to_int(*(c+2)))
|
||||
println(to_int(*(c+3)))
|
||||
|
||||
println()
|
||||
|
||||
println(to_int(c[0]))
|
||||
println(to_int(c[1]))
|
||||
println(to_int(c[2]))
|
||||
println(to_int(c[3]))
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user