vex-ast 0.2.0__py3-none-any.whl → 0.2.1__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/__init__.py +20 -17
- vex_ast/ast/__init__.py +1 -1
- vex_ast/ast/navigator.py +12 -0
- vex_ast/parser/__init__.py +27 -0
- vex_ast/registry/functions/__init__.py +11 -0
- vex_ast/registry/functions/display.py +147 -0
- vex_ast/registry/functions/drivetrain.py +163 -0
- vex_ast/registry/functions/initialize.py +28 -0
- vex_ast/registry/functions/motor.py +140 -0
- vex_ast/registry/functions/sensors.py +195 -0
- vex_ast/registry/functions/timing.py +104 -0
- vex_ast/types/__init__.py +140 -0
- vex_ast/types/base.py +84 -0
- vex_ast/types/enums.py +97 -0
- vex_ast/types/objects.py +64 -0
- vex_ast/types/primitives.py +69 -0
- vex_ast/types/type_checker.py +32 -0
- vex_ast/utils/__init__.py +38 -0
- vex_ast/utils/type_definitions.py +9 -0
- vex_ast/visitors/__init__.py +28 -0
- {vex_ast-0.2.0.dist-info → vex_ast-0.2.1.dist-info}/METADATA +1 -1
- {vex_ast-0.2.0.dist-info → vex_ast-0.2.1.dist-info}/RECORD +25 -12
- {vex_ast-0.2.0.dist-info → vex_ast-0.2.1.dist-info}/WHEEL +0 -0
- {vex_ast-0.2.0.dist-info → vex_ast-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {vex_ast-0.2.0.dist-info → vex_ast-0.2.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,195 @@
|
|
1
|
+
from ..registry import registry
|
2
|
+
from ..signature import VexFunctionSignature, VexFunctionParameter, ParameterMode, SimulationCategory
|
3
|
+
from ...types.base import VOID, ANY
|
4
|
+
from ...types.primitives import INT, FLOAT, BOOL
|
5
|
+
from ...types.enums import DISTANCE_UNITS, ROTATION_UNITS, VELOCITY_UNITS
|
6
|
+
from ...types.objects import DISTANCE, ROTATION, INERTIAL, OPTICAL, GPS
|
7
|
+
|
8
|
+
def register_sensor_functions():
|
9
|
+
"""Register sensor-related functions in the registry"""
|
10
|
+
|
11
|
+
# Distance sensor functions
|
12
|
+
|
13
|
+
# Distance.object_distance() method
|
14
|
+
object_distance_params = [
|
15
|
+
VexFunctionParameter("units", DISTANCE_UNITS, "MM", description="Distance units")
|
16
|
+
]
|
17
|
+
|
18
|
+
object_distance_signature = VexFunctionSignature(
|
19
|
+
name="object_distance",
|
20
|
+
return_type=FLOAT,
|
21
|
+
parameters=object_distance_params,
|
22
|
+
description="Get the distance to the detected object",
|
23
|
+
category=SimulationCategory.SENSOR_READING,
|
24
|
+
python_name="object_distance",
|
25
|
+
cpp_name="objectDistance",
|
26
|
+
object_type=DISTANCE,
|
27
|
+
method_name="object_distance"
|
28
|
+
)
|
29
|
+
|
30
|
+
registry.register_function(object_distance_signature)
|
31
|
+
|
32
|
+
# Distance.is_object_detected() method
|
33
|
+
is_object_detected_signature = VexFunctionSignature(
|
34
|
+
name="is_object_detected",
|
35
|
+
return_type=BOOL,
|
36
|
+
parameters=[],
|
37
|
+
description="Check if an object is detected",
|
38
|
+
category=SimulationCategory.SENSOR_READING,
|
39
|
+
python_name="is_object_detected",
|
40
|
+
cpp_name="isObjectDetected",
|
41
|
+
object_type=DISTANCE,
|
42
|
+
method_name="is_object_detected"
|
43
|
+
)
|
44
|
+
|
45
|
+
registry.register_function(is_object_detected_signature)
|
46
|
+
|
47
|
+
# Rotation sensor functions
|
48
|
+
|
49
|
+
# Rotation.angle() method
|
50
|
+
angle_params = [
|
51
|
+
VexFunctionParameter("units", ROTATION_UNITS, "DEGREES", description="Rotation units")
|
52
|
+
]
|
53
|
+
|
54
|
+
angle_signature = VexFunctionSignature(
|
55
|
+
name="angle",
|
56
|
+
return_type=FLOAT,
|
57
|
+
parameters=angle_params,
|
58
|
+
description="Get the angle of the rotation sensor",
|
59
|
+
category=SimulationCategory.SENSOR_READING,
|
60
|
+
python_name="angle",
|
61
|
+
cpp_name="angle",
|
62
|
+
object_type=ROTATION,
|
63
|
+
method_name="angle"
|
64
|
+
)
|
65
|
+
|
66
|
+
registry.register_function(angle_signature)
|
67
|
+
|
68
|
+
# Rotation.reset_position() method
|
69
|
+
reset_position_signature = VexFunctionSignature(
|
70
|
+
name="reset_position",
|
71
|
+
return_type=VOID,
|
72
|
+
parameters=[],
|
73
|
+
description="Reset the position of the rotation sensor",
|
74
|
+
category=SimulationCategory.SENSOR_READING,
|
75
|
+
python_name="reset_position",
|
76
|
+
cpp_name="resetPosition",
|
77
|
+
object_type=ROTATION,
|
78
|
+
method_name="reset_position"
|
79
|
+
)
|
80
|
+
|
81
|
+
registry.register_function(reset_position_signature)
|
82
|
+
|
83
|
+
# Rotation.set_position() method
|
84
|
+
set_position_params = [
|
85
|
+
VexFunctionParameter("value", FLOAT, description="Position value to set"),
|
86
|
+
VexFunctionParameter("units", ROTATION_UNITS, "DEGREES", description="Rotation units")
|
87
|
+
]
|
88
|
+
|
89
|
+
set_position_signature = VexFunctionSignature(
|
90
|
+
name="set_position",
|
91
|
+
return_type=VOID,
|
92
|
+
parameters=set_position_params,
|
93
|
+
description="Set the position of the rotation sensor",
|
94
|
+
category=SimulationCategory.SENSOR_READING,
|
95
|
+
python_name="set_position",
|
96
|
+
cpp_name="setPosition",
|
97
|
+
object_type=ROTATION,
|
98
|
+
method_name="set_position"
|
99
|
+
)
|
100
|
+
|
101
|
+
registry.register_function(set_position_signature)
|
102
|
+
|
103
|
+
# Rotation.velocity() method
|
104
|
+
velocity_params = [
|
105
|
+
VexFunctionParameter("units", VELOCITY_UNITS, "RPM", description="Velocity units")
|
106
|
+
]
|
107
|
+
|
108
|
+
velocity_signature = VexFunctionSignature(
|
109
|
+
name="velocity",
|
110
|
+
return_type=FLOAT,
|
111
|
+
parameters=velocity_params,
|
112
|
+
description="Get the velocity of the rotation sensor",
|
113
|
+
category=SimulationCategory.SENSOR_READING,
|
114
|
+
python_name="velocity",
|
115
|
+
cpp_name="velocity",
|
116
|
+
object_type=ROTATION,
|
117
|
+
method_name="velocity"
|
118
|
+
)
|
119
|
+
|
120
|
+
registry.register_function(velocity_signature)
|
121
|
+
|
122
|
+
# Inertial sensor functions
|
123
|
+
|
124
|
+
# Inertial.calibrate() method
|
125
|
+
calibrate_signature = VexFunctionSignature(
|
126
|
+
name="calibrate",
|
127
|
+
return_type=VOID,
|
128
|
+
parameters=[],
|
129
|
+
description="Calibrate the inertial sensor",
|
130
|
+
category=SimulationCategory.SENSOR_READING,
|
131
|
+
python_name="calibrate",
|
132
|
+
cpp_name="calibrate",
|
133
|
+
object_type=INERTIAL,
|
134
|
+
method_name="calibrate"
|
135
|
+
)
|
136
|
+
|
137
|
+
registry.register_function(calibrate_signature)
|
138
|
+
|
139
|
+
# Inertial.is_calibrating() method
|
140
|
+
is_calibrating_signature = VexFunctionSignature(
|
141
|
+
name="is_calibrating",
|
142
|
+
return_type=BOOL,
|
143
|
+
parameters=[],
|
144
|
+
description="Check if the inertial sensor is calibrating",
|
145
|
+
category=SimulationCategory.SENSOR_READING,
|
146
|
+
python_name="is_calibrating",
|
147
|
+
cpp_name="isCalibrating",
|
148
|
+
object_type=INERTIAL,
|
149
|
+
method_name="is_calibrating"
|
150
|
+
)
|
151
|
+
|
152
|
+
registry.register_function(is_calibrating_signature)
|
153
|
+
|
154
|
+
# Inertial.heading() method
|
155
|
+
heading_params = [
|
156
|
+
VexFunctionParameter("units", ROTATION_UNITS, "DEGREES", description="Rotation units")
|
157
|
+
]
|
158
|
+
|
159
|
+
heading_signature = VexFunctionSignature(
|
160
|
+
name="heading",
|
161
|
+
return_type=FLOAT,
|
162
|
+
parameters=heading_params,
|
163
|
+
description="Get the heading of the inertial sensor",
|
164
|
+
category=SimulationCategory.SENSOR_READING,
|
165
|
+
python_name="heading",
|
166
|
+
cpp_name="heading",
|
167
|
+
object_type=INERTIAL,
|
168
|
+
method_name="heading"
|
169
|
+
)
|
170
|
+
|
171
|
+
registry.register_function(heading_signature)
|
172
|
+
|
173
|
+
# Inertial.rotation() method
|
174
|
+
rotation_params = [
|
175
|
+
VexFunctionParameter("units", ROTATION_UNITS, "DEGREES", description="Rotation units")
|
176
|
+
]
|
177
|
+
|
178
|
+
rotation_signature = VexFunctionSignature(
|
179
|
+
name="rotation",
|
180
|
+
return_type=FLOAT,
|
181
|
+
parameters=rotation_params,
|
182
|
+
description="Get the rotation of the inertial sensor",
|
183
|
+
category=SimulationCategory.SENSOR_READING,
|
184
|
+
python_name="rotation",
|
185
|
+
cpp_name="rotation",
|
186
|
+
object_type=INERTIAL,
|
187
|
+
method_name="rotation"
|
188
|
+
)
|
189
|
+
|
190
|
+
registry.register_function(rotation_signature)
|
191
|
+
|
192
|
+
# Add more sensor functions for other sensor types...
|
193
|
+
|
194
|
+
if __name__ == "__main__":
|
195
|
+
register_sensor_functions()
|
@@ -0,0 +1,104 @@
|
|
1
|
+
from ..registry import registry
|
2
|
+
from ..signature import VexFunctionSignature, VexFunctionParameter, ParameterMode, SimulationCategory
|
3
|
+
from ...types.base import VOID, ANY
|
4
|
+
from ...types.primitives import INT, FLOAT, BOOL
|
5
|
+
from ...types.enums import TIME_UNITS
|
6
|
+
from ...types.objects import TIMER
|
7
|
+
|
8
|
+
def register_timing_functions():
|
9
|
+
"""Register timing-related functions in the registry"""
|
10
|
+
|
11
|
+
# Global wait function
|
12
|
+
wait_params = [
|
13
|
+
VexFunctionParameter("time", FLOAT, description="Time to wait"),
|
14
|
+
VexFunctionParameter("units", TIME_UNITS, "MSEC", description="Time units")
|
15
|
+
]
|
16
|
+
|
17
|
+
wait_signature = VexFunctionSignature(
|
18
|
+
name="wait",
|
19
|
+
return_type=VOID,
|
20
|
+
parameters=wait_params,
|
21
|
+
description="Wait for a specified amount of time",
|
22
|
+
category=SimulationCategory.TIMING_CONTROL,
|
23
|
+
python_name="wait",
|
24
|
+
cpp_name="wait"
|
25
|
+
)
|
26
|
+
|
27
|
+
registry.register_function(wait_signature)
|
28
|
+
|
29
|
+
# Timer functions
|
30
|
+
|
31
|
+
# Timer.time() method
|
32
|
+
time_params = [
|
33
|
+
VexFunctionParameter("units", TIME_UNITS, "MSEC", description="Time units")
|
34
|
+
]
|
35
|
+
|
36
|
+
time_signature = VexFunctionSignature(
|
37
|
+
name="time",
|
38
|
+
return_type=FLOAT,
|
39
|
+
parameters=time_params,
|
40
|
+
description="Get the current time of the timer",
|
41
|
+
category=SimulationCategory.TIMING_CONTROL,
|
42
|
+
python_name="time",
|
43
|
+
cpp_name="time",
|
44
|
+
object_type=TIMER,
|
45
|
+
method_name="time"
|
46
|
+
)
|
47
|
+
|
48
|
+
registry.register_function(time_signature)
|
49
|
+
|
50
|
+
# Timer.clear() method
|
51
|
+
clear_signature = VexFunctionSignature(
|
52
|
+
name="clear",
|
53
|
+
return_type=VOID,
|
54
|
+
parameters=[],
|
55
|
+
description="Clear the timer",
|
56
|
+
category=SimulationCategory.TIMING_CONTROL,
|
57
|
+
python_name="clear",
|
58
|
+
cpp_name="clear",
|
59
|
+
object_type=TIMER,
|
60
|
+
method_name="clear"
|
61
|
+
)
|
62
|
+
|
63
|
+
registry.register_function(clear_signature)
|
64
|
+
|
65
|
+
# Timer.reset() method
|
66
|
+
reset_signature = VexFunctionSignature(
|
67
|
+
name="reset",
|
68
|
+
return_type=VOID,
|
69
|
+
parameters=[],
|
70
|
+
description="Reset the timer",
|
71
|
+
category=SimulationCategory.TIMING_CONTROL,
|
72
|
+
python_name="reset",
|
73
|
+
cpp_name="reset",
|
74
|
+
object_type=TIMER,
|
75
|
+
method_name="reset"
|
76
|
+
)
|
77
|
+
|
78
|
+
registry.register_function(reset_signature)
|
79
|
+
|
80
|
+
# Timer.event() method
|
81
|
+
event_params = [
|
82
|
+
VexFunctionParameter("callback", ANY, description="Callback function to execute"),
|
83
|
+
VexFunctionParameter("delay", FLOAT, description="Time delay before callback execution"),
|
84
|
+
VexFunctionParameter("units", TIME_UNITS, "MSEC", description="Time units")
|
85
|
+
]
|
86
|
+
|
87
|
+
event_signature = VexFunctionSignature(
|
88
|
+
name="event",
|
89
|
+
return_type=VOID,
|
90
|
+
parameters=event_params,
|
91
|
+
description="Register a callback function to be called after a delay",
|
92
|
+
category=SimulationCategory.EVENT_HANDLING,
|
93
|
+
python_name="event",
|
94
|
+
cpp_name="event",
|
95
|
+
object_type=TIMER,
|
96
|
+
method_name="event"
|
97
|
+
)
|
98
|
+
|
99
|
+
registry.register_function(event_signature)
|
100
|
+
|
101
|
+
# Add more timing functions as needed...
|
102
|
+
|
103
|
+
if __name__ == "__main__":
|
104
|
+
register_timing_functions()
|
@@ -0,0 +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
|
+
]
|
vex_ast/types/base.py
ADDED
@@ -0,0 +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)
|
84
|
+
type_registry.register_type(ANY)
|
vex_ast/types/enums.py
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
from typing import Dict, List, Any, Optional, Set
|
2
|
+
from .base import VexType, type_registry
|
3
|
+
from .primitives import StringType, IntegerType, INT
|
4
|
+
|
5
|
+
class EnumType(VexType):
|
6
|
+
"""Represents a VEX enum type"""
|
7
|
+
|
8
|
+
def __init__(self, name: str, values: Dict[str, Any] = None):
|
9
|
+
self._name = name
|
10
|
+
self._values = values or {}
|
11
|
+
type_registry.register_type(self)
|
12
|
+
|
13
|
+
@property
|
14
|
+
def name(self) -> str:
|
15
|
+
return self._name
|
16
|
+
|
17
|
+
@property
|
18
|
+
def values(self) -> Dict[str, Any]:
|
19
|
+
return self._values.copy()
|
20
|
+
|
21
|
+
def is_compatible_with(self, other: VexType) -> bool:
|
22
|
+
"""Enums are compatible with themselves or with integers"""
|
23
|
+
return isinstance(other, EnumType) and self.name == other.name or isinstance(other, IntegerType)
|
24
|
+
|
25
|
+
def __str__(self) -> str:
|
26
|
+
return f"enum {self._name}"
|
27
|
+
|
28
|
+
def add_value(self, name: str, value: Any) -> None:
|
29
|
+
"""Add a value to the enum"""
|
30
|
+
self._values[name] = value
|
31
|
+
|
32
|
+
def is_valid_value(self, value: Any) -> bool:
|
33
|
+
"""Check if a value is valid for this enum"""
|
34
|
+
return value in self._values.values() or value in self._values
|
35
|
+
|
36
|
+
# Create VEX enum types
|
37
|
+
DIRECTION_TYPE = EnumType("DirectionType", {
|
38
|
+
"FORWARD": 0,
|
39
|
+
"REVERSE": 1
|
40
|
+
})
|
41
|
+
|
42
|
+
TURN_TYPE = EnumType("TurnType", {
|
43
|
+
"LEFT": 0,
|
44
|
+
"RIGHT": 1
|
45
|
+
})
|
46
|
+
|
47
|
+
BRAKE_TYPE = EnumType("BrakeType", {
|
48
|
+
"COAST": 0,
|
49
|
+
"BRAKE": 1,
|
50
|
+
"HOLD": 2
|
51
|
+
})
|
52
|
+
|
53
|
+
VELOCITY_UNITS = EnumType("VelocityUnits", {
|
54
|
+
"PCT": 0, # Percentage
|
55
|
+
"RPM": 1, # Revolutions per minute
|
56
|
+
"DPS": 2 # Degrees per second
|
57
|
+
})
|
58
|
+
|
59
|
+
ROTATION_UNITS = EnumType("RotationUnits", {
|
60
|
+
"DEG": 0, # Degrees
|
61
|
+
"REV": 1, # Revolutions
|
62
|
+
"RAW": 2 # Raw data
|
63
|
+
})
|
64
|
+
|
65
|
+
TIME_UNITS = EnumType("TimeUnits", {
|
66
|
+
"SEC": 0, # Seconds
|
67
|
+
"MSEC": 1 # Milliseconds
|
68
|
+
})
|
69
|
+
|
70
|
+
DISTANCE_UNITS = EnumType("DistanceUnits", {
|
71
|
+
"MM": 0, # Millimeters
|
72
|
+
"IN": 1 # Inches
|
73
|
+
})
|
74
|
+
|
75
|
+
CURRENT_UNITS = EnumType("CurrentUnits", {
|
76
|
+
"AMP": 0 # Amperes
|
77
|
+
})
|
78
|
+
|
79
|
+
TORQUE_UNITS = EnumType("TorqueUnits", {
|
80
|
+
"NM": 0, # Newton meters
|
81
|
+
"INLB": 1 # Inch pounds
|
82
|
+
})
|
83
|
+
|
84
|
+
TEMPERATURE_UNITS = EnumType("TemperatureUnits", {
|
85
|
+
"CELSIUS": 0,
|
86
|
+
"FAHRENHEIT": 1
|
87
|
+
})
|
88
|
+
|
89
|
+
ANALOG_UNITS = EnumType("AnalogUnits", {
|
90
|
+
"PCT": 0, # Percentage
|
91
|
+
"EIGHTBIT": 1, # 8-bit (0-255)
|
92
|
+
"TENBIT": 2, # 10-bit (0-1023)
|
93
|
+
"TWELVEBIT": 3, # 12-bit (0-4095)
|
94
|
+
"MV": 4 # Millivolts
|
95
|
+
})
|
96
|
+
|
97
|
+
# Add more VEX enum types as needed
|
vex_ast/types/objects.py
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
from typing import Optional, List, Dict, Any, Set, TYPE_CHECKING
|
2
|
+
from .base import VexType, type_registry
|
3
|
+
|
4
|
+
# Use TYPE_CHECKING to avoid circular imports
|
5
|
+
if TYPE_CHECKING:
|
6
|
+
from ..registry.signature import VexFunctionSignature
|
7
|
+
|
8
|
+
class ObjectType(VexType):
|
9
|
+
"""Base class for all VEX object types (motors, sensors, etc.)"""
|
10
|
+
|
11
|
+
def __init__(self, name: str, methods: Dict[str, 'VexFunctionSignature'] = None):
|
12
|
+
self._name = name
|
13
|
+
self._methods = methods or {}
|
14
|
+
type_registry.register_type(self)
|
15
|
+
|
16
|
+
@property
|
17
|
+
def name(self) -> str:
|
18
|
+
return self._name
|
19
|
+
|
20
|
+
@property
|
21
|
+
def methods(self) -> Dict[str, Any]: # Use Any instead of forward reference
|
22
|
+
return self._methods
|
23
|
+
|
24
|
+
def add_method(self, method_name: str, signature: Any) -> None: # Use Any instead of forward reference
|
25
|
+
"""Add a method to this object type"""
|
26
|
+
self._methods[method_name] = signature
|
27
|
+
|
28
|
+
def get_method(self, method_name: str) -> Optional[Any]: # Use Any instead of forward reference
|
29
|
+
"""Get a method by name"""
|
30
|
+
return self._methods.get(method_name)
|
31
|
+
|
32
|
+
def is_compatible_with(self, other: VexType) -> bool:
|
33
|
+
"""Objects are compatible only with the same type"""
|
34
|
+
return isinstance(other, ObjectType) and self.name == other.name
|
35
|
+
|
36
|
+
def __str__(self) -> str:
|
37
|
+
return self._name
|
38
|
+
|
39
|
+
# VEX object types - define basic types here, methods will be added later
|
40
|
+
MOTOR = ObjectType("Motor")
|
41
|
+
MOTOR_GROUP = ObjectType("MotorGroup")
|
42
|
+
DRIVETRAIN = ObjectType("Drivetrain")
|
43
|
+
BRAIN = ObjectType("Brain")
|
44
|
+
CONTROLLER = ObjectType("Controller")
|
45
|
+
INERTIAL = ObjectType("Inertial")
|
46
|
+
DISTANCE = ObjectType("Distance")
|
47
|
+
ROTATION = ObjectType("Rotation")
|
48
|
+
OPTICAL = ObjectType("Optical")
|
49
|
+
GPS = ObjectType("GPS")
|
50
|
+
ELECTROMAGNETIC = ObjectType("Electromagnetic")
|
51
|
+
BRAIN_BATTERY = ObjectType("BrainBattery")
|
52
|
+
BRAIN_SCREEN = ObjectType("BrainScreen")
|
53
|
+
BRAIN_LCD = ObjectType("BrainLcd")
|
54
|
+
COMPETITION = ObjectType("Competition")
|
55
|
+
TIMER = ObjectType("Timer")
|
56
|
+
BUMPER = ObjectType("Bumper")
|
57
|
+
LIMIT_SWITCH = ObjectType("LimitSwitch")
|
58
|
+
ENCODER = ObjectType("Encoder")
|
59
|
+
SONAR = ObjectType("Sonar")
|
60
|
+
GYRO = ObjectType("Gyro")
|
61
|
+
PNEUMATIC = ObjectType("Pneumatic")
|
62
|
+
VISION = ObjectType("Vision")
|
63
|
+
|
64
|
+
# Add additional object types as needed
|