From 807625f0112df22bfe293aa4d36d67c31c4fb243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Gro=C3=9F?= Date: Fri, 3 Feb 2023 12:58:39 +0100 Subject: [PATCH] Add a basic JavaScript-to-FuzzIL compiler The new compiler: - Is (mostly) written in Swift to ensure that changes to FuzzIL are reflected in the compiler. - Features an "end-to-end" testsuite that runs as part of `swift test`. The testsuite consists of a number of JavaScript programs which are compiled to FuzzIL, then lifted back to JavaScript and checked to produce the same output as the original code. - Uses a (fairly) stable protobuf-based AST format which is currently produced by a node.js-based parser (since there seem to be no good JavaScript parsers with swift integration), but could also be produced by any other parser. The compiler is still quite far away from being feature complete but it should support the most important language features. Adding support for more features is usually relatively simple: typically it involves adding one or more tests to the testuite, adding the relevant AST nodes to ast.proto, updating the parser script to emit these nodes, and updating the compiler to handle them. However, some features may require changes to FuzzIL, such as proper handling of loop headers. The compiler is currently exposed through the FuzzILTool's --compile option. In the future we may want to have a more sophisticated CLI interface, for example to allow removing calls to certain functions (such as assertX from tests) from the compiled code. --- .gitignore | 5 + Cloud/Docker/Corpus/.gitignore | 2 + Cloud/Docker/Dockerfile | 3 + Cloud/GCE/config-template.sh | 2 + Cloud/GCE/start.sh | 2 +- Compiler/.gitignore | 6 - Compiler/Dockerfile | 35 - Compiler/README.md | 110 - Compiler/bin/dune | 5 - Compiler/bin/fuzzilli_compiler.ml | 36 - Compiler/build-pbs.sh | 4 - Compiler/dune-project | 1 - Compiler/fuzzilli_compiler.opam | 0 Compiler/package.json | 22 - Compiler/src/ProgramBuilder.ml | 721 --- Compiler/src/ProgramBuilder.mli | 152 - Compiler/src/VariableScope.ml | 534 -- Compiler/src/VariableScope.mli | 1 - Compiler/src/compiler.ml | 28 - Compiler/src/dune | 4 - Compiler/src/proto/dune | 5 - Compiler/src/proto/operations_pb.ml | 1408 ----- Compiler/src/proto/operations_pb.mli | 259 - Compiler/src/proto/operations_pp.ml | 358 -- Compiler/src/proto/operations_pp.mli | 130 - Compiler/src/proto/operations_types.ml | 452 -- Compiler/src/proto/operations_types.mli | 455 -- Compiler/src/proto/program_pb.ml | 1519 ----- Compiler/src/proto/program_pb.mli | 43 - Compiler/src/proto/program_pp.ml | 138 - Compiler/src/proto/program_pp.mli | 22 - Compiler/src/proto/program_types.ml | 166 - Compiler/src/proto/program_types.mli | 166 - Compiler/src/proto/typesystem_pb.ml | 208 - Compiler/src/proto/typesystem_pb.mli | 31 - Compiler/src/proto/typesystem_pp.ml | 36 - Compiler/src/proto/typesystem_pp.mli | 16 - Compiler/src/proto/typesystem_types.ml | 56 - Compiler/src/proto/typesystem_types.mli | 57 - Compiler/src/translate.ml | 959 --- Compiler/src/translate.mli | 2 - Compiler/src/util.ml | 182 - Compiler/src/util.mli | 33 - Compiler/supportedBuiltins.txt | 48 - Compiler/test/array_assign.ml | 25 - Compiler/test/array_assign_sugared.ml | 27 - Compiler/test/array_decl.ml | 20 - Compiler/test/array_hole.ml | 18 - Compiler/test/array_spread.ml | 18 - Compiler/test/basic_break.ml | 23 - Compiler/test/basic_compare_test.ml | 30 - Compiler/test/basic_continue.ml | 25 - Compiler/test/basic_for.ml | 32 - Compiler/test/basic_func_call.ml | 18 - Compiler/test/basic_func_ret.ml | 30 - Compiler/test/basic_while.ml | 30 - Compiler/test/binary_ops.ml | 52 - Compiler/test/bitwise_ops.ml | 23 - Compiler/test/create_array.ml | 21 - Compiler/test/del_test.ml | 27 - Compiler/test/do_while.ml | 32 - Compiler/test/dune | 5 - Compiler/test/empty_assignment_scope.ml | 34 - Compiler/test/exp_statement.ml | 24 - Compiler/test/for_in.ml | 29 - Compiler/test/for_in_scope2.ml | 29 - Compiler/test/for_in_scoping.ml | 29 - Compiler/test/for_of.ml | 26 - Compiler/test/func_call_with_spread.ml | 39 - Compiler/test/func_dec_order.ml | 28 - Compiler/test/func_exp_test.ml | 23 - Compiler/test/func_param_scoping.ml | 32 - Compiler/test/if_else.ml | 32 - Compiler/test/in_test.ml | 24 - Compiler/test/instance_of.ml | 22 - Compiler/test/load_array_index.ml | 23 - Compiler/test/load_bigint.ml | 16 - Compiler/test/load_bool.ml | 18 - Compiler/test/load_float.ml | 16 - Compiler/test/load_infinity.ml | 16 - Compiler/test/load_null.ml | 16 - Compiler/test/load_property.ml | 19 - Compiler/test/load_regex.ml | 27 - Compiler/test/logical_ops.ml | 22 - Compiler/test/lone_if.ml | 23 - Compiler/test/new.ml | 21 - Compiler/test/object_creation.ml | 24 - Compiler/test/prog_10.ml | 30 - Compiler/test/prog_1007.ml | 26 - Compiler/test/prop_name_assignment.ml | 22 - Compiler/test/single_constant.ml | 16 - Compiler/test/single_let.ml | 19 - Compiler/test/single_string_literal.ml | 16 - Compiler/test/spread_object.ml | 30 - Compiler/test/store_property_sugared.ml | 25 - Compiler/test/sugared_assignment.ml | 26 - Compiler/test/ternary.ml | 26 - Compiler/test/test.ml | 84 - Compiler/test/this.ml | 16 - Compiler/test/throw.ml | 18 - Compiler/test/typeof.ml | 18 - Compiler/test/unary_minus.ml | 17 - Compiler/test/unary_ops.ml | 25 - Compiler/test/undefined.ml | 16 - Compiler/test/update.ml | 20 - Compiler/test/util.ml | 27 - Compiler/test/v8_natives.ml | 22 - Compiler/test/var_hoisting_1.ml | 35 - Compiler/test/var_hoisting_2.ml | 42 - Compiler/test/var_hoisting_3.ml | 40 - Compiler/test/var_hoisting_shadow.ml | 36 - Compiler/test/varied_func_types.ml | 86 - Compiler/test/void.ml | 19 - Compiler/test/with.ml | 31 - Compiler/test/with_load_scope.ml | 26 - Package.swift | 53 +- Sources/FuzzILTool/main.swift | 39 + Sources/Fuzzilli/Base/ProgramBuilder.swift | 22 +- Sources/Fuzzilli/CodeGen/CodeGenerators.swift | 13 +- Sources/Fuzzilli/Compiler/Compiler.swift | 835 +++ Sources/Fuzzilli/Compiler/Parser.swift | 91 + Sources/Fuzzilli/Compiler/Parser/README.md | 7 + Sources/Fuzzilli/Compiler/Parser/package.json | 6 + Sources/Fuzzilli/Compiler/Parser/parser.js | 472 ++ .../Environment/JavaScriptEnvironment.swift | 2 +- Sources/Fuzzilli/FuzzIL/Instruction.swift | 14 +- Sources/Fuzzilli/FuzzIL/JSTyper.swift | 5 + Sources/Fuzzilli/FuzzIL/JsOperations.swift | 50 +- Sources/Fuzzilli/FuzzIL/TypeSystem.swift | 2 +- Sources/Fuzzilli/Lifting/FuzzILLifter.swift | 22 +- .../Fuzzilli/Lifting/JavaScriptLifter.swift | 27 +- .../Minimization/InliningReducer.swift | 4 +- .../Fuzzilli/Minimization/PostProcessor.swift | 2 +- Sources/Fuzzilli/Protobuf/ast.pb.swift | 5350 +++++++++++++++++ Sources/Fuzzilli/Protobuf/ast.proto | 327 + Sources/Fuzzilli/Protobuf/operations.pb.swift | 8 + Sources/Fuzzilli/Protobuf/operations.proto | 1 + Sources/Fuzzilli/Util/Stack.swift | 8 + .../FuzzilliCli/CodeGeneratorWeights.swift | 2 +- Tests/FuzzilliTests/CompilerTests.swift | 138 + Tests/FuzzilliTests/CompilerTests/README.md | 9 + .../CompilerTests/basic_control_flow.js | 63 + .../CompilerTests/basic_expressions.js | 35 + .../CompilerTests/basic_functions.js | 29 + .../CompilerTests/basic_object_access.js | 14 + .../CompilerTests/basic_objects.js | 36 + .../CompilerTests/basic_scoping.js | 20 + .../CompilerTests/basic_variables.js | 14 + .../CompilerTests/global_variable_access.js | 14 + Tests/FuzzilliTests/CompilerTests/literals.js | 11 + .../multiline_string_literals.js | 22 + .../CompilerTests/recursive_functions.js | 11 + .../FuzzilliTests/CompilerTests/spreading.js | 27 + .../FuzzilliTests/CompilerTests/v8_natives.js | 13 + .../CompilerTests/variable_hoisting.js | 29 + Tests/FuzzilliTests/LifterTest.swift | 4 +- 156 files changed, 7815 insertions(+), 10340 deletions(-) create mode 100644 Cloud/Docker/Corpus/.gitignore delete mode 100644 Compiler/.gitignore delete mode 100644 Compiler/Dockerfile delete mode 100644 Compiler/README.md delete mode 100644 Compiler/bin/dune delete mode 100644 Compiler/bin/fuzzilli_compiler.ml delete mode 100755 Compiler/build-pbs.sh delete mode 100644 Compiler/dune-project delete mode 100644 Compiler/fuzzilli_compiler.opam delete mode 100644 Compiler/package.json delete mode 100644 Compiler/src/ProgramBuilder.ml delete mode 100644 Compiler/src/ProgramBuilder.mli delete mode 100644 Compiler/src/VariableScope.ml delete mode 100644 Compiler/src/VariableScope.mli delete mode 100644 Compiler/src/compiler.ml delete mode 100644 Compiler/src/dune delete mode 100644 Compiler/src/proto/dune delete mode 100644 Compiler/src/proto/operations_pb.ml delete mode 100644 Compiler/src/proto/operations_pb.mli delete mode 100644 Compiler/src/proto/operations_pp.ml delete mode 100644 Compiler/src/proto/operations_pp.mli delete mode 100644 Compiler/src/proto/operations_types.ml delete mode 100644 Compiler/src/proto/operations_types.mli delete mode 100644 Compiler/src/proto/program_pb.ml delete mode 100644 Compiler/src/proto/program_pb.mli delete mode 100644 Compiler/src/proto/program_pp.ml delete mode 100644 Compiler/src/proto/program_pp.mli delete mode 100644 Compiler/src/proto/program_types.ml delete mode 100644 Compiler/src/proto/program_types.mli delete mode 100644 Compiler/src/proto/typesystem_pb.ml delete mode 100644 Compiler/src/proto/typesystem_pb.mli delete mode 100644 Compiler/src/proto/typesystem_pp.ml delete mode 100644 Compiler/src/proto/typesystem_pp.mli delete mode 100644 Compiler/src/proto/typesystem_types.ml delete mode 100644 Compiler/src/proto/typesystem_types.mli delete mode 100644 Compiler/src/translate.ml delete mode 100644 Compiler/src/translate.mli delete mode 100644 Compiler/src/util.ml delete mode 100644 Compiler/src/util.mli delete mode 100644 Compiler/supportedBuiltins.txt delete mode 100644 Compiler/test/array_assign.ml delete mode 100644 Compiler/test/array_assign_sugared.ml delete mode 100644 Compiler/test/array_decl.ml delete mode 100644 Compiler/test/array_hole.ml delete mode 100644 Compiler/test/array_spread.ml delete mode 100644 Compiler/test/basic_break.ml delete mode 100644 Compiler/test/basic_compare_test.ml delete mode 100644 Compiler/test/basic_continue.ml delete mode 100644 Compiler/test/basic_for.ml delete mode 100644 Compiler/test/basic_func_call.ml delete mode 100644 Compiler/test/basic_func_ret.ml delete mode 100644 Compiler/test/basic_while.ml delete mode 100644 Compiler/test/binary_ops.ml delete mode 100644 Compiler/test/bitwise_ops.ml delete mode 100644 Compiler/test/create_array.ml delete mode 100644 Compiler/test/del_test.ml delete mode 100644 Compiler/test/do_while.ml delete mode 100644 Compiler/test/dune delete mode 100644 Compiler/test/empty_assignment_scope.ml delete mode 100644 Compiler/test/exp_statement.ml delete mode 100644 Compiler/test/for_in.ml delete mode 100644 Compiler/test/for_in_scope2.ml delete mode 100644 Compiler/test/for_in_scoping.ml delete mode 100644 Compiler/test/for_of.ml delete mode 100644 Compiler/test/func_call_with_spread.ml delete mode 100644 Compiler/test/func_dec_order.ml delete mode 100644 Compiler/test/func_exp_test.ml delete mode 100644 Compiler/test/func_param_scoping.ml delete mode 100644 Compiler/test/if_else.ml delete mode 100644 Compiler/test/in_test.ml delete mode 100644 Compiler/test/instance_of.ml delete mode 100644 Compiler/test/load_array_index.ml delete mode 100644 Compiler/test/load_bigint.ml delete mode 100644 Compiler/test/load_bool.ml delete mode 100644 Compiler/test/load_float.ml delete mode 100644 Compiler/test/load_infinity.ml delete mode 100644 Compiler/test/load_null.ml delete mode 100644 Compiler/test/load_property.ml delete mode 100644 Compiler/test/load_regex.ml delete mode 100644 Compiler/test/logical_ops.ml delete mode 100644 Compiler/test/lone_if.ml delete mode 100644 Compiler/test/new.ml delete mode 100644 Compiler/test/object_creation.ml delete mode 100644 Compiler/test/prog_10.ml delete mode 100644 Compiler/test/prog_1007.ml delete mode 100644 Compiler/test/prop_name_assignment.ml delete mode 100644 Compiler/test/single_constant.ml delete mode 100644 Compiler/test/single_let.ml delete mode 100644 Compiler/test/single_string_literal.ml delete mode 100644 Compiler/test/spread_object.ml delete mode 100644 Compiler/test/store_property_sugared.ml delete mode 100644 Compiler/test/sugared_assignment.ml delete mode 100644 Compiler/test/ternary.ml delete mode 100644 Compiler/test/test.ml delete mode 100644 Compiler/test/this.ml delete mode 100644 Compiler/test/throw.ml delete mode 100644 Compiler/test/typeof.ml delete mode 100644 Compiler/test/unary_minus.ml delete mode 100644 Compiler/test/unary_ops.ml delete mode 100644 Compiler/test/undefined.ml delete mode 100644 Compiler/test/update.ml delete mode 100644 Compiler/test/util.ml delete mode 100644 Compiler/test/v8_natives.ml delete mode 100644 Compiler/test/var_hoisting_1.ml delete mode 100644 Compiler/test/var_hoisting_2.ml delete mode 100644 Compiler/test/var_hoisting_3.ml delete mode 100644 Compiler/test/var_hoisting_shadow.ml delete mode 100644 Compiler/test/varied_func_types.ml delete mode 100644 Compiler/test/void.ml delete mode 100644 Compiler/test/with.ml delete mode 100644 Compiler/test/with_load_scope.ml create mode 100644 Sources/Fuzzilli/Compiler/Compiler.swift create mode 100644 Sources/Fuzzilli/Compiler/Parser.swift create mode 100644 Sources/Fuzzilli/Compiler/Parser/README.md create mode 100644 Sources/Fuzzilli/Compiler/Parser/package.json create mode 100644 Sources/Fuzzilli/Compiler/Parser/parser.js create mode 100644 Sources/Fuzzilli/Protobuf/ast.pb.swift create mode 100644 Sources/Fuzzilli/Protobuf/ast.proto create mode 100644 Tests/FuzzilliTests/CompilerTests.swift create mode 100644 Tests/FuzzilliTests/CompilerTests/README.md create mode 100644 Tests/FuzzilliTests/CompilerTests/basic_control_flow.js create mode 100644 Tests/FuzzilliTests/CompilerTests/basic_expressions.js create mode 100644 Tests/FuzzilliTests/CompilerTests/basic_functions.js create mode 100644 Tests/FuzzilliTests/CompilerTests/basic_object_access.js create mode 100644 Tests/FuzzilliTests/CompilerTests/basic_objects.js create mode 100644 Tests/FuzzilliTests/CompilerTests/basic_scoping.js create mode 100644 Tests/FuzzilliTests/CompilerTests/basic_variables.js create mode 100644 Tests/FuzzilliTests/CompilerTests/global_variable_access.js create mode 100644 Tests/FuzzilliTests/CompilerTests/literals.js create mode 100644 Tests/FuzzilliTests/CompilerTests/multiline_string_literals.js create mode 100644 Tests/FuzzilliTests/CompilerTests/recursive_functions.js create mode 100644 Tests/FuzzilliTests/CompilerTests/spreading.js create mode 100644 Tests/FuzzilliTests/CompilerTests/v8_natives.js create mode 100644 Tests/FuzzilliTests/CompilerTests/variable_hoisting.js diff --git a/.gitignore b/.gitignore index a7356a55..ffb223b3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,11 @@ Package.resolved /*.xcodeproj .vscode .*.sw? +.swiftpm # custom GCE configuration Cloud/GCE/config.sh + +# node.js dependencies, used by the JavaScript parser for the FuzzIL compiler +node_modules +package-lock.json diff --git a/Cloud/Docker/Corpus/.gitignore b/Cloud/Docker/Corpus/.gitignore new file mode 100644 index 00000000..7091b09c --- /dev/null +++ b/Cloud/Docker/Corpus/.gitignore @@ -0,0 +1,2 @@ +*js +*fuzzil.protobuf diff --git a/Cloud/Docker/Dockerfile b/Cloud/Docker/Dockerfile index c957d23e..403b9de7 100644 --- a/Cloud/Docker/Dockerfile +++ b/Cloud/Docker/Dockerfile @@ -23,6 +23,9 @@ ADD DuktapeBuilder/out duktape # Add JerryScript binary ADD JerryScriptBuilder/out jerryscript +# Add Corpus (if any) +ADD Corpus corpus + # Add Fuzzilli binaries ADD FuzzilliBuilder/out/Fuzzilli Fuzzilli ADD FuzzilliBuilder/out/REPRLRun REPRLRun diff --git a/Cloud/GCE/config-template.sh b/Cloud/GCE/config-template.sh index 645dc07c..7c76435e 100644 --- a/Cloud/GCE/config-template.sh +++ b/Cloud/GCE/config-template.sh @@ -19,6 +19,8 @@ BINARY=./v8/d8 FUZZILLI_ARGS="--profile=v8" # Arguments for the root instance. See ./Fuzzilli --help FUZZILLI_ROOT_ARGS="--exportStatistics" +# Arguments for the intermediate instances. See ./Fuzzilli --help +FUZZILLI_INTERMEDIATE_ARGS="" # Arguments for the leaf instances. See ./Fuzzilli --help FUZZILLI_LEAF_ARGS="" diff --git a/Cloud/GCE/start.sh b/Cloud/GCE/start.sh index da3ab4de..0e637b5f 100755 --- a/Cloud/GCE/start.sh +++ b/Cloud/GCE/start.sh @@ -165,7 +165,7 @@ if [ "$START_INTERMEDIATES" = true ]; then --container-tty \ --container-command=/bin/bash \ --container-arg="-c" \ - --container-arg="sysctl -w 'kernel.core_pattern=|/bin/false' && ./Fuzzilli --instanceType=intermediate --connectTo=$parent_ip:1337 --bindTo=0.0.0.0:1337 $FUZZILLI_ARGS $BINARY" \ + --container-arg="sysctl -w 'kernel.core_pattern=|/bin/false' && ./Fuzzilli --instanceType=intermediate --connectTo=$parent_ip:1337 --bindTo=0.0.0.0:1337 $FUZZILLI_ARGS $FUZZILLI_INTERMEDIATE_ARGS $BINARY" \ --network-tier=PREMIUM \ --maintenance-policy=MIGRATE \ --labels=container-vm=$IMAGE,level=$level,role=intermediate,session=$SESSION diff --git a/Compiler/.gitignore b/Compiler/.gitignore deleted file mode 100644 index 1b0c58e2..00000000 --- a/Compiler/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -_build -_esy -*.merlin -esy.lock -node_modules -fuzzilli_compiler.install \ No newline at end of file diff --git a/Compiler/Dockerfile b/Compiler/Dockerfile deleted file mode 100644 index 471eba63..00000000 --- a/Compiler/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM ubuntu:latest - -ENV DEBIAN_FRONTEND=noninteractive -ENV SHELL=bash - -RUN apt-get -y update && apt-get -y upgrade -RUN apt-get install -y curl opam npm -RUN npm install -g --unsafe-perm esy - -RUN useradd -m builder -WORKDIR /home/builder -USER builder - -ADD --chown=builder:builder ./ Compiler -WORKDIR Compiler - -# Set up Opam & Ocaml properly, for OCaml v 4.10.0 -# Pin flow, and setup the package.json -RUN opam init -a --disable-sandboxing -RUN opam switch create 4.10.0 && \ - eval $(opam env) && \ - opam pin add -y flow_parser https://github.com/facebook/flow.git && \ - sed -i 's/.*REPLACE ME.*/ "flow_parser": "link:\/home\/builder\/.opam\/4.10.0\/.opam-switch\/sources\/flow_parser\/flow_parser.opam"/' package.json - -# Install dependencies -RUN esy install - -# And build! -RUN esy build - -# Run the tests to verify that the compiler works correctly -RUN esy x test - -# Finally, copy the compiler binary into the current directory for easy access -RUN cp _esy/default/build/default/bin/fuzzilli_compiler.exe . \ No newline at end of file diff --git a/Compiler/README.md b/Compiler/README.md deleted file mode 100644 index 6f9e193e..00000000 --- a/Compiler/README.md +++ /dev/null @@ -1,110 +0,0 @@ -# Overview - -Originally written by [William Parks](https://github.com/WilliamParks) - -This compiler compiles a Javascript source file to the Fuzzilli intermediate language, encoded in a protobuf. This allows Fuzzilli to start execution from a large initial corpus. - - -This compiler was designed and tested on Ubuntu 20.04. See below for running in in Docker. - -## Dependencies -This project uses ocaml-protoc for protobufs, and flow_parser for parsing JS. - -- Installing flow_parser is unfortunately a bit non-standard. Development followed the process here to get the correct version: [Installing flow_ast](https://discuss.ocaml.org/t/library-to-parse-javascript-in-opam/5775/6). - -- Pin and install flow_parser via - `opam pin add flow_parser https://github.com/facebook/flow.git` - -- Find the opam file for flow_parser on your system. Mine was at `~/.opam/default/.opam-switch/sources/flow_parser/flow_parser.opam` - Add that value to package.json, under resolutions - -- Install esy (https://esy.sh/), which requires npm - -- Run esy to install and build - - `esy install` - - `esy build` - -## Building Protobuf files - -`esy run-script build-pbs` will build the Ocaml interface to the protobuf files found in the [Protobuf](Sources/Fuzzilli/Protobuf) directory, and will put the results in [src/proto](./src/proto) - -## Testing - -`esy x test` will run all the compiler tests, found in [test](./test). Currently, each one consists of a Javascript source snippet, and expected resulting fuzzil output. Note that these tests may be sensitive to changes in the Fuzzilli intermediate language. - -## Running -Once successfully built, the compiler can be run with `esy x fuzzilli_compiler` or `./Compiler/_esy/default/build/default/bin/fuzzilli_compiler.exe` - -## Useful compiler flags - - -ast - Prints the abstract syntax tree produced by flow_ast. Useful for further compiler development - -builtins - Prints all Javascript identifiers the compiler has determined to be builtins - -use-placeholder - Replaces all unknown Javascript builtins with a call to a function named `placeholder`. This is a hack to increase the number of samples that execute successfully. `Placeholder` must then be defined in the Fuzzilli profile for the targeted engine. - -v8-natives - Flow_ast does not properly handle the syntax of v8 natives (example %PrepareFunctionForOptimization). With this flag enabled, the compiler will first scan the input file for a short list of natives specified in [util.ml](src/util.ml), and replace them with function calls to functions of the same name, without the leading `%`. Each function defined this way must then be implemented properly in the [V8 profile](Sources/FuzzilliCli/Profiles/V8Profile.swift). - -## Docker - -This compiler can also be run in Docker, using the following commands - -Build the Docker image and run tests with `docker build -t compiler_builder .` - -To copy the executable out of the docker container, use: - - `docker create --name temp_container compiler_builder && docker cp temp_container:/home/builder/Compiler/fuzzilli_compiler.exe fuzzilli_compiler.exe && docker rm temp_container` - -# Design - -This compiler is implemented in a pair of passes over the Abstract Syntax Tree (AST) produced by `flow_ast`, one to do variable hoisting and the second to produce the output protobuf. The general design principle is to keep the compiler simple, avoiding any of the optimizations seen in a normal compiler (constant folding, etc.), nor trying to achieve quick compilation. - -* [translate](./src/translate.ml) contains the compilation logic. It walks the AST, and calls both ProgramBuilder and VariableScope. -* [VariableScope](./src/VariableScope.ml) walks the AST and returns which functions and variables should be hoisted -* [ProgramBuilder](./src/Programbuilder.ml) produces individual instructions in the protobuf format, without compiler logic - -## Loops -All loops are converted to `while` loops, where the conditional is a comparison against the integer `0`, and executed once before the loop, and at the end of each iteration. -This is best explained in the following example: - -```javascript -for(let i = 0; i < 10; i++){ - foo(i); -} -``` -becomes -```javascript -let i = 0; -let t1 = i < 10; -while(t1 != 0) { - foo(i); - i++; - t1 = i < 10; -} -``` - -## Variable & Function Hoisting -The compiler implements a basic version of both variable and function hoisting. [VariableScope](./src/VariableScope.ml) determines which variables and functions require hoisting to meet the Fuzzilli static checks, and lifts those to the beginning of the function in which they are defined. It assumes that the whole program will be inserted into a `main` function, as currently implemented in each individual JS engine profile. - -## Type Information -The compiler is designed to include minimal type information, intending Fuzzilli proper to collect type information itself. Values are based on the hardcoded values in [TypeSystem.swift](Sources/Fuzzilli/FuzzIL/TypeSystem.swift). The type information in the overall program protobuf is left empty. Function parameters are provided as `.anything` and return `.unknown`. The constants are defined in [ProgramBuilder](./src/Programbuilder.ml) as `unknown_type_int` and `anything_type_int` - -## Known limitations/TODOs - -* Improve variable hoisting (current implementation is likely only partially correct, proper scoping is likely incorrect) -* Implement the following, which may require changes to Fuzzilli proper - - Template Literals - - Classes - - Spread (update Fuzzilli) -* Improve for/while loops. The current implementation makes all loops while loops, with a comparison against 0. -* Improve for-of/for-in loops. A large number of test cases have more complex left sides, while Fuzzilli only supports declaring/defining a new variable. - - Example from a regression: for (a[i++].x in []) -* Add FuzzILTool, Javascript engine to compiler tests, to ensure the output is a valid Fuzzilli IL program, and lifts to valid Javascript -* Detect and properly handle global variables (e.g. g = 5 without var/let/const) -* `build_func_ops` in [ProgramBuilder](./src/Programbuilder.ml) should be simplified to move more compilation functionality into the translation functionality -* `With` statements are likely incorrect, check [tests/with.ml](./tests/with.ml) for an example -* [ProgramBuilder](./src/Programbuilder.ml) has hardcoded values for types in the protobuf, that need to match those in TypeSystem.swift - * These could be expanded into a full type constructor, similar to what is in `TypeSystem.swfit` \ No newline at end of file diff --git a/Compiler/bin/dune b/Compiler/bin/dune deleted file mode 100644 index 7d5249a2..00000000 --- a/Compiler/bin/dune +++ /dev/null @@ -1,5 +0,0 @@ -(executable - (name fuzzilli_compiler) - (public_name fuzzilli_compiler) - (libraries compiler core flow_parser ocaml-protoc proto str) - (preprocess (pps ppx_jane ppx_deriving ppx_deriving.show))) \ No newline at end of file diff --git a/Compiler/bin/fuzzilli_compiler.ml b/Compiler/bin/fuzzilli_compiler.ml deleted file mode 100644 index 19ad52b0..00000000 --- a/Compiler/bin/fuzzilli_compiler.ml +++ /dev/null @@ -1,36 +0,0 @@ -let do_compile infile outfile ~(emit_ast : bool) ~(emit_builtins: bool) ~(v8_natives: bool) ~(use_placeholder: bool)= - try - let file_string = Core.In_channel.read_all infile in - let (prog, err) = Compiler.string_to_flow_ast file_string in - let (loc_type, a) = prog in - let prog_string = Compiler.print_ast_statement_list a.statements in - if emit_ast then - print_endline ("Provided AST: \n" ^ prog_string ^ "\n") - else (); - let inst_list = Compiler.flow_ast_to_inst_list prog emit_builtins v8_natives use_placeholder in - let prog = Compiler.inst_list_to_prog inst_list in - Compiler.write_proto_obj_to_file prog outfile - with - Invalid_argument x -> print_endline ("Invalid arg: " ^ x) - | Parse_error.Error y -> - let _, err_list = List.split y in - Printf.printf "Compiler Error %s\n" (Parse_error.PP.error (List.hd err_list)) - | y -> print_endline ("Other compiler error" ^ (Core.Exn.to_string y)) - -let command = - let open Core in - Command.basic - ~summary:"Compile a JS source file to Fuzzil" - Command.Let_syntax.( - let%map_open - infile = (anon ("infile" %: Filename.arg_type)) - and outfile = (anon ("outfile" %: string)) - and emit_ast = flag "-ast" no_arg ~doc: "Print the Flow_ast" - and emit_builtins = flag "-builtins" no_arg ~doc: "Print all builtins encountered" - and v8_natives = flag "-v8-natives" no_arg ~doc: "Include v8 natives, as funtions without the leading %. Requires the builtins be included in the fuzzilli profile for v8. Currently only uses a hardcoded list in util.ml" - and use_placeholder = flag "-use-placeholder" no_arg ~doc: "Replaces each unknown builtin with 'placeholder'." - in - fun () -> do_compile infile outfile ~emit_ast ~emit_builtins ~v8_natives ~use_placeholder) - -let () = - Core.Command.run command diff --git a/Compiler/build-pbs.sh b/Compiler/build-pbs.sh deleted file mode 100755 index 3d57d675..00000000 --- a/Compiler/build-pbs.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -ocaml-protoc -I ../Sources/Fuzzilli/Protobuf/ ../Sources/Fuzzilli/Protobuf/operations.proto -ml_out ./src/proto -ocaml-protoc -I ../Sources/Fuzzilli/Protobuf/ ../Sources/Fuzzilli/Protobuf/program.proto -ml_out ./src/proto -ocaml-protoc -I ../Sources/Fuzzilli/Protobuf/ ../Sources/Fuzzilli/Protobuf/typesystem.proto -ml_out ./src/proto diff --git a/Compiler/dune-project b/Compiler/dune-project deleted file mode 100644 index f75713fb..00000000 --- a/Compiler/dune-project +++ /dev/null @@ -1 +0,0 @@ -(lang dune 1.2) diff --git a/Compiler/fuzzilli_compiler.opam b/Compiler/fuzzilli_compiler.opam deleted file mode 100644 index e69de29b..00000000 diff --git a/Compiler/package.json b/Compiler/package.json deleted file mode 100644 index f19d3378..00000000 --- a/Compiler/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "fuzzilli_compiler", - "version": "0.1", - "esy": { - "build": "dune build -p #{self.name}" - }, - "dependencies": { - "@opam/core": "*", - "@opam/ocaml-lsp-server": "*", - "@opam/ocaml-protoc": "*", - "flow_parser": "*", - "ocaml": "~4.10", - "@opam/alcotest": "*", - "@opam/uuidm": "*" - }, - "resolutions": { - "flow_parser": "link:{REPLACE ME PATH HERE}/.opam/4.10.0/.opam-switch/sources/flow_parser/flow_parser.opam" - }, - "scripts": { - "build-pbs": "./build-pbs.sh" - } -} diff --git a/Compiler/src/ProgramBuilder.ml b/Compiler/src/ProgramBuilder.ml deleted file mode 100644 index 15c70274..00000000 --- a/Compiler/src/ProgramBuilder.ml +++ /dev/null @@ -1,721 +0,0 @@ -open Program_types - -module String_Set = Set.Make(struct type t = string let compare = compare end) - -type var = int32 - -(* Keeps a mapping of ids to temps *) -type temp_map_t = (string, var, Core.String.comparator_witness) Core.Map.t - - -type inst = instruction - -(* Keeps a mapping of ids that are still visible in Javascipt, but that Fuzzilli considers out of scope. -Used to determine if var should be loaded from scope, rather than accessed as a temp *) -type var_scope_map_t = (string, string, Core.String.comparator_witness) Core.Map.t - -type builder = - { mutable next_index : var; - mutable local_maps : temp_map_t list; - mutable hoisted_vars : String_Set.t; - emit_builtins : bool; - include_v8_natives : bool; - use_placeholder: bool; - } - -type lookup_result = InScope of var - | NotFound - -type binary_op = Plus - | Minus - | Mult - | Div - | Mod - | Xor - | LShift - | RShift - | Exp - | RShift3 - | BitAnd - | BitOr - | LogicalAnd - | LogicalOr - -type compare_op = Equal - | NotEqual - | StrictEqual - | StrictNotEqual - | LessThan - | LessThanEqual - | GreaterThan - | GreaterThanEqual - -type unary_op = Not - | BitNot - | Minus - | Plus - | PreInc - | PostInc - | PreDec - | PostDec - -(* TODO: Expand these into full constructors, similar to what is in TypeSystem.swift *) -let unknown_type_int = Int32.shift_left 1l 8 -let anything_type_int = Int32.sub (Int32.shift_left 1l 12) 1l -let nothing_type_int = 0l - -let translate_compare_op compare_op = - let res : Operations_types.comparator = match compare_op with - Equal -> Equal - | NotEqual -> Not_equal - | StrictEqual -> Strict_equal - | StrictNotEqual -> Strict_not_equal - | LessThan -> Less_than - | LessThanEqual -> Less_than_or_equal - | GreaterThan -> Greater_than - | GreaterThanEqual -> Greater_than_or_equal in - res - -let init_builder emit_builtins include_v8_natives use_placeholder = { - next_index = 0l; - local_maps = [Core.Map.empty (module Core.String)]; - hoisted_vars = String_Set.empty; - emit_builtins = emit_builtins; - include_v8_natives = include_v8_natives; - use_placeholder = use_placeholder; - } - -(* Get a new intermediate id *) -let get_new_intermed_temp builder = - let ret_index = builder.next_index in - builder.next_index <- Base.Int32.(+) builder.next_index 1l; - (* Fuzzilli limits var numbers to fit within 16 bits*) - if Core.Int32.(>) ret_index 65535l then - raise (Invalid_argument "Too many variables for Fuzzilli. Must be <= 65535") - else (); - ret_index - -let add_hoisted_var (var_name:string) builder = - let new_hoised_var_set = String_Set.add var_name builder.hoisted_vars in - builder.hoisted_vars <- new_hoised_var_set - -let is_hoisted_var (var_name:string) builder = - String_Set.mem var_name builder.hoisted_vars - -let clear_hoisted_vars builder = - builder.hoisted_vars <- String_Set.empty - -(* Associate an intermediate variable with an identifier, with specified visibility *) -let add_new_var_identifier name num builder = - let curr_local_map, rest_maps = match builder.local_maps with - [] -> raise (Invalid_argument "Empty local scopes") - | x :: tl -> x, tl - in - let new_map = Core.Map.update curr_local_map name (fun _ -> num) in - builder.local_maps <- new_map :: rest_maps - -(* This group of functions manages variable scope*) -let push_local_scope builder = - let new_map = Core.Map.empty (module Core.String) in - builder.local_maps <- new_map :: builder.local_maps - -let pop_local_scope builder = - match (Core.List.tl builder.local_maps) with - Some x -> builder.local_maps <- x - | None -> raise (Invalid_argument "Tried to pop empty local scope") - -let update_map m (i:(var * string) option) = - match i with - Some (temp,name ) -> Core.Map.update m name (fun _ -> temp) - | None -> m - -let rec check_local_maps map_list name = - match map_list with - hd :: tl -> (match Core.Map.find hd name with - Some x -> Some x - | None -> check_local_maps tl name) - | [] -> None - -(* Fist looks through the local maps in appropriate order, then checks globals, -and then items declared as 'var' but outside the fuzzilli scope *) -let lookup_var_name builder name = - let local_map_res = check_local_maps builder.local_maps name in - match local_map_res with - Some x -> InScope x - | None -> NotFound - -let should_emit_builtins builder = - builder.emit_builtins - -let include_v8_natives builder = - builder.include_v8_natives - -let use_placeholder builder = - builder.use_placeholder - -let build_load_bigInt b builder = - let result_var = get_new_intermed_temp builder in - (* TODO: Validate if this is right *) - let is_int f = fst (Float.modf f) <= Float.epsilon in - if is_int b && b <= (Base.Int64.to_float Int64.max_int) && b >= (Base.Int64.to_float Int64.min_int) then - let op : Operations_types.load_big_int = Operations_types.{value = Int64.of_float b} in - let inst = Program_types.{ - inouts = [result_var]; - operation = Load_big_int op; - } in - result_var, inst - else - raise (Invalid_argument ("Improper Bigint provided")) - -let build_load_bool b builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [result_var]; - operation = Load_boolean Operations_types.{value = b}; - } in - result_var, inst - -let build_load_builtin name builder = - let result_var = get_new_intermed_temp builder in - let inst : Program_types.instruction = Program_types.{ - inouts = [result_var]; - operation = Load_builtin Operations_types.{builtin_name = name}; - } in - result_var, inst - -let build_load_float f builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [result_var]; - operation = Load_float Operations_types.{value = f}; - } in - result_var, inst - -let build_load_from_scope name builder = - let result_var = get_new_intermed_temp builder in - let inst : Program_types.instruction = Program_types.{ - inouts = [result_var]; - operation = Load_from_scope Operations_types.{id = name}; - } in - result_var, inst - -let build_load_integer i builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [result_var]; - operation = Load_integer Operations_types.{value = i}; - } in - result_var, inst - -let build_load_null builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [result_var]; - operation = Load_null; - } in - result_var, inst - -let build_load_regex pattern flags builder = - let result_var = get_new_intermed_temp builder in - let op = Operations_types.{value = pattern; flags = Util.regex_flag_str_to_int flags} in - let inst_op = Load_reg_exp op in - let inst = Program_types.{ - inouts = [result_var]; - operation = inst_op; - } in - result_var, inst - -let build_load_string s builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [result_var]; - operation = Load_string Operations_types.{value = s}; - } in - result_var, inst - -let build_load_undefined builder = - let result_var = get_new_intermed_temp builder in - let inst : Program_types.instruction = Program_types.{ - inouts = [result_var]; - operation = Program_types.Load_undefined; - } in - result_var, inst - -let build_delete_prop var name builder = - let inst_op = Program_types.Delete_property Operations_types.{property_name = name} in - let inst : Program_types.instruction = Program_types.{ - inouts = [var]; - operation = inst_op; - } in - var, inst - -let build_delete_computed_prop obj_var exp_var builder = - let inst = Program_types.{ - inouts = [obj_var; exp_var]; - operation = Delete_computed_property; - } in - obj_var, inst - -let build_load_prop input_var name builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [input_var; result_var]; - operation = Load_property{property_name = name}; - } in - result_var, inst - -let build_load_computed_prop obj_var exp_var builder = - let result_var = get_new_intermed_temp builder in - let load_inst = Program_types.{ - inouts = [obj_var; exp_var; result_var]; - operation = Load_computed_property; - } in - result_var, load_inst - -let build_store_prop obj_var value_var prop_name builder = - Program_types.{ - inouts = [obj_var; value_var]; - operation = Store_property{property_name = prop_name } - } - -let build_store_computed_prop obj_var index_var value_var builder = - Program_types.{ - inouts = [obj_var; index_var; value_var]; - operation = Program_types.Store_computed_property; - } - -let build_load_element array_var index builder = - let result_var = get_new_intermed_temp builder in - let load_inst = Program_types.{ - inouts = [array_var; result_var]; - operation = Load_element{index = Int64.of_int index}; - } in - result_var, load_inst - -let build_new_object obj_var arg_list builder = - let result_var = get_new_intermed_temp builder in - let new_obj_inst = Program_types.{ - inouts = [obj_var] @ arg_list @ [result_var]; - operation = Program_types.Construct; - } in - result_var, new_obj_inst - -let build_binary_op lvar rvar (binary_op: binary_op) builder = - let result_var = get_new_intermed_temp builder in - let op : Operations_types.binary_operation = match binary_op with - Plus -> Operations_types.{op = Add} - | Minus -> Operations_types.{op = Sub} - | Mult -> Operations_types.{op = Mul} - | Div -> Operations_types.{op = Div} - | Mod -> Operations_types.{op = Mod} - | Xor -> Operations_types.{op = Xor} - | LShift -> Operations_types.{op = Lshift} - | RShift -> Operations_types.{op = Rshift} - | Exp -> Operations_types.{op = Exp} - | RShift3 -> Operations_types.{op = Unrshift} - | BitAnd -> Operations_types.{op = Bit_and} - | BitOr -> Operations_types.{op = Bit_or} - | LogicalAnd -> Operations_types.{op = Logical_and} - | LogicalOr -> Operations_types.{op = Logical_or} in - let inst = Program_types.{ - inouts = [lvar; rvar; result_var]; - operation = Binary_operation op; - } in - result_var, inst - -let build_compare_op lvar rvar (compare_op: compare_op) builder = - let result_var = get_new_intermed_temp builder in - let op = translate_compare_op compare_op in - let inst = Program_types.{ - inouts = [lvar; rvar; result_var]; - operation = Compare Operations_types.{op = op}; - } in - result_var, inst - -let build_instanceof_op lvar rvar builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [lvar; rvar; result_var]; - operation = Instance_of; - } in - result_var, inst - -let build_in_op lvar rvar builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [lvar; rvar; result_var]; - operation = In; - } in - result_var, inst - - -let build_unary_op var unary_op builder = - let result_var = get_new_intermed_temp builder in - let op = match unary_op with - Not -> Operations_types.Logical_not - | BitNot -> Operations_types.Bitwise_not - | Minus -> Operations_types.Minus - | Plus -> Operations_types.Plus - | PreInc -> Operations_types.Pre_inc - | PostInc -> Operations_types.Post_inc - | PreDec -> Operations_types.Pre_dec - | PostDec -> Operations_types.Post_dec - in - let unary_inst = Program_types.{ - inouts = [var; result_var]; - operation = Unary_operation Operations_types.{op = op}; - } in - result_var, unary_inst - -let build_await_op var builder = - let result_var = get_new_intermed_temp builder in - let inst : Program_types.instruction = Program_types.{ - inouts = [var; result_var]; - operation = Await; - } in - result_var, inst - -let build_typeof_op var builder = - let result_var = get_new_intermed_temp builder in - let inst : Program_types.instruction = Program_types.{ - inouts = [var; result_var]; - operation = Type_of; - } in - result_var, inst - -(* Fuzzilli doesn't have a loadVoid operator. Execute the operation inst, and then load undefined*) -let build_void_op builder = - let result_var = get_new_intermed_temp builder in - let inst : Program_types.instruction = Program_types.{ - inouts = [result_var]; - operation = Load_undefined; - } in - result_var, inst - -let build_yield_op var builder = - Program_types.{ - inouts = [var]; - operation = Yield; - } - -let build_yield_each_op var builder = - Program_types.{ - inouts = [var]; - operation = Yield_each; - } - -let build_continue builder = - Program_types.{ - inouts = []; - operation = Program_types.Continue; - } - -let build_dup_op value builder = - let result_var = get_new_intermed_temp builder in - let inst : Program_types.instruction = Program_types.{ - inouts = [value; result_var]; - operation = Program_types.Dup; - } in - result_var, inst - -let build_reassign_op dst src builder = - Program_types.{ - inouts = [dst; src]; - operation = Reassign; - } - -let build_begin_if var builder = - let begin_if_inst = Program_types.{ - inouts = [var]; - operation = Begin_if; - } in - begin_if_inst - -let build_begin_else builder = - let begin_else_inst = Program_types.{ - inouts = []; - operation = Begin_else; - } in - begin_else_inst - -let build_end_if builder = - let end_if_inst = Program_types.{ - inouts = []; - operation = End_if; - } in - end_if_inst - -let build_begin_while lvar rvar compare_op builder = - let op = translate_compare_op compare_op in - Program_types.{ - inouts = [lvar; rvar]; - operation = Begin_while{comparator = op}; - } - -let build_end_while builder = - Program_types.{ - inouts = []; - operation = End_while; - } - -let build_begin_do_while lvar rvar compare_op builder = - let op = translate_compare_op compare_op in - Program_types.{ - inouts = [lvar; rvar]; - operation = Begin_do_while{comparator = op}; - } - -let build_end_do_while builder = - Program_types.{ - inouts = []; - operation = End_do_while; - } - -let build_begin_for_in_op left_temp right_var builder = - let inst = Program_types.{ - inouts = [right_var; left_temp]; - operation = Program_types.Begin_for_in; - } in - left_temp, inst - -let build_end_for_in_op builder = - Program_types.{ - inouts = []; - operation = Program_types.End_for_in; - } - -let build_begin_for_of_op right_var builder = - let left_temp = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [right_var; left_temp]; - operation = Program_types.Begin_for_of; - } in - (left_temp, inst) - -let build_end_for_of_op builder = - Program_types.{ - inouts = []; - operation = Program_types.End_for_of; - } - -let build_begin_try_op builder = - Program_types.{ - inouts = []; - operation = Program_types.Begin_try; - } - -let build_begin_catch_op name builder = - let intermed_temp = get_new_intermed_temp builder in - add_new_var_identifier name intermed_temp builder; - Program_types.{ - inouts = [intermed_temp]; - operation = Program_types.Begin_catch; - } - -let build_end_try_catch_op builder = - Program_types.{ - inouts = []; - operation = Program_types.End_try_catch; - } - -let build_begin_with_op var builder = - Program_types.{ - inouts = [var]; - operation = Program_types.Begin_with; - } - -let build_end_with_op builder = - Program_types.{ - inouts = []; - operation = Program_types.End_with; - } - -let build_throw_op var builder = - Program_types.{ - inouts = [var]; - operation = Program_types.Throw_exception; - } - -let build_break_op builder = - Program_types.{ - inouts = []; - operation = Program_types.Break; - } - -let build_create_array args builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = args @ [result_var]; - operation = Create_array; - } in - result_var, inst - -let build_create_array_with_spread args spread_args builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = args @ [result_var]; - operation = Create_array_with_spread Operations_types.{spreads = spread_args}; - } in - result_var, inst - -let build_create_object name_list arg_list builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = arg_list @ [result_var]; - operation = Create_object{property_names = name_list}; - } in - result_var, inst - -let build_create_object_with_spread name_list arg_list builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = arg_list @ [result_var]; - operation = Create_object_with_spread{property_names = name_list}; - } in - result_var, inst - -let build_call func args builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [func] @ args @ [result_var]; - operation = Call_function; - } in - result_var, inst - -let build_call_with_spread func args spread_list builder = - let result_var = get_new_intermed_temp builder in - let inst = Program_types.{ - inouts = [func] @ args @ [result_var]; - operation = Call_function_with_spread Operations_types.{spreads = spread_list}; - } in - result_var, inst - -let build_call_method sub_exp_temp args method_name builder = - let result_var = get_new_intermed_temp builder in - let inst : Program_types.instruction = Program_types.{ - inouts = [sub_exp_temp] @ args @ [result_var]; - operation = Call_method{method_name = method_name}; - } in - result_var, inst - -let build_return_op var builder = - Program_types.{ - inouts = [var]; - operation = Program_types.Return; - } - -let id_to_func_type id builder = - let temp = get_new_intermed_temp builder in - let type_ext = Typesystem_types.{ - properties = []; - methods = []; - group = ""; - signature = None; - } in - let _type : Typesystem_types.type_ = Typesystem_types.{ - definite_type = nothing_type_int; - possible_type = anything_type_int; - ext = Extension type_ext; - } in - add_new_var_identifier id temp builder; - (temp, _type) - -(* TODO: Some of this functionality needs to be moved to translate.ml *) -let build_func_ops func_var arg_names rest_arg_name_opt is_arrow is_async is_generator builder = - - let temp_func x = id_to_func_type x builder in - let proced_ids = List.map temp_func arg_names in - let temps, types = List.split proced_ids in - - let rest_temp, rest_type = match rest_arg_name_opt with - None -> [], [] - | Some rest_arg_name -> - let rest_var = get_new_intermed_temp builder in - let type_ext = Typesystem_types.{ - properties = []; - methods = []; - group = ""; - signature = None; - } in - let type_mess : Typesystem_types.type_ = Typesystem_types.{ - definite_type = nothing_type_int; - possible_type = anything_type_int; - ext = Extension type_ext; - } in - add_new_var_identifier rest_arg_name rest_var builder; - [rest_var], [type_mess] - in - - let all_temps = temps @ rest_temp in - let all_types = types @ rest_type in - let type_ext = Typesystem_types.{ - properties = []; - methods = []; - group = ""; - signature = None; - } in - - (* Build start func inst*) - let output_type : Typesystem_types.type_ = Typesystem_types.{ - definite_type = unknown_type_int; - possible_type = unknown_type_int; - ext = Extension type_ext; - } in - - let func_signature : Typesystem_types.function_signature = Typesystem_types.{ - input_types = all_types; - output_type = Some output_type; - } in - - let begin_inst_op, end_inst_op = - if is_arrow then - if is_async then - let begin_func_op : Operations_types.begin_async_arrow_function_definition - = Operations_types.{signature = Some func_signature} in - let inst_op = Program_types.Begin_async_arrow_function_definition begin_func_op in - let end_op = Program_types.End_async_arrow_function_definition in - inst_op, end_op - else - (* Norm arrow *) - let begin_func_op : Operations_types.begin_arrow_function_definition - = Operations_types.{signature = Some func_signature} in - let inst_op = Program_types.Begin_arrow_function_definition begin_func_op in - let end_op = Program_types.End_arrow_function_definition in - inst_op, end_op - else - if is_async then - (* Norm Async*) - let begin_func_op : Operations_types.begin_async_function_definition - = Operations_types.{signature = Some func_signature} in - let inst_op = Program_types.Begin_async_function_definition begin_func_op in - let end_op = Program_types.End_async_function_definition in - inst_op, end_op - else - if is_generator then - (* Generator*) - let begin_func_op : Operations_types.begin_generator_function_definition - = Operations_types.{signature = Some func_signature} in - let inst_op = Program_types.Begin_generator_function_definition begin_func_op in - let end_op = Program_types.End_generator_function_definition in - inst_op, end_op - else - let begin_func_op : Operations_types.begin_plain_function_definition - = Operations_types.{signature = Some func_signature} in - let inst_op = Program_types.Begin_plain_function_definition begin_func_op in - let end_op = Program_types.End_plain_function_definition in - inst_op, end_op - in - let begin_func_inst = Program_types.{ - inouts = func_var :: all_temps; - operation = begin_inst_op; - } in - - let end_func_inst = Program_types.{ - inouts = []; - operation = end_inst_op; - } in - - (func_var, begin_func_inst, end_func_inst) - -let inst_to_prog_inst inst = - inst \ No newline at end of file diff --git a/Compiler/src/ProgramBuilder.mli b/Compiler/src/ProgramBuilder.mli deleted file mode 100644 index 0489f3dd..00000000 --- a/Compiler/src/ProgramBuilder.mli +++ /dev/null @@ -1,152 +0,0 @@ -type builder - -type var - -type inst - -(* A identifier is either in_scope as a fuzzilli temp, needs to be loaded from scope (e.g. a var in an exited scope), or is not found *) -type lookup_result = InScope of var - | NotFound - -type binary_op = Plus - | Minus - | Mult - | Div - | Mod - | Xor - | LShift - | RShift - | Exp - | RShift3 - | BitAnd - | BitOr - | LogicalAnd - | LogicalOr - -type compare_op = Equal - | NotEqual - | StrictEqual - | StrictNotEqual - | LessThan - | LessThanEqual - | GreaterThan - | GreaterThanEqual - -type unary_op = Not - | BitNot - | Minus - | Plus - | PreInc - | PostInc - | PreDec - | PostDec - -(* Initializes the variable builder *) -val init_builder : bool -> bool -> bool -> builder - -(* Gets a new temp variable number, for use in int32ermediate values *) -val get_new_intermed_temp : builder -> var - -(* Support functions for variable hoisting *) -val add_hoisted_var : string -> builder -> unit -val is_hoisted_var : string -> builder -> bool -val clear_hoisted_vars : builder -> unit - -(* Adds a new variable name & temp to the builder *) -val add_new_var_identifier : string -> var -> builder -> unit - -(* Adds a new scope to the stack *) -val push_local_scope : builder -> unit - -(* Removes the current scope from the stack *) -val pop_local_scope : builder -> unit - -(* Access if emit_builtins has been set *) -val should_emit_builtins : builder -> bool - -(* Looks up an existing variable name, and returns the associated variable number*) -val lookup_var_name : builder -> string -> lookup_result - -(* Whether to preprocess the hardcoded list of v8 natives, in order to remove the % *) -val include_v8_natives : builder -> bool - -(* Whether to replace unknown builtins with the placeholder builtin *) -val use_placeholder : builder -> bool - -(* Functions to build instructions in a manner similar to ProgramBuilder.swift *) -(* Note: Flow_Ast encodes BigInts as a float *) -val build_load_bigInt : float -> builder -> (var * inst) -val build_load_bool : bool -> builder -> (var * inst) -val build_load_builtin : string -> builder -> (var * inst) -val build_load_float : float -> builder -> (var * inst) -val build_load_from_scope : string -> builder -> (var * inst) -val build_load_integer : int64 -> builder -> (var * inst) -val build_load_null : builder -> (var * inst) -val build_load_regex : string -> string -> builder -> (var * inst) -val build_load_string : string -> builder -> (var * inst) -val build_load_undefined : builder -> (var * inst) - -val build_delete_prop : var -> string -> builder -> (var * inst) -val build_delete_computed_prop : var -> var -> builder -> (var * inst) -val build_load_prop : var -> string -> builder -> (var * inst) -val build_load_computed_prop : var -> var -> builder -> (var * inst) -val build_store_prop : var -> var -> string -> builder -> inst -val build_store_computed_prop : var -> var -> var -> builder -> inst -val build_load_element : var -> int -> builder -> (var * inst) -val build_new_object : var -> var list -> builder -> (var * inst) - -val build_binary_op : var -> var -> binary_op -> builder -> (var * inst) -val build_compare_op : var -> var -> compare_op -> builder -> (var * inst) -val build_instanceof_op : var -> var -> builder -> (var * inst) -val build_in_op : var -> var -> builder -> (var * inst) - -val build_unary_op : var -> unary_op -> builder -> (var * inst) -val build_await_op : var -> builder -> (var * inst) -val build_typeof_op : var -> builder -> (var * inst) -val build_void_op : builder -> (var * inst) -val build_yield_op : var -> builder -> inst -val build_yield_each_op : var -> builder -> inst - -val build_continue : builder -> inst -val build_dup_op : var -> builder -> (var * inst) -val build_reassign_op : var -> var -> builder -> inst - -val build_begin_if : var -> builder -> inst -val build_begin_else : builder -> inst -val build_end_if : builder -> inst - -val build_begin_while : var -> var -> compare_op -> builder -> inst -val build_end_while : builder -> inst -val build_begin_do_while : var -> var -> compare_op -> builder -> inst -val build_end_do_while : builder -> inst - -val build_begin_for_in_op : var -> var -> builder -> (var * inst) -val build_end_for_in_op : builder -> inst -val build_begin_for_of_op : var -> builder -> (var * inst) -val build_end_for_of_op : builder -> inst - - -val build_begin_try_op : builder -> inst -val build_begin_catch_op : string -> builder -> inst -val build_end_try_catch_op : builder -> inst - -val build_begin_with_op : var -> builder -> inst -val build_end_with_op : builder -> inst - -val build_throw_op : var -> builder -> inst -val build_break_op : builder -> inst - - -val build_create_array : var list -> builder -> (var * inst) -val build_create_array_with_spread : var list -> bool list -> builder -> (var * inst) -val build_create_object : string list -> var list -> builder -> (var * inst) -val build_create_object_with_spread : string list -> var list -> builder -> (var * inst) - -val build_call : var -> var list -> builder -> (var * inst) -val build_call_with_spread : var -> var list -> bool list-> builder -> (var * inst) -val build_call_method : var -> var list -> string -> builder -> (var * inst) -val build_return_op : var -> builder -> inst - -val build_func_ops : var -> string list -> string option -> bool -> bool -> bool -> builder -> (var * inst * inst) - -val inst_to_prog_inst : inst -> Program_types.instruction \ No newline at end of file diff --git a/Compiler/src/VariableScope.ml b/Compiler/src/VariableScope.ml deleted file mode 100644 index cd6cf236..00000000 --- a/Compiler/src/VariableScope.ml +++ /dev/null @@ -1,534 +0,0 @@ -module String_Set = Set.Make(String) - -type varUseData = - { - var_decs: String_Set.t; - var_cond_decs: String_Set.t; - var_uses: String_Set.t; - var_to_hoist: String_Set.t; - func_decs: String_Set.t; - func_uses: String_Set.t; - func_to_hoist: String_Set.t; - } - -let print_use_data d = - let print_set s = String_Set.iter print_endline s in - print_endline "Declares"; - print_set d.var_decs; - print_endline "Cond Declares"; - print_set d.var_cond_decs; - print_endline "Uses"; - print_set d.var_uses; - print_endline "Hoists"; - print_set d.var_to_hoist; - print_endline "Func Decs"; - print_set d.func_decs; - print_endline "Func Uses"; - print_set d.func_uses; - print_endline "Func Hoists"; - print_set d.func_to_hoist; - print_endline "" - -let empty_use_data = - { - var_decs = String_Set.empty; - var_cond_decs = String_Set.empty; - var_uses = String_Set.empty; - var_to_hoist = String_Set.empty; - func_decs = String_Set.empty; - func_uses = String_Set.empty; - func_to_hoist = String_Set.empty; - } - -let build_declare_data dec = - { - var_decs = String_Set.singleton dec; - var_cond_decs = String_Set.empty; - var_uses = String_Set.empty; - var_to_hoist = String_Set.empty; - func_decs = String_Set.empty; - func_uses = String_Set.empty; - func_to_hoist = String_Set.empty; - } - -let build_conditional_declare_data condDecl = - { - var_decs = String_Set.empty; - var_cond_decs = String_Set.singleton condDecl; - var_uses = String_Set.empty; - var_to_hoist = String_Set.empty; - func_decs = String_Set.empty; - func_uses = String_Set.empty; - func_to_hoist = String_Set.empty; - } - -let build_use_data use = - { - var_decs = String_Set.empty; - var_cond_decs = String_Set.empty; - var_uses = String_Set.singleton use; - var_to_hoist = String_Set.empty; - func_decs = String_Set.empty; - func_uses = String_Set.empty; - func_to_hoist = String_Set.empty; - } - -let build_function_dec_func dec = - { - var_decs = String_Set.empty; - var_cond_decs = String_Set.empty; - var_uses = String_Set.empty; - var_to_hoist = String_Set.empty; - func_decs = String_Set.singleton dec; - func_uses = String_Set.empty; - func_to_hoist = String_Set.empty; - } - -let build_function_use_data use = - { - var_decs = String_Set.empty; - var_cond_decs = String_Set.empty; - var_uses = String_Set.empty; - var_to_hoist = String_Set.empty; - func_decs = String_Set.empty; - func_uses = String_Set.singleton use; - func_to_hoist = String_Set.empty; - } - -let combine_use_data_nohoist (a: varUseData) (b: varUseData) = - let declares_union = String_Set.union a.var_decs b.var_decs in - let cond_declars_union = String_Set.union a.var_cond_decs b.var_cond_decs in - let res = - { - var_decs = declares_union; - var_cond_decs = String_Set.diff cond_declars_union declares_union; - var_uses = String_Set.union a.var_uses b.var_uses; - var_to_hoist = String_Set.union a.var_to_hoist b.var_to_hoist; - func_decs = String_Set.union a.func_decs b.func_decs; - func_uses = String_Set.union a.func_uses b.func_uses; - func_to_hoist = String_Set.union a.func_to_hoist b.func_to_hoist; - } in - res - -let combine_use_data_hoist (a: varUseData) (b: varUseData) = - let declares_union = String_Set.union a.var_decs b.var_decs in - let cond_declars_union = String_Set.union a.var_cond_decs b.var_cond_decs in - let new_hoist = String_Set.inter a.var_cond_decs b.var_uses in - let new_func_hoist = String_Set.inter a.func_uses b.func_decs in - let res = - { - var_decs = declares_union; - var_cond_decs = String_Set.diff cond_declars_union declares_union; - var_uses = String_Set.union a.var_uses b.var_uses; - var_to_hoist = String_Set.union a.var_to_hoist b.var_to_hoist |> String_Set.union new_hoist; - func_decs = String_Set.union a.func_decs b.func_decs; - func_uses = String_Set.union a.func_uses b.func_uses; - func_to_hoist = String_Set.union a.func_to_hoist b.func_to_hoist |> String_Set.union new_func_hoist; - } in - res - - -let combine_use_data_list_nohoist (l: varUseData list) = - List.fold_left combine_use_data_nohoist empty_use_data l - -let combine_use_data_list_hoist (l: varUseData list) = - List.fold_left combine_use_data_hoist empty_use_data l - -let leave_conditional_data data = - { - var_decs = String_Set.empty; - var_cond_decs = String_Set.union data.var_decs data.var_cond_decs; - var_uses = data.var_uses; - var_to_hoist = data.var_to_hoist; - func_decs = data.func_decs; - func_uses = data.func_uses; - func_to_hoist = data.func_to_hoist; - } - -(* For leaving a function *) -let remove_declared_and_used data = - { - var_decs = String_Set.empty; - var_cond_decs = String_Set.empty; - var_uses = String_Set.diff data.var_uses (String_Set.union data.var_decs data.var_cond_decs); - var_to_hoist = String_Set.empty; - func_decs = data.func_decs; - func_uses = data.func_uses; - func_to_hoist = data.func_to_hoist; - - } - -let rec get_expression_useData_array (exp: ('M, 'T) Flow_ast.Expression.Array.t) = - let data = List.map get_expression_useData_array_elem exp.elements in - combine_use_data_list_nohoist data - -and get_expression_useData_array_elem (elem: ('M, 'T) Flow_ast.Expression.Array.element) = - match elem with - Expression e -> get_expression_useData e - | Spread spread -> - let _, unwrapped = spread in - get_expression_useData unwrapped.argument - | Hole h -> - empty_use_data - -and get_expression_useData_arg_list (arg_list: ('M, 'T) Flow_ast.Expression.ArgList.t) = - let _, unwrapped = arg_list in - let arguments = unwrapped.arguments in - let proc_exp_or_spread (exp_or_spread: ('M, 'T) Flow_ast.Expression.expression_or_spread) = - match exp_or_spread with - Expression exp -> - get_expression_useData exp - | Spread spread -> - empty_use_data - in - List.map proc_exp_or_spread arguments |> combine_use_data_list_nohoist - -and get_expression_useData_assignment (assign_exp: (Loc.t, Loc.t) Flow_ast.Expression.Assignment.t) = - match assign_exp.left with - (_ , (Flow_ast.Pattern.Identifier id)) -> - let (_, act_name) = id.name in - let left = build_declare_data act_name.name in - let right = get_expression_useData assign_exp.right in - combine_use_data_nohoist left right - | (_, (Flow_ast.Pattern.Expression (_, exp))) -> - (match exp with - Flow_ast.Expression.Member mem -> - let obj_data = get_expression_useData mem._object in - let right_data = get_expression_useData assign_exp.right in - (match mem.property with - Flow_ast.Expression.Member.PropertyExpression pex -> - combine_use_data_list_nohoist (obj_data :: get_expression_useData pex :: [right_data]) - | Flow_ast.Expression.Member.PropertyIdentifier pid -> - let (_, unwapped_id) = pid in - let idData = build_declare_data unwapped_id.name in - combine_use_data_list_nohoist (obj_data :: [idData; right_data]) - | _ -> raise (Invalid_argument "Unhandled member property in exp assignment")) - | _ -> raise (Invalid_argument "Unhandled assignment expression left member")) - | _ -> raise (Invalid_argument "Unhandled assignment expressesion left ") - -and get_expression_useData_call (call_exp: ('M, 'T) Flow_ast.Expression.Call.t) = - let (_, callee) = call_exp.callee in - let arg_data = get_expression_useData_arg_list call_exp.arguments in - match callee with - (* Handle the method call case explicity*) - Flow_ast.Expression.Member member -> - (match member.property with - (* Handle method calls seperately for all other cases *) - Flow_ast.Expression.Member.PropertyIdentifier (_, id) -> - let sub_exp_data = get_expression_useData member._object in - let method_data = build_use_data id.name in - combine_use_data_list_nohoist (sub_exp_data :: arg_data :: [method_data]) - | _ -> - let callee_data = get_expression_useData call_exp.callee in - combine_use_data_nohoist callee_data arg_data) - | Flow_ast.Expression.Identifier id -> - let (_, unwrapped) = id in - let name = unwrapped.name in - let callee_data = build_function_use_data name in - combine_use_data_nohoist callee_data arg_data - | _ -> let callee_data = get_expression_useData call_exp.callee in - combine_use_data_nohoist callee_data arg_data - -(* Note: This is a conditional expression, not an if statement *) -and get_expression_useData_conditional (cond_exp: (Loc.t, Loc.t) Flow_ast.Expression.Conditional.t) = - let test_data = get_expression_useData cond_exp.test in - let consequent_data = get_expression_useData cond_exp.consequent in - let alternative_data =get_expression_useData cond_exp.alternate in - combine_use_data_list_nohoist (test_data :: consequent_data :: [alternative_data]) - -and get_expression_useData_member (memb_exp: ('M, 'T) Flow_ast.Expression.Member.t) = - let sub_data = get_expression_useData memb_exp._object in - let property_data = match memb_exp.property with - PropertyIdentifier (_, i) -> build_use_data i.name - | PropertyPrivateName (_, p) -> - let (_, i) = p.id in - build_use_data i.name - | PropertyExpression pe -> get_expression_useData pe - in - combine_use_data_nohoist sub_data property_data - -and get_expression_useData_new (new_exp: ('M, 'T) Flow_ast.Expression.New.t) = - let callee_data = get_expression_useData new_exp.callee in - let arguments = new_exp.arguments in - let arg_data = match arguments with - None -> empty_use_data - | Some act_args -> - get_expression_useData_arg_list act_args - in - combine_use_data_nohoist callee_data arg_data - -and get_expression_useData_object_property (prop_val: ('M, 'T) Flow_ast.Expression.Object.property) = - match prop_val with - Property (_, prop) -> - let data, prop_name_key = match prop with - Init init_val -> - let init_data = get_expression_useData init_val.value in - init_data, init_val.key - | Set func -> - let _, act_func = func.value in - let set_data = get_function_useData act_func in - set_data, func.key - | Get func -> - let (_, act_func) = func.value in - let func_data = get_function_useData act_func in - func_data, func.key - | Method func -> - let (_, act_func) = func.value in - let func_data = get_function_useData act_func in - func_data, func.key in - let prop_name : string = match prop_name_key with - Literal (_, l) -> l.raw - | Identifier (_, i) -> i.name - | PrivateName (_, p) -> let (_, i) = p.id in - i.name - | Computed _ -> raise (Invalid_argument "Unhandled Object key type Computed Key in object creation during var hoisting") in - let prop_name_data = build_use_data prop_name in - combine_use_data_nohoist data prop_name_data - | SpreadProperty (_, spreadProp) -> - get_expression_useData spreadProp.argument - -and get_expression_useData_object (exp : ('M, 'T) Flow_ast.Expression.Object.t) = - let props = exp.properties in - let prop_data = List.map get_expression_useData_object_property props in - combine_use_data_list_nohoist prop_data - -and get_expression_useData (exp: ('M, 'T) Flow_ast.Expression.t) = - let (_, unwrapped_exp) = exp in - match unwrapped_exp with - (Flow_ast.Expression.ArrowFunction arrow_func) -> - empty_use_data - | (Flow_ast.Expression.Array array_op) -> - get_expression_useData_array array_op - | (Flow_ast.Expression.Assignment assign_op) -> - get_expression_useData_assignment assign_op - | (Flow_ast.Expression.Binary bin_op) -> - combine_use_data_nohoist (get_expression_useData bin_op.left) (get_expression_useData bin_op.right) - | (Flow_ast.Expression.Call call_op) -> - get_expression_useData_call call_op - | (Flow_ast.Expression.Conditional cond_exp) -> - get_expression_useData_conditional cond_exp - | (Flow_ast.Expression.Function func_exp) -> - (match func_exp.id with - None -> empty_use_data - | Some (_, id) -> - build_declare_data id.name) - | (Flow_ast.Expression.Identifier id_val) -> - let (_, unwraped_id_val) = id_val in - build_use_data unwraped_id_val.name - | (Flow_ast.Expression.Import _) -> - empty_use_data - | (Flow_ast.Expression.Literal lit_val) -> - empty_use_data - | (Flow_ast.Expression.Logical log_op) -> - combine_use_data_nohoist (get_expression_useData log_op.left) (get_expression_useData log_op.right) - | (Flow_ast.Expression.Member memb_exp) -> - get_expression_useData_member memb_exp - | (Flow_ast.Expression.New new_exp) -> - get_expression_useData_new new_exp - | (Flow_ast.Expression.Object create_obj_op) -> - get_expression_useData_object create_obj_op - | (Flow_ast.Expression.This this_exp) -> - empty_use_data - | (Flow_ast.Expression.Unary u_val) -> - get_expression_useData u_val.argument - | (Flow_ast.Expression.Update update_exp) -> - get_expression_useData update_exp.argument - | (Flow_ast.Expression.Yield yield_exp) -> - (match yield_exp.argument with - Some x -> get_expression_useData x - | None -> empty_use_data) - | x -> raise (Invalid_argument ("Unhandled expression type in variable hoisting " ^ (Util.trim_flow_ast_string (Util.print_expression exp)))) - -and get_pattern_useData (pat: (Loc.t, Loc.t) Flow_ast.Pattern.t) = - match pat with - (_, (Flow_ast.Pattern.Identifier x)) -> - let var_id = x.name in - let (_, act_name) = var_id in - build_declare_data act_name.name - | (_, (Flow_ast.Pattern.Array arr)) -> - let proc_array_elem (b:(Loc.t, Loc.t) Flow_ast.Pattern.Array.element) = - match b with - Element (_, e) -> get_pattern_useData e.argument - | _ -> raise (Invalid_argument "Var Hoisting invalid argument in get_pattern_useddata") in - let processed_list = List.map proc_array_elem arr.elements in - combine_use_data_list_nohoist processed_list - | _ -> raise (Invalid_argument "Unhandled pattern in var hoisting") - -and get_function_useData (func: (Loc.t, Loc.t) Flow_ast.Function.t) = - let name_data = (match func.id with - None -> empty_use_data - | Some (_, id) -> - build_function_dec_func id.name) in - let body_data = match func.body with - BodyBlock body_block -> - let _, state_block = body_block in - get_statement_list_use_data state_block.body - | BodyExpression body_exp -> get_expression_useData body_exp - in - let res = combine_use_data_nohoist name_data (remove_declared_and_used body_data) in - res - -and get_statement_useData_doWhile (do_while_statement: (Loc.t, Loc.t) Flow_ast.Statement.DoWhile.t) = - let body_data = get_statement_useData do_while_statement.body |> leave_conditional_data in - let test_data = get_expression_useData do_while_statement.test in - combine_use_data_nohoist body_data test_data - -and get_statement_useData_for (for_state: (Loc.t, Loc.t) Flow_ast.Statement.For.t) = - let init_data = match for_state.init with - None -> empty_use_data - | Some (InitDeclaration (_, decl)) -> get_statement_vardecl_useData decl - | Some (InitExpression exp) -> get_expression_useData exp - in - let test_data = match for_state.test with - None -> empty_use_data - | Some exp -> get_expression_useData exp - in - let body_data = get_statement_useData for_state.body |> leave_conditional_data in - let update_data = match for_state.update with - None -> empty_use_data - | Some exp -> get_expression_useData exp - in - combine_use_data_list_nohoist [init_data; test_data; body_data; update_data] - -(* Both for-in and for-of only allow creation of a new variable on the left side *) -and get_statement_useData_for_in (for_in_state: (Loc.t, Loc.t) Flow_ast.Statement.ForIn.t) = - let right_data = get_expression_useData for_in_state.right in - let name_decl_data = match for_in_state.left with - LeftDeclaration (_, d) -> - let decs = d.declarations in - (match decs with - [(_, declarator)] -> ( match declarator.id with - (_, (Flow_ast.Pattern.Identifier x)) -> - let (_, act_name) = x.name in - build_declare_data act_name.name - | _ -> raise (Invalid_argument ("Improper declaration in for-in loop during var hoisting"))) - | _ -> raise (Invalid_argument "Improper declaration in for-in loop during var hoisting")) - | LeftPattern p -> (match p with - (_, (Flow_ast.Pattern.Identifier id)) -> - let (_, act_name) = id.name in - build_use_data act_name.name - | _ -> raise (Invalid_argument ("Inproper left pattern in for-in loop during var hoisting"))) in - (* let name_decl_data = build_declare_data act_name.name in *) - let body_data = get_statement_useData for_in_state.body in - let new_decls_conditional = combine_use_data_nohoist name_decl_data body_data |> leave_conditional_data in - combine_use_data_nohoist right_data new_decls_conditional - -and get_statement_useData_for_of (for_of_state: (Loc.t, Loc.t) Flow_ast.Statement.ForOf.t) = - let right_data = get_expression_useData for_of_state.right in - let var_id = match for_of_state.left with - LeftDeclaration (_, d) -> - let decs = d.declarations in - (match decs with - [(_, declarator)] -> ( match declarator.id with - (_, (Flow_ast.Pattern.Identifier x)) -> x - | _ -> raise (Invalid_argument ("Improper declaration in for-of loop during var hoisting"))) - | _ -> raise (Invalid_argument "Improper declaration in for-of loop during var hoisting")) - | LeftPattern p -> (match p with - (_, (Flow_ast.Pattern.Identifier id)) -> id - | _ -> raise (Invalid_argument ("Improper left pattern in for-of loop during var hoisting"))) in - let (_, act_name) = var_id.name in - let name_decl_data = build_declare_data act_name.name in - let body_data = get_statement_useData for_of_state.body in - let new_decls_conditional = combine_use_data_nohoist name_decl_data body_data |> leave_conditional_data in - combine_use_data_nohoist right_data new_decls_conditional - -and get_statement_useData_if (if_statement: (Loc.t, Loc.t) Flow_ast.Statement.If.t) = - let test_data = get_expression_useData if_statement.test in - let consequent_statement_data = get_statement_useData if_statement.consequent in - let fin_statement_data = match if_statement.alternate with - None -> empty_use_data - | Some (_, alt) -> - get_statement_useData alt.body - in - let conditional_data = combine_use_data_nohoist consequent_statement_data fin_statement_data in - let proc_cond_data = leave_conditional_data conditional_data in - let res = combine_use_data_nohoist test_data proc_cond_data in - res - -and get_statement_vardecl_useDat_rec (decs : (Loc.t, Loc.t) Flow_ast.Statement.VariableDeclaration.Declarator.t list) (kind: Flow_ast.Statement.VariableDeclaration.kind) = - match decs with - [] -> empty_use_data - | (_, declarator) :: tl -> - let dec_data = get_pattern_useData declarator.id in - let initalization_data = match declarator.init with - None -> empty_use_data - | Some exp -> get_expression_useData exp in - combine_use_data_nohoist dec_data initalization_data |> combine_use_data_nohoist (get_statement_vardecl_useDat_rec tl kind) - -and get_statement_vardecl_useData (var_decl: (Loc.t, Loc.t) Flow_ast.Statement.VariableDeclaration.t) = - let decs = var_decl.declarations in - let kind = var_decl.kind in - get_statement_vardecl_useDat_rec decs kind - -and get_statement_useData_return (ret_state: (Loc.t, Loc.t) Flow_ast.Statement.Return.t) = - match ret_state.argument with - None -> empty_use_data - | Some exp -> get_expression_useData exp - -and get_statement_useData_try (try_statement: (Loc.t, Loc.t) Flow_ast.Statement.Try.t) = - let (_, try_block) = try_statement.block in - let try_block_data = get_statement_list_use_data try_block.body in - let catch_block_data = match try_statement.handler with - None -> empty_use_data - | Some (_, catch_clause) -> - let temp_name = match catch_clause.param with - | Some (_, (Flow_ast.Pattern.Identifier var_identifier)) -> - let (_, act_name) = var_identifier.name in - act_name.name - | _ -> raise (Invalid_argument "Unsupported catch type") - in - let (_, catch_cause_block) = catch_clause.body in - let body_data = get_statement_list_use_data catch_cause_block.body in - let name_data = build_declare_data temp_name in - combine_use_data_nohoist body_data name_data - in - let finalizer_data = match try_statement.finalizer with - None -> empty_use_data - | Some (_, fin_block) -> get_statement_list_use_data fin_block.body in - let combined_data = combine_use_data_list_nohoist [try_block_data; catch_block_data; finalizer_data] in - leave_conditional_data combined_data - -and get_statement_useData_while (while_statement: (Loc.t, Loc.t) Flow_ast.Statement.While.t) = - let test_data = get_expression_useData while_statement.test in - let body_data = get_statement_useData while_statement.body |> leave_conditional_data in - combine_use_data_nohoist test_data body_data - -and get_statement_useData_with (with_state: (Loc.t, Loc.t) Flow_ast.Statement.With.t) = - let object_data = get_expression_useData with_state._object in - let body_data = get_statement_useData with_state.body |> leave_conditional_data in - combine_use_data_nohoist object_data body_data - -and get_statement_useData (statement: (Loc.t, Loc.t) Flow_ast.Statement.t) = - let res = match statement with - (_, Flow_ast.Statement.Block state_block) -> get_statement_list_use_data state_block.body - | (_, Flow_ast.Statement.Break _) -> empty_use_data - | (_, Flow_ast.Statement.Continue state_continue) -> empty_use_data - | (_, Flow_ast.Statement.DoWhile state_do_while) -> get_statement_useData_doWhile state_do_while - | (_, Flow_ast.Statement.Empty _) -> empty_use_data - | (_, Flow_ast.Statement.Expression state_exp) -> get_expression_useData state_exp.expression - | (_, Flow_ast.Statement.For state_for) -> get_statement_useData_for state_for - | (_, Flow_ast.Statement.ForIn state_foin) -> get_statement_useData_for_in state_foin - | (_, Flow_ast.Statement.ForOf state_forof) -> get_statement_useData_for_of state_forof - | (_, Flow_ast.Statement.FunctionDeclaration func_def) -> get_function_useData func_def - | (_, Flow_ast.Statement.If state_if) -> get_statement_useData_if state_if - | (_, Flow_ast.Statement.ImportDeclaration _) -> empty_use_data - | (_, Flow_ast.Statement.Return state_return) -> get_statement_useData_return state_return - | (_, Flow_ast.Statement.Throw state_throw) -> get_expression_useData state_throw.argument - | (_, Flow_ast.Statement.Try state_try) -> get_statement_useData_try state_try - | (_ , VariableDeclaration decl) -> get_statement_vardecl_useData decl - | (_, Flow_ast.Statement.While state_while) -> get_statement_useData_while state_while - | (_, Flow_ast.Statement.With state_with) -> get_statement_useData_with state_with - | _ as s -> raise (Invalid_argument (Printf.sprintf "Unhandled statement type in var hoisting %s" (Util.trim_flow_ast_string (Util.print_statement s)))) in - res - -and get_statement_list_use_data (statements: (Loc.t, Loc.t) Flow_ast.Statement.t list) = - let statement_data = List.map get_statement_useData statements in - let res = combine_use_data_list_hoist statement_data in - res - - -let get_vars_to_hoist (statements: (Loc.t, Loc.t) Flow_ast.Statement.t list) = - let varData = get_statement_list_use_data statements in - let var_res : string list = String_Set.to_seq varData.var_to_hoist |> List.of_seq in - let func_res : string list = String_Set.to_seq varData.func_to_hoist |> List.of_seq in - (var_res, func_res) \ No newline at end of file diff --git a/Compiler/src/VariableScope.mli b/Compiler/src/VariableScope.mli deleted file mode 100644 index 978da155..00000000 --- a/Compiler/src/VariableScope.mli +++ /dev/null @@ -1 +0,0 @@ -val get_vars_to_hoist : (Loc.t, Loc.t) Flow_ast.Statement.t list -> string list * string list \ No newline at end of file diff --git a/Compiler/src/compiler.ml b/Compiler/src/compiler.ml deleted file mode 100644 index ca63a978..00000000 --- a/Compiler/src/compiler.ml +++ /dev/null @@ -1,28 +0,0 @@ - -(* Translate an ast to a list of instructions *) -let flow_ast_to_inst_list = Translate.flow_ast_to_inst_list - -(* Util Interface *) -let print_ast_statement_list = Util.print_statement_list - -(* Run the flow_ast parser *) -let string_to_flow_ast = Util.string_to_flow_ast - -(* Output a generated Protobuf*) -let write_proto_obj_to_file = Util.write_proto_obj_to_file - -(* Wrap a list of instructions in the program structure *) -let inst_list_to_prog = Util.inst_list_to_prog - -(* Pretty print support *) -let pp_instruction = Program_pp.pp_instruction - -let init_test_builder = ProgramBuilder.init_builder false false false - -(* Give the test interface access to the protobufs *) -module Program_types = Program_types -module Operations_types = Operations_types -module Typesystem_types = Typesystem_types - -(* Make ProgramBuilder available to our test suite*) -module ProgramBuilder = ProgramBuilder \ No newline at end of file diff --git a/Compiler/src/dune b/Compiler/src/dune deleted file mode 100644 index 339839ed..00000000 --- a/Compiler/src/dune +++ /dev/null @@ -1,4 +0,0 @@ -(library - (name compiler) - (libraries core flow_parser ocaml-protoc proto str) - (preprocess (pps ppx_jane ppx_deriving ppx_deriving.show))) \ No newline at end of file diff --git a/Compiler/src/proto/dune b/Compiler/src/proto/dune deleted file mode 100644 index 11d17c2e..00000000 --- a/Compiler/src/proto/dune +++ /dev/null @@ -1,5 +0,0 @@ -(library - (name proto) - (wrapped false) - (libraries ocaml-protoc) - (preprocess (pps ppx_gen_rec ppx_deriving.std sedlex.ppx))) diff --git a/Compiler/src/proto/operations_pb.ml b/Compiler/src/proto/operations_pb.ml deleted file mode 100644 index 7022916d..00000000 --- a/Compiler/src/proto/operations_pb.ml +++ /dev/null @@ -1,1408 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - -type load_integer_mutable = { - mutable value : int64; -} - -let default_load_integer_mutable () : load_integer_mutable = { - value = 0L; -} - -type load_big_int_mutable = { - mutable value : int64; -} - -let default_load_big_int_mutable () : load_big_int_mutable = { - value = 0L; -} - -type load_float_mutable = { - mutable value : float; -} - -let default_load_float_mutable () : load_float_mutable = { - value = 0.; -} - -type load_string_mutable = { - mutable value : string; -} - -let default_load_string_mutable () : load_string_mutable = { - value = ""; -} - -type load_boolean_mutable = { - mutable value : bool; -} - -let default_load_boolean_mutable () : load_boolean_mutable = { - value = false; -} - -type load_reg_exp_mutable = { - mutable value : string; - mutable flags : int32; -} - -let default_load_reg_exp_mutable () : load_reg_exp_mutable = { - value = ""; - flags = 0l; -} - -type create_object_mutable = { - mutable property_names : string list; -} - -let default_create_object_mutable () : create_object_mutable = { - property_names = []; -} - -type create_object_with_spread_mutable = { - mutable property_names : string list; -} - -let default_create_object_with_spread_mutable () : create_object_with_spread_mutable = { - property_names = []; -} - -type create_array_with_spread_mutable = { - mutable spreads : bool list; -} - -let default_create_array_with_spread_mutable () : create_array_with_spread_mutable = { - spreads = []; -} - -type load_builtin_mutable = { - mutable builtin_name : string; -} - -let default_load_builtin_mutable () : load_builtin_mutable = { - builtin_name = ""; -} - -type load_property_mutable = { - mutable property_name : string; -} - -let default_load_property_mutable () : load_property_mutable = { - property_name = ""; -} - -type store_property_mutable = { - mutable property_name : string; -} - -let default_store_property_mutable () : store_property_mutable = { - property_name = ""; -} - -type delete_property_mutable = { - mutable property_name : string; -} - -let default_delete_property_mutable () : delete_property_mutable = { - property_name = ""; -} - -type load_element_mutable = { - mutable index : int64; -} - -let default_load_element_mutable () : load_element_mutable = { - index = 0L; -} - -type store_element_mutable = { - mutable index : int64; -} - -let default_store_element_mutable () : store_element_mutable = { - index = 0L; -} - -type delete_element_mutable = { - mutable index : int64; -} - -let default_delete_element_mutable () : delete_element_mutable = { - index = 0L; -} - -type begin_plain_function_definition_mutable = { - mutable signature : Typesystem_types.function_signature option; -} - -let default_begin_plain_function_definition_mutable () : begin_plain_function_definition_mutable = { - signature = None; -} - -type begin_strict_function_definition_mutable = { - mutable signature : Typesystem_types.function_signature option; -} - -let default_begin_strict_function_definition_mutable () : begin_strict_function_definition_mutable = { - signature = None; -} - -type begin_arrow_function_definition_mutable = { - mutable signature : Typesystem_types.function_signature option; -} - -let default_begin_arrow_function_definition_mutable () : begin_arrow_function_definition_mutable = { - signature = None; -} - -type begin_generator_function_definition_mutable = { - mutable signature : Typesystem_types.function_signature option; -} - -let default_begin_generator_function_definition_mutable () : begin_generator_function_definition_mutable = { - signature = None; -} - -type begin_async_function_definition_mutable = { - mutable signature : Typesystem_types.function_signature option; -} - -let default_begin_async_function_definition_mutable () : begin_async_function_definition_mutable = { - signature = None; -} - -type begin_async_arrow_function_definition_mutable = { - mutable signature : Typesystem_types.function_signature option; -} - -let default_begin_async_arrow_function_definition_mutable () : begin_async_arrow_function_definition_mutable = { - signature = None; -} - -type begin_async_generator_function_definition_mutable = { - mutable signature : Typesystem_types.function_signature option; -} - -let default_begin_async_generator_function_definition_mutable () : begin_async_generator_function_definition_mutable = { - signature = None; -} - -type call_method_mutable = { - mutable method_name : string; -} - -let default_call_method_mutable () : call_method_mutable = { - method_name = ""; -} - -type call_function_with_spread_mutable = { - mutable spreads : bool list; -} - -let default_call_function_with_spread_mutable () : call_function_with_spread_mutable = { - spreads = []; -} - -type unary_operation_mutable = { - mutable op : Operations_types.unary_operator; -} - -let default_unary_operation_mutable () : unary_operation_mutable = { - op = Operations_types.default_unary_operator (); -} - -type binary_operation_mutable = { - mutable op : Operations_types.binary_operator; -} - -let default_binary_operation_mutable () : binary_operation_mutable = { - op = Operations_types.default_binary_operator (); -} - -type compare_mutable = { - mutable op : Operations_types.comparator; -} - -let default_compare_mutable () : compare_mutable = { - op = Operations_types.default_comparator (); -} - -type eval_mutable = { - mutable code : string; -} - -let default_eval_mutable () : eval_mutable = { - code = ""; -} - -type begin_class_definition_mutable = { - mutable has_superclass : bool; - mutable constructor_parameters : Typesystem_types.type_ list; - mutable instance_properties : string list; - mutable instance_method_names : string list; - mutable instance_method_signatures : Typesystem_types.function_signature list; -} - -let default_begin_class_definition_mutable () : begin_class_definition_mutable = { - has_superclass = false; - constructor_parameters = []; - instance_properties = []; - instance_method_names = []; - instance_method_signatures = []; -} - -type begin_method_definition_mutable = { - mutable num_parameters : int32; -} - -let default_begin_method_definition_mutable () : begin_method_definition_mutable = { - num_parameters = 0l; -} - -type call_super_method_mutable = { - mutable method_name : string; -} - -let default_call_super_method_mutable () : call_super_method_mutable = { - method_name = ""; -} - -type load_super_property_mutable = { - mutable property_name : string; -} - -let default_load_super_property_mutable () : load_super_property_mutable = { - property_name = ""; -} - -type store_super_property_mutable = { - mutable property_name : string; -} - -let default_store_super_property_mutable () : store_super_property_mutable = { - property_name = ""; -} - -type load_from_scope_mutable = { - mutable id : string; -} - -let default_load_from_scope_mutable () : load_from_scope_mutable = { - id = ""; -} - -type store_to_scope_mutable = { - mutable id : string; -} - -let default_store_to_scope_mutable () : store_to_scope_mutable = { - id = ""; -} - -type begin_while_mutable = { - mutable comparator : Operations_types.comparator; -} - -let default_begin_while_mutable () : begin_while_mutable = { - comparator = Operations_types.default_comparator (); -} - -type begin_do_while_mutable = { - mutable comparator : Operations_types.comparator; -} - -let default_begin_do_while_mutable () : begin_do_while_mutable = { - comparator = Operations_types.default_comparator (); -} - -type begin_for_mutable = { - mutable comparator : Operations_types.comparator; - mutable op : Operations_types.binary_operator; -} - -let default_begin_for_mutable () : begin_for_mutable = { - comparator = Operations_types.default_comparator (); - op = Operations_types.default_binary_operator (); -} - - -let rec decode_load_integer d = - let v = default_load_integer_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.value <- Pbrt.Decoder.int64_as_varint d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_integer), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.value = v.value; - } : Operations_types.load_integer) - -let rec decode_load_big_int d = - let v = default_load_big_int_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.value <- Pbrt.Decoder.int64_as_varint d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_big_int), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.value = v.value; - } : Operations_types.load_big_int) - -let rec decode_load_float d = - let v = default_load_float_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bits64) -> begin - v.value <- Pbrt.Decoder.float_as_bits64 d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_float), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.value = v.value; - } : Operations_types.load_float) - -let rec decode_load_string d = - let v = default_load_string_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.value <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_string), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.value = v.value; - } : Operations_types.load_string) - -let rec decode_load_boolean d = - let v = default_load_boolean_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.value <- Pbrt.Decoder.bool d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_boolean), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.value = v.value; - } : Operations_types.load_boolean) - -let rec decode_load_reg_exp d = - let v = default_load_reg_exp_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.value <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_reg_exp), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.flags <- Pbrt.Decoder.int32_as_varint d; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_reg_exp), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.value = v.value; - Operations_types.flags = v.flags; - } : Operations_types.load_reg_exp) - -let rec decode_create_object d = - let v = default_create_object_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.property_names <- List.rev v.property_names; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.property_names <- (Pbrt.Decoder.string d) :: v.property_names; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(create_object), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.property_names = v.property_names; - } : Operations_types.create_object) - -let rec decode_create_object_with_spread d = - let v = default_create_object_with_spread_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.property_names <- List.rev v.property_names; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.property_names <- (Pbrt.Decoder.string d) :: v.property_names; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(create_object_with_spread), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.property_names = v.property_names; - } : Operations_types.create_object_with_spread) - -let rec decode_create_array_with_spread d = - let v = default_create_array_with_spread_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.spreads <- List.rev v.spreads; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.spreads <- Pbrt.Decoder.packed_fold (fun l d -> (Pbrt.Decoder.bool d)::l) [] d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(create_array_with_spread), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.spreads = v.spreads; - } : Operations_types.create_array_with_spread) - -let rec decode_load_builtin d = - let v = default_load_builtin_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.builtin_name <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_builtin), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.builtin_name = v.builtin_name; - } : Operations_types.load_builtin) - -let rec decode_load_property d = - let v = default_load_property_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.property_name <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_property), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.property_name = v.property_name; - } : Operations_types.load_property) - -let rec decode_store_property d = - let v = default_store_property_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.property_name <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(store_property), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.property_name = v.property_name; - } : Operations_types.store_property) - -let rec decode_delete_property d = - let v = default_delete_property_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.property_name <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(delete_property), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.property_name = v.property_name; - } : Operations_types.delete_property) - -let rec decode_load_element d = - let v = default_load_element_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.index <- Pbrt.Decoder.int64_as_varint d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_element), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.index = v.index; - } : Operations_types.load_element) - -let rec decode_store_element d = - let v = default_store_element_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.index <- Pbrt.Decoder.int64_as_varint d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(store_element), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.index = v.index; - } : Operations_types.store_element) - -let rec decode_delete_element d = - let v = default_delete_element_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.index <- Pbrt.Decoder.int64_as_varint d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(delete_element), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.index = v.index; - } : Operations_types.delete_element) - -let rec decode_begin_plain_function_definition d = - let v = default_begin_plain_function_definition_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.signature <- Some (Typesystem_pb.decode_function_signature (Pbrt.Decoder.nested d)); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_plain_function_definition), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.signature = v.signature; - } : Operations_types.begin_plain_function_definition) - -let rec decode_begin_strict_function_definition d = - let v = default_begin_strict_function_definition_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.signature <- Some (Typesystem_pb.decode_function_signature (Pbrt.Decoder.nested d)); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_strict_function_definition), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.signature = v.signature; - } : Operations_types.begin_strict_function_definition) - -let rec decode_begin_arrow_function_definition d = - let v = default_begin_arrow_function_definition_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.signature <- Some (Typesystem_pb.decode_function_signature (Pbrt.Decoder.nested d)); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_arrow_function_definition), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.signature = v.signature; - } : Operations_types.begin_arrow_function_definition) - -let rec decode_begin_generator_function_definition d = - let v = default_begin_generator_function_definition_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.signature <- Some (Typesystem_pb.decode_function_signature (Pbrt.Decoder.nested d)); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_generator_function_definition), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.signature = v.signature; - } : Operations_types.begin_generator_function_definition) - -let rec decode_begin_async_function_definition d = - let v = default_begin_async_function_definition_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.signature <- Some (Typesystem_pb.decode_function_signature (Pbrt.Decoder.nested d)); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_async_function_definition), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.signature = v.signature; - } : Operations_types.begin_async_function_definition) - -let rec decode_begin_async_arrow_function_definition d = - let v = default_begin_async_arrow_function_definition_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.signature <- Some (Typesystem_pb.decode_function_signature (Pbrt.Decoder.nested d)); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_async_arrow_function_definition), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.signature = v.signature; - } : Operations_types.begin_async_arrow_function_definition) - -let rec decode_begin_async_generator_function_definition d = - let v = default_begin_async_generator_function_definition_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.signature <- Some (Typesystem_pb.decode_function_signature (Pbrt.Decoder.nested d)); - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_async_generator_function_definition), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.signature = v.signature; - } : Operations_types.begin_async_generator_function_definition) - -let rec decode_call_method d = - let v = default_call_method_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.method_name <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(call_method), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.method_name = v.method_name; - } : Operations_types.call_method) - -let rec decode_call_function_with_spread d = - let v = default_call_function_with_spread_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.spreads <- List.rev v.spreads; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.spreads <- Pbrt.Decoder.packed_fold (fun l d -> (Pbrt.Decoder.bool d)::l) [] d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(call_function_with_spread), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.spreads = v.spreads; - } : Operations_types.call_function_with_spread) - -let rec decode_unary_operator d = - match Pbrt.Decoder.int_as_varint d with - | 0 -> (Operations_types.Pre_inc:Operations_types.unary_operator) - | 1 -> (Operations_types.Pre_dec:Operations_types.unary_operator) - | 2 -> (Operations_types.Post_inc:Operations_types.unary_operator) - | 3 -> (Operations_types.Post_dec:Operations_types.unary_operator) - | 4 -> (Operations_types.Logical_not:Operations_types.unary_operator) - | 5 -> (Operations_types.Bitwise_not:Operations_types.unary_operator) - | 6 -> (Operations_types.Plus:Operations_types.unary_operator) - | 7 -> (Operations_types.Minus:Operations_types.unary_operator) - | _ -> Pbrt.Decoder.malformed_variant "unary_operator" - -let rec decode_unary_operation d = - let v = default_unary_operation_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.op <- decode_unary_operator d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(unary_operation), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.op = v.op; - } : Operations_types.unary_operation) - -let rec decode_binary_operator d = - match Pbrt.Decoder.int_as_varint d with - | 0 -> (Operations_types.Add:Operations_types.binary_operator) - | 1 -> (Operations_types.Sub:Operations_types.binary_operator) - | 2 -> (Operations_types.Mul:Operations_types.binary_operator) - | 3 -> (Operations_types.Div:Operations_types.binary_operator) - | 4 -> (Operations_types.Mod:Operations_types.binary_operator) - | 5 -> (Operations_types.Bit_and:Operations_types.binary_operator) - | 6 -> (Operations_types.Bit_or:Operations_types.binary_operator) - | 7 -> (Operations_types.Logical_and:Operations_types.binary_operator) - | 8 -> (Operations_types.Logical_or:Operations_types.binary_operator) - | 9 -> (Operations_types.Xor:Operations_types.binary_operator) - | 10 -> (Operations_types.Lshift:Operations_types.binary_operator) - | 11 -> (Operations_types.Rshift:Operations_types.binary_operator) - | 12 -> (Operations_types.Exp:Operations_types.binary_operator) - | 13 -> (Operations_types.Unrshift:Operations_types.binary_operator) - | _ -> Pbrt.Decoder.malformed_variant "binary_operator" - -let rec decode_binary_operation d = - let v = default_binary_operation_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.op <- decode_binary_operator d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(binary_operation), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.op = v.op; - } : Operations_types.binary_operation) - -let rec decode_comparator d = - match Pbrt.Decoder.int_as_varint d with - | 0 -> (Operations_types.Equal:Operations_types.comparator) - | 1 -> (Operations_types.Strict_equal:Operations_types.comparator) - | 2 -> (Operations_types.Not_equal:Operations_types.comparator) - | 3 -> (Operations_types.Strict_not_equal:Operations_types.comparator) - | 4 -> (Operations_types.Less_than:Operations_types.comparator) - | 5 -> (Operations_types.Less_than_or_equal:Operations_types.comparator) - | 6 -> (Operations_types.Greater_than:Operations_types.comparator) - | 7 -> (Operations_types.Greater_than_or_equal:Operations_types.comparator) - | _ -> Pbrt.Decoder.malformed_variant "comparator" - -let rec decode_compare d = - let v = default_compare_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.op <- decode_comparator d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(compare), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.op = v.op; - } : Operations_types.compare) - -let rec decode_eval d = - let v = default_eval_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.code <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(eval), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.code = v.code; - } : Operations_types.eval) - -let rec decode_begin_class_definition d = - let v = default_begin_class_definition_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.instance_method_signatures <- List.rev v.instance_method_signatures; - v.instance_method_names <- List.rev v.instance_method_names; - v.instance_properties <- List.rev v.instance_properties; - v.constructor_parameters <- List.rev v.constructor_parameters; - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.has_superclass <- Pbrt.Decoder.bool d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_class_definition), field(1)" pk - | Some (2, Pbrt.Bytes) -> begin - v.constructor_parameters <- (Typesystem_pb.decode_type_ (Pbrt.Decoder.nested d)) :: v.constructor_parameters; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_class_definition), field(2)" pk - | Some (3, Pbrt.Bytes) -> begin - v.instance_properties <- (Pbrt.Decoder.string d) :: v.instance_properties; - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_class_definition), field(3)" pk - | Some (4, Pbrt.Bytes) -> begin - v.instance_method_names <- (Pbrt.Decoder.string d) :: v.instance_method_names; - end - | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_class_definition), field(4)" pk - | Some (5, Pbrt.Bytes) -> begin - v.instance_method_signatures <- (Typesystem_pb.decode_function_signature (Pbrt.Decoder.nested d)) :: v.instance_method_signatures; - end - | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_class_definition), field(5)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.has_superclass = v.has_superclass; - Operations_types.constructor_parameters = v.constructor_parameters; - Operations_types.instance_properties = v.instance_properties; - Operations_types.instance_method_names = v.instance_method_names; - Operations_types.instance_method_signatures = v.instance_method_signatures; - } : Operations_types.begin_class_definition) - -let rec decode_begin_method_definition d = - let v = default_begin_method_definition_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.num_parameters <- Pbrt.Decoder.int32_as_varint d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_method_definition), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.num_parameters = v.num_parameters; - } : Operations_types.begin_method_definition) - -let rec decode_call_super_method d = - let v = default_call_super_method_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.method_name <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(call_super_method), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.method_name = v.method_name; - } : Operations_types.call_super_method) - -let rec decode_load_super_property d = - let v = default_load_super_property_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.property_name <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_super_property), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.property_name = v.property_name; - } : Operations_types.load_super_property) - -let rec decode_store_super_property d = - let v = default_store_super_property_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.property_name <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(store_super_property), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.property_name = v.property_name; - } : Operations_types.store_super_property) - -let rec decode_load_from_scope d = - let v = default_load_from_scope_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.id <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(load_from_scope), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.id = v.id; - } : Operations_types.load_from_scope) - -let rec decode_store_to_scope d = - let v = default_store_to_scope_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.id <- Pbrt.Decoder.string d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(store_to_scope), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.id = v.id; - } : Operations_types.store_to_scope) - -let rec decode_begin_while d = - let v = default_begin_while_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.comparator <- decode_comparator d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_while), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.comparator = v.comparator; - } : Operations_types.begin_while) - -let rec decode_begin_do_while d = - let v = default_begin_do_while_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.comparator <- decode_comparator d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_do_while), field(1)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.comparator = v.comparator; - } : Operations_types.begin_do_while) - -let rec decode_begin_for d = - let v = default_begin_for_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.comparator <- decode_comparator d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_for), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.op <- decode_binary_operator d; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(begin_for), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Operations_types.comparator = v.comparator; - Operations_types.op = v.op; - } : Operations_types.begin_for) - -let rec encode_load_integer (v:Operations_types.load_integer) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.int64_as_varint v.Operations_types.value encoder; - () - -let rec encode_load_big_int (v:Operations_types.load_big_int) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.int64_as_varint v.Operations_types.value encoder; - () - -let rec encode_load_float (v:Operations_types.load_float) encoder = - Pbrt.Encoder.key (1, Pbrt.Bits64) encoder; - Pbrt.Encoder.float_as_bits64 v.Operations_types.value encoder; - () - -let rec encode_load_string (v:Operations_types.load_string) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.value encoder; - () - -let rec encode_load_boolean (v:Operations_types.load_boolean) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.bool v.Operations_types.value encoder; - () - -let rec encode_load_reg_exp (v:Operations_types.load_reg_exp) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.value encoder; - Pbrt.Encoder.key (2, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint v.Operations_types.flags encoder; - () - -let rec encode_create_object (v:Operations_types.create_object) encoder = - List.iter (fun x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string x encoder; - ) v.Operations_types.property_names; - () - -let rec encode_create_object_with_spread (v:Operations_types.create_object_with_spread) encoder = - List.iter (fun x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string x encoder; - ) v.Operations_types.property_names; - () - -let rec encode_create_array_with_spread (v:Operations_types.create_array_with_spread) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (fun encoder -> - List.iter (fun x -> - Pbrt.Encoder.bool x encoder; - ) v.Operations_types.spreads; - ) encoder; - () - -let rec encode_load_builtin (v:Operations_types.load_builtin) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.builtin_name encoder; - () - -let rec encode_load_property (v:Operations_types.load_property) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.property_name encoder; - () - -let rec encode_store_property (v:Operations_types.store_property) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.property_name encoder; - () - -let rec encode_delete_property (v:Operations_types.delete_property) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.property_name encoder; - () - -let rec encode_load_element (v:Operations_types.load_element) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.int64_as_varint v.Operations_types.index encoder; - () - -let rec encode_store_element (v:Operations_types.store_element) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.int64_as_varint v.Operations_types.index encoder; - () - -let rec encode_delete_element (v:Operations_types.delete_element) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.int64_as_varint v.Operations_types.index encoder; - () - -let rec encode_begin_plain_function_definition (v:Operations_types.begin_plain_function_definition) encoder = - begin match v.Operations_types.signature with - | Some x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_function_signature x) encoder; - | None -> (); - end; - () - -let rec encode_begin_strict_function_definition (v:Operations_types.begin_strict_function_definition) encoder = - begin match v.Operations_types.signature with - | Some x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_function_signature x) encoder; - | None -> (); - end; - () - -let rec encode_begin_arrow_function_definition (v:Operations_types.begin_arrow_function_definition) encoder = - begin match v.Operations_types.signature with - | Some x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_function_signature x) encoder; - | None -> (); - end; - () - -let rec encode_begin_generator_function_definition (v:Operations_types.begin_generator_function_definition) encoder = - begin match v.Operations_types.signature with - | Some x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_function_signature x) encoder; - | None -> (); - end; - () - -let rec encode_begin_async_function_definition (v:Operations_types.begin_async_function_definition) encoder = - begin match v.Operations_types.signature with - | Some x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_function_signature x) encoder; - | None -> (); - end; - () - -let rec encode_begin_async_arrow_function_definition (v:Operations_types.begin_async_arrow_function_definition) encoder = - begin match v.Operations_types.signature with - | Some x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_function_signature x) encoder; - | None -> (); - end; - () - -let rec encode_begin_async_generator_function_definition (v:Operations_types.begin_async_generator_function_definition) encoder = - begin match v.Operations_types.signature with - | Some x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_function_signature x) encoder; - | None -> (); - end; - () - -let rec encode_call_method (v:Operations_types.call_method) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.method_name encoder; - () - -let rec encode_call_function_with_spread (v:Operations_types.call_function_with_spread) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (fun encoder -> - List.iter (fun x -> - Pbrt.Encoder.bool x encoder; - ) v.Operations_types.spreads; - ) encoder; - () - -let rec encode_unary_operator (v:Operations_types.unary_operator) encoder = - match v with - | Operations_types.Pre_inc -> Pbrt.Encoder.int_as_varint (0) encoder - | Operations_types.Pre_dec -> Pbrt.Encoder.int_as_varint 1 encoder - | Operations_types.Post_inc -> Pbrt.Encoder.int_as_varint 2 encoder - | Operations_types.Post_dec -> Pbrt.Encoder.int_as_varint 3 encoder - | Operations_types.Logical_not -> Pbrt.Encoder.int_as_varint 4 encoder - | Operations_types.Bitwise_not -> Pbrt.Encoder.int_as_varint 5 encoder - | Operations_types.Plus -> Pbrt.Encoder.int_as_varint 6 encoder - | Operations_types.Minus -> Pbrt.Encoder.int_as_varint 7 encoder - -let rec encode_unary_operation (v:Operations_types.unary_operation) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - encode_unary_operator v.Operations_types.op encoder; - () - -let rec encode_binary_operator (v:Operations_types.binary_operator) encoder = - match v with - | Operations_types.Add -> Pbrt.Encoder.int_as_varint (0) encoder - | Operations_types.Sub -> Pbrt.Encoder.int_as_varint 1 encoder - | Operations_types.Mul -> Pbrt.Encoder.int_as_varint 2 encoder - | Operations_types.Div -> Pbrt.Encoder.int_as_varint 3 encoder - | Operations_types.Mod -> Pbrt.Encoder.int_as_varint 4 encoder - | Operations_types.Bit_and -> Pbrt.Encoder.int_as_varint 5 encoder - | Operations_types.Bit_or -> Pbrt.Encoder.int_as_varint 6 encoder - | Operations_types.Logical_and -> Pbrt.Encoder.int_as_varint 7 encoder - | Operations_types.Logical_or -> Pbrt.Encoder.int_as_varint 8 encoder - | Operations_types.Xor -> Pbrt.Encoder.int_as_varint 9 encoder - | Operations_types.Lshift -> Pbrt.Encoder.int_as_varint 10 encoder - | Operations_types.Rshift -> Pbrt.Encoder.int_as_varint 11 encoder - | Operations_types.Exp -> Pbrt.Encoder.int_as_varint 12 encoder - | Operations_types.Unrshift -> Pbrt.Encoder.int_as_varint 13 encoder - -let rec encode_binary_operation (v:Operations_types.binary_operation) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - encode_binary_operator v.Operations_types.op encoder; - () - -let rec encode_comparator (v:Operations_types.comparator) encoder = - match v with - | Operations_types.Equal -> Pbrt.Encoder.int_as_varint (0) encoder - | Operations_types.Strict_equal -> Pbrt.Encoder.int_as_varint 1 encoder - | Operations_types.Not_equal -> Pbrt.Encoder.int_as_varint 2 encoder - | Operations_types.Strict_not_equal -> Pbrt.Encoder.int_as_varint 3 encoder - | Operations_types.Less_than -> Pbrt.Encoder.int_as_varint 4 encoder - | Operations_types.Less_than_or_equal -> Pbrt.Encoder.int_as_varint 5 encoder - | Operations_types.Greater_than -> Pbrt.Encoder.int_as_varint 6 encoder - | Operations_types.Greater_than_or_equal -> Pbrt.Encoder.int_as_varint 7 encoder - -let rec encode_compare (v:Operations_types.compare) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - encode_comparator v.Operations_types.op encoder; - () - -let rec encode_eval (v:Operations_types.eval) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.code encoder; - () - -let rec encode_begin_class_definition (v:Operations_types.begin_class_definition) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.bool v.Operations_types.has_superclass encoder; - List.iter (fun x -> - Pbrt.Encoder.key (2, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_type_ x) encoder; - ) v.Operations_types.constructor_parameters; - List.iter (fun x -> - Pbrt.Encoder.key (3, Pbrt.Bytes) encoder; - Pbrt.Encoder.string x encoder; - ) v.Operations_types.instance_properties; - List.iter (fun x -> - Pbrt.Encoder.key (4, Pbrt.Bytes) encoder; - Pbrt.Encoder.string x encoder; - ) v.Operations_types.instance_method_names; - List.iter (fun x -> - Pbrt.Encoder.key (5, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_function_signature x) encoder; - ) v.Operations_types.instance_method_signatures; - () - -let rec encode_begin_method_definition (v:Operations_types.begin_method_definition) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint v.Operations_types.num_parameters encoder; - () - -let rec encode_call_super_method (v:Operations_types.call_super_method) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.method_name encoder; - () - -let rec encode_load_super_property (v:Operations_types.load_super_property) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.property_name encoder; - () - -let rec encode_store_super_property (v:Operations_types.store_super_property) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.property_name encoder; - () - -let rec encode_load_from_scope (v:Operations_types.load_from_scope) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.id encoder; - () - -let rec encode_store_to_scope (v:Operations_types.store_to_scope) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Operations_types.id encoder; - () - -let rec encode_begin_while (v:Operations_types.begin_while) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - encode_comparator v.Operations_types.comparator encoder; - () - -let rec encode_begin_do_while (v:Operations_types.begin_do_while) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - encode_comparator v.Operations_types.comparator encoder; - () - -let rec encode_begin_for (v:Operations_types.begin_for) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - encode_comparator v.Operations_types.comparator encoder; - Pbrt.Encoder.key (2, Pbrt.Varint) encoder; - encode_binary_operator v.Operations_types.op encoder; - () diff --git a/Compiler/src/proto/operations_pb.mli b/Compiler/src/proto/operations_pb.mli deleted file mode 100644 index ef3c0182..00000000 --- a/Compiler/src/proto/operations_pb.mli +++ /dev/null @@ -1,259 +0,0 @@ -(** operations.proto Binary Encoding *) - - -(** {2 Protobuf Encoding} *) - -val encode_load_integer : Operations_types.load_integer -> Pbrt.Encoder.t -> unit -(** [encode_load_integer v encoder] encodes [v] with the given [encoder] *) - -val encode_load_big_int : Operations_types.load_big_int -> Pbrt.Encoder.t -> unit -(** [encode_load_big_int v encoder] encodes [v] with the given [encoder] *) - -val encode_load_float : Operations_types.load_float -> Pbrt.Encoder.t -> unit -(** [encode_load_float v encoder] encodes [v] with the given [encoder] *) - -val encode_load_string : Operations_types.load_string -> Pbrt.Encoder.t -> unit -(** [encode_load_string v encoder] encodes [v] with the given [encoder] *) - -val encode_load_boolean : Operations_types.load_boolean -> Pbrt.Encoder.t -> unit -(** [encode_load_boolean v encoder] encodes [v] with the given [encoder] *) - -val encode_load_reg_exp : Operations_types.load_reg_exp -> Pbrt.Encoder.t -> unit -(** [encode_load_reg_exp v encoder] encodes [v] with the given [encoder] *) - -val encode_create_object : Operations_types.create_object -> Pbrt.Encoder.t -> unit -(** [encode_create_object v encoder] encodes [v] with the given [encoder] *) - -val encode_create_object_with_spread : Operations_types.create_object_with_spread -> Pbrt.Encoder.t -> unit -(** [encode_create_object_with_spread v encoder] encodes [v] with the given [encoder] *) - -val encode_create_array_with_spread : Operations_types.create_array_with_spread -> Pbrt.Encoder.t -> unit -(** [encode_create_array_with_spread v encoder] encodes [v] with the given [encoder] *) - -val encode_load_builtin : Operations_types.load_builtin -> Pbrt.Encoder.t -> unit -(** [encode_load_builtin v encoder] encodes [v] with the given [encoder] *) - -val encode_load_property : Operations_types.load_property -> Pbrt.Encoder.t -> unit -(** [encode_load_property v encoder] encodes [v] with the given [encoder] *) - -val encode_store_property : Operations_types.store_property -> Pbrt.Encoder.t -> unit -(** [encode_store_property v encoder] encodes [v] with the given [encoder] *) - -val encode_delete_property : Operations_types.delete_property -> Pbrt.Encoder.t -> unit -(** [encode_delete_property v encoder] encodes [v] with the given [encoder] *) - -val encode_load_element : Operations_types.load_element -> Pbrt.Encoder.t -> unit -(** [encode_load_element v encoder] encodes [v] with the given [encoder] *) - -val encode_store_element : Operations_types.store_element -> Pbrt.Encoder.t -> unit -(** [encode_store_element v encoder] encodes [v] with the given [encoder] *) - -val encode_delete_element : Operations_types.delete_element -> Pbrt.Encoder.t -> unit -(** [encode_delete_element v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_plain_function_definition : Operations_types.begin_plain_function_definition -> Pbrt.Encoder.t -> unit -(** [encode_begin_plain_function_definition v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_strict_function_definition : Operations_types.begin_strict_function_definition -> Pbrt.Encoder.t -> unit -(** [encode_begin_strict_function_definition v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_arrow_function_definition : Operations_types.begin_arrow_function_definition -> Pbrt.Encoder.t -> unit -(** [encode_begin_arrow_function_definition v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_generator_function_definition : Operations_types.begin_generator_function_definition -> Pbrt.Encoder.t -> unit -(** [encode_begin_generator_function_definition v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_async_function_definition : Operations_types.begin_async_function_definition -> Pbrt.Encoder.t -> unit -(** [encode_begin_async_function_definition v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_async_arrow_function_definition : Operations_types.begin_async_arrow_function_definition -> Pbrt.Encoder.t -> unit -(** [encode_begin_async_arrow_function_definition v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_async_generator_function_definition : Operations_types.begin_async_generator_function_definition -> Pbrt.Encoder.t -> unit -(** [encode_begin_async_generator_function_definition v encoder] encodes [v] with the given [encoder] *) - -val encode_call_method : Operations_types.call_method -> Pbrt.Encoder.t -> unit -(** [encode_call_method v encoder] encodes [v] with the given [encoder] *) - -val encode_call_function_with_spread : Operations_types.call_function_with_spread -> Pbrt.Encoder.t -> unit -(** [encode_call_function_with_spread v encoder] encodes [v] with the given [encoder] *) - -val encode_unary_operator : Operations_types.unary_operator -> Pbrt.Encoder.t -> unit -(** [encode_unary_operator v encoder] encodes [v] with the given [encoder] *) - -val encode_unary_operation : Operations_types.unary_operation -> Pbrt.Encoder.t -> unit -(** [encode_unary_operation v encoder] encodes [v] with the given [encoder] *) - -val encode_binary_operator : Operations_types.binary_operator -> Pbrt.Encoder.t -> unit -(** [encode_binary_operator v encoder] encodes [v] with the given [encoder] *) - -val encode_binary_operation : Operations_types.binary_operation -> Pbrt.Encoder.t -> unit -(** [encode_binary_operation v encoder] encodes [v] with the given [encoder] *) - -val encode_comparator : Operations_types.comparator -> Pbrt.Encoder.t -> unit -(** [encode_comparator v encoder] encodes [v] with the given [encoder] *) - -val encode_compare : Operations_types.compare -> Pbrt.Encoder.t -> unit -(** [encode_compare v encoder] encodes [v] with the given [encoder] *) - -val encode_eval : Operations_types.eval -> Pbrt.Encoder.t -> unit -(** [encode_eval v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_class_definition : Operations_types.begin_class_definition -> Pbrt.Encoder.t -> unit -(** [encode_begin_class_definition v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_method_definition : Operations_types.begin_method_definition -> Pbrt.Encoder.t -> unit -(** [encode_begin_method_definition v encoder] encodes [v] with the given [encoder] *) - -val encode_call_super_method : Operations_types.call_super_method -> Pbrt.Encoder.t -> unit -(** [encode_call_super_method v encoder] encodes [v] with the given [encoder] *) - -val encode_load_super_property : Operations_types.load_super_property -> Pbrt.Encoder.t -> unit -(** [encode_load_super_property v encoder] encodes [v] with the given [encoder] *) - -val encode_store_super_property : Operations_types.store_super_property -> Pbrt.Encoder.t -> unit -(** [encode_store_super_property v encoder] encodes [v] with the given [encoder] *) - -val encode_load_from_scope : Operations_types.load_from_scope -> Pbrt.Encoder.t -> unit -(** [encode_load_from_scope v encoder] encodes [v] with the given [encoder] *) - -val encode_store_to_scope : Operations_types.store_to_scope -> Pbrt.Encoder.t -> unit -(** [encode_store_to_scope v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_while : Operations_types.begin_while -> Pbrt.Encoder.t -> unit -(** [encode_begin_while v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_do_while : Operations_types.begin_do_while -> Pbrt.Encoder.t -> unit -(** [encode_begin_do_while v encoder] encodes [v] with the given [encoder] *) - -val encode_begin_for : Operations_types.begin_for -> Pbrt.Encoder.t -> unit -(** [encode_begin_for v encoder] encodes [v] with the given [encoder] *) - - -(** {2 Protobuf Decoding} *) - -val decode_load_integer : Pbrt.Decoder.t -> Operations_types.load_integer -(** [decode_load_integer decoder] decodes a [load_integer] value from [decoder] *) - -val decode_load_big_int : Pbrt.Decoder.t -> Operations_types.load_big_int -(** [decode_load_big_int decoder] decodes a [load_big_int] value from [decoder] *) - -val decode_load_float : Pbrt.Decoder.t -> Operations_types.load_float -(** [decode_load_float decoder] decodes a [load_float] value from [decoder] *) - -val decode_load_string : Pbrt.Decoder.t -> Operations_types.load_string -(** [decode_load_string decoder] decodes a [load_string] value from [decoder] *) - -val decode_load_boolean : Pbrt.Decoder.t -> Operations_types.load_boolean -(** [decode_load_boolean decoder] decodes a [load_boolean] value from [decoder] *) - -val decode_load_reg_exp : Pbrt.Decoder.t -> Operations_types.load_reg_exp -(** [decode_load_reg_exp decoder] decodes a [load_reg_exp] value from [decoder] *) - -val decode_create_object : Pbrt.Decoder.t -> Operations_types.create_object -(** [decode_create_object decoder] decodes a [create_object] value from [decoder] *) - -val decode_create_object_with_spread : Pbrt.Decoder.t -> Operations_types.create_object_with_spread -(** [decode_create_object_with_spread decoder] decodes a [create_object_with_spread] value from [decoder] *) - -val decode_create_array_with_spread : Pbrt.Decoder.t -> Operations_types.create_array_with_spread -(** [decode_create_array_with_spread decoder] decodes a [create_array_with_spread] value from [decoder] *) - -val decode_load_builtin : Pbrt.Decoder.t -> Operations_types.load_builtin -(** [decode_load_builtin decoder] decodes a [load_builtin] value from [decoder] *) - -val decode_load_property : Pbrt.Decoder.t -> Operations_types.load_property -(** [decode_load_property decoder] decodes a [load_property] value from [decoder] *) - -val decode_store_property : Pbrt.Decoder.t -> Operations_types.store_property -(** [decode_store_property decoder] decodes a [store_property] value from [decoder] *) - -val decode_delete_property : Pbrt.Decoder.t -> Operations_types.delete_property -(** [decode_delete_property decoder] decodes a [delete_property] value from [decoder] *) - -val decode_load_element : Pbrt.Decoder.t -> Operations_types.load_element -(** [decode_load_element decoder] decodes a [load_element] value from [decoder] *) - -val decode_store_element : Pbrt.Decoder.t -> Operations_types.store_element -(** [decode_store_element decoder] decodes a [store_element] value from [decoder] *) - -val decode_delete_element : Pbrt.Decoder.t -> Operations_types.delete_element -(** [decode_delete_element decoder] decodes a [delete_element] value from [decoder] *) - -val decode_begin_plain_function_definition : Pbrt.Decoder.t -> Operations_types.begin_plain_function_definition -(** [decode_begin_plain_function_definition decoder] decodes a [begin_plain_function_definition] value from [decoder] *) - -val decode_begin_strict_function_definition : Pbrt.Decoder.t -> Operations_types.begin_strict_function_definition -(** [decode_begin_strict_function_definition decoder] decodes a [begin_strict_function_definition] value from [decoder] *) - -val decode_begin_arrow_function_definition : Pbrt.Decoder.t -> Operations_types.begin_arrow_function_definition -(** [decode_begin_arrow_function_definition decoder] decodes a [begin_arrow_function_definition] value from [decoder] *) - -val decode_begin_generator_function_definition : Pbrt.Decoder.t -> Operations_types.begin_generator_function_definition -(** [decode_begin_generator_function_definition decoder] decodes a [begin_generator_function_definition] value from [decoder] *) - -val decode_begin_async_function_definition : Pbrt.Decoder.t -> Operations_types.begin_async_function_definition -(** [decode_begin_async_function_definition decoder] decodes a [begin_async_function_definition] value from [decoder] *) - -val decode_begin_async_arrow_function_definition : Pbrt.Decoder.t -> Operations_types.begin_async_arrow_function_definition -(** [decode_begin_async_arrow_function_definition decoder] decodes a [begin_async_arrow_function_definition] value from [decoder] *) - -val decode_begin_async_generator_function_definition : Pbrt.Decoder.t -> Operations_types.begin_async_generator_function_definition -(** [decode_begin_async_generator_function_definition decoder] decodes a [begin_async_generator_function_definition] value from [decoder] *) - -val decode_call_method : Pbrt.Decoder.t -> Operations_types.call_method -(** [decode_call_method decoder] decodes a [call_method] value from [decoder] *) - -val decode_call_function_with_spread : Pbrt.Decoder.t -> Operations_types.call_function_with_spread -(** [decode_call_function_with_spread decoder] decodes a [call_function_with_spread] value from [decoder] *) - -val decode_unary_operator : Pbrt.Decoder.t -> Operations_types.unary_operator -(** [decode_unary_operator decoder] decodes a [unary_operator] value from [decoder] *) - -val decode_unary_operation : Pbrt.Decoder.t -> Operations_types.unary_operation -(** [decode_unary_operation decoder] decodes a [unary_operation] value from [decoder] *) - -val decode_binary_operator : Pbrt.Decoder.t -> Operations_types.binary_operator -(** [decode_binary_operator decoder] decodes a [binary_operator] value from [decoder] *) - -val decode_binary_operation : Pbrt.Decoder.t -> Operations_types.binary_operation -(** [decode_binary_operation decoder] decodes a [binary_operation] value from [decoder] *) - -val decode_comparator : Pbrt.Decoder.t -> Operations_types.comparator -(** [decode_comparator decoder] decodes a [comparator] value from [decoder] *) - -val decode_compare : Pbrt.Decoder.t -> Operations_types.compare -(** [decode_compare decoder] decodes a [compare] value from [decoder] *) - -val decode_eval : Pbrt.Decoder.t -> Operations_types.eval -(** [decode_eval decoder] decodes a [eval] value from [decoder] *) - -val decode_begin_class_definition : Pbrt.Decoder.t -> Operations_types.begin_class_definition -(** [decode_begin_class_definition decoder] decodes a [begin_class_definition] value from [decoder] *) - -val decode_begin_method_definition : Pbrt.Decoder.t -> Operations_types.begin_method_definition -(** [decode_begin_method_definition decoder] decodes a [begin_method_definition] value from [decoder] *) - -val decode_call_super_method : Pbrt.Decoder.t -> Operations_types.call_super_method -(** [decode_call_super_method decoder] decodes a [call_super_method] value from [decoder] *) - -val decode_load_super_property : Pbrt.Decoder.t -> Operations_types.load_super_property -(** [decode_load_super_property decoder] decodes a [load_super_property] value from [decoder] *) - -val decode_store_super_property : Pbrt.Decoder.t -> Operations_types.store_super_property -(** [decode_store_super_property decoder] decodes a [store_super_property] value from [decoder] *) - -val decode_load_from_scope : Pbrt.Decoder.t -> Operations_types.load_from_scope -(** [decode_load_from_scope decoder] decodes a [load_from_scope] value from [decoder] *) - -val decode_store_to_scope : Pbrt.Decoder.t -> Operations_types.store_to_scope -(** [decode_store_to_scope decoder] decodes a [store_to_scope] value from [decoder] *) - -val decode_begin_while : Pbrt.Decoder.t -> Operations_types.begin_while -(** [decode_begin_while decoder] decodes a [begin_while] value from [decoder] *) - -val decode_begin_do_while : Pbrt.Decoder.t -> Operations_types.begin_do_while -(** [decode_begin_do_while decoder] decodes a [begin_do_while] value from [decoder] *) - -val decode_begin_for : Pbrt.Decoder.t -> Operations_types.begin_for -(** [decode_begin_for decoder] decodes a [begin_for] value from [decoder] *) diff --git a/Compiler/src/proto/operations_pp.ml b/Compiler/src/proto/operations_pp.ml deleted file mode 100644 index 326adf20..00000000 --- a/Compiler/src/proto/operations_pp.ml +++ /dev/null @@ -1,358 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - -let rec pp_load_integer fmt (v:Operations_types.load_integer) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "value" Pbrt.Pp.pp_int64 fmt v.Operations_types.value; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_big_int fmt (v:Operations_types.load_big_int) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "value" Pbrt.Pp.pp_int64 fmt v.Operations_types.value; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_float fmt (v:Operations_types.load_float) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "value" Pbrt.Pp.pp_float fmt v.Operations_types.value; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_string fmt (v:Operations_types.load_string) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "value" Pbrt.Pp.pp_string fmt v.Operations_types.value; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_boolean fmt (v:Operations_types.load_boolean) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "value" Pbrt.Pp.pp_bool fmt v.Operations_types.value; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_reg_exp fmt (v:Operations_types.load_reg_exp) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "value" Pbrt.Pp.pp_string fmt v.Operations_types.value; - Pbrt.Pp.pp_record_field "flags" Pbrt.Pp.pp_int32 fmt v.Operations_types.flags; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_create_object fmt (v:Operations_types.create_object) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "property_names" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.Operations_types.property_names; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_create_object_with_spread fmt (v:Operations_types.create_object_with_spread) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "property_names" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.Operations_types.property_names; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_create_array_with_spread fmt (v:Operations_types.create_array_with_spread) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "spreads" (Pbrt.Pp.pp_list Pbrt.Pp.pp_bool) fmt v.Operations_types.spreads; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_builtin fmt (v:Operations_types.load_builtin) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "builtin_name" Pbrt.Pp.pp_string fmt v.Operations_types.builtin_name; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_property fmt (v:Operations_types.load_property) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "property_name" Pbrt.Pp.pp_string fmt v.Operations_types.property_name; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_store_property fmt (v:Operations_types.store_property) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "property_name" Pbrt.Pp.pp_string fmt v.Operations_types.property_name; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_delete_property fmt (v:Operations_types.delete_property) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "property_name" Pbrt.Pp.pp_string fmt v.Operations_types.property_name; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_element fmt (v:Operations_types.load_element) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "index" Pbrt.Pp.pp_int64 fmt v.Operations_types.index; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_store_element fmt (v:Operations_types.store_element) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "index" Pbrt.Pp.pp_int64 fmt v.Operations_types.index; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_delete_element fmt (v:Operations_types.delete_element) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "index" Pbrt.Pp.pp_int64 fmt v.Operations_types.index; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_plain_function_definition fmt (v:Operations_types.begin_plain_function_definition) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "signature" (Pbrt.Pp.pp_option Typesystem_pp.pp_function_signature) fmt v.Operations_types.signature; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_strict_function_definition fmt (v:Operations_types.begin_strict_function_definition) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "signature" (Pbrt.Pp.pp_option Typesystem_pp.pp_function_signature) fmt v.Operations_types.signature; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_arrow_function_definition fmt (v:Operations_types.begin_arrow_function_definition) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "signature" (Pbrt.Pp.pp_option Typesystem_pp.pp_function_signature) fmt v.Operations_types.signature; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_generator_function_definition fmt (v:Operations_types.begin_generator_function_definition) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "signature" (Pbrt.Pp.pp_option Typesystem_pp.pp_function_signature) fmt v.Operations_types.signature; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_async_function_definition fmt (v:Operations_types.begin_async_function_definition) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "signature" (Pbrt.Pp.pp_option Typesystem_pp.pp_function_signature) fmt v.Operations_types.signature; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_async_arrow_function_definition fmt (v:Operations_types.begin_async_arrow_function_definition) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "signature" (Pbrt.Pp.pp_option Typesystem_pp.pp_function_signature) fmt v.Operations_types.signature; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_async_generator_function_definition fmt (v:Operations_types.begin_async_generator_function_definition) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "signature" (Pbrt.Pp.pp_option Typesystem_pp.pp_function_signature) fmt v.Operations_types.signature; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_call_method fmt (v:Operations_types.call_method) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "method_name" Pbrt.Pp.pp_string fmt v.Operations_types.method_name; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_call_function_with_spread fmt (v:Operations_types.call_function_with_spread) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "spreads" (Pbrt.Pp.pp_list Pbrt.Pp.pp_bool) fmt v.Operations_types.spreads; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_unary_operator fmt (v:Operations_types.unary_operator) = - match v with - | Operations_types.Pre_inc -> Format.fprintf fmt "Pre_inc" - | Operations_types.Pre_dec -> Format.fprintf fmt "Pre_dec" - | Operations_types.Post_inc -> Format.fprintf fmt "Post_inc" - | Operations_types.Post_dec -> Format.fprintf fmt "Post_dec" - | Operations_types.Logical_not -> Format.fprintf fmt "Logical_not" - | Operations_types.Bitwise_not -> Format.fprintf fmt "Bitwise_not" - | Operations_types.Plus -> Format.fprintf fmt "Plus" - | Operations_types.Minus -> Format.fprintf fmt "Minus" - -let rec pp_unary_operation fmt (v:Operations_types.unary_operation) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "op" pp_unary_operator fmt v.Operations_types.op; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_binary_operator fmt (v:Operations_types.binary_operator) = - match v with - | Operations_types.Add -> Format.fprintf fmt "Add" - | Operations_types.Sub -> Format.fprintf fmt "Sub" - | Operations_types.Mul -> Format.fprintf fmt "Mul" - | Operations_types.Div -> Format.fprintf fmt "Div" - | Operations_types.Mod -> Format.fprintf fmt "Mod" - | Operations_types.Bit_and -> Format.fprintf fmt "Bit_and" - | Operations_types.Bit_or -> Format.fprintf fmt "Bit_or" - | Operations_types.Logical_and -> Format.fprintf fmt "Logical_and" - | Operations_types.Logical_or -> Format.fprintf fmt "Logical_or" - | Operations_types.Xor -> Format.fprintf fmt "Xor" - | Operations_types.Lshift -> Format.fprintf fmt "Lshift" - | Operations_types.Rshift -> Format.fprintf fmt "Rshift" - | Operations_types.Exp -> Format.fprintf fmt "Exp" - | Operations_types.Unrshift -> Format.fprintf fmt "Unrshift" - -let rec pp_binary_operation fmt (v:Operations_types.binary_operation) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "op" pp_binary_operator fmt v.Operations_types.op; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_comparator fmt (v:Operations_types.comparator) = - match v with - | Operations_types.Equal -> Format.fprintf fmt "Equal" - | Operations_types.Strict_equal -> Format.fprintf fmt "Strict_equal" - | Operations_types.Not_equal -> Format.fprintf fmt "Not_equal" - | Operations_types.Strict_not_equal -> Format.fprintf fmt "Strict_not_equal" - | Operations_types.Less_than -> Format.fprintf fmt "Less_than" - | Operations_types.Less_than_or_equal -> Format.fprintf fmt "Less_than_or_equal" - | Operations_types.Greater_than -> Format.fprintf fmt "Greater_than" - | Operations_types.Greater_than_or_equal -> Format.fprintf fmt "Greater_than_or_equal" - -let rec pp_compare fmt (v:Operations_types.compare) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "op" pp_comparator fmt v.Operations_types.op; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_eval fmt (v:Operations_types.eval) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "code" Pbrt.Pp.pp_string fmt v.Operations_types.code; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_class_definition fmt (v:Operations_types.begin_class_definition) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "has_superclass" Pbrt.Pp.pp_bool fmt v.Operations_types.has_superclass; - Pbrt.Pp.pp_record_field "constructor_parameters" (Pbrt.Pp.pp_list Typesystem_pp.pp_type_) fmt v.Operations_types.constructor_parameters; - Pbrt.Pp.pp_record_field "instance_properties" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.Operations_types.instance_properties; - Pbrt.Pp.pp_record_field "instance_method_names" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.Operations_types.instance_method_names; - Pbrt.Pp.pp_record_field "instance_method_signatures" (Pbrt.Pp.pp_list Typesystem_pp.pp_function_signature) fmt v.Operations_types.instance_method_signatures; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_method_definition fmt (v:Operations_types.begin_method_definition) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "num_parameters" Pbrt.Pp.pp_int32 fmt v.Operations_types.num_parameters; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_call_super_method fmt (v:Operations_types.call_super_method) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "method_name" Pbrt.Pp.pp_string fmt v.Operations_types.method_name; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_super_property fmt (v:Operations_types.load_super_property) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "property_name" Pbrt.Pp.pp_string fmt v.Operations_types.property_name; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_store_super_property fmt (v:Operations_types.store_super_property) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "property_name" Pbrt.Pp.pp_string fmt v.Operations_types.property_name; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_load_from_scope fmt (v:Operations_types.load_from_scope) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "id" Pbrt.Pp.pp_string fmt v.Operations_types.id; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_store_to_scope fmt (v:Operations_types.store_to_scope) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "id" Pbrt.Pp.pp_string fmt v.Operations_types.id; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_while fmt (v:Operations_types.begin_while) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "comparator" pp_comparator fmt v.Operations_types.comparator; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_do_while fmt (v:Operations_types.begin_do_while) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "comparator" pp_comparator fmt v.Operations_types.comparator; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_begin_for fmt (v:Operations_types.begin_for) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "comparator" pp_comparator fmt v.Operations_types.comparator; - Pbrt.Pp.pp_record_field "op" pp_binary_operator fmt v.Operations_types.op; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () diff --git a/Compiler/src/proto/operations_pp.mli b/Compiler/src/proto/operations_pp.mli deleted file mode 100644 index 2564ac6a..00000000 --- a/Compiler/src/proto/operations_pp.mli +++ /dev/null @@ -1,130 +0,0 @@ -(** operations.proto Pretty Printing *) - - -(** {2 Formatters} *) - -val pp_load_integer : Format.formatter -> Operations_types.load_integer -> unit -(** [pp_load_integer v] formats v *) - -val pp_load_big_int : Format.formatter -> Operations_types.load_big_int -> unit -(** [pp_load_big_int v] formats v *) - -val pp_load_float : Format.formatter -> Operations_types.load_float -> unit -(** [pp_load_float v] formats v *) - -val pp_load_string : Format.formatter -> Operations_types.load_string -> unit -(** [pp_load_string v] formats v *) - -val pp_load_boolean : Format.formatter -> Operations_types.load_boolean -> unit -(** [pp_load_boolean v] formats v *) - -val pp_load_reg_exp : Format.formatter -> Operations_types.load_reg_exp -> unit -(** [pp_load_reg_exp v] formats v *) - -val pp_create_object : Format.formatter -> Operations_types.create_object -> unit -(** [pp_create_object v] formats v *) - -val pp_create_object_with_spread : Format.formatter -> Operations_types.create_object_with_spread -> unit -(** [pp_create_object_with_spread v] formats v *) - -val pp_create_array_with_spread : Format.formatter -> Operations_types.create_array_with_spread -> unit -(** [pp_create_array_with_spread v] formats v *) - -val pp_load_builtin : Format.formatter -> Operations_types.load_builtin -> unit -(** [pp_load_builtin v] formats v *) - -val pp_load_property : Format.formatter -> Operations_types.load_property -> unit -(** [pp_load_property v] formats v *) - -val pp_store_property : Format.formatter -> Operations_types.store_property -> unit -(** [pp_store_property v] formats v *) - -val pp_delete_property : Format.formatter -> Operations_types.delete_property -> unit -(** [pp_delete_property v] formats v *) - -val pp_load_element : Format.formatter -> Operations_types.load_element -> unit -(** [pp_load_element v] formats v *) - -val pp_store_element : Format.formatter -> Operations_types.store_element -> unit -(** [pp_store_element v] formats v *) - -val pp_delete_element : Format.formatter -> Operations_types.delete_element -> unit -(** [pp_delete_element v] formats v *) - -val pp_begin_plain_function_definition : Format.formatter -> Operations_types.begin_plain_function_definition -> unit -(** [pp_begin_plain_function_definition v] formats v *) - -val pp_begin_strict_function_definition : Format.formatter -> Operations_types.begin_strict_function_definition -> unit -(** [pp_begin_strict_function_definition v] formats v *) - -val pp_begin_arrow_function_definition : Format.formatter -> Operations_types.begin_arrow_function_definition -> unit -(** [pp_begin_arrow_function_definition v] formats v *) - -val pp_begin_generator_function_definition : Format.formatter -> Operations_types.begin_generator_function_definition -> unit -(** [pp_begin_generator_function_definition v] formats v *) - -val pp_begin_async_function_definition : Format.formatter -> Operations_types.begin_async_function_definition -> unit -(** [pp_begin_async_function_definition v] formats v *) - -val pp_begin_async_arrow_function_definition : Format.formatter -> Operations_types.begin_async_arrow_function_definition -> unit -(** [pp_begin_async_arrow_function_definition v] formats v *) - -val pp_begin_async_generator_function_definition : Format.formatter -> Operations_types.begin_async_generator_function_definition -> unit -(** [pp_begin_async_generator_function_definition v] formats v *) - -val pp_call_method : Format.formatter -> Operations_types.call_method -> unit -(** [pp_call_method v] formats v *) - -val pp_call_function_with_spread : Format.formatter -> Operations_types.call_function_with_spread -> unit -(** [pp_call_function_with_spread v] formats v *) - -val pp_unary_operator : Format.formatter -> Operations_types.unary_operator -> unit -(** [pp_unary_operator v] formats v *) - -val pp_unary_operation : Format.formatter -> Operations_types.unary_operation -> unit -(** [pp_unary_operation v] formats v *) - -val pp_binary_operator : Format.formatter -> Operations_types.binary_operator -> unit -(** [pp_binary_operator v] formats v *) - -val pp_binary_operation : Format.formatter -> Operations_types.binary_operation -> unit -(** [pp_binary_operation v] formats v *) - -val pp_comparator : Format.formatter -> Operations_types.comparator -> unit -(** [pp_comparator v] formats v *) - -val pp_compare : Format.formatter -> Operations_types.compare -> unit -(** [pp_compare v] formats v *) - -val pp_eval : Format.formatter -> Operations_types.eval -> unit -(** [pp_eval v] formats v *) - -val pp_begin_class_definition : Format.formatter -> Operations_types.begin_class_definition -> unit -(** [pp_begin_class_definition v] formats v *) - -val pp_begin_method_definition : Format.formatter -> Operations_types.begin_method_definition -> unit -(** [pp_begin_method_definition v] formats v *) - -val pp_call_super_method : Format.formatter -> Operations_types.call_super_method -> unit -(** [pp_call_super_method v] formats v *) - -val pp_load_super_property : Format.formatter -> Operations_types.load_super_property -> unit -(** [pp_load_super_property v] formats v *) - -val pp_store_super_property : Format.formatter -> Operations_types.store_super_property -> unit -(** [pp_store_super_property v] formats v *) - -val pp_load_from_scope : Format.formatter -> Operations_types.load_from_scope -> unit -(** [pp_load_from_scope v] formats v *) - -val pp_store_to_scope : Format.formatter -> Operations_types.store_to_scope -> unit -(** [pp_store_to_scope v] formats v *) - -val pp_begin_while : Format.formatter -> Operations_types.begin_while -> unit -(** [pp_begin_while v] formats v *) - -val pp_begin_do_while : Format.formatter -> Operations_types.begin_do_while -> unit -(** [pp_begin_do_while v] formats v *) - -val pp_begin_for : Format.formatter -> Operations_types.begin_for -> unit -(** [pp_begin_for v] formats v *) diff --git a/Compiler/src/proto/operations_types.ml b/Compiler/src/proto/operations_types.ml deleted file mode 100644 index 8c2ad0f8..00000000 --- a/Compiler/src/proto/operations_types.ml +++ /dev/null @@ -1,452 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - - -type load_integer = { - value : int64; -} - -type load_big_int = { - value : int64; -} - -type load_float = { - value : float; -} - -type load_string = { - value : string; -} - -type load_boolean = { - value : bool; -} - -type load_reg_exp = { - value : string; - flags : int32; -} - -type create_object = { - property_names : string list; -} - -type create_object_with_spread = { - property_names : string list; -} - -type create_array_with_spread = { - spreads : bool list; -} - -type load_builtin = { - builtin_name : string; -} - -type load_property = { - property_name : string; -} - -type store_property = { - property_name : string; -} - -type delete_property = { - property_name : string; -} - -type load_element = { - index : int64; -} - -type store_element = { - index : int64; -} - -type delete_element = { - index : int64; -} - -type begin_plain_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_strict_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_arrow_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_generator_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_async_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_async_arrow_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_async_generator_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type call_method = { - method_name : string; -} - -type call_function_with_spread = { - spreads : bool list; -} - -type unary_operator = - | Pre_inc - | Pre_dec - | Post_inc - | Post_dec - | Logical_not - | Bitwise_not - | Plus - | Minus - -type unary_operation = { - op : unary_operator; -} - -type binary_operator = - | Add - | Sub - | Mul - | Div - | Mod - | Bit_and - | Bit_or - | Logical_and - | Logical_or - | Xor - | Lshift - | Rshift - | Exp - | Unrshift - -type binary_operation = { - op : binary_operator; -} - -type comparator = - | Equal - | Strict_equal - | Not_equal - | Strict_not_equal - | Less_than - | Less_than_or_equal - | Greater_than - | Greater_than_or_equal - -type compare = { - op : comparator; -} - -type eval = { - code : string; -} - -type begin_class_definition = { - has_superclass : bool; - constructor_parameters : Typesystem_types.type_ list; - instance_properties : string list; - instance_method_names : string list; - instance_method_signatures : Typesystem_types.function_signature list; -} - -type begin_method_definition = { - num_parameters : int32; -} - -type call_super_method = { - method_name : string; -} - -type load_super_property = { - property_name : string; -} - -type store_super_property = { - property_name : string; -} - -type load_from_scope = { - id : string; -} - -type store_to_scope = { - id : string; -} - -type begin_while = { - comparator : comparator; -} - -type begin_do_while = { - comparator : comparator; -} - -type begin_for = { - comparator : comparator; - op : binary_operator; -} - -let rec default_load_integer - ?value:((value:int64) = 0L) - () : load_integer = { - value; -} - -let rec default_load_big_int - ?value:((value:int64) = 0L) - () : load_big_int = { - value; -} - -let rec default_load_float - ?value:((value:float) = 0.) - () : load_float = { - value; -} - -let rec default_load_string - ?value:((value:string) = "") - () : load_string = { - value; -} - -let rec default_load_boolean - ?value:((value:bool) = false) - () : load_boolean = { - value; -} - -let rec default_load_reg_exp - ?value:((value:string) = "") - ?flags:((flags:int32) = 0l) - () : load_reg_exp = { - value; - flags; -} - -let rec default_create_object - ?property_names:((property_names:string list) = []) - () : create_object = { - property_names; -} - -let rec default_create_object_with_spread - ?property_names:((property_names:string list) = []) - () : create_object_with_spread = { - property_names; -} - -let rec default_create_array_with_spread - ?spreads:((spreads:bool list) = []) - () : create_array_with_spread = { - spreads; -} - -let rec default_load_builtin - ?builtin_name:((builtin_name:string) = "") - () : load_builtin = { - builtin_name; -} - -let rec default_load_property - ?property_name:((property_name:string) = "") - () : load_property = { - property_name; -} - -let rec default_store_property - ?property_name:((property_name:string) = "") - () : store_property = { - property_name; -} - -let rec default_delete_property - ?property_name:((property_name:string) = "") - () : delete_property = { - property_name; -} - -let rec default_load_element - ?index:((index:int64) = 0L) - () : load_element = { - index; -} - -let rec default_store_element - ?index:((index:int64) = 0L) - () : store_element = { - index; -} - -let rec default_delete_element - ?index:((index:int64) = 0L) - () : delete_element = { - index; -} - -let rec default_begin_plain_function_definition - ?signature:((signature:Typesystem_types.function_signature option) = None) - () : begin_plain_function_definition = { - signature; -} - -let rec default_begin_strict_function_definition - ?signature:((signature:Typesystem_types.function_signature option) = None) - () : begin_strict_function_definition = { - signature; -} - -let rec default_begin_arrow_function_definition - ?signature:((signature:Typesystem_types.function_signature option) = None) - () : begin_arrow_function_definition = { - signature; -} - -let rec default_begin_generator_function_definition - ?signature:((signature:Typesystem_types.function_signature option) = None) - () : begin_generator_function_definition = { - signature; -} - -let rec default_begin_async_function_definition - ?signature:((signature:Typesystem_types.function_signature option) = None) - () : begin_async_function_definition = { - signature; -} - -let rec default_begin_async_arrow_function_definition - ?signature:((signature:Typesystem_types.function_signature option) = None) - () : begin_async_arrow_function_definition = { - signature; -} - -let rec default_begin_async_generator_function_definition - ?signature:((signature:Typesystem_types.function_signature option) = None) - () : begin_async_generator_function_definition = { - signature; -} - -let rec default_call_method - ?method_name:((method_name:string) = "") - () : call_method = { - method_name; -} - -let rec default_call_function_with_spread - ?spreads:((spreads:bool list) = []) - () : call_function_with_spread = { - spreads; -} - -let rec default_unary_operator () = (Pre_inc:unary_operator) - -let rec default_unary_operation - ?op:((op:unary_operator) = default_unary_operator ()) - () : unary_operation = { - op; -} - -let rec default_binary_operator () = (Add:binary_operator) - -let rec default_binary_operation - ?op:((op:binary_operator) = default_binary_operator ()) - () : binary_operation = { - op; -} - -let rec default_comparator () = (Equal:comparator) - -let rec default_compare - ?op:((op:comparator) = default_comparator ()) - () : compare = { - op; -} - -let rec default_eval - ?code:((code:string) = "") - () : eval = { - code; -} - -let rec default_begin_class_definition - ?has_superclass:((has_superclass:bool) = false) - ?constructor_parameters:((constructor_parameters:Typesystem_types.type_ list) = []) - ?instance_properties:((instance_properties:string list) = []) - ?instance_method_names:((instance_method_names:string list) = []) - ?instance_method_signatures:((instance_method_signatures:Typesystem_types.function_signature list) = []) - () : begin_class_definition = { - has_superclass; - constructor_parameters; - instance_properties; - instance_method_names; - instance_method_signatures; -} - -let rec default_begin_method_definition - ?num_parameters:((num_parameters:int32) = 0l) - () : begin_method_definition = { - num_parameters; -} - -let rec default_call_super_method - ?method_name:((method_name:string) = "") - () : call_super_method = { - method_name; -} - -let rec default_load_super_property - ?property_name:((property_name:string) = "") - () : load_super_property = { - property_name; -} - -let rec default_store_super_property - ?property_name:((property_name:string) = "") - () : store_super_property = { - property_name; -} - -let rec default_load_from_scope - ?id:((id:string) = "") - () : load_from_scope = { - id; -} - -let rec default_store_to_scope - ?id:((id:string) = "") - () : store_to_scope = { - id; -} - -let rec default_begin_while - ?comparator:((comparator:comparator) = default_comparator ()) - () : begin_while = { - comparator; -} - -let rec default_begin_do_while - ?comparator:((comparator:comparator) = default_comparator ()) - () : begin_do_while = { - comparator; -} - -let rec default_begin_for - ?comparator:((comparator:comparator) = default_comparator ()) - ?op:((op:binary_operator) = default_binary_operator ()) - () : begin_for = { - comparator; - op; -} diff --git a/Compiler/src/proto/operations_types.mli b/Compiler/src/proto/operations_types.mli deleted file mode 100644 index a98f2501..00000000 --- a/Compiler/src/proto/operations_types.mli +++ /dev/null @@ -1,455 +0,0 @@ -(** operations.proto Types *) - - - -(** {2 Types} *) - -type load_integer = { - value : int64; -} - -type load_big_int = { - value : int64; -} - -type load_float = { - value : float; -} - -type load_string = { - value : string; -} - -type load_boolean = { - value : bool; -} - -type load_reg_exp = { - value : string; - flags : int32; -} - -type create_object = { - property_names : string list; -} - -type create_object_with_spread = { - property_names : string list; -} - -type create_array_with_spread = { - spreads : bool list; -} - -type load_builtin = { - builtin_name : string; -} - -type load_property = { - property_name : string; -} - -type store_property = { - property_name : string; -} - -type delete_property = { - property_name : string; -} - -type load_element = { - index : int64; -} - -type store_element = { - index : int64; -} - -type delete_element = { - index : int64; -} - -type begin_plain_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_strict_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_arrow_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_generator_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_async_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_async_arrow_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type begin_async_generator_function_definition = { - signature : Typesystem_types.function_signature option; -} - -type call_method = { - method_name : string; -} - -type call_function_with_spread = { - spreads : bool list; -} - -type unary_operator = - | Pre_inc - | Pre_dec - | Post_inc - | Post_dec - | Logical_not - | Bitwise_not - | Plus - | Minus - -type unary_operation = { - op : unary_operator; -} - -type binary_operator = - | Add - | Sub - | Mul - | Div - | Mod - | Bit_and - | Bit_or - | Logical_and - | Logical_or - | Xor - | Lshift - | Rshift - | Exp - | Unrshift - -type binary_operation = { - op : binary_operator; -} - -type comparator = - | Equal - | Strict_equal - | Not_equal - | Strict_not_equal - | Less_than - | Less_than_or_equal - | Greater_than - | Greater_than_or_equal - -type compare = { - op : comparator; -} - -type eval = { - code : string; -} - -type begin_class_definition = { - has_superclass : bool; - constructor_parameters : Typesystem_types.type_ list; - instance_properties : string list; - instance_method_names : string list; - instance_method_signatures : Typesystem_types.function_signature list; -} - -type begin_method_definition = { - num_parameters : int32; -} - -type call_super_method = { - method_name : string; -} - -type load_super_property = { - property_name : string; -} - -type store_super_property = { - property_name : string; -} - -type load_from_scope = { - id : string; -} - -type store_to_scope = { - id : string; -} - -type begin_while = { - comparator : comparator; -} - -type begin_do_while = { - comparator : comparator; -} - -type begin_for = { - comparator : comparator; - op : binary_operator; -} - - -(** {2 Default values} *) - -val default_load_integer : - ?value:int64 -> - unit -> - load_integer -(** [default_load_integer ()] is the default value for type [load_integer] *) - -val default_load_big_int : - ?value:int64 -> - unit -> - load_big_int -(** [default_load_big_int ()] is the default value for type [load_big_int] *) - -val default_load_float : - ?value:float -> - unit -> - load_float -(** [default_load_float ()] is the default value for type [load_float] *) - -val default_load_string : - ?value:string -> - unit -> - load_string -(** [default_load_string ()] is the default value for type [load_string] *) - -val default_load_boolean : - ?value:bool -> - unit -> - load_boolean -(** [default_load_boolean ()] is the default value for type [load_boolean] *) - -val default_load_reg_exp : - ?value:string -> - ?flags:int32 -> - unit -> - load_reg_exp -(** [default_load_reg_exp ()] is the default value for type [load_reg_exp] *) - -val default_create_object : - ?property_names:string list -> - unit -> - create_object -(** [default_create_object ()] is the default value for type [create_object] *) - -val default_create_object_with_spread : - ?property_names:string list -> - unit -> - create_object_with_spread -(** [default_create_object_with_spread ()] is the default value for type [create_object_with_spread] *) - -val default_create_array_with_spread : - ?spreads:bool list -> - unit -> - create_array_with_spread -(** [default_create_array_with_spread ()] is the default value for type [create_array_with_spread] *) - -val default_load_builtin : - ?builtin_name:string -> - unit -> - load_builtin -(** [default_load_builtin ()] is the default value for type [load_builtin] *) - -val default_load_property : - ?property_name:string -> - unit -> - load_property -(** [default_load_property ()] is the default value for type [load_property] *) - -val default_store_property : - ?property_name:string -> - unit -> - store_property -(** [default_store_property ()] is the default value for type [store_property] *) - -val default_delete_property : - ?property_name:string -> - unit -> - delete_property -(** [default_delete_property ()] is the default value for type [delete_property] *) - -val default_load_element : - ?index:int64 -> - unit -> - load_element -(** [default_load_element ()] is the default value for type [load_element] *) - -val default_store_element : - ?index:int64 -> - unit -> - store_element -(** [default_store_element ()] is the default value for type [store_element] *) - -val default_delete_element : - ?index:int64 -> - unit -> - delete_element -(** [default_delete_element ()] is the default value for type [delete_element] *) - -val default_begin_plain_function_definition : - ?signature:Typesystem_types.function_signature option -> - unit -> - begin_plain_function_definition -(** [default_begin_plain_function_definition ()] is the default value for type [begin_plain_function_definition] *) - -val default_begin_strict_function_definition : - ?signature:Typesystem_types.function_signature option -> - unit -> - begin_strict_function_definition -(** [default_begin_strict_function_definition ()] is the default value for type [begin_strict_function_definition] *) - -val default_begin_arrow_function_definition : - ?signature:Typesystem_types.function_signature option -> - unit -> - begin_arrow_function_definition -(** [default_begin_arrow_function_definition ()] is the default value for type [begin_arrow_function_definition] *) - -val default_begin_generator_function_definition : - ?signature:Typesystem_types.function_signature option -> - unit -> - begin_generator_function_definition -(** [default_begin_generator_function_definition ()] is the default value for type [begin_generator_function_definition] *) - -val default_begin_async_function_definition : - ?signature:Typesystem_types.function_signature option -> - unit -> - begin_async_function_definition -(** [default_begin_async_function_definition ()] is the default value for type [begin_async_function_definition] *) - -val default_begin_async_arrow_function_definition : - ?signature:Typesystem_types.function_signature option -> - unit -> - begin_async_arrow_function_definition -(** [default_begin_async_arrow_function_definition ()] is the default value for type [begin_async_arrow_function_definition] *) - -val default_begin_async_generator_function_definition : - ?signature:Typesystem_types.function_signature option -> - unit -> - begin_async_generator_function_definition -(** [default_begin_async_generator_function_definition ()] is the default value for type [begin_async_generator_function_definition] *) - -val default_call_method : - ?method_name:string -> - unit -> - call_method -(** [default_call_method ()] is the default value for type [call_method] *) - -val default_call_function_with_spread : - ?spreads:bool list -> - unit -> - call_function_with_spread -(** [default_call_function_with_spread ()] is the default value for type [call_function_with_spread] *) - -val default_unary_operator : unit -> unary_operator -(** [default_unary_operator ()] is the default value for type [unary_operator] *) - -val default_unary_operation : - ?op:unary_operator -> - unit -> - unary_operation -(** [default_unary_operation ()] is the default value for type [unary_operation] *) - -val default_binary_operator : unit -> binary_operator -(** [default_binary_operator ()] is the default value for type [binary_operator] *) - -val default_binary_operation : - ?op:binary_operator -> - unit -> - binary_operation -(** [default_binary_operation ()] is the default value for type [binary_operation] *) - -val default_comparator : unit -> comparator -(** [default_comparator ()] is the default value for type [comparator] *) - -val default_compare : - ?op:comparator -> - unit -> - compare -(** [default_compare ()] is the default value for type [compare] *) - -val default_eval : - ?code:string -> - unit -> - eval -(** [default_eval ()] is the default value for type [eval] *) - -val default_begin_class_definition : - ?has_superclass:bool -> - ?constructor_parameters:Typesystem_types.type_ list -> - ?instance_properties:string list -> - ?instance_method_names:string list -> - ?instance_method_signatures:Typesystem_types.function_signature list -> - unit -> - begin_class_definition -(** [default_begin_class_definition ()] is the default value for type [begin_class_definition] *) - -val default_begin_method_definition : - ?num_parameters:int32 -> - unit -> - begin_method_definition -(** [default_begin_method_definition ()] is the default value for type [begin_method_definition] *) - -val default_call_super_method : - ?method_name:string -> - unit -> - call_super_method -(** [default_call_super_method ()] is the default value for type [call_super_method] *) - -val default_load_super_property : - ?property_name:string -> - unit -> - load_super_property -(** [default_load_super_property ()] is the default value for type [load_super_property] *) - -val default_store_super_property : - ?property_name:string -> - unit -> - store_super_property -(** [default_store_super_property ()] is the default value for type [store_super_property] *) - -val default_load_from_scope : - ?id:string -> - unit -> - load_from_scope -(** [default_load_from_scope ()] is the default value for type [load_from_scope] *) - -val default_store_to_scope : - ?id:string -> - unit -> - store_to_scope -(** [default_store_to_scope ()] is the default value for type [store_to_scope] *) - -val default_begin_while : - ?comparator:comparator -> - unit -> - begin_while -(** [default_begin_while ()] is the default value for type [begin_while] *) - -val default_begin_do_while : - ?comparator:comparator -> - unit -> - begin_do_while -(** [default_begin_do_while ()] is the default value for type [begin_do_while] *) - -val default_begin_for : - ?comparator:comparator -> - ?op:binary_operator -> - unit -> - begin_for -(** [default_begin_for ()] is the default value for type [begin_for] *) diff --git a/Compiler/src/proto/program_pb.ml b/Compiler/src/proto/program_pb.ml deleted file mode 100644 index b2d64614..00000000 --- a/Compiler/src/proto/program_pb.ml +++ /dev/null @@ -1,1519 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - -type instruction_mutable = { - mutable inouts : int32 list; - mutable operation : Program_types.instruction_operation; -} - -let default_instruction_mutable () : instruction_mutable = { - inouts = []; - operation = Program_types.Op_idx (0l); -} - -type type_info_mutable = { - mutable variable : int32; - mutable index : int32; - mutable type_ : Typesystem_types.type_ option; - mutable quality : Program_types.type_quality; -} - -let default_type_info_mutable () : type_info_mutable = { - variable = 0l; - index = 0l; - type_ = None; - quality = Program_types.default_type_quality (); -} - -type program_mutable = { - mutable uuid : bytes; - mutable code : Program_types.instruction list; - mutable types : Program_types.type_info list; - mutable type_collection_status : Program_types.type_collection_status; - mutable comments : (int32 * string) list; - mutable parent : Program_types.program option; -} - -let default_program_mutable () : program_mutable = { - uuid = Bytes.create 0; - code = []; - types = []; - type_collection_status = Program_types.default_type_collection_status (); - comments = []; - parent = None; -} - - -let rec decode_instruction_operation d = - let rec loop () = - let ret:Program_types.instruction_operation = match Pbrt.Decoder.key d with - | None -> Pbrt.Decoder.malformed_variant "instruction_operation" - | Some (2, _) -> (Program_types.Op_idx (Pbrt.Decoder.int32_as_varint d) : Program_types.instruction_operation) - | Some (5, _) -> (Program_types.Load_integer (Operations_pb.decode_load_integer (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (76, _) -> (Program_types.Load_big_int (Operations_pb.decode_load_big_int (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (6, _) -> (Program_types.Load_float (Operations_pb.decode_load_float (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (7, _) -> (Program_types.Load_string (Operations_pb.decode_load_string (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (8, _) -> (Program_types.Load_boolean (Operations_pb.decode_load_boolean (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (9, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Load_undefined : Program_types.instruction_operation) - end - | Some (10, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Load_null : Program_types.instruction_operation) - end - | Some (77, _) -> (Program_types.Load_reg_exp (Operations_pb.decode_load_reg_exp (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (11, _) -> (Program_types.Create_object (Operations_pb.decode_create_object (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (12, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Create_array : Program_types.instruction_operation) - end - | Some (13, _) -> (Program_types.Create_object_with_spread (Operations_pb.decode_create_object_with_spread (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (14, _) -> (Program_types.Create_array_with_spread (Operations_pb.decode_create_array_with_spread (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (15, _) -> (Program_types.Load_builtin (Operations_pb.decode_load_builtin (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (16, _) -> (Program_types.Load_property (Operations_pb.decode_load_property (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (17, _) -> (Program_types.Store_property (Operations_pb.decode_store_property (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (18, _) -> (Program_types.Delete_property (Operations_pb.decode_delete_property (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (19, _) -> (Program_types.Load_element (Operations_pb.decode_load_element (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (20, _) -> (Program_types.Store_element (Operations_pb.decode_store_element (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (21, _) -> (Program_types.Delete_element (Operations_pb.decode_delete_element (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (22, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Load_computed_property : Program_types.instruction_operation) - end - | Some (23, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Store_computed_property : Program_types.instruction_operation) - end - | Some (24, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Delete_computed_property : Program_types.instruction_operation) - end - | Some (25, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Type_of : Program_types.instruction_operation) - end - | Some (26, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Instance_of : Program_types.instruction_operation) - end - | Some (27, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.In : Program_types.instruction_operation) - end - | Some (28, _) -> (Program_types.Begin_plain_function_definition (Operations_pb.decode_begin_plain_function_definition (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (30, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_plain_function_definition : Program_types.instruction_operation) - end - | Some (65, _) -> (Program_types.Begin_strict_function_definition (Operations_pb.decode_begin_strict_function_definition (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (66, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_strict_function_definition : Program_types.instruction_operation) - end - | Some (67, _) -> (Program_types.Begin_arrow_function_definition (Operations_pb.decode_begin_arrow_function_definition (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (68, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_arrow_function_definition : Program_types.instruction_operation) - end - | Some (69, _) -> (Program_types.Begin_generator_function_definition (Operations_pb.decode_begin_generator_function_definition (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (70, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_generator_function_definition : Program_types.instruction_operation) - end - | Some (71, _) -> (Program_types.Begin_async_function_definition (Operations_pb.decode_begin_async_function_definition (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (72, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_async_function_definition : Program_types.instruction_operation) - end - | Some (79, _) -> (Program_types.Begin_async_arrow_function_definition (Operations_pb.decode_begin_async_arrow_function_definition (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (80, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_async_arrow_function_definition : Program_types.instruction_operation) - end - | Some (85, _) -> (Program_types.Begin_async_generator_function_definition (Operations_pb.decode_begin_async_generator_function_definition (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (86, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_async_generator_function_definition : Program_types.instruction_operation) - end - | Some (29, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Return : Program_types.instruction_operation) - end - | Some (73, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Yield : Program_types.instruction_operation) - end - | Some (74, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Yield_each : Program_types.instruction_operation) - end - | Some (75, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Await : Program_types.instruction_operation) - end - | Some (31, _) -> (Program_types.Call_method (Operations_pb.decode_call_method (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (32, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Call_function : Program_types.instruction_operation) - end - | Some (33, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Construct : Program_types.instruction_operation) - end - | Some (34, _) -> (Program_types.Call_function_with_spread (Operations_pb.decode_call_function_with_spread (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (35, _) -> (Program_types.Unary_operation (Operations_pb.decode_unary_operation (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (36, _) -> (Program_types.Binary_operation (Operations_pb.decode_binary_operation (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (37, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Dup : Program_types.instruction_operation) - end - | Some (38, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Reassign : Program_types.instruction_operation) - end - | Some (39, _) -> (Program_types.Compare (Operations_pb.decode_compare (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (40, _) -> (Program_types.Eval (Operations_pb.decode_eval (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (87, _) -> (Program_types.Begin_class_definition (Operations_pb.decode_begin_class_definition (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (88, _) -> (Program_types.Begin_method_definition (Operations_pb.decode_begin_method_definition (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (89, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_class_definition : Program_types.instruction_operation) - end - | Some (90, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Call_super_constructor : Program_types.instruction_operation) - end - | Some (91, _) -> (Program_types.Call_super_method (Operations_pb.decode_call_super_method (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (92, _) -> (Program_types.Load_super_property (Operations_pb.decode_load_super_property (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (93, _) -> (Program_types.Store_super_property (Operations_pb.decode_store_super_property (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (41, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Begin_with : Program_types.instruction_operation) - end - | Some (42, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_with : Program_types.instruction_operation) - end - | Some (43, _) -> (Program_types.Load_from_scope (Operations_pb.decode_load_from_scope (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (44, _) -> (Program_types.Store_to_scope (Operations_pb.decode_store_to_scope (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (45, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Begin_if : Program_types.instruction_operation) - end - | Some (46, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Begin_else : Program_types.instruction_operation) - end - | Some (47, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_if : Program_types.instruction_operation) - end - | Some (48, _) -> (Program_types.Begin_while (Operations_pb.decode_begin_while (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (49, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_while : Program_types.instruction_operation) - end - | Some (50, _) -> (Program_types.Begin_do_while (Operations_pb.decode_begin_do_while (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (51, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_do_while : Program_types.instruction_operation) - end - | Some (52, _) -> (Program_types.Begin_for (Operations_pb.decode_begin_for (Pbrt.Decoder.nested d)) : Program_types.instruction_operation) - | Some (53, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_for : Program_types.instruction_operation) - end - | Some (54, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Begin_for_in : Program_types.instruction_operation) - end - | Some (55, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_for_in : Program_types.instruction_operation) - end - | Some (56, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Begin_for_of : Program_types.instruction_operation) - end - | Some (57, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_for_of : Program_types.instruction_operation) - end - | Some (58, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Break : Program_types.instruction_operation) - end - | Some (59, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Continue : Program_types.instruction_operation) - end - | Some (60, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Begin_try : Program_types.instruction_operation) - end - | Some (61, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Begin_catch : Program_types.instruction_operation) - end - | Some (62, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_try_catch : Program_types.instruction_operation) - end - | Some (63, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Throw_exception : Program_types.instruction_operation) - end - | Some (81, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Begin_code_string : Program_types.instruction_operation) - end - | Some (82, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_code_string : Program_types.instruction_operation) - end - | Some (83, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Begin_block_statement : Program_types.instruction_operation) - end - | Some (84, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.End_block_statement : Program_types.instruction_operation) - end - | Some (64, _) -> begin - Pbrt.Decoder.empty_nested d ; - (Program_types.Nop : Program_types.instruction_operation) - end - | Some (n, payload_kind) -> ( - Pbrt.Decoder.skip d payload_kind; - loop () - ) - in - ret - in - loop () - -and decode_instruction d = - let v = default_instruction_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.inouts <- List.rev v.inouts; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.inouts <- Pbrt.Decoder.packed_fold (fun l d -> (Pbrt.Decoder.int32_as_varint d)::l) [] d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.operation <- Program_types.Op_idx (Pbrt.Decoder.int32_as_varint d); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(2)" pk - | Some (5, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_integer (Operations_pb.decode_load_integer (Pbrt.Decoder.nested d)); - end - | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(5)" pk - | Some (76, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_big_int (Operations_pb.decode_load_big_int (Pbrt.Decoder.nested d)); - end - | Some (76, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(76)" pk - | Some (6, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_float (Operations_pb.decode_load_float (Pbrt.Decoder.nested d)); - end - | Some (6, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(6)" pk - | Some (7, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_string (Operations_pb.decode_load_string (Pbrt.Decoder.nested d)); - end - | Some (7, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(7)" pk - | Some (8, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_boolean (Operations_pb.decode_load_boolean (Pbrt.Decoder.nested d)); - end - | Some (8, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(8)" pk - | Some (9, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Load_undefined; - end - | Some (9, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(9)" pk - | Some (10, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Load_null; - end - | Some (10, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(10)" pk - | Some (77, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_reg_exp (Operations_pb.decode_load_reg_exp (Pbrt.Decoder.nested d)); - end - | Some (77, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(77)" pk - | Some (11, Pbrt.Bytes) -> begin - v.operation <- Program_types.Create_object (Operations_pb.decode_create_object (Pbrt.Decoder.nested d)); - end - | Some (11, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(11)" pk - | Some (12, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Create_array; - end - | Some (12, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(12)" pk - | Some (13, Pbrt.Bytes) -> begin - v.operation <- Program_types.Create_object_with_spread (Operations_pb.decode_create_object_with_spread (Pbrt.Decoder.nested d)); - end - | Some (13, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(13)" pk - | Some (14, Pbrt.Bytes) -> begin - v.operation <- Program_types.Create_array_with_spread (Operations_pb.decode_create_array_with_spread (Pbrt.Decoder.nested d)); - end - | Some (14, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(14)" pk - | Some (15, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_builtin (Operations_pb.decode_load_builtin (Pbrt.Decoder.nested d)); - end - | Some (15, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(15)" pk - | Some (16, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_property (Operations_pb.decode_load_property (Pbrt.Decoder.nested d)); - end - | Some (16, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(16)" pk - | Some (17, Pbrt.Bytes) -> begin - v.operation <- Program_types.Store_property (Operations_pb.decode_store_property (Pbrt.Decoder.nested d)); - end - | Some (17, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(17)" pk - | Some (18, Pbrt.Bytes) -> begin - v.operation <- Program_types.Delete_property (Operations_pb.decode_delete_property (Pbrt.Decoder.nested d)); - end - | Some (18, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(18)" pk - | Some (19, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_element (Operations_pb.decode_load_element (Pbrt.Decoder.nested d)); - end - | Some (19, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(19)" pk - | Some (20, Pbrt.Bytes) -> begin - v.operation <- Program_types.Store_element (Operations_pb.decode_store_element (Pbrt.Decoder.nested d)); - end - | Some (20, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(20)" pk - | Some (21, Pbrt.Bytes) -> begin - v.operation <- Program_types.Delete_element (Operations_pb.decode_delete_element (Pbrt.Decoder.nested d)); - end - | Some (21, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(21)" pk - | Some (22, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Load_computed_property; - end - | Some (22, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(22)" pk - | Some (23, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Store_computed_property; - end - | Some (23, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(23)" pk - | Some (24, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Delete_computed_property; - end - | Some (24, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(24)" pk - | Some (25, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Type_of; - end - | Some (25, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(25)" pk - | Some (26, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Instance_of; - end - | Some (26, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(26)" pk - | Some (27, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.In; - end - | Some (27, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(27)" pk - | Some (28, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_plain_function_definition (Operations_pb.decode_begin_plain_function_definition (Pbrt.Decoder.nested d)); - end - | Some (28, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(28)" pk - | Some (30, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_plain_function_definition; - end - | Some (30, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(30)" pk - | Some (65, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_strict_function_definition (Operations_pb.decode_begin_strict_function_definition (Pbrt.Decoder.nested d)); - end - | Some (65, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(65)" pk - | Some (66, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_strict_function_definition; - end - | Some (66, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(66)" pk - | Some (67, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_arrow_function_definition (Operations_pb.decode_begin_arrow_function_definition (Pbrt.Decoder.nested d)); - end - | Some (67, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(67)" pk - | Some (68, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_arrow_function_definition; - end - | Some (68, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(68)" pk - | Some (69, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_generator_function_definition (Operations_pb.decode_begin_generator_function_definition (Pbrt.Decoder.nested d)); - end - | Some (69, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(69)" pk - | Some (70, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_generator_function_definition; - end - | Some (70, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(70)" pk - | Some (71, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_async_function_definition (Operations_pb.decode_begin_async_function_definition (Pbrt.Decoder.nested d)); - end - | Some (71, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(71)" pk - | Some (72, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_async_function_definition; - end - | Some (72, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(72)" pk - | Some (79, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_async_arrow_function_definition (Operations_pb.decode_begin_async_arrow_function_definition (Pbrt.Decoder.nested d)); - end - | Some (79, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(79)" pk - | Some (80, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_async_arrow_function_definition; - end - | Some (80, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(80)" pk - | Some (85, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_async_generator_function_definition (Operations_pb.decode_begin_async_generator_function_definition (Pbrt.Decoder.nested d)); - end - | Some (85, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(85)" pk - | Some (86, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_async_generator_function_definition; - end - | Some (86, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(86)" pk - | Some (29, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Return; - end - | Some (29, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(29)" pk - | Some (73, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Yield; - end - | Some (73, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(73)" pk - | Some (74, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Yield_each; - end - | Some (74, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(74)" pk - | Some (75, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Await; - end - | Some (75, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(75)" pk - | Some (31, Pbrt.Bytes) -> begin - v.operation <- Program_types.Call_method (Operations_pb.decode_call_method (Pbrt.Decoder.nested d)); - end - | Some (31, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(31)" pk - | Some (32, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Call_function; - end - | Some (32, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(32)" pk - | Some (33, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Construct; - end - | Some (33, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(33)" pk - | Some (34, Pbrt.Bytes) -> begin - v.operation <- Program_types.Call_function_with_spread (Operations_pb.decode_call_function_with_spread (Pbrt.Decoder.nested d)); - end - | Some (34, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(34)" pk - | Some (35, Pbrt.Bytes) -> begin - v.operation <- Program_types.Unary_operation (Operations_pb.decode_unary_operation (Pbrt.Decoder.nested d)); - end - | Some (35, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(35)" pk - | Some (36, Pbrt.Bytes) -> begin - v.operation <- Program_types.Binary_operation (Operations_pb.decode_binary_operation (Pbrt.Decoder.nested d)); - end - | Some (36, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(36)" pk - | Some (37, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Dup; - end - | Some (37, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(37)" pk - | Some (38, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Reassign; - end - | Some (38, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(38)" pk - | Some (39, Pbrt.Bytes) -> begin - v.operation <- Program_types.Compare (Operations_pb.decode_compare (Pbrt.Decoder.nested d)); - end - | Some (39, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(39)" pk - | Some (40, Pbrt.Bytes) -> begin - v.operation <- Program_types.Eval (Operations_pb.decode_eval (Pbrt.Decoder.nested d)); - end - | Some (40, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(40)" pk - | Some (87, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_class_definition (Operations_pb.decode_begin_class_definition (Pbrt.Decoder.nested d)); - end - | Some (87, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(87)" pk - | Some (88, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_method_definition (Operations_pb.decode_begin_method_definition (Pbrt.Decoder.nested d)); - end - | Some (88, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(88)" pk - | Some (89, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_class_definition; - end - | Some (89, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(89)" pk - | Some (90, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Call_super_constructor; - end - | Some (90, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(90)" pk - | Some (91, Pbrt.Bytes) -> begin - v.operation <- Program_types.Call_super_method (Operations_pb.decode_call_super_method (Pbrt.Decoder.nested d)); - end - | Some (91, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(91)" pk - | Some (92, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_super_property (Operations_pb.decode_load_super_property (Pbrt.Decoder.nested d)); - end - | Some (92, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(92)" pk - | Some (93, Pbrt.Bytes) -> begin - v.operation <- Program_types.Store_super_property (Operations_pb.decode_store_super_property (Pbrt.Decoder.nested d)); - end - | Some (93, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(93)" pk - | Some (41, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Begin_with; - end - | Some (41, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(41)" pk - | Some (42, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_with; - end - | Some (42, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(42)" pk - | Some (43, Pbrt.Bytes) -> begin - v.operation <- Program_types.Load_from_scope (Operations_pb.decode_load_from_scope (Pbrt.Decoder.nested d)); - end - | Some (43, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(43)" pk - | Some (44, Pbrt.Bytes) -> begin - v.operation <- Program_types.Store_to_scope (Operations_pb.decode_store_to_scope (Pbrt.Decoder.nested d)); - end - | Some (44, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(44)" pk - | Some (45, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Begin_if; - end - | Some (45, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(45)" pk - | Some (46, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Begin_else; - end - | Some (46, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(46)" pk - | Some (47, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_if; - end - | Some (47, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(47)" pk - | Some (48, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_while (Operations_pb.decode_begin_while (Pbrt.Decoder.nested d)); - end - | Some (48, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(48)" pk - | Some (49, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_while; - end - | Some (49, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(49)" pk - | Some (50, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_do_while (Operations_pb.decode_begin_do_while (Pbrt.Decoder.nested d)); - end - | Some (50, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(50)" pk - | Some (51, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_do_while; - end - | Some (51, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(51)" pk - | Some (52, Pbrt.Bytes) -> begin - v.operation <- Program_types.Begin_for (Operations_pb.decode_begin_for (Pbrt.Decoder.nested d)); - end - | Some (52, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(52)" pk - | Some (53, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_for; - end - | Some (53, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(53)" pk - | Some (54, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Begin_for_in; - end - | Some (54, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(54)" pk - | Some (55, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_for_in; - end - | Some (55, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(55)" pk - | Some (56, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Begin_for_of; - end - | Some (56, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(56)" pk - | Some (57, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_for_of; - end - | Some (57, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(57)" pk - | Some (58, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Break; - end - | Some (58, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(58)" pk - | Some (59, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Continue; - end - | Some (59, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(59)" pk - | Some (60, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Begin_try; - end - | Some (60, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(60)" pk - | Some (61, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Begin_catch; - end - | Some (61, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(61)" pk - | Some (62, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_try_catch; - end - | Some (62, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(62)" pk - | Some (63, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Throw_exception; - end - | Some (63, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(63)" pk - | Some (81, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Begin_code_string; - end - | Some (81, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(81)" pk - | Some (82, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_code_string; - end - | Some (82, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(82)" pk - | Some (83, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Begin_block_statement; - end - | Some (83, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(83)" pk - | Some (84, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.End_block_statement; - end - | Some (84, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(84)" pk - | Some (64, Pbrt.Bytes) -> begin - Pbrt.Decoder.empty_nested d; - v.operation <- Program_types.Nop; - end - | Some (64, pk) -> - Pbrt.Decoder.unexpected_payload "Message(instruction), field(64)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Program_types.inouts = v.inouts; - Program_types.operation = v.operation; - } : Program_types.instruction) - -let rec decode_type_collection_status d = - match Pbrt.Decoder.int_as_varint d with - | 0 -> (Program_types.Success:Program_types.type_collection_status) - | 1 -> (Program_types.Error:Program_types.type_collection_status) - | 2 -> (Program_types.Timeout:Program_types.type_collection_status) - | 3 -> (Program_types.Notattempted:Program_types.type_collection_status) - | _ -> Pbrt.Decoder.malformed_variant "type_collection_status" - -let rec decode_type_quality d = - match Pbrt.Decoder.int_as_varint d with - | 0 -> (Program_types.Inferred:Program_types.type_quality) - | 1 -> (Program_types.Runtime:Program_types.type_quality) - | _ -> Pbrt.Decoder.malformed_variant "type_quality" - -let rec decode_type_info d = - let v = default_type_info_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.variable <- Pbrt.Decoder.int32_as_varint d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_info), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.index <- Pbrt.Decoder.int32_as_varint d; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_info), field(2)" pk - | Some (3, Pbrt.Bytes) -> begin - v.type_ <- Some (Typesystem_pb.decode_type_ (Pbrt.Decoder.nested d)); - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_info), field(3)" pk - | Some (4, Pbrt.Varint) -> begin - v.quality <- decode_type_quality d; - end - | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_info), field(4)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Program_types.variable = v.variable; - Program_types.index = v.index; - Program_types.type_ = v.type_; - Program_types.quality = v.quality; - } : Program_types.type_info) - -let rec decode_program d = - let v = default_program_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.comments <- List.rev v.comments; - v.types <- List.rev v.types; - v.code <- List.rev v.code; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.uuid <- Pbrt.Decoder.bytes d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(program), field(1)" pk - | Some (2, Pbrt.Bytes) -> begin - v.code <- (decode_instruction (Pbrt.Decoder.nested d)) :: v.code; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(program), field(2)" pk - | Some (3, Pbrt.Bytes) -> begin - v.types <- (decode_type_info (Pbrt.Decoder.nested d)) :: v.types; - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(program), field(3)" pk - | Some (4, Pbrt.Varint) -> begin - v.type_collection_status <- decode_type_collection_status d; - end - | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(program), field(4)" pk - | Some (5, Pbrt.Bytes) -> begin - let decode_value = (fun d -> - Pbrt.Decoder.string d - ) in - v.comments <- ( - (Pbrt.Decoder.map_entry d ~decode_key:Pbrt.Decoder.int32_as_zigzag ~decode_value)::v.comments; - ); - end - | Some (5, pk) -> - Pbrt.Decoder.unexpected_payload "Message(program), field(5)" pk - | Some (6, Pbrt.Bytes) -> begin - v.parent <- Some (decode_program (Pbrt.Decoder.nested d)); - end - | Some (6, pk) -> - Pbrt.Decoder.unexpected_payload "Message(program), field(6)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Program_types.uuid = v.uuid; - Program_types.code = v.code; - Program_types.types = v.types; - Program_types.type_collection_status = v.type_collection_status; - Program_types.comments = v.comments; - Program_types.parent = v.parent; - } : Program_types.program) - -let rec encode_instruction_operation (v:Program_types.instruction_operation) encoder = - begin match v with - | Program_types.Op_idx x -> - Pbrt.Encoder.key (2, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint x encoder; - | Program_types.Load_integer x -> - Pbrt.Encoder.key (5, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_integer x) encoder; - | Program_types.Load_big_int x -> - Pbrt.Encoder.key (76, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_big_int x) encoder; - | Program_types.Load_float x -> - Pbrt.Encoder.key (6, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_float x) encoder; - | Program_types.Load_string x -> - Pbrt.Encoder.key (7, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_string x) encoder; - | Program_types.Load_boolean x -> - Pbrt.Encoder.key (8, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_boolean x) encoder; - | Program_types.Load_undefined -> - Pbrt.Encoder.key (9, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Load_null -> - Pbrt.Encoder.key (10, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Load_reg_exp x -> - Pbrt.Encoder.key (77, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_reg_exp x) encoder; - | Program_types.Create_object x -> - Pbrt.Encoder.key (11, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_create_object x) encoder; - | Program_types.Create_array -> - Pbrt.Encoder.key (12, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Create_object_with_spread x -> - Pbrt.Encoder.key (13, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_create_object_with_spread x) encoder; - | Program_types.Create_array_with_spread x -> - Pbrt.Encoder.key (14, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_create_array_with_spread x) encoder; - | Program_types.Load_builtin x -> - Pbrt.Encoder.key (15, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_builtin x) encoder; - | Program_types.Load_property x -> - Pbrt.Encoder.key (16, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_property x) encoder; - | Program_types.Store_property x -> - Pbrt.Encoder.key (17, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_store_property x) encoder; - | Program_types.Delete_property x -> - Pbrt.Encoder.key (18, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_delete_property x) encoder; - | Program_types.Load_element x -> - Pbrt.Encoder.key (19, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_element x) encoder; - | Program_types.Store_element x -> - Pbrt.Encoder.key (20, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_store_element x) encoder; - | Program_types.Delete_element x -> - Pbrt.Encoder.key (21, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_delete_element x) encoder; - | Program_types.Load_computed_property -> - Pbrt.Encoder.key (22, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Store_computed_property -> - Pbrt.Encoder.key (23, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Delete_computed_property -> - Pbrt.Encoder.key (24, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Type_of -> - Pbrt.Encoder.key (25, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Instance_of -> - Pbrt.Encoder.key (26, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.In -> - Pbrt.Encoder.key (27, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_plain_function_definition x -> - Pbrt.Encoder.key (28, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_plain_function_definition x) encoder; - | Program_types.End_plain_function_definition -> - Pbrt.Encoder.key (30, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_strict_function_definition x -> - Pbrt.Encoder.key (65, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_strict_function_definition x) encoder; - | Program_types.End_strict_function_definition -> - Pbrt.Encoder.key (66, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_arrow_function_definition x -> - Pbrt.Encoder.key (67, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_arrow_function_definition x) encoder; - | Program_types.End_arrow_function_definition -> - Pbrt.Encoder.key (68, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_generator_function_definition x -> - Pbrt.Encoder.key (69, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_generator_function_definition x) encoder; - | Program_types.End_generator_function_definition -> - Pbrt.Encoder.key (70, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_async_function_definition x -> - Pbrt.Encoder.key (71, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_async_function_definition x) encoder; - | Program_types.End_async_function_definition -> - Pbrt.Encoder.key (72, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_async_arrow_function_definition x -> - Pbrt.Encoder.key (79, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_async_arrow_function_definition x) encoder; - | Program_types.End_async_arrow_function_definition -> - Pbrt.Encoder.key (80, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_async_generator_function_definition x -> - Pbrt.Encoder.key (85, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_async_generator_function_definition x) encoder; - | Program_types.End_async_generator_function_definition -> - Pbrt.Encoder.key (86, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Return -> - Pbrt.Encoder.key (29, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Yield -> - Pbrt.Encoder.key (73, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Yield_each -> - Pbrt.Encoder.key (74, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Await -> - Pbrt.Encoder.key (75, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Call_method x -> - Pbrt.Encoder.key (31, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_call_method x) encoder; - | Program_types.Call_function -> - Pbrt.Encoder.key (32, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Construct -> - Pbrt.Encoder.key (33, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Call_function_with_spread x -> - Pbrt.Encoder.key (34, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_call_function_with_spread x) encoder; - | Program_types.Unary_operation x -> - Pbrt.Encoder.key (35, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_unary_operation x) encoder; - | Program_types.Binary_operation x -> - Pbrt.Encoder.key (36, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_binary_operation x) encoder; - | Program_types.Dup -> - Pbrt.Encoder.key (37, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Reassign -> - Pbrt.Encoder.key (38, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Compare x -> - Pbrt.Encoder.key (39, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_compare x) encoder; - | Program_types.Eval x -> - Pbrt.Encoder.key (40, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_eval x) encoder; - | Program_types.Begin_class_definition x -> - Pbrt.Encoder.key (87, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_class_definition x) encoder; - | Program_types.Begin_method_definition x -> - Pbrt.Encoder.key (88, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_method_definition x) encoder; - | Program_types.End_class_definition -> - Pbrt.Encoder.key (89, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Call_super_constructor -> - Pbrt.Encoder.key (90, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Call_super_method x -> - Pbrt.Encoder.key (91, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_call_super_method x) encoder; - | Program_types.Load_super_property x -> - Pbrt.Encoder.key (92, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_super_property x) encoder; - | Program_types.Store_super_property x -> - Pbrt.Encoder.key (93, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_store_super_property x) encoder; - | Program_types.Begin_with -> - Pbrt.Encoder.key (41, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_with -> - Pbrt.Encoder.key (42, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Load_from_scope x -> - Pbrt.Encoder.key (43, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_from_scope x) encoder; - | Program_types.Store_to_scope x -> - Pbrt.Encoder.key (44, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_store_to_scope x) encoder; - | Program_types.Begin_if -> - Pbrt.Encoder.key (45, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_else -> - Pbrt.Encoder.key (46, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_if -> - Pbrt.Encoder.key (47, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_while x -> - Pbrt.Encoder.key (48, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_while x) encoder; - | Program_types.End_while -> - Pbrt.Encoder.key (49, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_do_while x -> - Pbrt.Encoder.key (50, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_do_while x) encoder; - | Program_types.End_do_while -> - Pbrt.Encoder.key (51, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_for x -> - Pbrt.Encoder.key (52, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_for x) encoder; - | Program_types.End_for -> - Pbrt.Encoder.key (53, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_for_in -> - Pbrt.Encoder.key (54, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_for_in -> - Pbrt.Encoder.key (55, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_for_of -> - Pbrt.Encoder.key (56, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_for_of -> - Pbrt.Encoder.key (57, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Break -> - Pbrt.Encoder.key (58, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Continue -> - Pbrt.Encoder.key (59, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_try -> - Pbrt.Encoder.key (60, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_catch -> - Pbrt.Encoder.key (61, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_try_catch -> - Pbrt.Encoder.key (62, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Throw_exception -> - Pbrt.Encoder.key (63, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_code_string -> - Pbrt.Encoder.key (81, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_code_string -> - Pbrt.Encoder.key (82, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_block_statement -> - Pbrt.Encoder.key (83, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_block_statement -> - Pbrt.Encoder.key (84, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Nop -> - Pbrt.Encoder.key (64, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - end - -and encode_instruction (v:Program_types.instruction) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (fun encoder -> - List.iter (fun x -> - Pbrt.Encoder.int32_as_varint x encoder; - ) v.Program_types.inouts; - ) encoder; - begin match v.Program_types.operation with - | Program_types.Op_idx x -> - Pbrt.Encoder.key (2, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint x encoder; - | Program_types.Load_integer x -> - Pbrt.Encoder.key (5, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_integer x) encoder; - | Program_types.Load_big_int x -> - Pbrt.Encoder.key (76, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_big_int x) encoder; - | Program_types.Load_float x -> - Pbrt.Encoder.key (6, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_float x) encoder; - | Program_types.Load_string x -> - Pbrt.Encoder.key (7, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_string x) encoder; - | Program_types.Load_boolean x -> - Pbrt.Encoder.key (8, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_boolean x) encoder; - | Program_types.Load_undefined -> - Pbrt.Encoder.key (9, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Load_null -> - Pbrt.Encoder.key (10, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Load_reg_exp x -> - Pbrt.Encoder.key (77, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_reg_exp x) encoder; - | Program_types.Create_object x -> - Pbrt.Encoder.key (11, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_create_object x) encoder; - | Program_types.Create_array -> - Pbrt.Encoder.key (12, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Create_object_with_spread x -> - Pbrt.Encoder.key (13, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_create_object_with_spread x) encoder; - | Program_types.Create_array_with_spread x -> - Pbrt.Encoder.key (14, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_create_array_with_spread x) encoder; - | Program_types.Load_builtin x -> - Pbrt.Encoder.key (15, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_builtin x) encoder; - | Program_types.Load_property x -> - Pbrt.Encoder.key (16, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_property x) encoder; - | Program_types.Store_property x -> - Pbrt.Encoder.key (17, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_store_property x) encoder; - | Program_types.Delete_property x -> - Pbrt.Encoder.key (18, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_delete_property x) encoder; - | Program_types.Load_element x -> - Pbrt.Encoder.key (19, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_element x) encoder; - | Program_types.Store_element x -> - Pbrt.Encoder.key (20, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_store_element x) encoder; - | Program_types.Delete_element x -> - Pbrt.Encoder.key (21, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_delete_element x) encoder; - | Program_types.Load_computed_property -> - Pbrt.Encoder.key (22, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Store_computed_property -> - Pbrt.Encoder.key (23, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Delete_computed_property -> - Pbrt.Encoder.key (24, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Type_of -> - Pbrt.Encoder.key (25, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Instance_of -> - Pbrt.Encoder.key (26, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.In -> - Pbrt.Encoder.key (27, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_plain_function_definition x -> - Pbrt.Encoder.key (28, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_plain_function_definition x) encoder; - | Program_types.End_plain_function_definition -> - Pbrt.Encoder.key (30, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_strict_function_definition x -> - Pbrt.Encoder.key (65, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_strict_function_definition x) encoder; - | Program_types.End_strict_function_definition -> - Pbrt.Encoder.key (66, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_arrow_function_definition x -> - Pbrt.Encoder.key (67, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_arrow_function_definition x) encoder; - | Program_types.End_arrow_function_definition -> - Pbrt.Encoder.key (68, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_generator_function_definition x -> - Pbrt.Encoder.key (69, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_generator_function_definition x) encoder; - | Program_types.End_generator_function_definition -> - Pbrt.Encoder.key (70, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_async_function_definition x -> - Pbrt.Encoder.key (71, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_async_function_definition x) encoder; - | Program_types.End_async_function_definition -> - Pbrt.Encoder.key (72, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_async_arrow_function_definition x -> - Pbrt.Encoder.key (79, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_async_arrow_function_definition x) encoder; - | Program_types.End_async_arrow_function_definition -> - Pbrt.Encoder.key (80, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_async_generator_function_definition x -> - Pbrt.Encoder.key (85, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_async_generator_function_definition x) encoder; - | Program_types.End_async_generator_function_definition -> - Pbrt.Encoder.key (86, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Return -> - Pbrt.Encoder.key (29, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Yield -> - Pbrt.Encoder.key (73, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Yield_each -> - Pbrt.Encoder.key (74, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Await -> - Pbrt.Encoder.key (75, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Call_method x -> - Pbrt.Encoder.key (31, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_call_method x) encoder; - | Program_types.Call_function -> - Pbrt.Encoder.key (32, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Construct -> - Pbrt.Encoder.key (33, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Call_function_with_spread x -> - Pbrt.Encoder.key (34, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_call_function_with_spread x) encoder; - | Program_types.Unary_operation x -> - Pbrt.Encoder.key (35, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_unary_operation x) encoder; - | Program_types.Binary_operation x -> - Pbrt.Encoder.key (36, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_binary_operation x) encoder; - | Program_types.Dup -> - Pbrt.Encoder.key (37, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Reassign -> - Pbrt.Encoder.key (38, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Compare x -> - Pbrt.Encoder.key (39, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_compare x) encoder; - | Program_types.Eval x -> - Pbrt.Encoder.key (40, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_eval x) encoder; - | Program_types.Begin_class_definition x -> - Pbrt.Encoder.key (87, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_class_definition x) encoder; - | Program_types.Begin_method_definition x -> - Pbrt.Encoder.key (88, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_method_definition x) encoder; - | Program_types.End_class_definition -> - Pbrt.Encoder.key (89, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Call_super_constructor -> - Pbrt.Encoder.key (90, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Call_super_method x -> - Pbrt.Encoder.key (91, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_call_super_method x) encoder; - | Program_types.Load_super_property x -> - Pbrt.Encoder.key (92, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_super_property x) encoder; - | Program_types.Store_super_property x -> - Pbrt.Encoder.key (93, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_store_super_property x) encoder; - | Program_types.Begin_with -> - Pbrt.Encoder.key (41, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_with -> - Pbrt.Encoder.key (42, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Load_from_scope x -> - Pbrt.Encoder.key (43, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_load_from_scope x) encoder; - | Program_types.Store_to_scope x -> - Pbrt.Encoder.key (44, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_store_to_scope x) encoder; - | Program_types.Begin_if -> - Pbrt.Encoder.key (45, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_else -> - Pbrt.Encoder.key (46, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_if -> - Pbrt.Encoder.key (47, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_while x -> - Pbrt.Encoder.key (48, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_while x) encoder; - | Program_types.End_while -> - Pbrt.Encoder.key (49, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_do_while x -> - Pbrt.Encoder.key (50, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_do_while x) encoder; - | Program_types.End_do_while -> - Pbrt.Encoder.key (51, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_for x -> - Pbrt.Encoder.key (52, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Operations_pb.encode_begin_for x) encoder; - | Program_types.End_for -> - Pbrt.Encoder.key (53, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_for_in -> - Pbrt.Encoder.key (54, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_for_in -> - Pbrt.Encoder.key (55, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_for_of -> - Pbrt.Encoder.key (56, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_for_of -> - Pbrt.Encoder.key (57, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Break -> - Pbrt.Encoder.key (58, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Continue -> - Pbrt.Encoder.key (59, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_try -> - Pbrt.Encoder.key (60, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_catch -> - Pbrt.Encoder.key (61, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_try_catch -> - Pbrt.Encoder.key (62, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Throw_exception -> - Pbrt.Encoder.key (63, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_code_string -> - Pbrt.Encoder.key (81, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_code_string -> - Pbrt.Encoder.key (82, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Begin_block_statement -> - Pbrt.Encoder.key (83, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.End_block_statement -> - Pbrt.Encoder.key (84, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - | Program_types.Nop -> - Pbrt.Encoder.key (64, Pbrt.Bytes) encoder; - Pbrt.Encoder.empty_nested encoder - end; - () - -let rec encode_type_collection_status (v:Program_types.type_collection_status) encoder = - match v with - | Program_types.Success -> Pbrt.Encoder.int_as_varint (0) encoder - | Program_types.Error -> Pbrt.Encoder.int_as_varint 1 encoder - | Program_types.Timeout -> Pbrt.Encoder.int_as_varint 2 encoder - | Program_types.Notattempted -> Pbrt.Encoder.int_as_varint 3 encoder - -let rec encode_type_quality (v:Program_types.type_quality) encoder = - match v with - | Program_types.Inferred -> Pbrt.Encoder.int_as_varint (0) encoder - | Program_types.Runtime -> Pbrt.Encoder.int_as_varint 1 encoder - -let rec encode_type_info (v:Program_types.type_info) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint v.Program_types.variable encoder; - Pbrt.Encoder.key (2, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint v.Program_types.index encoder; - begin match v.Program_types.type_ with - | Some x -> - Pbrt.Encoder.key (3, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (Typesystem_pb.encode_type_ x) encoder; - | None -> (); - end; - Pbrt.Encoder.key (4, Pbrt.Varint) encoder; - encode_type_quality v.Program_types.quality encoder; - () - -let rec encode_program (v:Program_types.program) encoder = - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.bytes v.Program_types.uuid encoder; - List.iter (fun x -> - Pbrt.Encoder.key (2, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (encode_instruction x) encoder; - ) v.Program_types.code; - List.iter (fun x -> - Pbrt.Encoder.key (3, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (encode_type_info x) encoder; - ) v.Program_types.types; - Pbrt.Encoder.key (4, Pbrt.Varint) encoder; - encode_type_collection_status v.Program_types.type_collection_status encoder; - let encode_key = Pbrt.Encoder.int32_as_zigzag in - let encode_value = (fun x encoder -> - Pbrt.Encoder.string x encoder; - ) in - List.iter (fun (k, v) -> - Pbrt.Encoder.key (5, Pbrt.Bytes) encoder; - let map_entry = (k, Pbrt.Varint), (v, Pbrt.Bytes) in - Pbrt.Encoder.map_entry ~encode_key ~encode_value map_entry encoder - ) v.Program_types.comments; - begin match v.Program_types.parent with - | Some x -> - Pbrt.Encoder.key (6, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (encode_program x) encoder; - | None -> (); - end; - () diff --git a/Compiler/src/proto/program_pb.mli b/Compiler/src/proto/program_pb.mli deleted file mode 100644 index ee576a4d..00000000 --- a/Compiler/src/proto/program_pb.mli +++ /dev/null @@ -1,43 +0,0 @@ -(** program.proto Binary Encoding *) - - -(** {2 Protobuf Encoding} *) - -val encode_instruction_operation : Program_types.instruction_operation -> Pbrt.Encoder.t -> unit -(** [encode_instruction_operation v encoder] encodes [v] with the given [encoder] *) - -val encode_instruction : Program_types.instruction -> Pbrt.Encoder.t -> unit -(** [encode_instruction v encoder] encodes [v] with the given [encoder] *) - -val encode_type_collection_status : Program_types.type_collection_status -> Pbrt.Encoder.t -> unit -(** [encode_type_collection_status v encoder] encodes [v] with the given [encoder] *) - -val encode_type_quality : Program_types.type_quality -> Pbrt.Encoder.t -> unit -(** [encode_type_quality v encoder] encodes [v] with the given [encoder] *) - -val encode_type_info : Program_types.type_info -> Pbrt.Encoder.t -> unit -(** [encode_type_info v encoder] encodes [v] with the given [encoder] *) - -val encode_program : Program_types.program -> Pbrt.Encoder.t -> unit -(** [encode_program v encoder] encodes [v] with the given [encoder] *) - - -(** {2 Protobuf Decoding} *) - -val decode_instruction_operation : Pbrt.Decoder.t -> Program_types.instruction_operation -(** [decode_instruction_operation decoder] decodes a [instruction_operation] value from [decoder] *) - -val decode_instruction : Pbrt.Decoder.t -> Program_types.instruction -(** [decode_instruction decoder] decodes a [instruction] value from [decoder] *) - -val decode_type_collection_status : Pbrt.Decoder.t -> Program_types.type_collection_status -(** [decode_type_collection_status decoder] decodes a [type_collection_status] value from [decoder] *) - -val decode_type_quality : Pbrt.Decoder.t -> Program_types.type_quality -(** [decode_type_quality decoder] decodes a [type_quality] value from [decoder] *) - -val decode_type_info : Pbrt.Decoder.t -> Program_types.type_info -(** [decode_type_info decoder] decodes a [type_info] value from [decoder] *) - -val decode_program : Pbrt.Decoder.t -> Program_types.program -(** [decode_program decoder] decodes a [program] value from [decoder] *) diff --git a/Compiler/src/proto/program_pp.ml b/Compiler/src/proto/program_pp.ml deleted file mode 100644 index bbd8522d..00000000 --- a/Compiler/src/proto/program_pp.ml +++ /dev/null @@ -1,138 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - -let rec pp_instruction_operation fmt (v:Program_types.instruction_operation) = - match v with - | Program_types.Op_idx x -> Format.fprintf fmt "@[Op_idx(%a)@]" Pbrt.Pp.pp_int32 x - | Program_types.Load_integer x -> Format.fprintf fmt "@[Load_integer(%a)@]" Operations_pp.pp_load_integer x - | Program_types.Load_big_int x -> Format.fprintf fmt "@[Load_big_int(%a)@]" Operations_pp.pp_load_big_int x - | Program_types.Load_float x -> Format.fprintf fmt "@[Load_float(%a)@]" Operations_pp.pp_load_float x - | Program_types.Load_string x -> Format.fprintf fmt "@[Load_string(%a)@]" Operations_pp.pp_load_string x - | Program_types.Load_boolean x -> Format.fprintf fmt "@[Load_boolean(%a)@]" Operations_pp.pp_load_boolean x - | Program_types.Load_undefined -> Format.fprintf fmt "Load_undefined" - | Program_types.Load_null -> Format.fprintf fmt "Load_null" - | Program_types.Load_reg_exp x -> Format.fprintf fmt "@[Load_reg_exp(%a)@]" Operations_pp.pp_load_reg_exp x - | Program_types.Create_object x -> Format.fprintf fmt "@[Create_object(%a)@]" Operations_pp.pp_create_object x - | Program_types.Create_array -> Format.fprintf fmt "Create_array" - | Program_types.Create_object_with_spread x -> Format.fprintf fmt "@[Create_object_with_spread(%a)@]" Operations_pp.pp_create_object_with_spread x - | Program_types.Create_array_with_spread x -> Format.fprintf fmt "@[Create_array_with_spread(%a)@]" Operations_pp.pp_create_array_with_spread x - | Program_types.Load_builtin x -> Format.fprintf fmt "@[Load_builtin(%a)@]" Operations_pp.pp_load_builtin x - | Program_types.Load_property x -> Format.fprintf fmt "@[Load_property(%a)@]" Operations_pp.pp_load_property x - | Program_types.Store_property x -> Format.fprintf fmt "@[Store_property(%a)@]" Operations_pp.pp_store_property x - | Program_types.Delete_property x -> Format.fprintf fmt "@[Delete_property(%a)@]" Operations_pp.pp_delete_property x - | Program_types.Load_element x -> Format.fprintf fmt "@[Load_element(%a)@]" Operations_pp.pp_load_element x - | Program_types.Store_element x -> Format.fprintf fmt "@[Store_element(%a)@]" Operations_pp.pp_store_element x - | Program_types.Delete_element x -> Format.fprintf fmt "@[Delete_element(%a)@]" Operations_pp.pp_delete_element x - | Program_types.Load_computed_property -> Format.fprintf fmt "Load_computed_property" - | Program_types.Store_computed_property -> Format.fprintf fmt "Store_computed_property" - | Program_types.Delete_computed_property -> Format.fprintf fmt "Delete_computed_property" - | Program_types.Type_of -> Format.fprintf fmt "Type_of" - | Program_types.Instance_of -> Format.fprintf fmt "Instance_of" - | Program_types.In -> Format.fprintf fmt "In" - | Program_types.Begin_plain_function_definition x -> Format.fprintf fmt "@[Begin_plain_function_definition(%a)@]" Operations_pp.pp_begin_plain_function_definition x - | Program_types.End_plain_function_definition -> Format.fprintf fmt "End_plain_function_definition" - | Program_types.Begin_strict_function_definition x -> Format.fprintf fmt "@[Begin_strict_function_definition(%a)@]" Operations_pp.pp_begin_strict_function_definition x - | Program_types.End_strict_function_definition -> Format.fprintf fmt "End_strict_function_definition" - | Program_types.Begin_arrow_function_definition x -> Format.fprintf fmt "@[Begin_arrow_function_definition(%a)@]" Operations_pp.pp_begin_arrow_function_definition x - | Program_types.End_arrow_function_definition -> Format.fprintf fmt "End_arrow_function_definition" - | Program_types.Begin_generator_function_definition x -> Format.fprintf fmt "@[Begin_generator_function_definition(%a)@]" Operations_pp.pp_begin_generator_function_definition x - | Program_types.End_generator_function_definition -> Format.fprintf fmt "End_generator_function_definition" - | Program_types.Begin_async_function_definition x -> Format.fprintf fmt "@[Begin_async_function_definition(%a)@]" Operations_pp.pp_begin_async_function_definition x - | Program_types.End_async_function_definition -> Format.fprintf fmt "End_async_function_definition" - | Program_types.Begin_async_arrow_function_definition x -> Format.fprintf fmt "@[Begin_async_arrow_function_definition(%a)@]" Operations_pp.pp_begin_async_arrow_function_definition x - | Program_types.End_async_arrow_function_definition -> Format.fprintf fmt "End_async_arrow_function_definition" - | Program_types.Begin_async_generator_function_definition x -> Format.fprintf fmt "@[Begin_async_generator_function_definition(%a)@]" Operations_pp.pp_begin_async_generator_function_definition x - | Program_types.End_async_generator_function_definition -> Format.fprintf fmt "End_async_generator_function_definition" - | Program_types.Return -> Format.fprintf fmt "Return" - | Program_types.Yield -> Format.fprintf fmt "Yield" - | Program_types.Yield_each -> Format.fprintf fmt "Yield_each" - | Program_types.Await -> Format.fprintf fmt "Await" - | Program_types.Call_method x -> Format.fprintf fmt "@[Call_method(%a)@]" Operations_pp.pp_call_method x - | Program_types.Call_function -> Format.fprintf fmt "Call_function" - | Program_types.Construct -> Format.fprintf fmt "Construct" - | Program_types.Call_function_with_spread x -> Format.fprintf fmt "@[Call_function_with_spread(%a)@]" Operations_pp.pp_call_function_with_spread x - | Program_types.Unary_operation x -> Format.fprintf fmt "@[Unary_operation(%a)@]" Operations_pp.pp_unary_operation x - | Program_types.Binary_operation x -> Format.fprintf fmt "@[Binary_operation(%a)@]" Operations_pp.pp_binary_operation x - | Program_types.Dup -> Format.fprintf fmt "Dup" - | Program_types.Reassign -> Format.fprintf fmt "Reassign" - | Program_types.Compare x -> Format.fprintf fmt "@[Compare(%a)@]" Operations_pp.pp_compare x - | Program_types.Eval x -> Format.fprintf fmt "@[Eval(%a)@]" Operations_pp.pp_eval x - | Program_types.Begin_class_definition x -> Format.fprintf fmt "@[Begin_class_definition(%a)@]" Operations_pp.pp_begin_class_definition x - | Program_types.Begin_method_definition x -> Format.fprintf fmt "@[Begin_method_definition(%a)@]" Operations_pp.pp_begin_method_definition x - | Program_types.End_class_definition -> Format.fprintf fmt "End_class_definition" - | Program_types.Call_super_constructor -> Format.fprintf fmt "Call_super_constructor" - | Program_types.Call_super_method x -> Format.fprintf fmt "@[Call_super_method(%a)@]" Operations_pp.pp_call_super_method x - | Program_types.Load_super_property x -> Format.fprintf fmt "@[Load_super_property(%a)@]" Operations_pp.pp_load_super_property x - | Program_types.Store_super_property x -> Format.fprintf fmt "@[Store_super_property(%a)@]" Operations_pp.pp_store_super_property x - | Program_types.Begin_with -> Format.fprintf fmt "Begin_with" - | Program_types.End_with -> Format.fprintf fmt "End_with" - | Program_types.Load_from_scope x -> Format.fprintf fmt "@[Load_from_scope(%a)@]" Operations_pp.pp_load_from_scope x - | Program_types.Store_to_scope x -> Format.fprintf fmt "@[Store_to_scope(%a)@]" Operations_pp.pp_store_to_scope x - | Program_types.Begin_if -> Format.fprintf fmt "Begin_if" - | Program_types.Begin_else -> Format.fprintf fmt "Begin_else" - | Program_types.End_if -> Format.fprintf fmt "End_if" - | Program_types.Begin_while x -> Format.fprintf fmt "@[Begin_while(%a)@]" Operations_pp.pp_begin_while x - | Program_types.End_while -> Format.fprintf fmt "End_while" - | Program_types.Begin_do_while x -> Format.fprintf fmt "@[Begin_do_while(%a)@]" Operations_pp.pp_begin_do_while x - | Program_types.End_do_while -> Format.fprintf fmt "End_do_while" - | Program_types.Begin_for x -> Format.fprintf fmt "@[Begin_for(%a)@]" Operations_pp.pp_begin_for x - | Program_types.End_for -> Format.fprintf fmt "End_for" - | Program_types.Begin_for_in -> Format.fprintf fmt "Begin_for_in" - | Program_types.End_for_in -> Format.fprintf fmt "End_for_in" - | Program_types.Begin_for_of -> Format.fprintf fmt "Begin_for_of" - | Program_types.End_for_of -> Format.fprintf fmt "End_for_of" - | Program_types.Break -> Format.fprintf fmt "Break" - | Program_types.Continue -> Format.fprintf fmt "Continue" - | Program_types.Begin_try -> Format.fprintf fmt "Begin_try" - | Program_types.Begin_catch -> Format.fprintf fmt "Begin_catch" - | Program_types.End_try_catch -> Format.fprintf fmt "End_try_catch" - | Program_types.Throw_exception -> Format.fprintf fmt "Throw_exception" - | Program_types.Begin_code_string -> Format.fprintf fmt "Begin_code_string" - | Program_types.End_code_string -> Format.fprintf fmt "End_code_string" - | Program_types.Begin_block_statement -> Format.fprintf fmt "Begin_block_statement" - | Program_types.End_block_statement -> Format.fprintf fmt "End_block_statement" - | Program_types.Nop -> Format.fprintf fmt "Nop" - -and pp_instruction fmt (v:Program_types.instruction) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "inouts" (Pbrt.Pp.pp_list Pbrt.Pp.pp_int32) fmt v.Program_types.inouts; - Pbrt.Pp.pp_record_field "operation" pp_instruction_operation fmt v.Program_types.operation; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_type_collection_status fmt (v:Program_types.type_collection_status) = - match v with - | Program_types.Success -> Format.fprintf fmt "Success" - | Program_types.Error -> Format.fprintf fmt "Error" - | Program_types.Timeout -> Format.fprintf fmt "Timeout" - | Program_types.Notattempted -> Format.fprintf fmt "Notattempted" - -let rec pp_type_quality fmt (v:Program_types.type_quality) = - match v with - | Program_types.Inferred -> Format.fprintf fmt "Inferred" - | Program_types.Runtime -> Format.fprintf fmt "Runtime" - -let rec pp_type_info fmt (v:Program_types.type_info) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "variable" Pbrt.Pp.pp_int32 fmt v.Program_types.variable; - Pbrt.Pp.pp_record_field "index" Pbrt.Pp.pp_int32 fmt v.Program_types.index; - Pbrt.Pp.pp_record_field "type_" (Pbrt.Pp.pp_option Typesystem_pp.pp_type_) fmt v.Program_types.type_; - Pbrt.Pp.pp_record_field "quality" pp_type_quality fmt v.Program_types.quality; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -let rec pp_program fmt (v:Program_types.program) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "uuid" Pbrt.Pp.pp_bytes fmt v.Program_types.uuid; - Pbrt.Pp.pp_record_field "code" (Pbrt.Pp.pp_list pp_instruction) fmt v.Program_types.code; - Pbrt.Pp.pp_record_field "types" (Pbrt.Pp.pp_list pp_type_info) fmt v.Program_types.types; - Pbrt.Pp.pp_record_field "type_collection_status" pp_type_collection_status fmt v.Program_types.type_collection_status; - Pbrt.Pp.pp_record_field "comments" (Pbrt.Pp.pp_associative_list Pbrt.Pp.pp_int32 Pbrt.Pp.pp_string) fmt v.Program_types.comments; - Pbrt.Pp.pp_record_field "parent" (Pbrt.Pp.pp_option pp_program) fmt v.Program_types.parent; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () diff --git a/Compiler/src/proto/program_pp.mli b/Compiler/src/proto/program_pp.mli deleted file mode 100644 index 1f417cea..00000000 --- a/Compiler/src/proto/program_pp.mli +++ /dev/null @@ -1,22 +0,0 @@ -(** program.proto Pretty Printing *) - - -(** {2 Formatters} *) - -val pp_instruction_operation : Format.formatter -> Program_types.instruction_operation -> unit -(** [pp_instruction_operation v] formats v *) - -val pp_instruction : Format.formatter -> Program_types.instruction -> unit -(** [pp_instruction v] formats v *) - -val pp_type_collection_status : Format.formatter -> Program_types.type_collection_status -> unit -(** [pp_type_collection_status v] formats v *) - -val pp_type_quality : Format.formatter -> Program_types.type_quality -> unit -(** [pp_type_quality v] formats v *) - -val pp_type_info : Format.formatter -> Program_types.type_info -> unit -(** [pp_type_info v] formats v *) - -val pp_program : Format.formatter -> Program_types.program -> unit -(** [pp_program v] formats v *) diff --git a/Compiler/src/proto/program_types.ml b/Compiler/src/proto/program_types.ml deleted file mode 100644 index 212e3fdc..00000000 --- a/Compiler/src/proto/program_types.ml +++ /dev/null @@ -1,166 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - - -type instruction_operation = - | Op_idx of int32 - | Load_integer of Operations_types.load_integer - | Load_big_int of Operations_types.load_big_int - | Load_float of Operations_types.load_float - | Load_string of Operations_types.load_string - | Load_boolean of Operations_types.load_boolean - | Load_undefined - | Load_null - | Load_reg_exp of Operations_types.load_reg_exp - | Create_object of Operations_types.create_object - | Create_array - | Create_object_with_spread of Operations_types.create_object_with_spread - | Create_array_with_spread of Operations_types.create_array_with_spread - | Load_builtin of Operations_types.load_builtin - | Load_property of Operations_types.load_property - | Store_property of Operations_types.store_property - | Delete_property of Operations_types.delete_property - | Load_element of Operations_types.load_element - | Store_element of Operations_types.store_element - | Delete_element of Operations_types.delete_element - | Load_computed_property - | Store_computed_property - | Delete_computed_property - | Type_of - | Instance_of - | In - | Begin_plain_function_definition of Operations_types.begin_plain_function_definition - | End_plain_function_definition - | Begin_strict_function_definition of Operations_types.begin_strict_function_definition - | End_strict_function_definition - | Begin_arrow_function_definition of Operations_types.begin_arrow_function_definition - | End_arrow_function_definition - | Begin_generator_function_definition of Operations_types.begin_generator_function_definition - | End_generator_function_definition - | Begin_async_function_definition of Operations_types.begin_async_function_definition - | End_async_function_definition - | Begin_async_arrow_function_definition of Operations_types.begin_async_arrow_function_definition - | End_async_arrow_function_definition - | Begin_async_generator_function_definition of Operations_types.begin_async_generator_function_definition - | End_async_generator_function_definition - | Return - | Yield - | Yield_each - | Await - | Call_method of Operations_types.call_method - | Call_function - | Construct - | Call_function_with_spread of Operations_types.call_function_with_spread - | Unary_operation of Operations_types.unary_operation - | Binary_operation of Operations_types.binary_operation - | Dup - | Reassign - | Compare of Operations_types.compare - | Eval of Operations_types.eval - | Begin_class_definition of Operations_types.begin_class_definition - | Begin_method_definition of Operations_types.begin_method_definition - | End_class_definition - | Call_super_constructor - | Call_super_method of Operations_types.call_super_method - | Load_super_property of Operations_types.load_super_property - | Store_super_property of Operations_types.store_super_property - | Begin_with - | End_with - | Load_from_scope of Operations_types.load_from_scope - | Store_to_scope of Operations_types.store_to_scope - | Begin_if - | Begin_else - | End_if - | Begin_while of Operations_types.begin_while - | End_while - | Begin_do_while of Operations_types.begin_do_while - | End_do_while - | Begin_for of Operations_types.begin_for - | End_for - | Begin_for_in - | End_for_in - | Begin_for_of - | End_for_of - | Break - | Continue - | Begin_try - | Begin_catch - | End_try_catch - | Throw_exception - | Begin_code_string - | End_code_string - | Begin_block_statement - | End_block_statement - | Nop - -and instruction = { - inouts : int32 list; - operation : instruction_operation; -} - -type type_collection_status = - | Success - | Error - | Timeout - | Notattempted - -type type_quality = - | Inferred - | Runtime - -type type_info = { - variable : int32; - index : int32; - type_ : Typesystem_types.type_ option; - quality : type_quality; -} - -type program = { - uuid : bytes; - code : instruction list; - types : type_info list; - type_collection_status : type_collection_status; - comments : (int32 * string) list; - parent : program option; -} - -let rec default_instruction_operation () : instruction_operation = Op_idx (0l) - -and default_instruction - ?inouts:((inouts:int32 list) = []) - ?operation:((operation:instruction_operation) = Op_idx (0l)) - () : instruction = { - inouts; - operation; -} - -let rec default_type_collection_status () = (Success:type_collection_status) - -let rec default_type_quality () = (Inferred:type_quality) - -let rec default_type_info - ?variable:((variable:int32) = 0l) - ?index:((index:int32) = 0l) - ?type_:((type_:Typesystem_types.type_ option) = None) - ?quality:((quality:type_quality) = default_type_quality ()) - () : type_info = { - variable; - index; - type_; - quality; -} - -let rec default_program - ?uuid:((uuid:bytes) = Bytes.create 0) - ?code:((code:instruction list) = []) - ?types:((types:type_info list) = []) - ?type_collection_status:((type_collection_status:type_collection_status) = default_type_collection_status ()) - ?comments:((comments:(int32 * string) list) = []) - ?parent:((parent:program option) = None) - () : program = { - uuid; - code; - types; - type_collection_status; - comments; - parent; -} diff --git a/Compiler/src/proto/program_types.mli b/Compiler/src/proto/program_types.mli deleted file mode 100644 index df833fc2..00000000 --- a/Compiler/src/proto/program_types.mli +++ /dev/null @@ -1,166 +0,0 @@ -(** program.proto Types *) - - - -(** {2 Types} *) - -type instruction_operation = - | Op_idx of int32 - | Load_integer of Operations_types.load_integer - | Load_big_int of Operations_types.load_big_int - | Load_float of Operations_types.load_float - | Load_string of Operations_types.load_string - | Load_boolean of Operations_types.load_boolean - | Load_undefined - | Load_null - | Load_reg_exp of Operations_types.load_reg_exp - | Create_object of Operations_types.create_object - | Create_array - | Create_object_with_spread of Operations_types.create_object_with_spread - | Create_array_with_spread of Operations_types.create_array_with_spread - | Load_builtin of Operations_types.load_builtin - | Load_property of Operations_types.load_property - | Store_property of Operations_types.store_property - | Delete_property of Operations_types.delete_property - | Load_element of Operations_types.load_element - | Store_element of Operations_types.store_element - | Delete_element of Operations_types.delete_element - | Load_computed_property - | Store_computed_property - | Delete_computed_property - | Type_of - | Instance_of - | In - | Begin_plain_function_definition of Operations_types.begin_plain_function_definition - | End_plain_function_definition - | Begin_strict_function_definition of Operations_types.begin_strict_function_definition - | End_strict_function_definition - | Begin_arrow_function_definition of Operations_types.begin_arrow_function_definition - | End_arrow_function_definition - | Begin_generator_function_definition of Operations_types.begin_generator_function_definition - | End_generator_function_definition - | Begin_async_function_definition of Operations_types.begin_async_function_definition - | End_async_function_definition - | Begin_async_arrow_function_definition of Operations_types.begin_async_arrow_function_definition - | End_async_arrow_function_definition - | Begin_async_generator_function_definition of Operations_types.begin_async_generator_function_definition - | End_async_generator_function_definition - | Return - | Yield - | Yield_each - | Await - | Call_method of Operations_types.call_method - | Call_function - | Construct - | Call_function_with_spread of Operations_types.call_function_with_spread - | Unary_operation of Operations_types.unary_operation - | Binary_operation of Operations_types.binary_operation - | Dup - | Reassign - | Compare of Operations_types.compare - | Eval of Operations_types.eval - | Begin_class_definition of Operations_types.begin_class_definition - | Begin_method_definition of Operations_types.begin_method_definition - | End_class_definition - | Call_super_constructor - | Call_super_method of Operations_types.call_super_method - | Load_super_property of Operations_types.load_super_property - | Store_super_property of Operations_types.store_super_property - | Begin_with - | End_with - | Load_from_scope of Operations_types.load_from_scope - | Store_to_scope of Operations_types.store_to_scope - | Begin_if - | Begin_else - | End_if - | Begin_while of Operations_types.begin_while - | End_while - | Begin_do_while of Operations_types.begin_do_while - | End_do_while - | Begin_for of Operations_types.begin_for - | End_for - | Begin_for_in - | End_for_in - | Begin_for_of - | End_for_of - | Break - | Continue - | Begin_try - | Begin_catch - | End_try_catch - | Throw_exception - | Begin_code_string - | End_code_string - | Begin_block_statement - | End_block_statement - | Nop - -and instruction = { - inouts : int32 list; - operation : instruction_operation; -} - -type type_collection_status = - | Success - | Error - | Timeout - | Notattempted - -type type_quality = - | Inferred - | Runtime - -type type_info = { - variable : int32; - index : int32; - type_ : Typesystem_types.type_ option; - quality : type_quality; -} - -type program = { - uuid : bytes; - code : instruction list; - types : type_info list; - type_collection_status : type_collection_status; - comments : (int32 * string) list; - parent : program option; -} - - -(** {2 Default values} *) - -val default_instruction_operation : unit -> instruction_operation -(** [default_instruction_operation ()] is the default value for type [instruction_operation] *) - -val default_instruction : - ?inouts:int32 list -> - ?operation:instruction_operation -> - unit -> - instruction -(** [default_instruction ()] is the default value for type [instruction] *) - -val default_type_collection_status : unit -> type_collection_status -(** [default_type_collection_status ()] is the default value for type [type_collection_status] *) - -val default_type_quality : unit -> type_quality -(** [default_type_quality ()] is the default value for type [type_quality] *) - -val default_type_info : - ?variable:int32 -> - ?index:int32 -> - ?type_:Typesystem_types.type_ option -> - ?quality:type_quality -> - unit -> - type_info -(** [default_type_info ()] is the default value for type [type_info] *) - -val default_program : - ?uuid:bytes -> - ?code:instruction list -> - ?types:type_info list -> - ?type_collection_status:type_collection_status -> - ?comments:(int32 * string) list -> - ?parent:program option -> - unit -> - program -(** [default_program ()] is the default value for type [program] *) diff --git a/Compiler/src/proto/typesystem_pb.ml b/Compiler/src/proto/typesystem_pb.ml deleted file mode 100644 index 649fabae..00000000 --- a/Compiler/src/proto/typesystem_pb.ml +++ /dev/null @@ -1,208 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - -type type__mutable = { - mutable definite_type : int32; - mutable possible_type : int32; - mutable ext : Typesystem_types.type_ext; -} - -let default_type__mutable () : type__mutable = { - definite_type = 0l; - possible_type = 0l; - ext = Typesystem_types.Extension_idx (0l); -} - -type type_extension_mutable = { - mutable properties : string list; - mutable methods : string list; - mutable group : string; - mutable signature : Typesystem_types.function_signature option; -} - -let default_type_extension_mutable () : type_extension_mutable = { - properties = []; - methods = []; - group = ""; - signature = None; -} - -type function_signature_mutable = { - mutable input_types : Typesystem_types.type_ list; - mutable output_type : Typesystem_types.type_ option; -} - -let default_function_signature_mutable () : function_signature_mutable = { - input_types = []; - output_type = None; -} - - -let rec decode_type_ext d = - let rec loop () = - let ret:Typesystem_types.type_ext = match Pbrt.Decoder.key d with - | None -> Pbrt.Decoder.malformed_variant "type_ext" - | Some (3, _) -> (Typesystem_types.Extension_idx (Pbrt.Decoder.int32_as_varint d) : Typesystem_types.type_ext) - | Some (4, _) -> (Typesystem_types.Extension (decode_type_extension (Pbrt.Decoder.nested d)) : Typesystem_types.type_ext) - | Some (n, payload_kind) -> ( - Pbrt.Decoder.skip d payload_kind; - loop () - ) - in - ret - in - loop () - -and decode_type_ d = - let v = default_type__mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - ); continue__ := false - | Some (1, Pbrt.Varint) -> begin - v.definite_type <- Pbrt.Decoder.int32_as_varint d; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_), field(1)" pk - | Some (2, Pbrt.Varint) -> begin - v.possible_type <- Pbrt.Decoder.int32_as_varint d; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_), field(2)" pk - | Some (3, Pbrt.Varint) -> begin - v.ext <- Typesystem_types.Extension_idx (Pbrt.Decoder.int32_as_varint d); - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_), field(3)" pk - | Some (4, Pbrt.Bytes) -> begin - v.ext <- Typesystem_types.Extension (decode_type_extension (Pbrt.Decoder.nested d)); - end - | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_), field(4)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Typesystem_types.definite_type = v.definite_type; - Typesystem_types.possible_type = v.possible_type; - Typesystem_types.ext = v.ext; - } : Typesystem_types.type_) - -and decode_type_extension d = - let v = default_type_extension_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.methods <- List.rev v.methods; - v.properties <- List.rev v.properties; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.properties <- (Pbrt.Decoder.string d) :: v.properties; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_extension), field(1)" pk - | Some (2, Pbrt.Bytes) -> begin - v.methods <- (Pbrt.Decoder.string d) :: v.methods; - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_extension), field(2)" pk - | Some (3, Pbrt.Bytes) -> begin - v.group <- Pbrt.Decoder.string d; - end - | Some (3, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_extension), field(3)" pk - | Some (4, Pbrt.Bytes) -> begin - v.signature <- Some (decode_function_signature (Pbrt.Decoder.nested d)); - end - | Some (4, pk) -> - Pbrt.Decoder.unexpected_payload "Message(type_extension), field(4)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Typesystem_types.properties = v.properties; - Typesystem_types.methods = v.methods; - Typesystem_types.group = v.group; - Typesystem_types.signature = v.signature; - } : Typesystem_types.type_extension) - -and decode_function_signature d = - let v = default_function_signature_mutable () in - let continue__= ref true in - while !continue__ do - match Pbrt.Decoder.key d with - | None -> ( - v.input_types <- List.rev v.input_types; - ); continue__ := false - | Some (1, Pbrt.Bytes) -> begin - v.input_types <- (decode_type_ (Pbrt.Decoder.nested d)) :: v.input_types; - end - | Some (1, pk) -> - Pbrt.Decoder.unexpected_payload "Message(function_signature), field(1)" pk - | Some (2, Pbrt.Bytes) -> begin - v.output_type <- Some (decode_type_ (Pbrt.Decoder.nested d)); - end - | Some (2, pk) -> - Pbrt.Decoder.unexpected_payload "Message(function_signature), field(2)" pk - | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind - done; - ({ - Typesystem_types.input_types = v.input_types; - Typesystem_types.output_type = v.output_type; - } : Typesystem_types.function_signature) - -let rec encode_type_ext (v:Typesystem_types.type_ext) encoder = - begin match v with - | Typesystem_types.Extension_idx x -> - Pbrt.Encoder.key (3, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint x encoder; - | Typesystem_types.Extension x -> - Pbrt.Encoder.key (4, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (encode_type_extension x) encoder; - end - -and encode_type_ (v:Typesystem_types.type_) encoder = - Pbrt.Encoder.key (1, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint v.Typesystem_types.definite_type encoder; - Pbrt.Encoder.key (2, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint v.Typesystem_types.possible_type encoder; - begin match v.Typesystem_types.ext with - | Typesystem_types.Extension_idx x -> - Pbrt.Encoder.key (3, Pbrt.Varint) encoder; - Pbrt.Encoder.int32_as_varint x encoder; - | Typesystem_types.Extension x -> - Pbrt.Encoder.key (4, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (encode_type_extension x) encoder; - end; - () - -and encode_type_extension (v:Typesystem_types.type_extension) encoder = - List.iter (fun x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.string x encoder; - ) v.Typesystem_types.properties; - List.iter (fun x -> - Pbrt.Encoder.key (2, Pbrt.Bytes) encoder; - Pbrt.Encoder.string x encoder; - ) v.Typesystem_types.methods; - Pbrt.Encoder.key (3, Pbrt.Bytes) encoder; - Pbrt.Encoder.string v.Typesystem_types.group encoder; - begin match v.Typesystem_types.signature with - | Some x -> - Pbrt.Encoder.key (4, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (encode_function_signature x) encoder; - | None -> (); - end; - () - -and encode_function_signature (v:Typesystem_types.function_signature) encoder = - List.iter (fun x -> - Pbrt.Encoder.key (1, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (encode_type_ x) encoder; - ) v.Typesystem_types.input_types; - begin match v.Typesystem_types.output_type with - | Some x -> - Pbrt.Encoder.key (2, Pbrt.Bytes) encoder; - Pbrt.Encoder.nested (encode_type_ x) encoder; - | None -> (); - end; - () diff --git a/Compiler/src/proto/typesystem_pb.mli b/Compiler/src/proto/typesystem_pb.mli deleted file mode 100644 index 1addbe64..00000000 --- a/Compiler/src/proto/typesystem_pb.mli +++ /dev/null @@ -1,31 +0,0 @@ -(** typesystem.proto Binary Encoding *) - - -(** {2 Protobuf Encoding} *) - -val encode_type_ext : Typesystem_types.type_ext -> Pbrt.Encoder.t -> unit -(** [encode_type_ext v encoder] encodes [v] with the given [encoder] *) - -val encode_type_ : Typesystem_types.type_ -> Pbrt.Encoder.t -> unit -(** [encode_type_ v encoder] encodes [v] with the given [encoder] *) - -val encode_type_extension : Typesystem_types.type_extension -> Pbrt.Encoder.t -> unit -(** [encode_type_extension v encoder] encodes [v] with the given [encoder] *) - -val encode_function_signature : Typesystem_types.function_signature -> Pbrt.Encoder.t -> unit -(** [encode_function_signature v encoder] encodes [v] with the given [encoder] *) - - -(** {2 Protobuf Decoding} *) - -val decode_type_ext : Pbrt.Decoder.t -> Typesystem_types.type_ext -(** [decode_type_ext decoder] decodes a [type_ext] value from [decoder] *) - -val decode_type_ : Pbrt.Decoder.t -> Typesystem_types.type_ -(** [decode_type_ decoder] decodes a [type_] value from [decoder] *) - -val decode_type_extension : Pbrt.Decoder.t -> Typesystem_types.type_extension -(** [decode_type_extension decoder] decodes a [type_extension] value from [decoder] *) - -val decode_function_signature : Pbrt.Decoder.t -> Typesystem_types.function_signature -(** [decode_function_signature decoder] decodes a [function_signature] value from [decoder] *) diff --git a/Compiler/src/proto/typesystem_pp.ml b/Compiler/src/proto/typesystem_pp.ml deleted file mode 100644 index ba86b3d5..00000000 --- a/Compiler/src/proto/typesystem_pp.ml +++ /dev/null @@ -1,36 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - -let rec pp_type_ext fmt (v:Typesystem_types.type_ext) = - match v with - | Typesystem_types.Extension_idx x -> Format.fprintf fmt "@[Extension_idx(%a)@]" Pbrt.Pp.pp_int32 x - | Typesystem_types.Extension x -> Format.fprintf fmt "@[Extension(%a)@]" pp_type_extension x - -and pp_type_ fmt (v:Typesystem_types.type_) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "definite_type" Pbrt.Pp.pp_int32 fmt v.Typesystem_types.definite_type; - Pbrt.Pp.pp_record_field "possible_type" Pbrt.Pp.pp_int32 fmt v.Typesystem_types.possible_type; - Pbrt.Pp.pp_record_field "ext" pp_type_ext fmt v.Typesystem_types.ext; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -and pp_type_extension fmt (v:Typesystem_types.type_extension) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "properties" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.Typesystem_types.properties; - Pbrt.Pp.pp_record_field "methods" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.Typesystem_types.methods; - Pbrt.Pp.pp_record_field "group" Pbrt.Pp.pp_string fmt v.Typesystem_types.group; - Pbrt.Pp.pp_record_field "signature" (Pbrt.Pp.pp_option pp_function_signature) fmt v.Typesystem_types.signature; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () - -and pp_function_signature fmt (v:Typesystem_types.function_signature) = - let pp_i fmt () = - Format.pp_open_vbox fmt 1; - Pbrt.Pp.pp_record_field "input_types" (Pbrt.Pp.pp_list pp_type_) fmt v.Typesystem_types.input_types; - Pbrt.Pp.pp_record_field "output_type" (Pbrt.Pp.pp_option pp_type_) fmt v.Typesystem_types.output_type; - Format.pp_close_box fmt () - in - Pbrt.Pp.pp_brk pp_i fmt () diff --git a/Compiler/src/proto/typesystem_pp.mli b/Compiler/src/proto/typesystem_pp.mli deleted file mode 100644 index 534cfbce..00000000 --- a/Compiler/src/proto/typesystem_pp.mli +++ /dev/null @@ -1,16 +0,0 @@ -(** typesystem.proto Pretty Printing *) - - -(** {2 Formatters} *) - -val pp_type_ext : Format.formatter -> Typesystem_types.type_ext -> unit -(** [pp_type_ext v] formats v *) - -val pp_type_ : Format.formatter -> Typesystem_types.type_ -> unit -(** [pp_type_ v] formats v *) - -val pp_type_extension : Format.formatter -> Typesystem_types.type_extension -> unit -(** [pp_type_extension v] formats v *) - -val pp_function_signature : Format.formatter -> Typesystem_types.function_signature -> unit -(** [pp_function_signature v] formats v *) diff --git a/Compiler/src/proto/typesystem_types.ml b/Compiler/src/proto/typesystem_types.ml deleted file mode 100644 index b2590723..00000000 --- a/Compiler/src/proto/typesystem_types.ml +++ /dev/null @@ -1,56 +0,0 @@ -[@@@ocaml.warning "-27-30-39"] - - -type type_ext = - | Extension_idx of int32 - | Extension of type_extension - -and type_ = { - definite_type : int32; - possible_type : int32; - ext : type_ext; -} - -and type_extension = { - properties : string list; - methods : string list; - group : string; - signature : function_signature option; -} - -and function_signature = { - input_types : type_ list; - output_type : type_ option; -} - -let rec default_type_ext () : type_ext = Extension_idx (0l) - -and default_type_ - ?definite_type:((definite_type:int32) = 0l) - ?possible_type:((possible_type:int32) = 0l) - ?ext:((ext:type_ext) = Extension_idx (0l)) - () : type_ = { - definite_type; - possible_type; - ext; -} - -and default_type_extension - ?properties:((properties:string list) = []) - ?methods:((methods:string list) = []) - ?group:((group:string) = "") - ?signature:((signature:function_signature option) = None) - () : type_extension = { - properties; - methods; - group; - signature; -} - -and default_function_signature - ?input_types:((input_types:type_ list) = []) - ?output_type:((output_type:type_ option) = None) - () : function_signature = { - input_types; - output_type; -} diff --git a/Compiler/src/proto/typesystem_types.mli b/Compiler/src/proto/typesystem_types.mli deleted file mode 100644 index a2305a33..00000000 --- a/Compiler/src/proto/typesystem_types.mli +++ /dev/null @@ -1,57 +0,0 @@ -(** typesystem.proto Types *) - - - -(** {2 Types} *) - -type type_ext = - | Extension_idx of int32 - | Extension of type_extension - -and type_ = { - definite_type : int32; - possible_type : int32; - ext : type_ext; -} - -and type_extension = { - properties : string list; - methods : string list; - group : string; - signature : function_signature option; -} - -and function_signature = { - input_types : type_ list; - output_type : type_ option; -} - - -(** {2 Default values} *) - -val default_type_ext : unit -> type_ext -(** [default_type_ext ()] is the default value for type [type_ext] *) - -val default_type_ : - ?definite_type:int32 -> - ?possible_type:int32 -> - ?ext:type_ext -> - unit -> - type_ -(** [default_type_ ()] is the default value for type [type_] *) - -val default_type_extension : - ?properties:string list -> - ?methods:string list -> - ?group:string -> - ?signature:function_signature option -> - unit -> - type_extension -(** [default_type_extension ()] is the default value for type [type_extension] *) - -val default_function_signature : - ?input_types:type_ list -> - ?output_type:type_ option -> - unit -> - function_signature -(** [default_function_signature ()] is the default value for type [function_signature] *) diff --git a/Compiler/src/translate.ml b/Compiler/src/translate.ml deleted file mode 100644 index 7e84472c..00000000 --- a/Compiler/src/translate.ml +++ /dev/null @@ -1,959 +0,0 @@ -open ProgramBuilder - -let flow_binaryassign_op_to_progbuilder_binop (op : Flow_ast.Expression.Assignment.operator) = - let res : binary_op = match op with - PlusAssign -> Plus - | MinusAssign -> Minus - | MultAssign -> Mult - | DivAssign -> Div - | ModAssign -> Mod - | BitXorAssign -> Xor - | LShiftAssign -> LShift - | RShiftAssign -> RShift - | ExpAssign -> Exp - | RShift3Assign -> RShift3 - | BitAndAssign -> BitAnd - | BitOrAssign -> BitOr in - res - -let hoist_id var_name builder = - let result_temp, inst = build_load_undefined builder in - add_new_var_identifier var_name result_temp builder; - add_hoisted_var var_name builder; - inst - -let hoist_functions_to_top (statements: (Loc.t, Loc.t) Flow_ast.Statement.t list) = - let partition_func (s:(Loc.t, Loc.t) Flow_ast.Statement.t) = match s with - (_, Flow_ast.Statement.FunctionDeclaration _) -> true - | _ -> false in - let function_list, rest_list = List.partition partition_func statements in - function_list @ rest_list - -(* Designed to be called on the statements of a function *) -let handle_varHoist (statements: (Loc.t, Loc.t) Flow_ast.Statement.t list) (builder: builder) = - let hoisted_functions = hoist_functions_to_top statements in - let var_useData, func_useData = VariableScope.get_vars_to_hoist hoisted_functions in - let is_not_builtin s = Util.is_supported_builtin s (include_v8_natives builder) |> not in - let funcs_to_hoist = List.filter is_not_builtin func_useData in - let hoist_func var = hoist_id var builder in - let hoist_vars = List.map hoist_func var_useData in - let hoist_funcs = List.map hoist_func funcs_to_hoist in - hoist_vars @ hoist_funcs - -(* Handle the various types of literal*) -let proc_exp_literal (lit_val: ('T) Flow_ast.Literal.t) (builder: builder) = - let (temp_val, inst) = match lit_val.value with - (Flow_ast.Literal.String s) -> - (* TODO: This may be the cause of the issue where some files fail Fuzzilli import due to a UTF-8 error *) - let newString = Util.encode_newline s in - build_load_string newString builder - | (Flow_ast.Literal.Boolean b) -> - build_load_bool b builder - | (Flow_ast.Literal.Null) -> - build_load_null builder - | (Flow_ast.Literal.Number num) -> - (* Flow_ast only has one type for a number, while Fuzzilli has several, each with its own protobuf type*) - if Float.is_integer num && not (String.contains lit_val.raw '.') && Int64.of_float num >= Int64.min_int && Int64.of_float num <= Int64.max_int then - build_load_integer (Int64.of_float num) builder - else - build_load_float num builder - | (Flow_ast.Literal.BigInt b) -> - build_load_bigInt b builder - | (Flow_ast.Literal.RegExp r) -> - let pattern = r.pattern in - let flags = r.flags in - build_load_regex pattern flags builder in - (temp_val, [inst]) - -(* Handle the various unary types*) -let rec proc_exp_unary (u_val: ('M, 'T) Flow_ast.Expression.Unary.t) (builder: builder) = - match u_val.operator with - Flow_ast.Expression.Unary.Not -> - let arg_result_var, argument = proc_expression u_val.argument builder in - let result_var, inst = build_unary_op arg_result_var Not builder in - result_var, argument @ [inst] - | Flow_ast.Expression.Unary.BitNot -> - let arg_result_var, argument = proc_expression u_val.argument builder in - let result_var, inst = build_unary_op arg_result_var BitNot builder in - result_var, argument @ [inst] - | Flow_ast.Expression.Unary.Minus -> - let arg_result_var, argument = proc_expression u_val.argument builder in - let result_var, inst = build_unary_op arg_result_var Minus builder in - result_var, argument @ [inst] - | Flow_ast.Expression.Unary.Plus -> - let arg_result_var, argument = proc_expression u_val.argument builder in - let result_var, inst = build_unary_op arg_result_var Plus builder in - result_var, argument @ [inst] - | Flow_ast.Expression.Unary.Typeof -> - let arg_result_var, argument = proc_expression u_val.argument builder in - let result_var, inst = build_typeof_op arg_result_var builder in - result_var, argument @ [inst] - | Flow_ast.Expression.Unary.Await -> - let arg_result_var, argument = proc_expression u_val.argument builder in - let result_var, inst = build_await_op arg_result_var builder in - result_var, argument @ [inst] - | Flow_ast.Expression.Unary.Delete -> - (* Need to determine between computed delete, and named delete*) - let _, unwrapped_arg = u_val.argument in - let del_temp, del_inst = match unwrapped_arg with - Flow_ast.Expression.Member mem -> - let obj_temp, obj_inst = proc_expression mem._object builder in - ( match mem.property with - Flow_ast.Expression.Member.PropertyIdentifier (_, id) -> - let name = id.name in - let obj, del_inst = build_delete_prop obj_temp name builder in - obj, obj_inst @ [del_inst] - | Flow_ast.Expression.Member.PropertyExpression exp -> - let sub_temp, sub_inst = proc_expression exp builder in - let (obj, com_del_inst) = build_delete_computed_prop obj_temp sub_temp builder in - obj_temp, obj_inst @ sub_inst @ [com_del_inst] - | _ -> raise (Invalid_argument "Unhandled delete member property") ) - | Identifier id -> raise (Invalid_argument "Deleting an ID isn't supported in Fuzzilli") - | _ -> raise (Invalid_argument "Unsupported delete expression ") in - del_temp, del_inst - | Flow_ast.Expression.Unary.Void -> - let _, argument = proc_expression u_val.argument builder in - let result_var, inst = build_void_op builder in - result_var, argument @ [inst] - - -(* First, check against various edge cases. Otherwise, check the context, and handle the result appropriately *) -and proc_exp_id (id_val: ('M, 'T) Flow_ast.Identifier.t) builder = - let (_, unwraped_id_val) = id_val in - let name = unwraped_id_val.name in - if String.equal name "Infinity" then (* TODO: What other values go here? *) - let (result_var, inst) = build_load_float Float.infinity builder in - result_var, [inst] - else if String.equal name "undefined" then - let result_var, inst = build_load_undefined builder in - result_var, [inst] - else match lookup_var_name builder name with - InScope x -> (x, []) - | NotFound -> - if Util.is_supported_builtin name (include_v8_natives builder) then - let (result_var, inst) = build_load_builtin name builder in - if (should_emit_builtins builder) then print_endline ("Builtin: " ^ name) else (); - (result_var, [inst]) - else if use_placeholder builder then - let (result_var, inst) = build_load_builtin "placeholder" builder in - (result_var, [inst]) - else - raise (Invalid_argument ("Unhandled builtin " ^ name)) - -and proc_exp_bin_op (bin_op: ('M, 'T) Flow_ast.Expression.Binary.t) builder = - let (lvar, linsts) = proc_expression bin_op.left builder in - let (rvar, rinsts) = proc_expression bin_op.right builder in - let build_binary_op_func op = build_binary_op lvar rvar op builder in - let build_compare_op_func op = build_compare_op lvar rvar op builder in - let (result_var, inst) = match bin_op.operator with - Plus -> build_binary_op_func Plus - | Minus -> build_binary_op_func Minus - | Mult -> build_binary_op_func Mult - | Div -> build_binary_op_func Div - | Mod -> build_binary_op_func Mod - | Xor -> build_binary_op_func Xor - | LShift -> build_binary_op_func LShift - | RShift -> build_binary_op_func RShift - | Exp -> build_binary_op_func Exp - | RShift3 -> build_binary_op_func RShift3 - | BitAnd -> build_binary_op_func BitAnd - | BitOr -> build_binary_op_func BitOr - | Equal -> build_compare_op_func Equal - | NotEqual -> build_compare_op_func NotEqual - | StrictEqual -> build_compare_op_func StrictEqual - | StrictNotEqual -> build_compare_op_func StrictNotEqual - | LessThan -> build_compare_op_func LessThan - | LessThanEqual -> build_compare_op_func LessThanEqual - | GreaterThan -> build_compare_op_func GreaterThan - | GreaterThanEqual -> build_compare_op_func GreaterThanEqual - | Instanceof -> build_instanceof_op lvar rvar builder - | In -> build_in_op lvar rvar builder in - (result_var, linsts @ rinsts @ [inst]) - -and proc_exp_logical (log_op: ('M, 'T) Flow_ast.Expression.Logical.t) builder = - let (lvar, linsts) = proc_expression log_op.left builder in - let (rvar, rinsts) = proc_expression log_op.right builder in - let op = match log_op.operator with - Flow_ast.Expression.Logical.And -> LogicalAnd - | Flow_ast.Expression.Logical.Or -> LogicalOr - | x -> raise (Invalid_argument ("Unhandled logical expression type" ^ (Util.trim_flow_ast_string (Util.print_logical_operator x)))) in - let (result_var, inst) = build_binary_op lvar rvar op builder in - (result_var, linsts @ rinsts @ [inst]) - -(* There are various different expression types, so pattern match on each time, and ccall the appropriate, more specific, function*) -and proc_exp_assignment (assign_exp: ('M, 'T) Flow_ast.Expression.Assignment.t) (builder: builder) = - match assign_exp.left with - (_, (Flow_ast.Pattern.Identifier id)) -> proc_exp_assignment_norm_id assign_exp id.name builder - | (_, (Flow_ast.Pattern.Expression (_, exp))) -> - (match exp with - Flow_ast.Expression.Member mem -> - let obj = mem._object in - (match mem.property with - Flow_ast.Expression.Member.PropertyExpression pex -> proc_exp_assignment_prod_exp pex obj assign_exp.right assign_exp.operator builder - | Flow_ast.Expression.Member.PropertyIdentifier pid -> proc_exp_assignment_prod_id pid obj assign_exp.right assign_exp.operator builder - | _ -> raise (Invalid_argument "Unhandled member property in exp assignment")) - | _ -> raise (Invalid_argument "Unhandled assignment expression left member")) - | _ -> raise (Invalid_argument "Unhandled assignment expressesion left ") - -and proc_exp_assignment_prod_id - (prop_id: (Loc.t, Loc.t) Flow_ast.Identifier.t) - (obj: (Loc.t, Loc.t) Flow_ast.Expression.t) - (right_exp: (Loc.t, Loc.t) Flow_ast.Expression.t) - (op: Flow_ast.Expression.Assignment.operator option) - (builder: builder) = - let obj_temp, obj_inst = proc_expression obj builder in - let (_, unwapped_id) = prop_id in - let name = unwapped_id.name in - let right_exp_temp, right_exp_inst = proc_expression right_exp builder in - let (sugared_assignment_temp, assigment_insts) = match op with - None -> (right_exp_temp, []) - | Some op -> - let (initial_prop_var, load_inst) = build_load_prop obj_temp name builder in - let bin_op = flow_binaryassign_op_to_progbuilder_binop op in - let result_var, assignment_inst = build_binary_op initial_prop_var right_exp_temp bin_op builder in - (result_var, [load_inst; assignment_inst]) in - let store_inst = build_store_prop obj_temp sugared_assignment_temp name builder in - (sugared_assignment_temp, obj_inst @ right_exp_inst @ assigment_insts @ [store_inst]) - -(* Handle assignments to property expressions *) -and proc_exp_assignment_prod_exp - (prop_exp: (Loc.t, Loc.t) Flow_ast.Expression.t) - (obj: (Loc.t, Loc.t) Flow_ast.Expression.t) - (right_exp: (Loc.t, Loc.t) Flow_ast.Expression.t) - (op: Flow_ast.Expression.Assignment.operator option) - (builder: builder) = - - let obj_temp, obj_inst = proc_expression obj builder in - let index_exp_temp, index_exp_inst = proc_expression prop_exp builder in - let right_exp_temp, right_exp_inst = proc_expression right_exp builder in - - let (lval_var, assigment_insts) = match op with - None -> (right_exp_temp, []) - | Some op -> - let load_temp_var, load_inst = build_load_computed_prop obj_temp index_exp_temp builder in - let bin_op = flow_binaryassign_op_to_progbuilder_binop op in - let result_var, assignment_inst = build_binary_op load_temp_var right_exp_temp bin_op builder in - (result_var, [load_inst; assignment_inst]) in - let store_inst = build_store_computed_prop obj_temp index_exp_temp lval_var builder in - (lval_var, obj_inst @ index_exp_inst @ right_exp_inst @ assigment_insts @ [store_inst]) - -(* Handle assignments to normal identifiers*) -and proc_exp_assignment_norm_id (assign_exp: ('M, 'T) Flow_ast.Expression.Assignment.t) (id: (Loc.t, Loc.t) Flow_ast.Identifier.t) builder = - let (_, act_name) = id in - let (exp_output_loc, exp_insts) = proc_expression assign_exp.right builder in - - let (sugared_assignment_temp, sugared_assigment_exp) = match assign_exp.operator with - None -> (exp_output_loc, []) - | Some op -> - let source, source_inst = match lookup_var_name builder act_name.name with - InScope x -> (x, []) - | NotFound -> - raise (Invalid_argument "Variable not found") in - let bin_op = flow_binaryassign_op_to_progbuilder_binop op in - let result_var, assignment_inst = build_binary_op source exp_output_loc bin_op builder in - - (result_var, source_inst @ [assignment_inst]) - in - let var_temp, add_inst = match lookup_var_name builder act_name.name with - (* This case is where a variable is being declared, without a let/const/var.*) - NotFound -> - let result_var, inst = build_dup_op sugared_assignment_temp builder in - add_new_var_identifier act_name.name result_var builder; - (result_var, [inst]) - | InScope existing_temp -> - let inst = build_reassign_op existing_temp sugared_assignment_temp builder in - (existing_temp, [inst]) - in - (var_temp, exp_insts @ sugared_assigment_exp @ add_inst) - -(* Handle a list of arguments to a function call*) -and proc_arg_list (arg_list: ('M, 'T) Flow_ast.Expression.ArgList.t) builder = - let _, unwrapped = arg_list in - let arguments = unwrapped.arguments in - let proc_exp_or_spread (exp_or_spread: ('M, 'T) Flow_ast.Expression.expression_or_spread) = - match exp_or_spread with - Expression exp -> - proc_expression exp builder - | Spread spread -> - let (_, unwrapped) = spread in - proc_expression unwrapped.argument builder in - let reg_list, unflattened_inst_list = List.split (List.map proc_exp_or_spread arguments) in - reg_list, List.flatten unflattened_inst_list - -and arg_list_get_spread_list (arg_list: ('M, 'T) Flow_ast.Expression.ArgList.t) = - let _, unwrapped = arg_list in - let arguments = unwrapped.arguments in - let proc_exp_or_spread (exp_or_spread: ('M, 'T) Flow_ast.Expression.expression_or_spread) = - match exp_or_spread with - Expression exp -> false - | Spread spread -> true in - List.map proc_exp_or_spread arguments - -and proc_exp_call (call_exp: ('M, 'T) Flow_ast.Expression.Call.t) builder = - let _ : unit = match call_exp.targs with - None -> () - | Some a -> raise (Invalid_argument "Unhandled targs in call") in - let is_spread_list = arg_list_get_spread_list call_exp.arguments in - let is_spread = List.fold_left (||) false is_spread_list in - let (_, callee) = call_exp.callee in - match callee with - (* Handle the method call case explicity*) - Flow_ast.Expression.Member member -> - (match member.property with - (* Handle method calls seperately for all other cases *) - Flow_ast.Expression.Member.PropertyIdentifier (_, id) -> - let sub_exp_temp, sub_exp_inst = proc_expression member._object builder in - if is_spread then raise (Invalid_argument "Unhandled spread in member call") else (); - let arg_regs, arg_inst = proc_arg_list call_exp.arguments builder in - let result_var, inst = build_call_method sub_exp_temp arg_regs id.name builder in - (result_var, sub_exp_inst @ arg_inst @ [inst]) - | _ -> - let callee_reg, callee_inst = proc_expression call_exp.callee builder in - let arg_regs, arg_inst = proc_arg_list call_exp.arguments builder in - let result_reg, inst = if is_spread - then - build_call_with_spread callee_reg arg_regs is_spread_list builder - else - build_call callee_reg arg_regs builder in - (result_reg, callee_inst @ arg_inst @ [inst])) - (* Otherwise, run the callee sub expression as normal*) - | _ -> let callee_reg, callee_inst = proc_expression call_exp.callee builder in - let arg_regs, arg_inst = proc_arg_list call_exp.arguments builder in - let result_reg, inst = if is_spread - then - build_call_with_spread callee_reg arg_regs is_spread_list builder - else - build_call callee_reg arg_regs builder in - (result_reg, callee_inst @ arg_inst @ [inst]) - -and proc_array_elem (elem: ('M, 'T) Flow_ast.Expression.Array.element) (builder: builder) = - match elem with - Expression e -> - let temp, inst = proc_expression e builder in - false, (temp, inst) - | Spread spread -> - let _, unwrapped = spread in - let temp, inst = proc_expression unwrapped.argument builder in - true, (temp, inst) - | Hole h -> - (* Fuzzilli doesn't support array holes, so load undefined instead *) - let result_var, inst = build_load_undefined builder in - false, (result_var, [inst]) - -and proc_create_array (exp: ('M, 'T) Flow_ast.Expression.Array.t) (builder: builder) = - let temp_func a = proc_array_elem a builder in - let is_spread_list, temp_list = List.split (List.map temp_func exp.elements) in - let arg_regs, arg_inst = List.split temp_list in - let flat_inst = List.flatten arg_inst in - let is_spread = List.fold_left (||) false is_spread_list in - let result_var, create_array_inst = if is_spread - then - build_create_array_with_spread arg_regs is_spread_list builder - else - build_create_array arg_regs builder - in - (result_var, flat_inst @ [create_array_inst]) - -and proc_create_object_property (prop_val: ('M, 'T) Flow_ast.Expression.Object.property) builder = - match prop_val with - Property (_, prop) -> - let temp_reg, prop_name_key, inst = match prop with - Init init_val -> - let temp, exp_inst = proc_expression init_val.value builder in - temp, init_val.key, exp_inst - | Set func -> - let _, act_func = func.value in - let temp, inst = proc_func act_func builder false in - temp, func.key, inst - | Get func -> - let (_, act_func) = func.value in - let temp, inst = proc_func act_func builder false in - temp, func.key, inst - | Method func -> - let (_, act_func) = func.value in - let temp, inst = proc_func act_func builder false in - temp, func.key, inst in - let prop_name : string = match prop_name_key with - Literal (_, l) -> l.raw - | Identifier (_, i) -> i.name - | PrivateName (_, p) -> let (_, i) = p.id in - i.name - | Computed _ -> raise (Invalid_argument "Unhandled Object key type Computed Key in object creation") in - (temp_reg, [prop_name]), inst - | SpreadProperty (_, spreadProp) -> - let temp_reg, exp_inst = proc_expression spreadProp.argument builder in - (temp_reg, []), exp_inst - -and proc_create_object (exp : ('M, 'T) Flow_ast.Expression.Object.t) (builder: builder) = - let props = exp.properties in - let temp_func a = proc_create_object_property a builder in - let obj_temp_tuple, create_obj_inst = List.split (List.map temp_func props) in - let obj_temp_list, obj_key_list_unflattened = List.split obj_temp_tuple in - let obj_key_list_flat = List.flatten obj_key_list_unflattened in - let flat_inst = List.flatten create_obj_inst in - let result_var, create_obj_inst = if List.length obj_key_list_flat == List.length obj_temp_list then - build_create_object obj_key_list_flat obj_temp_list builder - else - build_create_object_with_spread obj_key_list_flat obj_temp_list builder - in - (result_var, flat_inst @ [create_obj_inst]) - -and proc_exp_member (memb_exp: ('M, 'T) Flow_ast.Expression.Member.t) (builder: builder) = - let (sub_exp_temp, sub_exp_inst) = proc_expression memb_exp._object builder in - let return_temp, insts = match memb_exp.property with - PropertyIdentifier (_, i) -> - let result_var, load_prop_inst = build_load_prop sub_exp_temp i.name builder in - (result_var, [load_prop_inst]) - | PropertyPrivateName (_, p) -> - let (_, i) = p.id in - let result_var, load_prop_inst = build_load_prop sub_exp_temp i.name builder in - (result_var, [load_prop_inst]) - | PropertyExpression pe -> - let (_, unwrapped) = pe in - let opt_index = match unwrapped with - Flow_ast.Expression.Literal l -> - (match l.value with - Number n -> - if Float.is_integer n then Some (Float.to_int n) else None - | _ -> None) - | _ -> None in - match opt_index with - Some n -> (* Do a load element with the number*) - let result_var, load_element_inst = build_load_element sub_exp_temp n builder in - result_var, [load_element_inst] - | _ -> - (* Do a loadComputed with the expression*) - (* TODO: Is this the right operation here? *) - let member_exp_temp, member_exp_inst = proc_expression pe builder in - let result_var, load_computed_prop_inst = build_load_computed_prop sub_exp_temp member_exp_temp builder in - (result_var, member_exp_inst @ [load_computed_prop_inst]) in - (return_temp, sub_exp_inst @ insts) - -and proc_exp_new (new_exp: ('M, 'T) Flow_ast.Expression.New.t) (builder: builder) = - let callee = new_exp.callee in - let (callee_reg, callee_inst) = proc_expression callee builder in - let _ : unit = match new_exp.targs with - None -> () - | Some a -> raise (Invalid_argument "Unhandled targs in call") in - let arguments = new_exp.arguments in - let (arg_regs, arg_inst) = match arguments with - None -> ([], []) - | Some act_args -> - (let is_spread = List.fold_left (||) false ( arg_list_get_spread_list act_args ) in - let temp, insts = proc_arg_list act_args builder in - if is_spread then raise (Invalid_argument "Unhandled spread in new") - else temp, insts) - in - let result_var, create_obj_inst = build_new_object callee_reg arg_regs builder in - (result_var, callee_inst @ arg_inst @ [create_obj_inst]) - -and proc_exp_this this_exp builder = - let (result_var, inst) = build_load_builtin "this" builder in - result_var, [inst] - -and proc_exp_update (update_exp: (Loc.t, Loc.t) Flow_ast.Expression.Update.t) (builder: builder) = - let (sub_exp_temp, sub_exp_inst) = proc_expression update_exp.argument builder in - let update_op : unary_op = match update_exp.operator with - Increment -> if update_exp.prefix then PreInc else PostInc - | Decrement -> if update_exp.prefix then PreDec else PostDec in - let result_var, update_inst = build_unary_op sub_exp_temp update_op builder in - result_var, sub_exp_inst @ [update_inst] - -and proc_exp_yield (yield_exp: (Loc.t, Loc.t) Flow_ast.Expression.Yield.t) (builder: builder) = - let sub_exp_temp, sub_exp_insts = match yield_exp.argument with - | Some exp -> proc_expression exp builder - | _ -> raise (Invalid_argument "Unhandled yield without argument") in - let yield_inst = if yield_exp.delegate - then - build_yield_each_op sub_exp_temp builder - else - build_yield_op sub_exp_temp builder - in - sub_exp_temp, sub_exp_insts @ [yield_inst] - -(* Ternary expressions are not handled by Fuzzilli, so convert them to an if-else *) -and proc_exp_conditional (cond_exp: (Loc.t, Loc.t) Flow_ast.Expression.Conditional.t) (builder: builder) = - let result_temp, zero_temp_inst = build_load_integer 0L builder in - let (test_temp, test_inst) = proc_expression cond_exp.test builder in - let begin_if_inst = build_begin_if test_temp builder in - let consequent_temp, consequest_inst = proc_expression cond_exp.consequent builder in - let consequent_reassign_inst = build_reassign_op result_temp consequent_temp builder in - let begin_else_inst = build_begin_else builder in - let alternative_temp, alternative_inst = proc_expression cond_exp.alternate builder in - let alternative_reassign_inst = build_reassign_op result_temp alternative_temp builder in - let end_if_inst = build_end_if builder in - (result_temp, [zero_temp_inst] @ test_inst @ [begin_if_inst] @ consequest_inst @ [consequent_reassign_inst] @ [begin_else_inst] @ - alternative_inst @ [alternative_reassign_inst; end_if_inst]) - -and proc_class_method class_proto_temp builder (m: (Loc.t, Loc.t) Flow_ast.Class.Method.t) = - let _, unwrapped_method = m in - let key = unwrapped_method.key in - let method_name = match key with - Literal (_, l) -> l.raw - | Identifier (_, i) -> i.name - | PrivateName (_, p) -> let (_, i) = p.id in - i.name - | Computed _ -> raise (Invalid_argument "Unhandled method name in class creation") in - let _, func = unwrapped_method.value in - let method_temp, method_inst = proc_func func builder false in - (* TODO: Double check if this is the right operation *) - let load_propotype_inst = build_store_prop class_proto_temp method_temp method_name builder in - method_inst @ [load_propotype_inst] - -and proc_expression (exp: ('M, 'T) Flow_ast.Expression.t) (builder: builder) = - let (_, unwrapped_exp) = exp in - match unwrapped_exp with - | (Flow_ast.Expression.Array array_op) -> - proc_create_array array_op builder - | (Flow_ast.Expression.ArrowFunction arrow_func) -> - proc_func arrow_func builder true - | (Flow_ast.Expression.Assignment assign_op) -> - proc_exp_assignment assign_op builder - | (Flow_ast.Expression.Binary bin_op) -> - proc_exp_bin_op bin_op builder - | (Flow_ast.Expression.Call call_op) -> - proc_exp_call call_op builder - | (Flow_ast.Expression.Conditional cond_exp) -> - proc_exp_conditional cond_exp builder - | (Flow_ast.Expression.Function func_exp) -> - proc_func func_exp builder false - | (Flow_ast.Expression.Identifier id_val) -> - proc_exp_id id_val builder - | (Flow_ast.Expression.Import _) -> - (* Fuzzilli doesn't support imports, so effectively nop this out *) - let var, inst = build_load_undefined builder in - var, [inst] - | (Flow_ast.Expression.Literal lit_val) -> - proc_exp_literal lit_val builder - | (Flow_ast.Expression.Logical log_op) -> - proc_exp_logical log_op builder - | (Flow_ast.Expression.Member memb_exp) -> - proc_exp_member memb_exp builder - | (Flow_ast.Expression.New new_exp) -> - proc_exp_new new_exp builder - | (Flow_ast.Expression.Object create_obj_op) -> - proc_create_object create_obj_op builder - | (Flow_ast.Expression.This this_exp) -> - proc_exp_this this_exp builder - | (Flow_ast.Expression.Unary u_val) -> - proc_exp_unary u_val builder - | (Flow_ast.Expression.Update update_exp) -> - proc_exp_update update_exp builder - | (Flow_ast.Expression.Yield yield_exp) -> - proc_exp_yield yield_exp builder - | x -> raise (Invalid_argument ("Unhandled expression type " ^ (Util.trim_flow_ast_string (Util.print_expression exp)))) - -(* Process a single actual declaration *) -and proc_var_declaration_actual (var_name: string) (init: (Loc.t, Loc.t) Flow_ast.Expression.t option) (kind: Flow_ast.Statement.VariableDeclaration.kind) (builder : builder) = - let temp_var_num, new_insts = match init with - None -> - (* Handle a declaration without a definition *) - (match kind with - Flow_ast.Statement.VariableDeclaration.Var -> - let undef_temp, undef_inst = build_load_undefined builder in - let result_var, dup_inst = build_dup_op undef_temp builder in - add_new_var_identifier var_name result_var builder; - result_var, [undef_inst; dup_inst] - | Flow_ast.Statement.VariableDeclaration.Let -> - let undef_temp, undef_inst = build_load_undefined builder in - add_new_var_identifier var_name undef_temp builder; - undef_temp, [undef_inst] - | _ -> raise (Invalid_argument "Empty const declaration")) - | Some exp -> proc_expression exp builder in - let reassign_inst = (match kind with - Flow_ast.Statement.VariableDeclaration.Var -> - let is_hoisted = is_hoisted_var var_name builder in - if is_hoisted then - let hoisted_temp = lookup_var_name builder var_name in - match hoisted_temp with - NotFound -> raise (Invalid_argument "Unfound hoisted temp") - | InScope temp -> - let inst = build_reassign_op temp temp_var_num builder in - [inst] - else - (add_new_var_identifier var_name temp_var_num builder; - []) - | _ -> - add_new_var_identifier var_name temp_var_num builder; - []) - in - new_insts @ reassign_inst - -and proc_handle_single_var_declaration (dec : (Loc.t, Loc.t) Flow_ast.Statement.VariableDeclaration.Declarator.t') (kind: Flow_ast.Statement.VariableDeclaration.kind) (builder : builder) = - let foo = match dec.id, dec.init with - (_, (Flow_ast.Pattern.Identifier id)), exp -> - let (_, act_name) = id.name in - proc_var_declaration_actual act_name.name exp kind builder - | (_, (Flow_ast.Pattern.Array arr)), (Some (_, Flow_ast.Expression.Array exp)) -> - let get_name (a: ('M, 'T) Flow_ast.Pattern.Array.element) = - match a with - Element (_, e) -> - (match e.argument with - (_, (Flow_ast.Pattern.Identifier x)) -> - let var_id = x.name in - let (_, act_name) = var_id in - act_name.name - | _ -> raise (Invalid_argument "Improper args in variable declaration")) - | _ -> raise (Invalid_argument "Improper args in variable declaration") in - let id_elems = List.map get_name arr.elements in - let get_elem (e: (Loc.t, Loc.t) Flow_ast.Expression.Array.element) = - match e with - Expression exp -> exp - | _ -> raise (Invalid_argument "Improper args in variable declaration") in - let elems = List.map get_elem exp.elements in - let process id elem = proc_var_declaration_actual id (Some elem) kind builder in - List.map2 process id_elems elems |> List.flatten - | _, _ -> raise (Invalid_argument "Improper args in variable declaration") in - - foo - -(* Process a single variable declaration *) -and proc_var_dec_declarators (decs : (Loc.t, Loc.t) Flow_ast.Statement.VariableDeclaration.Declarator.t list) (kind: Flow_ast.Statement.VariableDeclaration.kind) (builder : builder) = - match decs with - [] -> [] - | (_, declarator) :: tl -> - proc_handle_single_var_declaration declarator kind builder @ (proc_var_dec_declarators tl kind builder) - -(* Processes a variable declaration statement, which can be made up of multiple vars *) -and proc_var_decl_statement (var_decl: (Loc.t, Loc.t) Flow_ast.Statement.VariableDeclaration.t) (builder: builder) = - let decs = var_decl.declarations in - let kind = var_decl.kind in - proc_var_dec_declarators decs kind builder - -and proc_if_statement (if_statement: (Loc.t, Loc.t) Flow_ast.Statement.If.t) (builder: builder) = - let test = if_statement.test in - let (test_temp_val, test_inst) = proc_expression test builder in - - let begin_if_inst = build_begin_if test_temp_val builder in - - push_local_scope builder; - let consequent_statements = proc_single_statement if_statement.consequent builder in - pop_local_scope builder; - - (* Fuzzilli requires an else for each if, due to how AbstractInterpreter works *) - let begin_else_inst = build_begin_else builder in - - push_local_scope builder; - let fin_statement = match if_statement.alternate with - None -> [] - | Some (_, alt) -> - let alt_inst = proc_single_statement alt.body builder in - alt_inst in - pop_local_scope builder; - - let end_if_inst = build_end_if builder in - test_inst @ begin_if_inst :: consequent_statements @ [begin_else_inst] @ fin_statement @ [end_if_inst] - - -(* TODO: Improve this. Puts all expressions into a temp, and compares with 0. Could be better*) -and proc_while (while_statement: (Loc.t, Loc.t) Flow_ast.Statement.While.t) (builder: builder) = - (* Build initial check, put into temp*) - let test_exp_reg, test_exp_inst = proc_expression while_statement.test builder in - let pre_loop_inst = test_exp_inst in - - (* Build begin while *) - let zero_temp, zero_temp_inst = build_load_integer 0L builder in - let begin_while_inst = build_begin_while test_exp_reg zero_temp NotEqual builder in - let begin_loop_inst = zero_temp_inst :: [begin_while_inst] in - - push_local_scope builder; - (* Build body *) - let body_statement = proc_single_statement while_statement.body builder in - pop_local_scope builder; - - (* Reexecute comparison, and load into temp*) - let test_exp_reg_internal, test_exp_inst_internal = proc_expression while_statement.test builder in - let reassign_inst = build_reassign_op test_exp_reg test_exp_reg_internal builder in - let re_exec_test_exp = test_exp_inst_internal @ [reassign_inst] in - - let end_while_inst = build_end_while builder in - pre_loop_inst @ begin_loop_inst @ body_statement @ re_exec_test_exp @ [end_while_inst] - -and proc_do_while (do_while_statement: (Loc.t, Loc.t) Flow_ast.Statement.DoWhile.t) (builder: builder) = - (* Build initial check, put into temp*) - (* let test_exp_reg, test_exp_inst = proc_expression do_while_statement.test builder in *) - let zero_temp, zero_temp_inst = build_load_integer 0L builder in - let intermed, dup_inst = build_dup_op zero_temp builder in - - (* Build begin while *) - let begin_while_inst = build_begin_do_while intermed zero_temp NotEqual builder in - push_local_scope builder; - (* Build body *) - let body_statement = proc_single_statement do_while_statement.body builder in - pop_local_scope builder; - (* Execute comparison, and load into temp*) - let test_exp_reg_internal, test_exp_inst_internal = proc_expression do_while_statement.test builder in - let reassign_inst = build_reassign_op intermed test_exp_reg_internal builder in - let re_exec_test_exp = test_exp_inst_internal @ [reassign_inst] in - - let end_while_inst = build_end_do_while builder in - [zero_temp_inst; dup_inst; begin_while_inst] @ body_statement @ re_exec_test_exp @ [end_while_inst] - -and proc_try (try_statement: (Loc.t, Loc.t) Flow_ast.Statement.Try.t) (builder: builder) = - let try_inst = build_begin_try_op builder in - push_local_scope builder; - let (_, try_block) = try_statement.block in - let block_inst = proc_statements try_block.body builder in - let catch_inst, catch_body_inst = match try_statement.handler with - None -> raise (Invalid_argument "Empty catch") - | Some (_, catch_clause) -> - let temp_name = match catch_clause.param with - | Some (_, (Flow_ast.Pattern.Identifier var_identifier)) -> - let (_, act_name) = var_identifier.name in - act_name.name - | _ -> raise (Invalid_argument "Unsupported catch type") - in - let (_, catch_cause_block) = catch_clause.body in - let catch_body_inst = proc_statements catch_cause_block.body builder in - let catch_inst = build_begin_catch_op temp_name builder in - (catch_inst, catch_body_inst) - in - let finalizer_inst = match try_statement.finalizer with - None -> [] - | Some (_, fin_block) -> proc_statements fin_block.body builder in - pop_local_scope builder; - let end_try_catch_inst = build_end_try_catch_op builder in - [try_inst] @ block_inst @ [catch_inst] @ catch_body_inst @ [end_try_catch_inst] @ finalizer_inst - -and proc_func (func: (Loc.t, Loc.t) Flow_ast.Function.t) (builder : builder) (is_arrow: bool) = - (* Get func name*) - let func_name_opt = match func.id with - None -> None - | Some (_, id) -> - Some id.name - in - - (* Unwraps a flow_ast paramter to a string identifier *) - let param_to_id (input: ('M, 'T) Flow_ast.Function.Param.t) = - let (_, unwrapped_input) = input in - let pattern = unwrapped_input.argument in - let (_, act_name) = match pattern with - (_, (Flow_ast.Pattern.Identifier x)) -> x.name - | _ -> raise (Invalid_argument "Didn't get an Identifier when expected in function declaration") in - act_name.name in - - (* Process function parameters*) - let (_, unwrapped_param) = func.params in - let param_ids = List.map param_to_id unwrapped_param.params in - - let rest_arg_name_opt = match unwrapped_param.rest with - None -> None - | Some (_, rest_id) -> - let act_id = rest_id.argument in - let (_, id_string) = match act_id with - (_, (Flow_ast.Pattern.Identifier x)) -> x.name - | _ -> raise (Invalid_argument "Unhandled rest temp") in - Some id_string.name - in - let func_temp = get_new_intermed_temp builder in - (match func_name_opt with - Some name -> - if is_hoisted_var name builder then - () - else - add_new_var_identifier name func_temp builder; - | _ -> ()); - push_local_scope builder; - let func_temp, begin_func_inst, end_func_inst = build_func_ops func_temp param_ids rest_arg_name_opt is_arrow func.async func.generator builder in - (* Process func body*) - let func_inst = match func.body with - BodyBlock body_block -> - let _, state_block = body_block in - let hoisted_statements = handle_varHoist state_block.body builder in - hoisted_statements @ proc_statements state_block.body builder - | BodyExpression body_exp -> - let _, inst = proc_expression body_exp builder in - inst - in - pop_local_scope builder; - - let reassign_inst = (match func_name_opt with - Some name -> - if is_hoisted_var name builder then - match (lookup_var_name builder name) with - NotFound -> raise (Invalid_argument "Hoisted func not found") - | InScope x -> [build_reassign_op x func_temp builder] - else - [] - | _ -> []) in - func_temp, [begin_func_inst] @ func_inst @ [end_func_inst] @ reassign_inst - -(* TODO: Fuzzilli return statements currently only allow variables. Add the ability to return without a value *) -and proc_return (ret_state: (Loc.t, Loc.t) Flow_ast.Statement.Return.t) (builder: builder) = - let return_var, return_insts = match ret_state.argument with - None -> - let temp, inst = build_load_undefined builder in - temp, [inst] - | Some exp -> - let temp_num, insts = proc_expression exp builder in - temp_num, insts - in - let return_inst = build_return_op return_var builder in - return_insts @ [return_inst] - -and proc_with (with_state: (Loc.t, Loc.t) Flow_ast.Statement.With.t) (builder: builder) = - let result_var, with_insts = proc_expression with_state._object builder in - let begin_with_inst = build_begin_with_op result_var builder in - let body_insts = proc_single_statement with_state.body builder in - let end_with_inst = build_end_with_op builder in - with_insts @ [begin_with_inst] @ body_insts @ [end_with_inst] - -and proc_throw (throw_state: (Loc.t, Loc.t) Flow_ast.Statement.Throw.t) (builder: builder) = - let temp, inst = proc_expression throw_state.argument builder in - let throw_inst = build_throw_op temp builder in - inst @ [throw_inst] - -and proc_break builder = - [build_break_op builder] - -(* Both for-in and for-of only allow creation of a new variable on the left side *) -and proc_for_in (for_in_state: (Loc.t, Loc.t) Flow_ast.Statement.ForIn.t) (builder: builder) = - let right_temp, right_inst = proc_expression for_in_state.right builder in - push_local_scope builder; - - let var_temp, end_of_loop_cleanup_inst = match for_in_state.left with - LeftDeclaration (_, d) -> - let decs = d.declarations in - (match decs with - [(_, declarator)] -> ( match declarator.id with - (_, (Flow_ast.Pattern.Identifier id)) -> - let (_, id_type) = id.name in - let left_temp = get_new_intermed_temp builder in - add_new_var_identifier id_type.name left_temp builder; - left_temp, [] - - | _ -> raise (Invalid_argument ("Improper declaration in for-in loop"))) - | _ -> raise (Invalid_argument "Improper declaration in for-in loop")) - | LeftPattern p -> (match p with - (_, (Flow_ast.Pattern.Identifier id)) -> - let (_, id_type) = id.name in - let lookup = lookup_var_name builder id_type.name in - (match lookup with - InScope x -> - (* Fuzzilli does not support reusing a variable in a for-in loop, so we have to make a new one and reassign it*) - let left_temp = get_new_intermed_temp builder in - add_new_var_identifier id_type.name left_temp builder; - let reassign_inst = build_reassign_op x left_temp builder in - left_temp, [reassign_inst] - | NotFound -> - let left_temp = get_new_intermed_temp builder in - add_new_var_identifier id_type.name left_temp builder; - left_temp, [] ) - | _ -> raise (Invalid_argument ("Inproper left pattern in for-in loop"))) in - - let _, start_for_in_inst = build_begin_for_in_op var_temp right_temp builder in - let body_inst = proc_single_statement for_in_state.body builder in - let end_for_in = build_end_for_in_op builder in - pop_local_scope builder; - right_inst @ [start_for_in_inst] @ body_inst @ end_of_loop_cleanup_inst @ [end_for_in]; - -and proc_for_of (for_of_state: (Loc.t, Loc.t) Flow_ast.Statement.ForOf.t) (builder: builder) = - let right_temp, right_inst = proc_expression for_of_state.right builder in - push_local_scope builder; - let var_id = match for_of_state.left with - LeftDeclaration (_, d) -> - let decs = d.declarations in - (match decs with - [(_, declarator)] -> ( match declarator.id with - (_, (Flow_ast.Pattern.Identifier x)) -> x - | _ -> raise (Invalid_argument ("Improper declaration in for-of loop"))) - | _ -> raise (Invalid_argument "Improper declaration in for-of loop")) - | LeftPattern p -> (match p with - (* TODO: Fuzzilli does not support reusing a variable in a for-of loop *) - (_, (Flow_ast.Pattern.Identifier id)) -> id - | _ -> raise (Invalid_argument ("Inproper left pattern in for-of loop"))) in - let (_, act_name) = var_id.name in - let left_temp, start_for_of_inst = build_begin_for_of_op right_temp builder in - add_new_var_identifier act_name.name left_temp builder; - - let body_inst = proc_single_statement for_of_state.body builder in - let end_for_of_inst = build_end_for_of_op builder in - right_inst @ [start_for_of_inst] @ body_inst @ [end_for_of_inst]; - -(* Fuzzilli For loops in Fuzzilli only *) -and proc_for (for_state: (Loc.t, Loc.t) Flow_ast.Statement.For.t) (builder: builder) = - let init_inst = match for_state.init with - None -> [] - | Some (InitDeclaration (_, decl)) -> proc_var_decl_statement decl builder - | Some (InitExpression exp) -> - let (_, exp_insts) = proc_expression exp builder in - exp_insts - in - (* Variables used in the condition need to be declared outside the while loop*) - let test_exp_reg, test_exp_inst = match for_state.test with - Some exp -> proc_expression exp builder - | None -> raise (Invalid_argument "Unhandled empty for-loop test") in - let pre_loop_inst = test_exp_inst in - push_local_scope builder; - - (*start while loop*) - let zero_temp, zero_temp_inst = build_load_integer 0L builder in - let begin_while_inst = build_begin_while test_exp_reg zero_temp NotEqual builder in - let begin_loop_inst = zero_temp_inst :: [begin_while_inst] in - - (*Body instructions*) - let body_insts = proc_single_statement for_state.body builder in - - (* Update*) - let update_insts = match for_state.update with - None -> [] - | Some exp -> - let (_, exp_insts) = proc_expression exp builder - in exp_insts in - - (* Redo the check*) - let test_exp_reg_internal, test_exp_inst_internal = match for_state.test with - Some exp -> proc_expression exp builder - | None -> raise (Invalid_argument "Unhandled empty for-loop test") in - let reassign_inst = build_reassign_op test_exp_reg test_exp_reg_internal builder in - let re_exec_test_exp = test_exp_inst_internal @ [reassign_inst] in - - (* End while*) - let end_while_inst = build_end_while builder in - pop_local_scope builder; - init_inst @ pre_loop_inst @ begin_loop_inst @ body_insts @ update_insts @ re_exec_test_exp @ [end_while_inst] - -and proc_continue builder = - [build_continue builder] - -and proc_single_statement (statement: (Loc.t, Loc.t) Flow_ast.Statement.t) builder = - match statement with - (_, Flow_ast.Statement.Block state_block) -> proc_statements state_block.body builder - | (_, Flow_ast.Statement.Break _) -> proc_break builder - | (_, Flow_ast.Statement.Continue state_continue) -> proc_continue builder - | (_, Flow_ast.Statement.DoWhile state_do_while) -> proc_do_while state_do_while builder - | (_, Flow_ast.Statement.Empty _) -> [] - | (_, Flow_ast.Statement.Expression state_exp) -> - let (_, inst) = proc_expression state_exp.expression builder in - inst - | (_, Flow_ast.Statement.For state_for) -> proc_for state_for builder - | (_, Flow_ast.Statement.ForIn state_foin) -> proc_for_in state_foin builder - | (_, Flow_ast.Statement.ForOf state_forof) -> proc_for_of state_forof builder - | (_, Flow_ast.Statement.FunctionDeclaration func_def) -> - let (_, res) = proc_func func_def builder false in - res - | (_, Flow_ast.Statement.If state_if) -> proc_if_statement state_if builder - (* Fuzzilli doesn't support imports *) - | (_, Flow_ast.Statement.ImportDeclaration _) -> [] - | (_, Flow_ast.Statement.Return state_return) -> proc_return state_return builder - | (_, Flow_ast.Statement.Throw state_throw) -> proc_throw state_throw builder - | (_, Flow_ast.Statement.Try state_try) -> proc_try state_try builder - | (_ , VariableDeclaration decl) -> proc_var_decl_statement decl builder - | (_, Flow_ast.Statement.While state_while) -> proc_while state_while builder - | (_, Flow_ast.Statement.With state_with) -> proc_with state_with builder - | _ as s -> raise (Invalid_argument (Printf.sprintf "Unhandled statement type %s" (Util.trim_flow_ast_string (Util.print_statement s)))) - -and proc_statements (statements: (Loc.t, Loc.t) Flow_ast.Statement.t list) (var_builder: builder) = - match statements with - [] -> [] - | hd :: tl -> - let new_statement = proc_single_statement hd var_builder in - new_statement @ proc_statements tl var_builder - -let flow_ast_to_inst_list (prog: (Loc.t, Loc.t) Flow_ast.Program.t) emit_builtins include_v8_natives use_placeholder = - let init_var_builder = init_builder emit_builtins include_v8_natives use_placeholder in - let (_, prog_t) = prog in - let hoisted_funcs = handle_varHoist prog_t.statements init_var_builder in - let proced_statements = hoisted_funcs @ proc_statements prog_t.statements init_var_builder in - let proced_statements_converted = List.map inst_to_prog_inst proced_statements in - proced_statements_converted diff --git a/Compiler/src/translate.mli b/Compiler/src/translate.mli deleted file mode 100644 index 04b72eb2..00000000 --- a/Compiler/src/translate.mli +++ /dev/null @@ -1,2 +0,0 @@ -(* Converts a Flow AST program to a program taken as input for protobuf generation*) -val flow_ast_to_inst_list : (Loc.t, Loc.t) Flow_ast.Program.t -> bool -> bool -> bool -> Program_types.instruction list \ No newline at end of file diff --git a/Compiler/src/util.ml b/Compiler/src/util.ml deleted file mode 100644 index 19d923d1..00000000 --- a/Compiler/src/util.ml +++ /dev/null @@ -1,182 +0,0 @@ - -let remove_percent input = - Str.global_replace (Str.regexp_string "%") "" input - -let encode_newline input = - Str.global_replace (Str.regexp_string "\n") "\\n" input - -(* Only bother filtering the ones we care about - TODO: Optimize this list*) -let chrome_builtins = [ - "%PrepareFunctionForOptimization"; - "%OptimizeFunctionOnNextCall"; - "%NeverOptimizeFunction"; - "%DeoptimizeFunction"; - "%DeoptimizeNow"; - "%OptimizeOsr"; - "%RemoveArrayHoles"; - "%CompileLazy"; - "%CompileForOnStackReplacement"; - "%OptimizeObjectForAddingMultipleProperties"; - "%CompileOptimized_Concurrent"; - "%CompileOptimized_NotConcurrent"; -] - - -let modify_chrome_builtins s = - let proc whole part = Str.global_replace (Str.regexp_string part) (remove_percent part) whole in - List.fold_left proc s chrome_builtins - -let string_to_flow_ast str = - let processed = modify_chrome_builtins str in - Parser_flow.program processed - -let convert_comp_op (op: Flow_ast.Expression.Binary.operator) = - match op with - Equal -> Operations_types.{op = Operations_types.Equal} - | NotEqual -> Operations_types.{op = Operations_types.Not_equal} - | StrictEqual -> Operations_types.{op = Operations_types.Strict_equal} - | StrictNotEqual -> Operations_types.{op = Operations_types.Strict_not_equal} - | LessThan -> Operations_types.{op = Operations_types.Less_than} - | LessThanEqual -> Operations_types.{op = Operations_types.Less_than_or_equal} - | GreaterThan -> Operations_types.{op = Operations_types.Greater_than} - | GreaterThanEqual -> Operations_types.{op = Operations_types.Greater_than_or_equal} - | _ -> raise (Invalid_argument "Tried to convert invalid comp op") - -let is_compare_op (op: Flow_ast.Expression.Binary.operator) = - match op with - Equal | NotEqual | StrictEqual | StrictNotEqual | LessThan | LessThanEqual | GreaterThan | GreaterThanEqual -> true - | _ -> false - -let paramaterized_type_placeholder a b = () - -let print_unary_expression s = - Flow_ast.Expression.Unary.show paramaterized_type_placeholder paramaterized_type_placeholder s ^ "\n" - -let print_unary_operator v = - match v with - Flow_ast.Expression.Unary.Minus -> "Minus" - | Flow_ast.Expression.Unary.Plus -> "Plus" - | Flow_ast.Expression.Unary.Not -> "Not" - | Flow_ast.Expression.Unary.BitNot -> "BitNot" - | Flow_ast.Expression.Unary.Typeof -> "Typeof" - | Flow_ast.Expression.Unary.Void -> "Void" - | Flow_ast.Expression.Unary.Delete -> "Delete" - | Flow_ast.Expression.Unary.Await -> "Await" - -let print_binary_operator s = - Flow_ast.Expression.Binary.show_operator s ^ "\n" - -let print_logical_operator s = - Flow_ast.Expression.Logical.show_operator s ^ "\n" - -let print_statement s = - Flow_ast.Statement.show paramaterized_type_placeholder paramaterized_type_placeholder s ^ "\n" - -let print_expression s = - Flow_ast.Expression.show paramaterized_type_placeholder paramaterized_type_placeholder s ^ "\n" - -let print_literal s = - Flow_ast.Literal.show paramaterized_type_placeholder s ^ "\n" - -(* Gets just the type from a Flow_ast.__TYPE___.show statement. For use in building information on which operations the compiler doesn't handle yet*) -let trim_flow_ast_string s = - let split_string = Core.String.split_lines s in - let res = Core.List.nth split_string 1 in - match res with - None -> s - | Some a -> a - -let write_proto_obj_to_file proto_obj file = - let encoder = Pbrt.Encoder.create () in - Program_pb.encode_program proto_obj encoder; - let oc = Core.Out_channel.create file in - Core.Out_channel.output_bytes oc (Pbrt.Encoder.to_bytes encoder); - Core.Out_channel.close oc - -let rec print_statement_list l = - match l with - | [] -> "" - | x :: xs -> print_statement x ^ print_statement_list xs - -let regex_flag_str_to_int s = - let open Core in - if String.contains s 'i' then (Int32.shift_left 1l 0) else 0l - |> Int32.(lor) (if String.contains s 'g' then (Int32.shift_left 1l 1) else 0l) - |> Int32.(lor) (if String.contains s 'm' then (Int32.shift_left 1l 2) else 0l) - |> Int32.(lor) (if String.contains s 's' then (Int32.shift_left 1l 3) else 0l) - |> Int32.(lor) (if String.contains s 'u' then (Int32.shift_left 1l 4) else 0l) - |> Int32.(lor) (if String.contains s 'y' then (Int32.shift_left 1l 5) else 0l) - -let gen_uuid = - let rand_chr _ = Char.chr (Random.int 256) in - Bytes.init 16 rand_chr - -let inst_list_to_prog inst_list = - Program_types.{ - uuid = gen_uuid; - code = inst_list; - types = []; - type_collection_status = Program_types.Notattempted; - comments = []; - parent = None; - } - -let builtins = ["Reflect"; -"Promise"; -"Infinity"; -"isNaN"; -"Int16Array"; -"Symbol"; -"Object"; -"Int32Array"; -"Map"; -"WeakMap"; -"isFinite"; -"parseInt"; -"Math"; -"Int8Array"; -"Set"; -"Function"; -"RegExp"; -"Uint32Array"; -"JSON"; -"String"; -"parseFloat"; -"WeakSet"; -"Uint8Array"; -"BigInt"; -"undefined"; -"NaN"; -"Number"; -"Proxy"; -"ArrayBuffer"; -"gc"; -"Float32Array"; -"eval"; -"Float64Array"; -"DataView"; -"Uint16Array"; -"Array"; -"this"; -"arguments"; -"Uint8ClampedArray"; -"Boolean"; -] - -let chrome_natives = [ - "PrepareFunctionForOptimization"; - "OptimizeFunctionOnNextCall"; - "NeverOptimizeFunction"; - "DeoptimizeFunction"; - "DeoptimizeNow"; - "OptimizeOsr"; -] - -let is_supported_builtin b is_chrome = - let norm = List.mem b builtins in - let in_chrome = List.mem b chrome_natives in - if is_chrome then - norm || in_chrome - else - norm \ No newline at end of file diff --git a/Compiler/src/util.mli b/Compiler/src/util.mli deleted file mode 100644 index ae51d09b..00000000 --- a/Compiler/src/util.mli +++ /dev/null @@ -1,33 +0,0 @@ -val string_to_flow_ast : string -> (Loc.t, Loc.t) Flow_ast.Program.t * (Loc.t * Parse_error.t) list - -val encode_newline : string -> string - -val convert_comp_op : Flow_ast.Expression.Binary.operator -> Operations_types.compare - -val is_compare_op : Flow_ast.Expression.Binary.operator -> bool - -val print_statement : ('M, 'T) Flow_ast.Statement.t -> string - -val print_unary_expression : ('M, 'T) Flow_ast.Expression.Unary.t -> string - -val print_unary_operator : Flow_ast.Expression.Unary.operator -> string - -val print_binary_operator : Flow_ast.Expression.Binary.operator -> string - -val print_logical_operator : Flow_ast.Expression.Logical.operator -> string - -val print_expression : ('M, 'T) Flow_ast.Expression.t -> string - -val print_statement_list: (('M, 'T) Flow_ast.Statement.t) list -> string - -val print_literal: ('T) Flow_ast.Literal.t -> string - -val trim_flow_ast_string : string -> string - -val write_proto_obj_to_file : Program_types.program -> string -> unit - -val inst_list_to_prog : Program_types.instruction list -> Program_types.program - -val regex_flag_str_to_int : string -> int32 - -val is_supported_builtin : string -> bool -> bool \ No newline at end of file diff --git a/Compiler/supportedBuiltins.txt b/Compiler/supportedBuiltins.txt deleted file mode 100644 index e4f88c79..00000000 --- a/Compiler/supportedBuiltins.txt +++ /dev/null @@ -1,48 +0,0 @@ -Reflect -PrepareFunctionForOptimization -Promise -Infinity -isNaN -Int16Array -Symbol -Object -Int32Array -Map -WeakMap -isFinite -parseInt -Math -Int8Array -Set -Function -RegExp -OptimizeOsr -GetOptimizationStatus -Uint32Array -JSON -String -parseFloat -WeakSet -Uint8Array -BigInt -undefined -NaN -NeverOptimizeFunction -DeoptimizeNow -ToFastProperties -Number -Proxy -ArrayBuffer -gc -DeoptimizeFunction -OptimizeFunctionOnNextCall -Float32Array -eval -Float64Array -DataView -Uint16Array -Array -this -arguments -Uint8ClampedArray -Boolean \ No newline at end of file diff --git a/Compiler/test/array_assign.ml b/Compiler/test/array_assign.ml deleted file mode 100644 index eefc7ae9..00000000 --- a/Compiler/test/array_assign.ml +++ /dev/null @@ -1,25 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 12; -const v1 = [v0,v0,v0]; -const v2 = 10; -v1[v2 + 20] = 30;" - -let correct = - let builder = init_builder false false false in - let int12_temp, load_int_12 = build_load_integer 12L builder in - let array_temp, load_array = build_create_array [int12_temp; int12_temp; int12_temp] builder in - let int10_temp, load_int_10 = build_load_integer 10L builder in - let int20_temp, load_int_20 = build_load_integer 20L builder in - let add_res_temp, add_inst = build_binary_op int10_temp int20_temp Plus builder in - let int30_temp, load_int_30 = build_load_integer 30L builder in - let store_comp_inst = build_store_computed_prop array_temp add_res_temp int30_temp builder in - let res = [load_int_12; load_array; load_int_10; load_int_20; add_inst; load_int_30; store_comp_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "array_assign" correct prog \ No newline at end of file diff --git a/Compiler/test/array_assign_sugared.ml b/Compiler/test/array_assign_sugared.ml deleted file mode 100644 index e9a021cf..00000000 --- a/Compiler/test/array_assign_sugared.ml +++ /dev/null @@ -1,27 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 12; -const v1 = [v0,v0,v0]; -const v2 = 10; -v1[v2 + 20] += 30;" - -let correct = - let builder = init_builder false false false in - let int12_temp, load_int_12 = build_load_integer 12L builder in - let array_temp, load_array = build_create_array [int12_temp; int12_temp; int12_temp] builder in - let int10_temp, load_int_10 = build_load_integer 10L builder in - let int20_temp, load_int_20 = build_load_integer 20L builder in - let add_res_temp, add_inst = build_binary_op int10_temp int20_temp Plus builder in - let int30_temp, load_int_30 = build_load_integer 30L builder in - let comp_prop_temp, load_comp_prop_inst = build_load_computed_prop array_temp add_res_temp builder in - let add_res_temp2, add_inst2 = build_binary_op comp_prop_temp int30_temp Plus builder in - let store_comp_inst = build_store_computed_prop array_temp add_res_temp add_res_temp2 builder in - let res = [load_int_12; load_array; load_int_10; load_int_20; add_inst; load_int_30; load_comp_prop_inst; add_inst2; store_comp_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "array_assign_sugared" correct prog \ No newline at end of file diff --git a/Compiler/test/array_decl.ml b/Compiler/test/array_decl.ml deleted file mode 100644 index 43e2aab5..00000000 --- a/Compiler/test/array_decl.ml +++ /dev/null @@ -1,20 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"var [r, g, f] = [20, 15, 35]; -" - -let correct = - let builder = init_builder false false false in - let _, l0_inst = build_load_integer 20L builder in - let _, l1_inst = build_load_integer 15L builder in - let _, l2_inst = build_load_integer 35L builder in - let res = [l0_inst; l1_inst; l2_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "array_decl" correct prog - \ No newline at end of file diff --git a/Compiler/test/array_hole.ml b/Compiler/test/array_hole.ml deleted file mode 100644 index 59afe06b..00000000 --- a/Compiler/test/array_hole.ml +++ /dev/null @@ -1,18 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let a = [1,,1];" - -let correct = - let builder = init_builder false false false in - let int_temp, load_int = build_load_integer 1L builder in - let undef_temp, load_undef_inst = build_load_undefined builder in - let int_temp2, load_int_2 = build_load_integer 1L builder in - let _, create_array_inst = build_create_array [int_temp; undef_temp; int_temp2] builder in - let res = [load_int; load_undef_inst; load_int_2; create_array_inst] in - List.map inst_to_prog_inst res -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "array_hole" correct prog \ No newline at end of file diff --git a/Compiler/test/array_spread.ml b/Compiler/test/array_spread.ml deleted file mode 100644 index 5289bdd9..00000000 --- a/Compiler/test/array_spread.ml +++ /dev/null @@ -1,18 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 0; -const v1 = [v0,...v0,];" - -let correct = - let builder = init_builder false false false in - let int_temp, load_int = build_load_integer 0L builder in - let _, create_array_inst = build_create_array_with_spread [int_temp; int_temp] [false; true] builder in - let res = [load_int; create_array_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "array_spread" correct prog \ No newline at end of file diff --git a/Compiler/test/basic_break.ml b/Compiler/test/basic_break.ml deleted file mode 100644 index 3b2c6e5e..00000000 --- a/Compiler/test/basic_break.ml +++ /dev/null @@ -1,23 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder -let input = -"const v0 = 1; -while(v0){ - break; -}" - -let correct = - let builder = init_builder false false false in - let int_temp, load_int = build_load_integer 1L builder in - let int_temp0, load_int0 = build_load_integer 0L builder in - let begin_while_inst = build_begin_while int_temp int_temp0 NotEqual builder in - let break_inst = build_break_op builder in - let reassign_inst = build_reassign_op int_temp int_temp builder in - let end_while_inst = build_end_while builder in - let res = [load_int; load_int0; begin_while_inst; break_inst; reassign_inst; end_while_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "basic_break" correct prog \ No newline at end of file diff --git a/Compiler/test/basic_compare_test.ml b/Compiler/test/basic_compare_test.ml deleted file mode 100644 index cdc5625d..00000000 --- a/Compiler/test/basic_compare_test.ml +++ /dev/null @@ -1,30 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 1 == 1; -const v1 = 1 === 1; -const v2 = 2 >= 2; -const v3 = 7 < 9;" - -let correct = - let builder = init_builder false false false in - let int_1, load_1 = build_load_integer 1L builder in - let int_1_2, load_1_2 = build_load_integer 1L builder in - let _, equal_inst = build_compare_op int_1 int_1_2 Equal builder in - let int_1_3, load_1_3 = build_load_integer 1L builder in - let int_1_4, load_1_4 = build_load_integer 1L builder in - let _, strict_equal_inst = build_compare_op int_1_3 int_1_4 StrictEqual builder in - let int_2_0, load_2_0 = build_load_integer 2L builder in - let int_2_1, load_2_1 = build_load_integer 2L builder in - let _, greater_eq_inst = build_compare_op int_2_0 int_2_1 GreaterThanEqual builder in - let int_7, load_7 = build_load_integer 7L builder in - let int_9, load_9 = build_load_integer 9L builder in - let _, less_than_inst = build_compare_op int_7 int_9 LessThan builder in - let res = [load_1; load_1_2; equal_inst; load_1_3; load_1_4; strict_equal_inst; load_2_0; load_2_1; greater_eq_inst; load_7; load_9; less_than_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "basic_compare_test" correct prog \ No newline at end of file diff --git a/Compiler/test/basic_continue.ml b/Compiler/test/basic_continue.ml deleted file mode 100644 index 520354eb..00000000 --- a/Compiler/test/basic_continue.ml +++ /dev/null @@ -1,25 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"while(1){ - continue; -} -" - -let correct = - let builder = init_builder false false false in - let int_temp_1, load_int1 = build_load_integer 1L builder in - let int_temp_0, load_int0 = build_load_integer 0L builder in - let begin_while = build_begin_while int_temp_1 int_temp_0 NotEqual builder in - let continue_inst = build_continue builder in - let int_temp_1_2, load_int2 = build_load_integer 1L builder in - let reassign_inst = build_reassign_op int_temp_1 int_temp_1_2 builder in - let end_while = build_end_while builder in - let res = [load_int1; load_int0; begin_while; continue_inst; load_int2; reassign_inst; end_while] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "basic_continue" correct prog \ No newline at end of file diff --git a/Compiler/test/basic_for.ml b/Compiler/test/basic_for.ml deleted file mode 100644 index e8e02309..00000000 --- a/Compiler/test/basic_for.ml +++ /dev/null @@ -1,32 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"for(let v0 = 2; v0 < 10; v0 = v0 + 1){ - let v2 = v0 + 12; -}" - -let correct = - let builder = init_builder false false false in - let int_2_temp, load_int2 = build_load_integer 2L builder in - let int_10_temp, load_int10 = build_load_integer 10L builder in - let compare_temp, first_compare_inst = build_compare_op int_2_temp int_10_temp LessThan builder in - let int_0_temp, load_int0 = build_load_integer 0L builder in - let begin_while = build_begin_while compare_temp int_0_temp NotEqual builder in - let int_12_temp, load_int12 = build_load_integer 12L builder in - let add_temp, add_inst = build_binary_op int_2_temp int_12_temp Plus builder in - let int_1_temp, load_int1 = build_load_integer 1L builder in - let add_temp2, add_inst2 = build_binary_op int_2_temp int_1_temp Plus builder in - let reassign_op = build_reassign_op int_2_temp add_temp2 builder in - let int_10_temp2, load_int102 = build_load_integer 10L builder in - let compare_temp2, second_compare_inst = build_compare_op int_2_temp int_10_temp2 LessThan builder in - let reassign_op2 = build_reassign_op compare_temp compare_temp2 builder in - let end_while = build_end_while builder in - let res = [load_int2; load_int10; first_compare_inst; load_int0; begin_while; load_int12; add_inst; load_int1; add_inst2; reassign_op; load_int102; second_compare_inst; reassign_op2; end_while] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "basic_for" correct prog - \ No newline at end of file diff --git a/Compiler/test/basic_func_call.ml b/Compiler/test/basic_func_call.ml deleted file mode 100644 index 643153bb..00000000 --- a/Compiler/test/basic_func_call.ml +++ /dev/null @@ -1,18 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = isNaN(0);" - -let correct = - let builder = init_builder false false false in - let builtin_temp, load_builtin = build_load_builtin "isNaN" builder in - let temp_0, load_int = build_load_integer 0L builder in - let _, call_inst = build_call builtin_temp [temp_0] builder in - let res = [load_builtin; load_int; call_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "basic_func_call" correct prog \ No newline at end of file diff --git a/Compiler/test/basic_func_ret.ml b/Compiler/test/basic_func_ret.ml deleted file mode 100644 index a78aebcb..00000000 --- a/Compiler/test/basic_func_ret.ml +++ /dev/null @@ -1,30 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"function v1(v2,v3) { - let v4 = v2 * v3; - return v4; -} -" - -let correct = - let builder = init_builder false false false in - let func_temp = get_new_intermed_temp builder in - let _, begin_func_inst, end_func_inst = build_func_ops func_temp ["v2"; "v3"] None false false false builder in - (* TODO: This needs to be updated along with the function builder interface *) - let v2_temp = match lookup_var_name builder "v2" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - let v3_temp = match lookup_var_name builder "v3" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - let bin_temp, bin_inst = build_binary_op v2_temp v3_temp Mult builder in - let ret_inst = build_return_op bin_temp builder in - let res = [begin_func_inst; bin_inst; ret_inst; end_func_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "basic_func_ret" correct prog \ No newline at end of file diff --git a/Compiler/test/basic_while.ml b/Compiler/test/basic_while.ml deleted file mode 100644 index 0666b4c6..00000000 --- a/Compiler/test/basic_while.ml +++ /dev/null @@ -1,30 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let v0 = 0; -const v1 = 20; -while(v0 <= v1){ - v0 += 1; -}" - -let correct = - let builder = init_builder false false false in - let int_0, load_int_0 = build_load_integer 0L builder in - let int_20, load_int_20 = build_load_integer 20L builder in - let compare_temp, compare_inst_0 = build_compare_op int_0 int_20 LessThanEqual builder in - let int_0_2, load_int_0_2 = build_load_integer 0L builder in - let begin_while = build_begin_while compare_temp int_0_2 NotEqual builder in - let int_1, load_int_1 = build_load_integer 1L builder in - let bin_temp, bin_op = build_binary_op int_0 int_1 Plus builder in - let reassign_op = build_reassign_op int_0 bin_temp builder in - let compare_temp2, compare_inst2 = build_compare_op int_0 int_20 LessThanEqual builder in - let reassign_op2 = build_reassign_op compare_temp compare_temp2 builder in - let end_while = build_end_while builder in - let res = [load_int_0; load_int_20; compare_inst_0; load_int_0_2; begin_while; load_int_1; bin_op; reassign_op; compare_inst2; reassign_op2; end_while] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "basic_while" correct prog \ No newline at end of file diff --git a/Compiler/test/binary_ops.ml b/Compiler/test/binary_ops.ml deleted file mode 100644 index edd8b88a..00000000 --- a/Compiler/test/binary_ops.ml +++ /dev/null @@ -1,52 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v1 = 1 * 2 + 2 / 3; -const v2 = 5 * 6 - 2; -const v3 = 9 ** 10; -const v4 = 11 << 12; -const v5 = 13 >> 14; -const v6 = 15 % 16; -const v7 = 17 >>> 2; -" - -let correct = - let builder = init_builder false false false in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let mul_temp, mul_op = build_binary_op int_1 int_2 Mult builder in - let int_2_2, load_int_2_2 = build_load_integer 2L builder in - let int_3, load_int_3 = build_load_integer 3L builder in - let dev_temp, div_op = build_binary_op int_2_2 int_3 Div builder in - let _, add_op = build_binary_op mul_temp dev_temp Plus builder in - let int_5, load_int_5 = build_load_integer 5L builder in - let int_6, load_int_6 = build_load_integer 6L builder in - let mul_temp_2, mul_op_2 = build_binary_op int_5 int_6 Mult builder in - let int_2_3, load_int_2_3 = build_load_integer 2L builder in - let _, sub_op = build_binary_op mul_temp_2 int_2_3 Minus builder in - let int_9, load_int_9 = build_load_integer 9L builder in - let int_10, load_int_10 = build_load_integer 10L builder in - let _, exp_op = build_binary_op int_9 int_10 Exp builder in - let int_11, load_int_11 = build_load_integer 11L builder in - let int_12, load_int_12 = build_load_integer 12L builder in - let _, lshift_op = build_binary_op int_11 int_12 LShift builder in - let int_13, load_int_13 = build_load_integer 13L builder in - let int_14, load_int_14 = build_load_integer 14L builder in - let _, right_op = build_binary_op int_13 int_14 RShift builder in - let int_15, load_int_15 = build_load_integer 15L builder in - let int_16, load_int_16 = build_load_integer 16L builder in - let _, mod_op = build_binary_op int_15 int_16 Mod builder in - let int_17, load_int_17 = build_load_integer 17L builder in - let int_2_4, load_int_2_4 = build_load_integer 2L builder in - let _, unshift_op = build_binary_op int_17 int_2_4 RShift3 builder in - let res = [load_int_1; load_int_2; mul_op; load_int_2_2; load_int_3; div_op; add_op; load_int_5; - load_int_6; mul_op_2; load_int_2_3; sub_op; load_int_9; load_int_10; exp_op; - load_int_11; load_int_12; lshift_op; load_int_13; load_int_14; right_op; - load_int_15; load_int_16; mod_op; load_int_17; load_int_2_4; unshift_op] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "binary_ops" correct prog \ No newline at end of file diff --git a/Compiler/test/bitwise_ops.ml b/Compiler/test/bitwise_ops.ml deleted file mode 100644 index 4c51e346..00000000 --- a/Compiler/test/bitwise_ops.ml +++ /dev/null @@ -1,23 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 1 | 2; -const v1 = 3 & 4; -" - -let correct = - let builder = init_builder false false false in - let temp_1, load_1_temp = build_load_integer 1L builder in - let temp_2, load_2_temp = build_load_integer 2L builder in - let _, or_inst = build_binary_op temp_1 temp_2 BitOr builder in - let temp_3, load_3_temp = build_load_integer 3L builder in - let temp_4, load_4_temp = build_load_integer 4L builder in - let _, and_inst = build_binary_op temp_3 temp_4 BitAnd builder in - let res = [load_1_temp; load_2_temp; or_inst; load_3_temp; load_4_temp; and_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "bitwise_ops" correct prog \ No newline at end of file diff --git a/Compiler/test/create_array.ml b/Compiler/test/create_array.ml deleted file mode 100644 index 888df95e..00000000 --- a/Compiler/test/create_array.ml +++ /dev/null @@ -1,21 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 15; -const v1 = 20; -const v2 = [v1,v0]; -" - -let correct = - let builder = init_builder false false false in - let int_15_temp, load_int_15 = build_load_integer 15L builder in - let int_20_temp, load_int_20 = build_load_integer 20L builder in - let _, create_array = build_create_array [int_20_temp; int_15_temp] builder in - let res = [load_int_15; load_int_20; create_array] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "create_array" correct prog \ No newline at end of file diff --git a/Compiler/test/del_test.ml b/Compiler/test/del_test.ml deleted file mode 100644 index 6954fa92..00000000 --- a/Compiler/test/del_test.ml +++ /dev/null @@ -1,27 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - - -let input = -"const v0 = 1337; -const v1 = [v0]; -delete v1[0]; -const v10 = \"function\"; -delete v10.length; -" - -let correct = - let builder = init_builder false false false in - let int1337, load_1337 = build_load_integer 1337L builder in - let arr_temp, build_array = build_create_array [int1337] builder in - let zero_temp, load_zero_temp = build_load_integer 0L builder in - let _, del_inst = build_delete_computed_prop arr_temp zero_temp builder in - let string_temp, load_string_temp = build_load_string "function" builder in - let _, del_inst2 = build_delete_prop string_temp "length" builder in - let res = [load_1337; build_array; load_zero_temp; del_inst; load_string_temp; del_inst2] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "del_test" correct prog \ No newline at end of file diff --git a/Compiler/test/do_while.ml b/Compiler/test/do_while.ml deleted file mode 100644 index 27b2f305..00000000 --- a/Compiler/test/do_while.ml +++ /dev/null @@ -1,32 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let v0 = 0; -do{ - v0 = v0 + 1; -}while(v0 < 10); -" - -let correct = - let builder = init_builder false false false in - - let int_0, load_int_0 = build_load_integer 0L builder in - let int_0_1, load_int_0_1 = build_load_integer 0L builder in - let dup_var, dup_inst = build_dup_op int_0_1 builder in - let do_while_inst = build_begin_do_while dup_var int_0_1 NotEqual builder in - let int_1, load_int_1 = build_load_integer 1L builder in - let add_temp, add_inst = build_binary_op int_0 int_1 Plus builder in - let reassign_inst = build_reassign_op int_0 add_temp builder in - let int_10, load_int_10 = build_load_integer 10L builder in - let compare_temp, compare_inst = build_compare_op int_0 int_10 LessThan builder in - let reassign_inst_2 = build_reassign_op dup_var compare_temp builder in - let end_do_while_inst = build_end_do_while builder in - let res = [load_int_0; load_int_0_1; dup_inst; do_while_inst; load_int_1; add_inst; reassign_inst; load_int_10; - compare_inst; reassign_inst_2; end_do_while_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "do_while" correct prog \ No newline at end of file diff --git a/Compiler/test/dune b/Compiler/test/dune deleted file mode 100644 index 16125535..00000000 --- a/Compiler/test/dune +++ /dev/null @@ -1,5 +0,0 @@ -(executable - (name test) - (public_name test) - (libraries alcotest compiler) - (preprocess (pps ppx_deriving.show))) \ No newline at end of file diff --git a/Compiler/test/empty_assignment_scope.ml b/Compiler/test/empty_assignment_scope.ml deleted file mode 100644 index f63f1edb..00000000 --- a/Compiler/test/empty_assignment_scope.ml +++ /dev/null @@ -1,34 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -" -var x; -while (x != 0) { - x = 1; -} -" - -let correct = - let builder = init_builder false false false in - let undef_temp, undef_inst = build_load_undefined builder in - let dup_temp, dup_inst = build_dup_op undef_temp builder in - let compare_target_temp, build_compare_target = build_load_integer 0L builder in - let compare_res_temp, build_compare = build_compare_op dup_temp compare_target_temp NotEqual builder in - let zero_temp, load_zero_temp = build_load_integer 0L builder in - let begin_while_inst = build_begin_while compare_res_temp zero_temp NotEqual builder in - let one_temp, load_one_temp = build_load_integer 1L builder in - let reassign_inst = build_reassign_op dup_temp one_temp builder in - let second_compare_target_temp, build_second_compare_target_inst = build_load_integer 0L builder in - let second_compare_temp, build_second_compare_inst = build_compare_op dup_temp second_compare_target_temp NotEqual builder in - let second_reassign_inst = build_reassign_op compare_res_temp second_compare_temp builder in - let end_while_inst = build_end_while builder in - let res = [undef_inst; dup_inst; build_compare_target; build_compare; load_zero_temp; begin_while_inst; load_one_temp; reassign_inst; - build_second_compare_target_inst; build_second_compare_inst; second_reassign_inst; end_while_inst ] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "empty_assignment_scope" correct prog - \ No newline at end of file diff --git a/Compiler/test/exp_statement.ml b/Compiler/test/exp_statement.ml deleted file mode 100644 index 6359f5c5..00000000 --- a/Compiler/test/exp_statement.ml +++ /dev/null @@ -1,24 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let v0 = 0; -const v1 = 5; -v0 = v1 + 1; -" - -let correct = - let builder = init_builder false false false in - let int_0, load_int_0 = build_load_integer 0L builder in - let int_5, load_int_5 = build_load_integer 5L builder in - let int_1, load_int_1 = build_load_integer 1L builder in - let bin_temp, bin_inst = build_binary_op int_5 int_1 Plus builder in - let reassign_inst = build_reassign_op int_0 bin_temp builder in - let res = [load_int_0; load_int_5; load_int_1; bin_inst; reassign_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "exp_statement" correct prog - \ No newline at end of file diff --git a/Compiler/test/for_in.ml b/Compiler/test/for_in.ml deleted file mode 100644 index e8a9adc1..00000000 --- a/Compiler/test/for_in.ml +++ /dev/null @@ -1,29 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - - -let input = -"const v0 = 12; -const v1 = [v0,v0,v0,v0,v0]; -for (const v2 in v1) { - let v3 = v2; - isNaN(v3); -}" - -let correct = - let builder = init_builder false false false in - let int_12, load_int_12 = build_load_integer 12L builder in - let arr_temp, create_arr_inst = build_create_array [int_12; int_12; int_12; int_12; int_12] builder in - let left_temp = get_new_intermed_temp builder in - let _, begin_for_in = build_begin_for_in_op left_temp arr_temp builder in - let builtin_temp, load_builtin = build_load_builtin "isNaN" builder in - let _, call_inst = build_call builtin_temp [left_temp] builder in - let end_for_in = build_end_for_in_op builder in - let res = [load_int_12; create_arr_inst; begin_for_in; load_builtin; call_inst; end_for_in] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "for_in_scoping" correct prog - \ No newline at end of file diff --git a/Compiler/test/for_in_scope2.ml b/Compiler/test/for_in_scope2.ml deleted file mode 100644 index 1e5ac729..00000000 --- a/Compiler/test/for_in_scope2.ml +++ /dev/null @@ -1,29 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"for (var x in x) { - function x() { - ; - } - let a = x(); -} -" - -let correct = - let builder = init_builder false false false in - let placeholder_temp, load_placeholder = build_load_builtin "placeholder" builder in - let temp = get_new_intermed_temp builder in - let _, begin_for_in = build_begin_for_in_op temp placeholder_temp builder in - let func_temp = get_new_intermed_temp builder in - let func_temp2, begin_func_inst, end_func_inst = build_func_ops func_temp [] None false false false builder in - let _, call_inst = build_call func_temp2 [] builder in - let end_for_in = build_end_for_in_op builder in - let res = [load_placeholder; begin_for_in; begin_func_inst; end_func_inst; call_inst; end_for_in] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "for_in_scope2" correct prog - \ No newline at end of file diff --git a/Compiler/test/for_in_scoping.ml b/Compiler/test/for_in_scoping.ml deleted file mode 100644 index 93174cd2..00000000 --- a/Compiler/test/for_in_scoping.ml +++ /dev/null @@ -1,29 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let i = \"ABC\" -for (i in [0]) { -} -let b = i + \"D\";" - -(* Note: Fuzzilli does not support using an existing var *) -let correct = - let builder = init_builder false false false in - let string_temp, load_string_inst = build_load_string "ABC" builder in - let int_temp, load_int_inst = build_load_integer 0L builder in - let arr_temp, load_array_inst = build_create_array [int_temp] builder in - let left_for_in = get_new_intermed_temp builder in - let _, begin_for_in_inst = build_begin_for_in_op left_for_in arr_temp builder in - let reassign_inst = build_reassign_op string_temp left_for_in builder in - let end_for_in_inst = build_end_for_in_op builder in - let string_temp2, load_string_inst2 = build_load_string "D" builder in - let add_temp, add_inst = build_binary_op string_temp string_temp2 Plus builder in - let res = [load_string_inst; load_int_inst; load_array_inst; begin_for_in_inst; reassign_inst; end_for_in_inst; load_string_inst2; add_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "for_in_scoping" correct prog - \ No newline at end of file diff --git a/Compiler/test/for_of.ml b/Compiler/test/for_of.ml deleted file mode 100644 index 16b19144..00000000 --- a/Compiler/test/for_of.ml +++ /dev/null @@ -1,26 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 20; -const v1 = [v0,v0,v0,v0,v0]; -for (const v2 of v1){ - isNaN(v2); -}" - -let correct = - let builder = init_builder false false false in - let int_20, load_int_20 = build_load_integer 20L builder in - let array_temp, create_array_inst = build_create_array [int_20; int_20; int_20; int_20; int_20] builder in - let begin_for_of_temp, begin_for_of_inst = build_begin_for_of_op array_temp builder in - let isNan_temp, load_IsNaN = build_load_builtin "isNaN" builder in - let _, call_inst = build_call isNan_temp [begin_for_of_temp] builder in - let end_for_of = build_end_for_of_op builder in - let res = [load_int_20; create_array_inst; begin_for_of_inst; load_IsNaN; call_inst; end_for_of] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "for_of" correct prog - \ No newline at end of file diff --git a/Compiler/test/func_call_with_spread.ml b/Compiler/test/func_call_with_spread.ml deleted file mode 100644 index 2199d7ab..00000000 --- a/Compiler/test/func_call_with_spread.ml +++ /dev/null @@ -1,39 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"function test(v0, ...v101){ - return v0 + v101[0]; -} -const v5 = [0,1]; -const v17 = test(10,...v5); -" - -let correct = - let builder = init_builder false false false in - let func_temp = get_new_intermed_temp builder in - let _, begin_func_inst, end_func_inst = build_func_ops func_temp ["v0"] (Some "v101") false false false builder in - (* TODO: Update this along with the function interface *) - let v0_temp = match lookup_var_name builder "v0" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - let v101_temp = match lookup_var_name builder "v101" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - let elem_temp, load_elem_inst = build_load_element v101_temp 0 builder in - let bin_temp, bin_inst = build_binary_op v0_temp elem_temp Plus builder in - let ret_inst = build_return_op bin_temp builder in - - let int_0, load_int_0 = build_load_integer 0L builder in - let int_1, load_int_1 = build_load_integer 1L builder in - - let arr_temp, create_arr_temp = build_create_array [int_0; int_1] builder in - let int_10, load_int_10 = build_load_integer 10L builder in - let _, call_inst = build_call_with_spread func_temp [int_10; arr_temp] [false; true] builder in - let res = [begin_func_inst; load_elem_inst; bin_inst; ret_inst; end_func_inst; load_int_0; load_int_1; create_arr_temp; load_int_10; call_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "func_call_with_spread" correct prog \ No newline at end of file diff --git a/Compiler/test/func_dec_order.ml b/Compiler/test/func_dec_order.ml deleted file mode 100644 index 4510a2d4..00000000 --- a/Compiler/test/func_dec_order.ml +++ /dev/null @@ -1,28 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"function b() {a();} -function a() { - return 7; -} -" - -let correct = - let builder = init_builder false false false in - let undef_temp, load_undef_inst = build_load_undefined builder in - let func_temp = get_new_intermed_temp builder in - let _, begin_func_inst, end_func_inst = build_func_ops func_temp [] None false false false builder in - let _, call_inst = build_call undef_temp [] builder in - let func_temp2 = get_new_intermed_temp builder in - let _, begin_func_inst_2, end_func_inst_2 = build_func_ops func_temp2 [] None false false false builder in - let int_temp, load_int_inst = build_load_integer 7L builder in - let ret_inst = build_return_op int_temp builder in - let reassign_inst = build_reassign_op undef_temp func_temp2 builder in - let res = [load_undef_inst; begin_func_inst; call_inst; end_func_inst; begin_func_inst_2; load_int_inst; ret_inst; end_func_inst_2; reassign_inst ] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "func_dec_order" correct prog \ No newline at end of file diff --git a/Compiler/test/func_exp_test.ml b/Compiler/test/func_exp_test.ml deleted file mode 100644 index ba7d8e97..00000000 --- a/Compiler/test/func_exp_test.ml +++ /dev/null @@ -1,23 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = function () { const v1 = 12; return v1;} -const v2 = v0(); -" - -let correct = - let builder = init_builder false false false in - (* TODO: This needs to be updated along with the function builder interface *) - let func_temp = get_new_intermed_temp builder in - let _, begin_func_inst, end_func_inst = build_func_ops func_temp [] None false false false builder in - let int_12, load_int_12 = build_load_integer 12L builder in - let return_inst = build_return_op int_12 builder in - let _, call_inst = build_call func_temp [] builder in - let res = [begin_func_inst; load_int_12; return_inst; end_func_inst; call_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "func_exp_test" correct prog \ No newline at end of file diff --git a/Compiler/test/func_param_scoping.ml b/Compiler/test/func_param_scoping.ml deleted file mode 100644 index d93450b1..00000000 --- a/Compiler/test/func_param_scoping.ml +++ /dev/null @@ -1,32 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - - -let input = -"function test(a) { - a[0] = 1.5; -} -a = new Array();" - -let correct = - let builder = init_builder false false false in - let func_temp = get_new_intermed_temp builder in - let _, begin_func_inst, end_func_inst = build_func_ops func_temp ["a"] None false false false builder in - (* TODO: This needs to be updated along with the function builder interface *) - let a_temp = match lookup_var_name builder "a" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - - let int_0, load_int_0 = build_load_integer 0L builder in - let float_15, load_float = build_load_float 1.5 builder in - let store_inst = build_store_computed_prop a_temp int_0 float_15 builder in - let array_builtin, load_builtin_inst = build_load_builtin "Array" builder in - let construct_temp, construct_inst = build_new_object array_builtin [] builder in - let _, dup_op = build_dup_op construct_temp builder in - let res = [begin_func_inst; load_int_0; load_float; store_inst; end_func_inst; load_builtin_inst; construct_inst; dup_op] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "func_param_scoping" correct prog \ No newline at end of file diff --git a/Compiler/test/if_else.ml b/Compiler/test/if_else.ml deleted file mode 100644 index 418e355e..00000000 --- a/Compiler/test/if_else.ml +++ /dev/null @@ -1,32 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"if(1){ - const v0 = 3; -} else if(2){ - const v1 = 4; -} else { - const v2 = 5; -} -" -let correct = - let builder = init_builder false false false in - let int_1, load_int_1 = build_load_integer 1L builder in - let begin_if_inst_1 = build_begin_if int_1 builder in - let int_3, load_int_3 = build_load_integer 3L builder in - let else_inst = build_begin_else builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let begin_if_inst_2 = build_begin_if int_2 builder in - let int_4, load_int_4 = build_load_integer 4L builder in - let int_5, load_int_5 = build_load_integer 5L builder in - let end_if_inst = build_end_if builder in - let res = [load_int_1; begin_if_inst_1; load_int_3; else_inst; load_int_2; begin_if_inst_2; load_int_4; else_inst; - load_int_5; end_if_inst; end_if_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "if_else" correct prog - \ No newline at end of file diff --git a/Compiler/test/in_test.ml b/Compiler/test/in_test.ml deleted file mode 100644 index fdee78b9..00000000 --- a/Compiler/test/in_test.ml +++ /dev/null @@ -1,24 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 10; -const v3 = [15,20]; -const v4 = v0 in v3; -" - -let correct = - let builder = init_builder false false false in - let int_10, load_int_10 = build_load_integer 10L builder in - let int_15, load_int_15 = build_load_integer 15L builder in - let int_20, load_int_20 = build_load_integer 20L builder in - let array_temp, create_array_inst = build_create_array [int_15; int_20] builder in - let _, in_inst = build_in_op int_10 array_temp builder in - let res = [load_int_10; load_int_15; load_int_20; create_array_inst; in_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "in_test" correct prog - \ No newline at end of file diff --git a/Compiler/test/instance_of.ml b/Compiler/test/instance_of.ml deleted file mode 100644 index 16a2de97..00000000 --- a/Compiler/test/instance_of.ml +++ /dev/null @@ -1,22 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 1; -const v1 = 2; -const v2 = v1 instanceof v0; -" - -let correct = - let builder = init_builder false false false in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let _, instance_inst = build_instanceof_op int_2 int_1 builder in - let res = [load_int_1; load_int_2; instance_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "instance_of" correct prog - \ No newline at end of file diff --git a/Compiler/test/load_array_index.ml b/Compiler/test/load_array_index.ml deleted file mode 100644 index 31ae94bc..00000000 --- a/Compiler/test/load_array_index.ml +++ /dev/null @@ -1,23 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v3 = [0,1,2]; -const v5 = v3[0]; -const v7 = v3[v5];" - -let correct = - let builder = init_builder false false false in - let int_0, load_int_0 = build_load_integer 0L builder in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let arr_temp, create_arr = build_create_array [int_0; int_1; int_2] builder in - let elem_temp, load_elem_inst = build_load_element arr_temp 0 builder in - let _, load_comp_elem_inst = build_load_computed_prop arr_temp elem_temp builder in - let res = [load_int_0; load_int_1; load_int_2; create_arr; load_elem_inst; load_comp_elem_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "load_array_index" correct prog \ No newline at end of file diff --git a/Compiler/test/load_bigint.ml b/Compiler/test/load_bigint.ml deleted file mode 100644 index ed4db4b1..00000000 --- a/Compiler/test/load_bigint.ml +++ /dev/null @@ -1,16 +0,0 @@ -open Compiler.ProgramBuilder -open Program_types - -let input = -"const v0 = 9007199254740991n;" - -let correct = - let builder = init_builder false false false in - let _, load_big_int_inst = build_load_bigInt 9007199254740991.0 builder in - let res = [load_big_int_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "load_bigint" correct prog \ No newline at end of file diff --git a/Compiler/test/load_bool.ml b/Compiler/test/load_bool.ml deleted file mode 100644 index 16205571..00000000 --- a/Compiler/test/load_bool.ml +++ /dev/null @@ -1,18 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = true; -const v1 = false;" - -let correct = - let builder = init_builder false false false in - let _, load_true = build_load_bool true builder in - let _, load_false = build_load_bool false builder in - let res = [load_true; load_false] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "load_bool" correct prog \ No newline at end of file diff --git a/Compiler/test/load_float.ml b/Compiler/test/load_float.ml deleted file mode 100644 index 5bfe0695..00000000 --- a/Compiler/test/load_float.ml +++ /dev/null @@ -1,16 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 20.15;" - -let correct = - let builder = init_builder false false false in - let _, inst = build_load_float 20.15 builder in - let res = [inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "load_float" correct prog \ No newline at end of file diff --git a/Compiler/test/load_infinity.ml b/Compiler/test/load_infinity.ml deleted file mode 100644 index a0226f9b..00000000 --- a/Compiler/test/load_infinity.ml +++ /dev/null @@ -1,16 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = Infinity;" - -let correct = - let builder = init_builder false false false in - let _, inst = build_load_float infinity builder in - let res = [inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "load_infinity" correct prog \ No newline at end of file diff --git a/Compiler/test/load_null.ml b/Compiler/test/load_null.ml deleted file mode 100644 index 55f613fe..00000000 --- a/Compiler/test/load_null.ml +++ /dev/null @@ -1,16 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = null;" - -let correct = - let builder = init_builder false false false in - let _, load_null = build_load_null builder in - let res = [load_null] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "load_null" correct prog \ No newline at end of file diff --git a/Compiler/test/load_property.ml b/Compiler/test/load_property.ml deleted file mode 100644 index 0b5d7ffb..00000000 --- a/Compiler/test/load_property.ml +++ /dev/null @@ -1,19 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = {}; -const v1 = 13.37; -const v2 = v0.__proto__;" -let correct = - let builder = init_builder false false false in - let obj_temp, create_obj = build_create_object [] [] builder in - let float_temp, load_float_inst = build_load_float 13.37 builder in - let _, load_prop_inst = build_load_prop obj_temp "__proto__" builder in - let res = [create_obj; load_float_inst; load_prop_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "load_property" correct prog \ No newline at end of file diff --git a/Compiler/test/load_regex.ml b/Compiler/test/load_regex.ml deleted file mode 100644 index 874b89c6..00000000 --- a/Compiler/test/load_regex.ml +++ /dev/null @@ -1,27 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -(* Note: this produces compiler warnings, but seems to work fine *) -let input = -"const v0 = /\w+\s/i; -const v1 = /\w+\s/g; -const v2 = /\w+\s/m; -const v3 = /\w+\s/s; -const v4 = /\w+\s/u; -const v5 = /\w+\s/y;" - -let correct = - let builder = init_builder false false false in - let _, regexp1 = build_load_regex "\\w+\\s" "i" builder in - let _, regexp2 = build_load_regex "\\w+\\s" "g" builder in - let _, regexp3 = build_load_regex "\\w+\\s" "m" builder in - let _, regexp4 = build_load_regex "\\w+\\s" "s" builder in - let _, regexp5 = build_load_regex "\\w+\\s" "u" builder in - let _, regexp6 = build_load_regex "\\w+\\s" "y" builder in - let res = [regexp1; regexp2; regexp3; regexp4; regexp5; regexp6] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "load_regex" correct prog \ No newline at end of file diff --git a/Compiler/test/logical_ops.ml b/Compiler/test/logical_ops.ml deleted file mode 100644 index 3a6b8cd8..00000000 --- a/Compiler/test/logical_ops.ml +++ /dev/null @@ -1,22 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 1 || 2; -const v1 = 3 && 4;" - -let correct = - let builder = init_builder false false false in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let _, or_inst = build_binary_op int_1 int_2 LogicalOr builder in - let int_3, load_int_3 = build_load_integer 3L builder in - let int_4, load_int_4 = build_load_integer 4L builder in - let _, and_inst = build_binary_op int_3 int_4 LogicalAnd builder in - let res = [load_int_1; load_int_2; or_inst; load_int_3; load_int_4; and_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "Logical_ops" correct prog \ No newline at end of file diff --git a/Compiler/test/lone_if.ml b/Compiler/test/lone_if.ml deleted file mode 100644 index dd0a1bf6..00000000 --- a/Compiler/test/lone_if.ml +++ /dev/null @@ -1,23 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 12; -if(v0){ - let v1 = 12; -}" - -let correct = - let builder = init_builder false false false in - let temp_12, load_int_12 = build_load_integer 12L builder in - let begin_if_inst = build_begin_if temp_12 builder in - let _, load_int_12_2 = build_load_integer 12L builder in - let begin_else = build_begin_else builder in - let end_if = build_end_if builder in - let res = [load_int_12; begin_if_inst; load_int_12_2; begin_else; end_if] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "lone_if" correct prog \ No newline at end of file diff --git a/Compiler/test/new.ml b/Compiler/test/new.ml deleted file mode 100644 index 9d064de6..00000000 --- a/Compiler/test/new.ml +++ /dev/null @@ -1,21 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v1 = new Uint8Array(); -const v5 = new Float32Array(12);" - -let correct = - let builder = init_builder false false false in - let uint8Array, load_uint8_builtin = build_load_builtin "Uint8Array" builder in - let _, construct_uin8_inst = build_new_object uint8Array [] builder in - let float32Array, load_float32_builtin = build_load_builtin "Float32Array" builder in - let int_12_temp, load_12 = build_load_integer 12L builder in - let _, construct_float32_inst = build_new_object float32Array [int_12_temp] builder in - let res = [load_uint8_builtin; construct_uin8_inst; load_float32_builtin; load_12; construct_float32_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "new_test" correct prog \ No newline at end of file diff --git a/Compiler/test/object_creation.ml b/Compiler/test/object_creation.ml deleted file mode 100644 index 12787909..00000000 --- a/Compiler/test/object_creation.ml +++ /dev/null @@ -1,24 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let v0 = 1; -const v1 = 2 -const v7 = {toString:1+2,e:v0+v1};" - -let correct = - let builder = init_builder false false false in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let int_1_2, load_int_1_2 = build_load_integer 1L builder in - let int_2_2, load_int_2_2 = build_load_integer 2L builder in - let second_temp, second_add = build_binary_op int_1_2 int_2_2 Plus builder in - let first_temp, first_add = build_binary_op int_1 int_2 Plus builder in - let _, create_obj_inst = build_create_object ["toString"; "e"] [second_temp; first_temp] builder in - let res = [load_int_1; load_int_2; load_int_1_2; load_int_2_2; second_add; first_add; create_obj_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "object_creation" correct prog \ No newline at end of file diff --git a/Compiler/test/prog_10.ml b/Compiler/test/prog_10.ml deleted file mode 100644 index 0ccb68da..00000000 --- a/Compiler/test/prog_10.ml +++ /dev/null @@ -1,30 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 4294967296; -const v1 = isNaN; -const v2 = v0 === v1; -const v3 = v0 == v1; -const v4 = 13.37; -const v5 = [v4,v4]; -const v6 = 1337; -const v7 = {toString:v5,e:v6};" - -let correct = - let builder = init_builder false false false in - let large_int, load_large_int = build_load_integer 4294967296L builder in - let isNaN, load_isNaN = build_load_builtin "isNaN" builder in - let _, compare_inst = build_compare_op large_int isNaN StrictEqual builder in - let _, compare_inst_2 = build_compare_op large_int isNaN Equal builder in - let float, load_float = build_load_float 13.37 builder in - let array, create_array = build_create_array [float; float] builder in - let int_1337, load_int_1337 = build_load_integer 1337L builder in - let _, create_object = build_create_object ["toString"; "e"] [array; int_1337] builder in - let res = [load_large_int; load_isNaN; compare_inst; compare_inst_2; load_float; create_array; load_int_1337; create_object] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "prog_10" correct prog \ No newline at end of file diff --git a/Compiler/test/prog_1007.ml b/Compiler/test/prog_1007.ml deleted file mode 100644 index ee28eec1..00000000 --- a/Compiler/test/prog_1007.ml +++ /dev/null @@ -1,26 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 2147483647; -const v1 = \"function\"; -try { - const v2 = v1.repeat(v0); -} catch(v3) { -}" - -let correct = - let builder = init_builder false false false in - let large_int, load_large_int = build_load_integer 2147483647L builder in - let func_string, load_func_string = build_load_string "function" builder in - let begin_try = build_begin_try_op builder in - let _, call_method = build_call_method func_string [large_int] "repeat" builder in - let begin_catch = build_begin_catch_op "foobarbaz" builder in - let end_catch = build_end_try_catch_op builder in - let res = [load_large_int; load_func_string; begin_try; call_method; begin_catch; end_catch] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "prog_1007" correct prog \ No newline at end of file diff --git a/Compiler/test/prop_name_assignment.ml b/Compiler/test/prop_name_assignment.ml deleted file mode 100644 index db9bd116..00000000 --- a/Compiler/test/prop_name_assignment.ml +++ /dev/null @@ -1,22 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = \"function\"; -const v1 = 13.37; -const v2 = v0.__proto__; -v2.toString = v1;" - -let correct = - let builder = init_builder false false false in - let func_string, load_func_string = build_load_string "function" builder in - let float, load_float = build_load_float 13.37 builder in - let prop_temp, load_prop = build_load_prop func_string "__proto__" builder in - let store_prop = build_store_prop prop_temp float "toString" builder in - let res = [load_func_string; load_float; load_prop; store_prop] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "prop_name_assignment" correct prog \ No newline at end of file diff --git a/Compiler/test/single_constant.ml b/Compiler/test/single_constant.ml deleted file mode 100644 index 616079d5..00000000 --- a/Compiler/test/single_constant.ml +++ /dev/null @@ -1,16 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 0;" - -let correct = - let builder = init_builder false false false in - let _, inst = build_load_integer 0L builder in - let res = [inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "single_constant" correct prog \ No newline at end of file diff --git a/Compiler/test/single_let.ml b/Compiler/test/single_let.ml deleted file mode 100644 index 5b140fa2..00000000 --- a/Compiler/test/single_let.ml +++ /dev/null @@ -1,19 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let v0 = 0; -v0 = 12;" - -let correct = - let builder = init_builder false false false in - let int_0_temp, load_0_inst = build_load_integer 0L builder in - let int_12_temp, load_12_inst = build_load_integer 12L builder in - let reassign_inst = build_reassign_op int_0_temp int_12_temp builder in - let res = [load_0_inst; load_12_inst; reassign_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "single_let" correct prog \ No newline at end of file diff --git a/Compiler/test/single_string_literal.ml b/Compiler/test/single_string_literal.ml deleted file mode 100644 index cf0dd9da..00000000 --- a/Compiler/test/single_string_literal.ml +++ /dev/null @@ -1,16 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = \"foobarbaz\";" - -let correct = - let builder = init_builder false false false in - let _, inst = build_load_string "foobarbaz" builder in - let res = [inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "single_string_literal" correct prog \ No newline at end of file diff --git a/Compiler/test/spread_object.ml b/Compiler/test/spread_object.ml deleted file mode 100644 index 99d2f657..00000000 --- a/Compiler/test/spread_object.ml +++ /dev/null @@ -1,30 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let v0 = 1; -const v1 = 2 -const v7 = {toString:1+2,e:v0+v1}; -const v11 = {foobar:3+4,...v7};" - -let correct = - let builder = init_builder false false false in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let int_1_2, load_int_1_2 = build_load_integer 1L builder in - let int_2_2, load_int_2_2 = build_load_integer 2L builder in - let second_temp, second_add = build_binary_op int_1_2 int_2_2 Plus builder in - let first_temp, first_add = build_binary_op int_1 int_2 Plus builder in - let obj, create_obj_inst = build_create_object ["toString"; "e"] [second_temp; first_temp] builder in - - let int_3, load_int_3 = build_load_integer 3L builder in - let int_4, load_int_4 = build_load_integer 4L builder in - let third_temp, third_add = build_binary_op int_3 int_4 Plus builder in - let _, spread_inst = build_create_object_with_spread ["foobar"] [third_temp; obj] builder in - let res = [load_int_1; load_int_2; load_int_1_2; load_int_2_2; second_add; first_add; create_obj_inst; load_int_3; load_int_4; third_add; spread_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "spread_object" correct prog \ No newline at end of file diff --git a/Compiler/test/store_property_sugared.ml b/Compiler/test/store_property_sugared.ml deleted file mode 100644 index f3bc710b..00000000 --- a/Compiler/test/store_property_sugared.ml +++ /dev/null @@ -1,25 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = {}; -const v1 = 13.37; -v0.a = 10; -v0.a += v1;" - -let correct = - let builder = init_builder false false false in - let obj, create_obj = build_create_object [] [] builder in - let float, load_float = build_load_float 13.37 builder in - let int, load_int = build_load_integer 10L builder in - let store_prop = build_store_prop obj int "a" builder in - let temp_prop, load_prop = build_load_prop obj "a" builder in - let add_temp, add_inst = build_binary_op temp_prop float Plus builder in - let store_prop2 = build_store_prop obj add_temp "a" builder in - let res = [create_obj; load_float; load_int; store_prop; load_prop; add_inst; store_prop2] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "store_property_sugared" correct prog \ No newline at end of file diff --git a/Compiler/test/sugared_assignment.ml b/Compiler/test/sugared_assignment.ml deleted file mode 100644 index 71f47409..00000000 --- a/Compiler/test/sugared_assignment.ml +++ /dev/null @@ -1,26 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let v0 = 1; -v0 += 10; -let v1 = 2; -v1 -= 20;" - -let correct = - let builder = init_builder false false false in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_10, load_int_10 = build_load_integer 10L builder in - let add_temp, add_inst = build_binary_op int_1 int_10 Plus builder in - let reassign_op = build_reassign_op int_1 add_temp builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let int_20, load_int_20 = build_load_integer 20L builder in - let sub_temp, sub_inst = build_binary_op int_2 int_20 Minus builder in - let reassign_op2 = build_reassign_op int_2 sub_temp builder in - let res = [load_int_1; load_int_10; add_inst; reassign_op; load_int_2; load_int_20; sub_inst; reassign_op2] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "sugared_assignment" correct prog \ No newline at end of file diff --git a/Compiler/test/ternary.ml b/Compiler/test/ternary.ml deleted file mode 100644 index c42b63ee..00000000 --- a/Compiler/test/ternary.ml +++ /dev/null @@ -1,26 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let a = 1 < 0 ? 2 : 3;" - -let correct = - let builder = init_builder false false false in - let int_0, load_int_0 = build_load_integer 0L builder in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_0_2, load_int_0_2 = build_load_integer 0L builder in - let compare_temp, compare_inst = build_compare_op int_1 int_0_2 LessThan builder in - let begin_if_inst = build_begin_if compare_temp builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let reassign_inst = build_reassign_op int_0 int_2 builder in - let begin_else = build_begin_else builder in - let int_3, load_int_3 = build_load_integer 3L builder in - let reassign_inst2 = build_reassign_op int_0 int_3 builder in - let end_if = build_end_if builder in - let res = [load_int_0; load_int_1; load_int_0_2; compare_inst; begin_if_inst; load_int_2; reassign_inst; begin_else; load_int_3; reassign_inst2; end_if] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "ternary_test" correct prog \ No newline at end of file diff --git a/Compiler/test/test.ml b/Compiler/test/test.ml deleted file mode 100644 index 68b6828b..00000000 --- a/Compiler/test/test.ml +++ /dev/null @@ -1,84 +0,0 @@ -let () = Alcotest.run "fuzzilli_compiler_tests" [ - "tests", [ - (* Basic Straightline Code *) - Alcotest.test_case "array_decl" `Quick Array_decl.test; - Alcotest.test_case "array_hole" `Quick Array_hole.test; - Alcotest.test_case "basic_compare_test" `Quick Basic_compare_test.test; - Alcotest.test_case "binary_ops" `Quick Binary_ops.test; - Alcotest.test_case "bitwise_ops" `Quick Bitwise_ops.test; - Alcotest.test_case "exp_statement" `Quick Exp_statement.test; - Alcotest.test_case "in_test" `Quick In_test.test; - Alcotest.test_case "instance_of" `Quick Instance_of.test; - Alcotest.test_case "load_array_index" `Quick Load_array_index.test; - Alcotest.test_case "load_bigint" `Quick Load_bigint.test; - Alcotest.test_case "load_bool" `Quick Load_bool.test; - Alcotest.test_case "load_float" `Quick Load_float.test; - Alcotest.test_case "load_infinity" `Quick Load_infinity.test; - Alcotest.test_case "load_null" `Quick Load_null.test; - Alcotest.test_case "load_property" `Quick Load_property.test; - Alcotest.test_case "load_regex" `Quick Load_regex.test; - Alcotest.test_case "logical_ops" `Quick Logical_ops.test; - Alcotest.test_case "new" `Quick New.test; - Alcotest.test_case "object_creation" `Quick Object_creation.test; - Alcotest.test_case "prog_10" `Quick Prog_10.test; - Alcotest.test_case "prog_1007" `Quick Prog_1007.test; - Alcotest.test_case "prop_name_assignment" `Quick Prop_name_assignment.test; - Alcotest.test_case "single_constant" `Quick Single_constant.test; - Alcotest.test_case "single_let" `Quick Single_let.test; - Alcotest.test_case "single_string_literal" `Quick Single_string_literal.test; - Alcotest.test_case "spread_object" `Quick Spread_object.test; - Alcotest.test_case "store_property_sugared" `Quick Store_property_sugared.test; - Alcotest.test_case "sugared_assignment" `Quick Sugared_assignment.test; - Alcotest.test_case "ternary" `Quick Ternary.test; - Alcotest.test_case "this" `Quick This.test; - Alcotest.test_case "throw" `Quick Throw.test; - Alcotest.test_case "typeof" `Quick Typeof.test; - Alcotest.test_case "unary_minus" `Quick Unary_minus.test; - Alcotest.test_case "unary_ops" `Quick Unary_ops.test; - Alcotest.test_case "undefined" `Quick Undefined.test; - Alcotest.test_case "update" `Quick Update.test; - Alcotest.test_case "void" `Quick Void.test; - - (* Control Flow*) - Alcotest.test_case "basic_break" `Quick Basic_break.test; - Alcotest.test_case "basic_for" `Quick Basic_for.test; - Alcotest.test_case "basic_while" `Quick Basic_while.test; - Alcotest.test_case "basic_continue" `Quick Basic_continue.test; - Alcotest.test_case "do_while" `Quick Do_while.test; - Alcotest.test_case "for_in" `Quick For_in.test; - Alcotest.test_case "for_in_scope2" `Quick For_in_scope2.test; - Alcotest.test_case "for_in_scoping" `Quick For_in_scoping.test; - Alcotest.test_case "for_of" `Quick For_of.test; - Alcotest.test_case "if_else" `Quick If_else.test; - Alcotest.test_case "lone_if" `Quick Lone_if.test; - Alcotest.test_case "with" `Quick With.test; - Alcotest.test_case "with_load_scope" `Quick With_load_scope.test; - - (* Functions*) - Alcotest.test_case "basic_func_call" `Quick Basic_func_call.test; - Alcotest.test_case "basic_func_ret" `Quick Basic_func_ret.test; - Alcotest.test_case "func_dec_order" `Quick Func_dec_order.test; - Alcotest.test_case "func_call_with_spread" `Quick Func_call_with_spread.test; - Alcotest.test_case "func_exp_test" `Quick Func_exp_test.test; - Alcotest.test_case "func_param_scoping" `Quick Func_param_scoping.test; - Alcotest.test_case "varied_func_types" `Quick Varied_func_types.test; - - (* Array Operations *) - Alcotest.test_case "array_assign" `Quick Array_assign.test; - Alcotest.test_case "array_assign_sugared" `Quick Array_assign_sugared.test; - Alcotest.test_case "array_spread" `Quick Array_spread.test; - Alcotest.test_case "create_array" `Quick Create_array.test; - Alcotest.test_case "del_test" `Quick Del_test.test; - - (* Variable Hoisting *) - Alcotest.test_case "var_hoisting_1" `Quick Var_hoisting_1.test; - Alcotest.test_case "var_hoisting_2" `Quick Var_hoisting_2.test; - Alcotest.test_case "var_hoisting_3" `Quick Var_hoisting_3.test; - Alcotest.test_case "var_hoisting_shadow" `Quick Var_hoisting_shadow.test; - - (* Other *) - Alcotest.test_case "empty_assignment_scope" `Quick Empty_assignment_scope.test; - Alcotest.test_case "v8_natives" `Quick V8_natives.test; - - ]; -] \ No newline at end of file diff --git a/Compiler/test/this.ml b/Compiler/test/this.ml deleted file mode 100644 index d866c3e8..00000000 --- a/Compiler/test/this.ml +++ /dev/null @@ -1,16 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = this" - -let correct = - let builder = init_builder false false false in - let _, inst = build_load_builtin "this" builder in - let res = [inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "this" correct prog \ No newline at end of file diff --git a/Compiler/test/throw.ml b/Compiler/test/throw.ml deleted file mode 100644 index 89f791c9..00000000 --- a/Compiler/test/throw.ml +++ /dev/null @@ -1,18 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 0; -throw v0;" - -let correct = - let builder = init_builder false false false in - let temp_0, load_0 = build_load_integer 0L builder in - let inst = build_throw_op temp_0 builder in - let res = [load_0; inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "throw" correct prog \ No newline at end of file diff --git a/Compiler/test/typeof.ml b/Compiler/test/typeof.ml deleted file mode 100644 index 034c0b0b..00000000 --- a/Compiler/test/typeof.ml +++ /dev/null @@ -1,18 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 12; -const v2 = typeof v0;" - -let correct = - let builder = init_builder false false false in - let int, load_int = build_load_integer 12L builder in - let _, typeof_inst = build_typeof_op int builder in - let res = [load_int; typeof_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "typeof" correct prog \ No newline at end of file diff --git a/Compiler/test/unary_minus.ml b/Compiler/test/unary_minus.ml deleted file mode 100644 index 0899d8af..00000000 --- a/Compiler/test/unary_minus.ml +++ /dev/null @@ -1,17 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v2 = -256;" - -let correct = - let builder = init_builder false false false in - let pos_temp, load_int = build_load_integer 256L builder in - let _, unary_inst = build_unary_op pos_temp Minus builder in - let res = [load_int; unary_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "unary_minus" correct prog \ No newline at end of file diff --git a/Compiler/test/unary_ops.ml b/Compiler/test/unary_ops.ml deleted file mode 100644 index b21dd2fd..00000000 --- a/Compiler/test/unary_ops.ml +++ /dev/null @@ -1,25 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = !true; -const v1 = !false; -const v2 = !v0; -const v3 = ~5;" - -let correct = - let builder = init_builder false false false in - let true_temp, load_true = build_load_bool true builder in - let not_temp, not_inst_1 = build_unary_op true_temp Not builder in - let false_temp, load_false = build_load_bool false builder in - let _, not_inst_2 = build_unary_op false_temp Not builder in - let _, not_inst_3 = build_unary_op not_temp Not builder in - let int_5, load_int_5 = build_load_integer 5L builder in - let _, bit_not_inst = build_unary_op int_5 BitNot builder in - let res = [load_true; not_inst_1; load_false; not_inst_2; not_inst_3; load_int_5; bit_not_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "unary_ops" correct prog \ No newline at end of file diff --git a/Compiler/test/undefined.ml b/Compiler/test/undefined.ml deleted file mode 100644 index b300920c..00000000 --- a/Compiler/test/undefined.ml +++ /dev/null @@ -1,16 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let a = undefined;" - -let correct = - let builder = init_builder false false false in - let _, inst = build_load_undefined builder in - let res = [inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "undefined" correct prog \ No newline at end of file diff --git a/Compiler/test/update.ml b/Compiler/test/update.ml deleted file mode 100644 index 48b2ba0b..00000000 --- a/Compiler/test/update.ml +++ /dev/null @@ -1,20 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = 5; -v0++; ---v0;" - -let correct = - let builder = init_builder false false false in - let int_5, load_int_5 = build_load_integer 5L builder in - let _, post_inc = build_unary_op int_5 PostInc builder in - let _, pre_inc = build_unary_op int_5 PreDec builder in - let res = [load_int_5; post_inc; pre_inc] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "update" correct prog \ No newline at end of file diff --git a/Compiler/test/util.ml b/Compiler/test/util.ml deleted file mode 100644 index 56226b67..00000000 --- a/Compiler/test/util.ml +++ /dev/null @@ -1,27 +0,0 @@ -let inst_testable = Alcotest.testable Compiler.pp_instruction (=) - -let type_ext = Typesystem_types.{ - properties = []; - methods = []; - group = ""; - signature = None; -} - - -let default_input_type = Typesystem_types.{ - definite_type = 4095l; - possible_type = 4095l; - ext = Extension type_ext -} - -let spread_input_type = Typesystem_types.{ - definite_type = 2147483648l; - possible_type = 2147483648l; - ext = Extension type_ext -} - -let default_output_type = Typesystem_types.{ - definite_type = Int32.shift_left 1l 8; - possible_type = Int32.shift_left 1l 8; - ext = Extension type_ext -} diff --git a/Compiler/test/v8_natives.ml b/Compiler/test/v8_natives.ml deleted file mode 100644 index b22fea42..00000000 --- a/Compiler/test/v8_natives.ml +++ /dev/null @@ -1,22 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v0 = function () { const v1 = 12; return v1;} -%PrepareFunctionForOptimization(v0);" - -let correct = - let builder = init_builder false true true in - let func_temp = get_new_intermed_temp builder in - let _, begin_func_inst, end_func_inst = build_func_ops func_temp [] None false false false builder in - let int_12, load_12 = build_load_integer 12L builder in - let ret_inst = build_return_op int_12 builder in - let builtin_temp, load_builtin = build_load_builtin "PrepareFunctionForOptimization" builder in - let _, call_inst = build_call builtin_temp [func_temp] builder in - let res = [begin_func_inst; load_12; ret_inst; end_func_inst; load_builtin; call_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false true true in - Alcotest.(check (list Util.inst_testable)) "v8_natives" correct prog \ No newline at end of file diff --git a/Compiler/test/var_hoisting_1.ml b/Compiler/test/var_hoisting_1.ml deleted file mode 100644 index 8c665c6f..00000000 --- a/Compiler/test/var_hoisting_1.ml +++ /dev/null @@ -1,35 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"function foo() { - if(1){ - var asdf = 12; - } - isNaN(asdf); -} -foo(); -" - -let correct = - let builder = init_builder false false false in - let func_temp = get_new_intermed_temp builder in - let _, begin_func_inst, end_func_inst = build_func_ops func_temp [] None false false false builder in - let undef_temp, load_undef_inst = build_load_undefined builder in - let integer_temp, load_integer_inst = build_load_integer 1L builder in - let begin_if_inst = build_begin_if integer_temp builder in - let load_hoisted_temp, load_hoisted_inst = build_load_integer 12L builder in - let reassign_inst = build_reassign_op undef_temp load_hoisted_temp builder in - let begin_else_inst = build_begin_else builder in - let end_if_inst = build_end_if builder in - let print_temp, load_print_inst = build_load_builtin "isNaN" builder in - let _, call_print_inst = build_call print_temp [undef_temp] builder in - let _, call_foo_inst = build_call func_temp [] builder in - let res = [begin_func_inst; load_undef_inst; load_integer_inst; begin_if_inst; load_hoisted_inst; reassign_inst; begin_else_inst; end_if_inst; load_print_inst; call_print_inst; end_func_inst; call_foo_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "var_hoisting_1" correct prog - \ No newline at end of file diff --git a/Compiler/test/var_hoisting_2.ml b/Compiler/test/var_hoisting_2.ml deleted file mode 100644 index 6914b1a3..00000000 --- a/Compiler/test/var_hoisting_2.ml +++ /dev/null @@ -1,42 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"function foo() { - for(var i = 1; i < 2; i++){ - var asdf = i; - } - isNaN(asdf); -} -foo(); -" - -let correct = - let builder = init_builder false false false in - let func_temp = get_new_intermed_temp builder in - let _, begin_func_inst, end_func_inst = build_func_ops func_temp [] None false false false builder in - let undef_temp, load_undef_inst = build_load_undefined builder in - let integer_temp, load_integer_inst = build_load_integer 1L builder in - let compare_temp_target, load_compare_temp_inst = build_load_integer 2L builder in - let compare_temp, compare_inst = build_compare_op integer_temp compare_temp_target LessThan builder in - let i_temp, load_i_inital_inst = build_load_integer 0L builder in - let begin_while_inst = build_begin_while compare_temp i_temp NotEqual builder in - let reassign_hoisted_inst = build_reassign_op undef_temp integer_temp builder in - let _, inc_loop_var_inst = build_unary_op integer_temp PostInc builder in - let loop_compare_temp, load_loop_temp_inst = build_load_integer 2L builder in - let recompare_temp, recompare_inst = build_compare_op integer_temp loop_compare_temp LessThan builder in - let reassign_loop_compare = build_reassign_op compare_temp recompare_temp builder in - let end_while__inst = build_end_while builder in - let print_temp, load_print_inst = build_load_builtin "isNaN" builder in - let _, call_print_inst = build_call print_temp [undef_temp] builder in - let _, call_foo_inst = build_call func_temp [] builder in - let res = [begin_func_inst; load_undef_inst; load_integer_inst; load_compare_temp_inst; compare_inst; load_i_inital_inst; - begin_while_inst; reassign_hoisted_inst; inc_loop_var_inst; load_loop_temp_inst; recompare_inst; reassign_loop_compare; end_while__inst; - load_print_inst; call_print_inst; end_func_inst; call_foo_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "var_hoisting_2" correct prog - \ No newline at end of file diff --git a/Compiler/test/var_hoisting_3.ml b/Compiler/test/var_hoisting_3.ml deleted file mode 100644 index 22ab4c9a..00000000 --- a/Compiler/test/var_hoisting_3.ml +++ /dev/null @@ -1,40 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"function foo() { - let t = 1; - if(t){ - if(t){ - var asdf = 12; - } - } - isNaN(asdf); -} -foo(); -" - -let correct = - let builder = init_builder false false false in - let func_temp = get_new_intermed_temp builder in - let _, begin_func_inst, end_func_inst = build_func_ops func_temp [] None false false false builder in - let undef_temp, load_undef_inst = build_load_undefined builder in - let integer_temp, load_integer_inst = build_load_integer 1L builder in - - let begin_if_inst = build_begin_if integer_temp builder in - let load_hoisted_temp, load_hoisted_inst = build_load_integer 12L builder in - let reassign_inst = build_reassign_op undef_temp load_hoisted_temp builder in - let begin_else_inst = build_begin_else builder in - let end_if_inst = build_end_if builder in - - let print_temp, load_print_inst = build_load_builtin "isNaN" builder in - let _, call_print_inst = build_call print_temp [undef_temp] builder in - let _, call_foo_inst = build_call func_temp [] builder in - let res = [begin_func_inst; load_undef_inst; load_integer_inst; begin_if_inst; begin_if_inst; load_hoisted_inst; reassign_inst; begin_else_inst; end_if_inst; begin_else_inst; end_if_inst; load_print_inst; call_print_inst; end_func_inst; call_foo_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "var_hoisting_3" correct prog - \ No newline at end of file diff --git a/Compiler/test/var_hoisting_shadow.ml b/Compiler/test/var_hoisting_shadow.ml deleted file mode 100644 index a1689411..00000000 --- a/Compiler/test/var_hoisting_shadow.ml +++ /dev/null @@ -1,36 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"for(x in [0]){} -if(1){ - var x = 12; -} -isNaN(x); -" - -let correct = - let builder = init_builder false false false in - let undef_temp, load_undef_inst = build_load_undefined builder in - let integer_temp, load_integer_inst = build_load_integer 0L builder in - let array_temp, array_build_inst = build_create_array [integer_temp] builder in - let for_in_temp = get_new_intermed_temp builder in - let _, begin_for_in_inst = build_begin_for_in_op for_in_temp array_temp builder in - let reassign_inst = build_reassign_op undef_temp for_in_temp builder in - let end_for_in_inst = build_end_for_in_op builder in - let if_condition_temp, load_if_condition_inst = build_load_integer 1L builder in - let begin_if_inst = build_begin_if if_condition_temp builder in - let load_hoisted_temp, load_hoisted_inst = build_load_integer 12L builder in - let reassign_inst2 = build_reassign_op undef_temp load_hoisted_temp builder in - let begin_else_inst = build_begin_else builder in - let end_if_inst = build_end_if builder in - let print_temp, load_print_inst = build_load_builtin "isNaN" builder in - let _, call_print_inst = build_call print_temp [undef_temp] builder in - let res = [load_undef_inst; load_integer_inst; array_build_inst; begin_for_in_inst; reassign_inst; end_for_in_inst; load_if_condition_inst; begin_if_inst; load_hoisted_inst; reassign_inst2; begin_else_inst; end_if_inst; load_print_inst; call_print_inst] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "var_hoisting_shadow" correct prog - \ No newline at end of file diff --git a/Compiler/test/varied_func_types.ml b/Compiler/test/varied_func_types.ml deleted file mode 100644 index f0b8d562..00000000 --- a/Compiler/test/varied_func_types.ml +++ /dev/null @@ -1,86 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - - -let input = -"const v0 = [1,2,3]; -const v1 = (v0) => { - return v0 + 4; -}; -async function v2(v0) { - return v0 + 5; -} -const v3 = async (v0) => { - return v0 + 5; -} -function * v4(v0) { - yield v0 + 6; -} -function * v5(v0) { - yield *v0; -}" - -let correct = - let builder = init_builder false false false in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let int_3, load_int_3 = build_load_integer 3L builder in - let array_temp, create_array_inst = build_create_array [int_1; int_2; int_3] builder in - - (* TODO: Update this when updating the function op interface *) - let arrow_func_temp = get_new_intermed_temp builder in - let _, begin_arrow_inst, end_arrow_inst = build_func_ops arrow_func_temp ["v0"] None true false false builder in - let v0_temp_1 = match lookup_var_name builder "v0" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - let int_4, load_int_4 = build_load_integer 4L builder in - let add_temp_1, add_inst_1 = build_binary_op v0_temp_1 int_4 Plus builder in - let return_1 = build_return_op add_temp_1 builder in - - let async_func_temp = get_new_intermed_temp builder in - let _, begin_async_inst, end_asnyc_inst = build_func_ops async_func_temp ["v0"] None false true false builder in - let v0_temp_2 = match lookup_var_name builder "v0" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - let int_5, load_int_5 = build_load_integer 5L builder in - let add_temp_2, add_inst_2 = build_binary_op v0_temp_2 int_5 Plus builder in - let return_2 = build_return_op add_temp_2 builder in - - let async_arrow_func_temp = get_new_intermed_temp builder in - let _, begin_async_arrow_inst, end_asnyc_arrow_inst = build_func_ops async_arrow_func_temp ["v0"] None true true false builder in - let v0_temp_3 = match lookup_var_name builder "v0" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - let int_5_2, load_int_5_2 = build_load_integer 5L builder in - let add_temp_3, add_inst_3 = build_binary_op v0_temp_3 int_5_2 Plus builder in - let return_3 = build_return_op add_temp_3 builder in - - let generator_func_temp_1 = get_new_intermed_temp builder in - let _, begin_generator_func_1, end_generator_func_1 = build_func_ops generator_func_temp_1 ["v0"] None false false true builder in - let v0_temp_4 = match lookup_var_name builder "v0" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - let int_6, load_int_6 = build_load_integer 6L builder in - let add_temp_4, add_inst_4 = build_binary_op v0_temp_4 int_6 Plus builder in - let yield_inst = build_yield_op add_temp_4 builder in - - let generator_func_temp_2 = get_new_intermed_temp builder in - let _, begin_generator_func_2, end_generator_func_2 = build_func_ops generator_func_temp_2 ["v0"] None false false true builder in - let v0_temp_5 = match lookup_var_name builder "v0" with - InScope x -> x - | NotFound -> raise (Invalid_argument "improper variable lookup") in - let yield_each_inst = build_yield_each_op v0_temp_5 builder in - - let res = [load_int_1; load_int_2; load_int_3; create_array_inst; - begin_arrow_inst; load_int_4; add_inst_1; return_1; end_arrow_inst; - begin_async_inst; load_int_5; add_inst_2; return_2; end_asnyc_inst; - begin_async_arrow_inst; load_int_5_2; add_inst_3; return_3; end_asnyc_arrow_inst; - begin_generator_func_1; load_int_6; add_inst_4; yield_inst; end_generator_func_1; - begin_generator_func_2; yield_each_inst; end_generator_func_2 - ] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "varied_func_types" correct prog \ No newline at end of file diff --git a/Compiler/test/void.ml b/Compiler/test/void.ml deleted file mode 100644 index a382f88e..00000000 --- a/Compiler/test/void.ml +++ /dev/null @@ -1,19 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let a = void (1 + 2);" - -let correct = - let builder = init_builder false false false in - let int_1, load_int_1 = build_load_integer 1L builder in - let int_2, load_int_2 = build_load_integer 2L builder in - let _, binary_op = build_binary_op int_1 int_2 Plus builder in - let _, load_undef = build_load_undefined builder in - let res = [load_int_1; load_int_2; binary_op; load_undef] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "void" correct prog \ No newline at end of file diff --git a/Compiler/test/with.ml b/Compiler/test/with.ml deleted file mode 100644 index c78abb91..00000000 --- a/Compiler/test/with.ml +++ /dev/null @@ -1,31 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"let v0 = 10; -let v4 = 13; -const v2 = [12]; -with (v2) { - const v3 = 0.0; - const v9 = v0 - v4; -}" - - -(* TODO: This likely is incorrect *) -let correct = - let builder = init_builder false false false in - let int_10, load_int_10 = build_load_integer 10L builder in - let int_13, load_int_13 = build_load_integer 13L builder in - let int_12, load_int_12 = build_load_integer 12L builder in - let arr_temp, create_array_inst = build_create_array [int_12] builder in - let begin_with = build_begin_with_op arr_temp builder in - let float, load_float = build_load_float 0.0 builder in - let _, sub_inst = build_binary_op int_10 int_13 Minus builder in - let end_with = build_end_with_op builder in - let res = [load_int_10; load_int_13; load_int_12; create_array_inst; begin_with; load_float; sub_inst; end_with] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "with" correct prog \ No newline at end of file diff --git a/Compiler/test/with_load_scope.ml b/Compiler/test/with_load_scope.ml deleted file mode 100644 index e6ba099b..00000000 --- a/Compiler/test/with_load_scope.ml +++ /dev/null @@ -1,26 +0,0 @@ -open Program_types -open Compiler.ProgramBuilder - -let input = -"const v9 = {__proto__:0,length:0}; -with (v9) { - const v11 = length; -} -" - -(* TODO: This may not be correct, as length should come from v9 *) -let correct = - let builder = init_builder false false false in - let int_0_1, load_int_0_1 = build_load_integer 0L builder in - let int_0_2, load_int_0_2 = build_load_integer 0L builder in - let obj_temp, create_obj = build_create_object ["__proto__"; "length"] [int_0_1; int_0_2] builder in - let begin_with = build_begin_with_op obj_temp builder in - let _, load_builtin = build_load_builtin "placeholder" builder in - let end_with = build_end_with_op builder in - let res = [load_int_0_1; load_int_0_2; create_obj; begin_with; load_builtin; end_with] in - List.map inst_to_prog_inst res - -let test () = - let (ast, errors) = Compiler.string_to_flow_ast input in - let prog = Compiler.flow_ast_to_inst_list ast false false true in - Alcotest.(check (list Util.inst_testable)) "with" correct prog \ No newline at end of file diff --git a/Package.swift b/Package.swift index 30017dc3..86dc7910 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.0 +// swift-tools-version:5.3 // // Copyright 2019 Google LLC // @@ -22,22 +22,51 @@ let package = Package( .macOS(.v10_13), ], products: [ - .library(name: "Fuzzilli", targets: ["Fuzzilli"]), + .library(name: "Fuzzilli",targets: ["Fuzzilli"]), ], dependencies: [ .package(url: "https://github.com/apple/swift-protobuf.git", from: "1.6.0"), ], targets: [ - .target(name: "libsocket", dependencies: []), - .target(name: "libreprl", dependencies: []), - // Using '-c release' when building uses '-O2', so '-O3' provides a performance gain - .target(name: "libcoverage", dependencies: [], cSettings: [.unsafeFlags(["-O3"])], linkerSettings: [.linkedLibrary("rt", .when(platforms: [.linux]))]), - .target(name: "Fuzzilli", dependencies: ["SwiftProtobuf", "libsocket", "libreprl", "libcoverage"]), - .target(name: "REPRLRun", dependencies: ["libreprl"]), - .target(name: "FuzzilliCli", dependencies: ["Fuzzilli"]), - .target(name: "FuzzILTool", dependencies: ["Fuzzilli"]), - - .testTarget(name: "FuzzilliTests", dependencies: ["Fuzzilli"]), + .target(name: "libsocket", + dependencies: []), + + .target(name: "libreprl", + dependencies: []), + + .target(name: "libcoverage", + dependencies: [], + cSettings: [.unsafeFlags(["-O3"])], // Using '-c release' when building uses '-O2', so '-O3' provides a performance gain + linkerSettings: [.linkedLibrary("rt", .when(platforms: [.linux]))]), + + .target(name: "Fuzzilli", + dependencies: [ + .product(name: "SwiftProtobuf", package: "swift-protobuf"), + "libsocket", + "libreprl", + "libcoverage"], + exclude: [ + "Protobuf/sync.proto", + "Protobuf/operations.proto", + "Protobuf/program.proto", + "Protobuf/README.md"], + resources: [ + // The ast.proto file is required by the node.js parser + .copy("Protobuf/ast.proto"), + .copy("Compiler/Parser")]), + + .target(name: "REPRLRun", + dependencies: ["libreprl"]), + + .target(name: "FuzzilliCli", + dependencies: ["Fuzzilli"]), + + .target(name: "FuzzILTool", + dependencies: ["Fuzzilli"]), + + .testTarget(name: "FuzzilliTests", + dependencies: ["Fuzzilli"], + resources: [.copy("CompilerTests")]), ], swiftLanguageVersions: [.v5] ) diff --git a/Sources/FuzzILTool/main.swift b/Sources/FuzzILTool/main.swift index 38272e50..d1043066 100644 --- a/Sources/FuzzILTool/main.swift +++ b/Sources/FuzzILTool/main.swift @@ -110,6 +110,7 @@ if args["-h"] != nil || args["--help"] != nil || args.numPositionalArguments != --dumpProtobuf : Dumps the raw content of the given protobuf file --dumpProgram : Dumps the internal representation of the program stored in the given protobuf file --checkCorpus : Attempts to load all .fuzzil.protobuf files in a directory and checks if they are statically valid + --compile : Compile the given JavaScript program to a FuzzIL program. Requires node.js """) exit(0) } @@ -154,6 +155,44 @@ else if args.has("--checkCorpus") { print("Successfully loaded \(numPrograms) programs") } +// Compile a JavaScript program to a FuzzIL program. Requires node.js +else if args.has("--compile") { + guard let parser = JavaScriptParser() else { + print("The JavaScript parser does not appear to be working. See Source/Fuzzilli/Compiler/Parser/README.md for instructions on how to set it up.") + exit(-1) + } + + let ast: JavaScriptParser.AST + do { + ast = try parser.parse(path) + } catch { + print("Failed to parse \(path): \(error)") + exit(-1) + } + + let compiler = JavaScriptCompiler() + let program: Program + do { + program = try compiler.compile(ast) + } catch { + print("Failed to compile: \(error)") + exit(-1) + } + + print(FuzzILLifter().lift(program)) + print() + print(JavaScriptLifter(ecmaVersion: .es6).lift(program)) + + do { + let outputPath = URL(fileURLWithPath: path).deletingPathExtension().appendingPathExtension("fuzzil.protobuf") + try program.asProtobuf().serializedData().write(to: outputPath) + print("FuzzIL program written to \(outputPath.relativePath)") + } catch { + print("Failed to store output program to disk: \(error)") + exit(-1) + } +} + else { print("Invalid option: \(args.unusedOptionals.first!)") exit(-1) diff --git a/Sources/Fuzzilli/Base/ProgramBuilder.swift b/Sources/Fuzzilli/Base/ProgramBuilder.swift index 43bbb23d..b087fe18 100644 --- a/Sources/Fuzzilli/Base/ProgramBuilder.swift +++ b/Sources/Fuzzilli/Base/ProgramBuilder.swift @@ -1629,7 +1629,7 @@ public class ProgramBuilder { body(Array(instr.innerOutputs)) b.emit(EndClassStaticMethod()) } - + public func addStaticGetter(for name: String, _ body: (_ this: Variable) -> ()) { let instr = b.emit(BeginClassStaticGetter(propertyName: name)) body(instr.innerOutput) @@ -1923,13 +1923,21 @@ public class ProgramBuilder { return instr.output } - public func doReturn(_ value: Variable) { - emit(Return(), withInputs: [value]) + public func doReturn(_ value: Variable? = nil) { + if let returnValue = value { + emit(Return(hasReturnValue: true), withInputs: [returnValue]) + } else { + emit(Return(hasReturnValue: false)) + } } @discardableResult - public func yield(_ value: Variable) -> Variable { - return emit(Yield(), withInputs: [value]).output + public func yield(_ value: Variable? = nil) -> Variable { + if let argument = value { + return emit(Yield(hasArgument: true), withInputs: [argument]).output + } else { + return emit(Yield(hasArgument: false)).output + } } public func yieldEach(_ value: Variable) { @@ -2051,8 +2059,8 @@ public class ProgramBuilder { emit(DefineNamedVariable(name), withInputs: [value]) } - public func eval(_ string: String, with arguments: [Variable] = []) { - emit(Eval(string, numArguments: arguments.count), withInputs: arguments) + public func eval(_ string: String, with arguments: [Variable] = [], hasOutput: Bool = false) { + emit(Eval(string, numArguments: arguments.count, hasOutput: hasOutput), withInputs: arguments) } public func buildWith(_ scopeObject: Variable, body: () -> Void) { diff --git a/Sources/Fuzzilli/CodeGen/CodeGenerators.swift b/Sources/Fuzzilli/CodeGen/CodeGenerators.swift index 291b3c50..49eed11c 100644 --- a/Sources/Fuzzilli/CodeGen/CodeGenerators.swift +++ b/Sources/Fuzzilli/CodeGen/CodeGenerators.swift @@ -892,14 +892,23 @@ public let CodeGenerators: [CodeGenerator] = [ CodeGenerator("SubroutineReturnGenerator", inContext: .subroutine, input: .anything) { b, val in assert(b.context.contains(.subroutine)) - b.doReturn(val) + if probability(0.9) { + b.doReturn(val) + } else { + b.doReturn() + } }, CodeGenerator("YieldGenerator", inContext: .generatorFunction, input: .anything) { b, val in assert(b.context.contains(.generatorFunction)) if probability(0.5) { - b.yield(val) + if probability(0.9) { + b.yield(val) + } else { + b.yield() + } } else { + // TODO only do this when the value is iterable? b.yieldEach(val) } }, diff --git a/Sources/Fuzzilli/Compiler/Compiler.swift b/Sources/Fuzzilli/Compiler/Compiler.swift new file mode 100644 index 00000000..03140dba --- /dev/null +++ b/Sources/Fuzzilli/Compiler/Compiler.swift @@ -0,0 +1,835 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + +/// Compiles a JavaScript AST into a FuzzIL program. +public class JavaScriptCompiler { + public typealias AST = Compiler_Protobuf_AST + typealias StatementNode = Compiler_Protobuf_Statement + typealias ExpressionNode = Compiler_Protobuf_Expression + + // Simple error enum for errors that are displayed to the user. + public enum CompilerError: Error { + case invalidASTError(String) + case invalidNodeError(String) + case unsupportedFeatureError(String) + } + + public init() {} + + /// The compiled code. + private var code = Code() + + /// The environment is used to determine if an identifier identifies a builtin object. + /// TODO we should probably use the correct target environment, with any additional builtins etc. here. But for now, we just manually add `gc` since that's relatively common. + private var environment = JavaScriptEnvironment(additionalBuiltins: ["gc": .function()]) + + /// Contains the mapping from JavaScript variables to FuzzIL variables in every active scope. + private var scopes = Stack<[String: Variable]>() + + /// List of all named variables. + /// TODO instead of a global list, this should be per (var) scope. + private var namedVariables = Set() + + /// The next free FuzzIL variable. + private var nextVariable = 0 + + public func compile(_ ast: AST) throws -> Program { + reset() + + try enterNewScope { + for statement in ast.statements { + try compileStatement(statement) + } + } + + try code.check() + + return Program(code: code) + } + + /// Allocates the next free variable. + private func nextFreeVariable() -> Variable { + let v = Variable(number: nextVariable) + nextVariable += 1 + return v + } + + private func compileStatement(_ node: StatementNode) throws { + guard let stmt = node.statement else { + throw CompilerError.invalidASTError("missing concrete statement in statement node") + } + + switch stmt { + + case .emptyStatement: + break + + case .blockStatement(let blockStatement): + emit(BeginBlockStatement()) + try enterNewScope { + for statement in blockStatement.body { + try compileStatement(statement) + } + } + emit(EndBlockStatement()) + + case .variableDeclaration(let variableDeclaration): + for decl in variableDeclaration.declarations { + let initialValue: Variable + if decl.hasValue { + initialValue = try compileExpression(decl.value) + } else { + initialValue = emit(LoadUndefined()).output + } + + if variableDeclaration.kind == .var && namedVariables.contains(decl.name) { + emit(DefineNamedVariable(decl.name), withInputs: [initialValue]) + } else { + map(decl.name, to: initialValue) + } + } + + case .functionDeclaration(let functionDeclaration): + let parameters = convertParameters(functionDeclaration.parameters) + let functionBegin, functionEnd: Operation + switch functionDeclaration.type { + case .plain: + functionBegin = BeginPlainFunction(parameters: parameters, isStrict: false) + functionEnd = EndPlainFunction() + case .generator: + functionBegin = BeginGeneratorFunction(parameters: parameters, isStrict: false) + functionEnd = EndGeneratorFunction() + case .async: + functionBegin = BeginAsyncFunction(parameters: parameters, isStrict: false) + functionEnd = EndAsyncFunction() + case .asyncGenerator: + functionBegin = BeginAsyncGeneratorFunction(parameters: parameters, isStrict: false) + functionEnd = EndAsyncGeneratorFunction() + case .UNRECOGNIZED(let type): + throw CompilerError.invalidNodeError("invalid function declaration type \(type)") + } + + let instr = emit(functionBegin) + map(functionDeclaration.name, to: instr.output) + try enterNewScope { + mapParameters(functionDeclaration.parameters, to: instr.innerOutputs) + for statement in functionDeclaration.body { + try compileStatement(statement) + } + } + emit(functionEnd) + + case .returnStatement(let returnStatement): + if returnStatement.hasArgument { + let value = try compileExpression(returnStatement.argument) + emit(Return(hasReturnValue: true), withInputs: [value]) + } else { + emit(Return(hasReturnValue: false)) + } + + case .expressionStatement(let expressionStatement): + try compileExpression(expressionStatement.expression) + + case .ifStatement(let ifStatement): + let test = try compileExpression(ifStatement.test) + emit(BeginIf(inverted: false), withInputs: [test]) + try enterNewScope { + try compileBody(ifStatement.ifBody) + } + if ifStatement.hasElseBody { + emit(BeginElse()) + try enterNewScope { + try compileBody(ifStatement.elseBody) + } + } + emit(EndIf()) + + case .whileLoop(let whileLoop): + // TODO change the IL to avoid this special handling. + if case .binaryExpression(let test) = whileLoop.test.expression, let op = Comparator(rawValue: test.operator) { + let lhs = try compileExpression(test.lhs) + let rhs = try compileExpression(test.rhs) + emit(BeginWhileLoop(comparator: op), withInputs: [lhs, rhs]) + } else { + // TODO this is probably often wrong... + let test = try compileExpression(whileLoop.test) + let True = emit(LoadBoolean(value: true)).output + emit(BeginWhileLoop(comparator: .equal), withInputs: [test, True]) + } + + try enterNewScope { + try compileBody(whileLoop.body) + } + + emit(EndWhileLoop()) + + case .doWhileLoop(let doWhileLoop): + // TODO change the IL to avoid this special handling. + if case .binaryExpression(let test) = doWhileLoop.test.expression, let op = Comparator(rawValue: test.operator) { + let lhs = try compileExpression(test.lhs) + let rhs = try compileExpression(test.rhs) + emit(BeginDoWhileLoop(comparator: op), withInputs: [lhs, rhs]) + } else { + // TODO this is probably often wrong... + let test = try compileExpression(doWhileLoop.test) + let True = emit(LoadBoolean(value: true)).output + emit(BeginDoWhileLoop(comparator: .equal), withInputs: [test, True]) + } + + try enterNewScope { + try compileBody(doWhileLoop.body) + } + + emit(EndDoWhileLoop()) + + case .forLoop(let forLoop): + // TODO change the IL to avoid this special handling. + + // Process initializer. + let initializer = forLoop.init_p; + guard initializer.hasValue else { + throw CompilerError.invalidNodeError("Expected an initial value in the for loop initializer") + } + let start = try compileExpression(initializer.value) + + // Process test expression. + guard case .binaryExpression(let test) = forLoop.test.expression, let comparator = Comparator(rawValue: test.operator) else { + throw CompilerError.invalidNodeError("Expected a comparison as part of the test of a for loop") + } + guard case .identifier(let identifier) = test.lhs.expression else { + throw CompilerError.invalidNodeError("Expected an identifier as lhs of the test expression in a for loop") + } + guard identifier.name == initializer.name else { + throw CompilerError.invalidNodeError("Expected the lhs of the test expression in a for loop to be the loop variable") + } + let end = try compileExpression(test.rhs) + + // Process update expression. + guard case .updateExpression(let update) = forLoop.update.expression else { + throw CompilerError.invalidNodeError("Expected an update expression as final part of a for loop") + } + guard case .identifier(let identifier) = update.argument.expression else { + throw CompilerError.invalidNodeError("Expected an identifier as argument to the update expression in a for loop") + } + guard identifier.name == initializer.name else { + throw CompilerError.invalidNodeError("Expected the update expression in a for loop to update the loop variable") + } + let one = emit(LoadInteger(value: 1)).output + let op: BinaryOperator + switch update.operator { + case "++": + op = .Add + case "--": + op = .Sub + default: + throw CompilerError.invalidNodeError("Unexpected operator in for loop update: \(update.operator)") + } + + let loopVar = emit(BeginForLoop(comparator: comparator, op: op), withInputs: [start, end, one]).innerOutput + try enterNewScope { + map(initializer.name, to: loopVar) + try compileBody(forLoop.body) + } + + emit(EndForLoop()) + + case .forInLoop(let forInLoop): + let initializer = forInLoop.left; + guard !initializer.hasValue else { + throw CompilerError.invalidNodeError("Expected no initial value for the variable declared in a for-in loop") + } + + let obj = try compileExpression(forInLoop.right) + + let loopVar = emit(BeginForInLoop(), withInputs: [obj]).innerOutput + try enterNewScope { + map(initializer.name, to: loopVar) + try compileBody(forInLoop.body) + } + + emit(EndForInLoop()) + + case .forOfLoop(let forOfLoop): + let initializer = forOfLoop.left; + guard !initializer.hasValue else { + throw CompilerError.invalidNodeError("Expected no initial value for the variable declared in a for-of loop") + } + + let obj = try compileExpression(forOfLoop.right) + + let loopVar = emit(BeginForOfLoop(), withInputs: [obj]).innerOutput + try enterNewScope { + map(initializer.name, to: loopVar) + try compileBody(forOfLoop.body) + } + + emit(EndForOfLoop()) + + case .tryStatement(let tryStatement): + emit(BeginTry()) + try enterNewScope { + for statement in tryStatement.body { + try compileStatement(statement) + } + } + if tryStatement.hasCatch { + try enterNewScope { + let beginCatch = emit(BeginCatch()) + if tryStatement.catch.hasParameter { + map(tryStatement.catch.parameter.name, to: beginCatch.innerOutput) + } + for statement in tryStatement.catch.body { + try compileStatement(statement) + } + } + } + if tryStatement.hasFinally { + try enterNewScope { + emit(BeginFinally()) + for statement in tryStatement.finally.body { + try compileStatement(statement) + } + } + } + emit(EndTryCatchFinally()) + + case .throwStatement(let throwStatement): + let value = try compileExpression(throwStatement.argument) + emit(ThrowException(), withInputs: [value]) + + } + } + + // This is essentially the same as compileStatement except that it skips a top-level BlockStatement: + // For example, the body of a loop is a single statement. If the body consists of multiple statements + // then the "top-level" statement is a BlockStatement. When compiling such code to FuzzIL, that + // top-level BlockStatement should be skipped as it would otherwise turn into a separate Begin/EndBlock. + // This does not modify the current scope, the caller is expected to do that. + private func compileBody(_ statement: StatementNode) throws { + if case .blockStatement(let blockStatement) = statement.statement { + for statement in blockStatement.body { + try compileStatement(statement) + } + } else { + try compileStatement(statement) + } + } + + @discardableResult + private func compileExpression(_ node: ExpressionNode) throws -> Variable { + guard let expr = node.expression else { + throw CompilerError.invalidASTError("missing concrete expression in expression node") + } + + switch expr { + + case .identifier(let identifier): + // Identifiers can generally turn into one of three things: + // 1. A FuzzIL variable that has previously been associated with the identifier + // 2. A LoadBuiltin operation if the identifier belongs to a builtin object (as defined by the environment) + // 3. A LoadNamedVariable operation in all other cases (typically global or hoisted variables, but could also be properties in a with statement) + + // We currently fall-back to case 3 if none of the other works. However, this isn't quite correct as it would incorrectly deal with e.g. + // + // let v = 42; + // function foo() { + // v = 5; + // var v = 3; + // } + // foo() + // + // As the `v = 5` would end up changing the outer variable. + // TODO To deal with this correctly, we'd have to walk over the AST twice. + + // Case 1 + if let v = lookupIdentifier(identifier.name) { + return v + } + + // Case 2 + if environment.builtins.contains(identifier.name) { + return emit(LoadBuiltin(builtinName: identifier.name)).output + } + + // Case 3 + // In this case, we need to remember that this variable was accessed in the current scope. + // If the variable access is hoisted, and the variable is defined later, then this allows + // the variable definition to turn into a DefineNamedVariable operation. + namedVariables.insert(identifier.name) + return emit(LoadNamedVariable(identifier.name)).output + + case .numberLiteral(let literal): + if let intValue = Int64(exactly: literal.value) { + return emit(LoadInteger(value: intValue)).output + } else { + return emit(LoadFloat(value: literal.value)).output + } + + case .bigIntLiteral(let literal): + if let intValue = Int64(literal.value) { + return emit(LoadBigInt(value: intValue)).output + } else { + // TODO should LoadBigInt support larger integer values (represented as string)? + let stringValue = emit(LoadString(value: literal.value)).output + let BigInt = emit(LoadBuiltin(builtinName: "BigInt")).output + return emit(CallFunction(numArguments: 1), withInputs: [BigInt, stringValue]).output + } + + case .stringLiteral(let literal): + let value = literal.value.replacingOccurrences(of: "\n", with: "\\n") + return emit(LoadString(value: value)).output + + case .regExpLiteral(let literal): + guard let flags = RegExpFlags.fromString(literal.flags) else { + throw CompilerError.invalidNodeError("invalid RegExp flags: \(literal.flags)") + } + return emit(LoadRegExp(pattern: literal.pattern, flags: flags)).output + + case .booleanLiteral(let literal): + return emit(LoadBoolean(value: literal.value)).output + + case .nullLiteral: + return emit(LoadNull()).output + + case .thisExpression: + return emit(LoadThis()).output + + case .assignmentExpression(let assignmentExpression): + guard let lhs = assignmentExpression.lhs.expression else { + throw CompilerError.invalidNodeError("Missing lhs in assignment expression") + } + let rhs = try compileExpression(assignmentExpression.rhs) + + let assignmentOperator: BinaryOperator? + switch assignmentExpression.operator { + case "=": + assignmentOperator = nil + default: + // It's something like "+=", "-=", etc. + let binaryOperator = String(assignmentExpression.operator.dropLast()) + guard let op = BinaryOperator(rawValue: binaryOperator) else { + throw CompilerError.invalidNodeError("Unknown assignment operator \(assignmentExpression.operator)") + } + assignmentOperator = op + } + + switch lhs { + + case .memberExpression(let memberExpression): + // Compile to a Set- or Update{Property/Element/ComputedProperty} operation + let object = try compileExpression(memberExpression.object) + guard let property = memberExpression.property else { throw CompilerError.invalidNodeError("missing property in member expression") } + switch property { + case .name(let name): + if let op = assignmentOperator { + emit(UpdateProperty(propertyName: name, operator: op), withInputs: [object, rhs]) + } else { + emit(SetProperty(propertyName: name), withInputs: [object, rhs]) + } + case .expression(let expr): + if case .numberLiteral(let literal) = expr.expression, let index = Int64(exactly: literal.value) { + if let op = assignmentOperator { + emit(UpdateElement(index: index, operator: op), withInputs: [object, rhs]) + } else { + emit(SetElement(index: index), withInputs: [object, rhs]) + } + } else { + let property = try compileExpression(expr) + if let op = assignmentOperator { + emit(UpdateComputedProperty(operator: op), withInputs: [object, property, rhs]) + } else { + emit(SetComputedProperty(), withInputs: [object, property, rhs]) + } + } + } + + + case .identifier(let identifier): + if let lhs = lookupIdentifier(identifier.name) { + // Compile to a Reassign or Update operation + switch assignmentExpression.operator { + case "=": + emit(Reassign(), withInputs: [lhs, rhs]) + default: + // It's something like "+=", "-=", etc. + let binaryOperator = String(assignmentExpression.operator.dropLast()) + guard let op = BinaryOperator(rawValue: binaryOperator) else { + throw CompilerError.invalidNodeError("Unknown assignment operator \(assignmentExpression.operator)") + } + emit(Update(op), withInputs: [lhs, rhs]) + } + } else { + // It's (probably) a hoisted or a global variable access. Compile as a named variable. + switch assignmentExpression.operator { + case "=": + emit(StoreNamedVariable(identifier.name), withInputs: [rhs]) + default: + // It's something like "+=", "-=", etc. + let binaryOperator = String(assignmentExpression.operator.dropLast()) + guard let op = BinaryOperator(rawValue: binaryOperator) else { + throw CompilerError.invalidNodeError("Unknown assignment operator \(assignmentExpression.operator)") + } + let oldVal = emit(LoadNamedVariable(identifier.name)).output + let newVal = emit(BinaryOperation(op), withInputs: [oldVal, rhs]).output + emit(StoreNamedVariable(identifier.name), withInputs: [newVal]) + } + } + + default: + throw CompilerError.unsupportedFeatureError("Compiler only supports assignments to object members or identifiers") + } + + return rhs + + case .objectExpression(let objectExpression): + // The expressions for property values and computed properties need to be emitted before the object literal is opened. + var propertyValues = [Variable]() + var computedPropertyKeys = [Variable]() + for field in objectExpression.fields { + guard let field = field.field else { + throw CompilerError.invalidNodeError("missing concrete field in object expression") + } + if case .property(let property) = field { + propertyValues.append(try compileExpression(property.value)) + if case .expression(let expression) = property.key { + computedPropertyKeys.append(try compileExpression(expression)) + } + } + } + + // Reverse the arrays since we'll remove the elements in FIFO order. + propertyValues.reverse() + computedPropertyKeys.reverse() + + // Now build the object literal. + emit(BeginObjectLiteral()) + for field in objectExpression.fields { + switch field.field! { + case .property(let property): + guard let key = property.key else { + throw CompilerError.invalidNodeError("missing key in object expression field") + } + let inputs = [propertyValues.removeLast()] + switch key { + case .name(let name): + emit(ObjectLiteralAddProperty(propertyName: name), withInputs: inputs) + case .index(let index): + emit(ObjectLiteralAddElement(index: index), withInputs: inputs) + case .expression: + emit(ObjectLiteralAddComputedProperty(), withInputs: [computedPropertyKeys.removeLast()] + inputs) + } + case .method(let method): + let parameters = convertParameters(method.parameters) + let instr = emit(BeginObjectLiteralMethod(methodName: method.name, parameters: parameters)) + try enterNewScope { + // Ignore the explicit |this| parameter. + let parameterVariables = instr.innerOutputs.dropFirst() + mapParameters(method.parameters, to: parameterVariables) + for statement in method.body { + try compileStatement(statement) + } + } + emit(EndObjectLiteralMethod()) + case .getter(let getter): + emit(BeginObjectLiteralGetter(propertyName: getter.name)) + try enterNewScope { + for statement in getter.body { + try compileStatement(statement) + } + } + emit(EndObjectLiteralGetter()) + case .setter(let setter): + let instr = emit(BeginObjectLiteralSetter(propertyName: setter.name)) + try enterNewScope { + // Ignore the explicit |this| parameter. + let parameterVariables = instr.innerOutputs.dropFirst() + mapParameters([setter.parameter], to: parameterVariables) + for statement in setter.body { + try compileStatement(statement) + } + } + emit(EndObjectLiteralSetter()) + } + } + return emit(EndObjectLiteral()).output + + case .arrayExpression(let arrayExpression): + var elements = [Variable]() + var undefined: Variable? = nil + for elem in arrayExpression.elements { + if elem.expression == nil { + if undefined == nil { + undefined = emit(LoadUndefined()).output + } + elements.append(undefined!) + } else { + elements.append(try compileExpression(elem)) + } + } + return emit(CreateArray(numInitialValues: elements.count), withInputs: elements).output + + case .functionExpression(let functionExpression): + let parameters = convertParameters(functionExpression.parameters) + let functionBegin, functionEnd: Operation + switch functionExpression.type { + case .plain: + functionBegin = BeginPlainFunction(parameters: parameters, isStrict: false) + functionEnd = EndPlainFunction() + case .generator: + functionBegin = BeginGeneratorFunction(parameters: parameters, isStrict: false) + functionEnd = EndGeneratorFunction() + case .async: + functionBegin = BeginAsyncFunction(parameters: parameters, isStrict: false) + functionEnd = EndAsyncFunction() + case .asyncGenerator: + functionBegin = BeginAsyncGeneratorFunction(parameters: parameters, isStrict: false) + functionEnd = EndAsyncGeneratorFunction() + case .UNRECOGNIZED(let type): + throw CompilerError.invalidNodeError("invalid function declaration type \(type)") + } + + let instr = emit(functionBegin) + try enterNewScope { + mapParameters(functionExpression.parameters, to: instr.innerOutputs) + for statement in functionExpression.body { + try compileStatement(statement) + } + } + emit(functionEnd) + + return instr.output + + case .arrowFunctionExpression(let arrowFunction): + let parameters = convertParameters(arrowFunction.parameters) + let functionBegin, functionEnd: Operation + switch arrowFunction.type { + case .plain: + functionBegin = BeginArrowFunction(parameters: parameters, isStrict: false) + functionEnd = EndArrowFunction() + case .async: + functionBegin = BeginAsyncArrowFunction(parameters: parameters, isStrict: false) + functionEnd = EndAsyncArrowFunction() + default: + throw CompilerError.invalidNodeError("invalid arrow function type \(arrowFunction.type)") + } + + let instr = emit(functionBegin) + try enterNewScope { + mapParameters(arrowFunction.parameters, to: instr.innerOutputs) + guard let body = arrowFunction.body else { throw CompilerError.invalidNodeError("missing body in arrow function") } + switch body { + case .block(let block): + try compileStatement(block) + case .expression(let expr): + let result = try compileExpression(expr) + emit(Return(hasReturnValue: true), withInputs: [result]) + } + } + emit(functionEnd) + + return instr.output + + case .callExpression(let callExpression): + let (arguments, spreads) = try compileCallArguments(callExpression.arguments) + let isSpreading = spreads.contains(true) + + // See if this is a function or a method call + if case .memberExpression(let memberExpression) = callExpression.callee.expression { + let object = try compileExpression(memberExpression.object) + guard let property = memberExpression.property else { throw CompilerError.invalidNodeError("missing property in member expression in call expression") } + switch property { + case .name(let name): + if isSpreading { + return emit(CallMethodWithSpread(methodName: name, numArguments: arguments.count, spreads: spreads), withInputs: [object] + arguments).output + } else { + return emit(CallMethod(methodName: name, numArguments: arguments.count), withInputs: [object] + arguments).output + } + case .expression(let expr): + let method = try compileExpression(expr) + if isSpreading { + return emit(CallComputedMethodWithSpread(numArguments: arguments.count, spreads: spreads), withInputs: [object, method] + arguments).output + } else { + return emit(CallComputedMethod(numArguments: arguments.count), withInputs: [object, method] + arguments).output + } + } + // Now check if it is a V8 intrinsic function + } else if case .v8IntrinsicIdentifier(let v8Intrinsic) = callExpression.callee.expression { + guard !isSpreading else { throw CompilerError.unsupportedFeatureError("Not currently supporting spread calls to V8 intrinsics") } + let argsString = Array(repeating: "%@", count: arguments.count).joined(separator: ", ") + return emit(Eval("%\(v8Intrinsic.name)(\(argsString))", numArguments: arguments.count, hasOutput: true), withInputs: arguments).output + // Otherwise it's a regular function call + } else { + let callee = try compileExpression(callExpression.callee) + if isSpreading { + return emit(CallFunctionWithSpread(numArguments: arguments.count, spreads: spreads), withInputs: [callee] + arguments).output + } else { + return emit(CallFunction(numArguments: arguments.count), withInputs: [callee] + arguments).output + } + } + + case .newExpression(let newExpression): + let callee = try compileExpression(newExpression.callee) + let (arguments, spreads) = try compileCallArguments(newExpression.arguments) + let isSpreading = spreads.contains(true) + if isSpreading { + return emit(ConstructWithSpread(numArguments: arguments.count, spreads: spreads), withInputs: [callee] + arguments).output + } else { + return emit(Construct(numArguments: arguments.count), withInputs: [callee] + arguments).output + } + + case .memberExpression(let memberExpression): + let object = try compileExpression(memberExpression.object) + guard let property = memberExpression.property else { throw CompilerError.invalidNodeError("missing property in member expression") } + switch property { + case .name(let name): + return emit(GetProperty(propertyName: name), withInputs: [object]).output + case .expression(let expr): + if case .numberLiteral(let literal) = expr.expression, let index = Int64(exactly: literal.value) { + return emit(GetElement(index: index), withInputs: [object]).output + } else { + let property = try compileExpression(expr) + return emit(GetComputedProperty(), withInputs: [object, property]).output + } + } + + case .unaryExpression(let unaryExpression): + let argument = try compileExpression(unaryExpression.argument) + + if unaryExpression.operator == "typeof" { + return emit(TypeOf(), withInputs: [argument]).output + } + guard let op = UnaryOperator(rawValue: unaryExpression.operator) else { + throw CompilerError.invalidNodeError("invalid unary operator: \(unaryExpression.operator)") + } + return emit(UnaryOperation(op), withInputs: [argument]).output + + case .binaryExpression(let binaryExpression): + let lhs = try compileExpression(binaryExpression.lhs) + let rhs = try compileExpression(binaryExpression.rhs) + if let op = Comparator(rawValue: binaryExpression.operator) { + return emit(Compare(op), withInputs: [lhs, rhs]).output + } else if let op = BinaryOperator(rawValue: binaryExpression.operator) { + return emit(BinaryOperation(op), withInputs: [lhs, rhs]).output + } else if binaryExpression.operator == "in" { + return emit(TestIn(), withInputs: [lhs, rhs]).output + } else if binaryExpression.operator == "instanceof" { + return emit(TestInstanceOf(), withInputs: [lhs, rhs]).output + } else { + throw CompilerError.invalidNodeError("invalid binary operator: \(binaryExpression.operator)") + } + + case .updateExpression(let updateExpression): + // This is just a unary expression that modifies the argument (e.g. `++`) + let argument = try compileExpression(updateExpression.argument) + var stringOp = updateExpression.operator + if !updateExpression.isPrefix { + // The rawValue of postfix operators have an additional space at the end, which we make use of here. + stringOp += " " + } + guard let op = UnaryOperator(rawValue: stringOp) else { + throw CompilerError.invalidNodeError("invalid unary operator: \(updateExpression.operator)") + } + return emit(UnaryOperation(op), withInputs: [argument]).output + + case .yieldExpression(let yieldExpression): + let argument: Variable + if yieldExpression.hasArgument { + argument = try compileExpression(yieldExpression.argument) + return emit(Yield(hasArgument: true), withInputs: [argument]).output + } else { + return emit(Yield(hasArgument: false)).output + } + + case .spreadElement: + fatalError("SpreadElement must be handled as part of their surrounding expression") + + case .v8IntrinsicIdentifier: + fatalError("V8IntrinsicIdentifiers must be handled as part of their surrounding CallExpression") + + } + } + + @discardableResult + private func emit(_ op: Operation, withInputs inputs: [Variable] = []) -> Instruction { + assert(op.numInputs == inputs.count) + let outputs = (0.. ()) rethrows { + scopes.push([:]) + try block() + scopes.pop() + } + + private func map(_ identifier: String, to v: Variable) { + assert(scopes.top[identifier] == nil) + scopes.top[identifier] = v + } + + private func mapParameters(_ parameters: [Compiler_Protobuf_Parameter], to variables: ArraySlice) { + assert(parameters.count == variables.count) + for (param, v) in zip(parameters, variables) { + map(param.name, to: v) + } + } + + private func convertParameters(_ parameters: [Compiler_Protobuf_Parameter]) -> Parameters { + return Parameters(count: parameters.count) + } + + /// Convenience accessor for the currently active scope. + private var currentScope: [String: Variable] { + return scopes.top + } + + /// Lookup the FuzzIL variable currently mapped to the given identifier, if any. + private func lookupIdentifier(_ name: String) -> Variable? { + for scope in scopes.elementsStartingAtTop() { + if let v = scope[name] { + return v + } + } + return nil + } + + private func compileCallArguments(_ args: [ExpressionNode]) throws -> ([Variable], [Bool]) { + var variables = [Variable]() + var spreads = [Bool]() + + for expr in args { + if case .spreadElement(let spreadElement) = expr.expression { + variables.append(try compileExpression(spreadElement.argument)) + spreads.append(true) + } else { + variables.append(try compileExpression(expr)) + spreads.append(false) + } + } + + assert(variables.count == spreads.count) + return (variables, spreads) + } + + private func reset() { + code = Code() + scopes.removeAll() + nextVariable = 0 + } +} diff --git a/Sources/Fuzzilli/Compiler/Parser.swift b/Sources/Fuzzilli/Compiler/Parser.swift new file mode 100644 index 00000000..1b05494f --- /dev/null +++ b/Sources/Fuzzilli/Compiler/Parser.swift @@ -0,0 +1,91 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + +/// Parses JavaScript code into an AST. +/// +/// Frontent to the node.js/babel based parser in the Parser/ subdirectory. +public class JavaScriptParser { + public typealias AST = Compiler_Protobuf_AST + + /// The path to the node.js executable used for running the parser script. + public let nodejsExecutablePath: String + + // Simple error enum for errors that are displayed to the user. + public enum ParserError: Error { + case parsingFailed(String) + } + + /// The path to the parse.js script that implements the actual parsing using babel.js. + private let parserScriptPath: String + + public init?() { + guard let path = JavaScriptParser.findNodeJsInstallation() else { + return nil + } + self.nodejsExecutablePath = path + + // The Parser/ subdirectory is copied verbatim into the module bundle, see Package.swift. + self.parserScriptPath = Bundle.module.path(forResource: "parser", ofType: "js", inDirectory: "Parser")! + + // Check if the parser works. If not, it's likely because its node.js dependencies have not been installed. + do { + try runParserScript(withArguments: []) + } catch { + return nil + } + } + + public func parse(_ path: String) throws -> AST { + let astProtobufDefinitionPath = Bundle.module.path(forResource: "ast", ofType: "proto")! + let outputFilePath = FileManager.default.temporaryDirectory.path + "/" + UUID().uuidString + ".ast.proto" + try runParserScript(withArguments: [astProtobufDefinitionPath, path, outputFilePath]) + let data = try Data(contentsOf: URL(fileURLWithPath: outputFilePath)) + try FileManager.default.removeItem(atPath: outputFilePath) + return try AST(serializedData: data) + } + + private func runParserScript(withArguments arguments: [String]) throws { + let output = Pipe() + let task = Process() + task.standardOutput = output + task.standardError = output + task.arguments = [parserScriptPath] + arguments + task.executableURL = URL(fileURLWithPath: nodejsExecutablePath) + try task.run() + task.waitUntilExit() + + let data = output.fileHandleForReading.readDataToEndOfFile() + guard task.terminationStatus == 0 else { + throw ParserError.parsingFailed(String(data: data, encoding: .utf8)!) + } + } + + /// Looks for an executable named `node` in the $PATH and, if found, returns it. + private static func findNodeJsInstallation() -> String? { + if let pathVar = ProcessInfo.processInfo.environment["PATH"] { + var directories = pathVar.split(separator: ":") + // Also append the homebrew binary path since it may not be in $PATH, especially inside XCode. + directories.append("/opt/homebrew/bin") + for directory in directories { + let path = String(directory + "/node") + if FileManager.default.isExecutableFile(atPath: path) { + return path + } + } + } + return nil + } +} diff --git a/Sources/Fuzzilli/Compiler/Parser/README.md b/Sources/Fuzzilli/Compiler/Parser/README.md new file mode 100644 index 00000000..8ce819fa --- /dev/null +++ b/Sources/Fuzzilli/Compiler/Parser/README.md @@ -0,0 +1,7 @@ +# Parser + +Simple JavaScript parser based on babel.js to parse JavaScript code into the protobuf-based AST format used by the FuzzIL compiler. + +## Usage + +Make sure node.js is installed and in the $PATH. Then install the parser's dependencies: `npm i`. The parser can then be invoked manually as follows: `node parser.js ../../Protobuf/ast.proto code.js output.ast.proto` and will produce an AST as a protobuf. However, the parser is automatically invoked by the FuzzIL compiler, so there is usually no need to run it manually. diff --git a/Sources/Fuzzilli/Compiler/Parser/package.json b/Sources/Fuzzilli/Compiler/Parser/package.json new file mode 100644 index 00000000..5efb3368 --- /dev/null +++ b/Sources/Fuzzilli/Compiler/Parser/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "@babel/parser": "^7.20.7", + "protobufjs": "^7.1.2" + } +} diff --git a/Sources/Fuzzilli/Compiler/Parser/parser.js b/Sources/Fuzzilli/Compiler/Parser/parser.js new file mode 100644 index 00000000..ea355424 --- /dev/null +++ b/Sources/Fuzzilli/Compiler/Parser/parser.js @@ -0,0 +1,472 @@ +const Parser = require("@babel/parser"); +const protobuf = require("protobufjs"); +const fs = require('fs'); + +if (process.argv.length < 5) { + console.log(`Usage: node ${process.argv[1]} path/to/ast.proto path/to/code.js path/to/output.ast.proto`); + process.exit(0); +} + +let astProtobufDefinitionPath = process.argv[2]; +let inputFilePath = process.argv[3]; +let outputFilePath = process.argv[4]; + +function assert(cond, msg) { + if (!cond) { + if (typeof msg !== 'undefined') { + throw "Assertion failed: " + msg; + } else { + throw "Assertion failed"; + } + } +} + +function tryReadFile(path) { + let content; + try { + content = fs.readFileSync(path, 'utf8').toString(); + } catch(err) { + console.log(`Couldn't read ${path}: ${err}`); + process.exit(-1); + } + return content; +} + +// Parse the given JavaScript script and return an AST compatible with Fuzzilli's protobuf-based AST format. +function parse(script, proto) { + let ast = Parser.parse(script, { plugins: ["v8intrinsic"] }); + + function assertNoError(err) { + if (err) throw err; + } + + function dump(node) { + console.log(JSON.stringify(node, null, 2)); + } + + function visitProgram(node) { + const AST = proto.lookupType('compiler.protobuf.AST'); + let program = {statements: []}; + for (let child of node.body) { + program.statements.push(visitStatement(child)); + } + assertNoError(AST.verify(program)); + return AST.create(program); + } + + // Helper function to turn misc. object into their corresponding protobuf message. + function make(name, obj) { + let Proto = proto.lookupType('compiler.protobuf.' + name); + assertNoError(Proto.verify(obj)); + return Proto.create(obj); + } + + // Helper function to turn object nodes into their corresponding protobuf message. + const Statement = proto.lookupType('compiler.protobuf.Statement'); + function makeStatement(name, node) { + let Proto = proto.lookupType('compiler.protobuf.' + name); + let fieldName = name.charAt(0).toLowerCase() + name.slice(1); + assertNoError(Proto.verify(node)); + let statement = {[fieldName]: Proto.create(node)}; + assertNoError(Statement.verify(statement)); + return Statement.create(statement); + } + + function visitParameter(param) { + assert(param.type == 'Identifier'); + return make('Parameter', { name: param.name }); + } + + function visitStatement(node) { + switch (node.type) { + case 'EmptyStatement': { + return makeStatement('EmptyStatement', {}); + } + case 'BlockStatement': { + let body = []; + for (let stmt of node.body) { + body.push(visitStatement(stmt)); + } + return makeStatement('BlockStatement', {body}); + } + case 'ExpressionStatement': { + let expr = visitExpression(node.expression); + return makeStatement('ExpressionStatement', {expression: expr}); + } + case 'VariableDeclaration': { + let kind; + if (node.kind === "var") { + kind = 0; + } else if (node.kind === "let") { + kind = 1; + } else if (node.kind === "const") { + kind = 2; + } else { + throw "Unknown variable declaration kind: " + node.kind; + } + + let declarations = []; + for (let decl of node.declarations) { + assert(decl.type === 'VariableDeclarator', "Expected variable declarator nodes inside variable declaration, found " + decl.type); + let outDecl = {name: decl.id.name}; + if (decl.init !== null) { + outDecl.value = visitExpression(decl.init); + } + declarations.push(make('VariableDeclarator', outDecl)); + } + + return makeExpression('VariableDeclaration', { kind, declarations }); + } + case 'FunctionDeclaration': { + assert(node.id.type === 'Identifier', "Expected an identifier as function declaration name"); + let name = node.id.name; + let type = 0; //"PLAIN"; + if (node.generator && node.async) { + type = 3; //"ASYNC_GENERATOR"; + } else if (node.generator) { + type = 1; //"GENERATOR"; + } else if (node.async) { + type = 2; //"ASYNC"; + } + let parameters = node.params.map(visitParameter); + assert(node.body.type === 'BlockStatement', "Expected block statement as function declaration body, found " + node.body.type); + let body = node.body.body.map(visitStatement); + return makeStatement('FunctionDeclaration', { name, type, parameters, body }); + } + case 'ReturnStatement': { + if (node.argument !== null) { + return makeStatement('ReturnStatement', { argument: visitExpression(node.argument) }); + } else { + return makeStatement('ReturnStatement', {}); + } + } + case 'IfStatement': { + let ifStmt = {}; + ifStmt.test = visitExpression(node.test); + ifStmt.ifBody = visitStatement(node.consequent); + if (node.alternate !== null) { + ifStmt.elseBody = visitStatement(node.alternate); + } + return makeStatement('IfStatement', ifStmt); + } + case 'WhileStatement': { + let whileLoop = {}; + whileLoop.test = visitExpression(node.test); + whileLoop.body = visitStatement(node.body); + return makeStatement('WhileLoop', whileLoop); + } + case 'DoWhileStatement': { + let doWhileLoop = {}; + doWhileLoop.test = visitExpression(node.test); + doWhileLoop.body = visitStatement(node.body); + return makeStatement('DoWhileLoop', doWhileLoop); + } + case 'ForStatement': { + assert(node.init !== null, "Expected for loop with initializer") + assert(node.test !== null, "Expected for loop with test expression") + assert(node.update !== null, "Expected for loop with update expression") + assert(node.init.type === 'VariableDeclaration', "Expected variable declaration as init part of a for loop, found " + node.init.type); + assert(node.init.declarations.length === 1, "Expected exactly one variable declaration in the init part of a for loop"); + let decl = node.init.declarations[0]; + let forLoop = {}; + let initDecl = { name: decl.id.name }; + if (decl.init !== null) { + initDecl.value = visitExpression(decl.init); + } + forLoop.init = make('VariableDeclarator', initDecl); + forLoop.test = visitExpression(node.test); + forLoop.update = visitExpression(node.update); + forLoop.body = visitStatement(node.body); + return makeStatement('ForLoop', forLoop); + } + case 'ForInStatement': { + assert(node.left.type === 'VariableDeclaration', "Expected variable declaration as init part of a for-in loop, found " + node.left.type); + assert(node.left.declarations.length === 1, "Expected exactly one variable declaration in the init part of a for-in loop"); + let decl = node.left.declarations[0]; + let forInLoop = {}; + let initDecl = { name: decl.id.name }; + assert(decl.init == null, "Expected no initial value for the variable declared as part of a for-in loop") + forInLoop.left = make('VariableDeclarator', initDecl); + forInLoop.right = visitExpression(node.right); + forInLoop.body = visitStatement(node.body); + return makeStatement('ForInLoop', forInLoop); + } + case 'ForOfStatement': { + assert(node.left.type === 'VariableDeclaration', "Expected variable declaration as init part of a for-in loop, found " + node.left.type); + assert(node.left.declarations.length === 1, "Expected exactly one variable declaration in the init part of a for-in loop"); + let decl = node.left.declarations[0]; + let forOfLoop = {}; + let initDecl = { name: decl.id.name }; + assert(decl.init == null, "Expected no initial value for the variable declared as part of a for-in loop") + forOfLoop.left = make('VariableDeclarator', initDecl); + forOfLoop.right = visitExpression(node.right); + forOfLoop.body = visitStatement(node.body); + return makeStatement('ForOfLoop', forOfLoop); + } + case 'TryStatement': { + assert(node.block.type === 'BlockStatement', "Expected block statement as body of a try block"); + let tryStatement = {} + tryStatement.body = node.block.body.map(visitStatement); + assert(node.handler !== null || node.finalizer !== null, "TryStatements require either a handler or a finalizer (or both)") + if (node.handler !== null) { + assert(node.handler.type === 'CatchClause', "Expected catch clause as try handler"); + assert(node.handler.body.type === 'BlockStatement', "Expected block statement as body of a catch block"); + let catchClause = {}; + if (node.handler.param !== null) { + catchClause.parameter = visitParameter(node.handler.param); + } + catchClause.body = node.handler.body.body.map(visitStatement); + tryStatement.catch = make('CatchClause', catchClause); + } + if (node.finalizer !== null) { + assert(node.finalizer.type === 'BlockStatement', "Expected block statement as body of finally block"); + let finallyClause = {}; + finallyClause.body = node.finalizer.body.map(visitStatement); + tryStatement.finally = make('FinallyClause', finallyClause); + } + return makeStatement('TryStatement', tryStatement); + } + case 'ThrowStatement': { + return makeStatement('ThrowStatement', { argument: visitExpression(node.argument) }); + } + default: { + throw "Unhandled node type " + node.type; + } + } + } + + // Helper function to turn object nodes into their corresponding protobuf message. + const Expression = proto.lookupType('compiler.protobuf.Expression'); + function makeExpression(name, node) { + let Proto = proto.lookupType('compiler.protobuf.' + name); + let fieldName = name.charAt(0).toLowerCase() + name.slice(1); + assertNoError(Proto.verify(node)); + let expression = { [fieldName]: Proto.create(node) }; + assertNoError(Expression.verify(expression)); + return Expression.create(expression); + } + + function visitExpression(node) { + const Expression = proto.lookupType('compiler.protobuf.Expression'); + switch (node.type) { + case 'Identifier': { + return makeExpression('Identifier', { name: node.name }); + } + case 'NumericLiteral': { + return makeExpression('NumberLiteral', { value: node.value }); + } + case 'BigIntLiteral': { + return makeExpression('BigIntLiteral', { value: node.value }); + } + case 'StringLiteral': { + return makeExpression('StringLiteral', { value: node.value }); + } + case 'RegExpLiteral': { + return makeExpression('RegExpLiteral', { pattern: node.pattern, flags: node.flags }); + } + case 'BooleanLiteral': { + return makeExpression('BooleanLiteral', { value: node.value }); + } + case 'NullLiteral': { + return makeExpression('NullLiteral', {}); + } + case 'ThisExpression': { + return makeExpression('ThisExpression', {}); + } + case 'AssignmentExpression': { + let operator = node.operator; + let lhs = visitExpression(node.left); + let rhs = visitExpression(node.right); + return makeExpression('AssignmentExpression', { operator, lhs, rhs }); + } + case 'ObjectExpression': { + let fields = []; + for (let property of node.properties) { + if (property.type === 'ObjectProperty') { + assert(!property.method); + if (property.computed) { + let expression = visitExpression(property.key); + let value = visitExpression(property.value); + property = make('ObjectProperty', { expression, value }); + fields.push(make('ObjectField', { property })); + } else { + if (property.key.type === 'Identifier') { + let name = property.key.name; + let value = visitExpression(property.value); + property = make('ObjectProperty', { name, value }); + fields.push(make('ObjectField', { property })); + } else if (property.key.type === 'NumericLiteral') { + let index = property.key.value; + let value = visitExpression(property.value); + property = make('ObjectProperty', { index, value }); + fields.push(make('ObjectField', { property })); + } else { + throw "Unknown property key type: " + property.key.type; + } + } + } else { + assert(property.type === 'ObjectMethod'); + let method = property; + assert(!method.shorthand); + assert(!method.computed); + assert(method.key.type === 'Identifier'); + let name = method.key.name; + if (method.kind === 'method') { + assert(method.body.type === 'BlockStatement'); + let type = 0; //"PLAIN"; + if (method.generator && method.async) { + type = 3; //"ASYNC_GENERATOR"; + } else if (method.generator) { + type = 1; //"GENERATOR"; + } else if (method.async) { + type = 2; //"ASYNC"; + } + let parameters = method.params.map(visitParameter); + let body = method.body.body.map(visitStatement); + method = make('ObjectMethod', { name, type, parameters, body }); + fields.push(make('ObjectField', { method })); + } else if (method.kind === 'get') { + assert(method.params.length === 0); + assert(!method.generator && !method.async); + assert(method.body.type === 'BlockStatement'); + let body = method.body.body.map(visitStatement); + let getter = make('ObjectGetter', { name, body }); + fields.push(make('ObjectField', { getter })); + } else if (method.kind === 'set') { + assert(method.params.length === 1); + assert(!method.generator && !method.async); + assert(method.body.type === 'BlockStatement'); + let parameter = visitParameter(method.params[0]); + let body = method.body.body.map(visitStatement); + let setter = make('ObjectSetter', { name, parameter, body }); + fields.push(make('ObjectField', { setter })); + } else { + throw "Unknown method kind: " + method.kind; + } + } + } + return makeExpression('ObjectExpression', { fields }); + } + case 'ArrayExpression': { + let elements = []; + for (let elem of node.elements) { + if (elem == null) { + // Empty expressions indicate holes. + elements.push(Expression.create({})); + } else { + elements.push(visitExpression(elem)); + } + } + return makeExpression('ArrayExpression', { elements }); + } + case 'FunctionExpression': { + let type = 0; //"PLAIN"; + if (node.generator && node.async) { + type = 3; //"ASYNC_GENERATOR"; + } else if (node.generator) { + type = 1; //"GENERATOR"; + } else if (node.async) { + type = 2; //"ASYNC"; + } + let parameters = node.params.map(visitParameter); + assert(node.body.type === 'BlockStatement', "Expected block statement as function expression body, found " + node.body.type); + let body = node.body.body.map(visitStatement); + return makeExpression('FunctionExpression', { type, parameters, body }); + } + case 'ArrowFunctionExpression': { + assert(node.id == null); + assert(node.generator == false); + let type = 0; //"PLAIN"; + if (node.async) { + type = 2; //"ASYNC"; + } + let parameters = node.params.map(visitParameter); + let out = { type, parameters }; + if (node.body.type === 'BlockStatement') { + out.block = visitStatement(node.body); + } else { + out.expression = visitExpression(node.body); + } + return makeExpression('ArrowFunctionExpression', out); + } + case 'CallExpression': { + let callee = visitExpression(node.callee); + let arguments = node.arguments.map(visitExpression); + return makeExpression('CallExpression', { callee, arguments }); + } + case 'NewExpression': { + let callee = visitExpression(node.callee); + let arguments = node.arguments.map(visitExpression); + return makeExpression('NewExpression', { callee, arguments }); + } + case 'MemberExpression': { + let object = visitExpression(node.object); + let out = { object }; + if (node.computed) { + out.expression = visitExpression(node.property); + } else { + assert(node.property.type === 'Identifier'); + out.name = node.property.name; + } + return makeExpression('MemberExpression', out); + } + case 'UnaryExpression': { + assert(node.prefix); + let operator = node.operator; + let argument = visitExpression(node.argument); + return makeExpression('UnaryExpression', { operator, argument }); + } + case 'BinaryExpression': + case 'LogicalExpression': { + let operator = node.operator; + let lhs = visitExpression(node.left); + let rhs = visitExpression(node.right); + return makeExpression('BinaryExpression', { operator, lhs, rhs }); + } + case 'UpdateExpression': { + let operator = node.operator; + let isPrefix = node.prefix; + let argument = visitExpression(node.argument); + return makeExpression('UpdateExpression', { operator, isPrefix, argument }); + } + case 'YieldExpression': { + assert(node.delegate == false); + if (node.argument !== null) { + let argument = visitExpression(node.argument); + return makeExpression('YieldExpression', { argument }); + } else { + return makeExpression('YieldExpression', {}); + } + } + case 'SpreadElement': { + let argument = visitExpression(node.argument); + return makeExpression('SpreadElement', { argument }); + } + case 'V8IntrinsicIdentifier': { + return makeExpression('V8IntrinsicIdentifier', { name: node.name }); + } + default: { + throw "Unhandled node type " + node.type; + } + } + } + + return visitProgram(ast.program); +} + +let script = tryReadFile(inputFilePath); + +protobuf.load(astProtobufDefinitionPath, function(err, root) { + if (err) + throw err; + + let ast = parse(script, root); + console.log(JSON.stringify(ast, null, 2)); + + const AST = root.lookupType('compiler.protobuf.AST'); + let buffer = AST.encode(ast).finish(); + + fs.writeFileSync(outputFilePath, buffer); + console.log("All done, output file @ " + outputFilePath); +}); + diff --git a/Sources/Fuzzilli/Environment/JavaScriptEnvironment.swift b/Sources/Fuzzilli/Environment/JavaScriptEnvironment.swift index 458317bd..9186445c 100644 --- a/Sources/Fuzzilli/Environment/JavaScriptEnvironment.swift +++ b/Sources/Fuzzilli/Environment/JavaScriptEnvironment.swift @@ -70,7 +70,7 @@ public class JavaScriptEnvironment: ComponentBase, Environment { // Builtin objects (ObjectGroups to be precise) that are not constructors. public let nonConstructors = ["Math", "JSON", "Reflect"] - public init(additionalBuiltins: [String: JSType], additionalObjectGroups: [ObjectGroup]) { + public init(additionalBuiltins: [String: JSType] = [:], additionalObjectGroups: [ObjectGroup] = []) { super.init(name: "JavaScriptEnvironment") // Build model of the JavaScript environment diff --git a/Sources/Fuzzilli/FuzzIL/Instruction.swift b/Sources/Fuzzilli/FuzzIL/Instruction.swift index cfd57cc4..8b80c25e 100644 --- a/Sources/Fuzzilli/FuzzIL/Instruction.swift +++ b/Sources/Fuzzilli/FuzzIL/Instruction.swift @@ -639,7 +639,10 @@ extension Instruction: ProtobufConvertible { case .defineNamedVariable(let op): $0.defineNamedVariable = Fuzzilli_Protobuf_DefineNamedVariable.with { $0.variableName = op.variableName } case .eval(let op): - $0.eval = Fuzzilli_Protobuf_Eval.with { $0.code = op.code } + $0.eval = Fuzzilli_Protobuf_Eval.with { + $0.code = op.code + $0.hasOutput_p = op.hasOutput + } case .callSuperConstructor: $0.callSuperConstructor = Fuzzilli_Protobuf_CallSuperConstructor() case .callSuperMethod(let op): @@ -990,9 +993,11 @@ extension Instruction: ProtobufConvertible { case .endConstructor: op = EndConstructor() case .return: - op = Return() + let hasReturnValue = inouts.count == 1 + op = Return(hasReturnValue: hasReturnValue) case .yield: - op = Yield() + let hasArgument = inouts.count == 2 + op = Yield(hasArgument: hasArgument) case .yieldEach: op = YieldEach() case .await: @@ -1042,7 +1047,8 @@ extension Instruction: ProtobufConvertible { case .defineNamedVariable(let p): op = DefineNamedVariable(p.variableName) case .eval(let p): - op = Eval(p.code, numArguments: inouts.count) + let numArguments = inouts.count - (p.hasOutput_p ? 1 : 0) + op = Eval(p.code, numArguments: numArguments, hasOutput: p.hasOutput_p) case .callSuperConstructor: op = CallSuperConstructor(numArguments: inouts.count) case .callSuperMethod(let p): diff --git a/Sources/Fuzzilli/FuzzIL/JSTyper.swift b/Sources/Fuzzilli/FuzzIL/JSTyper.swift index 91719ecc..f87c750c 100644 --- a/Sources/Fuzzilli/FuzzIL/JSTyper.swift +++ b/Sources/Fuzzilli/FuzzIL/JSTyper.swift @@ -686,6 +686,11 @@ public struct JSTyper: Analyzer { case .yield: set(instr.output, .unknown) + case .eval: + if instr.hasOneOutput { + set(instr.output, .unknown) + } + case .beginPlainFunction(let op as BeginAnyFunction), .beginArrowFunction(let op as BeginAnyFunction), .beginGeneratorFunction(let op as BeginAnyFunction), diff --git a/Sources/Fuzzilli/FuzzIL/JsOperations.swift b/Sources/Fuzzilli/FuzzIL/JsOperations.swift index 2e91afdf..7cd34175 100644 --- a/Sources/Fuzzilli/FuzzIL/JsOperations.swift +++ b/Sources/Fuzzilli/FuzzIL/JsOperations.swift @@ -124,6 +124,29 @@ public struct RegExpFlags: OptionSet, Hashable { return strRepr } + public static func fromString(_ str: String) -> RegExpFlags? { + var flags = RegExpFlags() + for c in str { + switch c { + case "i": + flags.formUnion(.caseInsensitive) + case "g": + flags.formUnion(.global) + case "m": + flags.formUnion(.multiline) + case "s": + flags.formUnion(.dotall) + case "u": + flags.formUnion(.unicode) + case "y": + flags.formUnion(.sticky) + default: + return nil + } + } + return flags + } + static let caseInsensitive = RegExpFlags(rawValue: 1 << 0) static let global = RegExpFlags(rawValue: 1 << 1) static let multiline = RegExpFlags(rawValue: 1 << 2) @@ -1072,8 +1095,13 @@ final class EndConstructor: EndAnySubroutine { final class Return: JsOperation { override var opcode: Opcode { .return(self) } - init() { - super.init(numInputs: 1, attributes: [.isJump], requiredContext: [.javascript, .subroutine]) + var hasReturnValue: Bool { + assert(numInputs == 0 || numInputs == 1) + return numInputs == 1 + } + + init(hasReturnValue: Bool) { + super.init(numInputs: hasReturnValue ? 1 : 0, attributes: [.isJump], requiredContext: [.javascript, .subroutine]) } } @@ -1081,8 +1109,13 @@ final class Return: JsOperation { final class Yield: JsOperation { override var opcode: Opcode { .yield(self) } - init() { - super.init(numInputs: 1, numOutputs: 1, attributes: [], requiredContext: [.javascript, .generatorFunction]) + var hasArgument: Bool { + assert(numInputs == 0 || numInputs == 1) + return numInputs == 1 + } + + init(hasArgument: Bool) { + super.init(numInputs: hasArgument ? 1 : 0, numOutputs: 1, attributes: [], requiredContext: [.javascript, .generatorFunction]) } } @@ -1477,9 +1510,14 @@ final class Eval: JsOperation { let code: String - init(_ string: String, numArguments: Int) { + var hasOutput: Bool { + assert(numOutputs == 0 || numOutputs == 1) + return numOutputs == 1 + } + + init(_ string: String, numArguments: Int, hasOutput: Bool) { self.code = string - super.init(numInputs: numArguments, numInnerOutputs: 0) + super.init(numInputs: numArguments, numOutputs: hasOutput ? 1 : 0) } } diff --git a/Sources/Fuzzilli/FuzzIL/TypeSystem.swift b/Sources/Fuzzilli/FuzzIL/TypeSystem.swift index 439058e1..31f15347 100644 --- a/Sources/Fuzzilli/FuzzIL/TypeSystem.swift +++ b/Sources/Fuzzilli/FuzzIL/TypeSystem.swift @@ -864,7 +864,7 @@ public struct Signature: Hashable, CustomStringConvertible { public var numParameters: Int { return parameters.count } - + public var hasRestParameter: Bool { return parameters.last?.isRestParameter ?? false } diff --git a/Sources/Fuzzilli/Lifting/FuzzILLifter.swift b/Sources/Fuzzilli/Lifting/FuzzILLifter.swift index b5a0ebeb..dfc58a0c 100644 --- a/Sources/Fuzzilli/Lifting/FuzzILLifter.swift +++ b/Sources/Fuzzilli/Lifting/FuzzILLifter.swift @@ -385,11 +385,19 @@ public class FuzzILLifter: Lifter { w.decreaseIndentionLevel() w.emit("\(op.name)") - case .return: - w.emit("Return \(input(0))") + case .return(let op): + if op.hasReturnValue { + w.emit("Return \(input(0))") + } else { + w.emit("Return") + } - case .yield: - w.emit("\(output()) <- Yield \(input(0))") + case .yield(let op): + if op.hasArgument { + w.emit("\(output()) <- Yield \(input(0))") + } else { + w.emit("\(output()) <- Yield") + } case .yieldEach: w.emit("YieldEach \(input(0))") @@ -473,7 +481,11 @@ public class FuzzILLifter: Lifter { case .eval(let op): let args = instr.inputs.map(lift).joined(separator: ", ") - w.emit("Eval '\(op.code)', [\(args)]") + if op.hasOutput { + w.emit("\(output()) <- Eval '\(op.code)', [\(args)]") + } else { + w.emit("Eval '\(op.code)', [\(args)]") + } case .explore: let arguments = instr.inputs.suffix(from: 1).map(lift).joined(separator: ", ") diff --git a/Sources/Fuzzilli/Lifting/JavaScriptLifter.swift b/Sources/Fuzzilli/Lifting/JavaScriptLifter.swift index d436c5b1..7754c9b2 100644 --- a/Sources/Fuzzilli/Lifting/JavaScriptLifter.swift +++ b/Sources/Fuzzilli/Lifting/JavaScriptLifter.swift @@ -611,12 +611,21 @@ public class JavaScriptLifter: Lifter { w.leaveCurrentBlock() w.emit("}") - case .return: - let VALUE = w.retrieve(expressionFor: instr.input(0)) - w.emit("return \(VALUE);") + case .return(let op): + if op.hasReturnValue { + let VALUE = w.retrieve(expressionFor: instr.input(0)) + w.emit("return \(VALUE);") + } else { + w.emit("return;") + } - case .yield: - let expr = YieldExpression.new() + "yield " + w.retrieve(expressionFor: instr.input(0)) + case .yield(let op): + let expr: Expression + if op.hasArgument { + expr = YieldExpression.new() + "yield " + w.retrieve(expressionFor: instr.input(0)) + } else { + expr = YieldExpression.new() + "yield" + } w.assign(expr, to: instr.output) case .yieldEach: @@ -783,7 +792,13 @@ public class JavaScriptLifter: Lifter { let range = EXPR.range(of: "%@")! EXPR.replaceSubrange(range, with: w.retrieve(expressionFor: v).text) } - w.emit("\(EXPR);") + if op.hasOutput { + let LET = w.declarationKeyword(for: instr.output) + let V = w.declare(instr.output) + w.emit("\(LET) \(V) = \(EXPR);") + } else { + w.emit("\(EXPR);") + } case .explore(let op): let EXPLORE = JavaScriptExploreHelper.exploreFunc diff --git a/Sources/Fuzzilli/Minimization/InliningReducer.swift b/Sources/Fuzzilli/Minimization/InliningReducer.swift index 51e79c19..f7912e03 100644 --- a/Sources/Fuzzilli/Minimization/InliningReducer.swift +++ b/Sources/Fuzzilli/Minimization/InliningReducer.swift @@ -211,7 +211,9 @@ struct InliningReducer: Reducer { // Returns (from the function being inlined) are converted to assignments to the return value. if instr.op is Return && functionDefinitionDepth == 0 { - c.append(Instruction(Reassign(), inputs: [rval, newInstr.input(0)])) + // Returns may not have a return value, in which case we'll use undefined. + let value = newInstr.hasInputs ? newInstr.input(0) : undefined + c.append(Instruction(Reassign(), inputs: [rval, value])) } else { c.append(newInstr) diff --git a/Sources/Fuzzilli/Minimization/PostProcessor.swift b/Sources/Fuzzilli/Minimization/PostProcessor.swift index 62dad1a6..f6b385c8 100644 --- a/Sources/Fuzzilli/Minimization/PostProcessor.swift +++ b/Sources/Fuzzilli/Minimization/PostProcessor.swift @@ -46,7 +46,7 @@ struct MinimizationPostProcessor { .endObjectLiteralGetter: // Insert return statements at the end of functions, but only if there is not one already. if lastInstr.op is Return || !b.hasVisibleVariables { break } - addedInstruction = Instruction(Return(), inputs: [b.randomVariable()]) + addedInstruction = Instruction(Return(hasReturnValue: true), inputs: [b.randomVariable()]) case .callFunction: // (Sometimes) insert random arguments, but only if there are none currently. if instr.hasAnyVariadicInputs || !b.hasVisibleVariables || probability(0.5) { break } diff --git a/Sources/Fuzzilli/Protobuf/ast.pb.swift b/Sources/Fuzzilli/Protobuf/ast.pb.swift new file mode 100644 index 00000000..8e61b1e4 --- /dev/null +++ b/Sources/Fuzzilli/Protobuf/ast.pb.swift @@ -0,0 +1,5350 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: ast.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +public enum Compiler_Protobuf_VariableDeclarationKind: SwiftProtobuf.Enum { + public typealias RawValue = Int + case `var` // = 0 + case `let` // = 1 + case const // = 2 + case UNRECOGNIZED(Int) + + public init() { + self = .var + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .var + case 1: self = .let + case 2: self = .const + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .var: return 0 + case .let: return 1 + case .const: return 2 + case .UNRECOGNIZED(let i): return i + } + } + +} + +#if swift(>=4.2) + +extension Compiler_Protobuf_VariableDeclarationKind: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [Compiler_Protobuf_VariableDeclarationKind] = [ + .var, + .let, + .const, + ] +} + +#endif // swift(>=4.2) + +public enum Compiler_Protobuf_FunctionType: SwiftProtobuf.Enum { + public typealias RawValue = Int + case plain // = 0 + case generator // = 1 + case async // = 2 + case asyncGenerator // = 3 + case UNRECOGNIZED(Int) + + public init() { + self = .plain + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .plain + case 1: self = .generator + case 2: self = .async + case 3: self = .asyncGenerator + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .plain: return 0 + case .generator: return 1 + case .async: return 2 + case .asyncGenerator: return 3 + case .UNRECOGNIZED(let i): return i + } + } + +} + +#if swift(>=4.2) + +extension Compiler_Protobuf_FunctionType: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [Compiler_Protobuf_FunctionType] = [ + .plain, + .generator, + .async, + .asyncGenerator, + ] +} + +#endif // swift(>=4.2) + +public struct Compiler_Protobuf_AST { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var statements: [Compiler_Protobuf_Statement] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// A parameter in a function declaration. Not an expression on its own. +public struct Compiler_Protobuf_Parameter { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var name: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_EmptyStatement { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_BlockStatement { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var body: [Compiler_Protobuf_Statement] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_VariableDeclarator { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var name: String { + get {return _storage._name} + set {_uniqueStorage()._name = newValue} + } + + /// The value is optional + public var value: Compiler_Protobuf_Expression { + get {return _storage._value ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._value = newValue} + } + /// Returns true if `value` has been explicitly set. + public var hasValue: Bool {return _storage._value != nil} + /// Clears the value of `value`. Subsequent reads from it will return its default value. + public mutating func clearValue() {_uniqueStorage()._value = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_VariableDeclaration { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var kind: Compiler_Protobuf_VariableDeclarationKind = .var + + public var declarations: [Compiler_Protobuf_VariableDeclarator] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_FunctionDeclaration { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var name: String = String() + + public var type: Compiler_Protobuf_FunctionType = .plain + + public var parameters: [Compiler_Protobuf_Parameter] = [] + + public var body: [Compiler_Protobuf_Statement] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_ReturnStatement { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The argument is optional + public var argument: Compiler_Protobuf_Expression { + get {return _storage._argument ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._argument = newValue} + } + /// Returns true if `argument` has been explicitly set. + public var hasArgument: Bool {return _storage._argument != nil} + /// Clears the value of `argument`. Subsequent reads from it will return its default value. + public mutating func clearArgument() {_uniqueStorage()._argument = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_ExpressionStatement { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var expression: Compiler_Protobuf_Expression { + get {return _storage._expression ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._expression = newValue} + } + /// Returns true if `expression` has been explicitly set. + public var hasExpression: Bool {return _storage._expression != nil} + /// Clears the value of `expression`. Subsequent reads from it will return its default value. + public mutating func clearExpression() {_uniqueStorage()._expression = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_IfStatement { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var test: Compiler_Protobuf_Expression { + get {return _storage._test ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._test = newValue} + } + /// Returns true if `test` has been explicitly set. + public var hasTest: Bool {return _storage._test != nil} + /// Clears the value of `test`. Subsequent reads from it will return its default value. + public mutating func clearTest() {_uniqueStorage()._test = nil} + + public var ifBody: Compiler_Protobuf_Statement { + get {return _storage._ifBody ?? Compiler_Protobuf_Statement()} + set {_uniqueStorage()._ifBody = newValue} + } + /// Returns true if `ifBody` has been explicitly set. + public var hasIfBody: Bool {return _storage._ifBody != nil} + /// Clears the value of `ifBody`. Subsequent reads from it will return its default value. + public mutating func clearIfBody() {_uniqueStorage()._ifBody = nil} + + /// The else body is optional + public var elseBody: Compiler_Protobuf_Statement { + get {return _storage._elseBody ?? Compiler_Protobuf_Statement()} + set {_uniqueStorage()._elseBody = newValue} + } + /// Returns true if `elseBody` has been explicitly set. + public var hasElseBody: Bool {return _storage._elseBody != nil} + /// Clears the value of `elseBody`. Subsequent reads from it will return its default value. + public mutating func clearElseBody() {_uniqueStorage()._elseBody = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_WhileLoop { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var test: Compiler_Protobuf_Expression { + get {return _storage._test ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._test = newValue} + } + /// Returns true if `test` has been explicitly set. + public var hasTest: Bool {return _storage._test != nil} + /// Clears the value of `test`. Subsequent reads from it will return its default value. + public mutating func clearTest() {_uniqueStorage()._test = nil} + + public var body: Compiler_Protobuf_Statement { + get {return _storage._body ?? Compiler_Protobuf_Statement()} + set {_uniqueStorage()._body = newValue} + } + /// Returns true if `body` has been explicitly set. + public var hasBody: Bool {return _storage._body != nil} + /// Clears the value of `body`. Subsequent reads from it will return its default value. + public mutating func clearBody() {_uniqueStorage()._body = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_DoWhileLoop { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var test: Compiler_Protobuf_Expression { + get {return _storage._test ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._test = newValue} + } + /// Returns true if `test` has been explicitly set. + public var hasTest: Bool {return _storage._test != nil} + /// Clears the value of `test`. Subsequent reads from it will return its default value. + public mutating func clearTest() {_uniqueStorage()._test = nil} + + public var body: Compiler_Protobuf_Statement { + get {return _storage._body ?? Compiler_Protobuf_Statement()} + set {_uniqueStorage()._body = newValue} + } + /// Returns true if `body` has been explicitly set. + public var hasBody: Bool {return _storage._body != nil} + /// Clears the value of `body`. Subsequent reads from it will return its default value. + public mutating func clearBody() {_uniqueStorage()._body = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_ForLoop { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var init_p: Compiler_Protobuf_VariableDeclarator { + get {return _storage._init_p ?? Compiler_Protobuf_VariableDeclarator()} + set {_uniqueStorage()._init_p = newValue} + } + /// Returns true if `init_p` has been explicitly set. + public var hasInit_p: Bool {return _storage._init_p != nil} + /// Clears the value of `init_p`. Subsequent reads from it will return its default value. + public mutating func clearInit_p() {_uniqueStorage()._init_p = nil} + + public var test: Compiler_Protobuf_Expression { + get {return _storage._test ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._test = newValue} + } + /// Returns true if `test` has been explicitly set. + public var hasTest: Bool {return _storage._test != nil} + /// Clears the value of `test`. Subsequent reads from it will return its default value. + public mutating func clearTest() {_uniqueStorage()._test = nil} + + public var update: Compiler_Protobuf_Expression { + get {return _storage._update ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._update = newValue} + } + /// Returns true if `update` has been explicitly set. + public var hasUpdate: Bool {return _storage._update != nil} + /// Clears the value of `update`. Subsequent reads from it will return its default value. + public mutating func clearUpdate() {_uniqueStorage()._update = nil} + + public var body: Compiler_Protobuf_Statement { + get {return _storage._body ?? Compiler_Protobuf_Statement()} + set {_uniqueStorage()._body = newValue} + } + /// Returns true if `body` has been explicitly set. + public var hasBody: Bool {return _storage._body != nil} + /// Clears the value of `body`. Subsequent reads from it will return its default value. + public mutating func clearBody() {_uniqueStorage()._body = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_ForInLoop { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var left: Compiler_Protobuf_VariableDeclarator { + get {return _storage._left ?? Compiler_Protobuf_VariableDeclarator()} + set {_uniqueStorage()._left = newValue} + } + /// Returns true if `left` has been explicitly set. + public var hasLeft: Bool {return _storage._left != nil} + /// Clears the value of `left`. Subsequent reads from it will return its default value. + public mutating func clearLeft() {_uniqueStorage()._left = nil} + + public var right: Compiler_Protobuf_Expression { + get {return _storage._right ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._right = newValue} + } + /// Returns true if `right` has been explicitly set. + public var hasRight: Bool {return _storage._right != nil} + /// Clears the value of `right`. Subsequent reads from it will return its default value. + public mutating func clearRight() {_uniqueStorage()._right = nil} + + public var body: Compiler_Protobuf_Statement { + get {return _storage._body ?? Compiler_Protobuf_Statement()} + set {_uniqueStorage()._body = newValue} + } + /// Returns true if `body` has been explicitly set. + public var hasBody: Bool {return _storage._body != nil} + /// Clears the value of `body`. Subsequent reads from it will return its default value. + public mutating func clearBody() {_uniqueStorage()._body = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_ForOfLoop { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var left: Compiler_Protobuf_VariableDeclarator { + get {return _storage._left ?? Compiler_Protobuf_VariableDeclarator()} + set {_uniqueStorage()._left = newValue} + } + /// Returns true if `left` has been explicitly set. + public var hasLeft: Bool {return _storage._left != nil} + /// Clears the value of `left`. Subsequent reads from it will return its default value. + public mutating func clearLeft() {_uniqueStorage()._left = nil} + + public var right: Compiler_Protobuf_Expression { + get {return _storage._right ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._right = newValue} + } + /// Returns true if `right` has been explicitly set. + public var hasRight: Bool {return _storage._right != nil} + /// Clears the value of `right`. Subsequent reads from it will return its default value. + public mutating func clearRight() {_uniqueStorage()._right = nil} + + public var body: Compiler_Protobuf_Statement { + get {return _storage._body ?? Compiler_Protobuf_Statement()} + set {_uniqueStorage()._body = newValue} + } + /// Returns true if `body` has been explicitly set. + public var hasBody: Bool {return _storage._body != nil} + /// Clears the value of `body`. Subsequent reads from it will return its default value. + public mutating func clearBody() {_uniqueStorage()._body = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_CatchClause { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var parameter: Compiler_Protobuf_Parameter { + get {return _parameter ?? Compiler_Protobuf_Parameter()} + set {_parameter = newValue} + } + /// Returns true if `parameter` has been explicitly set. + public var hasParameter: Bool {return self._parameter != nil} + /// Clears the value of `parameter`. Subsequent reads from it will return its default value. + public mutating func clearParameter() {self._parameter = nil} + + public var body: [Compiler_Protobuf_Statement] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _parameter: Compiler_Protobuf_Parameter? = nil +} + +public struct Compiler_Protobuf_FinallyClause { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var body: [Compiler_Protobuf_Statement] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_TryStatement { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var body: [Compiler_Protobuf_Statement] = [] + + /// The catch clause is optional + public var `catch`: Compiler_Protobuf_CatchClause { + get {return _catch ?? Compiler_Protobuf_CatchClause()} + set {_catch = newValue} + } + /// Returns true if ``catch`` has been explicitly set. + public var hasCatch: Bool {return self._catch != nil} + /// Clears the value of ``catch``. Subsequent reads from it will return its default value. + public mutating func clearCatch() {self._catch = nil} + + /// The finally clause is optional + public var finally: Compiler_Protobuf_FinallyClause { + get {return _finally ?? Compiler_Protobuf_FinallyClause()} + set {_finally = newValue} + } + /// Returns true if `finally` has been explicitly set. + public var hasFinally: Bool {return self._finally != nil} + /// Clears the value of `finally`. Subsequent reads from it will return its default value. + public mutating func clearFinally() {self._finally = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _catch: Compiler_Protobuf_CatchClause? = nil + fileprivate var _finally: Compiler_Protobuf_FinallyClause? = nil +} + +public struct Compiler_Protobuf_ThrowStatement { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var argument: Compiler_Protobuf_Expression { + get {return _storage._argument ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._argument = newValue} + } + /// Returns true if `argument` has been explicitly set. + public var hasArgument: Bool {return _storage._argument != nil} + /// Clears the value of `argument`. Subsequent reads from it will return its default value. + public mutating func clearArgument() {_uniqueStorage()._argument = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_Statement { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var statement: OneOf_Statement? { + get {return _storage._statement} + set {_uniqueStorage()._statement = newValue} + } + + public var emptyStatement: Compiler_Protobuf_EmptyStatement { + get { + if case .emptyStatement(let v)? = _storage._statement {return v} + return Compiler_Protobuf_EmptyStatement() + } + set {_uniqueStorage()._statement = .emptyStatement(newValue)} + } + + public var blockStatement: Compiler_Protobuf_BlockStatement { + get { + if case .blockStatement(let v)? = _storage._statement {return v} + return Compiler_Protobuf_BlockStatement() + } + set {_uniqueStorage()._statement = .blockStatement(newValue)} + } + + public var variableDeclaration: Compiler_Protobuf_VariableDeclaration { + get { + if case .variableDeclaration(let v)? = _storage._statement {return v} + return Compiler_Protobuf_VariableDeclaration() + } + set {_uniqueStorage()._statement = .variableDeclaration(newValue)} + } + + public var functionDeclaration: Compiler_Protobuf_FunctionDeclaration { + get { + if case .functionDeclaration(let v)? = _storage._statement {return v} + return Compiler_Protobuf_FunctionDeclaration() + } + set {_uniqueStorage()._statement = .functionDeclaration(newValue)} + } + + public var returnStatement: Compiler_Protobuf_ReturnStatement { + get { + if case .returnStatement(let v)? = _storage._statement {return v} + return Compiler_Protobuf_ReturnStatement() + } + set {_uniqueStorage()._statement = .returnStatement(newValue)} + } + + public var expressionStatement: Compiler_Protobuf_ExpressionStatement { + get { + if case .expressionStatement(let v)? = _storage._statement {return v} + return Compiler_Protobuf_ExpressionStatement() + } + set {_uniqueStorage()._statement = .expressionStatement(newValue)} + } + + public var ifStatement: Compiler_Protobuf_IfStatement { + get { + if case .ifStatement(let v)? = _storage._statement {return v} + return Compiler_Protobuf_IfStatement() + } + set {_uniqueStorage()._statement = .ifStatement(newValue)} + } + + public var whileLoop: Compiler_Protobuf_WhileLoop { + get { + if case .whileLoop(let v)? = _storage._statement {return v} + return Compiler_Protobuf_WhileLoop() + } + set {_uniqueStorage()._statement = .whileLoop(newValue)} + } + + public var doWhileLoop: Compiler_Protobuf_DoWhileLoop { + get { + if case .doWhileLoop(let v)? = _storage._statement {return v} + return Compiler_Protobuf_DoWhileLoop() + } + set {_uniqueStorage()._statement = .doWhileLoop(newValue)} + } + + public var forLoop: Compiler_Protobuf_ForLoop { + get { + if case .forLoop(let v)? = _storage._statement {return v} + return Compiler_Protobuf_ForLoop() + } + set {_uniqueStorage()._statement = .forLoop(newValue)} + } + + public var forInLoop: Compiler_Protobuf_ForInLoop { + get { + if case .forInLoop(let v)? = _storage._statement {return v} + return Compiler_Protobuf_ForInLoop() + } + set {_uniqueStorage()._statement = .forInLoop(newValue)} + } + + public var forOfLoop: Compiler_Protobuf_ForOfLoop { + get { + if case .forOfLoop(let v)? = _storage._statement {return v} + return Compiler_Protobuf_ForOfLoop() + } + set {_uniqueStorage()._statement = .forOfLoop(newValue)} + } + + public var tryStatement: Compiler_Protobuf_TryStatement { + get { + if case .tryStatement(let v)? = _storage._statement {return v} + return Compiler_Protobuf_TryStatement() + } + set {_uniqueStorage()._statement = .tryStatement(newValue)} + } + + public var throwStatement: Compiler_Protobuf_ThrowStatement { + get { + if case .throwStatement(let v)? = _storage._statement {return v} + return Compiler_Protobuf_ThrowStatement() + } + set {_uniqueStorage()._statement = .throwStatement(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Statement: Equatable { + case emptyStatement(Compiler_Protobuf_EmptyStatement) + case blockStatement(Compiler_Protobuf_BlockStatement) + case variableDeclaration(Compiler_Protobuf_VariableDeclaration) + case functionDeclaration(Compiler_Protobuf_FunctionDeclaration) + case returnStatement(Compiler_Protobuf_ReturnStatement) + case expressionStatement(Compiler_Protobuf_ExpressionStatement) + case ifStatement(Compiler_Protobuf_IfStatement) + case whileLoop(Compiler_Protobuf_WhileLoop) + case doWhileLoop(Compiler_Protobuf_DoWhileLoop) + case forLoop(Compiler_Protobuf_ForLoop) + case forInLoop(Compiler_Protobuf_ForInLoop) + case forOfLoop(Compiler_Protobuf_ForOfLoop) + case tryStatement(Compiler_Protobuf_TryStatement) + case throwStatement(Compiler_Protobuf_ThrowStatement) + + #if !swift(>=4.1) + public static func ==(lhs: Compiler_Protobuf_Statement.OneOf_Statement, rhs: Compiler_Protobuf_Statement.OneOf_Statement) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.emptyStatement, .emptyStatement): return { + guard case .emptyStatement(let l) = lhs, case .emptyStatement(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.blockStatement, .blockStatement): return { + guard case .blockStatement(let l) = lhs, case .blockStatement(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.variableDeclaration, .variableDeclaration): return { + guard case .variableDeclaration(let l) = lhs, case .variableDeclaration(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.functionDeclaration, .functionDeclaration): return { + guard case .functionDeclaration(let l) = lhs, case .functionDeclaration(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.returnStatement, .returnStatement): return { + guard case .returnStatement(let l) = lhs, case .returnStatement(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.expressionStatement, .expressionStatement): return { + guard case .expressionStatement(let l) = lhs, case .expressionStatement(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.ifStatement, .ifStatement): return { + guard case .ifStatement(let l) = lhs, case .ifStatement(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.whileLoop, .whileLoop): return { + guard case .whileLoop(let l) = lhs, case .whileLoop(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.doWhileLoop, .doWhileLoop): return { + guard case .doWhileLoop(let l) = lhs, case .doWhileLoop(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.forLoop, .forLoop): return { + guard case .forLoop(let l) = lhs, case .forLoop(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.forInLoop, .forInLoop): return { + guard case .forInLoop(let l) = lhs, case .forInLoop(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.forOfLoop, .forOfLoop): return { + guard case .forOfLoop(let l) = lhs, case .forOfLoop(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.tryStatement, .tryStatement): return { + guard case .tryStatement(let l) = lhs, case .tryStatement(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.throwStatement, .throwStatement): return { + guard case .throwStatement(let l) = lhs, case .throwStatement(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_Identifier { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var name: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_NumberLiteral { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var value: Double = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_BigIntLiteral { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var value: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_StringLiteral { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var value: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_RegExpLiteral { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var pattern: String = String() + + public var flags: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_BooleanLiteral { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var value: Bool = false + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_NullLiteral { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_ThisExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_AssignmentExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var `operator`: String { + get {return _storage._operator} + set {_uniqueStorage()._operator = newValue} + } + + public var lhs: Compiler_Protobuf_Expression { + get {return _storage._lhs ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._lhs = newValue} + } + /// Returns true if `lhs` has been explicitly set. + public var hasLhs: Bool {return _storage._lhs != nil} + /// Clears the value of `lhs`. Subsequent reads from it will return its default value. + public mutating func clearLhs() {_uniqueStorage()._lhs = nil} + + public var rhs: Compiler_Protobuf_Expression { + get {return _storage._rhs ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._rhs = newValue} + } + /// Returns true if `rhs` has been explicitly set. + public var hasRhs: Bool {return _storage._rhs != nil} + /// Clears the value of `rhs`. Subsequent reads from it will return its default value. + public mutating func clearRhs() {_uniqueStorage()._rhs = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_ObjectProperty { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var key: Compiler_Protobuf_ObjectProperty.OneOf_Key? = nil + + /// A "regular" property. + public var name: String { + get { + if case .name(let v)? = key {return v} + return String() + } + set {key = .name(newValue)} + } + + /// An element. + public var index: Int64 { + get { + if case .index(let v)? = key {return v} + return 0 + } + set {key = .index(newValue)} + } + + /// A computed property. + public var expression: Compiler_Protobuf_Expression { + get { + if case .expression(let v)? = key {return v} + return Compiler_Protobuf_Expression() + } + set {key = .expression(newValue)} + } + + public var value: Compiler_Protobuf_Expression { + get {return _value ?? Compiler_Protobuf_Expression()} + set {_value = newValue} + } + /// Returns true if `value` has been explicitly set. + public var hasValue: Bool {return self._value != nil} + /// Clears the value of `value`. Subsequent reads from it will return its default value. + public mutating func clearValue() {self._value = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Key: Equatable { + /// A "regular" property. + case name(String) + /// An element. + case index(Int64) + /// A computed property. + case expression(Compiler_Protobuf_Expression) + + #if !swift(>=4.1) + public static func ==(lhs: Compiler_Protobuf_ObjectProperty.OneOf_Key, rhs: Compiler_Protobuf_ObjectProperty.OneOf_Key) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.name, .name): return { + guard case .name(let l) = lhs, case .name(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.index, .index): return { + guard case .index(let l) = lhs, case .index(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.expression, .expression): return { + guard case .expression(let l) = lhs, case .expression(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} + + fileprivate var _value: Compiler_Protobuf_Expression? = nil +} + +public struct Compiler_Protobuf_ObjectMethod { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var name: String = String() + + public var type: Compiler_Protobuf_FunctionType = .plain + + public var parameters: [Compiler_Protobuf_Parameter] = [] + + public var body: [Compiler_Protobuf_Statement] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_ObjectGetter { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var name: String = String() + + public var body: [Compiler_Protobuf_Statement] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_ObjectSetter { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var name: String = String() + + public var parameter: Compiler_Protobuf_Parameter { + get {return _parameter ?? Compiler_Protobuf_Parameter()} + set {_parameter = newValue} + } + /// Returns true if `parameter` has been explicitly set. + public var hasParameter: Bool {return self._parameter != nil} + /// Clears the value of `parameter`. Subsequent reads from it will return its default value. + public mutating func clearParameter() {self._parameter = nil} + + public var body: [Compiler_Protobuf_Statement] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _parameter: Compiler_Protobuf_Parameter? = nil +} + +public struct Compiler_Protobuf_ObjectField { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var field: Compiler_Protobuf_ObjectField.OneOf_Field? = nil + + public var property: Compiler_Protobuf_ObjectProperty { + get { + if case .property(let v)? = field {return v} + return Compiler_Protobuf_ObjectProperty() + } + set {field = .property(newValue)} + } + + public var method: Compiler_Protobuf_ObjectMethod { + get { + if case .method(let v)? = field {return v} + return Compiler_Protobuf_ObjectMethod() + } + set {field = .method(newValue)} + } + + public var getter: Compiler_Protobuf_ObjectGetter { + get { + if case .getter(let v)? = field {return v} + return Compiler_Protobuf_ObjectGetter() + } + set {field = .getter(newValue)} + } + + public var setter: Compiler_Protobuf_ObjectSetter { + get { + if case .setter(let v)? = field {return v} + return Compiler_Protobuf_ObjectSetter() + } + set {field = .setter(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Field: Equatable { + case property(Compiler_Protobuf_ObjectProperty) + case method(Compiler_Protobuf_ObjectMethod) + case getter(Compiler_Protobuf_ObjectGetter) + case setter(Compiler_Protobuf_ObjectSetter) + + #if !swift(>=4.1) + public static func ==(lhs: Compiler_Protobuf_ObjectField.OneOf_Field, rhs: Compiler_Protobuf_ObjectField.OneOf_Field) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.property, .property): return { + guard case .property(let l) = lhs, case .property(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.method, .method): return { + guard case .method(let l) = lhs, case .method(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.getter, .getter): return { + guard case .getter(let l) = lhs, case .getter(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.setter, .setter): return { + guard case .setter(let l) = lhs, case .setter(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} +} + +public struct Compiler_Protobuf_ObjectExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var fields: [Compiler_Protobuf_ObjectField] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_ArrayExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// This can contain empty expressions which represent holes. + public var elements: [Compiler_Protobuf_Expression] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_FunctionExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var type: Compiler_Protobuf_FunctionType = .plain + + public var parameters: [Compiler_Protobuf_Parameter] = [] + + public var body: [Compiler_Protobuf_Statement] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_ArrowFunctionExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var type: Compiler_Protobuf_FunctionType { + get {return _storage._type} + set {_uniqueStorage()._type = newValue} + } + + public var parameters: [Compiler_Protobuf_Parameter] { + get {return _storage._parameters} + set {_uniqueStorage()._parameters = newValue} + } + + /// The body can either be an expression or a block statement. + public var body: OneOf_Body? { + get {return _storage._body} + set {_uniqueStorage()._body = newValue} + } + + public var block: Compiler_Protobuf_Statement { + get { + if case .block(let v)? = _storage._body {return v} + return Compiler_Protobuf_Statement() + } + set {_uniqueStorage()._body = .block(newValue)} + } + + public var expression: Compiler_Protobuf_Expression { + get { + if case .expression(let v)? = _storage._body {return v} + return Compiler_Protobuf_Expression() + } + set {_uniqueStorage()._body = .expression(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// The body can either be an expression or a block statement. + public enum OneOf_Body: Equatable { + case block(Compiler_Protobuf_Statement) + case expression(Compiler_Protobuf_Expression) + + #if !swift(>=4.1) + public static func ==(lhs: Compiler_Protobuf_ArrowFunctionExpression.OneOf_Body, rhs: Compiler_Protobuf_ArrowFunctionExpression.OneOf_Body) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.block, .block): return { + guard case .block(let l) = lhs, case .block(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.expression, .expression): return { + guard case .expression(let l) = lhs, case .expression(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_CallExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var callee: Compiler_Protobuf_Expression { + get {return _storage._callee ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._callee = newValue} + } + /// Returns true if `callee` has been explicitly set. + public var hasCallee: Bool {return _storage._callee != nil} + /// Clears the value of `callee`. Subsequent reads from it will return its default value. + public mutating func clearCallee() {_uniqueStorage()._callee = nil} + + public var arguments: [Compiler_Protobuf_Expression] { + get {return _storage._arguments} + set {_uniqueStorage()._arguments = newValue} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_NewExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var callee: Compiler_Protobuf_Expression { + get {return _storage._callee ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._callee = newValue} + } + /// Returns true if `callee` has been explicitly set. + public var hasCallee: Bool {return _storage._callee != nil} + /// Clears the value of `callee`. Subsequent reads from it will return its default value. + public mutating func clearCallee() {_uniqueStorage()._callee = nil} + + public var arguments: [Compiler_Protobuf_Expression] { + get {return _storage._arguments} + set {_uniqueStorage()._arguments = newValue} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_MemberExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var object: Compiler_Protobuf_Expression { + get {return _storage._object ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._object = newValue} + } + /// Returns true if `object` has been explicitly set. + public var hasObject: Bool {return _storage._object != nil} + /// Clears the value of `object`. Subsequent reads from it will return its default value. + public mutating func clearObject() {_uniqueStorage()._object = nil} + + public var property: OneOf_Property? { + get {return _storage._property} + set {_uniqueStorage()._property = newValue} + } + + /// A "regular" property. + public var name: String { + get { + if case .name(let v)? = _storage._property {return v} + return String() + } + set {_uniqueStorage()._property = .name(newValue)} + } + + /// A computed property or element. + public var expression: Compiler_Protobuf_Expression { + get { + if case .expression(let v)? = _storage._property {return v} + return Compiler_Protobuf_Expression() + } + set {_uniqueStorage()._property = .expression(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Property: Equatable { + /// A "regular" property. + case name(String) + /// A computed property or element. + case expression(Compiler_Protobuf_Expression) + + #if !swift(>=4.1) + public static func ==(lhs: Compiler_Protobuf_MemberExpression.OneOf_Property, rhs: Compiler_Protobuf_MemberExpression.OneOf_Property) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.name, .name): return { + guard case .name(let l) = lhs, case .name(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.expression, .expression): return { + guard case .expression(let l) = lhs, case .expression(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_UnaryExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var `operator`: String { + get {return _storage._operator} + set {_uniqueStorage()._operator = newValue} + } + + public var argument: Compiler_Protobuf_Expression { + get {return _storage._argument ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._argument = newValue} + } + /// Returns true if `argument` has been explicitly set. + public var hasArgument: Bool {return _storage._argument != nil} + /// Clears the value of `argument`. Subsequent reads from it will return its default value. + public mutating func clearArgument() {_uniqueStorage()._argument = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_BinaryExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var `operator`: String { + get {return _storage._operator} + set {_uniqueStorage()._operator = newValue} + } + + public var lhs: Compiler_Protobuf_Expression { + get {return _storage._lhs ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._lhs = newValue} + } + /// Returns true if `lhs` has been explicitly set. + public var hasLhs: Bool {return _storage._lhs != nil} + /// Clears the value of `lhs`. Subsequent reads from it will return its default value. + public mutating func clearLhs() {_uniqueStorage()._lhs = nil} + + public var rhs: Compiler_Protobuf_Expression { + get {return _storage._rhs ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._rhs = newValue} + } + /// Returns true if `rhs` has been explicitly set. + public var hasRhs: Bool {return _storage._rhs != nil} + /// Clears the value of `rhs`. Subsequent reads from it will return its default value. + public mutating func clearRhs() {_uniqueStorage()._rhs = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_UpdateExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var `operator`: String { + get {return _storage._operator} + set {_uniqueStorage()._operator = newValue} + } + + public var isPrefix: Bool { + get {return _storage._isPrefix} + set {_uniqueStorage()._isPrefix = newValue} + } + + public var argument: Compiler_Protobuf_Expression { + get {return _storage._argument ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._argument = newValue} + } + /// Returns true if `argument` has been explicitly set. + public var hasArgument: Bool {return _storage._argument != nil} + /// Clears the value of `argument`. Subsequent reads from it will return its default value. + public mutating func clearArgument() {_uniqueStorage()._argument = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_YieldExpression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The argument is optional + public var argument: Compiler_Protobuf_Expression { + get {return _storage._argument ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._argument = newValue} + } + /// Returns true if `argument` has been explicitly set. + public var hasArgument: Bool {return _storage._argument != nil} + /// Clears the value of `argument`. Subsequent reads from it will return its default value. + public mutating func clearArgument() {_uniqueStorage()._argument = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_SpreadElement { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var argument: Compiler_Protobuf_Expression { + get {return _storage._argument ?? Compiler_Protobuf_Expression()} + set {_uniqueStorage()._argument = newValue} + } + /// Returns true if `argument` has been explicitly set. + public var hasArgument: Bool {return _storage._argument != nil} + /// Clears the value of `argument`. Subsequent reads from it will return its default value. + public mutating func clearArgument() {_uniqueStorage()._argument = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +public struct Compiler_Protobuf_V8IntrinsicIdentifier { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var name: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +public struct Compiler_Protobuf_Expression { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var expression: OneOf_Expression? { + get {return _storage._expression} + set {_uniqueStorage()._expression = newValue} + } + + public var identifier: Compiler_Protobuf_Identifier { + get { + if case .identifier(let v)? = _storage._expression {return v} + return Compiler_Protobuf_Identifier() + } + set {_uniqueStorage()._expression = .identifier(newValue)} + } + + public var numberLiteral: Compiler_Protobuf_NumberLiteral { + get { + if case .numberLiteral(let v)? = _storage._expression {return v} + return Compiler_Protobuf_NumberLiteral() + } + set {_uniqueStorage()._expression = .numberLiteral(newValue)} + } + + public var bigIntLiteral: Compiler_Protobuf_BigIntLiteral { + get { + if case .bigIntLiteral(let v)? = _storage._expression {return v} + return Compiler_Protobuf_BigIntLiteral() + } + set {_uniqueStorage()._expression = .bigIntLiteral(newValue)} + } + + public var stringLiteral: Compiler_Protobuf_StringLiteral { + get { + if case .stringLiteral(let v)? = _storage._expression {return v} + return Compiler_Protobuf_StringLiteral() + } + set {_uniqueStorage()._expression = .stringLiteral(newValue)} + } + + public var regExpLiteral: Compiler_Protobuf_RegExpLiteral { + get { + if case .regExpLiteral(let v)? = _storage._expression {return v} + return Compiler_Protobuf_RegExpLiteral() + } + set {_uniqueStorage()._expression = .regExpLiteral(newValue)} + } + + public var booleanLiteral: Compiler_Protobuf_BooleanLiteral { + get { + if case .booleanLiteral(let v)? = _storage._expression {return v} + return Compiler_Protobuf_BooleanLiteral() + } + set {_uniqueStorage()._expression = .booleanLiteral(newValue)} + } + + public var nullLiteral: Compiler_Protobuf_NullLiteral { + get { + if case .nullLiteral(let v)? = _storage._expression {return v} + return Compiler_Protobuf_NullLiteral() + } + set {_uniqueStorage()._expression = .nullLiteral(newValue)} + } + + public var thisExpression: Compiler_Protobuf_ThisExpression { + get { + if case .thisExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_ThisExpression() + } + set {_uniqueStorage()._expression = .thisExpression(newValue)} + } + + public var assignmentExpression: Compiler_Protobuf_AssignmentExpression { + get { + if case .assignmentExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_AssignmentExpression() + } + set {_uniqueStorage()._expression = .assignmentExpression(newValue)} + } + + public var objectExpression: Compiler_Protobuf_ObjectExpression { + get { + if case .objectExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_ObjectExpression() + } + set {_uniqueStorage()._expression = .objectExpression(newValue)} + } + + public var arrayExpression: Compiler_Protobuf_ArrayExpression { + get { + if case .arrayExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_ArrayExpression() + } + set {_uniqueStorage()._expression = .arrayExpression(newValue)} + } + + public var functionExpression: Compiler_Protobuf_FunctionExpression { + get { + if case .functionExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_FunctionExpression() + } + set {_uniqueStorage()._expression = .functionExpression(newValue)} + } + + public var arrowFunctionExpression: Compiler_Protobuf_ArrowFunctionExpression { + get { + if case .arrowFunctionExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_ArrowFunctionExpression() + } + set {_uniqueStorage()._expression = .arrowFunctionExpression(newValue)} + } + + public var callExpression: Compiler_Protobuf_CallExpression { + get { + if case .callExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_CallExpression() + } + set {_uniqueStorage()._expression = .callExpression(newValue)} + } + + public var newExpression: Compiler_Protobuf_NewExpression { + get { + if case .newExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_NewExpression() + } + set {_uniqueStorage()._expression = .newExpression(newValue)} + } + + public var memberExpression: Compiler_Protobuf_MemberExpression { + get { + if case .memberExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_MemberExpression() + } + set {_uniqueStorage()._expression = .memberExpression(newValue)} + } + + public var unaryExpression: Compiler_Protobuf_UnaryExpression { + get { + if case .unaryExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_UnaryExpression() + } + set {_uniqueStorage()._expression = .unaryExpression(newValue)} + } + + public var binaryExpression: Compiler_Protobuf_BinaryExpression { + get { + if case .binaryExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_BinaryExpression() + } + set {_uniqueStorage()._expression = .binaryExpression(newValue)} + } + + public var updateExpression: Compiler_Protobuf_UpdateExpression { + get { + if case .updateExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_UpdateExpression() + } + set {_uniqueStorage()._expression = .updateExpression(newValue)} + } + + public var yieldExpression: Compiler_Protobuf_YieldExpression { + get { + if case .yieldExpression(let v)? = _storage._expression {return v} + return Compiler_Protobuf_YieldExpression() + } + set {_uniqueStorage()._expression = .yieldExpression(newValue)} + } + + public var spreadElement: Compiler_Protobuf_SpreadElement { + get { + if case .spreadElement(let v)? = _storage._expression {return v} + return Compiler_Protobuf_SpreadElement() + } + set {_uniqueStorage()._expression = .spreadElement(newValue)} + } + + public var v8IntrinsicIdentifier: Compiler_Protobuf_V8IntrinsicIdentifier { + get { + if case .v8IntrinsicIdentifier(let v)? = _storage._expression {return v} + return Compiler_Protobuf_V8IntrinsicIdentifier() + } + set {_uniqueStorage()._expression = .v8IntrinsicIdentifier(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Expression: Equatable { + case identifier(Compiler_Protobuf_Identifier) + case numberLiteral(Compiler_Protobuf_NumberLiteral) + case bigIntLiteral(Compiler_Protobuf_BigIntLiteral) + case stringLiteral(Compiler_Protobuf_StringLiteral) + case regExpLiteral(Compiler_Protobuf_RegExpLiteral) + case booleanLiteral(Compiler_Protobuf_BooleanLiteral) + case nullLiteral(Compiler_Protobuf_NullLiteral) + case thisExpression(Compiler_Protobuf_ThisExpression) + case assignmentExpression(Compiler_Protobuf_AssignmentExpression) + case objectExpression(Compiler_Protobuf_ObjectExpression) + case arrayExpression(Compiler_Protobuf_ArrayExpression) + case functionExpression(Compiler_Protobuf_FunctionExpression) + case arrowFunctionExpression(Compiler_Protobuf_ArrowFunctionExpression) + case callExpression(Compiler_Protobuf_CallExpression) + case newExpression(Compiler_Protobuf_NewExpression) + case memberExpression(Compiler_Protobuf_MemberExpression) + case unaryExpression(Compiler_Protobuf_UnaryExpression) + case binaryExpression(Compiler_Protobuf_BinaryExpression) + case updateExpression(Compiler_Protobuf_UpdateExpression) + case yieldExpression(Compiler_Protobuf_YieldExpression) + case spreadElement(Compiler_Protobuf_SpreadElement) + case v8IntrinsicIdentifier(Compiler_Protobuf_V8IntrinsicIdentifier) + + #if !swift(>=4.1) + public static func ==(lhs: Compiler_Protobuf_Expression.OneOf_Expression, rhs: Compiler_Protobuf_Expression.OneOf_Expression) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.identifier, .identifier): return { + guard case .identifier(let l) = lhs, case .identifier(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.numberLiteral, .numberLiteral): return { + guard case .numberLiteral(let l) = lhs, case .numberLiteral(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.bigIntLiteral, .bigIntLiteral): return { + guard case .bigIntLiteral(let l) = lhs, case .bigIntLiteral(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.stringLiteral, .stringLiteral): return { + guard case .stringLiteral(let l) = lhs, case .stringLiteral(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.regExpLiteral, .regExpLiteral): return { + guard case .regExpLiteral(let l) = lhs, case .regExpLiteral(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.booleanLiteral, .booleanLiteral): return { + guard case .booleanLiteral(let l) = lhs, case .booleanLiteral(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.nullLiteral, .nullLiteral): return { + guard case .nullLiteral(let l) = lhs, case .nullLiteral(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.thisExpression, .thisExpression): return { + guard case .thisExpression(let l) = lhs, case .thisExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.assignmentExpression, .assignmentExpression): return { + guard case .assignmentExpression(let l) = lhs, case .assignmentExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.objectExpression, .objectExpression): return { + guard case .objectExpression(let l) = lhs, case .objectExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.arrayExpression, .arrayExpression): return { + guard case .arrayExpression(let l) = lhs, case .arrayExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.functionExpression, .functionExpression): return { + guard case .functionExpression(let l) = lhs, case .functionExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.arrowFunctionExpression, .arrowFunctionExpression): return { + guard case .arrowFunctionExpression(let l) = lhs, case .arrowFunctionExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.callExpression, .callExpression): return { + guard case .callExpression(let l) = lhs, case .callExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.newExpression, .newExpression): return { + guard case .newExpression(let l) = lhs, case .newExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.memberExpression, .memberExpression): return { + guard case .memberExpression(let l) = lhs, case .memberExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.unaryExpression, .unaryExpression): return { + guard case .unaryExpression(let l) = lhs, case .unaryExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.binaryExpression, .binaryExpression): return { + guard case .binaryExpression(let l) = lhs, case .binaryExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.updateExpression, .updateExpression): return { + guard case .updateExpression(let l) = lhs, case .updateExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.yieldExpression, .yieldExpression): return { + guard case .yieldExpression(let l) = lhs, case .yieldExpression(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.spreadElement, .spreadElement): return { + guard case .spreadElement(let l) = lhs, case .spreadElement(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.v8IntrinsicIdentifier, .v8IntrinsicIdentifier): return { + guard case .v8IntrinsicIdentifier(let l) = lhs, case .v8IntrinsicIdentifier(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Compiler_Protobuf_VariableDeclarationKind: @unchecked Sendable {} +extension Compiler_Protobuf_FunctionType: @unchecked Sendable {} +extension Compiler_Protobuf_AST: @unchecked Sendable {} +extension Compiler_Protobuf_Parameter: @unchecked Sendable {} +extension Compiler_Protobuf_EmptyStatement: @unchecked Sendable {} +extension Compiler_Protobuf_BlockStatement: @unchecked Sendable {} +extension Compiler_Protobuf_VariableDeclarator: @unchecked Sendable {} +extension Compiler_Protobuf_VariableDeclaration: @unchecked Sendable {} +extension Compiler_Protobuf_FunctionDeclaration: @unchecked Sendable {} +extension Compiler_Protobuf_ReturnStatement: @unchecked Sendable {} +extension Compiler_Protobuf_ExpressionStatement: @unchecked Sendable {} +extension Compiler_Protobuf_IfStatement: @unchecked Sendable {} +extension Compiler_Protobuf_WhileLoop: @unchecked Sendable {} +extension Compiler_Protobuf_DoWhileLoop: @unchecked Sendable {} +extension Compiler_Protobuf_ForLoop: @unchecked Sendable {} +extension Compiler_Protobuf_ForInLoop: @unchecked Sendable {} +extension Compiler_Protobuf_ForOfLoop: @unchecked Sendable {} +extension Compiler_Protobuf_CatchClause: @unchecked Sendable {} +extension Compiler_Protobuf_FinallyClause: @unchecked Sendable {} +extension Compiler_Protobuf_TryStatement: @unchecked Sendable {} +extension Compiler_Protobuf_ThrowStatement: @unchecked Sendable {} +extension Compiler_Protobuf_Statement: @unchecked Sendable {} +extension Compiler_Protobuf_Statement.OneOf_Statement: @unchecked Sendable {} +extension Compiler_Protobuf_Identifier: @unchecked Sendable {} +extension Compiler_Protobuf_NumberLiteral: @unchecked Sendable {} +extension Compiler_Protobuf_BigIntLiteral: @unchecked Sendable {} +extension Compiler_Protobuf_StringLiteral: @unchecked Sendable {} +extension Compiler_Protobuf_RegExpLiteral: @unchecked Sendable {} +extension Compiler_Protobuf_BooleanLiteral: @unchecked Sendable {} +extension Compiler_Protobuf_NullLiteral: @unchecked Sendable {} +extension Compiler_Protobuf_ThisExpression: @unchecked Sendable {} +extension Compiler_Protobuf_AssignmentExpression: @unchecked Sendable {} +extension Compiler_Protobuf_ObjectProperty: @unchecked Sendable {} +extension Compiler_Protobuf_ObjectProperty.OneOf_Key: @unchecked Sendable {} +extension Compiler_Protobuf_ObjectMethod: @unchecked Sendable {} +extension Compiler_Protobuf_ObjectGetter: @unchecked Sendable {} +extension Compiler_Protobuf_ObjectSetter: @unchecked Sendable {} +extension Compiler_Protobuf_ObjectField: @unchecked Sendable {} +extension Compiler_Protobuf_ObjectField.OneOf_Field: @unchecked Sendable {} +extension Compiler_Protobuf_ObjectExpression: @unchecked Sendable {} +extension Compiler_Protobuf_ArrayExpression: @unchecked Sendable {} +extension Compiler_Protobuf_FunctionExpression: @unchecked Sendable {} +extension Compiler_Protobuf_ArrowFunctionExpression: @unchecked Sendable {} +extension Compiler_Protobuf_ArrowFunctionExpression.OneOf_Body: @unchecked Sendable {} +extension Compiler_Protobuf_CallExpression: @unchecked Sendable {} +extension Compiler_Protobuf_NewExpression: @unchecked Sendable {} +extension Compiler_Protobuf_MemberExpression: @unchecked Sendable {} +extension Compiler_Protobuf_MemberExpression.OneOf_Property: @unchecked Sendable {} +extension Compiler_Protobuf_UnaryExpression: @unchecked Sendable {} +extension Compiler_Protobuf_BinaryExpression: @unchecked Sendable {} +extension Compiler_Protobuf_UpdateExpression: @unchecked Sendable {} +extension Compiler_Protobuf_YieldExpression: @unchecked Sendable {} +extension Compiler_Protobuf_SpreadElement: @unchecked Sendable {} +extension Compiler_Protobuf_V8IntrinsicIdentifier: @unchecked Sendable {} +extension Compiler_Protobuf_Expression: @unchecked Sendable {} +extension Compiler_Protobuf_Expression.OneOf_Expression: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "compiler.protobuf" + +extension Compiler_Protobuf_VariableDeclarationKind: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "VAR"), + 1: .same(proto: "LET"), + 2: .same(proto: "CONST"), + ] +} + +extension Compiler_Protobuf_FunctionType: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "PLAIN"), + 1: .same(proto: "GENERATOR"), + 2: .same(proto: "ASYNC"), + 3: .same(proto: "ASYNC_GENERATOR"), + ] +} + +extension Compiler_Protobuf_AST: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".AST" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "statements"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.statements) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.statements.isEmpty { + try visitor.visitRepeatedMessageField(value: self.statements, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_AST, rhs: Compiler_Protobuf_AST) -> Bool { + if lhs.statements != rhs.statements {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_Parameter: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Parameter" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_Parameter, rhs: Compiler_Protobuf_Parameter) -> Bool { + if lhs.name != rhs.name {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_EmptyStatement: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EmptyStatement" + public static let _protobuf_nameMap = SwiftProtobuf._NameMap() + + public mutating func decodeMessage(decoder: inout D) throws { + while let _ = try decoder.nextFieldNumber() { + } + } + + public func traverse(visitor: inout V) throws { + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_EmptyStatement, rhs: Compiler_Protobuf_EmptyStatement) -> Bool { + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_BlockStatement: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".BlockStatement" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "body"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.body) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.body.isEmpty { + try visitor.visitRepeatedMessageField(value: self.body, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_BlockStatement, rhs: Compiler_Protobuf_BlockStatement) -> Bool { + if lhs.body != rhs.body {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_VariableDeclarator: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".VariableDeclarator" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "value"), + ] + + fileprivate class _StorageClass { + var _name: String = String() + var _value: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _name = source._name + _value = source._value + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &_storage._name) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._value) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !_storage._name.isEmpty { + try visitor.visitSingularStringField(value: _storage._name, fieldNumber: 1) + } + try { if let v = _storage._value { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_VariableDeclarator, rhs: Compiler_Protobuf_VariableDeclarator) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._name != rhs_storage._name {return false} + if _storage._value != rhs_storage._value {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_VariableDeclaration: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".VariableDeclaration" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "kind"), + 2: .same(proto: "declarations"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularEnumField(value: &self.kind) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &self.declarations) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.kind != .var { + try visitor.visitSingularEnumField(value: self.kind, fieldNumber: 1) + } + if !self.declarations.isEmpty { + try visitor.visitRepeatedMessageField(value: self.declarations, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_VariableDeclaration, rhs: Compiler_Protobuf_VariableDeclaration) -> Bool { + if lhs.kind != rhs.kind {return false} + if lhs.declarations != rhs.declarations {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_FunctionDeclaration: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".FunctionDeclaration" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "type"), + 3: .same(proto: "parameters"), + 4: .same(proto: "body"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() + case 2: try { try decoder.decodeSingularEnumField(value: &self.type) }() + case 3: try { try decoder.decodeRepeatedMessageField(value: &self.parameters) }() + case 4: try { try decoder.decodeRepeatedMessageField(value: &self.body) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + if self.type != .plain { + try visitor.visitSingularEnumField(value: self.type, fieldNumber: 2) + } + if !self.parameters.isEmpty { + try visitor.visitRepeatedMessageField(value: self.parameters, fieldNumber: 3) + } + if !self.body.isEmpty { + try visitor.visitRepeatedMessageField(value: self.body, fieldNumber: 4) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_FunctionDeclaration, rhs: Compiler_Protobuf_FunctionDeclaration) -> Bool { + if lhs.name != rhs.name {return false} + if lhs.type != rhs.type {return false} + if lhs.parameters != rhs.parameters {return false} + if lhs.body != rhs.body {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ReturnStatement: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ReturnStatement" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "argument"), + ] + + fileprivate class _StorageClass { + var _argument: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _argument = source._argument + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._argument) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._argument { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ReturnStatement, rhs: Compiler_Protobuf_ReturnStatement) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._argument != rhs_storage._argument {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ExpressionStatement: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ExpressionStatement" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "expression"), + ] + + fileprivate class _StorageClass { + var _expression: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _expression = source._expression + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._expression) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._expression { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ExpressionStatement, rhs: Compiler_Protobuf_ExpressionStatement) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._expression != rhs_storage._expression {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_IfStatement: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".IfStatement" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "test"), + 2: .same(proto: "ifBody"), + 3: .same(proto: "elseBody"), + ] + + fileprivate class _StorageClass { + var _test: Compiler_Protobuf_Expression? = nil + var _ifBody: Compiler_Protobuf_Statement? = nil + var _elseBody: Compiler_Protobuf_Statement? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _test = source._test + _ifBody = source._ifBody + _elseBody = source._elseBody + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._test) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._ifBody) }() + case 3: try { try decoder.decodeSingularMessageField(value: &_storage._elseBody) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._test { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = _storage._ifBody { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = _storage._elseBody { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_IfStatement, rhs: Compiler_Protobuf_IfStatement) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._test != rhs_storage._test {return false} + if _storage._ifBody != rhs_storage._ifBody {return false} + if _storage._elseBody != rhs_storage._elseBody {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_WhileLoop: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".WhileLoop" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "test"), + 2: .same(proto: "body"), + ] + + fileprivate class _StorageClass { + var _test: Compiler_Protobuf_Expression? = nil + var _body: Compiler_Protobuf_Statement? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _test = source._test + _body = source._body + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._test) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._body) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._test { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = _storage._body { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_WhileLoop, rhs: Compiler_Protobuf_WhileLoop) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._test != rhs_storage._test {return false} + if _storage._body != rhs_storage._body {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_DoWhileLoop: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".DoWhileLoop" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "test"), + 2: .same(proto: "body"), + ] + + fileprivate class _StorageClass { + var _test: Compiler_Protobuf_Expression? = nil + var _body: Compiler_Protobuf_Statement? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _test = source._test + _body = source._body + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._test) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._body) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._test { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = _storage._body { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_DoWhileLoop, rhs: Compiler_Protobuf_DoWhileLoop) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._test != rhs_storage._test {return false} + if _storage._body != rhs_storage._body {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ForLoop: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ForLoop" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "init"), + 2: .same(proto: "test"), + 3: .same(proto: "update"), + 4: .same(proto: "body"), + ] + + fileprivate class _StorageClass { + var _init_p: Compiler_Protobuf_VariableDeclarator? = nil + var _test: Compiler_Protobuf_Expression? = nil + var _update: Compiler_Protobuf_Expression? = nil + var _body: Compiler_Protobuf_Statement? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _init_p = source._init_p + _test = source._test + _update = source._update + _body = source._body + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._init_p) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._test) }() + case 3: try { try decoder.decodeSingularMessageField(value: &_storage._update) }() + case 4: try { try decoder.decodeSingularMessageField(value: &_storage._body) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._init_p { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = _storage._test { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = _storage._update { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try { if let v = _storage._body { + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ForLoop, rhs: Compiler_Protobuf_ForLoop) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._init_p != rhs_storage._init_p {return false} + if _storage._test != rhs_storage._test {return false} + if _storage._update != rhs_storage._update {return false} + if _storage._body != rhs_storage._body {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ForInLoop: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ForInLoop" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "left"), + 2: .same(proto: "right"), + 3: .same(proto: "body"), + ] + + fileprivate class _StorageClass { + var _left: Compiler_Protobuf_VariableDeclarator? = nil + var _right: Compiler_Protobuf_Expression? = nil + var _body: Compiler_Protobuf_Statement? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _left = source._left + _right = source._right + _body = source._body + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._left) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._right) }() + case 3: try { try decoder.decodeSingularMessageField(value: &_storage._body) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._left { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = _storage._right { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = _storage._body { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ForInLoop, rhs: Compiler_Protobuf_ForInLoop) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._left != rhs_storage._left {return false} + if _storage._right != rhs_storage._right {return false} + if _storage._body != rhs_storage._body {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ForOfLoop: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ForOfLoop" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "left"), + 2: .same(proto: "right"), + 3: .same(proto: "body"), + ] + + fileprivate class _StorageClass { + var _left: Compiler_Protobuf_VariableDeclarator? = nil + var _right: Compiler_Protobuf_Expression? = nil + var _body: Compiler_Protobuf_Statement? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _left = source._left + _right = source._right + _body = source._body + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._left) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._right) }() + case 3: try { try decoder.decodeSingularMessageField(value: &_storage._body) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._left { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = _storage._right { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = _storage._body { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ForOfLoop, rhs: Compiler_Protobuf_ForOfLoop) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._left != rhs_storage._left {return false} + if _storage._right != rhs_storage._right {return false} + if _storage._body != rhs_storage._body {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_CatchClause: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".CatchClause" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "parameter"), + 2: .same(proto: "body"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._parameter) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &self.body) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._parameter { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !self.body.isEmpty { + try visitor.visitRepeatedMessageField(value: self.body, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_CatchClause, rhs: Compiler_Protobuf_CatchClause) -> Bool { + if lhs._parameter != rhs._parameter {return false} + if lhs.body != rhs.body {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_FinallyClause: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".FinallyClause" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 3: .same(proto: "body"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 3: try { try decoder.decodeRepeatedMessageField(value: &self.body) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.body.isEmpty { + try visitor.visitRepeatedMessageField(value: self.body, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_FinallyClause, rhs: Compiler_Protobuf_FinallyClause) -> Bool { + if lhs.body != rhs.body {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_TryStatement: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".TryStatement" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "body"), + 2: .same(proto: "catch"), + 3: .same(proto: "finally"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.body) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._catch) }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._finally) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.body.isEmpty { + try visitor.visitRepeatedMessageField(value: self.body, fieldNumber: 1) + } + try { if let v = self._catch { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = self._finally { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_TryStatement, rhs: Compiler_Protobuf_TryStatement) -> Bool { + if lhs.body != rhs.body {return false} + if lhs._catch != rhs._catch {return false} + if lhs._finally != rhs._finally {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ThrowStatement: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ThrowStatement" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "argument"), + ] + + fileprivate class _StorageClass { + var _argument: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _argument = source._argument + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._argument) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._argument { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ThrowStatement, rhs: Compiler_Protobuf_ThrowStatement) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._argument != rhs_storage._argument {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_Statement: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Statement" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "emptyStatement"), + 2: .same(proto: "blockStatement"), + 3: .same(proto: "variableDeclaration"), + 4: .same(proto: "functionDeclaration"), + 5: .same(proto: "returnStatement"), + 6: .same(proto: "expressionStatement"), + 7: .same(proto: "ifStatement"), + 8: .same(proto: "whileLoop"), + 9: .same(proto: "doWhileLoop"), + 10: .same(proto: "forLoop"), + 11: .same(proto: "forInLoop"), + 12: .same(proto: "forOfLoop"), + 13: .same(proto: "tryStatement"), + 14: .same(proto: "throwStatement"), + ] + + fileprivate class _StorageClass { + var _statement: Compiler_Protobuf_Statement.OneOf_Statement? + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _statement = source._statement + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Compiler_Protobuf_EmptyStatement? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .emptyStatement(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .emptyStatement(v) + } + }() + case 2: try { + var v: Compiler_Protobuf_BlockStatement? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .blockStatement(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .blockStatement(v) + } + }() + case 3: try { + var v: Compiler_Protobuf_VariableDeclaration? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .variableDeclaration(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .variableDeclaration(v) + } + }() + case 4: try { + var v: Compiler_Protobuf_FunctionDeclaration? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .functionDeclaration(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .functionDeclaration(v) + } + }() + case 5: try { + var v: Compiler_Protobuf_ReturnStatement? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .returnStatement(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .returnStatement(v) + } + }() + case 6: try { + var v: Compiler_Protobuf_ExpressionStatement? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .expressionStatement(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .expressionStatement(v) + } + }() + case 7: try { + var v: Compiler_Protobuf_IfStatement? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .ifStatement(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .ifStatement(v) + } + }() + case 8: try { + var v: Compiler_Protobuf_WhileLoop? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .whileLoop(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .whileLoop(v) + } + }() + case 9: try { + var v: Compiler_Protobuf_DoWhileLoop? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .doWhileLoop(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .doWhileLoop(v) + } + }() + case 10: try { + var v: Compiler_Protobuf_ForLoop? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .forLoop(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .forLoop(v) + } + }() + case 11: try { + var v: Compiler_Protobuf_ForInLoop? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .forInLoop(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .forInLoop(v) + } + }() + case 12: try { + var v: Compiler_Protobuf_ForOfLoop? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .forOfLoop(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .forOfLoop(v) + } + }() + case 13: try { + var v: Compiler_Protobuf_TryStatement? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .tryStatement(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .tryStatement(v) + } + }() + case 14: try { + var v: Compiler_Protobuf_ThrowStatement? + var hadOneofValue = false + if let current = _storage._statement { + hadOneofValue = true + if case .throwStatement(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._statement = .throwStatement(v) + } + }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch _storage._statement { + case .emptyStatement?: try { + guard case .emptyStatement(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .blockStatement?: try { + guard case .blockStatement(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case .variableDeclaration?: try { + guard case .variableDeclaration(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + }() + case .functionDeclaration?: try { + guard case .functionDeclaration(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + }() + case .returnStatement?: try { + guard case .returnStatement(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 5) + }() + case .expressionStatement?: try { + guard case .expressionStatement(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 6) + }() + case .ifStatement?: try { + guard case .ifStatement(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 7) + }() + case .whileLoop?: try { + guard case .whileLoop(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 8) + }() + case .doWhileLoop?: try { + guard case .doWhileLoop(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 9) + }() + case .forLoop?: try { + guard case .forLoop(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 10) + }() + case .forInLoop?: try { + guard case .forInLoop(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 11) + }() + case .forOfLoop?: try { + guard case .forOfLoop(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 12) + }() + case .tryStatement?: try { + guard case .tryStatement(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 13) + }() + case .throwStatement?: try { + guard case .throwStatement(let v)? = _storage._statement else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 14) + }() + case nil: break + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_Statement, rhs: Compiler_Protobuf_Statement) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._statement != rhs_storage._statement {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_Identifier: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Identifier" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_Identifier, rhs: Compiler_Protobuf_Identifier) -> Bool { + if lhs.name != rhs.name {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_NumberLiteral: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".NumberLiteral" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularDoubleField(value: &self.value) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.value != 0 { + try visitor.visitSingularDoubleField(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_NumberLiteral, rhs: Compiler_Protobuf_NumberLiteral) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_BigIntLiteral: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".BigIntLiteral" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.value) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.value.isEmpty { + try visitor.visitSingularStringField(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_BigIntLiteral, rhs: Compiler_Protobuf_BigIntLiteral) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_StringLiteral: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".StringLiteral" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.value) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.value.isEmpty { + try visitor.visitSingularStringField(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_StringLiteral, rhs: Compiler_Protobuf_StringLiteral) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_RegExpLiteral: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".RegExpLiteral" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "pattern"), + 2: .same(proto: "flags"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.pattern) }() + case 2: try { try decoder.decodeSingularStringField(value: &self.flags) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.pattern.isEmpty { + try visitor.visitSingularStringField(value: self.pattern, fieldNumber: 1) + } + if !self.flags.isEmpty { + try visitor.visitSingularStringField(value: self.flags, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_RegExpLiteral, rhs: Compiler_Protobuf_RegExpLiteral) -> Bool { + if lhs.pattern != rhs.pattern {return false} + if lhs.flags != rhs.flags {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_BooleanLiteral: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".BooleanLiteral" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBoolField(value: &self.value) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.value != false { + try visitor.visitSingularBoolField(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_BooleanLiteral, rhs: Compiler_Protobuf_BooleanLiteral) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_NullLiteral: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".NullLiteral" + public static let _protobuf_nameMap = SwiftProtobuf._NameMap() + + public mutating func decodeMessage(decoder: inout D) throws { + while let _ = try decoder.nextFieldNumber() { + } + } + + public func traverse(visitor: inout V) throws { + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_NullLiteral, rhs: Compiler_Protobuf_NullLiteral) -> Bool { + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ThisExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ThisExpression" + public static let _protobuf_nameMap = SwiftProtobuf._NameMap() + + public mutating func decodeMessage(decoder: inout D) throws { + while let _ = try decoder.nextFieldNumber() { + } + } + + public func traverse(visitor: inout V) throws { + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ThisExpression, rhs: Compiler_Protobuf_ThisExpression) -> Bool { + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_AssignmentExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".AssignmentExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "operator"), + 2: .same(proto: "lhs"), + 3: .same(proto: "rhs"), + ] + + fileprivate class _StorageClass { + var _operator: String = String() + var _lhs: Compiler_Protobuf_Expression? = nil + var _rhs: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _operator = source._operator + _lhs = source._lhs + _rhs = source._rhs + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &_storage._operator) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._lhs) }() + case 3: try { try decoder.decodeSingularMessageField(value: &_storage._rhs) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !_storage._operator.isEmpty { + try visitor.visitSingularStringField(value: _storage._operator, fieldNumber: 1) + } + try { if let v = _storage._lhs { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = _storage._rhs { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_AssignmentExpression, rhs: Compiler_Protobuf_AssignmentExpression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._operator != rhs_storage._operator {return false} + if _storage._lhs != rhs_storage._lhs {return false} + if _storage._rhs != rhs_storage._rhs {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ObjectProperty: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ObjectProperty" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "index"), + 3: .same(proto: "expression"), + 4: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: String? + try decoder.decodeSingularStringField(value: &v) + if let v = v { + if self.key != nil {try decoder.handleConflictingOneOf()} + self.key = .name(v) + } + }() + case 2: try { + var v: Int64? + try decoder.decodeSingularInt64Field(value: &v) + if let v = v { + if self.key != nil {try decoder.handleConflictingOneOf()} + self.key = .index(v) + } + }() + case 3: try { + var v: Compiler_Protobuf_Expression? + var hadOneofValue = false + if let current = self.key { + hadOneofValue = true + if case .expression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.key = .expression(v) + } + }() + case 4: try { try decoder.decodeSingularMessageField(value: &self._value) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.key { + case .name?: try { + guard case .name(let v)? = self.key else { preconditionFailure() } + try visitor.visitSingularStringField(value: v, fieldNumber: 1) + }() + case .index?: try { + guard case .index(let v)? = self.key else { preconditionFailure() } + try visitor.visitSingularInt64Field(value: v, fieldNumber: 2) + }() + case .expression?: try { + guard case .expression(let v)? = self.key else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + }() + case nil: break + } + try { if let v = self._value { + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ObjectProperty, rhs: Compiler_Protobuf_ObjectProperty) -> Bool { + if lhs.key != rhs.key {return false} + if lhs._value != rhs._value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ObjectMethod: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ObjectMethod" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "type"), + 3: .same(proto: "parameters"), + 4: .same(proto: "body"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() + case 2: try { try decoder.decodeSingularEnumField(value: &self.type) }() + case 3: try { try decoder.decodeRepeatedMessageField(value: &self.parameters) }() + case 4: try { try decoder.decodeRepeatedMessageField(value: &self.body) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + if self.type != .plain { + try visitor.visitSingularEnumField(value: self.type, fieldNumber: 2) + } + if !self.parameters.isEmpty { + try visitor.visitRepeatedMessageField(value: self.parameters, fieldNumber: 3) + } + if !self.body.isEmpty { + try visitor.visitRepeatedMessageField(value: self.body, fieldNumber: 4) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ObjectMethod, rhs: Compiler_Protobuf_ObjectMethod) -> Bool { + if lhs.name != rhs.name {return false} + if lhs.type != rhs.type {return false} + if lhs.parameters != rhs.parameters {return false} + if lhs.body != rhs.body {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ObjectGetter: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ObjectGetter" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "body"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &self.body) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + if !self.body.isEmpty { + try visitor.visitRepeatedMessageField(value: self.body, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ObjectGetter, rhs: Compiler_Protobuf_ObjectGetter) -> Bool { + if lhs.name != rhs.name {return false} + if lhs.body != rhs.body {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ObjectSetter: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ObjectSetter" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "parameter"), + 3: .same(proto: "body"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._parameter) }() + case 3: try { try decoder.decodeRepeatedMessageField(value: &self.body) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + try { if let v = self._parameter { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + if !self.body.isEmpty { + try visitor.visitRepeatedMessageField(value: self.body, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ObjectSetter, rhs: Compiler_Protobuf_ObjectSetter) -> Bool { + if lhs.name != rhs.name {return false} + if lhs._parameter != rhs._parameter {return false} + if lhs.body != rhs.body {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ObjectField: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ObjectField" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "property"), + 2: .same(proto: "method"), + 3: .same(proto: "getter"), + 4: .same(proto: "setter"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Compiler_Protobuf_ObjectProperty? + var hadOneofValue = false + if let current = self.field { + hadOneofValue = true + if case .property(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.field = .property(v) + } + }() + case 2: try { + var v: Compiler_Protobuf_ObjectMethod? + var hadOneofValue = false + if let current = self.field { + hadOneofValue = true + if case .method(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.field = .method(v) + } + }() + case 3: try { + var v: Compiler_Protobuf_ObjectGetter? + var hadOneofValue = false + if let current = self.field { + hadOneofValue = true + if case .getter(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.field = .getter(v) + } + }() + case 4: try { + var v: Compiler_Protobuf_ObjectSetter? + var hadOneofValue = false + if let current = self.field { + hadOneofValue = true + if case .setter(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.field = .setter(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.field { + case .property?: try { + guard case .property(let v)? = self.field else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .method?: try { + guard case .method(let v)? = self.field else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case .getter?: try { + guard case .getter(let v)? = self.field else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + }() + case .setter?: try { + guard case .setter(let v)? = self.field else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ObjectField, rhs: Compiler_Protobuf_ObjectField) -> Bool { + if lhs.field != rhs.field {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ObjectExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ObjectExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "fields"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.fields) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.fields.isEmpty { + try visitor.visitRepeatedMessageField(value: self.fields, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ObjectExpression, rhs: Compiler_Protobuf_ObjectExpression) -> Bool { + if lhs.fields != rhs.fields {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ArrayExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ArrayExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "elements"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.elements) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.elements.isEmpty { + try visitor.visitRepeatedMessageField(value: self.elements, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ArrayExpression, rhs: Compiler_Protobuf_ArrayExpression) -> Bool { + if lhs.elements != rhs.elements {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_FunctionExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".FunctionExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "type"), + 2: .same(proto: "parameters"), + 3: .same(proto: "body"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularEnumField(value: &self.type) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &self.parameters) }() + case 3: try { try decoder.decodeRepeatedMessageField(value: &self.body) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.type != .plain { + try visitor.visitSingularEnumField(value: self.type, fieldNumber: 1) + } + if !self.parameters.isEmpty { + try visitor.visitRepeatedMessageField(value: self.parameters, fieldNumber: 2) + } + if !self.body.isEmpty { + try visitor.visitRepeatedMessageField(value: self.body, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_FunctionExpression, rhs: Compiler_Protobuf_FunctionExpression) -> Bool { + if lhs.type != rhs.type {return false} + if lhs.parameters != rhs.parameters {return false} + if lhs.body != rhs.body {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_ArrowFunctionExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ArrowFunctionExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "type"), + 2: .same(proto: "parameters"), + 3: .same(proto: "block"), + 4: .same(proto: "expression"), + ] + + fileprivate class _StorageClass { + var _type: Compiler_Protobuf_FunctionType = .plain + var _parameters: [Compiler_Protobuf_Parameter] = [] + var _body: Compiler_Protobuf_ArrowFunctionExpression.OneOf_Body? + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _type = source._type + _parameters = source._parameters + _body = source._body + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularEnumField(value: &_storage._type) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &_storage._parameters) }() + case 3: try { + var v: Compiler_Protobuf_Statement? + var hadOneofValue = false + if let current = _storage._body { + hadOneofValue = true + if case .block(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._body = .block(v) + } + }() + case 4: try { + var v: Compiler_Protobuf_Expression? + var hadOneofValue = false + if let current = _storage._body { + hadOneofValue = true + if case .expression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._body = .expression(v) + } + }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if _storage._type != .plain { + try visitor.visitSingularEnumField(value: _storage._type, fieldNumber: 1) + } + if !_storage._parameters.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._parameters, fieldNumber: 2) + } + switch _storage._body { + case .block?: try { + guard case .block(let v)? = _storage._body else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + }() + case .expression?: try { + guard case .expression(let v)? = _storage._body else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + }() + case nil: break + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_ArrowFunctionExpression, rhs: Compiler_Protobuf_ArrowFunctionExpression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._type != rhs_storage._type {return false} + if _storage._parameters != rhs_storage._parameters {return false} + if _storage._body != rhs_storage._body {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_CallExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".CallExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "callee"), + 2: .same(proto: "arguments"), + ] + + fileprivate class _StorageClass { + var _callee: Compiler_Protobuf_Expression? = nil + var _arguments: [Compiler_Protobuf_Expression] = [] + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _callee = source._callee + _arguments = source._arguments + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._callee) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &_storage._arguments) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._callee { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !_storage._arguments.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._arguments, fieldNumber: 2) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_CallExpression, rhs: Compiler_Protobuf_CallExpression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._callee != rhs_storage._callee {return false} + if _storage._arguments != rhs_storage._arguments {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_NewExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".NewExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "callee"), + 2: .same(proto: "arguments"), + ] + + fileprivate class _StorageClass { + var _callee: Compiler_Protobuf_Expression? = nil + var _arguments: [Compiler_Protobuf_Expression] = [] + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _callee = source._callee + _arguments = source._arguments + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._callee) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &_storage._arguments) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._callee { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !_storage._arguments.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._arguments, fieldNumber: 2) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_NewExpression, rhs: Compiler_Protobuf_NewExpression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._callee != rhs_storage._callee {return false} + if _storage._arguments != rhs_storage._arguments {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_MemberExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".MemberExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "object"), + 2: .same(proto: "name"), + 3: .same(proto: "expression"), + ] + + fileprivate class _StorageClass { + var _object: Compiler_Protobuf_Expression? = nil + var _property: Compiler_Protobuf_MemberExpression.OneOf_Property? + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _object = source._object + _property = source._property + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._object) }() + case 2: try { + var v: String? + try decoder.decodeSingularStringField(value: &v) + if let v = v { + if _storage._property != nil {try decoder.handleConflictingOneOf()} + _storage._property = .name(v) + } + }() + case 3: try { + var v: Compiler_Protobuf_Expression? + var hadOneofValue = false + if let current = _storage._property { + hadOneofValue = true + if case .expression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._property = .expression(v) + } + }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._object { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + switch _storage._property { + case .name?: try { + guard case .name(let v)? = _storage._property else { preconditionFailure() } + try visitor.visitSingularStringField(value: v, fieldNumber: 2) + }() + case .expression?: try { + guard case .expression(let v)? = _storage._property else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + }() + case nil: break + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_MemberExpression, rhs: Compiler_Protobuf_MemberExpression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._object != rhs_storage._object {return false} + if _storage._property != rhs_storage._property {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_UnaryExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".UnaryExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "operator"), + 2: .same(proto: "argument"), + ] + + fileprivate class _StorageClass { + var _operator: String = String() + var _argument: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _operator = source._operator + _argument = source._argument + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &_storage._operator) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._argument) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !_storage._operator.isEmpty { + try visitor.visitSingularStringField(value: _storage._operator, fieldNumber: 1) + } + try { if let v = _storage._argument { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_UnaryExpression, rhs: Compiler_Protobuf_UnaryExpression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._operator != rhs_storage._operator {return false} + if _storage._argument != rhs_storage._argument {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_BinaryExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".BinaryExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "operator"), + 2: .same(proto: "lhs"), + 3: .same(proto: "rhs"), + ] + + fileprivate class _StorageClass { + var _operator: String = String() + var _lhs: Compiler_Protobuf_Expression? = nil + var _rhs: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _operator = source._operator + _lhs = source._lhs + _rhs = source._rhs + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &_storage._operator) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._lhs) }() + case 3: try { try decoder.decodeSingularMessageField(value: &_storage._rhs) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !_storage._operator.isEmpty { + try visitor.visitSingularStringField(value: _storage._operator, fieldNumber: 1) + } + try { if let v = _storage._lhs { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = _storage._rhs { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_BinaryExpression, rhs: Compiler_Protobuf_BinaryExpression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._operator != rhs_storage._operator {return false} + if _storage._lhs != rhs_storage._lhs {return false} + if _storage._rhs != rhs_storage._rhs {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_UpdateExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".UpdateExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "operator"), + 2: .same(proto: "isPrefix"), + 3: .same(proto: "argument"), + ] + + fileprivate class _StorageClass { + var _operator: String = String() + var _isPrefix: Bool = false + var _argument: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _operator = source._operator + _isPrefix = source._isPrefix + _argument = source._argument + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &_storage._operator) }() + case 2: try { try decoder.decodeSingularBoolField(value: &_storage._isPrefix) }() + case 3: try { try decoder.decodeSingularMessageField(value: &_storage._argument) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !_storage._operator.isEmpty { + try visitor.visitSingularStringField(value: _storage._operator, fieldNumber: 1) + } + if _storage._isPrefix != false { + try visitor.visitSingularBoolField(value: _storage._isPrefix, fieldNumber: 2) + } + try { if let v = _storage._argument { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_UpdateExpression, rhs: Compiler_Protobuf_UpdateExpression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._operator != rhs_storage._operator {return false} + if _storage._isPrefix != rhs_storage._isPrefix {return false} + if _storage._argument != rhs_storage._argument {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_YieldExpression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".YieldExpression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "argument"), + ] + + fileprivate class _StorageClass { + var _argument: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _argument = source._argument + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._argument) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._argument { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_YieldExpression, rhs: Compiler_Protobuf_YieldExpression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._argument != rhs_storage._argument {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_SpreadElement: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SpreadElement" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "argument"), + ] + + fileprivate class _StorageClass { + var _argument: Compiler_Protobuf_Expression? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _argument = source._argument + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._argument) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._argument { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_SpreadElement, rhs: Compiler_Protobuf_SpreadElement) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._argument != rhs_storage._argument {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_V8IntrinsicIdentifier: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".V8IntrinsicIdentifier" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.name) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_V8IntrinsicIdentifier, rhs: Compiler_Protobuf_V8IntrinsicIdentifier) -> Bool { + if lhs.name != rhs.name {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Compiler_Protobuf_Expression: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Expression" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "identifier"), + 2: .same(proto: "numberLiteral"), + 3: .same(proto: "bigIntLiteral"), + 4: .same(proto: "stringLiteral"), + 5: .same(proto: "regExpLiteral"), + 6: .same(proto: "booleanLiteral"), + 7: .same(proto: "nullLiteral"), + 8: .same(proto: "thisExpression"), + 9: .same(proto: "assignmentExpression"), + 10: .same(proto: "objectExpression"), + 11: .same(proto: "arrayExpression"), + 12: .same(proto: "functionExpression"), + 13: .same(proto: "arrowFunctionExpression"), + 14: .same(proto: "callExpression"), + 15: .same(proto: "newExpression"), + 16: .same(proto: "memberExpression"), + 17: .same(proto: "unaryExpression"), + 18: .same(proto: "binaryExpression"), + 19: .same(proto: "updateExpression"), + 20: .same(proto: "yieldExpression"), + 21: .same(proto: "spreadElement"), + 22: .same(proto: "v8IntrinsicIdentifier"), + ] + + fileprivate class _StorageClass { + var _expression: Compiler_Protobuf_Expression.OneOf_Expression? + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _expression = source._expression + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Compiler_Protobuf_Identifier? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .identifier(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .identifier(v) + } + }() + case 2: try { + var v: Compiler_Protobuf_NumberLiteral? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .numberLiteral(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .numberLiteral(v) + } + }() + case 3: try { + var v: Compiler_Protobuf_BigIntLiteral? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .bigIntLiteral(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .bigIntLiteral(v) + } + }() + case 4: try { + var v: Compiler_Protobuf_StringLiteral? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .stringLiteral(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .stringLiteral(v) + } + }() + case 5: try { + var v: Compiler_Protobuf_RegExpLiteral? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .regExpLiteral(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .regExpLiteral(v) + } + }() + case 6: try { + var v: Compiler_Protobuf_BooleanLiteral? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .booleanLiteral(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .booleanLiteral(v) + } + }() + case 7: try { + var v: Compiler_Protobuf_NullLiteral? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .nullLiteral(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .nullLiteral(v) + } + }() + case 8: try { + var v: Compiler_Protobuf_ThisExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .thisExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .thisExpression(v) + } + }() + case 9: try { + var v: Compiler_Protobuf_AssignmentExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .assignmentExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .assignmentExpression(v) + } + }() + case 10: try { + var v: Compiler_Protobuf_ObjectExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .objectExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .objectExpression(v) + } + }() + case 11: try { + var v: Compiler_Protobuf_ArrayExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .arrayExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .arrayExpression(v) + } + }() + case 12: try { + var v: Compiler_Protobuf_FunctionExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .functionExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .functionExpression(v) + } + }() + case 13: try { + var v: Compiler_Protobuf_ArrowFunctionExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .arrowFunctionExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .arrowFunctionExpression(v) + } + }() + case 14: try { + var v: Compiler_Protobuf_CallExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .callExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .callExpression(v) + } + }() + case 15: try { + var v: Compiler_Protobuf_NewExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .newExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .newExpression(v) + } + }() + case 16: try { + var v: Compiler_Protobuf_MemberExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .memberExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .memberExpression(v) + } + }() + case 17: try { + var v: Compiler_Protobuf_UnaryExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .unaryExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .unaryExpression(v) + } + }() + case 18: try { + var v: Compiler_Protobuf_BinaryExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .binaryExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .binaryExpression(v) + } + }() + case 19: try { + var v: Compiler_Protobuf_UpdateExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .updateExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .updateExpression(v) + } + }() + case 20: try { + var v: Compiler_Protobuf_YieldExpression? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .yieldExpression(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .yieldExpression(v) + } + }() + case 21: try { + var v: Compiler_Protobuf_SpreadElement? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .spreadElement(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .spreadElement(v) + } + }() + case 22: try { + var v: Compiler_Protobuf_V8IntrinsicIdentifier? + var hadOneofValue = false + if let current = _storage._expression { + hadOneofValue = true + if case .v8IntrinsicIdentifier(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._expression = .v8IntrinsicIdentifier(v) + } + }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch _storage._expression { + case .identifier?: try { + guard case .identifier(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .numberLiteral?: try { + guard case .numberLiteral(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case .bigIntLiteral?: try { + guard case .bigIntLiteral(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + }() + case .stringLiteral?: try { + guard case .stringLiteral(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + }() + case .regExpLiteral?: try { + guard case .regExpLiteral(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 5) + }() + case .booleanLiteral?: try { + guard case .booleanLiteral(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 6) + }() + case .nullLiteral?: try { + guard case .nullLiteral(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 7) + }() + case .thisExpression?: try { + guard case .thisExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 8) + }() + case .assignmentExpression?: try { + guard case .assignmentExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 9) + }() + case .objectExpression?: try { + guard case .objectExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 10) + }() + case .arrayExpression?: try { + guard case .arrayExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 11) + }() + case .functionExpression?: try { + guard case .functionExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 12) + }() + case .arrowFunctionExpression?: try { + guard case .arrowFunctionExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 13) + }() + case .callExpression?: try { + guard case .callExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 14) + }() + case .newExpression?: try { + guard case .newExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 15) + }() + case .memberExpression?: try { + guard case .memberExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 16) + }() + case .unaryExpression?: try { + guard case .unaryExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 17) + }() + case .binaryExpression?: try { + guard case .binaryExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 18) + }() + case .updateExpression?: try { + guard case .updateExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 19) + }() + case .yieldExpression?: try { + guard case .yieldExpression(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 20) + }() + case .spreadElement?: try { + guard case .spreadElement(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 21) + }() + case .v8IntrinsicIdentifier?: try { + guard case .v8IntrinsicIdentifier(let v)? = _storage._expression else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 22) + }() + case nil: break + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Compiler_Protobuf_Expression, rhs: Compiler_Protobuf_Expression) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._expression != rhs_storage._expression {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/Fuzzilli/Protobuf/ast.proto b/Sources/Fuzzilli/Protobuf/ast.proto new file mode 100644 index 00000000..bebc17b8 --- /dev/null +++ b/Sources/Fuzzilli/Protobuf/ast.proto @@ -0,0 +1,327 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; +package compiler.protobuf; + +message AST { + repeated Statement statements = 1; +} + +// A parameter in a function declaration. Not an expression on its own. +message Parameter { + string name = 1; +} + +message EmptyStatement { +} + +message BlockStatement { + repeated Statement body = 1; +} + +enum VariableDeclarationKind { + VAR = 0; + LET = 1; + CONST = 2; +} + +message VariableDeclarator { + string name = 1; + // The value is optional + Expression value = 2; +} + +message VariableDeclaration { + VariableDeclarationKind kind = 1; + repeated VariableDeclarator declarations = 2; +} + +enum FunctionType { + PLAIN = 0; + GENERATOR = 1; + ASYNC = 2; + ASYNC_GENERATOR = 3; +} + +message FunctionDeclaration { + string name = 1; + FunctionType type = 2; + repeated Parameter parameters = 3; + repeated Statement body = 4; +} + +message ReturnStatement { + // The argument is optional + Expression argument = 1; +} + +message ExpressionStatement { + Expression expression = 1; +} + +message IfStatement { + Expression test = 1; + Statement ifBody = 2; + // The else body is optional + Statement elseBody = 3; +} + +message WhileLoop { + Expression test = 1; + Statement body = 2; +} + +message DoWhileLoop { + Expression test = 1; + Statement body = 2; +} + +message ForLoop { + VariableDeclarator init = 1; + Expression test = 2; + Expression update = 3; + Statement body = 4; +} + +message ForInLoop { + VariableDeclarator left = 1; + Expression right = 2; + Statement body = 3; +} + +message ForOfLoop { + VariableDeclarator left = 1; + Expression right = 2; + Statement body = 3; +} + +message CatchClause { + // The parameter is optional + Parameter parameter = 1; + repeated Statement body = 2; +} + +message FinallyClause { + repeated Statement body = 3; +} + +message TryStatement { + repeated Statement body = 1; + // The catch clause is optional + CatchClause catch = 2; + // The finally clause is optional + FinallyClause finally = 3; +} + +message ThrowStatement { + Expression argument = 1; +} + +message Statement { + oneof statement { + EmptyStatement emptyStatement = 1; + BlockStatement blockStatement = 2; + VariableDeclaration variableDeclaration = 3; + FunctionDeclaration functionDeclaration = 4; + ReturnStatement returnStatement = 5; + ExpressionStatement expressionStatement = 6; + IfStatement ifStatement = 7; + WhileLoop whileLoop = 8; + DoWhileLoop doWhileLoop = 9; + ForLoop forLoop = 10; + ForInLoop forInLoop = 11; + ForOfLoop forOfLoop = 12; + TryStatement tryStatement = 13; + ThrowStatement throwStatement = 14; + } +} + +message Identifier { + string name = 1; +} + +message NumberLiteral { + double value = 1; +} + +message BigIntLiteral { + string value = 1; +} + +message StringLiteral { + string value = 1; +} + +message RegExpLiteral { + string pattern = 1; + string flags = 2; +} + +message BooleanLiteral { + bool value = 1; +} + +message NullLiteral { +} + +message ThisExpression { +} + +message AssignmentExpression { + string operator = 1; + Expression lhs = 2; + Expression rhs = 3; +} + +message ObjectProperty { + oneof key { + // A "regular" property. + string name = 1; + // An element. + int64 index = 2; + // A computed property. + Expression expression = 3; + } + Expression value = 4; +} + +message ObjectMethod { + string name = 1; + FunctionType type = 2; + repeated Parameter parameters = 3; + repeated Statement body = 4; +} + +message ObjectGetter { + string name = 1; + repeated Statement body = 2; +} + +message ObjectSetter { + string name = 1; + Parameter parameter = 2; + repeated Statement body = 3; +} + +message ObjectField { + oneof field { + ObjectProperty property = 1; + ObjectMethod method = 2; + ObjectGetter getter = 3; + ObjectSetter setter = 4; + } +} + +message ObjectExpression { + repeated ObjectField fields = 1; +} + +message ArrayExpression { + // This can contain empty expressions which represent holes. + repeated Expression elements = 1; +} + +message FunctionExpression { + FunctionType type = 1; + repeated Parameter parameters = 2; + repeated Statement body = 3; +} + +message ArrowFunctionExpression { + FunctionType type = 1; + repeated Parameter parameters = 2; + // The body can either be an expression or a block statement. + oneof body { + Statement block = 3; + Expression expression = 4; + } +} + +message CallExpression { + Expression callee = 1; + repeated Expression arguments = 2; +} + +message NewExpression { + Expression callee = 1; + repeated Expression arguments = 2; +} + +message MemberExpression { + Expression object = 1; + oneof property { + // A "regular" property. + string name = 2; + // A computed property or element. + Expression expression = 3; + } +} + +message UnaryExpression { + string operator = 1; + Expression argument = 2; +} + +message BinaryExpression { + string operator = 1; + Expression lhs = 2; + Expression rhs = 3; +} + +message UpdateExpression { + string operator = 1; + bool isPrefix = 2; + Expression argument = 3; +} + +message YieldExpression { + // The argument is optional + Expression argument = 1; +} + +message SpreadElement { + Expression argument = 1; +} + +message V8IntrinsicIdentifier { + string name = 1; +} + +message Expression { + oneof expression { + Identifier identifier = 1; + NumberLiteral numberLiteral = 2; + BigIntLiteral bigIntLiteral = 3; + StringLiteral stringLiteral = 4; + RegExpLiteral regExpLiteral = 5; + BooleanLiteral booleanLiteral = 6; + NullLiteral nullLiteral = 7; + ThisExpression thisExpression = 8; + AssignmentExpression assignmentExpression = 9; + ObjectExpression objectExpression = 10; + ArrayExpression arrayExpression = 11; + FunctionExpression functionExpression = 12; + ArrowFunctionExpression arrowFunctionExpression = 13; + CallExpression callExpression = 14; + NewExpression newExpression = 15; + MemberExpression memberExpression = 16; + UnaryExpression unaryExpression = 17; + BinaryExpression binaryExpression = 18; + UpdateExpression updateExpression = 19; + YieldExpression yieldExpression = 20; + SpreadElement spreadElement = 21; + V8IntrinsicIdentifier v8IntrinsicIdentifier = 22; + } +} diff --git a/Sources/Fuzzilli/Protobuf/operations.pb.swift b/Sources/Fuzzilli/Protobuf/operations.pb.swift index f36ba9dc..4a0847d4 100644 --- a/Sources/Fuzzilli/Protobuf/operations.pb.swift +++ b/Sources/Fuzzilli/Protobuf/operations.pb.swift @@ -1817,6 +1817,8 @@ public struct Fuzzilli_Protobuf_Eval { public var code: String = String() + public var hasOutput_p: Bool = false + public var unknownFields = SwiftProtobuf.UnknownStorage() public init() {} @@ -5997,6 +5999,7 @@ extension Fuzzilli_Protobuf_Eval: SwiftProtobuf.Message, SwiftProtobuf._MessageI public static let protoMessageName: String = _protobuf_package + ".Eval" public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .same(proto: "code"), + 2: .same(proto: "hasOutput"), ] public mutating func decodeMessage(decoder: inout D) throws { @@ -6006,6 +6009,7 @@ extension Fuzzilli_Protobuf_Eval: SwiftProtobuf.Message, SwiftProtobuf._MessageI // enabled. https://github.com/apple/swift-protobuf/issues/1034 switch fieldNumber { case 1: try { try decoder.decodeSingularStringField(value: &self.code) }() + case 2: try { try decoder.decodeSingularBoolField(value: &self.hasOutput_p) }() default: break } } @@ -6015,11 +6019,15 @@ extension Fuzzilli_Protobuf_Eval: SwiftProtobuf.Message, SwiftProtobuf._MessageI if !self.code.isEmpty { try visitor.visitSingularStringField(value: self.code, fieldNumber: 1) } + if self.hasOutput_p != false { + try visitor.visitSingularBoolField(value: self.hasOutput_p, fieldNumber: 2) + } try unknownFields.traverse(visitor: &visitor) } public static func ==(lhs: Fuzzilli_Protobuf_Eval, rhs: Fuzzilli_Protobuf_Eval) -> Bool { if lhs.code != rhs.code {return false} + if lhs.hasOutput_p != rhs.hasOutput_p {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } diff --git a/Sources/Fuzzilli/Protobuf/operations.proto b/Sources/Fuzzilli/Protobuf/operations.proto index d8ab65a7..6995dc8b 100644 --- a/Sources/Fuzzilli/Protobuf/operations.proto +++ b/Sources/Fuzzilli/Protobuf/operations.proto @@ -525,6 +525,7 @@ message DefineNamedVariable { message Eval { string code = 1; + bool hasOutput = 2; } message CallSuperConstructor { diff --git a/Sources/Fuzzilli/Util/Stack.swift b/Sources/Fuzzilli/Util/Stack.swift index a4e0ec02..5d98f20a 100644 --- a/Sources/Fuzzilli/Util/Stack.swift +++ b/Sources/Fuzzilli/Util/Stack.swift @@ -69,4 +69,12 @@ public struct Stack { public mutating func removeAll() { buffer.removeAll() } + + public func elementsStartingAtTop() -> ReversedCollection<[Element]> { + return buffer.reversed() + } + + public func elementsStartingAtBottom() -> [Element] { + return buffer + } } diff --git a/Sources/FuzzilliCli/CodeGeneratorWeights.swift b/Sources/FuzzilliCli/CodeGeneratorWeights.swift index d76bd189..67db4b51 100644 --- a/Sources/FuzzilliCli/CodeGeneratorWeights.swift +++ b/Sources/FuzzilliCli/CodeGeneratorWeights.swift @@ -28,7 +28,7 @@ let codeGeneratorWeights = [ "ThisGenerator": 3, "ArgumentsGenerator": 1, "BuiltinGenerator": 10, - + "ObjectLiteralGenerator": 15, // The following generators determine how frequently different // types of fields are generated in object literals. diff --git a/Tests/FuzzilliTests/CompilerTests.swift b/Tests/FuzzilliTests/CompilerTests.swift new file mode 100644 index 00000000..38c0ecb0 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests.swift @@ -0,0 +1,138 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import XCTest +import Foundation +@testable import Fuzzilli + +/// Compiler testsuite. +/// +/// This testcase runs a number of "end-to-end" compiler tests using the .js files located in the CompilerTests/ directory: +/// For every such JavaScript testcase: +/// - The original code is executed inside a JavaScript engine (e.g. node.js) and the output recorded +/// - The code is parsed into an AST, then compiled to FuzzIL +/// - The resulting FuzzIL program is lifted back to JavaScript +/// - The new JavaScript code is again executed inside the same engine and the output again recorded +/// - The test passes if there are no errors along the way and if the output of both executions is identical +class CompilerTests: XCTestCase { + /// Path to the node.js binary. The testcase will first look for the `node` binary in the $PATH and store it here. + /// Will be used to execute testcases and to run the JavaScript parser to obtain an AST from JavaScript code. + var nodejsPath = "" + + /// Prefix to execute before every JavaScript testcase. Its main task is to define the `output` function. + let prefix = Data("const output = console.log;\n".utf8) + + func testFuzzILCompiler() throws { + // Initialize the parser. This can fail if no node.js executable is found or if the + // parser's node.js dependencies are not installed. In that case, skip these tests. + guard let parser = JavaScriptParser() else { + throw XCTSkip("The JavaScript parser does not appear to be working. See Sources/Fuzzilli/Compiler/Parser/README.md for details on how to set up the parser.") + } + + // Reuse the node.js executable used by the parser to execute the testcases. + nodejsPath = parser.nodejsExecutablePath + + let compiler = JavaScriptCompiler() + + let lifter = JavaScriptLifter(ecmaVersion: .es6) + + // TODO remove outputs once tests pass? + for testcasePath in enumerateAllTestcases() { + let testName = URL(fileURLWithPath: testcasePath).lastPathComponent + + // Execute the original code and record the output. + let (exitcode1, expectedOutput) = try executeScript(testcasePath) + guard exitcode1 == 0 else { + XCTFail("Tescase \(testName) failed to execute. Output:\n\(expectedOutput)") + continue + } + + // Compile the JavaScript code to FuzzIL... + guard let ast = try? parser.parse(testcasePath) else { + XCTFail("Could not parse \(testName)") + continue + } + guard let program = try? compiler.compile(ast) else { + XCTFail("Could not compile \(testName)") + continue + } + + // ... then lift it back to JavaScript and execute it again. + let script = lifter.lift(program) + let outputPath = writeTemporaryFile(withContent: script) + let (exitcode2, actualOutput) = try executeScript(outputPath) + try FileManager.default.removeItem(atPath: outputPath) + guard exitcode2 == 0 else { + XCTFail("Tescase \(testName) failed to execute after compiling and lifting. Output:\n\(actualOutput)") + continue + } + + // The output of both executions must be identical. + if expectedOutput != actualOutput { + XCTFail("Testcase \(testName) failed.\nExpected output:\n\(expectedOutput)\nActual output:\n\(actualOutput)") + } + } + } + + /// Executes the JavaScript script at the specified path using the configured engine and returns the stdout. + private func executeScript(_ path: String) throws -> (exitcode: Int32, output: String) { + let script = try Data(contentsOf: URL(fileURLWithPath: path)) + return try execute(nodejsPath, withInput: prefix + script, withArguments: ["--allow-natives-syntax"]) + } + + func execute(_ path: String, withInput input: Data = Data(), withArguments arguments: [String] = []) throws -> (exitcode: Int32, output: String) { + let inputPipe = Pipe() + let outputPipe = Pipe() + + // Write input into input pipe, then close it. + try inputPipe.fileHandleForWriting.write(contentsOf: input) + try inputPipe.fileHandleForWriting.close() + + // Execute the subprocess. + let task = Process() + task.standardOutput = outputPipe + task.standardError = outputPipe + task.arguments = arguments + task.executableURL = URL(fileURLWithPath: path) + task.standardInput = inputPipe + try task.run() + task.waitUntilExit() + + // Fetch and return the output. + let data = outputPipe.fileHandleForReading.readDataToEndOfFile() + return (task.terminationStatus, String(data: data, encoding: .utf8)!) + } + + /// Returns the absolute path of a random file inside the temporary directory. The file is not created. + private func getTemporaryFilename(withExtension ext: String) -> String { + return FileManager.default.temporaryDirectory.path + UUID().uuidString + "." + ext + } + + /// Writes the given data to a newly created temporary file and returns the absolute path to that file. + private func writeTemporaryFile(withContent content: String) -> String { + let path = getTemporaryFilename(withExtension: "js") + FileManager.default.createFile(atPath: path, contents: Data(content.utf8)) + return path + } + + /// Returns the absolute paths of all .js compiler testcases. + private func enumerateAllTestcases() -> [String] { + return Bundle.module.paths(forResourcesOfType: "js", inDirectory: "CompilerTests") + } + + public enum TestError: Error { + case parserError(String) + } + +} diff --git a/Tests/FuzzilliTests/CompilerTests/README.md b/Tests/FuzzilliTests/CompilerTests/README.md new file mode 100644 index 00000000..beebf450 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/README.md @@ -0,0 +1,9 @@ +# Compiler Tests + +An "end-to-end" testsuite for the JavaScript-to-FuzzIL compiler. + +How these work: +- These testcases contain JavaScript snippets that produce some output using the `output` function +- During testing, every (original) testcase is executed in a JavaScript engine such as node.js +- The testcase is then compiled to FuzzIL, lifted back to JavaScript, and executed again +- The test passes if the output of both executions is identical (and if there were no errors) diff --git a/Tests/FuzzilliTests/CompilerTests/basic_control_flow.js b/Tests/FuzzilliTests/CompilerTests/basic_control_flow.js new file mode 100644 index 00000000..c56b6f86 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/basic_control_flow.js @@ -0,0 +1,63 @@ +if (typeof output === 'undefined') output = console.log; + +let a = 5; +let b = 2; + +if (a > b) { + output("inside if"); +} + +if (b > a) { + output("inside if"); +} else { + output("inside else"); +} + +while (a > b) { + output("inside while loop"); + a--; +} + +if (b > a) { + output("inside if"); +} else if (a == b) { + output("inside else-if"); +} else { + output("inside else"); +} + +do { + output("inside do-while loop"); +} while (a > b); + +for (let i = 0; i < a; i++) { + output("inside for loop"); +} + +for (let p in [1,2,3]) { + output("inside for-in loop"); +} + +for (let v of [4,5]) { + output("inside for-of loop"); +} + +try { + output("inside try"); +} catch { + output("inside catch"); +} + +try { + output("inside try"); + throw 42; +} catch (e) { + output("caught " + e); + output("inside catch"); +} + +try { + output("inside try"); +} finally { + output("inside finally"); +} diff --git a/Tests/FuzzilliTests/CompilerTests/basic_expressions.js b/Tests/FuzzilliTests/CompilerTests/basic_expressions.js new file mode 100644 index 00000000..dfd3b2d1 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/basic_expressions.js @@ -0,0 +1,35 @@ +if (typeof output === 'undefined') output = console.log; + +let a = 42; +let b = 3; + +output(!a); +output(+a); +output(-a); +output(~a); +output(++a); +output(--a); +output(a++); +output(a--); + +output(a + b); +output(a - b); +output(a * b); +output(a / b); +output(a % b); +output(a ** b); +output(a ^ b); +output(a & b); +output(a | b); +output(a << b); +output(a >> b); +output(a >>> b); +output(a && b); +output(a || b); + +let arr = [1,2]; +output(typeof arr); +output(0 in arr); +output(2 in arr); +output(arr instanceof Array); +output(arr instanceof Object); diff --git a/Tests/FuzzilliTests/CompilerTests/basic_functions.js b/Tests/FuzzilliTests/CompilerTests/basic_functions.js new file mode 100644 index 00000000..ba49693b --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/basic_functions.js @@ -0,0 +1,29 @@ +if (typeof output === 'undefined') output = console.log; + +function f1(a, b) { + return a + b; +} +output(f1(1, 2)); + +let f2 = function(a, b) { + return a * b; +} +output(f2(3, 4)); + +let f3 = (x) => x + 1; +output(f3(5)); + +let f4 = (x) => { return x * 2 }; +output(f4(5)); + +function* f5(n) { + for (let i = 0; i < n; i++) { + yield n; + } +} +output(Array.from(f5(3)).length); + +async function f6() { + return 42; +} +output(f6().constructor.name); diff --git a/Tests/FuzzilliTests/CompilerTests/basic_object_access.js b/Tests/FuzzilliTests/CompilerTests/basic_object_access.js new file mode 100644 index 00000000..6a5720e7 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/basic_object_access.js @@ -0,0 +1,14 @@ +if (typeof output === 'undefined') output = console.log; + +let o = {} + +o.a = 1; +o.b = 2 * o.a; +o['c'] = o['a'] + 2 * o['b']; + +o[0] = 1; +o[1] = 1; +o[2] = o[1] + o[0]; +o[3] = o[2] + o[1]; + +output(JSON.stringify(o)); diff --git a/Tests/FuzzilliTests/CompilerTests/basic_objects.js b/Tests/FuzzilliTests/CompilerTests/basic_objects.js new file mode 100644 index 00000000..1ce4a3b9 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/basic_objects.js @@ -0,0 +1,36 @@ +if (typeof output === 'undefined') output = console.log; + +let o = {}; +output(o); + +let b = 1337; +o = {a: 42, b, 0: "foo", 1: "bar" }; +output(o.a); +output(o.b); +output(o[0]); +output(o[1]); + +o = {b: 42, ["baz"]: 13.37, get c() { return 13.37; }, set c(v) { output(v); }}; +output(o.b); +output(o.baz); +output(o.c); +o.c = 1234; + +o = {m(arg) { return arg; }}; +output(o.m(13.37)); + +let a = [1,2,3]; +output(a.length); +output(a[1]); + +a = [1.1,,3.3,,5.5,]; +output(a.length); +output(a[0]); +output(a[1]); +output(a[2]); + +function C(foo) { + this.foo = foo; +} +o = new C(1337); +output(o.foo); diff --git a/Tests/FuzzilliTests/CompilerTests/basic_scoping.js b/Tests/FuzzilliTests/CompilerTests/basic_scoping.js new file mode 100644 index 00000000..1c67d427 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/basic_scoping.js @@ -0,0 +1,20 @@ +if (typeof output === 'undefined') output = console.log; + +let x = 42; +let y = 1337; + +output(x); +output(y); + +function foo(x) { + output(x); + output(y); + { + let x = 43; + output(x); + output(y); + } + output(x); + output(y); +} +foo(44); diff --git a/Tests/FuzzilliTests/CompilerTests/basic_variables.js b/Tests/FuzzilliTests/CompilerTests/basic_variables.js new file mode 100644 index 00000000..e9687963 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/basic_variables.js @@ -0,0 +1,14 @@ +if (typeof output === 'undefined') output = console.log; + +var a, b = 42; +a = 41; +b -= 10; +output(a + b); + +let c = 1, d, e = 5; +c = 2; +d = e; +output(c + d - e); + +const C = c; +output(C); diff --git a/Tests/FuzzilliTests/CompilerTests/global_variable_access.js b/Tests/FuzzilliTests/CompilerTests/global_variable_access.js new file mode 100644 index 00000000..de68fef2 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/global_variable_access.js @@ -0,0 +1,14 @@ +if (typeof output === 'undefined') output = console.log; + +function foo() { + a = 42; + output(a); + output(this.a); + { + let a = 1337; + output(a); + } + output(a); +} +foo(); +output(a); diff --git a/Tests/FuzzilliTests/CompilerTests/literals.js b/Tests/FuzzilliTests/CompilerTests/literals.js new file mode 100644 index 00000000..96ca2ab9 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/literals.js @@ -0,0 +1,11 @@ +if (typeof output === 'undefined') output = console.log; + +output(42); +output(13.37); +output(123n); +output("a string literal"); +output(/regex/gs); +output(true); +output(false); +output(null); +output(undefined); diff --git a/Tests/FuzzilliTests/CompilerTests/multiline_string_literals.js b/Tests/FuzzilliTests/CompilerTests/multiline_string_literals.js new file mode 100644 index 00000000..242b06ef --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/multiline_string_literals.js @@ -0,0 +1,22 @@ +if (typeof output === 'undefined') output = console.log; + +let s = "abc\ndef\nghi"; +output(s); + +s = "abc\ +def\ +ghi"; +output(s); + +s = "abc" + +"def" + +"ghi"; +output(s); + +// TODO support template literals and add more tests for them +/* +s = `abc +def +ghi`; +output(s); +*/ diff --git a/Tests/FuzzilliTests/CompilerTests/recursive_functions.js b/Tests/FuzzilliTests/CompilerTests/recursive_functions.js new file mode 100644 index 00000000..1e916e2d --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/recursive_functions.js @@ -0,0 +1,11 @@ +if (typeof output === 'undefined') output = console.log; + +function f(v) { + if (v > 1) { + return f(v - 1) * v; + } else { + return 1; + } +} +output(f(42)); + diff --git a/Tests/FuzzilliTests/CompilerTests/spreading.js b/Tests/FuzzilliTests/CompilerTests/spreading.js new file mode 100644 index 00000000..33cfaa8e --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/spreading.js @@ -0,0 +1,27 @@ +if (typeof output === 'undefined') output = console.log; + +function foo(a, b, c) { + output(a); + output(b); + output(c); +} + +let a = [1,2,3,4]; + +foo(...a); +foo(100, ...a); +foo(100, 101, ...a); +foo(100, 101, 102, ...a); + +new foo(...a); +new foo(100, ...a); +new foo(100, 101, ...a); +new foo(100, 101, 102, ...a); + +let o = { foo }; +o.foo(...a); +o.foo(100, ...a); +o.foo(100, 101, ...a); +o.foo(100, 101, 102, ...a); + +// TODO also add tests for spreading in array literals diff --git a/Tests/FuzzilliTests/CompilerTests/v8_natives.js b/Tests/FuzzilliTests/CompilerTests/v8_natives.js new file mode 100644 index 00000000..b077477c --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/v8_natives.js @@ -0,0 +1,13 @@ +if (typeof output === 'undefined') output = console.log; + +function foo() { + return 42; +} +output(%GetOptimizationStatus(foo)); +foo(); +%PrepareFunctionForOptimization(foo); +foo(); +%OptimizeFunctionOnNextCall(foo); +foo(); +output(%GetOptimizationStatus(foo)); + diff --git a/Tests/FuzzilliTests/CompilerTests/variable_hoisting.js b/Tests/FuzzilliTests/CompilerTests/variable_hoisting.js new file mode 100644 index 00000000..0416e4b7 --- /dev/null +++ b/Tests/FuzzilliTests/CompilerTests/variable_hoisting.js @@ -0,0 +1,29 @@ +if (typeof output === 'undefined') output = console.log; + +function foo() { + output(v1); + var v1 = 42; + output(v1); + + output(v2); + do { + var v2 = 43; + output(v2); + } while(false); + output(v2); + + let v3 = 44; + function bar() { + // TODO the following doesn't currently work. + //output(v3); + //v3 = 45; + //output(v3); + var v3 = 46; + output(v3); + v3 = 47; + output(v3); + } + bar(); + output(v3); +} +foo(); diff --git a/Tests/FuzzilliTests/LifterTest.swift b/Tests/FuzzilliTests/LifterTest.swift index d84dc524..df14a8fb 100644 --- a/Tests/FuzzilliTests/LifterTest.swift +++ b/Tests/FuzzilliTests/LifterTest.swift @@ -73,7 +73,7 @@ class LifterTests: XCTestCase { v1.r = SomeObj.foo.bar.baz(42, 42); v1.s = Math.random() + 13.37; v1.s; - + """ XCTAssertEqual(actual, expected) @@ -409,7 +409,7 @@ class LifterTests: XCTestCase { } cls.addInstanceSetter(for: "baz") { this, v in } - + cls.addStaticProperty("foo") cls.addStaticInitializer { this in b.setProperty("foo", of: this, to: i)