Jelajahi Sumber

mx2cc cleanups.

Mark Sibly 9 tahun lalu
induk
melakukan
7ac42e3af6

+ 17 - 14
src/mx2new/func.monkey2

@@ -76,7 +76,7 @@ Class FuncValue Extends Value
 		Self.transFile=scope.FindFile().fdecl
 		Self.transFile=scope.FindFile().fdecl
 		Self.cscope=Cast<ClassScope>( scope )
 		Self.cscope=Cast<ClassScope>( scope )
 		
 		
-		If fdecl.kind="lambda" captures=New Stack<VarValue>
+		If IsLambda captures=New Stack<VarValue>
 	End
 	End
 	
 	
 	Property GenArgsName:String()
 	Property GenArgsName:String()
@@ -137,6 +137,10 @@ Class FuncValue Extends Value
 		Return (fdecl.kind="method" And types) Or fdecl.IsExtension
 		Return (fdecl.kind="method" And types) Or fdecl.IsExtension
 	End
 	End
 	
 	
+	Property IsLambda:Bool()
+		Return fdecl.kind="lambda"
+	End
+	
 	Method ToString:String() Override
 	Method ToString:String() Override
 	
 	
 		Local args:=Join( types )
 		Local args:=Join( types )
@@ -189,9 +193,7 @@ Class FuncValue Extends Value
 		
 		
 		Else If IsMethod
 		Else If IsMethod
 		
 		
-'			Local cscope:=Cast<ClassScope>( scope )
 			Local ctype:=cscope.ctype
 			Local ctype:=cscope.ctype
-'			Local cdecl:=ctype.cdecl
 			
 			
 			If fdecl.IsOperator
 			If fdecl.IsOperator
 				Local op:=fdecl.ident
 				Local op:=fdecl.ident
@@ -251,7 +253,7 @@ Class FuncValue Extends Value
 			If Not t Return Null
 			If Not t Return Null
 		Endif
 		Endif
 		
 		
-		If fdecl.kind="lambda"
+		If IsLambda
 			used=True
 			used=True
 			semanted=Self
 			semanted=Self
 			SemantStmts()
 			SemantStmts()
@@ -275,16 +277,16 @@ Class FuncValue Extends Value
 	Method ToValue:Value( instance:Value ) Override
 	Method ToValue:Value( instance:Value ) Override
 	
 	
 		Local value:Value=Self
 		Local value:Value=Self
-	
-		If fdecl.ident="new"
+		
+		If IsCtor
 		
 		
 			If instance Throw New SemantEx( "'New' cannot be directly invoked" )
 			If instance Throw New SemantEx( "'New' cannot be directly invoked" )
 			
 			
-		Else If fdecl.kind="method"
+		Else If IsMethod
 		
 		
 			If Not instance Throw New SemantEx( "Method '"+ToString()+"' cannot be accessed without an instance" )
 			If Not instance Throw New SemantEx( "Method '"+ToString()+"' cannot be accessed without an instance" )
 			
 			
-			If Not instance.type.ExtendsType( Cast<ClassScope>( scope ).ctype )
+			If Not instance.type.ExtendsType( cscope.ctype )
 				Throw New SemantEx( "Method '"+ToString()+"' cannot be accessed from an instance of a different class" )
 				Throw New SemantEx( "Method '"+ToString()+"' cannot be accessed from an instance of a different class" )
 			Endif
 			Endif
 			
 			
@@ -340,19 +342,19 @@ Class FuncValue Extends Value
 			End
 			End
 		Next
 		Next
 		
 		
-		If fdecl.kind="method"
+		If IsCtor Or IsMethod
 	
 	
 			If IsExtension
 			If IsExtension
 	
 	
-				selfValue=New VarValue( "capture","self",New LiteralValue( Cast<ClassScope>( scope ).ctype,"" ),scope )
+				selfValue=New VarValue( "capture","self",New LiteralValue( cscope.ctype,"" ),scope )
 				
 				
-			Else If fdecl.kind="method"
+			Else
 			
 			
-				selfValue=New SelfValue( Cast<ClassScope>( scope ).ctype )
+				selfValue=New SelfValue( cscope.ctype )
 				
 				
 			Endif
 			Endif
 			
 			
