ソースを参照

Generate debug/reflection data.
(Yet) More function pointer tweaks.
Fixed array casting.
Fixed issue where some strings might be optimized out, and later used :-)
Version bump...

woollybah 11 年 前
コミット
8ddad2edb5
9 ファイル変更413 行追加103 行削除
  1. 4 1
      bcc.bmx
  2. 316 79
      ctranslator.bmx
  3. 21 4
      decl.bmx
  4. 20 10
      expr.bmx
  5. 7 1
      options.bmx
  6. 14 4
      parser.bmx
  7. 1 1
      toker.bmx
  8. 3 3
      translator.bmx
  9. 27 0
      type.bmx

+ 4 - 1
bcc.bmx

@@ -116,7 +116,10 @@ Function SaveSource(file:String, trans:TCTranslator, mung:String)
 
 
 	Local path:String = OutputFilePath(file, mung, "c")
 	Local path:String = OutputFilePath(file, mung, "c")
 
 
-	SaveText(trans.JoinLines("source"), path)
+	Local pre:String = trans.JoinLines("pre_source")
+	Local src:String = trans.JoinLines("source")
+
+	SaveText(pre + "~n" + src, path)
 
 
 End Function
 End Function
 
 

+ 316 - 79
ctranslator.bmx

@@ -54,6 +54,29 @@ Type TCTranslator Extends TTranslator
 		If TDoublePtrType( ty ) Return "~q*d~q"
 		If TDoublePtrType( ty ) Return "~q*d~q"
 		If TLongPtrType( ty ) Return "~q*l~q"
 		If TLongPtrType( ty ) Return "~q*l~q"
 	End Method
 	End Method
+	
+	Method TransDebugScopeType$(ty:TType)
+		If TByteType( ty ) Return "b"
+		If TShortType( ty ) Return "s"
+		If TIntType( ty ) Return "i"
+		If TFloatType( ty ) Return "f"
+		If TDoubleType( ty ) Return "d"
+		If TLongType( ty ) Return "l"
+		If TStringType( ty ) Return "$"
+		If TArrayType( ty ) Then
+			Return "[]" + TransDebugScopeType(TArrayType( ty ).elemType)
+		End If
+		If TObjectType( ty ) Then
+			Return ":" + TObjectType( ty ).classDecl.ident
+		End If
+
+		If TBytePtrType( ty ) Return "*b"
+		If TShortPtrType( ty ) Return "*s"
+		If TIntPtrType( ty ) Return "*i"
+		If TFloatPtrType( ty ) Return "*f"
+		If TDoublePtrType( ty ) Return "*d"
+		If TLongPtrType( ty ) Return "*l"
+	End Method
 
 
 	Method TransType$( ty:TType, ident:String)
 	Method TransType$( ty:TType, ident:String)
 		If TVoidType( ty ) Or Not ty Then
 		If TVoidType( ty ) Or Not ty Then
@@ -393,10 +416,14 @@ t:+"NULLNULLNULL"
 	'***** Utility *****
 	'***** Utility *****
 
 
 	Method TransLocalDecl$( munged$,init:TExpr )
 	Method TransLocalDecl$( munged$,init:TExpr )
-		Return TransType( init.exprType, munged )+" "+munged+"="+init.Trans()
+		If TFunctionPtrType(init.exprType) Then
+			Return TransType( init.exprType, munged )+"="+init.Trans()
+		Else
+			Return TransType( init.exprType, munged )+" "+munged+"="+init.Trans()
+		End If
 	End Method
 	End Method
 
 
-	Method TransGlobalDecl$( munged$,init:TExpr, attrs:Int )
+	Method TransGlobalDecl$( munged$,init:TExpr, attrs:Int, ty:TType )
 		Local glob:String
 		Local glob:String
 
 
 		If Not (attrs & DECL_INITONLY) Then
 		If Not (attrs & DECL_INITONLY) Then
@@ -412,7 +439,15 @@ t:+"NULLNULLNULL"
 			glob :+ indent + "}"
 			glob :+ indent + "}"
 		Else
 		Else
 			If init Then
 			If init Then
-				glob :+ init.Trans()
+				If TFunctionPtrType(ty) Then
+					If TInvokeExpr(init) And Not TInvokeExpr(init).invokedWithBraces Then
+						glob :+ TInvokeExpr(init).decl.munged
+					Else
+						glob :+ init.Trans()
+					End If
+				Else
+					glob :+ init.Trans()
+				End If
 			Else
 			Else
 				glob :+ "0"
 				glob :+ "0"
 			End If
 			End If
@@ -498,7 +533,7 @@ t:+"NULLNULLNULL"
 	End Method
 	End Method
 
 
 	Method TransFunc$( decl:TFuncDecl,args:TExpr[],lhs:TExpr, sup:Int = False )
 	Method TransFunc$( decl:TFuncDecl,args:TExpr[],lhs:TExpr, sup:Int = False )
-'If decl.ident = "ParseModuleImport" DebugStop
+'If decl.ident = "lua_pushinteger" DebugStop
 
 
 		' for calling the super class method instead
 		' for calling the super class method instead
 		Local tSuper:String
 		Local tSuper:String
@@ -571,9 +606,10 @@ t:+"NULLNULLNULL"
 
 
 				Else If TIndexExpr(lhs) Then
 				Else If TIndexExpr(lhs) Then
 					Local loc:String = CreateLocal(lhs)
 					Local loc:String = CreateLocal(lhs)
