@@ -478,9 +478,7 @@ contents =
478
478
finalizer : finally -clause
479
479
480
480
\macro : ->
481
- env = this
482
-
483
- compile -as -macro = (es -ast ) ->
481
+ compile -as -macro = (es -ast ) ~>
484
482
485
483
# This hack around require makes loading macros from relative paths work.
486
484
#
@@ -501,7 +499,7 @@ contents =
501
499
root -require = main .require.bind main
502
500
503
501
let require = root -require
504
- eval "(#{env. compile-to-js es-ast})"
502
+ eval "(#{@ compile-to-js es-ast})"
505
503
506
504
switch &length
507
505
| 1 =>
@@ -511,21 +509,21 @@ contents =
511
509
512
510
# Mask any macro of that name in the current scope
513
511
514
- import -compilerspace -macro env , form .value, null
512
+ import -compilerspace -macro this , form .value, null
515
513
516
514
| otherwise
517
515
518
516
# Attempt to compile the argument, hopefully into an object,
519
517
# define macros from its keys
520
518
521
- es -ast = env . compile form
519
+ es -ast = @ compile form
522
520
523
521
result = compile -as -macro es -ast
524
522
525
523
switch typeof ! result
526
524
| \Object =>
527
525
for k , v of result
528
- import -compilerspace -macro env , k , v
526
+ import -compilerspace -macro this , k , v
529
527
| \Null => fallthrough
530
528
| \Undefined => # do nothing
531
529
| otherwise =>
@@ -540,19 +538,19 @@ contents =
540
538
name = name .value
541
539
target -name = form .value
542
540
543
- alias -target -macro = env . find-macro target -name
541
+ alias -target -macro = @ find -macro target -name
544
542
545
543
if not alias -target -macro
546
544
throw Error "Macro alias target `#target-name` is not defined"
547
545
548
- import -compilerspace -macro env , name , alias -target -macro
546
+ import -compilerspace -macro this , name , alias -target -macro
549
547
550
548
| form .type is \list
551
549
552
- userspace -macro = form |> env . compile |> compile -as -macro
550
+ userspace -macro = form |> @ compile |> compile -as -macro
553
551
554
552
name .= value
555
- import -compilerspace -macro env , name , userspace -macro
553
+ import -compilerspace -macro this , name , userspace -macro
556
554
557
555
| otherwise =>
558
556
throw Error "Bad number of arguments to macro constructor \
@@ -567,23 +565,24 @@ contents =
567
565
# means we have to resolve lists which first atom is `unquote` or
568
566
# `unquote-splicing` into either an array of values or an identifier to
569
567
# an array of values.
570
- qq -body = (env , ast ) ->
571
568
572
- recurse -on = (ast -list ) ->
569
+ qq -body = (ast ) ->
570
+
571
+ recurse -on = (ast -list ) ~>
573
572
ast -list .values
574
- |> map qq -body env , _
573
+ |> map qq -body .bind this
575
574
|> generate -concat
576
575
577
- unquote = - >
578
- if arguments . length isnt 1
576
+ unquote = ~ >
577
+ if & length isnt 1
579
578
throw Error "Expected 1 argument to unquote but got #{rest.length}"
580
579
581
580
# Unquoting should compile to just the thing separated with an array
582
581
# wrapper.
583
- [ env . compile it ]
582
+ [ @ compile it ]
584
583
585
- unquote -splicing = - >
586
- if arguments . length isnt 1
584
+ unquote -splicing = ~ >
585
+ if & length isnt 1
587
586
throw Error "Expected 1 argument to unquoteSplicing but got
588
587
#{rest.length}"
589
588
@@ -592,8 +591,7 @@ contents =
592
591
593
592
type : \MemberExpression
594
593
computed : false
595
- object :
596
- env .compile it
594
+ object : @compile it
597
595
property :
598
596
type : \Identifier
599
597
name : \values
@@ -604,19 +602,19 @@ contents =
604
602
switch
605
603
| not head ?
606
604
# quote an empty list
607
- [ quote .call env , {
605
+ [ quote .call this , {
608
606
type : \list
609
607
values : []
610
- location :"returned from macro"
608
+ location : "returned from macro"
611
609
} ]
612
610
| head .type is \atom =>
613
611
switch head .value
614
- | \unquote => unquote .apply null rest
615
- | \unquote -splicing => unquote -splicing .apply null rest
612
+ | \unquote => unquote ... rest
613
+ | \unquote -splicing => unquote -splicing ... rest
616
614
| _ => [ recurse -on ast ]
617
615
| _ => [ recurse -on ast ]
618
616
619
- | _ => [ quote .call env , ast ]
617
+ | _ => [ quote .call this , ast ]
620
618
621
619
generate -concat = (concattable -things ) ->
622
620
@@ -668,9 +666,6 @@ contents =
668
666
arguments : it
669
667
]
670
668
qq = (arg ) ->
671
-
672
- env = this
673
-
674
669
if &length > 1
675
670
throw Error "Too many arguments to quasiquote (`); \
676
671
expected 1, got #{&length}"
@@ -681,14 +676,14 @@ contents =
681
676
682
677
if first -arg .type is \atom and first -arg .value is \unquote
683
678
rest = arg .values.slice 1 .0
684
- env . compile rest
679
+ @ compile rest
685
680
686
681
else
687
682
arg .values
688
- |> map qq -body env , _
683
+ |> map qq -body .call this , _
689
684
|> generate -concat
690
685
691
- else quote .call env , arg # act like regular quote
686
+ else quote .call this , arg # act like regular quote
692
687
693
688
module .exports =
694
689
parent : null
0 commit comments