Skip to content
Browse files

got rid of instance_variable_get calls

  • Loading branch information...
1 parent b3b5364 commit 4469d6ba34ba9615df14698d17647b625ad140a0 @juliend2 committed Apr 9, 2011
Showing with 24 additions and 23 deletions.
  1. +12 −1 nodes.rb
  2. +12 −22 phlower.rb
View
13 nodes.rb
@@ -2,6 +2,7 @@ class Awesome
end
# Collection of nodes each one representing an expression.
class Nodes < Awesome
+ attr_accessor :nodes
def initialize(nodes)
@nodes = nodes
end
@@ -25,6 +26,7 @@ def eval(context)
# Literals are static values that have a Ruby representation,
# eg.: a string, a number, true, false, nil, etc.
class LiteralNode < Awesome
+ attr_accessor :value
def initialize(value)
@value = value
end
@@ -48,6 +50,7 @@ def eval(context)
end
class VarNode < Awesome
+ attr_accessor :name
def initialize(name)
@name = name
end
@@ -67,6 +70,7 @@ def eval(context)
# receiver.method(argument1, argument2)
#
class CallNode < Awesome
+ attr_accessor :receiver, :method, :arguments, :is_end
def initialize(receiver, method, arguments=[], is_end=false)
@receiver = receiver
@method = method
@@ -99,6 +103,7 @@ def eval(context)
end
class ArrayNode < Awesome
+ attr_accessor :values
def initialize(arguments=[])
@values = arguments
end
@@ -110,6 +115,7 @@ def end(context)
# Retreiving the value of a constant.
class GetConstantNode < Awesome
+ attr_accessor :name
def initialize(name)
@name = name
end
@@ -121,6 +127,7 @@ def eval(context)
# Setting the value of a constant.
class SetConstantNode < Awesome
+ attr_accessor :name, :value
def initialize(name, value)
@name = name
@value = value
@@ -133,6 +140,7 @@ def eval(context)
# Setting the value of a local variable.
class SetLocalNode < Awesome
+ attr_accessor :name, :value, :is_end
def initialize(name, value, is_end)
@name = name
@value = value
@@ -146,6 +154,7 @@ def eval(context)
# Method definition.
class DefNode < Awesome
+ attr_accessor :name, :params, :body
def initialize(name, params, body)
@name = name
@params = params
@@ -159,6 +168,7 @@ def eval(context)
# Class definition.
class ClassNode < Awesome
+ attr_accessor :name, :body
def initialize(name, body)
@name = name
@body = body
@@ -180,6 +190,7 @@ def eval(context)
# Look at this node if you want to implement other
# control structures like while, for, loop, etc.
class IfNode < Awesome
+ attr_accessor :condition, :body, :else_body
def initialize(condition, body, else_body=nil)
@condition = condition
@body = body
@@ -195,4 +206,4 @@ def eval(context)
@else_body.eval(context)
end
end
-end
+end
View
34 phlower.rb
@@ -177,7 +177,7 @@ def node(objet)
end
if objet.instance_of?(ArrayNode)
- arraynode(objet.instance_variable_get(:@values)) do |txt|
+ arraynode(objet.values) do |txt|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -189,7 +189,7 @@ def node(objet)
end
if objet.instance_of?(GetConstantNode)
- getconstantnode(objet.instance_variable_get(:@name)) do |txt|
+ getconstantnode(objet.name) do |txt|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -202,9 +202,7 @@ def node(objet)
# if true:
if objet.instance_of?(IfNode)
- ifnode(objet.instance_variable_get(:@condition),
- objet.instance_variable_get(:@body),
- objet.instance_variable_get(:@else_body)) do |txt|
+ ifnode(objet.condition, objet.body, objet.else_body) do |txt|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -217,8 +215,7 @@ def node(objet)
# class Name:
if objet.instance_of?(ClassNode)
- classnode(objet.instance_variable_get(:@name),
- objet.instance_variable_get(:@body)) do |txt|
+ classnode(objet.name, objet.body) do |txt|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -231,9 +228,7 @@ def node(objet)
# def methode:
if objet.instance_of?(DefNode)
- defnode(objet.instance_variable_get(:@name),
- objet.instance_variable_get(:@params),
- objet.instance_variable_get(:@body)) do |txt|
+ defnode(objet.name, objet.params, objet.body) do |txt|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -246,10 +241,7 @@ def node(objet)
# objet.method(args)
if objet.instance_of?(CallNode)
- callnode(objet.instance_variable_get(:@method),
- objet.instance_variable_get(:@arguments),
- objet.instance_variable_get(:@receiver),
- objet.instance_variable_get(:@is_end)) do |txt, type|
+ callnode(objet.method, objet.arguments, objet.receiver, objet.is_end) do |txt, type|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -262,7 +254,7 @@ def node(objet)
# variable
if objet.instance_of?(VarNode)
- varnode(objet.instance_variable_get(:@name)) do |txt|
+ varnode(objet.name) do |txt|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -275,9 +267,7 @@ def node(objet)
# var = value
if objet.instance_of?(SetLocalNode)
- setlocalnode(objet.instance_variable_get(:@name),
- objet.instance_variable_get(:@value),
- objet.instance_variable_get(:@is_end)) do |txt|
+ setlocalnode(objet.name, objet.value, objet.is_end) do |txt|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -289,7 +279,7 @@ def node(objet)
end
if objet.instance_of?(Nodes)
- nodenode(objet.instance_variable_get(:@nodes)) do |txt|
+ nodenode(objet.nodes) do |txt|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -301,7 +291,7 @@ def node(objet)
end
if objet.instance_of?(LiteralNode)
- literalnode(objet.instance_variable_get(:@value)) do |txt|
+ literalnode(objet.value) do |txt|
if txt.is_a?(Awesome)
node(txt)
elsif(txt.instance_of?(Array))
@@ -334,7 +324,7 @@ def initialize(inputfile, outputfile=false, isstring=false)
# output
returned = ''
if objects.instance_of?(Nodes)
- objarray = objects.instance_variable_get(:@nodes)
+ objarray = objects.nodes
objarray.each do |object|
returned << node(object) unless node(object).nil?
end
@@ -355,7 +345,7 @@ def initialize(inputfile, outputfile=false, isstring=false)
# output
@c << "<?php\n\n"
if objects.instance_of?(Nodes)
- objarray = objects.instance_variable_get(:@nodes)
+ objarray = objects.nodes
objarray.each do |object|
@c << node(object) unless node(object).nil?
end

0 comments on commit 4469d6b

Please sign in to comment.
Something went wrong with that request. Please try again.