Sha256: 086f6188cc205bbf8892807279b7955c8a6803bb12e785175577974d75cadac7

Contents?: true

Size: 650 Bytes

Versions: 7

Compression:

Stored size: 650 Bytes

Contents

require "nydp/vm"

class Nydp::Builtin::Ensuring
  include Nydp::Helper, Nydp::Builtin::Base, Singleton

  class InvokeProtection
    include Nydp::VM::Finally
    attr_reader :protection

    def initialize protection
      @protection = protection
    end

    def execute vm
      protection.invoke vm, Nydp::NIL
    end
  end

  def builtin_invoke vm, args
    fn_ensure = args.car
    fn_tricky = args.cdr.car

    protection_instructions = Nydp::Pair.from_list [InvokeProtection.new(fn_ensure), Nydp::PopArg]
    vm.instructions.push protection_instructions
    vm.contexts.push vm.current_context

    fn_tricky.invoke vm, Nydp::NIL
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nydp-0.3.0 lib/nydp/builtin/ensuring.rb
nydp-0.2.6 lib/nydp/builtin/ensuring.rb
nydp-0.2.5 lib/nydp/builtin/ensuring.rb
nydp-0.2.3 lib/nydp/builtin/ensuring.rb
nydp-0.2.2 lib/nydp/builtin/ensuring.rb
nydp-0.2.1 lib/nydp/builtin/ensuring.rb
nydp-0.2.0 lib/nydp/builtin/ensuring.rb