mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge remote-tracking branch 'upstream/master' into mrbgems
This commit is contained in:
@@ -52,7 +52,7 @@ struct RProc *mrb_closure_new(mrb_state*, mrb_irep*);
|
||||
void mrb_proc_copy(struct RProc *a, struct RProc *b);
|
||||
|
||||
#include "mruby/khash.h"
|
||||
KHASH_DECLARE(mt, mrb_sym, struct RProc*, 1);
|
||||
KHASH_DECLARE(mt, mrb_sym, struct RProc*, 1)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" { */
|
||||
|
||||
+31
-3
@@ -15,7 +15,7 @@
|
||||
#include "mruby/array.h"
|
||||
#include "error.h"
|
||||
|
||||
KHASH_DEFINE(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal);
|
||||
KHASH_DEFINE(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal)
|
||||
|
||||
typedef struct fc_result {
|
||||
mrb_sym name;
|
||||
@@ -630,7 +630,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalide argument specifier %c", c);
|
||||
mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid argument specifier %c", c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -848,6 +848,32 @@ mrb_mod_instance_methods(mrb_state *mrb, mrb_value mod)
|
||||
return class_instance_method_list(mrb, argc, argv, c, 0);
|
||||
}
|
||||
|
||||
mrb_value mrb_yield_internal(mrb_state *mrb, mrb_value b, int argc, mrb_value *argv, mrb_value self, struct RClass *c);
|
||||
|
||||
/* 15.2.2.4.35 */
|
||||
/*
|
||||
* call-seq:
|
||||
* mod.class_eval {| | block } -> obj
|
||||
* mod.module_eval {| | block } -> obj
|
||||
*
|
||||
* Evaluates block in the context of _mod_. This can
|
||||
* be used to add methods to a class. <code>module_eval</code> returns
|
||||
* the result of evaluating its argument.
|
||||
*/
|
||||
|
||||
mrb_value
|
||||
mrb_mod_module_eval(mrb_state *mrb, mrb_value mod)
|
||||
{
|
||||
mrb_value a, b;
|
||||
struct RClass *c;
|
||||
|
||||
if (mrb_get_args(mrb, "|S&", &a, &b) == 1) {
|
||||
mrb_raise(mrb, E_NOTIMP_ERROR, "module_eval/class_eval with string not implemented");
|
||||
}
|
||||
c = mrb_class_ptr(mod);
|
||||
return mrb_yield_internal(mrb, b, 0, 0, mod, c);
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_singleton_class(mrb_state *mrb, mrb_value v)
|
||||
{
|
||||
@@ -1504,9 +1530,11 @@ mrb_init_class(mrb_state *mrb)
|
||||
mrb_define_method(mrb, mod, "include", mrb_mod_include, ARGS_ANY()); /* 15.2.2.4.27 */
|
||||
mrb_define_method(mrb, mod, "include?", mrb_mod_include_p, ARGS_REQ(1)); /* 15.2.2.4.28 */
|
||||
mrb_define_method(mrb, mod, "append_features", mrb_mod_append_features, ARGS_REQ(1)); /* 15.2.2.4.10 */
|
||||
mrb_define_method(mrb, mod, "included", mrb_bob_init, ARGS_REQ(1)); /* 15.2.2.4.29 */
|
||||
mrb_define_method(mrb, mod, "class_eval", mrb_mod_module_eval, ARGS_ANY()); /* 15.2.2.4.15 */
|
||||
mrb_define_method(mrb, mod, "included", mrb_bob_init, ARGS_REQ(1)); /* 15.2.2.4.29 */
|
||||
mrb_define_method(mrb, mod, "included_modules", mrb_mod_included_modules, ARGS_NONE()); /* 15.2.2.4.30 */
|
||||
mrb_define_method(mrb, mod, "instance_methods", mrb_mod_instance_methods, ARGS_ANY()); /* 15.2.2.4.33 */
|
||||
mrb_define_method(mrb, mod, "module_eval", mrb_mod_module_eval, ARGS_ANY()); /* 15.2.2.4.35 */
|
||||
|
||||
mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, ARGS_NONE());
|
||||
mrb_define_method(mrb, mod, "inspect", mrb_mod_to_s, ARGS_NONE());
|
||||
|
||||
@@ -1412,7 +1412,6 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
codegen(s, tree->cdr->cdr->car, VAL);
|
||||
pop();
|
||||
gen_assignment(s, tree->car, cursp(), val);
|
||||
if (val) pop();
|
||||
dispatch(s, pos);
|
||||
break;
|
||||
}
|
||||
|
||||
+2
-2
@@ -29,8 +29,8 @@ mrb_hash_ht_hash_equal(mrb_state *mrb, mrb_value a, mrb_value b)
|
||||
return mrb_eql(mrb, a, b);
|
||||
}
|
||||
|
||||
KHASH_DECLARE(ht, mrb_value, mrb_value, 1);
|
||||
KHASH_DEFINE (ht, mrb_value, mrb_value, 1, mrb_hash_ht_hash_func, mrb_hash_ht_hash_equal);
|
||||
KHASH_DECLARE(ht, mrb_value, mrb_value, 1)
|
||||
KHASH_DEFINE (ht, mrb_value, mrb_value, 1, mrb_hash_ht_hash_func, mrb_hash_ht_hash_equal)
|
||||
|
||||
static void mrb_hash_modify(mrb_state *mrb, mrb_value hash);
|
||||
|
||||
|
||||
+2
-2
@@ -2511,7 +2511,7 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck)
|
||||
return mrb_fixnum_value(result);
|
||||
}
|
||||
bad:
|
||||
mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalide string for number(%s)", str);
|
||||
mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid string for number(%s)", str);
|
||||
/* not reached */
|
||||
return mrb_fixnum_value(0);
|
||||
}
|
||||
@@ -2621,7 +2621,7 @@ mrb_cstr_to_dbl(mrb_state *mrb, const char * p, int badcheck)
|
||||
if (p == end) {
|
||||
if (badcheck) {
|
||||
bad:
|
||||
mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalide string for float(%s)", p);
|
||||
mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid string for float(%s)", p);
|
||||
/* not reached */
|
||||
}
|
||||
return d;
|
||||
|
||||
+1
-1
@@ -256,7 +256,7 @@ iv_free(mrb_state *mrb, iv_tbl *t)
|
||||
#endif
|
||||
|
||||
KHASH_DECLARE(iv, mrb_sym, mrb_value, 1)
|
||||
KHASH_DEFINE(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal);
|
||||
KHASH_DEFINE(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal)
|
||||
|
||||
typedef struct iv_tbl {
|
||||
khash_t(iv) h;
|
||||
|
||||
@@ -31,6 +31,22 @@ assert('Module#append_features', '15.2.2.4.10') do
|
||||
Test4AppendFeatures2.const_get(:Const4AppendFeatures2) == Test4AppendFeatures2
|
||||
end
|
||||
|
||||
assert('Module#class_eval', '15.2.2.4.15') do
|
||||
class Test4ClassEval
|
||||
@a = 11
|
||||
@b = 12
|
||||
end
|
||||
Test4ClassEval.class_eval do
|
||||
def method1
|
||||
end
|
||||
end
|
||||
r = Test4ClassEval.instance_methods
|
||||
Test4ClassEval.class_eval{ @a } == 11 and
|
||||
Test4ClassEval.class_eval{ @b } == 12 and
|
||||
r.class == Array and r.include?(:method1)
|
||||
end
|
||||
|
||||
|
||||
assert('Module#class_variables', '15.2.2.4.19') do
|
||||
class Test4ClassVariables1
|
||||
@@var1 = 1
|
||||
@@ -151,6 +167,14 @@ assert('Module#instance_methods', '15.2.2.4.33') do
|
||||
r.class == Array and r.include?(:method3) and r.include?(:method2)
|
||||
end
|
||||
|
||||
assert('Module#module_eval', '15.2.2.4.35') do
|
||||
module Test4ModuleEval
|
||||
@a = 11
|
||||
@b = 12
|
||||
end
|
||||
Test4ModuleEval.module_eval{ @a } == 11 and
|
||||
Test4ModuleEval.module_eval{ @b } == 12
|
||||
end
|
||||
|
||||
# Not ISO specified
|
||||
|
||||
|
||||
@@ -58,3 +58,14 @@ assert('Nested const reference') do
|
||||
Syntax4Const::CONST1 == "hello world" and
|
||||
Syntax4Const::Const2.new.const1 == "hello world"
|
||||
end
|
||||
|
||||
assert('Abbreviated variable assignment as returns') do
|
||||
module Syntax4AbbrVarAsgnAsReturns
|
||||
class A
|
||||
def b
|
||||
@c ||= 1
|
||||
end
|
||||
end
|
||||
end
|
||||
Syntax4AbbrVarAsgnAsReturns::A.new.b == 1
|
||||
end
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@
|
||||
** an interactive way and executes it
|
||||
** immediately. It's a REPL...
|
||||
*/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <mruby.h>
|
||||
@@ -143,7 +143,7 @@ print_cmdline(int code_block_open)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char last_char;
|
||||
int last_char;
|
||||
char ruby_code[1024] = { 0 };
|
||||
char last_code_line[1024] = { 0 };
|
||||
int char_index;
|
||||
@@ -156,7 +156,7 @@ main(void)
|
||||
|
||||
print_hint();
|
||||
|
||||
/* new interpreter instance */
|
||||
/* new interpreter instance */
|
||||
mrb = mrb_open();
|
||||
if (mrb == NULL) {
|
||||
fprintf(stderr, "Invalid mrb interpreter, exiting mirb");
|
||||
@@ -207,7 +207,7 @@ main(void)
|
||||
parser->send = ruby_code + strlen(ruby_code);
|
||||
parser->lineno = 1;
|
||||
mrb_parser_parse(parser, cxt);
|
||||
code_block_open = is_code_block_open(parser);
|
||||
code_block_open = is_code_block_open(parser);
|
||||
|
||||
if (code_block_open) {
|
||||
/* no evaluation of code */
|
||||
|
||||
Reference in New Issue
Block a user