aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler
diff options
context:
space:
mode:
authorEduardo Julian2022-03-11 05:52:21 -0400
committerEduardo Julian2022-03-11 05:52:21 -0400
commit6766be5427b1788a44e07151e3fabe33ec4f8b37 (patch)
tree8d8aa5c1d8fd4a9f733f82c48080284ecd4ec31a /stdlib/source/library/lux/tool/compiler
parentac2c19d93407b00c89513f0f81e9cbbd1425bd9a (diff)
Added an easy way to export Lux functionality to host programs (everywhere else).
Diffstat (limited to 'stdlib/source/library/lux/tool/compiler')
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux24
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux60
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux69
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/function.lux3
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux7
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux13
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux3
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/synthesis/simple.lux6
-rw-r--r--stdlib/source/library/lux/tool/compiler/phase.lux1
9 files changed, 91 insertions, 95 deletions
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
index 241b28a2b..889d400b0 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
@@ -72,10 +72,10 @@
{try.#Failure error}
(phase.except ///.invalid_syntax [extension_name %.code inputs]))))
-(def: (context [module_id artifact_id])
+(def: (context [@module @artifact])
(-> unit.ID unit.ID)
... TODO: Find a better way that doesn't rely on clever tricks.
- [module_id (n.- (++ artifact_id) 0)])
+ [@module (n.- (++ @artifact) 0)])
... TODO: Inline "evaluate!'" into "evaluate!" ASAP
(def: (evaluate!' archive generate code//type codeS)
@@ -90,8 +90,8 @@
[module /////generation.module
id /////generation.next
codeG (generate archive codeS)
- module_id (/////generation.module_id module archive)
- codeV (/////generation.evaluate! (..context [module_id id]) [{.#None} codeG])]
+ @module (/////generation.module_id module archive)
+ codeV (/////generation.evaluate! (..context [@module id]) [{.#None} codeG])]
(in [code//type codeG codeV]))))
(def: .public (evaluate! archive type codeC)
@@ -133,9 +133,9 @@
_
{.#None})]
- module_id (phase.lifted (archive.id module archive))
+ @module (phase.lifted (archive.id module archive))
@self (/////generation.learn [name @abstraction] false (list#mix set.has dependencies interim_artifacts))
- [target_name value directive] (/////generation.define! [module_id @self] {.#None} [(maybe#each product.right @abstraction) codeG])
+ [target_name value directive] (/////generation.define! [@module @self] {.#None} [(maybe#each product.right @abstraction) codeG])
_ (/////generation.save! @self {.#None} directive)]
(in [code//type codeG value]))))
@@ -186,9 +186,9 @@
[dependencies (cache/artifact.dependencies archive codeS)
[interim_artifacts codeG] (/////generation.with_interim_artifacts archive
(generate archive codeS))
- module_id (phase.lifted (archive.id current_module archive))
+ @module (phase.lifted (archive.id current_module archive))
@self (<learn> extension (list#mix set.has dependencies interim_artifacts))
- [target_name value directive] (/////generation.define! [module_id @self] {.#None} [{.#None} codeG])
+ [target_name value directive] (/////generation.define! [@module @self] {.#None} [{.#None} codeG])
_ (/////generation.save! @self {.#None} directive)]
(in [codeG value])))))
@@ -499,7 +499,7 @@
(/////directive.lifted_synthesis
(synthesize archive programA))))
-(def: (define_program archive module_id generate program programS)
+(def: (define_program archive @module generate program programS)
(All (_ anchor expression directive output)
(-> Archive
module.ID
@@ -512,7 +512,7 @@
[interim_artifacts programG] (/////generation.with_interim_artifacts archive
(generate archive programS))
@self (/////generation.learn [/////program.name {.#None}] true (list#mix set.has dependencies interim_artifacts))]
- (/////generation.save! @self {.#None} (program [module_id @self] programG))))
+ (/////generation.save! @self {.#None} (program [@module @self] programG))))
(def: (def::program program)
(All (_ anchor expression directive)
@@ -528,9 +528,9 @@
programS (prepare_program archive analyse synthesize programC)
current_module (/////directive.lifted_analysis
(///.lifted meta.current_module_name))
- module_id (phase.lifted (archive.id current_module archive))
+ @module (phase.lifted (archive.id current_module archive))
_ (/////directive.lifted_generation
- (define_program archive module_id generate program programS))]
+ (define_program archive @module generate program programS))]
(in /////directive.no_requirements))
_
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux
index dff13d37f..fa18710f9 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux
@@ -1,34 +1,36 @@
(.using
- [library
- [lux "*"
- [abstract
- ["[0]" monad {"+" do}]]
- [control
- ["[0]" function]
- ["<>" parser
- ["<s>" synthesis {"+" Parser}]]]
- [data
- [collection
- ["[0]" dictionary]
- ["[0]" list]]]
- [target
- ["_" python {"+" Expression SVar}]]]]
- ["[0]" // "_"
- ["[1][0]" common {"+" custom}]
- ["//[1]" /// "_"
- ["/" bundle]
+ [library
+ [lux "*"
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ ["[0]" function]
+ ["<>" parser
+ ["<s>" synthesis {"+" Parser}]]]
+ [data
+ ["[0]" text
+ ["%" format]]
+ [collection
+ ["[0]" dictionary]
+ ["[0]" list]]]
+ [target
+ ["_" python {"+" Expression SVar}]]]]
+ ["[0]" // "_"
+ ["[1][0]" common {"+" custom}]
+ ["//[1]" /// "_"
+ ["/" bundle]
+ ["/[1]" // "_"
+ ["[0]" extension]
+ [generation
+ [extension {"+" Nullary Unary Binary Trinary
+ nullary unary binary trinary}]
+ ["//" python "_"
+ ["[1][0]" runtime {"+" Operation Phase Handler Bundle
+ with_vars}]]]
["/[1]" // "_"
- ["[0]" extension]
- [generation
- [extension {"+" Nullary Unary Binary Trinary
- nullary unary binary trinary}]
- ["//" python "_"
- ["[1][0]" runtime {"+" Operation Phase Handler Bundle
- with_vars}]]]
- ["/[1]" // "_"
- ["[0]" generation]
- ["//[1]" /// "_"
- ["[1][0]" phase]]]]]])
+ ["[0]" generation]
+ ["//[1]" /// "_"
+ ["[1][0]" phase]]]]]])
(def: (array::new size)
(Unary (Expression Any))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux
index b2d828de3..4a5ee59f0 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux
@@ -1,36 +1,38 @@
(.using
- [library
- [lux {"-" case exec let if}
- [abstract
- ["[0]" monad {"+" do}]]
- [control
- ["[0]" maybe]]
- [data
- ["[0]" text]
- [collection
- ["[0]" list ("[1]#[0]" functor mix)]]]
- [math
- [number
- ["n" nat]]]
- [target
- ["_" js {"+" Expression Computation Var Statement}]]]]
- ["[0]" // "_"
- ["[1][0]" runtime {"+" Operation Phase Phase! Generator Generator!}]
+ [library
+ [lux {"-" case exec let if}
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ ["[0]" maybe]]
+ [data
+ ["[0]" text]
+ [collection
+ ["[0]" list ("[1]#[0]" functor mix)]]]
+ [math
+ [number
+ ["n" nat]]]
+ [target
+ ["_" js {"+" Expression Computation Var Statement}]]]]
+ ["[0]" // "_"
+ ["[1][0]" runtime {"+" Operation Phase Phase! Generator Generator!}]
+ ["[1][0]" reference]
+ ["[1][0]" primitive]
+ ["/[1]" // "_"
["[1][0]" reference]
- ["[1][0]" primitive]
["/[1]" // "_"
- ["[1][0]" reference]
+ ["[1][0]" synthesis "_"
+ ["[1]/[0]" case]]
["/[1]" // "_"
- ["[1][0]" synthesis "_"
- ["[1]/[0]" case]]
- ["/[1]" // "_"
- ["[1][0]" synthesis {"+" Member Synthesis Path}]
- ["//[1]" /// "_"
- [reference
- [variable {"+" Register}]]
- ["[1][0]" phase ("[1]#[0]" monad)]
- [meta
- [archive {"+" Archive}]]]]]]])
+ ["[1][0]" synthesis {"+" Synthesis Path}
+ [access
+ ["[0]" member {"+" Member}]]]
+ ["//[1]" /// "_"
+ [reference
+ [variable {"+" Register}]]
+ ["[1][0]" phase ("[1]#[0]" monad)]
+ [meta
+ [archive {"+" Archive}]]]]]]])
(def: .public register
(-> Register Var)
@@ -95,12 +97,9 @@
(do ///////phase.monad
[valueO (expression archive valueS)]
(in (list#mix (function (_ side source)
- (.let [method (.case side
- (^template [<side> <accessor>]
- [{<side> lefts}
- (<accessor> (_.i32 (.int lefts)))])
- ([.#Left //runtime.tuple//left]
- [.#Right //runtime.tuple//right]))]
+ (.let [method (.if (value@ member.#right? side)
+ (//runtime.tuple//right (_.i32 (.int (value@ member.#lefts side))))
+ (//runtime.tuple//left (_.i32 (.int (value@ member.#lefts side)))))]
(method source)))
valueO
(list.reversed pathP)))))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/function.lux
index 5461530f7..a3fa9317d 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/function.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/function.lux
@@ -30,7 +30,8 @@
[archive
["[0]" unit]]
["[0]" cache "_"
- ["[1]" artifact]]]]]]])
+ [dependency
+ ["[1]" artifact]]]]]]]])
(def: .public (apply expression archive [functionS argsS+])
(Generator (Reification Synthesis))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux
index 26f54c884..0f8cbef41 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux
@@ -24,12 +24,7 @@
[number {"+" hex}
["[0]" i64]]]
[target
- ["_" js {"+" Expression Var Computation Statement}]]
- [tool
- [compiler
- [language
- [lux
- ["$" version]]]]]]]
+ ["_" js {"+" Expression Var Computation Statement}]]]]
["[0]" /// "_"
["[1][0]" reference]
["//[1]" /// "_"
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux
index dfb7908e7..1ad5f6df6 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux
@@ -21,7 +21,9 @@
["[1][0]" synthesis "_"
["[1]/[0]" case]]
["/[1]" // "_"
- ["[1][0]" synthesis {"+" Member Synthesis Path}]
+ ["[1][0]" synthesis {"+" Synthesis Path}
+ [access
+ ["[0]" member {"+" Member}]]]
["[1][0]" generation]
["//[1]" /// "_"
[reference
@@ -81,12 +83,9 @@
(do ///////phase.monad
[valueO (expression archive valueS)]
(in (list#mix (function (_ side source)
- (.let [method (.case side
- (^template [<side> <accessor>]
- [{<side> lefts}
- (<accessor> (_.int (.int lefts)))])
- ([.#Left //runtime.tuple//left]
- [.#Right //runtime.tuple//right]))]
+ (.let [method (.if (value@ member.#right? side)
+ (//runtime.tuple//right (_.int (.int (value@ member.#lefts side))))
+ (//runtime.tuple//left (_.int (.int (value@ member.#lefts side)))))]
(method source)))
valueO
(list.reversed pathP)))))
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 f78fb404b..ec725005a 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
@@ -29,7 +29,8 @@
["/[1]" // "_"
["[1][0]" generation]
["[1][0]" synthesis {"+" Synthesis Path}
- ["[0]" member {"+" Member}]]
+ [access
+ ["[0]" member {"+" Member}]]]
["//[1]" /// "_"
[reference
["[1][0]" variable {"+" Register}]]
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis/simple.lux b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis/simple.lux
index dbf435a6d..bd9463555 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis/simple.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis/simple.lux
@@ -12,7 +12,7 @@
["%" format]]]
[math
[number
- ["[0]" i64]
+ ["[0]" i64 ("[1]#[0]" equivalence)]
["n" nat]
["i" int]
["f" frac]]]]])
@@ -20,7 +20,7 @@
(type: .public Simple
(Variant
{#Bit Bit}
- {#I64 (I64 Any)}
+ {#I64 I64}
{#F64 Frac}
{#Text Text}))
@@ -50,7 +50,7 @@
[#Text text#= %.text])
[{#I64 reference'} {#I64 sample'}]
- (i.= (.int reference') (.int sample'))
+ (i64#= reference' sample')
_
false)))
diff --git a/stdlib/source/library/lux/tool/compiler/phase.lux b/stdlib/source/library/lux/tool/compiler/phase.lux
index a52f8b796..e09552d2c 100644
--- a/stdlib/source/library/lux/tool/compiler/phase.lux
+++ b/stdlib/source/library/lux/tool/compiler/phase.lux
@@ -1,7 +1,6 @@
(.using
[library
[lux "*"
- ["[0]" debug]
[abstract
[functor {"+" Functor}]
[monad {"+" Monad do}]]