From 700628f36e1ac846f007cec855b0f9ecdbb66c80 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 3 Jul 2022 03:12:11 -0400 Subject: Moved "lux/target" to "lux/meta/target". --- lux-jvm/source/program.lux | 16 +- stdlib/source/documentation/lux/meta/target.lux | 41 + stdlib/source/documentation/lux/meta/target/js.lux | 97 ++ .../documentation/lux/meta/target/jvm/type.lux | 64 + .../lux/meta/target/jvm/type/alias.lux | 20 + .../documentation/lux/meta/target/jvm/type/box.lux | 25 + .../lux/meta/target/jvm/type/category.lux | 30 + .../lux/meta/target/jvm/type/descriptor.lux | 42 + .../documentation/lux/meta/target/jvm/type/lux.lux | 28 + .../lux/meta/target/jvm/type/parser.lux | 53 + .../lux/meta/target/jvm/type/reflection.lux | 37 + .../lux/meta/target/jvm/type/signature.lux | 48 + .../source/documentation/lux/meta/target/lua.lux | 92 + .../documentation/lux/meta/target/python.lux | 112 ++ .../source/documentation/lux/meta/target/ruby.lux | 113 ++ stdlib/source/documentation/lux/target.lux | 41 - stdlib/source/documentation/lux/target/js.lux | 97 -- .../source/documentation/lux/target/jvm/type.lux | 64 - .../documentation/lux/target/jvm/type/alias.lux | 20 - .../documentation/lux/target/jvm/type/box.lux | 25 - .../documentation/lux/target/jvm/type/category.lux | 30 - .../lux/target/jvm/type/descriptor.lux | 42 - .../documentation/lux/target/jvm/type/lux.lux | 28 - .../documentation/lux/target/jvm/type/parser.lux | 53 - .../lux/target/jvm/type/reflection.lux | 37 - .../lux/target/jvm/type/signature.lux | 48 - stdlib/source/documentation/lux/target/lua.lux | 92 - stdlib/source/documentation/lux/target/python.lux | 112 -- stdlib/source/documentation/lux/target/ruby.lux | 113 -- stdlib/source/library/lux/abstract/apply.lux | 3 +- .../library/lux/control/concurrency/atom.lux | 2 +- .../library/lux/control/concurrency/thread.lux | 2 +- stdlib/source/library/lux/control/reader.lux | 5 +- stdlib/source/library/lux/control/thread.lux | 2 +- stdlib/source/library/lux/control/try.lux | 2 +- stdlib/source/library/lux/control/writer.lux | 5 +- stdlib/source/library/lux/data/collection/list.lux | 5 +- .../library/lux/data/collection/sequence.lux | 2 +- .../library/lux/data/collection/tree/zipper.lux | 5 +- .../source/library/lux/data/format/css/class.lux | 3 +- stdlib/source/library/lux/data/format/css/id.lux | 3 +- stdlib/source/library/lux/data/format/html.lux | 4 +- stdlib/source/library/lux/data/format/tar.lux | 25 +- stdlib/source/library/lux/data/text.lux | 2 +- stdlib/source/library/lux/data/text/buffer.lux | 2 +- .../source/library/lux/data/text/encoding/utf8.lux | 5 +- stdlib/source/library/lux/debug.lux | 5 +- stdlib/source/library/lux/ffi.jvm.lux | 27 +- stdlib/source/library/lux/ffi.lux | 9 +- stdlib/source/library/lux/ffi.php.lux | 2 +- stdlib/source/library/lux/ffi.scm.lux | 2 +- stdlib/source/library/lux/ffi/export.js.lux | 6 +- stdlib/source/library/lux/ffi/export.lua.lux | 6 +- stdlib/source/library/lux/ffi/export.py.lux | 6 +- stdlib/source/library/lux/ffi/export.rb.lux | 6 +- stdlib/source/library/lux/math.lux | 2 +- stdlib/source/library/lux/math/number/frac.lux | 2 +- stdlib/source/library/lux/meta/target.lux | 26 + .../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 | 150 ++ .../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 + .../library/lux/meta/target/jvm/bytecode.lux | 1177 +++++++++++++ .../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 | 151 ++ .../library/lux/meta/target/jvm/constant.lux | 251 +++ .../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 | 123 ++ .../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 | 145 ++ .../source/library/lux/meta/target/jvm/magic.lux | 22 + .../source/library/lux/meta/target/jvm/method.lux | 111 ++ .../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 | 212 +++ .../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 | 238 +++ .../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 | 498 ++++++ stdlib/source/library/lux/meta/target/r.lux | 394 +++++ stdlib/source/library/lux/meta/target/ruby.lux | 537 ++++++ stdlib/source/library/lux/meta/target/scheme.lux | 389 +++++ stdlib/source/library/lux/meta/type.lux | 2 +- stdlib/source/library/lux/meta/type/check.lux | 2 +- stdlib/source/library/lux/program.lux | 2 +- stdlib/source/library/lux/target.lux | 26 - stdlib/source/library/lux/target/common_lisp.lux | 473 ------ stdlib/source/library/lux/target/js.lux | 447 ----- stdlib/source/library/lux/target/jvm/attribute.lux | 150 -- .../library/lux/target/jvm/attribute/code.lux | 83 - .../lux/target/jvm/attribute/code/exception.lux | 59 - .../library/lux/target/jvm/attribute/constant.lux | 27 - stdlib/source/library/lux/target/jvm/bytecode.lux | 1177 ------------- .../library/lux/target/jvm/bytecode/address.lux | 75 - .../lux/target/jvm/bytecode/environment.lux | 110 -- .../lux/target/jvm/bytecode/environment/limit.lux | 59 - .../jvm/bytecode/environment/limit/registry.lux | 93 -- .../jvm/bytecode/environment/limit/stack.lux | 70 - .../lux/target/jvm/bytecode/instruction.lux | 704 -------- .../library/lux/target/jvm/bytecode/jump.lux | 29 - stdlib/source/library/lux/target/jvm/class.lux | 151 -- stdlib/source/library/lux/target/jvm/constant.lux | 251 --- .../library/lux/target/jvm/constant/pool.lux | 217 --- .../source/library/lux/target/jvm/constant/tag.lux | 52 - .../library/lux/target/jvm/encoding/name.lux | 42 - .../library/lux/target/jvm/encoding/signed.lux | 114 -- .../library/lux/target/jvm/encoding/unsigned.lux | 123 -- stdlib/source/library/lux/target/jvm/field.lux | 81 - stdlib/source/library/lux/target/jvm/index.lux | 39 - stdlib/source/library/lux/target/jvm/loader.lux | 144 -- stdlib/source/library/lux/target/jvm/magic.lux | 22 - stdlib/source/library/lux/target/jvm/method.lux | 111 -- stdlib/source/library/lux/target/jvm/modifier.lux | 93 -- .../library/lux/target/jvm/modifier/inner.lux | 23 - .../source/library/lux/target/jvm/reflection.lux | 385 ----- stdlib/source/library/lux/target/jvm/type.lux | 212 --- .../source/library/lux/target/jvm/type/alias.lux | 127 -- stdlib/source/library/lux/target/jvm/type/box.lux | 19 - .../library/lux/target/jvm/type/category.lux | 38 - .../library/lux/target/jvm/type/descriptor.lux | 125 -- stdlib/source/library/lux/target/jvm/type/lux.lux | 238 --- .../source/library/lux/target/jvm/type/parser.lux | 277 --- .../library/lux/target/jvm/type/reflection.lux | 105 -- .../library/lux/target/jvm/type/signature.lux | 183 -- stdlib/source/library/lux/target/jvm/version.lux | 42 - stdlib/source/library/lux/target/lua.lux | 408 ----- stdlib/source/library/lux/target/php.lux | 555 ------ stdlib/source/library/lux/target/python.lux | 498 ------ stdlib/source/library/lux/target/r.lux | 394 ----- stdlib/source/library/lux/target/ruby.lux | 537 ------ stdlib/source/library/lux/target/scheme.lux | 389 ----- stdlib/source/library/lux/test.lux | 2 +- stdlib/source/library/lux/time/instant.lux | 2 +- .../library/lux/tool/compiler/default/init.lux | 2 +- .../library/lux/tool/compiler/default/platform.lux | 2 +- .../compiler/language/lux/analysis/inference.lux | 3 +- .../language/lux/phase/extension/analysis/js.lux | 10 +- .../language/lux/phase/extension/analysis/jvm.lux | 48 +- .../language/lux/phase/extension/analysis/lua.lux | 6 +- .../language/lux/phase/extension/analysis/lux.lux | 5 +- .../language/lux/phase/extension/analysis/php.lux | 6 +- .../lux/phase/extension/analysis/python.lux | 6 +- .../language/lux/phase/extension/analysis/r.lux | 6 +- .../language/lux/phase/extension/analysis/ruby.lux | 6 +- .../lux/phase/extension/analysis/scheme.lux | 6 +- .../lux/phase/extension/declaration/jvm.lux | 48 +- .../lux/phase/extension/declaration/lux.lux | 8 +- .../extension/generation/common_lisp/common.lux | 5 +- .../lux/phase/extension/generation/js/common.lux | 6 +- .../lux/phase/extension/generation/js/host.lux | 5 +- .../lux/phase/extension/generation/jvm/common.lux | 15 +- .../lux/phase/extension/generation/jvm/host.lux | 38 +- .../lux/phase/extension/generation/lua/common.lux | 6 +- .../lux/phase/extension/generation/lua/host.lux | 5 +- .../lux/phase/extension/generation/php/common.lux | 5 +- .../lux/phase/extension/generation/php/host.lux | 5 +- .../phase/extension/generation/python/common.lux | 6 +- .../lux/phase/extension/generation/python/host.lux | 5 +- .../lux/phase/extension/generation/r/common.lux | 5 +- .../lux/phase/extension/generation/r/host.lux | 5 +- .../lux/phase/extension/generation/ruby/common.lux | 6 +- .../lux/phase/extension/generation/ruby/host.lux | 5 +- .../phase/extension/generation/scheme/common.lux | 5 +- .../lux/phase/extension/generation/scheme/host.lux | 5 +- .../lux/phase/generation/common_lisp/case.lux | 6 +- .../generation/common_lisp/extension/common.lux | 5 +- .../lux/phase/generation/common_lisp/function.lux | 5 +- .../lux/phase/generation/common_lisp/loop.lux | 5 +- .../lux/phase/generation/common_lisp/primitive.lux | 5 +- .../lux/phase/generation/common_lisp/reference.lux | 5 +- .../lux/phase/generation/common_lisp/runtime.lux | 6 +- .../lux/phase/generation/common_lisp/structure.lux | 5 +- .../compiler/language/lux/phase/generation/js.lux | 6 +- .../language/lux/phase/generation/js/case.lux | 6 +- .../language/lux/phase/generation/js/function.lux | 5 +- .../language/lux/phase/generation/js/loop.lux | 5 +- .../language/lux/phase/generation/js/primitive.lux | 5 +- .../language/lux/phase/generation/js/reference.lux | 5 +- .../language/lux/phase/generation/js/runtime.lux | 6 +- .../language/lux/phase/generation/js/structure.lux | 5 +- .../language/lux/phase/generation/jvm/case.lux | 18 +- .../language/lux/phase/generation/jvm/function.lux | 33 +- .../lux/phase/generation/jvm/function/abstract.lux | 9 +- .../generation/jvm/function/field/constant.lux | 17 +- .../jvm/function/field/constant/arity.lux | 11 +- .../generation/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/generation/jvm/function/method.lux | 9 +- .../phase/generation/jvm/function/method/apply.lux | 21 +- .../jvm/function/method/implementation.lux | 19 +- .../phase/generation/jvm/function/method/init.lux | 21 +- .../phase/generation/jvm/function/method/new.lux | 19 +- .../phase/generation/jvm/function/method/reset.lux | 17 +- .../language/lux/phase/generation/jvm/host.lux | 27 +- .../language/lux/phase/generation/jvm/loop.lux | 7 +- .../lux/phase/generation/jvm/primitive.lux | 14 +- .../language/lux/phase/generation/jvm/program.lux | 23 +- .../lux/phase/generation/jvm/reference.lux | 13 +- .../language/lux/phase/generation/jvm/runtime.lux | 32 +- .../lux/phase/generation/jvm/structure.lux | 13 +- .../language/lux/phase/generation/jvm/type.lux | 7 +- .../language/lux/phase/generation/jvm/value.lux | 13 +- .../compiler/language/lux/phase/generation/lua.lux | 6 +- .../language/lux/phase/generation/lua/case.lux | 6 +- .../language/lux/phase/generation/lua/function.lux | 5 +- .../language/lux/phase/generation/lua/loop.lux | 5 +- .../lux/phase/generation/lua/primitive.lux | 5 +- .../lux/phase/generation/lua/reference.lux | 5 +- .../language/lux/phase/generation/lua/runtime.lux | 6 +- .../lux/phase/generation/lua/structure.lux | 5 +- .../compiler/language/lux/phase/generation/php.lux | 6 +- .../language/lux/phase/generation/php/case.lux | 6 +- .../lux/phase/generation/php/extension/common.lux | 5 +- .../language/lux/phase/generation/php/function.lux | 5 +- .../language/lux/phase/generation/php/loop.lux | 5 +- .../lux/phase/generation/php/primitive.lux | 5 +- .../lux/phase/generation/php/reference.lux | 5 +- .../language/lux/phase/generation/php/runtime.lux | 6 +- .../language/lux/phase/generation/python.lux | 6 +- .../language/lux/phase/generation/python/case.lux | 6 +- .../lux/phase/generation/python/function.lux | 5 +- .../language/lux/phase/generation/python/loop.lux | 5 +- .../lux/phase/generation/python/primitive.lux | 5 +- .../lux/phase/generation/python/reference.lux | 5 +- .../lux/phase/generation/python/runtime.lux | 6 +- .../lux/phase/generation/python/structure.lux | 5 +- .../compiler/language/lux/phase/generation/r.lux | 6 +- .../language/lux/phase/generation/r/case.lux | 6 +- .../language/lux/phase/generation/r/function.lux | 5 +- .../language/lux/phase/generation/r/loop.lux | 5 +- .../language/lux/phase/generation/r/primitive.lux | 5 +- .../language/lux/phase/generation/r/reference.lux | 5 +- .../language/lux/phase/generation/r/runtime.lux | 6 +- .../language/lux/phase/generation/r/structure.lux | 5 +- .../language/lux/phase/generation/reference.lux | 2 +- .../language/lux/phase/generation/ruby.lux | 6 +- .../language/lux/phase/generation/ruby/case.lux | 6 +- .../lux/phase/generation/ruby/function.lux | 5 +- .../language/lux/phase/generation/ruby/loop.lux | 5 +- .../lux/phase/generation/ruby/primitive.lux | 5 +- .../lux/phase/generation/ruby/reference.lux | 5 +- .../language/lux/phase/generation/ruby/runtime.lux | 6 +- .../lux/phase/generation/ruby/structure.lux | 5 +- .../language/lux/phase/generation/scheme.lux | 6 +- .../language/lux/phase/generation/scheme/case.lux | 6 +- .../phase/generation/scheme/extension/common.lux | 6 +- .../lux/phase/generation/scheme/function.lux | 5 +- .../language/lux/phase/generation/scheme/loop.lux | 5 +- .../lux/phase/generation/scheme/primitive.lux | 5 +- .../lux/phase/generation/scheme/reference.lux | 5 +- .../lux/phase/generation/scheme/runtime.lux | 6 +- .../lux/phase/generation/scheme/structure.lux | 5 +- .../lux/tool/compiler/language/lux/syntax.lux | 2 +- .../lux/tool/compiler/meta/cache/artifact.lux | 3 +- .../lux/tool/compiler/meta/cache/module.lux | 3 +- .../library/lux/tool/compiler/meta/context.lux | 3 +- .../library/lux/tool/compiler/meta/io/archive.lux | 2 +- .../library/lux/tool/compiler/meta/io/context.lux | 3 +- .../lux/tool/compiler/meta/packager/jvm.lux | 9 +- .../lux/tool/compiler/meta/packager/ruby.lux | 5 +- .../lux/tool/compiler/meta/packager/scheme.lux | 5 +- .../lux/tool/compiler/meta/packager/script.lux | 5 +- stdlib/source/library/lux/world/console.lux | 5 +- stdlib/source/library/lux/world/environment.lux | 2 +- stdlib/source/library/lux/world/file.lux | 2 +- stdlib/source/library/lux/world/file/watch.lux | 2 +- .../source/library/lux/world/net/http/client.lux | 2 +- stdlib/source/library/lux/world/shell.lux | 5 +- stdlib/source/program/aedifex/artifact/time.lux | 3 +- .../program/aedifex/dependency/resolution.lux | 3 +- stdlib/source/program/aedifex/pom.lux | 4 +- stdlib/source/program/compositor.lux | 8 +- stdlib/source/test/lux.lux | 20 +- stdlib/source/test/lux/abstract/apply.lux | 4 +- stdlib/source/test/lux/abstract/comonad.lux | 4 +- stdlib/source/test/lux/abstract/equivalence.lux | 5 +- stdlib/source/test/lux/abstract/functor.lux | 5 +- .../source/test/lux/control/concurrency/async.lux | 11 +- .../test/lux/control/concurrency/semaphore.lux | 2 +- stdlib/source/test/lux/data/format/json.lux | 16 +- stdlib/source/test/lux/debug.lux | 2 +- stdlib/source/test/lux/extension.lux | 34 +- stdlib/source/test/lux/ffi.jvm.lux | 8 +- stdlib/source/test/lux/math/number/frac.lux | 2 +- stdlib/source/test/lux/meta.lux | 262 +-- stdlib/source/test/lux/meta/target.lux | 46 + stdlib/source/test/lux/meta/target/js.lux | 847 ++++++++++ stdlib/source/test/lux/meta/target/jvm.lux | 1758 ++++++++++++++++++++ stdlib/source/test/lux/meta/target/lua.lux | 723 ++++++++ stdlib/source/test/lux/meta/target/python.lux | 842 ++++++++++ stdlib/source/test/lux/meta/target/ruby.lux | 1062 ++++++++++++ stdlib/source/test/lux/static.lux | 2 +- stdlib/source/test/lux/target.lux | 46 - stdlib/source/test/lux/target/js.lux | 847 ---------- stdlib/source/test/lux/target/jvm.lux | 1757 ------------------- stdlib/source/test/lux/target/lua.lux | 723 -------- stdlib/source/test/lux/target/python.lux | 842 ---------- stdlib/source/test/lux/target/ruby.lux | 1062 ------------ stdlib/source/unsafe/lux/data/binary.lux | 5 +- stdlib/source/unsafe/lux/data/collection/array.lux | 2 +- 323 files changed, 16549 insertions(+), 16457 deletions(-) create mode 100644 stdlib/source/documentation/lux/meta/target.lux create mode 100644 stdlib/source/documentation/lux/meta/target/js.lux create mode 100644 stdlib/source/documentation/lux/meta/target/jvm/type.lux create mode 100644 stdlib/source/documentation/lux/meta/target/jvm/type/alias.lux create mode 100644 stdlib/source/documentation/lux/meta/target/jvm/type/box.lux create mode 100644 stdlib/source/documentation/lux/meta/target/jvm/type/category.lux create mode 100644 stdlib/source/documentation/lux/meta/target/jvm/type/descriptor.lux create mode 100644 stdlib/source/documentation/lux/meta/target/jvm/type/lux.lux create mode 100644 stdlib/source/documentation/lux/meta/target/jvm/type/parser.lux create mode 100644 stdlib/source/documentation/lux/meta/target/jvm/type/reflection.lux create mode 100644 stdlib/source/documentation/lux/meta/target/jvm/type/signature.lux create mode 100644 stdlib/source/documentation/lux/meta/target/lua.lux create mode 100644 stdlib/source/documentation/lux/meta/target/python.lux create mode 100644 stdlib/source/documentation/lux/meta/target/ruby.lux delete mode 100644 stdlib/source/documentation/lux/target.lux delete mode 100644 stdlib/source/documentation/lux/target/js.lux delete mode 100644 stdlib/source/documentation/lux/target/jvm/type.lux delete mode 100644 stdlib/source/documentation/lux/target/jvm/type/alias.lux delete mode 100644 stdlib/source/documentation/lux/target/jvm/type/box.lux delete mode 100644 stdlib/source/documentation/lux/target/jvm/type/category.lux delete mode 100644 stdlib/source/documentation/lux/target/jvm/type/descriptor.lux delete mode 100644 stdlib/source/documentation/lux/target/jvm/type/lux.lux delete mode 100644 stdlib/source/documentation/lux/target/jvm/type/parser.lux delete mode 100644 stdlib/source/documentation/lux/target/jvm/type/reflection.lux delete mode 100644 stdlib/source/documentation/lux/target/jvm/type/signature.lux delete mode 100644 stdlib/source/documentation/lux/target/lua.lux delete mode 100644 stdlib/source/documentation/lux/target/python.lux delete mode 100644 stdlib/source/documentation/lux/target/ruby.lux create mode 100644 stdlib/source/library/lux/meta/target.lux create mode 100644 stdlib/source/library/lux/meta/target/common_lisp.lux create mode 100644 stdlib/source/library/lux/meta/target/js.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/attribute.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/attribute/code.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/attribute/code/exception.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/attribute/constant.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/address.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/environment.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/environment/limit.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/environment/limit/registry.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/environment/limit/stack.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/instruction.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/bytecode/jump.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/class.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/constant.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/constant/pool.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/constant/tag.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/encoding/name.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/encoding/signed.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/encoding/unsigned.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/field.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/index.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/loader.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/magic.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/method.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/modifier.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/modifier/inner.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/reflection.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/type.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/type/alias.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/type/box.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/type/category.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/type/descriptor.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/type/lux.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/type/parser.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/type/reflection.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/type/signature.lux create mode 100644 stdlib/source/library/lux/meta/target/jvm/version.lux create mode 100644 stdlib/source/library/lux/meta/target/lua.lux create mode 100644 stdlib/source/library/lux/meta/target/php.lux create mode 100644 stdlib/source/library/lux/meta/target/python.lux create mode 100644 stdlib/source/library/lux/meta/target/r.lux create mode 100644 stdlib/source/library/lux/meta/target/ruby.lux create mode 100644 stdlib/source/library/lux/meta/target/scheme.lux delete mode 100644 stdlib/source/library/lux/target.lux delete mode 100644 stdlib/source/library/lux/target/common_lisp.lux delete mode 100644 stdlib/source/library/lux/target/js.lux delete mode 100644 stdlib/source/library/lux/target/jvm/attribute.lux delete mode 100644 stdlib/source/library/lux/target/jvm/attribute/code.lux delete mode 100644 stdlib/source/library/lux/target/jvm/attribute/code/exception.lux delete mode 100644 stdlib/source/library/lux/target/jvm/attribute/constant.lux delete mode 100644 stdlib/source/library/lux/target/jvm/bytecode.lux delete mode 100644 stdlib/source/library/lux/target/jvm/bytecode/address.lux delete mode 100644 stdlib/source/library/lux/target/jvm/bytecode/environment.lux delete mode 100644 stdlib/source/library/lux/target/jvm/bytecode/environment/limit.lux delete mode 100644 stdlib/source/library/lux/target/jvm/bytecode/environment/limit/registry.lux delete mode 100644 stdlib/source/library/lux/target/jvm/bytecode/environment/limit/stack.lux delete mode 100644 stdlib/source/library/lux/target/jvm/bytecode/instruction.lux delete mode 100644 stdlib/source/library/lux/target/jvm/bytecode/jump.lux delete mode 100644 stdlib/source/library/lux/target/jvm/class.lux delete mode 100644 stdlib/source/library/lux/target/jvm/constant.lux delete mode 100644 stdlib/source/library/lux/target/jvm/constant/pool.lux delete mode 100644 stdlib/source/library/lux/target/jvm/constant/tag.lux delete mode 100644 stdlib/source/library/lux/target/jvm/encoding/name.lux delete mode 100644 stdlib/source/library/lux/target/jvm/encoding/signed.lux delete mode 100644 stdlib/source/library/lux/target/jvm/encoding/unsigned.lux delete mode 100644 stdlib/source/library/lux/target/jvm/field.lux delete mode 100644 stdlib/source/library/lux/target/jvm/index.lux delete mode 100644 stdlib/source/library/lux/target/jvm/loader.lux delete mode 100644 stdlib/source/library/lux/target/jvm/magic.lux delete mode 100644 stdlib/source/library/lux/target/jvm/method.lux delete mode 100644 stdlib/source/library/lux/target/jvm/modifier.lux delete mode 100644 stdlib/source/library/lux/target/jvm/modifier/inner.lux delete mode 100644 stdlib/source/library/lux/target/jvm/reflection.lux delete mode 100644 stdlib/source/library/lux/target/jvm/type.lux delete mode 100644 stdlib/source/library/lux/target/jvm/type/alias.lux delete mode 100644 stdlib/source/library/lux/target/jvm/type/box.lux delete mode 100644 stdlib/source/library/lux/target/jvm/type/category.lux delete mode 100644 stdlib/source/library/lux/target/jvm/type/descriptor.lux delete mode 100644 stdlib/source/library/lux/target/jvm/type/lux.lux delete mode 100644 stdlib/source/library/lux/target/jvm/type/parser.lux delete mode 100644 stdlib/source/library/lux/target/jvm/type/reflection.lux delete mode 100644 stdlib/source/library/lux/target/jvm/type/signature.lux delete mode 100644 stdlib/source/library/lux/target/jvm/version.lux delete mode 100644 stdlib/source/library/lux/target/lua.lux delete mode 100644 stdlib/source/library/lux/target/php.lux delete mode 100644 stdlib/source/library/lux/target/python.lux delete mode 100644 stdlib/source/library/lux/target/r.lux delete mode 100644 stdlib/source/library/lux/target/ruby.lux delete mode 100644 stdlib/source/library/lux/target/scheme.lux create mode 100644 stdlib/source/test/lux/meta/target.lux create mode 100644 stdlib/source/test/lux/meta/target/js.lux create mode 100644 stdlib/source/test/lux/meta/target/jvm.lux create mode 100644 stdlib/source/test/lux/meta/target/lua.lux create mode 100644 stdlib/source/test/lux/meta/target/python.lux create mode 100644 stdlib/source/test/lux/meta/target/ruby.lux delete mode 100644 stdlib/source/test/lux/target.lux delete mode 100644 stdlib/source/test/lux/target/js.lux delete mode 100644 stdlib/source/test/lux/target/jvm.lux delete mode 100644 stdlib/source/test/lux/target/lua.lux delete mode 100644 stdlib/source/test/lux/target/python.lux delete mode 100644 stdlib/source/test/lux/target/ruby.lux diff --git a/lux-jvm/source/program.lux b/lux-jvm/source/program.lux index 8d9dcdb1c..528482b77 100644 --- a/lux-jvm/source/program.lux +++ b/lux-jvm/source/program.lux @@ -2,7 +2,6 @@ [library [lux (.except Definition) [program (.only program:)] - ["@" target] ["[0]" ffi (.only import)] [abstract [monad (.only do)]] @@ -17,14 +16,15 @@ ["%" \\format (.only format)]] [collection [array (.only Array)]]] + [meta + ["@" target (.only) + ["[0]" jvm + [bytecode (.only Bytecode)] + ["[1]/[0]" type + ["[1]/[0]" box]]]]] ["[0]" world ["[0]" file] - ["[1]/[0]" program]] - [target - ["[0]" jvm - [bytecode (.only Bytecode)] - ["[1]/[0]" type - ["[1]/[0]" box]]]] + ["[1]/[0]" environment]] [tool [compiler (.only) ["[0]" phase] @@ -158,7 +158,7 @@ (def (declare_success! _) (-> Any (Async Any)) - (async.future (at world/program.default exit +0))) + (async.future (at world/environment.default exit +0))) (def (lux_compiler it) (-> Any platform.Custom) diff --git a/stdlib/source/documentation/lux/meta/target.lux b/stdlib/source/documentation/lux/meta/target.lux new file mode 100644 index 000000000..a10a6e3f5 --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target.lux @@ -0,0 +1,41 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]] + ["[0]" / + ["[1][0]" js] + ["[1][0]" jvm/type] + ["[1][0]" lua] + ["[1][0]" python] + ["[1][0]" ruby]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.old) + ($.default /.js) + ($.default /.jvm) + ($.default /.lua) + ($.default /.python) + ($.default /.ruby) + ($.default /.common_lisp) + ($.default /.php) + ($.default /.r) + ($.default /.scheme) + + ($.documentation /.Target + (format "The name/ID of a platform targetted by a Lux compiler." + \n "This information can be used to generate code targetting specific platforms, and to make programs cross-platform."))] + [/js.documentation + /jvm/type.documentation + /lua.documentation + /python.documentation + /ruby.documentation])) diff --git a/stdlib/source/documentation/lux/meta/target/js.lux b/stdlib/source/documentation/lux/meta/target/js.lux new file mode 100644 index 000000000..68f67d560 --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/js.lux @@ -0,0 +1,97 @@ +(.require + [library + [lux (.except) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Code) + ($.default /.code) + ($.default /.Expression) + ($.default /.Computation) + ($.default /.Location) + ($.default /.Statement) + ($.default /.Var) + ($.default /.Access) + ($.default /.Literal) + ($.default /.Loop) + ($.default /.Label) + ($.default /.null) + ($.default /.undefined) + ($.default /.boolean) + ($.default /.number) + ($.default /.string) + ($.default /.array) + ($.default /.var) + ($.default /.at) + ($.default /.the) + ($.default /.apply) + ($.default /.do) + ($.default /.object) + ($.default /.,) + ($.default /.then) + ($.default /.function_definition) + ($.default /.function) + ($.default /.closure) + ($.default /.=) + ($.default /.<) + ($.default /.<=) + ($.default /.>) + ($.default /.>=) + ($.default /.+) + ($.default /.-) + ($.default /.*) + ($.default /./) + ($.default /.%) + ($.default /.left_shift) + ($.default /.arithmetic_right_shift) + ($.default /.logic_right_shift) + ($.default /.or) + ($.default /.and) + ($.default /.bit_xor) + ($.default /.bit_or) + ($.default /.bit_and) + ($.default /.not) + ($.default /.bit_not) + ($.default /.opposite) + ($.default /.to_i32) + ($.default /.i32) + ($.default /.int) + ($.default /.?) + ($.default /.type_of) + ($.default /.new) + ($.default /.statement) + ($.default /.use_strict) + ($.default /.declare) + ($.default /.define) + ($.default /.set) + ($.default /.throw) + ($.default /.return) + ($.default /.delete) + ($.default /.if) + ($.default /.when) + ($.default /.while) + ($.default /.do_while) + ($.default /.try) + ($.default /.for) + ($.default /.label) + ($.default /.with_label) + ($.default /.break) + ($.default /.break_at) + ($.default /.continue) + ($.default /.continue_at) + ($.default /.++) + ($.default /.--) + ($.default /.comment) + ($.default /.switch) + ($.default /.not_a_number?)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/jvm/type.lux b/stdlib/source/documentation/lux/meta/target/jvm/type.lux new file mode 100644 index 000000000..39bded852 --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/jvm/type.lux @@ -0,0 +1,64 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]] + ["[0]" / + ["[1][0]" alias] + ["[1][0]" box] + ["[1][0]" category] + ["[1][0]" descriptor] + ["[1][0]" lux] + ["[1][0]" parser] + ["[1][0]" reflection] + ["[1][0]" signature]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Type) + ($.default /.Argument) + ($.default /.Typed) + ($.default /.Constraint) + ($.default /.signature) + ($.default /.descriptor) + ($.default /.reflection) + ($.default /.void) + ($.default /.boolean) + ($.default /.byte) + ($.default /.short) + ($.default /.int) + ($.default /.long) + ($.default /.float) + ($.default /.double) + ($.default /.char) + ($.default /.array) + ($.default /.class) + ($.default /.declaration) + ($.default /.as_class) + ($.default /.wildcard) + ($.default /.var) + ($.default /.lower) + ($.default /.upper) + ($.default /.method) + ($.default /.equivalence) + ($.default /.hash) + ($.default /.primitive?) + ($.default /.void?) + ($.default /.class?) + ($.default /.format)] + [/alias.documentation + /box.documentation + /category.documentation + /descriptor.documentation + /lux.documentation + /parser.documentation + /reflection.documentation + /signature.documentation])) diff --git a/stdlib/source/documentation/lux/meta/target/jvm/type/alias.lux b/stdlib/source/documentation/lux/meta/target/jvm/type/alias.lux new file mode 100644 index 000000000..d8e17f39a --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/jvm/type/alias.lux @@ -0,0 +1,20 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Aliasing) + ($.default /.fresh) + ($.default /.method)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/jvm/type/box.lux b/stdlib/source/documentation/lux/meta/target/jvm/type/box.lux new file mode 100644 index 000000000..1f393eb2e --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/jvm/type/box.lux @@ -0,0 +1,25 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.boolean) + ($.default /.byte) + ($.default /.short) + ($.default /.int) + ($.default /.long) + ($.default /.float) + ($.default /.double) + ($.default /.char)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/jvm/type/category.lux b/stdlib/source/documentation/lux/meta/target/jvm/type/category.lux new file mode 100644 index 000000000..123041fcb --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/jvm/type/category.lux @@ -0,0 +1,30 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Method) + ($.default /.Return') + ($.default /.Value') + ($.default /.Return) + ($.default /.Value) + ($.default /.Void) + ($.default /.Object) + ($.default /.Parameter) + ($.default /.Primitive) + ($.default /.Var) + ($.default /.Class) + ($.default /.Array) + ($.default /.Declaration)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/jvm/type/descriptor.lux b/stdlib/source/documentation/lux/meta/target/jvm/type/descriptor.lux new file mode 100644 index 000000000..8a484151c --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/jvm/type/descriptor.lux @@ -0,0 +1,42 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Descriptor) + ($.default /.descriptor) + ($.default /.void) + ($.default /.boolean) + ($.default /.byte) + ($.default /.short) + ($.default /.int) + ($.default /.long) + ($.default /.float) + ($.default /.double) + ($.default /.char) + ($.default /.class_prefix) + ($.default /.class_suffix) + ($.default /.class) + ($.default /.declaration) + ($.default /.as_class) + ($.default /.var) + ($.default /.wildcard) + ($.default /.lower) + ($.default /.upper) + ($.default /.array_prefix) + ($.default /.array) + ($.default /.method) + ($.default /.equivalence) + ($.default /.class_name)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/jvm/type/lux.lux b/stdlib/source/documentation/lux/meta/target/jvm/type/lux.lux new file mode 100644 index 000000000..408b5c6f4 --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/jvm/type/lux.lux @@ -0,0 +1,28 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Lower) + ($.default /.Upper) + ($.default /.Mapping) + ($.default /.fresh) + ($.default /.unknown_var) + ($.default /.class) + ($.default /.type) + ($.default /.boxed_type) + ($.default /.return) + ($.default /.boxed_return) + ($.default /.check)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/jvm/type/parser.lux b/stdlib/source/documentation/lux/meta/target/jvm/type/parser.lux new file mode 100644 index 000000000..81e9d4bee --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/jvm/type/parser.lux @@ -0,0 +1,53 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.void) + ($.default /.boolean) + ($.default /.byte) + ($.default /.short) + ($.default /.int) + ($.default /.long) + ($.default /.float) + ($.default /.double) + ($.default /.char) + ($.default /.wildcard) + ($.default /.primitive) + ($.default /.class_name) + ($.default /.var_name) + ($.default /.var') + ($.default /.var) + ($.default /.var?) + ($.default /.name) + ($.default /.parameter) + ($.default /.array') + ($.default /.class) + ($.default /.lower?) + ($.default /.upper?) + ($.default /.read_class) + ($.default /.value) + ($.default /.array) + ($.default /.object) + ($.default /.return) + ($.default /.method) + ($.default /.array?) + ($.default /.class?) + ($.default /.primitive?) + ($.default /.wildcard?) + ($.default /.parameter?) + ($.default /.object?) + ($.default /.declaration') + ($.default /.declaration)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/jvm/type/reflection.lux b/stdlib/source/documentation/lux/meta/target/jvm/type/reflection.lux new file mode 100644 index 000000000..64ecb135c --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/jvm/type/reflection.lux @@ -0,0 +1,37 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Reflection) + ($.default /.reflection) + ($.default /.equivalence) + ($.default /.void) + ($.default /.boolean) + ($.default /.byte) + ($.default /.short) + ($.default /.int) + ($.default /.long) + ($.default /.float) + ($.default /.double) + ($.default /.char) + ($.default /.class) + ($.default /.declaration) + ($.default /.as_class) + ($.default /.array) + ($.default /.var) + ($.default /.wildcard) + ($.default /.lower) + ($.default /.upper)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/jvm/type/signature.lux b/stdlib/source/documentation/lux/meta/target/jvm/type/signature.lux new file mode 100644 index 000000000..8991f34ee --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/jvm/type/signature.lux @@ -0,0 +1,48 @@ +(.require + [library + [lux (.except char) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Signature) + ($.default /.signature) + ($.default /.void) + ($.default /.boolean) + ($.default /.byte) + ($.default /.short) + ($.default /.int) + ($.default /.long) + ($.default /.float) + ($.default /.double) + ($.default /.char) + ($.default /.array) + ($.default /.wildcard) + ($.default /.var_prefix) + ($.default /.var) + ($.default /.var_name) + ($.default /.lower_prefix) + ($.default /.upper_prefix) + ($.default /.lower) + ($.default /.upper) + ($.default /.parameters_start) + ($.default /.parameters_end) + ($.default /.class) + ($.default /.declaration) + ($.default /.as_class) + ($.default /.arguments_start) + ($.default /.arguments_end) + ($.default /.exception_prefix) + ($.default /.method) + ($.default /.equivalence) + ($.default /.hash)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/lua.lux b/stdlib/source/documentation/lux/meta/target/lua.lux new file mode 100644 index 000000000..dbbd515a5 --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/lua.lux @@ -0,0 +1,92 @@ +(.require + [library + [lux (.except) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Code) + ($.default /.equivalence) + ($.default /.hash) + ($.default /.manual) + ($.default /.code) + ($.default /.Expression) + ($.default /.Computation) + ($.default /.Location) + ($.default /.Statement) + ($.default /.Literal) + ($.default /.Var) + ($.default /.Access) + ($.default /.Label) + ($.default /.nil) + ($.default /.boolean) + ($.default /.int) + ($.default /.float) + ($.default /.string) + ($.default /.multi) + ($.default /.array) + ($.default /.table) + ($.default /.item) + ($.default /.the) + ($.default /.length) + ($.default /.apply) + ($.default /.do) + ($.default /.=) + ($.default /.<) + ($.default /.<=) + ($.default /.>) + ($.default /.>=) + ($.default /.+) + ($.default /.-) + ($.default /.*) + ($.default /.^) + ($.default /./) + ($.default /.//) + ($.default /.%) + ($.default /.concat) + ($.default /.or) + ($.default /.and) + ($.default /.bit_or) + ($.default /.bit_and) + ($.default /.bit_xor) + ($.default /.bit_shl) + ($.default /.bit_shr) + ($.default /.not) + ($.default /.opposite) + ($.default /.var) + ($.default /.label) + ($.default /.statement) + ($.default /.then) + ($.default /.local) + ($.default /.set) + ($.default /.let) + ($.default /.local/1) + ($.default /.if) + ($.default /.when) + ($.default /.while) + ($.default /.repeat) + ($.default /.for_in) + ($.default /.for_step) + ($.default /.return) + ($.default /.closure) + ($.default /.function) + ($.default /.local_function) + ($.default /.break) + ($.default /.set_label) + ($.default /.go_to) + ($.default /.error/1) + ($.default /.print/1) + ($.default /.require/1) + ($.default /.type/1) + ($.default /.ipairs/1) + ($.default /.error/2)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/python.lux b/stdlib/source/documentation/lux/meta/target/python.lux new file mode 100644 index 000000000..c531707ae --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/python.lux @@ -0,0 +1,112 @@ +(.require + [library + [lux (.except) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Code) + ($.default /.equivalence) + ($.default /.hash) + ($.default /.manual) + ($.default /.code) + ($.default /.Expression) + ($.default /.Computation) + ($.default /.Location) + ($.default /.Var) + ($.default /.Statement) + ($.default /.Literal) + ($.default /.Access) + ($.default /.Loop) + ($.default /.SVar) + ($.default /.Single) + ($.default /.PVar) + ($.default /.Poly) + ($.default /.KVar) + ($.default /.Keyword) + ($.default /.var) + ($.default /.poly) + ($.default /.keyword) + ($.default /.none) + ($.default /.bool) + ($.default /.int) + ($.default /.long) + ($.default /.float) + ($.default /.string) + ($.default /.unicode) + ($.default /.tuple) + ($.default /.list) + ($.default /.slice) + ($.default /.slice_from) + ($.default /.dict) + ($.default /.apply) + ($.default /.splat_poly) + ($.default /.splat_keyword) + ($.default /.the) + ($.default /.do) + ($.default /.item) + ($.default /.?) + ($.default /.is) + ($.default /.=) + ($.default /.<) + ($.default /.<=) + ($.default /.>) + ($.default /.>=) + ($.default /.+) + ($.default /.-) + ($.default /.*) + ($.default /./) + ($.default /.//) + ($.default /.%) + ($.default /.**) + ($.default /.bit_or) + ($.default /.bit_and) + ($.default /.bit_xor) + ($.default /.bit_shl) + ($.default /.bit_shr) + ($.default /.or) + ($.default /.and) + ($.default /.not) + ($.default /.opposite) + ($.default /.lambda) + ($.default /.set) + ($.default /.delete) + ($.default /.if) + ($.default /.when) + ($.default /.then) + ($.default /.break) + ($.default /.continue) + ($.default /.while) + ($.default /.for_in) + ($.default /.statement) + ($.default /.pass) + ($.default /.Except) + ($.default /.try) + ($.default /.raise) + ($.default /.return) + ($.default /.print) + ($.default /.exec) + ($.default /.def) + ($.default /.import) + ($.default /.comment) + ($.default /.str/1) + ($.default /.ord/1) + ($.default /.float/1) + ($.default /.int/1) + ($.default /.len/1) + ($.default /.chr/1) + ($.default /.unichr/1) + ($.default /.unicode/1) + ($.default /.repr/1) + ($.default /.__import__/1) + ($.default /.Exception/1)] + [])) diff --git a/stdlib/source/documentation/lux/meta/target/ruby.lux b/stdlib/source/documentation/lux/meta/target/ruby.lux new file mode 100644 index 000000000..a678fe81b --- /dev/null +++ b/stdlib/source/documentation/lux/meta/target/ruby.lux @@ -0,0 +1,113 @@ +(.require + [library + [lux (.except) + ["$" documentation] + [data + [text (.only \n) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]]]] + [\\library + ["[0]" /]]) + +(.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.Code) + ($.default /.equivalence) + ($.default /.hash) + ($.default /.manual) + ($.default /.code) + ($.default /.Expression) + ($.default /.Computation) + ($.default /.Location) + ($.default /.Var) + ($.default /.LVar) + ($.default /.Statement) + ($.default /.Literal) + ($.default /.Access) + ($.default /.GVar) + ($.default /.IVar) + ($.default /.SVar) + ($.default /.LVar*) + ($.default /.LVar**) + ($.default /.global) + ($.default /.instance) + ($.default /.static) + ($.default /.local) + ($.default /.variadic) + ($.default /.splat) + ($.default /.variadic_kv) + ($.default /.double_splat) + ($.default /.latest_error_message) + ($.default /.latest_error_location) + ($.default /.last_string_read) + ($.default /.last_line_number_read) + ($.default /.last_string_matched) + ($.default /.last_regexp_match) + ($.default /.case_insensitivity_flag) + ($.default /.input_record_separator) + ($.default /.output_record_separator) + ($.default /.script_name) + ($.default /.process_id) + ($.default /.exit_status) + ($.default /.command_line_arguments) + ($.default /.nil) + ($.default /.bool) + ($.default /.int) + ($.default /.string) + ($.default /.symbol) + ($.default /.float) + ($.default /.array_range) + ($.default /.array) + ($.default /.hash) + ($.default /.apply) + ($.default /.apply_lambda) + ($.default /.the) + ($.default /.item) + ($.default /.?) + ($.default /.statement) + ($.default /.then) + ($.default /.set) + ($.default /.if) + ($.default /.when) + ($.default /.while) + ($.default /.for_in) + ($.default /.Rescue) + ($.default /.begin) + ($.default /.catch) + ($.default /.return) + ($.default /.raise) + ($.default /.next) + ($.default /.redo) + ($.default /.break) + ($.default /.function) + ($.default /.lambda) + ($.default /.=) + ($.default /.<) + ($.default /.<=) + ($.default /.>) + ($.default /.>=) + ($.default /.+) + ($.default /.-) + ($.default /.*) + ($.default /./) + ($.default /.%) + ($.default /.pow) + ($.default /.or) + ($.default /.and) + ($.default /.bit_or) + ($.default /.bit_and) + ($.default /.bit_xor) + ($.default /.bit_shl) + ($.default /.bit_shr) + ($.default /.not) + ($.default /.opposite) + ($.default /.comment) + ($.default /.do) + ($.default /.print/1) + ($.default /.require/1) + ($.default /.print/2) + ($.default /.throw/1)] + [])) diff --git a/stdlib/source/documentation/lux/target.lux b/stdlib/source/documentation/lux/target.lux deleted file mode 100644 index a10a6e3f5..000000000 --- a/stdlib/source/documentation/lux/target.lux +++ /dev/null @@ -1,41 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]] - ["[0]" / - ["[1][0]" js] - ["[1][0]" jvm/type] - ["[1][0]" lua] - ["[1][0]" python] - ["[1][0]" ruby]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.old) - ($.default /.js) - ($.default /.jvm) - ($.default /.lua) - ($.default /.python) - ($.default /.ruby) - ($.default /.common_lisp) - ($.default /.php) - ($.default /.r) - ($.default /.scheme) - - ($.documentation /.Target - (format "The name/ID of a platform targetted by a Lux compiler." - \n "This information can be used to generate code targetting specific platforms, and to make programs cross-platform."))] - [/js.documentation - /jvm/type.documentation - /lua.documentation - /python.documentation - /ruby.documentation])) diff --git a/stdlib/source/documentation/lux/target/js.lux b/stdlib/source/documentation/lux/target/js.lux deleted file mode 100644 index 68f67d560..000000000 --- a/stdlib/source/documentation/lux/target/js.lux +++ /dev/null @@ -1,97 +0,0 @@ -(.require - [library - [lux (.except) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Code) - ($.default /.code) - ($.default /.Expression) - ($.default /.Computation) - ($.default /.Location) - ($.default /.Statement) - ($.default /.Var) - ($.default /.Access) - ($.default /.Literal) - ($.default /.Loop) - ($.default /.Label) - ($.default /.null) - ($.default /.undefined) - ($.default /.boolean) - ($.default /.number) - ($.default /.string) - ($.default /.array) - ($.default /.var) - ($.default /.at) - ($.default /.the) - ($.default /.apply) - ($.default /.do) - ($.default /.object) - ($.default /.,) - ($.default /.then) - ($.default /.function_definition) - ($.default /.function) - ($.default /.closure) - ($.default /.=) - ($.default /.<) - ($.default /.<=) - ($.default /.>) - ($.default /.>=) - ($.default /.+) - ($.default /.-) - ($.default /.*) - ($.default /./) - ($.default /.%) - ($.default /.left_shift) - ($.default /.arithmetic_right_shift) - ($.default /.logic_right_shift) - ($.default /.or) - ($.default /.and) - ($.default /.bit_xor) - ($.default /.bit_or) - ($.default /.bit_and) - ($.default /.not) - ($.default /.bit_not) - ($.default /.opposite) - ($.default /.to_i32) - ($.default /.i32) - ($.default /.int) - ($.default /.?) - ($.default /.type_of) - ($.default /.new) - ($.default /.statement) - ($.default /.use_strict) - ($.default /.declare) - ($.default /.define) - ($.default /.set) - ($.default /.throw) - ($.default /.return) - ($.default /.delete) - ($.default /.if) - ($.default /.when) - ($.default /.while) - ($.default /.do_while) - ($.default /.try) - ($.default /.for) - ($.default /.label) - ($.default /.with_label) - ($.default /.break) - ($.default /.break_at) - ($.default /.continue) - ($.default /.continue_at) - ($.default /.++) - ($.default /.--) - ($.default /.comment) - ($.default /.switch) - ($.default /.not_a_number?)] - [])) diff --git a/stdlib/source/documentation/lux/target/jvm/type.lux b/stdlib/source/documentation/lux/target/jvm/type.lux deleted file mode 100644 index 39bded852..000000000 --- a/stdlib/source/documentation/lux/target/jvm/type.lux +++ /dev/null @@ -1,64 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]] - ["[0]" / - ["[1][0]" alias] - ["[1][0]" box] - ["[1][0]" category] - ["[1][0]" descriptor] - ["[1][0]" lux] - ["[1][0]" parser] - ["[1][0]" reflection] - ["[1][0]" signature]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Type) - ($.default /.Argument) - ($.default /.Typed) - ($.default /.Constraint) - ($.default /.signature) - ($.default /.descriptor) - ($.default /.reflection) - ($.default /.void) - ($.default /.boolean) - ($.default /.byte) - ($.default /.short) - ($.default /.int) - ($.default /.long) - ($.default /.float) - ($.default /.double) - ($.default /.char) - ($.default /.array) - ($.default /.class) - ($.default /.declaration) - ($.default /.as_class) - ($.default /.wildcard) - ($.default /.var) - ($.default /.lower) - ($.default /.upper) - ($.default /.method) - ($.default /.equivalence) - ($.default /.hash) - ($.default /.primitive?) - ($.default /.void?) - ($.default /.class?) - ($.default /.format)] - [/alias.documentation - /box.documentation - /category.documentation - /descriptor.documentation - /lux.documentation - /parser.documentation - /reflection.documentation - /signature.documentation])) diff --git a/stdlib/source/documentation/lux/target/jvm/type/alias.lux b/stdlib/source/documentation/lux/target/jvm/type/alias.lux deleted file mode 100644 index d8e17f39a..000000000 --- a/stdlib/source/documentation/lux/target/jvm/type/alias.lux +++ /dev/null @@ -1,20 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Aliasing) - ($.default /.fresh) - ($.default /.method)] - [])) diff --git a/stdlib/source/documentation/lux/target/jvm/type/box.lux b/stdlib/source/documentation/lux/target/jvm/type/box.lux deleted file mode 100644 index 1f393eb2e..000000000 --- a/stdlib/source/documentation/lux/target/jvm/type/box.lux +++ /dev/null @@ -1,25 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.boolean) - ($.default /.byte) - ($.default /.short) - ($.default /.int) - ($.default /.long) - ($.default /.float) - ($.default /.double) - ($.default /.char)] - [])) diff --git a/stdlib/source/documentation/lux/target/jvm/type/category.lux b/stdlib/source/documentation/lux/target/jvm/type/category.lux deleted file mode 100644 index 123041fcb..000000000 --- a/stdlib/source/documentation/lux/target/jvm/type/category.lux +++ /dev/null @@ -1,30 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Method) - ($.default /.Return') - ($.default /.Value') - ($.default /.Return) - ($.default /.Value) - ($.default /.Void) - ($.default /.Object) - ($.default /.Parameter) - ($.default /.Primitive) - ($.default /.Var) - ($.default /.Class) - ($.default /.Array) - ($.default /.Declaration)] - [])) diff --git a/stdlib/source/documentation/lux/target/jvm/type/descriptor.lux b/stdlib/source/documentation/lux/target/jvm/type/descriptor.lux deleted file mode 100644 index 8a484151c..000000000 --- a/stdlib/source/documentation/lux/target/jvm/type/descriptor.lux +++ /dev/null @@ -1,42 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Descriptor) - ($.default /.descriptor) - ($.default /.void) - ($.default /.boolean) - ($.default /.byte) - ($.default /.short) - ($.default /.int) - ($.default /.long) - ($.default /.float) - ($.default /.double) - ($.default /.char) - ($.default /.class_prefix) - ($.default /.class_suffix) - ($.default /.class) - ($.default /.declaration) - ($.default /.as_class) - ($.default /.var) - ($.default /.wildcard) - ($.default /.lower) - ($.default /.upper) - ($.default /.array_prefix) - ($.default /.array) - ($.default /.method) - ($.default /.equivalence) - ($.default /.class_name)] - [])) diff --git a/stdlib/source/documentation/lux/target/jvm/type/lux.lux b/stdlib/source/documentation/lux/target/jvm/type/lux.lux deleted file mode 100644 index 408b5c6f4..000000000 --- a/stdlib/source/documentation/lux/target/jvm/type/lux.lux +++ /dev/null @@ -1,28 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Lower) - ($.default /.Upper) - ($.default /.Mapping) - ($.default /.fresh) - ($.default /.unknown_var) - ($.default /.class) - ($.default /.type) - ($.default /.boxed_type) - ($.default /.return) - ($.default /.boxed_return) - ($.default /.check)] - [])) diff --git a/stdlib/source/documentation/lux/target/jvm/type/parser.lux b/stdlib/source/documentation/lux/target/jvm/type/parser.lux deleted file mode 100644 index 81e9d4bee..000000000 --- a/stdlib/source/documentation/lux/target/jvm/type/parser.lux +++ /dev/null @@ -1,53 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.void) - ($.default /.boolean) - ($.default /.byte) - ($.default /.short) - ($.default /.int) - ($.default /.long) - ($.default /.float) - ($.default /.double) - ($.default /.char) - ($.default /.wildcard) - ($.default /.primitive) - ($.default /.class_name) - ($.default /.var_name) - ($.default /.var') - ($.default /.var) - ($.default /.var?) - ($.default /.name) - ($.default /.parameter) - ($.default /.array') - ($.default /.class) - ($.default /.lower?) - ($.default /.upper?) - ($.default /.read_class) - ($.default /.value) - ($.default /.array) - ($.default /.object) - ($.default /.return) - ($.default /.method) - ($.default /.array?) - ($.default /.class?) - ($.default /.primitive?) - ($.default /.wildcard?) - ($.default /.parameter?) - ($.default /.object?) - ($.default /.declaration') - ($.default /.declaration)] - [])) diff --git a/stdlib/source/documentation/lux/target/jvm/type/reflection.lux b/stdlib/source/documentation/lux/target/jvm/type/reflection.lux deleted file mode 100644 index 64ecb135c..000000000 --- a/stdlib/source/documentation/lux/target/jvm/type/reflection.lux +++ /dev/null @@ -1,37 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Reflection) - ($.default /.reflection) - ($.default /.equivalence) - ($.default /.void) - ($.default /.boolean) - ($.default /.byte) - ($.default /.short) - ($.default /.int) - ($.default /.long) - ($.default /.float) - ($.default /.double) - ($.default /.char) - ($.default /.class) - ($.default /.declaration) - ($.default /.as_class) - ($.default /.array) - ($.default /.var) - ($.default /.wildcard) - ($.default /.lower) - ($.default /.upper)] - [])) diff --git a/stdlib/source/documentation/lux/target/jvm/type/signature.lux b/stdlib/source/documentation/lux/target/jvm/type/signature.lux deleted file mode 100644 index 8991f34ee..000000000 --- a/stdlib/source/documentation/lux/target/jvm/type/signature.lux +++ /dev/null @@ -1,48 +0,0 @@ -(.require - [library - [lux (.except char) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Signature) - ($.default /.signature) - ($.default /.void) - ($.default /.boolean) - ($.default /.byte) - ($.default /.short) - ($.default /.int) - ($.default /.long) - ($.default /.float) - ($.default /.double) - ($.default /.char) - ($.default /.array) - ($.default /.wildcard) - ($.default /.var_prefix) - ($.default /.var) - ($.default /.var_name) - ($.default /.lower_prefix) - ($.default /.upper_prefix) - ($.default /.lower) - ($.default /.upper) - ($.default /.parameters_start) - ($.default /.parameters_end) - ($.default /.class) - ($.default /.declaration) - ($.default /.as_class) - ($.default /.arguments_start) - ($.default /.arguments_end) - ($.default /.exception_prefix) - ($.default /.method) - ($.default /.equivalence) - ($.default /.hash)] - [])) diff --git a/stdlib/source/documentation/lux/target/lua.lux b/stdlib/source/documentation/lux/target/lua.lux deleted file mode 100644 index dbbd515a5..000000000 --- a/stdlib/source/documentation/lux/target/lua.lux +++ /dev/null @@ -1,92 +0,0 @@ -(.require - [library - [lux (.except) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Code) - ($.default /.equivalence) - ($.default /.hash) - ($.default /.manual) - ($.default /.code) - ($.default /.Expression) - ($.default /.Computation) - ($.default /.Location) - ($.default /.Statement) - ($.default /.Literal) - ($.default /.Var) - ($.default /.Access) - ($.default /.Label) - ($.default /.nil) - ($.default /.boolean) - ($.default /.int) - ($.default /.float) - ($.default /.string) - ($.default /.multi) - ($.default /.array) - ($.default /.table) - ($.default /.item) - ($.default /.the) - ($.default /.length) - ($.default /.apply) - ($.default /.do) - ($.default /.=) - ($.default /.<) - ($.default /.<=) - ($.default /.>) - ($.default /.>=) - ($.default /.+) - ($.default /.-) - ($.default /.*) - ($.default /.^) - ($.default /./) - ($.default /.//) - ($.default /.%) - ($.default /.concat) - ($.default /.or) - ($.default /.and) - ($.default /.bit_or) - ($.default /.bit_and) - ($.default /.bit_xor) - ($.default /.bit_shl) - ($.default /.bit_shr) - ($.default /.not) - ($.default /.opposite) - ($.default /.var) - ($.default /.label) - ($.default /.statement) - ($.default /.then) - ($.default /.local) - ($.default /.set) - ($.default /.let) - ($.default /.local/1) - ($.default /.if) - ($.default /.when) - ($.default /.while) - ($.default /.repeat) - ($.default /.for_in) - ($.default /.for_step) - ($.default /.return) - ($.default /.closure) - ($.default /.function) - ($.default /.local_function) - ($.default /.break) - ($.default /.set_label) - ($.default /.go_to) - ($.default /.error/1) - ($.default /.print/1) - ($.default /.require/1) - ($.default /.type/1) - ($.default /.ipairs/1) - ($.default /.error/2)] - [])) diff --git a/stdlib/source/documentation/lux/target/python.lux b/stdlib/source/documentation/lux/target/python.lux deleted file mode 100644 index c531707ae..000000000 --- a/stdlib/source/documentation/lux/target/python.lux +++ /dev/null @@ -1,112 +0,0 @@ -(.require - [library - [lux (.except) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Code) - ($.default /.equivalence) - ($.default /.hash) - ($.default /.manual) - ($.default /.code) - ($.default /.Expression) - ($.default /.Computation) - ($.default /.Location) - ($.default /.Var) - ($.default /.Statement) - ($.default /.Literal) - ($.default /.Access) - ($.default /.Loop) - ($.default /.SVar) - ($.default /.Single) - ($.default /.PVar) - ($.default /.Poly) - ($.default /.KVar) - ($.default /.Keyword) - ($.default /.var) - ($.default /.poly) - ($.default /.keyword) - ($.default /.none) - ($.default /.bool) - ($.default /.int) - ($.default /.long) - ($.default /.float) - ($.default /.string) - ($.default /.unicode) - ($.default /.tuple) - ($.default /.list) - ($.default /.slice) - ($.default /.slice_from) - ($.default /.dict) - ($.default /.apply) - ($.default /.splat_poly) - ($.default /.splat_keyword) - ($.default /.the) - ($.default /.do) - ($.default /.item) - ($.default /.?) - ($.default /.is) - ($.default /.=) - ($.default /.<) - ($.default /.<=) - ($.default /.>) - ($.default /.>=) - ($.default /.+) - ($.default /.-) - ($.default /.*) - ($.default /./) - ($.default /.//) - ($.default /.%) - ($.default /.**) - ($.default /.bit_or) - ($.default /.bit_and) - ($.default /.bit_xor) - ($.default /.bit_shl) - ($.default /.bit_shr) - ($.default /.or) - ($.default /.and) - ($.default /.not) - ($.default /.opposite) - ($.default /.lambda) - ($.default /.set) - ($.default /.delete) - ($.default /.if) - ($.default /.when) - ($.default /.then) - ($.default /.break) - ($.default /.continue) - ($.default /.while) - ($.default /.for_in) - ($.default /.statement) - ($.default /.pass) - ($.default /.Except) - ($.default /.try) - ($.default /.raise) - ($.default /.return) - ($.default /.print) - ($.default /.exec) - ($.default /.def) - ($.default /.import) - ($.default /.comment) - ($.default /.str/1) - ($.default /.ord/1) - ($.default /.float/1) - ($.default /.int/1) - ($.default /.len/1) - ($.default /.chr/1) - ($.default /.unichr/1) - ($.default /.unicode/1) - ($.default /.repr/1) - ($.default /.__import__/1) - ($.default /.Exception/1)] - [])) diff --git a/stdlib/source/documentation/lux/target/ruby.lux b/stdlib/source/documentation/lux/target/ruby.lux deleted file mode 100644 index a678fe81b..000000000 --- a/stdlib/source/documentation/lux/target/ruby.lux +++ /dev/null @@ -1,113 +0,0 @@ -(.require - [library - [lux (.except) - ["$" documentation] - [data - [text (.only \n) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]]]] - [\\library - ["[0]" /]]) - -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [($.default /.Code) - ($.default /.equivalence) - ($.default /.hash) - ($.default /.manual) - ($.default /.code) - ($.default /.Expression) - ($.default /.Computation) - ($.default /.Location) - ($.default /.Var) - ($.default /.LVar) - ($.default /.Statement) - ($.default /.Literal) - ($.default /.Access) - ($.default /.GVar) - ($.default /.IVar) - ($.default /.SVar) - ($.default /.LVar*) - ($.default /.LVar**) - ($.default /.global) - ($.default /.instance) - ($.default /.static) - ($.default /.local) - ($.default /.variadic) - ($.default /.splat) - ($.default /.variadic_kv) - ($.default /.double_splat) - ($.default /.latest_error_message) - ($.default /.latest_error_location) - ($.default /.last_string_read) - ($.default /.last_line_number_read) - ($.default /.last_string_matched) - ($.default /.last_regexp_match) - ($.default /.case_insensitivity_flag) - ($.default /.input_record_separator) - ($.default /.output_record_separator) - ($.default /.script_name) - ($.default /.process_id) - ($.default /.exit_status) - ($.default /.command_line_arguments) - ($.default /.nil) - ($.default /.bool) - ($.default /.int) - ($.default /.string) - ($.default /.symbol) - ($.default /.float) - ($.default /.array_range) - ($.default /.array) - ($.default /.hash) - ($.default /.apply) - ($.default /.apply_lambda) - ($.default /.the) - ($.default /.item) - ($.default /.?) - ($.default /.statement) - ($.default /.then) - ($.default /.set) - ($.default /.if) - ($.default /.when) - ($.default /.while) - ($.default /.for_in) - ($.default /.Rescue) - ($.default /.begin) - ($.default /.catch) - ($.default /.return) - ($.default /.raise) - ($.default /.next) - ($.default /.redo) - ($.default /.break) - ($.default /.function) - ($.default /.lambda) - ($.default /.=) - ($.default /.<) - ($.default /.<=) - ($.default /.>) - ($.default /.>=) - ($.default /.+) - ($.default /.-) - ($.default /.*) - ($.default /./) - ($.default /.%) - ($.default /.pow) - ($.default /.or) - ($.default /.and) - ($.default /.bit_or) - ($.default /.bit_and) - ($.default /.bit_xor) - ($.default /.bit_shl) - ($.default /.bit_shr) - ($.default /.not) - ($.default /.opposite) - ($.default /.comment) - ($.default /.do) - ($.default /.print/1) - ($.default /.require/1) - ($.default /.print/2) - ($.default /.throw/1)] - [])) diff --git a/stdlib/source/library/lux/abstract/apply.lux b/stdlib/source/library/lux/abstract/apply.lux index 708441991..05827b9a9 100644 --- a/stdlib/source/library/lux/abstract/apply.lux +++ b/stdlib/source/library/lux/abstract/apply.lux @@ -1,7 +1,8 @@ (.require [library [lux (.except) - ["@" target]]] + [meta + ["@" 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 4ba43632f..2a7fec64c 100644 --- a/stdlib/source/library/lux/control/concurrency/atom.lux +++ b/stdlib/source/library/lux/control/concurrency/atom.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except) - ["@" target] ["[0]" ffi] [abstract [monad (.only do)]] @@ -14,6 +13,7 @@ ["[0]" array ["[1]" \\unsafe]]]] [meta + ["@" target] [type [primitive (.except)] ["[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 a9563b79d..5fb0f883b 100644 --- a/stdlib/source/library/lux/control/concurrency/thread.lux +++ b/stdlib/source/library/lux/control/concurrency/thread.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except) - ["@" target] ["[0]" ffi] [abstract ["[0]" monad (.only do)]] @@ -18,6 +17,7 @@ ["n" nat] ["f" frac]]] [meta + ["@" target] ["[0]" configuration]] [time ["[0]" instant]]]] diff --git a/stdlib/source/library/lux/control/reader.lux b/stdlib/source/library/lux/control/reader.lux index aa15befa8..5a657143e 100644 --- a/stdlib/source/library/lux/control/reader.lux +++ b/stdlib/source/library/lux/control/reader.lux @@ -1,11 +1,12 @@ (.require [library [lux (.except local with) - ["@" target] [abstract [apply (.only Apply)] ["[0]" functor (.only Functor)] - ["[0]" monad (.only Monad do)]]]]) + ["[0]" monad (.only Monad do)]] + [meta + ["@" target]]]]) (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 0b43c9344..665db5232 100644 --- a/stdlib/source/library/lux/control/thread.lux +++ b/stdlib/source/library/lux/control/thread.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except) - ["@" target] [abstract [functor (.only Functor)] [apply (.only Apply)] @@ -13,6 +12,7 @@ ["[0]" array ["[1]" \\unsafe (.only Array)]]]] [meta + ["@" target] [type [primitive (.except)] ["[0]" variance (.only Mutable)]]]]]) diff --git a/stdlib/source/library/lux/control/try.lux b/stdlib/source/library/lux/control/try.lux index fe17409a2..ca2010ce8 100644 --- a/stdlib/source/library/lux/control/try.lux +++ b/stdlib/source/library/lux/control/try.lux @@ -1,13 +1,13 @@ (.require [library [lux (.except with) - ["@" target] [abstract [apply (.only Apply)] [equivalence (.only Equivalence)] ["[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 c1c52b904..f55b31354 100644 --- a/stdlib/source/library/lux/control/writer.lux +++ b/stdlib/source/library/lux/control/writer.lux @@ -1,12 +1,13 @@ (.require [library [lux (.except with) - ["@" target] [abstract [monoid (.only Monoid)] [apply (.only Apply)] ["[0]" functor (.only Functor)] - ["[0]" monad (.only Monad do)]]]]) + ["[0]" monad (.only Monad do)]] + [meta + ["@" 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 c6e0f8587..dca6d6ec4 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except revised all only with) - ["@" target] [abstract [monoid (.only Monoid)] [apply (.only Apply)] @@ -19,7 +18,9 @@ ["[0]" product]] [math [number - ["n" nat]]]]]) + ["n" nat]]] + [meta + ["@" 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 e24e762d2..2b2f92b94 100644 --- a/stdlib/source/library/lux/data/collection/sequence.lux +++ b/stdlib/source/library/lux/data/collection/sequence.lux @@ -4,7 +4,6 @@ (.require [library [lux (.except list has revised only) - ["@" target] [abstract [functor (.only Functor)] [apply (.only Apply)] @@ -30,6 +29,7 @@ ["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 2ddc54d22..1e403280e 100644 --- a/stdlib/source/library/lux/data/collection/tree/zipper.lux +++ b/stdlib/source/library/lux/data/collection/tree/zipper.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except left right) - ["@" target] [abstract [functor (.only Functor)] [comonad (.only CoMonad)] @@ -14,7 +13,9 @@ [text ["%" \\format (.only format)]] [collection - ["[0]" list (.use "[1]#[0]" functor monoid)]]]]] + ["[0]" list (.use "[1]#[0]" functor monoid)]]] + [meta + ["@" target]]]] ["[0]" // (.only Tree) (.use "[1]#[0]" functor)]) (type (Family Zipper a) diff --git a/stdlib/source/library/lux/data/format/css/class.lux b/stdlib/source/library/lux/data/format/css/class.lux index b7bc2409e..c0bdf1dd5 100644 --- a/stdlib/source/library/lux/data/format/css/class.lux +++ b/stdlib/source/library/lux/data/format/css/class.lux @@ -1,13 +1,12 @@ (.require [library [lux (.except) - ["[0]" meta] [abstract [monad (.only do)]] [data ["[0]" text (.use "[1]#[0]" hash) ["%" \\format (.only format)]]] - [meta + ["[0]" meta (.only) ["[0]" code] [macro [syntax (.only syntax)]] diff --git a/stdlib/source/library/lux/data/format/css/id.lux b/stdlib/source/library/lux/data/format/css/id.lux index 637e9915e..dc8cc80dc 100644 --- a/stdlib/source/library/lux/data/format/css/id.lux +++ b/stdlib/source/library/lux/data/format/css/id.lux @@ -1,13 +1,12 @@ (.require [library [lux (.except) - ["[0]" meta] [abstract [monad (.only do)]] [data ["[0]" text (.use "[1]#[0]" hash) ["%" \\format (.only format)]]] - [meta + ["[0]" meta (.only) ["[0]" code] [macro [syntax (.only syntax)]] diff --git a/stdlib/source/library/lux/data/format/html.lux b/stdlib/source/library/lux/data/format/html.lux index 0bdc6984b..15d20bb2d 100644 --- a/stdlib/source/library/lux/data/format/html.lux +++ b/stdlib/source/library/lux/data/format/html.lux @@ -13,10 +13,10 @@ [meta [macro ["[0]" template]] + [target + ["[0]" js]] [type [primitive (.except)]]] - [target - ["[0]" js]] [world [net (.only URL)]]]] [// diff --git a/stdlib/source/library/lux/data/format/tar.lux b/stdlib/source/library/lux/data/format/tar.lux index e5924fa6e..8689701a7 100644 --- a/stdlib/source/library/lux/data/format/tar.lux +++ b/stdlib/source/library/lux/data/format/tar.lux @@ -237,17 +237,20 @@ (def (un_padded string) (-> Binary Binary) (case (binary!.size string) - 0 string - size (loop (again [end (-- size)]) - (case end - 0 (at utf8.codec encoded "") - _ (let [last_char (binary!.bits_8 end string)] - (`` (case (.nat last_char) - (char (,, (static ..null))) - (again (-- end)) - - _ - (binary!.slice 0 (++ end) string)))))))) + 0 + string + + size + (loop (again [end (-- size)]) + (case end + 0 (at utf8.codec encoded "") + _ (let [last_char (binary!.bits_8 end string)] + (`` (case (.nat last_char) + (char (,, (static ..null))) + (again (-- end)) + + _ + (binary!.slice 0 (++ end) string)))))))) (with_template [ ] [(primitive .public diff --git a/stdlib/source/library/lux/data/text.lux b/stdlib/source/library/lux/data/text.lux index 826afbb44..8b0547523 100644 --- a/stdlib/source/library/lux/data/text.lux +++ b/stdlib/source/library/lux/data/text.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except char) - ["@" target] [abstract [hash (.only Hash)] [monoid (.only Monoid)] @@ -19,6 +18,7 @@ ["n" nat] ["[0]" i64]]] [meta + ["@" target] [macro ["^" pattern]]]]]) diff --git a/stdlib/source/library/lux/data/text/buffer.lux b/stdlib/source/library/lux/data/text/buffer.lux index e8b4e496f..e9c7a0ec3 100644 --- a/stdlib/source/library/lux/data/text/buffer.lux +++ b/stdlib/source/library/lux/data/text/buffer.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except) - ["@" target] ["[0]" ffi (.only import)] [control ["[0]" function]] @@ -16,6 +15,7 @@ [number ["n" nat]]] [meta + ["@" target] [type [primitive (.except)]]]]] ["[0]" //]) diff --git a/stdlib/source/library/lux/data/text/encoding/utf8.lux b/stdlib/source/library/lux/data/text/encoding/utf8.lux index 4a90d20e4..d90d52a2a 100644 --- a/stdlib/source/library/lux/data/text/encoding/utf8.lux +++ b/stdlib/source/library/lux/data/text/encoding/utf8.lux @@ -1,14 +1,15 @@ (.require [library [lux (.except) - ["@" target] ["[0]" ffi] [abstract [codec (.only Codec)]] [control ["[0]" try (.only Try)]] [data - ["[0]" binary (.only Binary)]]]] + ["[0]" binary (.only Binary)]] + [meta + ["@" 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 2b27378b6..8031919ca 100644 --- a/stdlib/source/library/lux/debug.lux +++ b/stdlib/source/library/lux/debug.lux @@ -1,9 +1,7 @@ (.require [library [lux (.except private) - ["@" target] ["[0]" ffi (.only import)] - ["[0]" meta] [abstract ["[0]" monad (.only do)]] [control @@ -27,7 +25,8 @@ [ratio (.only Ratio)] ["n" nat] ["i" int]]] - [meta + ["[0]" meta (.only) + ["@" target] ["[0]" code (.only) ["<[1]>" \\parser]] [macro diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index 40db8e0c3..43fcd5c3c 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except Primitive Type int char is as type) - ["[0]" meta (.use "[1]#[0]" monad)] [abstract ["[0]" monad (.only do)]] [control @@ -22,7 +21,7 @@ [math [number ["n" nat]]] - [meta + ["[0]" meta (.use "[1]#[0]" monad) ["[0]" code (.only) ["<[1]>" \\parser(.only Parser)]] [macro (.only with_symbols) @@ -31,18 +30,18 @@ ["[0]" template] ["[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]]]]]]) + ["[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]]]]]]]) (def internal (-> External Text) diff --git a/stdlib/source/library/lux/ffi.lux b/stdlib/source/library/lux/ffi.lux index f145b56cb..fdbdde871 100644 --- a/stdlib/source/library/lux/ffi.lux +++ b/stdlib/source/library/lux/ffi.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except Symbol Alias Global global function type_of undefined) - ["[0]" meta] [abstract ["[0]" monad (.only do)]] [control @@ -15,16 +14,16 @@ ["%" \\format]] [collection ["[0]" list (.use "[1]#[0]" monad mix)]]] - [meta + ["[0]" meta (.only) ["[0]" code (.only) ["<[1]>" \\parser (.only Parser)]] ["[0]" macro (.only with_symbols) [syntax (.only syntax)] ["[0]" template]] [type - [primitive (.except)]]] - ["@" target (.only) - ["[0]" js]]]]) + [primitive (.except)]] + ["@" target (.only) + ["[0]" js]]]]]) (with_expansions [ (for @.js "js constant" @.python "python constant" diff --git a/stdlib/source/library/lux/ffi.php.lux b/stdlib/source/library/lux/ffi.php.lux index 87279aaf1..ecc9a836d 100644 --- a/stdlib/source/library/lux/ffi.php.lux +++ b/stdlib/source/library/lux/ffi.php.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except Alias) - ["@" target] [abstract [monad (.only do)]] [control @@ -15,6 +14,7 @@ [collection ["[0]" list (.use "[1]#[0]" functor)]]] ["[0]" meta (.only) + ["@" target] [type abstract] ["[0]" code (.only) diff --git a/stdlib/source/library/lux/ffi.scm.lux b/stdlib/source/library/lux/ffi.scm.lux index 7ba628f1d..602b72ea3 100644 --- a/stdlib/source/library/lux/ffi.scm.lux +++ b/stdlib/source/library/lux/ffi.scm.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except Alias) - ["@" target] [abstract [monad (.only do)]] [control @@ -15,6 +14,7 @@ [collection ["[0]" list (.use "[1]#[0]" functor)]]] ["[0]" meta (.only) + ["@" target] [type abstract] ["[0]" code (.only) diff --git a/stdlib/source/library/lux/ffi/export.js.lux b/stdlib/source/library/lux/ffi/export.js.lux index 67f97651d..d8f26b60d 100644 --- a/stdlib/source/library/lux/ffi/export.js.lux +++ b/stdlib/source/library/lux/ffi/export.js.lux @@ -19,9 +19,9 @@ ["[0]" code (.only) ["<[1]>" \\parser]] ["[0]" macro (.only) - [syntax (.only syntax)]]] - [target - ["/" js]] + [syntax (.only syntax)]] + [target + ["/" js]]] [tool [compiler ["[0]" phase] diff --git a/stdlib/source/library/lux/ffi/export.lua.lux b/stdlib/source/library/lux/ffi/export.lua.lux index 3d1b6e068..7f527112f 100644 --- a/stdlib/source/library/lux/ffi/export.lua.lux +++ b/stdlib/source/library/lux/ffi/export.lua.lux @@ -19,9 +19,9 @@ ["[0]" code (.only) ["<[1]>" \\parser]] ["[0]" macro (.only) - [syntax (.only syntax)]]] - [target - ["/" lua]] + [syntax (.only syntax)]] + [target + ["/" lua]]] [tool [compiler ["[0]" phase] diff --git a/stdlib/source/library/lux/ffi/export.py.lux b/stdlib/source/library/lux/ffi/export.py.lux index bbcc9c295..1ec506690 100644 --- a/stdlib/source/library/lux/ffi/export.py.lux +++ b/stdlib/source/library/lux/ffi/export.py.lux @@ -19,9 +19,9 @@ ["[0]" code (.only) ["<[1]>" \\parser]] ["[0]" macro (.only) - [syntax (.only syntax)]]] - [target - ["/" python]] + [syntax (.only syntax)]] + [target + ["/" python]]] [tool [compiler ["[0]" phase] diff --git a/stdlib/source/library/lux/ffi/export.rb.lux b/stdlib/source/library/lux/ffi/export.rb.lux index 56d67edca..674482154 100644 --- a/stdlib/source/library/lux/ffi/export.rb.lux +++ b/stdlib/source/library/lux/ffi/export.rb.lux @@ -21,9 +21,9 @@ ["[0]" code (.only) ["<[1]>" \\parser]] ["[0]" macro (.only) - [syntax (.only syntax)]]] - [target - ["/" ruby]] + [syntax (.only syntax)]] + [target + ["/" ruby]]] [tool [compiler ["[0]" phase] diff --git a/stdlib/source/library/lux/math.lux b/stdlib/source/library/lux/math.lux index eac02fe80..c01471596 100644 --- a/stdlib/source/library/lux/math.lux +++ b/stdlib/source/library/lux/math.lux @@ -2,7 +2,6 @@ [library [lux (.except) [extension (.only analysis)] - ["@" target] ["[0]" static] [abstract ["[0]" monad (.only do)]] @@ -16,6 +15,7 @@ [collection ["[0]" list (.use "[1]#[0]" mix)]]] [meta + ["@" target] ["[0]" code ["<[1]>" \\parser]] [macro diff --git a/stdlib/source/library/lux/math/number/frac.lux b/stdlib/source/library/lux/math/number/frac.lux index 4601d9ffa..fb2f1b85f 100644 --- a/stdlib/source/library/lux/math/number/frac.lux +++ b/stdlib/source/library/lux/math/number/frac.lux @@ -1,7 +1,6 @@ (.require [library [lux (.except nat int rev) - ["@" target] [abstract [hash (.only Hash)] [monoid (.only Monoid)] @@ -17,6 +16,7 @@ [data ["[0]" text]] [meta + ["@" target] [macro ["^" pattern]]]]] ["[0]" // diff --git a/stdlib/source/library/lux/meta/target.lux b/stdlib/source/library/lux/meta/target.lux new file mode 100644 index 000000000..11094325d --- /dev/null +++ b/stdlib/source/library/lux/meta/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/target/common_lisp.lux b/stdlib/source/library/lux/meta/target/common_lisp.lux new file mode 100644 index 000000000..b7ce2a7fb --- /dev/null +++ b/stdlib/source/library/lux/meta/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 + [primitive (.except)]]]]]) + +(def as_form + (-> Text Text) + (text.enclosed ["(" ")"])) + +(primitive .public (Code brand) + Text + + (def .public manual + (-> Text Code) + (|>> abstraction)) + + (def .public code + (-> (Code Any) Text) + (|>> representation)) + + (with_template [ ] + [(with_expansions [ (template.symbol [ "'"])] + (`` (primitive .public ( brand) Any)) + (`` (type .public ( brand) + ( ( brand)))))] + + [Expression Code] + [Computation Expression] + [Access Computation] + [Var Access] + + [Input Code] + ) + + (with_template [ ] + [(with_expansions [ (template.symbol [ "'"])] + (`` (primitive .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.case + #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/*) + (|> (case 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)) + (case 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/target/js.lux b/stdlib/source/library/lux/meta/target/js.lux new file mode 100644 index 000000000..e5a1ce144 --- /dev/null +++ b/stdlib/source/library/lux/meta/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 at ,) + [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 + [primitive (.except)]]]]]) + +(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)))) + +(primitive .public (Code brand) + Text + + (def .public code + (-> (Code Any) Text) + (|>> representation)) + + (with_template [ +] + [(with_expansions [ (template.symbol [ "'"])] + (primitive ( brand) Any) + (`` (type .public (|> Any (,, (template.spliced +))))))] + + [Expression [Code]] + [Computation [Expression' Code]] + [Location [Computation' Expression' Code]] + [Statement [Code]] + ) + + (with_template [ +] + [(with_expansions [ (template.symbol [ "'"])] + (primitive 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.case + #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 Statement) + (abstraction (format (representation name) " = " (representation value) ..statement_suffix))) + + (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+ + (case 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/target/jvm/attribute.lux b/stdlib/source/library/lux/meta/target/jvm/attribute.lux new file mode 100644 index 000000000..0b0af146e --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/attribute.lux @@ -0,0 +1,150 @@ +(.require + [library + [lux (.except Info Code Type) + [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]]) + +(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))}))) + + (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) + )))) + +(def common_attribute_length + (all n.+ + ... u2 attribute_name_index; + //unsigned.bytes/2 + ... u4 attribute_length; + //unsigned.bytes/4 + )) + +(def (length attribute) + (-> Attribute Nat) + (case attribute + (^.with_template [] + [{ [name length info]} + (|> length //unsigned.value (n.+ ..common_attribute_length))]) + ([#Constant] + [#Code] + [#Signature]))) + +... 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)] + (at ! each (signature' it) (//pool.utf8 "Signature")))) + +(def .public (format it) + (Format Attribute) + (case it + {#Constant it} + ((info_format /constant.format) it) + + {#Code it} + ((info_format (/code.format format)) it) + + {#Signature it} + ((info_format //index.format) it))) diff --git a/stdlib/source/library/lux/meta/target/jvm/attribute/code.lux b/stdlib/source/library/lux/meta/target/jvm/attribute/code.lux new file mode 100644 index 000000000..a350fde0f --- /dev/null +++ b/stdlib/source/library/lux/meta/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/target/jvm/attribute/code/exception.lux b/stdlib/source/library/lux/meta/target/jvm/attribute/code/exception.lux new file mode 100644 index 000000000..08c7cc129 --- /dev/null +++ b/stdlib/source/library/lux/meta/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/target/jvm/attribute/constant.lux b/stdlib/source/library/lux/meta/target/jvm/attribute/constant.lux new file mode 100644 index 000000000..830632337 --- /dev/null +++ b/stdlib/source/library/lux/meta/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/target/jvm/bytecode.lux b/stdlib/source/library/lux/meta/target/jvm/bytecode.lux new file mode 100644 index 000000000..906216326 --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/bytecode.lux @@ -0,0 +1,1177 @@ +(.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 (.only 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 + [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])) + +(def fresh + Tracker + [#program_counter /address.start + #next 0 + #known (dictionary.empty n.hash)]) + +(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 (_ ) + [(.case + {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 [(at 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 .public (label_has_already_been_set [label Label]) + (exception.report + "Label" (%.nat label))) + +(exception .public (mismatched_environments [instruction Symbol + label Label + address Address + expected Stack + actual Stack]) + (exception.report + "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 + (case (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 + (case (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)] + (case (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) + (case (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) + (case (^^it state) + {try.#Success [state' [left ^it]]} + (case (^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] + (.case stack + {.#Some _} + it + + ... {.#None} + _ + (in [])))) + +(def .public (when_acknowledged @ it) + (-> Label (Bytecode Any) (Bytecode Any)) + (do ..monad + [?@ (..acknowledged? @)] + (.case ?@ + {.#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 (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 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))] + (case (|> 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)) + (case (|> value ) + (^.with_template [ ] + [ (..bytecode $0 $1 @_ [])]) + + + _ (do ..monad + [index (..lifted ( ( value)))] + (case (|> 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)))] + (case (|> 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) + (case (|> 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)) + (case (|> 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) + (case (as Frac value) + (^.with_template [ ] + [ (..bytecode $0 $2 @_ [])]) + ([+0.0 _.dconst_0] + [+1.0 _.dconst_1]) + + _ (..arbitrary_double value)))) + +(exception .public (invalid_register [id Nat]) + (exception.report + "ID" (%.nat id))) + +(def (register id) + (-> Nat (Bytecode Register)) + (case (//unsigned.u1 id) + {try.#Success register} + (at ..monad in register) + + {try.#Failure error} + (..except ..invalid_register [id]))) + +(with_template [ ] + [(def .public ( local) + (-> Nat (Bytecode Any)) + (with_expansions [' (template.spliced )] + (`` (case 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 )] + (`` (case 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 .public (unknown_label [label Label]) + (exception.report + "Label" (%.nat label))) + +(exception .public (cannot_do_a_big_jump [label Label + @from Address + jump Big_Jump]) + (exception.report + "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 .public (unset_label [label Label]) + (exception.report + "Label" (%.nat label))) + +(def (resolve_label label resolver) + (-> Label Resolver (Try [Stack Address])) + (case (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) + (case (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] + (at /stack.equivalence = expected actual))) + (try|do jump (..jump @from @to)) + (case 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) + (case (dictionary.value label resolver) + {.#Some [expected {.#Some @to}]} + (<| (try|do _ (exception.assertion ..mismatched_environments [(symbol ) label @here expected actual] + (at /stack.equivalence = expected actual))) + (try|do jump (..jump @from @to)) + (case 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) + (case jump + {.#Left big} + big + + {.#Right small} + (/jump.lifted small))) + +(exception .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)))] + (case (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)) + (at ! 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 .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)))] + (case (do [! maybe.monad] + [@default (|> default get (monad.then ! product.right))] + (|> cases + (monad.each ! (|>> product.right get)) + (monad.then ! (monad.each ! product.right)) + (at ! 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 .public (multiarray_cannot_be_zero_dimensional [class (Type Object)]) + (exception.report + "Class" (..reflection class))) + +(def .public (multianewarray class dimensions) + (-> (Type Object) U1 (Bytecode Any)) + (do ..monad + [_ (is (Bytecode Any) + (case (|> 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 .public (invalid_range_for_try [start Address + end Address]) + (exception.report + "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) + (case (pre state) + {try.#Success [state' [left _]]} + (case (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)))) diff --git a/stdlib/source/library/lux/meta/target/jvm/bytecode/address.lux b/stdlib/source/library/lux/meta/target/jvm/bytecode/address.lux new file mode 100644 index 000000000..66b50f65a --- /dev/null +++ b/stdlib/source/library/lux/meta/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 + [primitive (.except)]]]]] + ["[0]" // + [jump (.only Big_Jump)] + ["/[1]" // + [encoding + ["[1][0]" unsigned (.only U2)] + ["[1][0]" signed (.only S4)]]]]) + +(primitive .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) + (at 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) + (at ///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/target/jvm/bytecode/environment.lux b/stdlib/source/library/lux/meta/target/jvm/bytecode/environment.lux new file mode 100644 index 000000000..fcb4540c7 --- /dev/null +++ b/stdlib/source/library/lux/meta/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 .public discontinuity) + +(def .public (stack environment) + (-> Environment (Try Stack)) + (case (the ..#stack environment) + {.#Some stack} + {try.#Success stack} + + {.#None} + (exception.except ..discontinuity []))) + +(def .public discontinue + (-> Environment Environment) + (.has ..#stack {.#None})) + +(exception .public (mismatched_stacks [expected Stack + actual Stack]) + (exception.report + "Expected" (/stack.text expected) + "Actual" (/stack.text actual))) + +(def .public (continue expected environment) + (-> Stack Environment (Try [Stack Environment])) + (case (the ..#stack environment) + {.#Some actual} + (if (at /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/target/jvm/bytecode/environment/limit.lux b/stdlib/source/library/lux/meta/target/jvm/bytecode/environment/limit.lux new file mode 100644 index 000000000..ce5801345 --- /dev/null +++ b/stdlib/source/library/lux/meta/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/target/jvm/bytecode/environment/limit/registry.lux b/stdlib/source/library/lux/meta/target/jvm/bytecode/environment/limit/registry.lux new file mode 100644 index 000000000..3f16fa4a2 --- /dev/null +++ b/stdlib/source/library/lux/meta/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 + [primitive (.except)]]]]] + ["[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) + +(primitive .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) + (at 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/target/jvm/bytecode/environment/limit/stack.lux b/stdlib/source/library/lux/meta/target/jvm/bytecode/environment/limit/stack.lux new file mode 100644 index 000000000..7c7e0472e --- /dev/null +++ b/stdlib/source/library/lux/meta/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 + [primitive (.except)]]]]] + ["[0]" ///// + [encoding + ["[1][0]" unsigned (.only U2)]]]) + +(primitive .public Stack + U2 + + (with_template [ ] + [(def .public + Stack + (|> /////unsigned.u2 maybe.trusted abstraction))] + + [0 empty] + [1 catch] + ) + + (def .public equivalence + (Equivalence Stack) + (at 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) + (at 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/target/jvm/bytecode/instruction.lux b/stdlib/source/library/lux/meta/target/jvm/bytecode/instruction.lux new file mode 100644 index 000000000..9dc19ed00 --- /dev/null +++ b/stdlib/source/library/lux/meta/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 + [primitive (.except)]]]]] + ["[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)))])]) + +(primitive .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)] + (at ! 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) + _ (case 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})]) + (case 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)] + (at ! 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) + _ (case 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]) + (case 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/target/jvm/bytecode/jump.lux b/stdlib/source/library/lux/meta/target/jvm/bytecode/jump.lux new file mode 100644 index 000000000..13c5f8f07 --- /dev/null +++ b/stdlib/source/library/lux/meta/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/target/jvm/class.lux b/stdlib/source/library/lux/meta/target/jvm/class.lux new file mode 100644 index 000000000..bd9fdd41b --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/class.lux @@ -0,0 +1,151 @@ +(.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)) + (Sequence Attribute) + (Try Class)) + (do try.monad + [[pool [@this @super @interfaces] =fields =methods @signature] + (<| (state.result' //pool.empty) + (do [! //pool.monad] + [classes (install_classes this super interfaces) + =fields (monad.all ! fields) + =methods (monad.all ! methods) + @signature (case signature + {.#Some signature} + (at ! each (|>> {.#Some}) (//attribute.signature signature)) + + {.#None} + (in {.#None}))] + (in [classes =fields =methods @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 (case @signature + {.#Some @signature} + (sequence.suffix @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/target/jvm/constant.lux b/stdlib/source/library/lux/meta/target/jvm/constant.lux new file mode 100644 index 000000000..a56a74c11 --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/constant.lux @@ -0,0 +1,251 @@ +(.require + [library + [lux (.except) + ["[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 + ["@" target] + [macro + ["^" pattern] + ["[0]" template]] + [type + [primitive (.except)]]]]] + ["[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) + +(primitive .public Class + (Index UTF8) + + (def .public index + (-> Class (Index UTF8)) + (|>> representation)) + + (def .public class + (-> (Index UTF8) Class) + (|>> abstraction)) + + (def .public class_equivalence + (Equivalence Class) + (at 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)) + +(primitive .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)))) + (at 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) + (case 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) + (case [reference sample] + (^.with_template [ ] + [[{ reference} { sample}] + (at = 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) + (case value + (^.with_template [ ] + [{ value} + (binaryF#composite (/tag.format ) + ( value))]) + () + )))) diff --git a/stdlib/source/library/lux/meta/target/jvm/constant/pool.lux b/stdlib/source/library/lux/meta/target/jvm/constant/pool.lux new file mode 100644 index 000000000..d3a8c2546 --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/constant/pool.lux @@ -0,0 +1,217 @@ +(.require + [library + [lux (.except) + ["[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.case + {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) + (case (it state) + {try.#Success [state' it']} + (it' state') + + ... {try.#Failure error} + failure + (as_expected failure)))))) + +(def try|each + (template (_ ) + [(case + {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]) + (case (sequence.item idx pool) + {try.#Success entry} + (case entry + [index { reference}] + (if (at = 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) + (at try.monad each //index.index)))) + (try|in [[next + (sequence.suffix [current new] pool)] + current]))))))])) + +(def /|do + (template (_ ) + [(function (_ ) + )])) + +(def /|each + (template (_ ) + [(case ( ) + {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/target/jvm/constant/tag.lux b/stdlib/source/library/lux/meta/target/jvm/constant/tag.lux new file mode 100644 index 000000000..bcd1d4209 --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/constant/tag.lux @@ -0,0 +1,52 @@ +(.require + [library + [lux (.except) + [abstract + [equivalence (.only Equivalence)]] + [control + ["[0]" try]] + [data + [binary + [\\format (.only Format)]]] + [meta + [type + [primitive (.except)]]]]] + ["[0]" /// + [encoding + ["[1][0]" unsigned (.only U1) (.use "u1//[0]" equivalence)]]]) + +(primitive .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/target/jvm/encoding/name.lux b/stdlib/source/library/lux/meta/target/jvm/encoding/name.lux new file mode 100644 index 000000000..7516cdc46 --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/encoding/name.lux @@ -0,0 +1,42 @@ +(.require + [library + [lux (.except) + [data + ["[0]" text (.only) + ["%" \\format (.only format)]]] + [meta + [type + [primitive (.except)]]]]]) + +(def .public internal_separator "/") +(def .public external_separator ".") + +(type .public External + Text) + +(primitive .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/target/jvm/encoding/signed.lux b/stdlib/source/library/lux/meta/target/jvm/encoding/signed.lux new file mode 100644 index 000000000..91d7c15c6 --- /dev/null +++ b/stdlib/source/library/lux/meta/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 + [primitive (.except)]]]]]) + +(primitive .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 .public (value_exceeds_the_scope [value Int + scope Nat]) + (exception.report + "Value" (%.int value) + "Scope (in bytes)" (%.nat scope))) + + (with_template [ <+> <->] + [(with_expansions [ (template.symbol [ "'"])] + (primitive 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/target/jvm/encoding/unsigned.lux b/stdlib/source/library/lux/meta/target/jvm/encoding/unsigned.lux new file mode 100644 index 000000000..858d06d80 --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/encoding/unsigned.lux @@ -0,0 +1,123 @@ +(.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 + [primitive (.except)]]]]]) + +(primitive .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 .public (value_exceeds_the_maximum [type Symbol + value Nat + maximum (Unsigned Any)]) + (exception.report + "Type" (%.symbol type) + "Value" (%.nat value) + "Maximum" (%.nat (representation maximum)))) + + (exception .public [brand] (subtraction_cannot_yield_negative_value + [type Symbol + parameter (Unsigned brand) + subject (Unsigned brand)]) + (exception.report + "Type" (%.symbol type) + "Parameter" (%.nat (representation parameter)) + "Subject" (%.nat (representation subject)))) + + (with_template [ <+> <-> ] + [(with_expansions [ (template.symbol [ "'"])] + (primitive .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/target/jvm/field.lux b/stdlib/source/library/lux/meta/target/jvm/field.lux new file mode 100644 index 000000000..e0561b457 --- /dev/null +++ b/stdlib/source/library/lux/meta/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? + (at ! each (|>> {.#Some}) (//attribute.signature (//type.signature type))) + (in {.#None}))] + (in [#modifier modifier + #name @name + #descriptor @descriptor + #attributes (case @signature + {.#Some @signature} + (sequence.suffix @signature attributes) + + {.#None} + attributes)]))) diff --git a/stdlib/source/library/lux/meta/target/jvm/index.lux b/stdlib/source/library/lux/meta/target/jvm/index.lux new file mode 100644 index 000000000..05489792b --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/index.lux @@ -0,0 +1,39 @@ +(.require + [library + [lux (.except) + [abstract + ["[0]" equivalence (.only Equivalence)]] + [data + [binary + [\\format (.only Format)]]] + [meta + [type + [primitive (.except)]]]]] + ["[0]" // + [encoding + ["[1][0]" unsigned (.only U2)]]]) + +(def .public length + //unsigned.bytes/2) + +(primitive .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))) + (at 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/target/jvm/loader.lux b/stdlib/source/library/lux/meta/target/jvm/loader.lux new file mode 100644 index 000000000..cb423bba7 --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/loader.lux @@ -0,0 +1,145 @@ +(.require + [library + [lux (.except) + ["[0]" ffi (.only import object do_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 + ["@" target]]]]) + +(type .public Library + (Atom (Dictionary Text Binary))) + +(exception .public (already_stored [class Text]) + (exception.report + "Class" class)) + +(exception .public (unknown [class Text]) + (exception.report + "Class" class)) + +(exception .public (cannot_define [class Text + error Text]) + (exception.report + "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))))] + (do_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 (Primitive "java.lang.Long")) + ffi.long_to_int)) + (as java/lang/Object + (|> bytecode + binary.size + (as (Primitive "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!)] + (case (dictionary.value class_name classes) + {.#Some bytecode} + (case (..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/target/jvm/magic.lux b/stdlib/source/library/lux/meta/target/jvm/magic.lux new file mode 100644 index 000000000..e5fc0a09d --- /dev/null +++ b/stdlib/source/library/lux/meta/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/target/jvm/method.lux b/stdlib/source/library/lux/meta/target/jvm/method.lux new file mode 100644 index 000000000..3db1be9bc --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/method.lux @@ -0,0 +1,111 @@ +(.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 !) + (at ! each sequence.of_list)) + attributes (case code + {.#Some code} + (do ! + [environment (case (if (//modifier.has? static modifier) + (//environment.static type) + (//environment.virtual type)) + {try.#Success environment} + (in environment) + + {try.#Failure error} + (function (_ _) {try.#Failure error})) + [environment exceptions instruction output] (//bytecode.resolve environment code) + .let [bytecode (|> instruction //instruction.result \\format.instance)] + @code (//attribute.code [//code.#limit (the //environment.#limit environment) + //code.#code bytecode + //code.#exception_table exceptions + //code.#attributes (sequence.sequence)])] + (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/target/jvm/modifier.lux b/stdlib/source/library/lux/meta/target/jvm/modifier.lux new file mode 100644 index 000000000..35b9894be --- /dev/null +++ b/stdlib/source/library/lux/meta/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 + [primitive (.except)]]]]] + ["[0]" // + [encoding + ["[1][0]" unsigned]]]) + +(primitive .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) + (at //unsigned.equivalence = + (representation reference) + (representation sample))))) + + (def !wrap + (template (_ value) + [(|> value + //unsigned.u2 + try.trusted + abstraction)])) + + (def !unwrap + (template (_ value) + [(|> value + representation + //unsigned.value)])) + + (def .public (has? sub super) + (All (_ of) (-> (Modifier of) (Modifier of) Bit)) + (let [sub (!unwrap sub)] + (|> (!unwrap super) + (i64.and sub) + (at i64.equivalence = sub)))) + + (def .public monoid + (All (_ of) (Monoid (Modifier of))) + (implementation + (def identity + (!wrap (hex "0000"))) + + (def (composite left right) + (!wrap (i64.or (!unwrap left) (!unwrap right)))))) + + (def .public empty + Modifier + (at ..monoid identity)) + + (def .public format + (All (_ of) (Format (Modifier of))) + (|>> representation //unsigned.format/2)) + + (def modifier + (-> Nat Modifier) + (|>> !wrap)) + ) + +(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)) + ((,! ..modifier) ((,! number.hex) (, g!code))))] + + (,* options)))))))) diff --git a/stdlib/source/library/lux/meta/target/jvm/modifier/inner.lux b/stdlib/source/library/lux/meta/target/jvm/modifier/inner.lux new file mode 100644 index 000000000..c61569575 --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/modifier/inner.lux @@ -0,0 +1,23 @@ +(.require + [library + [lux (.except static) + [meta + [type + [primitive (.except)]]]]] + [// (.only modifiers)]) + +(primitive .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/target/jvm/reflection.lux b/stdlib/source/library/lux/meta/target/jvm/reflection.lux new file mode 100644 index 000000000..3c5145a9d --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/reflection.lux @@ -0,0 +1,385 @@ +(.require + [library + [lux (.except Primitive 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 .public (unknown_class [class External]) + (exception.report + "Class" (%.text class))) + +(with_template [] + [(exception .public ( [jvm_type java/lang/reflect/Type]) + (exception.report + "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))) + (case (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))) + (<| (case (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))}))) + _) + (case (ffi.as java/lang/reflect/ParameterizedType reflection) + {.#Some reflection} + (let [raw (java/lang/reflect/ParameterizedType::getRawType reflection)] + (case (ffi.as java/lang/Class raw) + {.#Some raw'} + (let [! try.monad] + (|> reflection + java/lang/reflect/ParameterizedType::getActualTypeArguments + (array.list {.#None}) + (monad.each ! parameter) + (at ! 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)))) + (<| (case (ffi.as java/lang/reflect/TypeVariable reflection) + {.#Some reflection} + {try.#Success (/.var (java/lang/reflect/TypeVariable::getName reflection))} + _) + (case (ffi.as java/lang/reflect/WildcardType reflection) + {.#Some reflection} + ... TODO: Instead of having single lower/upper bounds, should + ... allow for multiple ones. + (case [(array.item 0 (java/lang/reflect/WildcardType::getLowerBounds reflection)) + (array.item 0 (java/lang/reflect/WildcardType::getUpperBounds reflection))] + (^.with_template [ ] + [ + (case (ffi.as java/lang/reflect/GenericArrayType bound) + {.#Some it} + ... TODO: Array bounds should not be "erased" as they + ... are right now. + {try.#Success /.wildcard} + + _ + (at try.monad each (parameter type bound)))]) + ([[_ {.#Some bound}] /.upper] + [[{.#Some bound} _] /.lower]) + + _ + {try.#Success /.wildcard}) + _) + (case (ffi.as java/lang/reflect/GenericArrayType reflection) + {.#Some reflection} + (|> reflection + java/lang/reflect/GenericArrayType::getGenericComponentType + type + (at try.monad each /.array)) + _) + (case (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))) + (<| (case (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))] + (case (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 .public (cannot_correspond [class (java/lang/Class java/lang/Object) + type Type]) + (exception.report + "Class" (java/lang/Object::toString class) + "Type" (%.type type))) + +(exception .public (type_parameter_mismatch [expected Nat + actual Nat + class (java/lang/Class java/lang/Object) + type Type]) + (exception.report + "Expected" (%.nat expected) + "Actual" (%.nat actual) + "Class" (java/lang/Object::toString class) + "Type" (%.type type))) + +(exception .public (non_jvm_type [type Type]) + (exception.report + "Type" (%.type type))) + +(def .public (correspond class type) + (-> (java/lang/Class java/lang/Object) Type (Try Mapping)) + (case type + {.#Primitive (static array.type_name) (list :member:)} + (if (java/lang/Class::isArray class) + (correspond (java/lang/Class::getComponentType class) + :member:) + (exception.except ..cannot_correspond [class type])) + + {.#Primitive 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} + (case (type.applied (list inputT) abstractionT) + {.#Some outputT} + (correspond class outputT) + + {.#None} + (exception.except ..non_jvm_type [type])) + + _ + (exception.except ..non_jvm_type [type]))) + +(exception .public (mistaken_field_owner [field java/lang/reflect/Field + owner (java/lang/Class java/lang/Object) + target (java/lang/Class java/lang/Object)]) + (exception.report + "Field" (java/lang/Object::toString field) + "Owner" (java/lang/Object::toString owner) + "Target" (java/lang/Object::toString target))) + +(with_template [] + [(exception .public ( [field Text + class (java/lang/Class java/lang/Object)]) + (exception.report + "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)) + (case (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)]] + (case (java/lang/reflect/Modifier::isStatic modifiers) + (|> fieldJ + java/lang/reflect/Field::getGenericType + ..type + (at ! 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/target/jvm/type.lux b/stdlib/source/library/lux/meta/target/jvm/type.lux new file mode 100644 index 000000000..f9944b0eb --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/type.lux @@ -0,0 +1,212 @@ +(.require + [library + [lux (.except Primitive Type 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 + [primitive (.except)]]]]] + ["[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)]]) + +(primitive .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 [