def test_op_with_type_multi_input_multi_output_signature(self) -> None: stack = Stack() cont = Continuation(stack) cont.stack.push(StackObject(stype=TTest, value="ttest")) cont.stack.push(StackObject(stype=TParm1, value="tparm")) cont.stack.push(StackObject(stype=TParm1, value="tparm")) make_word_context("test", lambda cont: 42, [TTest, TParm1, TParm1], [TTest, TParm1]) print_words() op, found = Type.op("test", cont) #, "Test") assert found assert op.sig == TypeSignature([ StackObject(stype=TTest), StackObject(stype=TParm1), StackObject(stype=TParm1) ], [StackObject(stype=TTest), StackObject(stype=TParm1)]) op( cont ) # Do this so the lambda doesn't get counted as a missed branch in our code coverage. op, found = Type.op("not found", cont) assert not found
def test_op_with_wrong_type_signature(self) -> None: stack = Stack() stack.push(StackObject(stype=TTest, value="tparm")) make_word_context("test", op_print, [TParm1]) with self.assertRaises(Exception): Type.op("test", stack)
def setUp(self) -> None: self.stack = Stack() self.cont = Continuation(self.stack) self.save_types = deepcopy(Type.types) self.save_ctors = deepcopy(Type.ctors) # Clear up all the types. the_types = ["Any", "CodeCompile", "Parm1", "Test"] for t in the_types: x = Type(t) Type.register_ctor("Test", Operation('nop', TOp), [StackObject(stype=TParm1)])
def test_match_in(self) -> None: empty_sig = TypeSignature([], []) s = Stack() assert empty_sig.match_in(s) s.push(StackObject(stype=TParm1)) sig = TypeSignature([StackObject(stype=TParm1)], []) # We can do this twice because it doesn't consume the stack. assert sig.match_in(s) assert sig.match_in(s) s.push(StackObject(stype=TTest)) assert sig.match_in(s) == False
def setUp(self) -> None: self.stack = Stack() self.cont = Continuation(self.stack) self.save_types = deepcopy(Type.types) self.save_ctors = deepcopy(Type.ctors) self.zero_pattern = StackObject(stype=TInt, value=0) self.one_pattern = StackObject(stype=TInt, value=1) self.any_pattern = StackObject(stype=TAny) self.true_pattern = StackObject(stype=TBool, value=True) self.false_pattern = StackObject(stype=TBool, value=False) self.int_pattern = StackObject(stype=TInt) op_debug(self.cont) op_on(self.cont)
def test_op_with_no_type_signature(self) -> None: def stack_fun(s: Stack) -> None: s.push(42) s = Stack() c = Continuation(s) make_word_context("test", stack_fun) op, found = Type.op("test", c) assert found assert op.sig == TypeSignature([], []) op( s ) # Do this so the lambda doesn't get counted as a missed branch in our code coverage.
def test_compile_no_input_no_output(self) -> None: code = """ noinputnooutput : -> ; stack . """ stack = Stack() cont = Continuation(stack) cont = cont.execute(interpret(cont, io.StringIO(code))) op, found = Type.op("noinputnooutput", cont ) #, "Test") assert found assert op.sig == TypeSignature([],[]) op, found = Type.op("not found", cont) assert not found
def test_compile_multi_input_multi_output(self) -> None: code = """ multiinput : Bool Int Int Int -> Int ; + == == . False bool 1 int 1 int 1 int """ stack = Stack() cont = Continuation(stack) cont = cont.execute(interpret(cont, io.StringIO(code))) op, found = Type.op("multiinput", cont ) #, "Test") assert found assert op.sig == TypeSignature([StackObject(stype=TBool),StackObject(stype=TInt),StackObject(stype=TInt),StackObject(stype=TInt)], [StackObject(stype=TInt)]) op, found = Type.op("not found", cont) assert not found
def setUp(self) -> None: self.s = Stack() self.r = Stack() self.c = Continuation(self.s, self.r, symbol=Symbol("Unknown", Location()))
def afc(code: str) -> TextIO: """ Given a string of ActorForth code, returns a file stream that can be executed by the interpreter. cont = interpret(cont, afc("1 int 2 int +")) """ return StringIO(code) """ INTRO 1.3 : Establish our stack and build our stateful Continutaion from it. """ stack = Stack() rstack = Stack() cont = Continuation(stack, rstack) def do_repl(filename: str, handle: TextIO): global cont # Set Debug on or off initially. op_debug(cont) op_off(cont) #op_on(cont) # Checkpoint our initial setup. op_checkpoint(cont)
def setUp(self) -> None: self.stack = Stack() self.cont = Continuation(self.stack) self.save_types = deepcopy(Type.types) self.save_ctors = deepcopy(Type.ctors)