vex-ast 0.2.5__py3-none-any.whl → 0.2.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vex_ast/README.md +101 -51
- vex_ast/READMEAPI.md +133 -318
- vex_ast/__init__.py +81 -81
- vex_ast/ast/README.md +87 -87
- vex_ast/ast/__init__.py +74 -74
- vex_ast/ast/core.py +71 -71
- vex_ast/ast/expressions.py +276 -276
- vex_ast/ast/interfaces.py +208 -208
- vex_ast/ast/literals.py +80 -80
- vex_ast/ast/navigator.py +225 -225
- vex_ast/ast/operators.py +135 -135
- vex_ast/ast/statements.py +351 -351
- vex_ast/ast/validators.py +121 -121
- vex_ast/ast/vex_nodes.py +279 -279
- vex_ast/parser/README.md +47 -47
- vex_ast/parser/__init__.py +26 -26
- vex_ast/parser/factory.py +190 -190
- vex_ast/parser/interfaces.py +34 -34
- vex_ast/parser/python_parser.py +831 -831
- vex_ast/registry/README.md +107 -29
- vex_ast/registry/__init__.py +51 -51
- vex_ast/registry/api.py +190 -155
- vex_ast/registry/categories.py +179 -136
- vex_ast/registry/functions/__init__.py +10 -10
- vex_ast/registry/functions/constructors.py +71 -35
- vex_ast/registry/functions/display.py +146 -146
- vex_ast/registry/functions/drivetrain.py +163 -163
- vex_ast/registry/functions/initialize.py +31 -31
- vex_ast/registry/functions/motor.py +140 -140
- vex_ast/registry/functions/sensors.py +194 -194
- vex_ast/registry/functions/timing.py +103 -103
- vex_ast/registry/language_map.py +77 -77
- vex_ast/registry/registry.py +164 -153
- vex_ast/registry/signature.py +269 -191
- vex_ast/registry/simulation_behavior.py +8 -8
- vex_ast/registry/validation.py +43 -43
- vex_ast/serialization/__init__.py +37 -37
- vex_ast/serialization/json_deserializer.py +284 -284
- vex_ast/serialization/json_serializer.py +148 -148
- vex_ast/serialization/schema.py +492 -492
- vex_ast/types/README.md +78 -26
- vex_ast/types/__init__.py +140 -140
- vex_ast/types/base.py +83 -83
- vex_ast/types/enums.py +122 -122
- vex_ast/types/objects.py +64 -64
- vex_ast/types/primitives.py +68 -68
- vex_ast/types/type_checker.py +31 -31
- vex_ast/utils/README.md +39 -39
- vex_ast/utils/__init__.py +37 -37
- vex_ast/utils/errors.py +112 -112
- vex_ast/utils/source_location.py +38 -38
- vex_ast/utils/type_definitions.py +8 -8
- vex_ast/visitors/README.md +49 -49
- vex_ast/visitors/__init__.py +27 -27
- vex_ast/visitors/analyzer.py +102 -102
- vex_ast/visitors/base.py +133 -133
- vex_ast/visitors/printer.py +196 -196
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/METADATA +206 -174
- vex_ast-0.2.6.dist-info/RECORD +64 -0
- vex_ast-0.2.5.dist-info/RECORD +0 -64
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/WHEEL +0 -0
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/licenses/LICENSE +0 -0
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/top_level.txt +0 -0
vex_ast/types/README.md
CHANGED
@@ -1,26 +1,78 @@
|
|
1
|
-
# VEX AST Types Package (vex_ast.types)
|
2
|
-
|
3
|
-
This package defines the type system used for the VEX V5 Robot Python language.
|
4
|
-
|
5
|
-
Purpose
|
6
|
-
|
7
|
-
The type system provides a way to represent and reason about the types of values in VEX code. This information is used for type checking, code optimization, and other purposes.
|
8
|
-
|
9
|
-
Structure
|
10
|
-
|
11
|
-
The package is organized into several modules:
|
12
|
-
|
13
|
-
* `base.py`: Defines base classes for types.
|
14
|
-
* `enums.py`: Defines enums for different type categories.
|
15
|
-
* `objects.py`: Defines classes for representing objects.
|
16
|
-
* `primitives.py`: Defines classes for representing primitive types (e.g., int, float, string, boolean).
|
17
|
-
* `type_checker.py`: Implements the type checking logic.
|
18
|
-
|
19
|
-
Key Concepts
|
20
|
-
|
21
|
-
* Types
|
22
|
-
* Type checking
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
The type system
|
1
|
+
# VEX AST Types Package (vex_ast.types)
|
2
|
+
|
3
|
+
This package defines the type system used for the VEX V5 Robot Python language.
|
4
|
+
|
5
|
+
## Purpose
|
6
|
+
|
7
|
+
The type system provides a way to represent and reason about the types of values in VEX code. This information is used for type checking, code optimization, and other purposes.
|
8
|
+
|
9
|
+
## Structure
|
10
|
+
|
11
|
+
The package is organized into several modules:
|
12
|
+
|
13
|
+
* `base.py`: Defines base classes for types.
|
14
|
+
* `enums.py`: Defines enums for different type categories.
|
15
|
+
* `objects.py`: Defines classes for representing objects.
|
16
|
+
* `primitives.py`: Defines classes for representing primitive types (e.g., int, float, string, boolean).
|
17
|
+
* `type_checker.py`: Implements the type checking logic.
|
18
|
+
|
19
|
+
## Key Concepts
|
20
|
+
|
21
|
+
* **Types**: Represent the kind of value that a variable or expression can have.
|
22
|
+
* **Type checking**: The process of verifying that the types in a program are consistent.
|
23
|
+
|
24
|
+
## Integration with Registry
|
25
|
+
|
26
|
+
The type system integrates seamlessly with the registry's category system:
|
27
|
+
|
28
|
+
- Object types (MOTOR, BRAIN, etc.) correspond to VexCategory entries
|
29
|
+
- Enum types map to valid parameter values
|
30
|
+
- Type validation works with function signatures
|
31
|
+
|
32
|
+
## Recent Updates
|
33
|
+
|
34
|
+
- Support for new VEX object types (Brain, Controller)
|
35
|
+
- Enhanced compatibility checking with category system
|
36
|
+
- Improved enum type validation
|
37
|
+
- Better integration with registry validation
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
The type system is used internally by the VEX AST parser, type checker, and other tools. It is not typically accessed directly by users.
|
42
|
+
|
43
|
+
### Example Internal Usage
|
44
|
+
|
45
|
+
```python
|
46
|
+
from vex_ast.types import MOTOR, DIRECTION_TYPE, VELOCITY_UNITS
|
47
|
+
from vex_ast.types.type_checker import type_checker
|
48
|
+
|
49
|
+
# Validate parameter types
|
50
|
+
if type_checker.is_compatible(arg_type, MOTOR):
|
51
|
+
# Process motor argument
|
52
|
+
|
53
|
+
# Check enum values
|
54
|
+
if value in DIRECTION_TYPE.values:
|
55
|
+
# Valid direction value
|
56
|
+
```
|
57
|
+
|
58
|
+
## Type Hierarchy
|
59
|
+
|
60
|
+
```
|
61
|
+
VexType (base)
|
62
|
+
├── PrimitiveType
|
63
|
+
│ ├── NumericType
|
64
|
+
│ │ ├── IntegerType
|
65
|
+
│ │ └── FloatType
|
66
|
+
│ ├── BooleanType
|
67
|
+
│ └── StringType
|
68
|
+
├── ObjectType (MOTOR, BRAIN, etc.)
|
69
|
+
├── EnumType (DIRECTION_TYPE, etc.)
|
70
|
+
└── VoidType
|
71
|
+
```
|
72
|
+
|
73
|
+
## Future Extensions
|
74
|
+
|
75
|
+
- Support for custom object methods
|
76
|
+
- Advanced type inference
|
77
|
+
- Generic types for containers
|
78
|
+
- Union types for flexible parameters
|
vex_ast/types/__init__.py
CHANGED
@@ -1,140 +1,140 @@
|
|
1
|
-
"""
|
2
|
-
Types package for VEX AST.
|
3
|
-
|
4
|
-
This package provides type definitions and type checking functionality for VEX AST.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from .base import (
|
8
|
-
VexType,
|
9
|
-
VoidType,
|
10
|
-
AnyType,
|
11
|
-
TypeRegistry,
|
12
|
-
VOID,
|
13
|
-
ANY,
|
14
|
-
type_registry
|
15
|
-
)
|
16
|
-
|
17
|
-
from .primitives import (
|
18
|
-
PrimitiveType,
|
19
|
-
IntegerType,
|
20
|
-
FloatType,
|
21
|
-
BooleanType,
|
22
|
-
StringType,
|
23
|
-
INT,
|
24
|
-
FLOAT,
|
25
|
-
BOOL,
|
26
|
-
STRING
|
27
|
-
)
|
28
|
-
|
29
|
-
from .objects import (
|
30
|
-
ObjectType,
|
31
|
-
MOTOR,
|
32
|
-
MOTOR_GROUP,
|
33
|
-
DRIVETRAIN,
|
34
|
-
BRAIN,
|
35
|
-
CONTROLLER,
|
36
|
-
INERTIAL,
|
37
|
-
DISTANCE,
|
38
|
-
ROTATION,
|
39
|
-
OPTICAL,
|
40
|
-
GPS,
|
41
|
-
ELECTROMAGNETIC,
|
42
|
-
BRAIN_BATTERY,
|
43
|
-
BRAIN_SCREEN,
|
44
|
-
BRAIN_LCD,
|
45
|
-
COMPETITION,
|
46
|
-
TIMER,
|
47
|
-
BUMPER,
|
48
|
-
LIMIT_SWITCH,
|
49
|
-
ENCODER,
|
50
|
-
SONAR,
|
51
|
-
GYRO,
|
52
|
-
PNEUMATIC,
|
53
|
-
VISION
|
54
|
-
)
|
55
|
-
|
56
|
-
from .enums import (
|
57
|
-
EnumType,
|
58
|
-
DIRECTION_TYPE,
|
59
|
-
TURN_TYPE,
|
60
|
-
BRAKE_TYPE,
|
61
|
-
VELOCITY_UNITS,
|
62
|
-
ROTATION_UNITS,
|
63
|
-
TIME_UNITS,
|
64
|
-
DISTANCE_UNITS,
|
65
|
-
CURRENT_UNITS,
|
66
|
-
TORQUE_UNITS,
|
67
|
-
TEMPERATURE_UNITS,
|
68
|
-
ANALOG_UNITS
|
69
|
-
)
|
70
|
-
|
71
|
-
from .type_checker import (
|
72
|
-
TypeChecker,
|
73
|
-
type_checker as check_type_compatibility
|
74
|
-
)
|
75
|
-
|
76
|
-
__all__ = [
|
77
|
-
# Base types
|
78
|
-
"VexType",
|
79
|
-
"VoidType",
|
80
|
-
"AnyType",
|
81
|
-
"TypeRegistry",
|
82
|
-
"VOID",
|
83
|
-
"ANY",
|
84
|
-
"type_registry",
|
85
|
-
|
86
|
-
# Primitive types
|
87
|
-
"PrimitiveType",
|
88
|
-
"IntegerType",
|
89
|
-
"FloatType",
|
90
|
-
"BooleanType",
|
91
|
-
"StringType",
|
92
|
-
"INT",
|
93
|
-
"FLOAT",
|
94
|
-
"BOOL",
|
95
|
-
"STRING",
|
96
|
-
|
97
|
-
# Object types
|
98
|
-
"ObjectType",
|
99
|
-
"MOTOR",
|
100
|
-
"MOTOR_GROUP",
|
101
|
-
"DRIVETRAIN",
|
102
|
-
"BRAIN",
|
103
|
-
"CONTROLLER",
|
104
|
-
"INERTIAL",
|
105
|
-
"DISTANCE",
|
106
|
-
"ROTATION",
|
107
|
-
"OPTICAL",
|
108
|
-
"GPS",
|
109
|
-
"ELECTROMAGNETIC",
|
110
|
-
"BRAIN_BATTERY",
|
111
|
-
"BRAIN_SCREEN",
|
112
|
-
"BRAIN_LCD",
|
113
|
-
"COMPETITION",
|
114
|
-
"TIMER",
|
115
|
-
"BUMPER",
|
116
|
-
"LIMIT_SWITCH",
|
117
|
-
"ENCODER",
|
118
|
-
"SONAR",
|
119
|
-
"GYRO",
|
120
|
-
"PNEUMATIC",
|
121
|
-
"VISION",
|
122
|
-
|
123
|
-
# Enum types
|
124
|
-
"EnumType",
|
125
|
-
"DIRECTION_TYPE",
|
126
|
-
"TURN_TYPE",
|
127
|
-
"BRAKE_TYPE",
|
128
|
-
"VELOCITY_UNITS",
|
129
|
-
"ROTATION_UNITS",
|
130
|
-
"TIME_UNITS",
|
131
|
-
"DISTANCE_UNITS",
|
132
|
-
"CURRENT_UNITS",
|
133
|
-
"TORQUE_UNITS",
|
134
|
-
"TEMPERATURE_UNITS",
|
135
|
-
"ANALOG_UNITS",
|
136
|
-
|
137
|
-
# Type checking
|
138
|
-
"TypeChecker",
|
139
|
-
"check_type_compatibility"
|
140
|
-
]
|
1
|
+
"""
|
2
|
+
Types package for VEX AST.
|
3
|
+
|
4
|
+
This package provides type definitions and type checking functionality for VEX AST.
|
5
|
+
"""
|
6
|
+
|
7
|
+
from .base import (
|
8
|
+
VexType,
|
9
|
+
VoidType,
|
10
|
+
AnyType,
|
11
|
+
TypeRegistry,
|
12
|
+
VOID,
|
13
|
+
ANY,
|
14
|
+
type_registry
|
15
|
+
)
|
16
|
+
|
17
|
+
from .primitives import (
|
18
|
+
PrimitiveType,
|
19
|
+
IntegerType,
|
20
|
+
FloatType,
|
21
|
+
BooleanType,
|
22
|
+
StringType,
|
23
|
+
INT,
|
24
|
+
FLOAT,
|
25
|
+
BOOL,
|
26
|
+
STRING
|
27
|
+
)
|
28
|
+
|
29
|
+
from .objects import (
|
30
|
+
ObjectType,
|
31
|
+
MOTOR,
|
32
|
+
MOTOR_GROUP,
|
33
|
+
DRIVETRAIN,
|
34
|
+
BRAIN,
|
35
|
+
CONTROLLER,
|
36
|
+
INERTIAL,
|
37
|
+
DISTANCE,
|
38
|
+
ROTATION,
|
39
|
+
OPTICAL,
|
40
|
+
GPS,
|
41
|
+
ELECTROMAGNETIC,
|
42
|
+
BRAIN_BATTERY,
|
43
|
+
BRAIN_SCREEN,
|
44
|
+
BRAIN_LCD,
|
45
|
+
COMPETITION,
|
46
|
+
TIMER,
|
47
|
+
BUMPER,
|
48
|
+
LIMIT_SWITCH,
|
49
|
+
ENCODER,
|
50
|
+
SONAR,
|
51
|
+
GYRO,
|
52
|
+
PNEUMATIC,
|
53
|
+
VISION
|
54
|
+
)
|
55
|
+
|
56
|
+
from .enums import (
|
57
|
+
EnumType,
|
58
|
+
DIRECTION_TYPE,
|
59
|
+
TURN_TYPE,
|
60
|
+
BRAKE_TYPE,
|
61
|
+
VELOCITY_UNITS,
|
62
|
+
ROTATION_UNITS,
|
63
|
+
TIME_UNITS,
|
64
|
+
DISTANCE_UNITS,
|
65
|
+
CURRENT_UNITS,
|
66
|
+
TORQUE_UNITS,
|
67
|
+
TEMPERATURE_UNITS,
|
68
|
+
ANALOG_UNITS
|
69
|
+
)
|
70
|
+
|
71
|
+
from .type_checker import (
|
72
|
+
TypeChecker,
|
73
|
+
type_checker as check_type_compatibility
|
74
|
+
)
|
75
|
+
|
76
|
+
__all__ = [
|
77
|
+
# Base types
|
78
|
+
"VexType",
|
79
|
+
"VoidType",
|
80
|
+
"AnyType",
|
81
|
+
"TypeRegistry",
|
82
|
+
"VOID",
|
83
|
+
"ANY",
|
84
|
+
"type_registry",
|
85
|
+
|
86
|
+
# Primitive types
|
87
|
+
"PrimitiveType",
|
88
|
+
"IntegerType",
|
89
|
+
"FloatType",
|
90
|
+
"BooleanType",
|
91
|
+
"StringType",
|
92
|
+
"INT",
|
93
|
+
"FLOAT",
|
94
|
+
"BOOL",
|
95
|
+
"STRING",
|
96
|
+
|
97
|
+
# Object types
|
98
|
+
"ObjectType",
|
99
|
+
"MOTOR",
|
100
|
+
"MOTOR_GROUP",
|
101
|
+
"DRIVETRAIN",
|
102
|
+
"BRAIN",
|
103
|
+
"CONTROLLER",
|
104
|
+
"INERTIAL",
|
105
|
+
"DISTANCE",
|
106
|
+
"ROTATION",
|
107
|
+
"OPTICAL",
|
108
|
+
"GPS",
|
109
|
+
"ELECTROMAGNETIC",
|
110
|
+
"BRAIN_BATTERY",
|
111
|
+
"BRAIN_SCREEN",
|
112
|
+
"BRAIN_LCD",
|
113
|
+
"COMPETITION",
|
114
|
+
"TIMER",
|
115
|
+
"BUMPER",
|
116
|
+
"LIMIT_SWITCH",
|
117
|
+
"ENCODER",
|
118
|
+
"SONAR",
|
119
|
+
"GYRO",
|
120
|
+
"PNEUMATIC",
|
121
|
+
"VISION",
|
122
|
+
|
123
|
+
# Enum types
|
124
|
+
"EnumType",
|
125
|
+
"DIRECTION_TYPE",
|
126
|
+
"TURN_TYPE",
|
127
|
+
"BRAKE_TYPE",
|
128
|
+
"VELOCITY_UNITS",
|
129
|
+
"ROTATION_UNITS",
|
130
|
+
"TIME_UNITS",
|
131
|
+
"DISTANCE_UNITS",
|
132
|
+
"CURRENT_UNITS",
|
133
|
+
"TORQUE_UNITS",
|
134
|
+
"TEMPERATURE_UNITS",
|
135
|
+
"ANALOG_UNITS",
|
136
|
+
|
137
|
+
# Type checking
|
138
|
+
"TypeChecker",
|
139
|
+
"check_type_compatibility"
|
140
|
+
]
|
vex_ast/types/base.py
CHANGED
@@ -1,84 +1,84 @@
|
|
1
|
-
from abc import ABC, abstractmethod
|
2
|
-
from typing import Any, Optional, Union, List, Type, Set, TypeVar, Generic
|
3
|
-
|
4
|
-
class VexType(ABC):
|
5
|
-
"""Base abstract class for all VEX types"""
|
6
|
-
|
7
|
-
@property
|
8
|
-
@abstractmethod
|
9
|
-
def name(self) -> str:
|
10
|
-
"""Return the canonical name of this type"""
|
11
|
-
pass
|
12
|
-
|
13
|
-
@abstractmethod
|
14
|
-
def is_compatible_with(self, other: 'VexType') -> bool:
|
15
|
-
"""Check if this type is compatible with another type"""
|
16
|
-
pass
|
17
|
-
|
18
|
-
@abstractmethod
|
19
|
-
def __str__(self) -> str:
|
20
|
-
"""String representation of the type"""
|
21
|
-
pass
|
22
|
-
|
23
|
-
def __eq__(self, other) -> bool:
|
24
|
-
if not isinstance(other, VexType):
|
25
|
-
return False
|
26
|
-
return self.name == other.name
|
27
|
-
|
28
|
-
class VoidType(VexType):
|
29
|
-
"""Represents the void type (no return value)"""
|
30
|
-
|
31
|
-
@property
|
32
|
-
def name(self) -> str:
|
33
|
-
return "void"
|
34
|
-
|
35
|
-
def is_compatible_with(self, other: VexType) -> bool:
|
36
|
-
return isinstance(other, VoidType)
|
37
|
-
|
38
|
-
def __str__(self) -> str:
|
39
|
-
return "void"
|
40
|
-
|
41
|
-
class AnyType(VexType):
|
42
|
-
"""Represents any type (for generic functions)"""
|
43
|
-
|
44
|
-
@property
|
45
|
-
def name(self) -> str:
|
46
|
-
return "any"
|
47
|
-
|
48
|
-
def is_compatible_with(self, other: VexType) -> bool:
|
49
|
-
return True # Any type is compatible with all types
|
50
|
-
|
51
|
-
def __str__(self) -> str:
|
52
|
-
return "any"
|
53
|
-
|
54
|
-
class TypeRegistry:
|
55
|
-
"""Global registry of types to ensure type uniqueness"""
|
56
|
-
|
57
|
-
_instance = None
|
58
|
-
|
59
|
-
def __new__(cls):
|
60
|
-
if cls._instance is None:
|
61
|
-
cls._instance = super(TypeRegistry, cls).__new__(cls)
|
62
|
-
cls._instance._types = {}
|
63
|
-
return cls._instance
|
64
|
-
|
65
|
-
def register_type(self, type_: VexType) -> None:
|
66
|
-
"""Register a type in the registry"""
|
67
|
-
self._types[type_.name] = type_
|
68
|
-
|
69
|
-
def get_type(self, name: str) -> Optional[VexType]:
|
70
|
-
"""Get a type by name"""
|
71
|
-
return self._types.get(name)
|
72
|
-
|
73
|
-
def get_all_types(self) -> List[VexType]:
|
74
|
-
"""Get all registered types"""
|
75
|
-
return list(self._types.values())
|
76
|
-
|
77
|
-
# Singleton instances
|
78
|
-
VOID = VoidType()
|
79
|
-
ANY = AnyType()
|
80
|
-
|
81
|
-
# Global registry
|
82
|
-
type_registry = TypeRegistry()
|
83
|
-
type_registry.register_type(VOID)
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from typing import Any, Optional, Union, List, Type, Set, TypeVar, Generic
|
3
|
+
|
4
|
+
class VexType(ABC):
|
5
|
+
"""Base abstract class for all VEX types"""
|
6
|
+
|
7
|
+
@property
|
8
|
+
@abstractmethod
|
9
|
+
def name(self) -> str:
|
10
|
+
"""Return the canonical name of this type"""
|
11
|
+
pass
|
12
|
+
|
13
|
+
@abstractmethod
|
14
|
+
def is_compatible_with(self, other: 'VexType') -> bool:
|
15
|
+
"""Check if this type is compatible with another type"""
|
16
|
+
pass
|
17
|
+
|
18
|
+
@abstractmethod
|
19
|
+
def __str__(self) -> str:
|
20
|
+
"""String representation of the type"""
|
21
|
+
pass
|
22
|
+
|
23
|
+
def __eq__(self, other) -> bool:
|
24
|
+
if not isinstance(other, VexType):
|
25
|
+
return False
|
26
|
+
return self.name == other.name
|
27
|
+
|
28
|
+
class VoidType(VexType):
|
29
|
+
"""Represents the void type (no return value)"""
|
30
|
+
|
31
|
+
@property
|
32
|
+
def name(self) -> str:
|
33
|
+
return "void"
|
34
|
+
|
35
|
+
def is_compatible_with(self, other: VexType) -> bool:
|
36
|
+
return isinstance(other, VoidType)
|
37
|
+
|
38
|
+
def __str__(self) -> str:
|
39
|
+
return "void"
|
40
|
+
|
41
|
+
class AnyType(VexType):
|
42
|
+
"""Represents any type (for generic functions)"""
|
43
|
+
|
44
|
+
@property
|
45
|
+
def name(self) -> str:
|
46
|
+
return "any"
|
47
|
+
|
48
|
+
def is_compatible_with(self, other: VexType) -> bool:
|
49
|
+
return True # Any type is compatible with all types
|
50
|
+
|
51
|
+
def __str__(self) -> str:
|
52
|
+
return "any"
|
53
|
+
|
54
|
+
class TypeRegistry:
|
55
|
+
"""Global registry of types to ensure type uniqueness"""
|
56
|
+
|
57
|
+
_instance = None
|
58
|
+
|
59
|
+
def __new__(cls):
|
60
|
+
if cls._instance is None:
|
61
|
+
cls._instance = super(TypeRegistry, cls).__new__(cls)
|
62
|
+
cls._instance._types = {}
|
63
|
+
return cls._instance
|
64
|
+
|
65
|
+
def register_type(self, type_: VexType) -> None:
|
66
|
+
"""Register a type in the registry"""
|
67
|
+
self._types[type_.name] = type_
|
68
|
+
|
69
|
+
def get_type(self, name: str) -> Optional[VexType]:
|
70
|
+
"""Get a type by name"""
|
71
|
+
return self._types.get(name)
|
72
|
+
|
73
|
+
def get_all_types(self) -> List[VexType]:
|
74
|
+
"""Get all registered types"""
|
75
|
+
return list(self._types.values())
|
76
|
+
|
77
|
+
# Singleton instances
|
78
|
+
VOID = VoidType()
|
79
|
+
ANY = AnyType()
|
80
|
+
|
81
|
+
# Global registry
|
82
|
+
type_registry = TypeRegistry()
|
83
|
+
type_registry.register_type(VOID)
|
84
84
|
type_registry.register_type(ANY)
|