Skip to content

Commit 986f2df

Browse files
committed
replace py-app with py-method to simplify the desugaring
1 parent 2eca1df commit 986f2df

File tree

3 files changed

+57
-56
lines changed

3 files changed

+57
-56
lines changed

‎base/python-desugar-flags.rkt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
; no idea how to write the code
5959
; (define-flag dsg-pass)
6060

61+
(define-flag dsg-dummy)
6162

6263

6364

‎base/python-desugar.rkt‎

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,11 @@
289289
(rec-desugar value)]
290290
[target-id (new-id)])
291291
(if (eq? dsg-subscript-assignment true)
292-
(py-app (py-getfield desugared-target '__setitem__)
292+
(py-method (py-getfield desugared-target '__setitem__)
293293
(list
294294
desugared-slice
295295
desugared-value)
296-
(none))
296+
)
297297
; if flag is off
298298
(CLet '$call (LocalId)
299299
(py-getfield desugared-target '__setitem__)
@@ -311,11 +311,11 @@
311311
(define assigns
312312
(if (eq? dsg-multiple-assignment true)
313313
(map2 (λ (t n)
314-
(CAssign t (py-app
314+
(CAssign t (py-method
315315
(py-getfield (CId '$tuple_result (LocalId))
316316
'__getitem__)
317317
(list (make-builtin-num n))
318-
(none))))
318+
)))
319319
targets-r
320320
(build-list (length targets-r) identity))
321321
; if flag is false
@@ -374,7 +374,7 @@
374374
(if (eq? dsg-raise true)
375375
(rec-desugar (LexApp expr (list) (list) (none) (none)))
376376
(CLet '$call (LocalId) (rec-desugar expr)
377-
(simple-apply-method (py-getfield (CId '$call (LocalId)) '__call__) (list) )))
377+
(py-method (py-getfield (CId '$call (LocalId)) '__call__) (list) )))
378378
(rec-desugar expr)))]
379379
(CRaise
380380
(if (LexPass? expr)
@@ -406,69 +406,69 @@
406406
(define right-r (rec-desugar right))
407407
(define right-c right-r)]
408408
(case op
409-
['Add (py-app (py-getfield left-c '__add__)
409+
['Add (py-method (py-getfield left-c '__add__)
410410
(list right-c)
411-
(none))]
412-
['Sub (py-app (py-getfield left-c '__sub__)
411+
)]
412+
['Sub (py-method (py-getfield left-c '__sub__)
413413
(list right-c)
414-
(none))]
415-
['Mult (py-app (py-getfield left-c '__mult__)
414+
)]
415+
['Mult (py-method (py-getfield left-c '__mult__)
416416
(list right-c)
417-
(none))]
418-
['Pow (py-app (py-getfield left-c '__pow__)
417+
)]
418+
['Pow (py-method (py-getfield left-c '__pow__)
419419
(list right-c)
420-
(none))]
421-
['Div (py-app (py-getfield left-c '__div__)
420+
)]
421+
['Div (py-method (py-getfield left-c '__div__)
422422
(list right-c)
423-
(none))]
424-
['FloorDiv (py-app (py-getfield left-c '__floordiv__)
423+
)]
424+
['FloorDiv (py-method (py-getfield left-c '__floordiv__)
425425
(list right-c)
426-
(none))]
427-
['Mod (py-app (py-getfield left-c '__mod__)
426+
)]
427+
['Mod (py-method (py-getfield left-c '__mod__)
428428
(list right-c)
429-
(none))]
430-
['BitAnd (py-app (py-getfield left-c '__and__)
429+
)]
430+
['BitAnd (py-method (py-getfield left-c '__and__)
431431
(list right-c)
432-
(none))]
433-
['BitOr (py-app (py-getfield left-c '__or__)
432+
)]
433+
['BitOr (py-method (py-getfield left-c '__or__)
434434
(list right-c)
435-
(none))]
436-
['BitXor (py-app (py-getfield left-c '__xor__)
435+
)]
436+
['BitXor (py-method (py-getfield left-c '__xor__)
437437
(list right-c)
438-
(none))]
439-
['LShift (py-app (py-getfield left-c '__lshift__)
438+
)]
439+
['LShift (py-method (py-getfield left-c '__lshift__)
440440
(list right-c)
441-
(none))]
442-
['RShift (py-app (py-getfield left-c '__rshift__)
441+
)]
442+
['RShift (py-method (py-getfield left-c '__rshift__)
443443
(list right-c)
444-
(none))]
445-
['Eq (py-app (py-getfield left-c '__eq__)
444+
)]
445+
['Eq (py-method (py-getfield left-c '__eq__)
446446
(list right-c)
447-
(none))]
448-
['Gt (py-app (py-getfield left-c '__gt__)
447+
)]
448+
['Gt (py-method (py-getfield left-c '__gt__)
449449
(list right-c)
450-
(none))]
451-
['Lt (py-app (py-getfield left-c '__lt__)
450+
)]
451+
['Lt (py-method (py-getfield left-c '__lt__)
452452
(list right-c)
453-
(none))]
454-
['LtE (py-app (py-getfield left-c '__lte__)
453+
)]
454+
['LtE (py-method (py-getfield left-c '__lte__)
455455
(list right-c)
456-
(none))]
457-
['GtE (py-app (py-getfield left-c '__gte__)
456+
)]
457+
['GtE (py-method (py-getfield left-c '__gte__)
458458
(list right-c)
459-
(none))]
459+
)]
460460
['NotEq (rec-desugar (LexUnaryOp 'Not (LexBinOp left 'Eq right)))]
461461
['In (CApp (CFunc (list 'container'test) (none)
462462
(CLet '__infunc__ (LocalId)
463463
(py-getfield (CId 'container (LocalId))
464464
'__in__)
465465
(CIf (CId '__infunc__ (LocalId))
466466
(CReturn
467-
(py-app
467+
(py-method
468468
(CId '__infunc__ (LocalId))
469469
(list
470470
(CId 'test (LocalId)))
471-
(none)))
471+
))
472472
(CRaise (some
473473
(make-exception 'TypeError
474474
(string-append
@@ -486,9 +486,9 @@
486486
['USub (rec-desugar (LexBinOp (LexNum 0) 'Sub operand))]
487487
['UAdd (rec-desugar (LexBinOp (LexNum 0) 'Add operand))]
488488
['Invert (local [(define roperand (rec-desugar operand))]
489-
(py-app (py-getfield roperand '__invrt__)
489+
(py-method (py-getfield roperand '__invrt__)
490490
(list)
491-
(none)))]
491+
))]
492492
[else (CBuiltinPrim op (list (rec-desugar operand)))])]
493493

494494
[LexBoolOp (op values) (desugar-boolop op values)]
@@ -554,12 +554,12 @@
554554
(CLet left-id
555555
(LocalId)
556556
left-r
557-
(py-app (py-getfield left-var
557+
(py-method (py-getfield left-var
558558
'__slice__)
559559

560560
(list slice-low
561561
slice-up slice-step)
562-
(none))))
562+
)))
563563
(local [(define slice-r (rec-desugar slice))
564564
(define exn-id (new-id))]
565565
(CLet left-id
@@ -576,10 +576,10 @@
576576
'TypeError
577577
"object is not subscriptable"))))
578578
(CNone))
579-
(py-app (py-getfield (CId left-id (LocalId))
579+
(py-method (py-getfield (CId left-id (LocalId))
580580
'__getitem__)
581581
(list slice-r)
582-
(none);TODO: not sure what to do with stararg.
582+
;TODO: not sure what to do with stararg.
583583
))))))]
584584
[(symbol=? ctx 'Load) ; flag is false
585585
(local [(define left-id (new-id))
@@ -590,11 +590,11 @@
590590
(define slice-up (rec-desugar (LexSlice-upper slice)))
591591
(define slice-step (rec-desugar (LexSlice-step slice)))]
592592
(CLet left-id (LocalId) left-r
593-
(simple-apply-method (py-getfield left-var '__slice__)
593+
(py-method (py-getfield left-var '__slice__)
594594
(list slice-low slice-up slice-step))))
595595
(let ((slice-r (rec-desugar slice)))
596596
(CLet left-id (LocalId) left-r
597-
(simple-apply-method (py-getfield left-var '__getitem__)
597+
(py-method (py-getfield left-var '__getitem__)
598598
(list slice-r))))))
599599
]
600600
[(symbol=? ctx 'Store)
@@ -761,11 +761,11 @@
761761
[target-id (new-id)]
762762
[target-var (CId target-id (LocalId))])
763763
(CLet target-id (LocalId) desugared-target
764-
(py-app (py-getfield target-var
764+
(py-method (py-getfield target-var
765765
'__delitem__)
766766
(list
767767
desugared-slice)
768-
(none))))]
768+
)))]
769769
[LexLocalId (x ctx) (rec-desugar
770770
(LexAssign (list (LexLocalId x ctx)) (LexUndefined)))]
771771
[LexGlobalId (x ctx) (rec-desugar

‎base/util.rkt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,14 @@
386386
(CObject (gid '%num) (some (MetaNum n))))
387387

388388
(define (py-len name)
389-
(py-app (py-getfield (CId name (LocalId)) '__len__)
389+
(py-method (py-getfield (CId name (LocalId)) '__len__)
390390
(list)
391-
(none)))
391+
))
392392

393393
(define (py-getitem name index)
394-
(py-app (py-getfield (CId name (LocalId)) '__getitem__)
394+
(py-method (py-getfield (CId name (LocalId)) '__getitem__)
395395
(list (CObject (gid '%num) (some (MetaNum index))))
396-
(none)))
396+
))
397397

398398
(define-syntax pylam
399399
(syntax-rules ()
@@ -512,7 +512,7 @@
512512
)))
513513

514514
; simple py-method-app
515-
(define (simple-apply-method [method : CExpr] [args : (listof CExpr)]) : CExpr
515+
(define (py-method [method : CExpr] [args : (listof CExpr)]) : CExpr
516516
(CLet '$call (LocalId) method
517517
(CApp (CBuiltinPrim 'obj-getattr (list (CId '$call (LocalId))
518518
(make-builtin-str "__func__")))

0 commit comments

Comments
(0)