Skip to content

Commit a76a2db

Browse files
committed
rt.count now unwraps
1 parent ff2fbc1 commit a76a2db

5 files changed

Lines changed: 20 additions & 19 deletions

File tree

pixie/vm/compiler.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def is_macro_call(form, ctx):
256256

257257
def call_macro(var, form, ctx):
258258
form = rt.next(form)
259-
args = [None] * rt.count(form).int_val()
259+
args = [None] * rt.count(form)
260260
i = 0
261261
while form is not nil:
262262
args[i] = rt.first(form)
@@ -278,7 +278,7 @@ def compile_map_literal(form, ctx):
278278

279279
rt.reduce(CompileMapRf(ctx), nil, form)
280280

281-
size = rt.count(form).int_val() * 2
281+
size = rt.count(form) * 2
282282
ctx.bytecode.append(code.INVOKE)
283283
ctx.bytecode.append(r_uint(size) + 1)
284284

@@ -321,7 +321,7 @@ def compile_form(form, ctx):
321321

322322
if isinstance(form, PersistentVector):
323323
vector_var = rt.vector()
324-
size = rt.count(form).int_val()
324+
size = rt.count(form)
325325
#assert rt.count(form).int_val() == 0
326326
ctx.push_const(code.intern_var(u"pixie.stdlib", u"vector"))
327327
for x in range(size):
@@ -359,7 +359,7 @@ def compile_platform_plus(form, ctx):
359359
def compile_platform_eq(form, ctx):
360360
form = form.next()
361361

362-
affirm(rt.count(form).int_val() == 2, u"TODO: REMOVE")
362+
affirm(rt.count(form) == 2, u"TODO: REMOVE")
363363
while form is not nil:
364364
compile_form(form.first(), ctx)
365365
form = form.next()
@@ -371,7 +371,7 @@ def compile_platform_eq(form, ctx):
371371
def add_args(args, ctx):
372372
required_args = -1
373373
local_idx = 0
374-
for x in range(rt.count(args).int_val()):
374+
for x in range(rt.count(args)):
375375
arg = rt.nth(args, rt.wrap(x))
376376
affirm(isinstance(arg, symbol.Symbol), u"Argument names must be symbols")
377377
if arg._str == u"&":
@@ -416,7 +416,7 @@ def compile_fn(form, ctx):
416416

417417

418418
def compile_fn_body(name, args, body, ctx):
419-
new_ctx = Context(name._str, rt.count(args).int_val(), ctx)
419+
new_ctx = Context(name._str, rt.count(args), ctx)
420420
required_args = add_args(args, new_ctx)
421421
bc = 0
422422

@@ -455,11 +455,11 @@ def compile_fn_body(name, args, body, ctx):
455455
ctx.bytecode.append(code.MAKE_VARIADIC)
456456
ctx.bytecode.append(r_uint(required_args))
457457

458-
return required_args, rt.count(args).int_val()
458+
return required_args, rt.count(args)
459459

460460
def compile_if(form, ctx):
461461
form = form.next()
462-
affirm(2 <= rt.count(form).int_val() <= 3, u"If must have either 2 or 3 forms")
462+
affirm(2 <= rt.count(form) <= 3, u"If must have either 2 or 3 forms")
463463

464464
test = rt.first(form)
465465
form = rt.next(form)
@@ -547,7 +547,7 @@ def compile_let(form, ctx):
547547
ctx.disable_tail_call()
548548

549549
binding_count = 0
550-
for i in range(0, rt.count(bindings).int_val(), 2):
550+
for i in range(0, rt.count(bindings), 2):
551551
binding_count += 1
552552
name = rt.nth(bindings, rt.wrap(i))
553553
affirm(isinstance(name, symbol.Symbol), u"Let locals must be symbols")
@@ -583,7 +583,7 @@ def compile_loop(form, ctx):
583583
ctx.disable_tail_call()
584584

585585
binding_count = 0
586-
for i in range(0, rt.count(bindings).int_val(), 2):
586+
for i in range(0, rt.count(bindings), 2):
587587
binding_count += 1
588588
name = rt.nth(bindings, rt.wrap(i))
589589
affirm(isinstance(name, symbol.Symbol), u"Loop must bindings must be symbols")
@@ -615,7 +615,7 @@ def compile_comment(form, ctx):
615615
ctx.push_const(nil)
616616

617617
def compile_ns(form, ctx):
618-
affirm(rt.count(form).int_val() == 2, u"ns only takes one argument, a symbol")
618+
affirm(rt.count(form) == 2, u"ns only takes one argument, a symbol")
619619

620620
nm = rt.first(rt.next(form))
621621

pixie/vm/custom_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def set_field_by_idx(self, idx, val):
5353
def create_type(type_name, fields):
5454
affirm(isinstance(type_name, Keyword), u"Type name must be a keyword")
5555

56-
field_count = rt.count(fields).int_val()
56+
field_count = rt.count(fields)
5757
acc = {}
58-
for i in range(rt.count(fields).int_val()):
58+
for i in range(rt.count(fields)):
5959
val = rt.nth(fields, rt.wrap(i))
6060
affirm(isinstance(val, Keyword), u"Field names must be keywords")
6161
acc[val] = i

pixie/vm/libs/ffi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def _ffi_fn(lib, nm, args, ret_type):
188188
affirm(isinstance(ret_type, object.Type), u"Ret type must be a type")
189189
affirm(rt.namespace(nm) is None, u"Name must not be namespaced")
190190

191-
cnt = rt.count(args).int_val()
191+
cnt = rt.count(args)
192192
new_args = [None] * cnt
193193
for x in range(cnt):
194194
t = rt.nth(args, rt.wrap(x))

pixie/vm/persistent_vector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,10 @@ def _reduce(self, f, init):
423423

424424
@as_var("vector")
425425
def vector__args(args):
426-
acc = EMPTY
426+
acc = rt._transient(EMPTY)
427427
for x in range(len(args)):
428-
acc = acc.conj(args[x])
429-
return acc
428+
acc = rt._conj_BANG_(acc, args[x])
429+
return rt._persistent_BANG_(acc)
430430

431431
@extend(proto._transient, PersistentVector)
432432
def _transient(self):

pixie/vm/stdlib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def __hash(x):
142142
_count_driver = jit.JitDriver(name="pixie.stdlib.count",
143143
greens=["tp"],
144144
reds="auto")
145+
@returns(r_uint)
145146
@as_var("count")
146147
def count(x):
147148
acc = 0
@@ -199,11 +200,11 @@ def apply__args(args):
199200

200201
fn = args[0]
201202
argc = r_uint(len(args) - 2)
202-
out_args = [None] * (argc + r_uint(rt.count(last_itm).int_val()))
203+
out_args = [None] * (argc + r_uint(rt.count(last_itm)))
203204

204205
list_copy(args, 1, out_args, 0, argc)
205206

206-
for x in range(rt.count(last_itm).int_val()):
207+
for x in range(rt.count(last_itm)):
207208
out_args[argc + x] = rt.nth(last_itm, rt.wrap(x))
208209

209210
return fn.invoke(out_args)

0 commit comments

Comments
 (0)