py-scopes/scopes/core/core.py

34 lines
1,000 B
Python

# scopes.core.core
"""The scopes.core package"""
from __future__ import annotations # no check of type annotations at runtime
import asyncio
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: 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