From b292376fd93f5d6ae471715294125646f6f14978 Mon Sep 17 00:00:00 2001 From: Saf Date: Mon, 31 Aug 2020 02:16:29 -0700 Subject: [PATCH] Added an #assemble_string method to Assembler --- lib/n65.rb | 8 ++++++++ spec/lib/n65/symbol_table_spec.rb | 13 +++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/n65.rb b/lib/n65.rb index 9dfd926..19b54d0 100644 --- a/lib/n65.rb +++ b/lib/n65.rb @@ -129,6 +129,14 @@ module N65 @promises << exec_result if exec_result.is_a?(Proc) end + # Assemble the given string + def assemble_string(string) + string.split(/\n/).each do |line| + assemble_one_line(line) + end + fulfill_promises + end + # This will empty out our promise queue and try to fullfil operations # that required an undefined symbol when first encountered. def fulfill_promises diff --git a/spec/lib/n65/symbol_table_spec.rb b/spec/lib/n65/symbol_table_spec.rb index 99ac6b4..7b0694c 100644 --- a/spec/lib/n65/symbol_table_spec.rb +++ b/spec/lib/n65/symbol_table_spec.rb @@ -168,10 +168,7 @@ RSpec.describe(N65::SymbolTable) do ASM end - before do - program.split(/\n/).each { |line| assembler.assemble_one_line(line) } - assembler.fulfill_promises - end + before { assembler.assemble_string(program) } it 'assigns the value of the scope main to the program counter value' do expect(assembler.symbol_table.resolve_symbol('global.main')).to eq(0x8000) @@ -199,7 +196,6 @@ RSpec.describe(N65::SymbolTable) do end let(:correct_binary) do [ - 0x4e, 0x45, 0x53, 0x1a, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x78, # SEI 0xd8, # CLD 0xa9, 0x0, # LDA immediate 0 @@ -210,12 +206,9 @@ RSpec.describe(N65::SymbolTable) do 0x60 # RTS forward_symbol ] end - let(:emitted_rom) { assembler.emit_binary_rom.bytes[0...26] } + let(:emitted_rom) { assembler.emit_binary_rom.bytes[16...26] } - before do - program.split(/\n/).each { |line| assembler.assemble_one_line(line) } - assembler.fulfill_promises - end + before { assembler.assemble_string(program) } it 'assembles the branch to forward_symbol correctly' do expect(emitted_rom).to eq(correct_binary)