Skip to content
This repository
Browse code

Updated assembler to output linker entries for directly used labels.

Fixed returning references for expression types in compiler.
  • Loading branch information...
commit 4764891daf10cdfc1d8673cb204144e4a10616f0 1 parent 2c543ee
James Rhodes authored May 12, 2012

Showing 33 changed files with 84 additions and 70 deletions. Show diff stats Hide diff stats

  1. 11  dtasm/aout.c
  2. 8  libdcpu-ci-lang-c/nodes/NAddressOfOperator.cpp
  3. 2  libdcpu-ci-lang-c/nodes/NAddressOfOperator.h
  4. 2  libdcpu-ci-lang-c/nodes/NAssignment.cpp
  5. 2  libdcpu-ci-lang-c/nodes/NAssignment.h
  6. 15  libdcpu-ci-lang-c/nodes/NBinaryOperator.cpp
  7. 2  libdcpu-ci-lang-c/nodes/NBinaryOperator.h
  8. 4  libdcpu-ci-lang-c/nodes/NBlock.cpp
  9. 2  libdcpu-ci-lang-c/nodes/NBlock.h
  10. 4  libdcpu-ci-lang-c/nodes/NCharacter.cpp
  11. 2  libdcpu-ci-lang-c/nodes/NCharacter.h
  12. 9  libdcpu-ci-lang-c/nodes/NDereferenceOperator.cpp
  13. 2  libdcpu-ci-lang-c/nodes/NDereferenceOperator.h
  14. 2  libdcpu-ci-lang-c/nodes/NExpression.h
  15. 4  libdcpu-ci-lang-c/nodes/NIdentifier.cpp
  16. 2  libdcpu-ci-lang-c/nodes/NIdentifier.h
  17. 4  libdcpu-ci-lang-c/nodes/NInteger.cpp
  18. 2  libdcpu-ci-lang-c/nodes/NInteger.h
  19. 23  libdcpu-ci-lang-c/nodes/NMethodCall.cpp
  20. 2  libdcpu-ci-lang-c/nodes/NMethodCall.h
  21. 2  libdcpu-ci-lang-c/nodes/NPostIncDec.cpp
  22. 2  libdcpu-ci-lang-c/nodes/NPostIncDec.h
  23. 2  libdcpu-ci-lang-c/nodes/NPreIncDec.cpp
  24. 2  libdcpu-ci-lang-c/nodes/NPreIncDec.h
  25. 6  libdcpu-ci-lang-c/nodes/NString.cpp
  26. 2  libdcpu-ci-lang-c/nodes/NString.h
  27. 8  libdcpu-ci-lang-c/nodes/NStructureResolutionOperator.cpp
  28. 2  libdcpu-ci-lang-c/nodes/NStructureResolutionOperator.h
  29. 4  libdcpu-ci-lang-c/nodes/NType.cpp
  30. 7  libdcpu-ci-lang-c/nodes/NType.h
  31. 8  libdcpu-ci-lang-c/nodes/NUnaryOperator.cpp
  32. 2  libdcpu-ci-lang-c/nodes/NUnaryOperator.h
  33. 3  libdcpu-ci-lang/nodes/IType.h
11  dtasm/aout.c
@@ -362,7 +362,7 @@ void aout_write(FILE* out, bool relocatable, bool intermediate)
362 362
 							break;
363 363
 						}
364 364
 					}
