Class: Peruby::Op::Eval
Overview
Block and string eval sharing the current lexical environment.
Instance Method Summary collapse
-
#initialize(body, string, file: '-e') ⇒ Eval
constructor
A new instance of Eval.
- #run(env, context) ⇒ Object
Methods inherited from Base
#argument_cells, #local_slot, #lvalue, #run_subroutine, #to_callable, #warning_directive?
Constructor Details
#initialize(body, string, file: '-e') ⇒ Eval
Returns a new instance of Eval.
229 230 231 232 233 |
# File 'lib/peruby/op/control.rb', line 229 def initialize(body, string, file: '-e') @body = body @string = string @file = file end |
Instance Method Details
#run(env, context) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/peruby/op/control.rb', line 235 def run(env, context) env.fetch(:scalar, '@').set('') result = if @string env.with_scope do source = Conv.to_str(@body.run(env, :scalar)) operation = CompileUnit.new(runtime: env.runtime, file: @file).compile(source, env:) operation.run_subroutine(env, context) end else @body.run_subroutine(env, context) end env.fetch(:scalar, '@').set('') result rescue Error => e value = e.is_a?(PerlError) ? e.value : e. value = env.runtime.(value) unless value.is_a?(Ref) env.fetch(:scalar, '@').set(value) context == :list ? [] : nil end |