From 617069b3986e9271d6e73191b899aa914e430dd6 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 8 Jan 2023 02:13:36 -0400 Subject: Moved compiler target machinery under meta/compiler. --- stdlib/source/library/lux/abstract/apply.lux | 3 +- .../library/lux/control/concurrency/atom.lux | 3 +- .../library/lux/control/concurrency/thread.lux | 5 +- stdlib/source/library/lux/control/parser.lux | 127 +- stdlib/source/library/lux/control/reader.lux | 4 +- stdlib/source/library/lux/control/thread.lux | 1 - stdlib/source/library/lux/control/try.lux | 1 - stdlib/source/library/lux/control/writer.lux | 3 +- stdlib/source/library/lux/data/collection/list.lux | 3 +- .../library/lux/data/collection/sequence.lux | 1 - .../library/lux/data/collection/tree/zipper.lux | 3 +- stdlib/source/library/lux/data/text.lux | 3 +- stdlib/source/library/lux/data/text/buffer.lux | 5 +- .../source/library/lux/data/text/encoding/utf8.lux | 3 +- stdlib/source/library/lux/debug.lux | 5 +- stdlib/source/library/lux/ffi.jvm.lux | 23 +- stdlib/source/library/lux/ffi.lux | 6 +- stdlib/source/library/lux/ffi.php.lux | 1 - stdlib/source/library/lux/ffi.scm.lux | 1 - stdlib/source/library/lux/math.lux | 2 +- stdlib/source/library/lux/math/number/frac.lux | 3 +- stdlib/source/library/lux/math/number/i32.lux | 5 +- .../library/lux/meta/compiler/default/init.lux | 5 +- .../library/lux/meta/compiler/default/platform.lux | 9 +- .../language/lux/phase/extension/analysis/js.lux | 5 +- .../language/lux/phase/extension/analysis/jvm.lux | 47 +- .../language/lux/phase/extension/analysis/lua.lux | 5 +- .../lux/phase/extension/analysis/python.lux | 5 +- .../language/lux/phase/extension/analysis/ruby.lux | 5 +- .../lux/phase/extension/declaration/jvm.lux | 44 +- .../lux/phase/extension/declaration/lux.lux | 1 - .../lux/phase/extension/translation/js/common.lux | 4 +- .../lux/phase/extension/translation/js/host.lux | 5 +- .../lux/phase/extension/translation/jvm/common.lux | 55 +- .../lux/phase/extension/translation/jvm/host.lux | 49 +- .../lux/phase/extension/translation/lua/common.lux | 4 +- .../lux/phase/extension/translation/lua/host.lux | 5 +- .../phase/extension/translation/python/common.lux | 4 +- .../phase/extension/translation/python/host.lux | 5 +- .../phase/extension/translation/ruby/common.lux | 4 +- .../lux/phase/extension/translation/ruby/host.lux | 5 +- .../lux/phase/translation/c++/primitive.lux | 5 +- .../language/lux/phase/translation/c++/runtime.lux | 5 +- .../language/lux/phase/translation/c++/type.lux | 5 +- .../language/lux/phase/translation/js/function.lux | 5 +- .../language/lux/phase/translation/js/loop.lux | 5 +- .../lux/phase/translation/js/primitive.lux | 5 +- .../lux/phase/translation/js/reference.lux | 5 +- .../language/lux/phase/translation/js/runtime.lux | 5 +- .../lux/phase/translation/js/structure.lux | 5 +- .../language/lux/phase/translation/js/when.lux | 5 +- .../language/lux/phase/translation/jvm.lux | 6 +- .../lux/phase/translation/jvm/function.lux | 35 +- .../phase/translation/jvm/function/abstract.lux | 9 +- .../translation/jvm/function/field/constant.lux | 17 +- .../jvm/function/field/constant/arity.lux | 11 +- .../translation/jvm/function/field/variable.lux | 19 +- .../jvm/function/field/variable/count.lux | 15 +- .../jvm/function/field/variable/foreign.lux | 17 +- .../jvm/function/field/variable/partial.lux | 17 +- .../lux/phase/translation/jvm/function/method.lux | 9 +- .../translation/jvm/function/method/apply.lux | 161 +- .../jvm/function/method/implementation.lux | 35 +- .../phase/translation/jvm/function/method/init.lux | 37 +- .../phase/translation/jvm/function/method/new.lux | 19 +- .../translation/jvm/function/method/reset.lux | 31 +- .../language/lux/phase/translation/jvm/host.lux | 27 +- .../language/lux/phase/translation/jvm/loop.lux | 7 +- .../lux/phase/translation/jvm/primitive.lux | 13 +- .../language/lux/phase/translation/jvm/program.lux | 39 +- .../lux/phase/translation/jvm/reference.lux | 13 +- .../language/lux/phase/translation/jvm/runtime.lux | 37 +- .../lux/phase/translation/jvm/structure.lux | 13 +- .../language/lux/phase/translation/jvm/type.lux | 7 +- .../language/lux/phase/translation/jvm/value.lux | 43 +- .../language/lux/phase/translation/jvm/when.lux | 25 +- .../lux/phase/translation/lua/function.lux | 5 +- .../language/lux/phase/translation/lua/loop.lux | 5 +- .../lux/phase/translation/lua/primitive.lux | 5 +- .../lux/phase/translation/lua/reference.lux | 5 +- .../language/lux/phase/translation/lua/runtime.lux | 5 +- .../lux/phase/translation/lua/structure.lux | 5 +- .../language/lux/phase/translation/lua/when.lux | 5 +- .../lux/phase/translation/python/function.lux | 5 +- .../language/lux/phase/translation/python/loop.lux | 5 +- .../lux/phase/translation/python/primitive.lux | 5 +- .../lux/phase/translation/python/reference.lux | 5 +- .../lux/phase/translation/python/runtime.lux | 5 +- .../lux/phase/translation/python/structure.lux | 5 +- .../language/lux/phase/translation/python/when.lux | 5 +- .../language/lux/phase/translation/reference.lux | 5 +- .../lux/phase/translation/ruby/function.lux | 5 +- .../language/lux/phase/translation/ruby/loop.lux | 5 +- .../lux/phase/translation/ruby/primitive.lux | 5 +- .../lux/phase/translation/ruby/reference.lux | 5 +- .../lux/phase/translation/ruby/runtime.lux | 5 +- .../lux/phase/translation/ruby/structure.lux | 5 +- .../language/lux/phase/translation/ruby/when.lux | 5 +- .../lux/meta/compiler/language/lux/syntax.lux | 5 +- .../lux/meta/compiler/meta/cache/artifact.lux | 3 +- .../lux/meta/compiler/meta/cache/module.lux | 3 +- .../library/lux/meta/compiler/meta/context.lux | 3 +- .../library/lux/meta/compiler/meta/io/archive.lux | 5 +- .../library/lux/meta/compiler/meta/io/context.lux | 2 - .../lux/meta/compiler/meta/packager/jvm.lux | 9 +- .../lux/meta/compiler/meta/packager/ruby.lux | 5 +- .../lux/meta/compiler/meta/packager/scheme.lux | 5 +- stdlib/source/library/lux/meta/compiler/target.lux | 26 + .../library/lux/meta/compiler/target/c++.lux | 350 ++++ .../lux/meta/compiler/target/common_lisp.lux | 473 ++++++ .../source/library/lux/meta/compiler/target/js.lux | 447 +++++ .../lux/meta/compiler/target/jvm/attribute.lux | 199 +++ .../meta/compiler/target/jvm/attribute/code.lux | 83 + .../target/jvm/attribute/code/exception.lux | 59 + .../compiler/target/jvm/attribute/constant.lux | 27 + .../target/jvm/attribute/line_number_table.lux | 71 + .../lux/meta/compiler/target/jvm/bytecode.lux | 1204 ++++++++++++++ .../meta/compiler/target/jvm/bytecode/address.lux | 75 + .../compiler/target/jvm/bytecode/environment.lux | 110 ++ .../target/jvm/bytecode/environment/limit.lux | 59 + .../jvm/bytecode/environment/limit/registry.lux | 93 ++ .../jvm/bytecode/environment/limit/stack.lux | 70 + .../compiler/target/jvm/bytecode/instruction.lux | 704 ++++++++ .../lux/meta/compiler/target/jvm/bytecode/jump.lux | 29 + .../library/lux/meta/compiler/target/jvm/class.lux | 152 ++ .../lux/meta/compiler/target/jvm/constant.lux | 251 +++ .../lux/meta/compiler/target/jvm/constant/pool.lux | 217 +++ .../lux/meta/compiler/target/jvm/constant/tag.lux | 52 + .../lux/meta/compiler/target/jvm/encoding/name.lux | 42 + .../meta/compiler/target/jvm/encoding/signed.lux | 114 ++ .../meta/compiler/target/jvm/encoding/unsigned.lux | 120 ++ .../library/lux/meta/compiler/target/jvm/field.lux | 81 + .../library/lux/meta/compiler/target/jvm/index.lux | 39 + .../lux/meta/compiler/target/jvm/loader.lux | 148 ++ .../library/lux/meta/compiler/target/jvm/magic.lux | 22 + .../lux/meta/compiler/target/jvm/method.lux | 118 ++ .../lux/meta/compiler/target/jvm/modifier.lux | 93 ++ .../meta/compiler/target/jvm/modifier/inner.lux | 23 + .../lux/meta/compiler/target/jvm/reflection.lux | 385 +++++ .../library/lux/meta/compiler/target/jvm/type.lux | 227 +++ .../lux/meta/compiler/target/jvm/type/alias.lux | 127 ++ .../lux/meta/compiler/target/jvm/type/box.lux | 19 + .../lux/meta/compiler/target/jvm/type/category.lux | 38 + .../meta/compiler/target/jvm/type/descriptor.lux | 125 ++ .../lux/meta/compiler/target/jvm/type/lux.lux | 239 +++ .../lux/meta/compiler/target/jvm/type/parser.lux | 277 +++ .../meta/compiler/target/jvm/type/reflection.lux | 105 ++ .../meta/compiler/target/jvm/type/signature.lux | 183 ++ .../lux/meta/compiler/target/jvm/version.lux | 42 + .../library/lux/meta/compiler/target/lua.lux | 407 +++++ .../library/lux/meta/compiler/target/php.lux | 554 ++++++ .../library/lux/meta/compiler/target/python.lux | 484 ++++++ .../source/library/lux/meta/compiler/target/r.lux | 394 +++++ .../library/lux/meta/compiler/target/ruby.lux | 537 ++++++ .../library/lux/meta/compiler/target/scheme.lux | 388 +++++ stdlib/source/library/lux/meta/extension.lux | 14 +- stdlib/source/library/lux/meta/target.lux | 26 - stdlib/source/library/lux/meta/target/c++.lux | 350 ---- .../source/library/lux/meta/target/common_lisp.lux | 473 ------ stdlib/source/library/lux/meta/target/js.lux | 447 ----- .../library/lux/meta/target/jvm/attribute.lux | 199 --- .../library/lux/meta/target/jvm/attribute/code.lux | 83 - .../meta/target/jvm/attribute/code/exception.lux | 59 - .../lux/meta/target/jvm/attribute/constant.lux | 27 - .../target/jvm/attribute/line_number_table.lux | 71 - .../library/lux/meta/target/jvm/bytecode.lux | 1204 -------------- .../lux/meta/target/jvm/bytecode/address.lux | 75 - .../lux/meta/target/jvm/bytecode/environment.lux | 110 -- .../meta/target/jvm/bytecode/environment/limit.lux | 59 - .../jvm/bytecode/environment/limit/registry.lux | 93 -- .../jvm/bytecode/environment/limit/stack.lux | 70 - .../lux/meta/target/jvm/bytecode/instruction.lux | 704 -------- .../library/lux/meta/target/jvm/bytecode/jump.lux | 29 - .../source/library/lux/meta/target/jvm/class.lux | 152 -- .../library/lux/meta/target/jvm/constant.lux | 250 --- .../library/lux/meta/target/jvm/constant/pool.lux | 217 --- .../library/lux/meta/target/jvm/constant/tag.lux | 52 - .../library/lux/meta/target/jvm/encoding/name.lux | 42 - .../lux/meta/target/jvm/encoding/signed.lux | 114 -- .../lux/meta/target/jvm/encoding/unsigned.lux | 120 -- .../source/library/lux/meta/target/jvm/field.lux | 81 - .../source/library/lux/meta/target/jvm/index.lux | 39 - .../source/library/lux/meta/target/jvm/loader.lux | 147 -- .../source/library/lux/meta/target/jvm/magic.lux | 22 - .../source/library/lux/meta/target/jvm/method.lux | 118 -- .../library/lux/meta/target/jvm/modifier.lux | 93 -- .../library/lux/meta/target/jvm/modifier/inner.lux | 23 - .../library/lux/meta/target/jvm/reflection.lux | 385 ----- stdlib/source/library/lux/meta/target/jvm/type.lux | 227 --- .../library/lux/meta/target/jvm/type/alias.lux | 127 -- .../library/lux/meta/target/jvm/type/box.lux | 19 - .../library/lux/meta/target/jvm/type/category.lux | 38 - .../lux/meta/target/jvm/type/descriptor.lux | 125 -- .../library/lux/meta/target/jvm/type/lux.lux | 239 --- .../library/lux/meta/target/jvm/type/parser.lux | 277 --- .../lux/meta/target/jvm/type/reflection.lux | 105 -- .../library/lux/meta/target/jvm/type/signature.lux | 183 -- .../source/library/lux/meta/target/jvm/version.lux | 42 - stdlib/source/library/lux/meta/target/lua.lux | 408 ----- stdlib/source/library/lux/meta/target/php.lux | 555 ------ stdlib/source/library/lux/meta/target/python.lux | 484 ------ stdlib/source/library/lux/meta/target/r.lux | 394 ----- stdlib/source/library/lux/meta/target/ruby.lux | 538 ------ stdlib/source/library/lux/meta/target/scheme.lux | 389 ----- stdlib/source/library/lux/meta/type.lux | 5 +- stdlib/source/library/lux/meta/type/check.lux | 5 +- stdlib/source/library/lux/program.lux | 5 +- stdlib/source/library/lux/test/property.lux | 3 +- stdlib/source/library/lux/web/html.lux | 5 +- stdlib/source/library/lux/world/console.lux | 3 +- stdlib/source/library/lux/world/environment.lux | 5 +- stdlib/source/library/lux/world/file.lux | 5 +- stdlib/source/library/lux/world/file/watch.lux | 5 +- .../source/library/lux/world/net/http/client.lux | 5 +- stdlib/source/library/lux/world/shell.lux | 3 +- stdlib/source/library/lux/world/time/instant.lux | 5 +- stdlib/source/library/lux/world/time/solar.lux | 5 +- stdlib/source/program/compositor.lux | 2 +- stdlib/source/test/aedifex/cli.lux | 6 +- stdlib/source/test/lux.lux | 5 +- stdlib/source/test/lux/abstract/equivalence.lux | 3 +- stdlib/source/test/lux/abstract/functor.lux | 3 +- .../source/test/lux/control/concurrency/async.lux | 3 +- .../test/lux/control/concurrency/semaphore.lux | 5 +- stdlib/source/test/lux/data/format/json.lux | 5 +- stdlib/source/test/lux/debug.lux | 5 +- stdlib/source/test/lux/ffi.jvm.lux | 7 +- stdlib/source/test/lux/math/number/frac.lux | 5 +- stdlib/source/test/lux/meta.lux | 120 +- stdlib/source/test/lux/meta/compiler.lux | 85 +- .../test/lux/meta/compiler/language/lux/phase.lux | 4 +- .../language/lux/phase/translation/jvm/host.lux | 7 +- .../language/lux/phase/translation/jvm/type.lux | 9 +- .../language/lux/phase/translation/jvm/value.lux | 64 + stdlib/source/test/lux/meta/compiler/meta/cli.lux | 8 +- stdlib/source/test/lux/meta/compiler/target.lux | 47 + stdlib/source/test/lux/meta/compiler/target/js.lux | 848 ++++++++++ .../source/test/lux/meta/compiler/target/jvm.lux | 1759 ++++++++++++++++++++ .../source/test/lux/meta/compiler/target/lua.lux | 725 ++++++++ .../test/lux/meta/compiler/target/python.lux | 844 ++++++++++ .../source/test/lux/meta/compiler/target/ruby.lux | 1062 ++++++++++++ stdlib/source/test/lux/meta/extension.lux | 28 +- stdlib/source/test/lux/meta/static.lux | 5 +- stdlib/source/test/lux/meta/target.lux | 47 - stdlib/source/test/lux/meta/target/js.lux | 848 ---------- stdlib/source/test/lux/meta/target/jvm.lux | 1758 ------------------- stdlib/source/test/lux/meta/target/lua.lux | 725 -------- stdlib/source/test/lux/meta/target/python.lux | 844 ---------- stdlib/source/test/lux/meta/target/ruby.lux | 1062 ------------ .../world/finance/market/analysis/pivot_point.lux | 28 +- stdlib/source/test/lux/world/time/solar.lux | 3 +- stdlib/source/unsafe/lux/data/binary.lux | 3 +- stdlib/source/unsafe/lux/data/collection/array.lux | 5 +- 253 files changed, 16406 insertions(+), 16159 deletions(-) create mode 100644 stdlib/source/library/lux/meta/compiler/target.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/c++.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/common_lisp.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/js.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/attribute.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/attribute/code.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/attribute/code/exception.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/attribute/constant.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/attribute/line_number_table.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/bytecode.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/address.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit/registry.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit/stack.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/instruction.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/jump.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/class.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/constant.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/constant/pool.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/constant/tag.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/encoding/name.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/encoding/signed.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/encoding/unsigned.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/field.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/index.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/loader.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/magic.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/method.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/modifier.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/modifier/inner.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/reflection.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/type.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/type/alias.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/type/box.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/type/category.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/type/descriptor.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/type/lux.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/type/parser.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/type/reflection.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/type/signature.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/jvm/version.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/lua.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/php.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/python.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/r.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/ruby.lux create mode 100644 stdlib/source/library/lux/meta/compiler/target/scheme.lux delete mode 100644 stdlib/source/library/lux/meta/target.lux delete mode 100644 stdlib/source/library/lux/meta/target/c++.lux delete mode 100644 stdlib/source/library/lux/meta/target/common_lisp.lux delete mode 100644 stdlib/source/library/lux/meta/target/js.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/attribute.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/attribute/code.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/attribute/code/exception.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/attribute/constant.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/attribute/line_number_table.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/address.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/environment.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/environment/limit.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/environment/limit/registry.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/environment/limit/stack.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/instruction.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/jump.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/class.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/constant.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/constant/pool.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/constant/tag.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/encoding/name.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/encoding/signed.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/encoding/unsigned.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/field.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/index.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/loader.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/magic.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/method.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/modifier.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/modifier/inner.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/reflection.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/type.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/type/alias.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/type/box.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/type/category.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/type/descriptor.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/type/lux.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/type/parser.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/type/reflection.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/type/signature.lux delete mode 100644 stdlib/source/library/lux/meta/target/jvm/version.lux delete mode 100644 stdlib/source/library/lux/meta/target/lua.lux delete mode 100644 stdlib/source/library/lux/meta/target/php.lux delete mode 100644 stdlib/source/library/lux/meta/target/python.lux delete mode 100644 stdlib/source/library/lux/meta/target/r.lux delete mode 100644 stdlib/source/library/lux/meta/target/ruby.lux delete mode 100644 stdlib/source/library/lux/meta/target/scheme.lux create mode 100644 stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/value.lux create mode 100644 stdlib/source/test/lux/meta/compiler/target.lux create mode 100644 stdlib/source/test/lux/meta/compiler/target/js.lux create mode 100644 stdlib/source/test/lux/meta/compiler/target/jvm.lux create mode 100644 stdlib/source/test/lux/meta/compiler/target/lua.lux create mode 100644 stdlib/source/test/lux/meta/compiler/target/python.lux create mode 100644 stdlib/source/test/lux/meta/compiler/target/ruby.lux delete mode 100644 stdlib/source/test/lux/meta/target.lux delete mode 100644 stdlib/source/test/lux/meta/target/js.lux delete mode 100644 stdlib/source/test/lux/meta/target/jvm.lux delete mode 100644 stdlib/source/test/lux/meta/target/lua.lux delete mode 100644 stdlib/source/test/lux/meta/target/python.lux delete mode 100644 stdlib/source/test/lux/meta/target/ruby.lux (limited to 'stdlib') diff --git a/stdlib/source/library/lux/abstract/apply.lux b/stdlib/source/library/lux/abstract/apply.lux index 69526ae86..df1e73a45 100644 --- a/stdlib/source/library/lux/abstract/apply.lux +++ b/stdlib/source/library/lux/abstract/apply.lux @@ -2,7 +2,8 @@ [library [lux (.except) [meta - ["@" target]]]] + [compiler + ["@" target]]]]] [// [monad (.only Monad do)] ["[0]" functor (.only Functor)]]) diff --git a/stdlib/source/library/lux/control/concurrency/atom.lux b/stdlib/source/library/lux/control/concurrency/atom.lux index 962149143..8068f29db 100644 --- a/stdlib/source/library/lux/control/concurrency/atom.lux +++ b/stdlib/source/library/lux/control/concurrency/atom.lux @@ -13,7 +13,8 @@ ["[0]" array ["[1]" \\unsafe]]]] [meta - ["@" target] + [compiler + ["@" target]] [type ["[0]" nominal (.except def)] ["[0]" variance (.only Mutable)]]]]]) diff --git a/stdlib/source/library/lux/control/concurrency/thread.lux b/stdlib/source/library/lux/control/concurrency/thread.lux index b30444a54..16ecebb90 100644 --- a/stdlib/source/library/lux/control/concurrency/thread.lux +++ b/stdlib/source/library/lux/control/concurrency/thread.lux @@ -17,8 +17,9 @@ ["n" nat] ["f" frac]]] [meta - ["@" target] - ["[0]" configuration]] + ["[0]" configuration] + [compiler + ["@" target]]] [world [time ["[0]" instant (.only Instant) (.use "[1]#[0]" order)] diff --git a/stdlib/source/library/lux/control/parser.lux b/stdlib/source/library/lux/control/parser.lux index c3c87c59f..9f2083573 100644 --- a/stdlib/source/library/lux/control/parser.lux +++ b/stdlib/source/library/lux/control/parser.lux @@ -13,11 +13,13 @@ [collection ["[0]" list (.use "[1]#[0]" functor monoid)]]]]]) -(type .public (Parser s a) - (-> s (Try [s a]))) +(type .public (Parser state of) + (-> state + (Try [state of]))) (def .public functor - (All (_ s) (Functor (Parser s))) + (All (_ state) + (Functor (Parser state))) (implementation (def (each f ma) (function (_ input) @@ -29,7 +31,8 @@ {try.#Failure msg}))))) (def .public apply - (All (_ s) (Apply (Parser s))) + (All (_ state) + (Apply (Parser state))) (implementation (def functor ..functor) @@ -48,7 +51,8 @@ {try.#Failure msg}))))) (def .public monad - (All (_ s) (Monad (Parser s))) + (All (_ state) + (Monad (Parser state))) (implementation (def functor ..functor) @@ -66,15 +70,18 @@ {try.#Failure msg}))))) (def .public (assertion message test) - (All (_ s) (-> Text Bit (Parser s Any))) + (All (_ state) + (-> Text Bit + (Parser state Any))) (function (_ input) (if test {try.#Success [input []]} {try.#Failure message}))) (def .public (maybe parser) - (All (_ s a) - (-> (Parser s a) (Parser s (Maybe a)))) + (All (_ state of) + (-> (Parser state of) + (Parser state (Maybe of)))) (function (_ input) (when (parser input) {try.#Success [input' x]} @@ -84,20 +91,23 @@ {try.#Success [input {.#None}]}))) (def .public (result parser input) - (All (_ s a) - (-> (Parser s a) s (Try [s a]))) + (All (_ state of) + (-> (Parser state of) state + (Try [state of]))) (parser input)) -(def .public (and first second) - (All (_ s a b) - (-> (Parser s a) (Parser s b) (Parser s [a b]))) +(def .public (and left right) + (All (_ state left right) + (-> (Parser state left) (Parser state right) + (Parser state (And left right)))) (do [! ..monad] - [head first] - (of ! each (|>> [head]) second))) + [head left] + (of ! each (|>> [head]) right))) (def .public (or left right) - (All (_ s a b) - (-> (Parser s a) (Parser s b) (Parser s (Or a b)))) + (All (_ state left right) + (-> (Parser state left) (Parser state right) + (Parser state (Or left right)))) (function (_ tokens) (when (left tokens) {try.#Success [tokens' output]} @@ -112,8 +122,9 @@ {try.#Failure error})))) (def .public (either this that) - (All (_ s a) - (-> (Parser s a) (Parser s a) (Parser s a))) + (All (_ state of) + (-> (Parser state of) (Parser state of) + (Parser state of))) (function (_ tokens) (when (this tokens) {try.#Failure _} @@ -123,8 +134,9 @@ success))) (def .public (some parser) - (All (_ s a) - (-> (Parser s a) (Parser s (List a)))) + (All (_ state of) + (-> (Parser state of) + (Parser state (List of)))) (function (_ input) (when (parser input) {try.#Success [input' head]} @@ -136,14 +148,17 @@ {try.#Success [input (list)]}))) (def .public (many parser) - (All (_ s a) - (-> (Parser s a) (Parser s (List a)))) + (All (_ state of) + (-> (Parser state of) + (Parser state (List of)))) (|> (..some parser) (..and parser) (of ..monad each (|>> {.#Item})))) (def .public (exactly amount parser) - (All (_ s a) (-> Nat (Parser s a) (Parser s (List a)))) + (All (_ state of) + (-> Nat (Parser state of) + (Parser state (List of)))) (when amount 0 (of ..monad in (list)) _ (do [! ..monad] @@ -153,13 +168,17 @@ (of ! each (|>> {.#Item x})))))) (def .public (at_least amount parser) - (All (_ s a) (-> Nat (Parser s a) (Parser s (List a)))) + (All (_ state of) + (-> Nat (Parser state of) + (Parser state (List of)))) (do [! ..monad] [minimum (..exactly amount parser)] (of ! each (list#composite minimum) (..some parser)))) (def .public (at_most amount parser) - (All (_ s a) (-> Nat (Parser s a) (Parser s (List a)))) + (All (_ state of) + (-> Nat (Parser state of) + (Parser state (List of)))) (when amount 0 (of ..monad in (list)) _ (function (_ input) @@ -173,7 +192,9 @@ {try.#Success [input (list)]})))) (def .public (between minimum additional parser) - (All (_ s a) (-> Nat Nat (Parser s a) (Parser s (List a)))) + (All (_ state of) + (-> Nat Nat (Parser state of) + (Parser state (List of)))) (do [! ..monad] [minimum (..exactly minimum parser)] (when additional @@ -182,7 +203,9 @@ (..at_most additional parser))))) (def .public (separated_by separator parser) - (All (_ s a b) (-> (Parser s b) (Parser s a) (Parser s (List a)))) + (All (_ state separator of) + (-> (Parser state separator) (Parser state of) + (Parser state (List of)))) (do [! ..monad] [?x (..maybe parser)] (when ?x @@ -196,7 +219,9 @@ (in {.#End})))) (def .public (not parser) - (All (_ s a) (-> (Parser s a) (Parser s Any))) + (All (_ state of) + (-> (Parser state of) + (Parser state Any))) (function (_ input) (when (parser input) {try.#Failure msg} @@ -206,7 +231,9 @@ {try.#Failure "Expected to fail; yet succeeded."}))) (def .public (failure message) - (All (_ s a) (-> Text (Parser s a))) + (All (_ state of) + (-> Text + (Parser state of))) (function (_ input) {try.#Failure message})) @@ -223,7 +250,9 @@ {try.#Failure error}))) (def .public (else value parser) - (All (_ s a) (-> a (Parser s a) (Parser s a))) + (All (_ state of) + (-> of (Parser state of) + (Parser state of))) (function (_ input) (when (parser input) {try.#Failure error} @@ -233,37 +262,49 @@ success))) (def .public remaining - (All (_ s) (Parser s s)) + (All (_ state) + (Parser state state)) (function (_ inputs) {try.#Success [inputs inputs]})) (def .public (rec parser) - (All (_ s a) (-> (-> (Parser s a) (Parser s a)) (Parser s a))) + (All (_ state of) + (-> (-> (Parser state of) + (Parser state of)) + (Parser state of))) (function (_ inputs) (..result (parser (rec parser)) inputs))) (def .public (after param subject) - (All (_ s _ a) (-> (Parser s _) (Parser s a) (Parser s a))) + (All (_ state _ of) + (-> (Parser state _) (Parser state of) + (Parser state of))) (do ..monad [_ param] subject)) (def .public (before param subject) - (All (_ s _ a) (-> (Parser s _) (Parser s a) (Parser s a))) + (All (_ state _ of) + (-> (Parser state _) (Parser state of) + (Parser state of))) (do ..monad [output subject _ param] (in output))) (def .public (only test parser) - (All (_ s a) (-> (-> a Bit) (Parser s a) (Parser s a))) + (All (_ state of) + (-> (-> of Bit) (Parser state of) + (Parser state of))) (do ..monad [output parser _ (..assertion "Constraint failed." (test output))] (in output))) (def .public (parses? parser) - (All (_ s a) (-> (Parser s a) (Parser s Bit))) + (All (_ state of) + (-> (Parser state of) + (Parser state Bit))) (function (_ input) (when (parser input) {try.#Success [input' _]} @@ -273,7 +314,9 @@ {try.#Success [input false]}))) (def .public (parses parser) - (All (_ s a) (-> (Parser s a) (Parser s Any))) + (All (_ state of) + (-> (Parser state of) + (Parser state Any))) (function (_ input) (when (parser input) {try.#Success [input' _]} @@ -283,7 +326,9 @@ {try.#Failure error}))) (def .public (speculative parser) - (All (_ s a) (-> (Parser s a) (Parser s a))) + (All (_ state of) + (-> (Parser state of) + (Parser state of))) (function (_ input) (when (parser input) {try.#Success [input' output]} @@ -293,7 +338,9 @@ failure))) (def .public (codec codec parser) - (All (_ s a z) (-> (Codec a z) (Parser s a) (Parser s z))) + (All (_ state medium of) + (-> (Codec medium of) (Parser state medium) + (Parser state of))) (function (_ input) (when (parser input) {try.#Success [input' to_decode]} diff --git a/stdlib/source/library/lux/control/reader.lux b/stdlib/source/library/lux/control/reader.lux index 245fb0077..0edf8ca10 100644 --- a/stdlib/source/library/lux/control/reader.lux +++ b/stdlib/source/library/lux/control/reader.lux @@ -4,9 +4,7 @@ [abstract [apply (.only Apply)] ["[0]" functor (.only Functor)] - ["[0]" monad (.only Monad do)]] - [meta - ["@" target]]]]) + ["[0]" monad (.only Monad do)]]]]) (type .public (Reader r a) (-> r a)) diff --git a/stdlib/source/library/lux/control/thread.lux b/stdlib/source/library/lux/control/thread.lux index 222ea8b2c..1d600628d 100644 --- a/stdlib/source/library/lux/control/thread.lux +++ b/stdlib/source/library/lux/control/thread.lux @@ -12,7 +12,6 @@ ["[0]" array ["[1]" \\unsafe (.only Array)]]]] [meta - ["@" target] [type ["[0]" nominal (.except def)] ["[0]" variance (.only Mutable)]]]]]) diff --git a/stdlib/source/library/lux/control/try.lux b/stdlib/source/library/lux/control/try.lux index c9ed542d7..136ebc486 100644 --- a/stdlib/source/library/lux/control/try.lux +++ b/stdlib/source/library/lux/control/try.lux @@ -7,7 +7,6 @@ ["[0]" functor (.only Functor)] ["[0]" monad (.only Monad do)]] [meta - ["@" target] ["[0]" location]]]]) (type .public (Try a) diff --git a/stdlib/source/library/lux/control/writer.lux b/stdlib/source/library/lux/control/writer.lux index 2f5069f46..3253320d2 100644 --- a/stdlib/source/library/lux/control/writer.lux +++ b/stdlib/source/library/lux/control/writer.lux @@ -7,7 +7,8 @@ ["[0]" functor (.only Functor)] ["[0]" monad (.only Monad do)]] [meta - ["@" target]]]]) + [compiler + ["@" target]]]]]) (type .public (Writer log value) (Record diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index 3ec1cd2c8..e88a8d798 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -20,7 +20,8 @@ [number ["n" nat]]] [meta - ["@" target]]]]) + [compiler + ["@" target]]]]]) ... (type (List a) ... #End diff --git a/stdlib/source/library/lux/data/collection/sequence.lux b/stdlib/source/library/lux/data/collection/sequence.lux index 2d114ca91..0863ef0dd 100644 --- a/stdlib/source/library/lux/data/collection/sequence.lux +++ b/stdlib/source/library/lux/data/collection/sequence.lux @@ -29,7 +29,6 @@ ["n" nat] ["[0]" i64]]] [meta - ["@" target] ["[0]" code (.only) ["<[1]>" \\parser (.only Parser)]] [macro diff --git a/stdlib/source/library/lux/data/collection/tree/zipper.lux b/stdlib/source/library/lux/data/collection/tree/zipper.lux index b06a5c591..28d4f66bb 100644 --- a/stdlib/source/library/lux/data/collection/tree/zipper.lux +++ b/stdlib/source/library/lux/data/collection/tree/zipper.lux @@ -15,7 +15,8 @@ [collection ["[0]" list (.use "[1]#[0]" functor monoid)]]] [meta - ["@" target]]]] + [compiler + ["@" target]]]]] ["[0]" // (.only Tree) (.use "[1]#[0]" functor)]) (type (Family Zipper a) diff --git a/stdlib/source/library/lux/data/text.lux b/stdlib/source/library/lux/data/text.lux index a2fe70b35..9d9c43e69 100644 --- a/stdlib/source/library/lux/data/text.lux +++ b/stdlib/source/library/lux/data/text.lux @@ -18,7 +18,8 @@ ["n" nat] ["[0]" i64]]] [meta - ["@" target]]]] + [compiler + ["@" target]]]]] [/ ["[0]" char (.only Char)]]) diff --git a/stdlib/source/library/lux/data/text/buffer.lux b/stdlib/source/library/lux/data/text/buffer.lux index 5b1bf4a6f..54adf6087 100644 --- a/stdlib/source/library/lux/data/text/buffer.lux +++ b/stdlib/source/library/lux/data/text/buffer.lux @@ -15,9 +15,10 @@ [number ["n" nat]]] [meta - ["@" target] [type - ["[0]" nominal (.except def)]]]]] + ["[0]" nominal (.except def)]] + [compiler + ["@" target]]]]] ["[0]" //]) (with_expansions [ (these (import java/lang/CharSequence diff --git a/stdlib/source/library/lux/data/text/encoding/utf8.lux b/stdlib/source/library/lux/data/text/encoding/utf8.lux index e6db26578..f03d07cfb 100644 --- a/stdlib/source/library/lux/data/text/encoding/utf8.lux +++ b/stdlib/source/library/lux/data/text/encoding/utf8.lux @@ -9,7 +9,8 @@ [data ["[0]" binary (.only Binary)]] [meta - ["@" target]]]] + [compiler + ["@" target]]]]] ["[0]" //]) (with_expansions [ (these (ffi.import java/lang/String diff --git a/stdlib/source/library/lux/debug.lux b/stdlib/source/library/lux/debug.lux index 5ee1ddbdf..39caa6c5e 100644 --- a/stdlib/source/library/lux/debug.lux +++ b/stdlib/source/library/lux/debug.lux @@ -26,7 +26,6 @@ ["n" nat] ["i" int]]] ["[0]" meta (.only) - ["@" target] ["[0]" code (.only) ["<[1]>" \\parser]] [macro @@ -34,7 +33,9 @@ ["[0]" template] ["[0]" syntax (.only syntax)]] ["[0]" type (.only) - ["<[1]>" \\parser (.only Parser)]]] + ["<[1]>" \\parser (.only Parser)]] + [compiler + ["@" target]]] [world [time (.only Time) [instant (.only Instant)] diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index b8c9650d4..b38df79d8 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -31,17 +31,18 @@ ["[0]" context]] ["[0]" type (.use "[1]#[0]" equivalence) ["[0]" check]] - [target - ["[0]" jvm - [encoding - ["[0]" name (.only External)]] - ["[1]" type (.only Type Argument Typed) - ["[0]" category (.only Void Value' Value Return' Return Method Primitive Object Class Array Var Parameter Declaration)] - ["[0]" box] - ["[0]" descriptor] - ["[0]" signature] - ["[0]" reflection] - ["[0]" parser]]]]]]]) + [compiler + [target + ["[0]" jvm + [encoding + ["[0]" name (.only External)]] + ["[1]" type (.only Type Argument Typed) + ["[0]" category (.only Void Value' Value Return' Return Method Primitive Object Class Array Var Parameter Declaration)] + ["[0]" box] + ["[0]" descriptor] + ["[0]" signature] + ["[0]" reflection] + ["[0]" parser]]]]]]]]) (def internal (-> External Text) diff --git a/stdlib/source/library/lux/ffi.lux b/stdlib/source/library/lux/ffi.lux index 8afc76f04..b0aa3cd6b 100644 --- a/stdlib/source/library/lux/ffi.lux +++ b/stdlib/source/library/lux/ffi.lux @@ -23,10 +23,10 @@ ["[0]" template]] [type (.only sharing) ["[0]" nominal (.except #name def)]] - ["@" target (.only) - ["[0]" js] - ["[0]" python]] [compiler + ["@" target (.only) + ["[0]" js] + ["[0]" python]] [arity (.only Arity)] [reference (.only Reference) [variable (.only Register)]] diff --git a/stdlib/source/library/lux/ffi.php.lux b/stdlib/source/library/lux/ffi.php.lux index 7eaa7b31a..578f57a5f 100644 --- a/stdlib/source/library/lux/ffi.php.lux +++ b/stdlib/source/library/lux/ffi.php.lux @@ -14,7 +14,6 @@ [collection ["[0]" list (.use "[1]#[0]" functor)]]] ["[0]" meta (.only) - ["@" target] [type ["[0]" nominal (.except def)]] ["[0]" code (.only) diff --git a/stdlib/source/library/lux/ffi.scm.lux b/stdlib/source/library/lux/ffi.scm.lux index 8db541680..585bf4e2f 100644 --- a/stdlib/source/library/lux/ffi.scm.lux +++ b/stdlib/source/library/lux/ffi.scm.lux @@ -14,7 +14,6 @@ [collection ["[0]" list (.use "[1]#[0]" functor)]]] ["[0]" meta (.only) - ["@" target] [type ["[0]" nominal (.except def)]] ["[0]" code (.only) diff --git a/stdlib/source/library/lux/math.lux b/stdlib/source/library/lux/math.lux index de44e4d21..c19059e81 100644 --- a/stdlib/source/library/lux/math.lux +++ b/stdlib/source/library/lux/math.lux @@ -13,7 +13,6 @@ ["[0]" list (.use "[1]#[0]" mix)]]] [meta [extension (.only analysis)] - ["@" target] ["[0]" location] ["[0]" code ["<[1]>" \\parser]] @@ -22,6 +21,7 @@ [type ["[0]" check]] [compiler + ["@" target] [language [lux ["[0]" phase (.use "[1]#[0]" monad)] diff --git a/stdlib/source/library/lux/math/number/frac.lux b/stdlib/source/library/lux/math/number/frac.lux index 6dcac2a10..60c730835 100644 --- a/stdlib/source/library/lux/math/number/frac.lux +++ b/stdlib/source/library/lux/math/number/frac.lux @@ -16,7 +16,8 @@ [data ["[0]" text]] [meta - ["@" target]]]] + [compiler + ["@" target]]]]] ["[0]" // ["[1][0]" i64] ["[1][0]" nat] diff --git a/stdlib/source/library/lux/math/number/i32.lux b/stdlib/source/library/lux/math/number/i32.lux index 3fc667291..3d88a04e4 100644 --- a/stdlib/source/library/lux/math/number/i32.lux +++ b/stdlib/source/library/lux/math/number/i32.lux @@ -8,10 +8,11 @@ ["[0]" maybe] ["[0]" try]] [meta - ["@" target] ["[0]" static] ["[0]" type (.only) - ["?[1]" \\parser]]]]] + ["?[1]" \\parser]] + [compiler + ["@" target]]]]] [// ["[0]" i64]]) diff --git a/stdlib/source/library/lux/meta/compiler/default/init.lux b/stdlib/source/library/lux/meta/compiler/default/init.lux index 8c12039a6..af5497d49 100644 --- a/stdlib/source/library/lux/meta/compiler/default/init.lux +++ b/stdlib/source/library/lux/meta/compiler/default/init.lux @@ -17,9 +17,10 @@ ["[0]" set] ["[0]" sequence (.use "[1]#[0]" functor)]]] ["[0]" meta (.only) - ["@" target (.only Target)] ["[0]" configuration (.only Configuration)] - ["[0]" version]] + ["[0]" version] + [compiler + [target (.only Target)]]] [world ["[0]" file]]]] ["[0]" // diff --git a/stdlib/source/library/lux/meta/compiler/default/platform.lux b/stdlib/source/library/lux/meta/compiler/default/platform.lux index a17939fe9..15bc9ed0a 100644 --- a/stdlib/source/library/lux/meta/compiler/default/platform.lux +++ b/stdlib/source/library/lux/meta/compiler/default/platform.lux @@ -26,11 +26,12 @@ ["[0]" set (.only Set)] ["[0]" list (.use "[1]#[0]" monoid functor mix)]]] ["[0]" meta (.only) - ["@" target] ["[0]" static] ["[0]" configuration (.only Configuration)] [type (.only sharing) - ["[0]" check]]] + ["[0]" check]] + [compiler + ["@" target]]] [world ["[0]" file (.only Path)] ["[0]" console]]]] @@ -759,7 +760,9 @@ (def .public Custom Type - (type_literal (-> (List Text) (Try ///.Custom)))) + (type_literal + (-> (List Text) + (Try ///.Custom)))) (exception.def .public (invalid_custom_compiler [definition type]) (Exception [Symbol Type]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/js.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/js.lux index a703fba70..da1d3845d 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/js.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/js.lux @@ -12,8 +12,9 @@ ["[0]" dictionary] ["[0]" list]]] ["[0]" meta (.only) - ["@" target (.only) - ["_" js]] + [compiler + ["@" target (.only) + ["_" js]]] ["[0]" code ["<[1]>" \\parser (.only Parser)]] ["[0]" type (.only) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/jvm.lux index 420daefdb..51108b50d 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/jvm.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/jvm.lux @@ -34,29 +34,30 @@ [macro ["^" pattern] ["[0]" template]] - [target - ["[0]" jvm - ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad)] - ["[0]!" reflection] - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - ["[0]" attribute] - ["[0]" field] - ["[0]" version] - ["[0]" method] - ["[0]" class] - ["[0]" constant (.only) - ["[0]" pool (.only Resource)]] - [encoding - ["[0]" name (.only External)]] - ["[1]" type (.only Type Argument Typed) (.use "[1]#[0]" equivalence) - ["[0]" category (.only Void Value' Value Return' Return Primitive Object Class Array Var Parameter Method)] - ["[0]" box] - ["[0]" reflection] - ["[0]" descriptor] - ["[0]" signature] - ["[0]" parser] - ["[0]" alias (.only Aliasing)] - ["[0]T" lux (.only Mapping)]]]] + [compiler + [target + ["[0]" jvm + ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad)] + ["[0]!" reflection] + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + ["[0]" attribute] + ["[0]" field] + ["[0]" version] + ["[0]" method] + ["[0]" class] + ["[0]" constant (.only) + ["[0]" pool (.only Resource)]] + [encoding + ["[0]" name (.only External)]] + ["[1]" type (.only Type Argument Typed) (.use "[1]#[0]" equivalence) + ["[0]" category (.only Void Value' Value Return' Return Primitive Object Class Array Var Parameter Method)] + ["[0]" box] + ["[0]" reflection] + ["[0]" descriptor] + ["[0]" signature] + ["[0]" parser] + ["[0]" alias (.only Aliasing)] + ["[0]T" lux (.only Mapping)]]]]] ["[0]" type (.use "[1]#[0]" equivalence) ["[0]" check (.only Check) (.use "[1]#[0]" monad)]]]]] ["[0]" // diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lua.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lua.lux index 092ca0575..bfa27b8ed 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lua.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lua.lux @@ -12,8 +12,9 @@ ["[0]" dictionary] ["[0]" list]]] ["[0]" meta (.only) - ["@" target (.only) - ["_" lua]] + [compiler + ["@" target (.only) + ["_" lua]]] ["[0]" code ["<[1]>" \\parser (.only Parser)]] ["[0]" type (.only) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/python.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/python.lux index 49721e9df..48e7cfc4d 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/python.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/python.lux @@ -12,8 +12,9 @@ ["[0]" dictionary] ["[0]" list]]] ["[0]" meta (.only) - ["@" target (.only) - ["_" python]] + [compiler + ["@" target (.only) + ["_" python]]] ["[0]" code ["<[1]>" \\parser (.only Parser)]] ["[0]" type (.only) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/ruby.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/ruby.lux index 9e85ce56b..6f1931791 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/ruby.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/ruby.lux @@ -12,8 +12,9 @@ ["[0]" dictionary] ["[0]" list]]] ["[0]" meta (.only) - ["@" target (.only) - ["_" ruby]] + [compiler + ["@" target (.only) + ["_" ruby]]] ["[0]" code ["<[1]>" \\parser (.only Parser)]] ["[0]" type (.only) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/jvm.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/jvm.lux index c99eb4832..8e342547b 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/jvm.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/jvm.lux @@ -33,27 +33,27 @@ ["[0]" template]] [type ["[0]" check (.only Check)]] - [target - [jvm - ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad)] - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - ["[0]" attribute] - ["[0]" field] - ["[0]" version] - ["[0]" method (.only Method)] - ["[0]" class] - ["[0]" constant (.only) - ["[0]" pool (.only Resource)]] - [encoding - ["[0]" name (.only External)]] - ["[0]" type (.only Type Constraint Argument Typed) - [category (.only Void Value Return Primitive Object Class Array Var Parameter)] - ["[0]T" lux (.only Mapping)] - ["[0]" signature] - ["[0]" reflection] - ["[0]" descriptor (.only Descriptor)] - ["[0]" parser]]]] [compiler + [target + [jvm + ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad)] + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + ["[0]" attribute] + ["[0]" field] + ["[0]" version] + ["[0]" method (.only Method)] + ["[0]" class] + ["[0]" constant (.only) + ["[0]" pool (.only Resource)]] + [encoding + ["[0]" name (.only External)]] + ["[0]" type (.only Type Constraint Argument Typed) + [category (.only Void Value Return Primitive Object Class Array Var Parameter)] + ["[0]T" lux (.only Mapping)] + ["[0]" signature] + ["[0]" reflection] + ["[0]" descriptor (.only Descriptor)] + ["[0]" parser]]]] [reference [variable (.only Register)]] [meta @@ -426,7 +426,7 @@ [[(n.+ jvm_register) (all _.composite ( jvm_register) - (value.wrap ) + (value.boxed ) (_.astore lux_register))]]] (`` (cond (,, (with_template [ ] [(of type.equivalence = argumentT) @@ -510,7 +510,7 @@ {.#Right returnT} (template.let [(unwrap_primitive ) [(all _.composite - (value.unwrap ) + (value.primitive ) )]] (`` (cond (,, (with_template [ ] [(of type.equivalence = returnT) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/lux.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/lux.lux index e4d405e2c..590ae56c6 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/lux.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/declaration/lux.lux @@ -23,7 +23,6 @@ [number ["n" nat]]] ["[0]" meta (.only) - ["@" target] ["[0]" code ["<[1]>" \\parser (.only Parser)]] [macro diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/common.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/common.lux index 407f22b4f..5a3e679ac 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/common.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/common.lux @@ -16,11 +16,11 @@ [number ["f" frac]]] [meta - ["@" target (.only) - ["_" js (.only Literal Expression Statement)]] [macro ["^" pattern]] [compiler + ["@" target (.only) + ["_" js (.only Literal Expression Statement)]] [meta [archive (.only Archive)]]]]]] [///// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/host.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/host.lux index cae36908d..f34f3f25f 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/host.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/js/host.lux @@ -11,8 +11,9 @@ ["[0]" dictionary] ["[0]" list]]] [meta - [target - ["_" js (.only Var Expression)]]]]] + [compiler + [target + ["_" js (.only Var Expression)]]]]]] [// [common (.only custom)] [//// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/jvm/common.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/jvm/common.lux index 654f1b008..4b6b3a259 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/jvm/common.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/jvm/common.lux @@ -18,13 +18,14 @@ ["f" frac] ["[0]" i32]]] [meta - [target - [jvm - ["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad)] - [encoding - ["[0]" signed (.only S4)]] - ["[0]" type (.only Type) - [category (.only Primitive Class)]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad)] + [encoding + ["[0]" signed (.only S4)]] + ["[0]" type (.only Type) + [category (.only Primitive Class)]]]]]]]] ["[0]" ///// ["[0]" extension] [translation @@ -70,12 +71,12 @@ (Bytecode Any) (all _.composite _.i2l - (///value.wrap type.long))) + (///value.boxed type.long))) (def jvm_int (Bytecode Any) (all _.composite - (///value.unwrap type.long) + (///value.primitive type.long) _.l2i)) (def (predicate bytecode) @@ -129,7 +130,7 @@ (in (do _.monad [@else _.new_label] (all _.composite - inputG (///value.unwrap type.long) _.l2i + inputG (///value.primitive type.long) _.l2i (_.lookupswitch @else table) conditionalsG (_.set_label @else) @@ -162,9 +163,9 @@ [(def ( [maskG inputG]) (Binary (Bytecode Any)) (all _.composite - inputG (///value.unwrap type.long) - maskG (///value.unwrap type.long) - (///value.wrap type.long)))] + inputG (///value.primitive type.long) + maskG (///value.primitive type.long) + (///value.boxed type.long)))] [i64::and _.land] [i64::or _.lor] @@ -175,9 +176,9 @@ [(def ( [shiftG inputG]) (Binary (Bytecode Any)) (all _.composite - inputG (///value.unwrap type.long) + inputG (///value.primitive type.long) shiftG ..jvm_int - (///value.wrap type.long)))] + (///value.boxed type.long)))] [i64::left_shifted _.lshl] [i64::right_shifted _.lushr] @@ -187,9 +188,9 @@ [(def ( [paramG subjectG]) (Binary (Bytecode Any)) (all _.composite - subjectG (///value.unwrap ) - paramG (///value.unwrap ) - (///value.wrap )))] + subjectG (///value.primitive ) + paramG (///value.primitive ) + (///value.boxed )))] [i64::+ type.long _.ladd] [i64::- type.long _.lsub] @@ -209,8 +210,8 @@ [(def ( [paramG subjectG]) (Binary (Bytecode Any)) (all _.composite - subjectG (///value.unwrap ) - paramG (///value.unwrap ) + subjectG (///value.primitive ) + paramG (///value.primitive ) (..predicate _.if_icmpeq)))] @@ -235,26 +236,26 @@ ))] [i64::f64 - (///value.unwrap type.long) + (///value.primitive type.long) (all _.composite _.l2d - (///value.wrap type.double))] + (///value.boxed type.double))] [i64::char - (///value.unwrap type.long) + (///value.primitive type.long) (all _.composite _.l2i _.i2c (..::toString ..$Character type.char))] [f64::i64 - (///value.unwrap type.double) + (///value.primitive type.double) (all _.composite _.d2l - (///value.wrap type.long))] + (///value.boxed type.long))] [f64::encode - (///value.unwrap type.double) + (///value.primitive type.double) (..::toString ..$Double type.double)] [f64::decode @@ -322,7 +323,7 @@ [text::= ..no_op ..no_op (_.invokevirtual ..$Object "equals" (type.method [(list) (list ..$Object) type.boolean (list)])) - (///value.wrap type.boolean)] + (///value.boxed type.boolean)] [text::< (_.checkcast $String) (_.checkcast $String) (_.invokevirtual ..$String "compareTo" (type.method [(list) (list ..$String) type.int (list)])) (..predicate _.iflt)] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/jvm/host.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/jvm/host.lux index 522cf231b..e6d606ce9 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/jvm/host.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/jvm/host.lux @@ -28,24 +28,25 @@ [macro ["^" pattern] ["[0]" template]] - [target - [jvm - ["[0]" version] - ["[0]" modifier (.use "[1]#[0]" monoid)] - ["[0]" method (.only Method)] - ["[0]" class (.only Class)] - [constant - [pool (.only Resource)]] - [encoding - ["[0]" name]] - ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad) - ["__" instruction (.only Primitive_Array_Type)]] - ["[0]" type (.only Type Typed Argument) - ["[0]" category (.only Void Value' Value Return' Return Primitive Object Array Var Parameter)] - ["[0]" box] - ["[0]" reflection] - ["[0]" signature] - ["[0]" parser]]]]]]] + [compiler + [target + [jvm + ["[0]" version] + ["[0]" modifier (.use "[1]#[0]" monoid)] + ["[0]" method (.only Method)] + ["[0]" class (.only Class)] + [constant + [pool (.only Resource)]] + [encoding + ["[0]" name]] + ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad) + ["__" instruction (.only Primitive_Array_Type)]] + ["[0]" type (.only Type Typed Argument) + ["[0]" category (.only Void Value' Value Return' Return Primitive Object Array Var Parameter)] + ["[0]" box] + ["[0]" reflection] + ["[0]" signature] + ["[0]" parser]]]]]]]] ["[0]" // [common (.only custom)] ["///[1]" //// @@ -592,7 +593,7 @@ (in (all _.composite objectG (_.instanceof (type.class class (list))) - (///value.wrap type.boolean)))))])) + (///value.boxed type.boolean)))))])) (def object::cast Handler @@ -606,13 +607,13 @@ (text#= to)) (all _.composite valueG - (///value.wrap )) + (///value.boxed )) (and (text#= from) (text#= (..reflection ) to)) (all _.composite valueG - (///value.unwrap ))] + (///value.primitive ))] [box.boolean type.boolean] [box.byte type.byte] @@ -1099,7 +1100,7 @@ (list#each (function (_ [register [type term]]) (let [then! (when (type.primitive? type) {.#Right type} - (///value.unwrap type) + (///value.primitive type) {.#Left type} (_.checkcast type))] @@ -1161,7 +1162,7 @@ {.#Right returnT} (template.let [(unwrap_primitive ) [(all _.composite - (///value.unwrap ) + (///value.primitive ) )]] (`` (cond (,, (with_template [ ] [(of type.equivalence = returnT) @@ -1216,7 +1217,7 @@ [[(n.+ jvm_register) (all _.composite ( jvm_register) - (///value.wrap ) + (///value.boxed ) (_.astore lux_register))]]] (`` (cond (,, (with_template [ ] [(of type.equivalence = argumentT) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/common.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/common.lux index e9a458146..84afea3dd 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/common.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/common.lux @@ -21,9 +21,9 @@ [meta [macro ["^" pattern]] - ["@" target (.only) - ["_" lua (.only Expression Statement)]] [compiler + ["@" target (.only) + ["_" lua (.only Expression Statement)]] [meta [archive (.only Archive)]]]]]] [///// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/host.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/host.lux index d27a45487..a57d8122f 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/host.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/host.lux @@ -13,8 +13,9 @@ [text ["%" \\format (.only format)]]] [meta - [target - ["_" lua (.only Var Expression)]]]]] + [compiler + [target + ["_" lua (.only Var Expression)]]]]]] ["[0]" // ["[1][0]" common (.only custom)] ["///[1]" //// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/python/common.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/python/common.lux index ad59ba175..8a6993af0 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/python/common.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/python/common.lux @@ -21,9 +21,9 @@ [meta [macro ["^" pattern]] - [target - ["_" python (.only Expression Statement)]] [compiler + [target + ["_" python (.only Expression Statement)]] [meta [archive (.only Archive)]]]]]] [///// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/python/host.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/python/host.lux index 8257f1fb1..10bec9e24 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/python/host.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/python/host.lux @@ -13,8 +13,9 @@ ["[0]" dictionary] ["[0]" list]]] [meta - [target - ["_" python (.only Expression SVar)]]]]] + [compiler + [target + ["_" python (.only Expression SVar)]]]]]] [// [common (.only custom)] [//// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/ruby/common.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/ruby/common.lux index f5facd483..96ffcb0c6 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/ruby/common.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/ruby/common.lux @@ -21,9 +21,9 @@ [meta [macro ["^" pattern]] - [target - ["_" ruby (.only Expression Statement)]] [compiler + [target + ["_" ruby (.only Expression Statement)]] [meta [archive (.only Archive)]]]]]] [///// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/ruby/host.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/ruby/host.lux index aebe5f445..b8321b637 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/ruby/host.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/ruby/host.lux @@ -13,8 +13,9 @@ [text ["%" \\format (.only format)]]] [meta - [target - ["_" ruby (.only Var Expression)]]]]] + [compiler + [target + ["_" ruby (.only Var Expression)]]]]]] [// [common (.only custom)] [//// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/primitive.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/primitive.lux index 6deddbdd5..a3e90178d 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/primitive.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/primitive.lux @@ -2,8 +2,9 @@ [library [lux (.except i64) [meta - [target - ["_" c++ (.only Literal Expression)]]]]]) + [compiler + [target + ["_" c++ (.only Literal Expression)]]]]]]) (def .public bit (-> Bit diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/runtime.lux index 7e29191ac..c03a1a813 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/runtime.lux @@ -8,8 +8,9 @@ ["[0]" code] [macro [syntax (.only syntax)]] - [target - ["_" c++]]]]]) + [compiler + [target + ["_" c++]]]]]]) (def .public (host_value of it) (-> _.Type _.Expression diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/type.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/type.lux index f091e288f..9aac0541c 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/type.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/type.lux @@ -2,8 +2,9 @@ [library [lux (.except i64) [meta - [target - ["_" c++]]]]]) + [compiler + [target + ["_" c++]]]]]]) (def .public bit _.Type diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/function.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/function.lux index dadd86f24..9216b36ec 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/function.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/function.lux @@ -10,8 +10,9 @@ [collection ["[0]" list (.use "[1]#[0]" functor mix)]]] [meta - [target - ["_" js (.only Expression Computation Var Statement)]]]]] + [compiler + [target + ["_" js (.only Expression Computation Var Statement)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Phase! Translator)] ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/loop.lux index 012c47d7e..364c5476f 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/loop.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/loop.lux @@ -13,8 +13,9 @@ [number ["n" nat]]] [meta - [target - ["_" js (.only Computation Var Expression Statement)]]]]] + [compiler + [target + ["_" js (.only Computation Var Expression Statement)]]]]]] ["[0]" // [runtime (.only Operation Phase Phase! Translator Translator!)] ["[1][0]" when] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/primitive.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/primitive.lux index 509108682..3f44bf974 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/primitive.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/primitive.lux @@ -2,8 +2,9 @@ [library [lux (.except i64) [meta - [target - ["_" js (.only Computation)]]]]] + [compiler + [target + ["_" js (.only Computation)]]]]]] ["[0]" // ["[1][0]" runtime]]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/reference.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/reference.lux index 95393bf91..d24f3b328 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/reference.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/reference.lux @@ -2,8 +2,9 @@ [library [lux (.except) [meta - [target - ["_" js (.only Expression)]]]]] + [compiler + [target + ["_" js (.only Expression)]]]]]] [/// [reference (.only System)]]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/runtime.lux index 13790c910..8957e7b7f 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/runtime.lux @@ -23,8 +23,9 @@ ["<[1]>" \\parser]] ["[0]" macro (.only) [syntax (.only syntax)]] - [target - ["_" js (.only Expression Var Computation Statement)]]]]] + [compiler + [target + ["_" js (.only Expression Var Computation Statement)]]]]]] ["[0]" /// ["[1][0]" reference] ["//[1]" /// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/structure.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/structure.lux index 081afea98..3d960d4ef 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/structure.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/structure.lux @@ -4,8 +4,9 @@ [abstract ["[0]" monad (.only do)]] [meta - [target - ["_" js (.only Expression)]]]]] + [compiler + [target + ["_" js (.only Expression)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Translator)] ["[1][0]" primitive] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/when.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/when.lux index a8fc6674f..a5b9e024f 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/when.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/when.lux @@ -15,8 +15,9 @@ [meta [macro ["^" pattern]] - [target - ["_" js (.only Expression Computation Var Statement)]]]]] + [compiler + [target + ["_" js (.only Expression Computation Var Statement)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Phase! Translator Translator!)] ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm.lux index a3ca297a4..056229af4 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm.lux @@ -12,12 +12,12 @@ ["[0]" meta (.only) [macro ["^" pattern]] - [target - [jvm - ["_" bytecode (.only Bytecode)]]] [type ["[0]" check]] [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)]]] [meta ["[0]" archive (.only Archive)] ["[0]" cache diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function.lux index ec4ad62bf..cacd56250 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function.lux @@ -17,23 +17,24 @@ ["n" nat] ["[0]" i32]]] [meta - [target - [jvm - ["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad)] - ["[0]" version] - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - ["[0]" field (.only Field)] - ["[0]" method (.only Method)] - ["[0]" class (.only Class)] - ["[0]" attribute] - ["[0]" type (.only Type) - [category (.only Return' Value')] - ["[0]" reflection]] - ["[0]" constant (.only) - [pool (.only Resource)]] - [encoding - ["[0]" name (.only External Internal)] - ["[0]" unsigned]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad)] + ["[0]" version] + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + ["[0]" field (.only Field)] + ["[0]" method (.only Method)] + ["[0]" class (.only Class)] + ["[0]" attribute] + ["[0]" type (.only Type) + [category (.only Return' Value')] + ["[0]" reflection]] + ["[0]" constant (.only) + [pool (.only Resource)]] + [encoding + ["[0]" name (.only External Internal)] + ["[0]" unsigned]]]]] [compiler [meta ["[0]" archive (.only Archive)] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/abstract.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/abstract.lux index ea783b42a..e5fe2d05b 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/abstract.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/abstract.lux @@ -5,10 +5,11 @@ [text ["%" \\format]]] [meta - [target - [jvm - ["[0]" type (.only Type) - [category (.only Method)]]]]]]] + [compiler + [target + [jvm + ["[0]" type (.only Type) + [category (.only Method)]]]]]]]] [// [field [constant diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/constant.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/constant.lux index cd54bb0f8..46939d297 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/constant.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/constant.lux @@ -5,14 +5,15 @@ [collection ["[0]" sequence]]] [meta - [target - [jvm - ["[0]" field (.only Field)] - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - [type (.only Type) - [category (.only Value)]] - [constant - [pool (.only Resource)]]]]]]]) + [compiler + [target + [jvm + ["[0]" field (.only Field)] + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + [type (.only Type) + [category (.only Value)]] + [constant + [pool (.only Resource)]]]]]]]]) (def modifier (Modifier Field) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/constant/arity.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/constant/arity.lux index 0f7856172..a3b14eb57 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/constant/arity.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/constant/arity.lux @@ -2,11 +2,12 @@ [library [lux (.except type) [meta - [target - [jvm - ["[0]" type] - [constant - [pool (.only Resource)]]]]]]] + [compiler + [target + [jvm + ["[0]" type] + [constant + [pool (.only Resource)]]]]]]]] ["[0]" // [///////// [arity (.only Arity)]]]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable.lux index 17ef0b605..f4db0d370 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable.lux @@ -6,15 +6,16 @@ ["[0]" list (.use "[1]#[0]" functor)] ["[0]" sequence]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - ["[0]" field (.only Field)] - [type (.only Type) - [category (.only Value Class)]] - [constant - [pool (.only Resource)]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + ["[0]" field (.only Field)] + [type (.only Type) + [category (.only Value Class)]] + [constant + [pool (.only Resource)]]]]]]]] ["[0]" //// ["[1][0]" type] ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux index c58fad6cf..182361228 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux @@ -4,13 +4,14 @@ [control ["[0]" try]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" type] - [encoding - [name (.only External)] - ["[0]" signed]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" type] + [encoding + [name (.only External)] + ["[0]" signed]]]]]]]] ["[0]" //// ["[1][0]" abstract]]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/foreign.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/foreign.lux index ae7170923..362cc7fe9 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/foreign.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/foreign.lux @@ -5,14 +5,15 @@ [collection ["[0]" list]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" field (.only Field)] - [constant - [pool (.only Resource)]] - [type (.only Type) - [category (.only Value Class)]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" field (.only Field)] + [constant + [pool (.only Resource)]] + [type (.only Type) + [category (.only Value Class)]]]]]]]] ["[0]" // (.only) ["///[1]" //// ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/partial.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/partial.lux index 7310e30ce..76f169327 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/partial.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/partial.lux @@ -10,14 +10,15 @@ [number ["n" nat]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad)] - ["[0]" field (.only Field)] - [type (.only Type) - [category (.only Class)]] - [constant - [pool (.only Resource)]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad)] + ["[0]" field (.only Field)] + [type (.only Type) + [category (.only Class)]] + [constant + [pool (.only Resource)]]]]]]]] ["[0]" // (.only) ["[1][0]" count] ["/[1]" // diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method.lux index b00454753..ec3edccb4 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method.lux @@ -2,10 +2,11 @@ [library [lux (.except) [meta - [target - [jvm - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - ["[0]" method (.only Method)]]]]]]) + [compiler + [target + [jvm + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + ["[0]" method (.only Method)]]]]]]]) (def .public modifier (Modifier Method) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/apply.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/apply.lux index 34a552ba6..29259d702 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/apply.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/apply.lux @@ -14,16 +14,17 @@ ["i" int] ["[0]" i32]]] [meta - [target - [jvm - ["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad)] - ["[0]" method (.only Method)] - [constant - [pool (.only Resource)]] - [encoding - ["[0]" signed]] - ["[0]" type (.only Type) - ["[0]" category (.only Class)]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad)] + ["[0]" method (.only Method)] + [constant + [pool (.only Resource)]] + [encoding + ["[0]" signed]] + ["[0]" type (.only Type) + ["[0]" category (.only Class)]]]]]]]] ["[0]" // (.only) ["[1][0]" reset] ["[1][0]" implementation] @@ -85,75 +86,75 @@ over_extent (i.- (.int apply_arity) (.int function_arity))] (method.method //.modifier ////runtime.apply::name - false (////runtime.apply::type apply_arity) - (list) - {.#Some (when num_partials - 0 (all _.composite - ////reference.this - (..inputs ..this_offset apply_arity) - (//implementation.call class function_arity) - _.areturn) - _ (do _.monad - [@default _.new_label - @labelsH _.new_label - @labelsT (|> _.new_label - (list.repeated (-- num_partials)) - (monad.all _.monad)) - .let [cases (|> (list#composite {.#Item [@labelsH @labelsT]} - (list @default)) - list.enumeration - (list#each (function (_ [stage @case]) - (let [current_partials (|> (list.indices stage) - (list#each (///partial.get class)) - (monad.all _.monad)) - already_partial? (n.> 0 stage) - exact_match? (i.= over_extent (.int stage)) - has_more_than_necessary? (i.> over_extent (.int stage))] + false (////runtime.apply::type apply_arity) + (list) + {.#Some (when num_partials + 0 (all _.composite + ////reference.this + (..inputs ..this_offset apply_arity) + (//implementation.call class function_arity) + _.areturn) + _ (do _.monad + [@default _.new_label + @labelsH _.new_label + @labelsT (|> _.new_label + (list.repeated (-- num_partials)) + (monad.all _.monad)) + .let [cases (|> (list#composite {.#Item [@labelsH @labelsT]} + (list @default)) + list.enumeration + (list#each (function (_ [stage @case]) + (let [current_partials (|> (list.indices stage) + (list#each (///partial.get class)) + (monad.all _.monad)) + already_partial? (n.> 0 stage) + exact_match? (i.= over_extent (.int stage)) + has_more_than_necessary? (i.> over_extent (.int stage))] + (all _.composite + (_.set_label @case) + (cond exact_match? + (all _.composite + ////reference.this + (if already_partial? + (_.invokevirtual class //reset.name (//reset.type class)) + (_#in [])) + current_partials + (..inputs ..this_offset apply_arity) + (//implementation.call class function_arity) + _.areturn) + + has_more_than_necessary? + (let [arity_inputs (|> function_arity (n.- stage)) + additional_inputs (|> apply_arity (n.- arity_inputs))] (all _.composite - (_.set_label @case) - (cond exact_match? - (all _.composite - ////reference.this - (if already_partial? - (_.invokevirtual class //reset.name (//reset.type class)) - (_#in [])) - current_partials - (..inputs ..this_offset apply_arity) - (//implementation.call class function_arity) - _.areturn) - - has_more_than_necessary? - (let [arity_inputs (|> function_arity (n.- stage)) - additional_inputs (|> apply_arity (n.- arity_inputs))] - (all _.composite - ////reference.this - (_.invokevirtual class //reset.name (//reset.type class)) - current_partials - (..inputs ..this_offset arity_inputs) - (//implementation.call class function_arity) - (apply (n.+ ..this_offset arity_inputs) additional_inputs) - _.areturn)) + ////reference.this + (_.invokevirtual class //reset.name (//reset.type class)) + current_partials + (..inputs ..this_offset arity_inputs) + (//implementation.call class function_arity) + (apply (n.+ ..this_offset arity_inputs) additional_inputs) + _.areturn)) - ... (i.< over_extent (.int stage)) - (let [current_environment (|> (list.indices (list.size environment)) - (list#each (///foreign.get class)) - (monad.all _.monad)) - missing_partials (|> _.aconst_null - (list.repeated (|> num_partials (n.- apply_arity) (n.- stage))) - (monad.all _.monad))] - (all _.composite - (_.new class) - _.dup - current_environment - ///count.value - (..increment apply_arity) - current_partials - (..inputs ..this_offset apply_arity) - missing_partials - (_.invokespecial class //init.name (//init.type environment function_arity)) - _.areturn))))))) - (monad.all _.monad))]] - (all _.composite - ///count.value - (_.tableswitch (try.trusted (signed.s4 +0)) @default [@labelsH @labelsT]) - cases)))}))) + ... (i.< over_extent (.int stage)) + (let [current_environment (|> (list.indices (list.size environment)) + (list#each (///foreign.get class)) + (monad.all _.monad)) + missing_partials (|> _.aconst_null + (list.repeated (|> num_partials (n.- apply_arity) (n.- stage))) + (monad.all _.monad))] + (all _.composite + (_.new class) + _.dup + current_environment + ///count.value + (..increment apply_arity) + current_partials + (..inputs ..this_offset apply_arity) + missing_partials + (_.invokespecial class //init.name (//init.type environment function_arity)) + _.areturn))))))) + (monad.all _.monad))]] + (all _.composite + ///count.value + (_.tableswitch (try.trusted (signed.s4 +0)) @default [@labelsH @labelsT]) + cases)))}))) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/implementation.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/implementation.lux index 420872a39..9b961beab 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/implementation.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/implementation.lux @@ -8,15 +8,16 @@ [number ["n" nat]]] [meta - [target - [jvm - ["_" bytecode (.only Label Bytecode)] - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - ["[0]" method (.only Method)] - [constant - [pool (.only Resource)]] - ["[0]" type (.only Type) - ["[0]" category (.only Class)]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Label Bytecode)] + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + ["[0]" method (.only Method)] + [constant + [pool (.only Resource)]] + ["[0]" type (.only Type) + ["[0]" category (.only Class)]]]]]]]] ["[0]" // (.only) ["//[1]" /// ["[0]" runtime] @@ -45,14 +46,14 @@ (def .public (method :it: arity @begin body) (-> (Type Class) Arity Label (Bytecode Any) (Resource Method)) (method.method ..modifier - ..name - false (..type :it: arity) - (list) - {.#Some (all _.composite - (_.set_label @begin) - body - (_.when_continuous _.areturn) - )})) + ..name + false (..type :it: arity) + (list) + {.#Some (all _.composite + (_.set_label @begin) + body + (_.when_continuous _.areturn) + )})) (def .public (call :it: arity) (-> (Type Class) Arity (Bytecode Any)) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/init.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/init.lux index 220755282..ced39ffd6 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/init.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/init.lux @@ -12,16 +12,17 @@ [number ["n" nat]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" method (.only Method)] - [encoding - ["[0]" signed]] - [constant - [pool (.only Resource)]] - ["[0]" type (.only Type) - ["[0]" category (.only Class Value)]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" method (.only Method)] + [encoding + ["[0]" signed]] + [constant + [pool (.only Resource)]] + ["[0]" type (.only Type) + ["[0]" category (.only Class Value)]]]]]]]] ["[0]" // (.only) ["[1][0]" implementation] ["/[1]" // @@ -95,11 +96,11 @@ offset_partial (is (-> Register Register) (|>> offset_arity (n.+ 1)))] (method.method //.modifier ..name - false (..type environment arity) - (list) - {.#Some (all _.composite - ////reference.this - (..super environment_size arity) - (store_all environment_size (///foreign.put class) offset_foreign) - (store_all (-- arity) (///partial.put class) offset_partial) - _.return)}))) + false (..type environment arity) + (list) + {.#Some (all _.composite + ////reference.this + (..super environment_size arity) + (store_all environment_size (///foreign.put class) offset_foreign) + (store_all (-- arity) (///partial.put class) offset_partial) + _.return)}))) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/new.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/new.lux index 5429d603f..79d7bcde0 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/new.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/new.lux @@ -10,15 +10,16 @@ [number ["n" nat]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" field (.only Field)] - ["[0]" method (.only Method)] - ["[0]" constant (.only) - [pool (.only Resource)]] - [type (.only Type) - ["[0]" category (.only Class Value Return)]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" field (.only Field)] + ["[0]" method (.only Method)] + ["[0]" constant (.only) + [pool (.only Resource)]] + [type (.only Type) + ["[0]" category (.only Class Value Return)]]]]] [compiler [meta ["[0]" archive (.only Archive)]]]]]] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/reset.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/reset.lux index 7f8154ed8..76d29acde 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/reset.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/function/method/reset.lux @@ -5,14 +5,15 @@ [collection ["[0]" list (.use "[1]#[0]" functor)]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" method (.only Method)] - [constant - [pool (.only Resource)]] - ["[0]" type (.only Type) - ["[0]" category (.only Class)]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" method (.only Method)] + [constant + [pool (.only Resource)]] + ["[0]" type (.only Type) + ["[0]" category (.only Class)]]]]]]]] ["[0]" // (.only) ["[1][0]" new] ["/[1]" // @@ -42,10 +43,10 @@ (def .public (method class environment arity) (-> (Type Class) (Environment Synthesis) Arity (Resource Method)) (method.method //.modifier ..name - false (..type class) - (list) - {.#Some (all _.composite - (if (arity.multiary? arity) - (//new.instance' (..current_environment class environment) class environment arity) - ////reference.this) - _.areturn)})) + false (..type class) + (list) + {.#Some (all _.composite + (if (arity.multiary? arity) + (//new.instance' (..current_environment class environment) class environment arity) + ////reference.this) + _.areturn)})) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux index 04ebfa62a..092af306d 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux @@ -22,19 +22,20 @@ ["[0]" dictionary (.only Dictionary)] ["[0]" sequence]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" loader (.only Library)] - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - ["[0]" field (.only Field)] - ["[0]" method (.only Method)] - ["[0]" version] - ["[0]" class (.only Class)] - ["[0]" encoding - ["[1]/[0]" name]] - ["[0]" type (.only) - ["[0]" descriptor]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" loader (.only Library)] + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + ["[0]" field (.only Field)] + ["[0]" method (.only Method)] + ["[0]" version] + ["[0]" class (.only Class)] + ["[0]" encoding + ["[1]/[0]" name]] + ["[0]" type (.only) + ["[0]" descriptor]]]]] [compiler [meta [archive diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/loop.lux index 98a58a08d..4ddcb2166 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/loop.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/loop.lux @@ -13,9 +13,10 @@ [number ["n" nat]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad)]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode) (.use "[1]#[0]" monad)]]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Translator)] ["[1][0]" value] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux index db64e3fa0..8be9200a9 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux @@ -12,12 +12,13 @@ [meta [macro ["^" pattern]] - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" type] - [encoding - ["[0]" signed]]]]]]]) + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" type] + [encoding + ["[0]" signed]]]]]]]]) (def $Boolean (type.class "java.lang.Boolean" (list))) (def $Long (type.class "java.lang.Long" (list))) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/program.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/program.lux index de928bd0b..1c5701621 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/program.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/program.lux @@ -11,17 +11,18 @@ [collection ["[0]" sequence]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - ["[0]" method (.only Method)] - ["[0]" version] - ["[0]" class (.only Class)] - [encoding - ["[0]" name]] - ["[0]" type (.only) - ["[0]" reflection]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + ["[0]" method (.only Method)] + ["[0]" version] + ["[0]" class (.only Class)] + [encoding + ["[0]" name]] + ["[0]" type (.only) + ["[0]" reflection]]]]] [compiler [language [lux @@ -145,14 +146,14 @@ (-> (-> unit.ID Text) (Program (Bytecode Any) Definition)) (let [super_class (|> ..^Object type.reflection reflection.reflection name.internal) main (method.method ..main::modifier "main" - false ..main::type - (list) - {.#Some (all _.composite - program - ..input_list - ..feed_inputs - ..run_io - _.return)}) + false ..main::type + (list) + {.#Some (all _.composite + program + ..input_list + ..feed_inputs + ..run_io + _.return)}) class (artifact_name context)] [class (<| (\\format.result class.format) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/reference.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/reference.lux index ac72e04a1..d336069d7 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/reference.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/reference.lux @@ -7,12 +7,13 @@ [text ["%" \\format (.only format)]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" type] - [encoding - ["[0]" unsigned]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" type] + [encoding + ["[0]" unsigned]]]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation)] ["[1][0]" value] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/runtime.lux index af848be72..cfdf7ac2a 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/runtime.lux @@ -22,21 +22,22 @@ ["[0]" i64]]] [meta ["[0]" version] - [target - ["[0]" jvm - ["_" bytecode (.only Label Bytecode)] - ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] - ["[0]" field (.only Field)] - ["[0]" method (.only Method)] - ["[1]/[0]" version] - ["[0]" class (.only Class)] - ["[0]" constant (.only) - [pool (.only Resource)]] - [encoding - ["[0]" name]] - ["[0]" type (.only Type) - ["[0]" category (.only Return' Value')] - ["[0]" reflection]]]]]]] + [compiler + [target + ["[0]" jvm + ["_" bytecode (.only Label Bytecode)] + ["[0]" modifier (.only Modifier) (.use "[1]#[0]" monoid)] + ["[0]" field (.only Field)] + ["[0]" method (.only Method)] + ["[1]/[0]" version] + ["[0]" class (.only Class)] + ["[0]" constant (.only) + [pool (.only Resource)]] + [encoding + ["[0]" name]] + ["[0]" type (.only Type) + ["[0]" category (.only Return' Value')] + ["[0]" reflection]]]]]]]] ["[0]" // ["[1][0]" type] ["[1][0]" value] @@ -155,7 +156,7 @@ (_.anewarray //type.value)) $lefts (all _.composite _.iload_0 - (//value.wrap type.int)) + (//value.boxed type.int)) $right? _.aload_1 $value _.aload_2] (method.method ..modifier ..variant::name @@ -228,7 +229,7 @@ (all _.composite _.aload_0 (_.invokestatic //type.frac "parseDouble" (type.method [(list) (list //type.text) type.double (list)])) - (//value.wrap type.double) + (//value.boxed type.double) ))})) (def .public log! @@ -315,7 +316,7 @@ ::lefts (all _.composite (..get ..variant_lefts) - (//value.unwrap type.int)) + (//value.primitive type.int)) ::right? (..get ..variant_right?) ::value (..get ..variant_value) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/structure.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/structure.lux index d9bca3484..c877aa0b8 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/structure.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/structure.lux @@ -12,12 +12,13 @@ [number ["[0]" i32]]] [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" type] - [encoding - ["[0]" signed]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" type] + [encoding + ["[0]" signed]]]]]]]] ["[0]" // ["[1][0]" type] ["[1][0]" runtime (.only Operation Phase Translator)] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/type.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/type.lux index 329c0a02f..37ba4209c 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/type.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/type.lux @@ -2,9 +2,10 @@ [library [lux (.except) [meta - [target - [jvm - ["[0]" type]]]]]]) + [compiler + [target + [jvm + ["[0]" type]]]]]]]) (def .public frac (type.class "java.lang.Double" (list))) (def .public text (type.class "java.lang.String" (list))) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/value.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/value.lux index 70adbaaf3..ad51ce9c4 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/value.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/value.lux @@ -2,18 +2,20 @@ [library [lux (.except Type) [meta - [target - [jvm - ["_" bytecode (.only Bytecode)] - ["[0]" type (.only Type) (.use "[1]#[0]" equivalence) - [category (.only Primitive)] - ["[0]" box]]]]]]]) + [compiler + [target + [jvm + ["_" bytecode (.only Bytecode)] + ["[0]" type (.only Type) (.use "[1]#[0]" equivalence) + [category (.only Primitive)] + ["[0]" box]]]]]]]]) (def .public field "value") (with_template [ ] [(def ( type) - (-> (Type Primitive) Text) + (-> (Type Primitive) + Text) (`` (cond (,, (with_template [ ] [(type#= type) ] @@ -23,28 +25,29 @@ [type.int ] [type.long ] [type.float ] - [type.double ] - [type.char ])) - ... else - (undefined))))] + [type.double ])) + ... type.char + )))] - [primitive_wrapper + [box box.boolean box.byte box.short box.int box.long box.float box.double box.char] - [primitive_unwrap + [value_method "booleanValue" "byteValue" "shortValue" "intValue" "longValue" "floatValue" "doubleValue" "charValue"] ) -(def .public (wrap type) - (-> (Type Primitive) (Bytecode Any)) - (let [wrapper (type.class (primitive_wrapper type) (list))] +(def .public (boxed type) + (-> (Type Primitive) + (Bytecode Any)) + (let [wrapper (type.class (box type) (list))] (_.invokestatic wrapper "valueOf" (type.method [(list) (list type) wrapper (list)])))) -(def .public (unwrap type) - (-> (Type Primitive) (Bytecode Any)) - (let [wrapper (type.class (primitive_wrapper type) (list))] +(def .public (primitive type) + (-> (Type Primitive) + (Bytecode Any)) + (let [wrapper (type.class (box type) (list))] (all _.composite (_.checkcast wrapper) - (_.invokevirtual wrapper (primitive_unwrap type) (type.method [(list) (list) type (list)]))))) + (_.invokevirtual wrapper (value_method type) (type.method [(list) (list) type (list)]))))) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/when.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/when.lux index 4be90b358..d16e62582 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/when.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/when.lux @@ -17,14 +17,15 @@ [meta [macro ["^" pattern]] - [target - [jvm - ["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad) - [environment - [limit - ["[0]" stack]]]] - ["[0]" type (.only Type) - [category (.only Method)]]]]]]] + [compiler + [target + [jvm + ["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad) + [environment + [limit + ["[0]" stack]]]] + ["[0]" type (.only Type) + [category (.only Method)]]]]]]]] ["[0]" // ["[1][0]" type] ["[1][0]" runtime (.only Operation Phase Translator)] @@ -118,7 +119,7 @@ [@else _.new_label] (all _.composite ..peek - (//value.unwrap type.boolean) + (//value.primitive type.boolean) (if! @else) then! (_.set_label @else) @@ -153,8 +154,8 @@ fork!))))] - [path|i64_fork (I64 Any) (//value.unwrap type.long) _.dup2 _.pop2 ..long _.lcmp _.ifne] - [path|f64_fork Frac (//value.unwrap type.double) _.dup2 _.pop2 _.double _.dcmpl _.ifne] + [path|i64_fork (I64 Any) (//value.primitive type.long) _.dup2 _.pop2 ..long _.lcmp _.ifne] + [path|f64_fork Frac (//value.primitive type.double) _.dup2 _.pop2 _.double _.dcmpl _.ifne] [path|text_fork Text (of _.monad in []) _.dup _.pop _.string ..equals@Object _.ifeq] ) @@ -269,7 +270,7 @@ @end _.new_label] (all _.composite test! - (//value.unwrap type.boolean) + (//value.primitive type.boolean) (_.ifeq @else) then! (_.when_continuous (_.goto @end)) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/function.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/function.lux index 8a0b43ac5..e0ad98469 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/function.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/function.lux @@ -10,8 +10,9 @@ [collection ["[0]" list (.use "[1]#[0]" functor mix)]]] [meta - [target - ["_" lua (.only Var Expression Label Statement)]]]]] + [compiler + [target + ["_" lua (.only Var Expression Label Statement)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Phase! Translator)] ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/loop.lux index 6b008d307..bf236869e 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/loop.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/loop.lux @@ -14,8 +14,9 @@ [number ["n" nat]]] [meta - [target - ["_" lua (.only Var Expression Label Statement)]]]]] + [compiler + [target + ["_" lua (.only Var Expression Label Statement)]]]]]] ["[0]" // [runtime (.only Operation Phase Phase! Translator Translator!)] ["[1][0]" when] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/primitive.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/primitive.lux index 48c05d948..3a961c192 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/primitive.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/primitive.lux @@ -2,8 +2,9 @@ [library [lux (.except i64) [meta - [target - ["_" lua (.only Literal)]]]]]) + [compiler + [target + ["_" lua (.only Literal)]]]]]]) (with_template [ ] [(def .public diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/reference.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/reference.lux index f7309bb8c..5f7023011 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/reference.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/reference.lux @@ -2,8 +2,9 @@ [library [lux (.except) [meta - [target - ["_" lua (.only Expression)]]]]] + [compiler + [target + ["_" lua (.only Expression)]]]]]] [/// [reference (.only System)]]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux index 78741fe06..22b4680fe 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux @@ -23,8 +23,9 @@ ["<[1]>" \\parser]] ["[0]" macro (.only) [syntax (.only syntax)]] - ["@" target (.only) - ["_" lua (.only Expression Location Var Computation Literal Label Statement)]]]]] + [compiler + ["@" target (.only) + ["_" lua (.only Expression Location Var Computation Literal Label Statement)]]]]]] ["[0]" /// ["[1][0]" reference] ["//[1]" /// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/structure.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/structure.lux index a15f0833a..5e9ac29f9 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/structure.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/structure.lux @@ -4,8 +4,9 @@ [abstract ["[0]" monad (.only do)]] [meta - [target - ["_" lua (.only Expression)]]]]] + [compiler + [target + ["_" lua (.only Expression)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Translator)] ["[1][0]" primitive] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/when.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/when.lux index 1bb6d979f..3fc103d8b 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/when.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/when.lux @@ -12,8 +12,9 @@ [meta [macro ["^" pattern]] - [target - ["_" lua (.only Expression Var Statement)]]]]] + [compiler + [target + ["_" lua (.only Expression Var Statement)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Phase! Translator Translator!)] ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/function.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/function.lux index 49a43f19c..93a026558 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/function.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/function.lux @@ -10,8 +10,9 @@ [collection ["[0]" list (.use "[1]#[0]" functor mix)]]] [meta - [target - ["_" python (.only SVar Expression Statement)]]]]] + [compiler + [target + ["_" python (.only SVar Expression Statement)]]]]]] ["[0]" // [runtime (.only Operation Phase Translator Phase! Translator!)] ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/loop.lux index 8fa93362b..d453a4daf 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/loop.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/loop.lux @@ -14,8 +14,9 @@ [number ["n" nat]]] [meta - [target - ["_" python (.only Expression SVar Statement)]]]]] + [compiler + [target + ["_" python (.only Expression SVar Statement)]]]]]] ["[0]" // [runtime (.only Operation Phase Translator Phase! Translator!)] ["[1][0]" when] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/primitive.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/primitive.lux index b50c2c965..88c0ec4d2 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/primitive.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/primitive.lux @@ -2,8 +2,9 @@ [library [lux (.except i64) [meta - [target - ["_" python (.only Expression)]]]]] + [compiler + [target + ["_" python (.only Expression)]]]]]] ["[0]" // ["[1][0]" runtime]]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/reference.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/reference.lux index 9b105605e..a9f05d739 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/reference.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/reference.lux @@ -2,8 +2,9 @@ [library [lux (.except) [meta - [target - ["_" python (.only Expression)]]]]] + [compiler + [target + ["_" python (.only Expression)]]]]]] [/// [reference (.only System)]]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux index 4a82f30f1..a3a1278ec 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux @@ -25,8 +25,9 @@ ["<[1]>" \\parser]] ["[0]" macro (.only) [syntax (.only syntax)]] - ["@" target (.only) - ["_" python (.only Expression SVar Computation Literal Statement)]]]]] + [compiler + ["@" target (.only) + ["_" python (.only Expression SVar Computation Literal Statement)]]]]]] ["[0]" /// ["[1][0]" reference] ["//[1]" /// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/structure.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/structure.lux index 747404963..4ac9f1446 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/structure.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/structure.lux @@ -4,8 +4,9 @@ [abstract ["[0]" monad (.only do)]] [meta - [target - ["_" python (.only Expression)]]]]] + [compiler + [target + ["_" python (.only Expression)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Translator)] ["[1][0]" primitive] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/when.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/when.lux index a8555492d..2294ae08a 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/when.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/when.lux @@ -16,8 +16,9 @@ [meta [macro ["^" pattern]] - [target - ["_" python (.only Expression SVar Statement)]]]]] + [compiler + [target + ["_" python (.only Expression SVar Statement)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Translator Phase! Translator!)] ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/reference.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/reference.lux index 4190683b5..bb5ba85e6 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/reference.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/reference.lux @@ -5,8 +5,9 @@ [text ["%" \\format (.only format)]]] [meta - ["@" target] - ["[0]" version]]]] + ["[0]" version] + [compiler + ["@" target]]]]] [//// ["[0]" phase (.use "[1]#[0]" monad)] ["[0]" translation] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/function.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/function.lux index ea8a104a3..41e0cbc42 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/function.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/function.lux @@ -10,8 +10,9 @@ [collection ["[0]" list (.use "[1]#[0]" functor mix)]]] [meta - [target - ["_" ruby (.only LVar GVar Expression Statement)]]]]] + [compiler + [target + ["_" ruby (.only LVar GVar Expression Statement)]]]]]] ["[0]" // [runtime (.only Operation Phase Translator Phase! Translator!)] ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/loop.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/loop.lux index a670b4b4b..a5cf36131 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/loop.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/loop.lux @@ -14,8 +14,9 @@ [number ["n" nat]]] [meta - [target - ["_" ruby (.only Expression LVar Statement)]]]]] + [compiler + [target + ["_" ruby (.only Expression LVar Statement)]]]]]] ["[0]" // [runtime (.only Operation Phase Translator Phase! Translator!)] ["[1][0]" when] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/primitive.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/primitive.lux index 06b100bc5..a103cb4ad 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/primitive.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/primitive.lux @@ -2,8 +2,9 @@ [library [lux (.except i64) [meta - [target - ["_" ruby (.only Literal)]]]]]) + [compiler + [target + ["_" ruby (.only Literal)]]]]]]) (with_template [ ] [(def .public diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/reference.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/reference.lux index 28629dc19..05ea2cc78 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/reference.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/reference.lux @@ -2,8 +2,9 @@ [library [lux (.except) [meta - [target - ["_" ruby (.only Expression)]]]]] + [compiler + [target + ["_" ruby (.only Expression)]]]]]] [/// [reference (.only System)]]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/runtime.lux index 8be246d69..c252a29b1 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/runtime.lux @@ -24,8 +24,9 @@ ["<[1]>" \\parser]] ["[0]" macro (.only) [syntax (.only syntax)]] - ["@" target (.only) - ["_" ruby (.only Expression LVar Computation Literal Statement)]]]]] + [compiler + ["@" target (.only) + ["_" ruby (.only Expression LVar Computation Literal Statement)]]]]]] ["[0]" /// ["[1][0]" reference] ["//[1]" /// diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/structure.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/structure.lux index 100ebd54f..18acf6b50 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/structure.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/structure.lux @@ -4,8 +4,9 @@ [abstract ["[0]" monad (.only do)]] [meta - [target - ["_" ruby (.only Expression)]]]]] + [compiler + [target + ["_" ruby (.only Expression)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Translator)] ["[1][0]" primitive] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/when.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/when.lux index f2f982e09..546cce489 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/when.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/when.lux @@ -16,8 +16,9 @@ [meta [macro ["^" pattern]] - [target - ["_" ruby (.only Expression LVar Statement)]]]]] + [compiler + [target + ["_" ruby (.only Expression LVar Statement)]]]]]] ["[0]" // ["[1][0]" runtime (.only Operation Phase Translator Phase! Translator!)] ["[1][0]" reference] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/syntax.lux b/stdlib/source/library/lux/meta/compiler/language/lux/syntax.lux index 85a28c8f7..381f3d579 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/syntax.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/syntax.lux @@ -41,13 +41,14 @@ ["[0]" list] ["[0]" dictionary (.only Dictionary)]]] [meta - ["@" target] ["[0]" symbol] ["[0]" code ["<[1]>" \\parser]] [macro [syntax (.only syntax)] - ["[0]" template]]] + ["[0]" template]] + [compiler + ["@" target]]] [math [number ["n" nat] diff --git a/stdlib/source/library/lux/meta/compiler/meta/cache/artifact.lux b/stdlib/source/library/lux/meta/compiler/meta/cache/artifact.lux index e404e3e4d..2c8458abc 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/cache/artifact.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/cache/artifact.lux @@ -10,7 +10,8 @@ [text ["%" \\format (.only format)]]] [meta - [target (.only Target)]] + [compiler + [target (.only Target)]]] [world ["[0]" file]]]] ["[0]" // diff --git a/stdlib/source/library/lux/meta/compiler/meta/cache/module.lux b/stdlib/source/library/lux/meta/compiler/meta/cache/module.lux index 7b3a122bb..3245f2ead 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/cache/module.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/cache/module.lux @@ -16,7 +16,8 @@ ["[0]" list (.use "[1]#[0]" functor)] ["[0]" dictionary (.only Dictionary)]]] [meta - ["@" target]] + [compiler + ["@" target]]] [world ["[0]" file]]]] ["[0]" // (.only) diff --git a/stdlib/source/library/lux/meta/compiler/meta/context.lux b/stdlib/source/library/lux/meta/compiler/meta/context.lux index ef520917a..f65ba71b8 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/context.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/context.lux @@ -2,7 +2,8 @@ [library [lux (.except #host #target) [meta - ["@" target (.only Target)]] + [compiler + ["@" target (.only Target)]]] [world [file (.only Path)]]]]) diff --git a/stdlib/source/library/lux/meta/compiler/meta/io/archive.lux b/stdlib/source/library/lux/meta/compiler/meta/io/archive.lux index b62fa4307..92c9c99a4 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/io/archive.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/io/archive.lux @@ -20,11 +20,12 @@ ["[0]" dictionary (.only Dictionary)] ["[0]" sequence (.only Sequence)]]] [meta - ["@" target (.only Target)] ["[0]" configuration (.only Configuration)] ["[0]" version] [macro - ["^" pattern]]] + ["^" pattern]] + [compiler + ["@" target (.only Target)]]] [world ["[0]" file]]]] ["[0]" // (.only) diff --git a/stdlib/source/library/lux/meta/compiler/meta/io/context.lux b/stdlib/source/library/lux/meta/compiler/meta/io/context.lux index 471ffe6f0..bd6cd284f 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/io/context.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/io/context.lux @@ -20,8 +20,6 @@ [collection ["[0]" dictionary (.only Dictionary)] ["[0]" list]]] - [meta - ["@" target]] [world ["[0]" file]]]] ["[0]" // (.only Context) diff --git a/stdlib/source/library/lux/meta/compiler/meta/packager/jvm.lux b/stdlib/source/library/lux/meta/compiler/meta/packager/jvm.lux index 18577f342..d83ae1caf 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/packager/jvm.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/packager/jvm.lux @@ -21,10 +21,11 @@ ["n" nat] ["i" int]]] [meta - [target - [jvm - [encoding - ["[0]" name]]]]] + [compiler + [target + [jvm + [encoding + ["[0]" name]]]]]] [world ["[0]" file]]]] ["[0]" // (.only Packager) diff --git a/stdlib/source/library/lux/meta/compiler/meta/packager/ruby.lux b/stdlib/source/library/lux/meta/compiler/meta/packager/ruby.lux index 04e3ef0a3..8ef41f448 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/packager/ruby.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/packager/ruby.lux @@ -22,8 +22,9 @@ ["[0]" nat]]] [meta [type (.only sharing)] - [target - ["_" ruby]]] + [compiler + [target + ["_" ruby]]]] [world ["[0]" file]]]] ["[0]" // (.only Packager) diff --git a/stdlib/source/library/lux/meta/compiler/meta/packager/scheme.lux b/stdlib/source/library/lux/meta/compiler/meta/packager/scheme.lux index e36749bb3..df317cf47 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/packager/scheme.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/packager/scheme.lux @@ -21,8 +21,9 @@ ["[0]" tar]]] [meta [type (.only sharing)] - [target - ["_" scheme]]] + [compiler + [target + ["_" scheme]]]] [world ["[0]" file] [time diff --git a/stdlib/source/library/lux/meta/compiler/target.lux b/stdlib/source/library/lux/meta/compiler/target.lux new file mode 100644 index 000000000..11094325d --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target.lux @@ -0,0 +1,26 @@ +(.require + [library + [lux (.except)]]) + +(type .public Target + Text) + +(with_template [ ] + [(def .public + Target + )] + + ... TODO: Delete ASAP. + [old "{old}"] + ... Available. + [js "JavaScript"] + [jvm "JVM"] + [lua "Lua"] + [python "Python"] + [ruby "Ruby"] + ... Not available yet. + [common_lisp "Common Lisp"] + [php "PHP"] + [r "R"] + [scheme "Scheme"] + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/c++.lux b/stdlib/source/library/lux/meta/compiler/target/c++.lux new file mode 100644 index 000000000..952cc0c0b --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/c++.lux @@ -0,0 +1,350 @@ +(.require + [library + [lux (.except Code Type Global Declaration int as function template local global type) + [abstract + [equivalence (.only Equivalence)]] + [control + ["|" pipe]] + [data + ["[0]" text (.only \n \t) (.use "[1]#[0]" equivalence) + ["%" \\format]] + [collection + ["[0]" list (.use "[1]#[0]" functor)]]] + [math + [number + ["f" frac]]] + [meta + [macro + ["[0]" template]] + [type + ["[0]" nominal]]]]]) + +(def parameter_separator ", ") +(def term_delimiters ["(" ")"]) +(def type_delimiters ["<" ">"]) + +(nominal.def .public (Code of) + Text + + (def .public equivalence + (All (_ of) + (Equivalence (Code of))) + (implementation + (def (= refererence it) + (text#= (nominal.representation refererence) + (nominal.representation it))))) + + (def .public code + (-> (Code Any) + Text) + (|>> nominal.representation)) + + (with_template [ +] + [(`` (with_template [ *'] + [(with_expansions [* (template.spliced *') + (template.symbol [ "'"])] + (nominal.def ( *) + Any) + + (.type .public + (Ex (_ *) + ( ( *)))))] + + (,, (template.spliced +))))] + + [Code + [[Type [of]] + [Expression [of]] + [Statement [of]]]] + + [Expression + [[Computation [of]] + [Reference [of]]]] + + [Type + [[Type_Name []]]] + + [Computation + [[Literal []]]] + + [Reference + [[Local []] + [Global []]]] + + [Statement + [[Declaration []]]] + ) + + (def .public bool + (-> Bit + Literal) + (|>> (|.when + .false "false" + .true "true") + nominal.abstraction)) + + (def .public double + (-> Frac + Literal) + (|>> (|.cond [(f.= f.positive_infinity)] + [(|.new "(+1.0/0.0)" [])] + + [(f.= f.negative_infinity)] + [(|.new "(-1.0/0.0)" [])] + + [(f.= f.not_a_number)] + [(|.new "(0.0/0.0)" [])] + + ... else + [%.frac]) + nominal.abstraction)) + + (.type .public Namespace + Text) + + (def .public standard + Namespace + "std") + + (def .public local + (-> Text + Local) + (|>> nominal.abstraction)) + + (def instantiation + (-> (List Type) + Text) + (|>> (|.when + (list) + "" + + it + (|> it + (list#each ..code) + (text.interposed ..parameter_separator) + (text.enclosed ..type_delimiters))))) + + (def .public (global [ns name] parameters) + (-> [Namespace Text] (List Type) + Global) + (nominal.abstraction + (let [instance (%.format name (instantiation parameters))] + (when ns + "" instance + _ (%.format ns "::" instance))))) + + (def .public (type name parameters) + (-> [Namespace Text] (List Type) + Type) + (|> (..global name parameters) + nominal.transmutation)) + + (def .public type_name + (-> Text + Type_Name) + (|>> nominal.abstraction)) + + (with_template [ ] + [(def .public + Type + (..type [ (template.text [])] (list)))] + + ["" void] + ) + + (def .public * + (-> Type + Type) + (|>> nominal.representation + (text.suffix "*") + nominal.abstraction)) + + (def .public deref + (-> Expression + Expression) + (|>> nominal.representation + (text.prefix "*") + nominal.abstraction)) + + (def .public (as type term) + (-> Type Expression + Computation) + (nominal.abstraction + (%.format "(" (nominal.representation type) ")" + " " (nominal.representation term)))) + + (def .public int + (-> Int + Literal) + (|>> %.int + nominal.abstraction)) + + (def application + (-> (List Expression) + Text) + (|>> (list#each ..code) + (text.interposed ..parameter_separator) + (text.enclosed ..term_delimiters))) + + (def .public (on parameters function) + (-> (List Expression) Expression + Expression) + (nominal.abstraction + (%.format (nominal.representation function) + (application parameters)))) + + (def .public (new of parameters) + (-> Type (List Expression) + Expression) + (nominal.abstraction + (%.format "new " + (nominal.representation of) + (application parameters)))) + + (def .public (do method types parameters object) + (-> Text (List Type) (List Expression) Expression + Expression) + (nominal.abstraction + (%.format (nominal.representation object) + "." method + (instantiation types) + (application parameters)))) + + (def .public (<< it to) + (-> Expression Expression + Expression) + (nominal.abstraction + (%.format (nominal.representation to) + " << " + (nominal.representation it)))) + + (def .public (include it) + (-> Text + Declaration) + (nominal.abstraction + (%.format "#include <" it ">"))) + + (def .public (then before after) + (All (_ of) + (-> (Statement of) (Statement of) + (Statement of))) + (nominal.abstraction + (%.format (nominal.representation before) + \n (nominal.representation after)))) + + (def statement + (-> Text + Statement) + (|>> (text.suffix ";") + nominal.abstraction)) + + (def .public ; + (-> Expression + Statement) + (|>> nominal.representation + ..statement)) + + (def .public delete + (-> Expression + Statement) + (|>> nominal.representation + (%.format "delete ") + ..statement)) + + (def template + (-> (List Type_Name) + Text) + (|>> (|.when + (list) + "" + + it + (%.format "template" + " " (|> it + (list#each (|>> nominal.representation (%.format "typename "))) + (text.interposed ..parameter_separator) + (text.enclosed ..type_delimiters)) + " ")))) + + (.type Argument + [Type Local]) + + (def (argument [type it]) + (-> Argument + Text) + (%.format (nominal.representation type) + " " (nominal.representation it))) + + (def arguments + (-> (List Argument) + Text) + (|>> (list#each ..argument) + (text.interposed ..parameter_separator) + (text.enclosed ..term_delimiters))) + + (def block + (-> Statement + Text) + (let [\n\t (%.format \n \t) + <| (%.format "{" \n) + |> (%.format \n "}")] + (|>> nominal.representation + (text.replaced \n \n\t) + (text.enclosed [<| |>])))) + + (def .public (function name types inputs output body) + (-> Local (List Type_Name) (List Argument) Type Statement + Declaration) + (nominal.abstraction + (%.format (..template types) (nominal.representation output) + " " (nominal.representation name) + (..arguments inputs) + " " (..block body)))) + + (def .public (namespace it body) + (-> Namespace Declaration + Declaration) + (nominal.abstraction + (%.format "namespace" + " " it + " " (..block body)))) + + ... https://en.cppreference.com/w/cpp/types/integer + (with_template [] + [(def .public ( it) + (-> Expression + Expression) + (..on (list it) + (nominal.abstraction (template.text []))))] + + [int64_t] + ) + + (def safe + (-> Text + Text) + (let [\\'' (%.format "\" text.\'')] + (`` (|>> (,, (with_template [ ] + [(text.replaced )] + + ["\" "\\"] + [text.\t "\t"] + [text.\v "\v"] + [text.\0 "\0"] + [text.\b "\b"] + [text.\f "\f"] + [text.\n "\n"] + [text.\r "\r"] + [text.\'' \\''] + )) + )))) + + ... https://en.cppreference.com/w/cpp/string/basic_string + (def .public u32string + (-> Text + Literal) + (|>> ..safe + %.text + (%.format "U") + nominal.abstraction)) + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/common_lisp.lux b/stdlib/source/library/lux/meta/compiler/target/common_lisp.lux new file mode 100644 index 000000000..60f46f514 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/common_lisp.lux @@ -0,0 +1,473 @@ +(.require + [library + [lux (.except Code int if cond or and comment let symbol) + [control + ["[0]" pipe]] + [data + ["[0]" text + ["%" \\format (.only format)]] + [collection + ["[0]" list (.use "[1]#[0]" monad monoid)]]] + [math + [number + ["f" frac]]] + [meta + [macro + ["[0]" template]] + [type + ["[0]" nominal (.except def)]]]]]) + +(def as_form + (-> Text Text) + (text.enclosed ["(" ")"])) + +(nominal.def .public (Code brand) + Text + + (def .public manual + (-> Text Code) + (|>> abstraction)) + + (def .public code + (-> (Code Any) Text) + (|>> representation)) + + (with_template [ ] + [(with_expansions [ (template.symbol [ "'"])] + (`` (nominal.def .public ( brand) Any)) + (`` (type .public ( brand) + ( ( brand)))))] + + [Expression Code] + [Computation Expression] + [Access Computation] + [Var Access] + + [Input Code] + ) + + (with_template [ ] + [(with_expansions [ (template.symbol [ "'"])] + (`` (nominal.def .public Any)) + (`` (type .public ( ))))] + + [Label Code] + [Tag Expression] + [Literal Expression] + [Var/1 Var] + [Var/* Input] + ) + + (type .public Lambda + (Record + [#input Var/* + #output (Expression Any)])) + + (def .public nil + Literal + (abstraction "()")) + + (with_template [ ] + [(def .public + (-> Text Literal) + (|>> (format ) abstraction))] + + ["'" symbol] + [":" keyword]) + + (def .public bool + (-> Bit Literal) + (|>> (pipe.when + #0 ..nil + #1 (..symbol "t")))) + + (def .public int + (-> Int Literal) + (|>> %.int abstraction)) + + (def .public float + (-> Frac Literal) + (|>> (pipe.cond [(f.= f.positive_infinity)] + [(pipe.new "(/ 1.0 0.0)" [])] + + [(f.= f.negative_infinity)] + [(pipe.new "(/ -1.0 0.0)" [])] + + [f.not_a_number?] + [(pipe.new "(/ 0.0 0.0)" [])] + + ... else + [%.frac]) + abstraction)) + + (def .public (double value) + (-> Frac Literal) + (abstraction + (.cond (f.= f.positive_infinity value) + "(/ 1.0d0 0.0d0)" + + (f.= f.negative_infinity value) + "(/ -1.0d0 0.0d0)" + + (f.not_a_number? value) + "(/ 0.0d0 0.0d0)" + + ... else + (.let [raw (%.frac value)] + (.if (text.contains? "E" raw) + (text.replaced_once "E" "d" raw) + (format raw "d0")))))) + + (def safe + (-> Text Text) + (`` (|>> (,, (with_template [ ] + [(text.replaced )] + + ["\" "\\"] + [text.tab "\t"] + [text.vertical_tab "\v"] + [text.null "\0"] + [text.back_space "\b"] + [text.form_feed "\f"] + [text.new_line "\n"] + [text.carriage_return "\r"] + [text.double_quote (format "\" text.double_quote)] + )) + ))) + + (def .public string + (-> Text Literal) + (|>> ..safe + (text.enclosed' text.double_quote) + abstraction)) + + (def .public var + (-> Text Var/1) + (|>> abstraction)) + + (def .public args + (-> (List Var/1) Var/*) + (|>> (list#each ..code) + (text.interposed " ") + ..as_form + abstraction)) + + (def .public (args& singles rest) + (-> (List Var/1) Var/1 Var/*) + (|> (when singles + {.#End} + "" + + {.#Item _} + (|> singles + (list#each ..code) + (text.interposed " ") + (text.suffix " "))) + (format "&rest " (representation rest)) + ..as_form + abstraction)) + + (def form + (-> (List (Expression Any)) Expression) + (|>> (list#each ..code) + (text.interposed " ") + ..as_form + abstraction)) + + (def .public (call/* func) + (-> (Expression Any) (-> (List (Expression Any)) (Computation Any))) + (|>> {.#Item func} ..form)) + + (with_template [ ] + [(def .public + (-> (List (Expression Any)) (Computation Any)) + (..call/* (..var )))] + + [vector/* "vector"] + [list/* "list"] + ) + + (def .public (labels definitions body) + (-> (List [Var/1 Lambda]) (Expression Any) (Computation Any)) + (..form (list (..var "labels") + (..form (list#each (function (_ [def_name [def_args def_body]]) + (..form (list def_name (transmutation def_args) def_body))) + definitions)) + body))) + + (def .public (destructuring_bind [bindings expression] body) + (-> [Var/* (Expression Any)] (List (Expression Any)) (Computation Any)) + (..form (list.partial (..var "destructuring-bind") + (transmutation bindings) expression + body))) + + (with_template [ + + +] + [(`` (def .public ( [(,, (template.spliced +))] function) + (-> [(,, (template.spliced +))] (Expression Any) (Computation Any)) + (..call/* function (list (,, (template.spliced +)))))) + + (`` (with_template [ ] + [(def .public ( args) + (-> [(,, (template.spliced +))] (Computation Any)) + ( args (..var )))] + + (,, (template.spliced +))))] + + [call/0 [] [] + [[get_universal_time/0 "get-universal-time"] + [make_hash_table/0 "make-hash-table"]]] + [call/1 [in0] [(Expression Any)] + [[length/1 "length"] + [function/1 "function"] + [copy_seq/1 "copy-seq"] + [null/1 "null"] + [error/1 "error"] + [not/1 "not"] + [floor/1 "floor"] + [type_of/1 "type-of"] + [write_to_string/1 "write-to-string"] + [read_from_string/1 "read-from-string"] + [print/1 "print"] + [reverse/1 "reverse"] + [sxhash/1 "sxhash"] + [string_upcase/1 "string-upcase"] + [string_downcase/1 "string-downcase"] + [char_int/1 "char-int"] + [text/1 "text"] + [hash_table_size/1 "hash-table-size"] + [hash_table_rehash_size/1 "hash-table-rehash-size"] + [code_char/1 "code-char"] + [char_code/1 "char-code"] + [string/1 "string"] + [write_line/1 "write-line"] + [pprint/1 "pprint"] + [identity/1 "identity"]]] + [call/2 [in0 in1] [(Expression Any) (Expression Any)] + [[apply/2 "apply"] + [append/2 "append"] + [cons/2 "cons"] + [char/2 "char"] + [nth/2 "nth"] + [nthcdr/2 "nthcdr"] + [coerce/2 "coerce"] + [eq/2 "eq"] + [equal/2 "equal"] + [string=/2 "string="] + [=/2 "="] + [+/2 "+"] + [*/2 "*"]]] + [call/3 [in0 in1 in2] [(Expression Any) (Expression Any) (Expression Any)] + [[subseq/3 "subseq"] + [map/3 "map"] + [concatenate/3 "concatenate"] + [format/3 "format"]]] + ) + + (with_template [ + +] + [(`` (with_template [ ] + [(def .public ( args) + (-> [(,, (template.spliced +))] (Access Any)) + (transmutation ( args (..var ))))] + + (,, (template.spliced +))))] + + [call/1 [(Expression Any)] + [[car/1 "car"] + [cdr/1 "cdr"] + [cadr/1 "cadr"] + [cddr/1 "cddr"]]] + [call/2 [(Expression Any) (Expression Any)] + [[svref/2 "svref"] + [elt/2 "elt"] + [gethash/2 "gethash"]]] + ) + + (def .public (make_hash_table/with_size size) + (-> (Expression Any) (Computation Any)) + (..call/* (..var "make-hash-table") + (list (..keyword "size") + size))) + + (def .public (funcall/+ [func args]) + (-> [(Expression Any) (List (Expression Any))] (Computation Any)) + (..call/* (..var "funcall") (list.partial func args))) + + (def .public (search/3 [reference space start]) + (-> [(Expression Any) (Expression Any) (Expression Any)] (Computation Any)) + (..call/* (..var "search") + (list reference + space + (..keyword "start2") start))) + + (def .public (concatenate/2|string [left right]) + (-> [(Expression Any) (Expression Any)] (Computation Any)) + (concatenate/3 [(..symbol "string") left right])) + + (with_template [ ] + [(def .public ( left right) + (-> (Expression Any) (Expression Any) (Computation Any)) + (..form (list (..var ) left right)))] + + [or "or"] + [and "and"] + ) + + (with_template [ ] + [(def .public ( [param subject]) + (-> [(Expression Any) (Expression Any)] (Computation Any)) + (..form (list (..var ) subject param)))] + + [/2 ">"] + [>=/2 ">="] + [string (Expression Any) (Expression Any) (Expression Any) (Computation Any)) + (..form (list (..var "if") test then else))) + + (def .public (when test then) + (-> (Expression Any) (Expression Any) (Computation Any)) + (..form (list (..var "when") test then))) + + (def .public (lambda input body) + (-> Var/* (Expression Any) Literal) + (..form (list (..var "lambda") (transmutation input) body))) + + (with_template [ ] + [(def .public ( bindings body) + (-> (List [Var/1 (Expression Any)]) (List (Expression Any)) (Computation Any)) + (..form (list.partial (..var ) + (|> bindings + (list#each (function (_ [name value]) + (..form (list name value)))) + ..form) + body)))] + + [let "let"] + [let* "let*"] + ) + + (def .public (defparameter name body) + (-> Var/1 (Expression Any) (Expression Any)) + (..form (list (..var "defparameter") name body))) + + (def .public (defun name inputs body) + (-> Var/1 Var/* (Expression Any) (Expression Any)) + (..form (list (..var "defun") name (transmutation inputs) body))) + + (with_template [ ] + [(def .public + (-> (List (Expression Any)) (Computation Any)) + (|>> (list.partial (..var )) ..form))] + + [progn "progn"] + [tagbody "tagbody"] + [values/* "values"] + ) + + (def .public (setq name value) + (-> Var/1 (Expression Any) (Expression Any)) + (..form (list (..var "setq") name value))) + + (def .public (setf access value) + (-> (Access Any) (Expression Any) (Expression Any)) + (..form (list (..var "setf") access value))) + + (type .public Handler + (Record + [#condition_type (Expression Any) + #condition Var/1 + #body (Expression Any)])) + + (def .public (handler_case handlers body) + (-> (List Handler) (Expression Any) (Computation Any)) + (..form (list.partial (..var "handler-case") + body + (list#each (function (_ [type condition handler]) + (..form (list type + (transmutation (..args (list condition))) + handler))) + handlers)))) + + (with_template [ ] + [(def .public ( conditions expression) + (-> (List Text) (Expression Any) (Expression Any)) + (when conditions + {.#End} + expression + + {.#Item single {.#End}} + (abstraction + (format single " " (representation expression))) + + _ + (abstraction + (format (|> conditions (list#each ..symbol) + (list.partial (..symbol "or")) ..form + representation) + " " (representation expression)))))] + + [conditional+ "#+"] + [conditional- "#-"]) + + (def .public label + (-> Text Label) + (|>> abstraction)) + + (def .public (block name body) + (-> Label (List (Expression Any)) (Computation Any)) + (..form (list.partial (..var "block") (transmutation name) body))) + + (def .public (return_from target value) + (-> Label (Expression Any) (Computation Any)) + (..form (list (..var "return-from") (transmutation target) value))) + + (def .public (return value) + (-> (Expression Any) (Computation Any)) + (..form (list (..var "return") value))) + + (def .public (cond clauses else) + (-> (List [(Expression Any) (Expression Any)]) (Expression Any) (Computation Any)) + (..form (list.partial (..var "cond") + (list#composite (list#each (function (_ [test then]) + (..form (list test then))) + clauses) + (list (..form (list (..bool true) else))))))) + + (def .public tag + (-> Text Tag) + (|>> abstraction)) + + (def .public go + (-> Tag (Expression Any)) + (|>> (list (..var "go")) + ..form)) + + (def .public values_list/1 + (-> (Expression Any) (Expression Any)) + (|>> (list (..var "values-list")) + ..form)) + + (def .public (multiple_value_setq bindings values) + (-> Var/* (Expression Any) (Expression Any)) + (..form (list (..var "multiple-value-setq") + (transmutation bindings) + values))) + ) + +(def .public (while condition body) + (-> (Expression Any) (Expression Any) (Computation Any)) + (..form (list (..var "loop") (..var "while") condition + (..var "do") body))) diff --git a/stdlib/source/library/lux/meta/compiler/target/js.lux b/stdlib/source/library/lux/meta/compiler/target/js.lux new file mode 100644 index 000000000..c158d9651 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/js.lux @@ -0,0 +1,447 @@ +(.require + [library + [lux (.except Location Code Label or and function if undefined for comment not int try ++ -- the type_of , when) + [control + ["[0]" pipe]] + [data + ["[0]" text (.only) + ["%" \\format (.only format)]] + [collection + ["[0]" list (.use "[1]#[0]" functor mix)]]] + [math + [number + ["i" int] + ["f" frac]]] + [meta + [macro + ["[0]" template]] + [type + ["[0]" nominal (.except def)]]]]]) + +(def expression + (text.enclosed ["(" ")"])) + +(def element + (text.enclosed ["[" "]"])) + +... Added the carriage return for better Windows compatibility. +(def \n+ + Text + (format text.carriage_return text.new_line)) + +(def nested + (-> Text Text) + (|>> (format \n+) + (text.replaced text.new_line (format text.new_line text.tab)))) + +(nominal.def .public (Code brand) + Text + + (def .public code + (-> (Code Any) Text) + (|>> representation)) + + (with_template [ +] + [(with_expansions [ (template.symbol [ "'"])] + (nominal.def ( brand) Any) + (`` (type .public (|> Any (,, (template.spliced +))))))] + + [Expression [Code]] + [Computation [Expression' Code]] + [Location [Computation' Expression' Code]] + [Statement [Code]] + ) + + (with_template [ +] + [(with_expansions [ (template.symbol [ "'"])] + (nominal.def Any) + (`` (type .public (|> (,, (template.spliced +))))))] + + [Var [Location' Computation' Expression' Code]] + [Access [Location' Computation' Expression' Code]] + [Literal [Computation' Expression' Code]] + [Loop [Statement' Code]] + [Label [Code]] + ) + + (with_template [ ] + [(def .public Literal (abstraction ))] + + [null "null"] + [undefined "undefined"] + ) + + (def .public boolean + (-> Bit Literal) + (|>> (pipe.when + #0 "false" + #1 "true") + abstraction)) + + (def .public (number value) + (-> Frac Literal) + (abstraction + (cond (f.not_a_number? value) + "NaN" + + (f.= f.positive_infinity value) + "Infinity" + + (f.= f.negative_infinity value) + "-Infinity" + + ... else + (|> value %.frac ..expression)))) + + (def safe + (-> Text Text) + (`` (|>> (,, (with_template [ ] + [(text.replaced )] + + ["\\" "\"] + ["\t" text.tab] + ["\v" text.vertical_tab] + ["\0" text.null] + ["\b" text.back_space] + ["\f" text.form_feed] + ["\n" text.new_line] + ["\r" text.carriage_return] + [(format "\" text.double_quote) + text.double_quote] + )) + ))) + + (def .public string + (-> Text Literal) + (|>> ..safe + (text.enclosed [text.double_quote text.double_quote]) + abstraction)) + + (def argument_separator ", ") + (def field_separator ": ") + (def statement_suffix ";") + + (def .public array + (-> (List Expression) Computation) + (|>> (list#each ..code) + (text.interposed ..argument_separator) + ..element + abstraction)) + + (def .public var + (-> Text Var) + (|>> abstraction)) + + (def .public (at index array_or_object) + (-> Expression Expression Access) + (abstraction (format (representation array_or_object) (..element (representation index))))) + + (def .public (the field object) + (-> Text Expression Access) + (abstraction (format (representation object) "." field))) + + (def .public (apply function inputs) + (-> Expression (List Expression) Computation) + (|> inputs + (list#each ..code) + (text.interposed ..argument_separator) + ..expression + (format (representation function)) + abstraction)) + + (def .public (do method inputs object) + (-> Text (List Expression) Expression Computation) + (apply (..the method object) inputs)) + + (def .public object + (-> (List [Text Expression]) Computation) + (|>> (list#each (.function (_ [key val]) + (format (representation (..string key)) ..field_separator (representation val)))) + (text.interposed ..argument_separator) + (text.enclosed ["{" "}"]) + ..expression + abstraction)) + + (def .public (, pre post) + (-> Expression Expression Computation) + (|> (format (representation pre) ..argument_separator (representation post)) + ..expression + abstraction)) + + (def .public (then pre post) + (-> Statement Statement Statement) + (abstraction (format (representation pre) + \n+ + (representation post)))) + + (def block + (-> Statement Text) + (let [close (format \n+ "}")] + (|>> representation + ..nested + (text.enclosed ["{" + close])))) + + (def .public (function_definition name inputs body) + (-> Var (List Var) Statement Statement) + (|> body + ..block + (format "function " (representation name) + (|> inputs + (list#each ..code) + (text.interposed ..argument_separator) + ..expression) + " ") + abstraction)) + + (def .public (function name inputs body) + (-> Var (List Var) Statement Computation) + (|> (..function_definition name inputs body) + representation + ..expression + abstraction)) + + (def .public (closure inputs body) + (-> (List Var) Statement Computation) + (|> body + ..block + (format "function" + (|> inputs + (list#each ..code) + (text.interposed ..argument_separator) + ..expression) + " ") + ..expression + abstraction)) + + (with_template [ ] + [(def .public ( param subject) + (-> Expression Expression Computation) + (|> (format (representation subject) " " " " (representation param)) + ..expression + abstraction))] + + [= "==="] + [< "<"] + [<= "<="] + [> ">"] + [>= ">="] + + [+ "+"] + [- "-"] + [* "*"] + [/ "/"] + [% "%"] + + [left_shift "<<"] + [arithmetic_right_shift ">>"] + [logic_right_shift ">>>"] + + [or "||"] + [and "&&"] + [bit_xor "^"] + [bit_or "|"] + [bit_and "&"] + ) + + (with_template [ ] + [(def .public + (-> Expression Computation) + (|>> representation (text.prefix ) ..expression abstraction))] + + ["!" not] + ["~" bit_not] + ["-" opposite] + ) + + (with_template [ ] + [... A 32-bit integer expression. + (def .public ( value) + (-> Computation) + (abstraction (..expression (format ( value) "|0"))))] + + [to_i32 Expression representation] + [i32 Int %.int] + ) + + (def .public (int value) + (-> Int Literal) + (abstraction (.if (i.< +0 value) + (%.int value) + (%.nat (.nat value))))) + + (def .public (? test then else) + (-> Expression Expression Expression Computation) + (|> (format (representation test) + " ? " (representation then) + " : " (representation else)) + ..expression + abstraction)) + + (def .public type_of + (-> Expression Computation) + (|>> representation + (format "typeof ") + ..expression + abstraction)) + + (def .public (new constructor inputs) + (-> Expression (List Expression) Computation) + (|> (format "new " (representation constructor) + (|> inputs + (list#each ..code) + (text.interposed ..argument_separator) + ..expression)) + ..expression + abstraction)) + + (def .public statement + (-> Expression Statement) + (|>> representation (text.suffix ..statement_suffix) abstraction)) + + (def .public use_strict + Statement + (abstraction (format text.double_quote "use strict" text.double_quote ..statement_suffix))) + + (def .public (declare name) + (-> Var Statement) + (abstraction (format "var " (representation name) ..statement_suffix))) + + (def .public (define name value) + (-> Var Expression Statement) + (abstraction (format "var " (representation name) " = " (representation value) ..statement_suffix))) + + (def .public (set name value) + (-> Location Expression Expression) + (abstraction (format (representation name) " = " (representation value)))) + + (def .public (throw message) + (-> Expression Statement) + (abstraction (format "throw " (representation message) ..statement_suffix))) + + (def .public (return value) + (-> Expression Statement) + (abstraction (format "return " (representation value) ..statement_suffix))) + + (def .public delete + (-> Location Expression) + (|>> representation + (format "delete ") + ..expression + abstraction)) + + (def .public (if test then! else!) + (-> Expression Statement Statement Statement) + (abstraction (format "if(" (representation test) ") " + (..block then!) + " else " + (..block else!)))) + + (def .public (when test then!) + (-> Expression Statement Statement) + (abstraction (format "if(" (representation test) ") " + (..block then!)))) + + (def .public (while test body) + (-> Expression Statement Loop) + (abstraction (format "while(" (representation test) ") " + (..block body)))) + + (def .public (do_while test body) + (-> Expression Statement Loop) + (abstraction (format "do " (..block body) + " while(" (representation test) ")" ..statement_suffix))) + + (def .public (try body [exception catch]) + (-> Statement [Var Statement] Statement) + (abstraction (format "try " + (..block body) + " catch(" (representation exception) ") " + (..block catch)))) + + (def .public (for var init condition update iteration) + (-> Var Expression Expression Expression Statement Loop) + (abstraction (format "for(" (representation (..define var init)) + " " (representation condition) + ..statement_suffix " " (representation update) + ")" + (..block iteration)))) + + (def .public label + (-> Text Label) + (|>> abstraction)) + + (def .public (with_label label loop) + (-> Label Loop Statement) + (abstraction (format (representation label) ": " (representation loop)))) + + (with_template [ <0> <1>] + [(def .public <0> + Statement + (abstraction (format ..statement_suffix))) + + (def .public (<1> label) + (-> Label Statement) + (abstraction (format " " (representation label) ..statement_suffix)))] + + ["break" break break_at] + ["continue" continue continue_at] + ) + + (with_template [ ] + [(def .public + (-> Location Expression) + (|>> representation + (text.suffix ) + abstraction))] + + [++ "++"] + [-- "--"] + ) + + (def .public (comment commentary on) + (All (_ kind) (-> Text (Code kind) (Code kind))) + (abstraction (format "/* " commentary " */" " " (representation on)))) + + (def .public (switch input cases default) + (-> Expression (List [(List Literal) Statement]) (Maybe Statement) Statement) + (abstraction (format "switch (" (representation input) ") " + (|> (format (|> cases + (list#each (.function (_ [when then]) + (format (|> when + (list#each (|>> representation (text.enclosed ["case " ":"]))) + (text.interposed \n+)) + (..nested (representation then))))) + (text.interposed \n+)) + \n+ + (.when default + {.#Some default} + (format "default:" + (..nested (representation default))) + + {.#None} + "")) + abstraction + ..block)))) + ) + +(with_template [ + + +] + [(`` (def .public ( function) + (-> Expression (,, (template.spliced +)) Computation) + (.function (_ (,, (template.spliced +))) + (..apply function (list (,, (template.spliced +))))))) + + (`` (with_template [ ] + [(def .public ( (..var )))] + + (,, (template.spliced +))))] + + [apply_1 [_0] [Expression] + [[not_a_number? "isNaN"]]] + + [apply_2 [_0 _1] [Expression Expression] + []] + + [apply_3 [_0 _1 _2] [Expression Expression Expression] + []] + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/attribute.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute.lux new file mode 100644 index 000000000..04d68cb41 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute.lux @@ -0,0 +1,199 @@ +(.require + [library + [lux (.except Info Code Type #info) + [abstract + [monad (.only do)] + ["[0]" equivalence (.only Equivalence)]] + [control + ["[0]" try]] + [data + ["[0]" sum] + ["[0]" product] + ["[0]" binary + ["[1]F" \\format (.only Format)]]] + [math + [number + ["n" nat]]] + [meta + [macro + ["^" pattern]]]]] + ["[0]" // + ["[1][0]" index (.only Index)] + ["[1][0]" type (.only Type) + ["[2][0]" signature (.only Signature)]] + [encoding + ["[1][0]" unsigned (.only U2 U4)]] + ["[1][0]" constant (.only UTF8 Class Value) + ["[2][0]" pool (.only Pool Resource) (.use "[1]#[0]" monad)]]] + ["[0]" / + ["[1][0]" constant (.only Constant)] + ["[1][0]" code] + ["[1][0]" line_number_table (.only Line_Number_Table)]]) + +(type .public (Info about) + (Record + [#name (Index UTF8) + #length U4 + #info about])) + +(def .public (info_equivalence Equivalence) + (All (_ about) + (-> (Equivalence about) + (Equivalence (Info about)))) + (all product.equivalence + //index.equivalence + //unsigned.equivalence + Equivalence)) + +(def (info_format format) + (All (_ about) + (-> (Format about) + (Format (Info about)))) + (function (_ [name length info]) + (let [[nameS nameT] (//index.format name) + [lengthS lengthT] (//unsigned.format/4 length) + [infoS infoT] (format info)] + [(all n.+ nameS lengthS infoS) + (|>> nameT lengthT infoT)]))) + +(with_expansions [ (these (/code.Code Attribute))] + (type .public Attribute + (Rec Attribute + (Variant + {#Constant (Info (Constant Any))} + {#Code (Info )} + {#Signature (Info (Index UTF8))} + {#Source_File (Info (Index UTF8))} + {#Line_Number_Table (Info Line_Number_Table)}))) + + (type .public Code + ) + ) + +(def .public equivalence + (Equivalence Attribute) + (equivalence.rec + (function (_ equivalence) + (all sum.equivalence + (info_equivalence /constant.equivalence) + (info_equivalence (/code.equivalence equivalence)) + (info_equivalence //index.equivalence) + (info_equivalence //index.equivalence) + (info_equivalence /line_number_table.equivalence) + )))) + +(def common_attribute_length + (all n.+ + ... u2 attribute_name_index; + //unsigned.bytes/2 + ... u4 attribute_length; + //unsigned.bytes/4 + )) + +(def (length attribute) + (-> Attribute Nat) + (when attribute + (^.with_template [] + [{ [name length info]} + (|> length //unsigned.value (n.+ ..common_attribute_length))]) + ([#Constant] + [#Code] + [#Signature] + [#Source_File] + [#Line_Number_Table]))) + +... TODO: Inline ASAP +(def (constant' index @name) + (-> (Constant Any) (Index UTF8) Attribute) + {#Constant [#name @name + ... https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.2 + #length (|> /constant.length //unsigned.u4 try.trusted) + #info index]}) + +(def .public (constant index) + (-> (Constant Any) (Resource Attribute)) + (//pool#each (constant' index) (//pool.utf8 "ConstantValue"))) + +... TODO: Inline ASAP +(def (code' specification @name) + (-> Code (Index UTF8) Attribute) + {#Code [#name @name + ... https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3 + #length (|> specification + (/code.length ..length) + //unsigned.u4 + try.trusted) + #info specification]}) + +(def .public (code specification) + (-> Code (Resource Attribute)) + (//pool#each (code' specification) (//pool.utf8 "Code"))) + +... TODO: Inline ASAP +(def (signature' it @name) + (-> (Index UTF8) (Index UTF8) Attribute) + {#Signature [#name @name + ... https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.9 + #length (|> //index.length //unsigned.u4 try.trusted) + #info it]}) + +(def .public (signature it) + (All (_ category) + (-> (Signature category) (Resource Attribute))) + (do //pool.monad + [it (|> it //signature.signature //pool.utf8)] + (//pool#each (signature' it) + (//pool.utf8 "Signature")))) + +... TODO: Inline ASAP +(def (source_file' it @name) + (-> (Index UTF8) (Index UTF8) + Attribute) + {#Source_File [#name @name + ... https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.10 + #length (|> //index.length //unsigned.u4 try.trusted) + #info it]}) + +(def .public (source_file it) + (-> Text + (Resource Attribute)) + (do //pool.monad + [it (//pool.utf8 it)] + (//pool#each (source_file' it) + (//pool.utf8 "SourceFile")))) + +... TODO: Inline ASAP +(def (line_number_table' it @name) + (-> Line_Number_Table (Index UTF8) + Attribute) + {#Line_Number_Table [#name @name + ... https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.12 + #length (|> it + /line_number_table.length + //unsigned.u4 + try.trusted) + #info it]}) + +(def .public (line_number_table it) + (-> Line_Number_Table + (Resource Attribute)) + (//pool#each (line_number_table' it) + (//pool.utf8 "LineNumberTable"))) + +(def .public (format it) + (Format Attribute) + (when it + {#Constant it} + ((info_format /constant.format) it) + + {#Code it} + ((info_format (/code.format format)) it) + + {#Signature it} + ((info_format //index.format) it) + + {#Source_File it} + ((info_format //index.format) it) + + {#Line_Number_Table it} + ((info_format /line_number_table.format) it))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/code.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/code.lux new file mode 100644 index 000000000..a350fde0f --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/code.lux @@ -0,0 +1,83 @@ +(.require + [library + [lux (.except Code) + [abstract + [equivalence (.only Equivalence)]] + [data + ["[0]" product] + ["[0]" binary (.only Binary)] + ["[0]" binary + ["[1]F" \\format (.only Format) (.use "[1]#[0]" monoid)]] + [collection + ["[0]" sequence (.only Sequence) (.use "[1]#[0]" functor mix)]]] + [math + [number + ["n" nat]]]]] + ["[0]" /// + [bytecode + [environment + ["[1][0]" limit (.only Limit)]]] + [encoding + ["[1][0]" unsigned (.only U2)]]] + ["[0]" / + ["[1][0]" exception (.only Exception)]]) + +(type .public (Code Attribute) + (Record + [#limit Limit + #code Binary + #exception_table (Sequence Exception) + #attributes (Sequence Attribute)])) + +(def .public (length length code) + (All (_ Attribute) (-> (-> Attribute Nat) (Code Attribute) Nat)) + (all n.+ + ... u2 max_stack; + ... u2 max_locals; + ///limit.length + ... u4 code_length; + ///unsigned.bytes/4 + ... u1 code[code_length]; + (binary.size (the #code code)) + ... u2 exception_table_length; + ///unsigned.bytes/2 + ... exception_table[exception_table_length]; + (|> code + (the #exception_table) + sequence.size + (n.* /exception.length)) + ... u2 attributes_count; + ///unsigned.bytes/2 + ... attribute_info attributes[attributes_count]; + (|> code + (the #attributes) + (sequence#each length) + (sequence#mix n.+ 0)))) + +(def .public (equivalence attribute_equivalence) + (All (_ attribute) + (-> (Equivalence attribute) (Equivalence (Code attribute)))) + (all product.equivalence + ///limit.equivalence + binary.equivalence + (sequence.equivalence /exception.equivalence) + (sequence.equivalence attribute_equivalence) + )) + +... https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3 +(def .public (format format code) + (All (_ Attribute) (-> (Format Attribute) (Format (Code Attribute)))) + (all binaryF#composite + ... u2 max_stack; + ... u2 max_locals; + (///limit.format (the #limit code)) + ... u4 code_length; + ... u1 code[code_length]; + (binaryF.binary_32 (the #code code)) + ... u2 exception_table_length; + ... exception_table[exception_table_length]; + ((binaryF.sequence_16 /exception.format) (the #exception_table code)) + ... u2 attributes_count; + ... attribute_info attributes[attributes_count]; + ((binaryF.sequence_16 format) (the #attributes code)) + )) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/code/exception.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/code/exception.lux new file mode 100644 index 000000000..08c7cc129 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/code/exception.lux @@ -0,0 +1,59 @@ +(.require + [library + [lux (.except) + [abstract + [equivalence (.only Equivalence)]] + [data + ["[0]" product] + [binary + ["[0]" \\format (.only Format)]]] + [math + [number + ["n" nat]]]]] + ["[0]" // + ["//[1]" /// + [constant (.only Class)] + ["[1][0]" index (.only Index)] + [bytecode + ["[1][0]" address (.only Address)]] + [encoding + ["[1][0]" unsigned (.only U2)]]]]) + +(type .public Exception + (Record + [#start Address + #end Address + #handler Address + #catch (Index Class)])) + +(def .public equivalence + (Equivalence Exception) + (all product.equivalence + ////address.equivalence + ////address.equivalence + ////address.equivalence + ////index.equivalence + )) + +... https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3 +(def .public length + Nat + (all n.+ + ... u2 start_pc; + ////unsigned.bytes/2 + ... u2 end_pc; + ////unsigned.bytes/2 + ... u2 handler_pc; + ////unsigned.bytes/2 + ... u2 catch_type; + ////unsigned.bytes/2 + )) + +(def .public format + (Format Exception) + (all \\format.and + ////address.format + ////address.format + ////address.format + ////index.format + )) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/constant.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/constant.lux new file mode 100644 index 000000000..830632337 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/constant.lux @@ -0,0 +1,27 @@ +(.require + [library + [lux (.except) + [abstract + [equivalence (.only Equivalence)]] + [data + [binary + [\\format (.only Format)]]]]] + ["[0]" /// + [constant (.only Value)] + ["[1][0]" index (.only Index)] + [encoding + ["[1][0]" unsigned (.only U2 U4)]]]) + +(type .public (Constant a) + (Index (Value a))) + +(def .public equivalence + (All (_ a) (Equivalence (Constant a))) + ///index.equivalence) + +(def .public length + ///index.length) + +(def .public format + (All (_ a) (Format (Constant a))) + ///index.format) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/line_number_table.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/line_number_table.lux new file mode 100644 index 000000000..1a3e73ece --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/attribute/line_number_table.lux @@ -0,0 +1,71 @@ +... https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.12 +(.require + [library + [lux (.except) + [abstract + [equivalence (.only Equivalence)]] + [data + ["[0]" product] + ["[0]" binary + ["![1]" \\format (.only Format) (.use "[1]#[0]" monoid)]] + [collection + ["[0]" sequence (.only Sequence)]]] + [math + [number + ["n" nat]]]]] + [/// + [encoding + ["[0]" unsigned (.only U2)]]]) + +(type .public Entry + (Record + [#start_program_counter U2 + #line_number U2])) + +(def entry_length + Nat + (all n.+ + ... u2 start_pc; + unsigned.bytes/2 + ... u2 line_number; + unsigned.bytes/2 + )) + +(def entry_equivalence + (Equivalence Entry) + (all product.equivalence + unsigned.equivalence + unsigned.equivalence + )) + +(def (entry_format it) + (Format Entry) + (all !binary#composite + (unsigned.format/2 (the #start_program_counter it)) + (unsigned.format/2 (the #line_number it)) + )) + +(type .public Line_Number_Table + (Sequence Entry)) + +(def .public empty + Line_Number_Table + sequence.empty) + +(def .public (length it) + (-> Line_Number_Table + Nat) + (all n.+ + ... u2 line_number_table_length; + unsigned.bytes/2 + ... line_number_table[line_number_table_length]; + (n.* entry_length (sequence.size it)) + )) + +(def .public equivalence + (Equivalence Line_Number_Table) + (sequence.equivalence entry_equivalence)) + +(def .public format + (Format Line_Number_Table) + (!binary.sequence_16 entry_format)) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode.lux new file mode 100644 index 000000000..dc51330fa --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode.lux @@ -0,0 +1,1204 @@ +(.require + [library + [lux (.except Type Label int try except) + ["[0]" ffi (.only import)] + [abstract + [monoid (.only Monoid)] + [functor (.only Functor)] + ["[0]" monad (.only Monad do)]] + [control + ["[0]" writer (.only Writer)] + ["[0]" state (.only +State)] + ["[0]" maybe] + ["[0]" try (.only Try) (.use "[1]#[0]" monad)] + ["[0]" exception]] + [data + ["[0]" product] + [text + ["%" \\format (.only format)]] + [collection + ["[0]" list (.use "[1]#[0]" functor mix)] + ["[0]" dictionary (.only Dictionary)] + ["[0]" sequence (.only Sequence)]]] + [math + [number + ["n" nat] + ["i" int] + ["[0]" i32 (.only I32)]]] + [meta + [macro + ["^" pattern] + ["[0]" template]]]]] + ["[0]" / + ["_" instruction (.only Primitive_Array_Type Instruction Estimator) (.use "[1]#[0]" monoid)] + ["[1][0]" address (.only Address)] + ["[1][0]" jump (.only Jump Big_Jump)] + ["[1][0]" environment (.only Environment) + [limit + ["/[0]" registry (.only Register Registry)] + ["/[0]" stack (.only Stack)]]] + ["/[1]" // + ["[1][0]" index (.only Index)] + [encoding + ["[1][0]" name] + ["[1][0]" unsigned (.only U1 U2)] + ["[1][0]" signed (.only S1 S2 S4)]] + ["[1][0]" constant (.only UTF8) + ["[1]/[0]" pool (.only Pool Resource)]] + [attribute + ["[0]" line_number_table (.only Line_Number_Table)] + [code + ["[1][0]" exception (.only Exception)]]] + ["[0]" type (.only Type) + [category (.only Class Object Value' Value Return' Return Method)] + ["[0]" reflection] + ["[0]" parser]]]]) + +(type .public Label + Nat) + +(type .public Resolver + (Dictionary Label [Stack (Maybe Address)])) + +(type .public Tracker + (Record + [#program_counter Address + #next Label + #known Resolver + #line_number_table Line_Number_Table])) + +(def fresh + Tracker + [#program_counter /address.start + #next 0 + #known (dictionary.empty n.hash) + #line_number_table line_number_table.empty]) + +(type .public Relative + (-> Resolver + (Try [(Sequence Exception) + Instruction]))) + +(def no_exceptions + (Sequence Exception) + sequence.empty) + +(def relative#identity + Relative + (function (_ _) + {try.#Success [..no_exceptions _.empty]})) + +(def try|do + (template (_ ) + [(.when + {try.#Success } + + + failure + (as_expected failure))])) + +(def try|in + (template (_ ) + [{try.#Success }])) + +(def (relative#composite left right) + (-> Relative Relative Relative) + (cond (same? ..relative#identity left) + right + + (same? ..relative#identity right) + left + + ... else + (function (_ resolver) + (<| (try|do [left_exceptions left_instruction] (left resolver)) + (try|do [right_exceptions right_instruction] (right resolver)) + (try|in [(of sequence.monoid composite left_exceptions right_exceptions) + (_#composite left_instruction right_instruction)]))))) + +(def relative_monoid + (Monoid Relative) + (implementation + (def identity ..relative#identity) + (def composite ..relative#composite))) + +(type .public (Bytecode a) + (+State Try [Pool Environment Tracker] + (Writer Relative a))) + +(def .public new_label + (Bytecode Label) + (function (_ [pool environment tracker]) + {try.#Success [[pool + environment + (revised #next ++ tracker)] + [..relative#identity + (the #next tracker)]]})) + +(exception.def .public (label_has_already_been_set label) + (exception.Exception Label) + (exception.report + (list ["Label" (%.nat label)]))) + +(exception.def .public (mismatched_environments [instruction label address expected actual]) + (exception.Exception [Symbol Label Address Stack Stack]) + (exception.report + (list ["Instruction" (%.symbol instruction)] + ["Label" (%.nat label)] + ["Address" (/address.text address)] + ["Expected" (/stack.text expected)] + ["Actual" (/stack.text actual)]))) + +(def .public (set? label) + (-> Label (Bytecode (Maybe [Stack Address]))) + (function (_ state) + (let [[pool environment tracker] state] + {try.#Success [state + [..relative#identity + (when (dictionary.value label (the #known tracker)) + {.#Some [expected {.#Some address}]} + {.#Some [expected address]} + + _ + {.#None})]]}))) + +(def .public (acknowledged? label) + (-> Label (Bytecode (Maybe Stack))) + (function (_ state) + (let [[pool environment tracker] state] + {try.#Success [state + [..relative#identity + (when (dictionary.value label (the #known tracker)) + {.#Some [expected {.#None}]} + {.#Some expected} + + _ + {.#None})]]}))) + +(def .public stack + (Bytecode (Maybe Stack)) + (function (_ state) + (let [[pool environment tracker] state] + {try.#Success [state + [..relative#identity + (the /environment.#stack environment)]]}))) + +(with_expansions [ (these (try|in [[pool + environment + (revised #known + (dictionary.has label [actual {.#Some @here}]) + tracker)] + [..relative#identity + []]]))] + (def .public (set_label label) + (-> Label (Bytecode Any)) + (function (_ [pool environment tracker]) + (let [@here (the #program_counter tracker)] + (when (dictionary.value label (the #known tracker)) + {.#Some [expected {.#Some address}]} + (exception.except ..label_has_already_been_set [label]) + + {.#Some [expected {.#None}]} + (<| (try|do [actual environment] (/environment.continue expected environment)) + ) + + ... {.#None} + _ + (<| (try|do [actual environment] (/environment.continue (|> environment + (the /environment.#stack) + (maybe.else /stack.empty)) + environment)) + )))))) + +(def .public functor + (Functor Bytecode) + (implementation + (def (each $ it) + (function (_ state) + (when (it state) + {try.#Success [state' [relative it]]} + {try.#Success [state' [relative ($ it)]]} + + ... {try.#Failure error} + failure + (as_expected failure)))))) + +(def .public monad + (Monad Bytecode) + (implementation + (def functor ..functor) + + (def (in it) + (function (_ state) + {try.#Success [state [relative#identity it]]})) + + (def (conjoint ^^it) + (function (_ state) + (when (^^it state) + {try.#Success [state' [left ^it]]} + (when (^it state') + {try.#Success [state'' [right it]]} + {try.#Success [state'' [(relative#composite left right) it]]} + + ... {try.#Failure error} + failure + (as_expected failure)) + + ... {try.#Failure error} + failure + (as_expected failure)))))) + +(def .public (when_continuous it) + (-> (Bytecode Any) (Bytecode Any)) + (do ..monad + [stack ..stack] + (.when stack + {.#Some _} + it + + ... {.#None} + _ + (in [])))) + +(def .public (when_acknowledged @ it) + (-> Label (Bytecode Any) (Bytecode Any)) + (do ..monad + [?@ (..acknowledged? @)] + (.when ?@ + {.#Some _} + it + + ... {.#None} + _ + (in [])))) + +(def .public (failure error) + (-> Text Bytecode) + (function (_ _) + {try.#Failure error})) + +(def .public (except exception value) + (All (_ e) (-> (exception.Exception e) e Bytecode)) + (..failure (exception.error exception value))) + +(def .public (resolve environment bytecode) + (All (_ a) + (-> Environment (Bytecode a) + (Resource [Environment Line_Number_Table (Sequence Exception) Instruction a]))) + (function (_ pool) + (<| (try|do [[pool environment tracker] [relative output]] (bytecode [pool environment ..fresh])) + (try|do [exceptions instruction] (relative (the #known tracker))) + (try|in [pool [environment + (the #line_number_table tracker) + exceptions + instruction + output]])))) + +(def (step estimator counter) + (-> Estimator Address (Try Address)) + (/address.move (estimator counter) counter)) + +(def (bytecode consumption production registry [estimator bytecode] input) + (All (_ a) (-> U2 U2 Registry [Estimator (-> [a] Instruction)] a (Bytecode Any))) + (function (_ [pool environment tracker]) + (<| (try|do environment' (|> environment + (/environment.consumes consumption) + (monad.then try.monad (|>> (/environment.produces production) + (try#each (/environment.has registry)) + try#conjoint)))) + (try|do program_counter' (step estimator (the #program_counter tracker))) + (try|in [[pool + environment' + (has #program_counter program_counter' tracker)] + [(function (_ _) + (try|in [..no_exceptions (bytecode input)])) + []]])))) + +(with_template [ ] + [(def U2 + (|> //unsigned.u2 try.trusted))] + + [$0 0] + [$1 1] + [$2 2] + [$3 3] + [$4 4] + [$5 5] + [$6 6] + ) + +(with_template [ ] + [(def Registry (|> //unsigned.u2 try.trusted /registry.registry))] + + [@_ 0] + [@0 1] + [@1 2] + [@2 3] + [@3 4] + [@4 5] + ) + +(with_template [ ] + [(def .public + (Bytecode Any) + (..bytecode + + + + []))] + + [nop $0 $0 @_ _.nop] + + [aconst_null $0 $1 @_ _.aconst_null] + + [iconst_m1 $0 $1 @_ _.iconst_m1] + [iconst_0 $0 $1 @_ _.iconst_0] + [iconst_1 $0 $1 @_ _.iconst_1] + [iconst_2 $0 $1 @_ _.iconst_2] + [iconst_3 $0 $1 @_ _.iconst_3] + [iconst_4 $0 $1 @_ _.iconst_4] + [iconst_5 $0 $1 @_ _.iconst_5] + + [lconst_0 $0 $2 @_ _.lconst_0] + [lconst_1 $0 $2 @_ _.lconst_1] + + [fconst_0 $0 $1 @_ _.fconst_0] + [fconst_1 $0 $1 @_ _.fconst_1] + [fconst_2 $0 $1 @_ _.fconst_2] + + [dconst_0 $0 $2 @_ _.dconst_0] + [dconst_1 $0 $2 @_ _.dconst_1] + + [pop $1 $0 @_ _.pop] + [pop2 $2 $0 @_ _.pop2] + + [dup $1 $2 @_ _.dup] + [dup_x1 $2 $3 @_ _.dup_x1] + [dup_x2 $3 $4 @_ _.dup_x2] + [dup2 $2 $4 @_ _.dup2] + [dup2_x1 $3 $5 @_ _.dup2_x1] + [dup2_x2 $4 $6 @_ _.dup2_x2] + + [swap $2 $2 @_ _.swap] + + [iaload $2 $1 @_ _.iaload] + [laload $2 $2 @_ _.laload] + [faload $2 $1 @_ _.faload] + [daload $2 $2 @_ _.daload] + [aaload $2 $1 @_ _.aaload] + [baload $2 $1 @_ _.baload] + [caload $2 $1 @_ _.caload] + [saload $2 $1 @_ _.saload] + + [iload_0 $0 $1 @0 _.iload_0] + [iload_1 $0 $1 @1 _.iload_1] + [iload_2 $0 $1 @2 _.iload_2] + [iload_3 $0 $1 @3 _.iload_3] + + [lload_0 $0 $2 @1 _.lload_0] + [lload_1 $0 $2 @2 _.lload_1] + [lload_2 $0 $2 @3 _.lload_2] + [lload_3 $0 $2 @4 _.lload_3] + + [fload_0 $0 $1 @0 _.fload_0] + [fload_1 $0 $1 @1 _.fload_1] + [fload_2 $0 $1 @2 _.fload_2] + [fload_3 $0 $1 @3 _.fload_3] + + [dload_0 $0 $2 @1 _.dload_0] + [dload_1 $0 $2 @2 _.dload_1] + [dload_2 $0 $2 @3 _.dload_2] + [dload_3 $0 $2 @4 _.dload_3] + + [aload_0 $0 $1 @0 _.aload_0] + [aload_1 $0 $1 @1 _.aload_1] + [aload_2 $0 $1 @2 _.aload_2] + [aload_3 $0 $1 @3 _.aload_3] + + [iastore $3 $0 @_ _.iastore] + [lastore $4 $0 @_ _.lastore] + [fastore $3 $0 @_ _.fastore] + [dastore $4 $0 @_ _.dastore] + [aastore $3 $0 @_ _.aastore] + [bastore $3 $0 @_ _.bastore] + [castore $3 $0 @_ _.castore] + [sastore $3 $0 @_ _.sastore] + + [istore_0 $1 $0 @0 _.istore_0] + [istore_1 $1 $0 @1 _.istore_1] + [istore_2 $1 $0 @2 _.istore_2] + [istore_3 $1 $0 @3 _.istore_3] + + [lstore_0 $2 $0 @1 _.lstore_0] + [lstore_1 $2 $0 @2 _.lstore_1] + [lstore_2 $2 $0 @3 _.lstore_2] + [lstore_3 $2 $0 @4 _.lstore_3] + + [fstore_0 $1 $0 @0 _.fstore_0] + [fstore_1 $1 $0 @1 _.fstore_1] + [fstore_2 $1 $0 @2 _.fstore_2] + [fstore_3 $1 $0 @3 _.fstore_3] + + [dstore_0 $2 $0 @1 _.dstore_0] + [dstore_1 $2 $0 @2 _.dstore_1] + [dstore_2 $2 $0 @3 _.dstore_2] + [dstore_3 $2 $0 @4 _.dstore_3] + + [astore_0 $1 $0 @0 _.astore_0] + [astore_1 $1 $0 @1 _.astore_1] + [astore_2 $1 $0 @2 _.astore_2] + [astore_3 $1 $0 @3 _.astore_3] + + [iadd $2 $1 @_ _.iadd] + [isub $2 $1 @_ _.isub] + [imul $2 $1 @_ _.imul] + [idiv $2 $1 @_ _.idiv] + [irem $2 $1 @_ _.irem] + [ineg $1 $1 @_ _.ineg] + [iand $2 $1 @_ _.iand] + [ior $2 $1 @_ _.ior] + [ixor $2 $1 @_ _.ixor] + [ishl $2 $1 @_ _.ishl] + [ishr $2 $1 @_ _.ishr] + [iushr $2 $1 @_ _.iushr] + + [ladd $4 $2 @_ _.ladd] + [lsub $4 $2 @_ _.lsub] + [lmul $4 $2 @_ _.lmul] + [ldiv $4 $2 @_ _.ldiv] + [lrem $4 $2 @_ _.lrem] + [lneg $2 $2 @_ _.lneg] + [land $4 $2 @_ _.land] + [lor $4 $2 @_ _.lor] + [lxor $4 $2 @_ _.lxor] + [lshl $3 $2 @_ _.lshl] + [lshr $3 $2 @_ _.lshr] + [lushr $3 $2 @_ _.lushr] + + [fadd $2 $1 @_ _.fadd] + [fsub $2 $1 @_ _.fsub] + [fmul $2 $1 @_ _.fmul] + [fdiv $2 $1 @_ _.fdiv] + [frem $2 $1 @_ _.frem] + [fneg $1 $1 @_ _.fneg] + + [dadd $4 $2 @_ _.dadd] + [dsub $4 $2 @_ _.dsub] + [dmul $4 $2 @_ _.dmul] + [ddiv $4 $2 @_ _.ddiv] + [drem $4 $2 @_ _.drem] + [dneg $2 $2 @_ _.dneg] + + [l2i $2 $1 @_ _.l2i] + [l2f $2 $1 @_ _.l2f] + [l2d $2 $2 @_ _.l2d] + + [f2i $1 $1 @_ _.f2i] + [f2l $1 $2 @_ _.f2l] + [f2d $1 $2 @_ _.f2d] + + [d2i $2 $1 @_ _.d2i] + [d2l $2 $2 @_ _.d2l] + [d2f $2 $1 @_ _.d2f] + + [i2l $1 $2 @_ _.i2l] + [i2f $1 $1 @_ _.i2f] + [i2d $1 $2 @_ _.i2d] + [i2b $1 $1 @_ _.i2b] + [i2c $1 $1 @_ _.i2c] + [i2s $1 $1 @_ _.i2s] + + [lcmp $4 $1 @_ _.lcmp] + + [fcmpl $2 $1 @_ _.fcmpl] + [fcmpg $2 $1 @_ _.fcmpg] + + [dcmpl $4 $1 @_ _.dcmpl] + [dcmpg $4 $1 @_ _.dcmpg] + + [arraylength $1 $1 @_ _.arraylength] + + [monitorenter $1 $0 @_ _.monitorenter] + [monitorexit $1 $0 @_ _.monitorexit] + ) + +(def discontinuity! + (Bytecode Any) + (function (_ [pool environment tracker]) + (<| (try|do _ (/environment.stack environment)) + (try|in [[pool + (/environment.discontinue environment) + tracker] + [..relative#identity + []]])))) + +(with_template [ ] + [(def .public + (Bytecode Any) + (do ..monad + [_ (..bytecode $0 @_ [])] + ..discontinuity!))] + + [ireturn $1 _.ireturn] + [lreturn $2 _.lreturn] + [freturn $1 _.freturn] + [dreturn $2 _.dreturn] + [areturn $1 _.areturn] + [return $0 _.return] + + [athrow $1 _.athrow] + ) + +(def .public (bipush byte) + (-> S1 (Bytecode Any)) + (..bytecode $0 $1 @_ _.bipush [byte])) + +(def (lifted resource) + (All (_ a) + (-> (Resource a) + (Bytecode a))) + (function (_ [pool environment tracker]) + (<| (try|do [pool' output] (resource pool)) + (try|in [[pool' environment tracker] + [..relative#identity + output]])))) + +(def .public (string value) + (-> //constant.UTF8 (Bytecode Any)) + (do ..monad + [index (..lifted (//constant/pool.string value))] + (when (|> index //index.value //unsigned.value //unsigned.u1) + {try.#Success index} + (..bytecode $0 $1 @_ _.ldc [index]) + + {try.#Failure _} + (..bytecode $0 $1 @_ _.ldc_w/string [index])))) + +(import java/lang/Float + "[1]::[0]" + ("static" floatToRawIntBits "manual" [float] int)) + +(import java/lang/Double + "[1]::[0]" + ("static" doubleToRawLongBits "manual" [double] long)) + +(with_template [ ] + [(def .public ( value) + (-> (Bytecode Any)) + (when (|> value ) + (^.with_template [ ] + [ (..bytecode $0 $1 @_ [])]) + + + _ (do ..monad + [index (..lifted ( ( value)))] + (when (|> index //index.value //unsigned.value //unsigned.u1) + {try.#Success index} + (..bytecode $0 $1 @_ _.ldc [index]) + + {try.#Failure _} + (..bytecode $0 $1 @_ [index])))))] + + [int I32 //constant.integer //constant/pool.integer _.ldc_w/integer + (<| .int i32.i64) + ([-1 _.iconst_m1] + [+0 _.iconst_0] + [+1 _.iconst_1] + [+2 _.iconst_2] + [+3 _.iconst_3] + [+4 _.iconst_4] + [+5 _.iconst_5])] + ) + +(def (arbitrary_float value) + (-> java/lang/Float (Bytecode Any)) + (do ..monad + [index (..lifted (//constant/pool.float (//constant.float value)))] + (when (|> index //index.value //unsigned.value //unsigned.u1) + {try.#Success index} + (..bytecode $0 $1 @_ _.ldc [index]) + + {try.#Failure _} + (..bytecode $0 $1 @_ _.ldc_w/float [index])))) + +(def float_bits + (-> java/lang/Float Int) + (|>> java/lang/Float::floatToRawIntBits + ffi.int_to_long + (as Int))) + +(def negative_zero_float_bits + (|> -0.0 (as java/lang/Double) ffi.double_to_float ..float_bits)) + +(def .public (float value) + (-> java/lang/Float (Bytecode Any)) + (if (i.= ..negative_zero_float_bits + (..float_bits value)) + (..arbitrary_float value) + (when (|> value ffi.float_to_double (as Frac)) + (^.with_template [ ] + [ (..bytecode $0 $1 @_ [])]) + ([+0.0 _.fconst_0] + [+1.0 _.fconst_1] + [+2.0 _.fconst_2]) + + _ (..arbitrary_float value)))) + +(with_template [ ] + [(def .public ( value) + (-> (Bytecode Any)) + (when (|> value ) + (^.with_template [ ] + [ (..bytecode $0 $2 @_ [])]) + + + _ (do ..monad + [index (..lifted ( ( value)))] + (..bytecode $0 $2 @_ [index]))))] + + [long Int //constant.long //constant/pool.long _.ldc2_w/long + (<|) + ([+0 _.lconst_0] + [+1 _.lconst_1])] + ) + +(def (arbitrary_double value) + (-> java/lang/Double (Bytecode Any)) + (do ..monad + [index (..lifted (//constant/pool.double (//constant.double (as Frac value))))] + (..bytecode $0 $2 @_ _.ldc2_w/double [index]))) + +(def double_bits + (-> java/lang/Double Int) + (|>> java/lang/Double::doubleToRawLongBits + (as Int))) + +(def negative_zero_double_bits + (..double_bits (as java/lang/Double -0.0))) + +(def .public (double value) + (-> java/lang/Double (Bytecode Any)) + (if (i.= ..negative_zero_double_bits + (..double_bits value)) + (..arbitrary_double value) + (when (as Frac value) + (^.with_template [ ] + [ (..bytecode $0 $2 @_ [])]) + ([+0.0 _.dconst_0] + [+1.0 _.dconst_1]) + + _ (..arbitrary_double value)))) + +(exception.def .public (invalid_register id) + (exception.Exception Nat) + (exception.report + (list ["ID" (%.nat id)]))) + +(def (register id) + (-> Nat (Bytecode Register)) + (when (//unsigned.u1 id) + {try.#Success register} + (of ..monad in register) + + {try.#Failure error} + (..except ..invalid_register [id]))) + +(with_template [ ] + [(def .public ( local) + (-> Nat (Bytecode Any)) + (with_expansions [' (template.spliced )] + (`` (when local + (,, (with_template [ ] + [ (..bytecode $0 [])] + + ')) + _ (do ..monad + [local (..register local)] + (..bytecode $0 ( local) [local]))))))] + + [/registry.for $1 iload _.iload + [[0 _.iload_0 @0] + [1 _.iload_1 @1] + [2 _.iload_2 @2] + [3 _.iload_3 @3]]] + [/registry.for_wide $2 lload _.lload + [[0 _.lload_0 @1] + [1 _.lload_1 @2] + [2 _.lload_2 @3] + [3 _.lload_3 @4]]] + [/registry.for $1 fload _.fload + [[0 _.fload_0 @0] + [1 _.fload_1 @1] + [2 _.fload_2 @2] + [3 _.fload_3 @3]]] + [/registry.for_wide $2 dload _.dload + [[0 _.dload_0 @1] + [1 _.dload_1 @2] + [2 _.dload_2 @3] + [3 _.dload_3 @4]]] + [/registry.for $1 aload _.aload + [[0 _.aload_0 @0] + [1 _.aload_1 @1] + [2 _.aload_2 @2] + [3 _.aload_3 @3]]] + ) + +(with_template [ ] + [(def .public ( local) + (-> Nat (Bytecode Any)) + (with_expansions [' (template.spliced )] + (`` (when local + (,, (with_template [ ] + [ (..bytecode $0 [])] + + ')) + _ (do ..monad + [local (..register local)] + (..bytecode $0 ( local) [local]))))))] + + [/registry.for $1 istore _.istore + [[0 _.istore_0 @0] + [1 _.istore_1 @1] + [2 _.istore_2 @2] + [3 _.istore_3 @3]]] + [/registry.for_wide $2 lstore _.lstore + [[0 _.lstore_0 @1] + [1 _.lstore_1 @2] + [2 _.lstore_2 @3] + [3 _.lstore_3 @4]]] + [/registry.for $1 fstore _.fstore + [[0 _.fstore_0 @0] + [1 _.fstore_1 @1] + [2 _.fstore_2 @2] + [3 _.fstore_3 @3]]] + [/registry.for_wide $2 dstore _.dstore + [[0 _.dstore_0 @1] + [1 _.dstore_1 @2] + [2 _.dstore_2 @3] + [3 _.dstore_3 @4]]] + [/registry.for $1 astore _.astore + [[0 _.astore_0 @0] + [1 _.astore_1 @1] + [2 _.astore_2 @2] + [3 _.astore_3 @3]]] + ) + +(with_template [ ] + [(def .public + (-> (Bytecode Any)) + (..bytecode @_ ))] + + [$1 $1 newarray _.newarray Primitive_Array_Type] + [$0 $1 sipush _.sipush S2] + ) + +(exception.def .public (unknown_label label) + (exception.Exception Label) + (exception.report + (list ["Label" (%.nat label)]))) + +(exception.def .public (cannot_do_a_big_jump [label @from jump]) + (exception.Exception [Label Address Big_Jump]) + (exception.report + (list ["Label" (%.nat label)] + ["Start" (|> @from /address.value //unsigned.value %.nat)] + ["Target" (|> jump //signed.value %.int)]))) + +(type Any_Jump + (Either Big_Jump + Jump)) + +(def (jump @from @to) + (-> Address Address (Try Any_Jump)) + (<| (try|do jump (try#each //signed.value + (/address.jump @from @to))) + (let [big? (or (i.> (//signed.value //signed.maximum/2) + jump) + (i.< (//signed.value //signed.minimum/2) + jump))]) + (if big? + (try#each (|>> {.#Left}) (//signed.s4 jump)) + (try#each (|>> {.#Right}) (//signed.s2 jump))))) + +(exception.def .public (unset_label label) + (exception.Exception Label) + (exception.report + (list ["Label" (%.nat label)]))) + +(def (resolve_label label resolver) + (-> Label Resolver (Try [Stack Address])) + (when (dictionary.value label resolver) + {.#Some [actual {.#Some address}]} + {try.#Success [actual address]} + + {.#Some [actual {.#None}]} + (exception.except ..unset_label [label]) + + ... {.#None} + _ + (exception.except ..unknown_label [label]))) + +(def (acknowledge_label stack label tracker) + (-> Stack Label Tracker Tracker) + (when (dictionary.value label (the #known tracker)) + {.#Some _} + tracker + + ... {.#None} + _ + (revised #known (dictionary.has label [stack {.#None}]) tracker))) + +(with_template [ ] + [(def .public ( label) + (-> Label (Bytecode Any)) + (let [[estimator bytecode] ] + (function (_ [pool environment tracker]) + (<| (let [@here (the #program_counter tracker)]) + (try|do environment' (|> environment + (/environment.consumes ))) + (try|do actual (/environment.stack environment')) + (try|do program_counter' (step estimator @here)) + (try|in (let [@from @here] + [[pool + environment' + (|> tracker + (..acknowledge_label actual label) + (has #program_counter program_counter'))] + [(function (_ resolver) + (<| (try|do [expected @to] (..resolve_label label resolver)) + (try|do _ (exception.assertion ..mismatched_environments [(symbol ) label @here expected actual] + (of /stack.equivalence = expected actual))) + (try|do jump (..jump @from @to)) + (when jump + {.#Left jump} + (exception.except ..cannot_do_a_big_jump [label @from jump]) + + {.#Right jump} + (try|in [..no_exceptions (bytecode jump)])))) + []]]))))))] + + [$1 ifeq _.ifeq] + [$1 ifne _.ifne] + [$1 iflt _.iflt] + [$1 ifge _.ifge] + [$1 ifgt _.ifgt] + [$1 ifle _.ifle] + + [$1 ifnull _.ifnull] + [$1 ifnonnull _.ifnonnull] + + [$2 if_icmpeq _.if_icmpeq] + [$2 if_icmpne _.if_icmpne] + [$2 if_icmplt _.if_icmplt] + [$2 if_icmpge _.if_icmpge] + [$2 if_icmpgt _.if_icmpgt] + [$2 if_icmple _.if_icmple] + + [$2 if_acmpeq _.if_acmpeq] + [$2 if_acmpne _.if_acmpne] + ) + +(with_template [ ] + [(def .public ( label) + (-> Label (Bytecode Any)) + (let [[estimator bytecode] ] + (function (_ [pool environment tracker]) + (<| (try|do actual (/environment.stack environment)) + (let [@here (the #program_counter tracker)]) + (try|do program_counter' (step estimator @here)) + (try|in (let [@from @here] + [[pool + (/environment.discontinue environment) + (|> tracker + (..acknowledge_label actual label) + (has #program_counter program_counter'))] + [(function (_ resolver) + (when (dictionary.value label resolver) + {.#Some [expected {.#Some @to}]} + (<| (try|do _ (exception.assertion ..mismatched_environments [(symbol ) label @here expected actual] + (of /stack.equivalence = expected actual))) + (try|do jump (..jump @from @to)) + (when jump + {.#Left jump} + + + {.#Right jump} + )) + + {.#Some [expected {.#None}]} + (exception.except ..unset_label [label]) + + ... {.#None} + _ + (exception.except ..unknown_label [label]))) + []]]))))))] + + [goto _.goto + (exception.except ..cannot_do_a_big_jump [label @from jump]) + (try|in [..no_exceptions (bytecode jump)])] + [goto_w _.goto_w + (try|in [..no_exceptions (bytecode jump)]) + (try|in [..no_exceptions (bytecode (/jump.lifted jump))])] + ) + +(def (big_jump jump) + (-> Any_Jump Big_Jump) + (when jump + {.#Left big} + big + + {.#Right small} + (/jump.lifted small))) + +(exception.def .public invalid_tableswitch) + +(def .public (tableswitch minimum default [at_minimum afterwards]) + (-> S4 Label [Label (List Label)] (Bytecode Any)) + (let [[estimator bytecode] _.tableswitch] + (function (_ [pool environment tracker]) + (<| (try|do environment' (|> environment + (/environment.consumes $1))) + (try|do actual (/environment.stack environment')) + (try|do program_counter' (step (estimator (list.size afterwards)) (the #program_counter tracker))) + (try|in (let [@from (the #program_counter tracker)] + [[pool + environment' + (|> (list#mix (..acknowledge_label actual) tracker (list.partial default at_minimum afterwards)) + (has #program_counter program_counter'))] + [(function (_ resolver) + (let [get (is (-> Label (Maybe [Stack (Maybe Address)])) + (function (_ label) + (dictionary.value label resolver)))] + (when (do [! maybe.monad] + [@default (|> default get (monad.then ! product.right)) + @at_minimum (|> at_minimum get (monad.then ! product.right))] + (|> afterwards + (monad.each ! get) + (monad.then ! (monad.each ! product.right)) + (of ! each (|>> [@default @at_minimum])))) + {.#Some [@default @at_minimum @afterwards]} + (<| (try|do >default (try#each ..big_jump (..jump @from @default))) + (try|do >at_minimum (try#each ..big_jump (..jump @from @at_minimum))) + (try|do >afterwards (monad.each try.monad (|>> (..jump @from) (try#each ..big_jump)) + @afterwards)) + (try|in [..no_exceptions (bytecode minimum >default [>at_minimum >afterwards])])) + + ... {.#None} + _ + (exception.except ..invalid_tableswitch [])))) + []]])))))) + +(exception.def .public invalid_lookupswitch) + +(def .public (lookupswitch default cases) + (-> Label (List [S4 Label]) (Bytecode Any)) + (let [cases (list.sorted (function (_ [left _] [right _]) + (i.< (//signed.value left) + (//signed.value right))) + cases) + [estimator bytecode] _.lookupswitch] + (function (_ [pool environment tracker]) + (<| (try|do environment' (|> environment + (/environment.consumes $1))) + (try|do actual (/environment.stack environment')) + (try|do program_counter' (step (estimator (list.size cases)) (the #program_counter tracker))) + (try|in (let [@from (the #program_counter tracker)] + [[pool + environment' + (|> (list#mix (..acknowledge_label actual) tracker (list.partial default (list#each product.right cases))) + (has #program_counter program_counter'))] + [(function (_ resolver) + (let [get (is (-> Label (Maybe [Stack (Maybe Address)])) + (function (_ label) + (dictionary.value label resolver)))] + (when (do [! maybe.monad] + [@default (|> default get (monad.then ! product.right))] + (|> cases + (monad.each ! (|>> product.right get)) + (monad.then ! (monad.each ! product.right)) + (of ! each (|>> [@default])))) + {.#Some [@default @cases]} + (<| (try|do >default (try#each ..big_jump (..jump @from @default))) + (try|do >cases (|> @cases + (monad.each try.monad (|>> (..jump @from) (try#each ..big_jump))) + (try#each (|>> (list.zipped_2 (list#each product.left cases)))))) + (try|in [..no_exceptions (bytecode >default >cases)])) + + ... {.#None} + _ + (exception.except ..invalid_lookupswitch [])))) + []]])))))) + +(def reflection + (All (_ category) + (-> (Type (<| Return' Value' category)) Text)) + (|>> type.reflection reflection.reflection)) + +(with_template [ ] + [(def .public ( class) + (-> (Type ) (Bytecode Any)) + (do ..monad + [... TODO: Make sure it's impossible to have indexes greater than U2. + index (..lifted (//constant/pool.class (//name.internal (..reflection class))))] + (..bytecode @_ [index])))] + + [$0 $1 new Class _.new] + [$1 $1 anewarray Object _.anewarray] + [$1 $1 checkcast Object _.checkcast] + [$1 $1 instanceof Object _.instanceof] + ) + +(def .public (iinc register increase) + (-> Nat U1 (Bytecode Any)) + (do ..monad + [register (..register register)] + (..bytecode $0 $0 (/registry.for register) _.iinc [register increase]))) + +(exception.def .public (multiarray_cannot_be_zero_dimensional class) + (exception.Exception (Type Object)) + (exception.report + (list ["Class" (..reflection class)]))) + +(def .public (multianewarray class dimensions) + (-> (Type Object) U1 (Bytecode Any)) + (do ..monad + [_ (is (Bytecode Any) + (when (|> dimensions //unsigned.value) + 0 (..except ..multiarray_cannot_be_zero_dimensional [class]) + _ (in []))) + index (..lifted (//constant/pool.class (//name.internal (..reflection class))))] + (..bytecode (//unsigned.lifted/2 dimensions) $1 @_ _.multianewarray [index dimensions]))) + +(def (type_size type) + (-> (Type Return) Nat) + (cond (same? type.void type) + 0 + + (or (same? type.long type) + (same? type.double type)) + 2 + + ... else + 1)) + +(with_template [ ] + [(def .public ( class method type) + (-> (Type Class) Text (Type Method) (Bytecode Any)) + (let [[type_variables inputs output exceptions] (parser.method type)] + (do ..monad + [index (<| ..lifted + ( (..reflection class)) + [//constant/pool.#name method + //constant/pool.#descriptor (type.descriptor type)]) + .let [consumption (|> inputs + (list#each ..type_size) + (list#mix n.+ (if 0 1)) + //unsigned.u1 + try.trusted) + production (|> output ..type_size //unsigned.u1 try.trusted)]] + (..bytecode (//unsigned.lifted/2 consumption) + (//unsigned.lifted/2 production) + @_ + [index consumption production]))))] + + [#1 invokestatic _.invokestatic //constant/pool.method] + [#0 invokevirtual _.invokevirtual //constant/pool.method] + [#0 invokespecial _.invokespecial //constant/pool.method] + [#0 invokeinterface _.invokeinterface //constant/pool.interface_method] + ) + +(with_template [ <1> <2>] + [(def .public ( class field type) + (-> (Type Class) Text (Type Value) (Bytecode Any)) + (do ..monad + [index (<| ..lifted + (//constant/pool.field (..reflection class)) + [//constant/pool.#name field + //constant/pool.#descriptor (type.descriptor type)])] + (if (or (same? type.long type) + (same? type.double type)) + (..bytecode $2 @_ <2> [index]) + (..bytecode $1 @_ <1> [index]))))] + + [$0 getstatic _.getstatic/1 _.getstatic/2] + [$1 getfield _.getfield/1 _.getfield/2] + ) + +(with_template [ <1> <2>] + [(def .public ( class field type) + (-> (Type Class) Text (Type Value) (Bytecode Any)) + (do [! ..monad] + [index (<| ..lifted + (//constant/pool.field (..reflection class)) + [//constant/pool.#name field + //constant/pool.#descriptor (type.descriptor type)])] + (if (or (same? type.long type) + (same? type.double type)) + (..bytecode $0 @_ <2> [index]) + (..bytecode $0 @_ <1> [index]))))] + + [putstatic $1 _.putstatic/1 $2 _.putstatic/2] + [putfield $2 _.putfield/1 $3 _.putfield/2] + ) + +(exception.def .public (invalid_range_for_try [start end]) + (exception.Exception [Address Address]) + (exception.report + (list ["Start" (|> start /address.value //unsigned.value %.nat)] + ["End" (|> end /address.value //unsigned.value %.nat)]))) + +(def .public (try @start @end @handler catch) + (-> Label Label Label (Type Class) (Bytecode Any)) + (do ..monad + [@catch (..lifted (//constant/pool.class (//name.internal (..reflection catch))))] + (function (_ [pool environment tracker]) + {try.#Success + [[pool + environment + (..acknowledge_label /stack.catch @handler tracker)] + [(function (_ resolver) + (<| (try|do [_ @start] (..resolve_label @start resolver)) + (try|do [_ @end] (..resolve_label @end resolver)) + (try|do _ (if (/address.after? @start @end) + (try|in []) + (exception.except ..invalid_range_for_try [@start @end]))) + (try|do [_ @handler] (..resolve_label @handler resolver)) + (try|in [(sequence.sequence + [//exception.#start @start + //exception.#end @end + //exception.#handler @handler + //exception.#catch @catch]) + _.empty]))) + []]]}))) + +(def .public (composite pre post) + (All (_ pre post) + (-> (Bytecode pre) (Bytecode post) (Bytecode post))) + (function (_ state) + (when (pre state) + {try.#Success [state' [left _]]} + (when (post state') + {try.#Success [state'' [right it]]} + {try.#Success [state'' [(relative#composite left right) it]]} + + ... {try.#Failure error} + failure + failure) + + ... {try.#Failure error} + failure + (as_expected failure)))) + +(def .public (map line) + (-> Nat (Bytecode Any)) + (function (_ [pool environment tracker]) + (<| (let [instruction (/address.value (the #program_counter tracker))]) + (try|do line (//unsigned.u2 line)) + (try|in [[pool + environment + (revised #line_number_table + (sequence.suffix [line_number_table.#start_program_counter instruction + line_number_table.#line_number line]) + tracker)] + [..relative#identity + []]])))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/address.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/address.lux new file mode 100644 index 000000000..6bcb3655a --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/address.lux @@ -0,0 +1,75 @@ +(.require + [library + [lux (.except) + [abstract + [equivalence (.only Equivalence)] + [monad (.only do)]] + [control + ["[0]" try (.only Try)]] + [data + [binary + [\\format (.only Format)]] + [text + ["%" \\format]]] + [math + [number + ["n" nat]]] + [meta + [type + ["[0]" nominal (.except def)]]]]] + ["[0]" // + [jump (.only Big_Jump)] + ["/[1]" // + [encoding + ["[1][0]" unsigned (.only U2)] + ["[1][0]" signed (.only S4)]]]]) + +(nominal.def .public Address + U2 + + (def .public value + (-> Address U2) + (|>> representation)) + + (def .public start + Address + (|> 0 ///unsigned.u2 try.trusted abstraction)) + + (def .public (move distance) + (-> U2 (-> Address (Try Address))) + (|>> representation + (///unsigned.+/2 distance) + (of try.functor each (|>> abstraction)))) + + (def with_sign + (-> Address (Try S4)) + (|>> representation ///unsigned.value .int ///signed.s4)) + + (def .public (jump from to) + (-> Address Address (Try Big_Jump)) + (do try.monad + [from (with_sign from) + to (with_sign to)] + (///signed.-/4 from to))) + + (def .public (after? reference subject) + (-> Address Address Bit) + (n.> (|> reference representation ///unsigned.value) + (|> subject representation ///unsigned.value))) + + (def .public equivalence + (Equivalence Address) + (implementation + (def (= reference subject) + (of ///unsigned.equivalence = + (representation reference) + (representation subject))))) + + (def .public format + (Format Address) + (|>> representation ///unsigned.format/2)) + + (def .public text + (%.Format Address) + (|>> representation ///unsigned.value %.nat)) + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment.lux new file mode 100644 index 000000000..9fd4d7250 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment.lux @@ -0,0 +1,110 @@ +(.require + [library + [lux (.except Type static has) + [abstract + [monad (.only do)] + [monoid (.only Monoid)]] + [control + ["[0]" try (.only Try)] + ["[0]" exception (.only Exception)]]]] + [/ + ["/[0]" limit (.only Limit) + ["/[0]" stack (.only Stack)] + ["/[0]" registry (.only Registry)]] + [/// + [encoding + [unsigned (.only U2)]] + [type (.only Type) + [category (.only Method)]]]]) + +(type .public Environment + (Record + [#limit Limit + #stack (Maybe Stack)])) + +(with_template [ ] + [(def .public ( type) + (-> (Type Method) (Try Environment)) + (do try.monad + [limit ( type)] + (in [#limit limit + #stack {.#Some /stack.empty}])))] + + [static /limit.static] + [virtual /limit.virtual] + ) + +(type .public Condition + (-> Environment (Try Environment))) + +(def .public monoid + (Monoid Condition) + (implementation + (def identity + (|>> {try.#Success})) + + (def (composite left right) + (function (_ environment) + (do try.monad + [environment (left environment)] + (right environment)))))) + +(exception.def .public discontinuity) + +(def .public (stack environment) + (-> Environment (Try Stack)) + (when (the ..#stack environment) + {.#Some stack} + {try.#Success stack} + + {.#None} + (exception.except ..discontinuity []))) + +(def .public discontinue + (-> Environment Environment) + (.has ..#stack {.#None})) + +(exception.def .public (mismatched_stacks [expected actual]) + (Exception [Stack Stack]) + (exception.report + (list ["Expected" (/stack.text expected)] + ["Actual" (/stack.text actual)]))) + +(def .public (continue expected environment) + (-> Stack Environment (Try [Stack Environment])) + (when (the ..#stack environment) + {.#Some actual} + (if (of /stack.equivalence = expected actual) + {try.#Success [actual environment]} + (exception.except ..mismatched_stacks [expected actual])) + + {.#None} + {try.#Success [expected (.has ..#stack {.#Some expected} environment)]})) + +(def .public (consumes amount) + (-> U2 Condition) + ... TODO: Revisit this definition once lenses/optics have been implemented, + ... since it can probably be simplified with them. + (function (_ environment) + (do try.monad + [previous (..stack environment) + current (/stack.pop amount previous)] + (in (.has ..#stack {.#Some current} environment))))) + +(def .public (produces amount) + (-> U2 Condition) + (function (_ environment) + (do try.monad + [previous (..stack environment) + current (/stack.push amount previous) + .let [limit (|> environment + (the [..#limit /limit.#stack]) + (/stack.max current))]] + (in (|> environment + (.has ..#stack {.#Some current}) + (.has [..#limit /limit.#stack] limit)))))) + +(def .public (has registry) + (-> Registry Condition) + (|>> (revised [..#limit /limit.#registry] (/registry.has registry)) + {try.#Success})) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit.lux new file mode 100644 index 000000000..ce5801345 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit.lux @@ -0,0 +1,59 @@ +(.require + [library + [lux (.except Type static) + [abstract + [monad (.only do)] + [equivalence (.only Equivalence)]] + [control + ["[0]" try (.only Try)]] + [data + ["[0]" product] + [binary + ["[0]" \\format (.only Format) (.use "[1]#[0]" monoid)]]] + [math + [number + ["n" nat]]]]] + ["[0]" / + ["[1][0]" stack (.only Stack)] + ["[1][0]" registry (.only Registry)] + [//// + [type (.only Type) + [category (.only Method)]]]]) + +(type .public Limit + (Record + [#stack Stack + #registry Registry])) + +(with_template [ ] + [(def .public ( type) + (-> (Type Method) (Try Limit)) + (do try.monad + [registry ( type)] + (in [#stack /stack.empty + #registry registry])))] + + [static /registry.static] + [virtual /registry.virtual] + ) + +(def .public length + (all n.+ + ... u2 max_stack; + /stack.length + ... u2 max_locals; + /registry.length)) + +(def .public equivalence + (Equivalence Limit) + (all product.equivalence + /stack.equivalence + /registry.equivalence + )) + +(def .public (format limit) + (Format Limit) + (all \\format#composite + (/stack.format (the #stack limit)) + (/registry.format (the #registry limit)) + )) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit/registry.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit/registry.lux new file mode 100644 index 000000000..9737de12c --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit/registry.lux @@ -0,0 +1,93 @@ +(.require + [library + [lux (.except Type for static has) + [abstract + ["[0]" equivalence (.only Equivalence)]] + [control + ["[0]" try (.only Try) (.use "[1]#[0]" functor)]] + [data + [binary + [\\format (.only Format)]] + [collection + ["[0]" list (.use "[1]#[0]" functor mix)]]] + [math + [number + ["n" nat]]] + [meta + [type + ["[0]" nominal (.except def)]]]]] + ["[0]" ///// + [encoding + ["[1][0]" unsigned (.only U1 U2)]] + ["[1][0]" type (.only Type) + [category (.only Method)] + ["[1]/[0]" parser]]]) + +(type .public Register + U1) + +(def normal 1) +(def wide 2) + +(nominal.def .public Registry + U2 + + (def .public registry + (-> U2 Registry) + (|>> abstraction)) + + (def (minimal type) + (-> (Type Method) Nat) + (let [[type_variables inputs output exceptions] (/////type/parser.method type)] + (|> inputs + (list#each (function (_ input) + (if (or (same? /////type.long input) + (same? /////type.double input)) + ..wide + ..normal))) + (list#mix n.+ 0)))) + + (with_template [ ] + [(def .public + (-> (Type Method) (Try Registry)) + (|>> ..minimal + (n.+ ) + /////unsigned.u2 + (try#each ..registry)))] + + [0 static] + [1 virtual] + ) + + (def .public equivalence + (Equivalence Registry) + (of equivalence.functor each + (|>> representation) + /////unsigned.equivalence)) + + (def .public format + (Format Registry) + (|>> representation /////unsigned.format/2)) + + (def .public (has needed) + (-> Registry Registry Registry) + (|>> representation + (/////unsigned.max/2 (representation needed)) + abstraction)) + + (with_template [ ] + [(def .public + (-> Register Registry) + (let [extra (|> /////unsigned.u2 try.trusted)] + (|>> /////unsigned.lifted/2 + (/////unsigned.+/2 extra) + try.trusted + abstraction)))] + + [for ..normal] + [for_wide ..wide] + ) + ) + +(def .public length + /////unsigned.bytes/2) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit/stack.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit/stack.lux new file mode 100644 index 000000000..7517c2b60 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/environment/limit/stack.lux @@ -0,0 +1,70 @@ +(.require + [library + [lux (.except) + [abstract + ["[0]" equivalence (.only Equivalence)]] + [control + ["[0]" maybe] + ["[0]" try (.only Try)]] + [data + [text + ["%" \\format]] + [binary + [\\format (.only Format)]]] + [meta + [type + ["[0]" nominal (.except def)]]]]] + ["[0]" ///// + [encoding + ["[1][0]" unsigned (.only U2)]]]) + +(nominal.def .public Stack + U2 + + (with_template [ ] + [(def .public + Stack + (|> /////unsigned.u2 maybe.trusted abstraction))] + + [0 empty] + [1 catch] + ) + + (def .public equivalence + (Equivalence Stack) + (of equivalence.functor each + (|>> representation) + /////unsigned.equivalence)) + + (def .public format + (Format Stack) + (|>> representation /////unsigned.format/2)) + + (def stack + (-> U2 Stack) + (|>> abstraction)) + + (with_template [ ] + [(def .public ( amount) + (-> U2 (-> Stack (Try Stack))) + (|>> representation + ( amount) + (of try.functor each ..stack)))] + + [/////unsigned.+/2 push] + [/////unsigned.-/2 pop] + ) + + (def .public (max left right) + (-> Stack Stack Stack) + (abstraction + (/////unsigned.max/2 (representation left) + (representation right)))) + + (def .public text + (%.Format Stack) + (|>> representation /////unsigned.value %.nat)) + ) + +(def .public length + /////unsigned.bytes/2) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/instruction.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/instruction.lux new file mode 100644 index 000000000..d8a6963ae --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/instruction.lux @@ -0,0 +1,704 @@ +(.require + [library + [lux (.except) + [ffi (.only)] + [abstract + [monad (.only do)] + [monoid (.only Monoid)]] + [control + ["[0]" function] + ["[0]" try]] + [data + ["[0]" product] + ["[0]" binary + [/ (.only)] + ["[1]" \\unsafe] + ["[0]" \\format (.only Mutation Specification)]] + [collection + ["[0]" list]]] + [math + [number (.only hex) + ["n" nat]]] + [meta + [macro + ["[0]" template]] + [type + ["[0]" nominal (.except def)]]]]] + ["[0]" // + ["[1][0]" address (.only Address)] + ["[1][0]" jump (.only Jump Big_Jump)] + [environment + [limit + [registry (.only Register)]]] + ["/[1]" // + ["[1][0]" index (.only Index)] + ["[1][0]" constant (.only Class Reference)] + [encoding + ["[1][0]" unsigned (.only U1 U2 U4)] + ["[1][0]" signed (.only S1 S2 S4)]] + [type + [category (.only Value Method)]]]]) + +(type .public Size + U2) + +(type .public Estimator + (-> Address Size)) + +(def fixed + (-> Size Estimator) + function.constant) + +(type .public Instruction + (-> Specification Specification)) + +(def .public empty + Instruction + function.identity) + +(def .public result + (-> Instruction Specification) + (function.on \\format.no_op)) + +(type Opcode + Nat) + +(with_template [ ] + [(def Size (|> ///unsigned.u2 try.trusted))] + + [1 opcode_size] + [1 register_size] + [1 byte_size] + [2 index_size] + [4 big_jump_size] + [4 integer_size] + ) + +(def (nullary' opcode) + (-> Opcode Mutation) + (function (_ [offset binary]) + [(n.+ (///unsigned.value ..opcode_size) + offset) + (binary.has_8! offset opcode binary)])) + +(def nullary + [Estimator (-> Opcode Instruction)] + [(..fixed ..opcode_size) + (function (_ opcode [size mutation]) + [(n.+ (///unsigned.value ..opcode_size) + size) + (|>> mutation ((nullary' opcode)))])]) + +(with_template [ ] + [(def + Size + (|> ..opcode_size + (///unsigned.+/2 ) + try.trusted))] + + [size/1 ..register_size] + [size/2 ..index_size] + [size/4 ..big_jump_size] + ) + +(with_template [ ] + [(with_expansions [ (template.symbol ["'" ])] + (def ( opcode input0) + (-> Opcode Mutation) + (function (_ [offset binary]) + [(n.+ (///unsigned.value ) offset) + (|> binary + (binary.has_8! offset opcode) + ( (n.+ (///unsigned.value ..opcode_size) offset) + ( input0)))])) + + (def + [Estimator (-> Opcode Instruction)] + [(..fixed ) + (function (_ opcode input0 [size mutation]) + [(n.+ (///unsigned.value ) size) + (|>> mutation (( opcode input0)))])]))] + + [..size/1 unary/1 U1 binary.has_8! ///unsigned.value] + [..size/2 unary/2 U2 binary.has_16! ///unsigned.value] + [..size/2 jump/2 Jump binary.has_16! ///signed.value] + [..size/4 jump/4 Big_Jump binary.has_32! ///signed.value] + ) + +(with_template [ ] + [(with_expansions [ (template.symbol ["'" ])] + (def ( opcode input0) + (-> Opcode Mutation) + (function (_ [offset binary]) + [(n.+ (///unsigned.value ) offset) + (|> binary + (binary.has_8! offset opcode) + ( (n.+ (///unsigned.value ..opcode_size) offset) + (///signed.value input0)))])) + + (def + [Estimator (-> Opcode Instruction)] + [(..fixed ) + (function (_ opcode input0 [size mutation]) + [(n.+ (///unsigned.value ) size) + (|>> mutation (( opcode input0)))])]))] + + [..size/1 unary/1' S1 binary.has_8!] + [..size/2 unary/2' S2 binary.has_16!] + ) + +(def size/11 + Size + (|> ..opcode_size + (///unsigned.+/2 ..register_size) try.trusted + (///unsigned.+/2 ..byte_size) try.trusted)) + +(def (binary/11' opcode input0 input1) + (-> Opcode U1 U1 Mutation) + (function (_ [offset binary]) + [(n.+ (///unsigned.value ..size/11) offset) + (|> binary + (binary.has_8! offset opcode) + (binary.has_8! (n.+ (///unsigned.value ..opcode_size) offset) + (///unsigned.value input0)) + (binary.has_8! (n.+ (///unsigned.value ..size/1) offset) + (///unsigned.value input1)))])) + +(def binary/11 + [Estimator (-> Opcode U1 U1 Instruction)] + [(..fixed ..size/11) + (function (_ opcode input0 input1 [size mutation]) + [(n.+ (///unsigned.value ..size/11) size) + (|>> mutation ((binary/11' opcode input0 input1)))])]) + +(def size/21 + Size + (|> ..opcode_size + (///unsigned.+/2 ..index_size) try.trusted + (///unsigned.+/2 ..byte_size) try.trusted)) + +(def (binary/21' opcode input0 input1) + (-> Opcode U2 U1 Mutation) + (function (_ [offset binary]) + [(n.+ (///unsigned.value ..size/21) offset) + (|> binary + (binary.has_8! offset opcode) + (binary.has_16! (n.+ (///unsigned.value ..opcode_size) offset) + (///unsigned.value input0)) + (binary.has_8! (n.+ (///unsigned.value ..size/2) offset) + (///unsigned.value input1)))])) + +(def binary/21 + [Estimator (-> Opcode U2 U1 Instruction)] + [(..fixed ..size/21) + (function (_ opcode input0 input1 [size mutation]) + [(n.+ (///unsigned.value ..size/21) size) + (|>> mutation ((binary/21' opcode input0 input1)))])]) + +(def size/211 + Size + (|> ..opcode_size + (///unsigned.+/2 ..index_size) try.trusted + (///unsigned.+/2 ..byte_size) try.trusted + (///unsigned.+/2 ..byte_size) try.trusted)) + +(def (trinary/211' opcode input0 input1 input2) + (-> Opcode U2 U1 U1 Mutation) + (function (_ [offset binary]) + [(n.+ (///unsigned.value ..size/211) offset) + (|> binary + (binary.has_8! offset opcode) + (binary.has_16! (n.+ (///unsigned.value ..opcode_size) offset) + (///unsigned.value input0)) + (binary.has_8! (n.+ (///unsigned.value ..size/2) offset) + (///unsigned.value input1)) + (binary.has_8! (n.+ (///unsigned.value ..size/21) offset) + (///unsigned.value input2)))])) + +(def trinary/211 + [Estimator (-> Opcode U2 U1 U1 Instruction)] + [(..fixed ..size/211) + (function (_ opcode input0 input1 input2 [size mutation]) + [(n.+ (///unsigned.value ..size/211) size) + (|>> mutation ((trinary/211' opcode input0 input1 input2)))])]) + +(nominal.def .public Primitive_Array_Type + U1 + + (def code + (-> Primitive_Array_Type U1) + (|>> representation)) + + (with_template [ ] + [(def .public + (|> ///unsigned.u1 try.trusted abstraction))] + + [04 t_boolean] + [05 t_char] + [06 t_float] + [07 t_double] + [08 t_byte] + [09 t_short] + [10 t_int] + [11 t_long] + )) + +... https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5 +(with_expansions [ (with_template [ ] + [[ [] []]] + + ["01" aconst_null] + + ["02" iconst_m1] + ["03" iconst_0] + ["04" iconst_1] + ["05" iconst_2] + ["06" iconst_3] + ["07" iconst_4] + ["08" iconst_5] + + ["09" lconst_0] + ["0A" lconst_1] + + ["0B" fconst_0] + ["0C" fconst_1] + ["0D" fconst_2] + + ["0E" dconst_0] + ["0F" dconst_1]) + (with_template [ ] + [[ [[register Register]] [register]]] + + ["15" iload] + ["16" lload] + ["17" fload] + ["18" dload] + ["19" aload]) + (with_template [ ] + [[ [] []]] + + ["1A" iload_0] + ["1B" iload_1] + ["1C" iload_2] + ["1D" iload_3] + + ["1E" lload_0] + ["1F" lload_1] + ["20" lload_2] + ["21" lload_3] + + ["22" fload_0] + ["23" fload_1] + ["24" fload_2] + ["25" fload_3] + + ["26" dload_0] + ["27" dload_1] + ["28" dload_2] + ["29" dload_3] + + ["2A" aload_0] + ["2B" aload_1] + ["2C" aload_2] + ["2D" aload_3]) + (with_template [ ] + [[ [[register Register]] [register]]] + + ["36" istore] + ["37" lstore] + ["38" fstore] + ["39" dstore] + ["3A" astore]) + (with_template [ ] + [[ [] []]] + + ["3B" istore_0] + ["3C" istore_1] + ["3D" istore_2] + ["3E" istore_3] + + ["3F" lstore_0] + ["40" lstore_1] + ["41" lstore_2] + ["42" lstore_3] + + ["43" fstore_0] + ["44" fstore_1] + ["45" fstore_2] + ["46" fstore_3] + + ["47" dstore_0] + ["48" dstore_1] + ["49" dstore_2] + ["4A" dstore_3] + + ["4B" astore_0] + ["4C" astore_1] + ["4D" astore_2] + ["4E" astore_3]) + (with_template [ ] + [[ [] []]] + + ["2E" iaload] + ["2F" laload] + ["30" faload] + ["31" daload] + ["32" aaload] + ["33" baload] + ["34" caload] + ["35" saload]) + (with_template [ ] + [[ [] []]] + + ["4f" iastore] + ["50" lastore] + ["51" fastore] + ["52" dastore] + ["53" aastore] + ["54" bastore] + ["55" castore] + ["56" sastore]) + (with_template [ ] + [[ [] []]] + + ["60" iadd] + ["64" isub] + ["68" imul] + ["6c" idiv] + ["70" irem] + ["74" ineg] + ["78" ishl] + ["7a" ishr] + ["7c" iushr] + ["7e" iand] + ["80" ior] + ["82" ixor] + + ["61" ladd] + ["65" lsub] + ["69" lmul] + ["6D" ldiv] + ["71" lrem] + ["75" lneg] + ["7F" land] + ["81" lor] + ["83" lxor] + + ["62" fadd] + ["66" fsub] + ["6A" fmul] + ["6E" fdiv] + ["72" frem] + ["76" fneg] + + ["63" dadd] + ["67" dsub] + ["6B" dmul] + ["6F" ddiv] + ["73" drem] + ["77" dneg]) + (with_template [ ] + [[ [] []]] + + ["88" l2i] + ["89" l2f] + ["8A" l2d] + + ["8B" f2i] + ["8C" f2l] + ["8D" f2d] + + ["8E" d2i] + ["8F" d2l] + ["90" d2f] + + ["85" i2l] + ["86" i2f] + ["87" i2d] + ["91" i2b] + ["92" i2c] + ["93" i2s]) + (with_template [ ] + [[ [] []]] + + ["94" lcmp] + + ["95" fcmpl] + ["96" fcmpg] + + ["97" dcmpl] + ["98" dcmpg]) + (with_template [ ] + [[ [] []]] + + ["AC" ireturn] + ["AD" lreturn] + ["AE" freturn] + ["AF" dreturn] + ["B0" areturn] + ["B1" return] + ) + (with_template [ ] + [[ [[jump Jump]] [jump]]] + + ["99" ifeq] + ["9A" ifne] + ["9B" iflt] + ["9C" ifge] + ["9D" ifgt] + ["9E" ifle] + + ["9F" if_icmpeq] + ["A0" if_icmpne] + ["A1" if_icmplt] + ["A2" if_icmpge] + ["A3" if_icmpgt] + ["A4" if_icmple] + + ["A5" if_acmpeq] + ["A6" if_acmpne] + + ["A7" goto] + ["A8" jsr] + + ["C6" ifnull] + ["C7" ifnonnull]) + (with_template [ ] + [[ [[index (Index (Reference Value))]] [(///index.value index)]]] + + ["B2" getstatic/1] ["B2" getstatic/2] + ["B3" putstatic/1] ["B3" putstatic/2] + ["B4" getfield/1] ["B4" getfield/2] + ["B5" putfield/1] ["B5" putfield/2])] + (with_template [ ] + [(with_expansions [' (template.spliced )] + (with_template [ ] + [(with_expansions [' (template.spliced ) + (with_template [ ] + [] + + ') + (with_template [ ] + [] + + ')] + (def .public + [Estimator (-> [] Instruction)] + (let [[estimator '] ] + [estimator + (function (_ []) + (`` (' (hex ) (,, (template.spliced )))))])))] + + ' + ))] + + [..nullary + [["00" nop [] []] + + ["57" pop [] []] + ["58" pop2 [] []] + ["59" dup [] []] + ["5A" dup_x1 [] []] + ["5B" dup_x2 [] []] + ["5C" dup2 [] []] + ["5D" dup2_x1 [] []] + ["5E" dup2_x2 [] []] + ["5F" swap [] []] + + + + + + ["79" lshl [] []] + ["7B" lshr [] []] + ["7D" lushr [] []] + + + + ["BE" arraylength [] []] + ["BF" athrow [] []] + ["C2" monitorenter [] []] + ["C3" monitorexit [] []]]] + + [..unary/1 + [["12" ldc [[index U1]] [index]] + + + ["A9" ret [[register Register]] [register]] + ["BC" newarray [[type Primitive_Array_Type]] [(..code type)]]]] + + [..unary/1' + [["10" bipush [[byte S1]] [byte]]]] + + [..unary/2 + [["13" ldc_w/integer [[index (Index ///constant.Integer)]] [(///index.value index)]] + ["13" ldc_w/float [[index (Index ///constant.Float)]] [(///index.value index)]] + ["13" ldc_w/string [[index (Index ///constant.String)]] [(///index.value index)]] + ["14" ldc2_w/long [[index (Index ///constant.Long)]] [(///index.value index)]] + ["14" ldc2_w/double [[index (Index ///constant.Double)]] [(///index.value index)]] + + ["BB" new [[index (Index Class)]] [(///index.value index)]] + ["BD" anewarray [[index (Index Class)]] [(///index.value index)]] + ["C0" checkcast [[index (Index Class)]] [(///index.value index)]] + ["C1" instanceof [[index (Index Class)]] [(///index.value index)]] + ["B6" invokevirtual [[index (Index (Reference Method))] [count U1] [output_count U1]] [(///index.value index)]] + ["B7" invokespecial [[index (Index (Reference Method))] [count U1] [output_count U1]] [(///index.value index)]] + ["B8" invokestatic [[index (Index (Reference Method))] [count U1] [output_count U1]] [(///index.value index)]]]] + + [..unary/2' + [["11" sipush [[short S2]] [short]]]] + + [..jump/2 + []] + + [..jump/4 + [["C8" goto_w [[jump Big_Jump]] [jump]] + ["C9" jsr_w [[jump Big_Jump]] [jump]]]] + + [..binary/11 + [["84" iinc [[register Register] [byte U1]] [register byte]]]] + + [..binary/21 + [["C5" multianewarray [[index (Index Class)] [count U1]] [(///index.value index) count]]]] + + [..trinary/211 + [["B9" invokeinterface [[index (Index (Reference Method))] [count U1] [output_count U1]] [(///index.value index) count (try.trusted (///unsigned.u1 0))]]]] + )) + +(def (switch_padding offset) + (-> Nat Nat) + (let [parameter_start (n.+ (///unsigned.value ..opcode_size) + offset)] + (n.% 4 + (n.- (n.% 4 parameter_start) + 4)))) + +(def .public tableswitch + [(-> Nat Estimator) + (-> S4 Big_Jump [Big_Jump (List Big_Jump)] Instruction)] + (let [estimator (is (-> Nat Estimator) + (function (_ amount_of_afterwards offset) + (|> (all n.+ + (///unsigned.value ..opcode_size) + (switch_padding (///unsigned.value (//address.value offset))) + (///unsigned.value ..big_jump_size) + (///unsigned.value ..integer_size) + (///unsigned.value ..integer_size) + (n.* (///unsigned.value ..big_jump_size) + (++ amount_of_afterwards))) + ///unsigned.u2 + try.trusted)))] + [estimator + (function (_ minimum default [at_minimum afterwards]) + (let [amount_of_afterwards (list.size afterwards) + estimator (estimator amount_of_afterwards)] + (function (_ [size mutation]) + (let [padding (switch_padding size) + tableswitch_size (try.trusted + (do [! try.monad] + [size (///unsigned.u2 size)] + (of ! each (|>> estimator ///unsigned.value) + (//address.move size //address.start)))) + tableswitch_mutation (is Mutation + (function (_ [offset binary]) + [(n.+ tableswitch_size offset) + (try.trusted + (do [! try.monad] + [amount_of_afterwards (|> amount_of_afterwards .int ///signed.s4) + maximum (///signed.+/4 minimum amount_of_afterwards)] + (in (let [_ (binary.has_8! offset (hex "AA") binary) + offset (n.+ (///unsigned.value ..opcode_size) offset) + _ (when padding + 3 (|> binary + (binary.has_8! offset 0) + (binary.has_16! (++ offset) 0)) + 2 (binary.has_16! offset 0 binary) + 1 (binary.has_8! offset 0 binary) + _ binary) + offset (n.+ padding offset) + _ (binary.has_32! offset (///signed.value default) binary) + offset (n.+ (///unsigned.value ..big_jump_size) offset) + _ (binary.has_32! offset (///signed.value minimum) binary) + offset (n.+ (///unsigned.value ..integer_size) offset) + _ (binary.has_32! offset (///signed.value maximum) binary)] + (loop (again [offset (n.+ (///unsigned.value ..integer_size) offset) + afterwards (is (List Big_Jump) + {.#Item at_minimum afterwards})]) + (when afterwards + {.#End} + binary + + {.#Item head tail} + (exec + (binary.has_32! offset (///signed.value head) binary) + (again (n.+ (///unsigned.value ..big_jump_size) offset) + tail))))))))]))] + [(n.+ tableswitch_size + size) + (|>> mutation tableswitch_mutation)]))))])) + +(def .public lookupswitch + [(-> Nat Estimator) + (-> Big_Jump (List [S4 Big_Jump]) Instruction)] + (let [case_size (n.+ (///unsigned.value ..integer_size) + (///unsigned.value ..big_jump_size)) + estimator (is (-> Nat Estimator) + (function (_ amount_of_cases offset) + (|> (all n.+ + (///unsigned.value ..opcode_size) + (switch_padding (///unsigned.value (//address.value offset))) + (///unsigned.value ..big_jump_size) + (///unsigned.value ..integer_size) + (n.* amount_of_cases case_size)) + ///unsigned.u2 + try.trusted)))] + [estimator + (function (_ default cases) + (let [amount_of_cases (list.size cases) + estimator (estimator amount_of_cases)] + (function (_ [size mutation]) + (let [padding (switch_padding size) + lookupswitch_size (try.trusted + (do [! try.monad] + [size (///unsigned.u2 size)] + (of ! each (|>> estimator ///unsigned.value) + (//address.move size //address.start)))) + lookupswitch_mutation (is Mutation + (function (_ [offset binary]) + [(n.+ lookupswitch_size offset) + (let [_ (binary.has_8! offset (hex "AB") binary) + offset (n.+ (///unsigned.value ..opcode_size) offset) + _ (when padding + 3 (|> binary + (binary.has_8! offset 0) + (binary.has_16! (++ offset) 0)) + 2 (binary.has_16! offset 0 binary) + 1 (binary.has_8! offset 0 binary) + _ binary) + offset (n.+ padding offset) + _ (binary.has_32! offset (///signed.value default) binary) + offset (n.+ (///unsigned.value ..big_jump_size) offset) + _ (binary.has_32! offset amount_of_cases binary)] + (loop (again [offset (n.+ (///unsigned.value ..integer_size) offset) + cases cases]) + (when cases + {.#End} + binary + + {.#Item [value jump] tail} + (exec + (binary.has_32! offset (///signed.value value) binary) + (binary.has_32! (n.+ (///unsigned.value ..integer_size) offset) (///signed.value jump) binary) + (again (n.+ case_size offset) + tail)))))]))] + [(n.+ lookupswitch_size + size) + (|>> mutation lookupswitch_mutation)]))))])) + +(def .public monoid + (Monoid Instruction) + (implementation + (def identity ..empty) + + (def (composite left right) + (|>> left right)))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/jump.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/jump.lux new file mode 100644 index 000000000..13c5f8f07 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/jump.lux @@ -0,0 +1,29 @@ +(.require + [library + [lux (.except) + [abstract + [equivalence (.only Equivalence)]] + [data + [binary + [\\format (.only Format)]]]]] + ["[0]" /// + [encoding + ["[1][0]" signed (.only S2 S4)]]]) + +(type .public Jump + S2) + +(def .public equivalence + (Equivalence Jump) + ///signed.equivalence) + +(def .public format + (Format Jump) + ///signed.format/2) + +(type .public Big_Jump + S4) + +(def .public lifted + (-> Jump Big_Jump) + ///signed.lifted/4) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/class.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/class.lux new file mode 100644 index 000000000..5ffb48007 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/class.lux @@ -0,0 +1,152 @@ +(.require + [library + [lux (.except Type public private) + [abstract + [equivalence (.only Equivalence)] + ["[0]" monad (.only do)]] + [control + ["[0]" state] + ["[0]" try (.only Try)]] + [data + ["[0]" product] + ["[0]" binary + ["[1]F" \\format (.only Format) (.use "[1]#[0]" monoid)]] + [collection + ["[0]" sequence (.only Sequence)]]]]] + ["[0]" // + ["[1][0]" modifier (.only Modifier modifiers)] + ["[1][0]" version (.only Version Minor Major)] + ["[1][0]" magic (.only Magic)] + ["[1][0]" index (.only Index)] + ["[1][0]" attribute (.only Attribute)] + ["[1][0]" field (.only Field)] + ["[1][0]" method (.only Method)] + [encoding + ["[1][0]" unsigned] + ["[1][0]" name (.only Internal)]] + ["[1][0]" type (.only Type) + [category (.only Inheritance)] + ["[2][0]" signature (.only Signature)]] + ["[1][0]" constant (.only Constant) + ["[2][0]" pool (.only Pool Resource)]]]) + +(type .public Class + (Rec Class + (Record + [#magic Magic + #minor_version Minor + #major_version Major + #constant_pool Pool + #modifier (Modifier Class) + #this (Index //constant.Class) + #super (Index //constant.Class) + #interfaces (Sequence (Index //constant.Class)) + #fields (Sequence Field) + #methods (Sequence Method) + #attributes (Sequence Attribute)]))) + +(modifiers + Class + ["0001" public] + ["0010" final] + ["0020" super] + ["0200" interface] + ["0400" abstract] + ["1000" synthetic] + ["2000" annotation] + ["4000" enum] + ) + +(def .public equivalence + (Equivalence Class) + (all product.equivalence + //unsigned.equivalence + //unsigned.equivalence + //unsigned.equivalence + //pool.equivalence + //modifier.equivalence + //index.equivalence + //index.equivalence + (sequence.equivalence //index.equivalence) + (sequence.equivalence //field.equivalence) + (sequence.equivalence //method.equivalence) + (sequence.equivalence //attribute.equivalence))) + +(def (install_classes this super interfaces) + (-> Internal Internal (List Internal) + (Resource [(Index //constant.Class) (Index //constant.Class) (Sequence (Index //constant.Class))])) + (do [! //pool.monad] + [@this (//pool.class this) + @super (//pool.class super) + @interfaces (is (Resource (Sequence (Index //constant.Class))) + (monad.mix ! (function (_ interface @interfaces) + (do ! + [@interface (//pool.class interface)] + (in (sequence.suffix @interface @interfaces)))) + sequence.empty + interfaces))] + (in [@this @super @interfaces]))) + +(def .public (class version modifier + this signature super interfaces + fields methods attributes) + (-> Major (Modifier Class) + Internal (Maybe (Signature Inheritance)) Internal (List Internal) + (List (Resource Field)) + (List (Resource Method)) + (List (Resource Attribute)) + (Try Class)) + (do try.monad + [[pool [@this @super @interfaces] fields methods attributes @signature] + (<| (state.result' //pool.empty) + (do [! //pool.monad] + [classes (install_classes this super interfaces) + fields (monad.all ! fields) + methods (monad.all ! methods) + attributes (monad.all ! attributes) + @signature (when signature + {.#Some signature} + (of ! each (|>> {.#Some}) (//attribute.signature signature)) + + {.#None} + (in {.#None}))] + (in [classes fields methods attributes @signature])))] + (in [#magic //magic.code + #minor_version //version.default_minor + #major_version version + #constant_pool pool + #modifier modifier + #this @this + #super @super + #interfaces @interfaces + #fields (sequence.of_list fields) + #methods (sequence.of_list methods) + #attributes (sequence.of_list (when @signature + {.#Some @signature} + {.#Item @signature attributes} + + {.#None} + attributes))]))) + +(def .public (format class) + (Format Class) + (`` (all binaryF#composite + (,, (with_template [ ] + [( (the class))] + + [//magic.format #magic] + [//version.format #minor_version] + [//version.format #major_version] + [//pool.format #constant_pool] + [//modifier.format #modifier] + [//index.format #this] + [//index.format #super])) + (,, (with_template [ ] + [((binaryF.sequence_16 ) (the class))] + + [//index.format #interfaces] + [//field.format #fields] + [//method.format #methods] + [//attribute.format #attributes] + )) + ))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/constant.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/constant.lux new file mode 100644 index 000000000..f5cdd6cf8 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/constant.lux @@ -0,0 +1,251 @@ +(.require + [library + [lux (.except Double) + ["[0]" ffi (.only import)] + [abstract + [monad (.only do)] + ["[0]" equivalence (.only Equivalence)]] + [data + ["[0]" sum] + ["[0]" product] + ["[0]" text] + ["[0]" binary + ["[1]F" \\format (.only Format) (.use "[1]#[0]" monoid)]]] + [math + [number + ["[0]" i32 (.only I32)] + ["[0]" i64] + ["[0]" int] + ["[0]" frac]]] + [meta + [macro + ["^" pattern] + ["[0]" template]] + [type + ["[0]" nominal (.except def #name)]] + [compiler + ["@" target]]]]] + ["[0]" / + ["[1][0]" tag] + ["/[1]" // + ["[1][0]" index (.only Index)] + [type + ["[1][0]" category] + ["[1][0]" descriptor (.only Descriptor)]] + [encoding + ["[1][0]" unsigned]]]]) + +(type .public UTF8 + Text) + +(def utf8_format + (Format UTF8) + binaryF.utf8_16) + +(nominal.def .public Class + (Index UTF8) + + (def .public index + (-> Class (Index UTF8)) + (|>> representation)) + + (def .public class + (-> (Index UTF8) Class) + (|>> abstraction)) + + (def .public class_equivalence + (Equivalence Class) + (of equivalence.functor each + ..index + //index.equivalence)) + + (def class_format + (Format Class) + (|>> representation //index.format)) + ) + +(import java/lang/Float + "[1]::[0]" + ("static" floatToRawIntBits "manual" [float] int)) + +(def .public float_equivalence + (Equivalence java/lang/Float) + (implementation + (def (= parameter subject) + (for @.old + ("jvm feq" parameter subject) + + @.jvm + (.jvm_float_=# (.jvm_object_cast# parameter) + (.jvm_object_cast# subject)))))) + +(import java/lang/Double + "[1]::[0]" + ("static" doubleToRawLongBits [double] long)) + +(nominal.def .public (Value kind) + kind + + (def .public value + (All (_ kind) (-> (Value kind) kind)) + (|>> representation)) + + (def .public (value_equivalence Equivalence) + (All (_ kind) + (-> (Equivalence kind) + (Equivalence (Value kind)))) + (of equivalence.functor each + (|>> representation) + Equivalence)) + + (with_template [ ] + [(type .public + (Value )) + + (def .public + (-> ) + (|>> abstraction))] + + [integer Integer I32] + [float Float java/lang/Float] + [long Long .Int] + [double Double Frac] + [string String (Index UTF8)] + ) + + (with_template [ ] + [(def + (Format ) + (`` (|>> representation + (,, (template.spliced )) + (,, (template.spliced )))))] + + [integer_format Integer [] [binaryF.bits_32]] + [float_format Float [java/lang/Float::floatToRawIntBits ffi.of_int .i64] [i32.i32 binaryF.bits_32]] + [long_format Long [] [binaryF.bits_64]] + [double_format Double [java/lang/Double::doubleToRawLongBits ffi.of_long] [binaryF.bits_64]] + [string_format String [] [//index.format]] + ) + ) + +(type .public (Name_And_Type of) + (Record + [#name (Index UTF8) + #descriptor (Index (Descriptor of))])) + +(type .public (Reference of) + (Record + [#class (Index Class) + #name_and_type (Index (Name_And_Type of))])) + +(with_template [ ] + [(def .public + (Equivalence ( Any)) + (all product.equivalence + //index.equivalence + //index.equivalence)) + + (def + (Format ( Any)) + (all binaryF.and + //index.format + //index.format))] + + [Name_And_Type name_and_type_equivalence name_and_type_format] + [Reference reference_equivalence reference_format] + ) + +(type .public Constant + (Variant + {#UTF8 UTF8} + {#Integer Integer} + {#Float Float} + {#Long Long} + {#Double Double} + {#Class Class} + {#String String} + {#Field (Reference //category.Value)} + {#Method (Reference //category.Method)} + {#Interface_Method (Reference //category.Method)} + {#Name_And_Type (Name_And_Type Any)})) + +(def .public (size constant) + (-> Constant Nat) + (when constant + (^.or {#Long _} {#Double _}) + 2 + + _ + 1)) + +(def .public equivalence + (Equivalence Constant) + ... TODO: Delete the explicit "implementation" and use the combinator + ... version below as soon as the new format for variants is implemented. + (implementation + (def (= reference sample) + (when [reference sample] + (^.with_template [ ] + [[{ reference} { sample}] + (of = reference sample)]) + ([#UTF8 text.equivalence] + [#Integer (..value_equivalence i32.equivalence)] + [#Long (..value_equivalence int.equivalence)] + [#Float (..value_equivalence float_equivalence)] + [#Double (..value_equivalence frac.equivalence)] + [#Class ..class_equivalence] + [#String (..value_equivalence //index.equivalence)] + [#Field ..reference_equivalence] + [#Method ..reference_equivalence] + [#Interface_Method ..reference_equivalence] + [#Name_And_Type ..name_and_type_equivalence]) + + _ + false))) + ... (all sum.equivalence + ... ... #UTF8 + ... text.equivalence + ... ... #Long + ... (..value_equivalence int.equivalence) + ... ... #Double + ... (..value_equivalence frac.equivalence) + ... ... #Class + ... ..class_equivalence + ... ... #String + ... (..value_equivalence //index.equivalence) + ... ... #Field + ... ..reference_equivalence + ... ... #Method + ... ..reference_equivalence + ... ... #Interface_Method + ... ..reference_equivalence + ... ... #Name_And_Type + ... ..name_and_type_equivalence + ... ) + ) + +(def .public format + (Format Constant) + (with_expansions [ (these [#UTF8 /tag.utf8 ..utf8_format] + [#Integer /tag.integer ..integer_format] + [#Float /tag.float ..float_format] + [#Long /tag.long ..long_format] + [#Double /tag.double ..double_format] + [#Class /tag.class ..class_format] + [#String /tag.string ..string_format] + [#Field /tag.field ..reference_format] + [#Method /tag.method ..reference_format] + [#Interface_Method /tag.interface_method ..reference_format] + [#Name_And_Type /tag.name_and_type ..name_and_type_format] + ... TODO: Method_Handle + ... TODO: Method_Type + ... TODO: Invoke_Dynamic + )] + (function (_ value) + (when value + (^.with_template [ ] + [{ value} + (binaryF#composite (/tag.format ) + ( value))]) + () + )))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/constant/pool.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/pool.lux new file mode 100644 index 000000000..46adfd870 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/pool.lux @@ -0,0 +1,217 @@ +(.require + [library + [lux (.except Double) + ["[0]" ffi] + [abstract + [equivalence (.only Equivalence)] + [functor (.only Functor)] + [monad (.only Monad do)]] + [control + ["[0]" pipe] + ["[0]" state (.only +State)] + ["[0]" try (.only Try)]] + [data + ["[0]" product] + ["[0]" text] + [binary + ["[0]" \\format (.only Format) (.use "specification#[0]" monoid)]] + [collection + ["[0]" sequence (.only Sequence) (.use "[1]#[0]" mix)]]] + [math + [number + ["[0]" int] + ["[0]" frac] + ["[0]" i32]]]]] + ["[0]" // (.only UTF8 String Class Integer Float Long Double Constant Name_And_Type Reference) + [// + ["[1][0]" index (.only Index)] + [encoding + ["[1][0]" name (.only Internal External)] + ["[1][0]" unsigned]] + [type + [category (.only Value Method)] + ["[1][0]" descriptor (.only Descriptor)]]]]) + +(type .public Pool + [Index (Sequence [Index Constant])]) + +(def .public equivalence + (Equivalence Pool) + (product.equivalence //index.equivalence + (sequence.equivalence (product.equivalence //index.equivalence + //.equivalence)))) + +(type .public (Resource a) + (+State Try Pool a)) + +(def .public functor + (Functor Resource) + (implementation + (def (each $ it) + (|>> it + (pipe.when + {try.#Success [state output]} + {try.#Success [state ($ output)]} + + ... {try.#Failure error} + failure + (as_expected failure)))))) + +(def .public monad + (Monad Resource) + (implementation + (def functor ..functor) + + (def (in it) + (function (_ state) + {try.#Success [state it]})) + + (def (conjoint it) + (function (_ state) + (when (it state) + {try.#Success [state' it']} + (it' state') + + ... {try.#Failure error} + failure + (as_expected failure)))))) + +(def try|each + (template (_ ) + [(when + {try.#Success } + + + ... {try.#Failure error} + failure + (as_expected failure))])) + +(def try|in + (template (_ ) + [{try.#Success }])) + +(def !add + (template (_ ) + [(let [[current pool] + ' ] + (with_expansions [ (these (again (.++ idx)))] + (loop (again [idx 0]) + (when (sequence.item idx pool) + {try.#Success entry} + (when entry + [index { reference}] + (if (of = reference ') + {try.#Success [[current pool] + index]} + ) + + _ + ) + + {try.#Failure _} + (<| (let [new { '}]) + (try|each @new (//unsigned.u2 (//.size new))) + (try|each next (is (Try Index) + (|> current + //index.value + (//unsigned.+/2 @new) + (of try.monad each //index.index)))) + (try|in [[next + (sequence.suffix [current new] pool)] + current]))))))])) + +(def /|do + (template (_ ) + [(function (_ ) + )])) + +(def /|each + (template (_ ) + [(when ( ) + {try.#Success [ ]} + + + ... {try.#Failure error} + failure + (as_expected failure))])) + +(type (Adder of) + (-> of (Resource (Index of)))) + +(with_template [ ] + [(def .public ( value) + (Adder ) + (<| (/|do %) + (!add % value)))] + + [integer Integer //.#Integer (//.value_equivalence i32.equivalence)] + [float Float //.#Float (//.value_equivalence //.float_equivalence)] + [long Long //.#Long (//.value_equivalence int.equivalence)] + [double Double //.#Double (//.value_equivalence frac.equivalence)] + [utf8 UTF8 //.#UTF8 text.equivalence] + ) + +(def .public (string value) + (-> Text (Resource (Index String))) + (<| (/|do %) + (/|each % @value (utf8 value)) + (let [value (//.string @value)]) + (!add % //.#String (//.value_equivalence //index.equivalence) value))) + +(def .public (class name) + (-> Internal (Resource (Index Class))) + (<| (/|do %) + (/|each % @name (utf8 (//name.read name))) + (let [value (//.class @name)]) + (!add % //.#Class //.class_equivalence value))) + +(def .public (descriptor value) + (All (_ kind) + (-> (Descriptor kind) + (Resource (Index (Descriptor kind))))) + (<| (let [value (//descriptor.descriptor value)]) + (/|do %) + (!add % //.#UTF8 text.equivalence value))) + +(type .public (Member of) + (Record + [#name UTF8 + #descriptor (Descriptor of)])) + +(def .public (name_and_type [name descriptor]) + (All (_ of) + (-> (Member of) (Resource (Index (Name_And_Type of))))) + (<| (/|do %) + (/|each % @name (utf8 name)) + (/|each % @descriptor (..descriptor descriptor)) + (!add % //.#Name_And_Type //.name_and_type_equivalence [//.#name @name //.#descriptor @descriptor]))) + +(with_template [ ] + [(def .public ( class member) + (-> External (Member ) (Resource (Index (Reference )))) + (<| (/|do %) + (/|each % @class (..class (//name.internal class))) + (/|each % @name_and_type (name_and_type member)) + (!add % //.reference_equivalence [//.#class @class //.#name_and_type @name_and_type])))] + + [field //.#Field Value] + [method //.#Method Method] + [interface_method //.#Interface_Method Method] + ) + +(def !index + (template (_ ) + [(|> //index.value //unsigned.value)])) + +(def .public format + (Format Pool) + (function (_ [next pool]) + (sequence#mix (function (_ [_index post] pre) + (specification#composite pre (//.format post))) + (\\format.bits_16 (!index next)) + pool))) + +(def .public empty + Pool + [(|> 1 //unsigned.u2 try.trusted //index.index) + sequence.empty]) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/constant/tag.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/tag.lux new file mode 100644 index 000000000..66a66f48a --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/tag.lux @@ -0,0 +1,52 @@ +(.require + [library + [lux (.except Tag) + [abstract + [equivalence (.only Equivalence)]] + [control + ["[0]" try]] + [data + [binary + [\\format (.only Format)]]] + [meta + [type + ["[0]" nominal (.except def)]]]]] + ["[0]" /// + [encoding + ["[1][0]" unsigned (.only U1) (.use "u1//[0]" equivalence)]]]) + +(nominal.def .public Tag + U1 + + (def .public equivalence + (Equivalence Tag) + (implementation + (def (= reference sample) + (u1//= (representation reference) + (representation sample))))) + + (with_template [ ] + [(def .public + Tag + (|> ///unsigned.u1 try.trusted abstraction))] + + [01 utf8] + [03 integer] + [04 float] + [05 long] + [06 double] + [07 class] + [08 string] + [09 field] + [10 method] + [11 interface_method] + [12 name_and_type] + [15 method_handle] + [16 method_type] + [18 invoke_dynamic] + ) + + (def .public format + (Format Tag) + (|>> representation ///unsigned.format/1)) + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/encoding/name.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/encoding/name.lux new file mode 100644 index 000000000..108ad8752 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/encoding/name.lux @@ -0,0 +1,42 @@ +(.require + [library + [lux (.except) + [data + ["[0]" text (.only) + ["%" \\format (.only format)]]] + [meta + [type + ["[0]" nominal (.except def)]]]]]) + +(def .public internal_separator "/") +(def .public external_separator ".") + +(type .public External + Text) + +(nominal.def .public Internal + Text + + (def .public internal + (-> External Internal) + (|>> (text.replaced ..external_separator + ..internal_separator) + abstraction)) + + (def .public read + (-> Internal Text) + (|>> representation)) + + (def .public external + (-> Internal External) + (|>> representation + (text.replaced ..internal_separator + ..external_separator)))) + +(def .public safe + (-> Text External) + (|>> ..internal ..external)) + +(def .public (qualify package class) + (-> Text External External) + (format (..safe package) ..external_separator class)) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/encoding/signed.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/encoding/signed.lux new file mode 100644 index 000000000..428f5ef8a --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/encoding/signed.lux @@ -0,0 +1,114 @@ +(.require + [library + [lux (.except int) + [abstract + [equivalence (.only Equivalence)] + [order (.only Order)]] + [control + ["[0]" try (.only Try)] + ["[0]" exception (.only Exception)]] + [data + [text + ["%" \\format (.only format)]] + [binary + ["[0]" \\format (.only Format)]]] + [math + [number + ["[0]" i64] + ["n" nat] + ["i" int]]] + [meta + [macro + ["[0]" template]] + [type + ["[0]" nominal (.except def)]]]]]) + +(nominal.def .public (Signed brand) + Int + + (def .public value + (-> (Signed Any) Int) + (|>> representation)) + + (def .public equivalence + (All (_ brand) (Equivalence (Signed brand))) + (implementation + (def (= reference sample) + (i.= (representation reference) (representation sample))))) + + (def .public order + (All (_ brand) (Order (Signed brand))) + (implementation + (def equivalence ..equivalence) + (def (< reference sample) + (i.< (representation reference) (representation sample))))) + + (exception.def .public (value_exceeds_the_scope [value scope]) + (Exception [Int Nat]) + (exception.report + (list ["Value" (%.int value)] + ["Scope (in bytes)" (%.nat scope)]))) + + (with_template [ <+> <->] + [(with_expansions [ (template.symbol [ "'"])] + (nominal.def Any) + (type .public (Signed ))) + + (def .public ) + + (def .public + + (|> (n.* i64.bits_per_byte) -- i64.mask abstraction)) + + (def .public + + (let [it (representation )] + (abstraction (-- (i.- it +0))))) + + (def .public + (-> Int (Try )) + (let [positive (representation ) + negative (i64.not positive)] + (function (_ value) + (if (i.= (if (i.< +0 value) + (i64.or negative value) + (i64.and positive value)) + value) + {try.#Success (abstraction value)} + (exception.except ..value_exceeds_the_scope [value ]))))) + + (with_template [ ] + [(def .public ( parameter subject) + (-> (Try )) + ( + ( (representation parameter) + (representation subject))))] + + [<+> i.+] + [<-> i.-] + )] + + [1 S1 bytes/1 s1 maximum/1 minimum/1 +/1 -/1] + [2 S2 bytes/2 s2 maximum/2 minimum/2 +/2 -/2] + [4 S4 bytes/4 s4 maximum/4 minimum/4 +/4 -/4] + ) + + (with_template [ ] + [(def .public + (-> ) + (|>> transmutation))] + + [lifted/2 S1 S2] + [lifted/4 S2 S4] + ) + + (with_template [ ] + [(def .public + (Format ) + (|>> representation ))] + + [format/1 S1 \\format.bits_8] + [format/2 S2 \\format.bits_16] + [format/4 S4 \\format.bits_32] + ) + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/encoding/unsigned.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/encoding/unsigned.lux new file mode 100644 index 000000000..afd21a166 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/encoding/unsigned.lux @@ -0,0 +1,120 @@ +(.require + [library + [lux (.except nat) + [abstract + [equivalence (.only Equivalence)] + [order (.only Order)]] + [control + ["[0]" try (.only Try)] + ["[0]" exception (.only Exception)]] + [data + [text + ["%" \\format (.only format)]] + [binary + ["[0]" \\format (.only Format)]]] + [math + [number + ["n" nat] + ["[0]" i64]]] + [meta + [macro + ["[0]" template]] + [type + ["[0]" nominal (.except def)]]]]]) + +(nominal.def .public (Unsigned brand) + Nat + + (def .public value + (-> (Unsigned Any) Nat) + (|>> representation)) + + (def .public equivalence + (All (_ brand) (Equivalence (Unsigned brand))) + (implementation + (def (= reference sample) + (n.= (representation reference) + (representation sample))))) + + (def .public order + (All (_ brand) (Order (Unsigned brand))) + (implementation + (def equivalence ..equivalence) + (def (< reference sample) + (n.< (representation reference) + (representation sample))))) + + (exception.def .public (value_exceeds_the_maximum [type value maximum]) + (Exception [Symbol Nat (Unsigned Any)]) + (exception.report + (list ["Type" (%.symbol type)] + ["Value" (%.nat value)] + ["Maximum" (%.nat (representation maximum))]))) + + (exception.def .public (subtraction_cannot_yield_negative_value [type parameter subject]) + (All (_ brand) (Exception [Symbol (Unsigned brand) (Unsigned brand)])) + (exception.report + (list ["Type" (%.symbol type)] + ["Parameter" (%.nat (representation parameter))] + ["Subject" (%.nat (representation subject))]))) + + (with_template [ <+> <-> ] + [(with_expansions [ (template.symbol [ "'"])] + (nominal.def .public Any) + (type .public (Unsigned ))) + + (def .public ) + + (def .public + + (|> (n.* i64.bits_per_byte) i64.mask abstraction)) + + (def .public ( value) + (-> Nat (Try )) + (if (n.> (representation ) value) + (exception.except ..value_exceeds_the_maximum [(symbol ) value ]) + {try.#Success (abstraction value)})) + + (def .public (<+> parameter subject) + (-> (Try )) + ( + (n.+ (representation parameter) + (representation subject)))) + + (def .public (<-> parameter subject) + (-> (Try )) + (let [parameter' (representation parameter) + subject' (representation subject)] + (if (n.> subject' parameter') + (exception.except ..subtraction_cannot_yield_negative_value [(symbol ) parameter subject]) + {try.#Success (abstraction (n.- parameter' subject'))}))) + + (def .public ( left right) + (-> ) + (abstraction (n.max (representation left) + (representation right))))] + + [1 U1 bytes/1 u1 maximum/1 +/1 -/1 max/1] + [2 U2 bytes/2 u2 maximum/2 +/2 -/2 max/2] + [4 U4 bytes/4 u4 maximum/4 +/4 -/4 max/4] + ) + + (with_template [ ] + [(def .public + (-> ) + (|>> transmutation))] + + [lifted/2 U1 U2] + [lifted/4 U2 U4] + ) + + (with_template [ ] + [(def .public + (Format ) + (|>> representation ))] + + [format/1 U1 \\format.bits_8] + [format/2 U2 \\format.bits_16] + [format/4 U4 \\format.bits_32] + ) + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/field.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/field.lux new file mode 100644 index 000000000..443d34f16 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/field.lux @@ -0,0 +1,81 @@ +(.require + [library + [lux (.except Type static public private) + [abstract + [equivalence (.only Equivalence)] + ["[0]" monad (.only do)]] + [data + ["[0]" product] + ["[0]" binary + ["[1]F" \\format (.only Format) (.use "[1]#[0]" monoid)]] + [collection + ["[0]" sequence (.only Sequence)]]]]] + ["[0]" // + ["[0]" modifier (.only Modifier modifiers)] + ["[1][0]" constant (.only UTF8) + ["[1]/[0]" pool (.only Pool Resource)]] + ["[1][0]" index (.only Index)] + ["[1][0]" attribute (.only Attribute)] + ["[1][0]" type (.only Type) + [category (.only Value)] + [descriptor (.only Descriptor)]]]) + +(type .public Field + (Rec Field + (Record + [#modifier (Modifier Field) + #name (Index UTF8) + #descriptor (Index (Descriptor Value)) + #attributes (Sequence Attribute)]))) + +(modifiers + Field + ["0001" public] + ["0002" private] + ["0004" protected] + ["0008" static] + ["0010" final] + ["0040" volatile] + ["0080" transient] + ["1000" synthetic] + ["4000" enum] + ) + +(def .public equivalence + (Equivalence Field) + (all product.equivalence + modifier.equivalence + //index.equivalence + //index.equivalence + (sequence.equivalence //attribute.equivalence))) + +(def .public (format field) + (Format Field) + (`` (all binaryF#composite + (,, (with_template [ ] + [( (the field))] + + [modifier.format #modifier] + [//index.format #name] + [//index.format #descriptor] + [(binaryF.sequence_16 //attribute.format) #attributes])) + ))) + +(def .public (field modifier name with_signature? type attributes) + (-> (Modifier Field) UTF8 Bit (Type Value) (Sequence Attribute) + (Resource Field)) + (do [! //constant/pool.monad] + [@name (//constant/pool.utf8 name) + @descriptor (//constant/pool.descriptor (//type.descriptor type)) + @signature (if with_signature? + (of ! each (|>> {.#Some}) (//attribute.signature (//type.signature type))) + (in {.#None}))] + (in [#modifier modifier + #name @name + #descriptor @descriptor + #attributes (when @signature + {.#Some @signature} + (sequence.suffix @signature attributes) + + {.#None} + attributes)]))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/index.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/index.lux new file mode 100644 index 000000000..522684c1c --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/index.lux @@ -0,0 +1,39 @@ +(.require + [library + [lux (.except) + [abstract + ["[0]" equivalence (.only Equivalence)]] + [data + [binary + [\\format (.only Format)]]] + [meta + [type + ["[0]" nominal (.except def)]]]]] + ["[0]" // + [encoding + ["[1][0]" unsigned (.only U2)]]]) + +(def .public length + //unsigned.bytes/2) + +(nominal.def .public (Index kind) + U2 + + (def .public index + (All (_ kind) (-> U2 (Index kind))) + (|>> abstraction)) + + (def .public value + (-> (Index Any) U2) + (|>> representation)) + + (def .public equivalence + (All (_ kind) (Equivalence (Index kind))) + (of equivalence.functor each + ..value + //unsigned.equivalence)) + + (def .public format + (All (_ kind) (Format (Index kind))) + (|>> representation //unsigned.format/2)) + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/loader.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/loader.lux new file mode 100644 index 000000000..70c85cc93 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/loader.lux @@ -0,0 +1,148 @@ +(.require + [library + [lux (.except) + ["[0]" ffi (.only import object to)] + [abstract + [monad (.only do)]] + [control + ["[0]" try (.only Try)] + ["[0]" exception (.only Exception)] + ["[0]" io (.only IO)] + [concurrency + ["[0]" atom (.only Atom)]]] + [data + ["[0]" binary (.only Binary)] + ["[0]" text (.only) + ["%" \\format (.only format)]] + [collection + ["[0]" array] + ["[0]" dictionary (.only Dictionary)]]] + [meta + [compiler + ["@" target]]]]]) + +(type .public Library + (Atom (Dictionary Text Binary))) + +(exception.def .public (already_stored class) + (Exception Text) + (exception.report + (list ["Class" class]))) + +(exception.def .public (unknown class) + (Exception Text) + (exception.report + (list ["Class" class]))) + +(exception.def .public (cannot_define [class error]) + (Exception [Text Text]) + (exception.report + (list ["Class" class] + ["Error" error]))) + +(import java/lang/Object + "[1]::[0]" + (getClass [] (java/lang/Class java/lang/Object))) + +(import java/lang/String + "[1]::[0]") + +(import java/lang/reflect/Method + "[1]::[0]" + (invoke [java/lang/Object [java/lang/Object]] "try" java/lang/Object)) + +(import (java/lang/Class a) + "[1]::[0]" + (getDeclaredMethod [java/lang/String [(java/lang/Class [? < java/lang/Object])]] java/lang/reflect/Method)) + +(import java/lang/Integer + "[1]::[0]" + ("read_only" "static" TYPE (java/lang/Class java/lang/Integer))) + +(import java/lang/reflect/AccessibleObject + "[1]::[0]" + (setAccessible [boolean] void)) + +(import java/lang/ClassLoader + "[1]::[0]" + (loadClass [java/lang/String] + "io" "try" (java/lang/Class java/lang/Object))) + +(with_expansions [ (these (java/lang/Class java/lang/Object))] + (def java/lang/ClassLoader::defineClass + java/lang/reflect/Method + (let [signature (|> (ffi.array 4) + (ffi.write! 0 (as + (ffi.class_for java/lang/String))) + (ffi.write! 1 (java/lang/Object::getClass (ffi.array byte 0))) + (ffi.write! 2 (as + (java/lang/Integer::TYPE))) + (ffi.write! 3 (as + (java/lang/Integer::TYPE))))] + (to (java/lang/Class::getDeclaredMethod (ffi.as_string "defineClass") + signature + (ffi.class_for java/lang/ClassLoader)) + (java/lang/reflect/AccessibleObject::setAccessible true))))) + +(def .public (define class_name bytecode loader) + (-> Text Binary java/lang/ClassLoader (Try java/lang/Object)) + (let [signature (array.of_list (list (as java/lang/Object + class_name) + (as java/lang/Object + bytecode) + (as java/lang/Object + (|> 0 + (as (Nominal "java.lang.Long")) + ffi.long_to_int)) + (as java/lang/Object + (|> bytecode + binary.size + (as (Nominal "java.lang.Long")) + ffi.long_to_int))))] + (java/lang/reflect/Method::invoke loader signature java/lang/ClassLoader::defineClass))) + +(def .public (new_library _) + (-> Any Library) + (atom.atom (dictionary.empty text.hash))) + +(def .public (memory library) + (-> Library java/lang/ClassLoader) + (with_expansions [ (for @.old + (<|) + + @.jvm + .jvm_object_cast#)] + (<| + (object [] java/lang/ClassLoader [] + [] + (java/lang/ClassLoader (findClass self [class_name java/lang/String]) + (java/lang/Class [? < java/lang/Object]) + "throws" [java/lang/ClassNotFoundException] + (let [class_name (as Text class_name) + classes (|> library atom.read! io.run!)] + (when (dictionary.value class_name classes) + {.#Some bytecode} + (when (..define class_name bytecode (<| self)) + {try.#Success class} + (as_expected class) + + {try.#Failure error} + (panic! (exception.error ..cannot_define [class_name error]))) + + {.#None} + (panic! (exception.error ..unknown [class_name]))))))))) + +(def .public (store name bytecode library) + (-> Text Binary Library (IO (Try Any))) + (do [! io.monad] + [library' (atom.read! library)] + (if (dictionary.key? library' name) + (in (exception.except ..already_stored name)) + (do ! + [_ (atom.update! (dictionary.has name bytecode) library)] + (in {try.#Success []}))))) + +(def .public (load name loader) + (-> Text java/lang/ClassLoader + (IO (Try (java/lang/Class java/lang/Object)))) + (java/lang/ClassLoader::loadClass (ffi.as_string name) loader)) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/magic.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/magic.lux new file mode 100644 index 000000000..e5fc0a09d --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/magic.lux @@ -0,0 +1,22 @@ +(.require + [library + [lux (.except) + [control + ["[0]" try]] + [math + [number (.only hex)]]]] + ["[0]" // + [encoding + ["[1][0]" unsigned (.only U4)]]]) + +(type .public Magic + U4) + +(def .public code + Magic + (|> (hex "CAFEBABE") + //unsigned.u4 + try.trusted)) + +(def .public format + //unsigned.format/4) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/method.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/method.lux new file mode 100644 index 000000000..a4689017a --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/method.lux @@ -0,0 +1,118 @@ +(.require + [library + [lux (.except Type static public private) + [abstract + [equivalence (.only Equivalence)] + ["[0]" monad (.only do)]] + [control + ["[0]" try]] + [data + ["[0]" product] + [binary + ["[0]" \\format (.only Format) (.use "[1]#[0]" monoid)]] + [collection + ["[0]" sequence (.only Sequence)] + ["[0]" list]]]]] + ["[0]" // + ["[1][0]" modifier (.only Modifier modifiers)] + ["[1][0]" index (.only Index)] + ["[1][0]" attribute (.only Attribute) + ["[2][0]" code]] + ["[1][0]" constant (.only UTF8) + ["[2][0]" pool (.only Pool Resource)]] + ["[1][0]" bytecode (.only Bytecode) + ["[2][0]" environment (.only Environment)] + ["[2][0]" instruction]] + ["[1][0]" type (.only Type) + [descriptor (.only Descriptor)] + ["[2][0]" category] + ["[2][0]" signature (.only Signature)]]]) + +(type .public Method + (Rec Method + (Record + [#modifier (Modifier Method) + #name (Index UTF8) + #descriptor (Index (Descriptor //category.Method)) + #attributes (Sequence Attribute)]))) + +(modifiers + Method + ["0001" public] + ["0002" private] + ["0004" protected] + ["0008" static] + ["0010" final] + ["0020" synchronized] + ["0040" bridge] + ["0080" var_args] + ["0100" native] + ["0400" abstract] + ["0800" strict] + ["1000" synthetic] + ) + +(def .public (method modifier name with_signature? type attributes code) + (-> (Modifier Method) UTF8 Bit (Type //category.Method) (List (Resource Attribute)) (Maybe (Bytecode Any)) + (Resource Method)) + (do [! //pool.monad] + [@name (//pool.utf8 name) + @descriptor (//pool.descriptor (//type.descriptor type)) + attributes (|> (if with_signature? + (list.partial (//attribute.signature (//type.signature type)) attributes) + attributes) + (monad.all !) + (of ! each sequence.of_list)) + attributes (when code + {.#Some code} + (do ! + [environment (when (if (//modifier.has? static modifier) + (//environment.static type) + (//environment.virtual type)) + {try.#Success environment} + (in environment) + + {try.#Failure error} + (function (_ _) + {try.#Failure error})) + [environment line_number_table exceptions instruction output] (//bytecode.resolve environment code) + .let [bytecode (|> instruction //instruction.result \\format.instance)] + code_attributes (is (Resource (Sequence Attribute)) + (if (sequence.empty? line_number_table) + (in sequence.empty) + (do ! + [@line_number_table (//attribute.line_number_table line_number_table)] + (in (sequence.sequence @line_number_table))))) + @code (//attribute.code [//code.#limit (the //environment.#limit environment) + //code.#code bytecode + //code.#exception_table exceptions + //code.#attributes code_attributes])] + (in (sequence.suffix @code attributes))) + + {.#None} + (in attributes))] + (in [#modifier modifier + #name @name + #descriptor @descriptor + #attributes attributes]))) + +(def .public equivalence + (Equivalence Method) + (all product.equivalence + //modifier.equivalence + //index.equivalence + //index.equivalence + (sequence.equivalence //attribute.equivalence) + )) + +(def .public (format field) + (Format Method) + (`` (all \\format#composite + (,, (with_template [ ] + [( (the field))] + + [//modifier.format #modifier] + [//index.format #name] + [//index.format #descriptor] + [(\\format.sequence_16 //attribute.format) #attributes])) + ))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/modifier.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/modifier.lux new file mode 100644 index 000000000..59359f103 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/modifier.lux @@ -0,0 +1,93 @@ +(.require + [library + [lux (.except) + [abstract + ["[0]" equivalence (.only Equivalence)] + ["[0]" monoid (.only Monoid)]] + [control + ["<>" parser] + ["[0]" try]] + [data + ["[0]" binary + ["[1]F" \\format (.only Format)]]] + [math + ["[0]" number (.only hex) + ["[0]" i64]]] + [meta + ["[0]" code (.only) + ["<[1]>" \\parser]] + [macro (.only with_symbols) + [syntax (.only syntax)]] + [type + ["[0]" nominal (.except def)]]]]] + ["[0]" // + [encoding + ["[1][0]" unsigned]]]) + +(nominal.def .public (Modifier of) + //unsigned.U2 + + (def .public code + (-> (Modifier Any) //unsigned.U2) + (|>> representation)) + + (def .public equivalence + (All (_ of) (Equivalence (Modifier of))) + (implementation + (def (= reference sample) + (of //unsigned.equivalence = + (representation reference) + (representation sample))))) + + (def !abstraction + (template (_ value) + [(|> value + //unsigned.u2 + try.trusted + abstraction)])) + + (def !representation + (template (_ value) + [(|> value + representation + //unsigned.value)])) + + (def .public (has? sub super) + (All (_ of) (-> (Modifier of) (Modifier of) Bit)) + (let [sub (!representation sub)] + (|> (!representation super) + (i64.and sub) + (of i64.equivalence = sub)))) + + (def .public monoid + (All (_ of) (Monoid (Modifier of))) + (implementation + (def identity + (!abstraction (hex "0000"))) + + (def (composite left right) + (!abstraction (i64.or (!representation left) + (!representation right)))))) + + (def .public empty + Modifier + (of ..monoid identity)) + + (def .public format + (All (_ of) (Format (Modifier of))) + (|>> representation //unsigned.format/2)) + ) + +(def .public modifiers + (syntax (_ [ofT .any + options (<>.many .any)]) + (with_symbols [g!modifier g!code] + (in (list (` (with_template [(, g!code) (, g!modifier)] + [(def (,' .public) (, g!modifier) + (..Modifier (, ofT)) + (|> (number.hex (, g!code)) + //unsigned.u2 + try.trusted + as_expected))] + + (,* options)))))))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/modifier/inner.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/modifier/inner.lux new file mode 100644 index 000000000..6a2a188fe --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/modifier/inner.lux @@ -0,0 +1,23 @@ +(.require + [library + [lux (.except static) + [meta + [type + ["[0]" nominal (.except def)]]]]] + [// (.only modifiers)]) + +(nominal.def .public Inner Any) + +(modifiers + Inner + ["0001" public] + ["0002" private] + ["0004" protected] + ["0008" static] + ["0010" final] + ["0200" interface] + ["0400" abstract] + ["1000" synthetic] + ["2000" annotation] + ["4000" enum] + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/reflection.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/reflection.lux new file mode 100644 index 000000000..d62ce7c3f --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/reflection.lux @@ -0,0 +1,385 @@ +(.require + [library + [lux (.except parameter type) + ["[0]" ffi (.only import)] + [abstract + ["[0]" monad (.only do)]] + [control + ["[0]" try (.only Try) (.use "[1]#[0]" functor)] + ["[0]" exception (.only Exception)]] + [data + ["[0]" text (.use "[1]#[0]" equivalence) + ["%" \\format (.only format)] + ["" \\parser]] + [collection + ["[0]" list (.use "[1]#[0]" mix functor)] + ["[0]" array] + ["[0]" dictionary]]] + [math + [number + ["n" nat]]] + [meta + ["[0]" type] + [macro + ["^" pattern]]]]] + ["[0]" // + [encoding + ["[1][0]" name (.only External)]] + ["/" type (.only) + [category (.only Void Value Return Method Primitive Object Class Array Parameter)] + ["[1][0]" lux (.only Mapping)] + ["[1][0]" descriptor] + ["[1][0]" reflection] + ["[1][0]" parser]]]) + +(import java/lang/String + "[1]::[0]") + +(import java/lang/Object + "[1]::[0]" + (toString [] java/lang/String) + (getClass [] (java/lang/Class java/lang/Object))) + +(import java/lang/reflect/Type + "[1]::[0]" + (getTypeName [] java/lang/String)) + +(import java/lang/reflect/GenericArrayType + "[1]::[0]" + (getGenericComponentType [] java/lang/reflect/Type)) + +(import java/lang/reflect/ParameterizedType + "[1]::[0]" + (getRawType [] java/lang/reflect/Type) + (getActualTypeArguments [] [java/lang/reflect/Type])) + +(import (java/lang/reflect/TypeVariable d) + "[1]::[0]" + (getName [] java/lang/String) + (getBounds [] [java/lang/reflect/Type])) + +(import (java/lang/reflect/WildcardType d) + "[1]::[0]" + (getLowerBounds [] [java/lang/reflect/Type]) + (getUpperBounds [] [java/lang/reflect/Type])) + +(import java/lang/reflect/Modifier + "[1]::[0]" + ("static" isStatic [int] boolean) + ("static" isFinal [int] boolean) + ("static" isInterface [int] boolean) + ("static" isAbstract [int] boolean)) + +(import java/lang/annotation/Annotation + "[1]::[0]") + +(import java/lang/Deprecated + "[1]::[0]") + +(import java/lang/reflect/Field + "[1]::[0]" + (getDeclaringClass [] (java/lang/Class java/lang/Object)) + (getModifiers [] int) + (getGenericType [] java/lang/reflect/Type) + (getDeclaredAnnotations [] [java/lang/annotation/Annotation])) + +(import java/lang/ClassLoader + "[1]::[0]") + +(import (java/lang/Class c) + "[1]::[0]" + ("static" forName [java/lang/String boolean java/lang/ClassLoader] "try" (java/lang/Class java/lang/Object)) + (getName [] java/lang/String) + (isAssignableFrom [(java/lang/Class java/lang/Object)] boolean) + (getTypeParameters [] [(java/lang/reflect/TypeVariable (java/lang/Class c))]) + (getDeclaredField [java/lang/String] "try" java/lang/reflect/Field) + (isArray [] boolean) + (getComponentType [] (java/lang/Class java/lang/Object))) + +(exception.def .public (unknown_class class) + (Exception External) + (exception.report + (list ["Class" (%.text class)]))) + +(with_template [] + [(exception.def .public ( jvm_type) + (Exception java/lang/reflect/Type) + (exception.report + (list ["Type" (java/lang/reflect/Type::getTypeName jvm_type)] + ["Class" (|> jvm_type java/lang/Object::getClass java/lang/Object::toString)])))] + + [not_a_class] + [cannot_convert_to_a_lux_type] + ) + +(def .public (load class_loader name) + (-> java/lang/ClassLoader External (Try (java/lang/Class java/lang/Object))) + (when (java/lang/Class::forName name false class_loader) + {try.#Failure _} + (exception.except ..unknown_class [name]) + + success + success)) + +(def .public (sub? class_loader super sub) + (-> java/lang/ClassLoader External External (Try Bit)) + (do try.monad + [super (..load class_loader super) + sub (..load class_loader sub)] + (in (java/lang/Class::isAssignableFrom sub super)))) + +(def (class' parameter reflection) + (-> (-> java/lang/reflect/Type (Try (/.Type Parameter))) + java/lang/reflect/Type + (Try (/.Type Class))) + (<| (when (ffi.as java/lang/Class reflection) + {.#Some class} + (let [class_name (|> class + (as (java/lang/Class java/lang/Object)) + java/lang/Class::getName)] + (`` (if (or (,, (with_template [] + [(text#= (/reflection.reflection ) + class_name)] + + [/reflection.boolean] + [/reflection.byte] + [/reflection.short] + [/reflection.int] + [/reflection.long] + [/reflection.float] + [/reflection.double] + [/reflection.char])) + (text.starts_with? /descriptor.array_prefix class_name)) + (exception.except ..not_a_class [reflection]) + {try.#Success (/.class class_name (list))}))) + _) + (when (ffi.as java/lang/reflect/ParameterizedType reflection) + {.#Some reflection} + (let [raw (java/lang/reflect/ParameterizedType::getRawType reflection)] + (when (ffi.as java/lang/Class raw) + {.#Some raw'} + (let [! try.monad] + (|> reflection + java/lang/reflect/ParameterizedType::getActualTypeArguments + (array.list {.#None}) + (monad.each ! parameter) + (of ! each (/.class (|> raw' + (as (java/lang/Class java/lang/Object)) + java/lang/Class::getName))) + (exception.with ..cannot_convert_to_a_lux_type [reflection]))) + + _ + (exception.except ..not_a_class [reflection]))) + _) + ... else + (exception.except ..cannot_convert_to_a_lux_type [reflection]))) + +(def .public (parameter type reflection) + (-> (-> java/lang/reflect/Type (Try (/.Type Value))) + (-> java/lang/reflect/Type (Try (/.Type Parameter)))) + (<| (when (ffi.as java/lang/reflect/TypeVariable reflection) + {.#Some reflection} + {try.#Success (/.var (java/lang/reflect/TypeVariable::getName reflection))} + _) + (when (ffi.as java/lang/reflect/WildcardType reflection) + {.#Some reflection} + ... TODO: Instead of having single lower/upper bounds, should + ... allow for multiple ones. + (when [(array.item 0 (java/lang/reflect/WildcardType::getLowerBounds reflection)) + (array.item 0 (java/lang/reflect/WildcardType::getUpperBounds reflection))] + (^.with_template [ ] + [ + (when (ffi.as java/lang/reflect/GenericArrayType bound) + {.#Some it} + ... TODO: Array bounds should not be "erased" as they + ... are right now. + {try.#Success /.wildcard} + + _ + (of try.monad each (parameter type bound)))]) + ([[_ {.#Some bound}] /.upper] + [[{.#Some bound} _] /.lower]) + + _ + {try.#Success /.wildcard}) + _) + (when (ffi.as java/lang/reflect/GenericArrayType reflection) + {.#Some reflection} + (|> reflection + java/lang/reflect/GenericArrayType::getGenericComponentType + type + (of try.monad each /.array)) + _) + (when (ffi.as java/lang/Class reflection) + {.#Some class} + (if (java/lang/Class::isArray class) + (|> class + java/lang/Class::getComponentType + type + (try#each /.array)) + (..class' (parameter type) reflection)) + _) + (..class' (parameter type) reflection))) + +(def .public (type reflection) + (-> java/lang/reflect/Type (Try (/.Type Value))) + (<| (when (ffi.as java/lang/Class reflection) + {.#Some reflection} + (let [class_name (|> reflection + (as (java/lang/Class java/lang/Object)) + java/lang/Class::getName)] + (`` (cond (,, (with_template [ ] + [(text#= (/reflection.reflection ) + class_name) + {try.#Success }] + + [/reflection.boolean /.boolean] + [/reflection.byte /.byte] + [/reflection.short /.short] + [/reflection.int /.int] + [/reflection.long /.long] + [/reflection.float /.float] + [/reflection.double /.double] + [/reflection.char /.char])) + (if (text.starts_with? /descriptor.array_prefix class_name) + (.result /parser.value (|> class_name //name.internal //name.read)) + {try.#Success (/.class class_name (list))})))) + _) + ... else + (..parameter type reflection))) + +(def .public class + (-> java/lang/reflect/Type + (Try (/.Type Class))) + (..class' (..parameter ..type))) + +(def .public (return reflection) + (-> java/lang/reflect/Type (Try (/.Type Return))) + (with_expansions [ (these (..type reflection))] + (when (ffi.as java/lang/Class reflection) + {.#Some class} + (let [class_name (|> reflection + (as (java/lang/Class java/lang/Object)) + java/lang/Class::getName)] + (if (text#= (/reflection.reflection /reflection.void) + class_name) + {try.#Success /.void} + )) + + {.#None} + ))) + +(exception.def .public (cannot_correspond [class type]) + (Exception [(java/lang/Class java/lang/Object) Type]) + (exception.report + (list ["Class" (java/lang/Object::toString class)] + ["Type" (%.type type)]))) + +(exception.def .public (type_parameter_mismatch [expected actual class type]) + (Exception [Nat Nat (java/lang/Class java/lang/Object) Type]) + (exception.report + (list ["Expected" (%.nat expected)] + ["Actual" (%.nat actual)] + ["Class" (java/lang/Object::toString class)] + ["Type" (%.type type)]))) + +(exception.def .public (non_jvm_type type) + (Exception Type) + (exception.report + (list ["Type" (%.type type)]))) + +(def .public (correspond class type) + (-> (java/lang/Class java/lang/Object) Type (Try Mapping)) + (when type + {.#Nominal array.nominal (list :member:)} + (if (java/lang/Class::isArray class) + (correspond (java/lang/Class::getComponentType class) + :member:) + (exception.except ..cannot_correspond [class type])) + + {.#Nominal name params} + (let [class_name (java/lang/Class::getName class) + class_params (array.list {.#None} (java/lang/Class::getTypeParameters class)) + num_class_params (list.size class_params) + num_type_params (list.size params)] + (if (text#= class_name name) + (if (n.= num_class_params num_type_params) + (|> params + (list.zipped_2 (list#each (|>> java/lang/reflect/TypeVariable::getName) + class_params)) + (list#mix (function (_ [name paramT] mapping) + (dictionary.has name paramT mapping)) + /lux.fresh) + {try.#Success}) + (exception.except ..type_parameter_mismatch [num_class_params num_type_params class type])) + (exception.except ..cannot_correspond [class type]))) + + {.#Named name anonymousT} + (correspond class anonymousT) + + {.#Apply inputT abstractionT} + (when (type.applied (list inputT) abstractionT) + {.#Some outputT} + (correspond class outputT) + + {.#None} + (exception.except ..non_jvm_type [type])) + + _ + (exception.except ..non_jvm_type [type]))) + +(exception.def .public (mistaken_field_owner [field owner target]) + (Exception [java/lang/reflect/Field (java/lang/Class java/lang/Object) (java/lang/Class java/lang/Object)]) + (exception.report + (list ["Field" (java/lang/Object::toString field)] + ["Owner" (java/lang/Object::toString owner)] + ["Target" (java/lang/Object::toString target)]))) + +(with_template [] + [(exception.def .public ( [field class]) + (Exception [Text (java/lang/Class java/lang/Object)]) + (exception.report + (list ["Field" (%.text field)] + ["Class" (java/lang/Object::toString class)])))] + + [unknown_field] + [not_a_static_field] + [not_a_virtual_field] + ) + +(def .public (field field target) + (-> Text (java/lang/Class java/lang/Object) (Try java/lang/reflect/Field)) + (when (java/lang/Class::getDeclaredField field target) + {try.#Success field} + (let [owner (java/lang/reflect/Field::getDeclaringClass field)] + (if (same? owner target) + {try.#Success field} + (exception.except ..mistaken_field_owner [field owner target]))) + + {try.#Failure _} + (exception.except ..unknown_field [field target]))) + +(def .public deprecated? + (-> (array.Array java/lang/annotation/Annotation) Bit) + (|>> (array.list {.#None}) + (list.all (|>> (ffi.as java/lang/Deprecated))) + list.empty? + not)) + +(with_template [ ] + [(def .public ( field class) + (-> Text (java/lang/Class java/lang/Object) (Try [Bit Bit (/.Type Value)])) + (do [! try.monad] + [fieldJ (..field field class) + .let [modifiers (java/lang/reflect/Field::getModifiers fieldJ)]] + (when (java/lang/reflect/Modifier::isStatic modifiers) + (|> fieldJ + java/lang/reflect/Field::getGenericType + ..type + (of ! each (|>> [(java/lang/reflect/Modifier::isFinal modifiers) + (..deprecated? (java/lang/reflect/Field::getDeclaredAnnotations fieldJ))]))) + (exception.except [field class]))))] + + [static_field ..not_a_static_field #1 #0] + [virtual_field ..not_a_virtual_field #0 #1] + ) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/type.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/type.lux new file mode 100644 index 000000000..e1cbb4374 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/type.lux @@ -0,0 +1,227 @@ +(.require + [library + [lux (.except Type Declaration int char) + [abstract + [equivalence (.only Equivalence)] + [hash (.only Hash)]] + [control + ["[0]" maybe]] + [data + ["[0]" text (.only) + ["%" \\format (.only Format)]] + [collection + ["[0]" list (.use "[1]#[0]" functor)]]] + [math + [number + ["n" nat]]] + [meta + [type + ["[0]" nominal (.except def #name)]]]]] + ["[0]" // + [encoding + ["[1][0]" name (.only External)]]] + ["[0]" / + [category (.only Void Value' Value Return' Return Method Primitive Object Class Array Var Parameter Declaration)] + ["[1][0]" signature (.only Signature)] + ["[1][0]" descriptor (.only Descriptor)] + ["[1][0]" reflection (.only Reflection)]]) + +(nominal.def .public (Type category) + [(Signature category) + (Descriptor category) + (Reflection category)] + + (type .public Argument + [Text (Type Value)]) + + (type .public (Typed a) + [(Type Value) a]) + + (type .public Constraint + (Record + [#name Text + #super_class (Type Class) + #super_interfaces (List (Type Class))])) + + (with_template [