diff --git a/projects/jdwp/codegen/BUCK b/projects/jdwp/codegen/BUCK new file mode 100644 index 0000000..1e63709 --- /dev/null +++ b/projects/jdwp/codegen/BUCK @@ -0,0 +1,19 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. + +python_binary( + name="generate-new-types", + main_module="projects.jdwp.codegen.new_type_generator", + deps=[ + ":codegen", + ], + visibility=["//projects/jdwp/runtime/..."], +) + +python_library( + name="codegen", + srcs=glob(["**/*.py"]), + deps=["//projects/jdwp/defs:defs"], + visibility=[ + "PUBLIC", + ], +) diff --git a/projects/jdwp/codegen/new_type_generator.py b/projects/jdwp/codegen/new_type_generator.py index 172d085..e034cdb 100644 --- a/projects/jdwp/codegen/new_type_generator.py +++ b/projects/jdwp/codegen/new_type_generator.py @@ -11,6 +11,11 @@ def get_type_alias_definition(jdwp_type: IdType) -> str: def generate_new_types(): + print("import typing") for id_type in IdType: type_alias_definition = get_type_alias_definition(id_type) print(type_alias_definition) + + +if "__main__" == __name__: + generate_new_types() diff --git a/projects/jdwp/defs/BUCK b/projects/jdwp/defs/BUCK new file mode 100644 index 0000000..55cb280 --- /dev/null +++ b/projects/jdwp/defs/BUCK @@ -0,0 +1,8 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. + +python_library( + name = "defs", + srcs = glob(["**/*.py"]), + visibility = ["PUBLIC"], + deps = [], +) diff --git a/projects/jdwp/runtime/BUCK b/projects/jdwp/runtime/BUCK new file mode 100644 index 0000000..48f578c --- /dev/null +++ b/projects/jdwp/runtime/BUCK @@ -0,0 +1,18 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. + +genrule( + name = "type-aliases", + out = "type_aliases.py", + cmd = "$(exe //projects/jdwp/codegen:generate-new-types) > $OUT", +) + +python_library( + name = "runtime", + srcs = [ + ":type-aliases", + ], + visibility = ["PUBLIC", ], + + + deps = [], +) diff --git a/projects/jdwp/runtime/async_streams.py b/projects/jdwp/runtime/async_streams.py new file mode 100644 index 0000000..98a5598 --- /dev/null +++ b/projects/jdwp/runtime/async_streams.py @@ -0,0 +1,181 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. + +import abc +import typing + +from projects.jdwp.defs.schema import IdType + + +class JDWPInputStreamBase(abc.ABC): + # Methods for OpaqueType + @abc.abstractmethod + async def read_boolean(self) -> bool: + pass + + @abc.abstractmethod + async def read_location(self) -> typing.Any: + pass + + @abc.abstractmethod + async def read_string(self) -> str: + pass + + # Methods for IdType + @abc.abstractmethod + async def read_object_id(self) -> IdType.OBJECT_ID: + pass + + @abc.abstractmethod + async def read_thread_id(self) -> IdType.THREAD_ID: + pass + + @abc.abstractmethod + async def read_thread_group_id(self) -> IdType.THREAD_GROUP_ID: + pass + + @abc.abstractmethod + async def read_string_id(self) -> IdType.STRING_ID: + pass + + @abc.abstractmethod + async def read_class_loader_id(self) -> IdType.CLASS_LOADER_ID: + pass + + @abc.abstractmethod + async def read_class_object_id(self) -> IdType.CLASS_OBJECT_ID: + pass + + @abc.abstractmethod + async def read_array_id(self) -> IdType.ARRAY_ID: + pass + + @abc.abstractmethod + async def read_reference_type_id(self) -> IdType.REFERENCE_TYPE_ID: + pass + + @abc.abstractmethod + async def read_class_id(self) -> IdType.CLASS_ID: + pass + + @abc.abstractmethod + async def read_interface_id(self) -> IdType.INTERFACE_ID: + pass + + @abc.abstractmethod + async def read_array_type_id(self) -> IdType.ARRAY_TYPE_ID: + pass + + @abc.abstractmethod + async def read_method_id(self) -> IdType.METHOD_ID: + pass + + @abc.abstractmethod + async def read_field_id(self) -> IdType.FIELD_ID: + pass + + @abc.abstractmethod + async def read_frame_id(self) -> IdType.FRAME_ID: + pass + + # Methods for IntegralType + @abc.abstractmethod + async def read_byte(self) -> int: + pass + + @abc.abstractmethod + async def read_int(self) -> int: + pass + + @abc.abstractmethod + async def read_long( + self, + ) -> int: + pass + + +class JDWPOutputStreamBase(abc.ABC): + # Methods for OpaqueType + @abc.abstractmethod + def write_boolean(self, value: bool) -> None: + pass + + @abc.abstractmethod + def write_location(self, value: typing.Any) -> None: + pass + + @abc.abstractmethod + def write_string(self, value: str) -> None: + pass + + # Methods for IdType + @abc.abstractmethod + def write_object_id(self, value: IdType.OBJECT_ID) -> None: + pass + + @abc.abstractmethod + def write_thread_id(self, value: IdType.THREAD_ID) -> None: + pass + + @abc.abstractmethod + def write_thread_group_id(self, value: IdType.THREAD_GROUP_ID) -> None: + pass + + @abc.abstractmethod + def write_string_id(self, value: IdType.STRING_ID) -> None: + pass + + @abc.abstractmethod + def write_class_loader_id(self, value: IdType.CLASS_LOADER_ID) -> None: + pass + + @abc.abstractmethod + def write_class_object_id(self, value: IdType.CLASS_OBJECT_ID) -> None: + pass + + @abc.abstractmethod + def write_array_id(self, value: IdType.ARRAY_ID) -> None: + pass + + @abc.abstractmethod + def write_reference_type_id(self, value: IdType.REFERENCE_TYPE_ID) -> None: + pass + + @abc.abstractmethod + def write_class_id(self, value: IdType.CLASS_ID) -> None: + pass + + @abc.abstractmethod + def write_interface_id(self, value: IdType.INTERFACE_ID) -> None: + pass + + @abc.abstractmethod + def write_array_type_id(self, value: IdType.ARRAY_TYPE_ID) -> None: + pass + + @abc.abstractmethod + def write_method_id(self, value: IdType.METHOD_ID) -> None: + pass + + @abc.abstractmethod + def write_field_id(self, value: IdType.FIELD_ID) -> None: + pass + + @abc.abstractmethod + def write_frame_id(self, value: IdType.FRAME_ID) -> None: + pass + + # Methods for IntegralType + @abc.abstractmethod + def write_byte(self, value: int) -> None: + pass + + @abc.abstractmethod + def write_int(self, value: int) -> None: + pass + + @abc.abstractmethod + def write_long( + self, + value: int, + ) -> None: + pass diff --git a/projects/jdwp/tests/BUCK b/projects/jdwp/tests/BUCK index a3c6283..3769477 100644 --- a/projects/jdwp/tests/BUCK +++ b/projects/jdwp/tests/BUCK @@ -3,7 +3,10 @@ python_test( name = "tests", deps = [ - "//projects/jdwp:lib", + "//projects/jdwp/defs:defs", + "//projects/jdwp/codegen:codegen", + + ], srcs = glob(["**/*.py"]), ) diff --git a/toolchains/BUCK b/toolchains/BUCK index 7f2730a..15362e2 100644 --- a/toolchains/BUCK +++ b/toolchains/BUCK @@ -2,6 +2,7 @@ load("@prelude//toolchains:python.bzl", "system_python_bootstrap_toolchain", "system_python_toolchain") load("@prelude//toolchains:cxx.bzl", "system_cxx_toolchain") +load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain") system_cxx_toolchain( name = "cxx", @@ -13,6 +14,11 @@ system_python_toolchain( visibility = ["PUBLIC"], ) +system_genrule_toolchain( + name = "genrule", + visibility = ["PUBLIC"], + ) + system_python_bootstrap_toolchain( name = "python_bootstrap", visibility = ["PUBLIC"],