Browse Source

Fixed some struct related issues.
No longer require second arg for BBARRAYDATA().

woollybah 8 years ago
parent
commit
d9c561d155
3 changed files with 62 additions and 42 deletions
  1. 53 36
      ctranslator.bmx
  2. 5 0
      expr.bmx
  3. 4 6
      translator.bmx

+ 53 - 36
ctranslator.bmx

@@ -458,7 +458,7 @@ Type TCTranslator Extends TTranslator
 		If objParam And (decl.IsMethod() Or decl.isCtor()) And ((Not decl.IsExtern()) Or (decl.IsExtern() And TClassDecl(decl.scope) And Not TClassDecl(decl.scope).IsStruct())) Then
 		If objParam And (decl.IsMethod() Or decl.isCtor()) And ((Not decl.IsExtern()) Or (decl.IsExtern() And TClassDecl(decl.scope) And Not TClassDecl(decl.scope).IsStruct())) Then
 			' object cast to match param type
 			' object cast to match param type
 			If TClassDecl(decl.scope) Then
 			If TClassDecl(decl.scope) Then
-				t :+ Bra(TransObject(TClassDecl(decl.scope).GetLatestFuncDecl(decl).scope))
+				t :+ Bra(TransObject(TClassDecl(decl.scope).GetLatestFuncDecl(decl).scope, TClassDecl(decl.scope).IsStruct()))
 			End If
 			End If
 			t:+ objParam
 			t:+ objParam
 		End If
 		End If
@@ -1186,40 +1186,52 @@ t:+"NULLNULLNULL"
 					End If
 					End If
 
 
 				Else If TIndexExpr(lhs) Then
 				Else If TIndexExpr(lhs) Then
-					Local lvar:String = CreateLocal(lhs, False, False)
-					Local lvarInit:String = Bra(lvar + " = " + lhs.Trans())
-				
-'					Local loc:String = CreateLocal(lhs)
-					Local obj:String = Bra(TransObject(decl.scope))
-
-					Local cdecl:TClassDecl = TClassDecl(decl.scope)
-
-					' Null test
-					If opt_debug Then
-						lvarInit = TransDebugNullObjectError(lvarInit, cdecl)
-					End If
-
-					If decl.attrs & FUNC_PTR Then
-						Local op:String
-						If cdecl.IsStruct() Then op = "." Else op = "->"
-						Return lhs.Trans() + op + decl.munged+TransArgs( args,decl, Null)
-					Else
-						If decl.scope.IsExtern()
-							'Local cdecl:TClassDecl = TClassDecl(decl.scope)
-							
-							If Not cdecl.IsStruct()  Then
-								Return Bra(lvarInit) + "->vtbl->" + decl.munged + Bra(TransArgs( args,decl, lvar ))
-							End If
-							Err "TODO extern types not allowed methods"
+					If TClassDecl(decl.scope) And TClassDecl(decl.scope).IsStruct() Then
+					
+						Local lvar:String = CreateLocal(lhs, True, False)
+					
+						If Not isPointerType(lhs.exprType) Then
+							Return "_" + decl.munged+TransArgs( args,decl, "&" + lvar )
 						Else
 						Else
