Skip to content

Commit

Permalink
Special _"if"_ optimization for matching against binary variants.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Feb 17, 2025
1 parent 6b4a53e commit 417a10f
Show file tree
Hide file tree
Showing 101 changed files with 1,452 additions and 1,125 deletions.
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ aedifex.jar

/lux-jvm/RELEASE
/lux-jvm/target
/lux-jvm/source/library
/lux-jvm/source/unsafe
/lux-jvm/source/projection
/lux-jvm/source/injection

/lux-js/RELEASE
/lux-js/target
Expand All @@ -36,10 +32,6 @@ aedifex.jar

/lux-lua/RELEASE
/lux-lua/target
/lux-lua/source/library
/lux-lua/source/unsafe
/lux-lua/source/projection
/lux-lua/source/injection

/lux-ruby/RELEASE
/lux-ruby/target
Expand Down
6 changes: 3 additions & 3 deletions aedifex/source/program/aedifex/command/auto.lux
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@
(monad.let [! ///action.monad]
[_ (list.each' ! (by watcher start watch.modification) targets)
_ <call>]
(loop (again [_ []])
(loop (of [_ []])
(monad.let !
[_ (..pause delay)
events (by watcher poll [])]
(when events
(list)
(again [])
(of [])

non_empty
(monad.let !
[_ <call>]
(again [])))))))))))
(of [])))))))))))
10 changes: 5 additions & 5 deletions aedifex/source/program/aedifex/command/build.lux
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@
text.equivalence)

