def _expression_reference(self, expression, address, type): """ Find all symbols referenced in the expression. Create an entry in the reference dict for each symbol found. Set the argument text for this instruction to the textual representation of this expression. If all symbols exist, evaluate the expression and return the value, otherwise return zero and defer the evaluation until all unresolved references are defined. """ references = expression.references(self) defer_eval = False try: [self[ref] for ref in references] defer_eval = False except SymbolUndefinedError: defer_eval = True # Evaluate before creating references in case an exception is raised # during evaluation. value = 0 if defer_eval else expression.eval(self) for ref in references: self.add_reference(ref, address, type, expression) self.set_argument(address, str(expression)) return value
def _data_expression(self, expression): """ Insert the results of an expression at the current position. """ value = expression.eval(self.meta) self._data_int(value)