-					Local obj:String = Bra("struct " + decl.scope.munged + "_obj*")
-					Local class:String = Bra("(" + obj + loc +")->clas" + tSuper)
+					Local obj:String = Bra(TransObject(decl.scope))
+					'Local class:String = Bra("(" + obj + loc +")->clas" + tSuper)
 					'Local class:String = Bra("&" + decl.scope.munged)
 					'Local class:String = Bra("&" + decl.scope.munged)
+					Local class:String = Bra(loc + "->clas" + tSuper)
 					Return class + "->" + TransFuncPrefix(decl.scope, decl.ident) + decl.ident+TransArgs( args,decl, loc )
 					Return class + "->" + TransFuncPrefix(decl.scope, decl.ident) + decl.ident+TransArgs( args,decl, loc )
 				Else
 				Else
 					InternalErr
 					InternalErr
@@ -757,14 +793,11 @@ t:+"NULLNULLNULL"
 		Local s:String
 		Local s:String
 
 
 		If Not sc Then
 		If Not sc Then
-			'InternalErr
 			s = "bbEmptyString"
 			s = "bbEmptyString"
-'			s = "_s" + stringConstCount
-'
-'			stringMap.Insert(value, s)
-'
-'			stringConstCount:+ 1e
 		Else
 		Else
+			If Not sc.count Then
+				sc.count :+ 1
+			End If
 			s = sc.id
 			s = sc.id
 		End If
 		End If
 
 
@@ -987,7 +1020,7 @@ t:+"NULLNULLNULL"
 				If TLongPtrType( src ) Return t
 				If TLongPtrType( src ) Return t
 			End If
 			End If
 		Else If TArrayType( dst )
 		Else If TArrayType( dst )
-			If TObjectType( src) And TObjectType( src ).classDecl.ident = "Array" Then
+			If TObjectType( src) And (TObjectType( src ).classDecl.ident = "Array" Or TObjectType( src ).classDecl.ident = "Object") Then
 				Return "bbArrayCastFromObject" + Bra(t + "," + TransArrayType(TArrayType( dst ).elemType))
 				Return "bbArrayCastFromObject" + Bra(t + "," + TransArrayType(TArrayType( dst ).elemType))
 			End If
 			End If
 		Else If TObjectType( dst )
 		Else If TObjectType( dst )
@@ -1298,7 +1331,7 @@ t:+"NULLNULLNULL"
 
 
 		Local rhs$=stmt.rhs.Trans()
 		Local rhs$=stmt.rhs.Trans()
 		Local lhs$=stmt.lhs.TransVar()
 		Local lhs$=stmt.lhs.TransVar()
-		
+
 		If TVarPtrType(stmt.lhs.exprType) Then
 		If TVarPtrType(stmt.lhs.exprType) Then
 			lhs = "*" + lhs
 			lhs = "*" + lhs
 		End If
 		End If
@@ -1344,6 +1377,9 @@ t:+"NULLNULLNULL"
 			Else
 			Else
 				s :+ lhs+TransAssignOp( stmt.op )+rhs
 				s :+ lhs+TransAssignOp( stmt.op )+rhs
 			End If
 			End If
+		Else If TFunctionPtrType(stmt.lhs.exprType) And TInvokeExpr(stmt.rhs) And Not TInvokeExpr(stmt.rhs).invokedWithBraces Then
+			rhs = TInvokeExpr(stmt.rhs).decl.munged
+			s :+ lhs+TransAssignOp( stmt.op )+rhs
 		Else
 		Else
 			s :+ lhs+TransAssignOp( stmt.op )+rhs
 			s :+ lhs+TransAssignOp( stmt.op )+rhs
 		End If
 		End If
@@ -1771,10 +1807,16 @@ End Rem
 		If Not classDecl.IsExtern() Then
 		If Not classDecl.IsExtern() Then
 			If opt_issuperstrict Then
 			If opt_issuperstrict Then
 				Emit "void _" + classid + "_New" + Bra(TransObject(classdecl) + " o") + ";"
 				Emit "void _" + classid + "_New" + Bra(TransObject(classdecl) + " o") + ";"
-				Emit "void _" + classid + "_Delete" + Bra(TransObject(classdecl) + " o") + ";"
 			Else
 			Else
 				Emit "int _" + classid + "_New" + Bra(TransObject(classdecl) + " o") + ";"
 				Emit "int _" + classid + "_New" + Bra(TransObject(classdecl) + " o") + ";"
-				Emit "int _" + classid + "_Delete" + Bra(TransObject(classdecl) + " o") + ";"
+			End If
+			
+			If classHierarchyHasFunction(classDecl, "Delete") Then
+				If opt_issuperstrict Then
+					Emit "void _" + classid + "_Delete" + Bra(TransObject(classdecl) + " o") + ";"
+				Else
+					Emit "int _" + classid + "_Delete" + Bra(TransObject(classdecl) + " o") + ";"
+				End If
 			End If
 			End If
 
 
 			If classHasFunction(classDecl, "ToString") Then
 			If classHasFunction(classDecl, "ToString") Then
@@ -1885,6 +1927,14 @@ End Rem
 		Return False
 		Return False
 	End Method
 	End Method
 
 
