Bladeren bron

Merge branch 'master' into bcc_gen

woollybah 8 jaren geleden
bovenliggende
commit
14a3ae1096
7 gewijzigde bestanden met toevoegingen van 234 en 142 verwijderingen
  1. 28 7
      ctranslator.bmx
  2. 105 36
      decl.bmx
  3. 23 6
      expr.bmx
  4. 34 83
      iparser.bmx
  5. 1 1
      options.bmx
  6. 22 4
      parser.bmx
  7. 21 5
      stmt.bmx

+ 28 - 7
ctranslator.bmx

@@ -1208,7 +1208,7 @@ t:+"NULLNULLNULL"
 			End If
 
 			' ((brl_standardio_TCStandardIO_obj*)o->clas)->md_Read(o, xxx, xxx)
-		If decl.IsMethod() Then
+		If decl.IsMethod() Or decl.IsField() Then
 			If  Not (decl.attrs & FUNC_PTR) Then
 
 				Local class:String
@@ -1558,7 +1558,7 @@ t:+"NULLNULLNULL"
 					t = "_" + ctorMunged + "_ObjectNew" + TransArgs( expr.args,expr.ctor, "&" + expr.classDecl.actual.munged )
 				Else
 					If expr.classDecl.IsStruct() Then
-						t = "_" + ctorMunged + "_ObjectNew" + TransArgs( expr.args,expr.ctor)
+						t = ctorMunged + "_ObjectNew" + TransArgs( expr.args,expr.ctor)
 					Else
 						t = "_" + ctorMunged + "_ObjectNew" + TransArgs( expr.args,expr.ctor, "&" + expr.classDecl.actual.munged)
 					End If
@@ -2364,7 +2364,11 @@ t:+"NULLNULLNULL"
 				Emit s + "if (bbObjectDowncast(ex,&bbArrayClass) != &bbEmptyArray) {"
 				Emit TransType( c.init.ty, c.init.munged )+" "+ c.init.munged + "=(BBARRAY)ex;" 
 			Else If TObjectType(c.init.ty) Then
-				Emit s + "if (bbObjectDowncast(ex,&"+TObjectType(c.init.ty).classDecl.munged+") != &bbNullObject) {"
+				If TObjectType(c.init.ty).classDecl.IsInterface() Then
+					Emit s + "if (bbInterfaceDowncast(ex,&"+TObjectType(c.init.ty).classDecl.munged+"_ifc) != &bbNullObject) {"
+				Else
+					Emit s + "if (bbObjectDowncast(ex,&"+TObjectType(c.init.ty).classDecl.munged+") != &bbNullObject) {"
+				End If
 				Emit TransType( c.init.ty, c.init.munged )+" "+ c.init.munged + "=" + Bra(TransType( c.init.ty, c.init.munged )) + "ex;" 
 			Else
 				Err "Not an object"
@@ -4285,7 +4289,12 @@ End Rem
 		
 		For Local fdecl:TFuncDecl = EachIn newDecls
 		
-			EmitClassDeclNew(classDecl, fdecl)
+			If fdecl.scope <> classDecl Then
+				fdecl.Clear()
+				EmitClassDeclNew(classDecl, fdecl)
+			Else
+				EmitClassDeclNew(classDecl, fdecl)
+			End If
 
 			' generate "objectNew" function if required
 			If (fdecl.argDecls And fdecl.argDecls.length) Or classDecl.IsStruct() Then
@@ -4325,7 +4334,13 @@ End Rem
 			funcMunged = classDecl.munged + "_" + fdecl.ident + MangleMethod(fdecl)
 		End If
 
-		Local t:String = TransObject(classdecl) + " _" + funcMunged + "_ObjectNew"
+		Local t:String = TransObject(classdecl) + " "
+		
+		If Not classDecl.IsStruct() Then
+			t :+ "_"
+		End If
+		
+		t :+ funcMunged + "_ObjectNew"
 
 		'Find decl we override
 		Local odecl:TFuncDecl=fdecl
@@ -4451,7 +4466,11 @@ End Rem
 	
 	Method EmitClassDeclObjectNewProto(classDecl:TClassDecl, fdecl:TFuncDecl)
 
-		Local t:String = TransObject(classdecl) + " _"
+		Local t:String = TransObject(classdecl) + " "
+		
+		If Not classDecl.IsStruct() Then
+			t :+ "_"
+		End If
 		
 		If classDecl = fdecl.scope Then
 			t :+ fdecl.munged
