Skip to content

Commit

Permalink
Codegen Input & Output Streams (#89)
Browse files Browse the repository at this point in the history
* Added buck binary files and runtime support

* Added code to include typing library

* Made input and output stream classes abstract

* removed constructors

* chore: fix linting issues.

* feat: update typing return values
  • Loading branch information
Daquiver1 authored Nov 24, 2023
1 parent a74c2d5 commit aaf01d1
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 1 deletion.
19 changes: 19 additions & 0 deletions projects/jdwp/codegen/BUCK
Original file line number Diff line number Diff line change
@@ -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",
],
)
5 changes: 5 additions & 0 deletions projects/jdwp/codegen/new_type_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 8 additions & 0 deletions projects/jdwp/defs/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

python_library(
name = "defs",
srcs = glob(["**/*.py"]),
visibility = ["PUBLIC"],
deps = [],
)
18 changes: 18 additions & 0 deletions projects/jdwp/runtime/BUCK
Original file line number Diff line number Diff line change
@@ -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 = [],
)
181 changes: 181 additions & 0 deletions projects/jdwp/runtime/async_streams.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion projects/jdwp/tests/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
python_test(
name = "tests",
deps = [
"//projects/jdwp:lib",
"//projects/jdwp/defs:defs",
"//projects/jdwp/codegen:codegen",


],
srcs = glob(["**/*.py"]),
)
6 changes: 6 additions & 0 deletions toolchains/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"],
Expand Down

0 comments on commit aaf01d1

Please sign in to comment.