+	Method classHierarchyHasFunction:Int(classDecl:TClassDecl, func:String)
+		If classHasFunction(classDecl, func) Return True
+		If classDecl.superClass And classDecl.superClass.munged <> "bbObjectClass" Then
+			Return classHierarchyHasFunction(classDecl.superClass, func)
+		End If
+		Return False
+	End Method
+
 	Method EmitMark( id$,ty:TType,queue:Int )
 	Method EmitMark( id$,ty:TType,queue:Int )
 
 
 		If TObjectType( ty )
 		If TObjectType( ty )
@@ -1906,6 +1956,161 @@ End Rem
 		EndIf
 		EndIf
 	End Method
 	End Method
 
 
+	Method TransDebugScopeAlignedOffset:Int(ty:TType, offset:Int)
+		If TByteType(ty) Then
+			' nothing
+		Else If TShortType(ty) Then
+			If offset Mod 2 Then
+				offset :+ offset Mod 2
+			End If
+		Else If TIntType(ty) Or TFloatType(ty) Then
+			If offset Mod 4 Then
+				offset :+ (4 - offset Mod 4)
+			End If
+		Else
+			If offset Mod WORD_SIZE Then
+				offset :+ (WORD_SIZE - offset Mod WORD_SIZE)
+			End If
+		End If
+		
+		Return offset
+	End Method
+	
+	Method EmitClassFieldsDebugScope:Int(classDecl:TClassDecl, offset:Int)
+
+		If classDecl.superClass Then
+			offset = EmitClassFieldsDebugScope(classDecl.superClass, offset)
+		End If
+
+		For Local decl:TFieldDecl = EachIn classDecl.Decls()
+			Emit "{"
+			Emit "BBDEBUGDECL_FIELD,"
+			Emit Enquote(decl.ident) + ","
+			Emit Enquote(TransDebugScopeType(decl.ty)) + ","
+			offset = TransDebugScopeAlignedOffset(decl.ty, offset)
+			If WORD_SIZE = 8 Then
+				Emit Bra("BBLONG") + offset
+			Else
+				Emit offset
+			End If
+			'If Not TFunctionPtrType(decl.ty) Then
+			'	Emit TransType(decl.ty, classDecl.actual.munged) + " _" + classDecl.actual.munged.ToLower() + "_" + decl.ident.ToLower() + ";"
+			'Else
+			'	Emit TransType(decl.ty, "_" + classDecl.actual.munged.ToLower() + "_" + decl.ident.ToLower()) + ";"
+			'End If
+			Emit "},"
+			
+			offset:+ decl.ty.GetSize()
+		Next
+
+		Return offset
+	End Method
+	
+	Method EmitClassStandardMethodDebugScope(ident:String, ty:String, munged:String)
+			Emit "{"
+			Emit "BBDEBUGDECL_TYPEMETHOD,"
+			Emit Enquote(ident) + ","
+			Emit Enquote(ty) + ","
+			Emit "&" + munged
+			Emit "},"
+	End Method
+
+	Method EmitBBClassFuncsDebugScope(decl:TFuncDecl)
+			Emit "{"
+			If decl.IsMethod() Then
+				Emit "BBDEBUGDECL_TYPEMETHOD,"
+			Else
+				Emit "BBDEBUGDECL_TYPEFUNCTION,"
+			End If
+			Emit Enquote(decl.ident) + ","
+			
+			Local s:String = "("
+			For Local i:Int = 0 Until decl.argDecls.length
+				If i Then
+					s:+ ","
+				End If
+				s:+ TransDebugScopeType(decl.argDecls[i].ty)
+			Next
+			s:+ ")"
+			If decl.retType Then
+				s:+ TransDebugScopeType(decl.retType)
+			End If
+			Emit Enquote(s) + ","
+			If decl.IsMethod() Then
+				Emit "_" + decl.munged
+			Else
+				Emit decl.munged
+			End If
+			Emit "},"
+	End Method
+
+	Method EmitBBClassClassFuncsDebugScope(classDecl:TClassDecl)
+		Local reserved:String = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
+
+		If classDecl.superClass Then
+			EmitBBClassClassFuncsDebugScope(classDecl.superClass)
+		End If
+
+		For Local decl:TDecl=EachIn classDecl.Decls()
+			Local fdecl:TFuncDecl =TFuncDecl( decl )
+			If fdecl
+				If fdecl.overrides Then
+					Continue
+				End If
+				If reserved.Find("," + fdecl.ident.ToLower() + ",") = -1 Then
+					EmitBBClassFuncsDebugScope( fdecl )
+					Continue
+				End If
+			EndIf
+		Next
+	End Method
+
+	Method EmitClassFuncsDebugScope(classDecl:TClassDecl)
+
+		Local classid$=classDecl.munged
+		Local superid$=classDecl.superClass.actual.munged
+
+		Local ret:String = "()i"
+		If opt_issuperstrict Then
+			ret = "()"
+		End If
+		
+		EmitClassStandardMethodDebugScope("New", ret, "_" + classid + "_New")
+	
+		If classHierarchyHasFunction(classDecl, "Delete") Then
+			EmitClassStandardMethodDebugScope("Delete", ret, "_" + classid + "_Delete")
+		End If
+
+		If classHasFunction(classDecl, "ToString") Then
+			EmitClassStandardMethodDebugScope("ToString", "()$", "_" + classid + "_ToString")
+			Emit "_" + classid + "_ToString,"
+		End If
+
+		If classHasFunction(classDecl, "ObjectCompare") Then
+			EmitClassStandardMethodDebugScope("ObjectCompare", "(:Object)i", "_" + classid + "_ObjectCompare")
+			Emit "_" + classid + "_ObjectCompare,"
+		End If
+
+		If classHasFunction(classDecl, "SendMessage") Then
+			EmitClassStandardMethodDebugScope("SendMessage", "(:Object):Object", "_" + classid + "_SendMessage")
+			Emit "_" + classid + "_SendMessage,"
+		End If
+
+		EmitBBClassClassFuncsDebugScope(classDecl)
+
+	End Method
+	
+	Method EmitClassGlobalDebugScope( classDecl:TClassDecl )
+		For Local decl:TGlobalDecl = EachIn classDecl.Decls()
+			Emit "{"
+			Emit "BBDEBUGDECL_GLOBAL,"
+			Emit Enquote(decl.ident) + ","
+			Emit Enquote(TransDebugScopeType(decl.ty)) + ","
+			Emit "&" + decl.munged
+			Emit "},"
+		Next
+	End Method
+
 	Method EmitClassDecl( classDecl:TClassDecl )
 	Method EmitClassDecl( classDecl:TClassDecl )
 
 
 		'If classDecl.IsTemplateInst()
 		'If classDecl.IsTemplateInst()
