Permalink
Browse files

use constants for dynvars, use Self for accessing current module

  • Loading branch information...
1 parent 785582b commit 87fe3efb1c8a146c74b7b188d6052e5bc653eb7f @vito committed Dec 25, 2011
Showing with 102 additions and 107 deletions.
  1. +17 −17 kernel/condition.ay
  2. +1 −1 kernel/define.ay
  3. +4 −7 kernel/dynamic.ay
  4. +27 −27 kernel/grammar.ay
  5. +22 −22 kernel/io.ay
  6. +3 −3 kernel/loop.ay
  7. +11 −11 kernel/pretty.ay
  8. +3 −3 kernel/repl.ay
  9. +12 −12 kernel/therie.ay
  10. +2 −4 lib/atomy/util.rb
View
@@ -10,8 +10,8 @@ use("dynamic")
IO = use("io")
-- registered handlers/restarts
-dynamic(handlers, [])
-dynamic(restarts, [])
+Handlers = dynamic([])
+Restarts = dynamic([])
catcher(x) := #"restart:#{Define message-name(x)}"
message-name(x) := Define message-name(x)
@@ -50,45 +50,45 @@ EndOfFile message := "unexpected end-of-file for " + @port show
macro(~body bind { ~*handlers }):
names [a]:
callback = `([~a]: ~a match: ~*handlers)
- `(let(~module handlers = ~callback . ^(~module handlers)):
+ `(let((~Self)::Handlers = ~callback . ^(~Self)::Handlers):
~body rescue:
- (e: StandardError) -> ~module error(e))
+ (e: StandardError) -> ~Self error(e))
macro(with-restarts(~*restarts) ~(block: Block)):
pairs = pairs-from(restarts)
rs = pairs collect [[n, e]]:
- `((~module)::Restart new(
+ `((~Self)::Restart new(
~message-name(n)
[~*arguments(n)] &~block(n) { ~e }
))
body =
pairs reduce(
- `{ ~block rescue: (e: StandardError) -> ~module error(e) }
+ `{ ~block rescue: (e: StandardError) -> ~Self error(e) }
) [x, [name, _]]:
`{ catch(~catcher(name)) ~x }
- `(let(~module restarts = [~*rs] + ^(~module restarts)) ~body)
+ `(let((~Self)::Restarts = [~*rs] + ^(~Self)::Restarts) ~body)
export
restart(name, *args) := do:
- ^restarts each [r]:
+ ^Restarts each [r]:
when(r name == name):
r invoke(*args)
error(NoRestartError new(name))
signal(c) := do:
- hs = ^handlers dup
+ hs = ^Handlers dup
until(hs empty?):
callback = hs shift
- let(handlers = hs):
+ let(Handlers = hs):
callback [c]
nil
@@ -111,8 +111,8 @@ error(x) := do:
signal(e)
- with-output-to(^(IO error-port)):
- ^debugger run(e)
+ with-output-to(^IO::ErrorPort):
+ ^Debugger run(e)
warning(x) :=
@@ -129,7 +129,7 @@ warning(x) :=
signal(w)
- with-output-to(^(IO error-port)):
+ with-output-to(^IO::ErrorPort):
(w name + ": " + w message) println
nil
@@ -145,12 +145,12 @@ DefaultDebugger = class:
"\n" display
define(show-options-for(e)):
- when(^restarts empty?):
+ when(^Restarts empty?):
exit(1)
"\n" display
"restarts:" println
- ^restarts each-with-index [r, i]:
+ ^Restarts each-with-index [r, i]:
(" :" + i to-s + " -> " + r name to-s) println
define(run(e)):
@@ -159,6 +159,6 @@ DefaultDebugger = class:
show-options-for(e)
"!> " display
- ^restarts [gets to-i] invoke
+ ^Restarts [gets to-i] invoke
-dynamic(debugger, DefaultDebugger)
+Debugger = dynamic(DefaultDebugger)
View
@@ -115,7 +115,7 @@ macro(module: ~*body):
macro(~x open: ~*body):
names [mod]:
`(~x module-eval:
- ~(module::WithModule new(node line))
+ ~(WithModule new(node line))
~*body)
macro(~x singleton: ~*body):
View
@@ -5,18 +5,15 @@ use("control-flow")
use("array")
Dynvar = class:
- initialize(@name, @default) := nil
+ initialize(@name, @default = nil) := nil
^Dynvar := Thread current [@name] || @default
Dynvar set(x) := Thread current [@name] = x
-macro(dynamic(~n, ~(root = 'nil))):
+macro(dynamic): `dynamic()
+macro(dynamic(~(root = 'nil))):
names [local]:
- `(do:
- @~n = (~module)::Dynvar new(~(local text), ~root)
-
- singleton:
- attr-reader(#~n))
+ `((~Self)::Dynvar new(~(local text), ~root))
macro(let(~*bindings) { ~*body }):
tmps = bindings zip(names(bindings size))
View
@@ -8,11 +8,11 @@ use("comparison")
require("kpeg")
require("set")
-dynamic(actions)
-dynamic(setups)
-dynamic(vars)
-dynamic(rule)
-dynamic(rule-vars)
+Actions = dynamic
+Setups = dynamic
+Vars = dynamic
+Rule = dynamic
+RuleVars = dynamic
const-name(c: Atomy::AST::Constant) := c name to-s
const-name(c: Atomy::AST::ScopedConstant) := const-name(c parent) + "::" + c name to-s
@@ -48,17 +48,17 @@ process-val(g, `(~a | ~b)) :=
`(~g any(~process-val(g, a), ~process-val(g, b)))
process-val(g, a: `{ ~*bs }) :=
- if(^actions)
+ if(^Actions)
then:
- vars = ^rule-vars to-a
- call = "actions[" + ^actions size to-s + "][" + vars join(", ") + "]"
- ^actions << [a, ^rule-vars to-a]
+ vars = ^RuleVars to-a
+ call = "actions[" + ^Actions size to-s + "][" + vars collect #to-s join(", ") + "]"
+ ^Actions << [a, vars]
`(~g action(~call))
else:
`(~g action({ ~*bs }))
process-val(g, `(<(~x)>)) := do:
- when(^rule-vars): ^rule-vars << "text"
+ when(^RuleVars): ^RuleVars << #text
`(~g collect(~process-val(g, x)))
process-val(g, `(@<(~x)>)) :=
@@ -144,10 +144,10 @@ macro(grammar: ~*body): names [g]:
n match:
`%%{ ~*xs } -> do:
call =
- if(^setups)
+ if(^Setups)
then:
- ^setups << `{ ~*xs }
- "setups[" + (^setups size - 1) to-s + "][]"
+ ^Setups << `{ ~*xs }
+ "setups[" + (^Setups size - 1) to-s + "][]"
else:
`{ ~*xs }
@@ -159,25 +159,25 @@ macro(grammar: ~*body): names [g]:
`(%~name = ~expr) -> do:
-- TODO: fix this, yo
call =
- if(^vars)
+ if(^Vars)
then:
- ^vars << `{ ~*xs }
- "vars[" + (^vars size - 1) to-s + "][]"
+ ^Vars << `{ ~*xs }
+ "vars[" + (^Vars size - 1) to-s + "][]"
else:
`{ ~*xs }
`(~g set-variable(~(name text to-s), call))
`(~(name)(~*args) := ~val) -> do:
- let(rule = name text,
- rule-vars = ::Set new(args to-a collect #text)):
+ let(Rule = name text,
+ RuleVars = ::Set new(args collect #text)):
`(~g set(~(name text to-s)
~process-val(g, val)
~(args collect [x]: x text to-s)))
`(~name := ~val) -> do:
- let(rule = name text,
- rule-vars = ::Set new):
+ let(Rule = name text,
+ RuleVars = ::Set new):
`(~g set(~(name text to-s), ~process-val(g, val)))
_ -> `unknown(~n)
@@ -186,14 +186,14 @@ macro(grammar: ~*body): names [g]:
macro(parser(~name): ~*grammar):
- let(actions = Array[],
- setups = Array[],
- vars = Array[]):
+ let(Actions = Array[],
+ Setups = Array[],
+ Vars = Array[]):
g = `(grammar: ~*grammar) evaluate
- acts = ^actions collect [[a, as]]:
+ acts = ^Actions collect [[action, as]]:
args = as collect [a]: Atomy::AST::Word new(0, a)
- `([~*args] ~a)
+ `([~*args] ~action)
def = Atomy::AST::ParserDefiner new(
node line
@@ -202,8 +202,8 @@ macro(parser(~name): ~*grammar):
`(do:
~name = ::KPeg::CompiledParser class:
- { self } setups := @setups ||= ~^setups
- { self } vars := @vars ||= ~^vars
+ { self } setups := @setups ||= ~^Setups
+ { self } vars := @vars ||= ~^Vars
actions := @actions ||= ~acts
View
@@ -4,69 +4,69 @@ use("control-flow")
use("dynamic")
-dynamic(output-port, $stdout)
-dynamic(input-port, $stdin)
-dynamic(error-port, $stderr)
+OutputPort = dynamic($stdout)
+InputPort = dynamic($stdin)
+ErrorPort = dynamic($stderr)
-x println := x tap: ^output-port puts(x to-s)
-x dump := x tap: ^output-port print(x to-s)
-x write := x tap: ^output-port puts(x show)
+x println := x tap: ^OutputPort puts(x to-s)
+x dump := x tap: ^OutputPort print(x to-s)
+x write := x tap: ^OutputPort puts(x show)
export
with-output-to((filename: String), mode = "w") &action :=
- let(output-port = File open(filename, mode)):
+ let(OutputPort = File open(filename, mode)):
action ensuring:
- ^output-port close
+ ^OutputPort close
with-output-to(io) &action :=
- let(output-port = io):
+ let(OutputPort = io):
action call
with-error-to((filename: String), mode = "w") &action :=
- let(error-port = File open(filename, mode)):
+ let(ErrorPort = File open(filename, mode)):
action ensuring:
- ^error-port close
+ ^ErrorPort close
with-error-to(io) &action :=
- let(error-port = io):
+ let(ErrorPort = io):
action call
read-line(sep = $separator) := do:
- x = ^input-port gets(sep)
+ x = ^InputPort gets(sep)
unless(x):
- error(EndOfFile new(^input-port))
+ error(EndOfFile new(^InputPort))
x
read-lines(sep = $separator) := do:
- x = ^input-port readlines(sep)
+ x = ^InputPort readlines(sep)
unless(x):
- error(EndOfFile new(^input-port))
+ error(EndOfFile new(^InputPort))
x
read-byte := do:
- x = ^input-port getc
+ x = ^InputPort getc
unless(x):
- error(EndOfFile new(^input-port))
+ error(EndOfFile new(^InputPort))
x
read-char := read-byte chr
read(length = nil, buffer = nil) :=
- ^input-port send(#read, length, buffer)
+ ^InputPort send(#read, length, buffer)
with-input-from((filename: String), mode = "r") &action :=
- let(input-port = File open(filename, mode)):
+ let(InputPort = File open(filename, mode)):
action ensuring:
- ^input-port close
+ ^InputPort close
with-input-from(io) &action :=
- let(input-port = io):
+ let(InputPort = io):
action call
View
@@ -4,7 +4,7 @@ use("dynamic")
use("control-flow")
use("meta")
-dynamic(labels, Hash new)
+Tags = dynamic(Hash new)
Atomy::AST open:
Labels = Node class:
@@ -20,7 +20,7 @@ Atomy::AST open:
@tags to-a collect [t]:
tags [t name] = g new-label
- let(labels = tags):
+ let(Tags = tags):
lbls zip(@tags to-a) each [[l, t]]:
l set!
t body compile(g)
@@ -39,7 +39,7 @@ Atomy::AST open:
bytecode(g) := do:
pos(g)
- g goto(^labels fetch(@name))
+ g goto(^Tags fetch(@name))
macro(labels ~(body: Block)):
Oops, something went wrong.

0 comments on commit 87fe3ef

Please sign in to comment.