Prechádzať zdrojové kódy

WIP geninfo, add "semtype" for var decls.

Mark Sibly 7 rokov pred
rodič
commit
7110e3ea5d

+ 5 - 7
src/mx2cc/block.monkey2

@@ -26,13 +26,11 @@ Class Block Extends Scope
 		inex=outer.inex
 	End
 	
-'	Property IsGeneric:Bool() Override
-
-'		If func.IsGeneric Return True
-
-'		Return Super.IsGeneric
-'	End
-
+	Property IsInstanceOf:Bool() Override
+		
+		Return func.instanceOf<>Null ?Else Super.IsInstanceOf
+	End
+	
 	Method FindValue:Value( ident:String ) Override
 
 		Local node:=FindNode( ident )

+ 6 - 0
src/mx2cc/errors.monkey2

@@ -130,11 +130,17 @@ Class OverloadEx Extends SemantEx
 End
 
 Function SemantError( func:String )
+#If __CONFIG__="debug"
+	DebugStop()
+#endif
 	Print "~n".Join( GetDebugStack() )
 	Throw New SemantEx( func+" Internal Error" )
 End
 
 Function TransError( func:String )
+#If __CONFIG__="debug"
+	DebugStop()
+#endif
 	Print "~n".Join( GetDebugStack() )
 	Throw New SemantEx( func+" Internal Error" )
 End

+ 4 - 2
src/mx2cc/geninfo/geninfo.monkey2

@@ -140,7 +140,9 @@ Class ParseInfoGenerator
 		If decl.type node.SetValue( "type",GenNode( decl.type ) )
 		
 		If decl.init node.SetValue( "init",GenNode( decl.init ) )
-		
+			
+		If decl.semtype node.SetString( "semtype",decl.semtype.Name )
+			
 		Return node
 	End
 	
@@ -330,5 +332,5 @@ Class ParseInfoGenerator
 		
 		Return node
 	End
-
+	
 End

+ 7 - 2
src/mx2cc/mx2cc.monkey2

@@ -22,10 +22,10 @@ Global opts_time:Bool
 
 Global StartDir:String
 
-Const TestArgs:="mx2cc makedocs mojo"
+'Const TestArgs:="mx2cc makemods"
  
 'Const TestArgs:="mx2cc makeapp src/mx2cc/test.monkey2"
-Const TestArgs:="mx2cc makeapp -parse -geninfo src/mx2cc/test.monkey2"
+Const TestArgs:="mx2cc makeapp -semant -geninfo src/mx2cc/test.monkey2"
 
 'Const TestArgs:="mx2cc makeapp -verbose src/mx2cc/catan/main.monkey2"
 
@@ -206,6 +206,11 @@ Function MakeApp:Bool( args:String[] )
 	Builder.Semant()
 	If Builder.errors.Length Return False
 	If opts.passes=2
+		If opts.geninfo
+			Local gen:=New ParseInfoGenerator
+			Local jobj:=gen.GenParseInfo( Builder.mainModule.fileDecls[0] )
+			Print jobj.ToJson()
+		Endif
 		Return True
 	Endif
 	

+ 12 - 1
src/mx2cc/test.monkey2

@@ -1,4 +1,15 @@
-Function Main:Int()
+
+#Import "<mojo>"
+
+Using mojo..
+
+Function Test:Int()
+	Return 0
+End
+
+Global g:=Image.Load( "test.png" )'New Image( 256,256 )
+
+Function Main:Void()
 	Local x:Int
 	Local y:Int
 	If x<10

+ 8 - 14
src/mx2cc/var.monkey2

@@ -6,6 +6,8 @@ Class VarDecl Extends Decl
 	Field type:Expr
 	Field init:Expr
 	
+	Field semtype:Type
+	
 	Method ToNode:SNode( scope:Scope ) Override
 	
 		Return New VarValue( Self,scope )
@@ -80,7 +82,7 @@ Class VarValue Extends Value
 			type=vdecl.type.SemantType( scope )
 			
 			If vdecl.init init=vdecl.init.SemantRValue( scope,type )
-			
+				
 		Else If vdecl.init
 		
 			init=vdecl.init.SemantRValue( scope )
@@ -88,34 +90,26 @@ Class VarValue Extends Value
 			If TCast<VoidType>( init.type ) Throw New SemantEx( "Variables cannot have 'Void' type" )
 			
 			type=init.type
-			
 		Else 
 
 			SemantError( "VarValue.OnSemant()" )
 
 		Endif
 		
-		If Not scope.IsGeneric And Not vdecl.IsExtern And Not Cast<Block>( scope )
-		
-			If vdecl.kind="global" Or vdecl.kind="const"
-				transFile.globals.Push( Self )
-			Else
-				scope.transMembers.Push( Self )
-			Endif
-  		
+		If Not scope.IsInstanceOf
+			If vdecl.semtype SemantError( "VarValue.OnSemant() 2" )
+			vdecl.semtype=type
 		Endif
 		
-		#rem
-		If Not type.IsGeneric And Not vdecl.IsExtern And Not Cast<Block>( scope )
+		If Not scope.IsGeneric And Not vdecl.IsExtern And Not Cast<Block>( scope )
 		
 			If vdecl.kind="global" Or vdecl.kind="const"
 				transFile.globals.Push( Self )
 			Else
 				scope.transMembers.Push( Self )
 			Endif
-			
+  		
 		Endif
-		#end
 		
 		Scope.semanting.Pop()