-		Else If fdecl.kind="lambda"
+		Else If IsLambda
 		
 		
 			selfValue=Cast<Block>( scope ).func.selfValue
 			selfValue=Cast<Block>( scope ).func.selfValue
 			If selfValue
 			If selfValue
@@ -419,7 +421,8 @@ Class FuncValue Extends Value
 
 
 		Else
 		Else
 		
 		
-			If fdecl.kind="method"
+			If IsCtor Or IsMethod
+			
 '				If fdecl.ident="new"
 '				If fdecl.ident="new"
 '					cscope.ctype.ctors.Push( Self )
 '					cscope.ctype.ctors.Push( Self )
 '				Else
 '				Else

+ 1 - 1
src/mx2new/mx2.monkey2

@@ -47,4 +47,4 @@ Using lib.c
 ' 3) edit .sh and .bat files to use new version (common.sh, updatemx2cc.bat, rebuildmx2cc.bat)
 ' 3) edit .sh and .bat files to use new version (common.sh, updatemx2cc.bat, rebuildmx2cc.bat)
 ' 4) ./rebuildall
 ' 4) ./rebuildall
 '
 '
-Const MX2CC_VERSION:="006"
+Const MX2CC_VERSION:="008"

+ 58 - 7
src/mx2new/mx2cc.monkey2

@@ -11,16 +11,13 @@ Using mx2.docs
 #Import "docsmaker.monkey2"
 #Import "docsmaker.monkey2"
 #Import "htmldocsmaker.monkey2"
 #Import "htmldocsmaker.monkey2"
 
 
-Using std
-Using mx2
-Using std.stringio
-Using std.filesystem
-Using lib.c
-Using libc
+Using libc..
+Using std..
+Using mx2..
 
 
 Global StartDir:String
 Global StartDir:String
 
 
-Const TestArgs:="mx2cc makedocs"
+Const TestArgs:="mx2cc makemods -clean"
 
 
 'Const TestArgs:="mx2cc makeapp src/mx2new/test.monkey2"
 'Const TestArgs:="mx2cc makeapp src/mx2new/test.monkey2"
 
 
@@ -274,6 +271,59 @@ Function ParseOpts:String[]( opts:BuildOpts,args:String[] )
 	Return Null
 	Return Null
 End
 End
 
 
+Function EnumModules( out:StringStack,cur:String,deps:StringMap<StringStack> )
+	If out.Contains( cur ) Return
+	
+	For Local dep:=Eachin deps[cur]
+		EnumModules( out,dep,deps )
+	Next
+	
+	out.Push( cur )
+End
+
+Function EnumModules:String[]()
+
+	Local mods:=New StringMap<StringStack>
+
+	For Local f:=Eachin LoadDir( "modules" )
+	
+		Local dir:="modules/"+f+"/"
+		If GetFileType( dir )<>FileType.Directory Continue
+		
+		Local str:=LoadString( dir+"module.json" )
+		If Not str Continue
+		
+		Local obj:=JsonObject.Parse( str )
+		If Not obj 
+			Print "Error parsing json:"+dir+"module.json"
+			Continue
+		Endif
+		
+		Local name:=obj["module"].ToString()
+		If name<>f Continue
+		
+		Local deps:=New StringStack
+		If name<>"monkey" deps.Push( "monkey" )
+		
+		Local jdeps:=obj["depends"]
+		If jdeps
+			For Local dep:=Eachin jdeps.ToArray()
+				deps.Push( dep.ToString() )
+			Next
+		Endif
+		
+		mods[name]=deps
+	Next
+	
+	Local out:=New StringStack
+	For Local cur:=Eachin mods.Keys
+		EnumModules( out,cur,mods )
+	Next
+	
+	Return out.ToArray()
+End
+
+#rem
 Function EnumModules:String[]()
 Function EnumModules:String[]()
 
 
 	Local mods:=New StringStack
 	Local mods:=New StringStack
