static void show_function(jl_value_t *v) { ios_t *s = jl_current_output_stream(); if (jl_is_gf(v)) { ios_puts(jl_gf_name(v)->name, s); } else { ios_puts("#<function>", s); } }
void jl_show_full_function(jl_value_t *v) { ios_t *s = jl_current_output_stream(); if (jl_is_gf(v)) { ios_puts("Methods for generic function ", s); ios_puts(jl_gf_name(v)->name, s); ios_putc('\n', s); jl_show_method_table((jl_function_t*)v); } else { show_function(v); } }
DLLEXPORT void jl_show_any(jl_value_t *v) { // fallback for printing some other builtin types ios_t *s = jl_current_output_stream(); if (jl_is_tuple(v)) { show_tuple((jl_tuple_t*)v, '(', ')', 1); } else if (jl_is_type(v)) { show_type(v); } else if (jl_is_func(v)) { show_function(v); } else if (jl_typeis(v,jl_intrinsic_type)) { ios_printf(s, "#<intrinsic-function %d>", *(uint32_t*)jl_bits_data(v)); } else { jl_value_t *t = (jl_value_t*)jl_typeof(v); if (jl_is_struct_type(t)) { jl_struct_type_t *st = (jl_struct_type_t*)t; ios_puts(st->name->name->name, s); ios_putc('(', s); size_t i; size_t n = st->names->length; for(i=0; i < n; i++) { jl_show(nth_field(v, i)); if (i < n-1) ios_putc(',', s); } ios_putc(')', s); } } }
static void symtab_search(jl_sym_t *tree, int *pcount, ios_t *result, jl_module_t *module, const char *str, const char *prefix, int plen) { do { if (common_prefix(prefix, tree->name) == plen && (module ? jl_defines_or_exports_p(module, tree) : jl_boundp(jl_current_module, tree))) { ios_puts(str, result); ios_puts(tree->name + plen, result); ios_putc('\n', result); (*pcount)++; } if (tree->left) symtab_search(tree->left, pcount, result, module, str, prefix, plen); tree = tree->right; } while (tree != NULL); }
static void show_type(jl_value_t *t) { ios_t *s = jl_current_output_stream(); if (jl_is_func_type(t)) { if (t == (jl_value_t*)jl_any_func) { ios_puts("Function", s); } else { jl_show((jl_value_t*)((jl_func_type_t*)t)->from); ios_write(s, "-->", 3); jl_show((jl_value_t*)((jl_func_type_t*)t)->to); } } else if (t == (jl_value_t*)jl_function_type) { ios_puts("Function", s); } else if (jl_is_union_type(t)) { if (t == (jl_value_t*)jl_bottom_type) { ios_write(s, "None", 4); } else if (t == jl_top_type) { ios_write(s, "Top", 3); } else { ios_write(s, "Union", 5); show_tuple(((jl_uniontype_t*)t)->types, '(', ')', 0); } } else if (jl_is_seq_type(t)) { jl_show(jl_tparam0(t)); ios_write(s, "...", 3); } else if (jl_is_typector(t)) { jl_show((jl_value_t*)((jl_typector_t*)t)->body); } else { assert(jl_is_some_tag_type(t)); jl_tag_type_t *tt = (jl_tag_type_t*)t; ios_puts(tt->name->name->name, s); jl_tuple_t *p = tt->parameters; if (p->length > 0) show_tuple(p, '{', '}', 0); } }
DLLEXPORT void jl_show_float(double d, int ndec) { ios_t *s = jl_current_output_stream(); char buf[64]; if (!DFINITE(d)) { char *rep = isnan(d) ? "NaN" : sign_bit(d) ? "-Inf" : "Inf"; ios_puts(rep, s); } else if (d == 0) { if (1/d < 0) ios_puts("-0.0", s); else ios_puts("0.0", s); } else { snprint_real(buf, sizeof(buf), d, 0, ndec, 3, 10); int hasdec = (strpbrk(buf, ".eE") != NULL); ios_puts(buf, s); if (!hasdec) ios_puts(".0", s); } }
static void symtab_search(jl_sym_t *tree, int *pcount, ios_t *result, const char *prefix, int plen) { do { if (common_prefix(prefix, tree->name) == plen && jl_boundp(jl_system_module, tree)) { ios_puts(tree->name, result); ios_putc('\n', result); (*pcount)++; } if (tree->left) symtab_search(tree->left, pcount, result, prefix, plen); tree = tree->right; } while (tree != NULL); }
int main(int argc, char *argv[]) { char fname_buf[1024]; fl_context_t *fl_ctx = &fl_global_ctx; fl_init(fl_ctx, 512*1024); fname_buf[0] = '\0'; value_t str = symbol_value(symbol(fl_ctx, "*install-dir*")); char *exedir = (char*)(str == UNBOUND ? NULL : cvalue_data(str)); if (exedir != NULL) { strcat(fname_buf, exedir); strcat(fname_buf, PATHSEPSTRING); } strcat(fname_buf, "flisp.boot"); value_t args[2]; fl_gc_handle(fl_ctx, &args[0]); fl_gc_handle(fl_ctx, &args[1]); FL_TRY_EXTERN(fl_ctx) { args[0] = cvalue_static_cstring(fl_ctx, fname_buf); args[1] = symbol(fl_ctx, ":read"); value_t f = fl_file(fl_ctx, &args[0], 2); fl_free_gc_handles(fl_ctx, 2); if (fl_load_system_image(fl_ctx, f)) return 1; (void)fl_applyn(fl_ctx, 1, symbol_value(symbol(fl_ctx, "__start")), argv_list(fl_ctx, argc, argv)); } FL_CATCH_EXTERN(fl_ctx) { ios_puts("fatal error:\n", ios_stderr); fl_print(fl_ctx, ios_stderr, fl_ctx->lasterror); ios_putc('\n', ios_stderr); return 1; } return 0; }
static NOINLINE int true_main(int argc, char *argv[]) { if (jl_core_module != NULL) { jl_array_t *args = (jl_array_t*)jl_get_global(jl_core_module, jl_symbol("ARGS")); if (args == NULL) { args = jl_alloc_cell_1d(0); JL_GC_PUSH1(&args); jl_set_const(jl_core_module, jl_symbol("ARGS"), (jl_value_t*)args); JL_GC_POP(); } 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); } } jl_function_t *start_client = jl_base_module ? (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("_start")) : NULL; if (start_client) { jl_apply(&start_client, 1); return 0; } // run program if specified, otherwise enter REPL if (argc > 0) { if (strcmp(argv[0], "-")) { return exec_program(argv[0]); } } ios_puts("WARNING: Base._start not defined, falling back to economy mode repl.\n", ios_stdout); if (!jl_errorexception_type) ios_puts("WARNING: jl_errorexception_type not defined; any errors will be fatal.\n", ios_stdout); while (!ios_eof(ios_stdin)) { char *volatile line = NULL; JL_TRY { ios_puts("\njulia> ", ios_stdout); ios_flush(ios_stdout); line = ios_readline(ios_stdin); jl_value_t *val = (jl_value_t*)jl_eval_string(line); if (jl_exception_occurred()) { jl_printf(JL_STDERR, "error during run:\n"); jl_static_show(JL_STDERR, jl_exception_in_transit); jl_exception_clear(); } else if (val) { jl_static_show(JL_STDOUT, val); } jl_printf(JL_STDOUT, "\n"); free(line); line = NULL; uv_run(jl_global_event_loop(),UV_RUN_NOWAIT); } JL_CATCH { if (line) { free(line); line = NULL; } jl_printf(JL_STDERR, "\nparser error:\n"); jl_static_show(JL_STDERR, jl_exception_in_transit); jl_printf(JL_STDERR, "\n"); jlbacktrace(); } } return 0; }
static LONG WINAPI _exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo, int in_ctx) { if (ExceptionInfo->ExceptionRecord->ExceptionFlags == 0) { switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { case EXCEPTION_INT_DIVIDE_BY_ZERO: fpreset(); if (!in_ctx) jl_throw(jl_diverror_exception); jl_throw_in_ctx(jl_diverror_exception, ExceptionInfo->ContextRecord, 0); return EXCEPTION_CONTINUE_EXECUTION; case EXCEPTION_STACK_OVERFLOW: bt_size = 0; if (!in_ctx) jl_rethrow_other(jl_stackovf_exception); jl_throw_in_ctx(jl_stackovf_exception, ExceptionInfo->ContextRecord, 0); return EXCEPTION_CONTINUE_EXECUTION; } ios_puts("Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.\nException: ", ios_stderr); switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: ios_puts("EXCEPTION_ACCESS_VIOLATION", ios_stderr); break; case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: ios_puts("EXCEPTION_ARRAY_BOUNDS_EXCEEDED", ios_stderr); break; case EXCEPTION_BREAKPOINT: ios_puts("EXCEPTION_BREAKPOINT", ios_stderr); break; case EXCEPTION_DATATYPE_MISALIGNMENT: ios_puts("EXCEPTION_DATATYPE_MISALIGNMENT", ios_stderr); break; case EXCEPTION_FLT_DENORMAL_OPERAND: ios_puts("EXCEPTION_FLT_DENORMAL_OPERAND", ios_stderr); break; case EXCEPTION_FLT_DIVIDE_BY_ZERO: ios_puts("EXCEPTION_FLT_DIVIDE_BY_ZERO", ios_stderr); break; case EXCEPTION_FLT_INEXACT_RESULT: ios_puts("EXCEPTION_FLT_INEXACT_RESULT", ios_stderr); break; case EXCEPTION_FLT_INVALID_OPERATION: ios_puts("EXCEPTION_FLT_INVALID_OPERATION", ios_stderr); break; case EXCEPTION_FLT_OVERFLOW: ios_puts("EXCEPTION_FLT_OVERFLOW", ios_stderr); break; case EXCEPTION_FLT_STACK_CHECK: ios_puts("EXCEPTION_FLT_STACK_CHECK", ios_stderr); break; case EXCEPTION_FLT_UNDERFLOW: ios_puts("EXCEPTION_FLT_UNDERFLOW", ios_stderr); break; case EXCEPTION_ILLEGAL_INSTRUCTION: ios_puts("EXCEPTION_ILLEGAL_INSTRUCTION", ios_stderr); break; case EXCEPTION_IN_PAGE_ERROR: ios_puts("EXCEPTION_IN_PAGE_ERROR", ios_stderr); break; case EXCEPTION_INT_DIVIDE_BY_ZERO: ios_puts("EXCEPTION_INT_DIVIDE_BY_ZERO", ios_stderr); break; case EXCEPTION_INT_OVERFLOW: ios_puts("EXCEPTION_INT_OVERFLOW", ios_stderr); break; case EXCEPTION_INVALID_DISPOSITION: ios_puts("EXCEPTION_INVALID_DISPOSITION", ios_stderr); break; case EXCEPTION_NONCONTINUABLE_EXCEPTION: ios_puts("EXCEPTION_NONCONTINUABLE_EXCEPTION", ios_stderr); break; case EXCEPTION_PRIV_INSTRUCTION: ios_puts("EXCEPTION_PRIV_INSTRUCTION", ios_stderr); break; case EXCEPTION_SINGLE_STEP: ios_puts("EXCEPTION_SINGLE_STEP", ios_stderr); break; case EXCEPTION_STACK_OVERFLOW: ios_puts("EXCEPTION_STACK_OVERFLOW", ios_stderr); break; default: ios_puts("UNKNOWN", ios_stderr); break; } ios_printf(ios_stderr," at 0x%Ix -- ", (size_t)ExceptionInfo->ExceptionRecord->ExceptionAddress); gdblookup((ptrint_t)ExceptionInfo->ExceptionRecord->ExceptionAddress); bt_size = rec_backtrace_ctx(bt_data, MAX_BT_SIZE, ExceptionInfo->ContextRecord); jlbacktrace(); } return EXCEPTION_CONTINUE_SEARCH; }
DLLEXPORT void jl_print_symbol(jl_sym_t *sym) { ios_puts(sym->name, jl_current_output_stream()); }
static LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) { if (ExceptionInfo->ExceptionRecord->ExceptionFlags == 0) { switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { case EXCEPTION_STACK_OVERFLOW: #if defined(_CPU_X86_64_) ExceptionInfo->ContextRecord->Rip = (DWORD64)&win_raise_exception; ExceptionInfo->ContextRecord->Rcx = (DWORD64)jl_stackovf_exception; ExceptionInfo->ContextRecord->Rsp &= (DWORD64)-16; ExceptionInfo->ContextRecord->Rsp -= 8; //fix up the stack pointer -- this seems to be correct by observation #elif defined(_CPU_X86_) ExceptionInfo->ContextRecord->Eip = (DWORD)&win_raise_exception; ExceptionInfo->ContextRecord->Ecx = (DWORD)jl_stackovf_exception; ExceptionInfo->ContextRecord->Esp &= (DWORD)-16; ExceptionInfo->ContextRecord->Esp -= 4; //fix up the stack pointer #else #error WIN16 not supported :P #endif return EXCEPTION_CONTINUE_EXECUTION; default: ios_puts("Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.\nException: ", ios_stderr); switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: ios_puts("EXCEPTION_ACCESS_VIOLATION", ios_stderr); break; case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: ios_puts("EXCEPTION_ARRAY_BOUNDS_EXCEEDED", ios_stderr); break; case EXCEPTION_BREAKPOINT: ios_puts("EXCEPTION_BREAKPOINT", ios_stderr); break; case EXCEPTION_DATATYPE_MISALIGNMENT: ios_puts("EXCEPTION_DATATYPE_MISALIGNMENT", ios_stderr); break; case EXCEPTION_FLT_DENORMAL_OPERAND: ios_puts("EXCEPTION_FLT_DENORMAL_OPERAND", ios_stderr); break; case EXCEPTION_FLT_DIVIDE_BY_ZERO: ios_puts("EXCEPTION_FLT_DIVIDE_BY_ZERO", ios_stderr); break; case EXCEPTION_FLT_INEXACT_RESULT: ios_puts("EXCEPTION_FLT_INEXACT_RESULT", ios_stderr); break; case EXCEPTION_FLT_INVALID_OPERATION: ios_puts("EXCEPTION_FLT_INVALID_OPERATION", ios_stderr); break; case EXCEPTION_FLT_OVERFLOW: ios_puts("EXCEPTION_FLT_OVERFLOW", ios_stderr); break; case EXCEPTION_FLT_STACK_CHECK: ios_puts("EXCEPTION_FLT_STACK_CHECK", ios_stderr); break; case EXCEPTION_FLT_UNDERFLOW: ios_puts("EXCEPTION_FLT_UNDERFLOW", ios_stderr); break; case EXCEPTION_ILLEGAL_INSTRUCTION: ios_puts("EXCEPTION_ILLEGAL_INSTRUCTION", ios_stderr); break; case EXCEPTION_IN_PAGE_ERROR: ios_puts("EXCEPTION_IN_PAGE_ERROR", ios_stderr); break; case EXCEPTION_INT_DIVIDE_BY_ZERO: ios_puts("EXCEPTION_INT_DIVIDE_BY_ZERO", ios_stderr); break; case EXCEPTION_INT_OVERFLOW: ios_puts("EXCEPTION_INT_OVERFLOW", ios_stderr); break; case EXCEPTION_INVALID_DISPOSITION: ios_puts("EXCEPTION_INVALID_DISPOSITION", ios_stderr); break; case EXCEPTION_NONCONTINUABLE_EXCEPTION: ios_puts("EXCEPTION_NONCONTINUABLE_EXCEPTION", ios_stderr); break; case EXCEPTION_PRIV_INSTRUCTION: ios_puts("EXCEPTION_PRIV_INSTRUCTION", ios_stderr); break; case EXCEPTION_SINGLE_STEP: ios_puts("EXCEPTION_SINGLE_STEP", ios_stderr); break; case EXCEPTION_STACK_OVERFLOW: ios_puts("EXCEPTION_STACK_OVERFLOW", ios_stderr); break; default: ios_puts("UNKNOWN", ios_stderr); break; } ios_printf(ios_stderr," at 0x%Ix -- ", (size_t)ExceptionInfo->ExceptionRecord->ExceptionAddress); gdblookup((ptrint_t)ExceptionInfo->ExceptionRecord->ExceptionAddress); bt_size = rec_backtrace_ctx(bt_data, MAX_BT_SIZE, ExceptionInfo->ContextRecord); jlbacktrace(); break; } } return EXCEPTION_CONTINUE_SEARCH; }
static void outs(char *s, ios_t *f) { ios_puts(s, f); HPOS += u8_strwidth(s); }
static void outs(fl_context_t *fl_ctx, char *s, ios_t *f) { ios_puts(s, f); fl_ctx->HPOS += u8_strwidth(s); }