Skip to content

Commit b99408b

Browse files
committed
desugar assignment flags
1 parent 0c6594c commit b99408b

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

‎base/python-desugar.rkt‎

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,36 @@
353353
(local [(define targets-r (map rec-desugar vals))
354354
(define value-r (rec-desugar value))
355355
(define assigns
356-
(map2 (λ (t n)
357-
(CAssign t (py-app
358-
(py-getfield (CId '$tuple_result (LocalId))
359-
'__getitem__)
360-
(list (make-builtin-num n))
361-
(none))))
362-
targets-r
363-
(build-list (length targets-r) identity)))]
364-
(if (eq? dsg-tuple-assignment true)
365-
(CLet '$tuple_result (LocalId) value-r
366-
(foldl (λ (a so-far) (CSeq so-far a))
367-
(first assigns) (rest assigns)))
368-
(CAssign (CId '$tuple_result (LocalId)) (CNone))))]
356+
(if (eq? dsg-tuple-assignment true)
357+
(map2 (λ (t n)
358+
(CAssign t (py-app
359+
(py-getfield (CId '$tuple_result (LocalId))
360+
'__getitem__)
361+
(list (make-builtin-num n))
362+
(none))))
363+
targets-r
364+
(build-list (length targets-r) identity))
365+
; if flag is off
366+
(map2 (λ (t n)
367+
(CAssign t (CLet '$call (LocalId)
368+
(py-getfield (CId '$tuple_result (LocalId))
369+
'__getitem__)
370+
(CSeq (CAssign (CId '$call (LocalId)) (py-getfield (CId '$call (LocalId)) '__call__))
371+
(CApp (CBuiltinPrim 'obj-getattr (list (CId '$call (LocalId))
372+
(make-builtin-str "__func__")))
373+
(list (CBuiltinPrim 'obj-getattr (list (CId '$call (LocalId))
374+
(make-builtin-str "__self__")))
375+
(make-builtin-num n))
376+
(none))))))
377+
targets-r
378+
(build-list (length targets-r) identity))
379+
)
380+
381+
382+
)]
383+
(CLet '$tuple_result (LocalId) value-r
384+
(foldl (λ (a so-far) (CSeq so-far a))
385+
(first assigns) (rest assigns))))]
369386
; The others become a CAssign.
370387
[else
371388
; NOTE(joe): I think this was broken before for >1 target
@@ -404,12 +421,10 @@
404421
;handle the implicit construction case
405422
(rec-desugar (LexApp expr (list) (list) (none) (none)))
406423
(rec-desugar expr)))]
407-
(if (eq? dsg-raise true)
408-
(CRaise
409-
(if (LexPass? expr)
410-
(none)
411-
(some expr-r)))
412-
(CNone)))]
424+
(CRaise
425+
(if (LexPass? expr)
426+
(none)
427+
(some expr-r))))]
413428

414429
[LexYield (expr) (CYield (rec-desugar expr))]
415430

0 commit comments

Comments
(0)