Nicolas Cannasse 8 éve
szülő
commit
59edf902ce
4 módosított fájl, 11 hozzáadás és 1 törlés
  1. 1 0
      src/hl.h
  2. 4 1
      src/jit.c
  3. 1 0
      src/opcodes.h
  4. 5 0
      src/std/error.c

+ 1 - 0
src/hl.h

@@ -479,6 +479,7 @@ HL_API const uchar *hl_field_name( int hash );
 
 #define hl_error(msg)	hl_error_msg(USTR(msg))
 HL_API void hl_error_msg( const uchar *msg, ... );
+HL_API void hl_assert();
 HL_API void hl_throw( vdynamic *v );
 HL_API void hl_rethrow( vdynamic *v );
 HL_API void hl_setup_exception( void *resolve_symbol, void *capture_stack );

+ 4 - 1
src/jit.c

@@ -1259,7 +1259,7 @@ static void call_native( jit_ctx *ctx, void *nativeFun, int size ) {
 	// native function, already resolved
 	op64(ctx,MOV,PEAX,pconst64(&p,(int_val)nativeFun));
 	op64(ctx,CALL,PEAX,UNUSED);
-	if( nativeFun == hl_null_access || nativeFun == hl_throw || nativeFun == on_jit_error )
+	if( nativeFun == hl_null_access || nativeFun == hl_assert || nativeFun == hl_throw || nativeFun == on_jit_error )
 		return;
 	discard_regs(ctx, true);
 	op64(ctx,ADD,PESP,pconst(&p,size));
@@ -3227,6 +3227,9 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 			op32(ctx, MOV, alloc_cpu(ctx,dst,false), pmem(&p,alloc_cpu(ctx,ra,true)->id,0));
 			store(ctx,dst,dst->current,false);
 			break;
+		case OAssert:
+			call_native(ctx, hl_assert, 0);
+			break;
 		case ONop:
 			break;
 		default:

+ 1 - 0
src/opcodes.h

@@ -138,6 +138,7 @@ OP_BEGIN
 	OP(OEnumField,4)
 	OP(OSetEnumField,3)
 
+	OP(OAssert,0)
 	OP(ONop,0)
 	// --
 	OP(OLast,0)

+ 5 - 0
src/std/error.c

@@ -134,6 +134,11 @@ HL_PRIM void hl_breakpoint() {
 	hl_debug_break();
 }
 
+HL_PRIM void hl_assert() {
+	hl_debug_break();
+	hl_error("Assert");
+}
+
 #define _SYMBOL _ABSTRACT(hl_symbol)
 
 DEFINE_PRIM(_ARR,exception_stack,_NO_ARG);