浏览代码

Fixed imported module file identifiers.
Better support for handling file imports for a module.
Ensure float output has a decimal point.
Improved handling of module-specifc identifiers (probably needs a loop to pick up all the dots though).
Don't output "try/catch" texts - for now we just output the content of the try block. TODO : the rest.

woollybah 11 年之前
父节点
当前提交
f9c476dd97
共有 6 个文件被更改,包括 53 次插入22 次删除
  1. 1 1
      config.bmx
  2. 22 11
      ctranslator.bmx
  3. 5 3
      iparser.bmx
  4. 24 5
      parser.bmx
  5. 0 1
      translator.bmx
  6. 1 1
      type.bmx

+ 1 - 1
config.bmx

@@ -190,7 +190,7 @@ Function MungModuleName:String(ident:String)
 End Function
 
 Function MungImportFromFile:String(file:String)
-	Return "// TODO : MungImportFromFile()"
+	Return "_bb_" + file
 End Function
 
 Rem

+ 22 - 11
ctranslator.bmx

@@ -127,8 +127,18 @@ Type TCTranslator Extends TTranslator
 			If TShortType( ty ) Return value
 			If TIntType( ty ) Return value
 			If TLongType( ty ) Return value+"LL"
-			If TFloatType( ty ) Return value+"f"
-			If TDoubleType( ty ) Return value+"f"
+			If TFloatType( ty ) Then
+				If value.Find(".") < 0 Then
+					value :+ ".0"
+				End If
+				Return value+"f"
+			End If
+			If TDoubleType( ty ) Then
+				If value.Find(".") < 0 Then
+					value :+ ".0"
+				End If
+				Return value+"f"
+			End If
 			If TStringType( ty ) Return "String("+Enquote( value )+")"
 			If TByteType( ty ) Return value
 		Else
@@ -310,7 +320,7 @@ Type TCTranslator Extends TTranslator
 		
 	Method TransFunc$( decl:TFuncDecl,args:TExpr[],lhs:TExpr )
 		If decl.IsMethod()
-			If lhs Then
+			If lhs And Not TSelfExpr(lhs) Then
 				If lhs.exprType = TType.stringType Then
 					Return decl.munged + TransArgs(args, decl, TransSubExpr( lhs ))
 'If decl.ident = "Print" DebugStop
@@ -708,15 +718,16 @@ Type TCTranslator Extends TTranslator
 	'***** Statements *****
 
 	Method TransTryStmt$( stmt:TTryStmt )
-		Emit "try{"
+		Emit "// TODO : Try/Catch"
+		Emit "//try{//"
 		EmitBlock( stmt.block )
 		For Local c:TCatchStmt=EachIn stmt.catches
 			MungDecl c.init
-			Emit "}catch("+TransType( c.init.ty, "" )+" "+c.init.munged+"){"
+			Emit "//}catch("+TransType( c.init.ty, "" )+" "+c.init.munged+"){//"
 			'dbgLocals.Push c.init
-			EmitBlock( c.block )
+			'EmitBlock( c.block )
 		Next
-		Emit "}"
+		Emit "//}"
 	End Method
 
 	Method TransAssignStmt$( stmt:TAssignStmt )
@@ -1896,7 +1907,7 @@ End Rem
 	Method EmitModuleInclude(moduleDecl:TModuleDecl)
 		If moduleDecl.filepath Then
 			' a module import
-			If FileType(moduleDecl.filepath) = FILETYPE_DIR Or opt_ismain Then
+			If FileType(moduleDecl.filepath) = FILETYPE_DIR Or (opt_ismain And moduleDecl.ident = opt_modulename) Then
 				Emit "#include <" + ModuleHeaderFromIdent(moduleDecl.ident, True) + ">"
 			Else
 				' maybe a file import...
@@ -1913,7 +1924,7 @@ End Rem
 				Emit MungModuleName(moduleDecl.ident) + "();"
 			Else
 				' maybe a file import...
-				Emit MungImportFromFile(moduleDecl.filepath) + "();"
+				Emit MungImportFromFile(moduleDecl.ident) + "();"
 			End If
 		End If
 	End Method
@@ -1927,7 +1938,7 @@ End Rem
 		prefix = app.GetPathPrefix()
 	
 		' TODO
-'DebugStop
+
 		If Not opt_apptype Then
 			app.mainFunc.munged="bb_localmain"
 		Else
@@ -1936,7 +1947,7 @@ End Rem
 		
 		For Local decl:TModuleDecl=EachIn app.imported.Values()
 			For Local mdecl:TDecl=EachIn decl.imported.Values()
-'DebugStop
+
 				MungDecl mdecl
 DebugLog mdecl.munged
 

+ 5 - 3
iparser.bmx

@@ -35,7 +35,7 @@ Type TIParser
 	Field _tokerStack:TList=New TList'<TToker>
 
 	Method ParseModuleImport:Int(pmod:TModuleDecl, modpath:String, path:String, imp:String = Null, iData:String = Null, attrs:Int = 0, relPath:String = "")
-'DebugStop	
+
 		Const STATE_CLASS:Int = 1
 		
 		