@@ -1920,7 +2125,10 @@ End Rem
 		Local superid$=classDecl.superClass.actual.munged
 		Local superid$=classDecl.superClass.actual.munged
 
 
 		EmitClassDeclNew(classDecl)
 		EmitClassDeclNew(classDecl)
-		EmitClassDeclDelete(classDecl)
+		
+		If classHierarchyHasFunction(classDecl, "Delete") Then
+			EmitClassDeclDelete(classDecl)
+		End If
 
 
 		Rem
 		Rem
 		'fields ctor
 		'fields ctor
@@ -1979,28 +2187,42 @@ End Rem
 
 
 		reserved = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
 		reserved = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
 
 
-		Emit "struct BBClass_" + classid + " " + classid + "={"
+		' debugscope
+		Emit "BBDebugScope " + classid + "_scope={"
+		Emit "BBDEBUGSCOPE_USERTYPE,"
+		Emit EnQuote(classDecl.ident) + ","
 
 
-		' super class
-'		If Not classDecl.superClass Then
-'			Emit "~t&bbObjectClass,"
-'		Else
-'		If classDecl.superClass.ident = "Object" Then
-			Emit "&" + classDecl.superClass.munged + ","
-'		Else
-'			Emit "&_" + classDecl.superClass.munged + ","
-'		End If
-'		End If
+		' debug field decls
+		EmitClassFieldsDebugScope(classDecl, WORD_SIZE)
+		
+		' debug global decls
+		EmitClassGlobalDebugScope(classDecl)
+		
+		' debug func decls
+		EmitClassFuncsDebugScope(classDecl)
+		
+		Emit "BBDEBUGDECL_END"
 
 
-		Emit "bbObjectFree,"
+		Emit "};"
 
 
-		Emit "0,"
-		'Emit "~t" + (OBJECT_BASE_OFFSET + classDecl.lastOffset) + ","
-		Emit "sizeof" + Bra("struct " + classid + "_obj") + ","
+		Emit "struct BBClass_" + classid + " " + classid + "={"
 
 
+		' super class reference
+		Emit "&" + classDecl.superClass.munged + ","
+		Emit "bbObjectFree,"
+		' debugscope
+		Emit "&" + classid + "_scope,"
+		' object instance size
+		Emit "sizeof" + Bra("struct " + classid + "_obj") + ","
 
 
+		' standard methods
 		Emit "_" + classid + "_New,"
 		Emit "_" + classid + "_New,"
-		Emit "_" + classid + "_Delete,"
+
+		If Not classHierarchyHasFunction(classDecl, "Delete") Then
+			Emit "bbObjectDtor,"
+		Else
+			Emit "_" + classid + "_Delete,"
+		End If
 
 
 		If classHasFunction(classDecl, "ToString") Then
 		If classHasFunction(classDecl, "ToString") Then
 			Emit "_" + classid + "_ToString,"
 			Emit "_" + classid + "_ToString,"
@@ -2189,7 +2411,11 @@ End Rem
 				If TStringVarPtrType(exprType) Then
 				If TStringVarPtrType(exprType) Then
 					Return Bra("(*" + variable + ")->length")
 					Return Bra("(*" + variable + ")->length")
 				Else
 				Else
-					Return Bra(variable + "->length")
+					If variable.StartsWith("&_s") Then
+						Return Bra(variable[1..] + ".length")
+					Else
+						Return Bra(variable + "->length")
+					End If
 				End If
 				End If
 			End If
 			End If
 		End If
 		End If
@@ -2416,7 +2642,9 @@ End Rem
 		' functions
 		' functions
 		If Not classDecl.IsExtern() Then
 		If Not classDecl.IsExtern() Then
 			Emit "-New%()=" + Enquote("_" + classDecl.munged + "_New")
 			Emit "-New%()=" + Enquote("_" + classDecl.munged + "_New")
