diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-05-18 10:09:28 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-06-19 18:46:55 +0900 |
commit | c8703a17ceedae4a72f83c962a4d098731a85dda (patch) | |
tree | 1a7559bafd2356904bef9b531ae3fa30d7649095 /compile.c | |
parent | f3e081c6b6f877c498ce9203429ee4fd7e812837 (diff) |
[Feature #16254] Allow `__builtin.func` style
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3165
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -7039,18 +7039,30 @@ iseq_builtin_function_lookup(const rb_iseq_t *iseq, const char *name) } static const char * -iseq_builtin_function_name(ID mid) +iseq_builtin_function_name(const enum node_type type, const NODE *recv, ID mid) { const char *name = rb_id2name(mid); static const char prefix[] = "__builtin_"; const size_t prefix_len = sizeof(prefix) - 1; - if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) { - return &name[prefix_len]; + if (type == NODE_CALL) { + if (recv) { + switch (nd_type(recv)) { + case NODE_VCALL: + if (recv->nd_mid == rb_intern("__builtin")) { + return name; + } + break; + default: break; + } + } } - else { - return NULL; + else if (type == NODE_VCALL || type == NODE_FCALL) { + if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) { + return &name[prefix_len]; + } } + return NULL; } static int @@ -7204,8 +7216,7 @@ compile_call(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, co NODE *args_node = node->nd_args; if (UNLIKELY(iseq_has_builtin_function_table(iseq)) && - (type == NODE_VCALL || type == NODE_FCALL) && - (builtin_func = iseq_builtin_function_name(mid)) != NULL) { + (builtin_func = iseq_builtin_function_name(type, node->nd_recv, mid)) != NULL) { if (parent_block != NULL) { COMPILE_ERROR(iseq, line, "should not call builtins here."); |