Skip to content

Commit

Permalink
Add :add keyword and implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarh committed Jun 11, 2013
1 parent 50fcf26 commit dc2bbd8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions compile_arithmetic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# Method to compile arithmetic
class Compiler

def compile_add(scope, left, right)
@e.with_register do |reg|
src = compile_eval_arg(scope,left)
@e.movl(src,reg)
@e.save_result(compile_eval_arg(scope,right))
@e.addl(reg, :eax)
end
[:subexpr]
end

end
4 changes: 3 additions & 1 deletion compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
require 'set'
require 'print_sexp'

require 'compile_arithmetic'

class Compiler
attr_reader :global_functions
attr_accessor :trace
Expand All @@ -21,7 +23,7 @@ class Compiler
:do, :class, :defun, :defm, :if, :lambda,
:assign, :while, :index, :let, :case, :ternif,
:hash, :return,:sexp, :module, :rescue, :incr, :block,
:required
:required, :add
]

Keywords = @@keywords
Expand Down

0 comments on commit dc2bbd8

Please sign in to comment.