2006-12-31 18:02:22 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
compile.c - ruby node tree -> VM instruction sequence
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: 04/01/01 03:42:15 JST
|
|
|
|
|
* blockinlining.c, compile.c, compile.h, debug.c, debug.h,
id.c, insnhelper.h, insns.def, thread.c, thread_pthread.ci,
thread_pthread.h, thread_win32.ci, thread_win32.h, vm.h,
vm_dump.c, vm_evalbody.ci, vm_opts.h: fix comments and
copyright year.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-14 01:13:04 +03:00
|
|
|
Copyright (C) 2004-2007 Koichi Sasada
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
* internal.h: declare internal functions here.
* node.h: declare NODE dependent internal functions here.
* iseq.h: declare rb_iseq_t dependent internal functions here.
* vm_core.h: declare rb_thread_t dependent internal functions here.
* bignum.c, class.c, compile.c, complex.c, cont.c, dir.c, encoding.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c, io.c,
iseq.c, load.c, marshal.c, math.c, numeric.c, object.c, parse.y,
proc.c, process.c, range.c, rational.c, re.c, ruby.c, string.c,
thread.c, time.c, transcode.c, variable.c, vm.c,
tool/compile_prelude.rb: don't declare internal functions declared
in above headers. include above headers if required.
Note that rb_thread_mark() was declared as
void rb_thread_mark(rb_thread_t *th) in cont.c but defined as
void rb_thread_mark(void *ptr) in vm.c. Now it is declared as
the later in internal.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 02:43:38 +04:00
|
|
|
#include "internal.h"
|
2015-12-08 16:58:50 +03:00
|
|
|
#include "ruby/re.h"
|
|
|
|
#include "encindex.h"
|
2010-09-10 09:03:40 +04:00
|
|
|
#include <math.h>
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-08-23 10:48:28 +04:00
|
|
|
#define USE_INSN_STACK_INCREASE 1
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
#include "vm_core.h"
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#include "iseq.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
#include "insns.inc"
|
|
|
|
#include "insns_info.inc"
|
2016-05-14 21:43:11 +03:00
|
|
|
#include "id_table.h"
|
2015-12-08 16:58:50 +03:00
|
|
|
#include "gc.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-12-16 04:14:27 +03:00
|
|
|
#ifdef HAVE_DLADDR
|
|
|
|
# include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2015-11-22 09:32:38 +03:00
|
|
|
#undef RUBY_UNTYPED_DATA_WARNING
|
|
|
|
#define RUBY_UNTYPED_DATA_WARNING 0
|
|
|
|
|
2009-09-05 09:34:56 +04:00
|
|
|
#define FIXNUM_INC(n, i) ((n)+(INT2FIX(i)&~FIXNUM_FLAG))
|
2009-09-05 09:37:11 +04:00
|
|
|
#define FIXNUM_OR(n, i) ((n)|INT2FIX(i))
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
typedef struct iseq_link_element {
|
2008-04-20 09:58:59 +04:00
|
|
|
enum {
|
2010-10-31 04:42:54 +03:00
|
|
|
ISEQ_ELEMENT_NONE,
|
|
|
|
ISEQ_ELEMENT_LABEL,
|
|
|
|
ISEQ_ELEMENT_INSN,
|
2010-12-10 05:42:06 +03:00
|
|
|
ISEQ_ELEMENT_ADJUST
|
2008-04-20 09:58:59 +04:00
|
|
|
} type;
|
2006-12-31 18:02:22 +03:00
|
|
|
struct iseq_link_element *next;
|
|
|
|
struct iseq_link_element *prev;
|
|
|
|
} LINK_ELEMENT;
|
|
|
|
|
|
|
|
typedef struct iseq_link_anchor {
|
|
|
|
LINK_ELEMENT anchor;
|
|
|
|
LINK_ELEMENT *last;
|
|
|
|
} LINK_ANCHOR;
|
|
|
|
|
2016-04-11 11:43:06 +03:00
|
|
|
typedef enum {
|
|
|
|
LABEL_RESCUE_NONE,
|
|
|
|
LABEL_RESCUE_BEG,
|
|
|
|
LABEL_RESCUE_END,
|
|
|
|
LABEL_RESCUE_TYPE_MAX
|
|
|
|
} LABEL_RESCUE_TYPE;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
typedef struct iseq_label_data {
|
|
|
|
LINK_ELEMENT link;
|
|
|
|
int label_no;
|
|
|
|
int position;
|
|
|
|
int sc_state;
|
|
|
|
int sp;
|
2015-11-14 09:26:15 +03:00
|
|
|
int refcnt;
|
2016-03-17 08:47:44 +03:00
|
|
|
unsigned int set: 1;
|
2016-04-11 11:43:06 +03:00
|
|
|
unsigned int rescued: 2;
|
2006-12-31 18:02:22 +03:00
|
|
|
} LABEL;
|
|
|
|
|
|
|
|
typedef struct iseq_insn_data {
|
|
|
|
LINK_ELEMENT link;
|
2008-04-20 09:58:59 +04:00
|
|
|
enum ruby_vminsn_type insn_id;
|
2011-08-24 10:31:15 +04:00
|
|
|
unsigned int line_no;
|
2006-12-31 18:02:22 +03:00
|
|
|
int operand_size;
|
|
|
|
int sc_state;
|
|
|
|
VALUE *operands;
|
|
|
|
} INSN;
|
|
|
|
|
2008-01-25 21:02:01 +03:00
|
|
|
typedef struct iseq_adjust_data {
|
|
|
|
LINK_ELEMENT link;
|
|
|
|
LABEL *label;
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
int line_no;
|
2008-01-25 21:02:01 +03:00
|
|
|
} ADJUST;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
struct ensure_range {
|
|
|
|
LABEL *begin;
|
|
|
|
LABEL *end;
|
|
|
|
struct ensure_range *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct iseq_compile_data_ensure_node_stack {
|
|
|
|
NODE *ensure_node;
|
|
|
|
struct iseq_compile_data_ensure_node_stack *prev;
|
|
|
|
struct ensure_range *erange;
|
|
|
|
};
|
|
|
|
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
/**
|
|
|
|
* debug function(macro) interface depend on CPDEBUG
|
|
|
|
* if it is less than 0, runtime option is in effect.
|
|
|
|
*
|
|
|
|
* debug level:
|
|
|
|
* 0: no debug output
|
|
|
|
* 1: show node type
|
|
|
|
* 2: show node important parameters
|
|
|
|
* ...
|
|
|
|
* 5: show other parameters
|
|
|
|
* 10: show every AST array
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CPDEBUG
|
|
|
|
#define CPDEBUG 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CPDEBUG >= 0
|
|
|
|
#define compile_debug CPDEBUG
|
|
|
|
#else
|
2015-12-02 10:52:12 +03:00
|
|
|
#define compile_debug ISEQ_COMPILE_DATA(iseq)->option->debug_level
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CPDEBUG
|
|
|
|
|
|
|
|
#define compile_debug_print_indent(level) \
|
2010-12-03 00:53:08 +03:00
|
|
|
ruby_debug_print_indent((level), compile_debug, gl_node_level * 2)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define debugp(header, value) (void) \
|
|
|
|
(compile_debug_print_indent(1) && \
|
2010-12-03 00:53:08 +03:00
|
|
|
ruby_debug_print_value(1, compile_debug, (header), (value)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define debugi(header, id) (void) \
|
|
|
|
(compile_debug_print_indent(1) && \
|
2010-12-03 00:53:08 +03:00
|
|
|
ruby_debug_print_id(1, compile_debug, (header), (id)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define debugp_param(header, value) (void) \
|
|
|
|
(compile_debug_print_indent(1) && \
|
2010-12-03 00:53:08 +03:00
|
|
|
ruby_debug_print_value(1, compile_debug, (header), (value)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define debugp_verbose(header, value) (void) \
|
|
|
|
(compile_debug_print_indent(2) && \
|
2010-12-03 00:53:08 +03:00
|
|
|
ruby_debug_print_value(2, compile_debug, (header), (value)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define debugp_verbose_node(header, value) (void) \
|
|
|
|
(compile_debug_print_indent(10) && \
|
2010-12-03 00:53:08 +03:00
|
|
|
ruby_debug_print_value(10, compile_debug, (header), (value)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define debug_node_start(node) ((void) \
|
|
|
|
(compile_debug_print_indent(1) && \
|
2010-12-03 00:53:08 +03:00
|
|
|
(ruby_debug_print_node(1, CPDEBUG, "", (NODE *)(node)), gl_node_level)), \
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
gl_node_level++)
|
|
|
|
|
2012-11-21 16:42:11 +04:00
|
|
|
#define debug_node_end() gl_node_level --
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static inline ID
|
|
|
|
r_id(ID id)
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
r_value(VALUE value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define debugi(header, id) r_id(id)
|
|
|
|
#define debugp(header, value) r_value(value)
|
|
|
|
#define debugp_verbose(header, value) r_value(value)
|
|
|
|
#define debugp_verbose_node(header, value) r_value(value)
|
|
|
|
#define debugp_param(header, value) r_value(value)
|
|
|
|
#define debug_node_start(node) ((void)0)
|
|
|
|
#define debug_node_end() ((void)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CPDEBUG > 1 || CPDEBUG < 0
|
2015-02-27 10:23:23 +03:00
|
|
|
#define printf ruby_debug_printf
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#define debugs if (compile_debug_print_indent(1)) ruby_debug_printf
|
2010-12-03 00:53:08 +03:00
|
|
|
#define debug_compile(msg, v) ((void)(compile_debug_print_indent(1) && fputs((msg), stderr)), (v))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#else
|
|
|
|
#define debugs if(0)printf
|
|
|
|
#define debug_compile(msg, v) (v)
|
|
|
|
#endif
|
|
|
|
|
2016-07-28 14:02:30 +03:00
|
|
|
#define LVAR_ERRINFO (1)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
/* create new label */
|
2010-12-03 00:53:08 +03:00
|
|
|
#define NEW_LABEL(l) new_label_body(iseq, (l))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
#define iseq_path(iseq) ((iseq)->body->location.path)
|
|
|
|
#define iseq_absolute_path(iseq) ((iseq)->body->location.absolute_path)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
#define NEW_ISEQ(node, name, type, line_no) \
|
2013-11-27 03:30:25 +04:00
|
|
|
new_child_iseq(iseq, (node), rb_fstring(name), 0, (type), (line_no))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
#define NEW_CHILD_ISEQ(node, name, type, line_no) \
|
|
|
|
new_child_iseq(iseq, (node), rb_fstring(name), iseq, (type), (line_no))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
/* add instructions */
|
|
|
|
#define ADD_SEQ(seq1, seq2) \
|
2010-12-03 00:53:08 +03:00
|
|
|
APPEND_LIST((seq1), (seq2))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
/* add an instruction */
|
|
|
|
#define ADD_INSN(seq, line, insn) \
|
2010-12-03 00:53:08 +03:00
|
|
|
ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (line), BIN(insn), 0))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2016-01-10 14:57:51 +03:00
|
|
|
/* insert an instruction before prev */
|
|
|
|
#define INSERT_BEFORE_INSN(prev, line, insn) \
|
|
|
|
INSERT_ELEM_PREV(&(prev)->link, (LINK_ELEMENT *) new_insn_body(iseq, (line), BIN(insn), 0))
|
|
|
|
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
/* add an instruction with some operands (1, 2, 3, 5) */
|
|
|
|
#define ADD_INSN1(seq, line, insn, op1) \
|
2010-12-03 00:53:08 +03:00
|
|
|
ADD_ELEM((seq), (LINK_ELEMENT *) \
|
|
|
|
new_insn_body(iseq, (line), BIN(insn), 1, (VALUE)(op1)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2016-01-10 14:57:51 +03:00
|
|
|
/* insert an instruction with some operands (1, 2, 3, 5) before prev */
|
|
|
|
#define INSERT_BEFORE_INSN1(prev, line, insn, op1) \
|
|
|
|
INSERT_ELEM_PREV(&(prev)->link, (LINK_ELEMENT *) \
|
|
|
|
new_insn_body(iseq, (line), BIN(insn), 1, (VALUE)(op1)))
|
|
|
|
|
2015-11-14 09:26:15 +03:00
|
|
|
#define LABEL_REF(label) ((label)->refcnt++)
|
|
|
|
|
2012-08-08 12:12:24 +04:00
|
|
|
/* add an instruction with label operand (alias of ADD_INSN1) */
|
2015-11-14 09:26:15 +03:00
|
|
|
#define ADD_INSNL(seq, line, insn, label) (ADD_INSN1(seq, line, insn, label), LABEL_REF(label))
|
2012-08-08 12:12:24 +04:00
|
|
|
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#define ADD_INSN2(seq, line, insn, op1, op2) \
|
2010-12-03 00:53:08 +03:00
|
|
|
ADD_ELEM((seq), (LINK_ELEMENT *) \
|
|
|
|
new_insn_body(iseq, (line), BIN(insn), 2, (VALUE)(op1), (VALUE)(op2)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define ADD_INSN3(seq, line, insn, op1, op2, op3) \
|
2010-12-03 00:53:08 +03:00
|
|
|
ADD_ELEM((seq), (LINK_ELEMENT *) \
|
|
|
|
new_insn_body(iseq, (line), BIN(insn), 3, (VALUE)(op1), (VALUE)(op2), (VALUE)(op3)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
/* Specific Insn factory */
|
|
|
|
#define ADD_SEND(seq, line, id, argc) \
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_SEND_R((seq), (line), (id), (argc), NULL, (VALUE)INT2FIX(0), NULL)
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
|
|
|
|
#define ADD_SEND_WITH_FLAG(seq, line, id, argc, flag) \
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_SEND_R((seq), (line), (id), (argc), NULL, (VALUE)(flag), NULL)
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
|
|
|
|
#define ADD_SEND_WITH_BLOCK(seq, line, id, argc, block) \
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_SEND_R((seq), (line), (id), (argc), (block), (VALUE)INT2FIX(0), NULL)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define ADD_CALL_RECEIVER(seq, line) \
|
2012-02-26 06:26:49 +04:00
|
|
|
ADD_INSN((seq), (line), putself)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define ADD_CALL(seq, line, id, argc) \
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_SEND_R((seq), (line), (id), (argc), NULL, (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define ADD_CALL_WITH_BLOCK(seq, line, id, argc, block) \
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_SEND_R((seq), (line), (id), (argc), (block), (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
#define ADD_SEND_R(seq, line, id, argc, block, flag, keywords) \
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_send(iseq, (line), (id), (VALUE)(argc), (block), (VALUE)(flag), (keywords)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define ADD_TRACE(seq, line, event) \
|
|
|
|
do { \
|
2015-12-02 11:05:36 +03:00
|
|
|
if ((event) == RUBY_EVENT_LINE && ISEQ_COVERAGE(iseq) && \
|
2016-06-27 02:56:57 +03:00
|
|
|
(line) > 0 && \
|
2015-12-02 10:52:12 +03:00
|
|
|
(line) != ISEQ_COMPILE_DATA(iseq)->last_coverable_line) { \
|
2015-12-02 11:05:36 +03:00
|
|
|
RARRAY_ASET(ISEQ_COVERAGE(iseq), (line) - 1, INT2FIX(0)); \
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->last_coverable_line = (line); \
|
2010-12-03 00:53:08 +03:00
|
|
|
ADD_INSN1((seq), (line), trace, INT2FIX(RUBY_EVENT_COVERAGE)); \
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
} \
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->trace_instruction) { \
|
2010-12-03 00:53:08 +03:00
|
|
|
ADD_INSN1((seq), (line), trace, INT2FIX(event)); \
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
} \
|
2012-12-29 16:21:58 +04:00
|
|
|
} while (0)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2016-07-28 14:02:30 +03:00
|
|
|
#define ADD_GETLOCAL(seq, line, idx, level) \
|
|
|
|
do { \
|
|
|
|
ADD_INSN2((seq), (line), getlocal, INT2FIX((idx) + VM_ENV_DATA_SIZE - 1), INT2FIX(level)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ADD_SETLOCAL(seq, line, idx, level) \
|
|
|
|
do { \
|
|
|
|
ADD_INSN2((seq), (line), setlocal, INT2FIX((idx) + VM_ENV_DATA_SIZE - 1), INT2FIX(level)); \
|
|
|
|
} while (0)
|
|
|
|
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
/* add label */
|
|
|
|
#define ADD_LABEL(seq, label) \
|
2010-12-03 00:53:08 +03:00
|
|
|
ADD_ELEM((seq), (LINK_ELEMENT *) (label))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2012-02-11 07:04:23 +04:00
|
|
|
#define APPEND_LABEL(seq, before, label) \
|
|
|
|
APPEND_ELEM((seq), (before), (LINK_ELEMENT *) (label))
|
|
|
|
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#define ADD_ADJUST(seq, line, label) \
|
2010-12-03 00:53:08 +03:00
|
|
|
ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), (line)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define ADD_ADJUST_RESTORE(seq, label) \
|
2010-12-03 00:53:08 +03:00
|
|
|
ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), -1))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
#define ADD_CATCH_ENTRY(type, ls, le, iseqv, lc) do { \
|
|
|
|
VALUE _e = rb_ary_new3(5, (type), \
|
|
|
|
(VALUE)(ls) | 1, (VALUE)(le) | 1, \
|
|
|
|
(VALUE)(iseqv), (VALUE)(lc) | 1); \
|
2015-11-14 09:26:15 +03:00
|
|
|
if (ls) LABEL_REF(ls); \
|
|
|
|
if (le) LABEL_REF(le); \
|
|
|
|
if (lc) LABEL_REF(lc); \
|
2015-12-02 10:52:12 +03:00
|
|
|
rb_ary_push(ISEQ_COMPILE_DATA(iseq)->catch_table_ary, freeze_hide_obj(_e)); \
|
2015-07-22 01:52:59 +03:00
|
|
|
} while (0)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
/* compile node */
|
|
|
|
#define COMPILE(anchor, desc, node) \
|
|
|
|
(debug_compile("== " desc "\n", \
|
2010-12-03 00:53:08 +03:00
|
|
|
iseq_compile_each(iseq, (anchor), (node), 0)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2009-11-03 20:46:28 +03:00
|
|
|
/* compile node, this node's value will be popped */
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#define COMPILE_POPED(anchor, desc, node) \
|
|
|
|
(debug_compile("== " desc "\n", \
|
2010-12-03 00:53:08 +03:00
|
|
|
iseq_compile_each(iseq, (anchor), (node), 1)))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2009-11-03 20:46:28 +03:00
|
|
|
/* compile node, which is popped when 'poped' is true */
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#define COMPILE_(anchor, desc, node, poped) \
|
|
|
|
(debug_compile("== " desc "\n", \
|
2010-12-03 00:53:08 +03:00
|
|
|
iseq_compile_each(iseq, (anchor), (node), (poped))))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2014-06-06 12:07:13 +04:00
|
|
|
#define COMPILE_RECV(anchor, desc, node) \
|
|
|
|
(private_recv_p(node) ? \
|
|
|
|
(ADD_INSN(anchor, nd_line(node), putself), VM_CALL_FCALL) : \
|
|
|
|
(COMPILE(anchor, desc, node->nd_recv), 0))
|
|
|
|
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#define OPERAND_AT(insn, idx) \
|
2010-12-03 00:53:08 +03:00
|
|
|
(((INSN*)(insn))->operands[(idx)])
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define INSN_OF(insn) \
|
|
|
|
(((INSN*)(insn))->insn_id)
|
|
|
|
|
2016-04-23 14:39:41 +03:00
|
|
|
#define IS_INSN(link) ((link)->type == ISEQ_ELEMENT_INSN)
|
|
|
|
#define IS_LABEL(link) ((link)->type == ISEQ_ELEMENT_LABEL)
|
|
|
|
#define IS_ADJUST(link) ((link)->type == ISEQ_ELEMENT_ADJUST)
|
2016-04-23 14:43:52 +03:00
|
|
|
#define IS_INSN_ID(iobj, insn) (INSN_OF(iobj) == BIN(insn))
|
2016-04-23 14:39:41 +03:00
|
|
|
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
/* error */
|
2016-04-19 07:46:20 +03:00
|
|
|
typedef void (*compile_error_func)(rb_iseq_t *, int, const char *, ...);
|
2015-12-04 20:26:38 +03:00
|
|
|
|
|
|
|
static void
|
2016-04-19 07:46:20 +03:00
|
|
|
append_compile_error(rb_iseq_t *iseq, int line, const char *fmt, ...)
|
2015-12-04 20:26:38 +03:00
|
|
|
{
|
2016-04-19 07:46:20 +03:00
|
|
|
VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info;
|
|
|
|
VALUE file = iseq->body->location.path;
|
2016-04-20 05:52:07 +03:00
|
|
|
VALUE err = err_info;
|
2015-12-04 20:26:38 +03:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2016-04-20 05:52:07 +03:00
|
|
|
err = rb_syntax_error_append(err, file, line, -1, NULL, fmt, args);
|
2015-12-04 20:26:38 +03:00
|
|
|
va_end(args);
|
2016-04-20 05:52:07 +03:00
|
|
|
if (NIL_P(err_info)) {
|
|
|
|
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err);
|
|
|
|
rb_set_errinfo(err);
|
|
|
|
}
|
2015-12-04 20:26:38 +03:00
|
|
|
}
|
|
|
|
|
2016-04-19 07:46:20 +03:00
|
|
|
static void
|
|
|
|
compile_bug(rb_iseq_t *iseq, int line, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
rb_report_bug_valist(iseq->body->location.path, line, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2015-12-04 20:26:38 +03:00
|
|
|
NOINLINE(static compile_error_func prepare_compile_error(rb_iseq_t *iseq));
|
|
|
|
|
|
|
|
static compile_error_func
|
|
|
|
prepare_compile_error(rb_iseq_t *iseq)
|
|
|
|
{
|
2016-04-19 07:46:20 +03:00
|
|
|
if (compile_debug) return &compile_bug;
|
2016-03-26 04:34:35 +03:00
|
|
|
return &append_compile_error;
|
2015-12-04 20:26:38 +03:00
|
|
|
}
|
|
|
|
|
2015-12-04 20:28:26 +03:00
|
|
|
#define COMPILE_ERROR prepare_compile_error(iseq)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2016-04-19 07:46:20 +03:00
|
|
|
#define ERROR_ARGS_AT(n) iseq, nd_line(n),
|
2015-11-22 09:32:32 +03:00
|
|
|
#define ERROR_ARGS ERROR_ARGS_AT(node)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2015-12-01 08:55:26 +03:00
|
|
|
#define EXPECT_NODE(prefix, node, ndtype) \
|
|
|
|
do { \
|
|
|
|
NODE *error_node = (node); \
|
|
|
|
enum node_type error_type = nd_type(error_node); \
|
|
|
|
if (error_type != (ndtype)) { \
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS_AT(error_node) \
|
|
|
|
prefix ": " #ndtype " is expected, but %s", \
|
|
|
|
ruby_node_name(error_type)); \
|
2015-12-01 08:55:26 +03:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define EXPECT_NODE_NONULL(prefix, parent, ndtype) \
|
|
|
|
do { \
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS_AT(parent) \
|
|
|
|
prefix ": must be " #ndtype ", but 0"); \
|
2015-12-01 08:55:26 +03:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define UNKNOWN_NODE(prefix, node) \
|
|
|
|
do { \
|
|
|
|
NODE *error_node = (node); \
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS_AT(error_node) prefix ": unknown node (%s)", \
|
|
|
|
ruby_node_name(nd_type(error_node))); \
|
2015-12-01 08:55:26 +03:00
|
|
|
} while (0)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
#define COMPILE_OK 1
|
|
|
|
#define COMPILE_NG 0
|
|
|
|
|
|
|
|
|
|
|
|
/* leave name uninitialized so that compiler warn if INIT_ANCHOR is
|
|
|
|
* missing */
|
|
|
|
#define DECL_ANCHOR(name) \
|
|
|
|
LINK_ANCHOR *name, name##_body__ = {{0,},}
|
|
|
|
#define INIT_ANCHOR(name) \
|
|
|
|
(name##_body__.last = &name##_body__.anchor, name = &name##_body__)
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
static inline VALUE
|
|
|
|
freeze_hide_obj(VALUE obj)
|
|
|
|
{
|
|
|
|
OBJ_FREEZE(obj);
|
|
|
|
RBASIC_CLEAR_CLASS(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
#include "optinsn.inc"
|
|
|
|
#if OPT_INSTRUCTIONS_UNIFICATION
|
|
|
|
#include "optunifs.inc"
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/* for debug */
|
2008-04-14 09:34:04 +04:00
|
|
|
#if CPDEBUG < 0
|
|
|
|
#define ISEQ_ARG iseq,
|
|
|
|
#define ISEQ_ARG_DECLARE rb_iseq_t *iseq,
|
|
|
|
#else
|
|
|
|
#define ISEQ_ARG
|
|
|
|
#define ISEQ_ARG_DECLARE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CPDEBUG
|
2015-12-02 10:52:12 +03:00
|
|
|
#define gl_node_level ISEQ_COMPILE_DATA(iseq)->node_level
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void dump_disasm_list(LINK_ELEMENT *elem);
|
|
|
|
|
|
|
|
static int insn_data_length(INSN *iobj);
|
|
|
|
static int calc_sp_depth(int depth, INSN *iobj);
|
|
|
|
|
2014-06-08 18:46:43 +04:00
|
|
|
static INSN *new_insn_body(rb_iseq_t *iseq, int line_no, enum ruby_vminsn_type insn_id, int argc, ...);
|
2009-05-17 09:27:32 +04:00
|
|
|
static LABEL *new_label_body(rb_iseq_t *iseq, long line);
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
static ADJUST *new_adjust_body(rb_iseq_t *iseq, LABEL *label, int line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
static int iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *anchor, NODE * n, int);
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
static int iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *anchor);
|
|
|
|
static int iseq_optimize(rb_iseq_t *iseq, LINK_ANCHOR *anchor);
|
|
|
|
static int iseq_insns_unification(rb_iseq_t *iseq, LINK_ANCHOR *anchor);
|
|
|
|
|
2014-12-17 05:57:53 +03:00
|
|
|
static int iseq_set_local_table(rb_iseq_t *iseq, const ID *tbl);
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
static int iseq_set_exception_local_table(rb_iseq_t *iseq);
|
|
|
|
static int iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *anchor, NODE * node);
|
|
|
|
|
|
|
|
static int iseq_set_sequence_stackcaching(rb_iseq_t *iseq, LINK_ANCHOR *anchor);
|
|
|
|
static int iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor);
|
|
|
|
static int iseq_set_exception_table(rb_iseq_t *iseq);
|
|
|
|
static int iseq_set_optargs_table(rb_iseq_t *iseq);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-04-14 09:34:04 +04:00
|
|
|
/*
|
|
|
|
* To make Array to LinkedList, use link_anchor
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2008-05-31 13:28:20 +04:00
|
|
|
verify_list(ISEQ_ARG_DECLARE const char *info, LINK_ANCHOR *anchor)
|
2008-04-14 09:34:04 +04:00
|
|
|
{
|
|
|
|
#if CPDEBUG
|
|
|
|
int flag = 0;
|
|
|
|
LINK_ELEMENT *list, *plist;
|
|
|
|
|
|
|
|
if (!compile_debug) return;
|
|
|
|
|
|
|
|
list = anchor->anchor.next;
|
|
|
|
plist = &anchor->anchor;
|
|
|
|
while (list) {
|
|
|
|
if (plist != list->prev) {
|
|
|
|
flag += 1;
|
|
|
|
}
|
|
|
|
plist = list;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anchor->last != plist && anchor->last != 0) {
|
|
|
|
flag |= 0x70000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag != 0) {
|
|
|
|
rb_bug("list verify error: %08x (%s)", flag, info);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if CPDEBUG < 0
|
2010-12-03 00:53:08 +03:00
|
|
|
#define verify_list(info, anchor) verify_list(iseq, (info), (anchor))
|
2008-04-14 09:34:04 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* elem1, elem2 => elem1, elem2, elem
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ADD_ELEM(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor, LINK_ELEMENT *elem)
|
|
|
|
{
|
|
|
|
elem->prev = anchor->last;
|
|
|
|
anchor->last->next = elem;
|
|
|
|
anchor->last = elem;
|
|
|
|
verify_list("add", anchor);
|
|
|
|
}
|
2012-02-11 07:04:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* elem1, before, elem2 => elem1, before, elem, elem2
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
APPEND_ELEM(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor, LINK_ELEMENT *before, LINK_ELEMENT *elem)
|
|
|
|
{
|
|
|
|
elem->prev = before;
|
|
|
|
elem->next = before->next;
|
|
|
|
elem->next->prev = elem;
|
|
|
|
before->next = elem;
|
|
|
|
if (before == anchor->last) anchor->last = elem;
|
|
|
|
verify_list("add", anchor);
|
|
|
|
}
|
2008-04-14 09:34:04 +04:00
|
|
|
#if CPDEBUG < 0
|
2010-12-03 00:53:08 +03:00
|
|
|
#define ADD_ELEM(anchor, elem) ADD_ELEM(iseq, (anchor), (elem))
|
2015-02-27 10:02:04 +03:00
|
|
|
#define APPEND_ELEM(anchor, before, elem) APPEND_ELEM(iseq, (anchor), (before), (elem))
|
2008-04-14 09:34:04 +04:00
|
|
|
#endif
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2015-07-21 13:47:45 +03:00
|
|
|
iseq_add_mark_object(const rb_iseq_t *iseq, VALUE v)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-07-01 22:16:02 +04:00
|
|
|
if (!SPECIAL_CONST_P(v)) {
|
2013-04-17 15:20:23 +04:00
|
|
|
rb_iseq_add_mark_object(iseq, v);
|
2007-07-01 22:16:02 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
#define ruby_sourcefile RSTRING_PTR(iseq->body->location.path)
|
* eval.c (ruby_exec_node, ruby_run_node), ruby.c (process_options):
use iseq instead of NODE.
* gc.c (source_filenames): removed.
* include/ruby/intern.h, parse.y (yycompile, parser_mark, parser_free,
ripper_initialize): rb_source_filename() is no longer used.
* compile.c, compile.h (ERROR_ARGS), parse.y (node_newnode, fixpos,
parser_warn, e_option_supplied, warn_unless_e_option, range_op,
cond0): nd_file is no longer used.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-12 07:41:51 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2015-07-21 13:47:45 +03:00
|
|
|
iseq_add_mark_object_compile_time(const rb_iseq_t *iseq, VALUE v)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-07-01 22:16:02 +04:00
|
|
|
if (!SPECIAL_CONST_P(v)) {
|
2015-12-02 10:52:12 +03:00
|
|
|
rb_ary_push(ISEQ_COMPILE_DATA(iseq)->mark_ary, v);
|
2007-07-01 22:16:02 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-12 17:45:30 +03:00
|
|
|
static int
|
|
|
|
validate_label(st_data_t name, st_data_t label, st_data_t arg)
|
|
|
|
{
|
|
|
|
rb_iseq_t *iseq = (rb_iseq_t *)arg;
|
|
|
|
LABEL *lobj = (LABEL *)label;
|
|
|
|
if (!lobj->link.next) {
|
|
|
|
do {
|
2016-04-19 07:46:20 +03:00
|
|
|
COMPILE_ERROR(iseq, lobj->position,
|
2015-12-04 20:28:26 +03:00
|
|
|
"%"PRIsVALUE": undefined label",
|
|
|
|
rb_id2str((ID)name));
|
2010-12-12 17:45:30 +03:00
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
validate_labels(rb_iseq_t *iseq, st_table *labels_table)
|
|
|
|
{
|
|
|
|
st_foreach(labels_table, validate_label, (st_data_t)iseq);
|
2015-11-22 09:32:38 +03:00
|
|
|
st_free_table(labels_table);
|
2015-12-02 10:52:12 +03:00
|
|
|
if (!NIL_P(ISEQ_COMPILE_DATA(iseq)->err_info)) {
|
|
|
|
rb_exc_raise(ISEQ_COMPILE_DATA(iseq)->err_info);
|
2010-12-12 17:45:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE
|
2015-07-22 01:52:59 +03:00
|
|
|
rb_iseq_compile_node(rb_iseq_t *iseq, NODE *node)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
DECL_ANCHOR(ret);
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(ret);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-05-25 19:37:05 +04:00
|
|
|
if (node == 0) {
|
|
|
|
COMPILE(ret, "nil", node);
|
2007-12-24 23:27:10 +03:00
|
|
|
iseq_set_local_table(iseq, 0);
|
2007-05-25 19:37:05 +04:00
|
|
|
}
|
|
|
|
else if (nd_type(node) == NODE_SCOPE) {
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
/* iseq type of top, method, class, block */
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
iseq_set_local_table(iseq, node->nd_tbl);
|
|
|
|
iseq_set_arguments(iseq, ret, node->nd_args);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
switch (iseq->body->type) {
|
2012-11-30 02:28:16 +04:00
|
|
|
case ISEQ_TYPE_BLOCK:
|
|
|
|
{
|
2015-12-02 10:52:12 +03:00
|
|
|
LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0);
|
|
|
|
LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0);
|
2012-11-30 02:28:16 +04:00
|
|
|
|
2016-04-11 11:43:06 +03:00
|
|
|
start->rescued = LABEL_RESCUE_BEG;
|
|
|
|
end->rescued = LABEL_RESCUE_END;
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_TRACE(ret, FIX2INT(iseq->body->location.first_lineno), RUBY_EVENT_B_CALL);
|
2014-06-20 02:09:23 +04:00
|
|
|
ADD_LABEL(ret, start);
|
2012-11-30 02:28:16 +04:00
|
|
|
COMPILE(ret, "block body", node->nd_body);
|
|
|
|
ADD_LABEL(ret, end);
|
2013-06-14 13:54:58 +04:00
|
|
|
ADD_TRACE(ret, nd_line(node), RUBY_EVENT_B_RETURN);
|
2012-11-30 02:28:16 +04:00
|
|
|
|
|
|
|
/* wide range catch handler must put at last */
|
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, 0, start);
|
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, 0, end);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISEQ_TYPE_CLASS:
|
|
|
|
{
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_TRACE(ret, FIX2INT(iseq->body->location.first_lineno), RUBY_EVENT_CLASS);
|
2012-11-30 02:28:16 +04:00
|
|
|
COMPILE(ret, "scoped node", node->nd_body);
|
|
|
|
ADD_TRACE(ret, nd_line(node), RUBY_EVENT_END);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISEQ_TYPE_METHOD:
|
|
|
|
{
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_TRACE(ret, FIX2INT(iseq->body->location.first_lineno), RUBY_EVENT_CALL);
|
2012-11-30 02:28:16 +04:00
|
|
|
COMPILE(ret, "scoped node", node->nd_body);
|
|
|
|
ADD_TRACE(ret, nd_line(node), RUBY_EVENT_RETURN);
|
|
|
|
break;
|
|
|
|
}
|
2007-07-10 11:52:03 +04:00
|
|
|
default: {
|
|
|
|
COMPILE(ret, "scoped node", node->nd_body);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
}
|
2015-03-11 16:31:11 +03:00
|
|
|
else if (RB_TYPE_P((VALUE)node, T_IMEMO)) {
|
|
|
|
const struct vm_ifunc *ifunc = (struct vm_ifunc *)node;
|
2013-08-22 10:50:42 +04:00
|
|
|
/* user callback */
|
2015-03-11 16:31:11 +03:00
|
|
|
(*ifunc->func)(iseq, ret, ifunc->data);
|
2013-08-22 10:50:42 +04:00
|
|
|
}
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
else {
|
2015-07-22 01:52:59 +03:00
|
|
|
switch (iseq->body->type) {
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
case ISEQ_TYPE_METHOD:
|
|
|
|
case ISEQ_TYPE_CLASS:
|
|
|
|
case ISEQ_TYPE_BLOCK:
|
|
|
|
case ISEQ_TYPE_EVAL:
|
2008-12-27 08:58:23 +03:00
|
|
|
case ISEQ_TYPE_MAIN:
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
case ISEQ_TYPE_TOP:
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "compile/should not be reached: %s:%d",
|
|
|
|
__FILE__, __LINE__);
|
2015-11-22 09:32:23 +03:00
|
|
|
return COMPILE_NG;
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
case ISEQ_TYPE_RESCUE:
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
iseq_set_exception_local_table(iseq);
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
COMPILE(ret, "rescue", node);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
break;
|
|
|
|
case ISEQ_TYPE_ENSURE:
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
iseq_set_exception_local_table(iseq);
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
COMPILE_POPED(ret, "ensure", node);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
break;
|
|
|
|
case ISEQ_TYPE_DEFINED_GUARD:
|
2015-09-12 21:47:43 +03:00
|
|
|
iseq_set_exception_local_table(iseq);
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
COMPILE(ret, "defined guard", node);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
break;
|
|
|
|
default:
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS "unknown scope");
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->type == ISEQ_TYPE_RESCUE || iseq->body->type == ISEQ_TYPE_ENSURE) {
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(ret, 0, LVAR_ERRINFO, 0);
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
ADD_INSN1(ret, 0, throw, INT2FIX(0) /* continue throw */ );
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_INSN(ret, ISEQ_COMPILE_DATA(iseq)->last_line, leave);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2010-12-12 17:45:30 +03:00
|
|
|
#if SUPPORT_JOKE
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->labels_table) {
|
|
|
|
st_table *labels_table = ISEQ_COMPILE_DATA(iseq)->labels_table;
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->labels_table = 0;
|
2015-11-22 09:32:38 +03:00
|
|
|
validate_labels(iseq, labels_table);
|
2010-12-12 17:45:30 +03:00
|
|
|
}
|
|
|
|
#endif
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
return iseq_setup(iseq, ret);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-07-02 16:49:35 +04:00
|
|
|
int
|
2009-01-19 04:06:56 +03:00
|
|
|
rb_iseq_translate_threaded_code(rb_iseq_t *iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
* vm.c: add a prefix "rb_" to exposed functions
vm_get_ruby_level_next_cfp(), rb_vm_make_env_object(),
vm_stack_to_heap(), vm_make_proc(), vm_invoke_proc(),
vm_get_sourceline(), vm_cref(), vm_localjump_error(),
vm_make_jump_tag_but_local_jump(), vm_jump_tag_but_local_jump().
This changes may affect only core because most of renamed functions
require a pointer of not-exposed struct such as rb_thread_t or NODE.
In short, they are core functions.
* cont.c, eval.c, eval_intern.h, load.c, proc.c, thread.c,
vm_core.h, vm_dump.c, vm_eval.c, vm_exec.c, vm_insnhelper.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-19 05:38:11 +03:00
|
|
|
const void * const *table = rb_vm_get_insns_address_table();
|
2014-07-26 11:30:26 +04:00
|
|
|
unsigned int i;
|
2015-07-23 12:34:31 +03:00
|
|
|
VALUE *encoded = (VALUE *)iseq->body->iseq_encoded;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
for (i = 0; i < iseq->body->iseq_size; /* */ ) {
|
|
|
|
int insn = (int)iseq->body->iseq_encoded[i];
|
2006-12-31 18:02:22 +03:00
|
|
|
int len = insn_len(insn);
|
2015-07-23 12:34:31 +03:00
|
|
|
encoded[i] = (VALUE)table[insn];
|
2006-12-31 18:02:22 +03:00
|
|
|
i += len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
|
|
|
static int
|
2014-09-10 12:53:56 +04:00
|
|
|
rb_vm_insn_addr2insn(const void *addr) /* cold path */
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
{
|
|
|
|
int insn;
|
|
|
|
const void * const *table = rb_vm_get_insns_address_table();
|
|
|
|
|
|
|
|
for (insn = 0; insn < VM_INSTRUCTION_SIZE; insn++) {
|
2014-09-10 12:53:56 +04:00
|
|
|
if (table[insn] == addr) {
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
return insn;
|
2014-09-10 12:53:56 +04:00
|
|
|
}
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
}
|
2014-09-10 12:53:56 +04:00
|
|
|
rb_bug("rb_vm_insn_addr2insn: invalid insn address: %p", addr);
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
VALUE *
|
2015-07-22 01:52:59 +03:00
|
|
|
rb_iseq_original_iseq(const rb_iseq_t *iseq) /* cold path */
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
{
|
2015-12-02 11:20:35 +03:00
|
|
|
VALUE *original_code;
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
|
2015-12-02 11:20:35 +03:00
|
|
|
if (ISEQ_ORIGINAL_ISEQ(iseq)) return ISEQ_ORIGINAL_ISEQ(iseq);
|
|
|
|
original_code = ISEQ_ORIGINAL_ISEQ_ALLOC(iseq, iseq->body->iseq_size);
|
2015-12-02 16:58:07 +03:00
|
|
|
MEMCPY(original_code, iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size);
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
|
|
|
|
#if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
for (i = 0; i < iseq->body->iseq_size; /* */ ) {
|
2015-12-02 11:20:35 +03:00
|
|
|
const void *addr = (const void *)original_code[i];
|
2014-09-10 12:53:56 +04:00
|
|
|
const int insn = rb_vm_insn_addr2insn(addr);
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
|
2015-12-02 11:20:35 +03:00
|
|
|
original_code[i] = insn;
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
i += insn_len(insn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-12-02 11:20:35 +03:00
|
|
|
return original_code;
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*********************************************/
|
|
|
|
/* definition of data structure for compiler */
|
|
|
|
/*********************************************/
|
|
|
|
|
2014-11-05 17:49:08 +03:00
|
|
|
/*
|
2014-11-05 17:49:04 +03:00
|
|
|
* On 32-bit SPARC, GCC by default generates SPARC V7 code that may require
|
|
|
|
* 8-byte word alignment. On the other hand, Oracle Solaris Studio seems to
|
2015-12-14 05:51:13 +03:00
|
|
|
* generate SPARCV8PLUS code with unaligned memory access instructions.
|
2014-11-05 17:49:04 +03:00
|
|
|
* That is why the STRICT_ALIGNMENT is defined only with GCC.
|
|
|
|
*/
|
|
|
|
#if defined(__sparc) && SIZEOF_VOIDP == 4 && defined(__GNUC__)
|
|
|
|
#define STRICT_ALIGNMENT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef STRICT_ALIGNMENT
|
|
|
|
#if defined(HAVE_TRUE_LONG_LONG) && SIZEOF_LONG_LONG > SIZEOF_VALUE
|
|
|
|
#define ALIGNMENT_SIZE SIZEOF_LONG_LONG
|
|
|
|
#else
|
|
|
|
#define ALIGNMENT_SIZE SIZEOF_VALUE
|
|
|
|
#endif
|
|
|
|
#define PADDING_SIZE_MAX ((size_t)((ALIGNMENT_SIZE) - 1))
|
|
|
|
#define ALIGNMENT_SIZE_MASK PADDING_SIZE_MAX
|
|
|
|
/* Note: ALIGNMENT_SIZE == (2 ** N) is expected. */
|
|
|
|
#else
|
|
|
|
#define PADDING_SIZE_MAX 0
|
|
|
|
#endif /* STRICT_ALIGNMENT */
|
|
|
|
|
|
|
|
#ifdef STRICT_ALIGNMENT
|
|
|
|
/* calculate padding size for aligned memory access */
|
|
|
|
static size_t
|
|
|
|
calc_padding(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
size_t mis;
|
|
|
|
size_t padding = 0;
|
|
|
|
|
|
|
|
mis = (size_t)ptr & ALIGNMENT_SIZE_MASK;
|
|
|
|
if (mis > 0) {
|
|
|
|
padding = ALIGNMENT_SIZE - mis;
|
|
|
|
}
|
2014-11-05 17:49:08 +03:00
|
|
|
/*
|
2014-11-05 17:49:04 +03:00
|
|
|
* On 32-bit sparc or equivalents, when a single VALUE is requested
|
|
|
|
* and padding == sizeof(VALUE), it is clear that no padding is needed.
|
|
|
|
*/
|
|
|
|
#if ALIGNMENT_SIZE > SIZEOF_VALUE
|
|
|
|
if (size == sizeof(VALUE) && padding == sizeof(VALUE)) {
|
|
|
|
padding = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return padding;
|
|
|
|
}
|
|
|
|
#endif /* STRICT_ALIGNMENT */
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static void *
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
compile_data_alloc(rb_iseq_t *iseq, size_t size)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
void *ptr = 0;
|
|
|
|
struct iseq_compile_data_storage *storage =
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->storage_current;
|
2014-11-05 17:49:04 +03:00
|
|
|
#ifdef STRICT_ALIGNMENT
|
|
|
|
size_t padding = calc_padding((void *)&storage->buff[storage->pos], size);
|
|
|
|
#else
|
|
|
|
const size_t padding = 0; /* expected to be optimized by compiler */
|
|
|
|
#endif /* STRICT_ALIGNMENT */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-11-05 17:49:04 +03:00
|
|
|
if (size >= INT_MAX - padding) rb_memerror();
|
|
|
|
if (storage->pos + size + padding > storage->size) {
|
2014-07-26 14:06:49 +04:00
|
|
|
unsigned int alloc_size = storage->size;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-11-05 17:49:04 +03:00
|
|
|
while (alloc_size < size + PADDING_SIZE_MAX) {
|
2014-07-26 14:06:49 +04:00
|
|
|
if (alloc_size >= INT_MAX / 2) rb_memerror();
|
2006-12-31 18:02:22 +03:00
|
|
|
alloc_size *= 2;
|
|
|
|
}
|
|
|
|
storage->next = (void *)ALLOC_N(char, alloc_size +
|
2014-07-26 11:57:44 +04:00
|
|
|
SIZEOF_ISEQ_COMPILE_DATA_STORAGE);
|
2015-12-02 10:52:12 +03:00
|
|
|
storage = ISEQ_COMPILE_DATA(iseq)->storage_current = storage->next;
|
2006-12-31 18:02:22 +03:00
|
|
|
storage->next = 0;
|
|
|
|
storage->pos = 0;
|
|
|
|
storage->size = alloc_size;
|
2014-11-05 17:49:04 +03:00
|
|
|
#ifdef STRICT_ALIGNMENT
|
|
|
|
padding = calc_padding((void *)&storage->buff[storage->pos], size);
|
|
|
|
#endif /* STRICT_ALIGNMENT */
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2014-11-05 17:49:04 +03:00
|
|
|
#ifdef STRICT_ALIGNMENT
|
|
|
|
storage->pos += (int)padding;
|
|
|
|
#endif /* STRICT_ALIGNMENT */
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
ptr = (void *)&storage->buff[storage->pos];
|
2014-07-29 12:22:33 +04:00
|
|
|
storage->pos += (int)size;
|
2006-12-31 18:02:22 +03:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INSN *
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
compile_data_alloc_insn(rb_iseq_t *iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
return (INSN *)compile_data_alloc(iseq, sizeof(INSN));
|
|
|
|
}
|
|
|
|
|
|
|
|
static LABEL *
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
compile_data_alloc_label(rb_iseq_t *iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
return (LABEL *)compile_data_alloc(iseq, sizeof(LABEL));
|
|
|
|
}
|
|
|
|
|
2008-01-25 21:02:01 +03:00
|
|
|
static ADJUST *
|
|
|
|
compile_data_alloc_adjust(rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
return (ADJUST *)compile_data_alloc(iseq, sizeof(ADJUST));
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* elem1, elemX => elem1, elem2, elemX
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
INSERT_ELEM_NEXT(LINK_ELEMENT *elem1, LINK_ELEMENT *elem2)
|
|
|
|
{
|
|
|
|
elem2->next = elem1->next;
|
|
|
|
elem2->prev = elem1;
|
|
|
|
elem1->next = elem2;
|
|
|
|
if (elem2->next) {
|
|
|
|
elem2->next->prev = elem2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-23 04:47:08 +03:00
|
|
|
/*
|
|
|
|
* elem1, elemX => elemX, elem2, elem1
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
INSERT_ELEM_PREV(LINK_ELEMENT *elem1, LINK_ELEMENT *elem2)
|
|
|
|
{
|
|
|
|
elem2->prev = elem1->prev;
|
|
|
|
elem2->next = elem1;
|
|
|
|
elem1->prev = elem2;
|
|
|
|
if (elem2->prev) {
|
|
|
|
elem2->prev->next = elem2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-18 10:07:03 +03:00
|
|
|
#if 0
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* elemX, elem1, elemY => elemX, elem2, elemY
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
REPLACE_ELEM(LINK_ELEMENT *elem1, LINK_ELEMENT *elem2)
|
|
|
|
{
|
|
|
|
elem2->prev = elem1->prev;
|
|
|
|
elem2->next = elem1->next;
|
|
|
|
if (elem1->prev) {
|
|
|
|
elem1->prev->next = elem2;
|
|
|
|
}
|
|
|
|
if (elem1->next) {
|
|
|
|
elem1->next->prev = elem2;
|
|
|
|
}
|
|
|
|
}
|
2016-04-18 10:07:03 +03:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
REMOVE_ELEM(LINK_ELEMENT *elem)
|
|
|
|
{
|
|
|
|
elem->prev->next = elem->next;
|
|
|
|
if (elem->next) {
|
|
|
|
elem->next->prev = elem->prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static LINK_ELEMENT *
|
|
|
|
FIRST_ELEMENT(LINK_ANCHOR *anchor)
|
|
|
|
{
|
|
|
|
return anchor->anchor.next;
|
|
|
|
}
|
|
|
|
|
2015-09-29 10:37:40 +03:00
|
|
|
static LINK_ELEMENT *
|
|
|
|
LAST_ELEMENT(LINK_ANCHOR *anchor)
|
|
|
|
{
|
|
|
|
return anchor->last;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static LINK_ELEMENT *
|
2008-04-14 09:34:04 +04:00
|
|
|
POP_ELEMENT(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
LINK_ELEMENT *elem = anchor->last;
|
|
|
|
anchor->last = anchor->last->prev;
|
|
|
|
anchor->last->next = 0;
|
|
|
|
verify_list("pop", anchor);
|
|
|
|
return elem;
|
|
|
|
}
|
2008-04-14 09:34:04 +04:00
|
|
|
#if CPDEBUG < 0
|
2010-12-03 00:53:08 +03:00
|
|
|
#define POP_ELEMENT(anchor) POP_ELEMENT(iseq, (anchor))
|
2008-04-14 09:34:04 +04:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
LIST_SIZE_ZERO(LINK_ANCHOR *anchor)
|
|
|
|
{
|
|
|
|
if (anchor->anchor.next == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* anc1: e1, e2, e3
|
|
|
|
* anc2: e4, e5
|
|
|
|
*#=>
|
|
|
|
* anc1: e1, e2, e3, e4, e5
|
|
|
|
* anc2: e4, e5 (broken)
|
|
|
|
*/
|
|
|
|
static void
|
2008-04-14 09:34:04 +04:00
|
|
|
APPEND_LIST(ISEQ_ARG_DECLARE LINK_ANCHOR *anc1, LINK_ANCHOR *anc2)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
if (anc2->anchor.next) {
|
|
|
|
anc1->last->next = anc2->anchor.next;
|
|
|
|
anc2->anchor.next->prev = anc1->last;
|
|
|
|
anc1->last = anc2->last;
|
|
|
|
}
|
|
|
|
verify_list("append", anc1);
|
|
|
|
}
|
2008-04-14 09:34:04 +04:00
|
|
|
#if CPDEBUG < 0
|
2010-12-03 00:53:08 +03:00
|
|
|
#define APPEND_LIST(anc1, anc2) APPEND_LIST(iseq, (anc1), (anc2))
|
2008-04-14 09:34:04 +04:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* anc1: e1, e2, e3
|
|
|
|
* anc2: e4, e5
|
|
|
|
*#=>
|
|
|
|
* anc1: e4, e5, e1, e2, e3
|
|
|
|
* anc2: e4, e5 (broken)
|
|
|
|
*/
|
|
|
|
static void
|
2008-04-14 09:34:04 +04:00
|
|
|
INSERT_LIST(ISEQ_ARG_DECLARE LINK_ANCHOR *anc1, LINK_ANCHOR *anc2)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
if (anc2->anchor.next) {
|
|
|
|
LINK_ELEMENT *first = anc1->anchor.next;
|
|
|
|
anc1->anchor.next = anc2->anchor.next;
|
|
|
|
anc1->anchor.next->prev = &anc1->anchor;
|
|
|
|
anc2->last->next = first;
|
|
|
|
if (first) {
|
|
|
|
first->prev = anc2->last;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
anc1->last = anc2->last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
verify_list("append", anc1);
|
|
|
|
}
|
2008-04-14 09:34:04 +04:00
|
|
|
#if CPDEBUG < 0
|
2010-12-03 00:53:08 +03:00
|
|
|
#define INSERT_LIST(anc1, anc2) INSERT_LIST(iseq, (anc1), (anc2))
|
2008-04-14 09:34:04 +04:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-04-14 09:34:04 +04:00
|
|
|
#if CPDEBUG && 0
|
2006-12-31 18:02:22 +03:00
|
|
|
static void
|
2008-04-14 09:34:04 +04:00
|
|
|
debug_list(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
LINK_ELEMENT *list = FIRST_ELEMENT(anchor);
|
|
|
|
printf("----\n");
|
|
|
|
printf("anch: %p, frst: %p, last: %p\n", &anchor->anchor,
|
|
|
|
anchor->anchor.next, anchor->last);
|
|
|
|
while (list) {
|
|
|
|
printf("curr: %p, next: %p, prev: %p, type: %d\n", list, list->next,
|
|
|
|
list->prev, FIX2INT(list->type));
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
printf("----\n");
|
|
|
|
|
|
|
|
dump_disasm_list(anchor->anchor.next);
|
|
|
|
verify_list("debug list", anchor);
|
|
|
|
}
|
2008-04-14 09:34:04 +04:00
|
|
|
#if CPDEBUG < 0
|
2010-12-03 00:53:08 +03:00
|
|
|
#define debug_list(anc) debug_list(iseq, (anc))
|
2008-04-14 09:34:04 +04:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static LABEL *
|
2009-05-17 09:27:32 +04:00
|
|
|
new_label_body(rb_iseq_t *iseq, long line)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
LABEL *labelobj = compile_data_alloc_label(iseq);
|
|
|
|
|
|
|
|
labelobj->link.type = ISEQ_ELEMENT_LABEL;
|
|
|
|
labelobj->link.next = 0;
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
labelobj->label_no = ISEQ_COMPILE_DATA(iseq)->label_no++;
|
2006-12-31 18:02:22 +03:00
|
|
|
labelobj->sc_state = 0;
|
|
|
|
labelobj->sp = -1;
|
2015-11-14 09:26:15 +03:00
|
|
|
labelobj->refcnt = 0;
|
2016-04-12 05:51:20 +03:00
|
|
|
labelobj->set = 0;
|
|
|
|
labelobj->rescued = LABEL_RESCUE_NONE;
|
2006-12-31 18:02:22 +03:00
|
|
|
return labelobj;
|
|
|
|
}
|
|
|
|
|
2008-01-25 21:02:01 +03:00
|
|
|
static ADJUST *
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
new_adjust_body(rb_iseq_t *iseq, LABEL *label, int line)
|
2008-01-25 21:02:01 +03:00
|
|
|
{
|
|
|
|
ADJUST *adjust = compile_data_alloc_adjust(iseq);
|
|
|
|
adjust->link.type = ISEQ_ELEMENT_ADJUST;
|
|
|
|
adjust->link.next = 0;
|
|
|
|
adjust->label = label;
|
|
|
|
adjust->line_no = line;
|
2015-12-29 11:36:22 +03:00
|
|
|
if (label) LABEL_REF(label);
|
2008-01-25 21:02:01 +03:00
|
|
|
return adjust;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static INSN *
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
new_insn_core(rb_iseq_t *iseq, int line_no,
|
2006-12-31 18:02:22 +03:00
|
|
|
int insn_id, int argc, VALUE *argv)
|
|
|
|
{
|
|
|
|
INSN *iobj = compile_data_alloc_insn(iseq);
|
2010-02-24 20:06:15 +03:00
|
|
|
/* printf("insn_id: %d, line: %d\n", insn_id, line_no); */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
iobj->link.type = ISEQ_ELEMENT_INSN;
|
|
|
|
iobj->link.next = 0;
|
|
|
|
iobj->insn_id = insn_id;
|
|
|
|
iobj->line_no = line_no;
|
|
|
|
iobj->operands = argv;
|
|
|
|
iobj->operand_size = argc;
|
|
|
|
iobj->sc_state = 0;
|
|
|
|
return iobj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INSN *
|
2014-06-08 18:46:43 +04:00
|
|
|
new_insn_body(rb_iseq_t *iseq, int line_no, enum ruby_vminsn_type insn_id, int argc, ...)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE *operands = 0;
|
|
|
|
va_list argv;
|
|
|
|
if (argc > 0) {
|
|
|
|
int i;
|
|
|
|
va_init_list(argv, argc);
|
|
|
|
operands = (VALUE *)compile_data_alloc(iseq, sizeof(VALUE) * argc);
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
VALUE v = va_arg(argv, VALUE);
|
|
|
|
operands[i] = v;
|
|
|
|
}
|
|
|
|
va_end(argv);
|
|
|
|
}
|
|
|
|
return new_insn_core(iseq, line_no, insn_id, argc, operands);
|
|
|
|
}
|
|
|
|
|
2015-09-19 20:59:58 +03:00
|
|
|
static struct rb_call_info *
|
|
|
|
new_callinfo(rb_iseq_t *iseq, ID mid, int argc, unsigned int flag, struct rb_call_info_kw_arg *kw_arg, int has_blockiseq)
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
{
|
2015-09-19 20:59:58 +03:00
|
|
|
size_t size = kw_arg != NULL ? sizeof(struct rb_call_info_with_kwarg) : sizeof(struct rb_call_info);
|
|
|
|
struct rb_call_info *ci = (struct rb_call_info *)compile_data_alloc(iseq, size);
|
|
|
|
struct rb_call_info_with_kwarg *ci_kw = (struct rb_call_info_with_kwarg *)ci;
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
ci->mid = mid;
|
|
|
|
ci->flag = flag;
|
|
|
|
ci->orig_argc = argc;
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
|
|
|
|
if (kw_arg) {
|
2015-09-19 20:59:58 +03:00
|
|
|
ci->flag |= VM_CALL_KWARG;
|
|
|
|
ci_kw->kw_arg = kw_arg;
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ci->orig_argc += kw_arg->keyword_len;
|
2015-09-19 20:59:58 +03:00
|
|
|
iseq->body->ci_kw_size++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
iseq->body->ci_size++;
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
}
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
if (!(ci->flag & (VM_CALL_ARGS_SPLAT | VM_CALL_ARGS_BLOCKARG)) &&
|
2015-09-19 20:59:58 +03:00
|
|
|
kw_arg == NULL && !has_blockiseq) {
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ci->flag |= VM_CALL_ARGS_SIMPLE;
|
|
|
|
}
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static INSN *
|
2015-09-19 20:59:58 +03:00
|
|
|
new_insn_send(rb_iseq_t *iseq, int line_no, ID id, VALUE argc, const rb_iseq_t *blockiseq, VALUE flag, struct rb_call_info_kw_arg *keywords)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2015-09-19 20:59:58 +03:00
|
|
|
VALUE *operands = (VALUE *)compile_data_alloc(iseq, sizeof(VALUE) * 3);
|
2015-09-08 11:21:07 +03:00
|
|
|
operands[0] = (VALUE)new_callinfo(iseq, id, FIX2INT(argc), FIX2INT(flag), keywords, blockiseq != NULL);
|
2015-09-19 20:59:58 +03:00
|
|
|
operands[1] = Qfalse; /* cache */
|
|
|
|
operands[2] = (VALUE)blockiseq;
|
|
|
|
return new_insn_core(iseq, line_no, BIN(send), 3, operands);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
static rb_iseq_t *
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
new_child_iseq(rb_iseq_t *iseq, NODE *node,
|
2015-07-22 01:52:59 +03:00
|
|
|
VALUE name, const rb_iseq_t *parent, enum iseq_type type, int line_no)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2015-07-22 01:52:59 +03:00
|
|
|
rb_iseq_t *ret_iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
debugs("[new_child_iseq]> ---------------------------------------\n");
|
2015-07-22 01:52:59 +03:00
|
|
|
ret_iseq = rb_iseq_new_with_opt(node, name,
|
|
|
|
iseq_path(iseq), iseq_absolute_path(iseq),
|
2015-12-02 10:52:12 +03:00
|
|
|
INT2FIX(line_no), parent, type, ISEQ_COMPILE_DATA(iseq)->option);
|
2006-12-31 18:02:22 +03:00
|
|
|
debugs("[new_child_iseq]< ---------------------------------------\n");
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq_add_mark_object(iseq, (VALUE)ret_iseq);
|
|
|
|
return ret_iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* debugs("[compile step 2] (iseq_array_to_linkedlist)\n"); */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-04-14 09:34:04 +04:00
|
|
|
if (compile_debug > 5)
|
2006-12-31 18:02:22 +03:00
|
|
|
dump_disasm_list(FIRST_ELEMENT(anchor));
|
|
|
|
|
|
|
|
debugs("[compile step 3.1 (iseq_optimize)]\n");
|
|
|
|
iseq_optimize(iseq, anchor);
|
|
|
|
|
2008-04-14 09:34:04 +04:00
|
|
|
if (compile_debug > 5)
|
2006-12-31 18:02:22 +03:00
|
|
|
dump_disasm_list(FIRST_ELEMENT(anchor));
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->instructions_unification) {
|
2006-12-31 18:02:22 +03:00
|
|
|
debugs("[compile step 3.2 (iseq_insns_unification)]\n");
|
|
|
|
iseq_insns_unification(iseq, anchor);
|
2008-04-14 09:34:04 +04:00
|
|
|
if (compile_debug > 5)
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
dump_disasm_list(FIRST_ELEMENT(anchor));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->stack_caching) {
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
debugs("[compile step 3.3 (iseq_set_sequence_stackcaching)]\n");
|
|
|
|
iseq_set_sequence_stackcaching(iseq, anchor);
|
2008-04-14 09:34:04 +04:00
|
|
|
if (compile_debug > 5)
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
dump_disasm_list(FIRST_ELEMENT(anchor));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
debugs("[compile step 4.1 (iseq_set_sequence)]\n");
|
2015-11-22 09:10:41 +03:00
|
|
|
if (!iseq_set_sequence(iseq, anchor)) return COMPILE_NG;
|
2008-04-14 09:34:04 +04:00
|
|
|
if (compile_debug > 5)
|
2006-12-31 18:02:22 +03:00
|
|
|
dump_disasm_list(FIRST_ELEMENT(anchor));
|
|
|
|
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
debugs("[compile step 4.2 (iseq_set_exception_table)]\n");
|
2015-11-22 09:10:41 +03:00
|
|
|
if (!iseq_set_exception_table(iseq)) return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
debugs("[compile step 4.3 (set_optargs_table)] \n");
|
2015-11-22 09:10:41 +03:00
|
|
|
if (!iseq_set_optargs_table(iseq)) return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-07-02 16:49:35 +04:00
|
|
|
debugs("[compile step 5 (iseq_translate_threaded_code)] \n");
|
2015-11-22 09:10:41 +03:00
|
|
|
if (!rb_iseq_translate_threaded_code(iseq)) return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-04-14 09:34:04 +04:00
|
|
|
if (compile_debug > 1) {
|
2015-07-22 01:52:59 +03:00
|
|
|
VALUE str = rb_iseq_disasm(iseq);
|
2006-12-31 18:02:22 +03:00
|
|
|
printf("%s\n", StringValueCStr(str));
|
|
|
|
}
|
|
|
|
debugs("[compile step: finish]\n");
|
|
|
|
|
2015-11-22 09:10:41 +03:00
|
|
|
return COMPILE_OK;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
static int
|
|
|
|
iseq_set_exception_local_table(rb_iseq_t *iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2015-09-12 21:47:43 +03:00
|
|
|
/* TODO: every id table is same -> share it.
|
|
|
|
* Current problem is iseq_free().
|
|
|
|
*/
|
2008-06-09 13:25:32 +04:00
|
|
|
ID id_dollar_bang;
|
2015-07-23 12:53:16 +03:00
|
|
|
ID *ids = (ID *)ALLOC_N(ID, 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-06-09 13:25:32 +04:00
|
|
|
CONST_ID(id_dollar_bang, "#$!");
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->local_table_size = 1;
|
2015-07-23 12:53:16 +03:00
|
|
|
ids[0] = id_dollar_bang;
|
|
|
|
iseq->body->local_table = ids;
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-04 17:52:20 +04:00
|
|
|
static int
|
2015-07-16 16:13:50 +03:00
|
|
|
get_lvar_level(const rb_iseq_t *iseq)
|
2012-10-04 17:52:20 +04:00
|
|
|
{
|
|
|
|
int lev = 0;
|
2015-07-22 01:52:59 +03:00
|
|
|
while (iseq != iseq->body->local_iseq) {
|
2012-10-04 17:52:20 +04:00
|
|
|
lev++;
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq = iseq->body->parent_iseq;
|
2012-10-04 17:52:20 +04:00
|
|
|
}
|
|
|
|
return lev;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2015-07-16 16:13:50 +03:00
|
|
|
get_dyna_var_idx_at_raw(const rb_iseq_t *iseq, ID id)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2015-07-25 00:44:14 +03:00
|
|
|
unsigned int i;
|
2007-02-25 04:34:33 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
for (i = 0; i < iseq->body->local_table_size; i++) {
|
|
|
|
if (iseq->body->local_table[i] == id) {
|
2015-07-25 00:44:14 +03:00
|
|
|
return (int)i;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-02-25 04:34:33 +03:00
|
|
|
static int
|
2015-07-16 16:13:50 +03:00
|
|
|
get_local_var_idx(const rb_iseq_t *iseq, ID id)
|
2007-02-25 04:34:33 +03:00
|
|
|
{
|
2015-07-22 01:52:59 +03:00
|
|
|
int idx = get_dyna_var_idx_at_raw(iseq->body->local_iseq, id);
|
2007-02-25 04:34:33 +03:00
|
|
|
|
2007-07-07 12:14:00 +04:00
|
|
|
if (idx < 0) {
|
|
|
|
rb_bug("get_local_var_idx: %d", idx);
|
2007-02-25 04:34:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2015-07-16 16:13:50 +03:00
|
|
|
get_dyna_var_idx(const rb_iseq_t *iseq, ID id, int *level, int *ls)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-07-07 12:14:00 +04:00
|
|
|
int lv = 0, idx = -1;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-07-07 12:14:00 +04:00
|
|
|
while (iseq) {
|
|
|
|
idx = get_dyna_var_idx_at_raw(iseq, id);
|
|
|
|
if (idx >= 0) {
|
|
|
|
break;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq = iseq->body->parent_iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
lv++;
|
|
|
|
}
|
2007-07-07 12:14:00 +04:00
|
|
|
|
|
|
|
if (idx < 0) {
|
|
|
|
rb_bug("get_dyna_var_idx: -1");
|
|
|
|
}
|
|
|
|
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
*level = lv;
|
2016-07-28 14:02:30 +03:00
|
|
|
*ls = iseq->body->local_table_size;
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
return idx;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2014-11-27 01:11:54 +03:00
|
|
|
static void
|
|
|
|
iseq_calc_param_size(rb_iseq_t *iseq)
|
|
|
|
{
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->param.flags.has_opt ||
|
|
|
|
iseq->body->param.flags.has_post ||
|
|
|
|
iseq->body->param.flags.has_rest ||
|
|
|
|
iseq->body->param.flags.has_block ||
|
|
|
|
iseq->body->param.flags.has_kw ||
|
|
|
|
iseq->body->param.flags.has_kwrest) {
|
2014-11-27 01:11:54 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->param.flags.has_block) {
|
|
|
|
iseq->body->param.size = iseq->body->param.block_start + 1;
|
2014-11-27 01:11:54 +03:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (iseq->body->param.flags.has_kwrest) {
|
|
|
|
iseq->body->param.size = iseq->body->param.keyword->rest_start + 1;
|
2014-11-27 01:11:54 +03:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (iseq->body->param.flags.has_kw) {
|
|
|
|
iseq->body->param.size = iseq->body->param.keyword->bits_start + 1;
|
2014-11-27 01:11:54 +03:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (iseq->body->param.flags.has_post) {
|
|
|
|
iseq->body->param.size = iseq->body->param.post_start + iseq->body->param.post_num;
|
2014-11-27 01:11:54 +03:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (iseq->body->param.flags.has_rest) {
|
|
|
|
iseq->body->param.size = iseq->body->param.rest_start + 1;
|
2014-11-27 01:11:54 +03:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (iseq->body->param.flags.has_opt) {
|
|
|
|
iseq->body->param.size = iseq->body->param.lead_num + iseq->body->param.opt_num;
|
2014-11-27 01:11:54 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_bug("unreachable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.size = iseq->body->param.lead_num;
|
2014-11-27 01:11:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-24 23:58:09 +03:00
|
|
|
static void
|
|
|
|
iseq_set_arguments_keywords(rb_iseq_t *iseq, LINK_ANCHOR *optargs, const struct rb_args_info *args)
|
|
|
|
{
|
|
|
|
NODE *node = args->kw_args;
|
|
|
|
struct rb_iseq_param_keyword *keyword;
|
|
|
|
const VALUE default_values = rb_ary_tmp_new(1);
|
|
|
|
const VALUE complex_mark = rb_str_tmp_new(0);
|
|
|
|
int kw = 0, rkw = 0, di = 0, i;
|
|
|
|
|
|
|
|
iseq->body->param.flags.has_kw = TRUE;
|
|
|
|
iseq->body->param.keyword = keyword = ZALLOC_N(struct rb_iseq_param_keyword, 1);
|
|
|
|
keyword->bits_start = get_dyna_var_idx_at_raw(iseq, args->kw_rest_arg->nd_vid);
|
|
|
|
|
|
|
|
while (node) {
|
|
|
|
NODE *val_node = node->nd_body->nd_value;
|
|
|
|
VALUE dv;
|
|
|
|
|
|
|
|
if (val_node == (NODE *)-1) {
|
|
|
|
++rkw;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (nd_type(val_node)) {
|
|
|
|
case NODE_LIT:
|
|
|
|
dv = val_node->nd_lit;
|
|
|
|
iseq_add_mark_object(iseq, dv);
|
|
|
|
break;
|
|
|
|
case NODE_NIL:
|
|
|
|
dv = Qnil;
|
|
|
|
break;
|
|
|
|
case NODE_TRUE:
|
|
|
|
dv = Qtrue;
|
|
|
|
break;
|
|
|
|
case NODE_FALSE:
|
|
|
|
dv = Qfalse;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
COMPILE_POPED(optargs, "kwarg", node); /* nd_type(node) == NODE_KW_ARG */
|
|
|
|
dv = complex_mark;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyword->num = ++di;
|
|
|
|
rb_ary_push(default_values, dv);
|
|
|
|
}
|
|
|
|
|
|
|
|
kw++;
|
|
|
|
node = node->nd_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyword->num = kw;
|
|
|
|
|
|
|
|
if (args->kw_rest_arg->nd_cflag != 0) {
|
|
|
|
keyword->rest_start = get_dyna_var_idx_at_raw(iseq, args->kw_rest_arg->nd_cflag);
|
|
|
|
iseq->body->param.flags.has_kwrest = TRUE;
|
|
|
|
}
|
|
|
|
keyword->required_num = rkw;
|
|
|
|
keyword->table = &iseq->body->local_table[keyword->bits_start - keyword->num];
|
|
|
|
|
|
|
|
{
|
|
|
|
VALUE *dvs = ALLOC_N(VALUE, RARRAY_LEN(default_values));
|
|
|
|
|
|
|
|
for (i = 0; i < RARRAY_LEN(default_values); i++) {
|
|
|
|
VALUE dv = RARRAY_AREF(default_values, i);
|
|
|
|
if (dv == complex_mark) dv = Qundef;
|
|
|
|
dvs[i] = dv;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyword->default_values = dvs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* parse.y, node.h, compile.c: change node tree structure. a purpose
of this change is to unify argument structure of method and block.
this change prohibits duplicate block parameter name.
new argument infromation:
NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
NODE_ARGS_AUX [r: ID, b: ID, ->]
NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
optarg information:
NODE_OPT_ARGS [idx, expr, ->]
* vm_macro.def: ditto.
* gc.c: ditto.
* iseq.c: ditto.
* compile.h: fix debug function name.
* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|
* test/ruby/test_lambda.rb: disalbe test temporarily.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:07:05 +03:00
|
|
|
static int
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
|
* parse.y, node.h, compile.c: change node tree structure. a purpose
of this change is to unify argument structure of method and block.
this change prohibits duplicate block parameter name.
new argument infromation:
NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
NODE_ARGS_AUX [r: ID, b: ID, ->]
NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
optarg information:
NODE_OPT_ARGS [idx, expr, ->]
* vm_macro.def: ditto.
* gc.c: ditto.
* iseq.c: ditto.
* compile.h: fix debug function name.
* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|
* test/ruby/test_lambda.rb: disalbe test temporarily.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:07:05 +03:00
|
|
|
{
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
debugs("iseq_set_arguments: %s\n", node_args ? "" : "0");
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
|
|
|
|
if (node_args) {
|
2011-12-26 18:19:58 +04:00
|
|
|
struct rb_args_info *args = node_args->nd_ainfo;
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
ID rest_id = 0;
|
2007-06-25 20:05:17 +04:00
|
|
|
int last_comma = 0;
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
ID block_id = 0;
|
|
|
|
|
2015-12-01 08:55:26 +03:00
|
|
|
EXPECT_NODE("iseq_set_arguments", node_args, NODE_ARGS);
|
2011-12-26 18:19:58 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.lead_num = (int)args->pre_args_num;
|
|
|
|
if (iseq->body->param.lead_num > 0) iseq->body->param.flags.has_lead = TRUE;
|
|
|
|
debugs(" - argc: %d\n", iseq->body->param.lead_num);
|
* parse.y, node.h, compile.c: change node tree structure. a purpose
of this change is to unify argument structure of method and block.
this change prohibits duplicate block parameter name.
new argument infromation:
NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
NODE_ARGS_AUX [r: ID, b: ID, ->]
NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
optarg information:
NODE_OPT_ARGS [idx, expr, ->]
* vm_macro.def: ditto.
* gc.c: ditto.
* iseq.c: ditto.
* compile.h: fix debug function name.
* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|
* test/ruby/test_lambda.rb: disalbe test temporarily.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:07:05 +03:00
|
|
|
|
2011-12-26 18:19:58 +04:00
|
|
|
rest_id = args->rest_arg;
|
|
|
|
if (rest_id == 1) {
|
|
|
|
last_comma = 1;
|
|
|
|
rest_id = 0;
|
|
|
|
}
|
|
|
|
block_id = args->block_arg;
|
|
|
|
|
|
|
|
if (args->first_post_arg) {
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.post_start = get_dyna_var_idx_at_raw(iseq, args->first_post_arg);
|
|
|
|
iseq->body->param.post_num = args->post_args_num;
|
|
|
|
iseq->body->param.flags.has_post = TRUE;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2011-12-26 18:19:58 +04:00
|
|
|
if (args->opt_args) {
|
|
|
|
NODE *node = args->opt_args;
|
2006-12-31 18:02:22 +03:00
|
|
|
LABEL *label;
|
2009-06-22 11:14:32 +04:00
|
|
|
VALUE labels = rb_ary_tmp_new(1);
|
2015-07-24 23:58:09 +03:00
|
|
|
VALUE *opt_table;
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
int i = 0, j;
|
|
|
|
|
|
|
|
while (node) {
|
2006-12-31 18:02:22 +03:00
|
|
|
label = NEW_LABEL(nd_line(node));
|
|
|
|
rb_ary_push(labels, (VALUE)label | 1);
|
|
|
|
ADD_LABEL(optargs, label);
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
COMPILE_POPED(optargs, "optarg", node->nd_body);
|
|
|
|
node = node->nd_next;
|
2006-12-31 18:02:22 +03:00
|
|
|
i += 1;
|
|
|
|
}
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/* last label */
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
label = NEW_LABEL(nd_line(node_args));
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(labels, (VALUE)label | 1);
|
|
|
|
ADD_LABEL(optargs, label);
|
|
|
|
|
2015-07-24 23:58:09 +03:00
|
|
|
opt_table = ALLOC_N(VALUE, i+1);
|
|
|
|
|
|
|
|
MEMCPY(opt_table, RARRAY_CONST_PTR(labels), VALUE, i+1);
|
2014-11-03 07:43:07 +03:00
|
|
|
for (j = 0; j < i+1; j++) {
|
2015-07-24 23:58:09 +03:00
|
|
|
opt_table[j] &= ~1;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2009-06-22 11:14:32 +04:00
|
|
|
rb_ary_clear(labels);
|
2014-11-03 02:14:21 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.flags.has_opt = TRUE;
|
2015-07-24 23:58:09 +03:00
|
|
|
iseq->body->param.opt_num = i;
|
|
|
|
iseq->body->param.opt_table = opt_table;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2011-12-26 18:20:09 +04:00
|
|
|
if (args->kw_args) {
|
2015-07-24 23:58:09 +03:00
|
|
|
iseq_set_arguments_keywords(iseq, optargs, args);
|
2011-12-26 18:20:09 +04:00
|
|
|
}
|
2012-03-13 17:00:17 +04:00
|
|
|
else if (args->kw_rest_arg) {
|
2015-07-24 23:58:09 +03:00
|
|
|
struct rb_iseq_param_keyword *keyword = ZALLOC_N(struct rb_iseq_param_keyword, 1);
|
|
|
|
keyword->rest_start = get_dyna_var_idx_at_raw(iseq, args->kw_rest_arg->nd_vid);
|
|
|
|
iseq->body->param.keyword = keyword;
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.flags.has_kwrest = TRUE;
|
2011-12-26 18:20:09 +04:00
|
|
|
}
|
|
|
|
|
2011-12-26 18:19:58 +04:00
|
|
|
if (args->pre_init) { /* m_init */
|
|
|
|
COMPILE_POPED(optargs, "init arguments (m)", args->pre_init);
|
|
|
|
}
|
|
|
|
if (args->post_init) { /* p_init */
|
|
|
|
COMPILE_POPED(optargs, "init arguments (p)", args->post_init);
|
2007-05-17 08:25:18 +04:00
|
|
|
}
|
|
|
|
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
if (rest_id) {
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.rest_start = get_dyna_var_idx_at_raw(iseq, rest_id);
|
|
|
|
iseq->body->param.flags.has_rest = TRUE;
|
|
|
|
assert(iseq->body->param.rest_start != -1);
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->param.post_start == 0) { /* TODO: why that? */
|
|
|
|
iseq->body->param.post_start = iseq->body->param.rest_start + 1;
|
2007-05-01 08:35:58 +04:00
|
|
|
}
|
2007-07-20 11:30:33 +04:00
|
|
|
}
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
|
|
|
|
if (block_id) {
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.block_start = get_dyna_var_idx_at_raw(iseq, block_id);
|
|
|
|
iseq->body->param.flags.has_block = TRUE;
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
}
|
|
|
|
|
2014-11-27 01:11:54 +03:00
|
|
|
iseq_calc_param_size(iseq);
|
2007-06-25 20:05:17 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->type == ISEQ_TYPE_BLOCK) {
|
|
|
|
if (iseq->body->param.flags.has_opt == FALSE &&
|
|
|
|
iseq->body->param.flags.has_post == FALSE &&
|
|
|
|
iseq->body->param.flags.has_rest == FALSE &&
|
|
|
|
iseq->body->param.flags.has_kw == FALSE &&
|
|
|
|
iseq->body->param.flags.has_kwrest == FALSE) {
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->param.lead_num == 1 && last_comma == 0) {
|
2007-08-16 20:29:11 +04:00
|
|
|
/* {|a|} */
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.flags.ambiguous_param0 = TRUE;
|
2007-08-16 20:29:11 +04:00
|
|
|
}
|
2007-06-25 20:05:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-12-17 05:57:53 +03:00
|
|
|
iseq_set_local_table(rb_iseq_t *iseq, const ID *tbl)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2016-07-28 14:02:30 +03:00
|
|
|
unsigned int size;
|
2007-02-25 04:34:33 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
if (tbl) {
|
2016-07-28 14:02:30 +03:00
|
|
|
size = (unsigned int)*tbl;
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
tbl++;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-02-25 04:34:33 +03:00
|
|
|
size = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-02-25 04:34:33 +03:00
|
|
|
|
|
|
|
if (size > 0) {
|
2015-07-23 12:53:16 +03:00
|
|
|
ID *ids = (ID *)ALLOC_N(ID, size);
|
|
|
|
MEMCPY(ids, tbl, ID, size);
|
|
|
|
iseq->body->local_table = ids;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2016-07-28 14:02:30 +03:00
|
|
|
iseq->body->local_table_size = size;
|
2007-02-25 04:34:33 +03:00
|
|
|
|
2016-07-28 14:02:30 +03:00
|
|
|
debugs("iseq_set_local_table: %u\n", iseq->body->local_table_size);
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-27 12:30:53 +03:00
|
|
|
static int
|
|
|
|
cdhash_cmp(VALUE val, VALUE lit)
|
|
|
|
{
|
|
|
|
if (val == lit) return 0;
|
|
|
|
if (SPECIAL_CONST_P(lit)) {
|
|
|
|
return val != lit;
|
|
|
|
}
|
|
|
|
if (SPECIAL_CONST_P(val) || BUILTIN_TYPE(val) != BUILTIN_TYPE(lit)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (BUILTIN_TYPE(lit) == T_STRING) {
|
|
|
|
return rb_str_hash_cmp(lit, val);
|
|
|
|
}
|
|
|
|
return !rb_eql(lit, val);
|
|
|
|
}
|
|
|
|
|
2009-09-08 17:10:04 +04:00
|
|
|
static st_index_t
|
2009-02-27 12:30:53 +03:00
|
|
|
cdhash_hash(VALUE a)
|
|
|
|
{
|
2009-09-08 17:10:04 +04:00
|
|
|
if (SPECIAL_CONST_P(a)) return (st_index_t)a;
|
2011-09-29 15:07:45 +04:00
|
|
|
if (RB_TYPE_P(a, T_STRING)) return rb_str_hash(a);
|
2009-02-27 12:30:53 +03:00
|
|
|
{
|
|
|
|
VALUE hval = rb_hash(a);
|
2009-09-08 17:10:04 +04:00
|
|
|
return (st_index_t)FIX2LONG(hval);
|
2009-02-27 12:30:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct st_hash_type cdhash_type = {
|
|
|
|
cdhash_cmp,
|
|
|
|
cdhash_hash,
|
|
|
|
};
|
|
|
|
|
2012-04-24 13:20:42 +04:00
|
|
|
struct cdhash_set_label_struct {
|
|
|
|
VALUE hash;
|
|
|
|
int pos;
|
|
|
|
int len;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
cdhash_set_label_i(VALUE key, VALUE val, void *ptr)
|
|
|
|
{
|
|
|
|
struct cdhash_set_label_struct *data = (struct cdhash_set_label_struct *)ptr;
|
|
|
|
LABEL *lobj = (LABEL *)(val & ~1);
|
|
|
|
rb_hash_aset(data->hash, key, INT2FIX(lobj->position - (data->pos+data->len)));
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2016-05-11 15:50:38 +03:00
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
get_ivar_ic_value(rb_iseq_t *iseq,ID id)
|
|
|
|
{
|
|
|
|
VALUE val;
|
2016-05-14 21:43:11 +03:00
|
|
|
struct rb_id_table *tbl = ISEQ_COMPILE_DATA(iseq)->ivar_cache_table;
|
|
|
|
if (tbl) {
|
|
|
|
if (rb_id_table_lookup(tbl,id,&val)) {
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tbl = rb_id_table_create(1);
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->ivar_cache_table = tbl;
|
2016-05-11 15:50:38 +03:00
|
|
|
}
|
2016-05-14 21:43:11 +03:00
|
|
|
val = INT2FIX(iseq->body->is_size++);
|
|
|
|
rb_id_table_insert(tbl,id,val);
|
2016-05-11 15:50:38 +03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/**
|
2010-10-31 04:42:54 +03:00
|
|
|
ruby insn object list -> raw instruction sequence
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
static int
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2011-08-24 10:31:15 +04:00
|
|
|
struct iseq_line_info_entry *line_info_table;
|
|
|
|
unsigned int last_line = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
LINK_ELEMENT *list;
|
|
|
|
VALUE *generated_iseq;
|
|
|
|
|
2015-08-27 09:25:53 +03:00
|
|
|
int insn_num, code_index, line_info_index, sp, stack_max = 0, line = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-08-27 09:25:53 +03:00
|
|
|
/* fix label position */
|
2006-12-31 18:02:22 +03:00
|
|
|
list = FIRST_ELEMENT(anchor);
|
2015-08-27 09:25:53 +03:00
|
|
|
insn_num = code_index = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
while (list) {
|
|
|
|
switch (list->type) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_INSN:
|
|
|
|
{
|
2015-12-02 10:31:23 +03:00
|
|
|
INSN *iobj = (INSN *)list;
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
line = iobj->line_no;
|
2015-08-27 09:25:53 +03:00
|
|
|
code_index += insn_data_length(iobj);
|
|
|
|
insn_num++;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_LABEL:
|
|
|
|
{
|
2015-12-02 10:31:23 +03:00
|
|
|
LABEL *lobj = (LABEL *)list;
|
2015-08-27 09:25:53 +03:00
|
|
|
lobj->position = code_index;
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
lobj->set = TRUE;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_NONE:
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
2008-01-25 21:02:01 +03:00
|
|
|
case ISEQ_ELEMENT_ADJUST:
|
|
|
|
{
|
2008-01-26 11:27:00 +03:00
|
|
|
ADJUST *adjust = (ADJUST *)list;
|
|
|
|
if (adjust->line_no != -1) {
|
2015-08-27 09:25:53 +03:00
|
|
|
code_index += 2 /* insn + 1 operand */;
|
|
|
|
insn_num++;
|
2008-01-26 11:27:00 +03:00
|
|
|
}
|
2008-01-25 21:02:01 +03:00
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
dump_disasm_list(FIRST_ELEMENT(anchor));
|
|
|
|
dump_disasm_list(list);
|
2016-04-19 07:46:20 +03:00
|
|
|
COMPILE_ERROR(iseq, line, "error: set_sequence");
|
2015-11-22 09:32:23 +03:00
|
|
|
return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make instruction sequence */
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq = ALLOC_N(VALUE, code_index);
|
|
|
|
line_info_table = ALLOC_N(struct iseq_line_info_entry, insn_num);
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->is_entries = ZALLOC_N(union iseq_inline_storage_entry, iseq->body->is_size);
|
2015-09-19 20:59:58 +03:00
|
|
|
iseq->body->ci_entries = (struct rb_call_info *)ruby_xmalloc(sizeof(struct rb_call_info) * iseq->body->ci_size +
|
|
|
|
sizeof(struct rb_call_info_with_kwarg) * iseq->body->ci_kw_size);
|
|
|
|
iseq->body->cc_entries = ZALLOC_N(struct rb_call_cache, iseq->body->ci_size + iseq->body->ci_kw_size);
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->ci_index = ISEQ_COMPILE_DATA(iseq)->ci_kw_index = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
list = FIRST_ELEMENT(anchor);
|
2015-08-27 09:25:53 +03:00
|
|
|
line_info_index = code_index = sp = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
while (list) {
|
|
|
|
switch (list->type) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_INSN:
|
|
|
|
{
|
2010-02-24 20:06:15 +03:00
|
|
|
int j, len, insn;
|
2008-04-03 04:00:48 +04:00
|
|
|
const char *types;
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE *operands;
|
2015-12-02 10:31:23 +03:00
|
|
|
INSN *iobj = (INSN *)list;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-01-25 21:02:01 +03:00
|
|
|
/* update sp */
|
|
|
|
sp = calc_sp_depth(sp, iobj);
|
|
|
|
if (sp > stack_max) {
|
|
|
|
stack_max = sp;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* fprintf(stderr, "insn: %-16s, sp: %d\n", insn_name(iobj->insn_id), sp); */
|
2006-12-31 18:02:22 +03:00
|
|
|
operands = iobj->operands;
|
|
|
|
insn = iobj->insn_id;
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index] = insn;
|
2006-12-31 18:02:22 +03:00
|
|
|
types = insn_op_types(insn);
|
|
|
|
len = insn_len(insn);
|
2009-07-13 08:44:20 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/* operand check */
|
2010-02-24 20:06:15 +03:00
|
|
|
if (iobj->operand_size != len - 1) {
|
|
|
|
/* printf("operand size miss! (%d, %d)\n", iobj->operand_size, len); */
|
2006-12-31 18:02:22 +03:00
|
|
|
dump_disasm_list(list);
|
2008-10-16 18:38:08 +04:00
|
|
|
xfree(generated_iseq);
|
2011-08-24 10:31:15 +04:00
|
|
|
xfree(line_info_table);
|
2016-04-19 07:46:20 +03:00
|
|
|
COMPILE_ERROR(iseq, iobj->line_no,
|
2015-12-04 20:28:26 +03:00
|
|
|
"operand size miss! (%d for %d)",
|
|
|
|
iobj->operand_size, len - 1);
|
2015-11-22 09:10:41 +03:00
|
|
|
return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; types[j]; j++) {
|
|
|
|
char type = types[j];
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* printf("--> [%c - (%d-%d)]\n", type, k, j); */
|
2006-12-31 18:02:22 +03:00
|
|
|
switch (type) {
|
2007-06-05 08:49:54 +04:00
|
|
|
case TS_OFFSET:
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
/* label(destination position) */
|
2015-12-02 10:31:23 +03:00
|
|
|
LABEL *lobj = (LABEL *)operands[j];
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
if (!lobj->set) {
|
2016-04-19 07:46:20 +03:00
|
|
|
COMPILE_ERROR(iseq, iobj->line_no,
|
2015-12-04 20:28:26 +03:00
|
|
|
"unknown label");
|
2015-11-22 09:32:23 +03:00
|
|
|
return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
if (lobj->sp == -1) {
|
|
|
|
lobj->sp = sp;
|
|
|
|
}
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = lobj->position - (code_index + len);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 08:49:54 +04:00
|
|
|
case TS_CDHASH:
|
|
|
|
{
|
2012-04-24 13:20:42 +04:00
|
|
|
VALUE map = operands[j];
|
2012-06-11 06:57:02 +04:00
|
|
|
struct cdhash_set_label_struct data;
|
|
|
|
data.hash = map;
|
2015-08-27 09:25:53 +03:00
|
|
|
data.pos = code_index;
|
2012-06-11 06:57:02 +04:00
|
|
|
data.len = len;
|
2012-04-24 13:20:42 +04:00
|
|
|
rb_hash_foreach(map, cdhash_set_label_i, (VALUE)&data);
|
|
|
|
|
2015-12-11 05:38:20 +03:00
|
|
|
rb_hash_rehash(map);
|
2015-07-22 01:52:59 +03:00
|
|
|
freeze_hide_obj(map);
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = map;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 08:49:54 +04:00
|
|
|
case TS_LINDEX:
|
|
|
|
case TS_NUM: /* ulong */
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = FIX2INT(operands[j]);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
2007-06-05 08:49:54 +04:00
|
|
|
case TS_ISEQ: /* iseq */
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE v = operands[j];
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = v;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 08:49:54 +04:00
|
|
|
case TS_VALUE: /* VALUE */
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE v = operands[j];
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = v;
|
2006-12-31 18:02:22 +03:00
|
|
|
/* to mark ruby object */
|
2007-07-01 22:16:02 +04:00
|
|
|
iseq_add_mark_object(iseq, v);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 08:49:54 +04:00
|
|
|
case TS_IC: /* inline cache */
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2015-07-25 00:44:14 +03:00
|
|
|
unsigned int ic_index = FIX2UINT(operands[j]);
|
2015-07-22 01:52:59 +03:00
|
|
|
IC ic = (IC)&iseq->body->is_entries[ic_index];
|
|
|
|
if (UNLIKELY(ic_index >= iseq->body->is_size)) {
|
|
|
|
rb_bug("iseq_set_sequence: ic_index overflow: index: %d, size: %d", ic_index, iseq->body->is_size);
|
2009-07-13 13:30:23 +04:00
|
|
|
}
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = (VALUE)ic;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-10-09 09:33:54 +04:00
|
|
|
case TS_CALLINFO: /* call info */
|
|
|
|
{
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info *base_ci = (struct rb_call_info *)operands[j];
|
|
|
|
struct rb_call_info *ci;
|
|
|
|
|
|
|
|
if (base_ci->flag & VM_CALL_KWARG) {
|
|
|
|
struct rb_call_info_with_kwarg *ci_kw_entries = (struct rb_call_info_with_kwarg *)&iseq->body->ci_entries[iseq->body->ci_size];
|
2015-12-02 10:52:12 +03:00
|
|
|
struct rb_call_info_with_kwarg *ci_kw = &ci_kw_entries[ISEQ_COMPILE_DATA(iseq)->ci_kw_index++];
|
2015-09-19 20:59:58 +03:00
|
|
|
*ci_kw = *((struct rb_call_info_with_kwarg *)base_ci);
|
|
|
|
ci = (struct rb_call_info *)ci_kw;
|
2015-12-02 10:52:12 +03:00
|
|
|
assert(ISEQ_COMPILE_DATA(iseq)->ci_kw_index <= iseq->body->ci_kw_size);
|
2015-09-19 20:59:58 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-12-02 10:52:12 +03:00
|
|
|
ci = &iseq->body->ci_entries[ISEQ_COMPILE_DATA(iseq)->ci_index++];
|
2015-09-19 20:59:58 +03:00
|
|
|
*ci = *base_ci;
|
2015-12-02 10:52:12 +03:00
|
|
|
assert(ISEQ_COMPILE_DATA(iseq)->ci_index <= iseq->body->ci_size);
|
2012-10-09 09:33:54 +04:00
|
|
|
}
|
2015-09-19 20:59:58 +03:00
|
|
|
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = (VALUE)ci;
|
2012-10-09 09:33:54 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-09-19 20:59:58 +03:00
|
|
|
case TS_CALLCACHE:
|
|
|
|
{
|
2015-12-02 10:52:12 +03:00
|
|
|
struct rb_call_cache *cc = &iseq->body->cc_entries[ISEQ_COMPILE_DATA(iseq)->ci_index + ISEQ_COMPILE_DATA(iseq)->ci_kw_index - 1];
|
2015-09-19 20:59:58 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = (VALUE)cc;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 08:49:54 +04:00
|
|
|
case TS_ID: /* ID */
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = SYM2ID(operands[j]);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
2007-06-05 08:49:54 +04:00
|
|
|
case TS_GENTRY:
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2009-07-16 04:01:06 +04:00
|
|
|
struct rb_global_entry *entry =
|
|
|
|
(struct rb_global_entry *)(operands[j] & (~1));
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = (VALUE)entry;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
break;
|
2014-12-15 22:09:25 +03:00
|
|
|
case TS_FUNCPTR:
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index + 1 + j] = operands[j];
|
2014-12-15 22:09:25 +03:00
|
|
|
break;
|
2007-06-05 08:49:54 +04:00
|
|
|
default:
|
2008-10-16 18:38:08 +04:00
|
|
|
xfree(generated_iseq);
|
2011-08-24 10:31:15 +04:00
|
|
|
xfree(line_info_table);
|
2016-04-19 07:46:20 +03:00
|
|
|
COMPILE_ERROR(iseq, iobj->line_no,
|
2015-12-04 20:28:26 +03:00
|
|
|
"unknown operand type: %c", type);
|
2015-11-22 09:10:41 +03:00
|
|
|
return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2011-08-24 10:31:15 +04:00
|
|
|
if (last_line != iobj->line_no) {
|
2015-08-27 09:25:53 +03:00
|
|
|
line_info_table[line_info_index].line_no = last_line = iobj->line_no;
|
|
|
|
line_info_table[line_info_index].position = code_index;
|
|
|
|
line_info_index++;
|
2011-08-24 10:31:15 +04:00
|
|
|
}
|
2015-08-27 09:25:53 +03:00
|
|
|
code_index += len;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_LABEL:
|
|
|
|
{
|
2015-12-02 10:31:23 +03:00
|
|
|
LABEL *lobj = (LABEL *)list;
|
2006-12-31 18:02:22 +03:00
|
|
|
if (lobj->sp == -1) {
|
|
|
|
lobj->sp = sp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sp = lobj->sp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-01-25 21:02:01 +03:00
|
|
|
case ISEQ_ELEMENT_ADJUST:
|
|
|
|
{
|
|
|
|
ADJUST *adjust = (ADJUST *)list;
|
|
|
|
int orig_sp = sp;
|
|
|
|
|
|
|
|
if (adjust->label) {
|
|
|
|
sp = adjust->label->sp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sp = 0;
|
|
|
|
}
|
|
|
|
|
2008-01-26 11:27:00 +03:00
|
|
|
if (adjust->line_no != -1) {
|
|
|
|
if (orig_sp - sp > 0) {
|
2011-08-24 10:31:15 +04:00
|
|
|
if (last_line != (unsigned int)adjust->line_no) {
|
2015-08-27 09:25:53 +03:00
|
|
|
line_info_table[line_info_index].line_no = last_line = adjust->line_no;
|
|
|
|
line_info_table[line_info_index].position = code_index;
|
|
|
|
line_info_index++;
|
2011-08-24 10:31:15 +04:00
|
|
|
}
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index++] = BIN(adjuststack);
|
|
|
|
generated_iseq[code_index++] = orig_sp - sp;
|
2008-01-26 11:27:00 +03:00
|
|
|
}
|
|
|
|
else if (orig_sp - sp == 0) {
|
|
|
|
/* jump to next insn */
|
2011-08-24 10:31:15 +04:00
|
|
|
if (last_line != (unsigned int)adjust->line_no) {
|
2015-08-27 09:25:53 +03:00
|
|
|
line_info_table[line_info_index].line_no = last_line = adjust->line_no;
|
|
|
|
line_info_table[line_info_index].position = code_index;
|
|
|
|
line_info_index++;
|
2011-08-24 10:31:15 +04:00
|
|
|
}
|
2015-08-27 09:25:53 +03:00
|
|
|
generated_iseq[code_index++] = BIN(nop);
|
|
|
|
generated_iseq[code_index++] = BIN(nop);
|
2008-01-26 11:27:00 +03:00
|
|
|
}
|
|
|
|
else {
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(iseq, adjust->line_no,
|
|
|
|
"iseq_set_sequence: adjust bug %d < %d",
|
|
|
|
orig_sp, sp);
|
2008-01-26 11:27:00 +03:00
|
|
|
}
|
2008-01-25 21:02:01 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->iseq_encoded = (void *)generated_iseq;
|
2015-08-27 09:25:53 +03:00
|
|
|
iseq->body->iseq_size = code_index;
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->stack_max = stack_max;
|
2007-06-30 22:04:35 +04:00
|
|
|
|
2015-08-27 09:25:53 +03:00
|
|
|
REALLOC_N(line_info_table, struct iseq_line_info_entry, line_info_index);
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->line_info_table = line_info_table;
|
2015-08-27 09:25:53 +03:00
|
|
|
iseq->body->line_info_size = line_info_index;
|
2011-08-24 10:31:15 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
label_get_position(LABEL *lobj)
|
|
|
|
{
|
|
|
|
return lobj->position;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
label_get_sp(LABEL *lobj)
|
|
|
|
{
|
|
|
|
return lobj->sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
iseq_set_exception_table(rb_iseq_t *iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2013-07-24 15:59:44 +04:00
|
|
|
const VALUE *tptr, *ptr;
|
2015-07-25 00:44:14 +03:00
|
|
|
unsigned int tlen, i;
|
2007-07-01 22:16:02 +04:00
|
|
|
struct iseq_catch_table_entry *entry;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
tlen = (int)RARRAY_LEN(ISEQ_COMPILE_DATA(iseq)->catch_table_ary);
|
|
|
|
tptr = RARRAY_CONST_PTR(ISEQ_COMPILE_DATA(iseq)->catch_table_ary);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-07-14 11:06:26 +04:00
|
|
|
if (tlen > 0) {
|
2015-07-24 22:49:16 +03:00
|
|
|
struct iseq_catch_table *table = xmalloc(iseq_catch_table_bytes(tlen));
|
|
|
|
table->size = tlen;
|
|
|
|
|
|
|
|
for (i = 0; i < table->size; i++) {
|
|
|
|
ptr = RARRAY_CONST_PTR(tptr[i]);
|
|
|
|
entry = &table->entries[i];
|
|
|
|
entry->type = (enum catch_type)(ptr[0] & 0xffff);
|
|
|
|
entry->start = label_get_position((LABEL *)(ptr[1] & ~1));
|
|
|
|
entry->end = label_get_position((LABEL *)(ptr[2] & ~1));
|
|
|
|
entry->iseq = (rb_iseq_t *)ptr[3];
|
|
|
|
|
|
|
|
/* register iseq as mark object */
|
|
|
|
if (entry->iseq != 0) {
|
|
|
|
iseq_add_mark_object(iseq, (VALUE)entry->iseq);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-07-24 22:49:16 +03:00
|
|
|
/* stack depth */
|
|
|
|
if (ptr[4]) {
|
|
|
|
LABEL *lobj = (LABEL *)(ptr[4] & ~1);
|
|
|
|
entry->cont = label_get_position(lobj);
|
|
|
|
entry->sp = label_get_sp(lobj);
|
|
|
|
|
|
|
|
/* TODO: Dirty Hack! Fix me */
|
|
|
|
if (entry->type == CATCH_TYPE_RESCUE ||
|
|
|
|
entry->type == CATCH_TYPE_BREAK ||
|
|
|
|
entry->type == CATCH_TYPE_NEXT) {
|
|
|
|
entry->sp--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
entry->cont = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2015-07-24 22:49:16 +03:00
|
|
|
iseq->body->catch_table = table;
|
2015-12-02 10:52:12 +03:00
|
|
|
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->catch_table_ary, 0); /* free */
|
2015-07-24 22:49:16 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
iseq->body->catch_table = NULL;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set optional argument table
|
|
|
|
* def foo(a, b=expr1, c=expr2)
|
|
|
|
* =>
|
|
|
|
* b:
|
|
|
|
* expr1
|
|
|
|
* c:
|
|
|
|
* expr2
|
|
|
|
*/
|
|
|
|
static int
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
iseq_set_optargs_table(rb_iseq_t *iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int i;
|
2015-07-24 23:58:09 +03:00
|
|
|
VALUE *opt_table = (VALUE *)iseq->body->param.opt_table;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->param.flags.has_opt) {
|
|
|
|
for (i = 0; i < iseq->body->param.opt_num + 1; i++) {
|
2015-07-24 23:58:09 +03:00
|
|
|
opt_table[i] = label_get_position((LABEL *)opt_table[i]);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LINK_ELEMENT *
|
|
|
|
get_destination_insn(INSN *iobj)
|
|
|
|
{
|
|
|
|
LABEL *lobj = (LABEL *)OPERAND_AT(iobj, 0);
|
|
|
|
LINK_ELEMENT *list;
|
|
|
|
|
|
|
|
list = lobj->link.next;
|
|
|
|
while (list) {
|
2016-04-23 14:39:41 +03:00
|
|
|
if (IS_INSN(list) || IS_ADJUST(list)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LINK_ELEMENT *
|
|
|
|
get_next_insn(INSN *iobj)
|
|
|
|
{
|
|
|
|
LINK_ELEMENT *list = iobj->link.next;
|
|
|
|
|
|
|
|
while (list) {
|
2016-04-23 14:39:41 +03:00
|
|
|
if (IS_INSN(list) || IS_ADJUST(list)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LINK_ELEMENT *
|
|
|
|
get_prev_insn(INSN *iobj)
|
|
|
|
{
|
|
|
|
LINK_ELEMENT *list = iobj->link.prev;
|
|
|
|
|
|
|
|
while (list) {
|
2016-04-23 14:39:41 +03:00
|
|
|
if (IS_INSN(list) || IS_ADJUST(list)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
list = list->prev;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-14 09:26:15 +03:00
|
|
|
static void
|
2016-01-01 09:28:58 +03:00
|
|
|
unref_destination(INSN *iobj, int pos)
|
2015-11-14 09:26:15 +03:00
|
|
|
{
|
2016-01-01 09:28:58 +03:00
|
|
|
LABEL *lobj = (LABEL *)OPERAND_AT(iobj, pos);
|
2015-11-14 09:26:15 +03:00
|
|
|
--lobj->refcnt;
|
|
|
|
if (!lobj->refcnt) REMOVE_ELEM(&lobj->link);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
replace_destination(INSN *dobj, INSN *nobj)
|
|
|
|
{
|
|
|
|
VALUE n = OPERAND_AT(nobj, 0);
|
|
|
|
LABEL *dl = (LABEL *)OPERAND_AT(dobj, 0);
|
|
|
|
LABEL *nl = (LABEL *)n;
|
|
|
|
--dl->refcnt;
|
|
|
|
++nl->refcnt;
|
|
|
|
OPERAND_AT(dobj, 0) = n;
|
|
|
|
if (!dl->refcnt) REMOVE_ELEM(&dl->link);
|
|
|
|
}
|
|
|
|
|
2015-11-22 10:53:37 +03:00
|
|
|
static int
|
2016-01-01 09:28:58 +03:00
|
|
|
remove_unreachable_chunk(rb_iseq_t *iseq, LINK_ELEMENT *i)
|
2015-11-22 10:53:37 +03:00
|
|
|
{
|
|
|
|
int removed = 0;
|
|
|
|
while (i) {
|
2016-04-23 14:39:41 +03:00
|
|
|
if (IS_INSN(i)) {
|
2016-01-01 09:28:58 +03:00
|
|
|
struct rb_iseq_constant_body *body = iseq->body;
|
|
|
|
VALUE insn = INSN_OF(i);
|
|
|
|
int pos, len = insn_len(insn);
|
|
|
|
for (pos = 0; pos < len; ++pos) {
|
|
|
|
switch (insn_op_types(insn)[pos]) {
|
|
|
|
case TS_OFFSET:
|
|
|
|
unref_destination((INSN *)i, pos);
|
|
|
|
break;
|
|
|
|
case TS_CALLINFO:
|
|
|
|
if (((struct rb_call_info *)OPERAND_AT(i, pos))->flag & VM_CALL_KWARG)
|
|
|
|
--(body->ci_kw_size);
|
|
|
|
else
|
|
|
|
--(body->ci_size);
|
|
|
|
break;
|
|
|
|
}
|
2015-11-22 10:53:37 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-23 14:39:41 +03:00
|
|
|
else if (IS_LABEL(i)) {
|
2016-01-01 06:05:55 +03:00
|
|
|
if (((LABEL *)i)->refcnt > 0) break;
|
|
|
|
}
|
2015-11-22 10:53:37 +03:00
|
|
|
else break;
|
|
|
|
REMOVE_ELEM(i);
|
|
|
|
removed = 1;
|
|
|
|
i = i->next;
|
|
|
|
}
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2007-05-21 08:46:51 +04:00
|
|
|
iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcallopt)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
INSN *iobj = (INSN *)list;
|
|
|
|
again:
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(iobj, jump)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
INSN *niobj, *diobj, *piobj;
|
|
|
|
/*
|
|
|
|
* useless jump elimination:
|
|
|
|
* jump LABEL1
|
|
|
|
* ...
|
|
|
|
* LABEL1:
|
|
|
|
* jump LABEL2
|
|
|
|
*
|
2008-12-24 16:01:09 +03:00
|
|
|
* => in this case, first jump instruction should jump to
|
2006-12-31 18:02:22 +03:00
|
|
|
* LABEL2 directly
|
|
|
|
*/
|
|
|
|
diobj = (INSN *)get_destination_insn(iobj);
|
|
|
|
niobj = (INSN *)get_next_insn(iobj);
|
|
|
|
|
|
|
|
if (diobj == niobj) {
|
2007-05-21 08:46:51 +04:00
|
|
|
/*
|
|
|
|
* jump LABEL
|
|
|
|
* LABEL:
|
|
|
|
* =>
|
|
|
|
* LABEL:
|
|
|
|
*/
|
2016-01-01 09:28:58 +03:00
|
|
|
unref_destination(iobj, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
REMOVE_ELEM(&iobj->link);
|
|
|
|
}
|
2016-04-23 14:43:52 +03:00
|
|
|
else if (iobj != diobj && IS_INSN_ID(diobj, jump) &&
|
2015-11-22 10:53:37 +03:00
|
|
|
OPERAND_AT(iobj, 0) != OPERAND_AT(diobj, 0)) {
|
|
|
|
replace_destination(iobj, diobj);
|
2016-01-01 09:28:58 +03:00
|
|
|
remove_unreachable_chunk(iseq, iobj->link.next);
|
2015-11-22 10:53:37 +03:00
|
|
|
goto again;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2016-04-23 14:43:52 +03:00
|
|
|
else if (IS_INSN_ID(diobj, leave)) {
|
2007-05-21 08:46:51 +04:00
|
|
|
/*
|
|
|
|
* jump LABEL
|
|
|
|
* ...
|
|
|
|
* LABEL:
|
|
|
|
* leave
|
|
|
|
* =>
|
|
|
|
* leave
|
|
|
|
* ...
|
|
|
|
* LABEL:
|
|
|
|
* leave
|
|
|
|
*/
|
2008-01-26 11:27:00 +03:00
|
|
|
INSN *popiobj = new_insn_core(iseq, iobj->line_no,
|
|
|
|
BIN(pop), 0, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
/* replace */
|
2016-01-01 09:28:58 +03:00
|
|
|
unref_destination(iobj, 0);
|
2016-04-18 10:07:03 +03:00
|
|
|
iobj->insn_id = BIN(leave);
|
|
|
|
iobj->operand_size = 0;
|
|
|
|
INSERT_ELEM_NEXT(&iobj->link, &popiobj->link);
|
2015-11-16 11:40:42 +03:00
|
|
|
goto again;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* useless jump elimination (if/unless destination):
|
|
|
|
* if L1
|
|
|
|
* jump L2
|
|
|
|
* L1:
|
|
|
|
* ...
|
|
|
|
* L2:
|
|
|
|
*
|
|
|
|
* ==>
|
|
|
|
* unless L2
|
|
|
|
* L1:
|
|
|
|
* ...
|
|
|
|
* L2:
|
|
|
|
*/
|
|
|
|
else if ((piobj = (INSN *)get_prev_insn(iobj)) != 0 &&
|
2016-04-23 14:43:52 +03:00
|
|
|
(IS_INSN_ID(piobj, branchif) ||
|
|
|
|
IS_INSN_ID(piobj, branchunless))) {
|
2006-12-31 18:02:22 +03:00
|
|
|
if (niobj == (INSN *)get_destination_insn(piobj)) {
|
2016-04-23 14:43:52 +03:00
|
|
|
piobj->insn_id = (IS_INSN_ID(piobj, branchif))
|
2007-04-05 12:58:46 +04:00
|
|
|
? BIN(branchunless) : BIN(branchif);
|
2015-11-14 09:26:15 +03:00
|
|
|
replace_destination(piobj, iobj);
|
2006-12-31 18:02:22 +03:00
|
|
|
REMOVE_ELEM(&iobj->link);
|
|
|
|
}
|
|
|
|
}
|
2016-01-01 09:28:58 +03:00
|
|
|
else if (remove_unreachable_chunk(iseq, iobj->link.next)) {
|
2015-11-22 10:53:37 +03:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(iobj, leave)) {
|
2016-01-01 09:28:58 +03:00
|
|
|
remove_unreachable_chunk(iseq, iobj->link.next);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-05-21 08:46:51 +04:00
|
|
|
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(iobj, branchif) ||
|
|
|
|
IS_INSN_ID(iobj, branchnil) ||
|
|
|
|
IS_INSN_ID(iobj, branchunless)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* if L1
|
|
|
|
* ...
|
|
|
|
* L1:
|
|
|
|
* jump L2
|
|
|
|
* =>
|
|
|
|
* if L2
|
|
|
|
*/
|
|
|
|
INSN *nobj = (INSN *)get_destination_insn(iobj);
|
2015-10-23 05:58:22 +03:00
|
|
|
INSN *pobj = (INSN *)iobj->link.prev;
|
2015-11-18 05:08:17 +03:00
|
|
|
int prev_dup = 0;
|
|
|
|
if (pobj) {
|
2016-04-23 14:39:41 +03:00
|
|
|
if (!IS_INSN(&pobj->link))
|
2015-11-18 05:08:17 +03:00
|
|
|
pobj = 0;
|
2016-04-23 14:43:52 +03:00
|
|
|
else if (IS_INSN_ID(pobj, dup))
|
2015-11-18 05:08:17 +03:00
|
|
|
prev_dup = 1;
|
|
|
|
}
|
2015-10-22 09:30:12 +03:00
|
|
|
|
2015-10-23 05:58:22 +03:00
|
|
|
for (;;) {
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(nobj, jump)) {
|
2015-11-14 09:26:15 +03:00
|
|
|
replace_destination(iobj, nobj);
|
2015-10-23 05:58:22 +03:00
|
|
|
}
|
2016-04-23 14:43:52 +03:00
|
|
|
else if (prev_dup && IS_INSN_ID(nobj, dup) &&
|
2015-10-23 05:58:22 +03:00
|
|
|
!!(nobj = (INSN *)nobj->link.next) &&
|
|
|
|
/* basic blocks, with no labels in the middle */
|
|
|
|
nobj->insn_id == iobj->insn_id) {
|
|
|
|
/*
|
|
|
|
* dup
|
|
|
|
* if L1
|
|
|
|
* ...
|
|
|
|
* L1:
|
|
|
|
* dup
|
|
|
|
* if L2
|
|
|
|
* =>
|
|
|
|
* dup
|
|
|
|
* if L2
|
|
|
|
* ...
|
|
|
|
* L1:
|
|
|
|
* dup
|
|
|
|
* if L2
|
|
|
|
*/
|
2015-11-14 09:26:15 +03:00
|
|
|
replace_destination(iobj, nobj);
|
2015-10-22 09:30:12 +03:00
|
|
|
}
|
2015-11-18 05:32:17 +03:00
|
|
|
else if (pobj) {
|
2015-11-18 10:09:27 +03:00
|
|
|
/*
|
|
|
|
* putnil
|
|
|
|
* if L1
|
|
|
|
* =>
|
|
|
|
* # nothing
|
|
|
|
*
|
|
|
|
* putobject true
|
|
|
|
* if L1
|
|
|
|
* =>
|
|
|
|
* jump L1
|
|
|
|
*
|
|
|
|
* putstring ".."
|
|
|
|
* if L1
|
|
|
|
* =>
|
|
|
|
* jump L1
|
|
|
|
*
|
2015-11-22 10:37:13 +03:00
|
|
|
* putstring ".."
|
|
|
|
* dup
|
|
|
|
* if L1
|
|
|
|
* =>
|
|
|
|
* putstring ".."
|
|
|
|
* jump L1
|
|
|
|
*
|
2015-11-18 10:09:27 +03:00
|
|
|
*/
|
2015-11-18 05:32:17 +03:00
|
|
|
int cond;
|
2016-04-23 14:39:41 +03:00
|
|
|
if (prev_dup && IS_INSN(pobj->link.prev)) {
|
2015-11-22 10:37:13 +03:00
|
|
|
pobj = (INSN *)pobj->link.prev;
|
|
|
|
}
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(pobj, putobject)) {
|
|
|
|
cond = (IS_INSN_ID(iobj, branchif) ?
|
2015-11-18 05:32:17 +03:00
|
|
|
OPERAND_AT(pobj, 0) != Qfalse :
|
2016-04-23 14:43:52 +03:00
|
|
|
IS_INSN_ID(iobj, branchunless) ?
|
2015-11-18 05:32:17 +03:00
|
|
|
OPERAND_AT(pobj, 0) == Qfalse :
|
|
|
|
FALSE);
|
|
|
|
}
|
2016-04-23 14:43:52 +03:00
|
|
|
else if (IS_INSN_ID(pobj, putstring)) {
|
|
|
|
cond = IS_INSN_ID(iobj, branchif);
|
2015-11-18 05:32:17 +03:00
|
|
|
}
|
2016-04-23 14:43:52 +03:00
|
|
|
else if (IS_INSN_ID(pobj, putnil)) {
|
|
|
|
cond = !IS_INSN_ID(iobj, branchif);
|
2015-11-18 05:32:17 +03:00
|
|
|
}
|
|
|
|
else break;
|
2015-11-22 10:37:13 +03:00
|
|
|
REMOVE_ELEM(iobj->link.prev);
|
2015-11-18 05:32:17 +03:00
|
|
|
if (cond) {
|
|
|
|
iobj->insn_id = BIN(jump);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
else {
|
2016-01-01 09:28:58 +03:00
|
|
|
unref_destination(iobj, 0);
|
2015-11-18 05:32:17 +03:00
|
|
|
REMOVE_ELEM(&iobj->link);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-10-23 05:58:22 +03:00
|
|
|
else break;
|
|
|
|
nobj = (INSN *)get_destination_insn(nobj);
|
2015-10-22 09:30:12 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(iobj, pop)) {
|
2015-11-11 12:38:20 +03:00
|
|
|
/*
|
|
|
|
* putself / putnil / putobject obj / putstring "..."
|
|
|
|
* pop
|
|
|
|
* =>
|
|
|
|
* # do nothing
|
|
|
|
*/
|
2015-11-10 06:45:10 +03:00
|
|
|
LINK_ELEMENT *prev = iobj->link.prev;
|
2016-04-23 14:39:41 +03:00
|
|
|
if (IS_INSN(prev)) {
|
2015-11-10 06:45:10 +03:00
|
|
|
enum ruby_vminsn_type previ = ((INSN *)prev)->insn_id;
|
|
|
|
if (previ == BIN(putobject) || previ == BIN(putnil) ||
|
|
|
|
previ == BIN(putself) || previ == BIN(putstring)) {
|
2015-11-11 12:38:20 +03:00
|
|
|
/* just push operand or static value and pop soon, no
|
|
|
|
* side effects */
|
2015-11-10 06:45:10 +03:00
|
|
|
REMOVE_ELEM(prev);
|
|
|
|
REMOVE_ELEM(&iobj->link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-19 08:12:14 +03:00
|
|
|
if (do_tailcallopt &&
|
2016-04-23 14:43:52 +03:00
|
|
|
(IS_INSN_ID(iobj, send) ||
|
|
|
|
IS_INSN_ID(iobj, opt_aref_with) ||
|
|
|
|
IS_INSN_ID(iobj, opt_aset_with) ||
|
|
|
|
IS_INSN_ID(iobj, invokesuper))) {
|
2007-05-21 08:46:51 +04:00
|
|
|
/*
|
|
|
|
* send ...
|
|
|
|
* leave
|
|
|
|
* =>
|
2012-10-15 21:22:57 +04:00
|
|
|
* send ..., ... | VM_CALL_TAILCALL, ...
|
2007-05-21 08:46:51 +04:00
|
|
|
* leave # unreachable
|
|
|
|
*/
|
2015-11-19 08:12:14 +03:00
|
|
|
INSN *piobj = NULL;
|
|
|
|
if (iobj->link.next) {
|
|
|
|
LINK_ELEMENT *next = iobj->link.next;
|
|
|
|
do {
|
2016-04-23 14:39:41 +03:00
|
|
|
if (!IS_INSN(next)) {
|
2015-11-19 08:12:14 +03:00
|
|
|
next = next->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (INSN_OF(next)) {
|
|
|
|
case BIN(nop):
|
|
|
|
/*case BIN(trace):*/
|
|
|
|
next = next->next;
|
|
|
|
break;
|
2016-09-23 06:15:31 +03:00
|
|
|
case BIN(jump):
|
|
|
|
/* if cond
|
|
|
|
* return tailcall
|
|
|
|
* end
|
|
|
|
*/
|
|
|
|
next = get_destination_insn((INSN *)next);
|
|
|
|
break;
|
2015-11-19 08:12:14 +03:00
|
|
|
case BIN(leave):
|
|
|
|
piobj = iobj;
|
|
|
|
default:
|
|
|
|
next = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (next);
|
|
|
|
}
|
2007-05-21 08:46:51 +04:00
|
|
|
|
2015-11-19 08:12:14 +03:00
|
|
|
if (piobj) {
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info *ci = (struct rb_call_info *)piobj->operands[0];
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(piobj, send) || IS_INSN_ID(piobj, invokesuper)) {
|
2016-01-26 09:14:59 +03:00
|
|
|
if (piobj->operands[2] == 0) { /* no blockiseq */
|
|
|
|
ci->flag |= VM_CALL_TAILCALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-10-15 21:22:57 +04:00
|
|
|
ci->flag |= VM_CALL_TAILCALL;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-23 17:12:27 +03:00
|
|
|
|
|
|
|
#define IS_TRACE_LINE(insn) \
|
|
|
|
(IS_INSN_ID(insn, trace) && \
|
|
|
|
OPERAND_AT(insn, 0) == INT2FIX(RUBY_EVENT_LINE))
|
|
|
|
if (IS_TRACE_LINE(iobj) && iobj->link.prev && IS_INSN(iobj->link.prev)) {
|
|
|
|
INSN *piobj = (INSN *)iobj->link.prev;
|
|
|
|
if (IS_TRACE_LINE(piobj)) {
|
|
|
|
REMOVE_ELEM(iobj->link.prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-24 20:06:15 +03:00
|
|
|
insn_set_specialized_instruction(rb_iseq_t *iseq, INSN *iobj, int insn_id)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
iobj->insn_id = insn_id;
|
2010-02-24 20:06:15 +03:00
|
|
|
iobj->operand_size = insn_len(insn_id) - 1;
|
|
|
|
|
2015-09-08 11:21:07 +03:00
|
|
|
if (insn_id == BIN(opt_neq)) {
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
VALUE *old_operands = iobj->operands;
|
2015-09-19 20:59:58 +03:00
|
|
|
iobj->operand_size = 4;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
iobj->operands = (VALUE *)compile_data_alloc(iseq, iobj->operand_size * sizeof(VALUE));
|
|
|
|
iobj->operands[0] = old_operands[0];
|
2015-09-19 20:59:58 +03:00
|
|
|
iobj->operands[1] = Qfalse; /* CALL_CACHE */
|
|
|
|
iobj->operands[2] = (VALUE)new_callinfo(iseq, idEq, 1, 0, NULL, FALSE);
|
|
|
|
iobj->operands[3] = Qfalse; /* CALL_CACHE */
|
2010-02-24 20:06:15 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(iobj, newarray) && iobj->link.next &&
|
2016-04-23 14:39:41 +03:00
|
|
|
IS_INSN(iobj->link.next)) {
|
2016-03-17 16:08:35 +03:00
|
|
|
/*
|
|
|
|
* [a, b, ...].max/min -> a, b, c, opt_newarray_max/min
|
|
|
|
*/
|
2016-03-17 16:19:02 +03:00
|
|
|
INSN *niobj = (INSN *)iobj->link.next;
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(niobj, send)) {
|
2016-03-17 16:08:35 +03:00
|
|
|
struct rb_call_info *ci = (struct rb_call_info *)OPERAND_AT(niobj, 0);
|
|
|
|
if ((ci->flag & VM_CALL_ARGS_SIMPLE) && ci->orig_argc == 0) {
|
|
|
|
switch (ci->mid) {
|
|
|
|
case idMax:
|
|
|
|
iobj->insn_id = BIN(opt_newarray_max);
|
|
|
|
REMOVE_ELEM(&niobj->link);
|
|
|
|
return COMPILE_OK;
|
|
|
|
case idMin:
|
|
|
|
iobj->insn_id = BIN(opt_newarray_min);
|
|
|
|
REMOVE_ELEM(&niobj->link);
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-23 14:43:52 +03:00
|
|
|
if (IS_INSN_ID(iobj, send)) {
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info *ci = (struct rb_call_info *)OPERAND_AT(iobj, 0);
|
|
|
|
const rb_iseq_t *blockiseq = (rb_iseq_t *)OPERAND_AT(iobj, 2);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-03-19 10:20:55 +04:00
|
|
|
#define SP_INSN(opt) insn_set_specialized_instruction(iseq, iobj, BIN(opt_##opt))
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
if (ci->flag & VM_CALL_ARGS_SIMPLE) {
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
switch (ci->orig_argc) {
|
2012-03-19 10:20:55 +04:00
|
|
|
case 0:
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
switch (ci->mid) {
|
2012-10-18 12:35:19 +04:00
|
|
|
case idLength: SP_INSN(length); return COMPILE_OK;
|
|
|
|
case idSize: SP_INSN(size); return COMPILE_OK;
|
|
|
|
case idEmptyP: SP_INSN(empty_p);return COMPILE_OK;
|
|
|
|
case idSucc: SP_INSN(succ); return COMPILE_OK;
|
|
|
|
case idNot: SP_INSN(not); return COMPILE_OK;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2012-03-19 10:20:55 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
switch (ci->mid) {
|
2012-10-18 12:35:19 +04:00
|
|
|
case idPLUS: SP_INSN(plus); return COMPILE_OK;
|
|
|
|
case idMINUS: SP_INSN(minus); return COMPILE_OK;
|
|
|
|
case idMULT: SP_INSN(mult); return COMPILE_OK;
|
|
|
|
case idDIV: SP_INSN(div); return COMPILE_OK;
|
|
|
|
case idMOD: SP_INSN(mod); return COMPILE_OK;
|
|
|
|
case idEq: SP_INSN(eq); return COMPILE_OK;
|
|
|
|
case idNeq: SP_INSN(neq); return COMPILE_OK;
|
|
|
|
case idLT: SP_INSN(lt); return COMPILE_OK;
|
|
|
|
case idLE: SP_INSN(le); return COMPILE_OK;
|
|
|
|
case idGT: SP_INSN(gt); return COMPILE_OK;
|
|
|
|
case idGE: SP_INSN(ge); return COMPILE_OK;
|
|
|
|
case idLTLT: SP_INSN(ltlt); return COMPILE_OK;
|
|
|
|
case idAREF: SP_INSN(aref); return COMPILE_OK;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2012-03-19 10:20:55 +04:00
|
|
|
break;
|
2013-12-11 10:38:42 +04:00
|
|
|
case 2:
|
|
|
|
switch (ci->mid) {
|
|
|
|
case idASET: SP_INSN(aset); return COMPILE_OK;
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2012-12-03 15:33:09 +04:00
|
|
|
}
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
|
2015-09-08 11:21:07 +03:00
|
|
|
if ((ci->flag & VM_CALL_ARGS_BLOCKARG) == 0 && blockiseq == NULL) {
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
iobj->insn_id = BIN(opt_send_without_block);
|
2015-09-19 20:59:58 +03:00
|
|
|
iobj->operand_size = insn_len(iobj->insn_id) - 1;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2012-03-19 10:20:55 +04:00
|
|
|
#undef SP_INSN
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
|
|
|
|
return COMPILE_OK;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2016-04-11 11:43:06 +03:00
|
|
|
static inline int
|
|
|
|
tailcallable_p(rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
switch (iseq->body->type) {
|
2016-11-05 19:42:27 +03:00
|
|
|
case ISEQ_TYPE_TOP:
|
|
|
|
case ISEQ_TYPE_EVAL:
|
|
|
|
case ISEQ_TYPE_MAIN:
|
|
|
|
/* not tail callable because cfp will be over popped */
|
2016-04-11 11:43:06 +03:00
|
|
|
case ISEQ_TYPE_RESCUE:
|
|
|
|
case ISEQ_TYPE_ENSURE:
|
|
|
|
/* rescue block can't tail call because of errinfo */
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
iseq_optimize(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
LINK_ELEMENT *list;
|
2015-12-02 10:52:12 +03:00
|
|
|
const int do_peepholeopt = ISEQ_COMPILE_DATA(iseq)->option->peephole_optimization;
|
2016-04-11 11:43:06 +03:00
|
|
|
const int do_tailcallopt = tailcallable_p(iseq) &&
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->option->tailcall_optimization;
|
2015-12-02 10:52:12 +03:00
|
|
|
const int do_si = ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction;
|
|
|
|
const int do_ou = ISEQ_COMPILE_DATA(iseq)->option->operands_unification;
|
2016-04-11 11:43:06 +03:00
|
|
|
int rescue_level = 0;
|
|
|
|
int tailcallopt = do_tailcallopt;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
list = FIRST_ELEMENT(anchor);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
while (list) {
|
2016-04-23 14:39:41 +03:00
|
|
|
if (IS_INSN(list)) {
|
2007-05-21 08:46:51 +04:00
|
|
|
if (do_peepholeopt) {
|
2016-04-11 11:43:06 +03:00
|
|
|
iseq_peephole_optimize(iseq, list, tailcallopt);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
if (do_si) {
|
|
|
|
iseq_specialized_instruction(iseq, (INSN *)list);
|
|
|
|
}
|
|
|
|
if (do_ou) {
|
|
|
|
insn_operands_unification((INSN *)list);
|
|
|
|
}
|
|
|
|
}
|
2016-04-23 14:39:41 +03:00
|
|
|
if (IS_LABEL(list)) {
|
2016-04-11 11:43:06 +03:00
|
|
|
switch (((LABEL *)list)->rescued) {
|
|
|
|
case LABEL_RESCUE_BEG:
|
|
|
|
rescue_level++;
|
|
|
|
tailcallopt = FALSE;
|
|
|
|
break;
|
|
|
|
case LABEL_RESCUE_END:
|
|
|
|
if (!--rescue_level) tailcallopt = do_tailcallopt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if OPT_INSTRUCTIONS_UNIFICATION
|
|
|
|
static INSN *
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
new_unified_insn(rb_iseq_t *iseq,
|
2006-12-31 18:02:22 +03:00
|
|
|
int insn_id, int size, LINK_ELEMENT *seq_list)
|
|
|
|
{
|
|
|
|
INSN *iobj = 0;
|
|
|
|
LINK_ELEMENT *list = seq_list;
|
|
|
|
int i, argc = 0;
|
|
|
|
VALUE *operands = 0, *ptr = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* count argc */
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
iobj = (INSN *)list;
|
|
|
|
argc += iobj->operand_size;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
ptr = operands =
|
|
|
|
(VALUE *)compile_data_alloc(iseq, sizeof(VALUE) * argc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy operands */
|
|
|
|
list = seq_list;
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
iobj = (INSN *)list;
|
|
|
|
MEMCPY(ptr, iobj->operands, VALUE, iobj->operand_size);
|
|
|
|
ptr += iobj->operand_size;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_insn_core(iseq, iobj->line_no, insn_id, argc, operands);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This scheme can get more performance if do this optimize with
|
|
|
|
* label address resolving.
|
|
|
|
* It's future work (if compile time was bottle neck).
|
|
|
|
*/
|
|
|
|
static int
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
iseq_insns_unification(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
#if OPT_INSTRUCTIONS_UNIFICATION
|
|
|
|
LINK_ELEMENT *list;
|
|
|
|
INSN *iobj, *niobj;
|
2010-01-20 10:12:16 +03:00
|
|
|
int id, k;
|
|
|
|
intptr_t j;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
list = FIRST_ELEMENT(anchor);
|
|
|
|
while (list) {
|
2016-04-23 14:39:41 +03:00
|
|
|
if (IS_INSN(list)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
iobj = (INSN *)list;
|
|
|
|
id = iobj->insn_id;
|
|
|
|
if (unified_insns_data[id] != 0) {
|
2008-04-03 04:00:48 +04:00
|
|
|
const int *const *entry = unified_insns_data[id];
|
2010-01-20 10:12:16 +03:00
|
|
|
for (j = 1; j < (intptr_t)entry[0]; j++) {
|
2008-04-03 04:00:48 +04:00
|
|
|
const int *unified = entry[j];
|
2006-12-31 18:02:22 +03:00
|
|
|
LINK_ELEMENT *li = list->next;
|
|
|
|
for (k = 2; k < unified[1]; k++) {
|
2016-04-23 14:39:41 +03:00
|
|
|
if (!IS_INSN(li) ||
|
2006-12-31 18:02:22 +03:00
|
|
|
((INSN *)li)->insn_id != unified[k]) {
|
|
|
|
goto miss;
|
|
|
|
}
|
|
|
|
li = li->next;
|
|
|
|
}
|
|
|
|
/* matched */
|
|
|
|
niobj =
|
|
|
|
new_unified_insn(iseq, unified[0], unified[1] - 1,
|
|
|
|
list);
|
|
|
|
|
|
|
|
/* insert to list */
|
|
|
|
niobj->link.prev = (LINK_ELEMENT *)iobj->link.prev;
|
|
|
|
niobj->link.next = li;
|
|
|
|
if (li) {
|
|
|
|
li->prev = (LINK_ELEMENT *)niobj;
|
|
|
|
}
|
|
|
|
|
|
|
|
list->prev->next = (LINK_ELEMENT *)niobj;
|
|
|
|
list = (LINK_ELEMENT *)niobj;
|
|
|
|
break;
|
|
|
|
miss:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if OPT_STACK_CACHING
|
|
|
|
|
|
|
|
#define SC_INSN(insn, stat) sc_insn_info[(insn)][(stat)]
|
2010-12-03 00:53:08 +03:00
|
|
|
#define SC_NEXT(insn) sc_insn_next[(insn)]
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
#include "opt_sc.inc"
|
|
|
|
|
|
|
|
static int
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
insn_set_sc_state(rb_iseq_t *iseq, INSN *iobj, int state)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int nstate;
|
|
|
|
int insn_id;
|
|
|
|
|
|
|
|
insn_id = iobj->insn_id;
|
|
|
|
iobj->insn_id = SC_INSN(insn_id, state);
|
|
|
|
nstate = SC_NEXT(iobj->insn_id);
|
|
|
|
|
|
|
|
if (insn_id == BIN(jump) ||
|
|
|
|
insn_id == BIN(branchif) || insn_id == BIN(branchunless)) {
|
|
|
|
LABEL *lobj = (LABEL *)OPERAND_AT(iobj, 0);
|
|
|
|
|
|
|
|
if (lobj->sc_state != 0) {
|
|
|
|
if (lobj->sc_state != nstate) {
|
|
|
|
dump_disasm_list((LINK_ELEMENT *)iobj);
|
|
|
|
dump_disasm_list((LINK_ELEMENT *)lobj);
|
|
|
|
printf("\n-- %d, %d\n", lobj->sc_state, nstate);
|
2016-04-19 07:46:20 +03:00
|
|
|
COMPILE_ERROR(iseq, iobj->line_no,
|
2015-12-04 20:28:26 +03:00
|
|
|
"insn_set_sc_state error\n");
|
2015-11-22 09:32:23 +03:00
|
|
|
return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lobj->sc_state = nstate;
|
|
|
|
}
|
|
|
|
if (insn_id == BIN(jump)) {
|
|
|
|
nstate = SCS_XX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (insn_id == BIN(leave)) {
|
|
|
|
nstate = SCS_XX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nstate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
label_set_sc_state(LABEL *lobj, int state)
|
|
|
|
{
|
|
|
|
if (lobj->sc_state != 0) {
|
|
|
|
if (lobj->sc_state != state) {
|
|
|
|
state = lobj->sc_state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lobj->sc_state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
iseq_set_sequence_stackcaching(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
#if OPT_STACK_CACHING
|
|
|
|
LINK_ELEMENT *list;
|
|
|
|
int state, insn_id;
|
|
|
|
|
|
|
|
/* initialize */
|
|
|
|
state = SCS_XX;
|
|
|
|
list = FIRST_ELEMENT(anchor);
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* dump_disasm_list(list); */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/* for each list element */
|
|
|
|
while (list) {
|
|
|
|
redo_point:
|
|
|
|
switch (list->type) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_INSN:
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
INSN *iobj = (INSN *)list;
|
|
|
|
insn_id = iobj->insn_id;
|
|
|
|
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* dump_disasm_list(list); */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
switch (insn_id) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case BIN(nop):
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
/* exception merge point */
|
|
|
|
if (state != SCS_AX) {
|
|
|
|
INSN *rpobj =
|
|
|
|
new_insn_body(iseq, 0, BIN(reput), 0);
|
|
|
|
|
|
|
|
/* replace this insn */
|
|
|
|
REPLACE_ELEM(list, (LINK_ELEMENT *)rpobj);
|
|
|
|
list = (LINK_ELEMENT *)rpobj;
|
|
|
|
goto redo_point;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case BIN(swap):
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
if (state == SCS_AB || state == SCS_BA) {
|
|
|
|
state = (state == SCS_AB ? SCS_BA : SCS_AB);
|
|
|
|
|
|
|
|
REMOVE_ELEM(list);
|
|
|
|
list = list->next;
|
|
|
|
goto redo_point;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case BIN(pop):
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
switch (state) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case SCS_AX:
|
|
|
|
case SCS_BX:
|
2006-12-31 18:02:22 +03:00
|
|
|
state = SCS_XX;
|
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case SCS_AB:
|
2006-12-31 18:02:22 +03:00
|
|
|
state = SCS_AX;
|
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case SCS_BA:
|
2006-12-31 18:02:22 +03:00
|
|
|
state = SCS_BX;
|
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case SCS_XX:
|
2006-12-31 18:02:22 +03:00
|
|
|
goto normal_insn;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
default:
|
2016-04-19 07:46:20 +03:00
|
|
|
COMPILE_ERROR(iseq, iobj->line_no,
|
2015-12-04 20:28:26 +03:00
|
|
|
"unreachable");
|
2015-11-22 09:32:23 +03:00
|
|
|
return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
/* remove useless pop */
|
|
|
|
REMOVE_ELEM(list);
|
|
|
|
list = list->next;
|
|
|
|
goto redo_point;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
default:;
|
2006-12-31 18:02:22 +03:00
|
|
|
/* none */
|
|
|
|
} /* end of switch */
|
|
|
|
normal_insn:
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
state = insn_set_sc_state(iseq, iobj, state);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_LABEL:
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
LABEL *lobj;
|
|
|
|
lobj = (LABEL *)list;
|
|
|
|
|
|
|
|
state = label_set_sc_state(lobj, state);
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-10-17 03:38:58 +04:00
|
|
|
compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int *cntp)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
NODE *list = node->nd_next;
|
|
|
|
VALUE lit = node->nd_lit;
|
2015-09-29 10:37:40 +03:00
|
|
|
LINK_ELEMENT *first_lit = 0;
|
2009-07-20 14:01:05 +04:00
|
|
|
int cnt = 0;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
debugp_param("nd_lit", lit);
|
2009-07-20 14:01:05 +04:00
|
|
|
if (!NIL_P(lit)) {
|
|
|
|
cnt++;
|
2015-10-05 20:29:04 +03:00
|
|
|
if (!RB_TYPE_P(lit, T_STRING)) {
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS "dstr: must be string: %s",
|
|
|
|
rb_builtin_type_name(TYPE(lit)));
|
2015-10-05 20:29:04 +03:00
|
|
|
}
|
|
|
|
lit = node->nd_lit = rb_fstring(lit);
|
2009-07-20 14:01:05 +04:00
|
|
|
ADD_INSN1(ret, nd_line(node), putobject, lit);
|
2015-09-29 10:37:40 +03:00
|
|
|
if (RSTRING_LEN(lit) == 0) first_lit = LAST_ELEMENT(ret);
|
2009-07-20 14:01:05 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
while (list) {
|
2012-10-17 03:38:58 +04:00
|
|
|
node = list->nd_head;
|
|
|
|
if (nd_type(node) == NODE_STR) {
|
2013-11-27 03:30:25 +04:00
|
|
|
node->nd_lit = rb_fstring(node->nd_lit);
|
2012-10-17 03:38:58 +04:00
|
|
|
ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit);
|
2015-09-29 10:37:40 +03:00
|
|
|
lit = Qnil;
|
2012-10-17 03:38:58 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
COMPILE(ret, "each string", node);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
cnt++;
|
|
|
|
list = list->nd_next;
|
|
|
|
}
|
2015-09-29 10:37:40 +03:00
|
|
|
if (NIL_P(lit) && first_lit) {
|
|
|
|
REMOVE_ELEM(first_lit);
|
|
|
|
--cnt;
|
|
|
|
}
|
2008-01-29 11:03:51 +03:00
|
|
|
*cntp = cnt;
|
|
|
|
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-01-29 11:03:51 +03:00
|
|
|
static int
|
|
|
|
compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node)
|
|
|
|
{
|
|
|
|
int cnt;
|
|
|
|
compile_dstr_fragments(iseq, ret, node, &cnt);
|
2006-12-31 18:02:22 +03:00
|
|
|
ADD_INSN1(ret, nd_line(node), concatstrings, INT2FIX(cnt));
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-29 11:03:51 +03:00
|
|
|
static int
|
|
|
|
compile_dregx(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node)
|
|
|
|
{
|
|
|
|
int cnt;
|
|
|
|
compile_dstr_fragments(iseq, ret, node, &cnt);
|
|
|
|
ADD_INSN2(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag), INT2FIX(cnt));
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2016-10-01 13:19:36 +03:00
|
|
|
static int
|
|
|
|
compile_flip_flop(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int again,
|
|
|
|
LABEL *then_label, LABEL *else_label)
|
|
|
|
{
|
|
|
|
const int line = nd_line(node);
|
|
|
|
LABEL *lend = NEW_LABEL(line);
|
|
|
|
rb_num_t cnt = ISEQ_FLIP_CNT_INCREMENT(iseq->body->local_iseq)
|
|
|
|
+ VM_SVAR_FLIPFLOP_START;
|
|
|
|
VALUE key = INT2FIX(cnt);
|
|
|
|
|
|
|
|
ADD_INSN2(ret, line, getspecial, key, INT2FIX(0));
|
|
|
|
ADD_INSNL(ret, line, branchif, lend);
|
|
|
|
|
|
|
|
/* *flip == 0 */
|
|
|
|
COMPILE(ret, "flip2 beg", node->nd_beg);
|
|
|
|
ADD_INSNL(ret, line, branchunless, else_label);
|
|
|
|
ADD_INSN1(ret, line, putobject, Qtrue);
|
|
|
|
ADD_INSN1(ret, line, setspecial, key);
|
|
|
|
if (!again) {
|
|
|
|
ADD_INSNL(ret, line, jump, then_label);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *flip == 1 */
|
|
|
|
ADD_LABEL(ret, lend);
|
|
|
|
COMPILE(ret, "flip2 end", node->nd_end);
|
|
|
|
ADD_INSNL(ret, line, branchunless, then_label);
|
|
|
|
ADD_INSN1(ret, line, putobject, Qfalse);
|
|
|
|
ADD_INSN1(ret, line, setspecial, key);
|
|
|
|
ADD_INSNL(ret, line, jump, then_label);
|
|
|
|
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * cond,
|
2006-12-31 18:02:22 +03:00
|
|
|
LABEL *then_label, LABEL *else_label)
|
|
|
|
{
|
|
|
|
switch (nd_type(cond)) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case NODE_AND:
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
LABEL *label = NEW_LABEL(nd_line(cond));
|
|
|
|
compile_branch_condition(iseq, ret, cond->nd_1st, label,
|
|
|
|
else_label);
|
|
|
|
ADD_LABEL(ret, label);
|
|
|
|
compile_branch_condition(iseq, ret, cond->nd_2nd, then_label,
|
|
|
|
else_label);
|
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case NODE_OR:
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
LABEL *label = NEW_LABEL(nd_line(cond));
|
|
|
|
compile_branch_condition(iseq, ret, cond->nd_1st, then_label,
|
|
|
|
label);
|
|
|
|
ADD_LABEL(ret, label);
|
|
|
|
compile_branch_condition(iseq, ret, cond->nd_2nd, then_label,
|
|
|
|
else_label);
|
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case NODE_LIT: /* NODE_LIT is always not true */
|
|
|
|
case NODE_TRUE:
|
|
|
|
case NODE_STR:
|
2016-04-26 11:38:20 +03:00
|
|
|
case NODE_DSTR:
|
|
|
|
case NODE_XSTR:
|
|
|
|
case NODE_DXSTR:
|
|
|
|
case NODE_DREGX:
|
|
|
|
case NODE_DREGX_ONCE:
|
|
|
|
case NODE_DSYM:
|
|
|
|
case NODE_ARRAY:
|
|
|
|
case NODE_ZARRAY:
|
|
|
|
case NODE_HASH:
|
|
|
|
case NODE_LAMBDA:
|
|
|
|
case NODE_DEFN:
|
|
|
|
case NODE_DEFS:
|
2009-11-03 20:46:28 +03:00
|
|
|
/* printf("useless condition eliminate (%s)\n", ruby_node_name(nd_type(cond))); */
|
2006-12-31 18:02:22 +03:00
|
|
|
ADD_INSNL(ret, nd_line(cond), jump, then_label);
|
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case NODE_FALSE:
|
|
|
|
case NODE_NIL:
|
2009-11-03 20:46:28 +03:00
|
|
|
/* printf("useless condition eliminate (%s)\n", ruby_node_name(nd_type(cond))); */
|
2006-12-31 18:02:22 +03:00
|
|
|
ADD_INSNL(ret, nd_line(cond), jump, else_label);
|
|
|
|
break;
|
2016-10-01 13:19:36 +03:00
|
|
|
case NODE_FLIP2:
|
|
|
|
compile_flip_flop(iseq, ret, cond, TRUE, then_label, else_label);
|
|
|
|
break;
|
|
|
|
case NODE_FLIP3:
|
|
|
|
compile_flip_flop(iseq, ret, cond, FALSE, then_label, else_label);
|
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
COMPILE(ret, "branch condition", cond);
|
|
|
|
ADD_INSNL(ret, nd_line(cond), branchunless, else_label);
|
|
|
|
ADD_INSNL(ret, nd_line(cond), jump, then_label);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
static int
|
2015-09-19 20:59:58 +03:00
|
|
|
compile_array_keyword_arg(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE * const root_node, struct rb_call_info_kw_arg ** const kw_arg_ptr)
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
{
|
|
|
|
if (kw_arg_ptr == NULL) return FALSE;
|
|
|
|
|
|
|
|
if (nd_type(root_node) == NODE_HASH && root_node->nd_head && nd_type(root_node->nd_head) == NODE_ARRAY) {
|
|
|
|
NODE *node = root_node->nd_head;
|
|
|
|
|
|
|
|
while (node) {
|
|
|
|
NODE *key_node = node->nd_head;
|
|
|
|
|
|
|
|
assert(nd_type(node) == NODE_ARRAY);
|
|
|
|
if (key_node && nd_type(key_node) == NODE_LIT && RB_TYPE_P(key_node->nd_lit, T_SYMBOL)) {
|
|
|
|
/* can be keywords */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
node = node->nd_next; /* skip value node */
|
|
|
|
node = node->nd_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* may be keywords */
|
|
|
|
node = root_node->nd_head;
|
|
|
|
{
|
|
|
|
int len = (int)node->nd_alen / 2;
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info_kw_arg *kw_arg = (struct rb_call_info_kw_arg *)ruby_xmalloc(sizeof(struct rb_call_info_kw_arg) + sizeof(VALUE) * (len - 1));
|
2015-02-06 04:31:53 +03:00
|
|
|
VALUE *keywords = kw_arg->keywords;
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
int i = 0;
|
|
|
|
kw_arg->keyword_len = len;
|
|
|
|
|
|
|
|
*kw_arg_ptr = kw_arg;
|
|
|
|
|
|
|
|
for (i=0; node != NULL; i++, node = node->nd_next->nd_next) {
|
|
|
|
NODE *key_node = node->nd_head;
|
|
|
|
NODE *val_node = node->nd_next->nd_head;
|
2015-02-06 04:31:53 +03:00
|
|
|
keywords[i] = key_node->nd_lit;
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
COMPILE(ret, "keyword values", val_node);
|
|
|
|
}
|
|
|
|
assert(i == len);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-04-12 05:33:34 +04:00
|
|
|
enum compile_array_type_t {
|
|
|
|
COMPILE_ARRAY_TYPE_ARRAY,
|
|
|
|
COMPILE_ARRAY_TYPE_HASH,
|
2012-06-11 06:57:02 +04:00
|
|
|
COMPILE_ARRAY_TYPE_ARGS
|
2012-04-12 05:33:34 +04:00
|
|
|
};
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2007-07-03 23:35:09 +04:00
|
|
|
compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
|
2015-09-19 20:59:58 +03:00
|
|
|
enum compile_array_type_t type, struct rb_call_info_kw_arg **keywords_ptr, int poped)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
NODE *node = node_root;
|
2012-04-12 05:33:34 +04:00
|
|
|
int line = (int)nd_line(node);
|
|
|
|
int len = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-04-12 05:33:34 +04:00
|
|
|
if (nd_type(node) == NODE_ZARRAY) {
|
|
|
|
if (!poped) {
|
|
|
|
switch (type) {
|
|
|
|
case COMPILE_ARRAY_TYPE_ARRAY: ADD_INSN1(ret, line, newarray, INT2FIX(0)); break;
|
|
|
|
case COMPILE_ARRAY_TYPE_HASH: ADD_INSN1(ret, line, newhash, INT2FIX(0)); break;
|
|
|
|
case COMPILE_ARRAY_TYPE_ARGS: /* do nothing */ break;
|
2007-07-03 23:11:49 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2012-04-12 05:33:34 +04:00
|
|
|
else {
|
|
|
|
int opt_p = 1;
|
|
|
|
int first = 1, i;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-04-12 05:33:34 +04:00
|
|
|
while (node) {
|
|
|
|
NODE *start_node = node, *end_node;
|
2012-04-29 01:12:05 +04:00
|
|
|
NODE *kw = 0;
|
2012-04-12 05:33:34 +04:00
|
|
|
const int max = 0x100;
|
|
|
|
DECL_ANCHOR(anchor);
|
|
|
|
INIT_ANCHOR(anchor);
|
|
|
|
|
2012-04-29 01:12:05 +04:00
|
|
|
for (i=0; i<max && node; i++, len++, node = node->nd_next) {
|
2015-12-01 08:55:26 +03:00
|
|
|
if (CPDEBUG > 0) {
|
|
|
|
EXPECT_NODE("compile_array", node, NODE_ARRAY);
|
2012-04-12 05:33:34 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-01-09 05:13:03 +03:00
|
|
|
if (type != COMPILE_ARRAY_TYPE_ARRAY && !node->nd_head) {
|
2012-04-29 01:12:05 +04:00
|
|
|
kw = node->nd_next;
|
2015-01-09 05:13:03 +03:00
|
|
|
node = 0;
|
|
|
|
if (kw) {
|
|
|
|
opt_p = 0;
|
|
|
|
node = kw->nd_next;
|
|
|
|
kw = kw->nd_head;
|
|
|
|
}
|
2012-04-29 01:12:05 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-04-12 05:33:34 +04:00
|
|
|
if (opt_p && nd_type(node->nd_head) != NODE_LIT) {
|
|
|
|
opt_p = 0;
|
|
|
|
}
|
|
|
|
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
if (type == COMPILE_ARRAY_TYPE_ARGS && node->nd_next == NULL /* last node */ && compile_array_keyword_arg(iseq, anchor, node->nd_head, keywords_ptr)) {
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
COMPILE_(anchor, "array element", node->nd_head, poped);
|
|
|
|
}
|
2007-07-03 23:35:09 +04:00
|
|
|
}
|
2012-04-12 05:33:34 +04:00
|
|
|
|
|
|
|
if (opt_p && type != COMPILE_ARRAY_TYPE_ARGS) {
|
|
|
|
if (!poped) {
|
|
|
|
VALUE ary = rb_ary_tmp_new(i);
|
|
|
|
|
|
|
|
end_node = node;
|
|
|
|
node = start_node;
|
|
|
|
|
|
|
|
while (node != end_node) {
|
|
|
|
rb_ary_push(ary, node->nd_head->nd_lit);
|
|
|
|
node = node->nd_next;
|
|
|
|
}
|
2012-11-29 21:35:29 +04:00
|
|
|
while (node && nd_type(node->nd_head) == NODE_LIT &&
|
|
|
|
node->nd_next && nd_type(node->nd_next->nd_head) == NODE_LIT) {
|
|
|
|
rb_ary_push(ary, node->nd_head->nd_lit);
|
|
|
|
node = node->nd_next;
|
2012-04-12 05:33:34 +04:00
|
|
|
rb_ary_push(ary, node->nd_head->nd_lit);
|
|
|
|
node = node->nd_next;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJ_FREEZE(ary);
|
|
|
|
|
|
|
|
iseq_add_mark_object_compile_time(iseq, ary);
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = 0;
|
|
|
|
if (type == COMPILE_ARRAY_TYPE_ARRAY) {
|
|
|
|
ADD_INSN1(ret, line, duparray, ary);
|
|
|
|
}
|
|
|
|
else { /* COMPILE_ARRAY_TYPE_HASH */
|
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
|
|
|
ADD_INSN1(ret, line, putobject, ary);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, id_core_hash_from_ary, INT2FIX(1));
|
2012-04-12 05:33:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (type == COMPILE_ARRAY_TYPE_ARRAY) {
|
|
|
|
ADD_INSN1(ret, line, putobject, ary);
|
|
|
|
ADD_INSN(ret, line, concatarray);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
|
|
|
ADD_INSN1(ret, line, putobject, ary);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, id_core_hash_merge_ary, INT2FIX(1));
|
2012-04-12 05:33:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!poped) {
|
|
|
|
switch (type) {
|
|
|
|
case COMPILE_ARRAY_TYPE_ARRAY:
|
|
|
|
ADD_INSN1(anchor, line, newarray, INT2FIX(i));
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_INSN(anchor, line, concatarray);
|
|
|
|
}
|
2013-01-09 22:38:41 +04:00
|
|
|
|
2012-04-12 05:33:34 +04:00
|
|
|
APPEND_LIST(ret, anchor);
|
|
|
|
break;
|
|
|
|
case COMPILE_ARRAY_TYPE_HASH:
|
2013-10-13 07:16:54 +04:00
|
|
|
if (i > 0) {
|
|
|
|
if (first) {
|
|
|
|
ADD_INSN1(anchor, line, newhash, INT2FIX(i));
|
|
|
|
APPEND_LIST(ret, anchor);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
|
|
|
ADD_INSN(ret, line, swap);
|
|
|
|
APPEND_LIST(ret, anchor);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, id_core_hash_merge_ptr, INT2FIX(i + 1));
|
2013-10-13 07:16:54 +04:00
|
|
|
}
|
2012-04-12 05:33:34 +04:00
|
|
|
}
|
2012-04-29 01:12:05 +04:00
|
|
|
if (kw) {
|
2013-10-13 07:16:54 +04:00
|
|
|
VALUE nhash = (i > 0 || !first) ? INT2FIX(2) : INT2FIX(1);
|
2012-04-29 01:12:05 +04:00
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
2013-10-13 07:16:54 +04:00
|
|
|
if (i > 0 || !first) ADD_INSN(ret, line, swap);
|
2012-04-29 01:12:05 +04:00
|
|
|
COMPILE(ret, "keyword splat", kw);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, id_core_hash_merge_kwd, nhash);
|
|
|
|
if (nhash == INT2FIX(1)) ADD_SEND(ret, line, rb_intern("dup"), INT2FIX(0));
|
2012-04-29 01:12:05 +04:00
|
|
|
}
|
2013-10-13 07:16:54 +04:00
|
|
|
first = 0;
|
2012-04-12 05:33:34 +04:00
|
|
|
break;
|
|
|
|
case COMPILE_ARRAY_TYPE_ARGS:
|
|
|
|
APPEND_LIST(ret, anchor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-09 22:38:41 +04:00
|
|
|
else {
|
|
|
|
/* poped */
|
|
|
|
APPEND_LIST(ret, anchor);
|
|
|
|
}
|
2012-04-12 05:33:34 +04:00
|
|
|
}
|
2007-07-03 23:35:09 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2007-07-03 23:35:09 +04:00
|
|
|
static VALUE
|
2012-04-12 05:33:34 +04:00
|
|
|
compile_array(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root, enum compile_array_type_t type)
|
2007-07-03 23:35:09 +04:00
|
|
|
{
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
return compile_array_(iseq, ret, node_root, type, NULL, 0);
|
2007-07-03 23:35:09 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
|
|
|
case_when_optimizable_literal(NODE * node)
|
|
|
|
{
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
switch (nd_type(node)) {
|
|
|
|
case NODE_LIT: {
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE v = node->nd_lit;
|
2010-09-09 17:40:14 +04:00
|
|
|
double ival;
|
2011-09-29 15:07:45 +04:00
|
|
|
if (RB_TYPE_P(v, T_FLOAT) &&
|
2010-09-09 17:40:14 +04:00
|
|
|
modf(RFLOAT_VALUE(v), &ival) == 0.0) {
|
|
|
|
return FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival);
|
|
|
|
}
|
2013-11-10 10:13:02 +04:00
|
|
|
if (SYMBOL_P(v) || rb_obj_is_kind_of(v, rb_cNumeric)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
return v;
|
|
|
|
}
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-12-08 04:46:45 +03:00
|
|
|
case NODE_NIL:
|
|
|
|
return Qnil;
|
|
|
|
case NODE_TRUE:
|
|
|
|
return Qtrue;
|
|
|
|
case NODE_FALSE:
|
|
|
|
return Qfalse;
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
case NODE_STR:
|
2013-11-27 03:30:25 +04:00
|
|
|
return node->nd_lit = rb_fstring(node->nd_lit);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2012-04-24 13:20:42 +04:00
|
|
|
return Qundef;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 13:20:42 +04:00
|
|
|
static int
|
|
|
|
when_vals(rb_iseq_t *iseq, LINK_ANCHOR *cond_seq, NODE *vals, LABEL *l1, int only_special_literals, VALUE literals)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
while (vals) {
|
2012-04-24 13:20:42 +04:00
|
|
|
NODE* val = vals->nd_head;
|
|
|
|
VALUE lit = case_when_optimizable_literal(val);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-04-24 13:20:42 +04:00
|
|
|
if (lit == Qundef) {
|
|
|
|
only_special_literals = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2012-04-24 13:20:42 +04:00
|
|
|
if (rb_hash_lookup(literals, lit) != Qnil) {
|
2015-12-24 11:25:44 +03:00
|
|
|
rb_compile_warning(ruby_sourcefile, nd_line(val),
|
|
|
|
"duplicated when clause is ignored");
|
2012-04-24 13:20:42 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_hash_aset(literals, lit, (VALUE)(l1) | 1);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-08-08 11:52:19 +04:00
|
|
|
ADD_INSN(cond_seq, nd_line(val), dup); /* dup target */
|
|
|
|
|
2011-07-10 07:11:52 +04:00
|
|
|
if (nd_type(val) == NODE_STR) {
|
2013-11-27 03:30:25 +04:00
|
|
|
val->nd_lit = rb_fstring(val->nd_lit);
|
2011-07-10 07:11:52 +04:00
|
|
|
debugp_param("nd_lit", val->nd_lit);
|
|
|
|
ADD_INSN1(cond_seq, nd_line(val), putobject, val->nd_lit);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
COMPILE(cond_seq, "when cond", val);
|
|
|
|
}
|
2012-08-08 11:52:19 +04:00
|
|
|
|
|
|
|
ADD_INSN1(cond_seq, nd_line(vals), checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_CASE));
|
2006-12-31 18:02:22 +03:00
|
|
|
ADD_INSNL(cond_seq, nd_line(val), branchif, l1);
|
|
|
|
vals = vals->nd_next;
|
|
|
|
}
|
2012-04-24 13:20:42 +04:00
|
|
|
return only_special_literals;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-08-23 11:10:56 +04:00
|
|
|
compile_massign_lhs(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
switch (nd_type(node)) {
|
2007-06-26 22:56:15 +04:00
|
|
|
case NODE_ATTRASGN: {
|
2016-01-10 14:57:51 +03:00
|
|
|
INSN *iobj;
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info *ci;
|
2007-08-23 10:48:28 +04:00
|
|
|
VALUE dupidx;
|
2016-01-10 14:57:51 +03:00
|
|
|
int line = nd_line(node);
|
2007-08-23 10:48:28 +04:00
|
|
|
|
|
|
|
COMPILE_POPED(ret, "masgn lhs (NODE_ATTRASGN)", node);
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
|
2015-10-23 04:47:08 +03:00
|
|
|
iobj = (INSN *)get_prev_insn((INSN *)LAST_ELEMENT(ret)); /* send insn */
|
2015-09-19 20:59:58 +03:00
|
|
|
ci = (struct rb_call_info *)iobj->operands[0];
|
|
|
|
ci->orig_argc += 1;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
dupidx = INT2FIX(ci->orig_argc);
|
2007-08-23 10:48:28 +04:00
|
|
|
|
2016-01-10 14:57:51 +03:00
|
|
|
INSERT_BEFORE_INSN1(iobj, line, topn, dupidx);
|
|
|
|
if (ci->flag & VM_CALL_ARGS_SPLAT) {
|
|
|
|
--ci->orig_argc;
|
|
|
|
INSERT_BEFORE_INSN1(iobj, line, newarray, INT2FIX(1));
|
|
|
|
INSERT_BEFORE_INSN(iobj, line, concatarray);
|
|
|
|
}
|
|
|
|
ADD_INSN(ret, line, pop); /* result */
|
2007-08-23 10:48:28 +04:00
|
|
|
break;
|
2007-06-26 22:56:15 +04:00
|
|
|
}
|
|
|
|
case NODE_MASGN: {
|
2007-08-23 11:10:56 +04:00
|
|
|
DECL_ANCHOR(anchor);
|
|
|
|
INIT_ANCHOR(anchor);
|
|
|
|
COMPILE_POPED(anchor, "nest masgn lhs", node);
|
|
|
|
REMOVE_ELEM(FIRST_ELEMENT(anchor));
|
|
|
|
ADD_SEQ(ret, anchor);
|
2007-08-23 10:48:28 +04:00
|
|
|
break;
|
2007-06-26 22:56:15 +04:00
|
|
|
}
|
|
|
|
default: {
|
2007-08-23 10:48:28 +04:00
|
|
|
DECL_ANCHOR(anchor);
|
|
|
|
INIT_ANCHOR(anchor);
|
|
|
|
COMPILE_POPED(anchor, "masgn lhs", node);
|
|
|
|
REMOVE_ELEM(FIRST_ELEMENT(anchor));
|
|
|
|
ADD_SEQ(ret, anchor);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-23 15:32:21 +04:00
|
|
|
static void
|
|
|
|
compile_massign_opt_lhs(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *lhsn)
|
|
|
|
{
|
|
|
|
if (lhsn) {
|
|
|
|
compile_massign_opt_lhs(iseq, ret, lhsn->nd_next);
|
|
|
|
compile_massign_lhs(iseq, ret, lhsn->nd_head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_massign_opt(rb_iseq_t *iseq, LINK_ANCHOR *ret,
|
|
|
|
NODE *rhsn, NODE *orig_lhsn)
|
|
|
|
{
|
2008-03-25 09:09:38 +03:00
|
|
|
VALUE mem[64];
|
2009-05-17 09:27:32 +04:00
|
|
|
const int memsize = numberof(mem);
|
2007-08-23 15:32:21 +04:00
|
|
|
int memindex = 0;
|
|
|
|
int llen = 0, rlen = 0;
|
|
|
|
int i;
|
|
|
|
NODE *lhsn = orig_lhsn;
|
|
|
|
|
|
|
|
#define MEMORY(v) { \
|
|
|
|
int i; \
|
|
|
|
if (memindex == memsize) return 0; \
|
|
|
|
for (i=0; i<memindex; i++) { \
|
|
|
|
if (mem[i] == (v)) return 0; \
|
|
|
|
} \
|
|
|
|
mem[memindex++] = (v); \
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rhsn == 0 || nd_type(rhsn) != NODE_ARRAY) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (lhsn) {
|
|
|
|
NODE *ln = lhsn->nd_head;
|
|
|
|
switch (nd_type(ln)) {
|
|
|
|
case NODE_LASGN:
|
|
|
|
MEMORY(ln->nd_vid);
|
|
|
|
break;
|
|
|
|
case NODE_DASGN:
|
|
|
|
case NODE_DASGN_CURR:
|
|
|
|
case NODE_IASGN:
|
|
|
|
case NODE_IASGN2:
|
|
|
|
case NODE_CVASGN:
|
|
|
|
MEMORY(ln->nd_vid);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
lhsn = lhsn->nd_next;
|
|
|
|
llen++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (rhsn) {
|
|
|
|
if (llen <= rlen) {
|
2009-11-03 20:46:28 +03:00
|
|
|
COMPILE_POPED(ret, "masgn val (popped)", rhsn->nd_head);
|
2007-08-23 15:32:21 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
COMPILE(ret, "masgn val", rhsn->nd_head);
|
|
|
|
}
|
|
|
|
rhsn = rhsn->nd_next;
|
|
|
|
rlen++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (llen > rlen) {
|
|
|
|
for (i=0; i<llen-rlen; i++) {
|
|
|
|
ADD_INSN(ret, nd_line(orig_lhsn), putnil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compile_massign_opt_lhs(iseq, ret, orig_lhsn);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-25 03:20:35 +03:00
|
|
|
static void
|
|
|
|
adjust_stack(rb_iseq_t *iseq, LINK_ANCHOR *ret, int line, int rlen, int llen)
|
|
|
|
{
|
|
|
|
if (rlen < llen) {
|
|
|
|
do {ADD_INSN(ret, line, putnil);} while (++rlen < llen);
|
|
|
|
}
|
|
|
|
else if (rlen > llen) {
|
|
|
|
do {ADD_INSN(ret, line, pop);} while (--rlen > llen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2007-08-23 11:10:56 +04:00
|
|
|
compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int poped)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-08-23 11:10:56 +04:00
|
|
|
NODE *rhsn = node->nd_value;
|
|
|
|
NODE *splatn = node->nd_args;
|
|
|
|
NODE *lhsn = node->nd_head;
|
|
|
|
int lhs_splat = (splatn && (VALUE)splatn != (VALUE)-1) ? 1 : 0;
|
|
|
|
|
2007-08-23 15:32:21 +04:00
|
|
|
if (!poped || splatn || !compile_massign_opt(iseq, ret, rhsn, lhsn)) {
|
2007-08-23 11:10:56 +04:00
|
|
|
int llen = 0;
|
2015-02-16 14:58:52 +03:00
|
|
|
int expand = 1;
|
2007-08-23 15:32:21 +04:00
|
|
|
DECL_ANCHOR(lhsseq);
|
|
|
|
|
2007-08-23 11:10:56 +04:00
|
|
|
INIT_ANCHOR(lhsseq);
|
2007-04-05 12:58:46 +04:00
|
|
|
|
2007-08-23 11:10:56 +04:00
|
|
|
while (lhsn) {
|
|
|
|
compile_massign_lhs(iseq, lhsseq, lhsn->nd_head);
|
|
|
|
llen += 1;
|
|
|
|
lhsn = lhsn->nd_next;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-08-23 11:10:56 +04:00
|
|
|
COMPILE(ret, "normal masgn rhs", rhsn);
|
2007-07-05 22:16:54 +04:00
|
|
|
|
2007-08-23 11:10:56 +04:00
|
|
|
if (!poped) {
|
|
|
|
ADD_INSN(ret, nd_line(node), dup);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2015-02-16 14:58:52 +03:00
|
|
|
else if (!lhs_splat) {
|
|
|
|
INSN *last = (INSN*)ret->last;
|
2016-04-23 14:39:41 +03:00
|
|
|
if (IS_INSN(&last->link) &&
|
2016-04-23 14:43:52 +03:00
|
|
|
IS_INSN_ID(last, newarray) &&
|
2015-02-25 03:20:35 +03:00
|
|
|
last->operand_size == 1) {
|
|
|
|
int rlen = FIX2INT(OPERAND_AT(last, 0));
|
2015-02-16 14:58:52 +03:00
|
|
|
/* special case: assign to aset or attrset */
|
|
|
|
if (llen == 2) {
|
|
|
|
POP_ELEMENT(ret);
|
2015-02-25 03:20:35 +03:00
|
|
|
adjust_stack(iseq, ret, nd_line(node), rlen, llen);
|
2015-02-16 14:58:52 +03:00
|
|
|
ADD_INSN(ret, nd_line(node), swap);
|
|
|
|
expand = 0;
|
|
|
|
}
|
2015-02-25 03:20:35 +03:00
|
|
|
else if (llen > 2 && llen != rlen) {
|
|
|
|
POP_ELEMENT(ret);
|
|
|
|
adjust_stack(iseq, ret, nd_line(node), rlen, llen);
|
|
|
|
ADD_INSN1(ret, nd_line(node), reverse, INT2FIX(llen));
|
|
|
|
expand = 0;
|
|
|
|
}
|
2015-02-16 14:58:52 +03:00
|
|
|
else if (llen > 2) {
|
|
|
|
last->insn_id = BIN(reverse);
|
|
|
|
expand = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (expand) {
|
|
|
|
ADD_INSN2(ret, nd_line(node), expandarray,
|
|
|
|
INT2FIX(llen), INT2FIX(lhs_splat));
|
|
|
|
}
|
2007-08-23 11:10:56 +04:00
|
|
|
ADD_SEQ(ret, lhsseq);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
if (lhs_splat) {
|
2007-06-26 22:56:15 +04:00
|
|
|
if (nd_type(splatn) == NODE_POSTARG) {
|
2007-08-23 11:10:56 +04:00
|
|
|
/*a, b, *r, p1, p2 */
|
|
|
|
NODE *postn = splatn->nd_2nd;
|
|
|
|
NODE *restn = splatn->nd_1st;
|
2009-06-22 11:05:50 +04:00
|
|
|
int num = (int)postn->nd_alen;
|
2007-08-23 11:10:56 +04:00
|
|
|
int flag = 0x02 | (((VALUE)restn == (VALUE)-1) ? 0x00 : 0x01);
|
2007-06-26 22:56:15 +04:00
|
|
|
|
2007-08-23 11:10:56 +04:00
|
|
|
ADD_INSN2(ret, nd_line(splatn), expandarray,
|
|
|
|
INT2FIX(num), INT2FIX(flag));
|
2007-06-26 22:56:15 +04:00
|
|
|
|
2007-08-23 11:10:56 +04:00
|
|
|
if ((VALUE)restn != (VALUE)-1) {
|
|
|
|
compile_massign_lhs(iseq, ret, restn);
|
2007-07-03 22:50:28 +04:00
|
|
|
}
|
2007-08-23 11:10:56 +04:00
|
|
|
while (postn) {
|
|
|
|
compile_massign_lhs(iseq, ret, postn->nd_head);
|
|
|
|
postn = postn->nd_next;
|
2007-07-03 22:50:28 +04:00
|
|
|
}
|
2007-06-26 22:56:15 +04:00
|
|
|
}
|
|
|
|
else {
|
2007-08-23 11:10:56 +04:00
|
|
|
/* a, b, *r */
|
|
|
|
compile_massign_lhs(iseq, ret, splatn);
|
2007-06-26 22:56:15 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
compile_colon2(rb_iseq_t *iseq, NODE * node,
|
2006-12-31 18:02:22 +03:00
|
|
|
LINK_ANCHOR *pref, LINK_ANCHOR *body)
|
|
|
|
{
|
|
|
|
switch (nd_type(node)) {
|
|
|
|
case NODE_CONST:
|
|
|
|
debugi("compile_colon2 - colon", node->nd_vid);
|
|
|
|
ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_vid));
|
|
|
|
break;
|
|
|
|
case NODE_COLON3:
|
|
|
|
debugi("compile_colon2 - colon3", node->nd_mid);
|
|
|
|
ADD_INSN(body, nd_line(node), pop);
|
|
|
|
ADD_INSN1(body, nd_line(node), putobject, rb_cObject);
|
|
|
|
ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_mid));
|
|
|
|
break;
|
|
|
|
case NODE_COLON2:
|
|
|
|
compile_colon2(iseq, node->nd_head, pref, body);
|
|
|
|
debugi("compile_colon2 - colon2", node->nd_mid);
|
|
|
|
ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_mid));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
COMPILE(pref, "const colon2 prefix", node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2008-05-14 06:31:28 +04:00
|
|
|
static VALUE
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
compile_cpath(LINK_ANCHOR *ret, rb_iseq_t *iseq, NODE *cpath)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-05-05 06:27:29 +04:00
|
|
|
if (nd_type(cpath) == NODE_COLON3) {
|
|
|
|
/* toplevel class ::Foo */
|
|
|
|
ADD_INSN1(ret, nd_line(cpath), putobject, rb_cObject);
|
2008-05-14 06:31:28 +04:00
|
|
|
return Qfalse;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2008-05-05 06:27:29 +04:00
|
|
|
else if (cpath->nd_head) {
|
|
|
|
/* Bar::Foo */
|
|
|
|
COMPILE(ret, "nd_else->nd_head", cpath->nd_head);
|
2008-05-14 06:31:28 +04:00
|
|
|
return Qfalse;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-05-05 06:27:29 +04:00
|
|
|
/* class at cbase Foo */
|
2009-12-03 21:25:57 +03:00
|
|
|
ADD_INSN1(ret, nd_line(cpath), putspecialobject,
|
|
|
|
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
|
2008-05-14 06:31:28 +04:00
|
|
|
return Qtrue;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 17:19:31 +04:00
|
|
|
#define private_recv_p(node) (nd_type((node)->nd_recv) == NODE_SELF)
|
2014-06-06 10:05:19 +04:00
|
|
|
|
2012-02-11 07:04:23 +04:00
|
|
|
#define defined_expr defined_expr0
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret,
|
2008-03-25 09:26:32 +03:00
|
|
|
NODE *node, LABEL **lfinish, VALUE needstr)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2012-09-24 12:36:53 +04:00
|
|
|
enum defined_type expr_type = 0;
|
2007-04-08 08:27:41 +04:00
|
|
|
enum node_type type;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-04-08 08:27:41 +04:00
|
|
|
switch (type = nd_type(node)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/* easy literals */
|
|
|
|
case NODE_NIL:
|
2012-09-24 12:36:53 +04:00
|
|
|
expr_type = DEFINED_NIL;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
case NODE_SELF:
|
2012-09-24 12:36:53 +04:00
|
|
|
expr_type = DEFINED_SELF;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
case NODE_TRUE:
|
2012-09-24 12:36:53 +04:00
|
|
|
expr_type = DEFINED_TRUE;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
case NODE_FALSE:
|
2012-09-24 12:36:53 +04:00
|
|
|
expr_type = DEFINED_FALSE;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
2007-04-05 12:58:46 +04:00
|
|
|
|
|
|
|
case NODE_ARRAY:{
|
|
|
|
NODE *vals = node;
|
|
|
|
|
|
|
|
do {
|
|
|
|
defined_expr(iseq, ret, vals->nd_head, lfinish, Qfalse);
|
* vm.c: some refactoring.
* rename th_* to vm_*.
* remove unused variables functions.
* add prototypes.
* blockinlining.c, compile.c, cont.c, eval.c, eval_intern.h,
eval_jump.h, eval_load.c, inits.c, insns.def, iseq.c, parse.y,
proc.c, process.c, signal.c, thread.c, vm.c, vm_dump.c,
vm_evalbody.ci, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-24 19:42:41 +04:00
|
|
|
|
2008-05-30 17:15:03 +04:00
|
|
|
if (!lfinish[1]) {
|
2008-03-25 09:26:32 +03:00
|
|
|
lfinish[1] = NEW_LABEL(nd_line(node));
|
2007-04-05 12:58:46 +04:00
|
|
|
}
|
2008-05-30 17:15:03 +04:00
|
|
|
ADD_INSNL(ret, nd_line(node), branchunless, lfinish[1]);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
} while ((vals = vals->nd_next) != NULL);
|
2007-04-05 12:58:46 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_STR:
|
|
|
|
case NODE_LIT:
|
2007-04-05 12:58:46 +04:00
|
|
|
case NODE_ZARRAY:
|
2008-08-25 14:06:12 +04:00
|
|
|
case NODE_AND:
|
|
|
|
case NODE_OR:
|
2008-08-25 18:04:09 +04:00
|
|
|
default:
|
2012-09-24 12:36:53 +04:00
|
|
|
expr_type = DEFINED_EXPR;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* variables */
|
|
|
|
case NODE_LVAR:
|
|
|
|
case NODE_DVAR:
|
2012-09-24 12:36:53 +04:00
|
|
|
expr_type = DEFINED_LVAR;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NODE_IVAR:
|
|
|
|
ADD_INSN(ret, nd_line(node), putnil);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_IVAR),
|
|
|
|
ID2SYM(node->nd_vid), needstr);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case NODE_GVAR:
|
|
|
|
ADD_INSN(ret, nd_line(node), putnil);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_GVAR),
|
2010-03-09 22:21:37 +03:00
|
|
|
ID2SYM(node->nd_entry->id), needstr);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case NODE_CVAR:
|
|
|
|
ADD_INSN(ret, nd_line(node), putnil);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_CVAR),
|
|
|
|
ID2SYM(node->nd_vid), needstr);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case NODE_CONST:
|
|
|
|
ADD_INSN(ret, nd_line(node), putnil);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_CONST),
|
|
|
|
ID2SYM(node->nd_vid), needstr);
|
|
|
|
return 1;
|
|
|
|
case NODE_COLON2:
|
2008-03-25 09:26:32 +03:00
|
|
|
if (!lfinish[1]) {
|
|
|
|
lfinish[1] = NEW_LABEL(nd_line(node));
|
|
|
|
}
|
|
|
|
defined_expr(iseq, ret, node->nd_head, lfinish, Qfalse);
|
|
|
|
ADD_INSNL(ret, nd_line(node), branchunless, lfinish[1]);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-03-25 09:26:32 +03:00
|
|
|
if (rb_is_const_id(node->nd_mid)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
COMPILE(ret, "defined/colon2#nd_head", node->nd_head);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_CONST),
|
|
|
|
ID2SYM(node->nd_mid), needstr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
COMPILE(ret, "defined/colon2#nd_head", node->nd_head);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_METHOD),
|
|
|
|
ID2SYM(node->nd_mid), needstr);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
case NODE_COLON3:
|
|
|
|
ADD_INSN1(ret, nd_line(node), putobject, rb_cObject);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined,
|
|
|
|
INT2FIX(DEFINED_CONST), ID2SYM(node->nd_mid), needstr);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* method dispatch */
|
|
|
|
case NODE_CALL:
|
|
|
|
case NODE_VCALL:
|
|
|
|
case NODE_FCALL:
|
2007-04-05 12:58:46 +04:00
|
|
|
case NODE_ATTRASGN:{
|
2014-07-25 07:21:12 +04:00
|
|
|
const int explicit_receiver =
|
|
|
|
(type == NODE_CALL ||
|
|
|
|
(type == NODE_ATTRASGN && !private_recv_p(node)));
|
2007-04-05 12:58:46 +04:00
|
|
|
|
2008-03-25 09:26:32 +03:00
|
|
|
if (!lfinish[1]) {
|
|
|
|
lfinish[1] = NEW_LABEL(nd_line(node));
|
|
|
|
}
|
2007-04-08 08:27:41 +04:00
|
|
|
if (node->nd_args) {
|
|
|
|
defined_expr(iseq, ret, node->nd_args, lfinish, Qfalse);
|
2008-03-25 09:26:32 +03:00
|
|
|
ADD_INSNL(ret, nd_line(node), branchunless, lfinish[1]);
|
2007-04-08 08:27:41 +04:00
|
|
|
}
|
2014-07-25 07:21:12 +04:00
|
|
|
if (explicit_receiver) {
|
2006-12-31 18:02:22 +03:00
|
|
|
defined_expr(iseq, ret, node->nd_recv, lfinish, Qfalse);
|
2008-03-25 09:26:32 +03:00
|
|
|
ADD_INSNL(ret, nd_line(node), branchunless, lfinish[1]);
|
2006-12-31 18:02:22 +03:00
|
|
|
COMPILE(ret, "defined/recv", node->nd_recv);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_METHOD),
|
|
|
|
ID2SYM(node->nd_mid), needstr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_INSN(ret, nd_line(node), putself);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_FUNC),
|
|
|
|
ID2SYM(node->nd_mid), needstr);
|
|
|
|
}
|
|
|
|
return 1;
|
2007-04-05 12:58:46 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
case NODE_YIELD:
|
|
|
|
ADD_INSN(ret, nd_line(node), putnil);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_YIELD), 0,
|
|
|
|
needstr);
|
|
|
|
return 1;
|
|
|
|
|
2007-11-27 07:43:54 +03:00
|
|
|
case NODE_BACK_REF:
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_NTH_REF:
|
|
|
|
ADD_INSN(ret, nd_line(node), putnil);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_REF),
|
2008-03-25 09:09:38 +03:00
|
|
|
INT2FIX((node->nd_nth << 1) | (type == NODE_BACK_REF)),
|
2007-11-27 07:43:54 +03:00
|
|
|
needstr);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 1;
|
|
|
|
|
2008-05-05 15:01:10 +04:00
|
|
|
case NODE_SUPER:
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_ZSUPER:
|
|
|
|
ADD_INSN(ret, nd_line(node), putnil);
|
|
|
|
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_ZSUPER), 0,
|
|
|
|
needstr);
|
|
|
|
return 1;
|
|
|
|
|
2007-04-05 12:58:46 +04:00
|
|
|
case NODE_OP_ASGN1:
|
|
|
|
case NODE_OP_ASGN2:
|
2008-05-12 09:05:50 +04:00
|
|
|
case NODE_OP_ASGN_OR:
|
|
|
|
case NODE_OP_ASGN_AND:
|
2007-04-05 12:58:46 +04:00
|
|
|
case NODE_MASGN:
|
|
|
|
case NODE_LASGN:
|
|
|
|
case NODE_DASGN:
|
|
|
|
case NODE_DASGN_CURR:
|
|
|
|
case NODE_GASGN:
|
|
|
|
case NODE_IASGN:
|
|
|
|
case NODE_CDECL:
|
|
|
|
case NODE_CVDECL:
|
|
|
|
case NODE_CVASGN:
|
2012-09-24 12:36:53 +04:00
|
|
|
expr_type = DEFINED_ASGN;
|
2007-04-05 12:58:46 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-09-24 12:36:53 +04:00
|
|
|
if (expr_type) {
|
2006-12-31 18:02:22 +03:00
|
|
|
if (needstr != Qfalse) {
|
2012-09-24 12:36:53 +04:00
|
|
|
VALUE str = rb_iseq_defined_string(expr_type);
|
|
|
|
ADD_INSN1(ret, nd_line(node), putobject, str);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_INSN1(ret, nd_line(node), putobject, Qtrue);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-11 07:04:23 +04:00
|
|
|
#undef defined_expr
|
|
|
|
|
|
|
|
static int
|
|
|
|
defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret,
|
|
|
|
NODE *node, LABEL **lfinish, VALUE needstr)
|
|
|
|
{
|
|
|
|
LINK_ELEMENT *lcur = ret->last;
|
|
|
|
int done = defined_expr0(iseq, ret, node, lfinish, needstr);
|
|
|
|
if (lfinish[1]) {
|
|
|
|
int line = nd_line(node);
|
|
|
|
LABEL *lstart = NEW_LABEL(line);
|
|
|
|
LABEL *lend = NEW_LABEL(line);
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *rescue = NEW_CHILD_ISEQ(NEW_NIL(),
|
|
|
|
rb_str_concat(rb_str_new2
|
|
|
|
("defined guard in "),
|
|
|
|
iseq->body->location.label),
|
|
|
|
ISEQ_TYPE_DEFINED_GUARD, 0);
|
2016-04-11 11:43:06 +03:00
|
|
|
lstart->rescued = LABEL_RESCUE_BEG;
|
|
|
|
lend->rescued = LABEL_RESCUE_END;
|
2012-02-11 07:04:23 +04:00
|
|
|
APPEND_LABEL(ret, lcur, lstart);
|
|
|
|
ADD_LABEL(ret, lend);
|
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lfinish[1]);
|
|
|
|
}
|
|
|
|
return done;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
static VALUE
|
2015-07-22 01:52:59 +03:00
|
|
|
make_name_for_block(const rb_iseq_t *orig_iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-12-27 04:15:56 +03:00
|
|
|
int level = 1;
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *iseq = orig_iseq;
|
2008-12-27 04:15:56 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (orig_iseq->body->parent_iseq != 0) {
|
|
|
|
while (orig_iseq->body->local_iseq != iseq) {
|
|
|
|
if (iseq->body->type == ISEQ_TYPE_BLOCK) {
|
2008-12-27 04:15:56 +03:00
|
|
|
level++;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq = iseq->body->parent_iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2008-12-27 04:15:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (level == 1) {
|
2015-07-22 01:52:59 +03:00
|
|
|
return rb_sprintf("block in %"PRIsVALUE, iseq->body->location.label);
|
2008-12-27 04:15:56 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-07-22 01:52:59 +03:00
|
|
|
return rb_sprintf("block (%d levels) in %"PRIsVALUE, level, iseq->body->location.label);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-16 23:54:58 +03:00
|
|
|
static void
|
|
|
|
push_ensure_entry(rb_iseq_t *iseq,
|
|
|
|
struct iseq_compile_data_ensure_node_stack *enl,
|
|
|
|
struct ensure_range *er, NODE *node)
|
|
|
|
{
|
|
|
|
enl->ensure_node = node;
|
2015-12-02 10:52:12 +03:00
|
|
|
enl->prev = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack; /* prev */
|
2009-02-16 23:54:58 +03:00
|
|
|
enl->erange = er;
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl;
|
2009-02-16 23:54:58 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static void
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
add_ensure_range(rb_iseq_t *iseq, struct ensure_range *erange,
|
2006-12-31 18:02:22 +03:00
|
|
|
LABEL *lstart, LABEL *lend)
|
|
|
|
{
|
|
|
|
struct ensure_range *ne =
|
|
|
|
compile_data_alloc(iseq, sizeof(struct ensure_range));
|
|
|
|
|
|
|
|
while (erange->next != 0) {
|
|
|
|
erange = erange->next;
|
|
|
|
}
|
|
|
|
ne->next = 0;
|
|
|
|
ne->begin = lend;
|
|
|
|
ne->end = erange->end;
|
|
|
|
erange->end = lstart;
|
|
|
|
|
|
|
|
erange->next = ne;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-16 23:54:58 +03:00
|
|
|
add_ensure_iseq(LINK_ANCHOR *ret, rb_iseq_t *iseq, int is_return)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
struct iseq_compile_data_ensure_node_stack *enlp =
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->ensure_node_stack;
|
2006-12-31 18:02:22 +03:00
|
|
|
struct iseq_compile_data_ensure_node_stack *prev_enlp = enlp;
|
|
|
|
DECL_ANCHOR(ensure);
|
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(ensure);
|
2006-12-31 18:02:22 +03:00
|
|
|
while (enlp) {
|
2009-02-16 23:54:58 +03:00
|
|
|
if (enlp->erange != 0) {
|
|
|
|
DECL_ANCHOR(ensure_part);
|
|
|
|
LABEL *lstart = NEW_LABEL(0);
|
|
|
|
LABEL *lend = NEW_LABEL(0);
|
|
|
|
INIT_ANCHOR(ensure_part);
|
2007-07-20 11:11:35 +04:00
|
|
|
|
2009-02-16 23:54:58 +03:00
|
|
|
add_ensure_range(iseq, enlp->erange, lstart, lend);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enlp->prev;
|
2009-02-16 23:54:58 +03:00
|
|
|
ADD_LABEL(ensure_part, lstart);
|
|
|
|
COMPILE_POPED(ensure_part, "ensure part", enlp->ensure_node);
|
|
|
|
ADD_LABEL(ensure_part, lend);
|
|
|
|
ADD_SEQ(ensure, ensure_part);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!is_return) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
enlp = enlp->prev;
|
|
|
|
}
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = prev_enlp;
|
2006-12-31 18:02:22 +03:00
|
|
|
ADD_SEQ(ret, ensure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2015-09-19 20:59:58 +03:00
|
|
|
setup_args(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *argn, unsigned int *flag, struct rb_call_info_kw_arg **keywords)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE argc = INT2FIX(0);
|
2007-04-26 20:54:58 +04:00
|
|
|
int nsplat = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
DECL_ANCHOR(arg_block);
|
2007-04-26 20:54:58 +04:00
|
|
|
DECL_ANCHOR(args_splat);
|
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(arg_block);
|
|
|
|
INIT_ANCHOR(args_splat);
|
2006-12-31 18:02:22 +03:00
|
|
|
if (argn && nd_type(argn) == NODE_BLOCK_PASS) {
|
2010-12-21 00:10:24 +03:00
|
|
|
COMPILE(arg_block, "block", argn->nd_body);
|
2012-10-15 21:22:57 +04:00
|
|
|
*flag |= VM_CALL_ARGS_BLOCKARG;
|
2006-12-31 18:02:22 +03:00
|
|
|
argn = argn->nd_head;
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_argn:
|
|
|
|
if (argn) {
|
|
|
|
switch (nd_type(argn)) {
|
|
|
|
case NODE_SPLAT: {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(args, "args (splat)", argn->nd_head);
|
2016-10-22 03:52:59 +03:00
|
|
|
ADD_INSN1(args, nd_line(argn), splatarray, nsplat ? Qtrue : Qfalse);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
argc = INT2FIX(1);
|
2007-06-25 21:52:33 +04:00
|
|
|
nsplat++;
|
2012-10-15 21:22:57 +04:00
|
|
|
*flag |= VM_CALL_ARGS_SPLAT;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-04-26 20:54:58 +04:00
|
|
|
case NODE_ARGSCAT:
|
|
|
|
case NODE_ARGSPUSH: {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
int next_is_array = (nd_type(argn->nd_head) == NODE_ARRAY);
|
|
|
|
DECL_ANCHOR(tmp);
|
2007-04-26 20:54:58 +04:00
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(tmp);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(tmp, "args (cat: splat)", argn->nd_body);
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
if (nd_type(argn) == NODE_ARGSCAT) {
|
2016-10-22 03:52:59 +03:00
|
|
|
ADD_INSN1(tmp, nd_line(argn), splatarray, nsplat ? Qtrue : Qfalse);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_INSN1(tmp, nd_line(argn), newarray, INT2FIX(1));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
INSERT_LIST(args_splat, tmp);
|
|
|
|
nsplat++;
|
2012-10-15 21:22:57 +04:00
|
|
|
*flag |= VM_CALL_ARGS_SPLAT;
|
2007-04-26 20:54:58 +04:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (next_is_array) {
|
2012-04-12 05:33:34 +04:00
|
|
|
argc = INT2FIX(compile_array(iseq, args, argn->nd_head, COMPILE_ARRAY_TYPE_ARGS) + 1);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
argn = argn->nd_head;
|
|
|
|
goto setup_argn;
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
case NODE_ARRAY:
|
|
|
|
{
|
|
|
|
argc = INT2FIX(compile_array_(iseq, args, argn, COMPILE_ARRAY_TYPE_ARGS, keywords, FALSE));
|
|
|
|
break;
|
|
|
|
}
|
2007-04-26 20:54:58 +04:00
|
|
|
default: {
|
2015-12-01 08:55:26 +03:00
|
|
|
UNKNOWN_NODE("setup_arg", argn);
|
2007-04-26 20:54:58 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-26 20:54:58 +04:00
|
|
|
if (nsplat > 1) {
|
|
|
|
int i;
|
|
|
|
for (i=1; i<nsplat; i++) {
|
|
|
|
ADD_INSN(args_splat, nd_line(args), concatarray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LIST_SIZE_ZERO(args_splat)) {
|
|
|
|
ADD_SEQ(args, args_splat);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-10-15 21:22:57 +04:00
|
|
|
if (*flag & VM_CALL_ARGS_BLOCKARG) {
|
2006-12-31 18:02:22 +03:00
|
|
|
ADD_SEQ(args, arg_block);
|
|
|
|
}
|
|
|
|
return argc;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2013-08-22 10:50:42 +04:00
|
|
|
static VALUE
|
|
|
|
build_postexe_iseq(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *body)
|
|
|
|
{
|
|
|
|
int line = nd_line(body);
|
|
|
|
VALUE argc = INT2FIX(0);
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *block = NEW_CHILD_ISEQ(body, make_name_for_block(iseq->body->parent_iseq), ISEQ_TYPE_BLOCK, line);
|
|
|
|
|
2013-08-22 10:50:42 +04:00
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_CALL_WITH_BLOCK(ret, line, id_core_set_postexe, argc, block);
|
2013-08-22 11:23:44 +04:00
|
|
|
iseq_set_local_table(iseq, 0);
|
2013-08-22 10:50:42 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2016-03-14 10:53:39 +03:00
|
|
|
static void
|
|
|
|
compile_named_capture_assign(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node)
|
|
|
|
{
|
|
|
|
NODE *vars;
|
|
|
|
LINK_ELEMENT *last;
|
|
|
|
int line = nd_line(node);
|
|
|
|
LABEL *fail_label = NEW_LABEL(line), *end_label = NEW_LABEL(line);
|
|
|
|
|
|
|
|
#if !(defined(NAMED_CAPTURE_BY_SVAR) && NAMED_CAPTURE_BY_SVAR-0)
|
|
|
|
ADD_INSN1(ret, line, getglobal, ((VALUE)rb_global_entry(idBACKREF) | 1));
|
|
|
|
#else
|
|
|
|
ADD_INSN2(ret, line, getspecial, INT2FIX(1) /* '~' */, INT2FIX(0));
|
|
|
|
#endif
|
|
|
|
ADD_INSN(ret, line, dup);
|
|
|
|
ADD_INSNL(ret, line, branchunless, fail_label);
|
|
|
|
|
|
|
|
for (vars = node; vars; vars = vars->nd_next) {
|
|
|
|
INSN *cap;
|
|
|
|
if (vars->nd_next) {
|
|
|
|
ADD_INSN(ret, line, dup);
|
|
|
|
}
|
|
|
|
last = ret->last;
|
|
|
|
COMPILE_POPED(ret, "capture", vars->nd_head);
|
|
|
|
last = last->next; /* putobject :var */
|
|
|
|
cap = new_insn_send(iseq, line, idAREF, INT2FIX(1),
|
|
|
|
NULL, INT2FIX(0), NULL);
|
|
|
|
INSERT_ELEM_PREV(last->next, (LINK_ELEMENT *)cap);
|
|
|
|
#if !defined(NAMED_CAPTURE_SINGLE_OPT) || NAMED_CAPTURE_SINGLE_OPT-0
|
|
|
|
if (!vars->nd_next && vars == node) {
|
|
|
|
/* only one name */
|
|
|
|
DECL_ANCHOR(nom);
|
|
|
|
|
|
|
|
INIT_ANCHOR(nom);
|
|
|
|
ADD_INSNL(nom, line, jump, end_label);
|
|
|
|
ADD_LABEL(nom, fail_label);
|
|
|
|
# if 0 /* $~ must be MatchData or nil */
|
|
|
|
ADD_INSN(nom, line, pop);
|
|
|
|
ADD_INSN(nom, line, putnil);
|
|
|
|
# endif
|
|
|
|
ADD_LABEL(nom, end_label);
|
|
|
|
(nom->last->next = cap->link.next)->prev = nom->last;
|
|
|
|
(cap->link.next = nom->anchor.next)->prev = &cap->link;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
ADD_INSNL(ret, line, jump, end_label);
|
|
|
|
ADD_LABEL(ret, fail_label);
|
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
for (vars = node; vars; vars = vars->nd_next) {
|
|
|
|
last = ret->last;
|
|
|
|
COMPILE_POPED(ret, "capture", vars->nd_head);
|
|
|
|
last = last->next; /* putobject :var */
|
|
|
|
((INSN*)last)->insn_id = BIN(putnil);
|
|
|
|
((INSN*)last)->operand_size = 0;
|
|
|
|
}
|
|
|
|
ADD_LABEL(ret, end_label);
|
|
|
|
}
|
|
|
|
|
2016-10-01 16:17:51 +03:00
|
|
|
static int
|
|
|
|
number_literal_p(NODE *n)
|
|
|
|
{
|
|
|
|
return (n && nd_type(n) == NODE_LIT && RB_INTEGER_TYPE_P(n->nd_lit));
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/**
|
|
|
|
compile each node
|
|
|
|
|
|
|
|
self: InstructionSequence
|
|
|
|
node: Ruby compiled node
|
|
|
|
poped: This node will be poped
|
|
|
|
*/
|
|
|
|
static int
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
enum node_type type;
|
2013-02-28 18:04:53 +04:00
|
|
|
LINK_ELEMENT *saved_last_element = 0;
|
2013-03-07 09:17:04 +04:00
|
|
|
int line;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (node == 0) {
|
|
|
|
if (!poped) {
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
debugs("node: NODE_NIL(implicit)\n");
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_INSN(ret, ISEQ_COMPILE_DATA(iseq)->last_line, putnil);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-27 14:06:51 +03:00
|
|
|
line = (int)nd_line(node);
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->last_line == line) {
|
2014-11-27 14:06:51 +03:00
|
|
|
/* ignore */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (node->flags & NODE_FL_NEWLINE) {
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->last_line = line;
|
2014-11-27 14:06:51 +03:00
|
|
|
ADD_TRACE(ret, line, RUBY_EVENT_LINE);
|
|
|
|
saved_last_element = ret->last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-26 22:56:15 +04:00
|
|
|
debug_node_start(node);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
type = nd_type(node);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case NODE_BLOCK:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
while (node && nd_type(node) == NODE_BLOCK) {
|
|
|
|
COMPILE_(ret, "BLOCK body", node->nd_head,
|
|
|
|
(node->nd_next == 0 && poped == 0) ? 0 : 1);
|
|
|
|
node = node->nd_next;
|
|
|
|
}
|
|
|
|
if (node) {
|
|
|
|
COMPILE_(ret, "BLOCK next", node->nd_next, poped);
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_IF:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
DECL_ANCHOR(cond_seq);
|
|
|
|
DECL_ANCHOR(then_seq);
|
|
|
|
DECL_ANCHOR(else_seq);
|
|
|
|
LABEL *then_label, *else_label, *end_label;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(cond_seq);
|
|
|
|
INIT_ANCHOR(then_seq);
|
|
|
|
INIT_ANCHOR(else_seq);
|
2013-03-07 09:17:04 +04:00
|
|
|
then_label = NEW_LABEL(line);
|
|
|
|
else_label = NEW_LABEL(line);
|
|
|
|
end_label = NEW_LABEL(line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
compile_branch_condition(iseq, cond_seq, node->nd_cond,
|
|
|
|
then_label, else_label);
|
|
|
|
COMPILE_(then_seq, "then", node->nd_body, poped);
|
|
|
|
COMPILE_(else_seq, "else", node->nd_else, poped);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_SEQ(ret, cond_seq);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, then_label);
|
|
|
|
ADD_SEQ(ret, then_seq);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, jump, end_label);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, else_label);
|
|
|
|
ADD_SEQ(ret, else_seq);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, end_label);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_CASE:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
NODE *vals;
|
|
|
|
NODE *tempnode = node;
|
|
|
|
LABEL *endlabel, *elselabel;
|
|
|
|
DECL_ANCHOR(head);
|
|
|
|
DECL_ANCHOR(body_seq);
|
|
|
|
DECL_ANCHOR(cond_seq);
|
2012-04-24 13:20:42 +04:00
|
|
|
int only_special_literals = 1;
|
|
|
|
VALUE literals = rb_hash_new();
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(head);
|
|
|
|
INIT_ANCHOR(body_seq);
|
|
|
|
INIT_ANCHOR(cond_seq);
|
2012-04-24 13:20:42 +04:00
|
|
|
|
2013-05-26 20:19:04 +04:00
|
|
|
rb_hash_tbl_raw(literals)->type = &cdhash_type;
|
2012-04-24 13:20:42 +04:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (node->nd_head == 0) {
|
|
|
|
COMPILE_(ret, "when", node->nd_body, poped);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
COMPILE(head, "case base", node->nd_head);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
node = node->nd_body;
|
|
|
|
type = nd_type(node);
|
2013-03-07 09:17:04 +04:00
|
|
|
line = nd_line(node);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (type != NODE_WHEN) {
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "NODE_CASE: unexpected node. must be NODE_WHEN, but %s", ruby_node_name(type));
|
2015-11-22 09:32:23 +03:00
|
|
|
debug_node_end();
|
|
|
|
return COMPILE_NG;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
endlabel = NEW_LABEL(line);
|
|
|
|
elselabel = NEW_LABEL(line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_SEQ(ret, head); /* case VAL */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
while (type == NODE_WHEN) {
|
|
|
|
LABEL *l1;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
l1 = NEW_LABEL(line);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(body_seq, l1);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(body_seq, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE_(body_seq, "when body", node->nd_body, poped);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(body_seq, line, jump, endlabel);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
vals = node->nd_head;
|
|
|
|
if (vals) {
|
2008-04-20 09:44:47 +04:00
|
|
|
switch (nd_type(vals)) {
|
|
|
|
case NODE_ARRAY:
|
2012-04-24 13:20:42 +04:00
|
|
|
only_special_literals = when_vals(iseq, cond_seq, vals, l1, only_special_literals, literals);
|
2008-04-20 09:44:47 +04:00
|
|
|
break;
|
|
|
|
case NODE_SPLAT:
|
|
|
|
case NODE_ARGSCAT:
|
|
|
|
case NODE_ARGSPUSH:
|
2012-04-24 13:20:42 +04:00
|
|
|
only_special_literals = 0;
|
2012-08-08 11:52:19 +04:00
|
|
|
ADD_INSN (cond_seq, nd_line(vals), dup);
|
2008-04-20 09:44:47 +04:00
|
|
|
COMPILE(cond_seq, "when/cond splat", vals);
|
2012-08-08 11:52:19 +04:00
|
|
|
ADD_INSN1(cond_seq, nd_line(vals), checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
|
2008-04-20 09:44:47 +04:00
|
|
|
ADD_INSNL(cond_seq, nd_line(vals), branchif, l1);
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-01 08:55:26 +03:00
|
|
|
UNKNOWN_NODE("NODE_CASE", vals);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-12-01 08:55:26 +03:00
|
|
|
EXPECT_NODE_NONULL("NODE_CASE", node, NODE_ARRAY);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
node = node->nd_next;
|
|
|
|
if (!node) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
type = nd_type(node);
|
2013-03-07 09:17:04 +04:00
|
|
|
line = nd_line(node);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
/* else */
|
|
|
|
if (node) {
|
|
|
|
ADD_LABEL(cond_seq, elselabel);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(cond_seq, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE_(cond_seq, "else", node, poped);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(cond_seq, line, jump, endlabel);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
debugs("== else (implicit)\n");
|
|
|
|
ADD_LABEL(cond_seq, elselabel);
|
|
|
|
ADD_INSN(cond_seq, nd_line(tempnode), pop);
|
|
|
|
if (!poped) {
|
|
|
|
ADD_INSN(cond_seq, nd_line(tempnode), putnil);
|
|
|
|
}
|
|
|
|
ADD_INSNL(cond_seq, nd_line(tempnode), jump, endlabel);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-04-24 13:20:42 +04:00
|
|
|
if (only_special_literals) {
|
|
|
|
iseq_add_mark_object(iseq, literals);
|
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_INSN(ret, nd_line(tempnode), dup);
|
2012-04-24 13:20:42 +04:00
|
|
|
ADD_INSN2(ret, nd_line(tempnode), opt_case_dispatch, literals, elselabel);
|
2015-11-14 09:26:15 +03:00
|
|
|
LABEL_REF(elselabel);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_SEQ(ret, cond_seq);
|
|
|
|
ADD_SEQ(ret, body_seq);
|
|
|
|
ADD_LABEL(ret, endlabel);
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_WHEN:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
NODE *vals;
|
|
|
|
NODE *val;
|
|
|
|
NODE *orig_node = node;
|
|
|
|
LABEL *endlabel;
|
|
|
|
DECL_ANCHOR(body_seq);
|
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(body_seq);
|
2013-03-07 09:17:04 +04:00
|
|
|
endlabel = NEW_LABEL(line);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
while (node && nd_type(node) == NODE_WHEN) {
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *l1 = NEW_LABEL(line = nd_line(node));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(body_seq, l1);
|
|
|
|
COMPILE_(body_seq, "when", node->nd_body, poped);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(body_seq, line, jump, endlabel);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
vals = node->nd_head;
|
2010-04-17 04:23:28 +04:00
|
|
|
if (!vals) {
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS "NODE_WHEN: must be NODE_ARRAY, but 0");
|
2010-04-17 04:23:28 +04:00
|
|
|
}
|
|
|
|
switch (nd_type(vals)) {
|
|
|
|
case NODE_ARRAY:
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
while (vals) {
|
|
|
|
val = vals->nd_head;
|
|
|
|
COMPILE(ret, "when2", val);
|
|
|
|
ADD_INSNL(ret, nd_line(val), branchif, l1);
|
|
|
|
vals = vals->nd_next;
|
|
|
|
}
|
2010-04-17 04:23:28 +04:00
|
|
|
break;
|
|
|
|
case NODE_SPLAT:
|
|
|
|
case NODE_ARGSCAT:
|
|
|
|
case NODE_ARGSPUSH:
|
|
|
|
ADD_INSN(ret, nd_line(vals), putnil);
|
|
|
|
COMPILE(ret, "when2/cond splat", vals);
|
2012-08-08 11:52:19 +04:00
|
|
|
ADD_INSN1(ret, nd_line(vals), checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_WHEN | VM_CHECKMATCH_ARRAY));
|
2010-04-17 04:23:28 +04:00
|
|
|
ADD_INSNL(ret, nd_line(vals), branchif, l1);
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-01 08:55:26 +03:00
|
|
|
UNKNOWN_NODE("NODE_WHEN", vals);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
node = node->nd_next;
|
|
|
|
}
|
|
|
|
/* else */
|
|
|
|
COMPILE_(ret, "else", node, poped);
|
|
|
|
ADD_INSNL(ret, nd_line(orig_node), jump, endlabel);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_SEQ(ret, body_seq);
|
|
|
|
ADD_LABEL(ret, endlabel);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_OPT_N:
|
|
|
|
case NODE_WHILE:
|
|
|
|
case NODE_UNTIL:{
|
2015-12-02 10:52:12 +03:00
|
|
|
LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
|
|
|
|
LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
|
|
|
|
LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
|
|
|
|
int prev_loopval_popped = ISEQ_COMPILE_DATA(iseq)->loopval_popped;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2009-02-16 23:54:58 +03:00
|
|
|
struct iseq_compile_data_ensure_node_stack enl;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(line); /* next */
|
|
|
|
LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(line); /* redo */
|
|
|
|
LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(line); /* break */
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *end_label = NEW_LABEL(line);
|
2015-11-22 10:53:37 +03:00
|
|
|
LABEL *adjust_label = NEW_LABEL(line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *next_catch_label = NEW_LABEL(line);
|
2008-05-24 10:29:48 +04:00
|
|
|
LABEL *tmp_label = NULL;
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->loopval_popped = 0;
|
2009-02-16 23:54:58 +03:00
|
|
|
push_ensure_entry(iseq, &enl, 0, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (type == NODE_OPT_N || node->nd_state == 1) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, jump, next_label);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2008-05-24 10:29:48 +04:00
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
tmp_label = NEW_LABEL(line);
|
|
|
|
ADD_INSNL(ret, line, jump, tmp_label);
|
2008-05-24 10:29:48 +04:00
|
|
|
}
|
2015-11-22 10:53:37 +03:00
|
|
|
ADD_LABEL(ret, adjust_label);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
2008-05-24 10:29:48 +04:00
|
|
|
ADD_LABEL(ret, next_catch_label);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
ADD_INSNL(ret, line, jump, next_label);
|
2008-05-24 10:29:48 +04:00
|
|
|
if (tmp_label) ADD_LABEL(ret, tmp_label);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, redo_label);
|
|
|
|
COMPILE_POPED(ret, "while body", node->nd_body);
|
|
|
|
ADD_LABEL(ret, next_label); /* next */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (type == NODE_WHILE) {
|
|
|
|
compile_branch_condition(iseq, ret, node->nd_cond,
|
|
|
|
redo_label, end_label);
|
|
|
|
}
|
|
|
|
else if (type == NODE_UNTIL) {
|
2013-05-19 07:10:21 +04:00
|
|
|
/* until */
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
compile_branch_condition(iseq, ret, node->nd_cond,
|
|
|
|
end_label, redo_label);
|
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_CALL_RECEIVER(ret, line);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_CALL(ret, line, idGets, INT2FIX(0));
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchif, redo_label);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
/* opt_n */
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, end_label);
|
2015-11-22 10:53:37 +03:00
|
|
|
ADD_ADJUST_RESTORE(ret, adjust_label);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (node->nd_state == Qundef) {
|
2013-03-07 09:17:04 +04:00
|
|
|
/* ADD_INSN(ret, line, putundef); */
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS "unsupported: putundef");
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-05-24 10:29:48 +04:00
|
|
|
ADD_LABEL(ret, break_label); /* break */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label,
|
|
|
|
0, break_label);
|
2008-05-24 10:29:48 +04:00
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_NEXT, redo_label, break_label, 0,
|
|
|
|
next_catch_label);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, 0,
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->redo_label);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->start_label = prev_start_label;
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->redo_label = prev_redo_label;
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->loopval_popped = prev_loopval_popped;
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->prev;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2015-04-29 06:48:26 +03:00
|
|
|
case NODE_FOR:
|
|
|
|
if (node->nd_var) {
|
|
|
|
/* massign to var in "for"
|
|
|
|
* args.length == 1 && Array === (tmp = args[0]) ? tmp : args
|
|
|
|
*/
|
|
|
|
NODE *var = node->nd_var;
|
|
|
|
LABEL *not_single = NEW_LABEL(nd_line(var));
|
|
|
|
LABEL *not_ary = NEW_LABEL(nd_line(var));
|
|
|
|
COMPILE(ret, "for var", var);
|
|
|
|
ADD_INSN(ret, line, dup);
|
|
|
|
ADD_CALL(ret, line, idLength, INT2FIX(0));
|
|
|
|
ADD_INSN1(ret, line, putobject, INT2FIX(1));
|
|
|
|
ADD_CALL(ret, line, idEq, INT2FIX(1));
|
|
|
|
ADD_INSNL(ret, line, branchunless, not_single);
|
|
|
|
ADD_INSN(ret, line, dup);
|
|
|
|
ADD_INSN1(ret, line, putobject, INT2FIX(0));
|
|
|
|
ADD_CALL(ret, line, idAREF, INT2FIX(1));
|
|
|
|
ADD_INSN1(ret, line, putobject, rb_cArray);
|
|
|
|
ADD_INSN1(ret, line, topn, INT2FIX(1));
|
|
|
|
ADD_CALL(ret, line, idEqq, INT2FIX(1));
|
|
|
|
ADD_INSNL(ret, line, branchunless, not_ary);
|
|
|
|
ADD_INSN(ret, line, swap);
|
|
|
|
ADD_LABEL(ret, not_ary);
|
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
ADD_LABEL(ret, not_single);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NODE_ITER:{
|
2015-12-02 10:52:12 +03:00
|
|
|
const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *retry_label = NEW_LABEL(line);
|
|
|
|
LABEL *retry_end_l = NEW_LABEL(line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-08-23 10:48:28 +04:00
|
|
|
ADD_LABEL(ret, retry_label);
|
|
|
|
if (nd_type(node) == NODE_FOR) {
|
|
|
|
COMPILE(ret, "iter caller (for)", node->nd_iter);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->current_block = NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq),
|
2015-07-22 01:52:59 +03:00
|
|
|
ISEQ_TYPE_BLOCK, line);
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_SEND_WITH_BLOCK(ret, line, idEach, INT2FIX(0), ISEQ_COMPILE_DATA(iseq)->current_block);
|
2007-08-23 10:48:28 +04:00
|
|
|
}
|
|
|
|
else {
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->current_block = NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq),
|
2015-07-22 01:52:59 +03:00
|
|
|
ISEQ_TYPE_BLOCK, line);
|
2007-08-23 10:48:28 +04:00
|
|
|
COMPILE(ret, "iter caller", node->nd_iter);
|
|
|
|
}
|
|
|
|
ADD_LABEL(ret, retry_end_l);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-08-23 10:48:28 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2007-08-23 10:48:28 +04:00
|
|
|
}
|
2007-07-05 14:04:56 +04:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
|
2007-07-05 14:04:56 +04:00
|
|
|
|
2007-08-23 10:48:28 +04:00
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, 0, retry_end_l);
|
2007-07-05 14:04:56 +04:00
|
|
|
|
2007-08-23 10:48:28 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_BREAK:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
unsigned long level = 0;
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
/* while/until */
|
2008-01-26 11:27:00 +03:00
|
|
|
LABEL *splabel = NEW_LABEL(0);
|
|
|
|
ADD_LABEL(ret, splabel);
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_ADJUST(ret, line, ISEQ_COMPILE_DATA(iseq)->redo_label);
|
|
|
|
COMPILE_(ret, "break val (while/until)", node->nd_stts, ISEQ_COMPILE_DATA(iseq)->loopval_popped);
|
2009-02-16 23:54:58 +03:00
|
|
|
add_ensure_iseq(ret, iseq, 0);
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_INSNL(ret, line, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
|
2008-01-26 11:27:00 +03:00
|
|
|
ADD_ADJUST_RESTORE(ret, splabel);
|
|
|
|
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
2008-01-26 11:27:00 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (iseq->body->type == ISEQ_TYPE_BLOCK) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break_by_insn:
|
|
|
|
/* escape from block */
|
|
|
|
COMPILE(ret, "break val (block)", node->nd_stts);
|
2015-07-17 16:18:12 +03:00
|
|
|
ADD_INSN1(ret, line, throw, INT2FIX(level | TAG_BREAK));
|
2008-01-26 11:27:00 +03:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2008-01-26 11:27:00 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (iseq->body->type == ISEQ_TYPE_EVAL) {
|
2007-12-19 19:10:54 +03:00
|
|
|
break_in_eval:
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "Can't escape from eval with break");
|
2015-11-22 09:32:23 +03:00
|
|
|
debug_node_end();
|
|
|
|
return COMPILE_NG;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *ip = iseq->body->parent_iseq;
|
|
|
|
|
2007-12-19 19:10:54 +03:00
|
|
|
while (ip) {
|
2015-12-02 10:52:12 +03:00
|
|
|
if (!ISEQ_COMPILE_DATA(ip)) {
|
2008-12-27 08:58:23 +03:00
|
|
|
ip = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
level++;
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
|
2015-07-20 03:08:23 +03:00
|
|
|
level = VM_THROW_NO_ESCAPE_FLAG;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
goto break_by_insn;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (ip->body->type == ISEQ_TYPE_BLOCK) {
|
2015-07-20 03:08:23 +03:00
|
|
|
level <<= VM_THROW_LEVEL_SHIFT;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
goto break_by_insn;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (ip->body->type == ISEQ_TYPE_EVAL) {
|
2007-12-19 19:10:54 +03:00
|
|
|
goto break_in_eval;
|
|
|
|
}
|
2008-12-27 08:58:23 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
ip = ip->body->parent_iseq;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "Invalid break");
|
2015-11-22 09:32:23 +03:00
|
|
|
debug_node_end();
|
|
|
|
return COMPILE_NG;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_NEXT:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
unsigned long level = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0) {
|
2008-01-26 11:27:00 +03:00
|
|
|
LABEL *splabel = NEW_LABEL(0);
|
2008-01-25 21:02:01 +03:00
|
|
|
debugs("next in while loop\n");
|
2008-01-26 11:27:00 +03:00
|
|
|
ADD_LABEL(ret, splabel);
|
2008-01-26 11:44:43 +03:00
|
|
|
COMPILE(ret, "next val/valid syntax?", node->nd_stts);
|
2009-02-16 23:54:58 +03:00
|
|
|
add_ensure_iseq(ret, iseq, 0);
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_ADJUST(ret, line, ISEQ_COMPILE_DATA(iseq)->redo_label);
|
|
|
|
ADD_INSNL(ret, line, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
|
2008-01-26 11:27:00 +03:00
|
|
|
ADD_ADJUST_RESTORE(ret, splabel);
|
2010-04-20 19:28:33 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
2010-04-20 19:28:33 +04:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2015-12-02 10:52:12 +03:00
|
|
|
else if (ISEQ_COMPILE_DATA(iseq)->end_label) {
|
2008-01-26 11:27:00 +03:00
|
|
|
LABEL *splabel = NEW_LABEL(0);
|
2007-08-16 17:12:24 +04:00
|
|
|
debugs("next in block\n");
|
2008-01-26 11:27:00 +03:00
|
|
|
ADD_LABEL(ret, splabel);
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_ADJUST(ret, line, ISEQ_COMPILE_DATA(iseq)->start_label);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "next val", node->nd_stts);
|
2009-02-16 23:54:58 +03:00
|
|
|
add_ensure_iseq(ret, iseq, 0);
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_INSNL(ret, line, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
|
2008-01-26 11:27:00 +03:00
|
|
|
ADD_ADJUST_RESTORE(ret, splabel);
|
|
|
|
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
2008-01-26 11:27:00 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (iseq->body->type == ISEQ_TYPE_EVAL) {
|
2007-12-19 19:10:54 +03:00
|
|
|
next_in_eval:
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "Can't escape from eval with next");
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2015-07-16 16:13:50 +03:00
|
|
|
const rb_iseq_t *ip = iseq;
|
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
while (ip) {
|
2015-12-02 10:52:12 +03:00
|
|
|
if (!ISEQ_COMPILE_DATA(ip)) {
|
2008-12-27 08:58:23 +03:00
|
|
|
ip = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-20 03:08:23 +03:00
|
|
|
level = VM_THROW_NO_ESCAPE_FLAG;
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
|
2007-08-16 22:12:02 +04:00
|
|
|
/* while loop */
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (ip->body->type == ISEQ_TYPE_BLOCK) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (ip->body->type == ISEQ_TYPE_EVAL) {
|
2007-12-19 19:10:54 +03:00
|
|
|
goto next_in_eval;
|
|
|
|
}
|
2008-12-27 08:58:23 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
ip = ip->body->parent_iseq;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
if (ip != 0) {
|
|
|
|
COMPILE(ret, "next val", node->nd_stts);
|
2015-07-17 16:18:12 +03:00
|
|
|
ADD_INSN1(ret, line, throw, INT2FIX(level | TAG_NEXT));
|
2008-01-26 11:27:00 +03:00
|
|
|
|
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2007-08-16 17:12:24 +04:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "Invalid next");
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_REDO:{
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->redo_label) {
|
2008-01-26 11:27:00 +03:00
|
|
|
LABEL *splabel = NEW_LABEL(0);
|
2007-08-16 17:12:24 +04:00
|
|
|
debugs("redo in while");
|
2008-01-26 11:27:00 +03:00
|
|
|
ADD_LABEL(ret, splabel);
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_ADJUST(ret, line, ISEQ_COMPILE_DATA(iseq)->redo_label);
|
2009-02-16 23:54:58 +03:00
|
|
|
add_ensure_iseq(ret, iseq, 0);
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_INSNL(ret, line, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
|
2008-01-26 11:27:00 +03:00
|
|
|
ADD_ADJUST_RESTORE(ret, splabel);
|
2010-04-20 19:28:33 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
2010-04-20 19:28:33 +04:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (iseq->body->type == ISEQ_TYPE_EVAL) {
|
2007-12-19 19:10:54 +03:00
|
|
|
redo_in_eval:
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "Can't escape from eval with redo");
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2015-12-02 10:52:12 +03:00
|
|
|
else if (ISEQ_COMPILE_DATA(iseq)->start_label) {
|
2008-01-26 11:27:00 +03:00
|
|
|
LABEL *splabel = NEW_LABEL(0);
|
|
|
|
|
|
|
|
debugs("redo in block");
|
|
|
|
ADD_LABEL(ret, splabel);
|
2009-02-16 23:54:58 +03:00
|
|
|
add_ensure_iseq(ret, iseq, 0);
|
2015-12-02 10:52:12 +03:00
|
|
|
ADD_ADJUST(ret, line, ISEQ_COMPILE_DATA(iseq)->start_label);
|
|
|
|
ADD_INSNL(ret, line, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
|
2008-01-26 11:27:00 +03:00
|
|
|
ADD_ADJUST_RESTORE(ret, splabel);
|
|
|
|
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-07-16 16:13:50 +03:00
|
|
|
const rb_iseq_t *ip = iseq;
|
2015-07-20 03:08:23 +03:00
|
|
|
const unsigned long level = VM_THROW_NO_ESCAPE_FLAG;
|
2015-07-16 16:13:50 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
while (ip) {
|
2015-12-02 10:52:12 +03:00
|
|
|
if (!ISEQ_COMPILE_DATA(ip)) {
|
2008-12-27 08:58:23 +03:00
|
|
|
ip = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
|
2007-08-16 17:12:24 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (ip->body->type == ISEQ_TYPE_BLOCK) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (ip->body->type == ISEQ_TYPE_EVAL) {
|
2007-12-19 19:10:54 +03:00
|
|
|
goto redo_in_eval;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2008-12-27 08:58:23 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
ip = ip->body->parent_iseq;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
if (ip != 0) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
2015-07-17 16:18:12 +03:00
|
|
|
ADD_INSN1(ret, line, throw, INT2FIX(level | TAG_REDO));
|
2008-01-26 11:27:00 +03:00
|
|
|
|
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2008-01-26 11:27:00 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "Invalid redo");
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_RETRY:{
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->type == ISEQ_TYPE_RESCUE) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
2015-07-17 16:18:12 +03:00
|
|
|
ADD_INSN1(ret, line, throw, INT2FIX(TAG_RETRY));
|
2007-12-25 15:37:16 +03:00
|
|
|
|
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2007-12-25 15:37:16 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "Invalid retry");
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_BEGIN:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE_(ret, "NODE_BEGIN", node->nd_body, poped);
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_RESCUE:{
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *lstart = NEW_LABEL(line);
|
|
|
|
LABEL *lend = NEW_LABEL(line);
|
|
|
|
LABEL *lcont = NEW_LABEL(line);
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *rescue = NEW_CHILD_ISEQ(node->nd_resq,
|
|
|
|
rb_str_concat(rb_str_new2("rescue in "), iseq->body->location.label),
|
|
|
|
ISEQ_TYPE_RESCUE, line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2016-04-11 11:43:06 +03:00
|
|
|
lstart->rescued = LABEL_RESCUE_BEG;
|
|
|
|
lend->rescued = LABEL_RESCUE_END;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, lstart);
|
|
|
|
COMPILE(ret, "rescue head", node->nd_head);
|
|
|
|
ADD_LABEL(ret, lend);
|
|
|
|
if (node->nd_else) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "rescue else", node->nd_else);
|
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, nop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, lcont);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
|
2009-11-03 20:46:28 +03:00
|
|
|
/* register catch entry */
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lcont);
|
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, 0, lstart);
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_RESBODY:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
NODE *resq = node;
|
|
|
|
NODE *narg;
|
|
|
|
LABEL *label_miss, *label_hit;
|
|
|
|
|
|
|
|
while (resq) {
|
2013-03-07 09:17:04 +04:00
|
|
|
label_miss = NEW_LABEL(line);
|
|
|
|
label_hit = NEW_LABEL(line);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
narg = resq->nd_args;
|
2008-04-20 09:44:47 +04:00
|
|
|
if (narg) {
|
|
|
|
switch (nd_type(narg)) {
|
|
|
|
case NODE_ARRAY:
|
|
|
|
while (narg) {
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(ret, line, LVAR_ERRINFO, 0);
|
2012-08-08 11:52:19 +04:00
|
|
|
COMPILE(ret, "rescue arg", narg->nd_head);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
|
|
|
|
ADD_INSNL(ret, line, branchif, label_hit);
|
2008-04-20 09:44:47 +04:00
|
|
|
narg = narg->nd_next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NODE_SPLAT:
|
|
|
|
case NODE_ARGSCAT:
|
|
|
|
case NODE_ARGSPUSH:
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(ret, line, LVAR_ERRINFO, 0);
|
2008-04-20 09:44:47 +04:00
|
|
|
COMPILE(ret, "rescue/cond splat", narg);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_RESCUE | VM_CHECKMATCH_ARRAY));
|
|
|
|
ADD_INSNL(ret, line, branchif, label_hit);
|
2008-04-20 09:44:47 +04:00
|
|
|
break;
|
|
|
|
default:
|
2015-12-01 08:55:26 +03:00
|
|
|
UNKNOWN_NODE("NODE_RESBODY", narg);
|
2008-04-20 09:44:47 +04:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2008-04-20 09:44:47 +04:00
|
|
|
else {
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(ret, line, LVAR_ERRINFO, 0);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putobject, rb_eStandardError);
|
|
|
|
ADD_INSN1(ret, line, checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
|
|
|
|
ADD_INSNL(ret, line, branchif, label_hit);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, jump, label_miss);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, label_hit);
|
|
|
|
COMPILE(ret, "resbody body", resq->nd_body);
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->tailcall_optimization) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, nop);
|
2007-08-19 08:16:13 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, leave);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, label_miss);
|
|
|
|
resq = resq->nd_head;
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_ENSURE:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
DECL_ANCHOR(ensr);
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *ensure = NEW_CHILD_ISEQ(node->nd_ensr,
|
|
|
|
rb_str_concat(rb_str_new2 ("ensure in "), iseq->body->location.label),
|
|
|
|
ISEQ_TYPE_ENSURE, line);
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *lstart = NEW_LABEL(line);
|
|
|
|
LABEL *lend = NEW_LABEL(line);
|
|
|
|
LABEL *lcont = NEW_LABEL(line);
|
2009-02-16 23:54:58 +03:00
|
|
|
struct ensure_range er;
|
2007-07-20 11:11:35 +04:00
|
|
|
struct iseq_compile_data_ensure_node_stack enl;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
struct ensure_range *erange;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(ensr);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE_POPED(ensr, "ensure ensr", node->nd_ensr);
|
|
|
|
|
2009-02-16 23:54:58 +03:00
|
|
|
er.begin = lstart;
|
|
|
|
er.end = lend;
|
|
|
|
er.next = 0;
|
|
|
|
push_ensure_entry(iseq, &enl, &er, node->nd_ensr);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
ADD_LABEL(ret, lstart);
|
|
|
|
COMPILE_(ret, "ensure head", node->nd_head, poped);
|
|
|
|
ADD_LABEL(ret, lend);
|
|
|
|
if (ensr->anchor.next == 0) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, nop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_SEQ(ret, ensr);
|
|
|
|
}
|
|
|
|
ADD_LABEL(ret, lcont);
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
erange = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->erange;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
while (erange) {
|
|
|
|
ADD_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end,
|
|
|
|
ensure, lcont);
|
|
|
|
erange = erange->next;
|
|
|
|
}
|
2009-02-16 23:54:58 +03:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl.prev;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case NODE_AND:
|
|
|
|
case NODE_OR:{
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *end_label = NEW_LABEL(line);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "nd_1st", node->nd_1st);
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
if (type == NODE_AND) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchunless, end_label);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchif, end_label);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
COMPILE_(ret, "nd_2nd", node->nd_2nd, poped);
|
|
|
|
ADD_LABEL(ret, end_label);
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case NODE_MASGN:{
|
2008-10-12 05:18:49 +04:00
|
|
|
compile_massign(iseq, ret, node, poped);
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case NODE_LASGN:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ID id = node->nd_vid;
|
2016-07-28 14:02:30 +03:00
|
|
|
int idx = iseq->body->local_iseq->body->local_table_size - get_local_var_idx(iseq, id);
|
2007-02-25 04:34:33 +03:00
|
|
|
|
2014-11-25 21:44:22 +03:00
|
|
|
debugs("lvar: %"PRIsVALUE" idx: %d\n", rb_id2str(id), idx);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "rvalue", node->nd_value);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_SETLOCAL(ret, line, idx, get_lvar_level(iseq));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DASGN:
|
|
|
|
case NODE_DASGN_CURR:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
int idx, lv, ls;
|
|
|
|
COMPILE(ret, "dvalue", node->nd_value);
|
2014-11-25 21:44:22 +03:00
|
|
|
debugi("dassn id", rb_id2str(node->nd_vid) ? node->nd_vid : '*');
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-07-07 12:14:00 +04:00
|
|
|
idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (idx < 0) {
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS "NODE_DASGN(_CURR): unknown id (%"PRIsVALUE")",
|
|
|
|
rb_id2str(node->nd_vid));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_SETLOCAL(ret, line, ls - idx, lv);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_GASGN:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "lvalue", node->nd_value);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setglobal,
|
2010-10-12 17:41:12 +04:00
|
|
|
((VALUE)node->nd_entry | 1));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-02-06 08:22:17 +03:00
|
|
|
case NODE_IASGN:
|
2007-02-04 22:17:33 +03:00
|
|
|
case NODE_IASGN2:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "lvalue", node->nd_value);
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN2(ret, line, setinstancevariable,
|
2016-05-11 15:50:38 +03:00
|
|
|
ID2SYM(node->nd_vid),
|
|
|
|
get_ivar_ic_value(iseq,node->nd_vid));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2007-02-04 22:17:33 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_CDECL:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "lvalue", node->nd_value);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (node->nd_vid) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putspecialobject,
|
2009-12-03 21:25:57 +03:00
|
|
|
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setconstant, ID2SYM(node->nd_vid));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
compile_cpath(ret, iseq, node->nd_else);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setconstant, ID2SYM(node->nd_else->nd_mid));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-02-02 13:24:06 +03:00
|
|
|
case NODE_CVASGN:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "cvasgn val", node->nd_value);
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setclassvariable,
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ID2SYM(node->nd_vid));
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-11-27 09:45:01 +03:00
|
|
|
case NODE_OP_ASGN1: {
|
2008-10-12 05:18:49 +04:00
|
|
|
DECL_ANCHOR(args);
|
|
|
|
VALUE argc;
|
rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.
ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody
This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated
* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
ci->index becomes a 32-bit signed int (from signed long).
Reorder for better packing on 64-bit, giving an 8 byte reduction
from 104 to 96 bytes for each ci.
* compile.c (new_callinfo, setup_args, iseq_compile_each,
iseq_build_from_ary_body): adjust for type changes
* vm_insnhelper.c (vm_getivar): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:32:44 +04:00
|
|
|
unsigned int flag = 0;
|
2014-09-14 05:56:53 +04:00
|
|
|
unsigned int asgnflag = 0;
|
2008-10-12 05:18:49 +04:00
|
|
|
ID id = node->nd_mid;
|
2010-06-02 07:05:06 +04:00
|
|
|
int boff = 0;
|
2008-10-12 05:18:49 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* a[x] (op)= y
|
|
|
|
*
|
2009-09-05 10:21:15 +04:00
|
|
|
* nil # nil
|
|
|
|
* eval a # nil a
|
|
|
|
* eval x # nil a x
|
|
|
|
* dupn 2 # nil a x a x
|
|
|
|
* send :[] # nil a x a[x]
|
|
|
|
* eval y # nil a x a[x] y
|
|
|
|
* send op # nil a x ret
|
|
|
|
* setn 3 # ret a x ret
|
|
|
|
* send []= # ret ?
|
|
|
|
* pop # ret
|
2008-10-12 05:18:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nd_recv[nd_args->nd_body] (nd_mid)= nd_args->nd_head;
|
|
|
|
* NODE_OP_ASGN nd_recv
|
|
|
|
* nd_args->nd_head
|
|
|
|
* nd_args->nd_body
|
|
|
|
* nd_mid
|
|
|
|
*/
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2009-09-05 10:21:15 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
2009-09-05 10:21:15 +04:00
|
|
|
}
|
2014-06-06 12:07:13 +04:00
|
|
|
asgnflag = COMPILE_RECV(ret, "NODE_OP_ASGN1 recv", node);
|
2010-06-02 07:05:06 +04:00
|
|
|
switch (nd_type(node->nd_args->nd_head)) {
|
|
|
|
case NODE_ZARRAY:
|
|
|
|
argc = INT2FIX(0);
|
|
|
|
break;
|
|
|
|
case NODE_BLOCK_PASS:
|
|
|
|
boff = 1;
|
|
|
|
default:
|
2008-10-12 05:18:49 +04:00
|
|
|
INIT_ANCHOR(args);
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
argc = setup_args(iseq, args, node->nd_args->nd_head, &flag, NULL);
|
2008-10-12 05:18:49 +04:00
|
|
|
ADD_SEQ(ret, args);
|
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, dupn, FIXNUM_INC(argc, 1 + boff));
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_SEND_WITH_FLAG(ret, line, idAREF, argc, INT2FIX(flag));
|
2015-04-30 13:51:13 +03:00
|
|
|
flag |= asgnflag;
|
2008-10-12 05:18:49 +04:00
|
|
|
|
|
|
|
if (id == 0 || id == 1) {
|
|
|
|
/* 0: or, 1: and
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
a[x] ||= y
|
|
|
|
|
|
|
|
unless/if a[x]
|
|
|
|
a[x]= y
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2008-10-12 05:18:49 +04:00
|
|
|
*/
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *label = NEW_LABEL(line);
|
|
|
|
LABEL *lfin = NEW_LABEL(line);
|
2008-10-12 05:18:49 +04:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
2008-10-12 05:18:49 +04:00
|
|
|
if (id == 0) {
|
|
|
|
/* or */
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchif, label);
|
2008-10-12 05:18:49 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* and */
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchunless, label);
|
2008-10-12 05:18:49 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2009-09-18 11:15:06 +04:00
|
|
|
COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body);
|
2009-09-05 10:21:15 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 2+boff));
|
2009-09-05 10:21:15 +04:00
|
|
|
}
|
2012-10-15 21:22:57 +04:00
|
|
|
if (flag & VM_CALL_ARGS_SPLAT) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, newarray, INT2FIX(1));
|
2010-06-02 07:05:06 +04:00
|
|
|
if (boff > 0) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, dupn, INT2FIX(3));
|
|
|
|
ADD_INSN(ret, line, swap);
|
|
|
|
ADD_INSN(ret, line, pop);
|
2010-06-02 07:05:06 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, concatarray);
|
2010-06-02 07:05:06 +04:00
|
|
|
if (boff > 0) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setn, INT2FIX(3));
|
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
ADD_INSN(ret, line, pop);
|
2010-06-02 07:05:06 +04:00
|
|
|
}
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_SEND_WITH_FLAG(ret, line, idASET, argc, INT2FIX(flag));
|
2008-10-12 05:18:49 +04:00
|
|
|
}
|
|
|
|
else {
|
2010-06-02 07:05:06 +04:00
|
|
|
if (boff > 0)
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, swap);
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_SEND_WITH_FLAG(ret, line, idASET, FIXNUM_INC(argc, 1), INT2FIX(flag));
|
2008-10-12 05:18:49 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
ADD_INSNL(ret, line, jump, lfin);
|
2008-10-12 05:18:49 +04:00
|
|
|
ADD_LABEL(ret, label);
|
2009-09-05 10:21:15 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 2+boff));
|
2009-09-05 10:21:15 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, adjuststack, FIXNUM_INC(argc, 2+boff));
|
2008-10-12 05:18:49 +04:00
|
|
|
ADD_LABEL(ret, lfin);
|
|
|
|
}
|
|
|
|
else {
|
2009-09-18 11:15:06 +04:00
|
|
|
COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, id, INT2FIX(1));
|
2009-09-05 10:21:15 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 2+boff));
|
2009-09-05 10:21:15 +04:00
|
|
|
}
|
2012-10-15 21:22:57 +04:00
|
|
|
if (flag & VM_CALL_ARGS_SPLAT) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, newarray, INT2FIX(1));
|
2010-06-02 07:05:06 +04:00
|
|
|
if (boff > 0) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, dupn, INT2FIX(3));
|
|
|
|
ADD_INSN(ret, line, swap);
|
|
|
|
ADD_INSN(ret, line, pop);
|
2010-06-02 07:05:06 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, concatarray);
|
2010-06-02 07:05:06 +04:00
|
|
|
if (boff > 0) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setn, INT2FIX(3));
|
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
ADD_INSN(ret, line, pop);
|
2010-06-02 07:05:06 +04:00
|
|
|
}
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_SEND_WITH_FLAG(ret, line, idASET, argc, INT2FIX(flag));
|
2008-10-12 05:18:49 +04:00
|
|
|
}
|
|
|
|
else {
|
2010-06-02 07:05:06 +04:00
|
|
|
if (boff > 0)
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, swap);
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_SEND_WITH_FLAG(ret, line, idASET, FIXNUM_INC(argc, 1), INT2FIX(flag));
|
2008-10-12 05:18:49 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2008-10-12 05:18:49 +04:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2008-10-12 05:18:49 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_OP_ASGN2:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ID atype = node->nd_next->nd_mid;
|
2015-10-12 05:48:37 +03:00
|
|
|
ID vid = node->nd_next->nd_vid, aid = rb_id_attrset(vid);
|
2014-06-06 12:07:13 +04:00
|
|
|
VALUE asgnflag;
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *lfin = NEW_LABEL(line);
|
|
|
|
LABEL *lcfin = NEW_LABEL(line);
|
2015-10-22 09:30:12 +03:00
|
|
|
LABEL *lskip = 0;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
/*
|
|
|
|
class C; attr_accessor :c; end
|
|
|
|
r = C.new
|
|
|
|
r.a &&= v # asgn2
|
|
|
|
|
|
|
|
eval r # r
|
|
|
|
dup # r r
|
|
|
|
eval r.a # r o
|
|
|
|
|
|
|
|
# or
|
|
|
|
dup # r o o
|
|
|
|
if lcfin # r o
|
|
|
|
pop # r
|
|
|
|
eval v # r v
|
2009-09-05 05:38:47 +04:00
|
|
|
swap # v r
|
|
|
|
topn 1 # v r v
|
|
|
|
send a= # v ?
|
|
|
|
jump lfin # v ?
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
lcfin: # r o
|
|
|
|
swap # o r
|
|
|
|
|
2009-09-05 05:38:47 +04:00
|
|
|
lfin: # o ?
|
|
|
|
pop # o
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
# and
|
|
|
|
dup # r o o
|
|
|
|
unless lcfin
|
|
|
|
pop # r
|
|
|
|
eval v # r v
|
2009-09-05 05:38:47 +04:00
|
|
|
swap # v r
|
|
|
|
topn 1 # v r v
|
|
|
|
send a= # v ?
|
|
|
|
jump lfin # v ?
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
# others
|
|
|
|
eval v # r o v
|
|
|
|
send ?? # r w
|
|
|
|
send a= # w
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-06-06 12:07:13 +04:00
|
|
|
asgnflag = COMPILE_RECV(ret, "NODE_OP_ASGN2#recv", node);
|
2015-10-22 09:30:12 +03:00
|
|
|
if (node->nd_next->nd_aid) {
|
|
|
|
lskip = NEW_LABEL(line);
|
|
|
|
ADD_INSN(ret, line, dup);
|
|
|
|
ADD_INSNL(ret, line, branchnil, lskip);
|
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
2015-10-12 05:48:37 +03:00
|
|
|
ADD_SEND(ret, line, vid, INT2FIX(0));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
if (atype == 0 || atype == 1) { /* 0: OR or 1: AND */
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (atype == 0) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchif, lcfin);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchunless, lcfin);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, swap);
|
|
|
|
ADD_INSN1(ret, line, topn, INT2FIX(1));
|
2015-10-12 05:48:37 +03:00
|
|
|
ADD_SEND_WITH_FLAG(ret, line, aid, INT2FIX(1), INT2FIX(asgnflag));
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, jump, lfin);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, lcfin);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, swap);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, lfin);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2015-10-22 09:30:12 +03:00
|
|
|
if (lskip) {
|
|
|
|
ADD_LABEL(ret, lskip);
|
|
|
|
}
|
2009-09-05 05:38:47 +04:00
|
|
|
if (poped) {
|
|
|
|
/* we can apply more optimize */
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2009-09-05 05:38:47 +04:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value);
|
2015-10-22 09:30:12 +03:00
|
|
|
ADD_SEND(ret, line, atype, INT2FIX(1));
|
2009-09-05 05:38:47 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, swap);
|
|
|
|
ADD_INSN1(ret, line, topn, INT2FIX(1));
|
2009-09-05 05:38:47 +04:00
|
|
|
}
|
2015-10-12 05:48:37 +03:00
|
|
|
ADD_SEND_WITH_FLAG(ret, line, aid, INT2FIX(1), INT2FIX(asgnflag));
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2015-10-22 09:30:12 +03:00
|
|
|
if (lskip) {
|
|
|
|
ADD_LABEL(ret, lskip);
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2012-12-24 19:59:31 +04:00
|
|
|
case NODE_OP_CDECL: {
|
|
|
|
LABEL *lfin = 0;
|
|
|
|
LABEL *lassign = 0;
|
|
|
|
ID mid;
|
|
|
|
|
|
|
|
switch (nd_type(node->nd_head)) {
|
|
|
|
case NODE_COLON3:
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putobject, rb_cObject);
|
2012-12-24 19:59:31 +04:00
|
|
|
break;
|
|
|
|
case NODE_COLON2:
|
|
|
|
COMPILE(ret, "NODE_OP_CDECL/colon2#nd_head", node->nd_head->nd_head);
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "%s: invalid node in NODE_OP_CDECL",
|
|
|
|
ruby_node_name(nd_type(node->nd_head)));
|
2015-11-22 09:32:23 +03:00
|
|
|
debug_node_end();
|
2012-12-24 19:59:31 +04:00
|
|
|
return COMPILE_NG;
|
|
|
|
}
|
|
|
|
mid = node->nd_head->nd_mid;
|
|
|
|
/* cref */
|
|
|
|
if (node->nd_aid == 0) {
|
2013-03-07 09:17:04 +04:00
|
|
|
lassign = NEW_LABEL(line);
|
|
|
|
ADD_INSN(ret, line, dup); /* cref cref */
|
|
|
|
ADD_INSN3(ret, line, defined, INT2FIX(DEFINED_CONST),
|
2012-12-24 19:59:31 +04:00
|
|
|
ID2SYM(mid), Qfalse); /* cref bool */
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchunless, lassign); /* cref */
|
2012-12-24 19:59:31 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup); /* cref cref */
|
|
|
|
ADD_INSN1(ret, line, getconstant, ID2SYM(mid)); /* cref obj */
|
2012-12-24 19:59:31 +04:00
|
|
|
|
|
|
|
if (node->nd_aid == 0 || node->nd_aid == 1) {
|
2013-03-07 09:17:04 +04:00
|
|
|
lfin = NEW_LABEL(line);
|
|
|
|
if (!poped) ADD_INSN(ret, line, dup); /* cref [obj] obj */
|
2012-12-24 19:59:31 +04:00
|
|
|
if (node->nd_aid == 0)
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchif, lfin);
|
2012-12-24 19:59:31 +04:00
|
|
|
else
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchunless, lfin);
|
2012-12-24 19:59:31 +04:00
|
|
|
/* cref [obj] */
|
2013-03-07 09:17:04 +04:00
|
|
|
if (!poped) ADD_INSN(ret, line, pop); /* cref */
|
2012-12-24 19:59:31 +04:00
|
|
|
if (lassign) ADD_LABEL(ret, lassign);
|
|
|
|
COMPILE(ret, "NODE_OP_CDECL#nd_value", node->nd_value);
|
|
|
|
/* cref value */
|
|
|
|
if (poped)
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, topn, INT2FIX(1)); /* cref value cref */
|
2012-12-24 19:59:31 +04:00
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, dupn, INT2FIX(2)); /* cref value cref value */
|
|
|
|
ADD_INSN(ret, line, swap); /* cref value value cref */
|
2012-12-24 19:59:31 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setconstant, ID2SYM(mid)); /* cref [value] */
|
2012-12-24 19:59:31 +04:00
|
|
|
ADD_LABEL(ret, lfin); /* cref [value] */
|
2013-03-07 09:17:04 +04:00
|
|
|
if (!poped) ADD_INSN(ret, line, swap); /* [value] cref */
|
|
|
|
ADD_INSN(ret, line, pop); /* [value] */
|
2012-12-24 19:59:31 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
COMPILE(ret, "NODE_OP_CDECL#nd_value", node->nd_value);
|
|
|
|
/* cref obj value */
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_CALL(ret, line, node->nd_aid, INT2FIX(1));
|
2012-12-24 19:59:31 +04:00
|
|
|
/* cref value */
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, swap); /* value cref */
|
2012-12-24 19:59:31 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, topn, INT2FIX(1)); /* value cref value */
|
|
|
|
ADD_INSN(ret, line, swap); /* value value cref */
|
2012-12-24 19:59:31 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setconstant, ID2SYM(mid));
|
2012-12-24 19:59:31 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_OP_ASGN_AND:
|
|
|
|
case NODE_OP_ASGN_OR:{
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *lfin = NEW_LABEL(line);
|
2008-03-25 09:26:32 +03:00
|
|
|
LABEL *lassign;
|
2007-06-05 08:49:54 +04:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (nd_type(node) == NODE_OP_ASGN_OR) {
|
2008-03-25 09:26:32 +03:00
|
|
|
LABEL *lfinish[2];
|
|
|
|
lfinish[0] = lfin;
|
|
|
|
lfinish[1] = 0;
|
|
|
|
defined_expr(iseq, ret, node->nd_head, lfinish, Qfalse);
|
|
|
|
lassign = lfinish[1];
|
|
|
|
if (!lassign) {
|
2013-03-07 09:17:04 +04:00
|
|
|
lassign = NEW_LABEL(line);
|
2008-03-25 09:26:32 +03:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchunless, lassign);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2008-03-25 09:26:32 +03:00
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
lassign = NEW_LABEL(line);
|
2008-03-25 09:26:32 +03:00
|
|
|
}
|
2007-06-05 08:49:54 +04:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "NODE_OP_ASGN_AND/OR#nd_head", node->nd_head);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
2007-06-05 08:49:54 +04:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (nd_type(node) == NODE_OP_ASGN_AND) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchunless, lfin);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, branchif, lfin);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, lassign);
|
|
|
|
COMPILE(ret, "NODE_OP_ASGN_AND/OR#nd_value", node->nd_value);
|
|
|
|
ADD_LABEL(ret, lfin);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
|
|
|
/* we can apply more optimize */
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_CALL:
|
2014-01-10 08:54:08 +04:00
|
|
|
/* optimization shortcut
|
|
|
|
* "literal".freeze -> opt_str_freeze("literal")
|
|
|
|
*/
|
2013-11-10 01:17:06 +04:00
|
|
|
if (node->nd_recv && nd_type(node->nd_recv) == NODE_STR &&
|
2014-12-17 03:54:13 +03:00
|
|
|
node->nd_mid == idFreeze && node->nd_args == NULL &&
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->current_block == NULL &&
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
|
2013-11-10 01:17:06 +04:00
|
|
|
VALUE str = rb_fstring(node->nd_recv->nd_lit);
|
|
|
|
iseq_add_mark_object(iseq, str);
|
|
|
|
ADD_INSN1(ret, line, opt_str_freeze, str);
|
|
|
|
if (poped) {
|
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-01-10 08:54:08 +04:00
|
|
|
/* optimization shortcut
|
|
|
|
* obj["literal"] -> opt_aref_with(obj, "literal")
|
|
|
|
*/
|
2014-06-06 10:05:19 +04:00
|
|
|
if (node->nd_mid == idAREF && !private_recv_p(node) && node->nd_args &&
|
2014-01-10 08:54:08 +04:00
|
|
|
nd_type(node->nd_args) == NODE_ARRAY && node->nd_args->nd_alen == 1 &&
|
2014-12-17 03:54:13 +03:00
|
|
|
nd_type(node->nd_args->nd_head) == NODE_STR &&
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->current_block == NULL &&
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
|
2014-01-10 08:54:08 +04:00
|
|
|
VALUE str = rb_fstring(node->nd_args->nd_head->nd_lit);
|
|
|
|
node->nd_args->nd_head->nd_lit = str;
|
|
|
|
COMPILE(ret, "recv", node->nd_recv);
|
2015-09-19 20:59:58 +03:00
|
|
|
ADD_INSN3(ret, line, opt_aref_with,
|
|
|
|
new_callinfo(iseq, idAREF, 1, 0, NULL, FALSE),
|
2015-11-26 15:36:43 +03:00
|
|
|
NULL/* CALL_CACHE */, str);
|
2014-01-10 08:54:08 +04:00
|
|
|
if (poped) {
|
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-10-22 09:30:12 +03:00
|
|
|
case NODE_QCALL:
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_FCALL:
|
|
|
|
case NODE_VCALL:{ /* VCALL: variable or call */
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
/*
|
|
|
|
call: obj.method(...)
|
|
|
|
fcall: func(...)
|
|
|
|
vcall: func
|
|
|
|
*/
|
|
|
|
DECL_ANCHOR(recv);
|
|
|
|
DECL_ANCHOR(args);
|
2015-10-22 09:30:12 +03:00
|
|
|
LABEL *lskip = 0;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ID mid = node->nd_mid;
|
|
|
|
VALUE argc;
|
rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.
ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody
This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated
* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
ci->index becomes a 32-bit signed int (from signed long).
Reorder for better packing on 64-bit, giving an 8 byte reduction
from 104 to 96 bytes for each ci.
* compile.c (new_callinfo, setup_args, iseq_compile_each,
iseq_build_from_ary_body): adjust for type changes
* vm_insnhelper.c (vm_getivar): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:32:44 +04:00
|
|
|
unsigned int flag = 0;
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info_kw_arg *keywords = NULL;
|
2015-12-02 10:52:12 +03:00
|
|
|
const rb_iseq_t *parent_block = ISEQ_COMPILE_DATA(iseq)->current_block;
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(recv);
|
|
|
|
INIT_ANCHOR(args);
|
2006-12-31 18:02:22 +03:00
|
|
|
#if SUPPORT_JOKE
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (nd_type(node) == NODE_VCALL) {
|
2012-12-03 09:14:50 +04:00
|
|
|
ID id_bitblt;
|
|
|
|
ID id_answer;
|
|
|
|
|
|
|
|
CONST_ID(id_bitblt, "bitblt");
|
|
|
|
CONST_ID(id_answer, "the_answer_to_life_the_universe_and_everything");
|
|
|
|
|
|
|
|
if (mid == id_bitblt) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, bitblt);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-12-03 09:14:50 +04:00
|
|
|
else if (mid == id_answer) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, answer);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* only joke */
|
|
|
|
{
|
2008-06-09 13:25:32 +04:00
|
|
|
ID goto_id;
|
|
|
|
ID label_id;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2008-06-09 13:25:32 +04:00
|
|
|
CONST_ID(goto_id, "__goto__");
|
|
|
|
CONST_ID(label_id, "__label__");
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (nd_type(node) == NODE_FCALL &&
|
|
|
|
(mid == goto_id || mid == label_id)) {
|
2010-12-12 17:45:30 +03:00
|
|
|
LABEL *label;
|
|
|
|
st_data_t data;
|
2015-12-02 10:52:12 +03:00
|
|
|
st_table *labels_table = ISEQ_COMPILE_DATA(iseq)->labels_table;
|
2010-12-12 17:45:30 +03:00
|
|
|
ID label_name;
|
|
|
|
|
|
|
|
if (!labels_table) {
|
|
|
|
labels_table = st_init_numtable();
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->labels_table = labels_table;
|
2010-12-12 17:45:30 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (nd_type(node->nd_args->nd_head) == NODE_LIT &&
|
|
|
|
SYMBOL_P(node->nd_args->nd_head->nd_lit)) {
|
|
|
|
|
2010-12-12 17:45:30 +03:00
|
|
|
label_name = SYM2ID(node->nd_args->nd_head->nd_lit);
|
|
|
|
if (!st_lookup(labels_table, (st_data_t)label_name, &data)) {
|
2013-03-07 09:17:04 +04:00
|
|
|
label = NEW_LABEL(line);
|
|
|
|
label->position = line;
|
2010-12-12 17:45:30 +03:00
|
|
|
st_insert(labels_table, (st_data_t)label_name, (st_data_t)label);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
label = (LABEL *)data;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "invalid goto/label format");
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mid == goto_id) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSNL(ret, line, jump, label);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_LABEL(ret, label);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
2009-11-03 20:46:28 +03:00
|
|
|
/* receiver */
|
2015-10-22 09:30:12 +03:00
|
|
|
if (type == NODE_CALL || type == NODE_QCALL) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(recv, "recv", node->nd_recv);
|
2015-10-22 09:30:12 +03:00
|
|
|
if (type == NODE_QCALL) {
|
|
|
|
lskip = NEW_LABEL(line);
|
|
|
|
ADD_INSN(recv, line, dup);
|
|
|
|
ADD_INSNL(recv, line, branchnil, lskip);
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else if (type == NODE_FCALL || type == NODE_VCALL) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_CALL_RECEIVER(recv, line);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
/* args */
|
|
|
|
if (nd_type(node) != NODE_VCALL) {
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
argc = setup_args(iseq, args, node->nd_args, &flag, &keywords);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
argc = INT2FIX(0);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_SEQ(ret, recv);
|
|
|
|
ADD_SEQ(ret, args);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
debugp_param("call args argc", argc);
|
|
|
|
debugp_param("call method", ID2SYM(mid));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
switch (nd_type(node)) {
|
|
|
|
case NODE_VCALL:
|
2012-10-15 21:22:57 +04:00
|
|
|
flag |= VM_CALL_VCALL;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
/* VCALL is funcall, so fall through */
|
|
|
|
case NODE_FCALL:
|
2012-10-15 21:22:57 +04:00
|
|
|
flag |= VM_CALL_FCALL;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_SEND_R(ret, line, mid, argc, parent_block, INT2FIX(flag), keywords);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-10-22 09:30:12 +03:00
|
|
|
if (lskip) {
|
|
|
|
ADD_LABEL(ret, lskip);
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_SUPER:
|
|
|
|
case NODE_ZSUPER:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
DECL_ANCHOR(args);
|
2013-03-07 09:17:00 +04:00
|
|
|
int argc;
|
rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.
ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody
This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated
* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
ci->index becomes a 32-bit signed int (from signed long).
Reorder for better packing on 64-bit, giving an 8 byte reduction
from 104 to 96 bytes for each ci.
* compile.c (new_callinfo, setup_args, iseq_compile_each,
iseq_build_from_ary_body): adjust for type changes
* vm_insnhelper.c (vm_getivar): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:32:44 +04:00
|
|
|
unsigned int flag = 0;
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info_kw_arg *keywords = NULL;
|
2015-12-02 10:52:12 +03:00
|
|
|
const rb_iseq_t *parent_block = ISEQ_COMPILE_DATA(iseq)->current_block;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(args);
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (nd_type(node) == NODE_SUPER) {
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
VALUE vargc = setup_args(iseq, args, node->nd_args, &flag, &keywords);
|
2013-03-07 09:17:00 +04:00
|
|
|
argc = FIX2INT(vargc);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* NODE_ZSUPER */
|
|
|
|
int i;
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *liseq = iseq->body->local_iseq;
|
2012-10-04 17:52:20 +04:00
|
|
|
int lvar_level = get_lvar_level(iseq);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
argc = liseq->body->param.lead_num;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
/* normal arguments */
|
2015-07-22 01:52:59 +03:00
|
|
|
for (i = 0; i < liseq->body->param.lead_num; i++) {
|
2016-07-28 14:02:30 +03:00
|
|
|
int idx = liseq->body->local_table_size - i;
|
|
|
|
ADD_GETLOCAL(args, line, idx, lvar_level);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
* parse.y, node.h, compile.c: change node tree structure. a purpose
of this change is to unify argument structure of method and block.
this change prohibits duplicate block parameter name.
new argument infromation:
NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
NODE_ARGS_AUX [r: ID, b: ID, ->]
NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
optarg information:
NODE_OPT_ARGS [idx, expr, ->]
* vm_macro.def: ditto.
* gc.c: ditto.
* iseq.c: ditto.
* compile.h: fix debug function name.
* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|
* test/ruby/test_lambda.rb: disalbe test temporarily.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:07:05 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (liseq->body->param.flags.has_opt) {
|
2014-11-03 02:14:21 +03:00
|
|
|
/* optional arguments */
|
|
|
|
int j;
|
2015-07-22 01:52:59 +03:00
|
|
|
for (j = 0; j < liseq->body->param.opt_num; j++) {
|
2016-07-28 14:02:30 +03:00
|
|
|
int idx = liseq->body->local_table_size - (i + j);
|
|
|
|
ADD_GETLOCAL(args, line, idx, lvar_level);
|
2007-06-24 11:29:21 +04:00
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
i += j;
|
|
|
|
argc = i;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
if (liseq->body->param.flags.has_rest) {
|
2014-11-03 02:14:21 +03:00
|
|
|
/* rest argument */
|
2016-07-28 14:02:30 +03:00
|
|
|
int idx = liseq->body->local_table_size - liseq->body->param.rest_start;
|
|
|
|
ADD_GETLOCAL(args, line, idx, lvar_level);
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
argc = liseq->body->param.rest_start + 1;
|
2014-11-03 02:14:21 +03:00
|
|
|
flag |= VM_CALL_ARGS_SPLAT;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
if (liseq->body->param.flags.has_post) {
|
2014-11-03 02:14:21 +03:00
|
|
|
/* post arguments */
|
2015-07-22 01:52:59 +03:00
|
|
|
int post_len = liseq->body->param.post_num;
|
|
|
|
int post_start = liseq->body->param.post_start;
|
2007-06-24 11:29:21 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (liseq->body->param.flags.has_rest) {
|
2014-11-03 02:14:21 +03:00
|
|
|
int j;
|
|
|
|
for (j=0; j<post_len; j++) {
|
2016-07-28 14:02:30 +03:00
|
|
|
int idx = liseq->body->local_table_size - (post_start + j);
|
|
|
|
ADD_GETLOCAL(args, line, idx, lvar_level);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
ADD_INSN1(args, line, newarray, INT2FIX(j));
|
|
|
|
ADD_INSN (args, line, concatarray);
|
|
|
|
/* argc is settled at above */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int j;
|
|
|
|
for (j=0; j<post_len; j++) {
|
2016-07-28 14:02:30 +03:00
|
|
|
int idx = liseq->body->local_table_size - (post_start + j);
|
|
|
|
ADD_GETLOCAL(args, line, idx, lvar_level);
|
2008-03-25 09:09:38 +03:00
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
argc = post_len + post_start;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
}
|
2013-03-07 09:21:40 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (liseq->body->param.flags.has_kw) { /* TODO: support keywords */
|
2016-07-28 14:02:30 +03:00
|
|
|
int local_size = liseq->body->local_table_size;
|
2014-11-03 02:14:21 +03:00
|
|
|
argc++;
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
|
2014-11-03 02:14:21 +03:00
|
|
|
ADD_INSN1(args, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (liseq->body->param.flags.has_kwrest) {
|
2016-07-28 14:02:30 +03:00
|
|
|
int idx = liseq->body->local_table_size - liseq->body->param.keyword->rest_start;
|
|
|
|
ADD_GETLOCAL(args, line, idx, lvar_level);
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_SEND (args, line, rb_intern("dup"), INT2FIX(0));
|
2014-11-03 02:14:21 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_INSN1(args, line, newhash, INT2FIX(0));
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
for (i = 0; i < liseq->body->param.keyword->num; ++i) {
|
|
|
|
ID id = liseq->body->param.keyword->table[i];
|
2014-11-03 02:14:21 +03:00
|
|
|
int idx = local_size - get_local_var_idx(liseq, id);
|
|
|
|
ADD_INSN1(args, line, putobject, ID2SYM(id));
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(args, line, idx, lvar_level);
|
2014-11-03 02:14:21 +03:00
|
|
|
}
|
|
|
|
ADD_SEND(args, line, id_core_hash_merge_ptr, INT2FIX(i * 2 + 1));
|
2015-07-22 01:52:59 +03:00
|
|
|
if (liseq->body->param.flags.has_rest) {
|
2014-11-03 02:14:21 +03:00
|
|
|
ADD_INSN1(args, line, newarray, INT2FIX(1));
|
|
|
|
ADD_INSN (args, line, concatarray);
|
|
|
|
--argc;
|
|
|
|
}
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
else if (liseq->body->param.flags.has_kwrest) {
|
2016-07-28 14:02:30 +03:00
|
|
|
int idx = liseq->body->local_table_size - liseq->body->param.keyword->rest_start;
|
|
|
|
ADD_GETLOCAL(args, line, idx, lvar_level);
|
|
|
|
|
2014-11-03 02:14:21 +03:00
|
|
|
ADD_SEND (args, line, rb_intern("dup"), INT2FIX(0));
|
2015-07-22 01:52:59 +03:00
|
|
|
if (liseq->body->param.flags.has_rest) {
|
2014-11-03 02:14:21 +03:00
|
|
|
ADD_INSN1(args, line, newarray, INT2FIX(1));
|
|
|
|
ADD_INSN (args, line, concatarray);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
argc++;
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2009-11-03 20:46:28 +03:00
|
|
|
/* dummy receiver */
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putobject, nd_type(node) == NODE_ZSUPER ? Qfalse : Qtrue);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_SEQ(ret, args);
|
2015-09-19 20:59:58 +03:00
|
|
|
ADD_INSN3(ret, line, invokesuper,
|
2015-09-08 11:21:07 +03:00
|
|
|
new_callinfo(iseq, 0, argc, flag | VM_CALL_SUPER | VM_CALL_FCALL, keywords, parent_block != NULL),
|
2015-09-19 20:59:58 +03:00
|
|
|
Qnil, /* CALL_CACHE */
|
2015-09-08 11:21:07 +03:00
|
|
|
parent_block);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_ARRAY:{
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
compile_array_(iseq, ret, node, COMPILE_ARRAY_TYPE_ARRAY, NULL, poped);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_ZARRAY:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, newarray, INT2FIX(0));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_VALUES:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
NODE *n = node;
|
|
|
|
while (n) {
|
|
|
|
COMPILE(ret, "values item", n->nd_head);
|
|
|
|
n = n->nd_next;
|
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, newarray, INT2FIX(node->nd_alen));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_HASH:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
DECL_ANCHOR(list);
|
|
|
|
int type = node->nd_head ? nd_type(node->nd_head) : NODE_ZARRAY;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(list);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
switch (type) {
|
2012-04-12 05:33:34 +04:00
|
|
|
case NODE_ARRAY:
|
2012-05-06 13:40:47 +04:00
|
|
|
compile_array(iseq, list, node->nd_head, COMPILE_ARRAY_TYPE_HASH);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_SEQ(ret, list);
|
|
|
|
break;
|
2012-04-12 05:33:34 +04:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case NODE_ZARRAY:
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, newhash, INT2FIX(0));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
default:
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS_AT(node->nd_head) "can't make hash with this node: %s",
|
|
|
|
ruby_node_name(type));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_RETURN:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
rb_iseq_t *is = iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2009-07-31 06:48:10 +04:00
|
|
|
if (is) {
|
2015-07-22 01:52:59 +03:00
|
|
|
if (is->body->type == ISEQ_TYPE_TOP) {
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "Invalid return");
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-01-26 11:27:00 +03:00
|
|
|
LABEL *splabel = 0;
|
2008-01-25 21:02:01 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (is->body->type == ISEQ_TYPE_METHOD) {
|
2008-01-26 11:27:00 +03:00
|
|
|
splabel = NEW_LABEL(0);
|
|
|
|
ADD_LABEL(ret, splabel);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_ADJUST(ret, line, 0);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
|
2007-08-16 17:12:24 +04:00
|
|
|
COMPILE(ret, "return nd_stts (return val)", node->nd_stts);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (is->body->type == ISEQ_TYPE_METHOD) {
|
2009-02-16 23:54:58 +03:00
|
|
|
add_ensure_iseq(ret, iseq, 1);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_TRACE(ret, line, RUBY_EVENT_RETURN);
|
|
|
|
ADD_INSN(ret, line, leave);
|
2008-01-26 11:27:00 +03:00
|
|
|
ADD_ADJUST_RESTORE(ret, splabel);
|
|
|
|
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
2008-01-25 21:02:01 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2015-07-17 16:18:12 +03:00
|
|
|
ADD_INSN1(ret, line, throw, INT2FIX(TAG_RETURN));
|
2007-12-20 03:46:12 +03:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2007-12-20 03:46:12 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_YIELD:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
DECL_ANCHOR(args);
|
2007-06-26 23:24:40 +04:00
|
|
|
VALUE argc;
|
rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.
ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody
This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated
* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
ci->index becomes a 32-bit signed int (from signed long).
Reorder for better packing on 64-bit, giving an 8 byte reduction
from 104 to 96 bytes for each ci.
* compile.c (new_callinfo, setup_args, iseq_compile_each,
iseq_build_from_ary_body): adjust for type changes
* vm_insnhelper.c (vm_getivar): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:32:44 +04:00
|
|
|
unsigned int flag = 0;
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info_kw_arg *keywords = NULL;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(args);
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->type == ISEQ_TYPE_TOP) {
|
2015-12-04 20:28:26 +03:00
|
|
|
COMPILE_ERROR(ERROR_ARGS "Invalid yield");
|
2015-11-22 09:32:23 +03:00
|
|
|
debug_node_end();
|
|
|
|
return COMPILE_NG;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (node->nd_head) {
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
argc = setup_args(iseq, args, node->nd_head, &flag, &keywords);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2007-06-26 23:24:40 +04:00
|
|
|
argc = INT2FIX(0);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2007-06-25 22:23:35 +04:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_SEQ(ret, args);
|
2015-09-08 11:21:07 +03:00
|
|
|
ADD_INSN1(ret, line, invokeblock, new_callinfo(iseq, 0, FIX2INT(argc), flag, keywords, FALSE));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_LVAR:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
|
|
|
ID id = node->nd_vid;
|
2016-07-28 14:02:30 +03:00
|
|
|
int idx = iseq->body->local_iseq->body->local_table_size - get_local_var_idx(iseq, id);
|
2007-02-25 04:34:33 +03:00
|
|
|
|
2014-11-25 21:44:22 +03:00
|
|
|
debugs("id: %"PRIsVALUE" idx: %d\n", rb_id2str(id), idx);
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(ret, line, idx, get_lvar_level(iseq));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DVAR:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
int lv, idx, ls;
|
|
|
|
debugi("nd_vid", node->nd_vid);
|
|
|
|
if (!poped) {
|
2007-07-07 12:14:00 +04:00
|
|
|
idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (idx < 0) {
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS "unknown dvar (%"PRIsVALUE")",
|
|
|
|
rb_id2str(node->nd_vid));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(ret, line, ls - idx, lv);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_GVAR:{
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, getglobal,
|
2010-10-12 17:41:12 +04:00
|
|
|
((VALUE)node->nd_entry | 1));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
* parse.y, compile.c, gc.c, insns.def, intern.h, iseq.c, node.h,
object.c, string.c, variable.c, vm_macro.def: revert private
instance variable feature, which is postponed until next major
release.
* marshal.c: TYPE_SYMBOL2 removed; MARSHAL_MINOR reverted back to
8th version.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-23 05:49:41 +03:00
|
|
|
case NODE_IVAR:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
debugi("nd_vid", node->nd_vid);
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN2(ret, line, getinstancevariable,
|
2016-05-11 15:50:38 +03:00
|
|
|
ID2SYM(node->nd_vid),
|
|
|
|
get_ivar_ic_value(iseq,node->nd_vid));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2007-02-04 22:17:33 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_CONST:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
debugi("nd_vid", node->nd_vid);
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *lend = NEW_LABEL(line);
|
2015-07-22 01:52:59 +03:00
|
|
|
int ic_index = iseq->body->is_size++;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN2(ret, line, getinlinecache, lend, INT2FIX(ic_index));
|
|
|
|
ADD_INSN1(ret, line, getconstant, ID2SYM(node->nd_vid));
|
|
|
|
ADD_INSN1(ret, line, setinlinecache, INT2FIX(ic_index));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, lend);
|
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
|
|
|
ADD_INSN1(ret, line, getconstant, ID2SYM(node->nd_vid));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_CVAR:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, getclassvariable,
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ID2SYM(node->nd_vid));
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_NTH_REF:{
|
2007-06-27 20:21:57 +04:00
|
|
|
if (!poped) {
|
2015-05-29 08:39:03 +03:00
|
|
|
if (!node->nd_nth) {
|
|
|
|
ADD_INSN(ret, line, putnil);
|
|
|
|
break;
|
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN2(ret, line, getspecial, INT2FIX(1) /* '~' */,
|
2007-06-27 20:21:57 +04:00
|
|
|
INT2FIX(node->nd_nth << 1));
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_BACK_REF:{
|
2007-06-27 20:21:57 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN2(ret, line, getspecial, INT2FIX(1) /* '~' */,
|
2007-06-27 20:21:57 +04:00
|
|
|
INT2FIX(0x01 | (node->nd_nth << 1)));
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_MATCH:
|
|
|
|
case NODE_MATCH2:
|
|
|
|
case NODE_MATCH3:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
DECL_ANCHOR(recv);
|
|
|
|
DECL_ANCHOR(val);
|
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(recv);
|
|
|
|
INIT_ANCHOR(val);
|
2012-12-29 16:22:04 +04:00
|
|
|
switch (nd_type(node)) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case NODE_MATCH:
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(recv, line, putobject, node->nd_lit);
|
|
|
|
ADD_INSN2(val, line, getspecial, INT2FIX(0),
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
INT2FIX(0));
|
|
|
|
break;
|
|
|
|
case NODE_MATCH2:
|
2009-11-03 20:46:28 +03:00
|
|
|
COMPILE(recv, "receiver", node->nd_recv);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(val, "value", node->nd_value);
|
|
|
|
break;
|
|
|
|
case NODE_MATCH3:
|
2009-11-03 20:46:28 +03:00
|
|
|
COMPILE(recv, "receiver", node->nd_value);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(val, "value", node->nd_recv);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
/* TODO: detect by node */
|
|
|
|
if (recv->last == recv->anchor.next &&
|
|
|
|
INSN_OF(recv->last) == BIN(putobject) &&
|
|
|
|
nd_type(node) == NODE_MATCH2) {
|
|
|
|
ADD_SEQ(ret, val);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, opt_regexpmatch1,
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
OPERAND_AT(recv->last, 0));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_SEQ(ret, recv);
|
|
|
|
ADD_SEQ(ret, val);
|
2015-09-19 20:59:58 +03:00
|
|
|
ADD_INSN2(ret, line, opt_regexpmatch2, new_callinfo(iseq, idEqTilde, 1, 0, NULL, FALSE), Qnil);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_SEQ(ret, recv);
|
|
|
|
ADD_SEQ(ret, val);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, idEqTilde, INT2FIX(1));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2016-03-14 10:53:39 +03:00
|
|
|
if (node->nd_args) {
|
|
|
|
compile_named_capture_assign(iseq, ret, node->nd_args);
|
|
|
|
}
|
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_LIT:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
debugp_param("lit", node->nd_lit);
|
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putobject, node->nd_lit);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_STR:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
debugp_param("nd_lit", node->nd_lit);
|
|
|
|
if (!poped) {
|
2015-08-21 23:47:53 +03:00
|
|
|
node->nd_lit = rb_fstring(node->nd_lit);
|
2015-12-02 10:52:12 +03:00
|
|
|
if (!ISEQ_COMPILE_DATA(iseq)->option->frozen_string_literal) {
|
2015-10-23 22:02:55 +03:00
|
|
|
ADD_INSN1(ret, line, putstring, node->nd_lit);
|
2015-08-21 23:47:53 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-12-09 20:02:02 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal || RTEST(ruby_debug)) {
|
|
|
|
VALUE debug_info = rb_ary_new_from_args(2, iseq->body->location.path, INT2FIX(line));
|
2015-12-10 05:35:22 +03:00
|
|
|
VALUE str = rb_str_dup(node->nd_lit);
|
2015-12-09 20:02:02 +03:00
|
|
|
rb_ivar_set(str, id_debug_created_info, rb_obj_freeze(debug_info));
|
|
|
|
ADD_INSN1(ret, line, putobject, rb_obj_freeze(str));
|
2015-12-10 05:35:22 +03:00
|
|
|
iseq_add_mark_object_compile_time(iseq, str);
|
2015-12-09 20:02:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-12-10 05:35:22 +03:00
|
|
|
ADD_INSN1(ret, line, putobject, node->nd_lit);
|
2015-12-09 20:02:02 +03:00
|
|
|
}
|
2015-08-21 23:47:53 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DSTR:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
compile_dstr(iseq, ret, node);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2015-11-09 11:32:37 +03:00
|
|
|
else {
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->frozen_string_literal) {
|
2015-11-21 02:49:31 +03:00
|
|
|
VALUE debug_info = Qnil;
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal || RTEST(ruby_debug)) {
|
2015-11-21 02:49:31 +03:00
|
|
|
debug_info = rb_ary_new_from_args(2, iseq->body->location.path, INT2FIX(line));
|
|
|
|
iseq_add_mark_object_compile_time(iseq, rb_obj_freeze(debug_info));
|
|
|
|
}
|
|
|
|
ADD_INSN1(ret, line, freezestring, debug_info);
|
2015-11-09 11:32:37 +03:00
|
|
|
}
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_XSTR:{
|
2013-11-27 03:30:25 +04:00
|
|
|
node->nd_lit = rb_fstring(node->nd_lit);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_CALL_RECEIVER(ret, line);
|
|
|
|
ADD_INSN1(ret, line, putobject, node->nd_lit);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_CALL(ret, line, idBackquote, INT2FIX(1));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DXSTR:{
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_CALL_RECEIVER(ret, line);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
compile_dstr(iseq, ret, node);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_CALL(ret, line, idBackquote, INT2FIX(1));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_EVSTR:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "nd_body", node->nd_body);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, tostring);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DREGX:{
|
2008-01-29 11:03:51 +03:00
|
|
|
compile_dregx(iseq, ret, node);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DREGX_ONCE:{
|
2015-07-22 01:52:59 +03:00
|
|
|
int ic_index = iseq->body->is_size++;
|
2013-08-20 21:41:13 +04:00
|
|
|
NODE *dregx_node = NEW_NODE(NODE_DREGX, node->u1.value, node->u2.value, node->u3.value);
|
|
|
|
NODE *block_node = NEW_NODE(NODE_SCOPE, 0, dregx_node, 0);
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t * block_iseq = NEW_CHILD_ISEQ(block_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-08-20 21:41:13 +04:00
|
|
|
ADD_INSN2(ret, line, once, block_iseq, INT2FIX(ic_index));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_ARGSCAT:{
|
2010-08-05 16:32:02 +04:00
|
|
|
if (poped) {
|
|
|
|
COMPILE(ret, "argscat head", node->nd_head);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, splatarray, Qfalse);
|
|
|
|
ADD_INSN(ret, line, pop);
|
2010-08-05 16:32:02 +04:00
|
|
|
COMPILE(ret, "argscat body", node->nd_body);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, splatarray, Qfalse);
|
|
|
|
ADD_INSN(ret, line, pop);
|
2010-08-05 16:32:02 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
COMPILE(ret, "argscat head", node->nd_head);
|
|
|
|
COMPILE(ret, "argscat body", node->nd_body);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, concatarray);
|
2010-08-05 16:32:02 +04:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_ARGSPUSH:{
|
2010-08-05 16:32:02 +04:00
|
|
|
if (poped) {
|
|
|
|
COMPILE(ret, "arsgpush head", node->nd_head);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, splatarray, Qfalse);
|
|
|
|
ADD_INSN(ret, line, pop);
|
2010-08-05 16:32:02 +04:00
|
|
|
COMPILE_(ret, "argspush body", node->nd_body, poped);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
COMPILE(ret, "arsgpush head", node->nd_head);
|
|
|
|
COMPILE_(ret, "argspush body", node->nd_body, poped);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, newarray, INT2FIX(1));
|
|
|
|
ADD_INSN(ret, line, concatarray);
|
2010-08-05 16:32:02 +04:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_SPLAT:{
|
2008-10-12 05:18:49 +04:00
|
|
|
COMPILE(ret, "splat", node->nd_head);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, splatarray, Qtrue);
|
2007-07-05 22:16:54 +04:00
|
|
|
|
2008-10-12 05:18:49 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2008-10-12 05:18:49 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DEFN:{
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *method_iseq = NEW_ISEQ(node->nd_defn,
|
|
|
|
rb_id2str(node->nd_mid),
|
|
|
|
ISEQ_TYPE_METHOD, line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-11-19 09:33:05 +03:00
|
|
|
debugp_param("defn/iseq", rb_iseqw_new(method_iseq));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
|
|
|
ADD_INSN1(ret, line, putobject, ID2SYM(node->nd_mid));
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_INSN1(ret, line, putiseq, method_iseq);
|
2015-11-13 21:01:59 +03:00
|
|
|
ADD_SEND (ret, line, id_core_define_method, INT2FIX(2));
|
2008-07-01 07:05:58 +04:00
|
|
|
|
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2008-07-01 07:05:58 +04:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DEFS:{
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t * singleton_method = NEW_ISEQ(node->nd_defn,
|
|
|
|
rb_id2str(node->nd_mid),
|
|
|
|
ISEQ_TYPE_METHOD, line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-11-19 09:33:05 +03:00
|
|
|
debugp_param("defs/iseq", rb_iseqw_new(singleton_method));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "defs: recv", node->nd_recv);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putobject, ID2SYM(node->nd_mid));
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_INSN1(ret, line, putiseq, singleton_method);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND (ret, line, id_core_define_singleton_method, INT2FIX(3));
|
2008-07-01 07:05:58 +04:00
|
|
|
|
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_ALIAS:{
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE));
|
2008-03-25 09:09:38 +03:00
|
|
|
COMPILE(ret, "alias arg1", node->u1.node);
|
|
|
|
COMPILE(ret, "alias arg2", node->u2.node);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, id_core_set_method_alias, INT2FIX(3));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-07-01 07:05:58 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2008-03-25 09:09:38 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_VALIAS:{
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
|
|
|
ADD_INSN1(ret, line, putobject, ID2SYM(node->u1.id));
|
|
|
|
ADD_INSN1(ret, line, putobject, ID2SYM(node->u2.id));
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, id_core_set_variable_alias, INT2FIX(2));
|
2007-11-27 04:02:30 +03:00
|
|
|
|
2008-07-01 07:05:58 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2008-03-25 09:09:38 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_UNDEF:{
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE));
|
2008-03-25 09:09:38 +03:00
|
|
|
COMPILE(ret, "undef arg", node->u2.node);
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, id_core_undef_method, INT2FIX(2));
|
2007-11-27 04:02:30 +03:00
|
|
|
|
2008-07-01 07:05:58 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2008-03-25 09:09:38 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_CLASS:{
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *class_iseq = NEW_CHILD_ISEQ(node->nd_body,
|
|
|
|
rb_sprintf("<class:%"PRIsVALUE">", rb_id2str(node->nd_cpath->nd_mid)),
|
|
|
|
ISEQ_TYPE_CLASS, line);
|
2011-01-28 20:57:34 +03:00
|
|
|
VALUE noscope = compile_cpath(ret, iseq, node->nd_cpath);
|
2012-12-20 12:13:53 +04:00
|
|
|
int flags = VM_DEFINECLASS_TYPE_CLASS;
|
2015-07-22 01:52:59 +03:00
|
|
|
|
2012-12-20 12:13:53 +04:00
|
|
|
if (!noscope) flags |= VM_DEFINECLASS_FLAG_SCOPED;
|
|
|
|
if (node->nd_super) flags |= VM_DEFINECLASS_FLAG_HAS_SUPERCLASS;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "super", node->nd_super);
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_INSN3(ret, line, defineclass, ID2SYM(node->nd_cpath->nd_mid), class_iseq, INT2FIX(flags));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_MODULE:{
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(node->nd_body,
|
|
|
|
rb_sprintf("<module:%"PRIsVALUE">", rb_id2str(node->nd_cpath->nd_mid)),
|
|
|
|
ISEQ_TYPE_CLASS, line);
|
2011-01-28 20:57:34 +03:00
|
|
|
VALUE noscope = compile_cpath(ret, iseq, node->nd_cpath);
|
2012-12-20 12:13:53 +04:00
|
|
|
int flags = VM_DEFINECLASS_TYPE_MODULE;
|
2015-07-22 01:52:59 +03:00
|
|
|
|
2012-12-20 12:13:53 +04:00
|
|
|
if (!noscope) flags |= VM_DEFINECLASS_FLAG_SCOPED;
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN (ret, line, putnil); /* dummy */
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_INSN3(ret, line, defineclass, ID2SYM(node->nd_cpath->nd_mid), module_iseq, INT2FIX(flags));
|
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_SCLASS:{
|
2008-06-09 13:25:32 +04:00
|
|
|
ID singletonclass;
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *singleton_class = NEW_ISEQ(node->nd_body, rb_str_new2("singleton class"),
|
|
|
|
ISEQ_TYPE_CLASS, line);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "sclass#recv", node->nd_recv);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN (ret, line, putnil);
|
2008-06-09 13:25:32 +04:00
|
|
|
CONST_ID(singletonclass, "singletonclass");
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN3(ret, line, defineclass,
|
2015-07-22 01:52:59 +03:00
|
|
|
ID2SYM(singletonclass), singleton_class,
|
2012-12-20 12:13:53 +04:00
|
|
|
INT2FIX(VM_DEFINECLASS_TYPE_SINGLETON_CLASS));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_COLON2:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (rb_is_const_id(node->nd_mid)) {
|
|
|
|
/* constant */
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *lend = NEW_LABEL(line);
|
2015-07-22 01:52:59 +03:00
|
|
|
int ic_index = iseq->body->is_size++;
|
2010-02-24 20:06:15 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
DECL_ANCHOR(pref);
|
|
|
|
DECL_ANCHOR(body);
|
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(pref);
|
|
|
|
INIT_ANCHOR(body);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
compile_colon2(iseq, node, pref, body);
|
|
|
|
if (LIST_SIZE_ZERO(pref)) {
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN2(ret, line, getinlinecache, lend, INT2FIX(ic_index));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SEQ(ret, body);
|
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setinlinecache, INT2FIX(ic_index));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, lend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADD_SEQ(ret, pref);
|
|
|
|
ADD_SEQ(ret, body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* function call */
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_CALL_RECEIVER(ret, line);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "colon2#nd_head", node->nd_head);
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_CALL(ret, line, node->nd_mid, INT2FIX(1));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_COLON3:{
|
2013-03-07 09:17:04 +04:00
|
|
|
LABEL *lend = NEW_LABEL(line);
|
2015-07-22 01:52:59 +03:00
|
|
|
int ic_index = iseq->body->is_size++;
|
2010-02-24 20:06:15 +03:00
|
|
|
|
2013-01-08 22:47:05 +04:00
|
|
|
debugi("colon3#nd_mid", node->nd_mid);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
/* add cache insn */
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN2(ret, line, getinlinecache, lend, INT2FIX(ic_index));
|
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putobject, rb_cObject);
|
|
|
|
ADD_INSN1(ret, line, getconstant, ID2SYM(node->nd_mid));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-12-02 10:52:12 +03:00
|
|
|
if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setinlinecache, INT2FIX(ic_index));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_LABEL(ret, lend);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DOT2:
|
|
|
|
case NODE_DOT3:{
|
2016-10-01 16:17:51 +03:00
|
|
|
int excl = type == NODE_DOT3;
|
|
|
|
VALUE flag = INT2FIX(excl);
|
|
|
|
NODE *b = node->nd_beg;
|
|
|
|
NODE *e = node->nd_end;
|
|
|
|
if (number_literal_p(b) && number_literal_p(e)) {
|
|
|
|
VALUE val = rb_range_new(b->nd_lit, e->nd_lit, excl);
|
|
|
|
iseq_add_mark_object_compile_time(iseq, val);
|
|
|
|
ADD_INSN1(ret, line, putobject, val);
|
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE(ret, "min", (NODE *) node->nd_beg);
|
|
|
|
COMPILE(ret, "max", (NODE *) node->nd_end);
|
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, newrange, flag);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2016-10-29 04:09:40 +03:00
|
|
|
case NODE_FLIP2:
|
|
|
|
case NODE_FLIP3:{
|
|
|
|
LABEL *lend = NEW_LABEL(line);
|
|
|
|
LABEL *ltrue = NEW_LABEL(line);
|
|
|
|
LABEL *lfalse = NEW_LABEL(line);
|
|
|
|
compile_branch_condition(iseq, ret, node, ltrue, lfalse);
|
|
|
|
ADD_INSNL(ret, line, jump, lend);
|
|
|
|
ADD_LABEL(ret, ltrue);
|
|
|
|
ADD_INSN1(ret, line, putobject, Qtrue);
|
|
|
|
ADD_INSNL(ret, line, jump, lend);
|
|
|
|
ADD_LABEL(ret, lfalse);
|
|
|
|
ADD_INSN1(ret, line, putobject, Qfalse);
|
|
|
|
ADD_LABEL(ret, lend);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_SELF:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putself);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_NIL:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_TRUE:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putobject, Qtrue);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_FALSE:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putobject, Qfalse);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_ERRINFO:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->type == ISEQ_TYPE_RESCUE) {
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(ret, line, LVAR_ERRINFO, 0);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2015-07-16 16:13:50 +03:00
|
|
|
const rb_iseq_t *ip = iseq;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
int level = 0;
|
|
|
|
while (ip) {
|
2015-07-22 01:52:59 +03:00
|
|
|
if (ip->body->type == ISEQ_TYPE_RESCUE) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
ip = ip->body->parent_iseq;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
level++;
|
|
|
|
}
|
|
|
|
if (ip) {
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(ret, line, LVAR_ERRINFO, level);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_DEFINED:{
|
2013-04-05 14:40:03 +04:00
|
|
|
if (poped) break;
|
|
|
|
if (!node->nd_head) {
|
|
|
|
VALUE str = rb_iseq_defined_string(DEFINED_NIL);
|
|
|
|
ADD_INSN1(ret, nd_line(node), putobject, str);
|
|
|
|
}
|
|
|
|
else {
|
2008-03-25 09:26:32 +03:00
|
|
|
LABEL *lfinish[2];
|
2013-03-07 09:17:04 +04:00
|
|
|
lfinish[0] = NEW_LABEL(line);
|
2008-03-25 09:26:32 +03:00
|
|
|
lfinish[1] = 0;
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
defined_expr(iseq, ret, node->nd_head, lfinish, Qtrue);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, swap);
|
|
|
|
ADD_INSN(ret, line, pop);
|
2008-03-25 09:26:32 +03:00
|
|
|
if (lfinish[1]) {
|
|
|
|
ADD_LABEL(ret, lfinish[1]);
|
|
|
|
}
|
|
|
|
ADD_LABEL(ret, lfinish[0]);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_POSTEXE:{
|
2013-08-22 10:50:42 +04:00
|
|
|
/* compiled to:
|
|
|
|
* ONCE{ rb_mRubyVMFrozenCore::core#set_postexe{ ... } }
|
|
|
|
*/
|
2015-07-22 01:52:59 +03:00
|
|
|
int is_index = iseq->body->is_size++;
|
|
|
|
const rb_iseq_t *once_iseq = NEW_CHILD_ISEQ((NODE *)IFUNC_NEW(build_postexe_iseq, node->nd_body, 0),
|
|
|
|
make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line);
|
2008-07-20 17:50:14 +04:00
|
|
|
|
2013-08-22 10:50:42 +04:00
|
|
|
ADD_INSN2(ret, line, once, once_iseq, INT2FIX(is_index));
|
2008-07-20 17:50:14 +04:00
|
|
|
|
2008-07-01 16:19:00 +04:00
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2011-12-26 18:20:09 +04:00
|
|
|
}
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
case NODE_KW_ARG:
|
|
|
|
{
|
|
|
|
LABEL *end_label = NEW_LABEL(nd_line(node));
|
|
|
|
NODE *default_value = node->nd_body->nd_value;
|
|
|
|
|
|
|
|
if (default_value == (NODE *)-1) {
|
|
|
|
/* required argument. do nothing */
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS "unreachable");
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
}
|
2014-12-02 07:55:07 +03:00
|
|
|
else if (nd_type(default_value) == NODE_LIT ||
|
|
|
|
nd_type(default_value) == NODE_NIL ||
|
|
|
|
nd_type(default_value) == NODE_TRUE ||
|
|
|
|
nd_type(default_value) == NODE_FALSE) {
|
2016-04-19 07:46:20 +03:00
|
|
|
compile_bug(ERROR_ARGS "unreachable");
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* if keywordcheck(_kw_bits, nth_keyword)
|
|
|
|
* kw = default_value
|
|
|
|
* end
|
|
|
|
*/
|
2016-07-28 14:02:30 +03:00
|
|
|
int kw_bits_idx = iseq->body->local_table_size - iseq->body->param.keyword->bits_start;
|
2015-07-22 01:52:59 +03:00
|
|
|
int keyword_idx = iseq->body->param.keyword->num;
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_INSN2(ret, line, checkkeyword, INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1), INT2FIX(keyword_idx));
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
ADD_INSNL(ret, line, branchif, end_label);
|
|
|
|
COMPILE_POPED(ret, "keyword default argument", node->nd_body);
|
|
|
|
ADD_LABEL(ret, end_label);
|
|
|
|
}
|
2011-12-26 18:20:09 +04:00
|
|
|
|
2012-03-13 17:00:17 +04:00
|
|
|
break;
|
2013-03-12 17:20:50 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
case NODE_DSYM:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
compile_dstr(iseq, ret, node);
|
|
|
|
if (!poped) {
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_SEND(ret, line, idIntern, INT2FIX(0));
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_ATTRASGN:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
DECL_ANCHOR(recv);
|
|
|
|
DECL_ANCHOR(args);
|
rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.
ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody
This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated
* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
ci->index becomes a 32-bit signed int (from signed long).
Reorder for better packing on 64-bit, giving an 8 byte reduction
from 104 to 96 bytes for each ci.
* compile.c (new_callinfo, setup_args, iseq_compile_each,
iseq_build_from_ary_body): adjust for type changes
* vm_insnhelper.c (vm_getivar): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:32:44 +04:00
|
|
|
unsigned int flag = 0;
|
2015-10-23 04:49:38 +03:00
|
|
|
ID mid = node->nd_mid;
|
|
|
|
LABEL *lskip = 0;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
VALUE argc;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-01-10 08:54:08 +04:00
|
|
|
/* optimization shortcut
|
|
|
|
* obj["literal"] = value -> opt_aset_with(obj, "literal", value)
|
|
|
|
*/
|
2015-10-23 04:49:38 +03:00
|
|
|
if (mid == idASET && !private_recv_p(node) && node->nd_args &&
|
2014-01-10 08:54:08 +04:00
|
|
|
nd_type(node->nd_args) == NODE_ARRAY && node->nd_args->nd_alen == 2 &&
|
2014-12-17 03:54:13 +03:00
|
|
|
nd_type(node->nd_args->nd_head) == NODE_STR &&
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->current_block == NULL &&
|
|
|
|
ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction)
|
2014-01-10 08:54:08 +04:00
|
|
|
{
|
|
|
|
VALUE str = rb_fstring(node->nd_args->nd_head->nd_lit);
|
|
|
|
node->nd_args->nd_head->nd_lit = str;
|
2014-01-25 09:17:17 +04:00
|
|
|
iseq_add_mark_object(iseq, str);
|
2014-01-10 08:54:08 +04:00
|
|
|
COMPILE(ret, "recv", node->nd_recv);
|
|
|
|
COMPILE(ret, "value", node->nd_args->nd_next->nd_head);
|
2014-01-25 09:21:07 +04:00
|
|
|
if (!poped) {
|
|
|
|
ADD_INSN(ret, line, swap);
|
|
|
|
ADD_INSN1(ret, line, topn, INT2FIX(1));
|
|
|
|
}
|
2015-09-19 20:59:58 +03:00
|
|
|
ADD_INSN3(ret, line, opt_aset_with,
|
|
|
|
new_callinfo(iseq, idASET, 2, 0, NULL, FALSE),
|
2015-11-26 15:36:43 +03:00
|
|
|
NULL/* CALL_CACHE */, str);
|
2014-01-25 09:21:07 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2014-01-10 08:54:08 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(recv);
|
|
|
|
INIT_ANCHOR(args);
|
* 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
2014-11-02 21:02:55 +03:00
|
|
|
argc = setup_args(iseq, args, node->nd_args, &flag, NULL);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-04-30 13:51:13 +03:00
|
|
|
flag |= COMPILE_RECV(recv, "recv", node);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
debugp_param("argc", argc);
|
2015-10-23 04:49:38 +03:00
|
|
|
debugp_param("nd_mid", ID2SYM(mid));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2015-10-23 04:49:38 +03:00
|
|
|
if (!rb_is_attrset_id(mid)) {
|
|
|
|
/* safe nav attr */
|
|
|
|
mid = rb_id_attrset(mid);
|
|
|
|
ADD_INSN(recv, line, dup);
|
|
|
|
lskip = NEW_LABEL(line);
|
|
|
|
ADD_INSNL(recv, line, branchnil, lskip);
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
if (!poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, putnil);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
ADD_SEQ(ret, recv);
|
|
|
|
ADD_SEQ(ret, args);
|
2007-07-03 22:58:42 +04:00
|
|
|
|
2012-10-15 21:22:57 +04:00
|
|
|
if (flag & VM_CALL_ARGS_BLOCKARG) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, topn, INT2FIX(1));
|
2012-10-15 21:22:57 +04:00
|
|
|
if (flag & VM_CALL_ARGS_SPLAT) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putobject, INT2FIX(-1));
|
2015-04-30 13:51:13 +03:00
|
|
|
ADD_SEND(ret, line, idAREF, INT2FIX(1));
|
2011-06-17 14:18:39 +04:00
|
|
|
}
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 3));
|
|
|
|
ADD_INSN (ret, line, pop);
|
2007-07-03 22:58:42 +04:00
|
|
|
}
|
2012-10-15 21:22:57 +04:00
|
|
|
else if (flag & VM_CALL_ARGS_SPLAT) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, dup);
|
|
|
|
ADD_INSN1(ret, line, putobject, INT2FIX(-1));
|
2015-04-30 13:51:13 +03:00
|
|
|
ADD_SEND(ret, line, idAREF, INT2FIX(1));
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 2));
|
|
|
|
ADD_INSN (ret, line, pop);
|
2011-06-17 14:18:39 +04:00
|
|
|
}
|
2007-07-03 22:58:42 +04:00
|
|
|
else {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, setn, FIXNUM_INC(argc, 1));
|
2009-09-05 09:34:56 +04:00
|
|
|
}
|
2007-07-03 22:58:42 +04:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
else {
|
|
|
|
ADD_SEQ(ret, recv);
|
|
|
|
ADD_SEQ(ret, args);
|
|
|
|
}
|
2015-10-23 04:49:38 +03:00
|
|
|
ADD_SEND_WITH_FLAG(ret, line, mid, argc, INT2FIX(flag));
|
|
|
|
if (lskip) ADD_LABEL(ret, lskip);
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case NODE_PRELUDE:{
|
2015-12-02 10:52:12 +03:00
|
|
|
const rb_compile_option_t *orig_opt = ISEQ_COMPILE_DATA(iseq)->option;
|
2015-09-27 09:44:02 +03:00
|
|
|
if (node->nd_orig) {
|
|
|
|
rb_compile_option_t new_opt = *orig_opt;
|
|
|
|
rb_iseq_make_compile_option(&new_opt, node->nd_orig);
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->option = &new_opt;
|
2015-09-27 09:44:02 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
COMPILE_POPED(ret, "prelude", node->nd_head);
|
|
|
|
COMPILE_(ret, "body", node->nd_body, poped);
|
2015-12-02 10:52:12 +03:00
|
|
|
ISEQ_COMPILE_DATA(iseq)->option = orig_opt;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-01-05 06:43:12 +03:00
|
|
|
case NODE_LAMBDA:{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
/* compile same as lambda{...} */
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *block = NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
VALUE argc = INT2FIX(0);
|
2015-07-22 01:52:59 +03:00
|
|
|
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
2014-09-09 02:08:59 +04:00
|
|
|
ADD_CALL_WITH_BLOCK(ret, line, idLambda, argc, block);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
|
|
|
if (poped) {
|
2013-03-07 09:17:04 +04:00
|
|
|
ADD_INSN(ret, line, pop);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
}
|
|
|
|
break;
|
2007-01-05 06:43:12 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
default:
|
2015-12-01 08:55:26 +03:00
|
|
|
UNKNOWN_NODE("iseq_compile_each", node);
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
return COMPILE_NG;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2013-02-28 18:04:53 +04:00
|
|
|
/* check & remove redundant trace(line) */
|
|
|
|
if (saved_last_element && ret /* ret can be 0 when error */ &&
|
|
|
|
ret->last == saved_last_element &&
|
|
|
|
((INSN *)saved_last_element)->insn_id == BIN(trace)) {
|
|
|
|
POP_ELEMENT(ret);
|
|
|
|
}
|
|
|
|
|
2007-06-26 22:56:15 +04:00
|
|
|
debug_node_end();
|
2006-12-31 18:02:22 +03:00
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************/
|
|
|
|
/* instruction information */
|
|
|
|
/***************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
insn_data_length(INSN *iobj)
|
|
|
|
{
|
|
|
|
return insn_len(iobj->insn_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
calc_sp_depth(int depth, INSN *insn)
|
|
|
|
{
|
|
|
|
return insn_stack_increase(depth, insn->insn_id, insn->operands);
|
|
|
|
}
|
|
|
|
|
2013-11-29 15:45:40 +04:00
|
|
|
static VALUE
|
|
|
|
opobj_inspect(VALUE obj)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2013-11-29 15:45:40 +04:00
|
|
|
struct RBasic *r = (struct RBasic *) obj;
|
|
|
|
if (!SPECIAL_CONST_P(r) && r->klass == 0) {
|
|
|
|
switch (BUILTIN_TYPE(r)) {
|
|
|
|
case T_STRING:
|
|
|
|
obj = rb_str_new_cstr(RSTRING_PTR(obj));
|
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
|
|
|
obj = rb_ary_dup(obj);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rb_inspect(obj);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2013-11-29 15:45:40 +04:00
|
|
|
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
|
|
|
insn_data_to_s_detail(INSN *iobj)
|
|
|
|
{
|
2013-11-29 15:45:40 +04:00
|
|
|
VALUE str = rb_sprintf("%-20s ", insn_name(iobj->insn_id));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (iobj->operands) {
|
2008-04-03 04:00:48 +04:00
|
|
|
const char *types = insn_op_types(iobj->insn_id);
|
2006-12-31 18:02:22 +03:00
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; types[j]; j++) {
|
|
|
|
char type = types[j];
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TS_OFFSET: /* label(destination position) */
|
|
|
|
{
|
|
|
|
LABEL *lobj = (LABEL *)OPERAND_AT(iobj, j);
|
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-22 12:53:34 +04:00
|
|
|
rb_str_catf(str, "<L%03d>", lobj->label_no);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TS_ISEQ: /* iseq */
|
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq = (rb_iseq_t *)OPERAND_AT(iobj, j);
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE val = Qnil;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
if (0 && iseq) { /* TODO: invalidate now */
|
2015-07-22 01:52:59 +03:00
|
|
|
val = (VALUE)iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2013-11-29 15:45:40 +04:00
|
|
|
rb_str_concat(str, opobj_inspect(val));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TS_LINDEX:
|
|
|
|
case TS_NUM: /* ulong */
|
|
|
|
case TS_VALUE: /* VALUE */
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
{
|
|
|
|
VALUE v = OPERAND_AT(iobj, j);
|
2013-11-29 15:45:40 +04:00
|
|
|
rb_str_concat(str, opobj_inspect(v));
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
break;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
case TS_ID: /* ID */
|
2013-11-29 15:45:40 +04:00
|
|
|
rb_str_concat(str, opobj_inspect(OPERAND_AT(iobj, j)));
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
case TS_GENTRY:
|
|
|
|
{
|
2009-07-16 04:01:06 +04:00
|
|
|
struct rb_global_entry *entry = (struct rb_global_entry *)
|
2006-12-31 18:02:22 +03:00
|
|
|
(OPERAND_AT(iobj, j) & (~1));
|
2014-11-25 21:44:22 +03:00
|
|
|
rb_str_append(str, rb_id2str(entry->id));
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2012-10-09 09:33:54 +04:00
|
|
|
case TS_IC: /* inline cache */
|
2010-02-24 20:06:15 +03:00
|
|
|
rb_str_catf(str, "<ic:%d>", FIX2INT(OPERAND_AT(iobj, j)));
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
2012-10-09 09:33:54 +04:00
|
|
|
case TS_CALLINFO: /* call info */
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
{
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info *ci = (struct rb_call_info *)OPERAND_AT(iobj, j);
|
2014-11-25 21:44:22 +03:00
|
|
|
rb_str_cat2(str, "<callinfo:");
|
2015-09-19 20:59:58 +03:00
|
|
|
if (ci->mid) rb_str_catf(str, "%"PRIsVALUE, rb_id2str(ci->mid));
|
2014-11-25 21:44:22 +03:00
|
|
|
rb_str_catf(str, ", %d>", ci->orig_argc);
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-09-19 20:59:58 +03:00
|
|
|
case TS_CALLCACHE: /* call cache */
|
|
|
|
{
|
|
|
|
rb_str_catf(str, "<call cache>");
|
|
|
|
break;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
case TS_CDHASH: /* case/when condition cache */
|
|
|
|
rb_str_cat2(str, "<ch>");
|
|
|
|
break;
|
2014-12-15 22:09:25 +03:00
|
|
|
case TS_FUNCPTR:
|
2014-12-16 04:14:27 +03:00
|
|
|
{
|
|
|
|
rb_insn_func_t func = (rb_insn_func_t)OPERAND_AT(iobj, j);
|
|
|
|
#ifdef HAVE_DLADDR
|
|
|
|
Dl_info info;
|
|
|
|
if (dladdr(func, &info) && info.dli_sname) {
|
|
|
|
rb_str_cat2(str, info.dli_sname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rb_str_catf(str, "<%p>", func);
|
|
|
|
}
|
2014-12-15 22:09:25 +03:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
default:{
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
rb_raise(rb_eSyntaxError, "unknown operand type: %c", type);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (types[j + 1]) {
|
|
|
|
rb_str_cat2(str, ", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_disasm_list(struct iseq_link_element *link)
|
|
|
|
{
|
|
|
|
int pos = 0;
|
|
|
|
INSN *iobj;
|
|
|
|
LABEL *lobj;
|
|
|
|
VALUE str;
|
|
|
|
|
|
|
|
printf("-- raw disasm--------\n");
|
|
|
|
|
|
|
|
while (link) {
|
|
|
|
switch (link->type) {
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_INSN:
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
iobj = (INSN *)link;
|
|
|
|
str = insn_data_to_s_detail(iobj);
|
2014-12-26 08:33:01 +03:00
|
|
|
printf("%04d %-65s(%4u)\n", pos, StringValueCStr(str), iobj->line_no);
|
2006-12-31 18:02:22 +03:00
|
|
|
pos += insn_data_length(iobj);
|
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_LABEL:
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
lobj = (LABEL *)link;
|
|
|
|
printf("<L%03d>\n", lobj->label_no);
|
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
case ISEQ_ELEMENT_NONE:
|
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
printf("[none]\n");
|
|
|
|
break;
|
|
|
|
}
|
2008-01-26 11:27:00 +03:00
|
|
|
case ISEQ_ELEMENT_ADJUST:
|
|
|
|
{
|
|
|
|
ADJUST *adjust = (ADJUST *)link;
|
2013-11-29 15:45:40 +04:00
|
|
|
printf("adjust: [label: %d]\n", adjust->label ? adjust->label->label_no : -1);
|
2008-01-26 11:27:00 +03:00
|
|
|
break;
|
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
/* ignore */
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
rb_raise(rb_eSyntaxError, "dump_disasm_list error: %ld\n", FIX2LONG(link->type));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
link = link->next;
|
|
|
|
}
|
|
|
|
printf("---------------------\n");
|
2015-11-22 09:29:41 +03:00
|
|
|
fflush(stdout);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
const char *
|
|
|
|
rb_insns_name(int i)
|
|
|
|
{
|
|
|
|
return insn_name_info[i];
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE
|
2009-01-19 04:06:56 +03:00
|
|
|
rb_insns_name_array(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE ary = rb_ary_new();
|
|
|
|
int i;
|
2009-05-17 09:27:32 +04:00
|
|
|
for (i = 0; i < numberof(insn_name_info); i++) {
|
2013-11-27 03:30:25 +04:00
|
|
|
rb_ary_push(ary, rb_fstring(rb_str_new2(insn_name_info[i])));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2008-12-05 06:35:48 +03:00
|
|
|
return rb_obj_freeze(ary);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static LABEL *
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
register_label(rb_iseq_t *iseq, struct st_table *labels_table, VALUE obj)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
LABEL *label = 0;
|
2007-06-28 14:41:39 +04:00
|
|
|
st_data_t tmp;
|
2006-12-31 18:02:22 +03:00
|
|
|
obj = rb_convert_type(obj, T_SYMBOL, "Symbol", "to_sym");
|
|
|
|
|
2007-06-28 14:41:39 +04:00
|
|
|
if (st_lookup(labels_table, obj, &tmp) == 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
label = NEW_LABEL(0);
|
|
|
|
st_insert(labels_table, obj, (st_data_t)label);
|
|
|
|
}
|
2007-06-28 14:41:39 +04:00
|
|
|
else {
|
|
|
|
label = (LABEL *)tmp;
|
|
|
|
}
|
2015-11-14 09:26:15 +03:00
|
|
|
LABEL_REF(label);
|
2006-12-31 18:02:22 +03:00
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
get_exception_sym2type(VALUE sym)
|
|
|
|
{
|
2008-06-09 13:25:32 +04:00
|
|
|
#undef rb_intern
|
2008-08-16 04:20:31 +04:00
|
|
|
#define rb_intern(str) rb_intern_const(str)
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE symRescue, symEnsure, symRetry;
|
|
|
|
static VALUE symBreak, symRedo, symNext;
|
|
|
|
|
|
|
|
if (symRescue == 0) {
|
|
|
|
symRescue = ID2SYM(rb_intern("rescue"));
|
|
|
|
symEnsure = ID2SYM(rb_intern("ensure"));
|
|
|
|
symRetry = ID2SYM(rb_intern("retry"));
|
|
|
|
symBreak = ID2SYM(rb_intern("break"));
|
|
|
|
symRedo = ID2SYM(rb_intern("redo"));
|
|
|
|
symNext = ID2SYM(rb_intern("next"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sym == symRescue) return CATCH_TYPE_RESCUE;
|
|
|
|
if (sym == symEnsure) return CATCH_TYPE_ENSURE;
|
|
|
|
if (sym == symRetry) return CATCH_TYPE_RETRY;
|
|
|
|
if (sym == symBreak) return CATCH_TYPE_BREAK;
|
2010-10-31 04:42:54 +03:00
|
|
|
if (sym == symRedo) return CATCH_TYPE_REDO;
|
2006-12-31 18:02:22 +03:00
|
|
|
if (sym == symNext) return CATCH_TYPE_NEXT;
|
2015-06-18 00:07:02 +03:00
|
|
|
rb_raise(rb_eSyntaxError, "invalid exception symbol: %+"PRIsVALUE, sym);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-10-31 04:42:54 +03:00
|
|
|
iseq_build_from_ary_exception(rb_iseq_t *iseq, struct st_table *labels_table,
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE exception)
|
|
|
|
{
|
|
|
|
int i;
|
2007-04-05 12:58:46 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
for (i=0; i<RARRAY_LEN(exception); i++) {
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *eiseq;
|
|
|
|
VALUE v, type;
|
2013-11-08 06:00:35 +04:00
|
|
|
const VALUE *ptr;
|
2006-12-31 18:02:22 +03:00
|
|
|
LABEL *lstart, *lend, *lcont;
|
2014-12-04 01:16:58 +03:00
|
|
|
unsigned int sp;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-10-11 10:33:58 +04:00
|
|
|
v = rb_convert_type(RARRAY_AREF(exception, i), T_ARRAY,
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
"Array", "to_ary");
|
|
|
|
if (RARRAY_LEN(v) != 6) {
|
|
|
|
rb_raise(rb_eSyntaxError, "wrong exception entry");
|
|
|
|
}
|
2013-11-08 06:00:35 +04:00
|
|
|
ptr = RARRAY_CONST_PTR(v);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
type = get_exception_sym2type(ptr[0]);
|
2006-12-31 18:02:22 +03:00
|
|
|
if (ptr[1] == Qnil) {
|
2015-07-22 01:52:59 +03:00
|
|
|
eiseq = NULL;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-07-22 01:52:59 +03:00
|
|
|
eiseq = rb_iseqw_to_iseq(rb_iseq_load(ptr[1], (VALUE)iseq, Qnil));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
lstart = register_label(iseq, labels_table, ptr[2]);
|
|
|
|
lend = register_label(iseq, labels_table, ptr[3]);
|
|
|
|
lcont = register_label(iseq, labels_table, ptr[4]);
|
2014-12-04 01:16:58 +03:00
|
|
|
sp = NUM2UINT(ptr[5]);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* bignum.c (big_rshift), compile.c (validate_label,
iseq_build_from_ary_exception), cont.c (cont_capture), dir.c
(dir_open_dir), gc.c (objspace_each_objects), io.c (pipe_open)
(rb_io_advise), parse.y (parser_compile_string)
(rb_parser_compile_file), proc.c (binding_free), process.c
(rb_proc_exec_n, rb_seteuid_core, proc_setegid, rb_setegid_core)
(p_uid_exchange, p_gid_exchange), regparse.c (strdup_with_null),
signal.c (sig_dfl), vm.c (rb_iseq_eval, rb_iseq_eval_main),
vm_insnhelper.c (vm_expandarray): suppress
unused-but-set-variable warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-05 13:57:00 +04:00
|
|
|
(void)sp;
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
ADD_CATCH_ENTRY(type, lstart, lend, eiseq, lcont);
|
2014-10-11 10:33:58 +04:00
|
|
|
|
|
|
|
RB_GC_GUARD(v);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
return COMPILE_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-19 04:06:56 +03:00
|
|
|
static struct st_table *
|
|
|
|
insn_make_insn_table(void)
|
|
|
|
{
|
|
|
|
struct st_table *table;
|
|
|
|
int i;
|
|
|
|
table = st_init_numtable();
|
|
|
|
|
|
|
|
for (i=0; i<VM_INSTRUCTION_SIZE; i++) {
|
|
|
|
st_insert(table, ID2SYM(rb_intern(insn_name(i))), i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
static const rb_iseq_t *
|
|
|
|
iseq_build_load_iseq(const rb_iseq_t *iseq, VALUE op)
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
{
|
2015-07-22 01:52:59 +03:00
|
|
|
VALUE iseqw;
|
|
|
|
const rb_iseq_t *loaded_iseq;
|
|
|
|
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
if (RB_TYPE_P(op, T_ARRAY)) {
|
2015-07-22 01:52:59 +03:00
|
|
|
iseqw = rb_iseq_load(op, (VALUE)iseq, Qnil);
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
}
|
|
|
|
else if (CLASS_OF(op) == rb_cISeq) {
|
2015-07-22 01:52:59 +03:00
|
|
|
iseqw = op;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eSyntaxError, "ISEQ is required");
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
|
|
|
|
loaded_iseq = rb_iseqw_to_iseq(iseqw);
|
|
|
|
iseq_add_mark_object(iseq, (VALUE)loaded_iseq);
|
|
|
|
return loaded_iseq;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
}
|
|
|
|
|
2014-11-25 04:46:11 +03:00
|
|
|
static VALUE
|
|
|
|
iseq_build_callinfo_from_hash(rb_iseq_t *iseq, VALUE op)
|
|
|
|
{
|
|
|
|
ID mid = 0;
|
|
|
|
int orig_argc = 0;
|
|
|
|
unsigned int flag = 0;
|
2015-09-19 20:59:58 +03:00
|
|
|
struct rb_call_info_kw_arg *kw_arg = 0;
|
2014-11-25 04:46:11 +03:00
|
|
|
|
|
|
|
if (!NIL_P(op)) {
|
|
|
|
VALUE vmid = rb_hash_aref(op, ID2SYM(rb_intern("mid")));
|
|
|
|
VALUE vflag = rb_hash_aref(op, ID2SYM(rb_intern("flag")));
|
|
|
|
VALUE vorig_argc = rb_hash_aref(op, ID2SYM(rb_intern("orig_argc")));
|
2014-12-04 01:16:58 +03:00
|
|
|
VALUE vkw_arg = rb_hash_aref(op, ID2SYM(rb_intern("kw_arg")));
|
2014-11-25 04:46:11 +03:00
|
|
|
|
|
|
|
if (!NIL_P(vmid)) mid = SYM2ID(vmid);
|
|
|
|
if (!NIL_P(vflag)) flag = NUM2UINT(vflag);
|
|
|
|
if (!NIL_P(vorig_argc)) orig_argc = FIX2INT(vorig_argc);
|
|
|
|
|
2014-12-04 01:16:58 +03:00
|
|
|
if (!NIL_P(vkw_arg)) {
|
|
|
|
int i;
|
|
|
|
int len = RARRAY_LENINT(vkw_arg);
|
2015-08-12 15:16:29 +03:00
|
|
|
size_t n = rb_call_info_kw_arg_bytes(len);
|
2014-12-04 01:16:58 +03:00
|
|
|
|
|
|
|
kw_arg = xmalloc(n);
|
|
|
|
kw_arg->keyword_len = len;
|
|
|
|
for (i = 0; i < len; i++) {
|
2015-02-06 04:31:53 +03:00
|
|
|
VALUE kw = RARRAY_AREF(vkw_arg, i);
|
|
|
|
SYM2ID(kw); /* make immortal */
|
|
|
|
kw_arg->keywords[i] = kw;
|
2014-12-04 01:16:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-25 04:46:11 +03:00
|
|
|
|
2015-09-08 11:21:07 +03:00
|
|
|
return (VALUE)new_callinfo(iseq, mid, orig_argc, flag, kw_arg, (flag & VM_CALL_ARGS_SIMPLE) == 0);
|
2014-11-25 04:46:11 +03:00
|
|
|
}
|
2015-09-08 11:21:07 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2010-10-31 04:42:54 +03:00
|
|
|
iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor,
|
2015-11-22 09:32:38 +03:00
|
|
|
VALUE body, VALUE labels_wrapper)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2009-11-03 20:46:28 +03:00
|
|
|
/* TODO: body should be frozen */
|
2013-11-08 06:00:35 +04:00
|
|
|
const VALUE *ptr = RARRAY_CONST_PTR(body);
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
long i, len = RARRAY_LEN(body);
|
2015-11-22 09:32:38 +03:00
|
|
|
struct st_table *labels_table = DATA_PTR(labels_wrapper);
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
int j;
|
2006-12-31 18:02:22 +03:00
|
|
|
int line_no = 0;
|
2015-11-22 09:32:23 +03:00
|
|
|
int ret = COMPILE_OK;
|
2011-08-24 10:31:15 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* index -> LABEL *label
|
|
|
|
*/
|
|
|
|
static struct st_table *insn_table;
|
|
|
|
|
|
|
|
if (insn_table == 0) {
|
2009-01-19 04:06:56 +03:00
|
|
|
insn_table = insn_make_insn_table();
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
VALUE obj = ptr[i];
|
|
|
|
|
|
|
|
if (SYMBOL_P(obj)) {
|
|
|
|
LABEL *label = register_label(iseq, labels_table, obj);
|
|
|
|
ADD_LABEL(anchor, label);
|
|
|
|
}
|
|
|
|
else if (FIXNUM_P(obj)) {
|
|
|
|
line_no = NUM2INT(obj);
|
|
|
|
}
|
2011-09-29 15:07:45 +04:00
|
|
|
else if (RB_TYPE_P(obj, T_ARRAY)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE *argv = 0;
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
int argc = RARRAY_LENINT(obj) - 1;
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
st_data_t insn_id;
|
2007-07-02 01:43:30 +04:00
|
|
|
VALUE insn;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2013-05-13 13:56:22 +04:00
|
|
|
insn = (argc < 0) ? Qnil : RARRAY_AREF(obj, 0);
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
if (st_lookup(insn_table, (st_data_t)insn, &insn_id) == 0) {
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* TODO: exception */
|
2016-04-19 07:46:20 +03:00
|
|
|
COMPILE_ERROR(iseq, line_no,
|
2015-12-04 20:28:26 +03:00
|
|
|
"unknown instruction: %+"PRIsVALUE, insn);
|
2015-11-22 09:32:23 +03:00
|
|
|
ret = COMPILE_NG;
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2010-10-12 18:35:40 +04:00
|
|
|
if (argc != insn_len((VALUE)insn_id)-1) {
|
2016-04-19 07:46:20 +03:00
|
|
|
COMPILE_ERROR(iseq, line_no,
|
2015-12-04 20:28:26 +03:00
|
|
|
"operand size mismatch");
|
2015-11-22 09:32:23 +03:00
|
|
|
ret = COMPILE_NG;
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
argv = compile_data_alloc(iseq, sizeof(VALUE) * argc);
|
|
|
|
for (j=0; j<argc; j++) {
|
|
|
|
VALUE op = rb_ary_entry(obj, j+1);
|
2010-10-12 18:35:40 +04:00
|
|
|
switch (insn_op_type((VALUE)insn_id, j)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
case TS_OFFSET: {
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
LABEL *label = register_label(iseq, labels_table, op);
|
|
|
|
argv[j] = (VALUE)label;
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case TS_LINDEX:
|
|
|
|
case TS_NUM:
|
2008-08-23 11:01:57 +04:00
|
|
|
(void)NUM2INT(op);
|
|
|
|
argv[j] = op;
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
case TS_VALUE:
|
|
|
|
argv[j] = op;
|
2007-07-01 22:16:02 +04:00
|
|
|
iseq_add_mark_object(iseq, op);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
case TS_ISEQ:
|
|
|
|
{
|
|
|
|
if (op != Qnil) {
|
2015-07-22 01:52:59 +03:00
|
|
|
argv[j] = (VALUE)iseq_build_load_iseq(iseq, op);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
argv[j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TS_GENTRY:
|
|
|
|
op = rb_convert_type(op, T_SYMBOL, "Symbol", "to_sym");
|
|
|
|
argv[j] = (VALUE)rb_global_entry(SYM2ID(op));
|
|
|
|
break;
|
|
|
|
case TS_IC:
|
2010-02-24 20:06:15 +03:00
|
|
|
argv[j] = op;
|
2015-07-25 00:44:14 +03:00
|
|
|
if (NUM2UINT(op) >= iseq->body->is_size) {
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->is_size = NUM2INT(op) + 1;
|
2012-10-09 09:33:54 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
2012-10-09 09:33:54 +04:00
|
|
|
case TS_CALLINFO:
|
2014-11-25 04:46:11 +03:00
|
|
|
argv[j] = iseq_build_callinfo_from_hash(iseq, op);
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
break;
|
2015-09-19 20:59:58 +03:00
|
|
|
case TS_CALLCACHE:
|
|
|
|
argv[j] = Qfalse;
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
case TS_ID:
|
|
|
|
argv[j] = rb_convert_type(op, T_SYMBOL,
|
|
|
|
"Symbol", "to_sym");
|
|
|
|
break;
|
|
|
|
case TS_CDHASH:
|
|
|
|
{
|
|
|
|
int i;
|
2014-12-04 01:16:58 +03:00
|
|
|
VALUE map = rb_hash_new();
|
|
|
|
|
|
|
|
rb_hash_tbl_raw(map)->type = &cdhash_type;
|
2006-12-31 18:02:22 +03:00
|
|
|
op = rb_convert_type(op, T_ARRAY, "Array", "to_ary");
|
|
|
|
for (i=0; i<RARRAY_LEN(op); i+=2) {
|
2014-12-04 01:16:58 +03:00
|
|
|
VALUE key = RARRAY_AREF(op, i);
|
|
|
|
VALUE sym = RARRAY_AREF(op, i+1);
|
2006-12-31 18:02:22 +03:00
|
|
|
LABEL *label =
|
|
|
|
register_label(iseq, labels_table, sym);
|
2014-12-04 01:16:58 +03:00
|
|
|
rb_hash_aset(map, key, (VALUE)label | 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2014-12-04 01:16:58 +03:00
|
|
|
RB_GC_GUARD(op);
|
|
|
|
argv[j] = map;
|
2015-09-10 06:17:30 +03:00
|
|
|
rb_iseq_add_mark_object(iseq, map);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
break;
|
2014-12-15 22:09:25 +03:00
|
|
|
case TS_FUNCPTR:
|
2014-12-16 08:54:32 +03:00
|
|
|
{
|
|
|
|
#if SIZEOF_VALUE <= SIZEOF_LONG
|
|
|
|
long funcptr = NUM2LONG(op);
|
|
|
|
#else
|
|
|
|
LONG_LONG funcptr = NUM2LL(op);
|
|
|
|
#endif
|
|
|
|
argv[j] = (VALUE)funcptr;
|
|
|
|
}
|
2014-12-15 22:09:25 +03:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
default:
|
2010-10-12 18:35:40 +04:00
|
|
|
rb_raise(rb_eSyntaxError, "unknown operand: %c", insn_op_type((VALUE)insn_id, j));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ADD_ELEM(anchor,
|
|
|
|
(LINK_ELEMENT*)new_insn_core(iseq, line_no,
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
(enum ruby_vminsn_type)insn_id, argc, argv));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eTypeError, "unexpected object for instruction");
|
|
|
|
}
|
|
|
|
}
|
2015-11-22 09:32:38 +03:00
|
|
|
DATA_PTR(labels_wrapper) = 0;
|
2010-12-12 17:45:30 +03:00
|
|
|
validate_labels(iseq, labels_table);
|
2015-11-22 09:32:23 +03:00
|
|
|
if (!ret) return ret;
|
2015-11-22 09:10:41 +03:00
|
|
|
return iseq_setup(iseq, anchor);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2010-12-03 00:53:08 +03:00
|
|
|
#define CHECK_ARRAY(v) rb_convert_type((v), T_ARRAY, "Array", "to_ary")
|
|
|
|
#define CHECK_SYMBOL(v) rb_convert_type((v), T_SYMBOL, "Symbol", "to_sym")
|
2014-12-04 01:16:58 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
int_param(int *dst, VALUE param, VALUE sym)
|
|
|
|
{
|
|
|
|
VALUE val = rb_hash_aref(param, sym);
|
|
|
|
switch (TYPE(val)) {
|
|
|
|
case T_NIL:
|
|
|
|
return FALSE;
|
|
|
|
case T_FIXNUM:
|
|
|
|
*dst = FIX2INT(val);
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
rb_raise(rb_eTypeError, "invalid %+"PRIsVALUE" Fixnum: %+"PRIsVALUE,
|
|
|
|
sym, val);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-07-24 23:58:09 +03:00
|
|
|
static const struct rb_iseq_param_keyword *
|
2014-12-04 01:16:58 +03:00
|
|
|
iseq_build_kw(rb_iseq_t *iseq, VALUE params, VALUE keywords)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int len = RARRAY_LENINT(keywords);
|
|
|
|
int default_len;
|
|
|
|
VALUE key, sym, default_val;
|
2015-07-23 12:53:16 +03:00
|
|
|
VALUE *dvs;
|
|
|
|
ID *ids;
|
2015-07-24 23:58:09 +03:00
|
|
|
struct rb_iseq_param_keyword *keyword = ZALLOC(struct rb_iseq_param_keyword);
|
2014-12-04 01:16:58 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.flags.has_kw = TRUE;
|
2014-12-04 01:16:58 +03:00
|
|
|
|
2015-07-24 23:58:09 +03:00
|
|
|
keyword->num = len;
|
2014-12-04 01:16:58 +03:00
|
|
|
#define SYM(s) ID2SYM(rb_intern(#s))
|
2015-07-24 23:58:09 +03:00
|
|
|
(void)int_param(&keyword->bits_start, params, SYM(kwbits));
|
|
|
|
i = keyword->bits_start - keyword->num;
|
2015-07-23 12:53:16 +03:00
|
|
|
ids = (VALUE *)&iseq->body->local_table[i];
|
2014-12-04 01:16:58 +03:00
|
|
|
#undef SYM
|
|
|
|
|
|
|
|
/* required args */
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
VALUE val = RARRAY_AREF(keywords, i);
|
|
|
|
|
|
|
|
if (!SYMBOL_P(val)) {
|
|
|
|
goto default_values;
|
|
|
|
}
|
2015-07-23 12:53:16 +03:00
|
|
|
ids[i] = SYM2ID(val);
|
2015-07-24 23:58:09 +03:00
|
|
|
keyword->required_num++;
|
2014-12-04 01:16:58 +03:00
|
|
|
}
|
|
|
|
|
2015-07-23 12:53:16 +03:00
|
|
|
default_values: /* note: we intentionally preserve `i' from previous loop */
|
2014-12-04 01:16:58 +03:00
|
|
|
default_len = len - i;
|
|
|
|
if (default_len == 0) {
|
2015-07-24 23:58:09 +03:00
|
|
|
return keyword;
|
2014-12-04 01:16:58 +03:00
|
|
|
}
|
|
|
|
|
2015-07-23 12:53:16 +03:00
|
|
|
dvs = ALLOC_N(VALUE, default_len);
|
2014-12-04 01:16:58 +03:00
|
|
|
|
|
|
|
for (j = 0; i < len; i++, j++) {
|
|
|
|
key = RARRAY_AREF(keywords, i);
|
|
|
|
CHECK_ARRAY(key);
|
|
|
|
|
|
|
|
switch (RARRAY_LEN(key)) {
|
|
|
|
case 1:
|
|
|
|
sym = RARRAY_AREF(key, 0);
|
|
|
|
default_val = Qundef;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
sym = RARRAY_AREF(key, 0);
|
|
|
|
default_val = RARRAY_AREF(key, 1);
|
|
|
|
break;
|
|
|
|
default:
|
2015-07-24 23:58:09 +03:00
|
|
|
rb_raise(rb_eTypeError, "keyword default has unsupported len %+"PRIsVALUE, key);
|
2014-12-04 01:16:58 +03:00
|
|
|
}
|
2015-07-23 12:53:16 +03:00
|
|
|
ids[i] = SYM2ID(sym);
|
|
|
|
dvs[j] = default_val;
|
2014-12-04 01:16:58 +03:00
|
|
|
}
|
2015-07-23 12:53:16 +03:00
|
|
|
|
2015-07-24 23:58:09 +03:00
|
|
|
keyword->table = ids;
|
|
|
|
keyword->default_values = dvs;
|
|
|
|
|
|
|
|
return keyword;
|
2014-12-04 01:16:58 +03:00
|
|
|
}
|
2007-07-02 01:43:30 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
void
|
2014-12-04 01:16:58 +03:00
|
|
|
rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE params,
|
2008-12-05 06:35:48 +03:00
|
|
|
VALUE exception, VALUE body)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2014-12-04 01:16:58 +03:00
|
|
|
#define SYM(s) ID2SYM(rb_intern(#s))
|
|
|
|
int i, len;
|
2006-12-31 18:02:22 +03:00
|
|
|
ID *tbl;
|
|
|
|
struct st_table *labels_table = st_init_numtable();
|
2015-11-22 09:32:38 +03:00
|
|
|
VALUE labels_wrapper = Data_Wrap_Struct(0, 0, st_free_table, labels_table);
|
2014-12-04 01:16:58 +03:00
|
|
|
VALUE arg_opt_labels = rb_hash_aref(params, SYM(opt));
|
|
|
|
VALUE keywords = rb_hash_aref(params, SYM(keyword));
|
|
|
|
VALUE sym_arg_rest = ID2SYM(rb_intern("#arg_rest"));
|
2006-12-31 18:02:22 +03:00
|
|
|
DECL_ANCHOR(anchor);
|
2007-07-20 11:11:35 +04:00
|
|
|
INIT_ANCHOR(anchor);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-12-04 01:16:58 +03:00
|
|
|
len = RARRAY_LENINT(locals);
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->local_table_size = len;
|
2015-12-07 21:44:45 +03:00
|
|
|
iseq->body->local_table = tbl = len > 0 ? (ID *)ALLOC_N(ID, iseq->body->local_table_size) : NULL;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2014-12-04 01:16:58 +03:00
|
|
|
for (i = 0; i < len; i++) {
|
2013-05-13 13:56:22 +04:00
|
|
|
VALUE lv = RARRAY_AREF(locals, i);
|
2014-12-04 01:16:58 +03:00
|
|
|
|
|
|
|
if (sym_arg_rest == lv) {
|
|
|
|
tbl[i] = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tbl[i] = FIXNUM_P(lv) ? (ID)FIX2LONG(lv) : SYM2ID(CHECK_SYMBOL(lv));
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2014-12-06 00:49:42 +03:00
|
|
|
/*
|
|
|
|
* we currently ignore misc params,
|
|
|
|
* local_size, stack_size and param.size are all calculated
|
|
|
|
*/
|
2014-12-04 01:16:58 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
#define INT_PARAM(F) int_param(&iseq->body->param.F, params, SYM(F))
|
2014-12-04 01:16:58 +03:00
|
|
|
if (INT_PARAM(lead_num)) {
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.flags.has_lead = TRUE;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
if (INT_PARAM(post_num)) iseq->body->param.flags.has_post = TRUE;
|
|
|
|
if (INT_PARAM(post_start)) iseq->body->param.flags.has_post = TRUE;
|
|
|
|
if (INT_PARAM(rest_start)) iseq->body->param.flags.has_rest = TRUE;
|
|
|
|
if (INT_PARAM(block_start)) iseq->body->param.flags.has_block = TRUE;
|
2014-12-04 01:16:58 +03:00
|
|
|
#undef INT_PARAM
|
2007-06-05 08:49:54 +04:00
|
|
|
|
2014-12-04 01:16:58 +03:00
|
|
|
switch (TYPE(arg_opt_labels)) {
|
|
|
|
case T_ARRAY:
|
|
|
|
len = RARRAY_LENINT(arg_opt_labels);
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.flags.has_opt = !!(len - 1 >= 0);
|
2014-12-04 01:16:58 +03:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
if (iseq->body->param.flags.has_opt) {
|
2015-07-24 23:58:09 +03:00
|
|
|
VALUE *opt_table = ALLOC_N(VALUE, len);
|
2014-12-04 01:16:58 +03:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
VALUE ent = RARRAY_AREF(arg_opt_labels, i);
|
|
|
|
LABEL *label = register_label(iseq, labels_table, ent);
|
2015-07-24 23:58:09 +03:00
|
|
|
opt_table[i] = (VALUE)label;
|
2014-12-04 01:16:58 +03:00
|
|
|
}
|
2015-07-24 23:58:09 +03:00
|
|
|
|
|
|
|
iseq->body->param.opt_num = len - 1;
|
|
|
|
iseq->body->param.opt_table = opt_table;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2014-12-04 01:16:58 +03:00
|
|
|
case T_NIL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rb_raise(rb_eTypeError, ":opt param is not an array: %+"PRIsVALUE,
|
|
|
|
arg_opt_labels);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (TYPE(keywords)) {
|
|
|
|
case T_ARRAY:
|
2015-07-24 23:58:09 +03:00
|
|
|
iseq->body->param.keyword = iseq_build_kw(iseq, params, keywords);
|
2014-12-04 01:16:58 +03:00
|
|
|
case T_NIL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rb_raise(rb_eTypeError, ":keywords param is not an array: %+"PRIsVALUE,
|
|
|
|
keywords);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Qtrue == rb_hash_aref(params, SYM(ambiguous_param0))) {
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.flags.ambiguous_param0 = TRUE;
|
2014-12-04 01:16:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (int_param(&i, params, SYM(kwrest))) {
|
2015-07-24 23:58:09 +03:00
|
|
|
struct rb_iseq_param_keyword *keyword = (struct rb_iseq_param_keyword *)iseq->body->param.keyword;
|
|
|
|
if (keyword == NULL) {
|
|
|
|
iseq->body->param.keyword = keyword = ZALLOC(struct rb_iseq_param_keyword);
|
|
|
|
}
|
|
|
|
keyword->rest_start = i;
|
|
|
|
iseq->body->param.flags.has_kwrest = TRUE;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2014-12-04 01:16:58 +03:00
|
|
|
#undef SYM
|
|
|
|
iseq_calc_param_size(iseq);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/* exception */
|
2010-10-31 04:42:54 +03:00
|
|
|
iseq_build_from_ary_exception(iseq, labels_table, exception);
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 08:25:10 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/* body */
|
2015-11-22 09:32:38 +03:00
|
|
|
iseq_build_from_ary_body(iseq, anchor, body, labels_wrapper);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
|
|
|
/* for parser */
|
|
|
|
|
|
|
|
int
|
2016-07-28 14:02:30 +03:00
|
|
|
rb_dvar_defined(ID id, const struct rb_block *base_block)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
{
|
2015-07-16 16:13:50 +03:00
|
|
|
const rb_iseq_t *iseq;
|
|
|
|
|
2016-07-28 14:02:30 +03:00
|
|
|
if (base_block && (iseq = vm_block_iseq(base_block)) != NULL) {
|
2015-07-22 01:52:59 +03:00
|
|
|
while (iseq->body->type == ISEQ_TYPE_BLOCK ||
|
|
|
|
iseq->body->type == ISEQ_TYPE_RESCUE ||
|
|
|
|
iseq->body->type == ISEQ_TYPE_ENSURE ||
|
|
|
|
iseq->body->type == ISEQ_TYPE_EVAL ||
|
|
|
|
iseq->body->type == ISEQ_TYPE_MAIN
|
2008-12-27 08:58:23 +03:00
|
|
|
) {
|
2015-07-25 00:44:14 +03:00
|
|
|
unsigned int i;
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
for (i = 0; i < iseq->body->local_table_size; i++) {
|
|
|
|
if (iseq->body->local_table[i] == id) {
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq = iseq->body->parent_iseq;
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-07-28 14:02:30 +03:00
|
|
|
rb_local_defined(ID id, const struct rb_block *base_block)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
{
|
2015-07-16 16:13:50 +03:00
|
|
|
const rb_iseq_t *iseq;
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2016-07-28 14:02:30 +03:00
|
|
|
if (base_block && (iseq = vm_block_iseq(base_block)) != NULL) {
|
2015-07-25 00:44:14 +03:00
|
|
|
unsigned int i;
|
2016-07-28 14:02:30 +03:00
|
|
|
iseq = iseq->body->local_iseq;
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
for (i=0; i<iseq->body->local_table_size; i++) {
|
|
|
|
if (iseq->body->local_table[i] == id) {
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-17 06:20:58 +03:00
|
|
|
static int
|
|
|
|
caller_location(VALUE *path, VALUE *absolute_path)
|
|
|
|
{
|
|
|
|
const rb_thread_t *const th = GET_THREAD();
|
|
|
|
const rb_control_frame_t *const cfp =
|
|
|
|
rb_vm_get_ruby_level_next_cfp(th, th->cfp);
|
|
|
|
|
|
|
|
if (cfp) {
|
|
|
|
int line = rb_vm_get_sourceline(cfp);
|
2015-07-22 01:52:59 +03:00
|
|
|
*path = cfp->iseq->body->location.path;
|
|
|
|
*absolute_path = cfp->iseq->body->location.absolute_path;
|
2014-12-17 06:20:58 +03:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
else {
|
2016-01-26 09:23:47 +03:00
|
|
|
*path = rb_fstring_cstr("<compiled>");
|
2014-12-17 06:20:58 +03:00
|
|
|
*absolute_path = *path;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
VALUE arg;
|
|
|
|
rb_insn_func_t func;
|
|
|
|
int line;
|
|
|
|
} accessor_args;
|
|
|
|
|
2015-07-22 01:52:59 +03:00
|
|
|
static const rb_iseq_t *
|
2014-12-17 06:20:58 +03:00
|
|
|
method_for_self(VALUE name, VALUE arg, rb_insn_func_t func,
|
|
|
|
VALUE (*build)(rb_iseq_t *, LINK_ANCHOR *, VALUE))
|
|
|
|
{
|
|
|
|
VALUE path, absolute_path;
|
|
|
|
accessor_args acc;
|
|
|
|
|
|
|
|
acc.arg = arg;
|
|
|
|
acc.func = func;
|
|
|
|
acc.line = caller_location(&path, &absolute_path);
|
2015-03-28 02:51:18 +03:00
|
|
|
return rb_iseq_new_with_opt((NODE *)IFUNC_NEW(build, (VALUE)&acc, 0),
|
2014-12-17 06:20:58 +03:00
|
|
|
rb_sym2str(name), path, absolute_path,
|
|
|
|
INT2FIX(acc.line), 0, ISEQ_TYPE_METHOD, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
for_self_aref(rb_iseq_t *iseq, LINK_ANCHOR *ret, VALUE a)
|
|
|
|
{
|
|
|
|
const accessor_args *const args = (void *)a;
|
|
|
|
const int line = args->line;
|
|
|
|
|
|
|
|
iseq_set_local_table(iseq, 0);
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.lead_num = 0;
|
|
|
|
iseq->body->param.size = 0;
|
2014-12-17 06:20:58 +03:00
|
|
|
|
|
|
|
ADD_INSN1(ret, line, putobject, args->arg);
|
|
|
|
ADD_INSN1(ret, line, opt_call_c_function, (VALUE)args->func);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
for_self_aset(rb_iseq_t *iseq, LINK_ANCHOR *ret, VALUE a)
|
|
|
|
{
|
|
|
|
const accessor_args *const args = (void *)a;
|
|
|
|
const int line = args->line;
|
|
|
|
static const ID vars[] = {1, idUScore};
|
|
|
|
|
|
|
|
iseq_set_local_table(iseq, vars);
|
2015-07-22 01:52:59 +03:00
|
|
|
iseq->body->param.lead_num = 1;
|
|
|
|
iseq->body->param.size = 1;
|
2014-12-17 06:20:58 +03:00
|
|
|
|
2016-07-28 14:02:30 +03:00
|
|
|
ADD_GETLOCAL(ret, line, numberof(vars)-1, 0);
|
2014-12-17 06:20:58 +03:00
|
|
|
ADD_INSN1(ret, line, putobject, args->arg);
|
|
|
|
ADD_INSN1(ret, line, opt_call_c_function, (VALUE)args->func);
|
|
|
|
ADD_INSN(ret, line, pop);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2014-12-19 14:02:10 +03:00
|
|
|
/*
|
|
|
|
* func (index) -> (value)
|
|
|
|
*/
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *
|
2014-12-17 06:20:58 +03:00
|
|
|
rb_method_for_self_aref(VALUE name, VALUE arg, rb_insn_func_t func)
|
|
|
|
{
|
|
|
|
return method_for_self(name, arg, func, for_self_aref);
|
|
|
|
}
|
|
|
|
|
2014-12-19 14:02:10 +03:00
|
|
|
/*
|
|
|
|
* func (index, value) -> (index, value)
|
|
|
|
*/
|
2015-07-22 01:52:59 +03:00
|
|
|
const rb_iseq_t *
|
2014-12-17 06:20:58 +03:00
|
|
|
rb_method_for_self_aset(VALUE name, VALUE arg, rb_insn_func_t func)
|
|
|
|
{
|
|
|
|
return method_for_self(name, arg, func, for_self_aset);
|
|
|
|
}
|
2015-12-08 16:58:50 +03:00
|
|
|
|
|
|
|
/* ISeq binary format */
|
|
|
|
|
|
|
|
typedef unsigned int ibf_offset_t;
|
|
|
|
#define IBF_OFFSET(ptr) ((ibf_offset_t)(VALUE)(ptr))
|
|
|
|
|
|
|
|
struct ibf_header {
|
|
|
|
char magic[4]; /* YARB */
|
|
|
|
unsigned int major_version;
|
|
|
|
unsigned int minor_version;
|
|
|
|
unsigned int size;
|
|
|
|
unsigned int extra_size;
|
|
|
|
|
|
|
|
unsigned int iseq_list_size;
|
|
|
|
unsigned int id_list_size;
|
|
|
|
unsigned int object_list_size;
|
|
|
|
|
|
|
|
ibf_offset_t iseq_list_offset;
|
|
|
|
ibf_offset_t id_list_offset;
|
|
|
|
ibf_offset_t object_list_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_id_entry {
|
|
|
|
enum {
|
|
|
|
ibf_id_enc_ascii,
|
|
|
|
ibf_id_enc_utf8,
|
|
|
|
ibf_id_enc_other
|
|
|
|
} enc : 2;
|
|
|
|
char body[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_dump {
|
|
|
|
VALUE str;
|
|
|
|
VALUE iseq_list; /* [iseq0 offset, ...] */
|
|
|
|
VALUE obj_list; /* [objs] */
|
|
|
|
st_table *iseq_table; /* iseq -> iseq number */
|
|
|
|
st_table *id_table; /* id -> id number */
|
|
|
|
};
|
|
|
|
|
|
|
|
rb_iseq_t * iseq_alloc(void);
|
|
|
|
|
|
|
|
struct ibf_load {
|
|
|
|
const char *buff;
|
|
|
|
const struct ibf_header *header;
|
|
|
|
ID *id_list; /* [id0, ...] */
|
|
|
|
VALUE iseq_list; /* [iseq0, ...] */
|
|
|
|
VALUE obj_list; /* [obj0, ...] */
|
|
|
|
VALUE loader_obj;
|
|
|
|
VALUE str;
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
};
|
|
|
|
|
|
|
|
static ibf_offset_t
|
|
|
|
ibf_dump_pos(struct ibf_dump *dump)
|
|
|
|
{
|
|
|
|
return (unsigned int)rb_str_strlen(dump->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ibf_offset_t
|
|
|
|
ibf_dump_write(struct ibf_dump *dump, const void *buff, unsigned long size)
|
|
|
|
{
|
|
|
|
ibf_offset_t pos = ibf_dump_pos(dump);
|
|
|
|
rb_str_cat(dump->str, (const char *)buff, size);
|
|
|
|
/* TODO: overflow check */
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_overwrite(struct ibf_dump *dump, void *buff, unsigned int size, long offset)
|
|
|
|
{
|
|
|
|
VALUE str = dump->str;
|
|
|
|
char *ptr = RSTRING_PTR(str);
|
2015-12-08 18:59:05 +03:00
|
|
|
if ((unsigned long)(size + offset) > (unsigned long)RSTRING_LEN(str))
|
|
|
|
rb_bug("ibf_dump_overwrite: overflow");
|
2015-12-08 16:58:50 +03:00
|
|
|
memcpy(ptr + offset, buff, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
ibf_load_alloc(const struct ibf_load *load, ibf_offset_t offset, int size)
|
|
|
|
{
|
|
|
|
void *buff = ruby_xmalloc(size);
|
|
|
|
memcpy(buff, load->buff + offset, size);
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IBF_W(b, type, n) (type *)(VALUE)ibf_dump_write(dump, (b), sizeof(type) * (n))
|
|
|
|
#define IBF_WV(variable) ibf_dump_write(dump, &(variable), sizeof(variable))
|
|
|
|
#define IBF_WP(b, type, n) ibf_dump_write(dump, (b), sizeof(type) * (n))
|
|
|
|
#define IBF_R(val, type, n) (type *)ibf_load_alloc(load, IBF_OFFSET(val), sizeof(type) * (n))
|
|
|
|
|
|
|
|
static int
|
|
|
|
ibf_table_lookup(struct st_table *table, st_data_t key)
|
|
|
|
{
|
|
|
|
st_data_t val;
|
|
|
|
|
|
|
|
if (st_lookup(table, key, &val)) {
|
|
|
|
return (int)val;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ibf_table_index(struct st_table *table, st_data_t key)
|
|
|
|
{
|
|
|
|
int index = ibf_table_lookup(table, key);
|
|
|
|
|
|
|
|
if (index < 0) { /* not found */
|
|
|
|
index = (int)table->num_entries;
|
|
|
|
st_insert(table, key, (st_data_t)index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dump/load generic */
|
|
|
|
|
|
|
|
static VALUE ibf_load_object(const struct ibf_load *load, VALUE object_index);
|
|
|
|
static rb_iseq_t *ibf_load_iseq(const struct ibf_load *load, const rb_iseq_t *index_iseq);
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_dump_object(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
long index = RARRAY_LEN(dump->obj_list);
|
|
|
|
long i;
|
|
|
|
for (i=0; i<index; i++) {
|
|
|
|
if (RARRAY_AREF(dump->obj_list, i) == obj) return (VALUE)i; /* dedup */
|
|
|
|
}
|
|
|
|
rb_ary_push(dump->obj_list, obj);
|
|
|
|
return (VALUE)index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_dump_id(struct ibf_dump *dump, ID id)
|
|
|
|
{
|
|
|
|
return (VALUE)ibf_table_index(dump->id_table, (st_data_t)id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ID
|
|
|
|
ibf_load_id(const struct ibf_load *load, const ID id_index)
|
|
|
|
{
|
|
|
|
ID id;
|
|
|
|
|
|
|
|
if (id_index == 0) {
|
|
|
|
id = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
id = load->id_list[(long)id_index];
|
|
|
|
|
|
|
|
if (id == 0) {
|
|
|
|
long *indices = (long *)(load->buff + load->header->id_list_offset);
|
|
|
|
VALUE str = ibf_load_object(load, indices[id_index]);
|
|
|
|
id = NIL_P(str) ? 0 : rb_intern_str(str); /* str == nil -> internal junk id */
|
|
|
|
load->id_list[(long)id_index] = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dump/load: code */
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_dump_callinfo(struct ibf_dump *dump, const struct rb_call_info *ci)
|
|
|
|
{
|
|
|
|
return (ci->flag & VM_CALL_KWARG) ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ibf_offset_t ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq);
|
|
|
|
|
|
|
|
static rb_iseq_t *
|
|
|
|
ibf_dump_iseq(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
if (iseq == NULL) {
|
|
|
|
return (rb_iseq_t *)-1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int iseq_index = ibf_table_lookup(dump->iseq_table, (st_data_t)iseq);
|
|
|
|
if (iseq_index < 0) {
|
|
|
|
iseq_index = ibf_table_index(dump->iseq_table, (st_data_t)iseq);
|
|
|
|
rb_ary_store(dump->iseq_list, iseq_index, LONG2NUM(ibf_dump_iseq_each(dump, rb_iseq_check(iseq))));
|
|
|
|
}
|
|
|
|
return (rb_iseq_t *)(VALUE)iseq_index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_dump_gentry(struct ibf_dump *dump, const struct rb_global_entry *entry)
|
|
|
|
{
|
|
|
|
return (VALUE)ibf_dump_id(dump, entry->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_gentry(const struct ibf_load *load, const struct rb_global_entry *entry)
|
|
|
|
{
|
|
|
|
ID gid = ibf_load_id(load, (ID)(VALUE)entry);
|
|
|
|
return (VALUE)rb_global_entry(gid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE *
|
|
|
|
ibf_dump_code(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
const int iseq_size = iseq->body->iseq_size;
|
|
|
|
int code_index;
|
|
|
|
VALUE *code;
|
|
|
|
const VALUE *orig_code = rb_iseq_original_iseq(iseq);
|
|
|
|
|
|
|
|
code = ALLOCA_N(VALUE, iseq_size);
|
|
|
|
|
|
|
|
for (code_index=0; code_index<iseq_size;) {
|
|
|
|
const VALUE insn = orig_code[code_index];
|
|
|
|
const char *types = insn_op_types(insn);
|
|
|
|
int op_index;
|
|
|
|
|
|
|
|
code[code_index++] = (VALUE)insn;
|
|
|
|
|
|
|
|
for (op_index=0; types[op_index]; op_index++, code_index++) {
|
|
|
|
VALUE op = orig_code[code_index];
|
|
|
|
switch (types[op_index]) {
|
|
|
|
case TS_CDHASH:
|
|
|
|
case TS_VALUE:
|
|
|
|
code[code_index] = ibf_dump_object(dump, op);
|
|
|
|
break;
|
|
|
|
case TS_ISEQ:
|
|
|
|
code[code_index] = (VALUE)ibf_dump_iseq(dump, (const rb_iseq_t *)op);
|
|
|
|
break;
|
|
|
|
case TS_IC:
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<iseq->body->is_size; i++) {
|
|
|
|
if (op == (VALUE)&iseq->body->is_entries[i]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
code[code_index] = i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TS_CALLINFO:
|
|
|
|
code[code_index] = ibf_dump_callinfo(dump, (const struct rb_call_info *)op);
|
|
|
|
break;
|
|
|
|
case TS_CALLCACHE:
|
|
|
|
code[code_index] = 0;
|
|
|
|
break;
|
|
|
|
case TS_ID:
|
|
|
|
code[code_index] = ibf_dump_id(dump, (ID)op);
|
|
|
|
break;
|
|
|
|
case TS_GENTRY:
|
|
|
|
code[code_index] = ibf_dump_gentry(dump, (const struct rb_global_entry *)op);
|
|
|
|
break;
|
|
|
|
case TS_FUNCPTR:
|
|
|
|
rb_raise(rb_eRuntimeError, "TS_FUNCPTR is not supported");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
code[code_index] = op;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(insn_len(insn) == op_index+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IBF_W(code, VALUE, iseq_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE *
|
|
|
|
ibf_load_code(const struct ibf_load *load, const rb_iseq_t *iseq, const struct rb_iseq_constant_body *body)
|
|
|
|
{
|
|
|
|
const int iseq_size = body->iseq_size;
|
|
|
|
int code_index;
|
|
|
|
VALUE *code = IBF_R(body->iseq_encoded, VALUE, iseq_size);
|
|
|
|
|
|
|
|
struct rb_call_info *ci_entries = iseq->body->ci_entries;
|
|
|
|
struct rb_call_info_with_kwarg *ci_kw_entries = (struct rb_call_info_with_kwarg *)&iseq->body->ci_entries[iseq->body->ci_size];
|
|
|
|
struct rb_call_cache *cc_entries = iseq->body->cc_entries;
|
|
|
|
union iseq_inline_storage_entry *is_entries = iseq->body->is_entries;
|
|
|
|
|
|
|
|
for (code_index=0; code_index<iseq_size;) {
|
|
|
|
const VALUE insn = code[code_index++];
|
|
|
|
const char *types = insn_op_types(insn);
|
|
|
|
int op_index;
|
|
|
|
|
|
|
|
for (op_index=0; types[op_index]; op_index++, code_index++) {
|
|
|
|
VALUE op = code[code_index];
|
|
|
|
|
|
|
|
switch (types[op_index]) {
|
|
|
|
case TS_CDHASH:
|
|
|
|
case TS_VALUE:
|
|
|
|
code[code_index] = ibf_load_object(load, op);
|
|
|
|
break;
|
|
|
|
case TS_ISEQ:
|
|
|
|
code[code_index] = (VALUE)ibf_load_iseq(load, (const rb_iseq_t *)op);
|
|
|
|
break;
|
|
|
|
case TS_IC:
|
|
|
|
code[code_index] = (VALUE)&is_entries[(int)op];
|
|
|
|
break;
|
|
|
|
case TS_CALLINFO:
|
|
|
|
code[code_index] = op ? (VALUE)ci_kw_entries++ : (VALUE)ci_entries++; /* op is Qtrue (kw) or Qfalse (!kw) */
|
|
|
|
break;
|
|
|
|
case TS_CALLCACHE:
|
|
|
|
code[code_index] = (VALUE)cc_entries++;
|
|
|
|
break;
|
|
|
|
case TS_ID:
|
|
|
|
code[code_index] = ibf_load_id(load, (ID)op);
|
|
|
|
break;
|
|
|
|
case TS_GENTRY:
|
|
|
|
code[code_index] = ibf_load_gentry(load, (const struct rb_global_entry *)op);
|
|
|
|
break;
|
|
|
|
case TS_FUNCPTR:
|
|
|
|
rb_raise(rb_eRuntimeError, "TS_FUNCPTR is not supported");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* code[code_index] = op; */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(insn_len(insn) == op_index+1);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE *
|
|
|
|
ibf_dump_param_opt_table(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
int opt_num = iseq->body->param.opt_num;
|
|
|
|
|
|
|
|
if (opt_num > 0) {
|
|
|
|
return IBF_W(iseq->body->param.opt_table, VALUE, opt_num + 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE *
|
|
|
|
ibf_load_param_opt_table(const struct ibf_load *load, const struct rb_iseq_constant_body *body)
|
|
|
|
{
|
|
|
|
int opt_num = body->param.opt_num;
|
|
|
|
|
|
|
|
if (opt_num > 0) {
|
|
|
|
ibf_offset_t offset = IBF_OFFSET(body->param.opt_table);
|
|
|
|
VALUE *table = ALLOC_N(VALUE, opt_num+1);
|
|
|
|
MEMCPY(table, load->buff + offset, VALUE, opt_num+1);
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rb_iseq_param_keyword *
|
|
|
|
ibf_dump_param_keyword(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
const struct rb_iseq_param_keyword *kw = iseq->body->param.keyword;
|
|
|
|
|
|
|
|
if (kw) {
|
|
|
|
struct rb_iseq_param_keyword dump_kw = *kw;
|
|
|
|
int dv_num = kw->num - kw->required_num;
|
|
|
|
ID *ids = kw->num > 0 ? ALLOCA_N(ID, kw->num) : NULL;
|
|
|
|
VALUE *dvs = dv_num > 0 ? ALLOCA_N(VALUE, dv_num) : NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<kw->num; i++) ids[i] = (ID)ibf_dump_id(dump, kw->table[i]);
|
|
|
|
for (i=0; i<dv_num; i++) dvs[i] = (VALUE)ibf_dump_object(dump, kw->default_values[i]);
|
|
|
|
|
|
|
|
dump_kw.table = IBF_W(ids, ID, kw->num);
|
|
|
|
dump_kw.default_values = IBF_W(dvs, VALUE, dv_num);
|
|
|
|
return IBF_W(&dump_kw, struct rb_iseq_param_keyword, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rb_iseq_param_keyword *
|
|
|
|
ibf_load_param_keyword(const struct ibf_load *load, const struct rb_iseq_constant_body *body)
|
|
|
|
{
|
|
|
|
if (body->param.keyword) {
|
|
|
|
struct rb_iseq_param_keyword *kw = IBF_R(body->param.keyword, struct rb_iseq_param_keyword, 1);
|
|
|
|
ID *ids = IBF_R(kw->table, ID, kw->num);
|
|
|
|
int dv_num = kw->num - kw->required_num;
|
|
|
|
VALUE *dvs = IBF_R(kw->default_values, VALUE, dv_num);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<kw->num; i++) {
|
|
|
|
ids[i] = ibf_load_id(load, ids[i]);
|
|
|
|
}
|
|
|
|
for (i=0; i<dv_num; i++) {
|
|
|
|
dvs[i] = ibf_load_object(load, dvs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
kw->table = ids;
|
|
|
|
kw->default_values = dvs;
|
|
|
|
return kw;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct iseq_line_info_entry *
|
|
|
|
ibf_dump_line_info_table(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
return IBF_W(iseq->body->line_info_table, struct iseq_line_info_entry, iseq->body->line_info_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct iseq_line_info_entry *
|
|
|
|
ibf_load_line_info_table(const struct ibf_load *load, const struct rb_iseq_constant_body *body)
|
|
|
|
{
|
|
|
|
return IBF_R(body->line_info_table, struct iseq_line_info_entry, body->line_info_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ID *
|
|
|
|
ibf_dump_local_table(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
|
|
|
{
|
2016-07-28 14:02:30 +03:00
|
|
|
const int size = iseq->body->local_table_size;
|
2015-12-08 16:58:50 +03:00
|
|
|
ID *table = ALLOCA_N(ID, size);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<size; i++) {
|
|
|
|
table[i] = ibf_dump_id(dump, iseq->body->local_table[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IBF_W(table, ID, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ID *
|
|
|
|
ibf_load_local_table(const struct ibf_load *load, const struct rb_iseq_constant_body *body)
|
|
|
|
{
|
2016-07-28 14:02:30 +03:00
|
|
|
const int size = body->local_table_size;
|
2015-12-08 16:58:50 +03:00
|
|
|
|
|
|
|
if (size > 0) {
|
|
|
|
ID *table = IBF_R(body->local_table, ID, size);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<size; i++) {
|
|
|
|
table[i] = ibf_load_id(load, table[i]);
|
|
|
|
}
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct iseq_catch_table *
|
|
|
|
ibf_dump_catch_table(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
const struct iseq_catch_table *table = iseq->body->catch_table;
|
|
|
|
|
|
|
|
if (table) {
|
|
|
|
int byte_size = iseq_catch_table_bytes(iseq->body->catch_table->size);
|
|
|
|
struct iseq_catch_table *dump_table = (struct iseq_catch_table *)ALLOCA_N(char, byte_size);
|
|
|
|
unsigned int i;
|
|
|
|
dump_table->size = table->size;
|
|
|
|
for (i=0; i<table->size; i++) {
|
|
|
|
dump_table->entries[i] = table->entries[i];
|
|
|
|
dump_table->entries[i].iseq = ibf_dump_iseq(dump, table->entries[i].iseq);
|
|
|
|
}
|
|
|
|
return (struct iseq_catch_table *)(VALUE)ibf_dump_write(dump, dump_table, byte_size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct iseq_catch_table *
|
|
|
|
ibf_load_catch_table(const struct ibf_load *load, const struct rb_iseq_constant_body *body)
|
|
|
|
{
|
|
|
|
if (body->catch_table) {
|
|
|
|
struct iseq_catch_table *table;
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int size;
|
|
|
|
size = *(unsigned int *)(load->buff + IBF_OFFSET(body->catch_table));
|
|
|
|
table = ibf_load_alloc(load, IBF_OFFSET(body->catch_table), iseq_catch_table_bytes(size));
|
|
|
|
for (i=0; i<size; i++) {
|
|
|
|
table->entries[i].iseq = ibf_load_iseq(load, table->entries[i].iseq);
|
|
|
|
}
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rb_call_info *
|
|
|
|
ibf_dump_ci_entries(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
const unsigned int ci_size = iseq->body->ci_size;
|
|
|
|
const unsigned int ci_kw_size = iseq->body->ci_kw_size;
|
|
|
|
const struct rb_call_info *ci_entries = iseq->body->ci_entries;
|
|
|
|
struct rb_call_info *dump_ci_entries;
|
|
|
|
struct rb_call_info_with_kwarg *dump_ci_kw_entries;
|
|
|
|
int byte_size = ci_size * sizeof(struct rb_call_info) +
|
|
|
|
ci_kw_size * sizeof(struct rb_call_info_with_kwarg);
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
dump_ci_entries = (struct rb_call_info *)ALLOCA_N(char, byte_size);
|
|
|
|
dump_ci_kw_entries = (struct rb_call_info_with_kwarg *)&dump_ci_entries[ci_size];
|
|
|
|
memcpy(dump_ci_entries, ci_entries, byte_size);
|
|
|
|
|
|
|
|
for (i=0; i<ci_size; i++) { /* conver ID for each ci */
|
|
|
|
dump_ci_entries[i].mid = ibf_dump_id(dump, dump_ci_entries[i].mid);
|
|
|
|
}
|
|
|
|
for (i=0; i<ci_kw_size; i++) {
|
|
|
|
const struct rb_call_info_kw_arg *kw_arg = dump_ci_kw_entries[i].kw_arg;
|
|
|
|
int j;
|
|
|
|
VALUE *keywords = ALLOCA_N(VALUE, kw_arg->keyword_len);
|
|
|
|
for (j=0; j<kw_arg->keyword_len; j++) {
|
|
|
|
keywords[j] = (VALUE)ibf_dump_object(dump, kw_arg->keywords[j]); /* kw_arg->keywords[n] is Symbol */
|
|
|
|
}
|
|
|
|
dump_ci_kw_entries[i].kw_arg = (struct rb_call_info_kw_arg *)(VALUE)ibf_dump_write(dump, &kw_arg->keyword_len, sizeof(int));
|
|
|
|
ibf_dump_write(dump, keywords, sizeof(VALUE) * kw_arg->keyword_len);
|
|
|
|
|
|
|
|
dump_ci_kw_entries[i].ci.mid = ibf_dump_id(dump, dump_ci_kw_entries[i].ci.mid);
|
|
|
|
}
|
|
|
|
return (struct rb_call_info *)(VALUE)ibf_dump_write(dump, dump_ci_entries, byte_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rb_call_info *
|
|
|
|
ibf_load_ci_entries(const struct ibf_load *load, const struct rb_iseq_constant_body *body)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
const unsigned int ci_size = body->ci_size;
|
|
|
|
const unsigned int ci_kw_size = body->ci_kw_size;
|
|
|
|
struct rb_call_info *ci_entries = ibf_load_alloc(load, IBF_OFFSET(body->ci_entries),
|
|
|
|
sizeof(struct rb_call_info) * body->ci_size +
|
|
|
|
sizeof(struct rb_call_info_with_kwarg) * body->ci_kw_size);
|
|
|
|
struct rb_call_info_with_kwarg *ci_kw_entries = (struct rb_call_info_with_kwarg *)&ci_entries[ci_size];
|
|
|
|
|
|
|
|
for (i=0; i<ci_size; i++) {
|
|
|
|
ci_entries[i].mid = ibf_load_id(load, ci_entries[i].mid);
|
|
|
|
}
|
|
|
|
for (i=0; i<ci_kw_size; i++) {
|
|
|
|
int j;
|
|
|
|
ibf_offset_t kw_arg_offset = IBF_OFFSET(ci_kw_entries[i].kw_arg);
|
|
|
|
const int keyword_len = *(int *)(load->buff + kw_arg_offset);
|
|
|
|
const VALUE *keywords = (VALUE *)(load->buff + kw_arg_offset + sizeof(int));
|
|
|
|
struct rb_call_info_kw_arg *kw_arg = ruby_xmalloc(sizeof(struct rb_call_info_kw_arg) + sizeof(VALUE) * (keyword_len - 1));
|
|
|
|
kw_arg->keyword_len = keyword_len;
|
|
|
|
for (j=0; j<kw_arg->keyword_len; j++) {
|
|
|
|
kw_arg->keywords[j] = (VALUE)ibf_load_object(load, keywords[j]);
|
|
|
|
}
|
|
|
|
ci_kw_entries[i].kw_arg = kw_arg;
|
|
|
|
ci_kw_entries[i].ci.mid = ibf_load_id(load, ci_kw_entries[i].ci.mid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ci_entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ibf_offset_t
|
|
|
|
ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
struct rb_iseq_constant_body dump_body;
|
|
|
|
dump_body = *iseq->body;
|
|
|
|
|
|
|
|
dump_body.location.path = ibf_dump_object(dump, dump_body.location.path);
|
|
|
|
dump_body.location.absolute_path = ibf_dump_object(dump, dump_body.location.absolute_path);
|
|
|
|
dump_body.location.base_label = ibf_dump_object(dump, dump_body.location.base_label);
|
|
|
|
dump_body.location.label = ibf_dump_object(dump, dump_body.location.label);
|
|
|
|
|
|
|
|
dump_body.iseq_encoded = ibf_dump_code(dump, iseq);
|
|
|
|
dump_body.param.opt_table = ibf_dump_param_opt_table(dump, iseq);
|
|
|
|
dump_body.param.keyword = ibf_dump_param_keyword(dump, iseq);
|
|
|
|
dump_body.line_info_table = ibf_dump_line_info_table(dump, iseq);
|
|
|
|
dump_body.local_table = ibf_dump_local_table(dump, iseq);
|
|
|
|
dump_body.catch_table = ibf_dump_catch_table(dump, iseq);
|
|
|
|
dump_body.parent_iseq = ibf_dump_iseq(dump, iseq->body->parent_iseq);
|
|
|
|
dump_body.local_iseq = ibf_dump_iseq(dump, iseq->body->local_iseq);
|
|
|
|
dump_body.is_entries = NULL;
|
|
|
|
dump_body.ci_entries = ibf_dump_ci_entries(dump, iseq);
|
|
|
|
dump_body.cc_entries = NULL;
|
|
|
|
dump_body.mark_ary = ISEQ_FLIP_CNT(iseq);
|
|
|
|
|
|
|
|
return ibf_dump_write(dump, &dump_body, sizeof(dump_body));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_location_str(const struct ibf_load *load, VALUE str_index)
|
|
|
|
{
|
|
|
|
VALUE str = ibf_load_object(load, str_index);
|
|
|
|
if (str != Qnil) {
|
|
|
|
str = rb_fstring(str);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_load_iseq_each(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
struct rb_iseq_constant_body *load_body = iseq->body = ZALLOC(struct rb_iseq_constant_body);
|
|
|
|
const struct rb_iseq_constant_body *body = (struct rb_iseq_constant_body *)(load->buff + offset);
|
|
|
|
|
|
|
|
/* memcpy(load_body, load->buff + offset, sizeof(*load_body)); */
|
|
|
|
load_body->type = body->type;
|
|
|
|
load_body->stack_max = body->stack_max;
|
|
|
|
load_body->iseq_size = body->iseq_size;
|
|
|
|
load_body->param = body->param;
|
|
|
|
load_body->local_table_size = body->local_table_size;
|
|
|
|
load_body->is_size = body->is_size;
|
|
|
|
load_body->ci_size = body->ci_size;
|
|
|
|
load_body->ci_kw_size = body->ci_kw_size;
|
|
|
|
load_body->line_info_size = body->line_info_size;
|
|
|
|
|
|
|
|
RB_OBJ_WRITE(iseq, &load_body->mark_ary, iseq_mark_ary_create((int)body->mark_ary));
|
|
|
|
|
|
|
|
RB_OBJ_WRITE(iseq, &load_body->location.path, ibf_load_location_str(load, body->location.path));
|
|
|
|
RB_OBJ_WRITE(iseq, &load_body->location.absolute_path, ibf_load_location_str(load, body->location.absolute_path));
|
|
|
|
RB_OBJ_WRITE(iseq, &load_body->location.base_label, ibf_load_location_str(load, body->location.base_label));
|
|
|
|
RB_OBJ_WRITE(iseq, &load_body->location.label, ibf_load_location_str(load, body->location.label));
|
|
|
|
load_body->location.first_lineno = body->location.first_lineno;
|
|
|
|
|
|
|
|
load_body->is_entries = ZALLOC_N(union iseq_inline_storage_entry, body->is_size);
|
|
|
|
load_body->ci_entries = ibf_load_ci_entries(load, body);
|
|
|
|
load_body->cc_entries = ZALLOC_N(struct rb_call_cache, body->ci_size + body->ci_kw_size);
|
|
|
|
load_body->param.opt_table = ibf_load_param_opt_table(load, body);
|
|
|
|
load_body->param.keyword = ibf_load_param_keyword(load, body);
|
|
|
|
load_body->line_info_table = ibf_load_line_info_table(load, body);
|
|
|
|
load_body->local_table = ibf_load_local_table(load, body);
|
|
|
|
load_body->catch_table = ibf_load_catch_table(load, body);
|
|
|
|
load_body->parent_iseq = ibf_load_iseq(load, body->parent_iseq);
|
|
|
|
load_body->local_iseq = ibf_load_iseq(load, body->local_iseq);
|
|
|
|
|
|
|
|
load_body->iseq_encoded = ibf_load_code(load, iseq, body);
|
|
|
|
|
|
|
|
rb_iseq_translate_threaded_code(iseq);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_iseq_list(struct ibf_dump *dump, struct ibf_header *header)
|
|
|
|
{
|
|
|
|
const long size = RARRAY_LEN(dump->iseq_list);
|
|
|
|
ibf_offset_t *list = ALLOCA_N(ibf_offset_t, size);
|
|
|
|
long i;
|
|
|
|
|
|
|
|
for (i=0; i<size; i++) {
|
|
|
|
list[i] = (ibf_offset_t)NUM2LONG(rb_ary_entry(dump->iseq_list, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
header->iseq_list_offset = ibf_dump_write(dump, list, sizeof(ibf_offset_t) * size);
|
|
|
|
header->iseq_list_size = (unsigned int)size;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ibf_dump_id_list_i_arg {
|
|
|
|
struct ibf_dump *dump;
|
|
|
|
long *list;
|
|
|
|
int current_i;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
ibf_dump_id_list_i(st_data_t key, st_data_t val, st_data_t ptr)
|
|
|
|
{
|
|
|
|
struct ibf_dump_id_list_i_arg *arg = (struct ibf_dump_id_list_i_arg *)ptr;
|
|
|
|
int i = (int)val;
|
|
|
|
ID id = (ID)key;
|
|
|
|
assert(arg->current_i == i);
|
|
|
|
arg->current_i++;
|
|
|
|
|
|
|
|
if (rb_id2name(id)) {
|
|
|
|
arg->list[i] = (long)ibf_dump_object(arg->dump, rb_id2str(id));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
arg->list[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_id_list(struct ibf_dump *dump, struct ibf_header *header)
|
|
|
|
{
|
|
|
|
const long size = dump->id_table->num_entries;
|
|
|
|
struct ibf_dump_id_list_i_arg arg;
|
|
|
|
arg.list = ALLOCA_N(long, size);
|
|
|
|
arg.dump = dump;
|
|
|
|
arg.current_i = 0;
|
|
|
|
|
|
|
|
st_foreach(dump->id_table, ibf_dump_id_list_i, (st_data_t)&arg);
|
|
|
|
|
|
|
|
header->id_list_offset = ibf_dump_write(dump, arg.list, sizeof(long) * size);
|
|
|
|
header->id_list_size = (unsigned int)size;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IBF_OBJECT_INTERNAL FL_PROMOTED0
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Binary format
|
|
|
|
* - ibf_object_header
|
|
|
|
* - ibf_object_xxx (xxx is type)
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ibf_object_header {
|
|
|
|
unsigned int type: 5;
|
|
|
|
unsigned int special_const: 1;
|
|
|
|
unsigned int frozen: 1;
|
|
|
|
unsigned int internal: 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ibf_object_class_index {
|
|
|
|
IBF_OBJECT_CLASS_OBJECT,
|
|
|
|
IBF_OBJECT_CLASS_ARRAY,
|
|
|
|
IBF_OBJECT_CLASS_STANDARD_ERROR
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_object_string {
|
|
|
|
long encindex;
|
|
|
|
long len;
|
|
|
|
char ptr[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_object_regexp {
|
|
|
|
long srcstr;
|
|
|
|
char option;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_object_array {
|
|
|
|
long len;
|
|
|
|
long ary[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_object_hash {
|
|
|
|
long len;
|
|
|
|
long keyval[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_object_struct_range {
|
|
|
|
long class_index;
|
|
|
|
long len;
|
|
|
|
long beg;
|
|
|
|
long end;
|
|
|
|
int excl;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_object_bignum {
|
|
|
|
ssize_t slen;
|
|
|
|
BDIGIT digits[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ibf_object_data_type {
|
|
|
|
IBF_OBJECT_DATA_ENCODING
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_object_complex_rational {
|
|
|
|
long a, b;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibf_object_symbol {
|
|
|
|
long str;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define IBF_OBJHEADER(offset) (struct ibf_object_header *)(load->buff + (offset))
|
|
|
|
#define IBF_OBJBODY(type, offset) (type *)(load->buff + sizeof(struct ibf_object_header) + (offset))
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_unsupported(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
rb_obj_info_dump(obj);
|
2015-12-09 04:34:01 +03:00
|
|
|
rb_bug("ibf_dump_object_unsupported: unsupported");
|
2015-12-08 16:58:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_unsupported(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
rb_bug("unsupported");
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_class(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
enum ibf_object_class_index cindex;
|
|
|
|
if (obj == rb_cObject) {
|
|
|
|
cindex = IBF_OBJECT_CLASS_OBJECT;
|
|
|
|
}
|
|
|
|
else if (obj == rb_cArray) {
|
|
|
|
cindex = IBF_OBJECT_CLASS_ARRAY;
|
|
|
|
}
|
|
|
|
else if (obj == rb_eStandardError) {
|
|
|
|
cindex = IBF_OBJECT_CLASS_STANDARD_ERROR;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_obj_info_dump(obj);
|
|
|
|
rb_p(obj);
|
|
|
|
rb_bug("unsupported class");
|
|
|
|
}
|
|
|
|
ibf_dump_write(dump, &cindex, sizeof(cindex));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_class(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
enum ibf_object_class_index *cindexp = IBF_OBJBODY(enum ibf_object_class_index, offset);
|
|
|
|
enum ibf_object_class_index cindex = *cindexp;
|
|
|
|
|
|
|
|
switch (cindex) {
|
|
|
|
case IBF_OBJECT_CLASS_OBJECT:
|
|
|
|
return rb_cObject;
|
|
|
|
case IBF_OBJECT_CLASS_ARRAY:
|
|
|
|
return rb_cArray;
|
|
|
|
case IBF_OBJECT_CLASS_STANDARD_ERROR:
|
|
|
|
return rb_eStandardError;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_bug("ibf_load_object_class: unknown class (%d)", (int)cindex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_float(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
double dbl = RFLOAT_VALUE(obj);
|
|
|
|
ibf_dump_write(dump, &dbl, sizeof(dbl));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_float(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
double *dblp = IBF_OBJBODY(double, offset);
|
|
|
|
return DBL2NUM(*dblp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_string(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
long encindex = (long)rb_enc_get_index(obj);
|
|
|
|
long len = RSTRING_LEN(obj);
|
|
|
|
const char *ptr = RSTRING_PTR(obj);
|
|
|
|
|
|
|
|
if (encindex > RUBY_ENCINDEX_BUILTIN_MAX) {
|
|
|
|
rb_encoding *enc = rb_enc_from_index((int)encindex);
|
|
|
|
const char *enc_name = rb_enc_name(enc);
|
|
|
|
encindex = RUBY_ENCINDEX_BUILTIN_MAX + ibf_dump_object(dump, rb_str_new2(enc_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
IBF_WV(encindex);
|
|
|
|
IBF_WV(len);
|
|
|
|
IBF_WP(ptr, char, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_string(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
const struct ibf_object_string *string = IBF_OBJBODY(struct ibf_object_string, offset);
|
|
|
|
VALUE str = rb_str_new(string->ptr, string->len);
|
|
|
|
int encindex = (int)string->encindex;
|
|
|
|
|
|
|
|
if (encindex > RUBY_ENCINDEX_BUILTIN_MAX) {
|
|
|
|
VALUE enc_name_str = ibf_load_object(load, encindex - RUBY_ENCINDEX_BUILTIN_MAX);
|
|
|
|
encindex = rb_enc_find_index(RSTRING_PTR(enc_name_str));
|
|
|
|
}
|
|
|
|
rb_enc_associate_index(str, encindex);
|
|
|
|
|
|
|
|
if (header->internal) rb_obj_hide(str);
|
2015-12-18 11:24:29 +03:00
|
|
|
if (header->frozen) str = rb_fstring(str);
|
2015-12-08 16:58:50 +03:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_regexp(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
struct ibf_object_regexp regexp;
|
|
|
|
regexp.srcstr = RREGEXP_SRC(obj);
|
|
|
|
regexp.option = (char)rb_reg_options(obj);
|
|
|
|
regexp.srcstr = (long)ibf_dump_object(dump, regexp.srcstr);
|
|
|
|
IBF_WV(regexp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_regexp(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
const struct ibf_object_regexp *regexp = IBF_OBJBODY(struct ibf_object_regexp, offset);
|
|
|
|
VALUE srcstr = ibf_load_object(load, regexp->srcstr);
|
|
|
|
VALUE reg = rb_reg_compile(srcstr, (int)regexp->option, NULL, 0);
|
|
|
|
|
|
|
|
if (header->internal) rb_obj_hide(reg);
|
|
|
|
if (header->frozen) rb_obj_freeze(reg);
|
|
|
|
|
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_array(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
long i, len = (int)RARRAY_LEN(obj);
|
|
|
|
IBF_WV(len);
|
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
long index = (long)ibf_dump_object(dump, RARRAY_AREF(obj, i));
|
|
|
|
IBF_WV(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_array(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
const struct ibf_object_array *array = IBF_OBJBODY(struct ibf_object_array, offset);
|
|
|
|
VALUE ary = rb_ary_new_capa(array->len);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<array->len; i++) {
|
|
|
|
rb_ary_push(ary, ibf_load_object(load, array->ary[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (header->internal) rb_obj_hide(ary);
|
|
|
|
if (header->frozen) rb_obj_freeze(ary);
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ibf_dump_object_hash_i(st_data_t key, st_data_t val, st_data_t ptr)
|
|
|
|
{
|
|
|
|
struct ibf_dump *dump = (struct ibf_dump *)ptr;
|
|
|
|
long key_index = (long)ibf_dump_object(dump, (VALUE)key);
|
|
|
|
long val_index = (long)ibf_dump_object(dump, (VALUE)val);
|
|
|
|
IBF_WV(key_index);
|
|
|
|
IBF_WV(val_index);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_hash(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
long len = RHASH_SIZE(obj);
|
|
|
|
IBF_WV(len);
|
|
|
|
if (len > 0) st_foreach(RHASH(obj)->ntbl, ibf_dump_object_hash_i, (st_data_t)dump);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_hash(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
const struct ibf_object_hash *hash = IBF_OBJBODY(struct ibf_object_hash, offset);
|
|
|
|
VALUE obj = rb_hash_new();
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<hash->len; i++) {
|
|
|
|
VALUE key = ibf_load_object(load, hash->keyval[i*2 ]);
|
|
|
|
VALUE val = ibf_load_object(load, hash->keyval[i*2+1]);
|
|
|
|
rb_hash_aset(obj, key, val);
|
|
|
|
}
|
2015-12-11 05:38:20 +03:00
|
|
|
rb_hash_rehash(obj);
|
2015-12-08 16:58:50 +03:00
|
|
|
|
|
|
|
if (header->internal) rb_obj_hide(obj);
|
|
|
|
if (header->frozen) rb_obj_freeze(obj);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_struct(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
if (rb_obj_is_kind_of(obj, rb_cRange)) {
|
|
|
|
struct ibf_object_struct_range range;
|
|
|
|
VALUE beg, end;
|
|
|
|
range.len = 3;
|
|
|
|
range.class_index = 0;
|
|
|
|
|
|
|
|
rb_range_values(obj, &beg, &end, &range.excl);
|
|
|
|
range.beg = (long)ibf_dump_object(dump, beg);
|
|
|
|
range.end = (long)ibf_dump_object(dump, end);
|
|
|
|
|
|
|
|
IBF_WV(range);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_bug("ibf_dump_object_struct: unsupported class");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_struct(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
const struct ibf_object_struct_range *range = IBF_OBJBODY(struct ibf_object_struct_range, offset);
|
|
|
|
VALUE beg = ibf_load_object(load, range->beg);
|
|
|
|
VALUE end = ibf_load_object(load, range->end);
|
|
|
|
VALUE obj = rb_range_new(beg, end, range->excl);
|
|
|
|
if (header->internal) rb_obj_hide(obj);
|
|
|
|
if (header->frozen) rb_obj_freeze(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_bignum(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
ssize_t len = BIGNUM_LEN(obj);
|
|
|
|
ssize_t slen = BIGNUM_SIGN(obj) > 0 ? len : len * -1;
|
|
|
|
BDIGIT *d = BIGNUM_DIGITS(obj);
|
|
|
|
|
|
|
|
IBF_WV(slen);
|
|
|
|
IBF_WP(d, BDIGIT, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_bignum(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
const struct ibf_object_bignum *bignum = IBF_OBJBODY(struct ibf_object_bignum, offset);
|
|
|
|
int sign = bignum->slen > 0;
|
|
|
|
ssize_t len = sign > 0 ? bignum->slen : -1 * bignum->slen;
|
|
|
|
VALUE obj = rb_integer_unpack(bignum->digits, len * 2, 2, 0,
|
|
|
|
INTEGER_PACK_LITTLE_ENDIAN | (sign == 0 ? INTEGER_PACK_NEGATIVE : 0));
|
|
|
|
if (header->internal) rb_obj_hide(obj);
|
|
|
|
if (header->frozen) rb_obj_freeze(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_data(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
if (rb_data_is_encoding(obj)) {
|
|
|
|
rb_encoding *enc = rb_to_encoding(obj);
|
|
|
|
const char *name = rb_enc_name(enc);
|
|
|
|
enum ibf_object_data_type type = IBF_OBJECT_DATA_ENCODING;
|
|
|
|
long len = strlen(name) + 1;
|
|
|
|
IBF_WV(type);
|
|
|
|
IBF_WV(len);
|
|
|
|
IBF_WP(name, char, strlen(name) + 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ibf_dump_object_unsupported(dump, obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_data(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
const enum ibf_object_data_type *typep = IBF_OBJBODY(enum ibf_object_data_type, offset);
|
|
|
|
/* const long *lenp = IBF_OBJBODY(long, offset + sizeof(enum ibf_object_data_type)); */
|
|
|
|
const char *data = IBF_OBJBODY(char, offset + sizeof(enum ibf_object_data_type) + sizeof(long));
|
|
|
|
|
|
|
|
switch (*typep) {
|
|
|
|
case IBF_OBJECT_DATA_ENCODING:
|
|
|
|
{
|
|
|
|
VALUE encobj = rb_enc_from_encoding(rb_enc_find(data));
|
|
|
|
return encobj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ibf_load_object_unsupported(load, header, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_complex_rational(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
long real = (long)ibf_dump_object(dump, RCOMPLEX(obj)->real);
|
|
|
|
long imag = (long)ibf_dump_object(dump, RCOMPLEX(obj)->imag);
|
|
|
|
|
|
|
|
IBF_WV(real);
|
|
|
|
IBF_WV(imag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_complex_rational(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
const struct ibf_object_complex_rational *nums = IBF_OBJBODY(struct ibf_object_complex_rational, offset);
|
|
|
|
VALUE a = ibf_load_object(load, nums->a);
|
|
|
|
VALUE b = ibf_load_object(load, nums->b);
|
|
|
|
VALUE obj = header->type == T_COMPLEX ?
|
|
|
|
rb_complex_new(a, b) : rb_rational_new(a, b);
|
|
|
|
|
|
|
|
if (header->internal) rb_obj_hide(obj);
|
|
|
|
if (header->frozen) rb_obj_freeze(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_symbol(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
VALUE str = rb_sym2str(obj);
|
|
|
|
long str_index = (long)ibf_dump_object(dump, str);
|
|
|
|
IBF_WV(str_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object_symbol(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset)
|
|
|
|
{
|
|
|
|
/* const struct ibf_object_header *header = IBF_OBJHEADER(offset); */
|
|
|
|
const struct ibf_object_symbol *symbol = IBF_OBJBODY(struct ibf_object_symbol, offset);
|
|
|
|
VALUE str = ibf_load_object(load, symbol->str);
|
|
|
|
ID id = rb_intern_str(str);
|
|
|
|
return ID2SYM(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (*ibf_dump_object_function)(struct ibf_dump *dump, VALUE obj);
|
|
|
|
static ibf_dump_object_function dump_object_functions[RUBY_T_MASK+1] = {
|
|
|
|
ibf_dump_object_unsupported, /* T_NONE */
|
|
|
|
ibf_dump_object_unsupported, /* T_OBJECT */
|
|
|
|
ibf_dump_object_class, /* T_CLASS */
|
|
|
|
ibf_dump_object_unsupported, /* T_MODULE */
|
|
|
|
ibf_dump_object_float, /* T_FLOAT */
|
|
|
|
ibf_dump_object_string, /* T_STRING */
|
|
|
|
ibf_dump_object_regexp, /* T_REGEXP */
|
|
|
|
ibf_dump_object_array, /* T_ARRAY */
|
|
|
|
ibf_dump_object_hash, /* T_HASH */
|
|
|
|
ibf_dump_object_struct, /* T_STRUCT */
|
|
|
|
ibf_dump_object_bignum, /* T_BIGNUM */
|
|
|
|
ibf_dump_object_unsupported, /* T_FILE */
|
|
|
|
ibf_dump_object_data, /* T_DATA */
|
|
|
|
ibf_dump_object_unsupported, /* T_MATCH */
|
|
|
|
ibf_dump_object_complex_rational, /* T_COMPLEX */
|
|
|
|
ibf_dump_object_complex_rational, /* T_RATIONAL */
|
|
|
|
ibf_dump_object_unsupported, /* 0x10 */
|
|
|
|
ibf_dump_object_unsupported, /* 0x11 T_NIL */
|
|
|
|
ibf_dump_object_unsupported, /* 0x12 T_TRUE */
|
|
|
|
ibf_dump_object_unsupported, /* 0x13 T_FALSE */
|
|
|
|
ibf_dump_object_symbol, /* 0x14 T_SYMBOL */
|
|
|
|
ibf_dump_object_unsupported, /* T_FIXNUM */
|
|
|
|
ibf_dump_object_unsupported, /* T_UNDEF */
|
|
|
|
ibf_dump_object_unsupported, /* 0x17 */
|
|
|
|
ibf_dump_object_unsupported, /* 0x18 */
|
|
|
|
ibf_dump_object_unsupported, /* 0x19 */
|
|
|
|
ibf_dump_object_unsupported, /* T_IMEMO 0x1a */
|
|
|
|
ibf_dump_object_unsupported, /* T_NODE 0x1b */
|
|
|
|
ibf_dump_object_unsupported, /* T_ICLASS 0x1c */
|
|
|
|
ibf_dump_object_unsupported, /* T_ZOMBIE 0x1d */
|
|
|
|
ibf_dump_object_unsupported, /* 0x1e */
|
|
|
|
ibf_dump_object_unsupported /* 0x1f */
|
|
|
|
};
|
|
|
|
|
|
|
|
static ibf_offset_t
|
|
|
|
lbf_dump_object_object(struct ibf_dump *dump, VALUE obj)
|
|
|
|
{
|
|
|
|
struct ibf_object_header obj_header;
|
|
|
|
ibf_offset_t current_offset = ibf_dump_pos(dump);
|
|
|
|
obj_header.type = TYPE(obj);
|
|
|
|
|
|
|
|
if (SPECIAL_CONST_P(obj)) {
|
|
|
|
if (RB_TYPE_P(obj, T_SYMBOL) ||
|
|
|
|
RB_TYPE_P(obj, T_FLOAT)) {
|
|
|
|
obj_header.internal = FALSE;
|
|
|
|
goto dump_object;
|
|
|
|
}
|
|
|
|
obj_header.special_const = TRUE;
|
|
|
|
obj_header.frozen = TRUE;
|
|
|
|
obj_header.internal = TRUE;
|
|
|
|
IBF_WV(obj_header);
|
|
|
|
IBF_WV(obj);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
obj_header.internal = (RBASIC_CLASS(obj) == 0) ? TRUE : FALSE;
|
|
|
|
dump_object:
|
|
|
|
obj_header.special_const = FALSE;
|
|
|
|
obj_header.frozen = FL_TEST(obj, FL_FREEZE) ? TRUE : FALSE;
|
|
|
|
IBF_WV(obj_header);
|
|
|
|
(*dump_object_functions[obj_header.type])(dump, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return current_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef VALUE (*ibf_load_object_function)(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t);
|
|
|
|
static ibf_load_object_function load_object_functions[RUBY_T_MASK+1] = {
|
|
|
|
ibf_load_object_unsupported, /* T_NONE */
|
|
|
|
ibf_load_object_unsupported, /* T_OBJECT */
|
|
|
|
ibf_load_object_class, /* T_CLASS */
|
|
|
|
ibf_load_object_unsupported, /* T_MODULE */
|
|
|
|
ibf_load_object_float, /* T_FLOAT */
|
|
|
|
ibf_load_object_string, /* T_STRING */
|
|
|
|
ibf_load_object_regexp, /* T_REGEXP */
|
|
|
|
ibf_load_object_array, /* T_ARRAY */
|
|
|
|
ibf_load_object_hash, /* T_HASH */
|
|
|
|
ibf_load_object_struct, /* T_STRUCT */
|
|
|
|
ibf_load_object_bignum, /* T_BIGNUM */
|
|
|
|
ibf_load_object_unsupported, /* T_FILE */
|
|
|
|
ibf_load_object_data, /* T_DATA */
|
|
|
|
ibf_load_object_unsupported, /* T_MATCH */
|
|
|
|
ibf_load_object_complex_rational, /* T_COMPLEX */
|
|
|
|
ibf_load_object_complex_rational, /* T_RATIONAL */
|
|
|
|
ibf_load_object_unsupported, /* 0x10 */
|
|
|
|
ibf_load_object_unsupported, /* T_NIL */
|
|
|
|
ibf_load_object_unsupported, /* T_TRUE */
|
|
|
|
ibf_load_object_unsupported, /* T_FALSE */
|
|
|
|
ibf_load_object_symbol,
|
|
|
|
ibf_load_object_unsupported, /* T_FIXNUM */
|
|
|
|
ibf_load_object_unsupported, /* T_UNDEF */
|
|
|
|
ibf_load_object_unsupported, /* 0x17 */
|
|
|
|
ibf_load_object_unsupported, /* 0x18 */
|
|
|
|
ibf_load_object_unsupported, /* 0x19 */
|
|
|
|
ibf_load_object_unsupported, /* T_IMEMO 0x1a */
|
|
|
|
ibf_load_object_unsupported, /* T_NODE 0x1b */
|
|
|
|
ibf_load_object_unsupported, /* T_ICLASS 0x1c */
|
|
|
|
ibf_load_object_unsupported, /* T_ZOMBIE 0x1d */
|
|
|
|
ibf_load_object_unsupported, /* 0x1e */
|
|
|
|
ibf_load_object_unsupported /* 0x1f */
|
|
|
|
};
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ibf_load_object(const struct ibf_load *load, VALUE object_index)
|
|
|
|
{
|
|
|
|
if (object_index == 0) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
2015-12-08 17:33:11 +03:00
|
|
|
else if (object_index >= load->header->object_list_size) {
|
|
|
|
rb_raise(rb_eIndexError, "object index out of range: %"PRIdVALUE, object_index);
|
|
|
|
}
|
2015-12-08 16:58:50 +03:00
|
|
|
else {
|
|
|
|
VALUE obj = rb_ary_entry(load->obj_list, (long)object_index);
|
|
|
|
if (obj == Qnil) { /* TODO: avoid multiple Qnil load */
|
|
|
|
ibf_offset_t *offsets = (ibf_offset_t *)(load->header->object_list_offset + load->buff);
|
|
|
|
ibf_offset_t offset = offsets[object_index];
|
|
|
|
const struct ibf_object_header *header = IBF_OBJHEADER(offset);
|
|
|
|
|
|
|
|
if (header->special_const) {
|
|
|
|
VALUE *vp = IBF_OBJBODY(VALUE, offset);
|
|
|
|
obj = *vp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
obj = (*load_object_functions[header->type])(load, header, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_ary_store(load->obj_list, (long)object_index, obj);
|
|
|
|
}
|
|
|
|
iseq_add_mark_object(load->iseq, obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_object_list(struct ibf_dump *dump, struct ibf_header *header)
|
|
|
|
{
|
|
|
|
VALUE list = rb_ary_tmp_new(RARRAY_LEN(dump->obj_list));
|
|
|
|
int i, size;
|
|
|
|
|
|
|
|
for (i=0; i<RARRAY_LEN(dump->obj_list); i++) {
|
|
|
|
VALUE obj = RARRAY_AREF(dump->obj_list, i);
|
|
|
|
ibf_offset_t offset = lbf_dump_object_object(dump, obj);
|
|
|
|
rb_ary_push(list, UINT2NUM(offset));
|
|
|
|
}
|
|
|
|
size = i;
|
|
|
|
header->object_list_offset = ibf_dump_pos(dump);
|
|
|
|
|
|
|
|
for (i=0; i<size; i++) {
|
|
|
|
ibf_offset_t offset = NUM2UINT(RARRAY_AREF(list, i));
|
|
|
|
IBF_WV(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
header->object_list_size = size;
|
|
|
|
}
|
|
|
|
|
2015-12-08 17:50:55 +03:00
|
|
|
static void
|
|
|
|
ibf_dump_mark(void *ptr)
|
|
|
|
{
|
|
|
|
struct ibf_dump *dump = (struct ibf_dump *)ptr;
|
|
|
|
rb_gc_mark(dump->str);
|
|
|
|
rb_gc_mark(dump->iseq_list);
|
|
|
|
rb_gc_mark(dump->obj_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_dump_free(void *ptr)
|
|
|
|
{
|
|
|
|
struct ibf_dump *dump = (struct ibf_dump *)ptr;
|
|
|
|
if (dump->iseq_table) {
|
|
|
|
st_free_table(dump->iseq_table);
|
|
|
|
dump->iseq_table = 0;
|
|
|
|
}
|
|
|
|
if (dump->id_table) {
|
|
|
|
st_free_table(dump->id_table);
|
|
|
|
dump->id_table = 0;
|
|
|
|
}
|
|
|
|
ruby_xfree(dump);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
ibf_dump_memsize(const void *ptr)
|
2015-12-08 16:58:50 +03:00
|
|
|
{
|
2015-12-09 03:38:32 +03:00
|
|
|
struct ibf_dump *dump = (struct ibf_dump *)ptr;
|
|
|
|
size_t size = sizeof(*dump);
|
|
|
|
if (dump->iseq_table) size += st_memsize(dump->iseq_table);
|
|
|
|
if (dump->id_table) size += st_memsize(dump->id_table);
|
|
|
|
return size;
|
2015-12-08 17:50:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_data_type_t ibf_dump_type = {
|
|
|
|
"ibf_dump",
|
|
|
|
{ibf_dump_mark, ibf_dump_free, ibf_dump_memsize,},
|
|
|
|
0, 0, RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
|
|
|
|
};
|
2015-12-08 16:58:50 +03:00
|
|
|
|
2015-12-08 17:50:55 +03:00
|
|
|
static void
|
|
|
|
ibf_dump_setup(struct ibf_dump *dump, VALUE dumper_obj)
|
|
|
|
{
|
|
|
|
RB_OBJ_WRITE(dumper_obj, &dump->str, rb_str_new(0, 0));
|
|
|
|
RB_OBJ_WRITE(dumper_obj, &dump->iseq_list, rb_ary_tmp_new(0));
|
|
|
|
RB_OBJ_WRITE(dumper_obj, &dump->obj_list, rb_ary_tmp_new(1));
|
|
|
|
rb_ary_push(dump->obj_list, Qnil); /* 0th is nil */
|
|
|
|
dump->iseq_table = st_init_numtable(); /* need free */
|
|
|
|
dump->id_table = st_init_numtable(); /* need free */
|
2015-12-08 16:58:50 +03:00
|
|
|
|
2015-12-08 17:50:55 +03:00
|
|
|
ibf_table_index(dump->id_table, 0); /* id_index:0 is 0 */
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt)
|
|
|
|
{
|
|
|
|
struct ibf_dump *dump;
|
|
|
|
struct ibf_header header = {{0}};
|
|
|
|
VALUE dump_obj;
|
|
|
|
VALUE str;
|
2015-12-08 16:58:50 +03:00
|
|
|
|
|
|
|
if (iseq->body->parent_iseq != NULL ||
|
|
|
|
iseq->body->local_iseq != iseq) {
|
|
|
|
rb_raise(rb_eRuntimeError, "should be top of iseq");
|
|
|
|
}
|
|
|
|
if (RTEST(ISEQ_COVERAGE(iseq))) {
|
|
|
|
rb_raise(rb_eRuntimeError, "should not compile with coverage");
|
|
|
|
}
|
|
|
|
|
2015-12-08 17:50:55 +03:00
|
|
|
dump_obj = TypedData_Make_Struct(0, struct ibf_dump, &ibf_dump_type, dump);
|
|
|
|
ibf_dump_setup(dump, dump_obj);
|
|
|
|
|
|
|
|
ibf_dump_write(dump, &header, sizeof(header));
|
|
|
|
ibf_dump_write(dump, RUBY_PLATFORM, strlen(RUBY_PLATFORM) + 1);
|
|
|
|
ibf_dump_iseq(dump, iseq);
|
2015-12-08 16:58:50 +03:00
|
|
|
|
|
|
|
header.magic[0] = 'Y'; /* YARB */
|
|
|
|
header.magic[1] = 'A';
|
|
|
|
header.magic[2] = 'R';
|
|
|
|
header.magic[3] = 'B';
|
|
|
|
header.major_version = ISEQ_MAJOR_VERSION;
|
|
|
|
header.minor_version = ISEQ_MINOR_VERSION;
|
2015-12-08 17:50:55 +03:00
|
|
|
ibf_dump_iseq_list(dump, &header);
|
|
|
|
ibf_dump_id_list(dump, &header);
|
|
|
|
ibf_dump_object_list(dump, &header);
|
|
|
|
header.size = ibf_dump_pos(dump);
|
2015-12-08 16:58:50 +03:00
|
|
|
|
|
|
|
if (RTEST(opt)) {
|
2015-12-08 17:47:38 +03:00
|
|
|
VALUE opt_str = opt;
|
|
|
|
const char *ptr = StringValuePtr(opt_str);
|
2015-12-08 18:30:46 +03:00
|
|
|
header.extra_size = RSTRING_LENINT(opt_str);
|
2015-12-08 17:50:55 +03:00
|
|
|
ibf_dump_write(dump, ptr, header.extra_size);
|
2015-12-08 16:58:50 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
header.extra_size = 0;
|
|
|
|
}
|
|
|
|
|
2015-12-08 17:50:55 +03:00
|
|
|
ibf_dump_overwrite(dump, &header, sizeof(header), 0);
|
2015-12-08 16:58:50 +03:00
|
|
|
|
2015-12-08 17:50:55 +03:00
|
|
|
str = dump->str;
|
|
|
|
ibf_dump_free(dump);
|
|
|
|
DATA_PTR(dump_obj) = NULL;
|
|
|
|
RB_GC_GUARD(dump_obj);
|
|
|
|
return str;
|
2015-12-08 16:58:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const ibf_offset_t *
|
|
|
|
ibf_iseq_list(const struct ibf_load *load)
|
|
|
|
{
|
|
|
|
return (ibf_offset_t *)(load->buff + load->header->iseq_list_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ibf_load_iseq_complete(rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
struct ibf_load *load = RTYPEDDATA_DATA(iseq->aux.loader.obj);
|
|
|
|
rb_iseq_t *prev_src_iseq = load->iseq;
|
|
|
|
load->iseq = iseq;
|
|
|
|
ibf_load_iseq_each(load, iseq, ibf_iseq_list(load)[iseq->aux.loader.index]);
|
|
|
|
ISEQ_COMPILE_DATA(iseq) = NULL;
|
|
|
|
FL_UNSET(iseq, ISEQ_NOT_LOADED_YET);
|
|
|
|
load->iseq = prev_src_iseq;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_LAZY_LOAD
|
|
|
|
const rb_iseq_t *
|
|
|
|
rb_iseq_complete(const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
ibf_load_iseq_complete((rb_iseq_t *)iseq);
|
|
|
|
return iseq;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static rb_iseq_t *
|
|
|
|
ibf_load_iseq(const struct ibf_load *load, const rb_iseq_t *index_iseq)
|
|
|
|
{
|
|
|
|
int iseq_index = (int)(VALUE)index_iseq;
|
|
|
|
|
|
|
|
if (iseq_index == -1) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE iseqv = rb_ary_entry(load->iseq_list, iseq_index);
|
|
|
|
|
|
|
|
if (iseqv != Qnil) {
|
|
|
|
return (rb_iseq_t *)iseqv;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_iseq_t *iseq = iseq_imemo_alloc();
|
|
|
|
FL_SET(iseq, ISEQ_NOT_LOADED_YET);
|
|
|
|
iseq->aux.loader.obj = load->loader_obj;
|
|
|
|
iseq->aux.loader.index = iseq_index;
|
|
|
|
rb_ary_store(load->iseq_list, iseq_index, (VALUE)iseq);
|
|
|
|
|
|
|
|
#if !USE_LAZY_LOAD
|
|
|
|
ibf_load_iseq_complete(iseq);
|
|
|
|
#endif /* !USE_LAZY_LOAD */
|
|
|
|
|
|
|
|
if (load->iseq) {
|
|
|
|
iseq_add_mark_object(load->iseq, (VALUE)iseq);
|
|
|
|
}
|
|
|
|
return iseq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-08 18:14:55 +03:00
|
|
|
ibf_load_setup(struct ibf_load *load, VALUE loader_obj, VALUE str)
|
2015-12-08 16:58:50 +03:00
|
|
|
{
|
2015-12-18 10:51:58 +03:00
|
|
|
rb_check_safe_obj(str);
|
|
|
|
|
2015-12-08 18:18:30 +03:00
|
|
|
if (RSTRING_LENINT(str) < (int)sizeof(struct ibf_header)) {
|
2015-12-08 18:14:55 +03:00
|
|
|
rb_raise(rb_eRuntimeError, "broken binary format");
|
|
|
|
}
|
2015-12-08 16:58:50 +03:00
|
|
|
RB_OBJ_WRITE(loader_obj, &load->str, str);
|
|
|
|
load->loader_obj = loader_obj;
|
|
|
|
load->buff = StringValuePtr(str);
|
|
|
|
load->header = (struct ibf_header *)load->buff;
|
|
|
|
RB_OBJ_WRITE(loader_obj, &load->iseq_list, rb_ary_tmp_new(0));
|
|
|
|
RB_OBJ_WRITE(loader_obj, &load->obj_list, rb_ary_tmp_new(0));
|
|
|
|
load->id_list = ZALLOC_N(ID, load->header->id_list_size);
|
|
|
|
load->iseq = NULL;
|
2015-12-08 18:14:55 +03:00
|
|
|
|
|
|
|
if (RSTRING_LENINT(str) < (int)load->header->size) {
|
|
|
|
rb_raise(rb_eRuntimeError, "broken binary format");
|
|
|
|
}
|
|
|
|
if (strncmp(load->header->magic, "YARB", 4) != 0) {
|
2015-12-25 02:23:46 +03:00
|
|
|
rb_raise(rb_eRuntimeError, "unknown binary format");
|
2015-12-08 18:14:55 +03:00
|
|
|
}
|
|
|
|
if (load->header->major_version != ISEQ_MAJOR_VERSION ||
|
|
|
|
load->header->minor_version != ISEQ_MINOR_VERSION) {
|
|
|
|
rb_raise(rb_eRuntimeError, "unmatched version file (%u.%u for %u.%u)",
|
|
|
|
load->header->major_version, load->header->minor_version, ISEQ_MAJOR_VERSION, ISEQ_MINOR_VERSION);
|
|
|
|
}
|
|
|
|
if (strcmp(load->buff + sizeof(struct ibf_header), RUBY_PLATFORM) != 0) {
|
|
|
|
rb_raise(rb_eRuntimeError, "unmatched platform");
|
|
|
|
}
|
2015-12-08 16:58:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_loader_mark(void *ptr)
|
|
|
|
{
|
|
|
|
if (ptr) {
|
|
|
|
struct ibf_load *load = (struct ibf_load *)ptr;
|
|
|
|
rb_gc_mark(load->str);
|
|
|
|
rb_gc_mark(load->iseq_list);
|
|
|
|
rb_gc_mark(load->obj_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ibf_loader_free(void *ptr)
|
|
|
|
{
|
|
|
|
if (ptr) {
|
|
|
|
struct ibf_load *load = (struct ibf_load *)ptr;
|
|
|
|
ruby_xfree(load->id_list);
|
|
|
|
ruby_xfree(load);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
ibf_loader_memsize(const void *ptr)
|
|
|
|
{
|
2015-12-09 03:38:32 +03:00
|
|
|
struct ibf_load *load = (struct ibf_load *)ptr;
|
|
|
|
return sizeof(struct ibf_load) + load->header->id_list_size * sizeof(ID);
|
2015-12-08 16:58:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_data_type_t ibf_load_type = {
|
|
|
|
"ibf_loader",
|
|
|
|
{ibf_loader_mark, ibf_loader_free, ibf_loader_memsize,},
|
|
|
|
0, 0, RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
|
|
|
|
};
|
|
|
|
|
|
|
|
const rb_iseq_t *
|
|
|
|
iseq_ibf_load(VALUE str)
|
|
|
|
{
|
|
|
|
struct ibf_load *load;
|
|
|
|
const rb_iseq_t *iseq;
|
|
|
|
VALUE loader_obj = TypedData_Make_Struct(0, struct ibf_load, &ibf_load_type, load);
|
|
|
|
|
2015-12-08 18:14:55 +03:00
|
|
|
ibf_load_setup(load, loader_obj, str);
|
2015-12-08 16:58:50 +03:00
|
|
|
iseq = ibf_load_iseq(load, 0);
|
|
|
|
|
|
|
|
RB_GC_GUARD(loader_obj);
|
|
|
|
return iseq;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
iseq_ibf_load_extra_data(VALUE str)
|
|
|
|
{
|
|
|
|
struct ibf_load *load;
|
|
|
|
VALUE loader_obj = TypedData_Make_Struct(0, struct ibf_load, &ibf_load_type, load);
|
|
|
|
VALUE extra_str;
|
|
|
|
|
2015-12-08 18:14:55 +03:00
|
|
|
ibf_load_setup(load, loader_obj, str);
|
2015-12-08 18:26:58 +03:00
|
|
|
extra_str = rb_str_new(load->buff + load->header->size, load->header->extra_size);
|
2015-12-08 16:58:50 +03:00
|
|
|
RB_GC_GUARD(loader_obj);
|
|
|
|
return extra_str;
|
|
|
|
}
|