~tim/scheme-vm

e9480ac858b3faabf1f7b349d3b0286a955049d4 — Tim Morgan 4 years ago 6276f39
Don't leave strings on the stack if unused
2 files changed, 10 insertions(+), 3 deletions(-)

M compiler.rb
M spec/compiler_spec.rb
M compiler.rb => compiler.rb +6 -2
@@ 170,8 170,12 @@ class Compiler
    [VM::PUSH_CHAR, char, pop_maybe(options)]
  end

  def compile_string(string, _options)
    [VM::PUSH_STR, string]
  def compile_string(string, options)
    [
      VM::PUSH_STR,
      string,
      pop_maybe(options)
    ]
  end

  def compile_number(number, options)

M spec/compiler_spec.rb => spec/compiler_spec.rb +4 -1
@@ 73,7 73,9 @@ describe Compiler do

      it 'compiles into vm instructions' do
        expect(d(@result)).to eq([
          'VM::PUSH_STR', 'a string',
          'VM::PUSH_STR',
          'a string',
          'VM::POP',
          'VM::HALT'
        ])
      end


@@ 1078,6 1080,7 @@ describe Compiler do
            'VM::PUSH_VAR', 'write-string',
            'VM::CALL',
            'VM::PUSH_STR', 'hello from main',
            'VM::POP',
            'VM::HALT'
          ])
        end