stof 0.9.19

Data that carries its own logic.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
//
// Copyright 2025 Formata, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

use std::sync::Arc;
use imbl::vector;
use crate::{model::{LibFunc, Param, obj::{ANY, AT, AT_REF, ATTRIBUTES, CHILDREN, CONTAINS, CREATE_TYPE, DIFF, DISTANCE, DUMP, EMPTY, EXISTS, FIELDS, FROM_ID, FROM_MAP, FUNCS, GET, GET_REF, ID, INSERT, INSTANCE_OF, IS_PARENT, IS_ROOT, LEN, MOVE, MOVE_FIELD, NAME, OBJ_LIB, PARENT, PATH, PROTO, REMOVE, REMOVE_PROTO, ROOT, RUN, SCHEMAFY, SET_PROTO, TO_MAP, TO_MAP_REF, UPCAST}}, runtime::{NumT, Type, Val, instruction::Instructions, instructions::Base}};


#[inline(always)]
/// Name.
pub fn obj_name() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "name".into(),
        is_async: false,
        docs: r#"# Obj.name(obj: obj) -> str
Return the name of this object.
```rust
const obj = new {};
assert(obj.name().len() > 0);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(NAME.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Id.
pub fn obj_id() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "id".into(),
        is_async: false,
        docs: r#"# Obj.id(obj: obj) -> str
Return the ID of this object.
```rust
const obj = new {};
assert(obj.id().len() > 0);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(ID.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Path.
pub fn obj_path() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "path".into(),
        is_async: false,
        docs: r#"# Obj.path(obj: obj) -> str
Return the path of this object as a dot '.' separated string.
```rust
assert_eq(self.path(), "root.TestObject"); // if self is "TestObject" and it's parent is "root"
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(PATH.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Parent.
pub fn obj_parent() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "parent".into(),
        is_async: false,
        docs: r#"# Obj.parent(obj: obj) -> obj
Return the parent of this object, or null if this object is a root.
```rust
const obj = new {};
assert_eq(obj.parent(), self);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(PARENT.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Is Parent?
pub fn obj_is_parent() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "is_parent".into(),
        is_async: false,
        docs: r#"# Obj.is_parent(obj: obj, other: obj) -> bool
Returns true if this object is a parent of another.
```rust
const obj = new {};
assert(self.is_parent(obj));
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "other".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(IS_PARENT.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Exists?
pub fn obj_exists() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "exists".into(),
        is_async: false,
        docs: r#"# Obj.exists(obj: obj) -> bool
Returns true if this object reference points to an existing object. This is false if the object has been dropped from the document.
```rust
const obj = new {};
assert(obj.exists());
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(EXISTS.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Children.
pub fn obj_children() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "children".into(),
        is_async: false,
        docs: r#"# Obj.children(obj: obj) -> list
Returns a list containing this objects children.
```rust
const obj = new {};
assert_eq(self.children(), [obj]);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(CHILDREN.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Root.
pub fn obj_root() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "root".into(),
        is_async: false,
        docs: r#"# Obj.root(obj: obj) -> obj
Returns the root object that contains this object (or self if this object is a root).
```rust
const obj = new {};
assert_eq(obj.root(), self); // if self is a root
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(ROOT.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Is root?
pub fn obj_is_root() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "is_root".into(),
        is_async: false,
        docs: r#"# Obj.is_root(obj: obj) -> bool
Returns true if this object is a root.
```rust
assert(self.is_root()); // if self is a root
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(IS_ROOT.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Prototype.
pub fn obj_proto() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "prototype".into(),
        is_async: false,
        docs: r#"# Obj.prototype(obj: obj) -> obj
Returns the prototype object for this object or null if this object doesn't have one.
```rust
assert_not(self.prototype()); // no prototype
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(PROTO.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Create a type.
pub fn obj_create_type() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "create_type".into(),
        is_async: false,
        docs: r#"# Obj.create_type(obj: obj, typename: str) -> void
Add a typename reference to the graph, pointing to this object. Programmatic version of #[type("typename")] attribute.
```rust
const obj = new { float x: 0, float y: 0 };
obj.create_type("MyType");

const ins = new MyType {};
assert_eq(ins.x, 0);
assert_eq(ins.y, 0);
assert_eq(typename ins, "MyType");
assert_eq(ins.prototype(), obj);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "typename".into(), param_type: Type::Str, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(CREATE_TYPE.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Upcast.
pub fn obj_upcast() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "upcast".into(),
        is_async: false,
        docs: r#"# Obj.upcast(obj: obj) -> bool
Set the prototype of this object to the prototype of this objects existing prototype.
```rust
const obj = new SubType {};
assert(obj.upcast());
assert_eq(typename obj, "SuperType");
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(UPCAST.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Set prototype.
pub fn obj_set_proto() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "set_prototype".into(),
        is_async: false,
        docs: r#"# Obj.set_prototype(obj: obj, proto: obj | str) -> void
Set the prototype of this object.
```rust
const proto = new {};
const obj = new {};
obj.set_prototype(proto);
assert_eq(obj.prototype(), proto);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "proto".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(SET_PROTO.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Remove prototype.
pub fn obj_remove_proto() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "remove_prototype".into(),
        is_async: false,
        docs: r#"# Obj.remove_prototype(obj: obj) -> void
Remove an object's prototype.
```rust
const obj = new MyType {};
obj.remove_prototype();
assert_eq(typename obj, "obj");
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(REMOVE_PROTO.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Instance of prototype?
pub fn obj_instance_of_proto() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "instance_of".into(),
        is_async: false,
        docs: r#"# Obj.instance_of(obj: obj, proto: str | obj) -> bool
Returns true if this object is an instance of a prototype.
```rust
const obj = new MyType {};
assert(obj.instance_of("MyType"));
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "proto".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(INSTANCE_OF.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Length.
pub fn obj_len() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "len".into(),
        is_async: false,
        docs: r#"# Obj.len(obj: obj) -> int
Number of fields on this object.
```rust
const obj = new { x: 0, y: 0 };
assert_eq(obj.len(), 2);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(LEN.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// At.
pub fn obj_at() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "at".into(),
        is_async: false,
        docs: r#"# Obj.at(obj: obj, index: int) -> (str, unknown)
Field (name, value) on this object at the given index, or null if the index is out of bounds.
```rust
const obj = new { x: 0, y: 0 };
assert_eq(obj[1], ("y", 0));
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "index".into(), param_type: Type::Num(NumT::Int), default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            if as_ref {
                instructions.push(AT_REF.clone());
            } else {
                instructions.push(AT.clone());
            }
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Get.
pub fn obj_get() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "get".into(),
        is_async: false,
        docs: r#"# Obj.get(obj: obj, name: str) -> unknown
Get data on this object by name (field value, fn, or data pointer).
```rust
const obj = new { x: 0, y: 0 };
assert_eq(obj.get("x"), 0);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "name".into(), param_type: Type::Str, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            if as_ref {
                instructions.push(GET_REF.clone());
            } else {
                instructions.push(GET.clone());
            }
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Contains?
pub fn obj_contains() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "contains".into(),
        is_async: false,
        docs: r#"# Obj.contains(obj: obj, name: str) -> bool
Return true if this object contains data with the given name.
```rust
const obj = new { x: 0, y: 0 };
assert(obj.contains("y"));
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "name".into(), param_type: Type::Str, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(CONTAINS.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Insert.
pub fn obj_insert() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "insert".into(),
        is_async: false,
        docs: r#"# Obj.insert(obj: obj, path: str, value: unknown) -> void
Either creates or assigns to a field, just like a normal field assignment, using this object as a starting context.
```rust
const obj = new { x: 0, y: 0 };
obj.insert("z", 9);
assert_eq(obj.z, 9);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "path".into(), param_type: Type::Str, default: None },
            Param { name: "value".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(INSERT.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Remove.
pub fn obj_remove() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "remove".into(),
        is_async: false,
        docs: r#"# Obj.remove(obj: obj, path: str, shallow: bool = false) -> bool
Performs a "drop" operation, just like the Std.drop(..) function, using this object as a starting context. Use this to remove fields, functions, data, etc.

## Shallow
If shallow is true and the path references an object field, drop the field, but don't drop the object from the graph. Default behavior is to drop objects.

```rust
const obj = new { x: 0, y: 0 };
assert(obj.remove("x"));
assert_not(obj.x);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "path".into(), param_type: Type::Str, default: None },
            Param { name: "shallow".into(), param_type: Type::Bool, default: Some(Arc::new(Base::Literal(Val::Bool(false)))) }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(REMOVE.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Move field.
pub fn obj_move_field() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "move_field".into(),
        is_async: false,
        docs: r#"# Obj.move_field(obj: obj, source: str, dest: str) -> bool
Move or rename a field from a source path/name to a destination path/name (like "mv" in bash), returning true if successfully moved.
```rust
const obj = new { x: 0, y: 0 };
obj.move_field("x", "dude");
assert_eq(obj.dude, 0);
assert_not(obj.x);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "source".into(), param_type: Type::Str, default: None },
            Param { name: "dest".into(), param_type: Type::Str, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(MOVE_FIELD.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Fields.
pub fn obj_fields() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "fields".into(),
        is_async: false,
        docs: r#"# Obj.fields(obj: obj) -> list
Returns a list of fields (tuples with name and value each) on this object.
```rust
const obj = new { x: 0, y: 0 };
assert_eq(obj.fields(), [("x", 0), ("y", 0)]);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(FIELDS.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Funcs.
pub fn obj_funcs() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "funcs".into(),
        is_async: false,
        docs: r#"# Obj.funcs(obj: obj, attributes: str | list | set = null) -> list
Returns a list of functions on this object, optionally filtering by attributes (str, list of str, set of str, tuple of str).
```rust
// #[myfunc] fn func() {}
assert_eq(self.funcs("myfunc"), [self.func]);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "attributes".into(), param_type: Type::Void, default: Some(Arc::new(Base::Literal(Val::Null))) },
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(FUNCS.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Empty?
pub fn obj_empty() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "empty".into(),
        is_async: false,
        docs: r#"# Obj.empty(obj: obj) -> bool
Returns true if this object doesn't have any data attached to it.
```rust
const obj = new { x: 0, y: 0 };
assert_not(obj.empty());
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(EMPTY.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Any?
pub fn obj_any() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "any".into(),
        is_async: false,
        docs: r#"# Obj.any(obj: obj) -> bool
Returns true if this object has any data attached to it.
```rust
const obj = new { x: 0, y: 0 };
assert(obj.any());
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(ANY.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Attributes.
pub fn obj_attributes() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "attributes".into(),
        is_async: false,
        docs: r#"# Obj.attributes(obj: obj, path: str = null) -> map
Returns a map of attributes, either for this object if the path is null, or for the field/func/obj at the given path.
```rust
assert_eq(self.attributes(), {"a": null}); // if self was defined as a field with the attribute #[a]
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "path".into(), param_type: Type::Str, default: Some(Arc::new(Base::Literal(Val::Null))) }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(ATTRIBUTES.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Move.
pub fn obj_move() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "move".into(),
        is_async: false,
        docs: r#"# Obj.move(obj: obj, dest: obj) -> bool
Move this object to a new parent destination. Parent destination cannot be a child of this object (node detachment).
```rust
const obj = new { x: 0, y: 0 };
const other = new {};
obj.move(other);
assert_eq(obj.parent(), other);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "dest".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(MOVE.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Distance.
pub fn obj_dist() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "dist".into(),
        is_async: false,
        docs: r#"# Obj.dist(obj: obj, other: obj) -> int
Get the distance between two objects (number of edges that separate them).
```rust
const obj = new { x: 0, y: 0 };
assert_eq(obj.dist(self), 1);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
            Param { name: "other".into(), param_type: Type::Void, default: None }
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(DISTANCE.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Run.
pub fn obj_run() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "run".into(),
        is_async: false,
        docs: r#"# Obj.run(obj: obj) -> void
Run an object (like calling a function, but for the entire object as a task). This will execute all fields and functions with a #[run] attribute, optionally with an order #[run(3)]. Any sub objects encountered will also get ran recursively. Arrays act like pipelines, unlocking serious functionality.

## Motivation
This concept enables data-driven abstractions above function calls. An example would be setting some fields on an object that already has some #[run] functions defined, ready to utilize the values in those fields. With prototypes, you can probably see how this is a powerful tool.

### Concrete Example
```rust
#[type]
Request: {
    str name: "europe"

    #[run]
    fn execute() {
        self.result = await Http.fetch("https://myawesomeendpoint/" + self.name);
    }
}

#[main]
fn example() {
    const req = new Request { name: "usa" };
    req.run();
    // now work with req.result as needed
}
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(Arc::new(Base::Literal(Val::Null))); // override context
            instructions.push(RUN.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Diff.
pub fn obj_diff() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "diff".into(),
        is_async: false,
        docs: r#"# Obj.diff(schema: obj, target: obj, symmetric: bool = false) -> void
Diffs the schema with the target, modifying the target object only. Removes all fields from the target that match the schema, recursively. Optionally, if symmetric, unique schema fields will be deep copied to the target object as well (a version of: (a - b) U (b - a)).
```rust
const sch = new { x: 3km, y: 5.5m };
const other = new { x: 3km, y: 5.6m };

let difference = copy(other);
sch.diff(difference);

assert_eq(difference.x, null);
assert_eq(difference.y, 5.6m);
```
"#.into(),
        params: vector![
            Param { name: "schema".into(), param_type: Type::Void, default: None },
            Param { name: "target".into(), param_type: Type::Void, default: None },
            Param { name: "symmetric".into(), param_type: Type::Bool, default: Some(Arc::new(Base::Literal(Val::Bool(false)))) },
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(DIFF.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Schemafy.
pub fn obj_schemafy() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "schemafy".into(),
        is_async: false,
        docs: r#"# Obj.schemafy(schema: obj, target: obj, remove_invalid: bool = false, remove_undefined: bool = false) -> bool
Applies all #[schema] fields from a schema object onto a target object, manipulating the target's fields accordingly and returning true if the target is determined to be valid (matches the schema).

## Use Cases
- filtering & renaming fields as a batch
- validation
- structured transformations (to/from APIs, etc.)
- access control

```rust
schema: {
    #[schema((target_value: str): bool => target_value.len() > 2)]
    first: 'John'

    #[schema(( // pipelines are big AND filters, applied in order and short circuited like &&
        (target_value: unknown): bool => (typeof target_value) == 'str',
        (target_value: str): bool => target_value.contains('Dude'),
    ))]
    last: 'Doe'
}

target: {
    first: 'aj'
    last: 'Dude'
    undefined: 'blah'
}

#[test]
fn schemafy_obj() {
    assert(self.schema.schemafy(self.target, remove_invalid = true, remove_undefined = true));
    assert_eq(str(self.target), "{\"last\":\"Dude\"}");
}
```
"#.into(),
        params: vector![
            Param { name: "schema".into(), param_type: Type::Void, default: None },
            Param { name: "target".into(), param_type: Type::Void, default: None },
            Param { name: "remove_invalid".into(), param_type: Type::Bool, default: Some(Arc::new(Base::Literal(Val::Bool(false)))) },
            Param { name: "remove_undefined".into(), param_type: Type::Bool, default: Some(Arc::new(Base::Literal(Val::Bool(false)))) },
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(SCHEMAFY.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// To Map.
pub fn obj_to_map() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "to_map".into(),
        is_async: false,
        docs: r#"# Obj.to_map(obj: obj) -> map
Create a new map out of this object's fields.
```rust
const obj = new { x: 3km, y: 5.5m };
const map = obj.to_map();
assert_eq(map.get("x"), 3km);
```
"#.into(),
        params: vector![
            Param { name: "obj".into(), param_type: Type::Void, default: None },
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            if as_ref {
                instructions.push(TO_MAP_REF.clone());
            } else {
                instructions.push(TO_MAP.clone());
            }
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// From Map.
pub fn obj_from_map() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "from_map".into(),
        is_async: false,
        docs: r#"# Obj.from_map(map: map) -> obj
Get the distance between two objects (number of edges that separate them).
```rust
const map = { "x": 0, "y": 0 };
const obj = Obj.from_map(map);
assert_eq(obj.x, 0);
```
"#.into(),
        params: vector![
            Param { name: "map".into(), param_type: Type::Map, default: None },
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(FROM_MAP.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// From ID.
pub fn obj_from_id() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "from_id".into(),
        is_async: false,
        docs: r#"# Obj.from_id(id: str) -> obj
Create a new object reference from an ID. Objects in Stof are references just like data.
```rust
const obj = new { x: 0, y: 0 };
const ptr = Obj.from_id(obj.id());
assert_eq(ptr, obj);
```
"#.into(),
        params: vector![
            Param { name: "id".into(), param_type: Type::Str, default: None },
        ],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(FROM_ID.clone());
            Ok(instructions)
        })
    }
}

#[inline(always)]
/// Dump graph info.
pub fn obj_dump_graph() -> LibFunc {
    LibFunc {
        library: OBJ_LIB.clone(),
        name: "dbg_graph".into(),
        is_async: false,
        docs: r#"# Obj.dbg_graph() -> void
Utility function for dumping the complete graph, helpful for some debugging cases. To dump a specific node, use Std.dbg(..) with the desired object(s).
"#.into(),
        params: vector![],
        return_type: None,
        unbounded_args: false,
        args_to_symbol_table: false,
        func: Arc::new(|_as_ref, _arg_count, _env, _graph| {
            let mut instructions = Instructions::default();
            instructions.push(DUMP.clone());
            Ok(instructions)
        })
    }
}