Skip to content

Commit

Permalink
fix testing in shell
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Oct 12, 2023
1 parent 70a27e6 commit 88796f1
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 7 deletions.
4 changes: 2 additions & 2 deletions eyg/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

packages = [
{ name = "gleam_bitwise", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "E2A46EE42E5E9110DAD67E0F71E7358CBE54D5EC22C526DD48CBBA3223025792" },
{ name = "gleam_fetch", version = "0.2.1", build_tools = ["gleam"], requirements = ["gleam_javascript", "gleam_stdlib", "gleam_http"], otp_app = "gleam_fetch", source = "hex", outer_checksum = "F64E93C754D948B2D37ABC4ADD5482FE0FAED4B99C79E66012DDE96BEDC40544" },
{ name = "gleam_fetch", version = "0.2.1", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_javascript", "gleam_stdlib"], otp_app = "gleam_fetch", source = "hex", outer_checksum = "F64E93C754D948B2D37ABC4ADD5482FE0FAED4B99C79E66012DDE96BEDC40544" },
{ name = "gleam_http", version = "3.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "FAE9AE3EB1CA90C2194615D20FFFD1E28B630E84DACA670B28D959B37BCBB02C" },
{ name = "gleam_javascript", version = "0.6.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "BFEBB63ABE4A1694E07DEFD19B160C2980304B5D775A89D4B02E7DE7C9D8008B" },
{ name = "gleam_json", version = "0.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "C6CC5BEECA525117E97D0905013AB3F8836537455645DDDD10FE31A511B195EF" },
{ name = "gleam_stdlib", version = "0.31.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "6D1BC5B4D4179B9FEE866B1E69FE180AC2CE485AD90047C0B32B2CA984052736" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
{ name = "lustre", version = "3.0.6", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "lustre", source = "hex", outer_checksum = "2D2BEF77B5966773467574C2DC23A27FAB7C720DEF428E72C610DA1547E7E171" },
{ name = "plinth", version = "0.1.3", build_tools = ["gleam"], requirements = ["gleam_javascript", "gleam_stdlib"], source = "local", path = "/Users/petersaxton/src/github.com/crowdhailer/plinth" },
{ name = "plinth", version = "0.1.3", build_tools = ["gleam"], requirements = ["gleam_javascript", "gleam_stdlib"], source = "local", path = "/opt/plinth" },
{ name = "simplifile", version = "0.1.14", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "10EA0207796F20488A3A166C50A189C9385333F3C9FAC187729DE7B9CE4ADDBC" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
]
Expand Down
2 changes: 1 addition & 1 deletion eyg/saved/saved.json

Large diffs are not rendered by default.

95 changes: 92 additions & 3 deletions eyg/src/harness/ffi/core.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import harness/ffi/integer
import harness/ffi/linked_list
import harness/ffi/string
import old_plinth/browser/window
import plinth/javascript/console

pub fn equal() {
let type_ =
Expand Down Expand Up @@ -133,19 +134,22 @@ pub fn lib() {
// list
|> extend("list_pop", linked_list.pop())
|> extend("list_fold", linked_list.fold())
|> extend("eval", eval())
}

pub fn do_eval(source, rev, env, k) {
use source <- cast.require(cast.list(source), rev, env, k)
case language_to_expression(source) {
Ok(expression) -> {
let value =
// must be value otherwise/effect continuations need sorting
let assert r.Value(value) =
r.eval(
expression,
r.Env([], lib().1),
Some(r.Kont(r.Apply(r.Defunc(r.Tag("Ok"), []), rev, env), None)),
)
r.prim(value, rev, env, k)
// console.log(value)
r.prim(r.Value(value), rev, env, k)
}
Error(_) -> r.prim(r.Value(r.error(r.unit)), rev, env, k)
}
Expand Down Expand Up @@ -288,7 +292,92 @@ pub fn expression_to_language(exp) {
}

pub fn language_to_expression(source) {
do_language_to_expression(source, fn(x, _) { Ok(x) })
// This stack overflows on resolving the built up k
// do_language_to_expression(source, fn(x, _) { Ok(x) })
Ok(stack_language_to_expression(source, []))
}

fn stack_language_to_expression(source, stack) {
let [node, ..source] = source
let #(exp, stack) = step(node, stack)
case exp {
Some(exp) ->
case apply(exp, stack) {
Ok(exp) -> {
exp
}
Error(stack) -> stack_language_to_expression(source, stack)
}
None -> stack_language_to_expression(source, stack)
}
}

fn apply(exp, stack) {
case stack {
[] -> Ok(exp)
[DoBody(label), ..stack] -> apply(e.Lambda(label, exp), stack)
[DoFunc, ..stack] -> Error([DoArg(exp), ..stack])
[DoArg(func), ..stack] -> apply(e.Apply(func, exp), stack)
[DoValue(label), ..stack] -> Error([DoThen(label, exp), ..stack])
[DoThen(label, value), ..stack] -> apply(e.Let(label, value, exp), stack)
}
}

type NativeStack {
DoBody(String)
DoFunc
DoArg(e.Expression)
DoValue(String)
DoThen(String, e.Expression)
}

fn step(node, stack) {
case node {
r.Tagged("Variable", r.Str(label)) -> {
#(Some(e.Variable(label)), stack)
}
r.Tagged("Lambda", r.Str(label)) -> {
#(None, [DoBody(label), ..stack])
}
r.Tagged("Apply", r.Record([])) -> {
// use arg, rest <- do_language_to_expression(rest)
#(None, [DoFunc, ..stack])
}
r.Tagged("Let", r.Str(label)) -> {
// use then, rest <- do_language_to_expression(rest)
#(None, [DoValue(label), ..stack])
}

r.Tagged("Integer", r.Integer(value)) -> #(Some(e.Integer(value)), stack)
r.Tagged("String", r.Str(value)) -> #(Some(e.Str(value)), stack)
r.Tagged("Binary", r.Binary(value)) -> #(Some(e.Binary(value)), stack)

r.Tagged("Tail", r.Record([])) -> #(Some(e.Tail), stack)
r.Tagged("Cons", r.Record([])) -> #(Some(e.Cons), stack)

r.Tagged("Vacant", r.Str(comment)) -> #(Some(e.Vacant(comment)), stack)

r.Tagged("Empty", r.Record([])) -> #(Some(e.Empty), stack)
r.Tagged("Extend", r.Str(label)) -> #(Some(e.Extend(label)), stack)
r.Tagged("Select", r.Str(label)) -> #(Some(e.Select(label)), stack)
r.Tagged("Overwrite", r.Str(label)) -> #(Some(e.Overwrite(label)), stack)
r.Tagged("Tag", r.Str(label)) -> #(Some(e.Tag(label)), stack)
r.Tagged("Case", r.Str(label)) -> #(Some(e.Case(label)), stack)
r.Tagged("NoCases", r.Record([])) -> #(Some(e.NoCases), stack)

r.Tagged("Perform", r.Str(label)) -> #(Some(e.Perform(label)), stack)
r.Tagged("Handle", r.Str(label)) -> #(Some(e.Handle(label)), stack)
r.Tagged("Shallow", r.Str(label)) -> #(Some(e.Shallow(label)), stack)
r.Tagged("Builtin", r.Str(identifier)) -> #(
Some(e.Builtin(identifier)),
stack,
)
remaining -> {
io.debug(#("remaining values", remaining, stack))
Error("error debuggin expressions")
panic("bad decodeding")
}
}
}

fn do_language_to_expression(term, k) {
Expand Down
3 changes: 2 additions & 1 deletion eyg/src/harness/stdlib.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import harness/ffi/core

pub fn lib() {
core.lib()
|> extend("eval", core.eval())
// part of core/lib
// |> extend("eval", core.eval())
}

pub fn env() {
Expand Down

0 comments on commit 88796f1

Please sign in to comment.