Skip to content

Instantly share code, notes, and snippets.

@vito
Created November 3, 2010 01:09
Show Gist options
  • Save vito/660645 to your computer and use it in GitHub Desktop.
Save vito/660645 to your computer and use it in GitHub Desktop.
atomo repl in atomo
_ evaluate-all: [] := error: @no-expressions
t evaluate-all: [e] := e evaluate-in: t
t evaluate-all: (e . es) :=
{ e evaluate-in: t
t evaluate-all: es
} call
(s: String) go: env :=
s parse-expressions match: {
[] -> @ok
es -> env (evaluate-all: es) show print
}
get-value: t :=
read-line parse-expressions match: {
[] -> get-value: t
es -> t evaluate-all: es
}
repl-debugger =
Object clone do:
{ run: e :=
{ Restart show-options-for: e
{ basic-repl } bind: {
@prompt ->
{ "[!]> " display
restart: @muffle-others
} call
@(special: n) ->
{ r = Restart get: (n as: Integer)
r action arguments length match: {
0 -> r jump: []
n -> r jump: (get-n-values: n)
}
} call
}
} call
}
get-n-values: 0 = []
get-n-values: n :=
{ ("enter value (" .. n show .. " to go): ") display
(get-value: sender) . (get-n-values: (n - 1))
} call
(env: Object) basic-repl :=
{ { signal: @prompt } with-restarts: { @muffle-others -> @ok }
in =
{ read-line } handle: {
@end-of-input -> { signal: @quit; "" } call
}
in match: {
':' . name ->
signal: @(special: name)
source ->
{ source go: env } with-restarts: {
@retry -> source go: env
@abort -> @ok
}
}
signal: @loop
} repeat
(env: Object) repl :=
with: current-debugger as: repl-debugger do: {
frame = 0
{ env basic-repl } bind: {
@prompt ->
("[" .. frame show .. "]> ") display
@loop -> (super frame = frame + 1)
@(special: "h") ->
":h\thelp" print
@quit ->
{ ask :=
{ "\nreally quit? (y/n) " display
read-char match: {
'y' -> halt
'n' -> "" print
_ -> ask
}
} call
ask
} call
}
}
Lobby clone repl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment