aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/compiler/default/phase/analysis.lux
diff options
context:
space:
mode:
authorEduardo Julian2018-08-08 22:29:33 -0400
committerEduardo Julian2018-08-08 22:29:33 -0400
commit2ab2c4dc219e5d3667f4f2626166dfc782052fe3 (patch)
tree14735c2348d631aea472c155e0ec9f00f0b7db43 /stdlib/source/lux/compiler/default/phase/analysis.lux
parent32db706bd8df4901321fce9f87ce06847d2ce4de (diff)
- Re-defined the relationship between analysis and evaluation.
- Fixed some bugs.
Diffstat (limited to 'stdlib/source/lux/compiler/default/phase/analysis.lux')
-rw-r--r--stdlib/source/lux/compiler/default/phase/analysis.lux74
1 files changed, 71 insertions, 3 deletions
diff --git a/stdlib/source/lux/compiler/default/phase/analysis.lux b/stdlib/source/lux/compiler/default/phase/analysis.lux
index 974fc2473..578560d11 100644
--- a/stdlib/source/lux/compiler/default/phase/analysis.lux
+++ b/stdlib/source/lux/compiler/default/phase/analysis.lux
@@ -3,9 +3,11 @@
[data
["." product]
["." error]
- [text ("text/." Equivalence<Text>)]
+ ["." maybe]
+ ["." text ("text/." Equivalence<Text>)
+ format]
[collection
- ["." list ("list/." Fold<List>)]]]
+ ["." list ("list/." Functor<List> Fold<List>)]]]
["." function]]
[//
["." extension (#+ Extension)]
@@ -128,7 +130,7 @@
value)
(list.indices (inc tag))))))]
- [sum-analysis Analysis #Structure no-op]
+ [sum-analysis Analysis #Structure ..no-op]
[sum-pattern Pattern #Complex id]
)
@@ -290,3 +292,69 @@
[set-current-module Text #.current-module (#.Some value)]
[set-cursor Cursor #.cursor value]
)
+
+(def: #export (%analysis analysis)
+ (Format Analysis)
+ (case analysis
+ (#Primitive primitive)
+ (case primitive
+ #Unit
+ "[]"
+
+ (^template [<tag> <format>]
+ (<tag> value)
+ (<format> value))
+ ([#Bit %b]
+ [#Nat %n]
+ [#Int %i]
+ [#Rev %r]
+ [#Frac %f]
+ [#Text %t]))
+
+ (#Structure structure)
+ (case structure
+ (#Sum _)
+ (let [[lefts right? value] (maybe.assume (..variant analysis))]
+ (format "(" (%n lefts) " " (%b right?) " " (%analysis value) ")"))
+
+ (#Product _)
+ (|> analysis
+ ..tuple
+ (list/map %analysis)
+ (text.join-with " ")
+ (text.enclose ["[" "]"])))
+
+ (#Reference reference)
+ (case reference
+ (#reference.Variable variable)
+ (reference.%variable variable)
+
+ (#reference.Constant constant)
+ (%name constant))
+
+ (#Case analysis match)
+ "{?}"
+
+ (#Function environment body)
+ (|> (%analysis body)
+ (format " ")
+ (format (|> environment
+ (list/map reference.%variable)
+ (text.join-with " ")
+ (text.enclose ["[" "]"])))
+ (text.enclose ["(" ")"]))
+
+ (#Apply _)
+ (|> analysis
+ ..application
+ #.Cons
+ (list/map %analysis)
+ (text.join-with " ")
+ (text.enclose ["(" ")"]))
+
+ (#Extension name parameters)
+ (|> parameters
+ (list/map %analysis)
+ (text.join-with " ")
+ (format (%t name) " ")
+ (text.enclose ["(" ")"]))))