Browse Source

Fixes a func find issue.
Improved array index expression handling.
Index expressions are now UInts.

woollybah 9 years ago
parent
commit
ac7b1ba368
6 changed files with 41 additions and 23 deletions
  1. 3 4
      ctranslator.bmx
  2. 7 3
      decl.bmx
  3. 20 14
      expr.bmx
  4. 1 1
      options.bmx
  5. 1 1
      parser.bmx
  6. 9 0
      translator.bmx

+ 3 - 4
ctranslator.bmx

@@ -33,8 +33,6 @@ Type TCTranslator Extends TTranslator
 	
 	
 	Field reserved_methods:String = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
 	Field reserved_methods:String = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
 	
 	
-	Field _inBinary:Int
-
 	Method New()
 	Method New()
 		_trans = Self
 		_trans = Self
 	End Method
 	End Method
@@ -761,6 +759,7 @@ t:+"NULLNULLNULL"
 				End If
 				End If
 
 
 				If TStmtExpr(lhs) Then
 				If TStmtExpr(lhs) Then
+					lhs.Trans()
 					lhs = TStmtExpr(lhs).expr
 					lhs = TStmtExpr(lhs).expr
 				End If
 				End If
 
 
@@ -1541,7 +1540,7 @@ t:+"NULLNULLNULL"
 	Method TransBinaryExpr$( expr:TBinaryExpr )
 	Method TransBinaryExpr$( expr:TBinaryExpr )
 		Local pri:Int=ExprPri( expr )
 		Local pri:Int=ExprPri( expr )
 		
 		
-		_inBinary = True
+		_inBinary :+ 1
 
 
 		Local t_lhs$=TransSubExpr( expr.lhs,pri )
 		Local t_lhs$=TransSubExpr( expr.lhs,pri )
 '		If TVarPtrType(expr.lhs.exprType) Then
 '		If TVarPtrType(expr.lhs.exprType) Then
@@ -1553,7 +1552,7 @@ t:+"NULLNULLNULL"
 '			t_rhs = "*" + t_rhs
 '			t_rhs = "*" + t_rhs
 '		End If
 '		End If
 
 
-		_inBinary = False
+		_inBinary :- 1
 		
 		
 		If expr.op = "+" Then
 		If expr.op = "+" Then
 			If TStringType(expr.exprType) Then
 			If TStringType(expr.exprType) Then

+ 7 - 3
decl.bmx

@@ -835,7 +835,7 @@ End Rem
 		Return decl
 		Return decl
 	End Method
 	End Method
 	
 	
-	Method FindFuncDecl:TFuncDecl( ident$,argExprs:TExpr[] = Null,explicit:Int=False, isArg:Int = False, isIdentExpr:Int = False )
+	Method FindFuncDecl:TFuncDecl( ident$,argExprs:TExpr[] = Null,explicit:Int=False, isArg:Int = False, isIdentExpr:Int = False, throwOnNotMatched:Int = False )
 'DebugLog "FindFuncDecl : " + ident
 'DebugLog "FindFuncDecl : " + ident
 'If ident = "FixPath" Then DebugStop
 'If ident = "FixPath" Then DebugStop
 		'Local funcs:TFuncDeclList=TFuncDeclList( FindDecl( ident ) )
 		'Local funcs:TFuncDeclList=TFuncDeclList( FindDecl( ident ) )
@@ -978,7 +978,11 @@ End Rem
 				If t t:+","
 				If t t:+","
 				If argExprs[i] t:+argExprs[i].exprType.ToString()
 				If argExprs[i] t:+argExprs[i].exprType.ToString()
 			Next
 			Next
-			Err "Unable to find overload for "+ident+"("+t+")."
+			If throwOnNotMatched Then
+				Throw "Unable to find overload for "+ident+"("+t+")."
+			Else
+				Err "Unable to find overload for "+ident+"("+t+")."
+			End If
 		EndIf
 		EndIf
 		
 		
 		match.AssertAccess
 		match.AssertAccess
