Selaa lähdekoodia

reflection updates.

Mark Sibly 8 vuotta sitten
vanhempi
commit
1f599ecd11

+ 4 - 2
src/mx2cc/buildproduct.monkey2

@@ -332,7 +332,8 @@ Class GccBuildProduct Extends BuildProduct
 			
 		Local rfile:=src.EndsWith( "/_r.cpp" )
 
-		Local obj:=module.cacheDir+MungPath( MakeRelativePath( src,module.cacheDir ) )
+'		Local obj:=module.cacheDir+MungPath( MakeRelativePath( src,module.cacheDir ) )
+		Local obj:=module.cacheDir+MungPath( MakeRelativePath( src,module.cfileDir ) )
 		If rfile And opts.reflection obj+="_r"
 			
 		obj+=toolchain="msvc" ? ".obj" Else ".o"
@@ -773,7 +774,8 @@ Class AndroidBuildProduct Extends BuildProduct
 		buf.Push( "LOCAL_SRC_FILES := \" )
 		
 		For Local src:=Eachin srcs
-			buf.Push( MakeRelativePath( src,jniDir )+" \" )
+'			buf.Push( MakeRelativePath( src,jniDir )+" \" )
+			buf.Push( MakeRelativePath( src,module.cfileDir )+" \" )
 		Next
 		
 		buf.Push( "" )

+ 1 - 1
src/mx2cc/mx2.monkey2

@@ -50,4 +50,4 @@ Using libc
 ' 3) edit .sh and .bat files to use new version (common.sh, common.bat)
 ' 4) ./rebuildall
 '
-Const MX2CC_VERSION:="1.1.07"
+Const MX2CC_VERSION:="1.1.08"

+ 5 - 3
src/mx2cc/mx2cc.monkey2

@@ -24,11 +24,13 @@ Using libc..
 Using std..
 Using mx2..
 
+Const MX2CC_VERSION_EXT:=""
+
 Global StartDir:String
 
-Const TestArgs:="mx2cc makedocs mojo3d"	' monkey libc miniz stb-image stb-image-write stb-vorbis std"
+'Const TestArgs:="mx2cc makedocs monkey libc miniz stb-image stb-image-write stb-vorbis std mojo mojo3d"
 
-'Const TestArgs:="mx2cc makeapp src/mx2cc/test.monkey2"
+Const TestArgs:="mx2cc makeapp src/mx2cc/test.monkey2"
 
 'Const TestArgs:="mx2cc makedocs mojo3d"
 
@@ -54,7 +56,7 @@ Function Main()
 	GCSetTrigger( 64*1024*1024 )
 
 	Print ""
-	Print "Mx2cc version "+MX2CC_VERSION
+	Print "Mx2cc version "+MX2CC_VERSION+MX2CC_VERSION_EXT
 	
 	StartDir=CurrentDir()
 	

+ 1 - 0
src/mx2cc/property.monkey2

@@ -46,6 +46,7 @@ Class PropertyList Extends FuncList
 				getFunc=New FuncValue( pdecl.getFunc,scope,Null,Null )
 				getFunc.Semant()
 				type=getFunc.ftype.retType
+				If type.Equals( Type.VoidType ) Throw New SemantEx( "Property '"+pdecl.ident+"' getter has void type" )
 				PushFunc( getFunc )
 			Catch ex:SemantEx
 			End

+ 13 - 8
src/mx2cc/test.monkey2

@@ -1,14 +1,19 @@
 
-#Import "<std>"
+#Import "<reflection>"
 
-Using std..
+Struct S
+	Field x:int
+
+End
+
+Function F:S Ptr()
+	Return null
+End
+
+Function F2:Int ptr()
+	Return Null
+End
 
 Function Main()
 	
-	Local idata:=New Int[10],ip:=idata.Data,i0:=ip
-	
-	ip+=10
-	
-	Print ip-i0
-	
 End

+ 5 - 1
src/mx2cc/translator.monkey2

@@ -340,7 +340,11 @@ Class Translator
 				
 				If GenTypeInfo( ctype ) 
 					Emit( "#ifdef BB_REFLECTION" )
-					Emit( "bbTypeInfo *bbGetType( "+cname+"* const& );" )
+					If ctype.IsStruct 
+						Emit( "bbTypeInfo *bbGetType( "+cname+" const& );" )
+					Else
+						Emit( "bbTypeInfo *bbGetType( "+cname+"* const& );" )
+					Endif
 					Emit( "#endif" )
 				Endif
 				

+ 55 - 14
src/mx2cc/translator_cpp.monkey2

@@ -79,13 +79,21 @@ Class Translator_CPP Extends Translator
 				Uses( ctype )
 				
 				Local cname:=ClassName( ctype )
+				Local rname:=""
 				
-				Emit( "bbTypeInfo *bbGetType("+cname+"* const&){" )
-				Emit( "return &bbObjectTypeInfo::instance;" )
+				If ctype.IsStruct
+					Emit( "bbTypeInfo *bbGetType("+cname+" const&){" )
+					rname="bbVoidTypeInfo"
+				Else
+					Emit( "bbTypeInfo *bbGetType("+cname+"* const&){" )
+					rname="bbObjectTypeInfo"
+				Endif
+								
+				Emit( "return &"+rname+"::instance;" )
 				Emit( "}" )
 				
 				Emit( "bbTypeInfo *"+cname+"::typeof()const{" )
-				Emit( "return &bbObjectTypeInfo::instance;" )
+				Emit( "return &"+rname+"::instance;" )
 				Emit( "}" )
 				
 			Next
@@ -579,7 +587,11 @@ Class Translator_CPP Extends Translator
 		Emit( "};" )
 		
 		If GenTypeInfo( ctype )
-			Emit( "bbTypeInfo *bbGetType( "+cname+"* const& );" )
+			If ctype.IsStruct
+				Emit( "bbTypeInfo *bbGetType( "+cname+" const& );" )
+			Else
+				Emit( "bbTypeInfo *bbGetType( "+cname+"* const& );" )
+			Endif
 		Endif
 		
 		If _debug
@@ -1011,14 +1023,39 @@ Class Translator_CPP Extends Translator
 		Emit( rcname+"::decls_t "+rcname+"::decls;" )
 		
 		EmitBr()
-		Emit( "bbTypeInfo *"+cname+"::typeof()const{" )
+
+		If ctype.IsStruct
+			Emit( "bbTypeInfo *bbGetType( "+cname+" const& ){" )
+		Else
+			Emit( "bbTypeInfo *bbGetType( "+cname+"* const& ){" )
+		Endif
+
 		Emit( "return &"+rcname+"::instance;" )
 		Emit( "}" )
-		
-		EmitBr()
-		Emit( "bbTypeInfo *bbGetType( "+cname+"* const& ){" )
+
+		Emit( "bbTypeInfo *"+cname+"::typeof()const{" )
 		Emit( "return &"+rcname+"::instance;" )
 		Emit( "}" )
+		
+		#rem
+		If ctype.IsStruct
+			EmitBr()
+			Emit( "bbTypeInfo *bbGetType( "+cname+" const& ){" )
+			Emit( "return &"+rcname+"::instance;" )
+			Emit( "}" )
+		Else
+			EmitBr()
+			Emit( "bbTypeInfo *"+cname+"::typeof()const{" )
+			Emit( "return &"+rcname+"::instance;" )
+			Emit( "}" )
+			
+			EmitBr()
+			Emit( "bbTypeInfo *bbGetType( "+cname+"* const& ){" )
+			Emit( "return &"+rcname+"::instance;" )
+			Emit( "}" )
+		Endif
+		#end
+		
 	End
 
 	'For later...
@@ -2200,7 +2237,7 @@ Function GenTypeInfo:Bool( vvar:VarValue )
 
 	If vvar.vdecl.kind<>"field" And vvar.vdecl.kind="global" And vvar.vdecl.kind="const" Return False
 	
-	Return True	'GenTypeInfo( vvar.type )
+	Return True
 End
 
 Function GenTypeInfo:Bool( func:FuncValue )
@@ -2209,17 +2246,21 @@ Function GenTypeInfo:Bool( func:FuncValue )
 
 	If func.IsExtension Return False
 	
-	Return True	'GenTypeInfo( func.ftype )
+	Return True
 End
 
 Function GenTypeInfo:Bool( ctype:ClassType )
 
-	If ctype.IsStruct Return False
-
-	'This 'sort of' works, but no generics just yet!
+	'disable generic instances
 	If ctype.types Or ctype.scope.IsInstanceOf Return False
+
+	'disable structs
+	'If ctype.IsStruct Return False
+
+	'disable native types
+	If ctype.ExtendsVoid Return False
 	
-	'No extensions yet either
+	'disable type extensions
 	If ctype.cdecl.IsExtension Return False
 	
 	Return True

+ 2 - 2
src/ted2go/Ted2.monkey2

@@ -13,7 +13,7 @@
 
 '----------------------------
 
-'#Import "<reflection>"
+#Import "<reflection>"
 
 #Import "<std>"
 #Import "<mojo>"
@@ -71,7 +71,7 @@
 #Import "syntax/CodeFormatter"
 #Import "syntax/Monkey2Formatter"
 
-#Import "testing/ParserTests"
+'#Import "testing/ParserTests"
 
 #Import "utils/JsonUtils"
 #Import "utils/Utils"