Selaa lähdekoodia

Fixed more function pointer issues.
Fixed Var variable handling with slices.

woollybah 10 vuotta sitten
vanhempi
commit
9fdff00300
3 muutettua tiedostoa jossa 55 lisäystä ja 35 poistoa
  1. 10 3
      ctranslator.bmx
  2. 37 30
      decl.bmx
  3. 8 2
      expr.bmx

+ 10 - 3
ctranslator.bmx

@@ -323,8 +323,11 @@ Type TCTranslator Extends TTranslator
 							t:+ TInvokeExpr(args[i]).Trans()
 							t:+ TInvokeExpr(args[i]).Trans()
 						Else
 						Else
 							' need to test scopes to see if we need to use the current instance's function or not
 							' need to test scopes to see if we need to use the current instance's function or not
-							Local fdecl:TFuncDecl = TInvokeExpr(args[i]).decl
-							mungdecl fdecl
+							' use the "actual", not the copy we made for the function pointer.
+							Local fdecl:TFuncDecl = TFuncDecl(TInvokeExpr(args[i]).decl.actual)
+							If Not fdecl.munged Then
+								MungDecl fdecl
+							End If
 
 
 							If TClassDecl(fdecl.scope) Then
 							If TClassDecl(fdecl.scope) Then
 								' current scope is related to function scope?
 								' current scope is related to function scope?
@@ -349,7 +352,11 @@ Type TCTranslator Extends TTranslator
 					End If
 					End If
 					' some cases where we are passing a function pointer via a void* parameter.
 					' some cases where we are passing a function pointer via a void* parameter.
 					If TCastExpr(args[i]) And TInvokeExpr(TCastExpr(args[i]).expr) And Not TInvokeExpr(TCastExpr(args[i]).expr).invokedWithBraces Then
 					If TCastExpr(args[i]) And TInvokeExpr(TCastExpr(args[i]).expr) And Not TInvokeExpr(TCastExpr(args[i]).expr).invokedWithBraces Then
-						t:+ TInvokeExpr(TCastExpr(args[i]).expr).decl.munged
+						If Not TInvokeExpr(TCastExpr(args[i]).expr).decl.munged Then
+							t:+ TInvokeExpr(TCastExpr(args[i]).expr).decl.actual.munged
+						Else
+							t:+ TInvokeExpr(TCastExpr(args[i]).expr).decl.munged
+						End If
 						Continue
 						Continue
 					End If
 					End If
 
 

+ 37 - 30
decl.bmx

@@ -76,7 +76,7 @@ Type TDecl
 		actual=Self
 		actual=Self
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl() Abstract
+	Method OnCopy:TDecl(deep:Int = True) Abstract
 	
 	
 	Method ToString$()
 	Method ToString$()
 		If TClassDecl( scope ) Return scope.ToString()+"."+ident
 		If TClassDecl( scope ) Return scope.ToString()+"."+ident
@@ -140,8 +140,8 @@ Type TDecl
 		EndIf
 		EndIf
 	End Method
 	End Method
 
 
-	Method Copy:TDecl()
-		Local t:TDecl=OnCopy()
+	Method Copy:TDecl(deep:Int = True)
+		Local t:TDecl=OnCopy(deep)
 		t.munged=munged
 		t.munged=munged
 		t.errInfo=errInfo
 		t.errInfo=errInfo
 		Return t
 		Return t
@@ -382,7 +382,7 @@ Type TConstDecl Extends TValDecl
 		Return inst
 		Return inst
 	End Method
 	End Method
 
 
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Return New TConstDecl.Create( ident,ty,CopyInit(), attrs )
 		Return New TConstDecl.Create( ident,ty,CopyInit(), attrs )
 	End Method
 	End Method
 	
 	
@@ -418,7 +418,7 @@ Type TLocalDecl Extends TVarDecl
 		Return Self
 		Return Self
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Return New TLocalDecl.Create( ident,ty,CopyInit(),attrs, generated )
 		Return New TLocalDecl.Create( ident,ty,CopyInit(),attrs, generated )
 	End Method
 	End Method
 	
 	
@@ -449,7 +449,7 @@ Type TArgDecl Extends TLocalDecl
 		Return inst
 		Return inst
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Local d:TArgDecl = New TArgDecl.Create( ident,ty,CopyInit(),attrs,generated )
 		Local d:TArgDecl = New TArgDecl.Create( ident,ty,CopyInit(),attrs,generated )
 		d.ty = d.declTy
 		d.ty = d.declTy
 		d.init = d.declInit
 		d.init = d.declInit
@@ -476,7 +476,7 @@ Type TGlobalDecl Extends TVarDecl
 		Return Self
 		Return Self
 	End Method
 	End Method
 
 
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Return New TGlobalDecl.Create( ident,ty,CopyInit(),attrs )
 		Return New TGlobalDecl.Create( ident,ty,CopyInit(),attrs )
 	End Method
 	End Method
 	
 	