@@ -1544,7 +1548,7 @@ End Rem
 		Return Super.GetDecl( ident )
 		Return Super.GetDecl( ident )
 	End Method
 	End Method
 	
 	
-	Method FindFuncDecl:TFuncDecl( ident$,args:TExpr[] = Null ,explicit:Int=False, isArg:Int = False, isIdentExpr:Int = False )
+	Method FindFuncDecl:TFuncDecl( ident$,args:TExpr[] = Null ,explicit:Int=False, isArg:Int = False, isIdentExpr:Int = False, throwOnNotMatched:Int = False )
 	
 	
 		If args = Null Then
 		If args = Null Then
 			args = New TExpr[0]
 			args = New TExpr[0]

+ 20 - 14
expr.bmx

@@ -313,6 +313,7 @@ Type TStmtExpr Extends TExpr
 	End Method
 	End Method
 
 
 	Method Copy:TExpr()
 	Method Copy:TExpr()
+		If exprType Return Self
 		Return New TStmtExpr.Create( stmt,CopyExpr(expr) )
 		Return New TStmtExpr.Create( stmt,CopyExpr(expr) )
 	End Method
 	End Method
 
 
@@ -1626,6 +1627,8 @@ Type TIndexExpr Extends TExpr
 	End Method
 	End Method
 
 
 	Method Copy:TExpr()
 	Method Copy:TExpr()
+		If exprType Return Self
+		
 		Local ind:TExpr[]
 		Local ind:TExpr[]
 		For Local i:Int = 0 Until index.length
 		For Local i:Int = 0 Until index.length
 			ind = ind + [CopyExpr(index[i])]
 			ind = ind + [CopyExpr(index[i])]
@@ -1638,11 +1641,7 @@ Type TIndexExpr Extends TExpr
 
 
 		expr=expr.Semant()
 		expr=expr.Semant()
 		For Local i:Int = 0 Until index.length
 		For Local i:Int = 0 Until index.length
-			If opt_arch = "x64" Then
-				index[i]=index[i].SemantAndCast( New TLongType )
-			Else
-				index[i]=index[i].SemantAndCast( New TIntType )
-			End If
+			index[i]=index[i].SemantAndCast( New TUIntType, True )
 		Next
 		Next
 
 
 		If TStringType( expr.exprType )
 		If TStringType( expr.exprType )
@@ -1654,27 +1653,25 @@ Type TIndexExpr Extends TExpr
 			exprType= TArrayType( expr.exprType ).elemType
 			exprType= TArrayType( expr.exprType ).elemType
 
 
 			If TArrayType( expr.exprType ).dims > 1 Then
 			If TArrayType( expr.exprType ).dims > 1 Then
+
 				' a multi-dimensional array of arrays is slightly more complex
 				' a multi-dimensional array of arrays is slightly more complex
 				If TArrayType(exprType) Then
 				If TArrayType(exprType) Then
 
 
 				'	Local tmpArr:TLocalDecl=New TLocalDecl.Create( "", NewPointerType(TType.T_ARRAY), expr )
 				'	Local tmpArr:TLocalDecl=New TLocalDecl.Create( "", NewPointerType(TType.T_ARRAY), expr )
 				'	Local stmt:TExpr = New TStmtExpr.Create( New TDeclStmt.Create( tmp ), Self ).Semant()
 				'	Local stmt:TExpr = New TStmtExpr.Create( New TDeclStmt.Create( tmp ), Self ).Semant()
 
 
-
-
-
 					Local sizeExpr:TExpr = New TArraySizeExpr.Create(expr, Null, index)
 					Local sizeExpr:TExpr = New TArraySizeExpr.Create(expr, Null, index)
 					index = [sizeExpr]
 					index = [sizeExpr]
