Skip to content

Commit 3614471

Browse files
committed
merge master
2 parents dc3f22a + fed04da commit 3614471

8 files changed

Lines changed: 77 additions & 37 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pixie-vm
44
.idea
55
lib
66
include
7+
pixie/*.pxic

pixie/ffi-infer.pxi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
[{:keys [name]}]
6363
(str "PixieChecker::DumpType<__typeof__(" name ")>();"))
6464

65+
(defmethod emit-infer-code :global
66+
[_]
67+
(str "std::cout <<\"[]\" << std::endl;"))
68+
6569

6670
(defn start-string []
6771
(str (apply str (map (fn [i]
@@ -80,6 +84,7 @@
8084
return 0;
8185
}")
8286

87+
8388
;; To Ctype conversion
8489

8590
(defmulti edn-to-ctype (fn [n _]
@@ -131,6 +136,10 @@ return 0;
131136
[{:keys [name]} {:keys [value type]}]
132137
`(def ~(symbol name) ~value))
133138

139+
(defmethod generate-code :global
140+
[{:keys [name]} _]
141+
`(def ~(symbol name) (ffi-voidp *library* ~(str name))))
142+
134143

135144

136145
(defmethod generate-code :function
@@ -228,6 +237,10 @@ return 0;
228237
`(swap! *bodies* conj (assoc {:op :callback}
229238
:name ~(name nm))))
230239

240+
(defmacro defglobal [nm]
241+
`(swap! *bodies* conj (assoc {:op :global}
242+
:name ~(name nm))))
243+
231244

232245
(defn compile-library [{:keys [prefix includes]} & source]
233246
(let [c-name (str "/tmp/" prefix ".c")

pixie/repl.pxi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
(try (let [form (read rdr false)]
2222
(if (= form eof)
2323
(exit 0)
24-
(println (eval form))))
24+
(let [x (eval form)]
25+
(pixie.stdlib/-push-history x)
26+
(prn x))))
2527
(catch ex
26-
(println "ERROR: \n" ex)))
28+
(pixie.stdlib/-set-*e ex)
29+
(println "ERROR: \n" ex)))
2730
(recur))))

pixie/stdlib.pxi

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,32 +144,22 @@
144144
([result] (xf result))
145145
([result item] (xf result (f item))))))
146146
([f coll]
147-
(let [i (iterator coll)]
148-
(loop []
149-
(if (at-end? i)
150-
nil
151-
(do (yield (f (current i)))
152-
(move-next! i)
153-
(recur))))))
147+
(lazy-seq*
148+
(fn []
149+
(let [s (seq coll)]
150+
(if s
151+
(cons (f (first s))
152+
(map f (rest s)))
153+
nil)))))
154154
([f & colls]
155-
(let [its (vec (map iterator colls))]
156-
(loop []
157-
(let [args (if (at-end? (first its))
158-
nil
159-
(reduce
160-
(fn [acc i]
161-
(if (at-end? i)
162-
(reduced nil)
163-
(let [new-acc (conj acc (current i))]
164-
(move-next! i)
165-
new-acc)))
166-
[]
167-
its))]
168-
169-
(if args
170-
(do (yield (apply f args))
171-
(recur)))))))))
172-
155+
(let [step (fn step [cs]
156+
(lazy-seq*
157+
(fn []
158+
(let [ss (map seq cs)]
159+
(if (every? identity ss)
160+
(cons (map first ss) (step (map rest ss)))
161+
nil)))))]
162+
(map (fn [args] (apply f args)) (step colls))))))
173163

174164
(def reduce (fn [rf init col]
175165
(-reduce col rf init)))
@@ -812,6 +802,7 @@ If further arguments are passed, invokes the method named by symbol, passing the
812802
(defn keyword? [v] (instance? Keyword v))
813803

814804
(defn list? [v] (instance? PersistentList v))
805+
(defn set? [v] (instance? PersistentHashSet v))
815806
(defn map? [v] (satisfies? IMap v))
816807
(defn fn? [v] (satisfies? IFn v))
817808

@@ -2191,3 +2182,11 @@ Expands to calls to `extend-type`."
21912182
(defn mapv
21922183
([f col]
21932184
(transduce (map f) conj col)))
2185+
2186+
(defn -push-history [x]
2187+
(def *3 *2)
2188+
(def *2 *1)
2189+
(def *1 x))
2190+
2191+
(defn -set-*e [e]
2192+
(def *e e))

pixie/test.pxi

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,25 @@
6161
yr# ~y]
6262
(assert (= xr# yr#) (str (show '~x xr#) " != " (show '~y yr#)))))
6363

64-
(defmacro assert-throws? [klass msg body]
65-
`(try
66-
~body
67-
(assert false (str "Expected a " ~klass " exception: " ~msg))
68-
(catch e#
69-
(assert (= (type e#) ~klass)
70-
(str "Expected exception of class " ~klass " but got " (type e#)))
71-
(assert (= (ex-msg e#) ~msg)
72-
(str "Expected message: " ~msg " but got " (ex-msg e#))))))
64+
(defmacro assert-throws?
65+
([body]
66+
`(let [exn# (try (do ~body nil) (catch e# e#))]
67+
(assert (not (nil? exn#))
68+
(str "Expected " (pr-str (quote ~body)) " to throw an exception"))
69+
exn#))
70+
([klass body]
71+
`(let [exn# (assert-throws? ~body)]
72+
(assert (= (type exn#) ~klass)
73+
(str "Expected " (pr-str (quote ~body))
74+
" to throw exception of class " (pr-str ~klass)
75+
" but got " (pr-str (type exn#))))
76+
exn#))
77+
([klass msg body]
78+
`(let [exn# (assert-throws? ~klass ~body)]
79+
(assert (= (ex-msg exn#) ~msg)
80+
(str "Expected " (pr-str (quote ~body))
81+
" to throw exception with message " (pr-str ~msg)
82+
" but got " (pr-str (ex-msg exn#)))))))
7383

7484
(defmacro assert [x]
7585
`(let [x# ~x]

pixie/vm/libs/ffi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ def _ffi_fn__args(args):
196196
f = FFIFn(lib, rt.name(nm), new_args, ret_type, is_variadic)
197197
return f
198198

199+
@as_var("ffi-voidp")
200+
def _ffi_voidp(lib, nm):
201+
affirm(isinstance(lib, ExternalLib), u"First argument to ffi-voidp should be an external library")
202+
name = rt.name(nm)
203+
return VoidP(lib.get_fn_ptr(name))
204+
205+
199206

200207

201208

pixie/vm/stdlib.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ def _load_file(filename, compile=False):
420420
import pixie.vm.reader as reader
421421
import pixie.vm.libs.pxic.writer as pxic_writer
422422
import os.path as path
423-
from pixie.vm.persistent_vector import EMPTY as EMPTY_VECTOR
424423
import os
425424

426425

tests/pixie/tests/test-stdlib.pxi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
(doseq [v vs]
77
(t/assert= (identity v) v))))
88

9+
(t/deftest test-map
10+
(t/assert= (map inc [1 2 3]) [2 3 4])
11+
(t/assert= (map + [1 2 3] [4 5 6]) [5 7 9])
12+
(t/assert= (map + [1 2 3] [4 5 6] [7 8 9]) [12 15 18])
13+
(let [value (map identity [1 2 3])]
14+
(t/assert= (seq value) [1 2 3])
15+
(t/assert= (seq value) [1 2 3])))
16+
917
(t/deftest test-mapcat
1018
(t/assert= (mapcat identity []) [])
1119
(t/assert= (mapcat first [[[1 2]] [[3] [:not :present]] [[4 5 6]]]) [1 2 3 4 5 6]))

0 commit comments

Comments
 (0)