2
0
Эх сурвалжийг харах

Fixes for debugger and mobile targets.

Mark Sibly 9 жил өмнө
parent
commit
3e1862c1fd

+ 61 - 0
modules/monkey/native/bbplatform.h

@@ -0,0 +1,61 @@
+
+#ifndef BB_PLATFORM_H
+#define BB_PLATFORM_H
+
+#ifdef _WIN32
+
+	#define BB_WINDOWS 1
+
+   #ifdef _WIN64
+   
+   #endif
+   
+#elif __APPLE__
+
+    #include "TargetConditionals.h"
+    
+    #if TARGET_IPHONE_SIMULATOR
+    
+    #elif TARGET_OS_IPHONE
+    
+    	#define BB_IOS 1
+    	
+    #elif TARGET_OS_MAC
+    
+        #define BB_MACOS 1
+        
+    #else
+    
+    	#error "Unknown Apple platform"
+    
+    #endif
+    
+#elif __EMSCRIPTEN__
+
+	#define BB_EMSCRIPTEN 1
+	    
+#elif __ANDROID__
+
+	#define BB_ANDROID 1
+	
+#elif __linux__
+
+	#define BB_LINUX 1
+
+/*	
+#elif __unix__ // all unices not caught above
+
+    // Unix
+    
+#elif defined(_POSIX_VERSION)
+
+    // POSIX
+*/
+    
+#else
+
+	#error "Unknown compiler"
+
+#endif
+
+#endif

+ 43 - 31
src/mx2cc/buildproduct.monkey2

@@ -334,7 +334,7 @@ Class GccBuildProduct Extends BuildProduct
 		If opts.verbose>0 Print "Compiling "+src
 			
 		If Not isasm cmd+=" -c"
-			
+		
 		cmd+=" -o ~q"+obj+"~q ~q"+src+"~q"
 			
 		Exec( cmd )
@@ -465,7 +465,7 @@ Class GccBuildProduct Extends BuildProduct
 
 			assetsDir=module.outputDir+"assets/"
 			
-			If ExtractExt( outputFile ).ToLower()<>".html" outputFile+=".html"
+			If ExtractExt( outputFile ).ToLower()<>".js" And ExtractExt( outputFile ).ToLower()<>".html" outputFile+=".html"
 			
 			cmd+=" --preload-file ~q"+assetsDir+"@/assets~q"
 		End
@@ -517,34 +517,6 @@ Class GccBuildProduct Extends BuildProduct
 	
 End
 
-Class IosBuildProduct Extends GccBuildProduct
-
-	Method New( module:Module,opts:BuildOpts )
-		Super.New( module,opts )
-	End
-	
-	Method BuildApp() Override
-	
-		Local arc:=BuildArchive()
-		
-		Local outputFile:=module.outputDir+"libmx2_main.a"
-		
-		Local cmd:="libtool -static -o ~q"+outputFile+"~q ~q"+arc+"~q"
-		
-		For Local lib:=Eachin LD_LIBS
-			cmd+=" ~q"+lib+"~q"
-		Next
-		
-		Print "cmd="+cmd
-		
-		Exec( cmd )
-	End
-	
-	Method Run() Override
-	End
-	
-End
-
 Class AndroidBuildProduct Extends BuildProduct
 
 	Method New( module:Module,opts:BuildOpts )