365  
-					/*else if (current_inner->type == AOUT_TYPE_NORMAL && (bstring)current_outer->expr->data != NULL)
  365
+					/*else if (current_inner->type == AOUT_TYPE_NORMAL)
366 366
 					{
367 367
 						// We're adjusting a label reference in the code
368 368
 						// to it's actual value.
@@ -393,6 +393,15 @@ void aout_write(FILE* out, bool relocatable, bool intermediate)
393 393
 					expr_delete(current_outer->expr);
394 394
 					current_outer->expr = NULL;
395 395
 					did_find = true;
  396
+					
  397
+					// We also need to add this entry to the adjustment
  398
+					// table for the linker since it also needs to adjust
  399
+					// internal label jumps in files when it concatenates
  400
+					// all of the object code together.
  401
+					linker_temp = lprov_create(NULL, out_index);
  402
+					linker_temp->next = linker_adjustment;
  403
+					linker_adjustment = linker_temp;
  404
+					fprintf(stderr, "LINK ADJUST 0x%04X\n", out_index);
396 405
 				}
397 406
 			}
398 407
 		}
8  libdcpu-ci-lang-c/nodes/NAddressOfOperator.cpp
@@ -27,11 +27,11 @@ AsmBlock* NAddressOfOperator::reference(AsmGenerator& context)
27 27
 	throw new CompilerException("Unable to get reference to the result of an address-of operator.");
28 28
 }
29 29
 
30  
-IType& NAddressOfOperator::getExpressionType(AsmGenerator& context)
  30
+IType* NAddressOfOperator::getExpressionType(AsmGenerator& context)
31 31
 {
32 32
 	// The address of operator has the type of it's expression as a pointer.
33  
-	IType& c = this->expr.getExpressionType(context);
34  
-	NType t = NType((NType&)c);
35  
-	t.pointerCount += 1;
  33
+	IType* i = this->expr.getExpressionType(context);
  34
+	NType* t = new NType(*((NType*)i));
  35
+	t->pointerCount += 1;
36 36
 	return t;
37 37
 }
2  libdcpu-ci-lang-c/nodes/NAddressOfOperator.h
@@ -23,7 +23,7 @@ class NAddressOfOperator : public NExpression
23 23
 		NAddressOfOperator(NExpression& expr) : expr(expr), NExpression("addressof") { }
24 24
 		virtual AsmBlock* compile(AsmGenerator& context);
25 25
 		virtual AsmBlock* reference(AsmGenerator& context);
26  
-		virtual IType& getExpressionType(AsmGenerator& context);
  26
+		virtual IType* getExpressionType(AsmGenerator& context);
27 27
 };
28 28
 
29 29
 #endif
2  libdcpu-ci-lang-c/nodes/NAssignment.cpp
@@ -118,7 +118,7 @@ AsmBlock* NAssignment::reference(AsmGenerator& context)
118 118
 	throw new CompilerException("Unable to get reference to the result of an assignment.");
119 119
 }
120 120
 
121  
-IType& NAssignment::getExpressionType(AsmGenerator& context)
  121
+IType* NAssignment::getExpressionType(AsmGenerator& context)
122 122
 {
123 123
 	// An assignment has the type of it's LHS.
124 124
 	return this->lhs.getExpressionType(context);
2  libdcpu-ci-lang-c/nodes/NAssignment.h
@@ -26,7 +26,7 @@ class NAssignment : public NExpression
26 26
 			lhs(lhs), op(op), rhs(rhs), NExpression("assignment") { }
27 27
 		virtual AsmBlock* compile(AsmGenerator& context);
28 28
 		virtual AsmBlock* reference(AsmGenerator& context);
29  
-		virtual IType& getExpressionType(AsmGenerator& context);
  29
+		virtual IType* getExpressionType(AsmGenerator& context);
30 30
 };
31 31
 
32 32
 #endif
15  libdcpu-ci-lang-c/nodes/NBinaryOperator.cpp
@@ -188,14 +188,17 @@ AsmBlock* NBinaryOperator::reference(AsmGenerator& context)
188 188
 	throw new CompilerException("Unable to get reference to the result of an binary operator.");
189 189
 }
190 190
 
191  
-IType& NBinaryOperator::getExpressionType(AsmGenerator& context)
  191
+IType* NBinaryOperator::getExpressionType(AsmGenerator& context)
192 192
 {
193 193
 	// A binary operator has the type of each of it's expressions.
194  
-	NType lType = (NType&)this->lhs.getExpressionType(context);
195  
-	NType rType = (NType&)this->rhs.getExpressionType(context);
196  
-
197  
-	if (lType != rType)
198  
-		throw new CompilerException("Unable to implicitly cast from " + lType.name + " to " + rType.name + ".");
  194
+	IType* lType = this->lhs.getExpressionType(context);
  195
+	IType* rType = this->rhs.getExpressionType(context);
  196
+
  197
+	// FIXME: We need a proper type system allowing for implicit
  198
+	//        casts between reasonable values (currently this won't
  199
+	//        even permit you to cast between int and int16_t).
  200
+	//if (lType != rType)
  201
+	//	throw new CompilerException("Unable to implicitly cast from " + lType.name + " to " + rType.name + ".");
199 202
 
200 203
 	return lType;
201 204
 }
2  libdcpu-ci-lang-c/nodes/NBinaryOperator.h
@@ -26,7 +26,7 @@ class NBinaryOperator : public NExpression
26 26
 			lhs(lhs), op(op), rhs(rhs), NExpression("binaryop") { }
27 27
 		virtual AsmBlock* compile(AsmGenerator& context);
28 28
 		virtual AsmBlock* reference(AsmGenerator& context);
29  
-		virtual IType& getExpressionType(AsmGenerator& context);
  29
+		virtual IType* getExpressionType(AsmGenerator& context);
30 30
 };
31 31
 
32 32
 #endif
4  libdcpu-ci-lang-c/nodes/NBlock.cpp
@@ -38,8 +38,8 @@ AsmBlock* NBlock::reference(AsmGenerator& context)
38 38
 	throw new CompilerException("Unable to get reference to the result of a block node.");
39 39
 }
40 40
 
41  
-IType& NBlock::getExpressionType(AsmGenerator& context)
  41
+IType* NBlock::getExpressionType(AsmGenerator& context)
42 42
 {
43 43
 	// A block of statements has no type.
44  
-	return NType::VoidType;
  44
+	return new NType(NType::VoidType);
45 45
 }
2  libdcpu-ci-lang-c/nodes/NBlock.h
@@ -24,7 +24,7 @@ class NBlock : public NExpression
24 24
 		NBlock() : NExpression("block") { }
25 25
 		virtual AsmBlock* compile(AsmGenerator& context);
26 26
 		virtual AsmBlock* reference(AsmGenerator& context);
27  
-		virtual IType& getExpressionType(AsmGenerator& context);
  27
+		virtual IType* getExpressionType(AsmGenerator& context);
28 28
 };
29 29
 
30 30
 #endif
4  libdcpu-ci-lang-c/nodes/NCharacter.cpp
@@ -34,8 +34,8 @@ AsmBlock* NCharacter::reference(AsmGenerator& context)
34 34
 	throw new CompilerException("Unable to get reference to a character node.");
35 35
 }
36 36
 
37  
-IType& NCharacter::getExpressionType(AsmGenerator& context)
  37
+IType* NCharacter::getExpressionType(AsmGenerator& context)
38 38
 {
39 39
 	// A character has the type char.
40  
-	return NInteger::CharType;
  40
+	return new NType(NInteger::CharType);
41 41
 }
2  libdcpu-ci-lang-c/nodes/NCharacter.h
@@ -23,7 +23,7 @@ class NCharacter : public NExpression
23 23
 		NCharacter(std::string value) : value(value), NExpression("character") { }
24 24
 		virtual AsmBlock* compile(AsmGenerator& context);
25 25
 		virtual AsmBlock* reference(AsmGenerator& context);
26  
-		virtual IType& getExpressionType(AsmGenerator& context);
  26
+		virtual IType* getExpressionType(AsmGenerator& context);
27 27
 };
28 28
 
29 29
 #endif
9  libdcpu-ci-lang-c/nodes/NDereferenceOperator.cpp
@@ -42,13 +42,14 @@ AsmBlock* NDereferenceOperator::reference(AsmGenerator& context)
42 42
 	return this->expr.compile(context);
43 43
 }
44 44
 
45  
-IType& NDereferenceOperator::getExpressionType(AsmGenerator& context)
  45
+IType* NDereferenceOperator::getExpressionType(AsmGenerator& context)
46 46
 {
47 47
 	// An dereference operator has the "unpointered" type of it's expression.
48  
-	NType t = NType((NType&)this->expr.getExpressionType(context));
  48
+	IType* i = this->expr.getExpressionType(context);
  49
+	NType* t = new NType(*((NType*)i));
49 50
 
50  
-	if (t.pointerCount > 0)
51  
-		t.pointerCount -= 1;
  51
+	if (t->pointerCount > 0)
  52
+		t->pointerCount -= 1;
52 53
 	else
53 54
 		throw new CompilerException("Attempting to dereference non-pointer type during type resolution.");
54 55
 
2  libdcpu-ci-lang-c/nodes/NDereferenceOperator.h
@@ -23,7 +23,7 @@ class NDereferenceOperator : public NExpression
23 23
 		NDereferenceOperator(NExpression& expr) : expr(expr), NExpression("dereference") { }
24 24
 		virtual AsmBlock* compile(AsmGenerator& context);
25 25
 		virtual AsmBlock* reference(AsmGenerator& context);
26  
-		virtual IType& getExpressionType(AsmGenerator& context);
  26
+		virtual IType* getExpressionType(AsmGenerator& context);
27 27
 };
28 28
 
29 29
 #endif
2  libdcpu-ci-lang-c/nodes/NExpression.h
@@ -24,7 +24,7 @@ class NExpression : public Node
24 24
 	protected:
25 25
 		NExpression(std::string type) : Node("expression-" + type) { }
26 26
 	public:
27  
-		virtual IType& getExpressionType(AsmGenerator& context) = 0;
  27
+		virtual IType* getExpressionType(AsmGenerator& context) = 0;
28 28
 };
29 29
 
30 30
 #endif
4  libdcpu-ci-lang-c/nodes/NIdentifier.cpp
@@ -57,7 +57,7 @@ AsmBlock* NIdentifier::reference(AsmGenerator& context)
57 57
 	return block;
58 58
 }
59 59
 
60  
-IType& NIdentifier::getExpressionType(AsmGenerator& context)
  60
+IType* NIdentifier::getExpressionType(AsmGenerator& context)
61 61
 {
62 62
 	// Search the current context for the variable with
63 63
 	// this name and return it's type.
@@ -66,5 +66,5 @@ IType& NIdentifier::getExpressionType(AsmGenerator& context)
66 66
 	if (type == NULL)
67 67
 		throw new CompilerException("Unable to resolve variable '" + this->name + "' when determining type information (does the variable exist?).");
68 68
 	else
69  
-		return *type;
  69
+		return type;
70 70
 }
2  libdcpu-ci-lang-c/nodes/NIdentifier.h
@@ -24,7 +24,7 @@ class NIdentifier : public NExpression
24 24
 		NIdentifier(const std::string& name, std::string type) : name(name), NExpression("identifier-" + type) { }
25 25
 		virtual AsmBlock* compile(AsmGenerator& context);
26 26
 		virtual AsmBlock* reference(AsmGenerator& context);
27  
-		virtual IType& getExpressionType(AsmGenerator& context);
  27
+		virtual IType* getExpressionType(AsmGenerator& context);
28 28
 };
29 29
 
30 30
 #endif
4  libdcpu-ci-lang-c/nodes/NInteger.cpp
@@ -60,8 +60,8 @@ AsmBlock* NInteger::reference(AsmGenerator& context)
60 60
 	throw new CompilerException("Unable to get reference to the result of a numeric literal.");
61 61
 }
62 62
 
63  
-IType& NInteger::getExpressionType(AsmGenerator& context)
  63
+IType* NInteger::getExpressionType(AsmGenerator& context)
64 64
 {
65 65
 	// All literals are currently unsigned 16-bit integers.
66  
-	return NInteger::UInt16Type;
  66
+	return new NType(NInteger::UInt16Type);
67 67
 }
2  libdcpu-ci-lang-c/nodes/NInteger.h
@@ -26,7 +26,7 @@ class NInteger : public NExpression
26 26
 		NInteger(long long value) : value(value), NExpression("integer") { }
27 27
 		virtual AsmBlock* compile(AsmGenerator& context);
28 28
 		virtual AsmBlock* reference(AsmGenerator& context);
29  
-		virtual IType& getExpressionType(AsmGenerator& context);
  29
+		virtual IType* getExpressionType(AsmGenerator& context);
30 30
 
31 31
 		// Specific types for integers.
32 32
 		static NType& Int8Type;
23  libdcpu-ci-lang-c/nodes/NMethodCall.cpp
@@ -46,6 +46,9 @@ AsmBlock* NMethodCall::compile(AsmGenerator& context)
46 46
 		isDirect = false;
47 47
 	}
48 48
 
  49
+	// FIXME: Again, without implicit type casting this breaks quite a few
  50
+	// things, so it's disabled for now.
  51
+	/*
49 52
 	// check if the called function matches the signature of this method call
50 53
 	// typedef std::vector<NVariableDeclaration*> VariableList; funcsig->arguments
51 54
 	// typedef std::vector<NExpression*> ExpressionList for this->arguments
@@ -59,16 +62,17 @@ AsmBlock* NMethodCall::compile(AsmGenerator& context)
59 62
 	// now check types of all the arguments
60 63
 	for (unsigned int i = 0; i < funcsig->arguments.size(); i++)
61 64
 	{
62  
-		NType callerType = (NType&) this->arguments[i]->getExpressionType(context);
63  
-		NType calleeType = (NType&) funcsig->arguments[i]->type;
64  
-		if (callerType.name != calleeType.name)
  65
+		NType* callerType = (NType*) this->arguments[i]->getExpressionType(context);
  66
+		NType& calleeType = funcsig->arguments[i]->type;
  67
+		if (callerType->name != calleeType.name)
65 68
 		{
66 69
 			throw new CompilerException("There is no function with the name "
67 70
 						    + this->id.name + " and signature " + this->calculateSignature(context) + "\n"
68 71
 						    + "Candidates are:\t" + this->id.name + " with signature " + funcsig->getSignature());
69 72
 		}
70 73
 	}
71  
-
  74
+	*/
  75
