-
-
Save hansihe/f3def06c5ee992e866f2b91e68a9d604 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"types": { | |
"u8": ["native", { | |
"type": "integer" | |
}], | |
"test": ["container", { | |
"virtual": true, | |
"fields": [ | |
{ | |
"name": "tag", | |
"type": "virtual", | |
"ref": "data", | |
"prop": "tag", | |
"type": "u8" | |
}, | |
{ | |
"name": "data", | |
"type": ["union", { | |
"name": "test_union", | |
"ref": "../tag", | |
"variants": [ | |
{ | |
"name": "zero", | |
"match": "0", | |
"type": "u8" | |
}, | |
{ | |
"name": "one", | |
"match": "1", | |
"type": ["container", { | |
"virtual": false, | |
"fields": [ | |
{ | |
"name": "woo", | |
"type": "u8" | |
}, | |
{ | |
"name": "hoo", | |
"type": "u8" | |
} | |
] | |
}] | |
} | |
] | |
}] | |
} | |
] | |
}] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@type "integer" | |
def_native("u8"); | |
def("test") => container(virtual: "true") { | |
virtual_field("tag", ref: "data", prop: "tag") => u8; | |
field("data") => union("test_union", ref: "../tag") { | |
variant("zero", match: "0") => u8; | |
variant("one", match: "1") => container { | |
field("woo") => u8; | |
field("hoo") => u8; | |
}; | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var type_1_size_of = types["::u8"]["size_of"]; | |
var type_1_serialize = types["::u8"]["serialize"]; | |
var type_1_deserialize = types["::u8"]["deserialize"]; | |
function type_2_size_of(input) { | |
let count = 0; | |
let type_input_0 = input; | |
{ | |
var type_input_1 = type_input_0; | |
switch (type_input_1.tag) { | |
case "zero": { | |
var type_input_1 = 0; | |
break; | |
} | |
case "one": { | |
var type_input_1 = 1; | |
break; | |
} | |
} | |
{ | |
var size = type_1_size_of(type_input_1); | |
count = count + size; | |
} | |
var type_input_2 = type_input_0; | |
{ | |
switch (type_input_2.tag) { | |
case "zero": { | |
var type_input_3 = type_input_2.data; | |
{ | |
var size = type_1_size_of(type_input_3); | |
count = count + size; | |
} | |
break; | |
} | |
case "one": { | |
var type_input_4 = type_input_2.data; | |
{ | |
var type_input_5 = type_input_4["woo"]; | |
{ | |
var size = type_1_size_of(type_input_5); | |
count = count + size; | |
} | |
var type_input_6 = type_input_4["hoo"]; | |
{ | |
var size = type_1_size_of(type_input_6); | |
count = count + size; | |
} | |
} | |
break; | |
} | |
} | |
} | |
} | |
return count; | |
} | |
function type_2_serialize(input, buffer, offset) { | |
let type_input_0 = input; | |
{ | |
var type_input_1 = type_input_0; | |
switch (type_input_1.tag) { | |
case "zero": { | |
var type_input_1 = 0; | |
break; | |
} | |
case "one": { | |
var type_input_1 = 1; | |
break; | |
} | |
} | |
{ | |
var offset = type_1_serialize(type_input_1, buffer, offset); | |
} | |
var type_input_2 = type_input_0; | |
{ | |
switch (type_input_2.tag) { | |
case "zero": { | |
var type_input_3 = type_input_2.data; | |
{ | |
var offset = type_1_serialize(type_input_3, buffer, offset); | |
} | |
break; | |
} | |
case "one": { | |
var type_input_4 = type_input_2.data; | |
{ | |
var type_input_5 = type_input_4["woo"]; | |
{ | |
var offset = type_1_serialize(type_input_5, buffer, offset); | |
} | |
var type_input_6 = type_input_4["hoo"]; | |
{ | |
var offset = type_1_serialize(type_input_6, buffer, offset); | |
} | |
} | |
break; | |
} | |
} | |
} | |
} | |
return offset; | |
} | |
function type_2_deserialize(buffer, offset) { | |
{ | |
{ | |
var [type_output_1, offset] = type_1_deserialize(buffer, offset); | |
} | |
{ | |
switch (type_output_1) { | |
case 0: { | |
{ | |
var [type_output_3, offset] = type_1_deserialize(buffer, offset); | |
} | |
var type_output_2 = { tag: "zero", data: type_output_3 }; | |
break; | |
} | |
case 1: { | |
{ | |
{ | |
var [type_output_5, offset] = type_1_deserialize(buffer, offset); | |
} | |
{ | |
var [type_output_6, offset] = type_1_deserialize(buffer, offset); | |
} | |
var type_output_4 = { woo: type_output_5, hoo: type_output_6 }; | |
} | |
var type_output_2 = { tag: "one", data: type_output_4 }; | |
break; | |
} | |
} | |
} | |
var type_output_0 = type_output_2; | |
} | |
return [type_output_0, offset]; | |
} | |
var exports = { | |
"::u8": {"size_of": type_1_size_of, "serialize": type_1_serialize, "deserialize": type_1_deserialize }, | |
"::test": {"size_of": type_2_size_of, "serialize": type_2_serialize, "deserialize": type_2_deserialize } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment