Răsfoiți Sursa

minor refactoring of hlc_main : use correct thread compatible code

Nicolas Cannasse 7 ani în urmă
părinte
comite
6cf114dcc2
5 a modificat fișierele cu 31 adăugiri și 32 ștergeri
  1. 1 1
      src/hl.h
  2. 2 0
      src/hlc.h
  3. 24 27
      src/hlc_main.c
  4. 0 4
      src/main.c
  5. 4 0
      src/std/sys.c

+ 1 - 1
src/hl.h

@@ -785,7 +785,7 @@ struct _hl_trap_ctx {
 	hl_trap_ctx *prev;
 };
 #define hl_trap(ctx,r,label) { hl_thread_info *__tinf = hl_get_thread(); ctx.prev = __tinf->trap_current; __tinf->trap_current = &ctx; if( setjmp(ctx.buf) ) { r = __tinf->exc_value; goto label; } }
-#define hl_endtrap(ctx)	hl_get_thread()->current_trap = ctx.prev
+#define hl_endtrap(ctx)	hl_get_thread()->trap_current = ctx.prev
 
 #define HL_EXC_MAX_STACK	0x100
 #define HL_EXC_RETHROW		1

+ 2 - 0
src/hlc.h

@@ -42,6 +42,8 @@
 #undef NO_ERROR
 #undef EOF
 #undef STRICT
+#undef TRUE
+#undef FALSE
 
 // disable some warnings triggered by HLC code generator
 

+ 24 - 27
src/hlc_main.c

@@ -36,6 +36,9 @@
 #ifdef HL_CONSOLE
 extern void sys_global_init();
 extern void sys_global_exit();
+#else
+#define sys_global_init()
+#define sys_global_exit()
 #endif
 
 
@@ -60,7 +63,7 @@ static uchar *hlc_resolve_symbol( void *addr, uchar *out, int *outSize ) {
 	if( !stack_process_handle ) {
 		stack_process_handle = GetCurrentProcess();
 		SymSetOptions(SYMOPT_LOAD_LINES);
-		SymInitialize(stack_process_handle,NULL,TRUE);
+		SymInitialize(stack_process_handle,NULL,(BOOL)1);
 	}
 	if( SymFromAddrW(stack_process_handle,(DWORD64)(int_val)addr,&index,&data.sym) ) {
 		DWORD offset = 0;
@@ -104,37 +107,31 @@ int wmain(int argc, uchar *argv[]) {
 #else
 int main(int argc, char *argv[]) {
 #endif
-	hl_trap_ctx ctx;
-	vdynamic *exc;
-#	ifdef HL_CONSOLE
+	vdynamic *ret;
+	bool isExc = false;
+	hl_type_fun tf = { 0 };
+	hl_type clt = { 0 };
+	vclosure cl = { 0 };
 	sys_global_init();
-#	endif
-	hl_global_init(&ctx);
+	hl_global_init();
+	hl_register_thread(&ret);
 	hl_setup_exception(hlc_resolve_symbol,hlc_capture_stack);
 	hl_setup_callbacks(hlc_static_call, hlc_get_wrapper);
 	hl_sys_init((void**)(argv + 1),argc - 1,NULL);
-	hl_trap(ctx, exc, on_exception);
-#	ifdef HL_VCC
-	__try {
-#	endif
-	hl_entry_point();
-#	ifdef HL_VCC
-	} __except( throw_handler(GetExceptionCode()) ) {}
-#	endif
-	hl_global_free();
-	return 0;
-on_exception:
-	{
-		varray *a = hl_exception_stack();
-		int i;
-		uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(exc));
-		for(i=0;i<a->size;i++)
-			uprintf(USTR("Called from %s\n"), hl_aptr(a,uchar*)[i]);
-		hl_debug_break();
+	tf.ret = &hlt_void;
+	clt.kind = HFUN;
+	clt.fun = &tf;
+	cl.t = &clt;
+	cl.fun = hl_entry_point;
+	ret = hl_dyn_call_safe(&cl, NULL, 0, &isExc);
+	if( isExc ) {
+		varray *a = hl_exception_stack();
+		int i;
+		uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(ret));
+		for (i = 0; i<a->size; i++)
+			uprintf(USTR("Called from %s\n"), hl_aptr(a, uchar*)[i]);
 	}
 	hl_global_free();
-#	ifdef HL_CONSOLE
 	sys_global_exit();
-#	endif
-	return 1;
+	return (int)isExc;
 }

+ 0 - 4
src/main.c

@@ -144,13 +144,9 @@ int main(int argc, pchar *argv[]) {
 			argc = first_boot_arg;
 		}
 	}
-#	ifdef HL_WIN
-	setlocale(LC_CTYPE,""); // printf to current locale
-#	endif
 	hl_global_init();
 	hl_sys_init((void**)argv,argc,file);
 	hl_register_thread(&ctx);
-	setbuf(stdout,NULL); // disable stdout buffering
 	ctx.code = load_code(file);
 	if( ctx.code == NULL )
 		return 1;

+ 4 - 0
src/std/sys.c

@@ -588,6 +588,10 @@ HL_PRIM void hl_sys_init(void **args, int nargs, void *hlfile) {
 	sys_args = (pchar**)args;
 	sys_nargs = nargs;
 	hl_file = hlfile;
+#	ifdef HL_WIN
+	setlocale(LC_CTYPE, ""); // printf to current locale
+#	endif
+	setbuf(stdout, NULL); // disable stdout buffering
 }
 
 HL_PRIM vbyte *hl_sys_hl_file() {