@@ -4887,7 +4906,9 @@ End Rem
 		' functions
 		If Not classDecl.IsExtern() Then
 
-			Emit "-New()=" + Enquote("_" + classDecl.munged + "_New")
+			If Not classDecl.attrs & CLASS_INTERFACE Then
+				Emit "-New()=" + Enquote("_" + classDecl.munged + "_New")
+			End If
 			If classHierarchyHasFunction(classDecl, "Delete") Then
 				Emit "-Delete()=" + Enquote("_" + classDecl.munged + "_Delete")
 			End If

+ 105 - 36
decl.bmx

@@ -22,29 +22,29 @@
 '    distribution.
 '
 
-Const DECL_EXTERN:Int=      $010000
-Const DECL_PRIVATE:Int=     $020000
-Const DECL_ABSTRACT:Int=    $040000
-Const DECL_FINAL:Int=       $080000
+Const DECL_EXTERN:Int=        $010000
+Const DECL_PRIVATE:Int=       $020000
+Const DECL_ABSTRACT:Int=      $040000
+Const DECL_FINAL:Int=         $080000
 
-Const DECL_SEMANTED:Int=    $100000
-Const DECL_SEMANTING:Int=   $200000
+Const DECL_SEMANTED:Int=      $100000
+Const DECL_SEMANTING:Int=     $200000
 
-Const DECL_POINTER:Int=     $400000
+Const DECL_POINTER:Int=       $400000
 
-Const DECL_ARG:Int=         $800000
-Const DECL_INITONLY:Int=   $1000000
+Const DECL_ARG:Int=           $800000
+Const DECL_INITONLY:Int=     $1000000
 
-Const DECL_NODEBUG:Int=    $2000000
-Const DECL_PROTECTED:Int=  $4000000
+Const DECL_NODEBUG:Int=      $2000000
+Const DECL_PROTECTED:Int=    $4000000
 
 Const DECL_API_CDECL:Int=   $00000000
 Const DECL_API_STDCALL:Int= $10000000
-Const DECL_API_DEFAULT:Int= DECL_API_CDECL
+Const DECL_API_DEFAULT:Int=DECL_API_CDECL
 
-Const CLASS_INTERFACE:Int=  $001000
-Const CLASS_THROWABLE:Int=  $002000
-Const CLASS_STRUCT:Int=     $004000
+Const CLASS_INTERFACE:Int=    $002000
+Const CLASS_THROWABLE:Int=    $004000
+Const CLASS_STRUCT:Int=       $008000
 
 Const SCOPE_FUNC:Int = 0
 Const SCOPE_CLASS_LOCAL:Int = 1
@@ -303,6 +303,9 @@ Type TDecl
 	End Method
 	
 	Method OnSemant() Abstract
+	
+	Method Clear()
+	End Method
 
 End Type
 
@@ -493,6 +496,9 @@ Type TValDecl Extends TDecl
 		End If
 	End Method
 	
+	Method Clear()
+	End Method
+	
 End Type
 
 Type TConstDecl Extends TValDecl
@@ -556,7 +562,9 @@ Type TLocalDecl Extends TVarDecl
 	End Method
 	
 	Method OnCopy:TDecl(deep:Int = True)
-		Return New TLocalDecl.Create( ident,ty,CopyInit(),attrs, generated, volatile )
+		Local decl:TLocalDecl = New TLocalDecl.Create( ident,ty,CopyInit(),attrs &~ DECL_SEMANTED, generated, volatile )
+		decl.scope = scope
+		Return decl
 	End Method
 
 	Method GetDeclPrefix:String()
@@ -567,6 +575,10 @@ Type TLocalDecl Extends TVarDecl
 		Return GetDeclPrefix() + Super.ToString()
 	End Method
 
+	Method Clear()
+		done = False
+	End Method
+
 End Type
 
 Type TArgDecl Extends TLocalDecl
@@ -718,6 +730,9 @@ Type TAliasDecl Extends TDecl
 	Method OnSemant()
 	End Method
 	
+	Method Clear()
+	End Method
+	
 End Type
 
 Type TScopeDecl Extends TDecl
@@ -1500,6 +1515,9 @@ End Rem
 	Method OnSemant()
 	End Method
 	
+	Method Clear()
+	End Method
+
 End Type
 
 Type TBlockDecl Extends TScopeDecl
