void sl_init_float(sl_vm_t* vm) { vm->lib.Float = sl_define_class(vm, "Float", vm->lib.Number); sl_class_set_allocator(vm, vm->lib.Float, allocate_float); sl_define_method(vm, vm->lib.Float, "to_s", 0, sl_float_to_s); sl_define_method(vm, vm->lib.Float, "inspect", 0, sl_float_to_s); sl_define_method(vm, vm->lib.Float, "to_i", 0, sl_float_to_i); sl_define_method(vm, vm->lib.Float, "to_f", 0, sl_float_to_f); sl_define_method(vm, vm->lib.Float, "succ", 0, sl_float_succ); sl_define_method(vm, vm->lib.Float, "pred", 0, sl_float_pred); sl_define_method(vm, vm->lib.Float, "-self", 0, sl_float_negate); sl_define_method(vm, vm->lib.Float, "round", 0, sl_float_round); sl_define_method(vm, vm->lib.Float, "floor", 0, sl_float_floor); sl_define_method(vm, vm->lib.Float, "ceil", 0, sl_float_ceil); sl_define_method(vm, vm->lib.Float, "+", 1, sl_float_add); sl_define_method(vm, vm->lib.Float, "-", 1, sl_float_sub); sl_define_method(vm, vm->lib.Float, "*", 1, sl_float_mul); sl_define_method(vm, vm->lib.Float, "/", 1, sl_float_div); sl_define_method(vm, vm->lib.Float, "%", 1, sl_float_mod); sl_define_method(vm, vm->lib.Float, "**", 1, sl_float_pow); sl_define_method(vm, vm->lib.Float, "==", 1, sl_float_eq); sl_define_method(vm, vm->lib.Float, "<=>", 1, sl_float_cmp); sl_define_method(vm, vm->lib.Float, "nan", 0, sl_float_nan); sl_define_method(vm, vm->lib.Float, "finite", 0, sl_float_finite); sl_define_method(vm, vm->lib.Float, "infinite", 0, sl_float_infinite); sl_class_set_const(vm, vm->lib.Object, "Infinity", sl_make_float(vm, 1.0/0.0)); sl_class_set_const(vm, vm->lib.Object, "NaN", sl_make_float(vm, 0.0/0.0)); }
void sl_init_ext_mysql(sl_vm_t* vm) { SLVAL MySQL, MySQL_Error, MySQL_Statement; MySQL = sl_define_class(vm, "MySQL", vm->lib.Object); sl_class_set_allocator(vm, MySQL, allocate_mysql); sl_define_method(vm, MySQL, "init", 3, sl_mysql_init); sl_define_method(vm, MySQL, "use", 1, sl_mysql_use); sl_define_method(vm, MySQL, "query", -2, sl_mysql_query); sl_define_method(vm, MySQL, "prepare", 1, sl_mysql_prepare); sl_define_method(vm, MySQL, "escape", 1, sl_mysql_escape); sl_define_method(vm, MySQL, "insert_id", 0, sl_mysql_insert_id); MySQL_Error = sl_define_class3(vm, sl_intern(vm, "Error"), vm->lib.Error, MySQL); MySQL_Statement = sl_define_class3(vm, sl_intern(vm, "Statement"), vm->lib.Object, MySQL); sl_class_set_allocator(vm, MySQL_Statement, allocate_mysql_stmt); sl_define_method(vm, MySQL_Statement, "param_count", 0, sl_mysql_stmt_param_count); sl_define_method(vm, MySQL_Statement, "execute", -1, sl_mysql_stmt_execute); sl_define_method(vm, MySQL_Statement, "insert_id", 0, sl_mysql_stmt_insert_id); vm->store[cMySQL] = MySQL; vm->store[cMySQL_Error] = MySQL_Error; vm->store[cMySQL_Statement] = MySQL_Statement; sl_do_string(vm, (uint8_t*)sl__ext_mysql_extensions_sl, strlen(sl__ext_mysql_extensions_sl), "ext/mysql/extensions.sl", 0); }
void sl_init_method(sl_vm_t* vm) { vm->lib.Method = sl_define_class(vm, "Method", vm->lib.Object); sl_class_set_allocator(vm, vm->lib.Method, allocate_method); sl_define_method(vm, vm->lib.Method, "bind", 1, sl_method_bind); sl_define_method(vm, vm->lib.Method, "apply", -2, method_apply); sl_define_method(vm, vm->lib.Method, "name", 0, sl_method_name); sl_define_method(vm, vm->lib.Method, "on", 0, sl_method_on); sl_define_method(vm, vm->lib.Method, "arity", 0, sl_method_arity); vm->lib.BoundMethod = sl_define_class(vm, "BoundMethod", vm->lib.Method); sl_class_set_allocator(vm, vm->lib.BoundMethod, allocate_bound_method); sl_define_method(vm, vm->lib.BoundMethod, "unbind", 0, bound_method_unbind); sl_define_method(vm, vm->lib.BoundMethod, "call", -1, bound_method_call); }
void sl_init_regexp(sl_vm_t* vm) { vm->lib.Regexp = sl_define_class(vm, "Regexp", vm->lib.Object); sl_class_set_allocator(vm, vm->lib.Regexp, allocate_regexp); vm->lib.Regexp_Match = sl_define_class3(vm, sl_intern(vm, "Match"), vm->lib.Object, vm->lib.Regexp); sl_class_set_allocator(vm, vm->lib.Regexp_Match, allocate_regexp_match); sl_define_method(vm, vm->lib.Regexp, "init", -2, sl_regexp_init); /* sl_define_method(vm, vm->lib.Regexp, "compile", 0, sl_regexp_compile); */ sl_define_method(vm, vm->lib.Regexp, "match", -2, sl_regexp_match); sl_define_method(vm, vm->lib.Regexp, "source", 0, sl_regexp_source); sl_define_method(vm, vm->lib.Regexp, "options", 0, sl_regexp_options); sl_define_method(vm, vm->lib.Regexp, "==", 1, sl_regexp_eq); sl_class_set_const(vm, vm->lib.Regexp, "CASELESS", sl_make_int(vm, PCRE_CASELESS)); sl_class_set_const(vm, vm->lib.Regexp, "EXTENDED", sl_make_int(vm, PCRE_EXTENDED)); sl_class_set_const(vm, vm->lib.Regexp, "PCRE_VERSION", sl_make_cstring(vm, pcre_version())); sl_define_method(vm, vm->lib.Regexp_Match, "regexp", 0, sl_regexp_match_regexp); sl_define_method(vm, vm->lib.Regexp_Match, "[]", 1, sl_regexp_match_index); sl_define_method(vm, vm->lib.Regexp_Match, "byte_offset", 1, sl_regexp_match_byte_offset); sl_define_method(vm, vm->lib.Regexp_Match, "offset", 1, sl_regexp_match_offset); sl_define_method(vm, vm->lib.Regexp_Match, "capture", 1, sl_regexp_match_capture); sl_define_method(vm, vm->lib.Regexp_Match, "length", 0, sl_regexp_match_length); sl_define_method(vm, vm->lib.Regexp_Match, "before", 0, sl_regexp_match_before); sl_define_method(vm, vm->lib.Regexp_Match, "after", 0, sl_regexp_match_after); }
void sl_init_true(sl_vm_t* vm) { vm->lib.True = sl_define_class(vm, "True", vm->lib.Object); sl_class_set_allocator(vm, vm->lib.True, allocate_true); sl_define_method(vm, vm->lib.True, "to_s", 0, true_to_s); sl_define_method(vm, vm->lib.True, "inspect", 0, true_to_s); sl_define_method(vm, vm->lib.True, "==", 1, true_eq); vm->lib._true = sl_allocate(vm, vm->lib.True); }
void sl_init_range(sl_vm_t* vm) { vm->lib.Range = sl_define_class(vm, "Range", vm->lib.Enumerable); sl_class_set_allocator(vm, vm->lib.Range, allocate_range); sl_define_method(vm, vm->lib.Range, "init", -3, range_init); sl_define_method(vm, vm->lib.Range, "enumerate", 0, range_enumerate); vm->lib.Range_Enumerator = sl_define_class3(vm, sl_intern(vm, "Enumerator"), vm->lib.Object, vm->lib.Range); sl_class_set_allocator(vm, vm->lib.Range_Enumerator, allocate_range_enumerator); sl_define_method(vm, vm->lib.Range_Enumerator, "current", 0, range_enumerator_current); sl_define_method(vm, vm->lib.Range_Enumerator, "next", 0, range_enumerator_next); }
void sl_init_ext_posix(sl_vm_t* vm) { SLVAL Posix = sl_define_class(vm, "Posix", vm->lib.Object); SLVAL Posix_OSError = sl_define_class3(vm, sl_intern(vm, "OSError"), vm->lib.Error, Posix); sl_define_method(vm, Posix_OSError, "errno", 0, sl_posix_oserror_get_errno); vm->store[cPosix_OSError] = Posix_OSError; sl_init_ext_posix_errno(vm, Posix); sl_init_ext_posix_fork(vm, Posix); sl_init_ext_posix_getpid(vm, Posix); }
void sl_init_nil(sl_vm_t* vm) { sl_object_t* nil = sl_get_ptr(vm->lib.nil); vm->lib.Nil = sl_define_class(vm, "Nil", vm->lib.Object); sl_class_set_allocator(vm, vm->lib.Nil, allocate_nil); nil->klass = vm->lib.Nil; nil->primitive_type = SL_T_NIL; nil->instance_variables = NULL; sl_define_method(vm, vm->lib.Nil, "to_s", 0, nil_to_s); sl_define_method(vm, vm->lib.Nil, "inspect", 0, nil_inspect); sl_define_method(vm, vm->lib.Nil, "==", 1, nil_eq); }
void sl_init_ext_json(sl_vm_t* vm) { SLVAL JSON = sl_define_class(vm, "JSON", vm->lib.Object); SLVAL JSON_ParseError = sl_define_class3(vm, sl_intern(vm, "ParseError"), vm->lib.SyntaxError, JSON); SLVAL JSON_DumpError = sl_define_class3(vm, sl_intern(vm, "DumpError"), vm->lib.SyntaxError, JSON); sl_define_singleton_method(vm, JSON, "parse", -2, sl_json_parse); sl_define_singleton_method(vm, JSON, "dump", 1, sl_json_dump); sl_define_singleton_method(vm, JSON, "decode", -2, sl_json_parse); sl_define_singleton_method(vm, JSON, "encode", 1, sl_json_dump); vm->store[cJSON] = JSON; vm->store[cJSON_ParseError] = JSON_ParseError; vm->store[cJSON_DumpError] = JSON_DumpError; }
void sl_init_enumerable(sl_vm_t* vm) { vm->lib.Enumerable = sl_define_class(vm, "Enumerable", vm->lib.Object); sl_define_method(vm, vm->lib.Enumerable, "map", 1, enumerable_map); sl_define_method(vm, vm->lib.Enumerable, "to_a", 0, enumerable_to_a); sl_define_method(vm, vm->lib.Enumerable, "reduce", -2, enumerable_reduce); sl_define_method(vm, vm->lib.Enumerable, "fold", -2, enumerable_reduce); sl_define_method(vm, vm->lib.Enumerable, "join", -1, sl_enumerable_join); sl_define_method(vm, vm->lib.Enumerable, "length", 0, enumerable_length); sl_define_method(vm, vm->lib.Enumerable, "empty", 0, enumerable_empty); sl_define_method(vm, vm->lib.Enumerable, "any", -1, enumerable_any); sl_define_method(vm, vm->lib.Enumerable, "all", -1, enumerable_all); sl_define_method(vm, vm->lib.Enumerable, "find", 1, enumerable_find); sl_define_method(vm, vm->lib.Enumerable, "filter", 1, enumerable_filter); sl_define_method(vm, vm->lib.Enumerable, "reject", 1, enumerable_reject); sl_define_method(vm, vm->lib.Enumerable, "sort", -1, enumerable_sort); sl_define_method(vm, vm->lib.Enumerable, "drop", 1, enumerable_drop); sl_define_method(vm, vm->lib.Enumerable, "take", 1, enumerable_take); }
void sl_init_ext_gcrypt(sl_vm_t* vm) { SLVAL GCrypt = sl_define_class(vm, "GCrypt", vm->lib.Object); SLVAL Algorithm = sl_define_class3(vm, sl_make_cstring(vm, "Algorithm"), vm->lib.Object, GCrypt); sl_vm_store_put(vm, &cGCrypt, GCrypt); sl_vm_store_put(vm, &cGCrypt_Algorithm, Algorithm); sl_class_set_allocator(vm, Algorithm, allocate_gcrypt_algorithm); sl_define_method(vm, Algorithm, "hex_digest", 1, sl_gcrypt_algorithm_hex_digest); sl_define_method(vm, Algorithm, "to_s", 0, sl_gcrypt_algorithm_inspect); sl_define_method(vm, Algorithm, "inspect", 0, sl_gcrypt_algorithm_inspect); #define MAKE_ALGO(name) make_algorithm_object(vm, GCrypt, Algorithm, #name, GCRY_MD_##name) MAKE_ALGO(MD5); MAKE_ALGO(SHA1); MAKE_ALGO(SHA224); MAKE_ALGO(SHA256); MAKE_ALGO(SHA384); MAKE_ALGO(SHA512); MAKE_ALGO(WHIRLPOOL); }
void sl_init_number(sl_vm_t* vm) { vm->lib.Number = sl_define_class(vm, "Number", vm->lib.Comparable); }