blob: b460a2e185c785e8dd6472633fb39a3eac7bc4e1 (
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
|
;; Copyright (c) Eduardo Julian. All rights reserved.
;; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
;; If a copy of the MPL was not distributed with this file,
;; You can obtain one at http://mozilla.org/MPL/2.0/.
(ns lux.analyser.lambda
(:require clojure.core.match
clojure.core.match.array
(lux [base :as & :refer [|let |do return |case]]
[host :as &host])
(lux.analyser [base :as &&]
[env :as &env])))
;; [Resource]
(defn with-lambda [self self-type arg arg-type body]
(&/with-closure
(|do [scope-name &/get-scope-name]
(&env/with-local self self-type
(&env/with-local arg arg-type
(|do [=return body
=captured &env/captured-vars]
(return (&/T [scope-name =captured =return]))))))))
(defn close-over [scope name register frame]
(|let [[[register-type register-cursor] _] register
register* (&&/|meta register-type register-cursor
(&&/$captured (&/T [scope
(->> frame (&/get$ &/$closure) (&/get$ &/$counter))
register])))]
(&/T [register* (&/update$ &/$closure #(->> %
(&/update$ &/$counter inc)
(&/update$ &/$mappings (fn [mps] (&/|put name register* mps))))
frame)])))
|