Doc editing

This commit is contained in:
Maggie Mari 2012-08-20 17:52:00 -05:00
commit e7cbaea1e8

View file

@ -933,7 +933,8 @@ Abstract Syntax Tree (aka Parse Tree)
self.left = left self.left = left
self.right = right self.right = right
def CodeGen(self): left = self.left.CodeGen() def CodeGen(self):
left = self.left.CodeGen()
right = self.right.CodeGen() right = self.right.CodeGen()
if self.operator == '+': if self.operator == '+':
@ -953,13 +954,13 @@ Abstract Syntax Tree (aka Parse Tree)
# Expression class for function calls. # Expression class for function calls.
class CallExpressionNode(ExpressionNode): class CallExpressionNode(ExpressionNode):
def __init__(self, callee, args): self.callee = callee self.args = def __init__(self, callee, args):
args self.callee = callee
self.args = args
def CodeGen(self): # Look up the name in the global module table. callee def CodeGen(self):
= g_llvm_module.get_function_named(self.callee) # Look up the name in the global module table.
callee = g_llvm_module.get_function_named(self.callee)
::
# Check for argument mismatch error. # Check for argument mismatch error.
if len(callee.args) != len(self.args): if len(callee.args) != len(self.args):
@ -973,13 +974,12 @@ Abstract Syntax Tree (aka Parse Tree)
class IfExpressionNode(ExpressionNode): class IfExpressionNode(ExpressionNode):
def __init__(self, condition, then_branch, else_branch): def __init__(self, condition, then_branch, else_branch):
self.condition = condition self.then_branch = then_branch self.condition = condition
self.then_branch = then_branch
self.else_branch = else_branch self.else_branch = else_branch
def CodeGen(self): condition = self.condition.CodeGen() def CodeGen(self): condition = self.condition.CodeGen()
::
# Convert condition to a bool by comparing equal to 0.0. # Convert condition to a bool by comparing equal to 0.0.
condition_bool = g_llvm_builder.fcmp( condition_bool = g_llvm_builder.fcmp(
FCMP_ONE, condition, Constant.real(Type.double(), 0), 'ifcond') FCMP_ONE, condition, Constant.real(Type.double(), 0), 'ifcond')
@ -1024,16 +1024,28 @@ Abstract Syntax Tree (aka Parse Tree)
class ForExpressionNode(ExpressionNode): class ForExpressionNode(ExpressionNode):
def __init__(self, loop_variable, start, end, step, body): def __init__(self, loop_variable, start, end, step, body):
self.loop_variable = loop_variable self.start = start self.end = end self.loop_variable = loop_variable
self.step = step self.body = body self.start = start
self.end = end
self.step = step
self.body = body
def CodeGen(self): # Output this as: # ... # start = startexpr # goto def CodeGen(self):
loop # loop: # variable = phi [start, loopheader], [nextvariable, # Output this as:
loopend] # ... # bodyexpr # ... # loopend: # step = stepexpr # # ...
nextvariable = variable + step # endcond = endexpr # br endcond, loop, # start = startexpr
endloop # outloop: # goto loop
# loop:
:: # variable = phi [start, loopheader], [nextvariable, loopend]
# ...
# bodyexpr
# ...
# loopend:
# step = stepexpr
# nextvariable = variable + step
# endcond = endexpr
# br endcond, loop, endloop
# outloop:
# Emit the start code first, without 'variable' in scope. # Emit the start code first, without 'variable' in scope.
start_value = self.start.CodeGen() start_value = self.start.CodeGen()