@@ -509,7 +509,7 @@ Type TFieldDecl Extends TVarDecl
 		Return Self
 		Return Self
 	End Method
 	End Method
 
 
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Return New TFieldDecl.Create( ident,ty,CopyInit(),attrs )
 		Return New TFieldDecl.Create( ident,ty,CopyInit(),attrs )
 	End Method
 	End Method
 	
 	
@@ -538,7 +538,7 @@ Type TAliasDecl Extends TDecl
 		Return Self
 		Return Self
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Return New TAliasDecl.Create( ident,decl,attrs )
 		Return New TAliasDecl.Create( ident,decl,attrs )
 	End Method
 	End Method
 	
 	
@@ -558,7 +558,7 @@ Type TScopeDecl Extends TDecl
 
 
 'Public
 'Public
 
 
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		InternalErr
 		InternalErr
 	End Method
 	End Method
 
 
@@ -793,9 +793,9 @@ End Rem
 		Return decl
 		Return decl
 	End Method
 	End Method
 	
 	
-	Method FindFuncDecl:TFuncDecl( ident$,argExprs:TExpr[] = Null,explicit:Int=False, isArg:Int = False )
+	Method FindFuncDecl:TFuncDecl( ident$,argExprs:TExpr[] = Null,explicit:Int=False, isArg:Int = False, isIdentExpr:Int = False )
 'DebugLog "FindFuncDecl : " + ident
 'DebugLog "FindFuncDecl : " + ident
-'If ident = "lua_pushcclosure" Then DebugStop
+'If ident = "FixPath" Then DebugStop
 		'Local funcs:TFuncDeclList=TFuncDeclList( FindDecl( ident ) )
 		'Local funcs:TFuncDeclList=TFuncDeclList( FindDecl( ident ) )
 		Local f:TDecl = TDecl(findDecl(ident))
 		Local f:TDecl = TDecl(findDecl(ident))
 		If Not f Then Return Null
 		If Not f Then Return Null
@@ -875,14 +875,17 @@ End Rem
 
 
 				Else If Not argDecls[i].init
 				Else If Not argDecls[i].init
 
 
-					' if this argument is missing and there isn't a default...
-					Err "Missing function parameter '" + argDecls[i].ident + "'"
-
-				Else
-					If func.attrs & FUNC_PTR Then
+					If (func.attrs & FUNC_PTR) Or isIdentExpr Then
 						exact=False
 						exact=False
 						Exit
 						Exit
 					End If
 					End If
+
+					' if this argument is missing and there isn't a default...
+					Err "Missing function parameter '" + argDecls[i].ident + "'"
+
+				Else ' for case of argdecls having default args
+					exact=False
+					If Not explicit Exit
 				EndIf
 				EndIf
 			
 			
 				possible=False
 				possible=False
@@ -979,11 +982,13 @@ Type TBlockDecl Extends TScopeDecl
 		stmts.AddLast stmt
 		stmts.AddLast stmt
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Local t:TBlockDecl=New TBlockDecl
 		Local t:TBlockDecl=New TBlockDecl
-		For Local stmt:TStmt=EachIn stmts
-			t.AddStmt stmt.Copy( t )
-		Next
+		If deep Then
+			For Local stmt:TStmt=EachIn stmts
+				t.AddStmt stmt.Copy( t )
+			Next
+		End If
 		t.extra = extra
 		t.extra = extra
 		t.generated = generated
 		t.generated = generated
 		Return t
 		Return t
@@ -1041,15 +1046,17 @@ Type TFuncDecl Extends TBlockDecl
 		Return Self
 		Return Self
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Local args:TArgDecl[]=argDecls[..]
 		Local args:TArgDecl[]=argDecls[..]
 		For Local i:Int=0 Until args.Length
 		For Local i:Int=0 Until args.Length
 			args[i]=TArgDecl( args[i].Copy() )
 			args[i]=TArgDecl( args[i].Copy() )
 		Next
 		Next
 		Local t:TFuncDecl=New TFuncDecl.CreateF( ident,retType,args,attrs )
 		Local t:TFuncDecl=New TFuncDecl.CreateF( ident,retType,args,attrs )
-		For Local stmt:TStmt=EachIn stmts
-			t.AddStmt stmt.Copy( t )
-		Next
+		If deep Then
+			For Local stmt:TStmt=EachIn stmts
+				t.AddStmt stmt.Copy( t )
+			Next
+		End If
 		t.retType = retType
 		t.retType = retType
 		t.scope = scope
 		t.scope = scope
 		t.overrides = overrides
 		t.overrides = overrides
@@ -1294,7 +1301,7 @@ Type TClassDecl Extends TScopeDecl
 		Return Self
 		Return Self
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		InternalErr
 		InternalErr
 	End Method
 	End Method
 	
 	