+	
72 76
 	// Get the stack table of this method.
73 77
 	StackFrame* frame = context.generateStackFrameIncomplete(funcsig);
74 78
 
@@ -176,7 +180,7 @@ AsmBlock* NMethodCall::reference(AsmGenerator& context)
176 180
 	throw new CompilerException("Unable to get reference to the result of a method call.");
177 181
 }
178 182
 
179  
-IType& NMethodCall::getExpressionType(AsmGenerator& context)
  183
+IType* NMethodCall::getExpressionType(AsmGenerator& context)
180 184
 {
181 185
 	// An method call has the type of the method's return type.
182 186
 	NFunctionDeclaration* funcdecl = (NFunctionDeclaration*)context.getFunction(this->id.name);
@@ -184,7 +188,7 @@ IType& NMethodCall::getExpressionType(AsmGenerator& context)
184 188
 	if (funcdecl == NULL)
185 189
 		throw new CompilerException("Called function was not found '" + this->id.name + "'.");
186 190
 
187  
-	return (NType&)funcdecl->type;
  191
+	return new NType(funcdecl->type);
188 192
 }
189 193
 
190 194
 
@@ -193,9 +197,6 @@ IType& NMethodCall::getExpressionType(AsmGenerator& context)
193 197
 /*  NFunctionSignature::calculateSignature() */