@@ -1521,6 +1539,7 @@ Type TBlockDecl Extends TScopeDecl
 	
 	Method OnCopy:TDecl(deep:Int = True)
 		Local t:TBlockDecl=New TBlockDecl
+		t.scope = scope
 		If deep Then
 			For Local stmt:TStmt=EachIn stmts
 				t.AddStmt stmt.Copy( t )
@@ -1545,6 +1564,12 @@ Type TBlockDecl Extends TScopeDecl
 		Return t
 	End Method
 
+	Method Clear()
+		For Local stmt:TStmt=EachIn stmts
+			stmt.Clear
+		Next
+	End Method
+
 End Type
 
 Const FUNC_METHOD:Int=   $0001			'mutually exclusive with ctor
@@ -1556,6 +1581,7 @@ Const FUNC_PTR:Int=      $0100
 Const FUNC_INIT:Int =    $0200
 Const FUNC_NESTED:Int =  $0400
 Const FUNC_OPERATOR:Int= $0800
+Const FUNC_FIELD:Int=    $1000
 
 'Fix! A func is NOT a block/scope!
 '
@@ -1698,7 +1724,11 @@ Type TFuncDecl Extends TBlockDecl
 	Method IsProperty:Int()
 		Return (attrs & FUNC_PROPERTY)<>0
 	End Method
-	
+
+	Method IsField:Int()
+		Return (attrs & FUNC_FIELD)<>0
+	End Method
+		
 	Method EqualsArgs:Int( decl:TFuncDecl ) ' careful, this is not commutative!
 		If argDecls.Length<>decl.argDecls.Length Return False
 		For Local i:Int=0 Until argDecls.Length
@@ -1733,6 +1763,12 @@ Type TFuncDecl Extends TBlockDecl
 
 		Local strictVoidToInt:Int = False
 
+		If isCtor() Or isDtor() Then
+			If ClassScope() And ClassScope().IsInterface() Then
+				Err ident + "() cannot be declared in an Interface."
+			End If
+		End If
+
 		'semant ret type
 		If Not retTypeExpr Then
 			If Not retType Then ' may have previously been set (if this is a function pointer)
@@ -1789,7 +1825,7 @@ Type TFuncDecl Extends TBlockDecl
 		'check for duplicate decl
 		If ident Then
 			For Local decl:TFuncDecl=EachIn scope.SemantedFuncs( ident )
-				If decl<>Self And EqualsArgs( decl )
+				If decl<>Self And EqualsArgs( decl ) And Not decl.IsCTOR()
 					Err "Duplicate declaration "+ToString()
 				EndIf
 				If noMangle Then
@@ -1862,25 +1898,11 @@ Type TFuncDecl Extends TBlockDecl
 							' check we aren't attempting to assign weaker access modifiers
 							If (IsProtected() And decl.IsPublic()) Or (IsPrivate() And (decl.IsProtected() Or decl.IsPublic())) Then
 							
-								Local p:String
-								If IsProtected() Then
-									p = "Protected"
-								Else
-									p = "Private"
-								End If
-								
-								Local dp:String
-								If decl.IsPublic() Then
-									dp = "Public"
-								Else
-									dp = "Protected"
-								End If
-							
-								Err ToString() + " clashes with " + decl.ToString() + ". Attempt to assign weaker access privileges ('" + p + "'), was '" + dp + "'."
+								Err PrivilegeError(Self, decl)
 							
 							End If
 						
-							If TObjectType(retType) And TObjectType(decl.retType ) Then
+							If (TObjectType(retType) And TObjectType(decl.retType )) Or (TArrayType(retType) And TArrayType(decl.retType)) Then
 								If Not retType.EqualsType( decl.retType ) And retType.ExtendsType( decl.retType ) Then
 									returnTypeSubclassed = True
 								End If
@@ -1962,13 +1984,56 @@ Type TFuncDecl Extends TBlockDecl
 		Return Super.CheckAccess()
 	End Method
 
+	Function PrivilegeError:String(decl:TFuncDecl, decl2:TFuncDecl)
+		Local p:String
+		If decl.IsProtected() Then
+			p = "Protected"
+		Else
+			p = "Private"
+		End If
+		
+		Local dp:String
+		If decl2.IsPublic() Then
+			dp = "Public"
+		Else
+			dp = "Protected"
+		End If
+	
+		Return decl.ToString() + " clashes with " + decl2.ToString() + ". Attempt to assign weaker access privileges ('" + p + "'), was '" + dp + "'."
+	End Function
+	
 End Type
 
 Type TNewDecl Extends TFuncDecl
 
 	Field chainedCtor:TNewExpr
 	
