aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/meta/compiler/language/lux/synthesis.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/meta/compiler/language/lux/synthesis.lux')
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/synthesis.lux76
1 files changed, 57 insertions, 19 deletions
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/synthesis.lux b/stdlib/source/library/lux/meta/compiler/language/lux/synthesis.lux
index 2006f836f..d10fdd654 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/synthesis.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/synthesis.lux
@@ -94,13 +94,29 @@
[#function s
#arguments (List s)]))
-(type .public (Branch s)
+(type .public (Exec of)
+ (Record
+ [#before of
+ #after of]))
+
+(type .public (Let of)
+ (Record
+ [#context [Register of]
+ #expression of]))
+
+(type .public (If of)
+ (Record
+ [##if_when of
+ #if_then of
+ ##if_else of]))
+
+(type .public (Branch of)
(Variant
- {#Exec s s}
- {#Let s Register s}
- {#If s s s}
- {#Get (List Member) s}
- {#When s (Path' s)}))
+ {#Exec (Exec of)}
+ {#Let (Let of)}
+ {#If (If of)}
+ {#Get (List Member) of}
+ {#When of (Path' of)}))
(type .public (Scope s)
(Record
@@ -398,7 +414,7 @@
(|> (format (%synthesis this) " " (%synthesis that))
(text.enclosed ["{#exec " "}"]))
- {#Let input register body}
+ {#Let [register input] body}
(|> (format (%.nat register) " " (%synthesis input) " " (%synthesis body))
(text.enclosed ["{#let " "}"]))
@@ -535,34 +551,34 @@
(n.* 29 (of super hash body))
))))
-(def (branch_equivalence (open "#[0]"))
+(def (branch_equivalence (open "/#[0]"))
(All (_ of)
(-> (Equivalence of)
(Equivalence (Branch of))))
(implementation
(def (= reference sample)
(when [reference sample]
- [{#Let [reference_input reference_register reference_body]}
- {#Let [sample_input sample_register sample_body]}]
- (and (#= reference_input sample_input)
+ [{#Let [[reference_register reference_input] reference_body]}
+ {#Let [[sample_register sample_input] sample_body]}]
+ (and (/#= reference_input sample_input)
(n.= reference_register sample_register)
- (#= reference_body sample_body))
+ (/#= reference_body sample_body))
[{#If [reference_test reference_then reference_else]}
{#If [sample_test sample_then sample_else]}]
- (and (#= reference_test sample_test)
- (#= reference_then sample_then)
- (#= reference_else sample_else))
+ (and (/#= reference_test sample_test)
+ (/#= reference_then sample_then)
+ (/#= reference_else sample_else))
[{#Get [reference_path reference_record]}
{#Get [sample_path sample_record]}]
(and (of (list.equivalence /member.equivalence) = reference_path sample_path)
- (#= reference_record sample_record))
+ (/#= reference_record sample_record))
[{#When [reference_input reference_path]}
{#When [sample_input sample_path]}]
- (and (#= reference_input sample_input)
- (of (path'_equivalence #=) = reference_path sample_path))
+ (and (/#= reference_input sample_input)
+ (of (path'_equivalence /#=) = reference_path sample_path))
_
false))))
@@ -582,7 +598,7 @@
(of super hash this)
(of super hash that))
- {#Let [input register body]}
+ {#Let [[register input] body]}
(all n.* 3
(of super hash input)
(of n.hash hash register)
@@ -793,3 +809,25 @@
[simple_left_side ..side/left]
[simple_right_side ..side/right]
)
+
+(def .public (flat_exec after)
+ (-> Term
+ [(List Term) Term])
+ (.when after
+ (branch/exec @ [before after])
+ (let [[tail after] (flat_exec after)]
+ [(list.partial before tail) after])
+
+ _
+ [(list) after]))
+
+(def .public (flat_let body)
+ (-> Term
+ [(List [Register Term]) Term])
+ (.when body
+ (branch/let @ [context body])
+ (let [[tail body] (flat_let body)]
+ [(list.partial context tail) body])
+
+ _
+ [(list) body]))