Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Oct 10, 2022
1 parent bc2d65e commit afa7394
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 53 deletions.
1 change: 0 additions & 1 deletion eyg/src/eyg/ast/encode.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ pub fn from_json(json: JSON) {
ast.variable(assert_string(label))
}
"Let" -> {

let [#("pattern", pattern), #("value", value), #("then", then)] = rest
let pattern = pattern_from_json(pattern)
let value = from_json(value)
Expand Down
3 changes: 1 addition & 2 deletions eyg/src/eyg/codegen/javascript.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ pub fn escape_string(raw) {
|> string.replace("\\", "\\\\")
|> string.replace("'", "\\'")
|> string.replace("\"", "\\\"")

// Not js but browser
// Not js but browser
|> string.replace("<", "\\<")
|> string.replace(">", "\\>")
}
Expand Down
41 changes: 20 additions & 21 deletions eyg/src/eyg/entry.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,34 @@ import eyg/typer
import eyg/typer/monotype as t
import eyg/editor/editor

fn update(page, interrupt, display, on_click) {
io.debug(page)
display(page)
fn update(page, interrupt, display, on_click) {
io.debug(page)
display(page)
}

}
fn b(args) {
Ok(r.Binary("done"))
}


fn b(args) {
Ok(r.Binary("done"))
}
// uses default builtin that need moving out of effectful
// has an entry point key should eventually be a hash
// maybe rename interpret standard
// builtin is always the same but env things are passed in
// All the runtime stuff is in gleam terms
// TODO are there any gleam helpers to turn tuples into things
pub fn interpret_client(source, key, display, on_click) {
io.debug("hooo")
let init = e.access(e.access(source, key), "init")
io.debug(init)
io.debug("hooo")
let init = e.access(e.access(source, key), "init")
io.debug(init)
let #(typed, typer) = analysis.infer(init, t.Unbound(-1), [])
io.debug("---- typed")
let #(xtyped, typer) = typer.expand_providers(typed, typer, [])
// assert Ok(term) = effectful.eval(editor.untype(xtyped))
// io.debug(term)
|> io.debug
// effectful.eval_call(r.BuiltinFn(b), term, effectful.real_log)
// |> io.debug
// // TODO make an AST the requires rendering
// term
}
let #(xtyped, typer) =
typer.expand_providers(typed, typer, [])
// assert Ok(term) = effectful.eval(editor.untype(xtyped))
// io.debug(term)
|> io.debug
// effectful.eval_call(r.BuiltinFn(b), term, effectful.real_log)
// |> io.debug
// // TODO make an AST the requires rendering
// term
}
27 changes: 13 additions & 14 deletions eyg/src/eyg/interpreter/effectful.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,26 @@ fn term_serialize(term) {
// TODO does with work can we have outside poller
on_code: (f) => { document.oncode = f }
});",
// This didn't work because of rendering captured variables for a fn within some scope.
// We need a whole review of rendering or use interpreter
// "(({init}) => {
// console.log(init, 'initial state')
// const update = ({page, interrupt}) => {
// document.body.innerHTML = page
// document.onclick = () => update(interrupt({Click: 'key'}))
// document.oncode = (code) => update(interrupt({Code: code}))
// TODO this needs the codegen part of loader
// }
// update(init)
// // TODO set interval
// })"
)
// This didn't work because of rendering captured variables for a fn within some scope.
// We need a whole review of rendering or use interpreter
// "(({init}) => {
// console.log(init, 'initial state')
// const update = ({page, interrupt}) => {
// document.body.innerHTML = page
// document.onclick = () => update(interrupt({Click: 'key'}))
// document.oncode = (code) => update(interrupt({Code: code}))
// TODO this needs the codegen part of loader
// }
// update(init)
// // TODO set interval
// })"
let page =
string.concat(["<head></head><body></body><script>", program, "</script>"])
// assert r.Function() = term
Ok(r.Binary(page))
}


fn env() {
map.new()
|> map.insert("do", r.BuiltinFn(do))
Expand Down
13 changes: 7 additions & 6 deletions eyg/src/eyg/interpreter/interpreter.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import eyg/analysis
import eyg/typer
import eyg/typer/monotype as t


pub type Object {
Binary(String)
Pid(Int)
Expand Down Expand Up @@ -119,12 +118,14 @@ pub fn render_object(object) {
// Builtins should never be included, I need to check variables used in a previous step
// Function(_,_,_,_) -> todo("this needs compile again but I need a way to do this without another type check")
Function(pattern, body, captured, _) -> {
// TODO this needs to render captured to be useful
let #(typed, typer) = analysis.infer(e.function(pattern, body), t.Unbound(-1), [])
let #(typed, typer) = typer.expand_providers(typed, typer, [])
javascript.render_to_string(typed, typer)
// TODO this needs to render captured to be useful
let #(typed, typer) =
analysis.infer(e.function(pattern, body), t.Unbound(-1), [])
let #(typed, typer) = typer.expand_providers(typed, typer, [])
javascript.render_to_string(typed, typer)
}
BuiltinFn(_) -> "null /* we aren't using builtin here should be part of env */"
BuiltinFn(_) ->
"null /* we aren't using builtin here should be part of env */"
// TODO remove Coroutine/ready there where and old experiment
Coroutine(_) -> "null"
Ready(_, _) -> "null"
Expand Down
11 changes: 9 additions & 2 deletions eyg/src/eyg/typer/monotype.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ pub fn literal(monotype) {
// need to add effects
string.concat(["new T.Function(", literal(from), ",", literal(to), ")"])
Unbound(i) -> string.concat(["new T.Unbound(", int.to_string(i), ")"])
Recursive(i, rest) -> string.concat(["new T.Recursive(", int.to_string(i), ", ", literal(rest), ")"])
Native(_, _) -> {
Recursive(i, rest) ->
string.concat([
"new T.Recursive(",
int.to_string(i),
", ",
literal(rest),
")",
])
Native(_, _) -> {
io.debug(monotype)
todo("ss literal")
}
Expand Down
14 changes: 7 additions & 7 deletions eyg/src/platform/browser.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ fn builtins() {
)
|> add_field("serialize", t.Function(t.Unbound(0), t.Binary, t.empty))
|> add_field(
"compile",
t.Function(
t.Tuple([t.Binary, t.Binary]),
t.Union([#("OK", t.Unbound(0)), #("Error", t.Binary)], Some(1)),
t.empty,
),
)
"compile",
t.Function(
t.Tuple([t.Binary, t.Binary]),
t.Union([#("OK", t.Unbound(0)), #("Error", t.Binary)], Some(1)),
t.empty,
),
)
}

fn add_field(state, key, type_) {
Expand Down

0 comments on commit afa7394

Please sign in to comment.