Skip to content

Commit

Permalink
remove builtins from handle
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Oct 8, 2023
1 parent 04b707c commit e767161
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 27 deletions.
2 changes: 1 addition & 1 deletion eyg/src/easel/embed.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ fn run(state: Embed) {
|> map.insert("Await", effect.await().2)
|> map.insert("Async", browser.async().2)
|> map.insert("Log", effect.debug_logger().2)
let ret = r.handle(r.eval(source, env, None), env.builtins, handlers)
let ret = r.handle(r.eval(source, env, None), handlers)
case ret {
r.Abort(reason, _rev, _env, _k) -> #(reason_to_string(reason), [])
r.Value(term) -> #(term_to_string(term), [])
Expand Down
3 changes: 1 addition & 2 deletions eyg/src/easel/loader.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ fn applet(root) {
let state = javascript.make_reference(arg)
let render = fn() {
let current = javascript.dereference(state)
let result =
r.handle(r.eval_call(func, current, env, None), env, handlers)
let result = r.handle(r.eval_call(func, current, env, None), handlers)
let _ = case result {
r.Value(r.Binary(page)) -> document.set_html(root, page)
_ -> {
Expand Down
10 changes: 4 additions & 6 deletions eyg/src/eyg/runtime/interpreter.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub fn run(source, env, term, extrinsic) {
case
handle(
eval(source, env, Some(Kont(CallWith(term, [], env), None))),
env.builtins,
extrinsic,
)
{
Expand All @@ -48,15 +47,14 @@ pub fn run_async(source, env, term, extrinsic) {
let ret =
handle(
eval(source, env, Some(Kont(CallWith(term, [], env), None))),
env.builtins,
extrinsic,
)
flatten_promise(ret, extrinsic)
}

// not really eval as includes handlers
pub fn eval_async(source, env, extrinsic) {
let ret = handle(eval(source, env, None), env.builtins, extrinsic)
let ret = handle(eval(source, env, None), extrinsic)
flatten_promise(ret, extrinsic)
}

Expand All @@ -75,13 +73,13 @@ pub fn flatten_promise(ret, extrinsic) {
p,
fn(return) {
let next = loop(V(Value(return)), rev, env, k)
flatten_promise(handle(next, env.builtins, extrinsic), extrinsic)
flatten_promise(handle(next, extrinsic), extrinsic)
},
)
}
}

pub fn handle(return, builtins, extrinsic) {
pub fn handle(return, extrinsic) {
case return {
// Don't have stateful handlers because extrinsic handlers can hold references to
// mutable state db files etc
Expand All @@ -91,7 +89,7 @@ pub fn handle(return, builtins, extrinsic) {
// handler only gets env in captured fn's
let #(c, rev, e, k) = handler(term, k)
let return = loop(c, rev, e, k)
handle(return, builtins, extrinsic)
handle(return, extrinsic)
}
Error(Nil) -> Abort(UnhandledEffect(label, term), rev, env, k)
}
Expand Down
2 changes: 0 additions & 2 deletions eyg/src/harness/impl/http.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ pub fn serve() {
env,
Some(r.Kont(r.CallWith(req, rev, env), None)),
),
[],
{
effect.init()
|> effect.extend("Log", effect.debug_logger())
Expand Down Expand Up @@ -129,7 +128,6 @@ pub fn receive() {
env,
Some(r.Kont(r.CallWith(req, rev, env), None)),
),
[],
{
effect.init()
|> effect.extend("Log", effect.debug_logger())
Expand Down
17 changes: 3 additions & 14 deletions eyg/src/platforms/browser.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,7 @@ pub fn async() {
let promise =
promisex.wait(0)
|> promise.await(fn(_: Nil) {
let ret =
r.handle(
r.eval_call(exec, r.unit, env, None),
env.builtins,
extrinsic,
)
let ret = r.handle(r.eval_call(exec, r.unit, env, None), extrinsic)
r.flatten_promise(ret, extrinsic)
})
|> promise.map(fn(result) {
Expand Down Expand Up @@ -212,12 +207,7 @@ fn listen() {
window.add_event_listener(
event,
fn(_) {
let ret =
r.handle(
r.eval_call(handle, r.unit, env, None),
env.builtins,
extrinsic,
)
let ret = r.handle(r.eval_call(handle, r.unit, env, None), extrinsic)
io.debug(ret)
Nil
},
Expand Down Expand Up @@ -269,8 +259,7 @@ fn on_keydown() {
fn do_handle(arg, handle, builtins, extrinsic) {
let assert r.Value(arg) = r.eval(arg, stdlib.env(), None)
// pass as general term to program arg or fn
let ret =
r.handle(r.eval_call(handle, arg, builtins, None), builtins, extrinsic)
let ret = r.handle(r.eval_call(handle, arg, builtins, None), extrinsic)
case ret {
r.Value(_) -> Nil
_ -> {
Expand Down
4 changes: 2 additions & 2 deletions eyg/src/platforms/shell.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn run(source, args) {
Some(r.Kont(r.Apply(r.Defunc(r.Select("prompt"), []), [], env), None)),
))
let assert r.Value(parser) =
r.handle(r.eval(source, env, k_parser), map.new(), handlers().1)
r.handle(r.eval(source, env, k_parser), handlers().1)
let parser = fn(prompt) {
fn(raw) {
let k =
Expand All @@ -81,7 +81,7 @@ pub fn run(source, args) {
Some(r.Kont(r.CallWith(r.Record([]), [], env), None)),
))
let assert r.Abort(r.UnhandledEffect("Prompt", prompt), _rev, env, k) =
r.handle(r.eval(source, env, k), map.new(), handlers().1)
r.handle(r.eval(source, env, k), handlers().1)

let assert r.Binary(prompt) = prompt

Expand Down

0 comments on commit e767161

Please sign in to comment.