From: dale.hamel@... Date: 2019-08-16T12:36:08+00:00 Subject: [ruby-core:94384] [Ruby master Feature#12093] Eval InstructionSequence with binding Issue #12093 has been updated by dalehamel (Dale Hamel). Yes when I test out Koichi's sample, the iseq look like: ``` disasm: #@:1 (1,0)-(1,6)> (catch: FALSE) 0000 putself ( 1)[Li] 0001 opt_send_without_block , 0004 putself 0005 opt_send_without_block , 0008 newarray 2 0010 leave ``` So there is no way for the local variables from the binding to be evaluated, as the original instruction sequence expects a method call. I hadn't realized that when compiling the iseq string, methods calls are found in this way. This indicates that yeah, Nobu's comment above appears correct, you must have the binding available when the iseq is compiled. It appears to do so implicitly based on the current binding. ---------------------------------------- Feature #12093: Eval InstructionSequence with binding https://bugs.ruby-lang.org/issues/12093#change-80799 * Author: pavel.evstigneev (Pavel Evstigneev) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Implementing this feature can boost template engine performance Currently Kernel#eval can accept binding argument, so code running with eval will have access to local variables and current instance. This feature used by template languages ERB: https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L887 Erubis: Can't find code on github, but it uses instance_eval or Kernel#eval Haml: https://github.com/haml/haml/blob/master/lib/haml/engine.rb#L115 My proposal is to make RubyVM::InstructionSequence#eval to recieve binding argument. So it can be used for caching templates. As I see from ERB and Haml, cached template is stored as ruby code string, every time when we render template that string (ruby code) is evaluated, internally ruby will parse it into RubyVM::InstructionSequence and then evaluate. Before I try to implement it myself in ruby, but could not. Lack of experience with C https://github.com/Paxa/ruby/commit/f5b602b6d9eada9675a4c002c9a5a79129df73a6 (not working) ---Files-------------------------------- 0002-Update-iseq.eval-to-accept-optional-binding-FIXES-Bu.patch (4.83 KB) 0001-RubyVM-InstructionSequence-eval_with.patch (2.91 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: