From 913171900fd11272ca328ded6553a56423db1e13 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 13 Jan 2023 16:14:20 -0400 Subject: Can now compile complex values (i.e. variants & tuples) in C++. --- stdlib/source/test/lux/meta.lux | 276 +++++++++++---------- .../test/lux/meta/compiler/language/lux/phase.lux | 4 +- .../language/lux/phase/translation/jvm/runtime.lux | 52 ++++ .../test/lux/meta/compiler/meta/archive/module.lux | 7 +- stdlib/source/test/lux/world/finance/money.lux | 33 ++- .../source/test/lux/world/time/series/average.lux | 83 ++++--- 6 files changed, 270 insertions(+), 185 deletions(-) create mode 100644 stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/runtime.lux (limited to 'stdlib/source/test/lux') diff --git a/stdlib/source/test/lux/meta.lux b/stdlib/source/test/lux/meta.lux index bb5da38b8..03ac91796 100644 --- a/stdlib/source/test/lux/meta.lux +++ b/stdlib/source/test/lux/meta.lux @@ -802,144 +802,154 @@ (try.else false)))) ))) -... (def label_related -... Test -... (do [! random.monad] -... [current_module (random.upper_cased 1) -... label_module (random.only (|>> (text#= current_module) not) -... (random.upper_cased 1)) +(def label_related + Test + (do [! random.monad] + [current_module (random.upper_cased 1) + label_module (random.upper_cased 2) -... name_0 (random.upper_cased 1) -... name_1 (random.only (|>> (text#= name_0) not) -... (random.upper_cased 1)) + name_0 (random.upper_cased 3) + ... name_1 (random.upper_cased 4) -... .let [random_tag (of ! each (|>> [label_module]) -... (random.upper_cased 1)) -... random_labels (is (Random [Text (List Text)]) -... (do ! -... [head (random.lower_cased 5)] -... (|> (random.lower_cased 5) -... (random.only (|>> (text#= head) not)) -... (random.set text.hash 3) -... (of ! each set.list) -... (random.and (in head)))))] -... tags_0 random_labels -... tags_1 (let [set/0 (set.of_list text.hash {.#Item tags_0})] -... (random.only (|>> {.#Item} -... (list.any? (set.member? set/0)) -... not) -... random_labels)) -... .let [type_0 {.#Nominal name_0 (list)} -... type_1 {.#Nominal name_1 (list)} + .let [random_tag (of ! each (|>> [label_module]) + (random.upper_cased 1)) + random_labels (is (-> Nat + (Random [Text (List Text)])) + (function (_ size) + (do ! + [head (random.lower_cased size)] + (|> (random.lower_cased size) + (random.only (|>> (text#= head) not)) + (random.set text.hash 3) + (of ! each set.list) + (random.and (in head))))))] + tags_0 (random_labels 5) + ... tags_1 (let [set/0 (set.of_list text.hash {.#Item tags_0})] + ... (random.only (|>> {.#Item} + ... (list.any? (set.member? set/0)) + ... not) + ... random_labels)) + .let [type_0 {.#Nominal name_0 (list)} + ... type_1 {.#Nominal name_1 (list)} -... expected_lux -... (is Lux -... [.#info [.#target "" -... .#version "" -... .#mode {.#Build} -... .#configuration (list)] -... .#source [location.dummy 0 ""] -... .#location location.dummy -... .#current_module {.#Some current_module} -... .#modules (list [current_module -... [.#module_hash 0 -... .#module_aliases (list) -... .#definitions (list) -... .#imports (list label_module) -... .#module_state {.#Active}]] -... [label_module -... [.#module_hash 0 -... .#module_aliases (list) -... .#definitions (list.partial [name_0 {.#Type [true type_0 {.#Left tags_0}]}] -... [name_1 {.#Type [true type_1 {.#Right tags_1}]}] -... (all list#composite -... (|> {.#Item tags_0} -... list.enumeration -... (list#each (function (_ [index short]) -... [short {.#Tag [true type_0 {.#Item tags_0} index]}]))) -... (|> {.#Item tags_1} -... list.enumeration -... (list#each (function (_ [index short]) -... [short {.#Slot [true type_1 {.#Item tags_1} index]}]))))) -... .#imports (list) -... .#module_state {.#Active}]]) -... .#scopes (list) -... .#type_context [.#ex_counter 0 -... .#var_counter 0 -... .#var_bindings (list)] -... .#expected {.#None} -... .#seed 0 -... .#scope_type_vars (list) -... .#extensions [] -... .#eval (as (-> Type Code (Meta Any)) []) -... .#host []])]] -... (all _.and -... (_.coverage [/.tag_lists] -... (let [equivalence (list.equivalence -... (product.equivalence -... (list.equivalence symbol.equivalence) -... type.equivalence))] -... (|> (/.tag_lists label_module) -... (/.result expected_lux) -... (try#each (of equivalence = (list [(list#each (|>> [label_module]) {.#Item tags_0}) -... type_0] -... [(list#each (|>> [label_module]) {.#Item tags_1}) -... type_1]))) -... (try.else false)))) -... (_.coverage [/.tags_of] -... (|> (/.tags_of [label_module name_1]) -... (/.result expected_lux) -... (try#each (of (maybe.equivalence (list.equivalence symbol.equivalence)) = {.#Some (list#each (|>> [label_module]) {.#Item tags_1})})) -... (try.else false))) -... ... (_.coverage [/.tag] -... ... (|> {.#Item tags_0} -... ... list.enumeration -... ... (list.every? (function (_ [expected_index label]) -... ... (|> [label_module label] -... ... /.tag -... ... (/.result expected_lux) -... ... (!expect (^.multi {try.#Success [actual_index actual_tags actual_type]} -... ... (let [correct_index! -... ... (n.= expected_index -... ... actual_index) + expected_lux + (is Lux + [.#info [.#target "" + .#version "" + .#mode {.#Build} + .#configuration (list)] + .#source [location.dummy 0 ""] + .#location location.dummy + .#current_module {.#Some current_module} + .#modules (list [current_module + [.#module_hash 0 + .#module_aliases (list) + .#definitions (list) + .#imports (list label_module) + .#module_state {.#Active}]] + [label_module + [.#module_hash 0 + .#module_aliases (list) + .#definitions (list.partial [name_0 [true {.#Definition [.Type type_0]}]] + ... [name_1 {.#Type [true type_1 {.#Right tags_1}]}] + (all list#composite + (let [cohort (is (List Symbol) + (list#each (|>> [label_module]) + {.#Item tags_0})) + last (-- (list.size cohort)) + right? (n.= last)] + (|> {.#Item tags_0} + list.enumeration + (list#each (function (_ [index short]) + [short [true {.#Definition [.Tag + (|> [{.#Some [index (right? index) cohort]} type_0] + (is Label) + (as Tag))]}]])))) + ... (|> {.#Item tags_1} + ... list.enumeration + ... (list#each (function (_ [index short]) + ... [short {.#Slot [true type_1 {.#Item tags_1} index]}]))) + )) + .#imports (list) + .#module_state {.#Active}]]) + .#scopes (list) + .#type_context [.#ex_counter 0 + .#var_counter 0 + .#var_bindings (list)] + .#expected {.#None} + .#seed 0 + .#scope_type_vars (list) + .#extensions [] + .#eval (as (-> Type Code (Meta Any)) []) + .#host []])]] + (all _.and + (_.coverage [/.tag_lists] + (let [equivalence (list.equivalence + (product.equivalence + (list.equivalence symbol.equivalence) + type.equivalence))] + (|> (/.tag_lists label_module) + (/.result expected_lux) + (try#each (of equivalence = (list [(list#each (|>> [label_module]) {.#Item tags_0}) + type_0] + ... [(list#each (|>> [label_module]) {.#Item tags_1}) + ... type_1] + ))) + (try.else false)))) + ... (_.coverage [/.tags_of] + ... (|> (/.tags_of [label_module name_1]) + ... (/.result expected_lux) + ... (try#each (of (maybe.equivalence (list.equivalence symbol.equivalence)) = {.#Some (list#each (|>> [label_module]) {.#Item tags_1})})) + ... (try.else false))) + ... (_.coverage [/.tag] + ... (|> {.#Item tags_0} + ... list.enumeration + ... (list.every? (function (_ [expected_index label]) + ... (|> [label_module label] + ... /.tag + ... (/.result expected_lux) + ... (!expect (^.multi {try.#Success [actual_index actual_tags actual_type]} + ... (let [correct_index! + ... (n.= expected_index + ... actual_index) -... ... correct_tags! -... ... (of (list.equivalence symbol.equivalence) = -... ... (list#each (|>> [label_module]) {.#Item tags_0}) -... ... actual_tags) + ... correct_tags! + ... (of (list.equivalence symbol.equivalence) = + ... (list#each (|>> [label_module]) {.#Item tags_0}) + ... actual_tags) -... ... correct_type! -... ... (type#= type_0 -... ... actual_type)] -... ... (and correct_index! -... ... correct_tags! -... ... correct_type!)))) -... ... ))))) -... ... (_.coverage [/.slot] -... ... (|> {.#Item tags_1} -... ... list.enumeration -... ... (list.every? (function (_ [expected_index label]) -... ... (|> [label_module label] -... ... /.slot -... ... (/.result expected_lux) -... ... (!expect (^.multi {try.#Success [actual_index actual_tags actual_type]} -... ... (let [correct_index! -... ... (n.= expected_index -... ... actual_index) + ... correct_type! + ... (type#= type_0 + ... actual_type)] + ... (and correct_index! + ... correct_tags! + ... correct_type!)))) + ... ))))) + ... (_.coverage [/.slot] + ... (|> {.#Item tags_1} + ... list.enumeration + ... (list.every? (function (_ [expected_index label]) + ... (|> [label_module label] + ... /.slot + ... (/.result expected_lux) + ... (!expect (^.multi {try.#Success [actual_index actual_tags actual_type]} + ... (let [correct_index! + ... (n.= expected_index + ... actual_index) -... ... correct_tags! -... ... (of (list.equivalence symbol.equivalence) = -... ... (list#each (|>> [label_module]) {.#Item tags_1}) -... ... actual_tags) + ... correct_tags! + ... (of (list.equivalence symbol.equivalence) = + ... (list#each (|>> [label_module]) {.#Item tags_1}) + ... actual_tags) -... ... correct_type! -... ... (type#= type_1 -... ... actual_type)] -... ... (and correct_index! -... ... correct_tags! -... ... correct_type!)))) -... ... ))))) -... ))) + ... correct_type! + ... (type#= type_1 + ... actual_type)] + ... (and correct_index! + ... correct_tags! + ... correct_type!)))) + ... ))))) + ))) (def injection (Injection Meta) @@ -1030,8 +1040,8 @@ ..definition_related ..search_related ..locals_related - ... (_.for [.Label] - ... ..label_related) + (_.for [.Label] + ..label_related) )) /code.test diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/phase.lux b/stdlib/source/test/lux/meta/compiler/language/lux/phase.lux index ba39fe79e..d9af04496 100644 --- a/stdlib/source/test/lux/meta/compiler/language/lux/phase.lux +++ b/stdlib/source/test/lux/meta/compiler/language/lux/phase.lux @@ -31,7 +31,8 @@ ["[1]/[0]" host] ["[1]/[0]" primitive] ["[1]/[0]" type] - ["[1]/[0]" value]]]]) + ["[1]/[0]" value] + ["[1]/[0]" runtime]]]]) (def (injection value) (All (_ of) @@ -219,4 +220,5 @@ /translation/jvm/primitive.test /translation/jvm/type.test /translation/jvm/value.test + /translation/jvm/runtime.test ))) diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/runtime.lux b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/runtime.lux new file mode 100644 index 000000000..97035f3c5 --- /dev/null +++ b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/runtime.lux @@ -0,0 +1,52 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)]] + [control + ["[0]" io] + ["[0]" try]] + [math + ["[0]" random (.only Random)]] + [meta + [type + ["[0]" check]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" / (.only) + [// + ["[0]" host] + [//// + ["[0]" phase] + ["[0]" translation]]]]]) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [module (random.lower_cased 1)]) + (`` (all _.and + (,, (with_template [ ] + [(_.coverage [] + (check.subsumes? ))] + + [/.State translation.State] + [/.Operation translation.Operation] + [/.Phase translation.Phase] + [/.Handler translation.Handler] + [/.Bundle translation.Bundle] + [/.Extender translation.Extender] + )) + (_.coverage [/.translation] + (let [[_ host] (io.run! host.host) + state (is /.State + (translation.state host module))] + (|> (do try.monad + [_ (phase.result state + (do phase.monad + [_ (translation.set_buffer translation.empty_buffer)] + /.translation))] + (in true)) + (try.else false)))) + )))) diff --git a/stdlib/source/test/lux/meta/compiler/meta/archive/module.lux b/stdlib/source/test/lux/meta/compiler/meta/archive/module.lux index a8075cc24..f965326b8 100644 --- a/stdlib/source/test/lux/meta/compiler/meta/archive/module.lux +++ b/stdlib/source/test/lux/meta/compiler/meta/archive/module.lux @@ -21,7 +21,9 @@ ["[1][0]" descriptor]]) (def .public (random it) - (All (_ a) (-> (Random a) (Random (/.Module a)))) + (All (_ of) + (-> (Random of) + (Random (/.Module of)))) (all random.and random.nat (/descriptor.random 0) @@ -34,7 +36,8 @@ (def .public test Test (<| (_.covering /._) - (_.for [/.Module]) + (_.for [/.Module + /.#id /.#descriptor /.#document]) (all _.and (_.coverage [/.ID /.runtime] (n.= 0 /.runtime)) diff --git a/stdlib/source/test/lux/world/finance/money.lux b/stdlib/source/test/lux/world/finance/money.lux index cc798afdd..798b1966f 100644 --- a/stdlib/source/test/lux/world/finance/money.lux +++ b/stdlib/source/test/lux/world/finance/money.lux @@ -39,10 +39,11 @@ Test (<| (_.covering /._) (do [! random.monad] - [expected_amount random.nat + [.let [random_amount (of ! each (n.% 1000,00) random.nat)] + expected_amount random_amount - expected_parameter (random.only (n.> 0) random.nat) - expected_subject random.nat]) + expected_parameter (random.only (n.> 0) random_amount) + expected_subject random_amount]) (_.for [/.Money]) (all _.and (_.for [/.equivalence /.=] @@ -56,16 +57,22 @@ (same? expected_amount (/.amount it))))) (_.coverage [/.+ /.-] (let [parameter (/.money currency.usd expected_parameter) - subject (/.money currency.usd expected_subject)] - (and (|> subject - (/.+ parameter) - (of /.equivalence = subject) - not) - (|> subject - (/.+ parameter) - (/.- parameter) - (maybe#each (of /.equivalence = subject)) - (maybe.else false))))) + subject (/.money currency.usd expected_subject) + + addition_shifts_the_value! + (|> subject + (/.+ parameter) + (of /.equivalence = subject) + not) + + addition_and_subtraction_are_inverses! + (|> subject + (/.+ parameter) + (/.- parameter) + (maybe#each (of /.equivalence = subject)) + (maybe.else false))] + (and addition_shifts_the_value! + addition_and_subtraction_are_inverses!))) (_.coverage [/.min] (let [expected_parameter (/.money currency.usd expected_parameter) expected_subject (/.money currency.usd expected_subject)] diff --git a/stdlib/source/test/lux/world/time/series/average.lux b/stdlib/source/test/lux/world/time/series/average.lux index 5cd02181a..fcc65673f 100644 --- a/stdlib/source/test/lux/world/time/series/average.lux +++ b/stdlib/source/test/lux/world/time/series/average.lux @@ -9,7 +9,8 @@ [math ["[0]" random (.only Random)] [number - ["n" nat]]] + ["n" nat] + ["f" frac]]] [world [time ["[0]" instant (.use "[1]#[0]" order)] @@ -35,13 +36,27 @@ //.#interval interval //.#data data]))) +(def (well_windowed? input additional output) + (All (_ input output) + (-> (/.Series input) Nat (/.Series output) + Bit)) + (let [correct_start! + (instant#< (//.start output) + (//.start input)) + + correct_size! + (n.= (n.- (++ additional) (//.size input)) + (//.size output))] + (and correct_start! + correct_size!))) + (def .public test Test (<| (_.covering /._) (do [! random.monad] [expected_events (of ! each (|>> (n.% 10) ++) random.nat) input (series expected_events) - expected_window_extras (of ! each (n.% expected_events) random.nat)]) + additional (of ! each (n.% expected_events) random.nat)]) (all _.and (_.coverage [/.cumulative] (let [output (/.cumulative input)] @@ -52,11 +67,8 @@ (_.coverage [/.windows] (<| (try.else false) (do try.monad - [output (/.windows expected_window_extras input)] - (in (and (instant#= (//.start input) - (//.start output)) - (n.= (n./ (++ expected_window_extras) (//.size input)) - (//.size output))))))) + [output (/.windows additional input)] + (in (well_windowed? input additional output))))) (_.coverage [/.window_size_is_too_large] (when (/.windows (++ expected_events) input) {try.#Failure error} @@ -64,37 +76,36 @@ {try.#Success _} false)) - (<| (_.for [/.Average /.moving]) + (<| (_.for [/.Average]) (all _.and - (_.coverage [/.Factor /.simple_factor /.exponential] - (<| (try.else false) - (do try.monad - [output (/.moving (/.exponential /.simple_factor) - expected_window_extras - input)] - (in (and (instant#< (//.start output) - (//.start input)) - (n.= (n.- expected_window_extras (//.size input)) - (//.size output))))))) - (_.coverage [/.simple] - (<| (try.else false) - (do try.monad - [output (/.moving /.simple - expected_window_extras - input)] - (in (and (instant#< (//.start output) - (//.start input)) - (n.= (n.- expected_window_extras (//.size input)) - (//.size output))))))) - (_.coverage [/.weighted] + (_.coverage [/.exponential /.simple /.weighted + + /.Factor /.simple_factor] + (let [exponential (/.exponential /.simple_factor input) + simple (/.simple input) + weighted (/.weighted input)] + (and (not (f.= exponential simple)) + (not (f.= exponential weighted)) + (not (f.= simple weighted))))) + (_.coverage [/.moving] (<| (try.else false) (do try.monad - [output (/.moving /.weighted - expected_window_extras - input)] - (in (and (instant#< (//.start output) - (//.start input)) - (n.= (n.- expected_window_extras (//.size input)) - (//.size output))))))) + [exponential (/.moving (/.exponential /.simple_factor) + additional + input) + simple (/.moving /.simple + additional + input) + weighted (/.moving /.weighted + additional + input) + .let [(open "//#[0]") (//.equivalence f.equivalence)]] + (in (and (and (well_windowed? input additional exponential) + (well_windowed? input additional simple) + (well_windowed? input additional weighted)) + (and (not (//#= exponential simple)) + (not (//#= exponential weighted)) + (not (//#= simple weighted))) + ))))) )) ))) -- cgit v1.2.3