From 0bd93d82eb7a50b9ce8be42800c388e87e6ca9bf Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 23 Feb 2018 23:10:28 -0400 Subject: - Added a code-generation utility module for JS. --- .../source/luxc/lang/translation/js/case.jvm.lux | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'new-luxc/source/luxc/lang/translation/js/case.jvm.lux') diff --git a/new-luxc/source/luxc/lang/translation/js/case.jvm.lux b/new-luxc/source/luxc/lang/translation/js/case.jvm.lux index cbb0e6c77..7c624c102 100644 --- a/new-luxc/source/luxc/lang/translation/js/case.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/js/case.jvm.lux @@ -6,15 +6,16 @@ (coll [list "list/" Fold])) [macro #+ "meta/" Monad]) (luxc [lang] - (lang ["ls" synthesis])) + (lang ["ls" synthesis] + (host [js #+ JS Expression Statement]))) [//] (// [".T" runtime] [".T" primitive] [".T" reference])) (def: #export (translate-let translate register valueS bodyS) - (-> (-> ls.Synthesis (Meta //.Expression)) Nat ls.Synthesis ls.Synthesis - (Meta //.Expression)) + (-> (-> ls.Synthesis (Meta Expression)) Nat ls.Synthesis ls.Synthesis + (Meta Expression)) (do macro.Monad [valueJS (translate valueS) bodyJS (translate bodyS)] @@ -24,8 +25,8 @@ "})()")))) (def: #export (translate-record-get translate valueS path) - (-> (-> ls.Synthesis (Meta //.Expression)) ls.Synthesis (List [Nat Bool]) - (Meta //.Expression)) + (-> (-> ls.Synthesis (Meta Expression)) ls.Synthesis (List [Nat Bool]) + (Meta Expression)) (do macro.Monad [valueJS (translate valueS)] (wrap (list/fold (function [[idx tail?] source] @@ -35,50 +36,50 @@ path)))) (def: #export (translate-if testJS thenJS elseJS) - (-> //.Expression //.Expression //.Expression - //.Expression) + (-> Expression Expression Expression + Expression) (format "(" testJS " ? " thenJS " : " elseJS ")")) (def: savepoint - //.Expression + Expression "pm_cursor_savepoint") (def: cursor - //.Expression + Expression "pm_cursor") (def: (push-cursor value) - (-> //.Expression //.Expression) + (-> Expression Expression) (format cursor ".push(" value ");")) (def: save-cursor - //.Statement + Statement (format savepoint ".push(" cursor ".slice());")) (def: restore-cursor - //.Statement + Statement (format cursor " = " savepoint ".pop();")) (def: peek-cursor - //.Expression + Expression (format cursor "[" cursor ".length - 1]")) (def: pop-cursor - //.Statement + Statement (format cursor ".pop();")) (def: pm-error - //.Expression + Expression (%t "PM-ERROR")) (def: fail-pattern-matching - //.Statement + Statement (format "throw " pm-error ";")) (exception: #export Unrecognized-Path) (def: (translate-pattern-matching' translate path) - (-> (-> ls.Synthesis (Meta //.Expression)) Code (Meta //.Expression)) + (-> (-> ls.Synthesis (Meta Expression)) Code (Meta Expression)) (case path (^code ("lux case exec" (~ bodyS))) (do macro.Monad @@ -154,7 +155,7 @@ )) (def: report-pattern-matching-error - //.Statement + Statement (format "if(ex === " pm-error ") {" "throw \"Invalid expression for pattern-matching.\";" "}" @@ -163,7 +164,7 @@ "}")) (def: (translate-pattern-matching translate path) - (-> (-> ls.Synthesis (Meta //.Expression)) Code (Meta //.Expression)) + (-> (-> ls.Synthesis (Meta Expression)) Code (Meta Expression)) (do macro.Monad [pmJS (translate-pattern-matching' translate path)] (wrap (format "try {" pmJS "}" @@ -172,13 +173,13 @@ "}")))) (def: (initialize-pattern-matching stack-init) - (-> //.Expression //.Statement) + (-> Expression Statement) (format "var temp;" "var " cursor " = [" stack-init "];" "var " savepoint " = [];")) (def: #export (translate-case translate valueS path) - (-> (-> ls.Synthesis (Meta //.Expression)) ls.Synthesis Code (Meta //.Expression)) + (-> (-> ls.Synthesis (Meta Expression)) ls.Synthesis Code (Meta Expression)) (do macro.Monad [valueJS (translate valueS) pmJS (translate-pattern-matching translate path)] -- cgit v1.2.3