Explorar o código

Nuked builtin 'Exception' type.

Mark Sibly %!s(int64=9) %!d(string=hai) anos
pai
achega
0cb821f292

+ 4 - 0
modules/monkey/debug.monkey2

@@ -7,6 +7,10 @@ Extern
 #end
 Function DebugStop()="bbDB::stop"
 
+#rem monkeydoc @hidden
+#end
+Function RuntimeError( message:String )="bbDB::error"
+
 #rem monkeydoc Generates a runtime error if a boolean expression is false.
 
 @param condition The boolean condition to check.

+ 1 - 2
modules/monkey/monkey.monkey2

@@ -14,6 +14,5 @@ Namespace monkey
 #Import "native/bbmonkey.cpp"
 #Import "native/bbgc.cpp"
 #Import "native/bbobject.cpp"
-#Import "native/bbinit.cpp"
 #Import "native/bbdebug.cpp"
-#Import "native/bbassert.cpp"
+#Import "native/bbinit.cpp"

+ 0 - 1
modules/monkey/native/bbarray.h

@@ -4,7 +4,6 @@
 
 #include "bbgc.h"
 #include "bbdebug.h"
-#include "bbassert.h"
 
 template<class T,int D> class bbArray : public bbGCNode{
 

+ 0 - 2
modules/monkey/native/bbassert.cpp

@@ -1,2 +0,0 @@
-
-#include "bbassert.h"

+ 0 - 27
modules/monkey/native/bbassert.h

@@ -1,27 +0,0 @@
-
-#ifndef BB_ASSERT_H
-#define BB_ASSERT_H
-
-#include "bbobject.h"
-
-inline void bbAssert( bool cond ){
-	if( !cond ) throw new bbException( "Assert failed" );
-}
-
-inline void bbAssert( bool cond,bbString msg ){
-	if( !cond ) throw new bbException( msg );
-}
-
-inline void bbDebugAssert( bool cond ){
-#ifndef NDEBUG
-	if( !cond ) throw new bbException( "Assert failed" );
-#endif
-}
-
-inline void bbDebugAssert( bool cond,bbString msg ){
-#ifndef NDEBUG
-	if( !cond ) throw new bbException( msg );
-#endif
-}
-
-#endif

+ 7 - 0
modules/monkey/native/bbdebug.cpp

@@ -104,6 +104,13 @@ namespace bbDB{
 		}
 	}
 	
+	void error( bbString msg ){
+		
+		printf( "\n%s\n",msg.c_str() );
+		stopped();
+
+	}
+	
 	bbArray<bbString> *stack(){
 	
 		int n=0;

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

@@ -3,6 +3,7 @@
 #define BB_DEBUG_H
 
 #include "bbstring.h"
+#include "bbobject.h"
 
 struct bbDBFiber;
 struct bbDBFrame;
@@ -100,7 +101,11 @@ namespace bbDB{
 	
 	void stopped();
 	
+	void error( bbString err );
+	
 	bbArray<bbString> *stack();
+	
+	void emitStack();
 }
 
 struct bbDBFrame{
@@ -164,4 +169,24 @@ template<class T> void bbDBLocal ( const char *name,T *var ){
 	++bbDB::currentContext->locals;
 }
 
+inline void bbAssert( bool cond ){
+	if( !cond ) bbDB::error( "Assert failed" );
+}
+
+inline void bbAssert( bool cond,bbString msg ){
+	if( !cond ) bbDB::error( msg );
+}
+
+inline void bbDebugAssert( bool cond ){
+#ifndef NDEBUG
+	if( !cond ) bbDB::error( "DebugAssert failed" );
+#endif
+}
+
+inline void bbDebugAssert( bool cond,bbString msg ){
+#ifndef NDEBUG
+	if( !cond ) bbDB::error( msg );
+#endif
+}
+
 #endif

+ 9 - 5
modules/monkey/native/bbmonkey.cpp

@@ -28,11 +28,13 @@ namespace{
 		case SIGBUS:err="Bus error";
 	#endif	
 		}
-		
-		bbAssert( false,err );
-		
-		printf( "Caught signal:%s\n",err );
+				
+#ifndef NDEBUG
+		bbDB::error( err );
 		exit( 0 );
+#endif
+		printf( "Caught signal:%s\n",err );
+		exit( -1 );
 		
 #if __APPLE__
 
@@ -108,7 +110,8 @@ int main( int argc,char **argv ){
 		}
 		
 		bbMain();
-		
+	
+/*		
 	}catch( bbException *ex ){
 	
 		printf( "\n***** Uncaught Monkey 2 Exception: %s *****\n\n",ex->message().c_str() );
@@ -116,6 +119,7 @@ int main( int argc,char **argv ){
 		for( int i=0;i<ex->debugStack()->length();++i ){
 			printf( "%s\n",ex->debugStack()->at( i ).c_str() );
 		}
+*/
 
 	}catch( bbThrowable *t ){
 	

+ 0 - 1
modules/monkey/native/bbmonkey.h

@@ -7,7 +7,6 @@
 #include "bbmemory.h"
 #include "bbstring.h"
 #include "bbdebug.h"
-#include "bbassert.h"
 #include "bbgc.h"
 #include "bbarray.h"
 #include "bbfunction.h"

+ 2 - 0
modules/monkey/native/bbobject.cpp

@@ -5,6 +5,7 @@
 
 bbNullCtor_t bbNullCtor;
 
+/*
 bbException::bbException(){
 
 	_debugStack=bbDB::stack();
@@ -14,3 +15,4 @@ bbException::bbException( bbString message ):bbException(){
 
 	_message=message;
 }
+*/

+ 2 - 0
modules/monkey/native/bbobject.h

@@ -36,6 +36,7 @@ struct bbObject : public bbGCNode{
 struct bbThrowable : public bbObject{
 };
 
+/*
 struct bbException : public bbThrowable{
 
 	bbException();
@@ -56,6 +57,7 @@ struct bbException : public bbThrowable{
 	
 	bbString _message;
 };
+*/
 
 struct bbInterface{
 

+ 2 - 0
modules/monkey/types.monkey2

@@ -374,6 +374,7 @@ Class @Throwable="bbThrowable"
 
 End
 
+#rem
 #rem monkeydoc Base class of all exception objects.
 #end
 Class @Exception Extends Throwable="bbException"
@@ -387,6 +388,7 @@ Class @Exception Extends Throwable="bbException"
 	Property DebugStack:String[]()="debugStack"
 	
 End
+#end
 
 #rem monkeydoc @hidden
 #end