194 198
 std::string NMethodCall::calculateSignature(AsmGenerator& context)
195 199
 {
196  
-
197  
-
198  
-
199 200
 	std::string sig = "(";
200 201
 	for (ExpressionList::const_iterator i = this->arguments.begin(); i != this->arguments.end(); i++)
201 202
 	{
@@ -203,8 +204,8 @@ std::string NMethodCall::calculateSignature(AsmGenerator& context)
203 204
 		{
204 205
 			sig = sig + ",";
205 206
 		}
206  
-		NType type = (NType&)(*i)->getExpressionType(context);
207  
-		sig = sig + type.name;
  207
+		NType* type = (NType*)((*i)->getExpressionType(context));
  208
+		sig = sig + type->name;
208 209
 	}
209 210
 	sig = sig + ")";
210 211
 	return sig;
2  libdcpu-ci-lang-c/nodes/NMethodCall.h
@@ -30,7 +30,7 @@ class NMethodCall : public NExpression
30 30
 		NMethodCall(const NIdentifier& id) : id(id), NExpression("methodcall") { }
31 31
 		virtual AsmBlock* compile(AsmGenerator& context);
32 32
 		virtual AsmBlock* reference(AsmGenerator& context);
33  
-		virtual IType& getExpressionType(AsmGenerator& context);
  33
+		virtual IType* getExpressionType(AsmGenerator& context);
34 34
 		virtual std::string calculateSignature(AsmGenerator& context);
35 35
 };