-			Emit "-Delete%()=" + Enquote("_" + classDecl.munged + "_Delete")
+			If classHierarchyHasFunction(classDecl, "Delete") Then
+				Emit "-Delete%()=" + Enquote("_" + classDecl.munged + "_Delete")
+			End If
 
 
 			Local reserved:String = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
 			Local reserved:String = ",New,Delete,ToString,Compare,SendMessage,_reserved1_,_reserved2_,_reserved3_,".ToLower()
 
 
@@ -2731,7 +2959,7 @@ End Rem
 
 
 			End If
 			End If
 
 
-			SetOutput("source")
+			SetOutput("pre_source")
 
 
 			Emit "#include ~q" + file + "~q"
 			Emit "#include ~q" + file + "~q"
 		End If
 		End If
@@ -2740,43 +2968,7 @@ End Rem
 	Method TransSource(app:TAppDecl)
 	Method TransSource(app:TAppDecl)
 
 
 		SetOutput("source")
 		SetOutput("source")
-
-		' include our header
-		EmitModuleInclude(app.mainModule)
-
-		' incbins
-		TransIncBin(app)
-
-		' strings
-		For Local s:String = EachIn app.stringConsts.Keys()
-			If s Then
-				Local key:TStringConst = TStringConst(app.stringConsts.ValueForKey(s))
-
-				Emit "static BBString " + key.id + "={"
-				Emit "&bbStringClass,"
-				'Emit "2147483647,"
-				Emit s.length + ","
-
-				Local t:String = "{"
-
-				For Local i:Int = 0 Until s.length
-					If i Then
-						t:+ ","
-					End If
-					t:+ s[i]
-
-					If i And Not (i Mod 16) Then
-						Emit t
-						t = ""
-					End If
-				Next
-
-				Emit t + "}"
-
-				Emit "};"
-			End If
-		Next
-
+		
 		'definitions!
 		'definitions!
 		For Local decl:TDecl=EachIn app.Semanted()
 		For Local decl:TDecl=EachIn app.Semanted()
 
 
@@ -2855,7 +3047,15 @@ End Rem
 
 
 			' TODO : what about OnDebugStop etc, who have no init ?
 			' TODO : what about OnDebugStop etc, who have no init ?
 			If decl.init And Not (decl.attrs & DECL_INITONLY) Then
 			If decl.init And Not (decl.attrs & DECL_INITONLY) Then
-				Emit TransGlobal( decl )+"="+decl.init.Trans()+";"
+				If TFunctionPtrType(decl.ty) Then
+					If TInvokeExpr(decl.init) And Not TInvokeExpr(decl.init).invokedWithBraces Then
+						Emit TransGlobal( decl )+"="+TInvokeExpr(decl.init).decl.munged + ";"
+					Else
+						Emit TransGlobal( decl )+"="+decl.init.Trans()+";"
+					End If
+				Else
+					Emit TransGlobal( decl )+"="+decl.init.Trans()+";"
+				End If
 			End If
 			End If
 		Next
 		Next
 
 
@@ -2868,11 +3068,48 @@ End Rem
 		Emit "return 0;"
 		Emit "return 0;"
 		Emit "}"
 		Emit "}"
 
 
-		'Emit "void gc_mark(){"
-		'For Local decl:TGlobalDecl=EachIn app.semantedGlobals
-		'	EmitMark TransGlobal( decl ),decl.ty,False
-		'Next
-		'Emit "}"
+
+
+
+		SetOutput("pre_source")
+
+		' include our header
+		EmitModuleInclude(app.mainModule)
+
+		' incbins
+		TransIncBin(app)
+
+		' strings
+		For Local s:String = EachIn app.stringConsts.Keys()
+			If s Then
+				Local key:TStringConst = TStringConst(app.stringConsts.ValueForKey(s))
+
+				If key.count > 0 Then
+					Emit "static BBString " + key.id + "={"
+					Emit "&bbStringClass,"
+					'Emit "2147483647,"
+					Emit s.length + ","
+
+					Local t:String = "{"
+
+					For Local i:Int = 0 Until s.length
+						If i Then
+							t:+ ","
+						End If
+						t:+ s[i]
+
+						If i And Not (i Mod 16) Then
+							Emit t
+							t = ""
+						End If
+					Next
+
+					Emit t + "}"
+
+					Emit "};"
+				End If
+			End If
+		Next
 
 
 	End Method
 	End Method
 
 

+ 21 - 4
decl.bmx

@@ -267,7 +267,7 @@ Type TValDecl Extends TDecl
 								argExpr :+ [aexp]
 								argExpr :+ [aexp]
 							Next
 							Next
 
 
-							expr=declInit.Copy().SemantFunc(argExpr, False)
+							expr=declInit.Copy().SemantFunc(argExpr, False, False)
 							If Not expr Then
 							If Not expr Then
 								expr = declInit.Copy().Semant()
 								expr = declInit.Copy().Semant()
 							End If
 							End If
@@ -790,6 +790,14 @@ End Rem
 			If _err Err _err
 			If _err Err _err
 			If explicit Return Null
 			If explicit Return Null
 		EndIf
 		EndIf
+
+		' last try... maybe we are trying to use it as a function pointer? (no args)
+		If Not match Then
+			If func And Not argExprs Then
+				match = func
+				match.maybeFunctionPtr = True
+			End If
+		End If
 		
 		
 		If Not match
 		If Not match
 			Local t$
 			Local t$
@@ -868,6 +876,8 @@ Type TFuncDecl Extends TBlockDecl
 	Field castTo:String
 	Field castTo:String
 	Field noCastGen:Int
 	Field noCastGen:Int
 	
 	
