Skip to content

Commit

Permalink
more serialization and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Feb 21, 2023
1 parent 8356df5 commit e4fddb8
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 19 deletions.
156 changes: 142 additions & 14 deletions eyg/public/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
return identity$1(a);
}

function string$1(data) {
function string$2(data) {
return decode_string(data);
}

Expand Down Expand Up @@ -1060,7 +1060,7 @@
function push_path(error, name) {
let name$1 = from(name);
let decoder = any(
toList$1([string$1, (x) => { return map(int$1(x), to_string$1); }]),
toList$1([string$2, (x) => { return map(int$1(x), to_string$1); }]),
);
let name$2 = (() => {
let $ = decoder(name$1);
Expand Down Expand Up @@ -1479,6 +1479,10 @@
return null
}

function string$1(input) {
return identity(input);
}

function bool(input) {
return identity(input);
}
Expand Down Expand Up @@ -3220,23 +3224,129 @@
);
}

function row_to_list(loop$row, loop$acc) {
while (true) {
let row = loop$row;
let acc = loop$acc;
if (row instanceof Closed) {
return [acc, object(toList([["closed", object(toList([]))]]))];
} else if (row instanceof Open) {
let i = row[0];
return [acc, object(toList([["open", int(i)]]))];
} else if (row instanceof Extend$1) {
let key = row.label;
let value = row.value;
let rest = row.tail;
loop$row = rest;
loop$acc = toList([[key, value]], acc);
} else {
throwError(
"case_no_match",
"atelier/worker/message",
18,
"row_to_list",
"No case clause matched",
{ values: [row] }
);
}
}
}

function encode_row(rows, f) {
let $ = row_to_list(rows, toList([]));
let rows$1 = $[0];
let tail = $[1];
return object(
toList([
[
"rows",
array(
rows$1,
(pair) => {
let label = pair[0];
let value = pair[1];
return object(
toList([["label", string$1(label)], ["value", f(value)]]),
);
},
),
],
["tail", tail],
]),
);
}

function encode_infered(inferred) {
if (!(inferred instanceof Infered)) {
throwError(
"assignment_no_match",
"atelier/worker/message",
17,
56,
"encode_infered",
"Assignment pattern did not match",
{ value: inferred }
);
}
inferred.substitutions;
let substitutions = inferred.substitutions;
let types = inferred.types;
inferred.environments;
return object(
toList([
["substitutions", null$()],
[
"substitutions",
object(
toList([
[
"terms",
array(
to_list$1(substitutions.terms),
(entry) => {
let var$ = entry[0];
let type_ = entry[1];
return object(
toList([
["var", int(var$)],
["term", encode_type(type_)],
]),
);
},
),
],
[
"rows",
array(
to_list$1(substitutions.rows),
(entry) => {
let var$ = entry[0];
let row = entry[1];
return object(
toList([
["var", int(var$)],
["term", encode_row(row, encode_type)],
]),
);
},
),
],
[
"effects",
array(
to_list$1(substitutions.effects),
(entry) => {
let var$ = entry[0];
let effect = entry[1];
return object(
toList([
["var", int(var$)],
["term", encode_row(effect, encode_pair)],
]),
);
},
),
],
]),
),
],
[
"types",
array(
Expand All @@ -3258,7 +3368,7 @@
throwError(
"case_no_match",
"atelier/worker/message",
28,
110,
"",
"No case clause matched",
{ values: [typed] }
Expand Down Expand Up @@ -3291,23 +3401,29 @@
return ["list", encode_type(type_$1)];
} else if (type_ instanceof Fun) {
let from = type_[0];
type_[1];
let effects = type_[1];
let to = type_[2];
return [
"fun",
object(
toList([["from", encode_type(from)], ["to", encode_type(to)]]),
toList([
["from", encode_type(from)],
["effects", encode_effects(effects)],
["to", encode_type(to)],
]),
),
];
} else if (type_ instanceof Record$1) {
return ["unbound", int(-100_000)];
let row = type_[0];
return ["record", encode_row(row, encode_type)];
} else if (type_ instanceof Union) {
return ["unbound", int(-100_000)];
let row = type_[0];
return ["union", encode_row(row, encode_type)];
} else {
throwError(
"case_no_match",
"atelier/worker/message",
42,
124,
"encode_type",
"No case clause matched",
{ values: [type_] }
Expand All @@ -3318,6 +3434,18 @@
);
}

function encode_effects(rows) {
return encode_row(rows, encode_pair);
}

function encode_pair(value) {
let lift = value[0];
let reply = value[1];
return object(
toList([["lift", encode_type(lift)], ["reply", encode_type(reply)]]),
);
}

class NotAFunction extends CustomType {
constructor(x0) {
super();
Expand Down Expand Up @@ -4595,11 +4723,11 @@
}

function label() {
return field$1("label", string$1);
return field$1("label", string$2);
}

function decoder(x) {
let $ = field$1("node", string$1)(x);
let $ = field$1("node", string$2)(x);
if (!$.isOk()) return $;
let node = $[0];

Expand Down Expand Up @@ -4633,7 +4761,7 @@
} else if (node === "binary") {
return decode1(
(var0) => { return new Binary$1(var0); },
field$1("value", string$1),
field$1("value", string$2),
);
} else if (node === "tail") {
return (_) => { return new Ok(new Tail()); };
Expand Down
19 changes: 14 additions & 5 deletions eyg/src/atelier/worker/message.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,22 @@ pub fn decode_inferred(data) {
dynamic.field(
"terms",
fn(x) {
dynamic.list(dynamic.decode2(
fn(a, b) { #(a, b) },
dynamic.field("var", dynamic.int),
dynamic.field("term", type_decoder),
))(
// io.debug(x)
dynamic.list(fn(x) {
dynamic.decode2(
fn(a, b) { #(a, b) },
// |> io.debug
dynamic.field("var", dynamic.int),
dynamic.field("term", type_decoder),
)(
x
|> io.debug,
)
|> io.debug
})(
x,
)
|> io.debug
|> result.map(map.from_list)
},
),
Expand Down

0 comments on commit e4fddb8

Please sign in to comment.