void jl_init_builtins(void) { jl_function_t *jl_print_gf = jl_new_generic_function(jl_symbol("print")); add_builtin_method1(jl_print_gf, (jl_type_t*)jl_array_uint8_type, jl_f_print_array_uint8); add_builtin_method1(jl_print_gf, (jl_type_t*)jl_sym_type, jl_f_print_symbol); jl_show_gf = jl_new_generic_function(jl_symbol("show")); add_builtin_method1(jl_show_gf, (jl_type_t*)jl_any_type, jl_f_show_any); add_builtin_method1(jl_show_gf, (jl_type_t*)jl_int64_type, jl_f_show_int64); add_builtin_method1(jl_show_gf, (jl_type_t*)jl_uint64_type, jl_f_show_uint64); jl_convert_gf = jl_new_generic_function(jl_symbol("convert")); jl_add_method(jl_convert_gf, jl_tuple2(jl_any_type, jl_any_type), jl_new_closure(jl_f_convert, NULL)); jl_add_method(jl_convert_gf, jl_tuple2(jl_tuple_type, jl_tuple_type), jl_new_closure(jl_f_convert_tuple, NULL)); add_builtin("print", (jl_value_t*)jl_print_gf); add_builtin("show", (jl_value_t*)jl_show_gf); add_builtin("convert", (jl_value_t*)jl_convert_gf); }
void jl_gc_add_finalizer(jl_value_t *v, jl_function_t *f) { jl_value_t **bp = (jl_value_t**)ptrhash_bp(&finalizer_table, v); if (*bp == HT_NOTFOUND) { *bp = (jl_value_t*)f; } else { *bp = (jl_value_t*)jl_tuple2((jl_value_t*)f, *bp); } }
// fetch references to things defined in boot.j void jl_get_builtin_hooks(void) { jl_nothing = global("nothing"); jl_root_task->tls = jl_nothing; jl_char_type = (jl_bits_type_t*)global("Char"); jl_int8_type = (jl_bits_type_t*)global("Int8"); jl_uint8_type = (jl_bits_type_t*)global("Uint8"); jl_int16_type = (jl_bits_type_t*)global("Int16"); jl_uint16_type = (jl_bits_type_t*)global("Uint16"); jl_uint32_type = (jl_bits_type_t*)global("Uint32"); jl_uint64_type = (jl_bits_type_t*)global("Uint64"); jl_float32_type = (jl_bits_type_t*)global("Float32"); jl_float64_type = (jl_bits_type_t*)global("Float64"); jl_weakref_type = (jl_struct_type_t*)global("WeakRef"); jl_weakref_type->fptr = jl_weakref_ctor; jl_weakref_type->env = NULL; jl_weakref_type->linfo = NULL; jl_string_type = (jl_tag_type_t*)global("String"); jl_ascii_string_type = (jl_struct_type_t*)global("ASCIIString"); jl_utf8_string_type = (jl_struct_type_t*)global("UTF8String"); jl_errorexception_type = (jl_struct_type_t*)global("ErrorException"); jl_typeerror_type = (jl_struct_type_t*)global("TypeError"); jl_loaderror_type = (jl_struct_type_t*)global("LoadError"); jl_uniontoocomplex_type = (jl_struct_type_t*)global("UnionTooComplexError"); jl_backtrace_type = (jl_struct_type_t*)global("BackTrace"); jl_symbolnode_type = (jl_struct_type_t*)global("SymbolNode"); jl_stackovf_exception = jl_apply((jl_function_t*)global("StackOverflowError"), NULL, 0); jl_divbyzero_exception = jl_apply((jl_function_t*)global("DivideByZeroError"), NULL, 0); jl_undefref_exception = jl_apply((jl_function_t*)global("UndefRefError"),NULL,0); jl_interrupt_exception = jl_apply((jl_function_t*)global("InterruptException"),NULL,0); jl_memory_exception = jl_apply((jl_function_t*)global("MemoryError"),NULL,0); jl_append_any_func = (jl_function_t*)global("append_any"); jl_method_missing_func = (jl_function_t*)global("method_missing"); jl_array_uint8_type = (jl_type_t*)jl_apply_type((jl_value_t*)jl_array_type, jl_tuple2(jl_uint8_type, jl_box_long(1))); }
// fetch references to things defined in boot.jl void jl_get_builtin_hooks(void) { jl_nothing = core("nothing"); jl_root_task->tls = jl_nothing; jl_root_task->consumers = jl_nothing; jl_root_task->donenotify = jl_nothing; jl_root_task->exception = jl_nothing; jl_char_type = (jl_datatype_t*)core("Char"); jl_int8_type = (jl_datatype_t*)core("Int8"); jl_uint8_type = (jl_datatype_t*)core("Uint8"); jl_int16_type = (jl_datatype_t*)core("Int16"); jl_uint16_type = (jl_datatype_t*)core("Uint16"); jl_uint32_type = (jl_datatype_t*)core("Uint32"); jl_uint64_type = (jl_datatype_t*)core("Uint64"); jl_float32_type = (jl_datatype_t*)core("Float32"); jl_float64_type = (jl_datatype_t*)core("Float64"); jl_floatingpoint_type = (jl_datatype_t*)core("FloatingPoint"); jl_stackovf_exception = jl_apply((jl_function_t*)core("StackOverflowError"), NULL, 0); jl_diverror_exception = jl_apply((jl_function_t*)core("DivideError"), NULL, 0); jl_domain_exception = jl_apply((jl_function_t*)core("DomainError"), NULL, 0); jl_overflow_exception = jl_apply((jl_function_t*)core("OverflowError"), NULL, 0); jl_inexact_exception = jl_apply((jl_function_t*)core("InexactError"), NULL, 0); jl_undefref_exception = jl_apply((jl_function_t*)core("UndefRefError"),NULL,0); jl_interrupt_exception = jl_apply((jl_function_t*)core("InterruptException"),NULL,0); jl_bounds_exception = jl_apply((jl_function_t*)core("BoundsError"),NULL,0); jl_memory_exception = jl_apply((jl_function_t*)core("MemoryError"),NULL,0); jl_ascii_string_type = (jl_datatype_t*)core("ASCIIString"); jl_utf8_string_type = (jl_datatype_t*)core("UTF8String"); jl_symbolnode_type = (jl_datatype_t*)core("SymbolNode"); jl_getfieldnode_type = (jl_datatype_t*)core("GetfieldNode"); jl_array_uint8_type = jl_apply_type((jl_value_t*)jl_array_type, jl_tuple2(jl_uint8_type, jl_box_long(1))); }
DLLEXPORT jl_value_t *jl_new_closure_internal(jl_lambda_info_t *li, jl_value_t *env) { assert(jl_is_lambda_info(li)); assert(jl_is_tuple(env)); jl_function_t *f=NULL; // note: env is pushed here to make codegen a little easier JL_GC_PUSH(&f, &env); if (li->fptr != NULL) { // function has been compiled f = jl_new_closure(li->fptr, env); } else { f = jl_new_closure(jl_trampoline, NULL); f->env = (jl_value_t*)jl_tuple2((jl_value_t*)f, env); } f->linfo = li; JL_GC_POP(); return (jl_value_t*)f; }
// this is for parsing one expression out of a string, keeping track of // the current position. DLLEXPORT jl_value_t *jl_parse_string(const char *str, int pos0, int greedy) { value_t s = cvalue_static_cstring(str); value_t p = fl_applyn(3, symbol_value(symbol("jl-parse-one-string")), s, fixnum(pos0), greedy?FL_T:FL_F); jl_value_t *expr=NULL, *pos1=NULL; JL_GC_PUSH(&expr, &pos1); value_t e = car_(p); if (e == FL_T || e == FL_F || e == FL_EOF) { expr = (jl_value_t*)jl_null; } else { expr = scm_to_julia(e); } pos1 = jl_box_long(toulong(cdr_(p),"parse")); jl_value_t *result = (jl_value_t*)jl_tuple2(expr, pos1); JL_GC_POP(); return result; }
// fetch references to things defined in boot.jl void jl_get_builtin_hooks(void) { jl_nothing = core("nothing"); jl_root_task->tls = jl_nothing; jl_char_type = (jl_bits_type_t*)core("Char"); jl_int8_type = (jl_bits_type_t*)core("Int8"); jl_uint8_type = (jl_bits_type_t*)core("Uint8"); jl_int16_type = (jl_bits_type_t*)core("Int16"); jl_uint16_type = (jl_bits_type_t*)core("Uint16"); jl_uint32_type = (jl_bits_type_t*)core("Uint32"); jl_uint64_type = (jl_bits_type_t*)core("Uint64"); jl_float32_type = (jl_bits_type_t*)core("Float32"); jl_float64_type = (jl_bits_type_t*)core("Float64"); jl_stackovf_exception = jl_apply((jl_function_t*)core("StackOverflowError"), NULL, 0); jl_divbyzero_exception = jl_apply((jl_function_t*)core("DivideByZeroError"), NULL, 0); jl_undefref_exception = jl_apply((jl_function_t*)core("UndefRefError"),NULL,0); jl_interrupt_exception = jl_apply((jl_function_t*)core("InterruptException"),NULL,0); jl_memory_exception = jl_apply((jl_function_t*)core("MemoryError"),NULL,0); jl_weakref_type = (jl_struct_type_t*)core("WeakRef"); jl_ascii_string_type = (jl_struct_type_t*)core("ASCIIString"); jl_utf8_string_type = (jl_struct_type_t*)core("UTF8String"); jl_symbolnode_type = (jl_struct_type_t*)core("SymbolNode"); jl_array_uint8_type = (jl_type_t*)jl_apply_type((jl_value_t*)jl_array_type, jl_tuple2(jl_uint8_type, jl_box_long(1))); }