-					Local tmp:TLocalDecl=New TLocalDecl.Create( "", NewPointerType(TType.T_INT), sizeExpr,,True )
+					Local tmp:TLocalDecl=New TLocalDecl.Create( "", NewPointerType(TType.T_UINT), sizeExpr,,True )
 					TArraySizeExpr(sizeExpr).val = tmp
 					TArraySizeExpr(sizeExpr).val = tmp
 					Local stmt:TExpr = New TStmtExpr.Create( New TDeclStmt.Create( tmp ), Self ).Semant()
 					Local stmt:TExpr = New TStmtExpr.Create( New TDeclStmt.Create( tmp ), Self ).Semant()
 					stmt.exprType = exprType
 					stmt.exprType = exprType
 
 
 					Return stmt
 					Return stmt
 				Else
 				Else
-					Local sizeExpr:TExpr = New TArraySizeExpr.Create(expr, Null, index)
+					Local sizeExpr:TExpr = New TArraySizeExpr.Create(expr, Null, index).Semant()
 					index = [sizeExpr]
 					index = [sizeExpr]
-					Local tmp:TLocalDecl=New TLocalDecl.Create( "", NewPointerType(TType.T_INT), sizeExpr,,True )
+					Local tmp:TLocalDecl=New TLocalDecl.Create( "", NewPointerType(TType.T_UINT), sizeExpr,,True )
 					TArraySizeExpr(sizeExpr).val = tmp
 					TArraySizeExpr(sizeExpr).val = tmp
 					Local stmt:TExpr = New TStmtExpr.Create( New TDeclStmt.Create( tmp ), Self ).Semant()
 					Local stmt:TExpr = New TStmtExpr.Create( New TDeclStmt.Create( tmp ), Self ).Semant()
 					stmt.exprType = exprType
 					stmt.exprType = exprType
@@ -1870,10 +1867,10 @@ Type TArraySizeExpr Extends TExpr
 		expr=expr.Semant()
 		expr=expr.Semant()
 		
 		
 		For Local i:Int = 0 Until index.length
 		For Local i:Int = 0 Until index.length
-			index[i]=index[i].SemantAndCast( New TIntType )
+			index[i]=index[i].SemantAndCast( New TUIntType )
 		Next
 		Next
 		
 		
-		exprType=NewPointerType(TType.T_INT)
+		exprType=NewPointerType(TType.T_UINT)
 		Return Self
 		Return Self
 	End Method
 	End Method
 
 
@@ -2146,7 +2143,16 @@ Type TIdentExpr Extends TExpr
 		_Semant
 		_Semant
 
 
 		'Local scope:TScopeDecl=IdentScope()
 		'Local scope:TScopeDecl=IdentScope()
-		Local fdecl:TFuncDecl=scope.FindFuncDecl( IdentLower(),args )
+		Local fdecl:TFuncDecl
+		Try
+			fdecl=scope.FindFuncDecl( IdentLower(),args,,,,True )
+		Catch errorMessage:String
+			If errorMessage.StartsWith("Compile Error") Then
+				Throw errorMessage
+			Else
+				' couldn't find an exact match, look elsewhere
+			End If
+		End Try
 
 
 		' if our scope is static, but the scope of the found function/method is not
 		' if our scope is static, but the scope of the found function/method is not
 		' then we should ignore it and continue looking higher up the scope stack.
 		' then we should ignore it and continue looking higher up the scope stack.

+ 1 - 1
options.bmx

@@ -25,7 +25,7 @@ SuperStrict
 
 
 Import "base.configmap.bmx"
 Import "base.configmap.bmx"
 
 
-Const version:String = "0.70"
+Const version:String = "0.71"
 
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1
 Const BUILDTYPE_MODULE:Int = 1

+ 1 - 1
parser.bmx

