Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add support for macro expanstion to the special forms

Signed-off-by: Jordan Wilberding <diginux@gmail.com>
  • Loading branch information...
commit 2a7622b3916e0df754bd4e23386109e287b655c8 1 parent 046415c
Eric Merritt authored April 12, 2012 jwilberding committed April 19, 2012

Showing 1 changed file with 45 additions and 0 deletions. Show diff stats Hide diff stats

  1. 45  src/joxa/compiler.jxa
45  src/joxa/compiler.jxa
@@ -2409,6 +2409,49 @@
2409 2409
                     (_
2410 2410
                      (add-error-r-nil-ctx ctx path0 {:invalid-reference {val possible-arity}})))))))))))
2411 2411
 
  2412
+(defn make-macroexpand-1 (path0 ctx val args)
  2413
+  (let (annots (annots-from-context [] path0 ctx)
  2414
+        possible-arity (erlang/length args)
  2415
+        path1 (traverse-path path0)
  2416
+        call-annots (annots-from-context [] path1 ctx)
  2417
+        process-args (fn (args)
  2418
+                         (lists/map
  2419
+                          (fn (arg)
  2420
+                              (cerl/ann_make_data annots {:atomic arg} []))
  2421
+                          args)))
  2422
+    (case (resolve-reference-ctx path0 ctx val possible-arity)
  2423
+      ({:apply :not-rest :macro {function arity}}
  2424
+       (cerl/ann_c_apply annots
  2425
+                         (cerl/ann_c_fname call-annots
  2426
+                                           function
  2427
+                                           arity)
  2428
+                         (process-args args)))
  2429
+      ({:apply :rest :macro {function arity}}
  2430
+       (cerl/ann_c_apply annots
  2431
+                         (cerl/ann_c_fname call-annots
  2432
+                                           function
  2433
+                                           arity)
  2434
+                         (process-args
  2435
+                          (runtime-args-to-arity args 1 arity []))))
  2436
+      ({:remote :not-rest :macro {module function arity}}
  2437
+       (cerl/ann_c_call annots
  2438
+                        (cerl/ann_c_atom call-annots
  2439
+                                         module)
  2440
+                        (cerl/ann_c_atom call-annots
  2441
+                                         function)
  2442
+                        (process-args args)))
  2443
+      ({:remote :rest :macro {module function arity}}
  2444
+       (cerl/ann_c_call annots
  2445
+                        (cerl/ann_c_atom call-annots
  2446
+                                         module)
  2447
+                        (cerl/ann_c_atom call-annots
  2448
+                                         function)
  2449
+
  2450
+                        (process-args (runtime-args-to-arity args 1 arity []))))
  2451
+      (_
  2452
+       (add-error-r-nil-ctx ctx path1 {:not-a-macro
  2453
+                                       {val possible-arity}})))))
  2454
+
2412 2455
 (defn make-try (path0 ctx form)
2413 2456
   (let (annots (annots-from-context [] path0 ctx))
2414 2457
     (case form
@@ -3204,6 +3247,8 @@
3204 3247
        (make-list (incr-path path0) ctx args))
3205 3248
       ((:tuple . args)
3206 3249
        (make-tuple-expr (incr-path path0) ctx args))
  3250
+      ([:macroexpand-1 (val . args)]
  3251
+       (make-macroexpand-1 (incr-path path0) ctx val args))
3207 3252
       ((:__try . _)
3208 3253
        (make-try path0 ctx form))
3209 3254
       ((:fn . fn-body)

0 notes on commit 2a7622b

Please sign in to comment.
Something went wrong with that request. Please try again.