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

Cleanups + docs to monkey module.

Mark Sibly 9 жил өмнө
parent
commit
b04ce36ec7

+ 15 - 4
modules/monkey/debug.monkey2

@@ -3,11 +3,22 @@ Namespace monkey.debug
 
 Extern
 
-#rem monkeydoc @hidden
+#rem monkeydoc Stops the app and activates the debugger (debug builds only).
+
+Stops the app, causing the debugger (if available) to activate. The app will then wait for further instructions from the
+debugger (step, continue, end etc).
+
+The debugger is only available in debug builds, and when running an app from the Ted2 IDE.
+
 #end
 Function DebugStop()="bbDB::stop"
 
-#rem monkeydoc @hidden
+#rem monkeydoc Generates a non-recoverable runtime error.
+
+Halts the program with a non-recoverable runtime error.
+
+@param message Runtime error message to generate.
+
 #end
 Function RuntimeError( message:String )="bbDB::error"
 
@@ -20,7 +31,7 @@ Function RuntimeError( message:String )="bbDB::error"
 #end
 Function Assert( condition:Bool,message:String="Assert failed" )="bbAssert"
 
-#rem monkeydoc Generates a runtime error if a boolean expression is false (Debug builds only).
+#rem monkeydoc Generates a runtime error if a boolean expression is false (debug builds only).
 
 This function does not execute at all in release builds, so make sure that `condition` doesn't inadvertantly execute
 any critical code.
@@ -32,7 +43,7 @@ any critical code.
 #end
 Function DebugAssert( condition:Bool,message:String="Debug assert failed" )="bbDebugAssert"
 
-#rem monkeydoc Gets the current stack state (Debug builds only).
+#rem monkeydoc Gets the current stack state (debug builds only).
 
 In release mode, an empty array is returned.
 

+ 16 - 0
modules/monkey/math.monkey2

@@ -114,7 +114,15 @@ Function Ceil:Double( x:Double )="std::ceil"
 @return The integral value nearest to `x`.
 
 #end
+#if __TARGET__="android"
+Public
+Function Round:Double( x:Double )
+	Return Floor( x+.5 )
+End
+Extern
+#else
 Function Round:Double( x:Double )="std::round"
+#endif
 
 
 #rem monkeydoc Raises a number to a power.
@@ -143,7 +151,15 @@ Function Log:Double( x:Double )="std::log"
 @return The base 2 logarithm of `x`.
 
 #end
+#if __TARGET__="android"
+Public
+Function Log2:Double( x:Double )
+	Return Log(x)/Log(2)
+End
+Extern
+#else
 Function Log2:Double( x:Double )="std::log2"
+#endif
 
 #rem monkeydoc Computes the base 10 logarithm of a number.
 

+ 5 - 1
modules/monkey/module.json

@@ -1,4 +1,8 @@
 {
 	"module":"monkey",
-	"version":"1.0.0"
+	"about":"Core language functionality",
+	"author":"Mark Sibly",
+	"version":"1.0.0",
+	"support":"http://monkey2.monkey-x.com",
+	"depends":[]
 }

+ 11 - 5
modules/monkey/native/bbdebug.cpp

@@ -30,15 +30,16 @@ namespace bbDB{
 		case SIGSEGV:err="Memory access violation";break;
 		case SIGILL:err="Illegal instruction";
 		case SIGFPE:err="Floating point exception";
-	#if !_WIN32
+#if !_WIN32
 		case SIGBUS:err="Bus error";
-	#endif	
+#endif	
 		}
 				
 #ifndef NDEBUG
 		error( err );
 		exit( 0 );
 #endif
+
 		printf( "Caught signal:%s\n",err );
 		exit( -1 );
 	}
