Cleanup
This commit is contained in:
parent
ae23e9fbe6
commit
c5eb2a33d7
17
compiler.rb
17
compiler.rb
@ -41,7 +41,7 @@ def push(obj)
|
|||||||
$outfile.puts "push #{segment} #{index}"
|
$outfile.puts "push #{segment} #{index}"
|
||||||
elsif obj.class == String
|
elsif obj.class == String
|
||||||
if obj.is_integer?
|
if obj.is_integer?
|
||||||
$outfile.puts "push constant #{obj.to_i}"
|
$outfile.puts "push constant #{obj}"
|
||||||
elsif is_var(obj.to_sym)
|
elsif is_var(obj.to_sym)
|
||||||
index,segment=get_index(obj.to_sym)
|
index,segment=get_index(obj.to_sym)
|
||||||
$outfile.puts "push #{segment} #{index}"
|
$outfile.puts "push #{segment} #{index}"
|
||||||
@ -148,15 +148,15 @@ def phase_two
|
|||||||
$outfile.puts "call Main.#{parsed_line[1]} #{nargs}"
|
$outfile.puts "call Main.#{parsed_line[1]} #{nargs}"
|
||||||
else
|
else
|
||||||
if line[1].include? "+"
|
if line[1].include? "+"
|
||||||
operand=line[1].split("+")
|
operands=line[1].split("+")
|
||||||
op="add"
|
op="add"
|
||||||
end
|
end
|
||||||
if line[1].include? "-"
|
if line[1].include? "-"
|
||||||
operand=line[1].split("-")
|
operands=line[1].split("-")
|
||||||
op="sub"
|
op="sub"
|
||||||
end
|
end
|
||||||
push(operand[0])
|
push(operands[0])
|
||||||
push(operand[1])
|
push(operands[1])
|
||||||
$outfile.puts(op)
|
$outfile.puts(op)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -190,10 +190,11 @@ end
|
|||||||
|
|
||||||
if !File.exists? "vmprog"
|
if !File.exists? "vmprog"
|
||||||
Dir.mkdir("vmprog")
|
Dir.mkdir("vmprog")
|
||||||
write_init()
|
|
||||||
end
|
|
||||||
|
|
||||||
Dir.chdir("vmprog")
|
Dir.chdir("vmprog")
|
||||||
|
write_init()
|
||||||
|
else
|
||||||
|
Dir.chdir("vmprog")
|
||||||
|
end
|
||||||
|
|
||||||
$outfile=File.new("Main.vm","w")
|
$outfile=File.new("Main.vm","w")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user