Class: SubNode

Inherits:
BinaryNode show all
Defined in:
lib/ast.rb

Instance Attribute Summary

Attributes inherited from BinaryNode

#left, #right

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ SubNode

Returns a new instance of SubNode.



43
44
45
# File 'lib/ast.rb', line 43

def initialize(left, right)
  super(left,right)
end

Instance Method Details

#evaluateObject



47
48
49
# File 'lib/ast.rb', line 47

def evaluate() 
  return @left.evaluate() - @right.evaluate()
end

#eweObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ast.rb', line 51

def ewe()
  iniciaSubN = "       sp := sp + tres \n"
  medioSubN = "\n       sp := sp - tres \n       tmp := M[sp + 3] \n"
  medioSubN+="       M[sp + 1] := tmp \n       sp := sp + tres \n"
  finSubN ="\n       sp := sp - tres \n       tmp := M[sp + 3] \n"
  finSubN+="       M[sp + 2] := tmp \n       tmp := M[sp + 1] \n"
  finSubN+="       tmp2 := M[sp + 2] \n       tmp := tmp - tmp2 \n"
  finSubN+="       M[sp + 0] := tmp \n"
  sub = iniciaSubN + @left.ewe() + medioSubN + @right.ewe() + finSubN 
  return sub
end