-	
+	Method OnCopy:TDecl(deep:Int = True)
+		Local args:TArgDecl[]=argDecls[..]
+		For Local i:Int=0 Until args.Length
+			args[i]=TArgDecl( args[i].Copy() )
+		Next
+		Local t:TNewDecl = TNewDecl(New TNewDecl.CreateF( ident,retType,args,attrs &~DECL_SEMANTED ))
+		If deep Then
+			For Local stmt:TStmt=EachIn stmts
+				t.AddStmt stmt.Copy( t )
+			Next
+		End If
+		t.retType = retType
+		t.scope = scope
+		t.overrides = overrides
+		t.superCtor = superCtor
+		t.castTo = castTo
+		t.noCastGen = noCastGen
+		t.munged = munged
+		t.metadata = metadata
+		t.mangled = mangled
+		t.noMangle = noMangle
+		t.chainedCtor = chainedCtor
+
+		Return  t
+	End Method
+
 
 End Type
 
@@ -2666,6 +2731,11 @@ End Rem
 							For Local decl2:TFuncDecl=EachIn cdecl.SemantedMethods( decl.ident )
 								' equals (or extends - for object types)
 								If decl2.EqualsFunc( decl )
+									If Not decl2.IsPublic() Then
+										' error on function decl
+										PushErr decl2.errInfo
+										Err TFuncDecl.PrivilegeError(decl2, decl)
+									End If
 									found=True
 									Exit
 								EndIf
@@ -2695,7 +2765,6 @@ End Rem
 	
 	Method CheckInterface(cdecl:TClassDecl, impls:TList)
 		While cdecl
-		
 			For Local decl:TFuncDecl=EachIn cdecl.SemantedMethods()
 				Local found:Int
 				For Local decl2:TFuncDecl=EachIn impls

+ 23 - 6
expr.bmx

@@ -920,10 +920,10 @@ Type TNewObjectExpr Extends TExpr
 				
 				' find other member decl (field, etc)
 				If Not errorDetails Then
-					Local decl:TVarDecl = TVarDecl(cdecl.GetDecl(id))
-					If decl Then
+					Local decl:TValDecl = TValDecl(cdecl.GetDecl(id))
+					If TVarDecl(decl) Then
 						Local tmp:TLocalDecl=New TLocalDecl.Create( "", eType, expr,, True )
-						Local varExpr:TExpr = New TMemberVarExpr.Create(New TVarExpr.Create( tmp ), decl).Semant()
+						Local varExpr:TExpr = New TMemberVarExpr.Create(New TVarExpr.Create( tmp ), TVarDecl(decl)).Semant()
 						expr = New TStmtExpr.Create( New TDeclStmt.Create( tmp ), varExpr ).Semant()
 						eType = decl.ty
 						If TObjectType(eType) Then
@@ -934,6 +934,12 @@ Type TNewObjectExpr Extends TExpr
 						End If
 						Continue
 					End If
+					If TConstDecl(decl) Then
+						decl.Semant()
+						expr = New TConstExpr.Create(decl.ty, TConstDecl(decl).value).Semant()
+						eType = decl.ty
+						Continue
+					End If
 				End If	
 
 				' didn't match member or function??
@@ -1486,7 +1492,6 @@ Type TCastExpr Extends TExpr
 
 	Method Eval$()
 		Local val$=expr.Eval()
-		If Not val Return val
 		If TBoolType( exprType )
 			If TIntegralType(expr.exprType)
 				If Long( val ) Return "1"
@@ -1527,6 +1532,10 @@ Type TCastExpr Extends TExpr
 		Else If TFloat64Type( exprType )
 			Return Float( val )
 		Else If TStringType( exprType )
+			If TBoolType( expr.exprType )
+				If val Return "1"
+				Return "0"
+			EndIf
 			Return String( val )
 		Else If TByteType( exprType )
 			Return Byte( val )
@@ -1584,8 +1593,16 @@ Type TUnaryExpr Extends TExpr
 				exprType._flags :~ TType.T_VAR
 			End If
 		Case "~~"
