~tim/scheme-vm

6d93e73fbdf02167c6cf4e5c76a2055191a3fd98 — Tim Morgan 3 years ago 50f0ca9
Get rid of unneeded keep_last option

`keep_last: true` was only being used by specs, and `(exit)`
already accomplishes the same effect, leaving the stack intact for
inspection.
2 files changed, 8 insertions(+), 8 deletions(-)

M compiler.rb
M spec/vm_spec.rb
M compiler.rb => compiler.rb +4 -4
@@ 35,12 35,12 @@ class Compiler
  attr_reader :variables, :arguments, :syntax, :source, :libs
  attr_accessor :filename

  def compile(code = nil, keep_last: false, halt: true)
  def compile(code = nil, halt: true)
    if code
      @source[@filename] = code
      @sexps = Parser.new(code, filename: filename).parse
    end
    compile_sexps(@sexps, options: { syntax: @syntax, locals: @locals }, halt: halt, keep_last: keep_last)
    compile_sexps(@sexps, options: { syntax: @syntax, locals: @locals }, halt: halt)
  end

  def mangle_identifier(name)


@@ 60,10 60,10 @@ class Compiler

  private

  def compile_sexps(sexps, options:, halt: false, keep_last: false)
  def compile_sexps(sexps, options:, halt: false)
    instructions = sexps
                   .each_with_index
                   .map { |s, i| compile_sexp(s, options.merge(use: i == sexps.size - 1 && keep_last)) }
                   .map { |s, i| compile_sexp(s, options) }
                   .flatten
                   .compact
    instructions << VM::HALT if halt

M spec/vm_spec.rb => spec/vm_spec.rb +4 -4
@@ 1177,7 1177,7 @@ describe VM do
              n))
          (fn 2)
        END
        instr = c.compile(keep_last: true)
        instr = c.compile
        subject.execute(instr)
      end



@@ 1205,7 1205,7 @@ describe VM do
              (fn (- n 1))))
          (fn 2)
        END
        instr = c.compile(keep_last: true)
        instr = c.compile
        subject.execute(instr)
      end



@@ 1235,7 1235,7 @@ describe VM do
              #f))
          (fn 2)
        END
        instr = c.compile(keep_last: true)
        instr = c.compile
        subject.execute(instr)
      end



@@ 1263,7 1263,7 @@ describe VM do
              n))
          (fn 2)
        END
        instr = c.compile(keep_last: true)
        instr = c.compile
        subject.execute(instr)
      end