@@ -290,6 +340,7 @@ Function EnumModules:String[]()
 	
 	
 	Return mods.ToArray()
 	Return mods.ToArray()
 End
 End
+#end
 
 
 Function LoadEnv:Bool( path:String )
 Function LoadEnv:Bool( path:String )
 
 

+ 9 - 7
src/mx2new/translator.monkey2

@@ -293,7 +293,9 @@ Class Translator
 	Field _usesFiles:=New StringMap<FileDecl>
 	Field _usesFiles:=New StringMap<FileDecl>
 	Field _usesTypes:=New StringMap<ClassType>
 	Field _usesTypes:=New StringMap<ClassType>
 	
 	
-	Field _refs:=New StringMap<SNode>
+	Field _refs:=New Map<SNode,Bool>
+	
+'	Field _refs:=New StringMap<SNode>
 	Field _refsVars:=New Stack<VarValue>
 	Field _refsVars:=New Stack<VarValue>
 	Field _refsFuncs:=New Stack<FuncValue>
 	Field _refsFuncs:=New Stack<FuncValue>
 	Field _refsTypes:=New Stack<ClassType>
 	Field _refsTypes:=New Stack<ClassType>
@@ -371,9 +373,9 @@ Class Translator
 		_incs[fdecl.ident]=fdecl
 		_incs[fdecl.ident]=fdecl
 	End
 	End
 	
 	
-	Method AddRef:Bool( name:String,node:SNode )
-		If _refs.Contains( name ) Return True
-		_refs[name]=node
+	Method AddRef:Bool( node:SNode )
+		If _refs[node] Return True
+		_refs[node]=True
 		Return False
 		Return False
 	End
 	End
 	
 	
@@ -386,7 +388,7 @@ Class Translator
 			Refs( vvar.type )
 			Refs( vvar.type )
 			Uses( vvar.scope.FindClass() )
 			Uses( vvar.scope.FindClass() )
 		Case "const","global"
 		Case "const","global"
-			If AddRef( VarName( vvar ),vvar ) Return
+			If AddRef( vvar ) Return
 			_refsVars.Push( vvar )
 			_refsVars.Push( vvar )
 			Refs( vvar.type )
 			Refs( vvar.type )
 		Case "local","param","capture"
 		Case "local","param","capture"
@@ -402,7 +404,7 @@ Class Translator
 		If fdecl.IsExtern Uses( func.transFile ) ; Return
 		If fdecl.IsExtern Uses( func.transFile ) ; Return
 		
 		
 		If fdecl.kind="function" Or func.IsExtension
 		If fdecl.kind="function" Or func.IsExtension
-			If AddRef( FuncName( func ),func ) Return
+			If AddRef( func ) Return
 			_refsFuncs.Push( func )
 			_refsFuncs.Push( func )
 			Refs( func.ftype )
 			Refs( func.ftype )
 		Else If fdecl.kind="method"
 		Else If fdecl.kind="method"
@@ -419,7 +421,7 @@ Class Translator
 		Local ctype:=TCast<ClassType>( type )
 		Local ctype:=TCast<ClassType>( type )
 		If ctype
 		If ctype
 			If IsStruct( ctype ) Uses( ctype ) ; Return
 			If IsStruct( ctype ) Uses( ctype ) ; Return
-			If AddRef( ClassName( ctype ),ctype ) Return
+			If AddRef( ctype ) Return
 			_refsTypes.Push( ctype )
 			_refsTypes.Push( ctype )
 			Return
 			Return
 		Endif
 		Endif

+ 1 - 1
src/mx2new/util.monkey2

@@ -85,7 +85,7 @@ Function MakeRelativePath:String( path:String,baseDir:String )
 		Local tdir:=baseDir
 		Local tdir:=baseDir
 		baseDir=ExtractDir( baseDir )
 		baseDir=ExtractDir( baseDir )
 		If baseDir=tdir 
 		If baseDir=tdir 
-			Print "MakeRelativePath Error! baseDir="+baseDir
+'			Print "MakeRelativePath Error! baseDir="+baseDir
 			Return path
 			Return path
 		Endif
 		Endif
 		relpath="../"+relpath
 		relpath="../"+relpath