-			expr=expr.SemantAndCast( New TIntType )
-			exprType=New TIntType
+			expr=expr.Semant()
+			If Not TIntegralType(expr.exprType) Or IsPointerType(expr.exprType) Then
+				Err "Bitwise complement can only be used with integers"
+			End If
+			If TByteType(expr.exprType) Or TShortType(expr.exprType) Then
+				expr=expr.SemantAndCast( New TIntType )
+				exprType=New TIntType
+			Else
+				exprType = expr.exprType
+			End If
 		Case "not"
 			expr=expr.SemantAndCast( New TBoolType,CAST_EXPLICIT )
 			exprType=New TBoolType

+ 34 - 83
iparser.bmx

@@ -853,89 +853,35 @@ Type TIParser
 			fdecl = ParseFuncDecl("", attrs, retTy)
 			ty = retTy
 		End If
-		
-		Repeat		
-			If CParse( "F" )
-				attrs:|DECL_FINAL
-			Else If CParse( "FW" )
-				attrs:|DECL_FINAL | DECL_API_STDCALL
-			Else If CParse( "FP" )
-				attrs:|DECL_FINAL|DECL_PRIVATE
-			Else If CParse( "FPW" )
-				attrs:|DECL_FINAL|DECL_PRIVATE | DECL_API_STDCALL
-			Else If CParse( "FR" )
-				attrs:|DECL_FINAL|DECL_PROTECTED
-			Else If CParse( "FRW" )
-				attrs:|DECL_FINAL|DECL_PROTECTED | DECL_API_STDCALL
-			Else If CParse( "A" )
-				attrs:|DECL_ABSTRACT
-			Else If CParse( "AW" )
-				attrs:|DECL_ABSTRACT | DECL_API_STDCALL
-			Else If CParse( "AP" )
-				attrs:|DECL_ABSTRACT|DECL_PRIVATE
-			Else If CParse( "APW" )
-				attrs:|DECL_ABSTRACT|DECL_PRIVATE | DECL_API_STDCALL
-			Else If CParse( "AR" )
-				attrs:|DECL_ABSTRACT|DECL_PROTECTED
-			Else If CParse( "ARW" )
-				attrs:|DECL_ABSTRACT|DECL_PROTECTED | DECL_API_STDCALL
-			Else If CParse( "W" )
-				attrs:| DECL_API_STDCALL
-			Else If CParse( "O" )
-				attrs:|FUNC_OPERATOR
-			Else If CParse( "OW" )
-				attrs:|FUNC_OPERATOR | DECL_API_STDCALL
-			Else If CParse( "OP" )
-				attrs:|FUNC_OPERATOR|DECL_PRIVATE
-			Else If CParse( "OPW" )
-				attrs:|FUNC_OPERATOR|DECL_PRIVATE | DECL_API_STDCALL
-			Else If CParse( "OR" )
-				attrs:|FUNC_OPERATOR|DECL_PROTECTED
-			Else If CParse( "ORW" )
-				attrs:|FUNC_OPERATOR|DECL_PROTECTED | DECL_API_STDCALL
-			Else If CParse( "P" )
-				attrs:|DECL_PRIVATE
-			Else If CParse( "PW" )
-				attrs:|DECL_PRIVATE | DECL_API_STDCALL
-			Else If CParse( "R" )
-				attrs:|DECL_PROTECTED
-			Else If CParse( "RW" )
-				attrs:|DECL_PROTECTED | DECL_API_STDCALL
-			Else If CParse( "FO" )
-				attrs:|DECL_FINAL|FUNC_OPERATOR
-			Else If CParse( "FOW" )
-				attrs:|DECL_FINAL|FUNC_OPERATOR | DECL_API_STDCALL
-			Else If CParse( "FOP" )
-				attrs:|DECL_FINAL|FUNC_OPERATOR|DECL_PRIVATE
-			Else If CParse( "FOPW" )
-				attrs:|DECL_FINAL|FUNC_OPERATOR|DECL_PRIVATE | DECL_API_STDCALL
-			Else If CParse( "FOR" )
-				attrs:|DECL_FINAL|FUNC_OPERATOR|DECL_PROTECTED
-			Else If CParse( "FORW" )
-				attrs:|DECL_FINAL|FUNC_OPERATOR|DECL_PROTECTED | DECL_API_STDCALL
-			Else If CParse( "AO" )
-				attrs:|DECL_ABSTRACT|FUNC_OPERATOR
-			Else If CParse( "AOW" )
-				attrs:|DECL_ABSTRACT|FUNC_OPERATOR | DECL_API_STDCALL
-			Else If CParse( "AOP" )
-				attrs:|DECL_ABSTRACT|FUNC_OPERATOR|DECL_PRIVATE
-			Else If CParse( "AOPW" )
-				attrs:|DECL_ABSTRACT|FUNC_OPERATOR|DECL_PRIVATE | DECL_API_STDCALL
-			Else If CParse( "AOR" )
-				attrs:|DECL_ABSTRACT|FUNC_OPERATOR|DECL_PROTECTED
-			Else If CParse( "AORW" )
-				attrs:|DECL_ABSTRACT|FUNC_OPERATOR|DECL_PROTECTED | DECL_API_STDCALL
-			'Else If CParse( "property" )
-			'	If attrs & FUNC_METHOD
-			'		attrs:|FUNC_PROPERTY
-			'	Else
-			'		Err "Only methods can be properties."
-			'	EndIf
-			Else
-				Exit
-			EndIf
-		Forever
-		
+
+		Local parsed:Int
+		For Local i:Int = 0 Until _toke.Length
+			Select _toke[i]
+				Case Asc("F")
+					attrs:| DECL_FINAL
+					parsed = True
+				Case Asc("W")
+					attrs:| DECL_API_STDCALL
+					parsed = True
+				Case Asc("P")
+					attrs:| DECL_PRIVATE
+					parsed = True
+				Case Asc("A")
+					attrs:| DECL_ABSTRACT
+					parsed = True
+				Case Asc("O")
+					attrs:| FUNC_OPERATOR
+					parsed = True
+				Case Asc("R")
+					attrs:| DECL_PROTECTED
+					parsed = True
+			End Select
+		Next
+
+		If parsed Then
+			NextToke
+		End If
+
 		Local funcDecl:TFuncDecl
 		If attrs & FUNC_CTOR Then
 			funcDecl = New TNewDecl.CreateF( id,ty,args,attrs )
