~tim/scheme-vm

ref: 04d738c7bb4afd67aef3edb2df04d940a20af0c4 scheme-vm/parser.rb -rw-r--r-- 808 bytes
04d738c7Tim Morgan Switch back to rust-peg and speed it up! 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'fiddle'
require_relative 'vm/atom'
require 'pathname'

class Parser
  class ParseError < StandardError
    attr_reader :line

    def initialize(line)
      @line = line
    end

    def message
      "error parsing at line #{line}"
    end
  end

  def initialize(code = nil, filename: nil)
    @code = code
    @filename = filename || ''
  end

  def parse
    parse_native
  end
end

LIB_PATHS = %w[
  target/release/libscheme_vm.so
  target/debug/libscheme_vm.so
  target/release/libscheme_vm.dylib
  target/debug/libscheme_vm.dylib
]

root = Pathname.new(File.expand_path('../', __FILE__))
library_path = LIB_PATHS.detect { |path| root.join(path).exist? }
library = Fiddle::dlopen(library_path)
init_parser = Fiddle::Function.new(library['init_parser'], [], Fiddle::TYPE_VOID)
init_parser.call