From 3b156dca7b4750e99bdd68b3858521e3fd6b3de5 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 29 Jul 2018 00:11:20 -0400 Subject: Moved evaluation machinery from new-luxc to stdlib. --- stdlib/source/lux/compiler/default.lux | 6 +++-- stdlib/source/lux/compiler/default/evaluation.lux | 30 ++++++++++++++++++++++ .../source/lux/compiler/default/phase/analysis.lux | 3 +++ .../lux/compiler/default/phase/extension.lux | 7 +++-- .../lux/compiler/default/phase/synthesis.lux | 3 +++ .../lux/compiler/default/phase/translation.lux | 3 +++ stdlib/test/tests.lux | 1 + 7 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 stdlib/source/lux/compiler/default/evaluation.lux (limited to 'stdlib') diff --git a/stdlib/source/lux/compiler/default.lux b/stdlib/source/lux/compiler/default.lux index bc6e2c9ec..bc58c5d7b 100644 --- a/stdlib/source/lux/compiler/default.lux +++ b/stdlib/source/lux/compiler/default.lux @@ -1,8 +1,10 @@ (.module: - lux) + [lux #* + [data + ["." error (#+ Error)]]]) (type: #export Eval - (-> Type Code (Meta Any))) + (-> Type Code (Error Any))) (type: #export Version Text) diff --git a/stdlib/source/lux/compiler/default/evaluation.lux b/stdlib/source/lux/compiler/default/evaluation.lux new file mode 100644 index 000000000..26c4b0355 --- /dev/null +++ b/stdlib/source/lux/compiler/default/evaluation.lux @@ -0,0 +1,30 @@ +(.module: + [lux #* + [control + [monad (#+ do)] + pipe] + [data + ["." error]]] + ["." // (#+ Eval) + ["." phase + ["." analysis + [".A" expression]] + ["." synthesis + [".S" expression]] + ["." translation]]]) + +(def: #export (evaluator analysis-state synthesis-state translation-state translate) + (All [anchor expression statement] + (-> analysis.State+ + synthesis.State+ + (translation.State+ anchor expression statement) + (translation.Phase anchor expression statement) + Eval)) + (function (eval type exprC) + (do error.Monad + [exprA (|> exprC (expressionA.analyser eval)(phase.run analysis-state)) + exprS (|> exprA expressionS.synthesize (phase.run synthesis-state))] + (phase.run translation-state + (do phase.Monad + [exprO (translate exprS)] + (translation.evaluate! exprO)))))) diff --git a/stdlib/source/lux/compiler/default/phase/analysis.lux b/stdlib/source/lux/compiler/default/phase/analysis.lux index cbd447d46..72d2a3485 100644 --- a/stdlib/source/lux/compiler/default/phase/analysis.lux +++ b/stdlib/source/lux/compiler/default/phase/analysis.lux @@ -51,6 +51,9 @@ (#Apply Analysis Analysis) (#Extension (Extension Analysis))) +(type: #export State+ + (extension.State .Lux Code Analysis)) + (type: #export Operation (extension.Operation .Lux Code Analysis)) diff --git a/stdlib/source/lux/compiler/default/phase/extension.lux b/stdlib/source/lux/compiler/default/phase/extension.lux index a24d72b0c..15960083b 100644 --- a/stdlib/source/lux/compiler/default/phase/extension.lux +++ b/stdlib/source/lux/compiler/default/phase/extension.lux @@ -23,11 +23,14 @@ (type: #export (Bundle s i o) )) +(type: #export (State s i o) + [(Bundle s i o) s]) + (type: #export (Operation s i o v) - (//.Operation [(Bundle s i o) s] v)) + (//.Operation (State s i o) v)) (type: #export (Phase s i o) - (//.Phase [(Bundle s i o) s] i o)) + (//.Phase (State s i o) i o)) (do-template [] [(exception: #export ( {name Text}) diff --git a/stdlib/source/lux/compiler/default/phase/synthesis.lux b/stdlib/source/lux/compiler/default/phase/synthesis.lux index 1dbbffd84..99111d2a7 100644 --- a/stdlib/source/lux/compiler/default/phase/synthesis.lux +++ b/stdlib/source/lux/compiler/default/phase/synthesis.lux @@ -98,6 +98,9 @@ (#Control (Control Synthesis)) (#Extension (Extension Synthesis))) +(type: #export State+ + (extension.State ..State Analysis Synthesis)) + (type: #export Operation (extension.Operation ..State Analysis Synthesis)) diff --git a/stdlib/source/lux/compiler/default/phase/translation.lux b/stdlib/source/lux/compiler/default/phase/translation.lux index d2b0b0678..321573767 100644 --- a/stdlib/source/lux/compiler/default/phase/translation.lux +++ b/stdlib/source/lux/compiler/default/phase/translation.lux @@ -71,6 +71,9 @@ #counter Nat #name-cache (Dictionary Name Text)}) +(type: #export (State+ anchor expression statement) + (extension.State (State anchor expression statement) Synthesis expression)) + (type: #export (Operation anchor expression statement) (extension.Operation (State anchor expression statement) Synthesis expression)) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 2380365bf..0e09def80 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -43,6 +43,7 @@ [host [".H" scheme]] [default + ["._" evaluation] [phase ["._" translation [scheme -- cgit v1.2.3