Skip to content

Commit

Permalink
New type for Lux (part 8).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Apr 30, 2024
1 parent e0b5643 commit e8b7977
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 177 deletions.
132 changes: 68 additions & 64 deletions stdlib/source/library/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -438,22 +438,10 @@
(.def# #Alias (tag [{#Some [1 #0 ..global_tags]} Global]) .public)
(.def# #Default (tag [{#Some [1 #1 ..global_tags]} Global]) .public)

... (every .public (Bindings k v)
... (Record
... [#counter Natural
... #mappings (Stack [k v])]))
(.def# Bindings
(.is# Type
{#Named [..prelude "Bindings"]
{#Universal {#Empty}
{#Universal {#Empty}
{#Product
... counter
Natural
... mappings
{#Reification {#Product {#Parameter 3}
{#Parameter 1}}
Stack}}}}})
(.type# "bindings")})
.public)

(.def# bindings_slots
Expand Down Expand Up @@ -487,41 +475,20 @@
(.def# #Local (tag [{#Some [0 #0 ..ref_tags]} Ref]) .public)
(.def# #Captured (tag [{#Some [0 #1 ..ref_tags]} Ref]) .public)

... TODO: Get rid of both #scope_name & #inner_scopes
... (every .public Scope
... (Record
... [#scope_name (Stack Text)
... #inner_scopes Natural
... #locals (Bindings Text [Type Natural])
... #captured (Bindings Text [Type Ref])]))
(.def# Scope
(.is# Type
{#Named [..prelude "Scope"]
{#Product
... name
{#Reification Text Stack}
{#Product
... inner
Natural
{#Product
... locals
{#Reification {#Product Type Natural} {#Reification Text Bindings}}
... captured
{#Reification {#Product Type Ref} {#Reification Text Bindings}}}}}})
(.type# "scope")})
.public)

(.def# scope_slots
(.is# {#Reification Name Stack}
{#Top [..prelude "#scope_name"]
{#Top [..prelude "#inner_scopes"]
{#Top [..prelude "#locals"]
{#Top [..prelude "#captured"]
{#Empty}}}}})
{#Top [..prelude "#locals"]
{#Top [..prelude "#captured"]
{#Empty}}})
#0)
(.def# #scope_name (slot [{#Some [0 #0 ..scope_slots]} Scope]) .public)
(.def# #inner_scopes (slot [{#Some [1 #0 ..scope_slots]} Scope]) .public)
(.def# #locals (slot [{#Some [2 #0 ..scope_slots]} Scope]) .public)
(.def# #captured (slot [{#Some [2 #1 ..scope_slots]} Scope]) .public)
(.def# #locals (slot [{#Some [0 #0 ..scope_slots]} Scope]) .public)
(.def# #captured (slot [{#Some [0 #1 ..scope_slots]} Scope]) .public)

... (every .public (Either l r)
... (Variant
Expand Down Expand Up @@ -1187,6 +1154,41 @@
depth))))))
body)))

(the' .private (list#mix mix complete partial)
... (for_any (_ a b) (-> (-> b a a) a (List b) a))
{#Universal {#Empty}
{#Universal {#Empty}
{#Function {#Function {#Parameter 1}
{#Function {#Parameter 3}
{#Parameter 3}}}
{#Function {#Parameter 3}
{#Function {#Reification {#Parameter 1} List}
{#Parameter 3}}}}}}
(.when# (.list_size# partial)
limit
((.is# {#Universal {#Empty}
{#Universal {#Empty}
{#Function Natural
{#Function {#Function {#Parameter 1}
{#Function {#Parameter 3}
{#Parameter 3}}}
{#Function {#Parameter 3}
{#Function {#Reification {#Parameter 1} List}
{#Parameter 3}}}}}}}
(function' (list#mix item mix complete partial)
(.when# (.int_<# (.as# Integer limit)
(.as# Integer item))
#1
(list#mix (.i64_+# 1 item)
mix
(mix (.list_item# item partial)
complete)
partial)

#0
complete)))
0 mix complete partial)))

(the' .private (initialized_quantification? lux)
{#Function Lux
Bit}
Expand All @@ -1198,17 +1200,17 @@
(.when# verdict
[#1] #1
_ (.when# scope
[..#scope_name _ ..#inner_scopes _ ..#captured _
[..#captured _
..#locals [..#counter _
..#mappings locals]]
(stack#mix (function' (_ local verdict)
(.when# local
[local _]
(.when# verdict
[#1] #1
_ (.text_=# ..quantification_level local))))
#0
locals))))
(list#mix (function' (_ local verdict)
(.when# local
[local _]
(.when# verdict
[#1] #1
_ (.text_=# ..quantification_level local))))
#0
locals))))
#0
scopes)))

Expand Down Expand Up @@ -1799,6 +1801,12 @@
{#Some y}
{#Some y})))

(the' .private (list#one f xs)
(for_any (_ input output)
(-> (-> input ($ Maybe output)) ($ List input)
($ Maybe output)))
(stack#one f (list#as_stack xs)))

(the' .private (in_env name state)
(-> Text Lux
($ Maybe Type))
Expand All @@ -1807,17 +1815,15 @@
..#expected expected ..#provenance provenance ..#eval _eval] state]
(stack#one (.is# (-> Scope ($ Maybe Type))
(function' (_ env)
(let' [[..#scope_name _
..#inner_scopes _
..#locals [..#counter _ ..#mappings locals]
(let' [[..#locals [..#counter _ ..#mappings locals]
..#captured _] env]
(stack#one (.is# (-> (Tuple Text (Tuple Type Any)) ($ Maybe Type))
(function' (_ it)
(let' [[bname [type _]] it]
(if (text#= name bname)
{#Some type}
{#None}))))
locals))))
(list#one (.is# (-> (Tuple Text (Tuple Type Any)) ($ Maybe Type))
(function' (_ it)
(let' [[bname [type _]] it]
(if (text#= name bname)
{#Some type}
{#None}))))
locals))))
scopes)))

(the' .private (available? expected_module current_module exported?)
Expand Down Expand Up @@ -3010,12 +3016,10 @@
..#source source/pre
..#current_module current_module/pre
..#modules modules/pre
..#scopes (stack#partial [#scope_name (stack)
#inner_scopes 0
#locals [#counter 0
#mappings (stack [..quantification_level [.Natural (.as# Natural -1)]])]
..#scopes (stack#partial [#locals [#counter 0
#mappings (list [..quantification_level [.Natural (.as# Natural -1)]])]
#captured [#counter 0
#mappings (stack)]]
#mappings (list)]]
scopes/pre)
..#type_context type_context/pre
..#seed seed/pre
Expand Down
28 changes: 12 additions & 16 deletions stdlib/source/library/lux/compiler/language/lux/analysis.lux
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,13 @@
.#source (its @type.#source it)
.#provenance (its @type.#provenance it)
.#current_module (its @type.#current_module it)
.#modules (list#each (function (_ [name it])
[name [.#module_hash (its @type.#module_hash it)
.#module_aliases (list.as_stack (its @type.#module_aliases it))
.#definitions (list.as_stack (its @type.#definitions it))
.#imports (its @type.#imports it)
.#module_state (its @type.#module_state it)]])
(its @type.#modules it))
.#scopes (its @type.#scopes it)
.#modules (its @type.#modules it)
.#scopes (stack#each (function (_ it)
[.#scope_name (stack)
.#inner_scopes 0
.#locals (revised .#mappings list.as_stack (its @type.#locals it))
.#captured (revised .#mappings list.as_stack (its @type.#captured it))])
(its @type.#scopes it))
.#type_context (its @type.#type_context it)
.#expected (its @type.#expected it)
.#seed (its @type.#seed it)
Expand All @@ -485,14 +484,11 @@
@type.#source (its .#source it)
@type.#provenance (its .#provenance it)
@type.#current_module (its .#current_module it)
@type.#modules (list#each (function (_ [name it])
[name [@type.#module_hash (its .#module_hash it)
@type.#module_aliases (list.of_stack (its .#module_aliases it))
@type.#definitions (list.of_stack (its .#definitions it))
@type.#imports (its .#imports it)
@type.#module_state (its .#module_state it)]])
(its .#modules it))
@type.#scopes (its .#scopes it)
@type.#modules (its .#modules it)
@type.#scopes (stack#each (function (_ it)
[@type.#locals (revised .#mappings list.of_stack (its .#locals it))
@type.#captured (revised .#mappings list.of_stack (its .#captured it))])
(its .#scopes it))
@type.#type_context (its .#type_context it)
@type.#expected (its .#expected it)
@type.#seed (its .#seed it)
Expand Down
Loading

0 comments on commit e8b7977

Please sign in to comment.