@@ -624,6 +596,8 @@ Class AndroidBuildProduct Extends BuildProduct
 			buf.Push( MakeRelativePath( src,jniDir )+" \" )
 		Next
 		buf.Push( "" )
+
+		buf.Push( "LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES" )
 		
 		If opts.productType="app"
 		
@@ -641,11 +615,16 @@ Class AndroidBuildProduct Extends BuildProduct
 			Next
 			buf.Push( "" )
 			
+			buf.Push( "LOCAL_LDLIBS += -ldl" )
+			
 			For Local lib:=Eachin LD_SYSLIBS
 				If lib.StartsWith( "-l" ) buf.Push( "LOCAL_LDLIBS += "+lib )
 			Next
 			
-			'This keeps the JNI functions in sdl2 alive, or it gets optimized out of the build as its unused...
+			buf.Push( "LOCAL_LDLIBS += -llog -landroid" )
+
+			'This keeps the JNI functions in sdl2 alive, or it gets optimized out of the build as its unused...alas, probably keeps
+			'entire static lib alive...
 			'
 			buf.Push( "LOCAL_WHOLE_STATIC_LIBRARIES := mx2_sdl2" )
 
@@ -654,6 +633,7 @@ Class AndroidBuildProduct Extends BuildProduct
 
 			buf.Push( "include $(BUILD_STATIC_LIBRARY)" )
 		Endif
+
 		
 		CSaveString( buf.Join( "~n" ),jniDir+"Android.mk" )
 		buf.Clear()
@@ -677,3 +657,35 @@ Class AndroidBuildProduct Extends BuildProduct
 	End
 	
 End
+
+Class IosBuildProduct Extends GccBuildProduct
+
+	Method New( module:Module,opts:BuildOpts )
+		Super.New( module,opts )
+	End
+	
+	Method BuildApp() Override
+	
+		Local arc:=BuildArchive()
+
+		Local outputFile:=opts.product+"libmx2_main.a"
+		
+		Local cmd:="libtool -static -o ~q"+outputFile+"~q ~q"+arc+"~q"
+		
+		For Local lib:=Eachin LD_LIBS
+			cmd+=" ~q"+lib+"~q"
+		Next
+		
+		For Local lib:=Eachin LD_SYSLIBS
+			If lib.ToLower().EndsWith( ".a~q" ) cmd+=" "+lib
+		Next
+		
+		Exec( cmd )
+		
+		CopyAssets( opts.product+"assets/" )
+	End
+	
+	Method Run() Override
+	End
+	
+End

+ 3 - 1
src/mx2cc/mx2cc.monkey2

@@ -21,7 +21,9 @@ Global StartDir:String
 
 'Const TestArgs:="mx2cc makedocs mojo"
 
-Const TestArgs:="mx2cc makeapp -clean -config=debug -target=desktop -product=D:/test_app/test.exe -assets=D:/test_app/assets -dlls=D:/test_app/ src/mx2cc/test.monkey2"
+Const TestArgs:="mx2cc makemods"
+
+'Const TestArgs:="mx2cc makeapp -clean -config=debug -target=desktop -product=D:/test_app/test.exe -assets=D:/test_app/assets -dlls=D:/test_app/ src/mx2cc/test.monkey2"
 'Const TestArgs:="mx2cc makeapp -clean -config=debug -target=desktop src/mx2cc/test.monkey2"
 
 'Const TestArgs:="mx2cc makeapp -clean src/ted2/ted2"

+ 118 - 8
src/mx2cc/parser.monkey2

@@ -12,6 +12,7 @@ Class Parser
 	End
 	
 	Method New( source:String,ppsyms:StringMap<String> )
+		Self.New()
 	
 		_ppsyms=ppsyms
 		
@@ -23,6 +24,9 @@ Class Parser
 	
 		_ppsyms=ppsyms
 		
+		_cc.Clear()
+		_cc.Push( 1 )
+		
 		_fdecl=New FileDecl
 		_fdecl.ident=ident
 		_fdecl.path=srcPath
@@ -1837,7 +1841,8 @@ Class Parser
 				
 				Continue
 				
-			Else If _ccnest<>_ifnest
+'			Else If _ccnest<>_ifnest
+			Else If _cc.Top<>1
 			
 				Local pos:=_toker.LinePos
 			
@@ -1904,9 +1909,18 @@ Class Parser
 	
 	'***** Messy Preprocessor - FIXME! *****
 	
+	Class EvalEx Extends Throwable
+		Field msg:String
+		Method new( msg:String )
+			Self.msg=msg
+		End
+	End
+	
 	Field _ppsyms:StringMap<String>
-	Field _ccnest:Int
-	Field _ifnest:Int
+	
+	Field _cc:=New Stack<Int>
+'	Field _ccnest:Int
+'	Field _ifnest:Int
 	Field _docs:=New StringStack
 	Field _doccing:Bool
 	Field _imports:=New StringStack
@@ -1921,7 +1935,8 @@ Class Parser
 	End
 	
 	Method EvalError( msg:String )
-		Error( "Failed to evaluate preprocessor expression: "+msg )' toke='"+Toke+"'" )
+		Throw New EvalEx( msg )
+'		Error( "Failed to evaluate preprocessor expression: "+msg )' toke='"+Toke+"'" )
 	End
 		
 	Method EvalPrimary:String()
@@ -1936,14 +1951,13 @@ Class Parser
 		Case TOKE_IDENT
 			Local id:=Parse()
 			Local t:=_ppsyms[id]
-			If Not t EvalError( "Preprocessor symbol '"+id+"' not found" )
-'			If Not t t="false"
+			If Not t EvalError( "symbol '"+id+"' not found" )
 			Return t
 		Case TOKE_STRINGLIT
 			Return Parse()
 		End
 
-		EvalError( "Failed to evaludate preprocessor expression - unexpected token '"+Toke+"'" )
+		EvalError( "unexpected token '"+Toke+"'" )
 		Return Null
 	End
 	
@@ -2009,6 +2023,99 @@ Class Parser
 	
 		Try
 		
+			Select p.Toke.ToLower()
+			Case "if"
+			
+				If _cc.Top=1
+					p.Bump()
+					If p.EvalBool() _cc.Push( 1 ) Else _cc.Push( 0 )
+				Else
+					_cc.Push( -1 )
+				Endif
+				
+			Case "else","elseif"
+			
+				If _cc.Top=1
+				
+					_cc.Pop()
+					_cc.Push( -1 )
+					
+				Else If _cc.Top=0
+
+					Local t:=True
+
+					If p.CParse( "else" )
+						If p.CParse( "if" ) t=p.EvalBool()
+					Else 
+						p.Bump()
+						t=p.EvalBool()
+					Endif
+					
+					If t
+						_cc.Pop()
+						_cc.Push( 1 )
+					Endif
+				
+				Endif
+				
+			Case "end","endif"
+			
+				If _cc.Length=1 EvalError( "#end without matching #if or #rem" )
+			
+				If p.CParse( "end" )
+					p.CParse( "if" )
+				Else
+					p.Bump()
+				End
+				
+				_cc.Pop()
+				
+				If _cc.Top=1 _doccing=False
+				
+			Case "rem"
+			
+				If _cc.Top=1 And p.Bump()="monkeydoc"
+
+					Local qhelp:=p._toker.Text.Slice( p._toker.TokePos+9 ).Trim()
+					_docs.Clear()
+					_docs.Push( qhelp )
+					_doccing=True
+
+				Endif
+				
+				_cc.Push( -1 )
+				
+			Case "import"
+			
+				If _cc.Top=1
+
+					p.Bump()
+					Local path:=p.ParseString()
+					
+					If path.StartsWith( "<" ) And path.EndsWith( ">" )
+					
+						If Not ExtractExt( path ) path=path.Slice( 0,-1 )+".monkey2>"
+						
+					Else If Not path.Contains( "@/" ) And Not path.EndsWith( "/" )
+					
+						If Not ExtractExt( path ) path+=".monkey2"
+						
+					Endif
+					
+					_imports.Push( path )
+					
+				Endif
+				
+			Case "print"
+			
+				If _cc.Top=1
+					p.Bump()				
+					Print p.Eval()
+				Endif
+				
+			End
+		
+			#rem
 			Select p.Toke.ToLower()
 			Case "if"
 				
@@ -2096,8 +2203,11 @@ Class Parser
 				Endif
 				
 			End
+			#end
 			
-		Catch ex:ParseEx
+		Catch ex:EvalEx
+		
+			Error( "Preprocessor error - "+ex.msg )
 		End
 		
 	End

+ 7 - 19
src/mx2cc/test.monkey2

@@ -1,27 +1,15 @@
 
-Namespace myapp
+#if __DESKTOP_TARGET__
 
-#Import "<std>"
-#Import "<mojo>"
+#else
 
-Using std..
-Using mojo..
+#if __TARGET__="emscripten"
 
-Class MyWindow Extends Window
+#endif
 
-	Method OnRender( canvas:Canvas ) Override
-	
-		canvas.DrawText( "Hello World",Width/2,Height/2,.5,.5 )
-	
-	End
-	
-End
+KNOB!
 
-Function Main()
+#endif
 
-	New AppInstance
-	
-	New MyWindow
-	
-	App.Run()
+Function Main()
 End