36 36
 
2  libdcpu-ci-lang-c/nodes/NPostIncDec.cpp
@@ -58,7 +58,7 @@ AsmBlock* NPostIncDec::reference(AsmGenerator& context)
58 58
 	throw new CompilerException("Unable to get reference to the result of an Post-Increment.");
59 59
 }
60 60
 
61  
-IType& NPostIncDec::getExpressionType(AsmGenerator& context)
  61
+IType* NPostIncDec::getExpressionType(AsmGenerator& context)
62 62
 {
63 63
 	// An assignment has the type of it's LHS.
64 64
 	return this->expr.getExpressionType(context);
2  libdcpu-ci-lang-c/nodes/NPostIncDec.h
@@ -25,7 +25,7 @@ class NPostIncDec : public NExpression
25 25
 			expr(expr), op(op), NExpression("postincdec") { }
26 26
 		virtual AsmBlock* compile(AsmGenerator& context);
27 27
 		virtual AsmBlock* reference(AsmGenerator& context);
28  
-		virtual IType& getExpressionType(AsmGenerator& context);
  28
+		virtual IType* getExpressionType(AsmGenerator& context);
29 29
 };
30 30
 
31 31
 #endif
2  libdcpu-ci-lang-c/nodes/NPreIncDec.cpp
@@ -61,7 +61,7 @@ AsmBlock* NPreIncDec::reference(AsmGenerator& context)
61 61
 	throw new CompilerException("Unable to get reference to the result of an Pre-Increment.");