(the (< left right)
(loop (again [left (view.as list.stack (text.all_split_by ..version_delimiter left))
right (view.as list.stack (text.all_split_by ..version_delimiter right))])
(loop (of [left (view.as list.stack (text.all_split_by ..version_delimiter left))
right (view.as list.stack (text.all_split_by ..version_delimiter right))])
(when [left right]
[{.:Top leftH leftT} {.:Top rightH rightT}]
(if (text.= leftH rightH)
(again leftT rightT)
(of leftT rightT)
(or (n.< (text.size leftH) (text.size rightH))
(text:< leftH rightH)))

Expand Down Expand Up @@ -230,7 +230,7 @@
(future.Resolver (Try Any))]
(future.future []))
_ (|> (by process <capability> [])
(future.upon! (function (again ?line)
(future.upon! (function (of ?line)
(when ?line
{try.:Failure error}
(if (exception.is? shell.no_more_output error)
Expand All @@ -245,7 +245,7 @@
(write! {try.:Failure error})

{try.:Success _}
(future.upon! again
(future.upon! of
(by process <capability> []))))
(is (Future (Try Any))
(console.write_line line console))))))
Expand Down
4 changes: 2 additions & 2 deletions aedifex/source/program/aedifex/command/clean.lux
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
? (by fs directory? target)
_ (let [! ///action.monad]
(if ?
(loop (again [root target])
(loop (of [root target])
(monad.let !
[_ (..clean_files! fs root)
_ (|> root
(by fs sub_directories)
(by ! each (list.each' ! again))
(by ! each (list.each' ! of))
(by ! conjoint))]
(by fs delete root)))
(by ! pure [])))]
Expand Down
8 changes: 4 additions & 4 deletions aedifex/source/program/aedifex/hash.lux
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@
(-> Text (Try (Hash h)))))
(let [hash_size (..hash_size injection)]
(if (n.= size hash_size)
(loop (again [input injection
chunk 0
output (binary.empty hash_size)])
(loop (of [input injection
chunk 0
output (binary.empty hash_size)])
(let [index (n.x chunk /64.bytes_per_i64)]
(when (text.split_at ..hex_per_chunk input)
{.:Some [head tail]}
(monad.let try.monad
[head (by n.base_16 of head)
output (binary.has_64! index head output)]
(again tail (++ chunk) output))
(of tail (++ chunk) output))

{.:None}
(`` (when (..hash_size input)
Expand Down
10 changes: 5 additions & 5 deletions lux-c++/source/program.lux
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@
(-> Runtime (-> Runtime Any Value) Any
Any)
(let [arity (tuple:arity @ input)]
(loop (next [member 0
output (array.empty arity)])
(loop (of [member 0
output (array.empty arity)])
(if (n.< arity member)
(next (++ member)
(array.has! member (lux_value @ (tuple:member @ member input))
output))
(of (++ member)
(array.has! member (lux_value @ (tuple:member @ member input))
output))
output))))

(the (lux_value @ it)
Expand Down
6 changes: 3 additions & 3 deletions lux-cl/source/program.lux
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,16 @@
(-> (Reader org/armedbear/lisp/LispObject)
(Reader org/armedbear/lisp/SimpleVector))
(let [size (.natural (org/armedbear/lisp/LispObject:length host_object))]
(loop (again [idx 0
output (as (Array Any) (array.new size))])
(loop (of [idx 0
output (as (Array Any) (array.new size))])
(if (n.< size idx)
... TODO: Start using "SVREF" instead of "elt" ASAP
(when (read (org/armedbear/lisp/LispObject:elt (.integer idx) host_object))
{try.:Failure error}
{try.:Failure error}

{try.:Success member}
(again (++ idx) (array.write! idx (as Any member) output)))
(of (++ idx) (array.write! idx (as Any member) output)))
{try.:Success output}))))

(the (read host_object)
Expand Down
12 changes: 6 additions & 6 deletions lux-js/source/program.lux
Original file line number Diff line number Diff line change
Expand Up @@ -397,26 +397,26 @@
(Maybe (Array java/lang/Object)))
(if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject:isArray [] js_object))
(let [num_keys (.natural (ffi.of_int (org/openjdk/nashorn/api/scripting/ScriptObjectMirror:size [] js_object)))]
(loop (again [idx 0
output (is (Array java/lang/Object)
(array.empty num_keys))])
(loop (of [idx 0
output (is (Array java/lang/Object)
(array.empty num_keys))])
(if (n.< num_keys idx)
(when (org/openjdk/nashorn/api/scripting/JSObject:getMember [(ffi.as_string (%.natural idx))] js_object)
{.:Some member}
(when (ffi.as org/openjdk/nashorn/internal/runtime/Undefined member)
{.:Some _}
(again (++ idx) output)
(of (++ idx) output)

{.:None}
(when (lux_object member)
{try.:Success parsed_member}
(again (++ idx) (array.has! idx (as (-> Any java/lang/Object) parsed_member) output))
(of (++ idx) (array.has! idx (as (-> Any java/lang/Object) parsed_member) output))

{try.:Failure error}
{.:None}))

{.:None}
(again (++ idx) output))
(of (++ idx) output))
{.:Some output})))
{.:None}))

Expand Down
30 changes: 0 additions & 30 deletions lux-jvm/project.clj

This file was deleted.

3 changes: 3 additions & 0 deletions lux-jvm/project.lux
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"lux" ["com.github.luxlang" "lux-jvm" "0.9.0-SNAPSHOT" "jar"]
"dependencies" [... ["com.github.luxlang" "stdlib" "0.9.0-SNAPSHOT" "tar"]
["com.github.luxlang" "lux-jvm-function" "0.6.5" "jar"]]

"sources" ["../stdlib/source"
"source"]

"program" program._]]
8 changes: 4 additions & 4 deletions lux-php/source/program.lux
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@
php/runtime/memory/ArrayMemory:size
(as Natural)
--)]
(loop (again [idx 0
output (as (Array Any) (array.new size))])
(loop (of [idx 0
output (as (Array Any) (array.new size))])
(if (n.< size idx)
(let [value (|> host_object
(php/runtime/memory/ArrayMemory:get (php/runtime/memory/LongMemory:new (.integer idx)))
Expand All @@ -328,12 +328,12 @@
php/runtime/memory/ReferenceMemory:getValue)]
(when (ffi.as php/runtime/memory/NullMemory value)
{.:Some _}
(again (++ idx) output)
(of (++ idx) output)

{.:None}
(when (read value)
{try.:Success lux_value}
(again (++ idx) (array.write! idx lux_value output))
(of (++ idx) (array.write! idx lux_value output))

error
error)))
Expand Down
6 changes: 3 additions & 3 deletions lux-r/source/program.lux
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@
(the (read_tuple read host_object)
(-> (Reader java/lang/Object) (Reader org/renjin/sexp/ListVector))
(let [size (.natural (org/renjin/sexp/ListVector:length host_object))]
(loop (again [idx 0
output (as (Array Any) (array.new size))])
(loop (of [idx 0
output (as (Array Any) (array.new size))])
(if (n.< size idx)
(when (|> host_object (org/renjin/sexp/ListVector:get_index (.integer idx)) (as java/lang/Object) read)
{try.:Failure error}
{try.:Failure error}

{try.:Success member}
(again (++ idx) (array.write! idx (as Any member) output)))
(of (++ idx) (array.write! idx (as Any member) output)))
{try.:Success output}))))

(the (field_class field host_object)
Expand Down
16 changes: 8 additions & 8 deletions stdlib/source/documentation/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,13 @@
($.example (' (the .public (range enum from to)
(for_any (_ a) (-> (Enum a) a a (List a)))
(let [(open "[0]") enum]
(loop (again [end to
output {.:Empty}])
(loop (of [end to
output {.:Empty}])
(if (< end from)
(again (pred end) {.:Top end output})
(of (pred end) {.:Top end output})

(< from end)
(again (succ end) {.:Top end output})
(of (succ end) {.:Top end output})

... (= end from)
{.:Top end output})))))))
Expand Down Expand Up @@ -677,12 +677,12 @@
))

($.definition /.loop
(text "Allows arbitrary looping, using the 'again' form to re-start the loop."
(text "Allows arbitrary looping, using the 'of' form to re-start the loop."
\n "Can be used in monadic code to create monadic loops.")
($.example (' (loop (again [count +0
x init])
($.example (' (loop (of [count +0
x init])
(if (< +10 count)
(again (++ count) (f x))
(of (++ count) (f x))
x))))

($.comment "Loops can also be given custom names.")
Expand Down
14 changes: 8 additions & 6 deletions stdlib/source/library/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -1664,13 +1664,15 @@
(the' .private (right_associativity op a1 a2)
(-> Code Code Code
Code)
(code:form (.list_composite# (.when# op
{:Form _ parts}
parts
(.when# op
{:Form _ parts}
(code:form (.list_composite# parts (list a1 a2)))

_
(list op))
(list a1 a2))))
{:Variant _ parts}
(code:variant (.list_composite# parts (list a1 a2)))

_
(code:form (list op a1 a2))))

(the' .private (function:flipped func)
(for_any (_ left right output)
Expand Down
10 changes: 5 additions & 5 deletions stdlib/source/library/lux/abstract/enum.lux
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
(let [(open "/:[0]") enum]
(if (/:= from to)
(list from)
(loop (again [end to
output (`` (is (List (,, (type_of from)))
(list)))])
(loop (of [end to
output (`` (is (List (,, (type_of from)))
(list)))])
(if (/:< end from)
(again (/:pred end) (.list_composite# (list end) output))
(of (/:pred end) (.list_composite# (list end) output))

(/:< from end)
(again (/:succ end) (.list_composite# (list end) output))
(of (/:succ end) (.list_composite# (list end) output))

... (/:= end from)
(.list_composite# (list end) output))))))
Loading

0 comments on commit 417a10f

Please sign in to comment.