コード例 #1
0
 def fn_type_expr(self, n):
     self.assert_kid_count(2, n)
     params = self.types(n.children[0])
     returns = self.type_expr(n.children[1])
     param_types = [param.type for param in params.children]
     fn_type = types.Function(param_types, returns.type)
     return as_typed(n, fn_type).addkid(params).addkid(returns)
コード例 #2
0
ファイル: generate.py プロジェクト: Aayyush/Sile
 def __init__(self, modules, module):
     self.modules = modules
     self.module = module
     self.functions = [
         self.module.new_function('main', types.Function([], types.UNIT))
     ]
     self.symbols = SymbolTable()
コード例 #3
0
 def run(mods):
     main = il.FunctionRef('main', 0, 'main', types.Function([], types.UNIT))
     main = mods.lookup(main)
     self = IlMachine(mods)
     self.push_frame(None, main, None, list(), dict())
     self.execute(Address(main, 0, 0))
     self.pop_frame()
コード例 #4
0
 def fn_stmt(self, n):
     self.assert_kid_count(4, n)
     name = n.children[0].value
     params = as_typed(n.children[1], types.UNIT)
     returns = self.type_expr(n.children[2])
     param_types = list()
     for p in n.children[1].children:
         param = self.param_decl(p)
         self.symbols[param.children[0].value] = param.type
         params.addkid(param)
         param_types.append(param.type)
     fn_type = types.Function(param_types, returns.type)
     name_node = as_typed(n.children[0], fn_type)
     self.push_function(fn_type)
     self.symbols[name] = fn_type
     self.symbols = self.symbols.push()
     body = self.stmts(n.children[3])
     self.symbols = self.symbols.pop()
     self.pop_function()
     typed = (as_typed(n, types.UNIT).addkid(name_node).addkid(
         params).addkid(returns).addkid(body))
     return typed