aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/analysis/common.lux
diff options
context:
space:
mode:
authorEduardo Julian2017-10-31 23:39:49 -0400
committerEduardo Julian2017-10-31 23:39:49 -0400
commit15121222d570f8fe3c5a326208e4f0bad737e63c (patch)
tree88c93ed1f4965fd0e80677df5553a0d47e521963 /new-luxc/source/luxc/lang/analysis/common.lux
parenta269ea72337852e8e57bd427773baed111ad6e92 (diff)
- Re-organized analysis.
Diffstat (limited to 'new-luxc/source/luxc/lang/analysis/common.lux')
-rw-r--r--new-luxc/source/luxc/lang/analysis/common.lux41
1 files changed, 41 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/analysis/common.lux b/new-luxc/source/luxc/lang/analysis/common.lux
new file mode 100644
index 000000000..4cbf5aedf
--- /dev/null
+++ b/new-luxc/source/luxc/lang/analysis/common.lux
@@ -0,0 +1,41 @@
+(;module:
+ lux
+ (lux (control monad
+ pipe)
+ (data text/format
+ [product])
+ [meta #+ Monad<Meta>]
+ (meta [type]
+ (type ["tc" check])))
+ (luxc ["&" base]
+ (lang analysis)))
+
+(def: #export (with-unknown-type action)
+ (All [a] (-> (Meta Analysis) (Meta [Type Analysis])))
+ (do Monad<Meta>
+ [[var-id var-type] (&;with-type-env
+ tc;create)
+ analysis (&;with-expected-type var-type
+ action)
+ analysis-type (&;with-type-env
+ (tc;clean var-id var-type))
+ _ (&;with-type-env
+ (tc;delete var-id))]
+ (wrap [analysis-type analysis])))
+
+(def: #export (with-var body)
+ (All [a] (-> (-> [Nat Type] (Meta a)) (Meta a)))
+ (do Monad<Meta>
+ [[id var] (&;with-type-env
+ tc;create)
+ output (body [id var])
+ _ (&;with-type-env
+ (tc;delete id))]
+ (wrap output)))
+
+(def: #export (variant-out-of-bounds-error type size tag)
+ (All [a] (-> Type Nat Nat (Meta a)))
+ (&;fail (format "Trying to create variant with tag beyond type's limitations." "\n"
+ " Tag: " (%i (nat-to-int tag)) "\n"
+ "Size: " (%i (nat-to-int size)) "\n"
+ "Type: " (%type type))))