This commit is contained in:
pjht 2018-03-04 14:18:45 -06:00
parent ae23e9fbe6
commit c5eb2a33d7
3 changed files with 13 additions and 12 deletions

View File

@ -41,7 +41,7 @@ def push(obj)
$outfile.puts "push #{segment} #{index}"
elsif obj.class == String
if obj.is_integer?
$outfile.puts "push constant #{obj.to_i}"
$outfile.puts "push constant #{obj}"
elsif is_var(obj.to_sym)
index,segment=get_index(obj.to_sym)
$outfile.puts "push #{segment} #{index}"
@ -148,15 +148,15 @@ def phase_two
$outfile.puts "call Main.#{parsed_line[1]} #{nargs}"
else
if line[1].include? "+"
operand=line[1].split("+")
operands=line[1].split("+")
op="add"
end
if line[1].include? "-"
operand=line[1].split("-")
operands=line[1].split("-")
op="sub"
end
push(operand[0])
push(operand[1])
push(operands[0])
push(operands[1])
$outfile.puts(op)
end
end
@ -190,10 +190,11 @@ end
if !File.exists? "vmprog"
Dir.mkdir("vmprog")
write_init()
end
Dir.chdir("vmprog")
write_init()
else
Dir.chdir("vmprog")
end
$outfile=File.new("Main.vm","w")