62 62
 }
63 63
 
64  
-IType& NPreIncDec::getExpressionType(AsmGenerator& context)
  64
+IType* NPreIncDec::getExpressionType(AsmGenerator& context)
65 65
 {
66 66
 	// An assignment has the type of it's LHS.
67 67
 	return this->expr.getExpressionType(context);
2  libdcpu-ci-lang-c/nodes/NPreIncDec.h
@@ -25,7 +25,7 @@ class NPreIncDec : public NExpression
25 25
 			expr(expr), op(op), NExpression("preincdec") { }
26 26
 		virtual AsmBlock* compile(AsmGenerator& context);
27 27
 		virtual AsmBlock* reference(AsmGenerator& context);
28  
-		virtual IType& getExpressionType(AsmGenerator& context);
  28
+		virtual IType* getExpressionType(AsmGenerator& context);
29 29
 };
30 30
 
31 31
 #endif
6  libdcpu-ci-lang-c/nodes/NString.cpp
@@ -43,10 +43,10 @@ AsmBlock* NString::reference(AsmGenerator& context)
43 43
 	throw new CompilerException("Unable to get reference to the result of a string literal.");
44 44
 }
45 45
 
46  
-IType& NString::getExpressionType(AsmGenerator& context)
  46
+IType* NString::getExpressionType(AsmGenerator& context)
47 47
 {
48 48
 	// A string has the type char*.
49  
-	NType t = NType(NInteger::CharType);
50  
-	t.pointerCount += 1;
  49
+	NType* t = new NType(NInteger::CharType);
  50
+	t->pointerCount += 1;
51 51
 	return t;
52 52
 }
