From 7e18f589a05bde28b3f710d92f72b7bd6b6e144f Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 5 Dec 2017 02:41:59 -0400 Subject: - Added analysis, synthesis, translation and statement extensions. - No longer doing ad-hoc I/O in new-luxc. - Minor fixes and adjustments. --- new-luxc/source/luxc/lang/extension.lux | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 new-luxc/source/luxc/lang/extension.lux (limited to 'new-luxc/source/luxc/lang/extension.lux') diff --git a/new-luxc/source/luxc/lang/extension.lux b/new-luxc/source/luxc/lang/extension.lux new file mode 100644 index 000000000..d38d564fb --- /dev/null +++ b/new-luxc/source/luxc/lang/extension.lux @@ -0,0 +1,84 @@ +(.module: + lux + (lux (control [monad #+ do] + ["ex" exception #+ exception:]) + (data ["e" error] + [text] + (coll [dict #+ Dict])) + [macro]) + [//]) + +(exception: #export Unknown-Analysis) +(exception: #export Unknown-Synthesis) +(exception: #export Unknown-Translation) +(exception: #export Unknown-Statement) + +(exception: #export Cannot-Define-Analysis-More-Than-Once) +(exception: #export Cannot-Define-Synthesis-More-Than-Once) +(exception: #export Cannot-Define-Translation-More-Than-Once) +(exception: #export Cannot-Define-Statement-More-Than-Once) + +(type: #export Expression + (-> (List Code) (Meta Code))) + +(type: #export Statement + (-> (List Code) (Meta Unit))) + +(type: #export Extensions + {#analysis (Dict Text Expression) + #synthesis (Dict Text Expression) + #translation (Dict Text Expression) + #statement (Dict Text Statement)}) + +(def: #export fresh + Extensions + {#analysis (dict.new text.Hash) + #synthesis (dict.new text.Hash) + #translation (dict.new text.Hash) + #statement (dict.new text.Hash)}) + +(def: get + (Meta Extensions) + (function [compiler] + (#e.Success [compiler + (|> compiler (get@ #.extensions) (:! Extensions))]))) + +(def: (set extensions) + (-> Extensions (Meta Unit)) + (function [compiler] + (#e.Success [(set@ #.extensions (:! Void extensions) compiler) + []]))) + +(do-template [ ] + [(def: #export ( name) + (-> Text (Meta )) + (do macro.Monad + [extensions ..get] + (case (dict.get name (get@ extensions)) + (#.Some extension) + (wrap extension) + + #.None + (//.throw name))))] + + [find-analysis Expression #analysis Unknown-Analysis] + [find-synthesis Expression #synthesis Unknown-Synthesis] + [find-translation Expression #translation Unknown-Translation] + [find-statement Statement #statement Unknown-Statement] + ) + +(do-template [ ] + [(def: #export ( name extension) + (-> Text (Meta Unit)) + (do macro.Monad + [extensions ..get + _ (//.assert name + (not (dict.contains? name (get@ extensions)))) + _ (..set (update@ (dict.put name extension) extensions))] + (wrap [])))] + + [install-analysis Expression #analysis Cannot-Define-Analysis-More-Than-Once] + [install-synthesis Expression #synthesis Cannot-Define-Synthesis-More-Than-Once] + [install-translation Expression #translation Cannot-Define-Translation-More-Than-Once] + [install-statement Statement #statement Cannot-Define-Statement-More-Than-Once] + ) -- cgit v1.2.3