~subsetpark/ec

ref: big ec/test-support.janet -rw-r--r-- 667 bytes
3f9b6ebe — Zach Smith Support bigints (note: this does not work on account of floats being coerced to big ints) 7 months ago
                                                                                
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
(import /src/calc)
(import /src/eval)

(use testament)

(defn unwrap
  [obj]
  (match obj
    {:data data} (map unwrap data)
    {:value value} value))

(defn vec=
  [val obj]
  (is (== val (unwrap obj))))

(defn- make-element
  [x]
  (if (or (number? x) (= :big/int (type x)))
    (:new calc/Int x) x))

(defn wrap
  [& args]
  (calc/wrap ;(map make-element args)))

(defn quote-wrap
  [& args]
  (calc/quote-wrap ;(map make-element args)))

(defn pop-and-compare
  [val s]
  (let [found (match (calc/pop s)
                {:value value} value)]
    (is (== val found))))

(defn eval-all
  [stack tokens]
  (each token tokens
    (eval/eval-and-push stack token)))