~tim/scheme-vm

4d798bd36115e84606e13d1d33db44ca8a0ee20b — Tim Morgan 2 years ago fd1db0d
Some small fixes to loading/including libraries
5 files changed, 9 insertions(+), 7 deletions(-)

M compiler.rb
M compiler/libraries.rb
M spec/compiler_spec.rb
M spec/lib/import-spec.scm
M spec/program_spec.rb
M compiler.rb => compiler.rb +1 -1
@@ 10,7 10,7 @@ require 'pry'

class Compiler
  ROOT_PATH = VM::ROOT_PATH
  LOAD_PATH = [File.join(ROOT_PATH, 'lib'), File.join(ROOT_PATH, 'spec')].freeze
  LOAD_PATH = [File.join(ROOT_PATH, 'lib')].freeze

  include Compiler::Libraries
  include Compiler::Lib::Scheme::Base

M compiler/libraries.rb => compiler/libraries.rb +2 -2
@@ 15,7 15,7 @@ class Compiler
    def do_include(paths, relative_to, options)
      paths.map do |path|
        raise "include expects a string, but got #{path.inspect}" unless path =~ /\A"(.+)?"\z/
        filename = "#{$1}.scm"
        filename = $1
        sexps = parse_file(filename, relative_to: relative_to)
        compile_sexps(sexps, options: options)
      end


@@ 95,7 95,7 @@ class Compiler

    def include_library_if_needed(name, relative_to, options)
      return [] if @libs.key?(name)
      do_include(["\"#{name}\""], relative_to, options)
      do_include(["\"#{name}.scm\""], relative_to, options)
    end

    def do_define_library((name, *declarations), options)

M spec/compiler_spec.rb => spec/compiler_spec.rb +3 -3
@@ 348,7 348,7 @@ describe Compiler do
    context 'variable out of scope' do
      let(:erroring_ast) do
        [
          [VM::Atom.new('include', __FILE__), '"./fixtures/library-test"'],
          [VM::Atom.new('include', __FILE__), '"./fixtures/library-test.scm"'],
          ['lambda', [],
            'n'],
          ['define', 'n', '10']


@@ 1129,7 1129,7 @@ describe Compiler do
        let(:ast) do
          [
            [VM::Atom.new('import', filename: ''), ['scheme', 'base']],
            [VM::Atom.new('include', __FILE__), '"./fixtures/include-test"'],
            [VM::Atom.new('include', __FILE__), '"./fixtures/include-test.scm"'],
            '"hello from main"'
          ]
        end


@@ 1153,7 1153,7 @@ describe Compiler do
      context 'given a path to a library' do
        let(:erroring_ast) do
          [
            [VM::Atom.new('include', __FILE__), '"./fixtures/library-test"'],
            [VM::Atom.new('include', __FILE__), '"./fixtures/library-test.scm"'],
            ['macro']
          ]
        end

M spec/lib/import-spec.scm => spec/lib/import-spec.scm +2 -0
@@ 1,6 1,8 @@
(import (scheme base)
        (assert))

(include "../fixtures/library-test.scm")

; import all
(begin
  (import (fixtures library-test))

M spec/program_spec.rb => spec/program_spec.rb +1 -1
@@ 256,7 256,7 @@ describe Program do

    context 'exception in macro in another file' do
      let(:code) do
        '(include "./fixtures/bad-macro") ' \
        '(include "./fixtures/bad-macro.scm") ' \
        '(bad-macro)'
      end