+	Field maybeFunctionPtr:Int
+	
 	Method CreateF:TFuncDecl( ident$,ty:TType,argDecls:TArgDecl[],attrs:Int )
 	Method CreateF:TFuncDecl( ident$,ty:TType,argDecls:TArgDecl[],attrs:Int )
 		Self.ident=ident
 		Self.ident=ident
 		Self.retTypeExpr=ty
 		Self.retTypeExpr=ty
@@ -889,6 +899,13 @@ Type TFuncDecl Extends TBlockDecl
 		For Local stmt:TStmt=EachIn stmts
 		For Local stmt:TStmt=EachIn stmts
 			t.AddStmt stmt.Copy( t )
 			t.AddStmt stmt.Copy( t )
 		Next
 		Next
+		t.retType = retType
+		t.scope = scope
+		t.overrides = overrides
+		t.superCtor = superCtor
+		t.castTo = castTo
+		t.noCastGen = noCastGen
+		t.munged = munged
 		Return  t
 		Return  t
 	End Method
 	End Method
 
 
@@ -1934,9 +1951,9 @@ pushenv Self
 		If value Then
 		If value Then
 			Local sc:TStringConst = TStringConst(stringConsts.ValueForKey(value))
 			Local sc:TStringConst = TStringConst(stringConsts.ValueForKey(value))
 			If sc Then
 			If sc Then
-				sc.count :- 1
-				If sc.count = 0 Then
-					stringConsts.Remove(value)
+				If sc.count > 0 Then
+					sc.count :- 1
+					'stringConsts.Remove(value)
 				End If
 				End If
 			End If
 			End If
 		End If
 		End If

+ 20 - 10
expr.bmx

@@ -41,7 +41,7 @@ Type TExpr
 		Err ToString()+" cannot be assigned to."
 		Err ToString()+" cannot be assigned to."
 	End Method
 	End Method
 
 
-	Method SemantFunc:TExpr( args:TExpr[] , throwError:Int = True )
+	Method SemantFunc:TExpr( args:TExpr[] , throwError:Int = True, funcCall:Int = False )
 		Err ToString()+" cannot be invoked."
 		Err ToString()+" cannot be invoked."
 	End Method
 	End Method
 
 
@@ -867,9 +867,14 @@ Type TCastExpr Extends TExpr
 			Return Self
 			Return Self
 		End If
 		End If
 		
 		
-		If TArrayType(ty) And TObjectType(src) And TObjectType(src).classDecl.ident = "Array" Then
-			exprType = ty
-			Return expr
+		If TArrayType(ty) And TObjectType(src) 
+			If TObjectType(src).classDecl.ident = "Array" Then
+				exprType = ty
+				Return expr
+			Else If  TObjectType(src).classDecl.ident = "Object" Then
+				exprType = ty
+				Return Self
+			End If
 		End If
 		End If
 
 
 		If Not exprType
 		If Not exprType
@@ -1460,7 +1465,7 @@ Type TIdentTypeExpr Extends TExpr
 		Err "Expression can't be used in this way"
 		Err "Expression can't be used in this way"
 	End Method
 	End Method
 
 
-	Method SemantFunc:TExpr( args:TExpr[] , throwError:Int = True )
+	Method SemantFunc:TExpr( args:TExpr[] , throwError:Int = True, funcCall:Int = False )
 		_Semant
 		_Semant
 		If args.Length=1 And args[0] Return args[0].Cast( cdecl.objectType,CAST_EXPLICIT )
 		If args.Length=1 And args[0] Return args[0].Cast( cdecl.objectType,CAST_EXPLICIT )
 		Err "Illegal number of arguments for type conversion"
 		Err "Illegal number of arguments for type conversion"
@@ -1506,7 +1511,10 @@ Type TIdentExpr Extends TExpr
 			Else
 			Else
 				expr=expr.Semant()
 				expr=expr.Semant()
 				scope=expr.exprType.GetClass()
 				scope=expr.exprType.GetClass()
-				If Not scope Err "Expression has no scope"
+				If Not scope Then
+					DebugStop
+					Err "Expression has no scope"
+				End If
 			End If
 			End If
 		Else
 		Else
 			scope=_env
 			scope=_env
@@ -1616,8 +1624,10 @@ Type TIdentExpr Extends TExpr
 		Local fdecl:TFuncDecl=scope.FindFuncDecl( ident,args, , isArg )
 		Local fdecl:TFuncDecl=scope.FindFuncDecl( ident,args, , isArg )
 
 
 		If fdecl
 		If fdecl
-			If _env.ModuleScope().IsStrict() And Not fdecl.IsProperty() And Not isArg 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."
 
 
+			fdecl.maybeFunctionPtr = False
+			
 			If Not fdecl.IsStatic()
 			If Not fdecl.IsStatic()
 				If expr Return New TInvokeMemberExpr.Create( expr,fdecl,args ).Semant()
 				If expr Return New TInvokeMemberExpr.Create( expr,fdecl,args ).Semant()
 				If scope<>_env Or Not _env.FuncScope() Or _env.FuncScope().IsStatic() Err "Method '"+ident+"' cannot be accessed from here."
 				If scope<>_env Or Not _env.FuncScope() Or _env.FuncScope().IsStatic() Err "Method '"+ident+"' cannot be accessed from here."
