Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mrubyc/mrubyc
Browse files Browse the repository at this point in the history
  • Loading branch information
kaz0505 committed Mar 5, 2021
2 parents 5300f02 + 0328a54 commit f57263c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 34 deletions.
28 changes: 26 additions & 2 deletions src/c_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,29 @@ int mrbc_string_chomp(mrbc_value *src)
}


//================================================================
/*! (method) new
*/
static void c_string_new(struct VM *vm, mrbc_value v[], int argc)
{
if (argc == 1 && v[1].tt != MRBC_TT_STRING) {
console_print( "TypeError\n" ); // raise? TypeError
return;
}
if (argc > 1) {
console_print( "Wrong number of arguments (expected 0..1)\n" ); // raise? ArgumentError
return;
}

mrbc_value value;
if (argc == 0) {
value = mrbc_string_new(vm, NULL, 0);
} else {
value = mrbc_string_dup(vm, &v[1]);
}
SET_RETURN(value);
}


//================================================================
/*! (method) +
Expand Down Expand Up @@ -627,7 +650,7 @@ static void c_string_getbyte(struct VM *vm, mrbc_value v[], int argc)
idx += len;
}
if( idx >= 0 ) {
SET_INT_RETURN( mrbc_string_cstr(&v[0])[idx] );
SET_INT_RETURN( ((uint8_t *)mrbc_string_cstr(&v[0]))[idx] );
} else {
SET_NIL_RETURN();
}
Expand Down Expand Up @@ -695,7 +718,7 @@ static void c_string_inspect(struct VM *vm, mrbc_value v[], int argc)
*/
static void c_string_ord(struct VM *vm, mrbc_value v[], int argc)
{
int i = (uint8_t)mrbc_string_cstr(v)[0];
int i = ((uint8_t *)mrbc_string_cstr(v))[0];

SET_INT_RETURN( i );
}
Expand Down Expand Up @@ -1203,6 +1226,7 @@ static void c_string_include(struct VM *vm, mrbc_value v[], int argc)
FILE("method_table_string.h")
FUNC("mrbc_init_class_string")
METHOD( "new", c_string_new )
METHOD( "+", c_string_add )
METHOD( "*", c_string_mul )
METHOD( "size", c_string_size )
Expand Down
4 changes: 2 additions & 2 deletions src/method_table_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ struct RClass *mrbc_init_class_array(struct VM *vm)
static const mrbc_sym method_symbols[] = {
MRBC_SYMID_PLUS,
MRBC_SYMID_LT_LT,
MRBC_SYMID_BLL_BLR,
MRBC_SYMID_BLL_BLR_EQ,
MRBC_SYMID_BL_BR,
MRBC_SYMID_BL_BR_EQ,
MRBC_SYMID_at,
MRBC_SYMID_clear,
MRBC_SYMID_count,
Expand Down
6 changes: 3 additions & 3 deletions src/method_table_fixnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ struct RClass *mrbc_init_class_fixnum(struct VM *vm)
MRBC_SYMID_MINUS_AT,
MRBC_SYMID_LT_LT,
MRBC_SYMID_GT_GT,
MRBC_SYMID_BLL_BLR,
MRBC_SYMID_HAT,
MRBC_SYMID_BL_BR,
MRBC_SYMID_XOR,
MRBC_SYMID_abs,
#if MRBC_USE_STRING
MRBC_SYMID_chr,
Expand All @@ -27,7 +27,7 @@ struct RClass *mrbc_init_class_fixnum(struct VM *vm)
MRBC_SYMID_to_s,
#endif
MRBC_SYMID_OR,
MRBC_SYMID_TILDE,
MRBC_SYMID_NEG,
};
static const mrbc_func_t method_functions[] = {
c_fixnum_mod,
Expand Down
6 changes: 3 additions & 3 deletions src/method_table_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
struct RClass *mrbc_init_class_hash(struct VM *vm)
{
static const mrbc_sym method_symbols[] = {
MRBC_SYMID_BLL_BLR,
MRBC_SYMID_BLL_BLR_EQ,
MRBC_SYMID_BL_BR,
MRBC_SYMID_BL_BR_EQ,
MRBC_SYMID_clear,
MRBC_SYMID_count,
MRBC_SYMID_delete,
Expand All @@ -19,7 +19,7 @@ struct RClass *mrbc_init_class_hash(struct VM *vm)
MRBC_SYMID_keys,
MRBC_SYMID_length,
MRBC_SYMID_merge,
MRBC_SYMID_merge_EXC,
MRBC_SYMID_merge_E,
MRBC_SYMID_new,
MRBC_SYMID_size,
MRBC_SYMID_to_h,
Expand Down
18 changes: 10 additions & 8 deletions src/method_table_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ struct RClass *mrbc_init_class_string(struct VM *vm)
MRBC_SYMID_MUL,
MRBC_SYMID_PLUS,
MRBC_SYMID_LT_LT,
MRBC_SYMID_BLL_BLR,
MRBC_SYMID_BLL_BLR_EQ,
MRBC_SYMID_BL_BR,
MRBC_SYMID_BL_BR_EQ,
MRBC_SYMID_b,
MRBC_SYMID_chomp,
MRBC_SYMID_chomp_EXC,
MRBC_SYMID_chomp_E,
MRBC_SYMID_clear,
MRBC_SYMID_dup,
MRBC_SYMID_empty_Q,
Expand All @@ -22,24 +22,25 @@ struct RClass *mrbc_init_class_string(struct VM *vm)
MRBC_SYMID_intern,
MRBC_SYMID_length,
MRBC_SYMID_lstrip,
MRBC_SYMID_lstrip_EXC,
MRBC_SYMID_lstrip_E,
MRBC_SYMID_new,
MRBC_SYMID_ord,
MRBC_SYMID_rstrip,
MRBC_SYMID_rstrip_EXC,
MRBC_SYMID_rstrip_E,
MRBC_SYMID_size,
MRBC_SYMID_slice_EXC,
MRBC_SYMID_slice_E,
MRBC_SYMID_split,
MRBC_SYMID_start_with_Q,
MRBC_SYMID_strip,
MRBC_SYMID_strip_EXC,
MRBC_SYMID_strip_E,
#if MRBC_USE_FLOAT
MRBC_SYMID_to_f,
#endif
MRBC_SYMID_to_i,
MRBC_SYMID_to_s,
MRBC_SYMID_to_sym,
MRBC_SYMID_tr,
MRBC_SYMID_tr_EXC,
MRBC_SYMID_tr_E,
};
static const mrbc_func_t method_functions[] = {
c_string_mul,
Expand All @@ -62,6 +63,7 @@ struct RClass *mrbc_init_class_string(struct VM *vm)
c_string_size,
c_string_lstrip,
c_string_lstrip_self,
c_string_new,
c_string_ord,
c_string_rstrip,
c_string_rstrip_self,
Expand Down
32 changes: 17 additions & 15 deletions src/symbol_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ enum {
MRBC_SYMID_TrueClass = 32,
MRBC_SYMID_TypeError = 33,
MRBC_SYMID_ZeroDivisionError = 34,
MRBC_SYMID_BLL_BLR = 35,
MRBC_SYMID_BLL_BLR_EQ = 36,
MRBC_SYMID_HAT = 37,
MRBC_SYMID_BL_BR = 35,
MRBC_SYMID_BL_BR_EQ = 36,
MRBC_SYMID_XOR = 37,
MRBC_SYMID_abs = 38,
MRBC_SYMID_acos = 39,
MRBC_SYMID_acosh = 40,
Expand All @@ -221,12 +221,12 @@ enum {
MRBC_SYMID_call = 52,
MRBC_SYMID_cbrt = 53,
MRBC_SYMID_chomp = 54,
MRBC_SYMID_chomp_EXC = 55,
MRBC_SYMID_chomp_E = 55,
MRBC_SYMID_chr = 56,
MRBC_SYMID_class = 57,
MRBC_SYMID_clear = 58,
MRBC_SYMID_collect = 59,
MRBC_SYMID_collect_EXC = 60,
MRBC_SYMID_collect_E = 60,
MRBC_SYMID_cos = 61,
MRBC_SYMID_cosh = 62,
MRBC_SYMID_count = 63,
Expand Down Expand Up @@ -271,13 +271,13 @@ enum {
MRBC_SYMID_log2 = 102,
MRBC_SYMID_loop = 103,
MRBC_SYMID_lstrip = 104,
MRBC_SYMID_lstrip_EXC = 105,
MRBC_SYMID_lstrip_E = 105,
MRBC_SYMID_map = 106,
MRBC_SYMID_map_EXC = 107,
MRBC_SYMID_map_E = 107,
MRBC_SYMID_max = 108,
MRBC_SYMID_memory_statistics = 109,
MRBC_SYMID_merge = 110,
MRBC_SYMID_merge_EXC = 111,
MRBC_SYMID_merge_E = 111,
MRBC_SYMID_message = 112,
MRBC_SYMID_min = 113,
MRBC_SYMID_minmax = 114,
Expand All @@ -293,22 +293,22 @@ enum {
MRBC_SYMID_puts = 124,
MRBC_SYMID_raise = 125,
MRBC_SYMID_reject = 126,
MRBC_SYMID_reject_EXC = 127,
MRBC_SYMID_reject_E = 127,
MRBC_SYMID_rstrip = 128,
MRBC_SYMID_rstrip_EXC = 129,
MRBC_SYMID_rstrip_E = 129,
MRBC_SYMID_shift = 130,
MRBC_SYMID_sin = 131,
MRBC_SYMID_sinh = 132,
MRBC_SYMID_size = 133,
MRBC_SYMID_slice_EXC = 134,
MRBC_SYMID_slice_E = 134,
MRBC_SYMID_sort = 135,
MRBC_SYMID_sort_EXC = 136,
MRBC_SYMID_sort_E = 136,
MRBC_SYMID_split = 137,
MRBC_SYMID_sprintf = 138,
MRBC_SYMID_sqrt = 139,
MRBC_SYMID_start_with_Q = 140,
MRBC_SYMID_strip = 141,
MRBC_SYMID_strip_EXC = 142,
MRBC_SYMID_strip_E = 142,
MRBC_SYMID_tan = 143,
MRBC_SYMID_tanh = 144,
MRBC_SYMID_times = 145,
Expand All @@ -319,10 +319,12 @@ enum {
MRBC_SYMID_to_s = 150,
MRBC_SYMID_to_sym = 151,
MRBC_SYMID_tr = 152,
MRBC_SYMID_tr_EXC = 153,
MRBC_SYMID_tr_E = 153,
MRBC_SYMID_unshift = 154,
MRBC_SYMID_values = 155,
MRBC_SYMID_OR = 156,
MRBC_SYMID_TILDE = 157,
MRBC_SYMID_NEG = 157,
};

#define MRB_SYM(sym) MRBC_SYMID_##sym
#endif
1 change: 0 additions & 1 deletion test/my_super_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def super_1_case

description "MySuper2"
def super_2_case
pend
obj = MySuper2.new()
obj.method1( 11, 22 )
assert_equal 22, obj.a1
Expand Down
12 changes: 12 additions & 0 deletions test/string_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@

class StringTest < MrubycTestCase

description "String.new with arg"
def string_new_with_arg
str = String.new("a string instance")
assert_equal "a string instance", str
end

description "String.new without arg"
def string_new_without_arg
str = String.new
assert_equal "", str
end

description "==, !="
def op_eq_case
assert_equal true, "abc" == "abc"
Expand Down

0 comments on commit f57263c

Please sign in to comment.