Sha256: cf9a079610be725f5584695aeb1977eb5168b7438a0062bb9d0daca58880fcde

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require: "compiler"

def Fancy eval: code binding: binding (nil) file: file ("(fancy-eval)") line: line (1) {
  """
  @code @String@ of Fancy code to be evaluated.
  @binding @Binding@ to evaluate @code in.
  @file @String that is the name of @File@ from which @code is evaluated from (if any).
  @line Starting line, defaults to 1.
  """

  binding if_nil: {
    binding = Binding setup(Rubinius VariableScope of_sender(),
                        Rubinius CompiledMethod of_sender(),
                        Rubinius StaticScope of_sender())
  }

  # The compiled method
  cm = Fancy Compiler compile_code: code vars: (binding variables()) file: file line: line

  # Binding#static_scope was renamed to Binding#constant_scope a while ago.
  # if the new version fails, retry with the old name for backwards compatibility (for now).
  try {
    cm scope=(binding constant_scope() dup())
  } catch NoMethodError {
    cm scope=(binding static_scope() dup())
  }
  cm name=('__fancy_eval__)

  script = Rubinius CompiledMethod Script new(cm, file, true)
  script eval_binding=(binding)
  script eval_source=(code)

  cm scope() script=(script)

  be = Rubinius BlockEnvironment new()
  be under_context(binding variables(), cm)

  if: (binding from_proc?()) then: {
    be proc_environment=(binding proc_environment)
  }

  be from_eval!()

  be call()
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fancy-0.8.0 lib/eval.fy