@@ -1629,7 +1639,7 @@ Type TIdentExpr Extends TExpr
 		IdentErr
 		IdentErr
 	End Method
 	End Method
 
 
-	Method SemantFunc:TExpr( args:TExpr[], throwError:Int = True )
+	Method SemantFunc:TExpr( args:TExpr[], throwError:Int = True, funcCall:Int = False )
 
 
 		_Semant
 		_Semant
 
 
@@ -1650,7 +1660,7 @@ Type TIdentExpr Extends TExpr
 				If expr Return New TInvokeMemberExpr.Create( expr,fdecl,args ).Semant()
 				If expr Return New TInvokeMemberExpr.Create( expr,fdecl,args ).Semant()
 				'If scope<>_env Or _env.FuncScope().IsStatic() Err "Method '"+ident+"' cannot be accessed from here."
 				'If scope<>_env Or _env.FuncScope().IsStatic() Err "Method '"+ident+"' cannot be accessed from here."
 			EndIf
 			EndIf
-			Return New TInvokeExpr.Create( fdecl,args ).Semant()
+			Return New TInvokeExpr.Create( fdecl,args, funcCall ).Semant()
 		EndIf
 		EndIf
 
 
 		'If args.Length=1 And args[0] And TObjectType( args[0].exprType )
 		'If args.Length=1 And args[0] And TObjectType( args[0].exprType )
@@ -1908,7 +1918,7 @@ Type TFuncCallExpr Extends TExpr
 
 
 	Method Semant:TExpr()
 	Method Semant:TExpr()
 		args=SemantArgs( args )
 		args=SemantArgs( args )
-		Return expr.SemantFunc( args )
+		Return expr.SemantFunc( args, True, True )
 	End Method
 	End Method
 
 
 End Type
 End Type

+ 7 - 1
options.bmx

@@ -25,7 +25,7 @@ SuperStrict
 
 
 Import "base.configmap.bmx"
 Import "base.configmap.bmx"
 
 
-Const version:String = "0.10"
+Const version:String = "0.11"
 
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1
 Const BUILDTYPE_MODULE:Int = 1
@@ -34,6 +34,8 @@ Const APPTYPE_NONE:Int = 0
 Const APPTYPE_CONSOLE:Int = 1
 Const APPTYPE_CONSOLE:Int = 1
 Const APPTYPE_GUI:Int = 2
 Const APPTYPE_GUI:Int = 2
 
 
+Global WORD_SIZE:Int = 4
+
 ' buildtype
 ' buildtype
 '    module
 '    module
 '    app
 '    app
@@ -168,6 +170,10 @@ Function ParseArgs:String[](args:String[])
 	If opt_buildtype = BUILDTYPE_MODULE Then
 	If opt_buildtype = BUILDTYPE_MODULE Then
 		opt_apptype = APPTYPE_NONE
 		opt_apptype = APPTYPE_NONE
 	End If
 	End If
+	
+	If opt_arch = "x64" Then
+		WORD_SIZE = 8
+	End If
 
 
 	Return args[count..]
 	Return args[count..]
 
 

+ 14 - 4
parser.bmx

@@ -718,6 +718,11 @@ Type TParser
 				ty = TType.MapToPointerType(ty)
 				ty = TType.MapToPointerType(ty)
 			End If
 			End If
 
 
+			' array
+			While CParse( "[]" )
+				ty=New TArrayType.Create( ty)
+			Wend
+
 			' optional brackets
 			' optional brackets
 			If CParse( "(" )
 			If CParse( "(" )
 				expr=ParseExpr()
 				expr=ParseExpr()
@@ -798,6 +803,11 @@ Type TParser
 				ty = TType.MapToPointerType(ty)
 				ty = TType.MapToPointerType(ty)
 			End If
 			End If
 
 
+			' string array
+			While CParse( "[]" )
+				ty=New TArrayType.Create( ty)
+			Wend
+
 			If CParse( "(" )
 			If CParse( "(" )
 				expr=ParseExpr()
 				expr=ParseExpr()
 				Parse ")"
 				Parse ")"
@@ -1346,7 +1356,7 @@ Type TParser
 		Parse "try"
 		Parse "try"
 
 
 		Local block:TBlockDecl=New TBlockDecl.Create( _block )
 		Local block:TBlockDecl=New TBlockDecl.Create( _block )
-		Local catches:Tlist=New TList
+		Local catches:TList=New TList
 
 
 		PushBlock block
 		PushBlock block
 		While _toke<>"end"
 		While _toke<>"end"
@@ -2009,7 +2019,7 @@ End If
 		PopBlock
 		PopBlock
 
 
 		NextToke
 		NextToke
-		If toke CParse toke
+		'If toke CParse toke
 
 
 		Return funcDecl
 		Return funcDecl
 	End Method
 	End Method
@@ -3021,7 +3031,7 @@ Function ParseApp:TAppDecl( path$ )
 End Function
 End Function
 
 
 Function MungModuleName:String(ident:Object)
 Function MungModuleName:String(ident:Object)
-	local mung:String
+	Local mung:String
 	If String(ident) Then
 	If String(ident) Then
 		Local id:String = String(ident)
 		Local id:String = String(ident)
 		mung = "__bb_" + id + "_" + id[id.Find(".") + 1..]
 		mung = "__bb_" + id + "_" + id[id.Find(".") + 1..]