-							'Local cdecl:TClassDecl = TClassDecl(decl.scope)
+							Return "_" + decl.munged+TransArgs( args,decl, lvar )
+						End If
+					Else
+						Local lvar:String = CreateLocal(lhs, False, False)
+						Local lvarInit:String = Bra(lvar + " = " + lhs.Trans())
+					
+	'					Local loc:String = CreateLocal(lhs)
+						Local obj:String = Bra(TransObject(decl.scope))
 	
 	
-							If cdecl And (cdecl.IsInterface() And Not equalsBuiltInFunc(cdecl, decl)) Then
-								Local ifc:String = Bra("(struct " + cdecl.munged + "_methods*)" + Bra("bbObjectInterface(" + obj + lvarInit + ", " + "&" + cdecl.munged + "_ifc)"))
-								Return ifc + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
-							Else					
-								Local class:String = Bra(lvarInit + "->clas" + tSuper)
-								Return class + "->" + TransFuncPrefix(decl.scope, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
+						Local cdecl:TClassDecl = TClassDecl(decl.scope)
+	
+
+						' Null test
+						If opt_debug Then
+							lvarInit = TransDebugNullObjectError(lvarInit, cdecl)
+						End If
+	
+						If decl.attrs & FUNC_PTR Then
+							Local op:String
+							If cdecl.IsStruct() Then op = "." Else op = "->"
+							Return lhs.Trans() + op + decl.munged+TransArgs( args,decl, Null)
+						Else
+							If decl.scope.IsExtern()
+								'Local cdecl:TClassDecl = TClassDecl(decl.scope)
+								
+								If Not cdecl.IsStruct()  Then
+									Return Bra(lvarInit) + "->vtbl->" + decl.munged + Bra(TransArgs( args,decl, lvar ))
+								End If
+								Err "TODO extern types not allowed methods"
+							Else
+								'Local cdecl:TClassDecl = TClassDecl(decl.scope)
+		
+								If cdecl And (cdecl.IsInterface() And Not equalsBuiltInFunc(cdecl, decl)) Then
+									Local ifc:String = Bra("(struct " + cdecl.munged + "_methods*)" + Bra("bbObjectInterface(" + obj + lvarInit + ", " + "&" + cdecl.munged + "_ifc)"))
+									Return ifc + "->" + TransFuncPrefix(cdecl, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
+								Else					
+									Local class:String = Bra(lvarInit + "->clas" + tSuper)
+									Return class + "->" + TransFuncPrefix(decl.scope, decl) + FuncDeclMangleIdent(decl)+TransArgs( args,decl, lvar )
+								End If
 							End If
 							End If
 						End If
 						End If
 					End If
 					End If
@@ -1621,6 +1633,11 @@ t:+"NULLNULLNULL"
 	End Method
 	End Method
 
 
 	Method TransSelfExpr$( expr:TSelfExpr )
 	Method TransSelfExpr$( expr:TSelfExpr )
+		If (TObjectType(expr.exprType) And TObjectType(expr.exprType).classDecl.IsStruct()) Or ..
+				(TClassType(expr.exprType) And TClassType(expr.exprType).classDecl.IsStruct()) Then
+			Return "*o"
+		End If
+		
 		Return "o"
 		Return "o"
 	End Method
 	End Method
 
 
@@ -1682,7 +1699,7 @@ t:+"NULLNULLNULL"
 		Else If IsPointerType( dst, 0, TType.T_POINTER | TType.T_CHAR_PTR | TType.T_SHORT_PTR )
 		Else If IsPointerType( dst, 0, TType.T_POINTER | TType.T_CHAR_PTR | TType.T_SHORT_PTR )
 
 
 			If TArrayType(src) Then
 			If TArrayType(src) Then
-				Return Bra(Bra(TransType(dst, "")) + "BBARRAYDATA(" + t + "," + t + "->dims)")
+				Return Bra(Bra(TransType(dst, "")) + "BBARRAYDATA(" + t + ",1)")
 			End If
 			End If
 			'If TByteType(src) And Not IsPointerType(src, TType.T_BYTE, TType.T_POINTER) Return Bra("&"+t)
 			'If TByteType(src) And Not IsPointerType(src, TType.T_BYTE, TType.T_POINTER) Return Bra("&"+t)
 
 
@@ -2201,13 +2218,13 @@ t:+"NULLNULLNULL"
 				If opt_debug Then
 				If opt_debug Then
 					Return Bra(Bra(TransType(TArrayType( expr.expr.exprType).elemType, "*")) + Bra("BBARRAYDATAINDEX(" + Bra(t_expr) + "," + Bra(t_expr) + "->dims," + t_index + ")")) + "[" + t_index + "]"
 					Return Bra(Bra(TransType(TArrayType( expr.expr.exprType).elemType, "*")) + Bra("BBARRAYDATAINDEX(" + Bra(t_expr) + "," + Bra(t_expr) + "->dims," + t_index + ")")) + "[" + t_index + "]"
 				Else
 				Else
-					Return Bra(Bra(TransType(TArrayType( expr.expr.exprType).elemType, "*")) + Bra("BBARRAYDATA(" + Bra(t_expr) + "," + Bra(t_expr) + "->dims)")) + "[" + t_index + "]"
+					Return Bra(Bra(TransType(TArrayType( expr.expr.exprType).elemType, "*")) + Bra("BBARRAYDATA(" + t_expr + ",1)")) + "[" + t_index + "]"
 				End If
 				End If
 			Else
 			Else
 				If opt_debug Then
 				If opt_debug Then
 					Return Bra("(" + TransType(expr.exprType, "") + "*)BBARRAYDATAINDEX(" + Bra(t_expr) + "," + Bra(t_expr) + "->dims," + t_index + ")") + "[" + t_index + "]"
 					Return Bra("(" + TransType(expr.exprType, "") + "*)BBARRAYDATAINDEX(" + Bra(t_expr) + "," + Bra(t_expr) + "->dims," + t_index + ")") + "[" + t_index + "]"
 				Else
 				Else
-					Return Bra("(" + TransType(expr.exprType, "") + "*)BBARRAYDATA(" + Bra(t_expr) + "," + Bra(t_expr) + "->dims)") + "[" + t_index + "]"
+					Return Bra("(" + TransType(expr.exprType, "") + "*)BBARRAYDATA(" + t_expr + ",1)") + "[" + t_index + "]"
 				End If
 				End If
 			End If
 			End If
 		End If
 		End If

+ 5 - 0
expr.bmx

@@ -289,6 +289,11 @@ Type TExpr
 			End If
 			End If
 			
 			
 		End If
 		End If
+		' balance structs
+		If TObjectType( lhs ).EqualsType(rhs) And TObjectType( lhs ).classDecl.IsStruct() And TObjectType( rhs ).classDecl.IsStruct() Then
+			Return lhs
+		End If
+		
 		Err "Can't balance types "+lhs.ToString()+" and "+rhs.ToString()+"."
 		Err "Can't balance types "+lhs.ToString()+" and "+rhs.ToString()+"."
 	End Method
 	End Method
 
 

+ 4 - 6
translator.bmx

@@ -898,7 +898,7 @@ End Rem
 	
 	
 	Method TransInvokeExpr$( expr:TInvokeExpr )
 	Method TransInvokeExpr$( expr:TInvokeExpr )
 		Local decl:TFuncDecl=TFuncDecl( expr.decl.actual ),t$
 		Local decl:TFuncDecl=TFuncDecl( expr.decl.actual ),t$
-'If decl.ident = "OnDebugStop" DebugStop	
+
 		If Not decl.munged Then
 		If Not decl.munged Then
 			MungDecl decl
 			MungDecl decl
 		End If
 		End If
@@ -921,7 +921,7 @@ End Rem
 				Return CreateLocal(expr)
 				Return CreateLocal(expr)
 			End If
 			End If
 		Else
 		Else
-			If decl Return TransFunc( TFuncDecl(decl),expr.args,Null )
+			Return TransFunc( TFuncDecl(decl),expr.args,Null )
 		End If
 		End If
 		
 		
 		InternalErr
 		InternalErr
@@ -938,7 +938,7 @@ End Rem
 				Return CreateLocal(expr)
 				Return CreateLocal(expr)
 			End If
 			End If
 		Else
 		Else
-			If decl Return TransFunc( TFuncDecl(decl),expr.args,expr.expr )	
+			Return TransFunc( TFuncDecl(decl),expr.args,expr.expr )	
 		End If
 		End If
 		
 		
 		InternalErr
 		InternalErr
@@ -1009,9 +1009,7 @@ End Rem
 
 
 			Else
 			Else
 				
 				
-				If TSelfExpr(stmt.expr) And TObjectType(TSelfExpr(stmt.expr).exprType).classDecl And TObjectType(TSelfExpr(stmt.expr).exprType).classDecl.IsStruct() Then
-					t :+ Bra("*" + stmt.expr.Trans())
-				Else If TObjectType(stmt.expr.exprType) And TObjectType(stmt.expr.exprType).classDecl.IsStruct() And TConstExpr(stmt.expr) And Not TConstExpr(stmt.expr).value Then
+				If TObjectType(stmt.expr.exprType) And TObjectType(stmt.expr.exprType).classDecl.IsStruct() And TConstExpr(stmt.expr) And Not TConstExpr(stmt.expr).value Then
 					Local lvar:String = CreateLocal(stmt.expr)
 					Local lvar:String = CreateLocal(stmt.expr)
 					t :+ " " + lvar
 					t :+ " " + lvar
 				Else
 				Else