rm TotallyNotJson

TotallyNotJson.roc now lives on the farm in virtual-dom-wip as Json.roc.
Any reference in stdlib or builtins has been removed, as well as the
last places it was used (in python/ruby-interop examples).
This commit is contained in:
shua 2024-06-28 15:23:48 +02:00
parent 67f555feea
commit d90da3af52
No known key found for this signature in database
GPG Key ID: 73387DA37055770F
37 changed files with 114 additions and 144 deletions

View File

@ -10,6 +10,5 @@ package [
Encode,
Hash,
Box,
TotallyNotJson,
Inspect,
] {}

View File

@ -16,7 +16,6 @@ pub fn module_source(module_id: ModuleId) -> &'static str {
ModuleId::DECODE => DECODE,
ModuleId::HASH => HASH,
ModuleId::INSPECT => INSPECT,
ModuleId::JSON => JSON,
_ => internal_error!(
"ModuleId {:?} is not part of the standard library",
module_id
@ -36,4 +35,3 @@ const ENCODE: &str = include_str!("../roc/Encode.roc");
const DECODE: &str = include_str!("../roc/Decode.roc");
const HASH: &str = include_str!("../roc/Hash.roc");
const INSPECT: &str = include_str!("../roc/Inspect.roc");
const JSON: &str = include_str!("../roc/TotallyNotJson.roc");

View File

@ -25,7 +25,6 @@ const MODULES: &[(ModuleId, &str)] = &[
(ModuleId::DECODE, "Decode.roc"),
(ModuleId::HASH, "Hash.roc"),
(ModuleId::INSPECT, "Inspect.roc"),
(ModuleId::JSON, "TotallyNotJson.roc"),
];
fn main() {

View File

@ -3630,7 +3630,6 @@ fn load_module<'a>(
"Decode", ModuleId::DECODE
"Hash", ModuleId::HASH
"Inspect", ModuleId::INSPECT
"TotallyNotJson", ModuleId::JSON
}
let (filename, opt_shorthand) = module_name_to_path(src_dir, &module_name, arc_shorthands);

View File

@ -25,5 +25,4 @@ pub const BUILTIN_MODULES: &[(ModuleId, &str)] = &[
(ModuleId::DECODE, "Decode"),
(ModuleId::HASH, "Hash"),
(ModuleId::INSPECT, "Inspect"),
(ModuleId::JSON, "TotallyNotJson"),
];

View File

@ -91,7 +91,6 @@ impl Default for ModuleCache<'_> {
DECODE,
HASH,
INSPECT,
JSON,
}
Self {

View File

@ -131,7 +131,6 @@ impl ModuleName {
pub const HASH: &'static str = "Hash";
pub const INSPECT: &'static str = "Inspect";
pub const TASK: &'static str = "Task";
pub const JSON: &'static str = "TotallyNotJson";
pub fn as_str(&self) -> &str {
self.0.as_str()

View File

@ -395,8 +395,7 @@ impl ModuleId {
}
pub fn is_automatically_imported(self) -> bool {
// The deprecated TotallyNotJson module is not automatically imported.
self.is_builtin() && self != ModuleId::JSON
self.is_builtin()
}
}
@ -1738,15 +1737,6 @@ define_builtins! {
32 INSPECT_TO_INSPECTOR: "toInspector"
33 INSPECT_TO_STR: "toStr"
}
15 JSON: "TotallyNotJson" => {
0 JSON_JSON: "TotallyNotJson"
1 JSON_FIELD_NAME_MAPPING: "FieldNameMapping"
2 JSON_NUMBER_STATE: "NumberState"
3 JSON_STRING_STATE: "StringState"
4 JSON_ARRAY_OPENING_STATE: "ArrayOpeningState"
5 JSON_ARRAY_CLOSING_STATE: "ArrayClosingState"
6 JSON_OBJECT_STATE: "ObjectState"
}
num_modules: 16 // Keep this count up to date by hand! (TODO: see the mut_map! macro for how we could determine this count correctly in the macro)
num_modules: 15 // Keep this count up to date by hand! (TODO: see the mut_map! macro for how we could determine this count correctly in the macro)
}

View File

@ -12,7 +12,7 @@ procedure List.66 (#Attr.2, #Attr.3):
let List.584 : [] = lowlevel ListGetUnsafe #Attr.2 #Attr.3;
ret List.584;
procedure List.92 (#Derived_gen.13, #Derived_gen.14, #Derived_gen.15, #Derived_gen.16, #Derived_gen.17):
procedure List.92 (#Derived_gen.11, #Derived_gen.12, #Derived_gen.13, #Derived_gen.14, #Derived_gen.15):
joinpoint List.577 List.163 List.164 List.165 List.166 List.167:
let List.579 : Int1 = CallByName Num.22 List.166 List.167;
if List.579 then
@ -25,7 +25,7 @@ procedure List.92 (#Derived_gen.13, #Derived_gen.14, #Derived_gen.15, #Derived_g
dec List.163;
ret List.164;
in
jump List.577 #Derived_gen.13 #Derived_gen.14 #Derived_gen.15 #Derived_gen.16 #Derived_gen.17;
jump List.577 #Derived_gen.11 #Derived_gen.12 #Derived_gen.13 #Derived_gen.14 #Derived_gen.15;
procedure Num.22 (#Attr.2, #Attr.3):
let Num.280 : Int1 = lowlevel NumLt #Attr.2 #Attr.3;
@ -37,8 +37,8 @@ procedure Num.51 (#Attr.2, #Attr.3):
procedure Test.10 (Test.69, #Attr.12):
let Test.72 : {} = UnionAtIndex (Id 0) (Index 0) #Attr.12;
let #Derived_gen.20 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.20 then
let #Derived_gen.18 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.18 then
free #Attr.12;
ret Test.72;
else
@ -52,7 +52,7 @@ procedure Test.10 (Test.69, #Attr.12):
procedure Test.14 (Test.45, #Attr.12):
let Test.55 : {{}, []} = UnionAtIndex (Id 1) (Index 1) #Attr.12;
let Test.54 : [<r>C {}, C *self {{}, []}] = UnionAtIndex (Id 1) (Index 0) #Attr.12;
joinpoint #Derived_gen.18:
joinpoint #Derived_gen.19:
let Test.50 : {} = Struct {};
let Test.51 : U8 = GetTagId Test.54;
joinpoint Test.52 Test.15:
@ -79,14 +79,14 @@ procedure Test.14 (Test.45, #Attr.12):
jump Test.52 Test.53;
in
let #Derived_gen.19 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.19 then
let #Derived_gen.20 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.20 then
free #Attr.12;
jump #Derived_gen.18;
jump #Derived_gen.19;
else
inc Test.54;
decref #Attr.12;
jump #Derived_gen.18;
jump #Derived_gen.19;
procedure Test.20 (Test.21, Test.18):
let Test.23 : [C {}, C []] = CallByName Test.32 Test.21 Test.18;

View File

@ -46,11 +46,11 @@ procedure Str.3 (#Attr.2, #Attr.3):
procedure Test.1 (Test.5):
ret Test.5;
procedure Test.11 (#Derived_gen.3, #Derived_gen.4):
procedure Test.11 (#Derived_gen.10, #Derived_gen.11):
joinpoint Test.27 Test.12 #Attr.12:
let Test.34 : Int1 = UnionAtIndex (Id 2) (Index 1) #Attr.12;
let Test.33 : [<rnw><null>, C *self Int1, C *self Int1] = UnionAtIndex (Id 2) (Index 0) #Attr.12;
joinpoint #Derived_gen.12:
joinpoint #Derived_gen.14:
joinpoint Test.31 Test.29:
let Test.30 : U8 = GetTagId Test.33;
switch Test.30:
@ -77,16 +77,16 @@ procedure Test.11 (#Derived_gen.3, #Derived_gen.4):
jump Test.31 Test.32;
in
let #Derived_gen.13 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.13 then
let #Derived_gen.15 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.15 then
free #Attr.12;
jump #Derived_gen.12;
jump #Derived_gen.14;
else
inc Test.33;
decref #Attr.12;
jump #Derived_gen.12;
jump #Derived_gen.14;
in
jump Test.27 #Derived_gen.3 #Derived_gen.4;
jump Test.27 #Derived_gen.10 #Derived_gen.11;
procedure Test.2 (Test.13):
ret Test.13;
@ -117,7 +117,7 @@ procedure Test.6 (Test.7, Test.8, Test.5):
procedure Test.9 (Test.10, #Attr.12):
let Test.43 : Int1 = UnionAtIndex (Id 1) (Index 1) #Attr.12;
let Test.42 : [<rnw><null>, C *self Int1, C *self Int1] = UnionAtIndex (Id 1) (Index 0) #Attr.12;
joinpoint #Derived_gen.14:
joinpoint #Derived_gen.12:
let Test.39 : U8 = GetTagId Test.42;
joinpoint Test.40 Test.38:
switch Test.43:
@ -145,14 +145,14 @@ procedure Test.9 (Test.10, #Attr.12):
jump Test.40 Test.41;
in
let #Derived_gen.15 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.15 then
let #Derived_gen.13 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.13 then
free #Attr.12;
jump #Derived_gen.14;
jump #Derived_gen.12;
else
inc Test.42;
decref #Attr.12;
jump #Derived_gen.14;
jump #Derived_gen.12;
procedure Test.0 ():
let Test.45 : Int1 = false;

View File

@ -111,7 +111,7 @@ procedure List.8 (#Attr.2, #Attr.3):
let List.624 : List U8 = lowlevel ListConcat #Attr.2 #Attr.3;
ret List.624;
procedure List.92 (#Derived_gen.32, #Derived_gen.33, #Derived_gen.34, #Derived_gen.35, #Derived_gen.36):
procedure List.92 (#Derived_gen.29, #Derived_gen.30, #Derived_gen.31, #Derived_gen.32, #Derived_gen.33):
joinpoint List.603 List.163 List.164 List.165 List.166 List.167:
let List.605 : Int1 = CallByName Num.22 List.166 List.167;
if List.605 then
@ -125,7 +125,7 @@ procedure List.92 (#Derived_gen.32, #Derived_gen.33, #Derived_gen.34, #Derived_g
dec List.163;
ret List.164;
in
jump List.603 #Derived_gen.32 #Derived_gen.33 #Derived_gen.34 #Derived_gen.35 #Derived_gen.36;
jump List.603 #Derived_gen.29 #Derived_gen.30 #Derived_gen.31 #Derived_gen.32 #Derived_gen.33;
procedure List.92 (#Derived_gen.37, #Derived_gen.38, #Derived_gen.39, #Derived_gen.40, #Derived_gen.41):
joinpoint List.577 List.163 List.164 List.165 List.166 List.167:

View File

@ -70,7 +70,7 @@ procedure List.8 (#Attr.2, #Attr.3):
let List.598 : List U8 = lowlevel ListConcat #Attr.2 #Attr.3;
ret List.598;
procedure List.92 (#Derived_gen.10, #Derived_gen.11, #Derived_gen.12, #Derived_gen.13, #Derived_gen.14):
procedure List.92 (#Derived_gen.13, #Derived_gen.14, #Derived_gen.15, #Derived_gen.16, #Derived_gen.17):
joinpoint List.577 List.163 List.164 List.165 List.166 List.167:
let List.579 : Int1 = CallByName Num.22 List.166 List.167;
if List.579 then
@ -84,7 +84,7 @@ procedure List.92 (#Derived_gen.10, #Derived_gen.11, #Derived_gen.12, #Derived_g
dec List.163;
ret List.164;
in
jump List.577 #Derived_gen.10 #Derived_gen.11 #Derived_gen.12 #Derived_gen.13 #Derived_gen.14;
jump List.577 #Derived_gen.13 #Derived_gen.14 #Derived_gen.15 #Derived_gen.16 #Derived_gen.17;
procedure Num.127 (#Attr.2):
let Num.280 : U8 = lowlevel NumIntCast #Attr.2;

View File

@ -77,7 +77,7 @@ procedure List.8 (#Attr.2, #Attr.3):
let List.598 : List U8 = lowlevel ListConcat #Attr.2 #Attr.3;
ret List.598;
procedure List.92 (#Derived_gen.14, #Derived_gen.15, #Derived_gen.16, #Derived_gen.17, #Derived_gen.18):
procedure List.92 (#Derived_gen.17, #Derived_gen.18, #Derived_gen.19, #Derived_gen.20, #Derived_gen.21):
joinpoint List.577 List.163 List.164 List.165 List.166 List.167:
let List.579 : Int1 = CallByName Num.22 List.166 List.167;
if List.579 then
@ -91,7 +91,7 @@ procedure List.92 (#Derived_gen.14, #Derived_gen.15, #Derived_gen.16, #Derived_g
dec List.163;
ret List.164;
in
jump List.577 #Derived_gen.14 #Derived_gen.15 #Derived_gen.16 #Derived_gen.17 #Derived_gen.18;
jump List.577 #Derived_gen.17 #Derived_gen.18 #Derived_gen.19 #Derived_gen.20 #Derived_gen.21;
procedure Num.127 (#Attr.2):
let Num.280 : U8 = lowlevel NumIntCast #Attr.2;

View File

@ -76,7 +76,7 @@ procedure List.8 (#Attr.2, #Attr.3):
let List.598 : List U8 = lowlevel ListConcat #Attr.2 #Attr.3;
ret List.598;
procedure List.92 (#Derived_gen.16, #Derived_gen.17, #Derived_gen.18, #Derived_gen.19, #Derived_gen.20):
procedure List.92 (#Derived_gen.13, #Derived_gen.14, #Derived_gen.15, #Derived_gen.16, #Derived_gen.17):
joinpoint List.577 List.163 List.164 List.165 List.166 List.167:
let List.579 : Int1 = CallByName Num.22 List.166 List.167;
if List.579 then
@ -90,7 +90,7 @@ procedure List.92 (#Derived_gen.16, #Derived_gen.17, #Derived_gen.18, #Derived_g
dec List.163;
ret List.164;
in
jump List.577 #Derived_gen.16 #Derived_gen.17 #Derived_gen.18 #Derived_gen.19 #Derived_gen.20;
jump List.577 #Derived_gen.13 #Derived_gen.14 #Derived_gen.15 #Derived_gen.16 #Derived_gen.17;
procedure Num.127 (#Attr.2):
let Num.280 : U8 = lowlevel NumIntCast #Attr.2;

View File

@ -17,7 +17,7 @@ procedure Test.4 (Test.5, #Attr.12):
let Test.16 : I64 = CallByName Num.19 Test.5 Test.17;
ret Test.16;
procedure Test.0 (#Derived_gen.2):
procedure Test.0 (#Derived_gen.0):
joinpoint Test.7 Test.1:
let Test.21 : I64 = 1i64;
let Test.9 : I64 = CallByName Num.19 Test.1 Test.21;
@ -33,4 +33,4 @@ procedure Test.0 (#Derived_gen.2):
ret Test.8;
in
jump Test.7 #Derived_gen.2;
jump Test.7 #Derived_gen.0;

View File

@ -90,8 +90,8 @@ procedure Test.19 ():
let Test.120 : [C Str, C {List U8, I64}] = TagId(0) Test.122;
ret Test.120;
else
dec Test.93;
dec Test.92;
dec Test.93;
let Test.128 : Str = "not a number";
let Test.126 : [C Str, C {List U8, I64}] = TagId(0) Test.128;
ret Test.126;

View File

@ -57,8 +57,8 @@ procedure Test.0 ():
else
let Test.22 : Str = "B";
let Test.23 : Int1 = lowlevel Eq Test.22 Test.12;
dec Test.12;
dec Test.22;
dec Test.12;
if Test.23 then
let Test.17 : [C U8, C U8, C ] = TagId(1) Test.2;
jump Test.13 Test.17;

View File

@ -20,9 +20,9 @@ procedure Test.0 ():
if Test.13 then
let Test.6 : {I64, Str} = CallByName Test.1;
let Test.5 : Int1 = CallByName Bool.11 Test.6 Test.4;
dec Test.6;
let #Derived_gen.0 : Str = StructAtIndex 1 Test.4;
dec #Derived_gen.0;
dec Test.6;
ret Test.5;
else
let #Derived_gen.1 : Str = StructAtIndex 1 Test.4;

View File

@ -6,10 +6,10 @@ procedure List.5 (#Attr.2, #Attr.3):
procedure Test.2 (Test.5):
let Test.6 : List [<rnnu>C List *self] = UnionAtIndex (Id 0) (Index 0) Test.5;
inc Test.6;
let #Derived_gen.1 : [<rnnu>C List *self] = Reset { symbol: Test.5, id: UpdateModeId { id: 0 } };
let #Derived_gen.2 : [<rnnu>C List *self] = Reset { symbol: Test.5, id: UpdateModeId { id: 1 } };
let Test.15 : {} = Struct {};
let Test.7 : List [<rnnu>C List *self] = CallByName List.5 Test.6 Test.15;
let Test.14 : [<rnnu>C List *self] = Reuse #Derived_gen.1 UpdateModeId { id: 0 } TagId(0) Test.7;
let Test.14 : [<rnnu>C List *self] = Reuse #Derived_gen.2 UpdateModeId { id: 1 } TagId(0) Test.7;
ret Test.14;
procedure Test.0 ():

View File

@ -10,7 +10,7 @@ procedure Num.21 (#Attr.2, #Attr.3):
let Num.279 : U8 = lowlevel NumMul #Attr.2 #Attr.3;
ret Num.279;
procedure Test.1 (#Derived_gen.2, #Derived_gen.3):
procedure Test.1 (#Derived_gen.0, #Derived_gen.1):
joinpoint Test.11 Test.2 Test.3:
let Test.26 : U8 = 0i64;
let Test.22 : Int1 = CallByName Bool.11 Test.2 Test.26;
@ -33,9 +33,9 @@ procedure Test.1 (#Derived_gen.2, #Derived_gen.3):
let Test.14 : [<rnu><null>, C *self U8] = TagId(0) Test.3 Test.2;
jump Test.11 Test.13 Test.14;
in
jump Test.11 #Derived_gen.2 #Derived_gen.3;
jump Test.11 #Derived_gen.0 #Derived_gen.1;
procedure Test.4 (#Derived_gen.0, #Derived_gen.1):
procedure Test.4 (#Derived_gen.2, #Derived_gen.3):
joinpoint Test.15 Test.5 #Attr.12:
let Test.20 : U8 = UnionAtIndex (Id 0) (Index 1) #Attr.12;
let Test.19 : [<rnu><null>, C *self U8] = UnionAtIndex (Id 0) (Index 0) #Attr.12;
@ -61,7 +61,7 @@ procedure Test.4 (#Derived_gen.0, #Derived_gen.1):
decref #Attr.12;
jump #Derived_gen.4;
in
jump Test.15 #Derived_gen.0 #Derived_gen.1;
jump Test.15 #Derived_gen.2 #Derived_gen.3;
procedure Test.6 (Test.7):
ret Test.7;

View File

@ -8,8 +8,8 @@ procedure Str.3 (#Attr.2, #Attr.3):
procedure Test.11 (Test.29, #Attr.12):
let Test.32 : {} = UnionAtIndex (Id 0) (Index 0) #Attr.12;
let #Derived_gen.11 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.11 then
let #Derived_gen.9 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.9 then
free #Attr.12;
ret Test.32;
else
@ -19,11 +19,11 @@ procedure Test.11 (Test.29, #Attr.12):
procedure Test.11 (Test.29, Test.10):
ret Test.10;
procedure Test.14 (#Derived_gen.0, #Derived_gen.1):
procedure Test.14 (#Derived_gen.7, #Derived_gen.8):
joinpoint Test.38 Test.37 #Attr.12:
let Test.46 : {} = UnionAtIndex (Id 1) (Index 1) #Attr.12;
let Test.45 : I64 = UnionAtIndex (Id 1) (Index 0) #Attr.12;
joinpoint #Derived_gen.9:
joinpoint #Derived_gen.10:
let Test.44 : {} = Struct {};
let Test.43 : {} = CallByName Test.11 Test.44 Test.46;
let Test.39 : [<r>C {}, C I64 {}] = CallByName Test.9 Test.43 Test.45;
@ -38,15 +38,15 @@ procedure Test.14 (#Derived_gen.0, #Derived_gen.1):
jump Test.38 Test.41 Test.39;
in
let #Derived_gen.10 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.10 then
let #Derived_gen.11 : Int1 = lowlevel RefCountIsUnique #Attr.12;
if #Derived_gen.11 then
free #Attr.12;
jump #Derived_gen.9;
jump #Derived_gen.10;
else
decref #Attr.12;
jump #Derived_gen.9;
jump #Derived_gen.10;
in
jump Test.38 #Derived_gen.0 #Derived_gen.1;
jump Test.38 #Derived_gen.7 #Derived_gen.8;
procedure Test.2 ():
let Test.6 : Str = "Hello";

View File

@ -23,7 +23,7 @@ procedure Test.2 (Test.9, Test.10):
let Test.29 : U64 = CallByName Test.3 Test.9;
ret Test.29;
else
joinpoint #Derived_gen.1:
joinpoint #Derived_gen.4:
let Test.13 : Str = UnionAtIndex (Id 0) (Index 0) Test.10;
let Test.14 : [<rnu><null>, C Str *self] = UnionAtIndex (Id 0) (Index 1) Test.10;
let Test.33 : U64 = CallByName Test.3 Test.12;
@ -36,15 +36,15 @@ procedure Test.2 (Test.9, Test.10):
else
ret Test.16;
in
let #Derived_gen.2 : Int1 = lowlevel RefCountIsUnique Test.9;
if #Derived_gen.2 then
let #Derived_gen.5 : Int1 = lowlevel RefCountIsUnique Test.9;
if #Derived_gen.5 then
dec Test.11;
free Test.9;
jump #Derived_gen.1;
jump #Derived_gen.4;
else
inc Test.12;
decref Test.9;
jump #Derived_gen.1;
jump #Derived_gen.4;
procedure Test.3 (Test.17):
let Test.26 : U8 = 1i64;
@ -55,22 +55,22 @@ procedure Test.3 (Test.17):
ret Test.22;
else
let Test.18 : [<rnu><null>, C Str *self] = UnionAtIndex (Id 0) (Index 1) Test.17;
joinpoint #Derived_gen.3:
joinpoint #Derived_gen.1:
let Test.24 : U64 = 1i64;
let Test.25 : U64 = CallByName Test.3 Test.18;
let Test.23 : U64 = CallByName Num.19 Test.24 Test.25;
ret Test.23;
in
let #Derived_gen.5 : Int1 = lowlevel RefCountIsUnique Test.17;
if #Derived_gen.5 then
let #Derived_gen.4 : Str = UnionAtIndex (Id 0) (Index 0) Test.17;
dec #Derived_gen.4;
let #Derived_gen.3 : Int1 = lowlevel RefCountIsUnique Test.17;
if #Derived_gen.3 then
let #Derived_gen.2 : Str = UnionAtIndex (Id 0) (Index 0) Test.17;
dec #Derived_gen.2;
free Test.17;
jump #Derived_gen.3;
jump #Derived_gen.1;
else
inc Test.18;
decref Test.17;
jump #Derived_gen.3;
jump #Derived_gen.1;
procedure Test.0 ():
let Test.5 : [<rnu><null>, C Str *self] = TagId(1) ;

View File

@ -141,7 +141,7 @@ procedure List.8 (#Attr.2, #Attr.3):
let List.625 : List U8 = lowlevel ListConcat #Attr.2 #Attr.3;
ret List.625;
procedure List.92 (#Derived_gen.44, #Derived_gen.45, #Derived_gen.46, #Derived_gen.47, #Derived_gen.48):
procedure List.92 (#Derived_gen.29, #Derived_gen.30, #Derived_gen.31, #Derived_gen.32, #Derived_gen.33):
joinpoint List.577 List.163 List.164 List.165 List.166 List.167:
let List.579 : Int1 = CallByName Num.22 List.166 List.167;
if List.579 then
@ -155,7 +155,7 @@ procedure List.92 (#Derived_gen.44, #Derived_gen.45, #Derived_gen.46, #Derived_g
dec List.163;
ret List.164;
in
jump List.577 #Derived_gen.44 #Derived_gen.45 #Derived_gen.46 #Derived_gen.47 #Derived_gen.48;
jump List.577 #Derived_gen.29 #Derived_gen.30 #Derived_gen.31 #Derived_gen.32 #Derived_gen.33;
procedure List.92 (#Derived_gen.52, #Derived_gen.53, #Derived_gen.54, #Derived_gen.55, #Derived_gen.56):
joinpoint List.604 List.163 List.164 List.165 List.166 List.167:

3
examples/python-interop/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.interop_env
demo.egg-info
dist

View File

@ -5,12 +5,7 @@ set -euxo pipefail
# Could assume roc binary on path but this may be preferable
cargo build --release
../../target/release/roc build --lib
# Neither the application nor python needs a .0, so we can just rename it
mv libhello.so.1.0 libhello.so.1
# but one of which does expect plain libhello.so, so we symlink it
ln -sf libhello.so.1 libhello.so
../../target/release/roc build --lib libhello.roc
# For Python to find libhello, it needs it to be in a known library path, so we export
export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
@ -24,6 +19,7 @@ export cc=clang
python -m venv .interop_env
source .interop_env/bin/activate
python setup.py install
set +x
echo "You may now enter your virtual environment.
In bash/zsh, run: source .interop_env/bin/activate
In fish, run: source .interop_env/bin/activate.fish

View File

@ -227,15 +227,7 @@ PyObject * call_roc(PyObject *self, PyObject *args)
roc__mainForHost_1_exposed_generic(&ret, &arg);
// Create a Python string from the heap-allocated JSON bytes the Roc function returned.
PyObject* json_bytes = PyUnicode_FromStringAndSize((char*)ret.bytes, ret.len);
PyObject* json_module = PyImport_ImportModule("json");
PyObject* loads_func = PyObject_GetAttrString(json_module, "loads");
PyObject *loads_args = PyTuple_Pack(1, json_bytes);
PyObject* py_obj = PyObject_CallObject(loads_func, loads_args);
Py_XDECREF(loads_args);
Py_XDECREF(loads_func);
Py_XDECREF(json_module);
Py_XDECREF(json_bytes);
PyObject* py_obj = PyUnicode_FromStringAndSize((char*)ret.bytes, ret.len);
// Now that we've created py_str, we're no longer referencing the RocBytes.
decref((void *)&ret, alignof(uint8_t *));

View File

@ -1,12 +1,16 @@
platform "python-interop"
requires {} { main : arg -> ret where arg implements Decoding, ret implements Encoding }
requires {} { main : U64 -> Str }
exposes []
packages {}
imports [TotallyNotJson]
imports []
provides [mainForHost]
mainForHost : List U8 -> List U8
mainForHost = \json ->
when Decode.fromBytes json TotallyNotJson.json is
Ok arg -> Encode.toBytes (main arg) TotallyNotJson.json
mainForHost = \input ->
when Str.fromUtf8 input is
Ok arg ->
when Str.toU64 arg is
Ok num -> main num |> Str.toUtf8
Err _ -> []
Err _ -> []

2
examples/ruby-interop/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
extconf.h
mkmf.log

View File

@ -47,7 +47,7 @@ This uses the `Makefile` generated earlier to take the compiled Roc library and
You can now try this out in Ruby's REPL (`irb`), like so:
```sh
$ irb
$ LD_LIBRARY_PATH="$PWD" irb
irb(main):001:0> require_relative 'demo'
=> true
irb(main):002:0> RocApp::call_roc 42

View File

@ -194,32 +194,28 @@ size_t roc_str_len(struct RocStr str)
extern void roc__mainForHost_1_exposed_generic(struct RocBytes *ret, struct RocBytes *arg);
// Receive a value from Ruby, JSON serialized it and pass it to Roc as a List U8
// Receive a value from Ruby, serialize it and pass it to Roc as a List U8
// (at which point the Roc platform will decode it and crash if it's invalid,
// which roc_panic will translate into a Ruby exception), then get some JSON back from Roc
// - also as a List U8 - and have Ruby JSON.parse it into a plain Ruby value to return.
// which roc_panic will translate into a Ruby exception), then get some utf-8 string back from Roc
// - also as a List U8 - and have Ruby decode it into a plain Ruby value to return.
VALUE call_roc(VALUE self, VALUE rb_arg)
{
// This must be required before the to_json method will exist on String.
rb_require("json");
VALUE str_arg = rb_funcall(rb_arg, rb_intern("to_s"), 0);
VALUE str_utf8_arg = rb_funcall(str_arg, rb_intern("force_encoding"), 1, rb_str_new_cstr("utf-8"));
// Turn the given Ruby value into a JSON string.
// TODO should we defensively encode it as UTF-8 first?
VALUE json_arg = rb_funcall(rb_arg, rb_intern("to_json"), 0);
struct RocBytes arg = init_rocbytes((uint8_t *)RSTRING_PTR(json_arg), RSTRING_LEN(json_arg));
struct RocBytes arg = init_rocbytes((uint8_t *)RSTRING_PTR(str_utf8_arg), RSTRING_LEN(str_utf8_arg));
struct RocBytes ret;
// Call the Roc function to populate `ret`'s bytes.
roc__mainForHost_1_exposed_generic(&ret, &arg);
// Create a rb_utf8_str from the heap-allocated JSON bytes the Roc function returned.
VALUE returned_json = rb_utf8_str_new((char *)ret.bytes, ret.len);
// Create a rb_utf8_str from the heap-allocated utf-8 bytes the Roc function returned.
VALUE returned_str = rb_utf8_str_new((char *)ret.bytes, ret.len);
// Now that we've created our Ruby JSON string, we're no longer referencing the RocBytes.
// Now that we've created our Ruby string, we're no longer referencing the RocBytes.
decref((void *)&ret, alignof(uint8_t *));
return rb_funcall(rb_define_module("JSON"), rb_intern("parse"), 1, returned_json);
return returned_str;
}
void Init_demo()

View File

@ -2,9 +2,8 @@
require 'mkmf'
# preparation for compilation goes here
dir_config('') # include the current directory in the library search path
have_library('hello') # depend on `libhello.dylib` being in the current path
# (.dylib is macOS-specific; other OSes would have different extensions)
# HACK: pass 'demo.c' as a header because otherwise ruby complains that roc_*alloc are not defined
have_library('hello', nil, 'demo.c')
create_header
create_makefile 'demo'

View File

@ -1,12 +1,16 @@
platform "ruby-interop"
requires {} { main : arg -> ret where arg implements Decoding, ret implements Encoding }
requires {} { main : U64 -> Str }
exposes []
packages {}
imports [TotallyNotJson]
imports []
provides [mainForHost]
mainForHost : List U8 -> List U8
mainForHost = \json ->
when Decode.fromBytes json TotallyNotJson.json is
Ok arg -> Encode.toBytes (main arg) TotallyNotJson.json
mainForHost = \input ->
when Str.fromUtf8 input is
Ok arg ->
when Str.toU64 arg is
Ok num -> main num |> Str.toUtf8
Err _ -> []
Err _ -> [] # TODO panic so that Ruby raises an exception

View File

@ -20,7 +20,7 @@ import Html.Internal.Shared exposing [
Handler,
translateStatic,
]
import TotallyNotJson
import Json
import Action
PlatformState state initData : {
@ -101,7 +101,7 @@ initClientAppHelp : List U8, App state initData -> { state, rendered : RenderedT
initClientAppHelp = \json, app ->
state =
json
|> Decode.fromBytes TotallyNotJson.json
|> Decode.fromBytes Json.json
|> app.init
dynamicView =
app.render state
@ -441,7 +441,7 @@ diffAttr = \{ nodeId, attrs, patches, handlers, deletedHandlerCache }, attr ->
if accessors == newAccessors then
Tuple attrs patches
else
json = newAccessors |> Encode.toBytes TotallyNotJson.json
json = newAccessors |> Encode.toBytes Json.json
Tuple
{ attrs & eventListeners: Dict.insert attrs.eventListeners eventName { accessors, handlerId } }
@ -593,7 +593,7 @@ renderAttr = \{ nodeId, attrs, patches, handlers, deletedHandlerCache }, attr ->
newDeletedHandlerCache: deletedHandlerCache,
}
accessorsJson =
accessors |> Encode.toBytes TotallyNotJson.json
accessors |> Encode.toBytes Json.json
patch =
SetListener nodeId eventType accessorsJson handlerId
@ -771,7 +771,7 @@ expect
initJson : List U8
initJson =
{ answer: 42 } |> Encode.toBytes TotallyNotJson.json # panics at mono/src/ir.rs:5739:56
{ answer: 42 } |> Encode.toBytes Json.json # panics at mono/src/ir.rs:5739:56
expected : { state : State, rendered : RenderedTree State, patches : List Patch }
expected = {
state: { answer: 42 },

View File

@ -4,7 +4,7 @@ module [
]
import Html.Internal.Shared exposing [Html, Attribute, App, translateStatic, text, element]
import TotallyNotJson
import Json
# -------------------------------
# STATIC HTML
@ -69,7 +69,7 @@ insertRocScript = \document, initData, wasmUrl, hostJavaScript ->
encode =
\value ->
value
|> Encode.toBytes TotallyNotJson.json
|> Encode.toBytes Json.json
|> Str.fromUtf8
|> Result.withDefault ""

View File

@ -1,18 +1,10 @@
## THIS MODULE IS DEPRECATED AND CURRENTLY IN THE PROCESS OF BEING REMOVED
## FROM STD LIBRARY
module [
Json,
json,
jsonWithOptions,
]
import List
import Str
import Result
import Encode exposing [EncoderFormatting, appendWith]
import Decode exposing [DecoderFormatting, DecodeResult]
import Num exposing [U8, U16, U64, F32, F64, Dec]
import Bool exposing [Bool]
import Encode exposing [appendWith]
## An opaque type with the `EncoderFormatting` and
## `DecoderFormatting` abilities.

View File

@ -6,7 +6,7 @@ platform "server-side"
Html.Internal.Shared.{ App },
Html.Internal.Server.{ initServerApp },
Html.{ renderStatic },
TotallyNotJson,
Json,
]
provides [main]
@ -14,7 +14,7 @@ main : Str, Str -> Result Str Str
main = \initJson, hostJavaScript ->
initJson
|> Str.toUtf8
|> Decode.fromBytes TotallyNotJson.json
|> Decode.fromBytes Json.json
|> Result.try \initData -> initServerApp app initData hostJavaScript
|> Result.map renderStatic
|> Result.mapErr \err ->