aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/compiler/default/evaluation.lux
blob: 3fb1a998493b84bb1a6df53bb138380aca03853a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(.module:
  [lux #*
   [control
    [monad (#+ do)]]
   [data
    ["." error]
    [text
     format]]]
  [//
   ["." phase
    [analysis (#+ Operation)
     [".A" expression]
     ["." type]]
    ["." synthesis
     [".S" expression]]
    ["." translation]]])

(type: #export Eval
  (-> Nat Type Code (Operation Any)))

(def: #export (evaluator synthesis-state translation-state translate)
  (All [anchor expression statement]
    (-> synthesis.State+
        (translation.State+ anchor expression statement)
        (translation.Phase anchor expression statement)
        Eval))
  (function (eval count type exprC)
    (do phase.Monad<Operation>
      [exprA (type.with-type type
               (expressionA.compile exprC))]
      (phase.lift (do error.Monad<Error>
                    [exprS (|> exprA expressionS.synthesize (phase.run synthesis-state))]
                    (phase.run translation-state
                               (do phase.Monad<Operation>
                                 [exprO (translate exprS)]
                                 (translation.evaluate! (format "eval" (%n count)) exprO))))))))