From 31416423809f64d4b5ea6b9651cced3179cc5ced Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Mon, 11 Nov 2019 16:38:46 +0900 Subject: __builtin_inline! Add an experimental `__builtin_inline!(c_expression)` special intrinsic which run a C code snippet. In `c_expression`, you can access the following variables: * ec (rb_execution_context_t *) * self (const VALUE) * local variables (const VALUE) Not that you can read these variables, but you can not write them. You need to return from this expression and return value will be a result of __builtin_inline!(). Examples: `def foo(x) __builtin_inline!('return rb_p(x);'); end` calls `p(x)`. `def double(x) __builtin_inline!('return INT2NUM(NUM2INT(x) * 2);')` returns x*2. --- builtin.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'builtin.h') diff --git a/builtin.h b/builtin.h index ee99e21dcc..236dfd961c 100644 --- a/builtin.h +++ b/builtin.h @@ -43,6 +43,19 @@ static inline void rb_builtin_function_check_arity13(VALUE (*f)(rb_execution_con static inline void rb_builtin_function_check_arity14(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){} static inline void rb_builtin_function_check_arity15(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){} +VALUE rb_vm_lvar_exposed(rb_execution_context_t *ec, int index); + +// inline +inline VALUE +rb_vm_lvar(rb_execution_context_t *ec, int index) +{ +#if VM_CORE_H_EC_DEFINED + return ec->cfp->ep[index]; +#else + return rb_vm_lvar_exposed(ec, index); +#endif +} + // dump/load struct builtin_binary { -- cgit v1.2.1