def annotate_routine_def(self, tree): block = def_helper.get_def_body(tree) block.live_out = tokset_new() # iterate until a fixed point is met self.change = True while self.change: self.change = False self.annotate_body(block)
def check_unitialized(self, tree): params = [p.value for p in def_helper.get_def_params(tree)] block = def_helper.get_def_body(tree) possibly_undef = tokset_difference(block.live_in, tokset_new(params)) if not tokset_empty(possibly_undef): for var, tok in possibly_undef.items(): msg = i18n.i18n('Variable "%s" possibly uninitialized') % (var,) area = position.ProgramAreaNear(tok) raise GbsUninitializedVarException(msg, area)
def _explode_interactive(self, program_tree): """ Replaces interactive macro with it's implementation in the program tree """ interactive = defhelper.find_def(program_tree.children[2], defhelper.is_interactive_def) if interactive != None: if self.explicit_board: macro_filename = "interactive_program.gbs" else: macro_filename = "interactive_program_implicit.gbs" implementation_program = self._load_implementation(macro_filename, ["lastKey", "read", "Show", "FreeVars"]) if self.explicit_board: refParam = interactive.children[2].children[0].value defhelper.recursive_replace_token(implementation_program, "t", refParam) interactive_impl = defhelper.find_def(implementation_program.children[2], defhelper.is_entrypoint_def) interactive_impl_case = defhelper.recursive_find_node(interactive_impl, functools.partial(defhelper.is_node, 'case')) interactive_impl_case.children = [interactive_impl_case.children[0], interactive_impl_case.children[1]] interactive_impl_case.children.append(defhelper.get_def_body(interactive)) defhelper.set_def_body(interactive, defhelper.get_def_body(interactive_impl)) defhelper.set_def_token_name(interactive, 'program')
def compile_routine_def(self, tree): "Compile a single definition." prfn = def_helper.get_def_keyword(tree) name = def_helper.get_def_name(tree).value self._current_def_name = name params = [param.value for param in def_helper.get_def_params(tree)] immutable_params = [] if prfn == 'function': immutable_params = params elif prfn == 'procedure' and len(params) > 1: immutable_params = params[1:] code = gbs_vm.GbsCompiledCode(tree, prfn, name, params, self.explicit_board) code.add_enter() for p in immutable_params: code.push(('setImmutable', p), near=tree) self.compile_commands(def_helper.get_def_body(tree), code) if prfn == 'procedure' and self.explicit_board: code.push(('pushFrom', params[0]), near=tree) code.add_leave_return() code.build_label_table() self.code.routines[name] = code
def check_unused_def(self, tree): self.check_unused_commands(def_helper.get_def_body(tree))