Skip to main content

nanvm_demos/gen.samples/
mod.rs

1// @generated by `fjs run ./fjs/nanvm/demos/module.f.mjs`. Do not edit: add or remove a sample instead.
2
3pub mod arrays;
4pub mod bigints;
5pub mod call_statements;
6pub mod calls;
7pub mod captures;
8pub mod collatz;
9pub mod comma;
10pub mod comments;
11pub mod constants;
12pub mod destructuring;
13pub mod entries;
14pub mod exports;
15pub mod function_outputs;
16pub mod functions;
17pub mod grouping;
18pub mod guards;
19pub mod hello;
20pub mod identifiers;
21pub mod in_operator;
22pub mod instanceof;
23pub mod loops;
24pub mod member_functions;
25pub mod names_and_identity;
26pub mod number_conversion;
27pub mod numbers;
28pub mod objects;
29pub mod operators;
30pub mod optional_chaining;
31pub mod parameters;
32pub mod property_access;
33pub mod sort;
34pub mod static_functions;
35pub mod string_conversion;
36pub mod string_escapes;
37pub mod strings;
38pub mod switch_statement;
39pub mod template_literals;
40pub mod values;
41pub mod variables;
42pub mod whitespace;
43
44/// Loads the `arrays` sample.
45#[unsafe(no_mangle)]
46pub extern "C" fn arrays() -> i32 {
47    crate::export(arrays::module::<nanvm_lib::naive::Naive>)
48}
49
50/// Loads the `bigints` sample.
51#[unsafe(no_mangle)]
52pub extern "C" fn bigints() -> i32 {
53    crate::export(bigints::module::<nanvm_lib::naive::Naive>)
54}
55
56/// Loads the `call_statements` sample.
57#[unsafe(no_mangle)]
58pub extern "C" fn call_statements() -> i32 {
59    crate::export(call_statements::module::<nanvm_lib::naive::Naive>)
60}
61
62/// Loads the `calls` sample.
63#[unsafe(no_mangle)]
64pub extern "C" fn calls() -> i32 {
65    crate::export(calls::module::<nanvm_lib::naive::Naive>)
66}
67
68/// Loads the `captures` sample.
69#[unsafe(no_mangle)]
70pub extern "C" fn captures() -> i32 {
71    crate::export(captures::module::<nanvm_lib::naive::Naive>)
72}
73
74/// Loads the `collatz` sample.
75#[unsafe(no_mangle)]
76pub extern "C" fn collatz() -> i32 {
77    crate::export(collatz::module::<nanvm_lib::naive::Naive>)
78}
79
80/// Loads the `comma` sample.
81#[unsafe(no_mangle)]
82pub extern "C" fn comma() -> i32 {
83    crate::export(comma::module::<nanvm_lib::naive::Naive>)
84}
85
86/// Loads the `comments` sample.
87#[unsafe(no_mangle)]
88pub extern "C" fn comments() -> i32 {
89    crate::export(comments::module::<nanvm_lib::naive::Naive>)
90}
91
92/// Loads the `constants` sample.
93#[unsafe(no_mangle)]
94pub extern "C" fn constants() -> i32 {
95    crate::export(constants::module::<nanvm_lib::naive::Naive>)
96}
97
98/// Loads the `destructuring` sample.
99#[unsafe(no_mangle)]
100pub extern "C" fn destructuring() -> i32 {
101    crate::export(destructuring::module::<nanvm_lib::naive::Naive>)
102}
103
104/// Loads the `entries` sample.
105#[unsafe(no_mangle)]
106pub extern "C" fn entries() -> i32 {
107    crate::export(entries::module::<nanvm_lib::naive::Naive>)
108}
109
110/// Loads the `exports` sample.
111#[unsafe(no_mangle)]
112pub extern "C" fn exports() -> i32 {
113    crate::export(exports::module::<nanvm_lib::naive::Naive>)
114}
115
116/// Loads the `function_outputs` sample.
117#[unsafe(no_mangle)]
118pub extern "C" fn function_outputs() -> i32 {
119    crate::export(function_outputs::module::<nanvm_lib::naive::Naive>)
120}
121
122/// Loads the `functions` sample.
123#[unsafe(no_mangle)]
124pub extern "C" fn functions() -> i32 {
125    crate::export(functions::module::<nanvm_lib::naive::Naive>)
126}
127
128/// Loads the `grouping` sample.
129#[unsafe(no_mangle)]
130pub extern "C" fn grouping() -> i32 {
131    crate::export(grouping::module::<nanvm_lib::naive::Naive>)
132}
133
134/// Loads the `guards` sample.
135#[unsafe(no_mangle)]
136pub extern "C" fn guards() -> i32 {
137    crate::export(guards::module::<nanvm_lib::naive::Naive>)
138}
139
140/// Loads the `hello` sample.
141#[unsafe(no_mangle)]
142pub extern "C" fn hello() -> i32 {
143    crate::export(hello::module::<nanvm_lib::naive::Naive>)
144}
145
146/// Loads the `identifiers` sample.
147#[unsafe(no_mangle)]
148pub extern "C" fn identifiers() -> i32 {
149    crate::export(identifiers::module::<nanvm_lib::naive::Naive>)
150}
151
152/// Loads the `in_operator` sample.
153#[unsafe(no_mangle)]
154pub extern "C" fn in_operator() -> i32 {
155    crate::export(in_operator::module::<nanvm_lib::naive::Naive>)
156}
157
158/// Loads the `instanceof` sample.
159#[unsafe(no_mangle)]
160pub extern "C" fn instanceof() -> i32 {
161    crate::export(instanceof::module::<nanvm_lib::naive::Naive>)
162}
163
164/// Loads the `loops` sample.
165#[unsafe(no_mangle)]
166pub extern "C" fn loops() -> i32 {
167    crate::export(loops::module::<nanvm_lib::naive::Naive>)
168}
169
170/// Loads the `member_functions` sample.
171#[unsafe(no_mangle)]
172pub extern "C" fn member_functions() -> i32 {
173    crate::export(member_functions::module::<nanvm_lib::naive::Naive>)
174}
175
176/// Loads the `names_and_identity` sample.
177#[unsafe(no_mangle)]
178pub extern "C" fn names_and_identity() -> i32 {
179    crate::export(names_and_identity::module::<nanvm_lib::naive::Naive>)
180}
181
182/// Loads the `number_conversion` sample.
183#[unsafe(no_mangle)]
184pub extern "C" fn number_conversion() -> i32 {
185    crate::export(number_conversion::module::<nanvm_lib::naive::Naive>)
186}
187
188/// Loads the `numbers` sample.
189#[unsafe(no_mangle)]
190pub extern "C" fn numbers() -> i32 {
191    crate::export(numbers::module::<nanvm_lib::naive::Naive>)
192}
193
194/// Loads the `objects` sample.
195#[unsafe(no_mangle)]
196pub extern "C" fn objects() -> i32 {
197    crate::export(objects::module::<nanvm_lib::naive::Naive>)
198}
199
200/// Loads the `operators` sample.
201#[unsafe(no_mangle)]
202pub extern "C" fn operators() -> i32 {
203    crate::export(operators::module::<nanvm_lib::naive::Naive>)
204}
205
206/// Loads the `optional_chaining` sample.
207#[unsafe(no_mangle)]
208pub extern "C" fn optional_chaining() -> i32 {
209    crate::export(optional_chaining::module::<nanvm_lib::naive::Naive>)
210}
211
212/// Loads the `parameters` sample.
213#[unsafe(no_mangle)]
214pub extern "C" fn parameters() -> i32 {
215    crate::export(parameters::module::<nanvm_lib::naive::Naive>)
216}
217
218/// Loads the `property_access` sample.
219#[unsafe(no_mangle)]
220pub extern "C" fn property_access() -> i32 {
221    crate::export(property_access::module::<nanvm_lib::naive::Naive>)
222}
223
224/// Loads the `sort` sample.
225#[unsafe(no_mangle)]
226pub extern "C" fn sort() -> i32 {
227    crate::export(sort::module::<nanvm_lib::naive::Naive>)
228}
229
230/// Loads the `static_functions` sample.
231#[unsafe(no_mangle)]
232pub extern "C" fn static_functions() -> i32 {
233    crate::export(static_functions::module::<nanvm_lib::naive::Naive>)
234}
235
236/// Loads the `string_conversion` sample.
237#[unsafe(no_mangle)]
238pub extern "C" fn string_conversion() -> i32 {
239    crate::export(string_conversion::module::<nanvm_lib::naive::Naive>)
240}
241
242/// Loads the `string_escapes` sample.
243#[unsafe(no_mangle)]
244pub extern "C" fn string_escapes() -> i32 {
245    crate::export(string_escapes::module::<nanvm_lib::naive::Naive>)
246}
247
248/// Loads the `strings` sample.
249#[unsafe(no_mangle)]
250pub extern "C" fn strings() -> i32 {
251    crate::export(strings::module::<nanvm_lib::naive::Naive>)
252}
253
254/// Loads the `switch_statement` sample.
255#[unsafe(no_mangle)]
256pub extern "C" fn switch_statement() -> i32 {
257    crate::export(switch_statement::module::<nanvm_lib::naive::Naive>)
258}
259
260/// Loads the `template_literals` sample.
261#[unsafe(no_mangle)]
262pub extern "C" fn template_literals() -> i32 {
263    crate::export(template_literals::module::<nanvm_lib::naive::Naive>)
264}
265
266/// Loads the `values` sample.
267#[unsafe(no_mangle)]
268pub extern "C" fn values() -> i32 {
269    crate::export(values::module::<nanvm_lib::naive::Naive>)
270}
271
272/// Loads the `variables` sample.
273#[unsafe(no_mangle)]
274pub extern "C" fn variables() -> i32 {
275    crate::export(variables::module::<nanvm_lib::naive::Naive>)
276}
277
278/// Loads the `whitespace` sample.
279#[unsafe(no_mangle)]
280pub extern "C" fn whitespace() -> i32 {
281    crate::export(whitespace::module::<nanvm_lib::naive::Naive>)
282}
283
284/// The calls each function sample lists, each answered as JavaScript answers it.
285#[cfg(test)]
286mod tests {
287    use nanvm_lib::naive::Naive;
288
289    #[test]
290    fn arrays() {
291        let entry = crate::load(super::arrays::module::<Naive>).unwrap();
292        crate::assert_call(&entry, 1.0, Ok("[3,[\"hello\",1,[true,null],2],true]"));
293        crate::assert_call(&entry, 2.0, Ok("[3,[\"hello\",2,[true,null],3],true]"));
294    }
295
296    #[test]
297    fn bigints() {
298        let entry = crate::load(super::bigints::module::<Naive>).unwrap();
299        crate::assert_call(&entry, 0.0, Ok("[0n,\"bigint\"]"));
300        crate::assert_call(&entry, 1.0, Ok("[68n,\"bigint\"]"));
301        crate::assert_call(&entry, 2.0, Ok("[-68n,\"bigint\"]"));
302    }
303
304    #[test]
305    fn call_statements() {
306        let entry = crate::load(super::call_statements::module::<Naive>).unwrap();
307        crate::assert_call(&entry, 2.0, Ok("3"));
308        crate::assert_call(&entry, 5.0, Err("\"out of range\""));
309    }
310
311    #[test]
312    fn calls() {
313        let entry = crate::load(super::calls::module::<Naive>).unwrap();
314        crate::assert_call(&entry, 1.0, Ok("[11,[3,1,4,5]]"));
315        crate::assert_call(&entry, 3.0, Ok("[13,[3,3,4,5]]"));
316    }
317
318    #[test]
319    fn captures() {
320        let entry = crate::load(super::captures::module::<Naive>).unwrap();
321        crate::assert_call(&entry, 1.0, Ok("7"));
322        crate::assert_call(&entry, 10.0, Ok("16"));
323    }
324
325    #[test]
326    fn comma() {
327        let entry = crate::load(super::comma::module::<Naive>).unwrap();
328        crate::assert_call(&entry, 1.0, Ok("3"));
329        crate::assert_call(&entry, -1.0, Err("\"negative\""));
330    }
331
332    #[test]
333    fn comments() {
334        let entry = crate::load(super::comments::module::<Naive>).unwrap();
335        crate::assert_call(&entry, 1.0, Ok("2"));
336        crate::assert_call(&entry, -42.5, Ok("-85"));
337    }
338
339    #[test]
340    fn constants() {
341        let entry = crate::load(super::constants::module::<Naive>).unwrap();
342        crate::assert_call(&entry, 0.0, Ok("[true,8080,\"localhost\"]"));
343        crate::assert_call(&entry, 1.0, Ok("[true,8081,\"localhost\"]"));
344    }
345
346    #[test]
347    fn destructuring() {
348        let entry = crate::load(super::destructuring::module::<Naive>).unwrap();
349        crate::assert_call(&entry, 1.0, Ok("[1,2,[3,4]]"));
350        crate::assert_call(&entry, 5.0, Ok("[5,10,[3,4]]"));
351    }
352
353    #[test]
354    fn entries() {
355        let entry = crate::load(super::entries::module::<Naive>).unwrap();
356        crate::assert_call(&entry, 0.0, Ok("\"newline\""));
357        crate::assert_call(&entry, 1.0, Ok("undefined"));
358    }
359
360    #[test]
361    fn exports() {
362        let entry = crate::load(super::exports::module::<Naive>).unwrap();
363        crate::assert_call(&entry, 1.0, Ok("5"));
364        crate::assert_call(&entry, 2.0, Ok("10"));
365    }
366
367    #[test]
368    fn function_outputs() {
369        let entry = crate::load(super::function_outputs::module::<Naive>).unwrap();
370        crate::assert_call(&entry, 0.0, Ok("[2,1]"));
371        crate::assert_call(&entry, 2.0, Ok("[2,3]"));
372    }
373
374    #[test]
375    fn functions() {
376        let entry = crate::load(super::functions::module::<Naive>).unwrap();
377        crate::assert_call(&entry, 1.0, Ok("[1,10]"));
378        crate::assert_call(&entry, 2.0, Ok("[1,20]"));
379    }
380
381    #[test]
382    fn grouping() {
383        let entry = crate::load(super::grouping::module::<Naive>).unwrap();
384        crate::assert_call(&entry, 1.0, Ok("[9,7,2]"));
385        crate::assert_call(&entry, 2.0, Ok("[12,8,2]"));
386    }
387
388    #[test]
389    fn guards() {
390        let entry = crate::load(super::guards::module::<Naive>).unwrap();
391        crate::assert_call(&entry, -5.0, Ok("\"negative\""));
392        crate::assert_call(&entry, 0.0, Ok("\"zero\""));
393        crate::assert_call(&entry, 7.0, Ok("\"positive\""));
394    }
395
396    #[test]
397    fn identifiers() {
398        let entry = crate::load(super::identifiers::module::<Naive>).unwrap();
399        crate::assert_call(&entry, 1.0, Ok("[2,2,3,4]"));
400        crate::assert_call(&entry, 2.0, Ok("[3,2,3,4]"));
401    }
402
403    #[test]
404    fn in_operator() {
405        let entry = crate::load(super::in_operator::module::<Naive>).unwrap();
406        crate::assert_call(&entry, 0.0, Ok("true"));
407        crate::assert_call(&entry, 1.0, Ok("false"));
408    }
409
410    #[test]
411    fn instanceof() {
412        let entry = crate::load(super::instanceof::module::<Naive>).unwrap();
413        crate::assert_call(&entry, 0.0, Ok("true"));
414        crate::assert_call(&entry, 1.0, Ok("false"));
415    }
416
417    #[test]
418    fn loops() {
419        let entry = crate::load(super::loops::module::<Naive>).unwrap();
420        crate::assert_call(&entry, 5.0, Ok("[8,3]"));
421        crate::assert_call(&entry, 100.0, Ok("[128,7]"));
422    }
423
424    #[test]
425    fn member_functions() {
426        let entry = crate::load(super::member_functions::module::<Naive>).unwrap();
427        crate::assert_call(&entry, 0.0, Ok("\"10-20-30-40\""));
428        crate::assert_call(&entry, 2.0, Ok("\"30-40\""));
429    }
430
431    #[test]
432    fn names_and_identity() {
433        let entry = crate::load(super::names_and_identity::module::<Naive>).unwrap();
434        crate::assert_call(&entry, 0.0, Ok("[true,false,true]"));
435        crate::assert_call(&entry, 1.0, Ok("[true,false,false]"));
436    }
437
438    #[test]
439    fn number_conversion() {
440        let entry = crate::load(super::number_conversion::module::<Naive>).unwrap();
441        crate::assert_call(&entry, 7.0, Ok("[7,16,1,7]"));
442        crate::assert_call(&entry, 0.5, Ok("[0.5,16,1,0.5]"));
443    }
444
445    #[test]
446    fn numbers() {
447        let entry = crate::load(super::numbers::module::<Naive>).unwrap();
448        crate::assert_call(&entry, 0.0, Ok("0"));
449        crate::assert_call(&entry, 1.0, Ok("-85"));
450        crate::assert_call(&entry, 2.0, Ok("600"));
451        crate::assert_call(&entry, 3.0, Ok("2e-7"));
452    }
453
454    #[test]
455    fn objects() {
456        let entry = crate::load(super::objects::module::<Naive>).unwrap();
457        crate::assert_call(&entry, 1.0, Ok("4"));
458        crate::assert_call(&entry, 2.0, Ok("5"));
459    }
460
461    #[test]
462    fn operators() {
463        let entry = crate::load(super::operators::module::<Naive>).unwrap();
464        crate::assert_call(&entry, 1.0, Ok("[7,0,2,-2,false,\"number\",\"small\"]"));
465        crate::assert_call(&entry, 2.0, Ok("[8,1,4,-3,false,\"number\",\"big\"]"));
466    }
467
468    #[test]
469    fn optional_chaining() {
470        let entry = crate::load(super::optional_chaining::module::<Naive>).unwrap();
471        crate::assert_call(&entry, 0.0, Ok("[1,[2],[3]]"));
472        crate::assert_call(&entry, 1.0, Ok("[undefined,undefined,undefined]"));
473    }
474
475    #[test]
476    fn parameters() {
477        let entry = crate::load(super::parameters::module::<Naive>).unwrap();
478        crate::assert_call(&entry, 1.0, Ok("[[1,10,0],[1,2,2]]"));
479        crate::assert_call(&entry, 4.0, Ok("[[4,10,0],[4,8,2]]"));
480    }
481
482    #[test]
483    fn property_access() {
484        let entry = crate::load(super::property_access::module::<Naive>).unwrap();
485        crate::assert_call(&entry, 0.0, Ok("[80,2]"));
486        crate::assert_call(&entry, 1.0, Ok("[443,2]"));
487    }
488
489    #[test]
490    fn static_functions() {
491        let entry = crate::load(super::static_functions::module::<Naive>).unwrap();
492        crate::assert_call(&entry, 0.0, Ok("[false,true,false,[[\"0\",2],[\"b\",0]]]"));
493        crate::assert_call(
494            &entry,
495            1.5,
496            Ok("[false,false,true,[[\"0\",2],[\"b\",1.5]]]"),
497        );
498    }
499
500    #[test]
501    fn string_conversion() {
502        let entry = crate::load(super::string_conversion::module::<Naive>).unwrap();
503        crate::assert_call(&entry, 42.0, Ok("[\"42\",\"42\",\"1,2\",\"true\"]"));
504        crate::assert_call(&entry, -0.5, Ok("[\"-0.5\",\"42\",\"1,2\",\"false\"]"));
505    }
506
507    #[test]
508    fn string_escapes() {
509        let entry = crate::load(super::string_escapes::module::<Naive>).unwrap();
510        crate::assert_call(&entry, 0.0, Ok("8"));
511        crate::assert_call(&entry, 1.0, Ok("4"));
512        crate::assert_call(&entry, 2.0, Ok("1"));
513    }
514
515    #[test]
516    fn strings() {
517        let entry = crate::load(super::strings::module::<Naive>).unwrap();
518        crate::assert_call(&entry, 0.0, Ok("6"));
519        crate::assert_call(&entry, 1.0, Ok("3"));
520    }
521
522    #[test]
523    fn switch_statement() {
524        let entry = crate::load(super::switch_statement::module::<Naive>).unwrap();
525        crate::assert_call(&entry, 0.0, Ok("\"container\""));
526        crate::assert_call(&entry, 1.0, Ok("\"container\""));
527        crate::assert_call(&entry, 2.0, Ok("\"text\""));
528        crate::assert_call(&entry, 3.0, Err("[\"unknown\",3]"));
529    }
530
531    #[test]
532    fn template_literals() {
533        let entry = crate::load(super::template_literals::module::<Naive>).unwrap();
534        crate::assert_call(&entry, 1.0, Ok("\"Hello, 1 world!\""));
535        crate::assert_call(&entry, 2.0, Ok("\"Hello, 2 worlds!\""));
536    }
537
538    #[test]
539    fn values() {
540        let entry = crate::load(super::values::module::<Naive>).unwrap();
541        crate::assert_call(&entry, 1.0, Ok("[1,\"s\",true,null,[1],-1,\"bigint\"]"));
542        crate::assert_call(&entry, 2.0, Ok("[2,\"s\",true,null,[2],-2,\"bigint\"]"));
543    }
544
545    #[test]
546    fn variables() {
547        let entry = crate::load(super::variables::module::<Naive>).unwrap();
548        crate::assert_call(&entry, 3.0, Ok("[3,1,6]"));
549        crate::assert_call(&entry, -2.0, Ok("[2,1]"));
550    }
551
552    #[test]
553    fn whitespace() {
554        let entry = crate::load(super::whitespace::module::<Naive>).unwrap();
555        crate::assert_call(&entry, 1.0, Ok("2"));
556        crate::assert_call(&entry, 2.0, Ok("3"));
557    }
558}