@@ -64,7 +64,7 @@ Type TIParser
 			
 			' import Object and String definitions
 			Local par:TIParser = New TIParser
-			par.ParseModuleImport(_mod, "brl.classes", modulepath("brl.blitz"), "blitz_classes.i")
+			par.ParseModuleImport(_mod, "brl.classes", modulepath("brl.blitz"), modulepath("brl.blitz") + "\blitz_classes.i")
 	
 			' set up built-in keywords
 			par = New TIParser
@@ -80,7 +80,7 @@ Type TIParser
 		
 		'Local ipath:String = path + "\" + ModuleIdent(modpath) + ".release.macos.x86.i"
 		If imp Then
-			ipath = path + "/" + imp
+			ipath = imp
 		Else
 			ipath = path + "/" + ModuleIdent(modpath) + FileMung() + ".i"
 		End If
@@ -88,6 +88,8 @@ Type TIParser
 		If Not iData Then
 DebugLog ipath
 			If Not FileType(ipath) Then
+DebugLog "TODO : missing .i file..."
+DebugLog "FILE NOT FOUND : " + ipath
 				Return False
 			End If
 	

+ 24 - 5
parser.bmx

@@ -496,6 +496,7 @@ Type TParser
 	Method ParseIdentType:TIdentType()
 		Local id$=ParseIdent()
 'DebugLog "ParseIdentType : " + id
+		If CParse( "." ) id:+"."+ParseIdent()
 		If CParse( "." ) id:+"."+ParseIdent()
 		Local args:TIdentType[]
 		If CParse( "<" )
@@ -1904,7 +1905,6 @@ Rem
 		EndIf
 End Rem
 		If CParse( "extends" )
-
 			'If attrs & CLASS_TEMPLATEARG
 			'	Err "Extends cannot be used with class parameters."
 			'EndIf
@@ -2060,8 +2060,8 @@ End Rem
 		
 		If filepath.Endswith(".bmx") Then
 
-			Local path:String = RealPath(filepath)
-			path = OutputFilePath(path, FileMung(), "i")
+			Local origPath:String = RealPath(filepath)
+			Local path:String = OutputFilePath(origPath, FileMung(), "i")
 	
 			If FileType( path )<>FILETYPE_FILE
 				Err "File '"+ path +"' not found."
@@ -2069,11 +2069,20 @@ End Rem
 	
 			
 			If _module.imported.Contains( path ) Return
+			
+			Local modpath:String
+			If opt_buildtype = BUILDTYPE_MODULE Then
+				modpath = opt_modulename + "_" + StripExt(filepath)
+				modpath = modpath.ToLower().Replace(".", "_")
+			Else
+				' todo file imports for apps
+				internalErr
+			End If
 	
 			' try to import interface
 			Local par:TIParser = New TIParser
 	
-			If par.ParseModuleImport(_module, "", "", path, , , filepath) Return
+			If par.ParseModuleImport(_module, modpath, origPath, path, , , filepath) Return
 		Else
 			If filepath.startswith("-") Then
 				_app.fileimports.AddLast filepath
@@ -2164,6 +2173,14 @@ End Rem
 	Method MungAppDecl(app:TAppDecl)
 		If opt_buildtype = BUILDTYPE_MODULE And opt_ismain Then
 			app.munged = MungModuleName(opt_modulename)
+		Else If opt_buildtype = BUILDTYPE_MODULE Then
+			Local dir:String = ExtractDir(opt_filepath).ToLower()
+			dir = dir[dir.findLast("/") + 1..]
+			If dir.EndsWith(".mod") Then
+				dir = dir.Replace(".mod", "")
+			End If
+			Local mung:String = "_bb_" + opt_modulename + "_" + StripExt(StripDir(opt_filepath).ToLower())
+			app.munged = mung.Replace(".", "_")
 		Else
 			' main application file?
 			If opt_apptype Then
@@ -2303,13 +2320,15 @@ End Rem
 		'If CParse( "strict" ) mattrs:|MODULE_STRICT
 		'If CParse( "superstrict" ) mattrs:|MODULE_SUPERSTRICT
 
-
 		Local path$=_toker.Path()
 		Local ident$=StripAll( path )
 		Local munged$	'="bb_"+ident+"_"
 
 		If opt_buildtype = BUILDTYPE_MODULE And opt_ismain
 			ValidateModIdent ident
+		Else If opt_buildtype = BUILDTYPE_MODULE Then
+			munged = opt_modulename + "_" + ident
+			munged = munged.ToLower().Replace(".", "_")
 		End If
 		
 		If opt_ismain Then 'And opt_modulename <> "brl.blitz" Then

+ 0 - 1
translator.bmx

@@ -105,7 +105,6 @@ Type TTranslator
 			EndIf
 
 			If TModuleDecl( decl )
-'DebugStop
 				munged=decl.ModuleScope().munged+"_"+id
 			EndIf
 

+ 1 - 1
type.bmx

@@ -486,7 +486,7 @@ Type TIdentType Extends TType
 	
 	Method Semant:TType()
 		If Not ident Return TClassDecl.nullObjectClass.objectType
-	
+
 		Local targs:TType[args.Length]
 		For Local i:Int=0 Until args.Length
 			targs[i]=args[i].Semant()