aboutsummaryrefslogtreecommitdiffstats
path: root/vm_core.h
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-02 18:02:55 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-02 18:02:55 +0000
commitfbebd502f9f374d1eef31c63c10c7d8adcd63280 (patch)
tree69dc3dbcdd12509100d01fce6e5d95343b3337c9 /vm_core.h
parent055a465ac4222f314917c1d682fbd9d0d73535af (diff)
downloadruby-fbebd502f9f374d1eef31c63c10c7d8adcd63280.tar.gz
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument. [Feature #10440] (Details are described in this ticket) Most of complex part is moved to vm_args.c. Now, ISeq#to_a does not catch up new instruction format. * vm_core.h: change iseq data structures. * introduce rb_call_info_kw_arg_t to represent keyword arguments. * add rb_call_info_t::kw_arg. * rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num. * rename rb_iseq_t::arg_keywords to arg_keyword_num. * rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits. to represent keyword bitmap parameter index. This bitmap parameter shows that which keyword parameters are given or not given (0 for given). It is refered by `checkkeyword' instruction described bellow. * rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest to represent keyword rest parameter index. * add rb_iseq_t::arg_keyword_default_values to represent default keyword values. * rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE to represent (ci->flag & (SPLAT|BLOCKARG)) && ci->blockiseq == NULL && ci->kw_arg == NULL. * vm_insnhelper.c, vm_args.c: rewrite with refactoring. * rewrite splat argument code. * rewrite keyword arguments/parameters code. * merge method and block parameter fitting code into one code base. * vm.c, vm_eval.c: catch up these changes. * compile.c (new_callinfo): callinfo requires kw_arg parameter. * compile.c (compile_array_): check the last argument Hash object or not. If Hash object and all keys are Symbol literals, they are compiled to keyword arguments. * insns.def (checkkeyword): add new instruction. This instruction check the availability of corresponding keyword. For example, a method "def foo k1: 'v1'; end" is cimpiled to the following instructions. 0000 checkkeyword 2, 0 # check k1 is given. 0003 branchif 9 # if given, jump to address #9 0005 putstring "v1" 0007 setlocal_OP__WC__0 3 # k1 = 'v1' 0009 trace 8 0011 putnil 0012 trace 16 0014 leave * insns.def (opt_send_simple): removed and add new instruction "opt_send_without_block". * parse.y (new_args_tail_gen): reorder variables. Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)" has parameter variables "k1, kr1, k2, &b, internal_id, krest", but this patch reorders to "kr1, k1, k2, internal_id, krest, &b". (locate a block variable at last) * parse.y (vtable_pop): added. This function remove latest `n' variables from vtable. * iseq.c: catch up iseq data changes. * proc.c: ditto. * class.c (keyword_error): export as rb_keyword_error(). * common.mk: depend vm_args.c for vm.o. * hash.c (rb_hash_has_key): export. * internal.h: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_core.h')
-rw-r--r--vm_core.h46
1 files changed, 27 insertions, 19 deletions
diff --git a/vm_core.h b/vm_core.h
index 6dd66ff6b8..f8494d07e6 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -135,13 +135,20 @@ union iseq_inline_storage_entry {
struct rb_thread_struct;
struct rb_control_frame_struct;
+typedef struct rb_call_info_kw_arg_struct {
+ int keyword_len;
+ ID keywords[1];
+} rb_call_info_kw_arg_t;
+
/* rb_call_info_t contains calling information including inline cache */
typedef struct rb_call_info_struct {
/* fixed at compile time */
ID mid;
+
unsigned int flag;
int orig_argc;
rb_iseq_t *blockiseq;
+ rb_call_info_kw_arg_t *kw_arg;
/* inline cache: keys */
rb_serial_t method_state;
@@ -240,23 +247,23 @@ struct rb_iseq_struct {
* *c, # rest
* d1, d2, ..., dO, # post
* e1:(...), e2:(...), ..., eK:(...), # keyword
- * **f, # keyword rest
+ * **f, # keyword_rest
* &g) # block
* =>
*
- * argc = M // or 0 if no mandatory arg
- * arg_opts = N+1 // or 0 if no optional arg
- * arg_rest = M+N // or -1 if no rest arg
- * arg_opt_table = [ (arg_opts entries) ]
- * arg_post_start = M+N+(*1) // or 0 if no post arguments
- * arg_post_len = O // or 0 if no post arguments
- * arg_keywords = K // or 0 if no keyword arg
- * arg_block = M+N+(*1)+O+K // or -1 if no block arg
- * arg_keyword = M+N+(*1)+O+K+(&1) // or -1 if no keyword arg/rest
- * arg_simple = 0 if not simple arguments.
- * = 1 if no opt, rest, post, block.
- * = 2 if ambiguous block parameter ({|a|}).
- * arg_size = M+N+O+(*1)+K+(&1)+(**1) argument size.
+ * argc = M // or 0 if no mandatory arg
+ * arg_opts = N+1 // or 0 if no optional arg
+ * arg_rest = M+N // or -1 if no rest arg
+ * arg_opt_table = [ (arg_opts entries) ]
+ * arg_post_start = M+N+(*1) // or 0 if no post arguments
+ * arg_post_num = O // or 0 if no post arguments
+ * arg_keyword_num = K // or 0 if no keyword arg
+ * arg_block = M+N+(*1)+O+K // or -1 if no block arg
+ * arg_keyword_bits = M+N+(*1)+O+K+(&1) // or -1 if no keyword arg/rest
+ * arg_simple = 0 if not simple arguments.
+ * = 1 if no opt, rest, post, block.
+ * = 2 if ambiguous block parameter ({|a|}).
+ * arg_size = M+N+O+(*1)+K+(&1)+(**1) argument size.
*/
int argc;
@@ -264,15 +271,16 @@ struct rb_iseq_struct {
int arg_rest;
int arg_block;
int arg_opts;
- int arg_post_len;
+ int arg_post_num;
int arg_post_start;
int arg_size;
VALUE *arg_opt_table;
- int arg_keyword;
- int arg_keyword_check; /* if this is true, raise an ArgumentError when unknown keyword argument is passed */
- int arg_keywords;
+ int arg_keyword_num;
+ int arg_keyword_bits;
+ int arg_keyword_rest;
int arg_keyword_required;
ID *arg_keyword_table;
+ VALUE *arg_keyword_default_values;
/* catch table */
struct iseq_catch_table *catch_table;
@@ -793,7 +801,7 @@ enum vm_check_match_type {
#define VM_CALL_TAILCALL (0x01 << 5) /* located at tail position */
#define VM_CALL_SUPER (0x01 << 6) /* super */
#define VM_CALL_OPT_SEND (0x01 << 7) /* internal flag */
-#define VM_CALL_ARGS_SKIP_SETUP (0x01 << 8) /* (flag & (SPLAT|BLOCKARG)) && blockiseq == 0 */
+#define VM_CALL_ARGS_SIMPLE (0x01 << 8) /* (ci->flag & (SPLAT|BLOCKARG)) && ci->blockiseq == NULL && ci->kw_arg == NULL */
enum vm_special_object_type {
VM_SPECIAL_OBJECT_VMCORE = 1,