Skip to content

Commit

Permalink
New type for Type (part 6).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 11, 2024
1 parent 5c76363 commit 8235d8f
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 205 deletions.
2 changes: 1 addition & 1 deletion documentation/bookmark/compilation/target/c++.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Memory management

0. []()
0. [Memory and Performance Overhead of Smart Pointers](https://www.modernescpp.com/index.php/memory-and-performance-overhead-of-smart-pointer)
0. [](https://coderedirect.com/questions/464444/c-atomic-cascompare-and-swap-operation-does-not-change-value)
0. [C++ Shared_Ptr implementation](https://codereview.stackexchange.com/questions/254279/c-shared-ptr-implementation)
Expand All @@ -22,6 +21,7 @@

# Reference

0. [Lightning Talk: Writing a Better std::move - Jonathan Müller - CppCon 2023](https://www.youtube.com/watch?v=hvnl6T2MnUk)
0. [CppCon 2018: Tom Poole “Why and How to Roll Your Own std::function Implementation”](https://www.youtube.com/watch?v=VY83afAJUIg)
0. [Writing custom C++20 coroutine systems](https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/coroutines-c++20/)
0. [STX](https://lamarrr.github.io/STX/)
Expand Down
1 change: 1 addition & 0 deletions documentation/bookmark/free.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [Public APIs](https://publicapis.io/)
0. [Free For Life](https://free.wdh.gg/#/)
0. [Open Domains: Free subdomains for personal sites, open-source projects, and more.](https://open-domains.net/)
0. https://free-for.dev/#/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reference

0. []()
0. [Implementing Your Own Garbage Collector in Java](https://coderoasis.com/custom-java-garbage-collector/)
0. [A Guide to the Go Garbage Collector](https://tip.golang.org/doc/gc-guide)
0. [Distilling the Real Cost of Production Garbage Collectors](https://users.cecs.anu.edu.au/~steveb/pubs/papers/lbo-ispass-2022.pdf)
0. [Summarizing Garbage Collection](https://eschew.wordpress.com/2016/09/02/summarizing-gc/)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/source/injection/lux/data/binary.lux
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@
caseT))])]

[0 .#Nominal (..and ..text (..list (..and ..bit again)))]
[1 .#Parameter indexed]
[1 .#Parameter (..and ..bit indexed)]
[2 .#Variable indexed]
[3 .#Opaque indexed]
[4 .#Quantification (all ..and ..bit (..stack again) again)]
[4 .#Quantification (all ..and ..bit (..stack (..and again again)) again)]
[5 .#Reification (..and again again)]
[6 .#Named (..and ..name again)]))
)))))))
Expand Down
258 changes: 139 additions & 119 deletions stdlib/source/library/lux.lux

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions stdlib/source/library/lux/compiler/language/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
(function (_ type))
(all _.or
(_.and _.text (_.list (_.and _.bit type)))
(_.and _.bit _.natural)
_.natural
_.natural
_.natural
(all _.and _.bit (_.stack type) type)
(all _.and _.bit (_.stack (_.and type type)) type)
(_.and type type)
(_.and (_.and _.text _.text) type))))

Expand Down Expand Up @@ -69,10 +69,10 @@
(function (_ type))
(all <>.or
(<>.and <binary>.text (<binary>.list (<>.and <binary>.bit type)))
(<>.and <binary>.bit <binary>.natural)
<binary>.natural
<binary>.natural
<binary>.natural
(all <>.and <binary>.bit (<binary>.stack type) type)
(all <>.and <binary>.bit (<binary>.stack (<>.and type type)) type)
(<>.and type type)
(<>.and (<>.and <binary>.text <binary>.text) type))))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@

{.#Variable @}
(if (n.= @variable @)
{.#Parameter @parameter}
{.#Parameter .argument @parameter}
:it:)

{.#Quantification quantification env body}
{.#Quantification quantification
(stack#each (quantified @variable @parameter) env)
(quantified @variable (n.+ 2 @parameter) body)}
(stack#each (function (_ [abstraction argument])
[(quantified @variable @parameter abstraction)
(quantified @variable @parameter argument)])
env)
(quantified @variable (++ @parameter) body)}

(^.or {.#Parameter _}
{.#Opaque _}
Expand Down Expand Up @@ -190,7 +193,7 @@

... {try.#Failure _}
... (do !
... [.let [:variable: (|> level (n.* 2) ++ {.#Parameter})]
... [.let [:variable: {.#Parameter .argument level}]
... _ (check.bind :variable: @variable)]
... (in (++ level))))))
... 0
Expand All @@ -203,13 +206,13 @@
))

(the (with_recursion @self recursion)
(-> Natural Type Type
Type)
(-> Natural Type
(Change Type))
(function (again it)
(`` (when it
(^.or {.#Parameter index}
(^.or {.#Parameter .abstraction index}
{.#Reification {.#Nominal "" (list)}
{.#Parameter index}})
{.#Parameter .abstraction index}})
(if (n.= @self index)
recursion
it)
Expand All @@ -219,8 +222,11 @@

{.#Quantification quantification environment quantified}
{.#Quantification quantification
(stack#each again environment)
(with_recursion (n.+ 2 @self) recursion quantified)}
(stack#each (function (_ [abstraction argument])
[(again abstraction)
(again argument)])
environment)
(with_recursion (++ @self) recursion quantified)}

{.#Nominal name parameters}
{.#Nominal name (list#each (function (_ [polarity it])
Expand All @@ -234,7 +240,7 @@
(-> Natural
(List Type))
(|>> list.indices
(list#each (|>> (n.* 2) ++ {.#Parameter}))
(list#each (|>> {.#Parameter .argument}))
list.reversed))

(template.with [<name> <types> <inputs> <exception> <when> <then>]
Expand Down Expand Up @@ -271,7 +277,7 @@
type.flat_tuple
(list.split_at (-- arity)))]
(phase#in (type.function
(list#each (..with_recursion (|> depth -- (n.* 2)) complex)
(list#each (..with_recursion (-- depth) complex)
(list#composite lefts (list (type.tuple right))))
(type.reification (parameters depth) complex))))]
[variant [Natural Bit] [lefts right?] ..not_a_variant
Expand All @@ -287,7 +293,7 @@
head)]
(-> (if (n.= 0 depth)
case
(..with_recursion (|> depth -- (n.* 2)) complex case))
(..with_recursion (-- depth) complex case))
(type.reification (parameters depth) complex)))

{.#Empty}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

{try.#Failure _}
(|> not_quantified
(/inference.quantified @input 1)
(/inference.quantified @input 0)
{.#Quantification .universal (stack)})))]
(in functionA)))))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
(exception.the .public empty_branches)

(the (quantified envs baseT)
(-> (Stack (Stack Type)) Type Type)
(-> (Stack (Stack [Type Type])) Type Type)
(.when envs
{.#Empty}
baseT
Expand All @@ -107,7 +107,7 @@
... type-check the input with respect to the patterns.
(the .public (tuple :it:)
(-> Type (Check [(Stack type.Variable) Type]))
(loop (again [envs (is (Stack (Stack Type))
(loop (again [envs (is (Stack (Stack [Type Type]))
(stack))
:it: :it:])
(.when :it:
Expand Down Expand Up @@ -170,7 +170,7 @@
(the .public (list type)
(-> Type
(Check [(Stack type.Variable) Type]))
(loop (list [envs (is (Stack (Stack Type))
(loop (list [envs (is (Stack (Stack [Type Type]))
(stack))
type type])
(.when type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@
un_bound!
(in (jvm.class (list) ..object_class))))

(^.or {.#Opaque id}
{.#Parameter id})
(^.or {.#Opaque _}
{.#Parameter _})
(phase#in (jvm.class (list) ..object_class))

{.#Quantification quantification env unquantified}
Expand Down Expand Up @@ -1274,9 +1274,7 @@
(the index_parameter
(-> Natural
.Type)
(|>> (n.* 2)
++
{.#Parameter}))
(|>> {.#Parameter .argument}))

(the (jvm_type_var_mapping owner_tvars method_tvars)
(-> (List Text) (List Text)
Expand Down
66 changes: 45 additions & 21 deletions stdlib/source/library/lux/compiler/type.lux
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@
[collection
["[0]" list (.use "[1]#[0]" functor)
["[0]" property (.use "[1]#[0]" functor)]]
["[0]" stack (.use "[1]#[0]" functor)]]]
["[0]" stack (.use "[1]#[0]" monad)]]]
[meta
["[0]" name]]
["[0]" function]]])
["[0]" function]
[math
[number
["n" natural]]]]])

(the prefix
name.delimiter)
Expand Down Expand Up @@ -152,10 +155,10 @@
(every .public (Type _)
(Variant
{#Nominal ..Text (..List' [.Polarity (Type _)])}
{#Parameter ..Natural}
{#Parameter .Parameter ..Natural}
{#Variable ..Natural}
{#Opaque ..Natural}
{#Quantification .Quantification (.Stack (Type _)) (Type _)}
{#Quantification .Quantification (.Stack [(Type _) (Type _)]) (Type _)}
{#Reification (Type _) (Type _)}
{#Named ..Name (Type _)}))

Expand All @@ -172,22 +175,28 @@
... {#Reification left right}
... {.#Reification (old left) (old right)}

... {#Parameter parameter it}
... {.#Parameter (|> it
... (n.* 2)
... (n.+ (when parameter
... .abstraction 0
... .argument 1)))}

... (,, (with_template [,new ,old]
... [{,new it}
... {,old it}]

... [#Parameter .#Parameter]
... [#Variable .#Variable]
... [#Opaque .#Opaque]
... ))

... (,, (with_template [,new ,old]
... [{#Quantification ,new environment body}
... {,old (stack#each old environment) (old body)}]

... [.universal .#Universal]
... [.existential .#Existential]
... ))
... {#Quantification quantification closure body}
... {.#Quantification quantification
... (|> closure
... (stack#each (.function (_ [abstraction argument])
... (stack (old abstraction) (old argument))))
... stack#conjoint)
... (old body)}

... (,, (with_template [,new ,old]
... [{,new name body}
Expand All @@ -211,22 +220,29 @@
... {.#Reification left right}
... {#Reification (new left) (new right)}

... {.#Parameter it}
... (let [[it parameter] (n./% 2 it)]
... {#Parameter (n.= 1 parameter) it})

... (,, (with_template [,new ,old]
... [{,old it}
... {,new it}]

... [#Parameter .#Parameter]
... [#Variable .#Variable]
... [#Opaque .#Opaque]
... ))

... (,, (with_template [,new ,old]
... [{,old environment body}
... {#Quantification ,new (stack#each new environment) (new body)}]
... {.#Quantification quantification closure body}
... {#Quantification quantification
... (loop (new_closure [closure closure])
... (when closure
... (stack.partial abstraction argument closure)
... (stack.partial [(new abstraction) (new argument)]
... (new_closure closure))

... [.universal .#Universal]
... [.existential .#Existential]
... ))
... else
... (stack)))
... (new body)}

... (,, (with_template [,new ,old]
... [{,old name body}
Expand Down Expand Up @@ -442,13 +458,18 @@
{.#Nominal it}
(nominal code it)

{.#Parameter parameter it}
(code#variant (.list (code#natural 1)
(code#bit #0)
(code#bit parameter)
(code#natural it)))

(,, (with_template [,lefts ,tag]
[{,tag it}
(code#variant (.list (code#natural ,lefts)
(code#bit #0)
(code#natural it)))]

[1 .#Parameter]
[2 .#Variable]
[3 .#Opaque]
))
Expand All @@ -457,7 +478,10 @@
(code#variant (.list (code#natural 4)
(code#bit #0)
(code#tuple (.list (code#bit quantification)
(code#stack code closure)
(code#stack (.function (_ [abstraction argument])
(` [(, (code abstraction))
(, (code argument))]))
closure)
(code body)))))

{.#Reification left right}
Expand Down
Loading

0 comments on commit 8235d8f

Please sign in to comment.