(.require [library [lux (.except) [program (.only program)] ["[0]" debug] ["[0]" ffi (.only import)] [abstract ["[0]" monad (.only do)]] [control ["[0]" maybe] ["[0]" try (.only Try)] ["[0]" exception (.only Exception)] ["[0]" io (.only IO io)] [concurrency ["[0]" async (.only Async)]]] [data ["[0]" text (.use "[1]#[0]" hash) ["%" \\format (.only format)] [encoding ["[0]" utf8]]] [collection ["[0]" array (.only Array)] ["[0]" list (.use "[1]#[0]" functor)]]] [math [number (.only hex) ["n" nat] ["i" int] ["[0]" i64]]] [meta ["@" target (.only) ["_" ruby]] [macro ["^" pattern] ["[0]" template]] ["[0]" compiler ["[0]" phase (.only Operation Phase) (.use "[1]#[0]" monad)] [reference [variable (.only Register)]] [language [lux [program (.only Program)] [translation (.only Host)] ["[0]" synthesis] [analysis [macro (.only Expander)]] [phase ["[0]" extension (.only Extender Handler) ["[0]" analysis ["[1]" ruby]] ["[0]" translation ["[1]" ruby]]] [translation ["[0]" reference] ["[0]" ruby (.only) ["[0]" runtime] ["[1]/[0]" reference]]]]]] [default ["[0]" platform (.only Platform)]] [meta [archive (.only Archive)] ["[0]" context] ["[0]" cli] ["[0]" packager ["[1]" ruby]]]]] ["[0]" world ["[0]" file] ["[1]/[0]" environment]]]] [program ["/" compositor]]) (import java/lang/String "[1]::[0]") (import (java/lang/Class a) "[1]::[0]" (getSuperclass [] (java/lang/Class ?)) (isInstance [java/lang/Object] boolean)) (import java/lang/Object "[1]::[0]" (toString [] java/lang/String) (getClass [] (java/lang/Class java/lang/Object))) (import java/lang/Integer "[1]::[0]" (longValue [] long)) (import java/lang/Long "[1]::[0]" (intValue [] int)) (import org/jruby/RubyString "[1]::[0]" ("static" newInternalFromJavaExternal [org/jruby/Ruby java/lang/String] org/jruby/RubyString) (asJavaString [] java/lang/String)) (import org/jruby/RubySymbol "[1]::[0]" (asJavaString [] java/lang/String)) (import org/jruby/runtime/builtin/IRubyObject "[1]::[0]") (import org/jruby/Ruby "[1]::[0]" (getCurrentContext [] org/jruby/runtime/ThreadContext) (getNil [] org/jruby/runtime/builtin/IRubyObject)) (import org/jruby/RubyClass "[1]::[0]") (import (org/jruby/RubyArray a) "[1]::[0]" (getLength [] int) (get [int] "?" java/lang/Object)) (import org/jruby/RubyHash "[1]::[0]" (get [java/lang/Object] "?" java/lang/Object)) (import org/jruby/runtime/ThreadContext "[1]::[0]") (import org/jruby/RubyRange "[1]::[0]" (first [org/jruby/runtime/ThreadContext] org/jruby/runtime/builtin/IRubyObject) (size [org/jruby/runtime/ThreadContext] org/jruby/runtime/builtin/IRubyObject)) (import org/jruby/runtime/JavaSites$CheckedSites "[1]::[0]") (import org/jruby/runtime/builtin/Variable "[1]::[0]") (import org/jruby/runtime/builtin/InstanceVariables "[1]::[0]") (import org/jruby/runtime/builtin/InternalVariables "[1]::[0]") (import org/jruby/embed/internal/LocalContextProvider "[1]::[0]" (getRuntime [] org/jruby/Ruby)) (import org/jruby/embed/ScriptingContainer "[1]::[0]" (new []) (runScriptlet [java/lang/String] "try" "?" java/lang/Object) (getProvider [] org/jruby/embed/internal/LocalContextProvider)) ... TODO; Figure out a way to not need "interpreter" to be a global variable. (def interpreter (org/jruby/embed/ScriptingContainer::new)) (def !ruby_runtime (template (!ruby_runtime) [(|> ..interpreter org/jruby/embed/ScriptingContainer::getProvider org/jruby/embed/internal/LocalContextProvider::getRuntime)])) (def !ruby_thread_context (template (!ruby_thread_context) [(|> (!ruby_runtime) org/jruby/Ruby::getCurrentContext)])) (def initial_ruby_runtime (!ruby_runtime)) (import org/jruby/java/proxies/JavaProxy "[1]::[0]" (new [org/jruby/Ruby org/jruby/RubyClass java/lang/Object]) (getObject [] java/lang/Object)) (import org/jruby/internal/runtime/methods/DynamicMethod "[1]::[0]") (import org/jruby/runtime/callsite/CacheEntry "[1]::[0]" (new [org/jruby/internal/runtime/methods/DynamicMethod int])) (import org/jruby/RubyFixnum "[1]::[0]" (new [org/jruby/Ruby long]) (getLongValue [] long)) (import org/jruby/RubyFloat "[1]::[0]" (new [org/jruby/Ruby double])) (import org/jruby/RubyBoolean "[1]::[0]" ("static" newBoolean [org/jruby/Ruby boolean] org/jruby/RubyBoolean)) (import org/jruby/RubyNil "[1]::[0]" (new [org/jruby/Ruby])) (import org/jruby/runtime/Block$Type "[1]::[0]" ("enum" PROC)) (import org/jruby/runtime/Signature "[1]::[0]" ("read_only" "static" THREE_ARGUMENTS org/jruby/runtime/Signature)) (import org/jruby/parser/StaticScope "[1]::[0]") (import org/jruby/parser/StaticScopeFactory "[1]::[0]" (new [org/jruby/Ruby]) (getDummyScope [] org/jruby/parser/StaticScope)) (import org/jruby/runtime/BlockBody "[1]::[0]") (import org/jruby/runtime/Block "[1]::[0]" ("read_only" "static" NULL_BLOCK org/jruby/runtime/Block) ("read_only" type org/jruby/runtime/Block$Type) (getBody [] org/jruby/runtime/BlockBody)) (import org/jruby/RubyProc "[1]::[0]" ("static" newProc [org/jruby/Ruby org/jruby/runtime/Block org/jruby/runtime/Block$Type] org/jruby/RubyProc) (call [org/jruby/runtime/ThreadContext [org/jruby/runtime/builtin/IRubyObject]] "try" org/jruby/runtime/builtin/IRubyObject)) (type Translator (-> java/lang/Object (Try Any))) (def (read_tuple read host_object) (-> Translator (org/jruby/RubyArray org/jruby/runtime/builtin/IRubyObject) (Try Any)) (let [size (.nat (ffi.of_int (org/jruby/RubyArray::getLength host_object)))] (loop (again [idx 0 output (is (Array Any) (array.empty size))]) (if (n.< size idx) (when (org/jruby/RubyArray::get (ffi.as_int (.int idx)) host_object) {.#None} (again (++ idx) output) {.#Some value} (when (read value) {try.#Success lux_value} (again (++ idx) (array.has! idx lux_value output)) failure failure)) {try.#Success output})))) (exception.def (unknown_kind_of_object object) (Exception java/lang/Object) (exception.report (list ["Class" (ffi.of_string (java/lang/Object::toString (java/lang/Object::getClass object)))] ["Object" (ffi.of_string (java/lang/Object::toString object))]))) (def (read_variant read host_object) (-> Translator org/jruby/RubyHash (Try Any)) (when [(org/jruby/RubyHash::get (ffi.as_string runtime.variant_tag_field) host_object) (org/jruby/RubyHash::get (ffi.as_string runtime.variant_flag_field) host_object) (org/jruby/RubyHash::get (ffi.as_string runtime.variant_value_field) host_object)] [{.#Some tag} ?flag {.#Some value}] (do try.monad [value (read value)] (in [(is Any (|> tag (as java/lang/Long) java/lang/Long::intValue (is java/lang/Integer))) (is Any (when ?flag {.#Some _} "" {.#None} (is java/lang/Object (ffi.null)))) (is Any value)])) _ (exception.except ..unknown_kind_of_object [(ffi.is java/lang/Object host_object)]))) (exception.def .public nil_has_no_lux_representation) (def (read host_object) Translator (`` (<| (if (ffi.null? host_object) (exception.except ..nil_has_no_lux_representation [])) (,, (with_template [ ] [(when (ffi.as host_object) {.#Some typed_object} (`` (|> typed_object (,, (template.spliced )))) _)] [java/lang/Boolean [{try.#Success}]] [java/lang/Long [{try.#Success}]] [java/lang/Double [{try.#Success}]] [java/lang/String [{try.#Success}]] [org/jruby/RubyFixnum [org/jruby/RubyFixnum::getLongValue {try.#Success}]] [org/jruby/RubyString [org/jruby/RubyString::asJavaString {try.#Success}]] [[java/lang/Object] [{try.#Success}]] [org/jruby/RubyArray [(as (org/jruby/RubyArray org/jruby/runtime/builtin/IRubyObject)) (read_tuple read)]] [org/jruby/RubyHash [(read_variant read)]] [org/jruby/RubySymbol [{try.#Success}]] [org/jruby/RubyProc [{try.#Success}]] [org/jruby/java/proxies/JavaProxy [org/jruby/java/proxies/JavaProxy::getObject {try.#Success}]] )) ... (exception.except ..unknown_kind_of_object [host_object]) {try.#Success host_object} ))) (def ruby_nil org/jruby/runtime/builtin/IRubyObject (org/jruby/Ruby::getNil ..initial_ruby_runtime)) (def lux_unit org/jruby/runtime/builtin/IRubyObject (<| (ffi.is org/jruby/runtime/builtin/IRubyObject) (org/jruby/RubyString::newInternalFromJavaExternal ..initial_ruby_runtime (ffi.as_string "")))) (def (wrapped_lux_value useful_object_class lux_structure) (-> (-> (-> java/lang/Object org/jruby/runtime/builtin/IRubyObject) (Array java/lang/Object) org/jruby/RubyClass) (-> (Array java/lang/Object) org/jruby/runtime/builtin/IRubyObject) (-> java/lang/Object org/jruby/runtime/builtin/IRubyObject)) (function (again value) (`` (<| (,, (with_template [ ] [(when (ffi.as value) {.#Some value} (|> value (ffi.is org/jruby/runtime/builtin/IRubyObject)) {.#None})] [[java/lang/Object] (<| lux_structure (as (Array java/lang/Object)))] [java/lang/Boolean (org/jruby/RubyBoolean::newBoolean ..initial_ruby_runtime)] [java/lang/Long (org/jruby/RubyFixnum::new ..initial_ruby_runtime)] [java/lang/Double (org/jruby/RubyFloat::new ..initial_ruby_runtime)] [java/lang/String (org/jruby/RubyString::newInternalFromJavaExternal ..initial_ruby_runtime)] [org/jruby/runtime/builtin/IRubyObject (<|)] )) ... (as org/jruby/runtime/builtin/IRubyObject value) (<| (ffi.is org/jruby/runtime/builtin/IRubyObject) (org/jruby/java/proxies/JavaProxy::new ..initial_ruby_runtime (useful_object_class again (as (Array java/lang/Object) value)) (ffi.is java/lang/Object value))))))) (exception.def (invalid_variant_access field) (Exception Text) (exception.report (list ["Field" (%.text field)]))) (exception.def (invalid_index index) (Exception java/lang/Object) (exception.report (list ["Class" (|> index java/lang/Object::getClass java/lang/Object::toString ffi.of_string)] ["Index" (|> index java/lang/Object::toString ffi.of_string)]))) (import java/util/Arrays "[1]::[0]" ("static" [t] copyOfRange [[t] int int] [t])) (exception.def (invalid_arity arity) (Exception Nat) (exception.report (list ["Arity" (%.nat arity)]))) (def (::call useful_object_class lux_structure value) (-> (-> (-> (Array java/lang/Object) org/jruby/runtime/builtin/IRubyObject) (Array java/lang/Object) org/jruby/RubyClass) (-> (Array java/lang/Object) org/jruby/runtime/builtin/IRubyObject) (-> (Array java/lang/Object) org/jruby/internal/runtime/methods/DynamicMethod)) (<| (ffi.is org/jruby/internal/runtime/methods/DynamicMethod) (ffi.object [] org/jruby/internal/runtime/methods/DynamicMethod [] [java/lang/String (ffi.as_string "call")] (org/jruby/internal/runtime/methods/DynamicMethod [] (dup this []) org/jruby/internal/runtime/methods/DynamicMethod (undefined)) (org/jruby/internal/runtime/methods/DynamicMethod [] (call this [thread_context org/jruby/runtime/ThreadContext self org/jruby/runtime/builtin/IRubyObject module org/jruby/RubyModule method java/lang/String args [org/jruby/runtime/builtin/IRubyObject] block org/jruby/runtime/Block]) org/jruby/runtime/builtin/IRubyObject (let [arity (ffi.length args)] (try.trusted (do [! try.monad] [args (|> arity list.indices (list#each (function (_ index) (ffi.read! index args))) (monad.each ! (|>> (ffi.is java/lang/Object) ..read))) output (when args (list arg/0) (in ((as (-> Any java/lang/Object) value) arg/0)) (list arg/0 arg/1) (in ((as (-> Any Any java/lang/Object) value) arg/0 arg/1)) (list arg/0 arg/1 arg/2) (in ((as (-> Any Any Any java/lang/Object) value) arg/0 arg/1 arg/2)) (list arg/0 arg/1 arg/2 arg/3) (in ((as (-> Any Any Any Any java/lang/Object) value) arg/0 arg/1 arg/2 arg/3)) (list arg/0 arg/1 arg/2 arg/3 arg/4) (in ((as (-> Any Any Any Any Any java/lang/Object) value) arg/0 arg/1 arg/2 arg/3 arg/4)) (list arg/0 arg/1 arg/2 arg/3 arg/4 arg/5) (in ((as (-> Any Any Any Any Any Any java/lang/Object) value) arg/0 arg/1 arg/2 arg/3 arg/4 arg/5)) (list arg/0 arg/1 arg/2 arg/3 arg/4 arg/5 arg/6) (in ((as (-> Any Any Any Any Any Any Any java/lang/Object) value) arg/0 arg/1 arg/2 arg/3 arg/4 arg/5 arg/6)) (list arg/0 arg/1 arg/2 arg/3 arg/4 arg/5 arg/6 arg/7) (in ((as (-> Any Any Any Any Any Any Any Any java/lang/Object) value) arg/0 arg/1 arg/2 arg/3 arg/4 arg/5 arg/6 arg/7)) _ (exception.except ..invalid_arity [arity]))] (in (wrapped_lux_value (as_expected useful_object_class) lux_structure output))))))))) (def (::access useful_object_class lux_structure value) (-> (-> (-> (Array java/lang/Object) org/jruby/runtime/builtin/IRubyObject) (Array java/lang/Object) org/jruby/RubyClass) (-> (Array java/lang/Object) org/jruby/runtime/builtin/IRubyObject) (-> (Array java/lang/Object) org/jruby/internal/runtime/methods/DynamicMethod)) (<| (ffi.is org/jruby/internal/runtime/methods/DynamicMethod) (ffi.object [] org/jruby/internal/runtime/methods/DynamicMethod [] [java/lang/String (ffi.as_string "[]")] (org/jruby/internal/runtime/methods/DynamicMethod [] (dup this []) org/jruby/internal/runtime/methods/DynamicMethod (undefined)) (org/jruby/internal/runtime/methods/DynamicMethod [] (call this [thread_context org/jruby/runtime/ThreadContext self org/jruby/runtime/builtin/IRubyObject module org/jruby/RubyModule method java/lang/String args [org/jruby/runtime/builtin/IRubyObject] block org/jruby/runtime/Block]) org/jruby/runtime/builtin/IRubyObject (let [member (ffi.read! 0 args)] (<| (when (ffi.as org/jruby/RubyFixnum member) {.#Some member} (when (array.item (.nat (ffi.of_long (org/jruby/RubyFixnum::getLongValue member))) value) {.#Some value} (wrapped_lux_value (as_expected useful_object_class) lux_structure value) {.#None} ..ruby_nil) {.#None}) (when (ffi.as org/jruby/RubyString member) {.#Some member} (when (ffi.of_string (org/jruby/RubyString::asJavaString member)) runtime.variant_tag_field (|> value (array.item 0) maybe.trusted (as java/lang/Integer) java/lang/Integer::longValue (org/jruby/RubyFixnum::new ..initial_ruby_runtime) (ffi.is org/jruby/runtime/builtin/IRubyObject)) runtime.variant_flag_field (when (array.item 1 value) {.#None} ..ruby_nil {.#Some flag} ..lux_unit) runtime.variant_value_field (when (array.item 2 value) {.#Some value} (wrapped_lux_value (as_expected useful_object_class) lux_structure value) {.#None} (panic! (exception.error ..nil_has_no_lux_representation []))) field (panic! (exception.error ..invalid_variant_access [field]))) {.#None}) (when (ffi.as org/jruby/RubyRange member) {.#Some member} (when [(|> member (org/jruby/RubyRange::first thread_context) (ffi.as org/jruby/RubyFixnum)) (|> member (org/jruby/RubyRange::size thread_context) (ffi.as org/jruby/RubyFixnum))] [{.#Some first} {.#Some size}] (let [first (ffi.of_long (org/jruby/RubyFixnum::getLongValue first)) size (ffi.of_long (org/jruby/RubyFixnum::getLongValue size))] (lux_structure (java/util/Arrays::copyOfRange value (ffi.as_int first) (ffi.as_int (i.+ first size))))) _ (panic! (exception.error ..invalid_index [(ffi.is java/lang/Object member)]))) {.#None}) (panic! (exception.error ..invalid_index [(ffi.is java/lang/Object member)])))))))) (def (::= value) (-> (Array java/lang/Object) org/jruby/internal/runtime/methods/DynamicMethod) (<| (ffi.is org/jruby/internal/runtime/methods/DynamicMethod) (ffi.object [] org/jruby/internal/runtime/methods/DynamicMethod [] [java/lang/String (ffi.as_string "==")] (org/jruby/internal/runtime/methods/DynamicMethod [] (dup this []) org/jruby/internal/runtime/methods/DynamicMethod (undefined)) (org/jruby/internal/runtime/methods/DynamicMethod [] (call this [thread_context org/jruby/runtime/ThreadContext self org/jruby/runtime/builtin/IRubyObject module org/jruby/RubyModule method java/lang/String args [org/jruby/runtime/builtin/IRubyObject] block org/jruby/runtime/Block]) org/jruby/runtime/builtin/IRubyObject (<| (ffi.is org/jruby/runtime/builtin/IRubyObject) (org/jruby/RubyBoolean::newBoolean ..initial_ruby_runtime) ffi.as_boolean (when (|> args (ffi.read! 0) (ffi.is java/lang/Object) ..read) {try.#Success reference} (same? (is Any reference) (is Any value)) {try.#Failure error} false)))))) (def (::length value) (-> (Array java/lang/Object) org/jruby/internal/runtime/methods/DynamicMethod) (<| (ffi.is org/jruby/internal/runtime/methods/DynamicMethod) (ffi.object [] org/jruby/internal/runtime/methods/DynamicMethod [] [java/lang/String (ffi.as_string "length")] (org/jruby/internal/runtime/methods/DynamicMethod [] (dup this []) org/jruby/internal/runtime/methods/DynamicMethod (undefined)) (org/jruby/internal/runtime/methods/DynamicMethod [] (call this [thread_context org/jruby/runtime/ThreadContext self org/jruby/runtime/builtin/IRubyObject module org/jruby/RubyModule method java/lang/String args [org/jruby/runtime/builtin/IRubyObject] block org/jruby/runtime/Block]) org/jruby/runtime/builtin/IRubyObject (|> value array.size .int ffi.as_long (org/jruby/RubyFixnum::new ..initial_ruby_runtime) (ffi.is org/jruby/runtime/builtin/IRubyObject)))))) (def (::to_s value) (-> (Array java/lang/Object) org/jruby/internal/runtime/methods/DynamicMethod) (<| (ffi.is org/jruby/internal/runtime/methods/DynamicMethod) (ffi.object [] org/jruby/internal/runtime/methods/DynamicMethod [] [java/lang/String (ffi.as_string "to_s")] (org/jruby/internal/runtime/methods/DynamicMethod [] (dup this []) org/jruby/internal/runtime/methods/DynamicMethod (undefined)) (org/jruby/internal/runtime/methods/DynamicMethod [] (call this [thread_context org/jruby/runtime/ThreadContext self org/jruby/runtime/builtin/IRubyObject module org/jruby/RubyModule method java/lang/String args [org/jruby/runtime/builtin/IRubyObject] block org/jruby/runtime/Block]) org/jruby/runtime/builtin/IRubyObject (|> value debug.inspection ffi.as_string (org/jruby/RubyString::newInternalFromJavaExternal ..initial_ruby_runtime) (ffi.is org/jruby/runtime/builtin/IRubyObject)))))) (exception.def (invalid_operation method) (Exception Text) (exception.report (list ["Method" (%.text method)]))) (def (::respond_to? value) (-> (Array java/lang/Object) org/jruby/internal/runtime/methods/DynamicMethod) (<| (ffi.is org/jruby/internal/runtime/methods/DynamicMethod) (ffi.object [] org/jruby/internal/runtime/methods/DynamicMethod [] [java/lang/String (ffi.as_string "respond_to?")] (org/jruby/internal/runtime/methods/DynamicMethod [] (dup this []) org/jruby/internal/runtime/methods/DynamicMethod (undefined)) (org/jruby/internal/runtime/methods/DynamicMethod [] (call this [thread_context org/jruby/runtime/ThreadContext self org/jruby/runtime/builtin/IRubyObject module org/jruby/RubyModule method java/lang/String args [org/jruby/runtime/builtin/IRubyObject] block org/jruby/runtime/Block]) org/jruby/runtime/builtin/IRubyObject (when (|> args (ffi.read! 0) (ffi.as org/jruby/RubySymbol)) {.#Some method} (|> (when (|> method org/jruby/RubySymbol::asJavaString ffi.of_string) (^.or "==" "equal?" "to_s" "inspect" "[]" "length" "respond_to?" ... "to_hash" ) true _ false) ffi.as_boolean (org/jruby/RubyBoolean::newBoolean ..initial_ruby_runtime) (ffi.is org/jruby/runtime/builtin/IRubyObject)) {.#None} (panic! (exception.error ..invalid_operation ["respond_to?"]))))))) (exception.def (unknown_method method) (Exception Text) (exception.report (list ["Method" (%.text method)]))) (def (useful_object_class lux_structure value) (-> (-> (Array java/lang/Object) org/jruby/runtime/builtin/IRubyObject) (Array java/lang/Object) org/jruby/RubyClass) (<| (ffi.is org/jruby/RubyClass) (ffi.object [] org/jruby/RubyClass [] [org/jruby/Ruby ..initial_ruby_runtime] (org/jruby/RubyClass [] (searchWithCache this [method java/lang/String]) org/jruby/runtime/callsite/CacheEntry (when (ffi.of_string method) "call" (org/jruby/runtime/callsite/CacheEntry::new (::call useful_object_class lux_structure value) (ffi.as_int +0)) "[]" (org/jruby/runtime/callsite/CacheEntry::new (::access useful_object_class lux_structure value) (ffi.as_int +1)) (^.or "==" "equal?") (org/jruby/runtime/callsite/CacheEntry::new (::= value) (ffi.as_int +2)) (^.or "count" "length" "size") (org/jruby/runtime/callsite/CacheEntry::new (::length value) (ffi.as_int +3)) (^.or "to_s" "inspect") (org/jruby/runtime/callsite/CacheEntry::new (::to_s value) (ffi.as_int +4)) "respond_to?" (org/jruby/runtime/callsite/CacheEntry::new (::respond_to? value) (ffi.as_int +5)) method (panic! (exception.error ..unknown_method [method]))))))) (def (lux_structure value) (-> (Array java/lang/Object) org/jruby/runtime/builtin/IRubyObject) (<| (ffi.is org/jruby/runtime/builtin/IRubyObject) (org/jruby/java/proxies/JavaProxy::new ..initial_ruby_runtime (useful_object_class lux_structure value) (as java/lang/Object value)))) (exception.def (cannot_apply_a_non_function object) (Exception java/lang/Object) (exception.report (list ["Non-function" (ffi.of_string (java/lang/Object::toString object))]))) (def macro! (-> Macro (Maybe org/jruby/RubyProc)) (|>> (as java/lang/Object) (ffi.as org/jruby/RubyProc))) (def to_host (-> Any org/jruby/runtime/builtin/IRubyObject) (|>> (as (Array java/lang/Object)) ..lux_structure)) (def (call_macro inputs lux macro) (-> (List Code) Lux org/jruby/RubyProc (Try (Try [Lux (List Code)]))) (as_expected (do try.monad [expansion (org/jruby/RubyProc::call (!ruby_thread_context) (|> (ffi.array org/jruby/runtime/builtin/IRubyObject 2) (ffi.write! 0 (..to_host inputs)) (ffi.write! 1 (..to_host lux))) macro)] (..read (ffi.is java/lang/Object expansion))))) (def (expander macro inputs lux) Expander (when (macro! macro) {.#Some macro} (when (call_macro inputs lux macro) {try.#Success output} (|> output (as java/lang/Object) ..read (as (Try (Try [Lux (List Code)])))) {try.#Failure error} {try.#Failure error}) {.#None} (exception.except ..cannot_apply_a_non_function [(as java/lang/Object macro)]))) (def host (IO (Host _.Expression _.Statement)) (io (let [run! (is (-> (_.Code Any) (Try Any)) (function (_ code) (do try.monad [output (org/jruby/embed/ScriptingContainer::runScriptlet (ffi.as_string (_.code code)) ..interpreter)] (..read (maybe.else (as java/lang/Object []) output)))))] (is (Host _.Expression _.Statement) (implementation (def (evaluate context [_ code]) (run! code)) (def execute run!) (def (define context custom [_ input]) (let [global (maybe.else (reference.artifact context) custom) @global (_.global global)] (do try.monad [.let [definition (_.set (list @global) input)] value (run! definition)] (in [global value definition])))) (def (ingest context content) (|> content (at utf8.codec decoded) try.trusted (as _.Statement))) (def (re_learn context custom content) (run! content)) (def (re_load context custom content) (do try.monad [_ (run! content)] (run! (_.global (reference.artifact context)))))))))) (for @.jvm (these (exception.def .public (invaid_phase_application [partial_application arity]) (Exception [(List Any) (List Any)]) (exception.report (list ["Partial Application" (%.nat (list.size partial_application))] ["Arity" (%.nat (list.size arity))]))) (def proc_type org/jruby/runtime/Block$Type (|> (org/jruby/runtime/Block::NULL_BLOCK) (org/jruby/runtime/Block::type))) (def phase_block_signature org/jruby/runtime/Signature (org/jruby/runtime/Signature::THREE_ARGUMENTS)) (def dummy_static_scope org/jruby/parser/StaticScope (|> (org/jruby/parser/StaticScopeFactory::new (!ruby_runtime)) (org/jruby/parser/StaticScopeFactory::getDummyScope))) (def phase_block_body org/jruby/runtime/BlockBody (<| (ffi.is org/jruby/runtime/BlockBody) (ffi.object [] org/jruby/runtime/BlockBody [] [org/jruby/runtime/Signature ..phase_block_signature] ... Methods (org/jruby/runtime/BlockBody [] (getFile this []) java/lang/String (ffi.as_string "YOLO")) (org/jruby/runtime/BlockBody [] (getLine this []) int (ffi.as_int (hex "+ABC,123"))) (org/jruby/runtime/BlockBody [] (getStaticScope this []) org/jruby/parser/StaticScope ..dummy_static_scope) (org/jruby/runtime/BlockBody [] (setStaticScope self [_ org/jruby/parser/StaticScope]) void []) (org/jruby/runtime/BlockBody [] (doYield self [_ org/jruby/runtime/ThreadContext _ org/jruby/runtime/Block _ org/jruby/runtime/builtin/IRubyObject]) org/jruby/runtime/builtin/IRubyObject (undefined)) (org/jruby/runtime/BlockBody [] (doYield self [_ org/jruby/runtime/ThreadContext _ org/jruby/runtime/Block _ [org/jruby/runtime/builtin/IRubyObject] _ org/jruby/runtime/builtin/IRubyObject]) org/jruby/runtime/builtin/IRubyObject (undefined)) ))) (def (host_phase partial_application phase) (All (_ s i o) (-> (List Any) (Phase s i o) org/jruby/RubyProc)) (let [block (ffi.object [] org/jruby/runtime/Block [] [org/jruby/runtime/BlockBody ..phase_block_body] ... Methods (org/jruby/runtime/Block [] (call this [_thread_context org/jruby/runtime/ThreadContext inputs [org/jruby/runtime/builtin/IRubyObject] _block org/jruby/runtime/Block]) org/jruby/runtime/builtin/IRubyObject (<| try.trusted (do [! try.monad] [inputs (|> inputs (array.list {.#None}) (monad.each ! (|>> (ffi.is java/lang/Object) ..read)))]) (when inputs ... It seems that org/jruby/runtime/Block::call can misbehave when getting called with a Lux state value. (list info source location current_module modules scopes type_context expected seed scope_type_vars extensions eval host) (when partial_application (list partial/0 partial/1) (in (..to_host ((as (-> Any Any Any Any) phase) partial/0 partial/1 [info source location current_module modules scopes type_context expected seed scope_type_vars extensions eval host]))) _ (exception.except ..invaid_phase_application [partial_application inputs])) (list) {try.#Success (<| (ffi.is org/jruby/runtime/builtin/IRubyObject) (host_phase partial_application phase))} (list input/0) (when partial_application (list) (in (<| (ffi.is org/jruby/runtime/builtin/IRubyObject) (host_phase (list input/0) phase))) (list partial/0) (in (<| (ffi.is org/jruby/runtime/builtin/IRubyObject) (host_phase (list partial/0 input/0) phase))) (list partial/0 partial/1) (in (..to_host ((as (-> Any Any Any Any) phase) partial/0 partial/1 input/0))) _ (exception.except ..invaid_phase_application [partial_application inputs])) (list input/0 input/1) (when partial_application (list) (in (<| (ffi.is org/jruby/runtime/builtin/IRubyObject) (host_phase (list input/0 input/1) phase))) (list partial/0) (in (..to_host ((as (-> Any Any Any Any) phase) partial/0 input/0 input/1))) _ (exception.except ..invaid_phase_application [partial_application inputs])) (list input/0 input/1 input/2) (when partial_application (list) (in (..to_host ((as (-> Any Any Any Any) phase) input/0 input/1 input/2))) _ (exception.except ..invaid_phase_application [partial_application inputs])) _ (exception.except ..invaid_phase_application [partial_application inputs])))))] (org/jruby/RubyProc::newProc (!ruby_runtime) block ..proc_type))) (def phase_wrapper phase.Wrapper (for @.jvm (..host_phase (list)) @.ruby (|>>))) (def extender Extender ... TODO: Stop relying on coercions ASAP. (<| (as Extender) (function (@self handler)) (as Handler) (function (@self phase)) (as Phase) (function (@self archive parameters)) (as Operation) (function (@self state)) (as Try) try.trusted (as Try) (do try.monad [handler (try.of_maybe (..macro! handler)) output (org/jruby/RubyProc::call (!ruby_thread_context) (|> (ffi.array org/jruby/runtime/builtin/IRubyObject 4) (ffi.write! 0 (as org/jruby/runtime/builtin/IRubyObject (phase_wrapper phase))) (ffi.write! 1 (..to_host archive)) (ffi.write! 2 (..to_host parameters)) (ffi.write! 3 (..to_host state))) handler)] (..read (ffi.is java/lang/Object output)))))) @.ruby (def extender Extender (|>> as_expected))) (def platform (IO (Platform Register _.Expression _.Statement)) (do io.monad [host ..host] (in [platform.#file_system (file.async file.default) platform.#host host platform.#phase ruby.expression platform.#runtime runtime.translate platform.#phase_wrapper ..phase_wrapper platform.#write (|>> _.code (at utf8.codec encoded))]))) (def (lux_program context program) (Program _.Expression _.Statement) (let [normal_runtime? (_.do "const_defined?" (list (_.string (_.code _.command_line_arguments))) {.#None} (is _.CVar (_.manual "Object")))] (_.statement (_.apply_lambda (list (runtime.lux//program_args (_.? normal_runtime? _.command_line_arguments (_.array (list)))) _.nil) program)))) (def (declare_success! _) (-> Any (Async Any)) (async.future (at world/environment.default exit +0))) (def (lux_compiler it) (-> Any platform.Custom) (undefined)) (def _ (program [service cli.service] (exec (do async.monad [_ (/.compiler ..lux_compiler (context.ruby (cli.target service)) ..expander analysis.bundle ..platform translation.bundle extension.empty ..lux_program (reference.constant ruby/reference.system) ..extender service [packager.package (format (cli.target service) (at file.default separator) "program")])] (..declare_success! [])) (io.io []))))