@@ -61,7 +61,7 @@ Type TForEachinStmt Extends TLoopStmt
 		If TArrayType( expr.exprType ) Or TStringType( expr.exprType )
 		If TArrayType( expr.exprType ) Or TStringType( expr.exprType )
 
 
 			Local exprTmp:TLocalDecl=New TLocalDecl.Create( "",Null,expr,,True )
 			Local exprTmp:TLocalDecl=New TLocalDecl.Create( "",Null,expr,,True )
-			Local indexTmp:TLocalDecl=New TLocalDecl.Create( "",Null,New TConstExpr.Create( New TIntType,"0" ),,True )
+			Local indexTmp:TLocalDecl=New TLocalDecl.Create( "",Null,New TConstExpr.Create( New TUIntType,"0" ),,True )
 
 
 			Local lenExpr:TExpr=New TIdentExpr.Create( "Length",New TVarExpr.Create( exprTmp ) )
 			Local lenExpr:TExpr=New TIdentExpr.Create( "Length",New TVarExpr.Create( exprTmp ) )
 
 

+ 9 - 0
translator.bmx

@@ -58,6 +58,8 @@ Type TTranslator
 	
 	
 	Field processingReturnStatement:Int
 	Field processingReturnStatement:Int
 
 
+	Field _inBinary:Int
+
 	Method PushVarScope()
 	Method PushVarScope()
 		varStack.Push customVarStack
 		varStack.Push customVarStack
 		customVarStack = New TStack
 		customVarStack = New TStack
@@ -275,6 +277,7 @@ Type TTranslator
 				TFunctionPtrType(TValDecl(decl).ty).func.munged = munged
 				TFunctionPtrType(TValDecl(decl).ty).func.munged = munged
 			End If
 			End If
 		End If
 		End If
+		
 	End Method
 	End Method
 
 
 Rem
 Rem
@@ -1175,7 +1178,9 @@ End Rem
 				Emit "}"
 				Emit "}"
 			EndIf
 			EndIf
 		Else If stmt.elseBlock.stmts.First()
 		Else If stmt.elseBlock.stmts.First()
+			_inBinary :+ 1
 			Emit "if"+Bra( stmt.expr.Trans() )+"{"
 			Emit "if"+Bra( stmt.expr.Trans() )+"{"
+			_inBinary :- 1
 			EmitLocalDeclarations(stmt.thenBlock)
 			EmitLocalDeclarations(stmt.thenBlock)
 			FreeVarsIfRequired(False)
 			FreeVarsIfRequired(False)
 			PushVarScope
 			PushVarScope
@@ -1199,8 +1204,10 @@ End Rem
 '					Emit "if"+Bra( stmt.expr.Trans() )+"{"
 '					Emit "if"+Bra( stmt.expr.Trans() )+"{"
 '				End If
 '				End If
 '			Else
 '			Else
+			_inBinary :+ 1
 				Emit "if"+Bra( stmt.expr.Trans() )+"{"
 				Emit "if"+Bra( stmt.expr.Trans() )+"{"
 				FreeVarsIfRequired(False)
 				FreeVarsIfRequired(False)
+			_inBinary :- 1
 '			End If
 '			End If
 			EmitLocalDeclarations(stmt.thenBlock)
 			EmitLocalDeclarations(stmt.thenBlock)
 			PushVarScope
 			PushVarScope
@@ -1242,7 +1249,9 @@ End Rem
 	Method TransWhileStmt$( stmt:TWhileStmt )
 	Method TransWhileStmt$( stmt:TWhileStmt )
 		Local nbroken:Int=broken
 		Local nbroken:Int=broken
 
 
+		_inBinary :+ 1
 		Emit "while"+Bra( stmt.expr.Trans() )+"{"
 		Emit "while"+Bra( stmt.expr.Trans() )+"{"
+		_inBinary :- 1
 		
 		
 		Local check:TTryBreakCheck = New TTryBreakCheck
 		Local check:TTryBreakCheck = New TTryBreakCheck
 		check.stmt = stmt
 		check.stmt = stmt