@@ -1161,6 +1107,11 @@ End Rem
 			decl=New TGlobalDecl.Create( id,ty,init,attrs )
 		Else If attrs & DECL_FIELD
 			decl=New TFieldDecl.Create( id,ty,init,attrs )
+			
+			If TFunctionPtrType(ty) Then
+				TFunctionPtrType(ty).func.attrs :| FUNC_FIELD
+			End If
+			
 		Else If attrs & DECL_CONST
 			decl=New TConstDecl.Create( id,ty,init,attrs )
 		Else If attrs & DECL_LOCAL

+ 1 - 1
options.bmx

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

+ 22 - 4
parser.bmx

@@ -35,11 +35,8 @@ Type TForEachinStmt Extends TLoopStmt
 	Field varty:TType
 	Field varlocal:Int
 	Field expr:TExpr
-	Field block:TBlockDecl
 	Field varExpr:TExpr
 	
-	Field stmts:TList=New TList
-
 	Method Create:TForEachinStmt( varid$,varty:TType,varlocal:Int,expr:TExpr,block:TBlockDecl,loopLabel:TLoopLabelDecl,varExpr:TExpr )
 		Self.varid=varid
 		Self.varty=varty
@@ -53,7 +50,19 @@ Type TForEachinStmt Extends TLoopStmt
 	End Method
 
 	Method OnCopy:TStmt( scope:TScopeDecl )
+		If loopLabel Then
+			If varExpr Then
 		Return New TForEachinStmt.Create( varid,varty,varlocal,expr.Copy(),block.CopyBlock( scope ),TLoopLabelDecl(loopLabel.Copy()), varExpr.Copy() )
+			Else
+				Return New TForEachinStmt.Create( varid,varty,varlocal,expr.Copy(),block.CopyBlock( scope ),TLoopLabelDecl(loopLabel.Copy()), Null )
+			End If
+		Else
+			If varExpr Then
+				Return New TForEachinStmt.Create( varid,varty,varlocal,expr.Copy(),block.CopyBlock( scope ),Null, varExpr.Copy() )
+			Else
+				Return New TForEachinStmt.Create( varid,varty,varlocal,expr.Copy(),block.CopyBlock( scope ),Null, Null )
+			End If
+		End If
 	End Method
 
 	Method OnSemant()
