Skip to content

Commit 0d8d248

Browse files
committed
Merge branch 'master' into utf8-streams
2 parents 8071349 + 1c0f115 commit 0d8d248

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

pixie/ffi-infer.pxi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ return 0;
9898
(defmethod edn-to-ctype :pointer
9999
[{:keys [of-type] :as ptr} in-struct?]
100100
(cond
101-
(and (= of-type {:signed? true :size 1 :type :int})
101+
(and (= (:size of-type) 1)
102+
(= (:type of-type) :int)
102103
(not in-struct?)) 'pixie.stdlib/CCharP
103104
(= (:type of-type) :function) (callback-type of-type in-struct?)
104105
:else 'pixie.stdlib/CVoidP))

pixie/stdlib.pxi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,6 +2311,24 @@ Expands to calls to `extend-type`."
23112311
([f col]
23122312
(transduce (map f) conj col)))
23132313

2314+
(defn macroexpand-1 [form]
2315+
{:doc "If form is a macro call, returns the expanded form.
2316+
2317+
Does nothing if not a macro call."
2318+
:signatures [[form]]
2319+
:examples [["(macroexpand-1 '(when condition this and-this))"
2320+
nil `(if condition (do this and-this))]
2321+
["(macroexpand-1 ())" nil ()]
2322+
["(macroexpand-1 [1 2])" nil [1 2]]]}
2323+
(if (or (not (list? form))
2324+
(= () form))
2325+
form
2326+
(let [[sym & args] form
2327+
fvar (resolve sym)]
2328+
(if (and fvar (macro? @fvar))
2329+
(apply @fvar args)
2330+
form))))
2331+
23142332
(def *1)
23152333
(def *2)
23162334
(def *3)

pixie/vm/libs/ffi.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,9 @@ def ffi_set_value(self, ptr, val):
394394
vpnt = rffi.cast(rffi.VOIDPP, ptr)
395395
vpnt[0] = rffi.cast(rffi.VOIDP, val.raw_data())
396396
else:
397-
print val
398-
affirm(False, u"Cannot encode this type")
397+
frm_name = rt.name(rt.str(val.type()))
398+
to_name = rt.name(rt.str(self))
399+
affirm(False, u"Cannot encode " + frm_name + u" as " + to_name)
399400

400401

401402
def ffi_size(self):
@@ -445,7 +446,13 @@ def ffi_get_value(self, ptr):
445446

446447
def ffi_set_value(self, ptr, val):
447448
pnt = rffi.cast(rffi.VOIDPP, ptr)
448-
if isinstance(val, Buffer):
449+
if isinstance(val, String):
450+
pnt = rffi.cast(rffi.CCHARPP, ptr)
451+
utf8 = unicode_to_utf8(rt.name(val))
452+
raw = rffi.str2charp(utf8)
453+
pnt[0] = raw
454+
return CCharPToken(raw)
455+
elif isinstance(val, Buffer):
449456
pnt[0] = val.buffer()
450457
elif isinstance(val, VoidP):
451458
pnt[0] = val.raw_data()
@@ -454,8 +461,10 @@ def ffi_set_value(self, ptr, val):
454461
elif isinstance(val, CStruct):
455462
pnt[0] = rffi.cast(rffi.VOIDP, val.raw_data())
456463
else:
457-
print val
458-
affirm(False, u"Cannot encode this type")
464+
frm_name = rt.name(rt.str(val.type()))
465+
to_name = rt.name(rt.str(self))
466+
affirm(False, u"Cannot encode " + frm_name + u" as " + to_name)
467+
459468

460469
def ffi_size(self):
461470
return rffi.sizeof(rffi.VOIDP)

pixie/vm/object.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ def runtime_error(msg):
151151
import pixie.vm.rt as rt
152152
raise WrappedException(RuntimeException(rt.wrap(msg)))
153153

154+
def safe_invoke(f, args):
155+
try:
156+
f.invoke(args)
157+
except Exception as ex:
158+
if isinstance(ex, WrappedException):
159+
print "UNSAFE EXCEPTION", ex._ex.__repr__()
160+
else:
161+
print "UNSAFE EXCEPTION", ex
162+
return None
163+
154164
class ErrorInfo(Object):
155165
_type = Type(u"pixie.stdlib.ErrorInfo")
156166
def type(self):

pixie/vm/threads.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pixie.vm.object import Object, Type
1+
from pixie.vm.object import Object, Type, safe_invoke
22
from pixie.vm.primitives import true
33
import rpython.rlib.rthread as rthread
44
from pixie.vm.primitives import nil
@@ -42,7 +42,7 @@ def bootstrap():
4242
rthread.gc_thread_start()
4343
fn = bootstrapper.fn()
4444
bootstrapper.release()
45-
fn.invoke([])
45+
safe_invoke(fn, [])
4646
rthread.gc_thread_die()
4747

4848
bootstrapper = Bootstrapper()

0 commit comments

Comments
 (0)