2  libdcpu-ci-lang-c/nodes/NString.h
@@ -23,7 +23,7 @@ class NString : public NExpression
23 23
 		NString(std::string value) : value(value), NExpression("string") { }
24 24
 		virtual AsmBlock* compile(AsmGenerator& context);
25 25
 		virtual AsmBlock* reference(AsmGenerator& context);
26  
-		virtual IType& getExpressionType(AsmGenerator& context);
  26
+		virtual IType* getExpressionType(AsmGenerator& context);
27 27
 };
28 28
 
29 29
 #endif
8  libdcpu-ci-lang-c/nodes/NStructureResolutionOperator.cpp
@@ -52,14 +52,14 @@ AsmBlock* NStructureResolutionOperator::reference(AsmGenerator& context)
52 52
 		throw new CompilerException("Unable to use AST node " + this->lhs.cType + " as part of the structure resolution operator; it is not a suitable left-value.");
53 53
 
54 54
 	// Ensure the LHS expression is actually a structure type.
55  
-	NType& t = (NType&)this->lhs.getExpressionType(context);
  55
+	NType* t = (NType*)this->lhs.getExpressionType(context);
56 56
 
57  
-	if (!t.isStruct)
  57
+	if (!t->isStruct)
58 58
 		throw new CompilerException("Unable to use AST node " + this->lhs.cType + " as part of the structure resolution operator; the resulting type is not a structure.");
59 59
 
60 60
 	// We need to work out at what offset is the RHS identifier
61 61
 	// in the structure.
62  
-	uint16_t pos = t.getStructFieldPosition(context, this->rhs.name);
  62
+	uint16_t pos = t->getStructFieldPosition(context, this->rhs.name);
63 63
 
64 64
 	// Evaluate the LHS, placing a reference to it's position on the stack.
65 65
 	AsmBlock* lhs = this->lhs.reference(context);
@@ -73,7 +73,7 @@ AsmBlock* NStructureResolutionOperator::reference(AsmGenerator& context)
73 73
 	return block;
74 74
 }
75 75
 
76  
-IType& NStructureResolutionOperator::getExpressionType(AsmGenerator& context)
  76
+IType* NStructureResolutionOperator::getExpressionType(AsmGenerator& context)
77 77
 {
78 78
 	// A structure resolution operator has the type of it's field.
79 79
 	throw new CompilerException("Unable to resolve type for structure resolution operator.");
2  libdcpu-ci-lang-c/nodes/NStructureResolutionOperator.h
@@ -28,7 +28,7 @@ class NStructureResolutionOperator : public NExpression
28 28
 			lhs(lhs), rhs(rhs), isDereference(isDereference), NExpression("field") { }
29 29
 		virtual AsmBlock* compile(AsmGenerator& context);
30 30
 		virtual AsmBlock* reference(AsmGenerator& context);
31  
-		virtual IType& getExpressionType(AsmGenerator& context);
  31
+		virtual IType* getExpressionType(AsmGenerator& context);
32 32
 };
33 33
 
34 34
 #endif
4  libdcpu-ci-lang-c/nodes/NType.cpp
@@ -108,10 +108,10 @@ uint16_t NType::getStructFieldPosition(AsmGenerator& context, std::string name)
108 108
 	throw new CompilerException("Unable to lookup field " + name + " in structure " + this->resolvedStruct->id.name + "!");
109 109
 }
110 110
 
111  
-IType& NType::getExpressionType(AsmGenerator& context)
  111
+IType* NType::getExpressionType(AsmGenerator& context)
112 112
 {
113 113
 	// Types are of type type ;)
114  
-	return NType::TypeType;
  114
+	return new NType(NType::TypeType);
115 115
 }
116 116
 
117 117
 bool NType::operator==(const NType& other) const
7  libdcpu-ci-lang-c/nodes/NType.h
@@ -23,24 +23,25 @@ class NStructureDeclaration;
23 23
 class NType : public NIdentifier, public IType
