Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
125 lines (97 sloc) 2.73 KB
use("core")
use("define")
use("comparison")
use("control-flow")
use("meta")
use("interpolation")
use("node")
use("patterns")
Atomy Patterns open:
NamedRedirectedInstance = NamedInstance class:
attributes(.target, .identifier)
construct(g, mod) := do:
get(g)
@target construct(g, mod)
g push-literal(@identifier)
g send(.new, 2)
g push-cpath-top
g find-const(.Atomy)
g send(.current_module, 0)
g send(.in_context, 1)
deconstruct(g, mod, locals = {}) := do:
mod compile(g, @target)
g swap
g push-literal(name)
g swap
g send(.instance-variable-set, 2)
g pop
NamedRedirectedClass = NamedClass class:
attributes(.target, .identifier)
construct(g, mod) := do:
get(g)
@target construct(g, mod)
g push-literal(@identifier)
g send(.new, 2)
g push-cpath-top
g find-const(.Atomy)
g send(.current_module, 0)
g send(.in_context, 1)
deconstruct(g, mod, locals = {}) := do:
have-class = g new-label
mod compile(g, @target)
g dup
g push-cpath-top
g find-const(.Class)
g kind-of
g git(have-class)
g send(.class, 0)
have-class set!
g swap
g push-literal(name)
g swap
g send(.class-variable-set, 2)
g pop
Atomy AST open:
ast:
RedirectedInstanceVariable(.target, @name)
RedirectedClassVariable(.target, @name)
RedirectedInstanceVariable bytecode(g, mod) := do:
pos(g)
mod compile(g, @target)
g push-literal(."@#{@name}")
g send(.instance-variable-get, 1)
RedirectedClassVariable bytecode(g, mod) := do:
pos(g)
have-class = g new-label
mod compile(g, @target)
g dup
g push-cpath-top
g find-const(.Class)
g kind-of
g git(have-class)
g send(.class, 0)
have-class set!
g push-literal(."@@#{@name}")
g send(.class-variable-get, 1)
pattern(ri: Atomy AST RedirectedInstanceVariable):
Atomy Patterns NamedRedirectedInstance new(node target, node name)
pattern(rc: Atomy AST RedirectedClassVariable):
Atomy Patterns NamedRedirectedClass new(node target, node name)
macro(~x onto ~(b: Block)):
names [val]:
`(do:
~val = self
let-macro(self = '~val):
{ with-variables-of(~val) ~b
} block call-on-instance(~x))
macro(with-variables-of(~x) ~(b: Block)):
names [val]:
body = b contents collect [c]:
c through-quotes([n]: n match: `@~_ -> true) [n]:
n match:
`@@~(name ? to-word) ->
RedirectedClassVariable new(n line, val, name to-word text)
`@~(name ? to-word) ->
RedirectedInstanceVariable new(n line, val, name to-word text)
_ -> n
`(do: ~val = ~x, ~*body)
Jump to Line
Something went wrong with that request. Please try again.