Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

145 lines (113 sloc) 4.209 kB
use("core")
infix("=! := **= *= <<= >>= &&=", 10, .right)
infix("&= ||= |= += -= /= ^= %=", 10, .right)
macro(do ~(b: Block)): b body
macro(~x =! ~y):
Set new(node line, x, y)
macro((~name)(~*args) = ~body):
DefineFunction new(node line, body, args, name text)
macro((~name)(~*args) &~b = ~body):
DefineFunction new(node line, body, args, name text, b)
macro(~(x: `((~_)(~*_)?)) = ~body):
DefineFunction new(node line, body, arguments(x), message-name(x))
macro(~(x: `((~_)(~*_)?)) &~b = ~body):
DefineFunction new(node line, body, arguments(x), message-name(x), b)
macro(~(x: `((~_)(~*_)!)) = ~body):
DefineFunction new(node line, body, arguments(x), message-name(x))
macro(~(x: `((~_)(~*_)!)) &~b = ~body):
DefineFunction new(node line, body, arguments(x), message-name(x), b)
arguments(b: Atomy AST Infix) = [b right]
arguments(? to-word) = []
arguments(Atomy AST Prefix) = []
arguments(Atomy AST Postfix) = []
arguments(`((~_)(~*args)?)) = args
arguments(`((~_)(~*args)!)) = args
arguments(c: Atomy AST Call) = c arguments
arguments(`(~_ (~_)(~*args)?)) = args
arguments(`(~_ (~_)(~*args)!)) = args
arguments(`(~_ (~_)(~*args))) = args
arguments(`(~_ ~(? to-word))) = []
arguments(`(~_ [~*args])) = args
arguments(`(~a &~_)) = arguments(a)
arguments(`/~x) = arguments(x)
arguments(`//~x) = arguments(x)
arguments(x) =
raise(ArgumentError, "cannot get arguments from:\n" + x inspect)
receiver(b: Atomy AST Infix) = b left
receiver(p: Atomy AST Prefix) = p receiver
receiver(p: Atomy AST Postfix) = p receiver
receiver(? to-word) = Atomy AST Primitive new(0, .self)
receiver(Atomy AST Call) = Atomy AST Primitive new(0, .self)
receiver(`((~_)(~*_)?)) = Atomy AST Primitive new(0, .self)
receiver(`((~_)(~*_)!)) = Atomy AST Primitive new(0, .self)
receiver(`(~a &~_)) = receiver(a)
receiver(`(~a ~_)) = a
receiver(`/~_) = 'Self
receiver(`//~_) = 'Kernel
receiver(x) =
raise(ArgumentError, "cannot get receiver from:\n" + x inspect)
message-name(b: Atomy AST Infix) = b operator
message-name(p: Atomy AST Prefix) = p message-name
message-name(p: Atomy AST Postfix) = p message-name
message-name(w: ? to-word) = w to-word text
message-name(`((~(w: Atomy AST Word))(~*_)?)) = (w text to-s + "?") to-sym
message-name(`((~(w: Atomy AST Word))(~*_)!)) = (w text to-s + "!") to-sym
message-name(`((~(w: Atomy AST Word))(~*_))) = w text
message-name(`(~_ ~(w: ? to-word))) = w to-word text
message-name(`(~_ (~(w: Atomy AST Word))(~*_))) = w text
message-name(`(~_ (~(w: Atomy AST Word))(~*_)?)) = (w text to-s + "?") to-sym
message-name(`(~_ (~(w: Atomy AST Word))(~*_)!)) = (w text to-s + "!") to-sym
message-name(`(~_ [~*_])) = .[]
message-name(`(~a &~_)) = message-name(a)
message-name(`/~x) = message-name(x)
message-name(`//~x) = message-name(x)
message-name(x) =
raise(ArgumentError, "cannot get message-name from:\n" + x inspect)
block(`(~_ &~b)) = b
block(_) = nil
macro(~x := ~y):
DefineMethod new(
node line,
y,
receiver(x),
arguments(x),
message-name(x),
block(x))
-- expose our helpers
{ self } arguments(x) := arguments(x)
{ self } receiver(x) := arguments(x)
{ self } message-name(x) := message-name(x)
{ self } block(x) := block(x)
macro(define(~x) ~(y: Block)):
`(~x := ~(y body))
macro(~x **= ~y): `(~x =! (~x ** ~y))
macro(~x *= ~y): `(~x =! (~x * ~y))
macro(~x <<= ~y): `(~x =! (~x << ~y))
macro(~x >>= ~y): `(~x =! (~x >> ~y))
macro(~x &= ~y): `(~x =! (~x & ~y))
macro(~x |= ~y): `(~x =! (~x | ~y))
macro(~x += ~y): `(~x =! (~x + ~y))
macro(~x -= ~y): `(~x =! (~x - ~y))
macro(~x /= ~y): `(~x =! (~x / ~y))
macro(~x ^= ~y): `(~x =! (~x ^ ~y))
macro(~x %= ~y): `(~x =! (~x % ~y))
WithModule = Class new(Atomy AST Node)
WithModule bytecode(g, _) := do:
pos(g)
g push-self
g add-scope
g push-nil
macro(class: ~*body):
`(//Class new open: ~*body, self)
macro(~super class: ~*body):
`(//Class new(~super) open: ~*body, self)
macro(module: ~*body):
`(//Module new open: ~*body, self)
macro(~x open: ~*body):
`(~x module-eval:
~(WithModule new(node line))
~*body)
macro(~x singleton: ~*body):
`(~x singleton-class open: ~*body)
macro(singleton: ~*body):
`(self singleton-class open: ~*body)
Jump to Line
Something went wrong with that request. Please try again.