@@ -3041,7 +3051,7 @@ Function MungModuleName:String(ident:Object)
 	End If
 	End If
 
 
 	'return sanitized, remove non-allowed chars
 	'return sanitized, remove non-allowed chars
-	return TStringHelper.Sanitize(mung)
+	Return TStringHelper.Sanitize(mung)
 End Function
 End Function
 
 
 Function EvalS$( source$,ty:TType )
 Function EvalS$( source$,ty:TType )

+ 1 - 1
toker.bmx

@@ -45,7 +45,7 @@ Type TToker
 	Const _keywords$=";"+ ..
 	Const _keywords$=";"+ ..
 	"strict;superstrict;"+ ..
 	"strict;superstrict;"+ ..
 	"public;private;"+ ..
 	"public;private;"+ ..
-	"short;int;float;double;long;string;object;ptr;var;varptr;mod;continue;exit;"+ ..
+	"short;int;float;double;long;string;object;array;ptr;var;varptr;mod;continue;exit;"+ ..
 	"include;import;module;extern;framework;"+ ..
 	"include;import;module;extern;framework;"+ ..
 	"new;self;super;eachin;true;false;null;not;"+ ..
 	"new;self;super;eachin;true;false;null;not;"+ ..
 	"extends;abstract;select;case;default;"+ ..
 	"extends;abstract;select;case;default;"+ ..

+ 3 - 3
translator.bmx

@@ -93,7 +93,7 @@ Type TTranslator
 		funcs.AddLast fdecl
 		funcs.AddLast fdecl
 	End Method
 	End Method
 	
 	
-	Method MungDecl( decl:TDecl )
+	Method MungDecl( decl:TDecl, allowDupes:Int = False )
 
 
 		If decl.munged Return
 		If decl.munged Return
 
 
@@ -363,7 +363,7 @@ End Rem
 
 
 	Method TransLocalDecl$( munged$,init:TExpr ) Abstract
 	Method TransLocalDecl$( munged$,init:TExpr ) Abstract
 
 
-	Method TransGlobalDecl$( munged$,init:TExpr, attrs:Int ) Abstract
+	Method TransGlobalDecl$( munged$,init:TExpr, attrs:Int, ty:TType ) Abstract
 	
 	
 	Method EmitPushErr()
 	Method EmitPushErr()
 	End Method
 	End Method
@@ -702,7 +702,7 @@ End Rem
 		Local gdecl:TGlobalDecl=TGlobalDecl( stmt.decl )
 		Local gdecl:TGlobalDecl=TGlobalDecl( stmt.decl )
 		If gdecl Then
 		If gdecl Then
 			MungDecl gdecl
 			MungDecl gdecl
-			Return TransGlobalDecl( gdecl.munged, gdecl.init, gdecl.attrs )
+			Return TransGlobalDecl( gdecl.munged, gdecl.init, gdecl.attrs, gdecl.ty )
 		End If
 		End If
 		InternalErr
 		InternalErr
 	End Method
 	End Method

+ 27 - 0
type.bmx

@@ -55,6 +55,10 @@ Type TType
 	Method ToString$()
 	Method ToString$()
 		Return "??Type??"
 		Return "??Type??"
 	End Method
 	End Method
+	
+	Method GetSize:Int()
+		Return WORD_SIZE
+	End Method
 
 
 	Method ArrayOf:TArrayType()
 	Method ArrayOf:TArrayType()
 		If Not _arrayOf Then
 		If Not _arrayOf Then
@@ -248,6 +252,10 @@ Type TBoolType Extends TType
 		Return "Bool"
 		Return "Bool"
 	End Method
 	End Method
 
 
+	Method GetSize:Int()
+		Return 4
+	End Method
+
 End Type
 End Type
 
 
 Type TNumericType Extends TType
 Type TNumericType Extends TType
@@ -278,6 +286,11 @@ Type TIntType Extends TNumericType
 	Method ToString$()
 	Method ToString$()
 		Return "Int"
 		Return "Int"
 	End Method
 	End Method
+
+	Method GetSize:Int()
+		Return 4
+	End Method
+
 End Type
 End Type
 
 
 Type TByteType Extends TNumericType
 Type TByteType Extends TNumericType
@@ -302,6 +315,11 @@ Type TByteType Extends TNumericType
 	Method ToString$()
 	Method ToString$()
 		Return "Byte"
 		Return "Byte"
 	End Method
 	End Method
+
+	Method GetSize:Int()
+		Return 1
+	End Method
+
 End Type
 End Type
 
 
 Type TShortType Extends TNumericType
 Type TShortType Extends TNumericType
@@ -326,6 +344,11 @@ Type TShortType Extends TNumericType
 	Method ToString$()
 	Method ToString$()
 		Return "Short"
 		Return "Short"
 	End Method
 	End Method
+
+	Method GetSize:Int()
+		Return 2
+	End Method
+
 End Type
 End Type
 
 
 Type TLongType Extends TNumericType ' BaH Long
 Type TLongType Extends TNumericType ' BaH Long
@@ -375,6 +398,10 @@ Type TFloatType Extends TNumericType
 		Return "Float"
 		Return "Float"
 	End Method
 	End Method
 
 
+	Method GetSize:Int()
+		Return 4
+	End Method
+
 End Type
 End Type
 
 
 Type TDoubleType Extends TNumericType
 Type TDoubleType Extends TNumericType