@@ -2024,6 +2033,9 @@ End Rem
 					ty= TType.stringType
 				Else
 					ty=ParseType()
+					While IsArrayDef()
+						ty=ParseArrayType(ty)
+					Wend
 				End If
 				Local init:TLocalDecl=New TLocalDecl.Create( id,ty,Null,0 )
 				Local block:TBlockDecl=New TBlockDecl.Create( _block )
@@ -2405,7 +2417,13 @@ End Rem
 
 		Select toke
 		Case "global" decl=New TGlobalDecl.Create( id,ty,init,attrs )
-		Case "field"  decl=New TFieldDecl.Create( id,ty,init,attrs )
+		Case "field"
+			decl=New TFieldDecl.Create( id,ty,init,attrs )
+
+			If TFunctionPtrType(ty) Then
+				TFunctionPtrType(ty).func.attrs :| FUNC_FIELD
+			End If
+
 		Case "const"  decl=New TConstDecl.Create( id,ty,init,attrs )
 		Case "local"  decl=New TLocalDecl.Create( id,ty,init,attrs )
 		End Select

+ 21 - 5
stmt.bmx

@@ -49,6 +49,9 @@ Type TStmt
 
 	Method Trans$() Abstract
 
+	Method Clear()
+	End Method
+	
 End Type
 
 Type TDeclStmt Extends TStmt
@@ -66,6 +69,9 @@ Type TDeclStmt Extends TStmt
 	End Method
 
 	Method OnCopy:TStmt( scope:TScopeDecl )
+		If Not decl.scope Then
+			decl.scope = scope
+		End If
 		Return New TDeclStmt.Create( decl.Copy(), generated )
 	End Method
 	
@@ -80,6 +86,11 @@ Type TDeclStmt Extends TStmt
 	Method Trans$()
 		Return _trans.TransDeclStmt( Self )
 	End Method
+	
+	Method Clear()
+		decl.Clear()
+	End Method
+	
 End Type
 
 Type TAssignStmt Extends TStmt
@@ -309,8 +320,7 @@ Type TCatchStmt Extends TStmt
 	
 	Method OnSemant()
 		init.Semant
-		If Not TObjectType( init.ty )  And Not TStringType(init.ty) Err "Variable type must extend Throwable"
-		'If Not init.Type.GetClass().IsThrowable() Err "Variable type must extend Throwable"
+		If (Not TObjectType( init.ty ) Or (TObjectType( init.ty ) And TObjectType( init.ty ).classDecl.IsStruct()))  And Not TStringType(init.ty) And Not TArrayType(init.ty) Err "'Catch' variables must be objects"
 		block.InsertDecl init
 		block.Semant
 	End Method
@@ -334,8 +344,7 @@ Type TThrowStmt Extends TStmt
 	
 	Method OnSemant()
 		expr=expr.Semant()
-		If Not TObjectType( expr.exprType ) And Not TStringType(expr.exprType) Err "Expression Type must extend Throwable"
-		'If Not expr.exprType.GetClass().IsThrowable() Err "Expression type must extend Throwable"
+		If (Not TObjectType( expr.exprType ) Or (TObjectType( expr.exprType ) And TObjectType( expr.exprType ).classDecl.IsStruct()))  And Not TStringType(expr.exprType) And Not TArrayType(expr.exprType) Err "'Throw' expression must be an object"
 	End Method
 	
 	Method Trans$()
@@ -444,6 +453,9 @@ Type TLoopStmt Extends TStmt
 	Field loopLabel:TLoopLabelDecl
 	Field block:TBlockDecl
 
+	Method Clear()
+		block.Clear()
+	End Method
 End Type
 
 Type TWhileStmt Extends TLoopStmt
@@ -461,7 +473,11 @@ Type TWhileStmt Extends TLoopStmt
 	End Method
 
 	Method OnCopy:TStmt( scope:TScopeDecl )
-		Return New TWhileStmt.Create( expr.Copy(),block.CopyBlock( scope ),TLoopLabelDecl(loopLabel.Copy()), generated )
+		If loopLabel Then
+			Return New TWhileStmt.Create( expr.Copy(),block.CopyBlock( scope ),TLoopLabelDecl(loopLabel.Copy()), generated )
+		Else
+			Return New TWhileStmt.Create( expr.Copy(),block.CopyBlock( scope ),Null, generated )
+		End If
 	End Method
 	
 	Method OnSemant()