class YAMLScript

Ruby binding for the libys shared library.

def self.load(ys_code, **options)

YAMLScript.load(IO.read('file.ys'))

require 'yamlscript'
@example

Interface with the libys shared library.
def self.load(ys_code, **options)
  new(**options).load(ys_code)
end

def initialize(**options)

def initialize(**options)
  # config not used yet
  @options = options
  # Create a new GraalVM isolate for life of the YAMLScript instance
  @isolate = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
  @error = nil
end

def load(ys_code)

Compile and eval a YAMLScript string and return the result
def load(ys_code)
  # Create a new GraalVM isolate thread for each call to load()
  thread = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
  raise Error, "Failed to create isolate" unless \
    LibYS.graal_create_isolate(nil, @isolate.ref, thread.ref).zero?
  # Call 'load_ys_to_json' function in libys shared library
  json_data = LibYS.load_ys_to_json(thread, ys_code)
  resp = JSON.parse(json_data.to_s)
  raise Error, "Failed to tear down isolate" unless \
    LibYS.graal_tear_down_isolate(thread).zero?
  raise Error, @error['cause'] if @error = resp['error']
  data = resp.fetch('data') do
    raise Error, "Unexpected response from 'libys'"
  end
  data
end