@@ -1457,7 +1464,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 )
+	Method FindFuncDecl:TFuncDecl( ident$,args:TExpr[] = Null ,explicit:Int=False, isArg:Int = False, isIdentExpr:Int = False )
 	
 	
 		If args = Null Then
 		If args = Null Then
 			args = New TExpr[0]
 			args = New TExpr[0]
@@ -1863,7 +1870,7 @@ Type TLoopLabelDecl Extends TDecl
 		Return Self
 		Return Self
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Return New TLoopLabelDecl.Create( ident,attrs )
 		Return New TLoopLabelDecl.Create( ident,attrs )
 	End Method
 	End Method
 	
 	
@@ -1882,7 +1889,7 @@ Type TDataLabelDecl Extends TDecl
 		Return Self
 		Return Self
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Return New TDataLabelDecl.Create( ident,attrs )
 		Return New TDataLabelDecl.Create( ident,attrs )
 	End Method
 	End Method
 	
 	
@@ -1905,7 +1912,7 @@ Type TDefDataDecl Extends TDecl
 		Return Self
 		Return Self
 	End Method
 	End Method
 	
 	
-	Method OnCopy:TDecl()
+	Method OnCopy:TDecl(deep:Int = True)
 		Return New TDefDataDecl.Create(TExpr.CopyArgs(data),TDataLabelDecl(label.Copy()),attrs)
 		Return New TDefDataDecl.Create(TExpr.CopyArgs(data),TDataLabelDecl(label.Copy()),attrs)
 	End Method
 	End Method
 
 

+ 8 - 2
expr.bmx

@@ -102,7 +102,7 @@ Type TExpr
 				If TInvokeExpr(args[i]) And Not TInvokeExpr(args[i]).invokedWithBraces Then
 				If TInvokeExpr(args[i]) And Not TInvokeExpr(args[i]).invokedWithBraces Then
 					TInvokeExpr(args[i]).exprType = New TFunctionPtrType
 					TInvokeExpr(args[i]).exprType = New TFunctionPtrType
 					Local cp:TDecl = TInvokeExpr(args[i]).decl
 					Local cp:TDecl = TInvokeExpr(args[i]).decl
-					TInvokeExpr(args[i]).decl = TFuncDecl(TInvokeExpr(args[i]).decl.Copy())
+					TInvokeExpr(args[i]).decl = TFuncDecl(TInvokeExpr(args[i]).decl.Copy(False))
 					TInvokeExpr(args[i]).decl.actual = cp
 					TInvokeExpr(args[i]).decl.actual = cp
 					TInvokeExpr(args[i]).decl.attrs :| FUNC_PTR
 					TInvokeExpr(args[i]).decl.attrs :| FUNC_PTR
 					TFunctionPtrType(TInvokeExpr(args[i]).exprType).func = TInvokeExpr(args[i]).decl
 					TFunctionPtrType(TInvokeExpr(args[i]).exprType).func = TInvokeExpr(args[i]).decl
@@ -1576,7 +1576,13 @@ Type TSliceExpr Extends TExpr
 		If TArrayType( expr.exprType ) Or TStringType( expr.exprType )
 		If TArrayType( expr.exprType ) Or TStringType( expr.exprType )
 			If from from=from.SemantAndCast( New TIntType )
 			If from from=from.SemantAndCast( New TIntType )
 			If term term=term.SemantAndCast( New TIntType )
 			If term term=term.SemantAndCast( New TIntType )
+
 			exprType=expr.exprType
 			exprType=expr.exprType
+			' remove var-ness
+			If exprType._flags & TType.T_VAR Then
+				exprType = exprType.Copy()
+				exprType._flags :~ TType.T_VAR
+			End If
 		Else
 		Else
 			Err "Slices can only be used on strings or arrays."
 			Err "Slices can only be used on strings or arrays."
 		EndIf
 		EndIf
@@ -1903,7 +1909,7 @@ Type TIdentExpr Extends TExpr
 		Local args:TExpr[]
 		Local args:TExpr[]
 		If rhs args=[rhs]
 		If rhs args=[rhs]
 
 
-		Local fdecl:TFuncDecl=scope.FindFuncDecl( ident,args, , isArg )
+		Local fdecl:TFuncDecl=scope.FindFuncDecl( ident,args, , isArg, True )
 
 
 		If fdecl
 		If fdecl
 			If _env.ModuleScope().IsStrict() And Not fdecl.IsProperty() And Not isArg And Not fdecl.maybeFunctionPtr Err "Identifier '"+ident+"' cannot be used in this way."
 			If _env.ModuleScope().IsStrict() And Not fdecl.IsProperty() And Not isArg And Not fdecl.maybeFunctionPtr Err "Identifier '"+ident+"' cannot be used in this way."