nodes.lisp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. (import test ())
  2. (import urn/analysis/nodes ())
  3. (import urn/resolve/scope scope)
  4. (defun affirm-zip (args vals exp)
  5. (with (scope (scope/child))
  6. ;; Add variables for each argument
  7. (for-each arg args
  8. (with (var (scope/add! scope (symbol->string arg) "arg" arg))
  9. (scope/set-var-variadic! var (string/starts-with? (symbol->string arg) "&"))
  10. (.<! arg :var var))))
  11. ;; Add variables for each value
  12. (loop [(val vals)] []
  13. (case (type val)
  14. ["symbol" (.<! val :var (scope/temp-var))]
  15. ["list" (for-each elem val (recur elem))]
  16. [_]))
  17. (affirm (eq? (zip-args args 1 vals 1) exp)))
  18. (describe "The compiler can operate on nodes"
  19. (section "can zip directly called lambdas"
  20. (it "with no arguments"
  21. (affirm-zip '() '() '())
  22. (affirm-zip '() '(1 2 3) '((() (1)) (() (2)) (() (3))))
  23. (affirm-zip '() '(1 2 (foo)) '((() (1)) (() (2)) (() ((foo))))))
  24. (it "with no values"
  25. (affirm-zip '(a) '() '(((a) ())))
  26. (affirm-zip '(&a) '() '(((&a) ()))))
  27. (it "with the perfect number of arguments"
  28. (affirm-zip '(a b c) '(1 2 3) '(((a) (1)) ((b) (2)) ((c) (3))))
  29. (affirm-zip '(&a b c) '(1 2 3) '(((&a) (1)) ((b) (2)) ((c) (3))))
  30. (affirm-zip '(&a b c) '(1 2 3 4) '(((&a) (1 2)) ((b) (3)) ((c) (4)))))
  31. (it "with extra arguments"
  32. (affirm-zip '(a b c) '(1) '(((a) (1)) ((b) ()) ((c) ())))
  33. (affirm-zip '(a b c) '(1 (foo)) '(((a) (1)) ((b c) ((foo)))))
  34. (affirm-zip '(a b c) '((foo)) '(((a b c) ((foo)))))
  35. (affirm-zip '(&a b c) '(1) '(((&a) ()) ((b) (1)) ((c) ())))
  36. (affirm-zip '(&a b c) '(1 2) '(((&a) ()) ((b) (1)) ((c) (2))))
  37. (affirm-zip '(&a b c) '((foo)) '(((&a b c) ((foo)))))
  38. (affirm-zip '(a b &c) '(1) '(((a) (1)) ((b) ()) ((&c) ())))
  39. (affirm-zip '(a b &c) '((foo)) '(((a b &c) ((foo))))))
  40. (it "with extra values"
  41. (affirm-zip '(a) '(1 2 3) '(((a) (1)) (() (2)) (() (3))))
  42. (affirm-zip '(a) '(1 2 (foo)) '(((a) (1)) (() (2)) (() ((foo)))))
  43. (affirm-zip '(&a) '(1 2 3) '(((&a) (1 2 3))))
  44. (affirm-zip '(&a) '(1 2 (foo)) '(((&a) (1 2 (foo))))))
  45. ))