def execute(self, operands: List[Expression], frame: Frame, gui_holder: Holder, eval_operands=True): verify_exact_callable_length(self, 1, len(operands)) operand = operands[0] if eval_operands: operand = evaluate_all(operands, frame, gui_holder.expression.children[1:])[0] if not isinstance(operand, Promise): raise OperandDeduceError( f"Force expected a Promise, received {operand}") if operand.forced: return operand.expr if logger.fragile: raise IrreversibleOperationError() gui_holder.expression.set_entries([ VisualExpression(operand.expr, gui_holder.expression.display_value) ]) gui_holder.apply() evaluated = evaluate(operand.expr, operand.frame, gui_holder.expression.children[0]) if not logger.dotted and not isinstance(evaluated, (Pair, NilType)): raise TypeMismatchError( f"Unable to force a Promise evaluating to {operand.expr}, expected another Pair or Nil" ) operand.expr = evaluated operand.force() return operand.expr
def execute_evaluated(self, operands: List[Expression], frame: Frame) -> Expression: verify_exact_callable_length(self, 0, len(operands)) if log.logger.fragile: raise IrreversibleOperationError() log.logger.raw_out("DISABLE_AUTODRAW[]\n") return Undefined
def execute(self, operands: List[Expression], frame: Frame, gui_holder: Holder, eval_operands=True): verify_exact_callable_length(self, 1, len(operands)) if eval_operands: operands = evaluate_all(operands, frame, gui_holder.expression.children[1:]) if not isinstance(operands[0], Symbol): raise OperandDeduceError( f"Load expected a Symbol, received {operands[0]}.") if logger.fragile: raise IrreversibleOperationError() try: with open(f"{operands[0].value}.scm") as file: code = "(begin-noexcept" + "\n".join(file.readlines()) + "\n)" buffer = TokenBuffer([code]) expr = get_expression(buffer) gui_holder.expression.set_entries([ VisualExpression(expr, gui_holder.expression.display_value) ]) gui_holder.apply() return evaluate(expr, frame, gui_holder.expression.children[0], True) except OSError as e: raise LoadError(e)
def execute(self, operands: List[Expression], frame: Frame, gui_holder: Holder, eval_operands=True): verify_exact_callable_length(self, 1, len(operands)) if eval_operands: operands = evaluate_all(operands, frame, gui_holder.expression.children[1:]) if (not isinstance(operands[0], Symbol)): raise OperandDeduceError(''.join([ 'Load expected a Symbol, received ', '{}'.format(operands[0]), '.' ])) if logger.fragile: raise IrreversibleOperationError() try: with open(''.join(['{}'.format(operands[0].value), '.scm'])) as file: code = (('(begin' + '\n'.join(file.readlines())) + '\n)') buffer = TokenBuffer([code]) expr = get_expression(buffer) gui_holder.expression.set_entries([ VisualExpression(expr, gui_holder.expression.display_value) ]) gui_holder.apply() return evaluate(expr, frame, gui_holder.expression.children[0], True) except OSError as e: raise LoadError(e)
def assign(self, varname: Symbol, varval: Expression): if log.logger.fragile and not self.temp: raise IrreversibleOperationError() if isinstance(varval, Thunk): assert varname == log.return_symbol varval.bind(self) return self.vars[varname.value] = varval log.logger.frame_store(self, varname.value, varval)
def execute_evaluated(self, operands: List[Expression], frame: Frame) -> Expression: verify_exact_callable_length(self, 2, len(operands)) if log.logger.fragile: raise IrreversibleOperationError() pair, val = operands if not isinstance(pair, Pair): raise OperandDeduceError(f"set-car! expected a Pair, received {pair}.") pair.first = val log.logger.raw_out("WARNING: Mutation operations on pairs are not yet supported by the debugger.") return Undefined
def mutate(self, varname: Symbol, varval: Expression): if log.logger.fragile and not self.temp: raise IrreversibleOperationError() assert not isinstance(varval, Thunk) if varname.value in self.vars: self.vars[varname.value] = varval log.logger.frame_store(self, varname.value, varval) elif self.parent is None: raise SymbolLookupError(f"Variable not found in current environment: '{varname}'") else: self.parent.mutate(varname, varval)
def execute_evaluated(self, operands: List[Expression], frame: Frame) -> Expression: verify_exact_callable_length(self, 2, len(operands)) if log.logger.fragile: raise IrreversibleOperationError() (pair, val) = operands if (not isinstance(pair, Pair)): raise OperandDeduceError( ''.join(['set-car! expected a Pair, received ', '{}'.format(pair), '.'])) pair.first = val log.logger.raw_out( 'WARNING: Mutation operations on pairs are not yet supported by the debugger.') return Undefined
def mutate(self, varname: Symbol, varval: Expression): if (log.logger.fragile and (not self.temp)): raise IrreversibleOperationError() assert (not isinstance(varval, Thunk)) if (varname.value in self.vars): self.vars[varname.value] = varval log.logger.frame_store(self, varname.value, varval) elif (self.parent is None): raise SymbolLookupError(''.join([ "Variable not found in current environment: '", '{}'.format(varname), "'" ])) else: self.parent.mutate(varname, varval)
def execute(self, operands: List[Expression], frame: Frame, gui_holder: Holder, eval_operands=True): verify_exact_callable_length(self, 1, len(operands)) if eval_operands: operands = evaluate_all(operands, frame, gui_holder.expression.children[1:]) if not isinstance(operands[0], String): raise OperandDeduceError(f"Load expected a String, received {operands[0]}.") if logger.fragile: raise IrreversibleOperationError() from os import listdir from os.path import join directory = operands[0].value try: targets = sorted(listdir(directory)) targets = [join(directory, target) for target in targets if target.endswith(".scm")] exprs = [make_list([Symbol("load"), make_list([Symbol("quote"), Symbol(x[:-4])])]) for x in targets] equiv = make_list([Symbol("begin-noexcept")] + exprs) gui_holder.expression.set_entries([equiv]) gui_holder.apply() return evaluate(equiv, frame, gui_holder.expression.children[0], True) except Exception as e: raise SchemeError(e)
def out(*args, **kwargs): if log.logger.fragile: raise IrreversibleOperationError() return func(*args, **kwargs)
def execute_simple(self, operand: Expression) -> Expression: if log.logger.fragile: raise IrreversibleOperationError() log.logger.raw_out("DRAW" + json.dumps( [log.logger.i, log.logger.heap.record(operand)]) + "\n") return Undefined