diff options
author | Eduardo Julian | 2021-11-04 02:54:45 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-11-04 02:54:45 -0400 |
commit | 305a3b5bca562601ee37b4cac69dd02f245830db (patch) | |
tree | 05bb9afc3345e5f9570c5d4ec3c4461def637061 | |
parent | 0dd20865adaf872d63aea1037034d22a3b906aba (diff) |
Better method calls in Ruby.
7 files changed, 57 insertions, 57 deletions
diff --git a/lux-ruby/commands.md b/lux-ruby/commands.md index e5eaf2372..cbdc685e1 100644 --- a/lux-ruby/commands.md +++ b/lux-ruby/commands.md @@ -34,6 +34,14 @@ cd ~/lux/stdlib/ \ ``` cd ~/lux/lux-ruby/ \ -&& mvn install:install-file -Dfile=target/program.jar -DgroupId=com.github.luxlang -DartifactId=lux-ruby -Dversion=0.6.4-SNAPSHOT -Dpackaging=jar +&& mvn install:install-file -Dfile=target/program.jar -DgroupId=com.github.luxlang -DartifactId=lux-ruby -Dversion=0.6.5-SNAPSHOT -Dpackaging=jar + +cd ~/lux/lux-ruby/ && mvn deploy:deploy-file \ +-Durl=https://<username>:<password>@oss.sonatype.org/content/repositories/snapshots/ \ +-Dfile=target/program.jar \ +-DgroupId=com.github.luxlang \ +-DartifactId=lux-ruby \ +-Dversion=0.6.5-SNAPSHOT \ +-Dpackaging=jar ``` diff --git a/stdlib/source/library/lux/target/ruby.lux b/stdlib/source/library/lux/target/ruby.lux index 5d4971a0d..5eaaf8e1d 100644 --- a/stdlib/source/library/lux/target/ruby.lux +++ b/stdlib/source/library/lux/target/ruby.lux @@ -211,35 +211,24 @@ (text.enclosed ["{" "}"]) :abstraction)) - (type: .public Input - (Variant - {#Arguments (List Expression)} - {#Block Statement})) - (def: (control_structure content) (-> Text Text) (format content text.new_line "end" ..statement_suffix)) - (def: .public (apply/* input func) - (-> Input Expression Computation) - (case input - {#Arguments args} - (|> args - (list#each (|>> :representation)) - (text.interposed ..input_separator) - (text.enclosed ["(" ")"]) - (format (:representation func)) - :abstraction) - - {#Block body!} - (|> body! - :representation - ..nested - (format "do") - ..control_structure - (format (:representation func) " ") - :abstraction))) + (def: .public (apply/* arguments block_lambda func) + (-> (List Expression) (Maybe Expression) Expression Computation) + (let [arguments (|> arguments + (list#each (|>> :representation)) + (text.interposed ..input_separator) + (text.enclosed ["(" ")"])) + block (case block_lambda + {.#None} + "" + + {.#Some lambda} + (format " &" (:representation lambda)))] + (:abstraction (format (:representation func) arguments block)))) (def: .public (the field object) (-> Text Expression Access) @@ -428,13 +417,13 @@ (:representation on)))) ) -(def: .public (do method input object) - (-> Text Input Expression Computation) - (|> object (..the method) (..apply/* input))) +(def: .public (do method arguments block_lambda object) + (-> Text (List Expression) (Maybe Expression) Expression Computation) + (|> object (..the method) (..apply/* arguments block_lambda))) (def: .public (apply_lambda/* args lambda) (-> (List Expression) Expression Computation) - (..do "call" {#Arguments args} lambda)) + (..do "call" args {.#None} lambda)) (def: .public (cond clauses else!) (-> (List [Expression Statement]) Statement Statement) @@ -460,7 +449,7 @@ <definitions> (template.spliced <function>+)] (def: .public (<apply> function <inputs>) (-> Expression <types> Computation) - (..apply/* {#Arguments (.list <inputs>)} function)) + (..apply/* (.list <inputs>) {.#None} function)) (template [<function>] [(`` (def: .public (~~ (template.symbol [<function> "/" <arity>])) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux index a32f4ad15..9ea3621e3 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux @@ -144,7 +144,7 @@ (|> /.empty (/.install "syntax char case!" lux::syntax_char_case!) (/.install "is" (binary (function (_ [reference subject]) - (_.do "equal?" {_.#Arguments (list reference)} subject)))) + (_.do "equal?" (list reference) {.#None} subject)))) (/.install "try" (unary //runtime.lux//try)))) (def: (capped operation parameter subject) @@ -169,10 +169,10 @@ (/.install "*" (binary (product.uncurried (..capped _.*)))) (/.install "/" (binary (product.uncurried //runtime.i64//division))) (/.install "%" (binary (function (_ [parameter subject]) - (_.do "remainder" {_.#Arguments (list parameter)} subject)))) + (_.do "remainder" (list parameter) {.#None} subject)))) (/.install "f64" (unary (_./ (_.float +1.0)))) - (/.install "char" (unary (_.do "chr" {_.#Arguments (list (_.string "UTF-8"))}))) + (/.install "char" (unary (_.do "chr" (list (_.string "UTF-8")) {.#None}))) ))) (def: f64_procs @@ -184,11 +184,11 @@ (/.install "*" (binary (product.uncurried _.*))) (/.install "/" (binary (product.uncurried _./))) (/.install "%" (binary (function (_ [parameter subject]) - (_.do "remainder" {_.#Arguments (list parameter)} subject)))) + (_.do "remainder" (list parameter) {.#None} subject)))) (/.install "=" (binary (product.uncurried _.=))) (/.install "<" (binary (product.uncurried _.<))) - (/.install "i64" (unary (_.do "floor" {_.#Arguments (list)}))) - (/.install "encode" (unary (_.do "to_s" {_.#Arguments (list)}))) + (/.install "i64" (unary (_.do "floor" (list) {.#None}))) + (/.install "encode" (unary (_.do "to_s" (list) {.#None}))) (/.install "decode" (unary //runtime.f64//decode))))) (def: (text//char [subjectO paramO]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux index 99c008a2f..ab9718b40 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux @@ -35,7 +35,7 @@ (def: (array::new [size]) (Unary Expression) - (_.do "new" {_.#Arguments (list size)} (_.local "Array"))) + (_.do "new" (list size) {.#None} (_.local "Array"))) (def: array::length (Unary Expression) @@ -81,7 +81,7 @@ (do [! ////////phase.monad] [objectG (phase archive objectS) inputsG (monad.each ! (phase archive) inputsS)] - (in (_.do methodS {_.#Arguments inputsG} objectG))))])) + (in (_.do methodS inputsG {.#None} objectG))))])) (template [<!> <?> <unit>] [(def: <!> (Nullary Expression) (function.constant <unit>)) @@ -113,7 +113,7 @@ (do [! ////////phase.monad] [abstractionG (phase archive abstractionS) inputsG (monad.each ! (phase archive) inputsS)] - (in (_.apply/* {_.#Arguments inputsG} abstractionG))))])) + (in (_.apply/* inputsG {.#None} abstractionG))))])) (def: ruby::import (custom diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux index 8b60ef65a..766b4fa43 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux @@ -107,11 +107,11 @@ (def: (push! value) (-> Expression Statement) - (_.statement (|> @cursor (_.do "push" {_.#Arguments (list value)})))) + (_.statement (|> @cursor (_.do "push" (list value) {.#None})))) (def: peek_and_pop Expression - (|> @cursor (_.do "pop" {_.#Arguments (list)}))) + (|> @cursor (_.do "pop" (list) {.#None}))) (def: pop! Statement @@ -124,18 +124,20 @@ (def: save! Statement (.let [cursor (_.array_range (_.int +0) (_.int -1) @cursor)] - (_.statement (|> @savepoint (_.do "push" {_.#Arguments (list cursor)}))))) + (_.statement (|> @savepoint (_.do "push" (list cursor) {.#None}))))) (def: restore! Statement - (_.set (list @cursor) (|> @savepoint (_.do "pop" {_.#Arguments (list)})))) + (_.set (list @cursor) (|> @savepoint (_.do "pop" (list) {.#None})))) (def: fail! _.break) (def: (multi_pop! pops) (-> Nat Statement) - (_.statement (_.do "slice!" {_.#Arguments (list (_.int (i.* -1 (.int pops))) - (_.int (.int pops)))} + (_.statement (_.do "slice!" + (list (_.int (i.* -1 (.int pops))) + (_.int (.int pops))) + {.#None} @cursor))) (template [<name> <flag>] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux index 2053b6628..32c78830d 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux @@ -110,8 +110,8 @@ (_.return (_.lambda {.#None} (list (_.variadic @missing)) (_.return (|> @self (_.apply_lambda/* (list (_.splat (|> (_.array (list)) - (_.do "concat" {_.#Arguments (list @curried)}) - (_.do "concat" {_.#Arguments (list @missing)}))))))))))) + (_.do "concat" (list @curried) {.#None}) + (_.do "concat" (list @missing) {.#None}))))))))))) )))] _ (/////generation.execute! declaration) _ (/////generation.save! function_artifact {.#None} declaration)] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux index e0c33442d..e3d1e8dff 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux @@ -114,7 +114,7 @@ inputs)] (in (list (` (def: .public ((~ g!name) (~+ inputsC)) (-> (~+ inputs_typesC) Computation) - (_.apply/* {_.#Arguments (list (~+ inputsC))} + (_.apply/* (list (~+ inputsC)) {.#None} (~ runtime_name)))) (` (def: (~ (code.local_symbol (format "@" name))) @@ -304,7 +304,7 @@ ) (runtime: (i64//division parameter subject) - (let [extra (_.do "remainder" {_.#Arguments (list parameter)} subject)] + (let [extra (_.do "remainder" (list parameter) {.#None} subject)] (_.return (|> subject (_.- extra) (_./ parameter))))) @@ -326,7 +326,7 @@ (with_vars [@input @temp] ($_ _.then (_.set (list @input) inputG) - (_.set (list @temp) (_.do "to_f" {_.#Arguments (list)} @input)) + (_.set (list @temp) (_.do "to_f" (list) {.#None} @input)) (_.if ($_ _.or (_.not (_.= (_.float +0.0) @temp)) (_.= (_.string "0") @input) @@ -344,7 +344,7 @@ (runtime: (text//index subject param start) (with_vars [idx] ($_ _.then - (_.set (list idx) (|> subject (_.do "index" {_.#Arguments (list param start)}))) + (_.set (list idx) (|> subject (_.do "index" (list param start) {.#None}))) (_.if (_.= _.nil idx) (_.return ..none) (_.return (..some idx)))))) @@ -361,7 +361,7 @@ (runtime: (text//char idx text) (_.if (|> idx (within? (_.the "length" text))) - (_.return (|> text (_.array_range idx idx) (_.do "ord" {_.#Arguments (list)}))) + (_.return (|> text (_.array_range idx idx) (_.do "ord" (list) {.#None}))) (_.statement (_.raise (_.string "[Lux Error] Cannot get char from text."))))) (def: runtime//text @@ -386,15 +386,16 @@ (def: runtime Statement ($_ _.then - (_.when (_.and (_.not (_.do "method_defined?" {_.#Arguments (list (_.string "remainder"))} + (_.when (_.and (_.not (_.do "method_defined?" (list (_.string "remainder")) {.#None} (_.local "Numeric"))) - (_.do "method_defined?" {_.#Arguments (list (_.string "remainder_of_divide"))} + (_.do "method_defined?" (list (_.string "remainder_of_divide")) {.#None} (_.local "Numeric"))) ... We're in DragonRuby territory. (_.statement - (_.do "class_eval" {_.#Block (_.statement - (_.alias_method/2 (_.string "remainder") - (_.string "remainder_of_divide")))} + (_.do "class_eval" (list) {.#Some (_.lambda {.#None} (list (_.local "_")) + (_.statement + (_.alias_method/2 (_.string "remainder") + (_.string "remainder_of_divide"))))} (_.local "Numeric")))) runtime//adt runtime//lux |