24 24
 {
25 25
 	private:
  26
+		std::string _name;
26 27
 		void resolveStruct(AsmGenerator& context);
27 28
 
28 29
 	protected:
29 30
 		NType(std::string classifier, const std::string& name, unsigned int pointerCount, bool isStruct) :
30  
-			pointerCount(pointerCount), isStruct(isStruct), resolvedStruct(NULL), NIdentifier(name, "type-" + classifier) { }
  31
+			pointerCount(pointerCount), isStruct(isStruct), resolvedStruct(NULL), _name(name), NIdentifier(name, "type-" + classifier) { }
31 32
 
32 33
 	public:
33 34
 		unsigned int pointerCount;
34 35
 		bool isStruct;
35 36
 		NStructureDeclaration* resolvedStruct;
36 37
 		NType(const std::string& name, unsigned int pointerCount, bool isStruct) :
37  
-			pointerCount(pointerCount), isStruct(isStruct), resolvedStruct(NULL), NIdentifier(name, "type") { }
  38
+			pointerCount(pointerCount), isStruct(isStruct), resolvedStruct(NULL), _name(name), NIdentifier(name, "type") { }
38 39
 		uint16_t getStructFieldPosition(AsmGenerator& context, std::string name);
39 40
 		size_t getBitSize(AsmGenerator& context);
40 41
 		virtual uint16_t getWordSize(AsmGenerator& context);
41 42
 		virtual AsmBlock* compile(AsmGenerator& context);
42 43
 		virtual AsmBlock* reference(AsmGenerator& context);
43  
-		virtual IType& getExpressionType(AsmGenerator& context);
  44
+		virtual IType* getExpressionType(AsmGenerator& context);
44 45
 
45 46
 		// Operator overloads.
46 47
 		bool operator==(const NType& other) const;
8  libdcpu-ci-lang-c/nodes/NUnaryOperator.cpp
@@ -76,10 +76,8 @@ AsmBlock* NUnaryOperator::reference(AsmGenerator& context)
76 76
 	throw new CompilerException("Unable to get reference to the result of an unary operator.");
77 77
 }
78 78
 
79  
-IType& NUnaryOperator::getExpressionType(AsmGenerator& context)
  79
+IType* NUnaryOperator::getExpressionType(AsmGenerator& context)
80 80
 {
81  
-	// A binary operator has the type of each of it's expressions.
82  
-	NType rType = (NType&)this->rhs.getExpressionType(context);
83  
-
84  
-	return rType;
  81
+	// A unary operator has the type of it's expression.
  82
+	return this->rhs.getExpressionType(context);
85 83
 }
2  libdcpu-ci-lang-c/nodes/NUnaryOperator.h
@@ -25,7 +25,7 @@ class NUnaryOperator : public NExpression
25 25
 			op(op), rhs(rhs), NExpression("unaryop") { }
26 26
 		virtual AsmBlock* compile(AsmGenerator& context);
27 27
 		virtual AsmBlock* reference(AsmGenerator& context);
28  
-		virtual IType& getExpressionType(AsmGenerator& context);
  28
+		virtual IType* getExpressionType(AsmGenerator& context);
29 29
 };
30 30
 
31 31
 #endif
3  libdcpu-ci-lang/nodes/IType.h
@@ -15,12 +15,13 @@
15 15
 #define __DCPU_COMP_INTERFACES_TYPE_H
16 16
 
17 17
 #include <stdint.h>
  18
+#include "../CompilerException.h"
18 19
 #include "../AsmGenerator.h"
19 20
 
20 21
 class IType
21 22
 {
22 23
 	public:
23  
-		virtual uint16_t getWordSize(AsmGenerator& context) = 0;
  24
+		virtual uint16_t getWordSize(AsmGenerator& context) { throw new CompilerException("Unable to get word size of unspecified type (internal error)."); }
24 25
 };
25 26
 
26 27
 #endif

0 notes on commit 4764891

Please sign in to comment.
Something went wrong with that request. Please try again.