int wmain(int argc, uchar *argv[]) { #else int main(int argc, char *argv[]) { #endif hl_trap_ctx ctx; vdynamic *exc; hl_global_init(&ctx); 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); 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(); } hl_global_free(); return 1; }
int main( int argc, char *argv[] ) { _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF ); if( argc == 1 ) { printf("HLVM %d.%d.%d (c)2015 Haxe Foundation\n Usage : hl <file>\n",HL_VERSION/100,(HL_VERSION/10)%10,HL_VERSION%10); return 1; } hl_global_init(); { hl_code *code; hl_module *m; const char *file = argv[1]; FILE *f = fopen(file,"rb"); int pos, size; char *fdata; if( f == NULL ) { printf("File not found '%s'\n",file); return 1; } fseek(f, 0, SEEK_END); size = (int)ftell(f); fseek(f, 0, SEEK_SET); fdata = (char*)malloc(size); pos = 0; while( pos < size ) { int r = (int)fread(fdata + pos, 1, size-pos, f); if( r <= 0 ) { printf("Failed to read '%s'\n",file); return 2; } pos += r; } fclose(f); code = hl_code_read((unsigned char*)fdata, size); free(fdata); if( code == NULL ) return 3; m = hl_module_alloc(code); if( m == NULL ) return 4; if( !hl_module_init(m) ) return 5; hl_callback(m->functions_ptrs[m->code->entrypoint],0,NULL); hl_module_free(m); hl_free(&code->alloc); } hl_global_free(); return 0; }