aboutsummaryrefslogtreecommitdiff
path: root/src/lux/analyser/case.clj
blob: 5227bfcb09e2a699db028871552feae589d86b73 (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
(ns lux.analyser.case
  (:require [clojure.core.match :refer [match]]
            (lux [base :as & :refer [exec return fail
                                     try-all-m map-m mapcat-m reduce-m
                                     assert!]]
                 [parser :as &parser]
                 [type :as &type])
            (lux.analyser [base :as &&]
                          [env :as &env])))

;; [Resources]
(defn locals [member]
  (match member
    [::&parser/Ident ?name]
    (list ?name)

    [::&parser/Tuple ?submembers]
    (mapcat locals ?submembers)

    [::&parser/Form ([[::&parser/Tag _] & ?submembers] :seq)]
    (mapcat locals ?submembers)

    _
    (list)))

(defn analyse-branch [analyse max-registers [bindings body]]
  ;; (prn 'analyse-branch max-registers bindings body)
  (reduce (fn [body* name]
            (&env/with-local name &type/+dont-care-type+ body*))
          (reduce (fn [body* _]
                    (&env/with-local "" &type/+dont-care-type+ body*))
                  (&&/analyse-1 analyse body)
                  (range (- max-registers (count bindings))))
          (reverse bindings)))