diff --git a/scopes/core/core.py b/scopes/core/core.py index 50affe8..248a71a 100644 --- a/scopes/core/core.py +++ b/scopes/core/core.py @@ -2,21 +2,33 @@ """The scopes.core package""" +from __future__ import annotations # no check of type annotations at runtime import asyncio -from dataclasses import dataclass -from types import CoroutineType, FunctionType +from collections.abc import AsyncGenerator, Callable, Coroutine +from dataclasses import dataclass, field from typing import Any +from scopes.core.message import Message from scopes.util import keywords as k, Symbol +type Proc = Callable[[Scope, Message], AsyncGenerator[Scope]] +type Program = Callable[[Scope], Proc] +type Syn = Callable[[Message], Message] + +async def proc_dummy(scope: Scope, msg: Message) -> AsyncGenerator[Scope]: + yield scope + @dataclass class Scope: value: Any = 0 categ: tuple[Symbol, Symbol] = (k.csys, k.c00) stage: Symbol = k.initial - proc: CoroutineType | None = None - program: dict[tuple[Symbol, Symbol], CoroutineType] = {} - syns: list[FunctionType] = [] - environ: asyncio.Queue | None = None + proc: Proc = proc_dummy + program: Program = lambda x: proc_dummy + syns: list[Syn] = field(default_factory=list) + environ: asyncio.Queue = field(default_factory=asyncio.Queue) + def set_proc(self) -> Scope: + self.proc = self.program(self) + return self