-
Notifications
You must be signed in to change notification settings - Fork 1
/
type_checking.cljc
58 lines (48 loc) · 1.92 KB
/
type_checking.cljc
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(ns fif.stdlib.type-checking
(:require
[fif.stack-machine :as stack]
[fif.stack-machine.evaluators :as evaluators]
[fif.stack-machine.words :as words :refer [set-global-word-defn]]
[fif.def :as def
:refer [wrap-function-with-arity
wrap-procedure-with-arity]
:include-macros true]))
(defn word?-op
[sm]
(let [[wname] (stack/get-stack sm)]
(if (-> sm words/get-word-listing (get wname))
(-> sm stack/pop-stack (stack/push-stack true) stack/dequeue-code)
(-> sm stack/pop-stack (stack/push-stack false) stack/dequeue-code))))
(defn fn?-op
[sm]
(let [[wname] (stack/get-stack sm)]
(if-let [meta (words/get-global-metadata sm wname)]
(if (:variable? meta)
(-> sm stack/pop-stack (stack/push-stack false) stack/dequeue-code)
(-> sm stack/pop-stack (stack/push-stack true) stack/dequeue-code))
(-> sm stack/pop-stack (stack/push-stack false) stack/dequeue-code))))
(defn variable?-op
[sm]
(let [[wname] (stack/get-stack sm)]
(if-let [meta (words/get-global-metadata sm wname)]
(if (:variable? meta)
(-> sm stack/pop-stack (stack/push-stack true) stack/dequeue-code)
(-> sm stack/pop-stack (stack/push-stack false) stack/dequeue-code))
(-> sm stack/pop-stack (stack/push-stack false) stack/dequeue-code))))
(defn import-stdlib-type-checking [sm]
(-> sm
(set-global-word-defn
'word? word?-op
:stdlib? true
:group :stdlib.type-checking
:doc "( any -- bool ) Returns true if the given value is a word definition.")
(set-global-word-defn
'fn? fn?-op
:stdlib? true
:group :stdlib.type-checking
:doc "( any -- bool ) Returns true if the given value is a word function.")
(set-global-word-defn
'variable? variable?-op
:stdlib? true
:group :stdlib.type-checking
:doc "( any -- bool ) Returns true if the given value is a word variable.")))