Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 61 lines (45 sloc) 1.479 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
macro(evaluate-when(~*when) ~(x: Block)):
  evaluated? = false

  when member?('compile) && do:
    x block-body evaluate
    evaluated? =! true

  when member?('load) && do:
    Atomy::CodeLoader when-load << [x block-body, evaluated?]

  when member?('run) &&
    Atomy::CodeLoader when-run << [x block-body, evaluated?]

  'nil

macro(for-macro ~(b: Block)):
  `(evaluate-when(compile, load, run):
      module(Atomy::Macro::Helpers):
        ~*(b contents))

macro(let-macro(~*ms) ~(b: Block)):
  tripled = ms zip(names(ms size) zip(names(ms size)))

  define =
    tripled collect [[`(~p = ~b), [let, mac]]]:
      `(do:
          Atomy::STATE [#~mac] = ~mac = '(macro(~p): ~b)

          Atomy::STATE [#~let] =
            Atomy::Macro register(
              ~mac pattern class
              ~mac pattern macro-pattern
              ~mac body
              Atomy::CodeLoader compiling
              true
            ))

  unwind =
    tripled collect [[_, [let, mac]]]:
      `(do:
          ~mac = Atomy::STATE [#~mac] pattern

          ~mac class remove-method(Atomy::STATE [#~let])

          when(lets = Atomy::Macro::Environment let [~mac class]):
            lets delete(Atomy::STATE [#~let])

            when(lets empty?):
              Atomy::Macro::Environment let delete(~mac class))

  names [res]:
    `(do:
        evaluate-when(compile):
          ~*define

        ~res = ~(b block-body)

        evaluate-when(compile):
          ~*unwind

        ~res)
Something went wrong with that request. Please try again.