diff --git a/source/tlang/compiler/codegen/emit/dgen.d b/source/tlang/compiler/codegen/emit/dgen.d index 7c219d27..0db1c31b 100644 --- a/source/tlang/compiler/codegen/emit/dgen.d +++ b/source/tlang/compiler/codegen/emit/dgen.d @@ -63,7 +63,7 @@ public final class DCodeEmitter : CodeEmitter { /* Extract type being pointed to */ Pointer pointerType = cast(Pointer)typeIn; - Type referType = pointerType.getReferType(); + Type referType = pointerType.getReferredType(); /* The type is then `transform()*` */ return typeTransform(referType)~"*"; @@ -774,8 +774,9 @@ int main() #include int main() { - thing(); + int retValue = thing(); assert(t_87bc875d0b65f741b69fb100a0edebc7 == 4); + assert(retValue == 6); return 0; }`); diff --git a/source/tlang/compiler/symbols/typing/core.d b/source/tlang/compiler/symbols/typing/core.d index ada3f9cb..7c50ffb5 100644 --- a/source/tlang/compiler/symbols/typing/core.d +++ b/source/tlang/compiler/symbols/typing/core.d @@ -106,7 +106,7 @@ public class Pointer : Integer this.dataType = dataType; } - public Type getReferType() + public Type getReferredType() { return dataType; } diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index 7bfdf4db..0c4e1182 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -598,7 +598,26 @@ public final class TypeChecker /* If pointer dereference */ else if(unaryOperator == SymbolType.STAR) { - /* TODO: Add support */ + gprintln("Type popped: "~to!(string)(expType)); + + // Okay, so yes, we would pop `ptr`'s type as `int*` which is correct + // but now, we must a.) ensure that IS the case and b.) + // push the type of `` with one star less on as we are derefrencing `ptr` + Type derefPointerType; + if(cast(Pointer)expType) + { + Pointer pointerType = cast(Pointer)expType; + + // Get the type being referred to + Type referredType = pointerType.getReferredType(); + + addType(referredType); + } + else + { + gprintln("You cannot dereference a type that is not a pointer type!", DebugType.ERROR); + assert(false); + } } /* If pointer create `&` */ else if(unaryOperator == SymbolType.AMPERSAND) @@ -632,6 +651,7 @@ public final class TypeChecker UnaryOpInstr addInst = new UnaryOpInstr(expInstr, unaryOperator); + gprintln("Made unaryop instr: "~to!(string)(addInst)); addInstr(addInst); } /* Function calls */ diff --git a/source/tlang/testing/simple_pointer.t b/source/tlang/testing/simple_pointer.t index 0724201c..69db5af0 100644 --- a/source/tlang/testing/simple_pointer.t +++ b/source/tlang/testing/simple_pointer.t @@ -5,12 +5,13 @@ int j; int function(int* ptr) { *ptr = 2+2; - - return 0; + return (*ptr)+1*2; } int thing() { int discardExpr = function(&j); int** l; + + return discardExpr; } \ No newline at end of file