This commit is contained in:
2025-11-16 14:56:14 +01:00
parent 56fb0982b4
commit 51984e297b
8 changed files with 376 additions and 357 deletions
View File
+145
View File
@@ -0,0 +1,145 @@
from abc import ABC
from collections.abc import Mapping
from dataclasses import dataclass, field
from enum import Enum
from typing import ClassVar
from lsprotocol.types import SymbolKind
class SkillDataType(Enum):
array = "a"
"""array"""
ddUserType = "b"
"""Boolean"""
opfcontext = "C"
"""OPF Context"""
dbobject = "d"
"""Cadence database object (CDBA)"""
envobj = "e"
"""environment"""
flonum = "f"
"""floating-point number"""
opffile = "F"
"""OPF file ID"""
general = "g"
"""any data type"""
nil = "g"
""""""
dgbSpecIlUserType = "G"
"""gdm spec"""
hdbobject = "h"
"""hierarchical database configuration object"""
list = "l"
"""linked list"""
nmpIlUserType = "m"
"""nmpll user type"""
cdsEvalObject = "M"
"""Cadence evaluation object"""
number = "n"
"""integere of floating point number"""
userType = "o"
"""user defined type (other)"""
port = "p"
"""I/O port"""
gdmspecListIlUSerType = "q"
""" gdm spec list"""
defstruct = "r"
"""defstruct"""
rodObj = "R"
"""relative object design (ROD) object"""
symbol = "s"
"""symbol"""
stringSymbol = "S"
"""symbol or character string"""
string = "t"
"""character string (text)"""
function = "u"
"""function object, either the name if a function (symbol) or a lambda function body (list)"""
funobj = "U"
"""function object"""
hdbpath = "v"
""""""
wtype = "w"
"""window type"""
integer = "x"
"""integer type"""
binary = "y"
"""binary function"""
pointer = "&"
"""pointer type"""
@dataclass(frozen=True)
class Builtin(ABC):
token: str
kind: ClassVar[SymbolKind]
@dataclass(frozen=True)
class Variable(Builtin):
kind: ClassVar[SymbolKind] = SymbolKind.Variable
typ: SkillDataType
default: str | None = None
@dataclass(frozen=True)
class AnonymousVariable(Builtin):
kind: ClassVar[SymbolKind] = SymbolKind.Variable
typ: SkillDataType
default: str | None = None
@dataclass(frozen=True)
class Procedure(Builtin):
kind: ClassVar[SymbolKind] = SymbolKind.Function
args: Mapping[str, Variable] = field(default_factory=dict)
rest: Variable | None = None
kwargs: Mapping[str, Variable] | Mapping[str, AnonymousVariable] = field(
default_factory=dict
)
"""list of ``Variable` if ``@key`` was used, and ``AnonymousVariable`` if ``@option`` was used"""
ret: SkillDataType = SkillDataType.nil
@property
def has_options(self) -> bool:
return bool(self.kwargs) and isinstance(
next(iter(self.kwargs.values())),
AnonymousVariable,
)
@property
def has_keys(self) -> bool:
return bool(self.kwargs) and isinstance(
next(iter(self.kwargs.values())),
Variable,
)
+6
View File
@@ -0,0 +1,6 @@
;; append
append(
l_list1
l_list2
) => l_result
+21
View File
@@ -0,0 +1,21 @@
from collections.abc import Mapping
from .common import Procedure, SkillDataType, Variable
NUM = SkillDataType.number
ANY = SkillDataType.general
FUNCTIONS: Mapping[str, Procedure] = {
"plus": Procedure(
"plus",
ret=NUM,
args={
"op1": Variable("op1", NUM),
"op2": Variable("op2", NUM),
},
rest=Variable("op3", NUM),
),
}
FUNCTIONS["plus"]