@@ -51,9 +52,13 @@ namespace bbDB{
 		signal( SIGSEGV,sighandler );
 		signal( SIGILL,sighandler );
 		signal( SIGFPE,sighandler );
+#if !_WIN32
+		signal( SIGBUS,sighandler );
+#endif		
 
+#ifndef NDEBUG
+		
 #if _WIN32
-
 		if( HANDLE breakEvent=OpenEvent( EVENT_ALL_ACCESS,false,"MX2_BREAK_EVENT" ) ){
 //			printf( "Found BREAK_EVENT!\n" );fflush( stdout );
 		    std::thread( [=](){
@@ -64,11 +69,12 @@ namespace bbDB{
 		    	}
 		    } ).detach();
 		}
-	
 #else		
-		signal( SIGBUS,sighandler );
 		signal( SIGTSTP,breakHandler );
 #endif
+
+#endif
+
 	}
 	
 	void emitVar( bbDBVar *v ){

+ 8 - 0
modules/monkey/native/bbmonkey.cpp

@@ -6,8 +6,16 @@ char **bb_argv;
 
 void bbMain();
 
+#ifdef __ANDROID__
+
+extern "C" int SDL_main( int argc,char *argv[] ){
+
+#else
+
 int main( int argc,char **argv ){
 
+#endif
+
 	bb_argc=argc;
 	bb_argv=argv;
 	

+ 25 - 0
modules/monkey/native/bbstring.h

@@ -289,6 +289,31 @@ class bbString{
 		return bbString( beg,end-beg );
 	}
 	
+	bbString trimStart()const{
+		const bbChar *beg=data();
+		const bbChar *end=data()+length();
+		while( beg!=end && *beg<=32 ) ++beg;
+		if( end-beg==length() ) return *this;
+		return bbString( beg,end-beg );
+	}
+	
+	bbString trimEnd()const{
+		const bbChar *beg=data();
+		const bbChar *end=data()+length();
+		while( beg!=end && *(end-1)<=32 ) --end;
+		if( end-beg==length() ) return *this;
+		return bbString( beg,end-beg );
+	}
+	
+	bbString dup( int n )const{
+		Rep *rep=Rep::alloc( length()*n );
+		bbChar *p=rep->data;
+		for( int j=0;j<n;++j ){
+			for( int i=0;i<_rep->length;++i ) *p++=data()[i];
+		}
+		return rep;
+	}
+	
 	bbString replace( const bbString &str,const bbString &repl )const{
 	
 		int n=0;

+ 53 - 29
modules/monkey/types.monkey2

@@ -190,6 +190,27 @@ Struct @String ="bbString"
 	#end
 	Method Trim:String()="trim"
 	
+	#rem monkeydoc Trim whitespace from the start a string.
+	
+	@return The string with any leading whitespace removed.
+	
+	#end
+	Method TrimStart:String()="trimStart"
+	
+	#rem monkeydoc Trim whitespace from the end of a string.
+	
+	@return The string with any trailing whitespace removed.
+	
+	#end
+	Method TrimEnd:String()="trimEnd"
+	
+	#rem monkeydoc Duplicates a string.
+	
+	@return The string duplicated `count` times.
+	
+	#end
+	Method Dup:String( count:Int )="dup"
+	
 	#rem monkeydoc Replace all occurances of a substring with another string.
 	
 	@param find The string to search for.
@@ -201,8 +222,26 @@ Struct @String ="bbString"
 	#end
 	Method Replace:String( find:String,replace:String )="replace"
 	
+	#rem monkeydoc Splits this string.
+	
+	Splits this string into an array of strings.
+	
+	@param separator Separator to use for splitting.
+	
+	@return An array of strings.
+	
+	#end
 	Method Split:String[]( separator:String )="split"
 	
+	#rem monkeydoc Joins an array of strings.
+	
+	Joins an array of strings, inserting this string between elements.
+	
+	@param bits The strings to join.
+
+	@return The joined string.	
+	
+	#end
 	Method Join:String( bits:String[] )="join"
 	
 	#rem monkeydoc Converts the string to a CString.
@@ -247,7 +286,9 @@ Struct @String ="bbString"
 	
 	#rem monkeydoc Creates a string from a null terminated CString.
 	
-	Note: Only `bufSize` bytes at most will be used to create the string, so this method is safe to call even if the string is not null terminated.
+	If `bufSize` is specified, only `bufsize` bytes at most bytes will be read.
+	
+	If `bufsize` is not specified, the CString must be correctly null terminated or Bad Things Will Happen.
 	
 	@param buf The memory buffer containing the CString.
 	
@@ -255,10 +296,14 @@ Struct @String ="bbString"
 	
 	#end	
 	Function FromCString:String( buf:Void Ptr,bufSize:Int )="bbString::fromCString"
+
+	Function FromCString:String( buf:Void Ptr )="bbString::fromCString"
 	
 	#rem monkeydoc Creates a string from a null terminated WString.
 	
-	Note: Only `bufSize` bytes at most will be used to create the string, so this method is safe to call even if the string is not null terminated.
+	If `bufSize` is specified, only `bufsize` bytes at most bytes will be read.
+	
+	If `bufsize` is not specified, the WString must be correctly null terminated or Bad Things Will Happen.
 	
 	@param buf The memory buffer containing the WString.
 	
@@ -266,10 +311,15 @@ Struct @String ="bbString"
 	
 	#end	
 	Function FromWString:String( buf:Void Ptr,bufSize:Int )="bbString::fromWString"
+	
+	Function FromWString:String( buf:Void Ptr )="bbString::fromWString"
+	
 
 	#rem monkeydoc Creates a string from a null terminated Utf8String.
 	
-	Note: Only `bufSize` bytes at most will be used to create the string, so this method is safe to call even if the string is not null terminated.
+	If `bufSize` is specified, only `bufsize` bytes at most bytes will be read.
+	
+	If `bufsize` is not specified, the Utf8String must be correctly null terminated or Bad Things Will Happen.
 	
 	@param buf The memory buffer containing the Utf8String.
 	
@@ -278,32 +328,6 @@ Struct @String ="bbString"
 	#end	
 	Function FromUtf8String:String( buf:Void Ptr,bufSize:Int )="bbString::fromUtf8String"
 	
-	
-	#rem monkeydoc Creates a string from a null terminated CString.
-	
-	Note: The CString must be correctly null terminated, or Bad Things Will Happen.
-	
-	@param buf The memory buffer containing the CString.
-	
-	#end	
-	Function FromCString:String( buf:Void Ptr )="bbString::fromCString"
-
-	#rem monkeydoc Creates a string from a null terminated WString.
-	
-	Note: The WString must be correctly null terminated, or Bad Things Will Happen.
-	
-	@param buf The memory buffer containing the WString.
-	
-	#end	
-	Function FromWString:String( buf:Void Ptr )="bbString::fromWString"
-
-	#rem monkeydoc Creates a string from a null terminated Utf8String.
-	
-	Note: The Utf8String must be correctly null terminated, or Bad Things Will Happen.
-	
-	@param buf The memory buffer containing the Utf8String.
-	
-	#end	
 	Function FromUtf8String:String( buf:Void Ptr )="bbString::fromUtf8String"
 	
 End