From db97be69fea5702154fb56d5966814c98911ad11 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 15 Jan 2018 21:12:17 +0100 Subject: [PATCH] fix subroutine usage scanning --- il65/compile.py | 27 ++++++++++----------------- il65/plyparse.py | 3 +-- testsource/calls.ill | 2 -- testsource/conditionals.ill | 1 - 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/il65/compile.py b/il65/compile.py index 9f1b6cfcb..ea095ac08 100644 --- a/il65/compile.py +++ b/il65/compile.py @@ -267,18 +267,16 @@ class PlyParser: self._get_subroutine_usages_from_return(module.subroutine_usage, node, block.scope) elif isinstance(node, Assignment): self._get_subroutine_usages_from_assignment(module.subroutine_usage, node, block.scope) + print("----------SUBROUTINES IN USE-------------") # XXX + import pprint + pprint.pprint(module.subroutine_usage) # XXX + print("----------/SUBROUTINES IN USE-------------") # XXX def _get_subroutine_usages_from_subcall(self, usages: Dict[Tuple[str, str], Set[str]], subcall: SubCall, parent_scope: Scope) -> None: - # node.target (relevant if its a symbolname -- a str), node.arguments (list of CallArgument) - # CallArgument.value = expression. - if isinstance(subcall.target.target, str): - try: - scopename, name = subcall.target.target.split('.') - except ValueError: - scopename = parent_scope.name - name = subcall.target.target - usages[(scopename, name)].add(str(subcall.sourceref)) + target = subcall.target.target + if isinstance(target, SymbolName): + usages[(parent_scope.name, target.name)].add(str(subcall.sourceref)) for arg in subcall.arguments: self._get_subroutine_usages_from_expression(usages, arg.value, parent_scope) @@ -309,14 +307,9 @@ class PlyParser: def _get_subroutine_usages_from_goto(self, usages: Dict[Tuple[str, str], Set[str]], goto: Goto, parent_scope: Scope) -> None: - # node.target (relevant if its a symbolname -- a str), node.condition (expression) - if isinstance(goto.target.target, str): - try: - symbol = parent_scope[goto.target.target] - except LookupError: - return - if isinstance(symbol, Subroutine): - usages[(parent_scope.name, symbol.name)].add(str(goto.sourceref)) + target = goto.target.target + if isinstance(target, SymbolName): + usages[(parent_scope.name, target.name)].add(str(goto.sourceref)) self._get_subroutine_usages_from_expression(usages, goto.condition, parent_scope) def _get_subroutine_usages_from_return(self, usages: Dict[Tuple[str, str], Set[str]], diff --git a/il65/plyparse.py b/il65/plyparse.py index 1bc30aa1d..cd0797c68 100644 --- a/il65/plyparse.py +++ b/il65/plyparse.py @@ -1245,7 +1245,6 @@ def p_calltarget(p): """ calltarget : symbolname | INTEGER - | BITAND symbolname | dereference """ if len(p) == 2: @@ -1402,7 +1401,7 @@ def p_error(p): if p.value in ("", "\n"): p.lexer.error_function(sref, "syntax error before end of line") else: - p.lexer.error_function(sref, "syntax error before '{:.20s}'", str(p.value).rstrip()) + p.lexer.error_function(sref, "syntax error before or at '{:.20s}'", str(p.value).rstrip()) else: lexer.error_function(None, "syntax error at end of input", lexer.source_filename) diff --git a/testsource/calls.ill b/testsource/calls.ill index 6cddb5072..6e59b7b81 100644 --- a/testsource/calls.ill +++ b/testsource/calls.ill @@ -24,8 +24,6 @@ bar2: bar: goto $c000 goto var1 ; jumps to the address in var1 goto mem1 ; jumps to the address in mem1 - goto &var1 ; strange, but jumps to the location in memory where var1 sits - goto &mem1 ; strange, but jumps to the location in mempory where mem1 sits (points to) goto [var1] goto [$c000.word] goto [var1] diff --git a/testsource/conditionals.ill b/testsource/conditionals.ill index dfc772f15..c2f4c5c7f 100644 --- a/testsource/conditionals.ill +++ b/testsource/conditionals.ill @@ -24,7 +24,6 @@ start: if_gt goto label if_cc goto value ;if_cc goto memvalue - if_cc goto &value ;if_cc goto #memvalue if_cc goto [value] ;if_cc goto [memvalue]