// return a new lambda-info that has some extra static parameters merged in JL_DLLEXPORT jl_lambda_info_t *jl_get_specialized(jl_method_t *m, jl_tupletype_t *types, jl_svec_t *sp) { jl_lambda_info_t *linfo = m->lambda_template; jl_lambda_info_t *new_linfo; assert(jl_svec_len(linfo->sparam_syms) == jl_svec_len(sp) || sp == jl_emptysvec); if (!m->isstaged) { new_linfo = jl_copy_lambda(linfo); new_linfo->specTypes = types; new_linfo->def = m; new_linfo->sparam_vals = sp; if (jl_options.compile_enabled == JL_OPTIONS_COMPILE_OFF || jl_options.compile_enabled == JL_OPTIONS_COMPILE_MIN) { // copy fptr from the template method definition new_linfo->fptr = linfo->fptr; new_linfo->jlcall_api = linfo->jlcall_api; if (jl_options.compile_enabled == JL_OPTIONS_COMPILE_OFF && new_linfo->fptr == NULL) { jl_printf(JL_STDERR,"code missing for "); jl_static_show(JL_STDERR, (jl_value_t*)new_linfo); jl_printf(JL_STDERR, " sysimg may not have been built with --compile=all\n"); } } } else { new_linfo = jl_instantiate_staged(m, types, sp); } return new_linfo; }
static int exec_program(void) { int err = 0; again: ; JL_TRY { if (err) { //jl_lisp_prompt(); //return 1; jl_value_t *errs = jl_stderr_obj(); jl_value_t *e = jl_exception_in_transit; if (errs != NULL) { jl_show(jl_stderr_obj(), e); } else { jl_printf(JL_STDERR, "error during bootstrap: "); jl_static_show(JL_STDERR, e); } jl_printf(JL_STDERR, "\n"); JL_EH_POP(); return 1; } jl_load(program); } JL_CATCH { err = 1; goto again; } return 0; }
static void _compile_all_deq(jl_array_t *found) { int found_i, found_l = jl_array_len(found); jl_printf(JL_STDERR, "found %d uncompiled methods for compile-all\n", (int)found_l); jl_method_instance_t *mi = NULL; jl_value_t *src = NULL; JL_GC_PUSH2(&mi, &src); for (found_i = 0; found_i < found_l; found_i++) { if (found_i % (1 + found_l / 300) == 0 || found_i == found_l - 1) // show 300 progress steps, to show progress without overwhelming log files jl_printf(JL_STDERR, " %d / %d\r", found_i + 1, found_l); jl_typemap_entry_t *ml = (jl_typemap_entry_t*)jl_array_ptr_ref(found, found_i); jl_method_t *m = ml->func.method; if (m->source == NULL) // TODO: generic implementations of generated functions continue; mi = jl_get_unspecialized(mi); assert(mi == m->unspecialized); // make sure we didn't get tricked by a generated function, since we can't handle those jl_code_instance_t *ucache = jl_get_method_inferred(mi, (jl_value_t*)jl_any_type, 1, ~(size_t)0); if (ucache->invoke != NULL) continue; src = m->source; // TODO: we could now enable storing inferred function pointers in the `unspecialized` cache //src = jl_type_infer(mi, jl_world_counter, 1); //if (ucache->invoke != NULL) // continue; // first try to create leaf signatures from the signature declaration and compile those _compile_all_union((jl_value_t*)ml->sig); // then also compile the generic fallback jl_compile_linfo(mi, (jl_code_info_t*)src, 1, &jl_default_cgparams); assert(ucache->functionObjectsDecls.functionObject != NULL); } JL_GC_POP(); jl_printf(JL_STDERR, "\n"); }
JL_DLLEXPORT jl_value_t *jl_apply_with_saved_exception_state(jl_value_t **args, uint32_t nargs, int drop_exceptions) { jl_ptls_t ptls = jl_get_ptls_states(); jl_value_t *exc = ptls->exception_in_transit; jl_array_t *bt = NULL; JL_GC_PUSH2(&exc, &bt); if (ptls->bt_size > 0) bt = (jl_array_t*)jl_get_backtrace(); jl_value_t *v; JL_TRY { v = jl_apply(args, nargs); } JL_CATCH { if (!drop_exceptions) { jl_printf(JL_STDERR, "Internal error: encountered unexpected error in runtime:\n"); jl_static_show(JL_STDERR, ptls->exception_in_transit); jl_printf(JL_STDERR, "\n"); jlbacktrace(); // written to STDERR_FILENO } v = NULL; } ptls->exception_in_transit = exc; if (bt != NULL) { ptls->bt_size = jl_array_len(bt); memcpy(ptls->bt_data, bt->data, ptls->bt_size * sizeof(void*)); } JL_GC_POP(); return v; }
static int exec_program(char *program) { int err = 0; again: ; JL_TRY { if (err) { jl_value_t *errs = jl_stderr_obj(); jl_value_t *e = jl_exception_in_transit; if (errs != NULL) { jl_show(errs, e); } else { jl_printf(JL_STDERR, "error during bootstrap:\n"); jl_static_show(JL_STDERR, e); jl_printf(JL_STDERR, "\n"); jlbacktrace(); } jl_printf(JL_STDERR, "\n"); JL_EH_POP(); return 1; } jl_load(program, strlen(program)); } JL_CATCH { err = 1; goto again; } return 0; }
void jl_check_static_parameter_conflicts(jl_lambda_info_t *li, jl_svec_t *t, jl_sym_t *fname) { jl_array_t *vinfo; size_t nvars; if (li->ast && jl_is_expr(li->ast)) { vinfo = jl_lam_vinfo((jl_expr_t*)li->ast); nvars = jl_array_len(vinfo); for(size_t i=0; i < jl_svec_len(t); i++) { for(size_t j=0; j < nvars; j++) { jl_value_t *tv = jl_svecref(t,i); if (jl_is_typevar(tv)) { if ((jl_sym_t*)jl_cellref((jl_array_t*)jl_cellref(vinfo,j),0) == ((jl_tvar_t*)tv)->name) { jl_printf(JL_STDERR, "WARNING: local variable %s conflicts with a static parameter in %s", ((jl_tvar_t*)tv)->name->name, fname->name); print_func_loc(JL_STDERR, li); jl_printf(JL_STDERR, ".\n"); } } } } } }
// NOTE: we use explici since explicit is a C++ keyword static void module_import_(jl_module_t *to, jl_module_t *from, jl_sym_t *s, int explici) { if (to == from) return; jl_binding_t *b = jl_get_binding(from, s); if (b == NULL) { jl_printf(JL_STDERR, "Warning: could not import %s.%s into %s\n", from->name->name, s->name, to->name->name); } else { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&to->bindings, s); jl_binding_t *bto = *bp; if (bto != HT_NOTFOUND) { if (bto == b) { // importing a binding on top of itself. harmless. } else if (bto->owner == b->owner) { // already imported bto->imported = (explici!=0); } else if (bto->owner != to && bto->owner != NULL) { // already imported from somewhere else jl_binding_t *bval = jl_get_binding(to, s); if (bval->constp && bval->value && b->constp && b->value == bval->value) { // equivalent binding bto->imported = (explici!=0); return; } jl_printf(JL_STDERR, "Warning: ignoring conflicting import of %s.%s into %s\n", from->name->name, s->name, to->name->name); } else if (bto->constp || bto->value) { // conflict with name owned by destination module assert(bto->owner == to); if (bto->constp && bto->value && b->constp && b->value == bto->value) { // equivalent binding return; } jl_printf(JL_STDERR, "Warning: import of %s.%s into %s conflicts with an existing identifier; ignored.\n", from->name->name, s->name, to->name->name); } else { bto->owner = b->owner; bto->imported = (explici!=0); } } else { jl_binding_t *nb = new_binding(s); nb->owner = b->owner; nb->imported = (explici!=0); *bp = nb; jl_gc_wb_buf(to, nb); } } }
void jl_write_compiler_output(void) { if (!jl_generating_output()) return; if (!jl_options.incremental) jl_precompile(jl_options.compile_enabled == JL_OPTIONS_COMPILE_ALL); if (!jl_module_init_order) { jl_printf(JL_STDERR, "WARNING: --output requested, but no modules defined during run\n"); return; } jl_array_t *worklist = jl_module_init_order; JL_GC_PUSH1(&worklist); jl_module_init_order = jl_alloc_vec_any(0); int i, l = jl_array_len(worklist); for (i = 0; i < l; i++) { jl_value_t *m = jl_arrayref(worklist, i); if (jl_get_global((jl_module_t*)m, jl_symbol("__init__"))) { jl_array_ptr_1d_push(jl_module_init_order, m); } } if (jl_options.incremental) { if (jl_options.outputji) if (jl_save_incremental(jl_options.outputji, worklist)) jl_exit(1); if (jl_options.outputbc || jl_options.outputunoptbc) jl_printf(JL_STDERR, "WARNING: incremental output to a .bc file is not implemented\n"); if (jl_options.outputo) jl_printf(JL_STDERR, "WARNING: incremental output to a .o file is not implemented\n"); } else { ios_t *s = NULL; if (jl_options.outputo || jl_options.outputbc || jl_options.outputunoptbc) s = jl_create_system_image(); if (jl_options.outputji) { if (s == NULL) { jl_save_system_image(jl_options.outputji); } else { ios_t f; if (ios_file(&f, jl_options.outputji, 1, 1, 1, 1) == NULL) jl_errorf("cannot open system image file \"%s\" for writing", jl_options.outputji); ios_write(&f, (const char*)s->buf, (size_t)s->size); ios_close(&f); } } if (jl_options.outputo || jl_options.outputbc || jl_options.outputunoptbc) jl_dump_native(jl_options.outputbc, jl_options.outputunoptbc, jl_options.outputo, (const char*)s->buf, (size_t)s->size); } JL_GC_POP(); }
static void print_obj_profile(void) { for(int i=0; i < obj_counts.size; i+=2) { if (obj_counts.table[i+1] != HT_NOTFOUND) { jl_printf(JL_STDERR, "%d ", obj_counts.table[i+1]-1); jl_static_show(JL_STDERR, (jl_value_t*)obj_counts.table[i]); jl_printf(JL_STDERR, "\n"); } } }
static int true_main(int argc, char *argv[]) { if (jl_base_module != NULL) { jl_array_t *args = (jl_array_t*)jl_get_global(jl_base_module, jl_symbol("ARGS")); if (args == NULL) { args = jl_alloc_cell_1d(0); jl_set_const(jl_base_module, jl_symbol("ARGS"), (jl_value_t*)args); } assert(jl_array_len(args) == 0); jl_array_grow_end(args, argc); int i; for (i=0; i < argc; i++) { jl_value_t *s = (jl_value_t*)jl_cstr_to_string(argv[i]); jl_set_typeof(s,jl_utf8_string_type); jl_arrayset(args, s, i); } } // run program if specified, otherwise enter REPL if (program) { int ret = exec_program(); uv_tty_reset_mode(); return ret; } jl_function_t *start_client = (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("_start")); if (start_client) { jl_apply(start_client, NULL, 0); return 0; } int iserr = 0; again: ; JL_TRY { if (iserr) { //jl_show(jl_exception_in_transit);# What if the error was in show? jl_printf(JL_STDERR, "\n\n"); iserr = 0; } uv_run(jl_global_event_loop(),UV_RUN_DEFAULT); } JL_CATCH { iserr = 1; jl_printf(JL_STDERR, "error during run:\n"); jl_show(jl_stderr_obj(),jl_exception_in_transit); jl_printf(JL_STDERR, "\n"); jlbacktrace(); goto again; } return iserr; }
// get binding for adding a method // like jl_get_binding_wr, but uses existing imports instead of warning // and overwriting. JL_DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_t *var) { if (jl_base_module && m->std_imports && !jl_binding_resolved_p(m,var)) { jl_module_t *opmod = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("Operators")); if (opmod != NULL && jl_defines_or_exports_p(opmod, var)) { jl_printf(JL_STDERR, "WARNING: module %s should explicitly import %s from %s\n", jl_symbol_name(m->name), jl_symbol_name(var), jl_symbol_name(jl_base_module->name)); jl_module_import(m, opmod, var); } } jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var); jl_binding_t *b = *bp; if (b != HT_NOTFOUND) { if (b->owner != m && b->owner != NULL) { jl_binding_t *b2 = jl_get_binding(b->owner, var); if (b2 == NULL) jl_errorf("invalid method definition: imported function %s.%s does not exist", jl_symbol_name(b->owner->name), jl_symbol_name(var)); if (!b->imported && (b2->value==NULL || jl_is_function(b2->value))) { if (b2->value && !jl_is_gf(b2->value)) { jl_errorf("error in method definition: %s.%s cannot be extended", jl_symbol_name(b->owner->name), jl_symbol_name(var)); } else { if (jl_base_module && m->std_imports && b->owner == jl_base_module) { jl_module_t *opmod = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("Operators")); if (opmod != NULL && jl_defines_or_exports_p(opmod, var)) { jl_printf(JL_STDERR, "WARNING: module %s should explicitly import %s from %s\n", jl_symbol_name(m->name), jl_symbol_name(var), jl_symbol_name(b->owner->name)); return b2; } } jl_errorf("error in method definition: function %s.%s must be explicitly imported to be extended", jl_symbol_name(b->owner->name), jl_symbol_name(var)); } } return b2; } b->owner = m; return b; } b = new_binding(var); b->owner = m; *bp = b; jl_gc_wb_buf(m, b); return *bp; }
void jl_print_gc_stats(JL_STREAM *s) { double gct = total_gc_time/1e9; malloc_stats(); double ptime = clock_now()-process_t0; jl_printf(s, "exec time\t%.5f sec\n", ptime); jl_printf(s, "gc time \t%.5f sec (%2.1f%%)\n", gct, (gct/ptime)*100); struct mallinfo mi = mallinfo(); jl_printf(s, "malloc size\t%d MB\n", mi.uordblks/1024/1024); jl_printf(s, "total freed\t%llu b\n", total_freed_bytes); jl_printf(s, "free rate\t%.1f MB/sec\n", (total_freed_bytes/gct)/1024/1024); }
void jl_module_run_initializer(jl_module_t *m) { jl_function_t *f = jl_module_get_initializer(m); if (f == NULL) return; JL_TRY { jl_apply(f, NULL, 0); } JL_CATCH { jl_printf(JL_STDERR, "Warning: error initializing module %s:\n", m->name->name); jl_static_show(JL_STDERR, jl_exception_in_transit); jl_printf(JL_STDERR, "\n"); } }
static size_t jl_show_svec(JL_STREAM *out, jl_svec_t *t, const char *head, const char *opn, const char *cls) { size_t i, n=0, len = jl_svec_len(t); n += jl_printf(out, "%s", head); n += jl_printf(out, "%s", opn); for (i = 0; i < len; i++) { jl_value_t *v = jl_svecref(t,i); n += jl_static_show(out, v); if (i != len-1) n += jl_printf(out, ", "); } n += jl_printf(out, "%s", cls); return n; }
JL_DLLEXPORT void jl_(void *jl_value) { jl_ptls_t ptls = jl_get_ptls_states(); jl_jmp_buf *old_buf = ptls->safe_restore; jl_jmp_buf buf; ptls->safe_restore = &buf; if (!jl_setjmp(buf, 0)) { jl_static_show((JL_STREAM*)STDERR_FILENO, (jl_value_t*)jl_value); jl_printf((JL_STREAM*)STDERR_FILENO,"\n"); } else { jl_printf((JL_STREAM*)STDERR_FILENO, "\n!!! ERROR in jl_ -- ABORTING !!!\n"); } ptls->safe_restore = old_buf; }
static void ti_initthread(int16_t tid) { jl_tls_states_t *ptls = jl_get_ptls_states(); #ifndef _OS_WINDOWS_ ptls->system_id = pthread_self(); #endif ptls->tid = tid; ptls->pgcstack = NULL; ptls->gc_state = 0; // GC unsafe // Conditionally initialize the safepoint address. See comment in // `safepoint.c` if (tid == 0) { ptls->safepoint = (size_t*)(jl_safepoint_pages + jl_page_size); } else { ptls->safepoint = (size_t*)(jl_safepoint_pages + jl_page_size * 2 + sizeof(size_t)); } ptls->defer_signal = 0; ptls->current_module = NULL; void *bt_data = malloc(sizeof(uintptr_t) * (JL_MAX_BT_SIZE + 1)); if (bt_data == NULL) { jl_printf(JL_STDERR, "could not allocate backtrace buffer\n"); gc_debug_critical_error(); abort(); } ptls->bt_data = (uintptr_t*)bt_data; jl_mk_thread_heap(ptls); jl_install_thread_signal_handler(); jl_all_tls_states[tid] = ptls; }
void jl_gc_collect(void) { size_t actual_allocd = allocd_bytes; total_allocd_bytes += allocd_bytes; allocd_bytes = 0; if (is_gc_enabled) { JL_SIGATOMIC_BEGIN(); jl_in_gc = 1; #if defined(GCTIME) || defined(GC_FINAL_STATS) double t0 = clock_now(); #endif gc_mark(); #ifdef GCTIME JL_PRINTF(JL_STDERR, "mark time %.3f ms\n", (clock_now()-t0)*1000); #endif #if defined(MEMPROFILE) all_pool_stats(); big_obj_stats(); #endif #ifdef GCTIME t0 = clock_now(); #endif sweep_weak_refs(); gc_sweep(); #ifdef GCTIME JL_PRINTF(JL_STDERR, "sweep time %.3f ms\n", (clock_now()-t0)*1000); #endif int nfinal = to_finalize.len; run_finalizers(); jl_in_gc = 0; JL_SIGATOMIC_END(); #if defined(GC_FINAL_STATS) total_gc_time += (clock_now()-t0); total_freed_bytes += freed_bytes; #endif #ifdef OBJPROFILE print_obj_profile(); htable_reset(&obj_counts, 0); #endif // tune collect interval based on current live ratio #if defined(MEMPROFILE) jl_printf(JL_STDERR, "allocd %ld, freed %ld, interval %ld, ratio %.2f\n", actual_allocd, freed_bytes, collect_interval, (double)freed_bytes/(double)actual_allocd); #endif if (freed_bytes < (7*(actual_allocd/10))) { if (collect_interval <= 2*(max_collect_interval/5)) collect_interval = 5*(collect_interval/2); } else { collect_interval = default_collect_interval; } freed_bytes = 0; // if a lot of objects were finalized, re-run GC to finish freeing // their storage if possible. if (nfinal > 100000) jl_gc_collect(); } }
// get binding for assignment DLLEXPORT jl_binding_t *jl_get_binding_wr(jl_module_t *m, jl_sym_t *var) { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var); jl_binding_t *b; if (*bp != HT_NOTFOUND) { if ((*bp)->owner == NULL) { (*bp)->owner = m; return *bp; } else if ((*bp)->owner != m) { // TODO: change this to an error soon jl_printf(JL_STDERR, "Warning: imported binding for %s overwritten in module %s\n", var->name, m->name->name); } else { return *bp; } } b = new_binding(var); b->owner = m; *bp = b; jl_gc_wb_buf(m, b); return *bp; }
static void module_import_(jl_module_t *to, jl_module_t *from, jl_sym_t *s, int explicit) { if (to == from) return; jl_binding_t *b = jl_get_binding(from, s); if (b == NULL) { jl_printf(JL_STDERR, "Warning: could not import %s.%s into %s\n", from->name->name, s->name, to->name->name); } else { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&to->bindings, s); jl_binding_t *bto = *bp; if (bto != HT_NOTFOUND) { if (bto == b) { // importing a binding on top of itself. harmless. } else if (bto->owner == b->owner) { // already imported bto->imported = (explicit!=0); } else if (bto->owner != to && bto->owner != NULL) { // already imported from somewhere else jl_binding_t *bval = jl_get_binding(to, s); if (bval->constp && bval->value && b->constp && b->value == bval->value) { // equivalent binding bto->imported = (explicit!=0); return; }
void jl_module_using(jl_module_t *to, jl_module_t *from) { if (to == from) return; for(size_t i=0; i < to->usings.len; i++) { if (from == to->usings.items[i]) return; } // print a warning if something visible via this "using" conflicts with // an existing identifier. note that an identifier added later may still // silently override a "using" name. see issue #2054. void **table = from->bindings.table; for(size_t i=1; i < from->bindings.size; i+=2) { if (table[i] != HT_NOTFOUND) { jl_binding_t *b = (jl_binding_t*)table[i]; if (b->exportp && (b->owner==from || b->imported)) { jl_sym_t *var = (jl_sym_t*)table[i-1]; jl_binding_t **tobp = (jl_binding_t**)ptrhash_bp(&to->bindings, var); if (*tobp != HT_NOTFOUND && (*tobp)->owner != NULL && // don't warn for conflicts with the module name itself. // see issue #4715 var != to->name && !eq_bindings(jl_get_binding(to,var), b)) { jl_printf(JL_STDERR, "Warning: using %s.%s in module %s conflicts with an existing identifier.\n", from->name->name, var->name, to->name->name); } } } } arraylist_push(&to->usings, from); }
void jl_binding_deprecation_warning(jl_binding_t *b) { if (b->deprecated && jl_options.depwarn) { if (jl_options.depwarn != JL_OPTIONS_DEPWARN_ERROR) jl_printf(JL_STDERR, "WARNING: "); if (b->owner) jl_printf(JL_STDERR, "%s.%s is deprecated", jl_symbol_name(b->owner->name), jl_symbol_name(b->name)); else jl_printf(JL_STDERR, "%s is deprecated", jl_symbol_name(b->name)); jl_value_t *v = b->value; if (v && (jl_is_type(v)/* || (jl_is_function(v) && jl_is_gf(v))*/)) { jl_printf(JL_STDERR, ", use "); jl_static_show(JL_STDERR, v); jl_printf(JL_STDERR, " instead"); } jl_printf(JL_STDERR, ".\n"); if (jl_options.depwarn != JL_OPTIONS_DEPWARN_ERROR) jl_printf(JL_STDERR, " likely near %s:%d\n", jl_filename, jl_lineno); if (jl_options.depwarn == JL_OPTIONS_DEPWARN_ERROR) { if (b->owner) jl_errorf("deprecated binding: %s.%s", jl_symbol_name(b->owner->name), jl_symbol_name(b->name)); else jl_errorf("deprecated binding: %s", jl_symbol_name(b->name)); } } }
DLLEXPORT void *jl_dlsym(uv_lib_t *handle, char *symbol) { void *ptr; int error = uv_dlsym(handle, symbol, &ptr); if (error != 0) { jl_printf(JL_STDERR, "symbol could not be found %s (%d): %s\n", symbol, error, uv_dlerror(handle)); } return ptr; }
void *jl_dlsym(jl_uv_libhandle handle, const char *symbol) { void *ptr; int error = uv_dlsym((uv_lib_t *) handle, symbol, &ptr); if (error != 0) { jl_printf(JL_STDERR, "symbol could not be found %s (%d): %s\n", symbol, error, uv_dlerror((uv_lib_t *) handle)); } return ptr; }
void jl_load(const char *fname) { if (jl_current_module == jl_base_module) { //This deliberatly uses ios, because stdio initialization has been moved to Julia jl_printf(JL_STDOUT, "%s\n", fname); } char *fpath = (char*)fname; uv_stat_t stbuf; if (jl_stat(fpath, (char*)&stbuf) != 0 || (stbuf.st_mode & S_IFMT) != S_IFREG) { jl_errorf("could not open file %s", fpath); } jl_start_parsing_file(fpath); jl_parse_eval_all(fpath); if (fpath != fname) free(fpath); if (jl_current_module == jl_base_module) { jl_printf(JL_STDOUT, "\x1B[1F\x1B[2K"); } }
int true_main(int argc, char *argv[]) { if (jl_base_module != NULL) { jl_array_t *args = (jl_array_t*)jl_get_global(jl_base_module, jl_symbol("ARGS")); assert(jl_array_len(args) == 0); jl_array_grow_end(args, argc); int i; for (i=0; i < argc; i++) { jl_value_t *s = (jl_value_t*)jl_cstr_to_string(argv[i]); s->type = (jl_value_t*)jl_utf8_string_type; jl_arrayset(args, s, i); } } // run program if specified, otherwise enter REPL if (program) { int ret = exec_program(); uv_tty_reset_mode(); return ret; } jl_function_t *start_client = (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("_start")); //uv_read_start(jl_stdin_tty,jl_alloc_read_buffer,&read_buffer); if (start_client) { jl_apply(start_client, NULL, 0); //rl_cleanup_after_signal(); return 0; } // client event loop not available; use fallback blocking version //install_read_event_handler(&echoBack); int iserr = 0; again: ; JL_TRY { if (iserr) { //jl_show(jl_exception_in_transit);# What if the error was in show? jl_printf(JL_STDERR, "\n\n"); iserr = 0; } uv_run(jl_global_event_loop(),UV_RUN_DEFAULT); } JL_CATCH { iserr = 1; JL_PUTS("error during run:\n",JL_STDERR); jl_show(jl_stderr_obj(),jl_exception_in_transit); JL_PUTS("\n",JL_STDOUT); goto again; } uv_tty_reset_mode(); return iserr; }
JL_DLLEXPORT void JL_NORETURN jl_error(const char *str) { if (jl_errorexception_type == NULL) { jl_printf(JL_STDERR, "ERROR: %s\n", str); jl_exit(1); } jl_value_t *msg = jl_pchar_to_string((char*)str, strlen(str)); JL_GC_PUSH1(&msg); jl_throw(jl_new_struct(jl_errorexception_type, msg)); }
static size_t jl_static_show_x(JL_STREAM *out, jl_value_t *v, struct recur_list *depth) { // show values without calling a julia method or allocating through the GC if (v == NULL) { return jl_printf(out, "#<null>"); } else if ((uintptr_t)v < 4096U) { return jl_printf(out, "#<%d>", (int)(uintptr_t)v); } unsigned int dist = 1; struct recur_list this_item = {depth, v}, *p = depth; while (p) { if (p->v == v) return jl_printf(out, "<circular reference @-%u>", dist); dist++; p = p->prev; } return jl_static_show_x_(out, v, (jl_datatype_t*)jl_typeof(v), &this_item); }
static void _compile_all_deq(jl_array_t *found) { int found_i, found_l = jl_array_len(found); jl_printf(JL_STDERR, "found %d uncompiled methods for compile-all\n", (int)found_l); jl_method_instance_t *linfo = NULL; jl_value_t *src = NULL; JL_GC_PUSH2(&linfo, &src); for (found_i = 0; found_i < found_l; found_i++) { if (found_i % (1 + found_l / 300) == 0 || found_i == found_l - 1) // show 300 progress steps, to show progress without overwhelming log files jl_printf(JL_STDERR, " %d / %d\r", found_i + 1, found_l); jl_typemap_entry_t *ml = (jl_typemap_entry_t*)jl_array_ptr_ref(found, found_i); jl_method_t *m = ml->func.method; if (m->isstaged) // TODO: generic implementations of generated functions continue; linfo = m->unspecialized; if (!linfo) { linfo = jl_get_specialized(m, (jl_value_t*)m->sig, jl_emptysvec); m->unspecialized = linfo; jl_gc_wb(m, linfo); } if (linfo->jlcall_api == 2) continue; src = m->source; // TODO: the `unspecialized` field is not yet world-aware, so we can't store // an inference result there. //src = jl_type_infer(&linfo, jl_world_counter, 1); //m->unspecialized = linfo; //jl_gc_wb(m, linfo); //if (linfo->jlcall_api == 2) // continue; // first try to create leaf signatures from the signature declaration and compile those _compile_all_union((jl_value_t*)ml->sig); // then also compile the generic fallback jl_compile_linfo(&linfo, (jl_code_info_t*)src, jl_world_counter, &jl_default_cgparams); assert(linfo->functionObjectsDecls.functionObject != NULL); } JL_GC_POP(); jl_printf(JL_STDERR, "\n"); }
static void ti_init_master_thread(void) { #ifdef _OS_WINDOWS_ if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hMainThread, 0, TRUE, DUPLICATE_SAME_ACCESS)) { jl_printf(JL_STDERR, "WARNING: failed to access handle to main thread\n"); hMainThread = INVALID_HANDLE_VALUE; } #endif ti_initthread(0); }
DLLEXPORT void jl_checked_assignment(jl_binding_t *b, jl_value_t *rhs) { if (b->constp && b->value != NULL) { if (!jl_egal(rhs, b->value)) { if (jl_typeof(rhs) != jl_typeof(b->value) || jl_is_type(rhs) || jl_is_function(rhs) || jl_is_module(rhs)) { jl_errorf("invalid redefinition of constant %s", b->name->name); } jl_printf(JL_STDERR,"Warning: redefining constant %s\n",b->name->name); } } b->value = rhs; jl_gc_wb_binding(b, rhs); }