2022-06-01 01:04:14 +00:00
|
|
|
"""The public interface for shoggoth's baked-in types."""
|
2022-01-09 23:32:11 +00:00
|
|
|
|
|
|
|
|
2022-05-31 15:36:47 +00:00
|
|
|
import typing as t
|
2022-04-15 06:31:58 +00:00
|
|
|
from uuid import UUID, uuid4
|
|
|
|
|
|
|
|
|
2022-05-31 15:36:47 +00:00
|
|
|
class TypeVariable(t.NamedTuple):
|
2022-04-15 06:31:58 +00:00
|
|
|
name: str
|
|
|
|
id: UUID = uuid4()
|
|
|
|
|
|
|
|
|
2022-05-31 15:36:47 +00:00
|
|
|
class ArrayExpr(t.NamedTuple):
|
|
|
|
child: t.Any
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
2022-05-31 15:36:47 +00:00
|
|
|
class SumExpr(t.NamedTuple):
|
|
|
|
children: t.List[t.Any]
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
2022-05-31 15:36:47 +00:00
|
|
|
class ProductExpr(t.NamedTuple):
|
|
|
|
children: t.Mapping[str, t.Any]
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
####################################################################################################
|
|
|
|
####################################################################################################
|
|
|
|
####################################################################################################
|
|
|
|
|
2022-05-31 15:36:47 +00:00
|
|
|
class FunctionRef(t.NamedTuple):
|
2022-04-15 06:31:58 +00:00
|
|
|
raw: str
|
|
|
|
type_params: list
|
|
|
|
name: str
|
|
|
|
args: list
|
|
|
|
ret: list
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def parse_list(l):
|
|
|
|
return [e for e in l.split(",") if e]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def parse(cls, raw: str):
|
|
|
|
vars, name, args, ret = raw.split(";")
|
|
|
|
return cls(
|
|
|
|
raw,
|
|
|
|
cls.parse_list(vars),
|
|
|
|
name,
|
|
|
|
cls.parse_list(args),
|
|
|
|
cls.parse_list(ret)
|
|
|
|
)
|
2022-05-31 15:36:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Closure(t.NamedTuple):
|
|
|
|
target: t.Union["Closure", FunctionRef]
|
|
|
|
args: t.List[t.Any]
|
|
|
|
|
|
|
|
|
2022-06-01 01:25:18 +00:00
|
|
|
class FunctionSignature(t.NamedTuple):
|
|
|
|
raw: str
|
|
|
|
type_params: list
|
|
|
|
name: str
|
|
|
|
args: list
|
|
|
|
ret: list
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def parse_list(l):
|
|
|
|
return [e for e in l.split(",") if e]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def parse(cls, raw: str):
|
|
|
|
vars, name, args, ret = raw.split(";")
|
|
|
|
return cls(
|
|
|
|
raw,
|
|
|
|
cls.parse_list(vars),
|
|
|
|
name,
|
|
|
|
cls.parse_list(args),
|
|
|
|
cls.parse_list(ret)
|
|
|
|
)
|
2022-06-01 05:54:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Closure(t.NamedTuple):
|
|
|
|
funref: FunctionRef
|
|
|
|
frag: t.List[t.Any]
|