-
Notifications
You must be signed in to change notification settings - Fork 7
/
inline_BM.h
2587 lines (2259 loc) · 70.5 KB
/
inline_BM.h
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
// file inline_BM.h
// SPDX-License-Identifier: GPL-3.0-or-later
/***
BISMON
Copyright © 2018 - 2022 CEA (Commissariat à l'énergie atomique et aux énergies alternatives)
contributed by Basile Starynkevitch (working at CEA, LIST, France)
<basile@starynkevitch.net> or <basile.starynkevitch@cea.fr>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef INLINE_BM_INCLUDED
#define INLINE_BM_INCLUDED
const char *
basename_BM (const char *f)
{
if (!f)
return "*null*";
const char *lsh = strrchr (f, '/');
if (lsh)
return lsh + 1;
else
return f;
} /* end basename_BM */
pid_t
gettid_BM (void)
{
return syscall (SYS_gettid, 0L);
} /* end gettid_BM */
double
clocktime_BM (clockid_t clid)
{
struct timespec ts = { 0, 0 };
if (clock_gettime (clid, &ts))
return NAN;
return (double) ts.tv_sec + 1.0e-9 * ts.tv_nsec;
}
intptr_t
timetoY2Kmillisec_BM (double t)
{
return (intptr_t) ((t - (double) Y2KEPOCH_BM) * 1000.0);
} /* end timetoY2Kmillisec_BM */
double
Y2Kmillisectotime_BM (intptr_t tt)
{
return (((double) tt * 1.0e-3 + (double) Y2KEPOCH_BM));
} /* end Y2Kmillisectotime_BM */
double
cputime_BM (void)
{
return clocktime_BM (CLOCK_PROCESS_CPUTIME_ID);
} /* end cputime_BM */
double
elapsedtime_BM (void)
{
struct timespec ts = { 0, 0 };
if (clock_gettime (CLOCK_MONOTONIC, &ts))
return NAN;
return (double) (ts.tv_sec - startrealtimespec_BM.tv_sec)
+ 1.0e-9 * (ts.tv_nsec - startrealtimespec_BM.tv_nsec);
} /* end elapsedtime_BM */
void
get_realtimespec_delayedms_BM (struct timespec *pts, unsigned millisec)
{
ASSERT_BM (pts != NULL);
memset (pts, 0, sizeof (struct timespec));
clock_gettime (CLOCK_REALTIME, pts);
pts->tv_nsec += (long) millisec *MILLION_BM;
while (pts->tv_nsec > BILLION_BM)
{
pts->tv_nsec -= (long) BILLION_BM;
pts->tv_sec++;
}
} /* end get_realtimespec_delayedms_BM */
bool
istaggedint_BM (value_tyBM v)
{
return ((uintptr_t) v) & 1;
} /* end istaggedint_BM */
intptr_t
getint_BM (value_tyBM v)
{
if (istaggedint_BM (v))
return ((intptr_t) v) >> 1;
return 0;
} /* end getint_BM */
intptr_t
getintdefault_BM (value_tyBM v, intptr_t def)
{
if (istaggedint_BM (v))
return ((intptr_t) v) >> 1;
return def;
} /* end getintdefault_BM */
value_tyBM
taggedint_BM (intptr_t i)
{
return (value_tyBM) ((i << 1) | 1);
} /* end taggedint_BM */
int
valtype_BM (const value_tyBM v)
{
if (!v)
return tyNone_BM;
if (istaggedint_BM (v))
return tyInt_BM;
if (((uintptr_t) v & 3) == 0)
{
typedhead_tyBM *ht = (typedhead_tyBM *) v;
WEAKASSERT_BM (ht->htyp != 0);
return ht->htyp;
}
return tyNone_BM;
} /* end valtype_BM */
bool
isgenuineval_BM (const value_tyBM v)
{
int ty = valtype_BM (v);
if (ty > type_LASTREAL_BM)
return false;
return ty != tyNone_BM;
} /* end isgenuineval_BM */
objectval_tyBM *
valclass_BM (const value_tyBM v)
{
if (!v)
return NULL;
if (istaggedint_BM (v))
return BMP_int;
if (((uintptr_t) v & 3) == 0)
{
typedhead_tyBM *ht = (typedhead_tyBM *) v;
WEAKASSERT_BM (ht->htyp != 0);
int ty = ht->htyp;
switch (ty)
{
case tyString_BM:
return BMP_string;
case tySet_BM:
return BMP_set;
case tyTuple_BM:
return BMP_tuple;
case tyNode_BM:
return BMP_node;
case tyClosure_BM:
return BMP_closure;
case tyDouble_BM:
return BMP_double_float;
case tyObject_BM:
#ifdef __cplusplus
{
objectval_tyBM *ob = ((objectval_tyBM *) v);
objectval_tyBM *clv = std::atomic_load (&ob->ob_classatomic);
return clv ? : BMP_undefined;
}
#else
{
objectval_tyBM *ob = ((objectval_tyBM *) v);
objectval_tyBM *clv = atomic_load (&ob->ob_aclass);
return clv ? : BMP_undefined;
}
#endif
case tyUnspecified_BM:
return BMP_unspecified;
}
}
#ifndef NDEBUG
weakassertfailureat_BM ("valclass_BM with bad type", __FILE__, __LINE__);
#endif // NDEBUG
return NULL;
} /* end valclass_BM */
hash_tyBM
valhash_BM (const value_tyBM v)
{
if (!v)
return 0;
int ty = valtype_BM (v);
switch (ty)
{
case tyInt_BM:
{
uintptr_t i = getint_BM (v);
hash_tyBM hi = (i & 0x3fffffff) ^ (i % 132594613);
if (hi == 0)
hi = ((i % 594571) & 0xfffffff) + 17;
ASSERT_BM (hi != 0);
return hi;
}
case tyString_BM:
case tySet_BM:
case tyTuple_BM:
case tyNode_BM:
case tyClosure_BM:
case tyObject_BM:
return ((typedhead_tyBM *) v)->hash;
case tyUnspecified_BM:
return 8594623;
default:
return 0;
}
} /* end valhash_BM */
bool
istuple_BM (const value_tyBM v)
{
return (valtype_BM (v) == tyTuple_BM);
} /* end istuple_BM */
const tupleval_tyBM *
tuplecast_BM (const value_tyBM v)
{
return istuple_BM (v) ? (const tupleval_tyBM *) v : NULL;
} /* end tuplecast_BM */
bool
valequal_BM (const value_tyBM v1, const value_tyBM v2)
{
if (v1 == v2)
return true;
int ty1 = valtype_BM (v1);
if (ty1 != valtype_BM (v2))
return false;
if (valhash_BM (v1) != valhash_BM (v2))
return false;
if (ty1 == tyObject_BM)
return false;
return valsamecontent_BM (v1, v2, 0);
} /* end valequal_BM */
int
valcmp_BM (const value_tyBM v1, const value_tyBM v2)
{
extern int valcmpdepth_BM (const value_tyBM v1, const value_tyBM v2,
int depth);
if (v1 == v2)
return 0;
return valcmpdepth_BM (v1, v2, 0);
} /* end valcmp_BM */
void
valarrqsort_BM (value_tyBM * arr, unsigned siz)
{
if (!arr || siz <= 1)
return;
qsort (arr, siz, sizeof (value_tyBM), valqcmp_BM);
} /* end valarrqsort_BM */
rawid_tyBM
objid_BM (const objectval_tyBM * obj)
{
if ((valtype_BM ((value_tyBM) obj) != tyObject_BM))
return (rawid_tyBM)
{
0, 0};
return obj->ob_id;
} /* end objid_BM */
double
objmtime_BM (const objectval_tyBM * obj)
{
if ((valtype_BM ((value_tyBM) obj) != tyObject_BM))
return 0.0;
return obj->ob_mtime;
} /* end objmtime_BM */
intptr_t
objmtimeY2Kmilli_BM (const objectval_tyBM * obj)
{
if ((valtype_BM ((value_tyBM) obj) != tyObject_BM))
return 0;
return timetoY2Kmillisec_BM (obj->ob_mtime);
} /* end objmtimeY2Kmilli_BM */
void
objtouchmtime_BM (objectval_tyBM * obj, double mtime)
{
if ((valtype_BM ((value_tyBM) obj) != tyObject_BM))
return;
obj->ob_mtime = mtime;
} /* end objtouchmtime_BM */
void
objtouchnow_BM (objectval_tyBM * obj)
{
if ((valtype_BM ((value_tyBM) obj) != tyObject_BM))
return;
obj->ob_mtime = clocktime_BM (CLOCK_REALTIME);
} /* end objtouchnow_BM */
objectval_tyBM *
objsignature_BM (const objectval_tyBM * obj)
{
if ((valtype_BM ((value_tyBM) obj) != tyObject_BM))
return NULL;
return obj->ob_sig;
} /* end objsignature_BM */
void *
objroutaddr_BM (const objectval_tyBM * obj, const objectval_tyBM * objsig)
{
if ((valtype_BM ((value_tyBM) obj) != tyObject_BM))
return NULL;
if (obj->ob_sig != objsig)
return NULL;
return obj->ob_routaddr;
} /* end objroutaddr_BM */
objectval_tyBM *
objclass_BM (const objectval_tyBM * obj)
{
if ((valtype_BM ((value_tyBM) obj) != tyObject_BM))
return NULL;
#ifdef __cplusplus
{
objectval_tyBM *clv = std::atomic_load (&obj->ob_classatomic);
return clv ? : BMP_undefined;
}
#else
{
objectval_tyBM *clv = atomic_load (&obj->ob_aclass);
return clv ? : BMP_undefined;
}
#endif
} /* end objclass_BM */
/// object support
bool
isobject_BM (const value_tyBM v)
{
return valtype_BM (v) == tyObject_BM;
} /* end isobject_BM */
bool
objlock_BM (objectval_tyBM * obj)
{
if (valtype_BM (obj) != tyObject_BM)
return false;
if (pthread_mutex_lock (&obj->ob_mutex))
return false;
if (curfailurehandle_BM)
{
ASSERT_BM (curfailurehandle_BM->failh_magic == FAILUREHANDLEMAGIC_BM);
if (curfailurehandle_BM->failh_lockset)
register_failock_BM (curfailurehandle_BM->failh_lockset, obj);
}
return true;
} /* end objlock_BM */
/// this is mostly useful inside asserts, to check that the object was
/// already locked in the same thread.
bool
objislocked_BM (objectval_tyBM * obj)
{
if (valtype_BM (obj) != tyObject_BM)
return false;
int lk = pthread_mutex_trylock (&obj->ob_mutex);
if (lk == 0)
{
pthread_mutex_unlock (&obj->ob_mutex);
return true;
}
return false;
} /* end objislocked_BM */
bool
objunlock_BM (objectval_tyBM * obj)
{
if (valtype_BM (obj) != tyObject_BM)
return false;
if (pthread_mutex_unlock (&obj->ob_mutex))
return false;
if (curfailurehandle_BM)
{
ASSERT_BM (curfailurehandle_BM->failh_magic == FAILUREHANDLEMAGIC_BM);
if (curfailurehandle_BM->failh_lockset)
unregister_failock_BM (curfailurehandle_BM->failh_lockset, obj);
}
return true;
} /* end objunlock_BM */
bool
objtrylock_BM (objectval_tyBM * obj)
{
if (valtype_BM (obj) != tyObject_BM)
return false;
if (pthread_mutex_trylock (&obj->ob_mutex))
return false;
if (curfailurehandle_BM)
{
ASSERT_BM (curfailurehandle_BM->failh_magic == FAILUREHANDLEMAGIC_BM);
register_failock_BM (curfailurehandle_BM->failh_lockset, obj);
};
return true;
} /* end objtrylock_BM */
objectval_tyBM *
objectcast_BM (const value_tyBM v)
{
return isobject_BM (v) ? (objectval_tyBM *) v : NULL;
} /* end objectcast_BM */
hash_tyBM
objecthash_BM (const objectval_tyBM * pob)
{
if (!isobject_BM ((value_tyBM) pob))
return 0;
hash_tyBM h = ((typedhead_tyBM *) pob)->hash;
ASSERT_BM (h > 0);
ASSERT_BM (h == hashid_BM (pob->ob_id));
return h;
} /* end objecthash_BM */
unsigned
objspacenum_BM (const objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return 0;
return obj->ob_space;
} /* end objspacenum_BM */
value_tyBM
objgetattr_BM (const objectval_tyBM * obj, const objectval_tyBM * objattr)
{
if (!isobject_BM ((value_tyBM) obj))
return NULL;
if (!isobject_BM ((value_tyBM) objattr))
return NULL;
if (!obj->ob_attrassoc)
return NULL;
return assoc_getattr_BM (obj->ob_attrassoc, objattr);
} /* end objgetattr_BM */
unsigned
objnbattrs_BM (const objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return 0;
if (!obj->ob_attrassoc)
return 0;
return assoc_nbkeys_BM (obj->ob_attrassoc);
} /* end objnbattrs_BM */
unsigned
objnbcomps_BM (const objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return 0;
if (!obj->ob_compvec)
return 0;
return datavectlen_BM (obj->ob_compvec);
} /* end objnbcomps_BM */
value_tyBM *
objcompdata_BM (const objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return NULL;
if (!obj->ob_compvec)
return NULL;
return (value_tyBM *) datavectdata_BM (obj->ob_compvec);
} /* end objcompdata_BM */
const setval_tyBM *
objsetattrs_BM (const objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return NULL;
if (!obj->ob_attrassoc)
return NULL;
return assoc_setattrs_BM (obj->ob_attrassoc);
} /* end objsetattrs_BM */
value_tyBM
objgetcomp_BM (const objectval_tyBM * obj, int rk)
{
if (!isobject_BM ((value_tyBM) obj))
return NULL;
if (!obj->ob_compvec)
return NULL;
return datavectnth_BM (obj->ob_compvec, rk);
} /* end objgetcomp_BM */
value_tyBM
objlastcomp_BM (const objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return NULL;
if (!obj->ob_compvec)
return NULL;
return datavectlast_BM (obj->ob_compvec);
} /* end objlastcomp_BM */
void
objputcomp_BM (objectval_tyBM * obj, int rk, const value_tyBM valcomp)
{
if (!isobject_BM ((value_tyBM) obj))
return;
if (!obj->ob_compvec)
return;
if (!valcomp || isgenuineval_BM (valcomp))
datavectputnth_BM (obj->ob_compvec, rk, valcomp);
} /* end objputcomp_BM */
void
objpoplastcomp_BM (objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return;
if (!obj->ob_compvec)
return;
obj->ob_compvec = datavect_pop_BM (obj->ob_compvec);
} /* end objpoplastcomp_BM */
void
objreservecomps_BM (objectval_tyBM * obj, unsigned gap)
{
if (!isobject_BM ((value_tyBM) obj))
return;
obj->ob_compvec = datavect_reserve_BM (obj->ob_compvec, gap);
} /* end objreservecomps_BM */
void
objremoveonecomp_BM (objectval_tyBM * obj, int rk)
{
if (!isobject_BM ((value_tyBM) obj) || !obj->ob_compvec)
return;
obj->ob_compvec = datavect_removeone_BM (obj->ob_compvec, rk);
} /* end objremoveonecomp_BM */
void
objinsertonecomp_BM (objectval_tyBM * obj, int rk, const value_tyBM compval)
{
if (!isobject_BM ((value_tyBM) obj))
return;
obj->ob_compvec = datavect_insertone_BM (obj->ob_compvec, rk, compval);
} /* end objinsertonecomp_BM */
void
objresetcomps_BM (objectval_tyBM * obj, unsigned len)
{
if (!isobject_BM ((value_tyBM) obj))
return;
obj->ob_compvec = datavect_reserve_BM (NULL, len);
} /* end objresetcomps_BM */
void
objappendcomp_BM (objectval_tyBM * obj, value_tyBM compval)
{
if (!isobject_BM ((value_tyBM) obj))
return;
if (compval && !isgenuineval_BM (compval))
return;
obj->ob_compvec = datavect_append_BM (obj->ob_compvec, compval);
} /* end objappendcomp_BM */
void
objgrowcomps_BM (objectval_tyBM * obj, unsigned gap)
{
if (!isobject_BM ((value_tyBM) obj))
return;
obj->ob_compvec = datavect_grow_BM (obj->ob_compvec, gap);
} /* end objgrowcomps_BM */
extendedval_tyBM
objpayload_BM (const objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return NULL;
return obj->ob_payl;
} /* end objpayload_BM */
void
objclearpayload_BM (objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj) || obj == BMP_contributors)
return;
extendedval_tyBM payl = obj->ob_payl;
if (!payl)
return;
obj->ob_payl = NULL;
deleteobjectpayload_BM (obj, payl);
} /* end objclearpayload_BM */
void
objputpayload_BM (objectval_tyBM * obj, extendedval_tyBM payl)
{
if (!isobject_BM ((value_tyBM) obj))
return;
extendedval_tyBM oldpayl = obj->ob_payl;
if (oldpayl == payl)
return;
obj->ob_payl = NULL;
if (oldpayl)
deleteobjectpayload_BM (obj, oldpayl);
obj->ob_payl = payl;
} /* end objputpayload_BM */
bool
objhasclassinfo_BM (const objectval_tyBM * obj)
{
extendedval_tyBM payl = objpayload_BM (obj);
if (!payl)
return false;
return (valtype_BM ((value_tyBM) payl) == typayl_classinfo_BM);
} /* end objhasclassinfo_BM */
objectval_tyBM *
objgetclassinfosuperclass_BM (const objectval_tyBM * obj)
{
if (!objhasclassinfo_BM (obj))
return NULL;
struct classinfo_stBM *clinf = //
(struct classinfo_stBM *) (obj->ob_payl);
ASSERT_BM (valtype_BM ((value_tyBM) clinf) == typayl_classinfo_BM);
objectval_tyBM *superob = clinf->clinf_superclass;
ASSERT_BM (!superob || isobject_BM ((value_tyBM) superob));
return superob;
} /* end objgetclassinfosuperclass_BM */
bool
objectisinstance_BM (const objectval_tyBM * obj,
const objectval_tyBM * obclass)
{
if (!objhasclassinfo_BM (obclass))
return false;
if (!isobject_BM ((value_tyBM) obj))
return false;
return objclassinfoissubclass_BM (objclass_BM (obj), obclass);
} /* end objectisinstance_BM */
const closure_tyBM *
objgetclassinfomethod_BM (const objectval_tyBM * obj,
const objectval_tyBM * obselector)
{
if (!objhasclassinfo_BM (obj))
return NULL;
if (!isobject_BM ((value_tyBM) obselector))
return NULL;
struct classinfo_stBM *clinf = //
(struct classinfo_stBM *) (obj->ob_payl);
ASSERT_BM (valtype_BM ((value_tyBM) clinf) == typayl_classinfo_BM);
const closure_tyBM *clos = (const closure_tyBM *) //
assoc_getattr_BM (clinf->clinf_dictmeth,
obselector);
ASSERT_BM (!clos || isclosure_BM ((value_tyBM) clos));
return clos;
} /* end objgetclassinfomethod_BM */
const setval_tyBM * //
objgetclassinfosetofselectors_BM (const objectval_tyBM * obj)
{
if (!objhasclassinfo_BM (obj))
return NULL;
struct classinfo_stBM *clinf = //
(struct classinfo_stBM *) (obj->ob_payl);
ASSERT_BM (valtype_BM ((value_tyBM) clinf) == typayl_classinfo_BM);
const setval_tyBM *set = //
assoc_setattrs_BM (clinf->clinf_dictmeth);
ASSERT_BM (!set || valtype_BM ((value_tyBM) set) == tySet_BM);
return set;
} /* end objgetclassinfosetofselectors_BM */
////////////////////////////////////////////////////////////////
bool
objhasstrbufferpayl_BM (const objectval_tyBM * obj)
{
extendedval_tyBM payl = objpayload_BM (obj);
if (!payl)
return false;
int pt = valtype_BM ((value_tyBM) payl);
return (pt == typayl_strbuffer_BM );
} /* end objhasstrbuffer_BM */
struct strbuffer_stBM *
objgetstrbufferpayl_BM (objectval_tyBM * obj)
{
extendedval_tyBM payl = objpayload_BM (obj);
if (!payl)
return NULL;
int pt = valtype_BM ((value_tyBM) payl);
if (pt == typayl_strbuffer_BM)
return (struct strbuffer_stBM *) payl;
return NULL;
} /* end objgetstrbufferpayl_BM */
////////////////
int
objectcmp_BM (const objectval_tyBM * ob1, const objectval_tyBM * ob2)
{
if (ob1 == ob2)
return 0;
if (ob1
&& (((intptr_t) ob1 & 3)
|| ((typedhead_tyBM *) ob1)->htyp != tyObject_BM))
FATAL_BM ("bad ob1@%p for objectcmp_BM", ob1);
if (ob2
&& (((intptr_t) ob1 & 3)
|| ((typedhead_tyBM *) ob2)->htyp != tyObject_BM))
FATAL_BM ("bad ob2@%p for objectcmp_BM", ob2);
if (!ob1)
return -1;
if (!ob2)
return +1;
return cmpid_BM (ob1->ob_id, ob2->ob_id);
} /* end objectcmp_BM */
int
objectnamedcmp_BM (const objectval_tyBM * ob1, const objectval_tyBM * ob2)
{
if (ob1 == ob2)
return 0;
if (!ob1)
return -1;
if (!ob2)
return +1;
ASSERT_BM (isobject_BM ((value_tyBM) ob1));
ASSERT_BM (isobject_BM ((value_tyBM) ob2));
const char *n1 = findobjectname_BM (ob1);
const char *n2 = findobjectname_BM (ob2);
if (n1 && n2)
return strcmp (n1, n2);
if (n1)
return -1;
if (n2)
return +1;
return objectcmp_BM (ob1, ob2);
} /* end objectnamedcmp_BM */
////////////////////////////////////////////////////////////////
bool
isassoc_BM (const value_tyBM v)
{
int ty = valtype_BM (v);
return ty == typayl_assoctable_BM || ty == typayl_assocpairs_BM;
} /* end isassoc_BM */
anyassoc_tyBM *
assoccast_BM (value_tyBM v)
{
if (isassoc_BM (v))
return (anyassoc_tyBM *) v;
return NULL;
} /* end assoccast_BM */
anyassoc_tyBM *
make_assoc_BM (unsigned len)
{
anyassoc_tyBM *res = NULL;
assoc_reorganize_BM (&res, len);
return res;
} /* end make_assoc_BM */
bool
objhasassocpayl_BM (const objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return false;
extendedval_tyBM payl = objpayload_BM (obj);
if (!payl)
return false;
return isassoc_BM (payl);
} /* end objhasassocpayl_BM */
anyassoc_tyBM *
objgetassocpayl_BM (objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return NULL;
extendedval_tyBM payl = objpayload_BM (obj);
if (!payl)
return NULL;
return assoccast_BM (payl);
} /* end objgetassocpayl_BM */
const setval_tyBM *
objassocsetattrspayl_BM (objectval_tyBM * obj)
{
anyassoc_tyBM *asso = objgetassocpayl_BM (obj);
if (!asso)
return NULL;
return assoc_setattrs_BM (asso);
} /* end objassocsetattrspayl_BM */
unsigned
objassocnbkeyspayl_BM (const objectval_tyBM * obj)
{
anyassoc_tyBM *asso = objgetassocpayl_BM ((objectval_tyBM *) obj);
if (!asso)
return 0;
return assoc_nbkeys_BM (asso);
} /* end objassocnbkeyspayl_BM */
value_tyBM
objassocgetattrpayl_BM (objectval_tyBM * obj, const objectval_tyBM * obattr)
{
anyassoc_tyBM *asso = objgetassocpayl_BM (obj);
if (!asso)
return NULL;
if (!isobject_BM ((value_tyBM) obattr))
return NULL;
return assoc_getattr_BM (asso, obattr);
} /* end objassocgetattrpayl_BM */
void
objassocaddattrpayl_BM (objectval_tyBM * obj,
const objectval_tyBM * obattr, value_tyBM val)
{
anyassoc_tyBM *asso = objgetassocpayl_BM (obj);
if (!asso)
return;
if (!isobject_BM ((value_tyBM) obattr))
return;
anyassoc_tyBM *newasso = assoc_addattr_BM (asso, obattr, val);
if (newasso != asso)
obj->ob_payl = newasso;
} /* end objassocaddattrpayl_BM */
void
objassocremoveattrpayl_BM (objectval_tyBM * obj,
const objectval_tyBM * obattr)
{
anyassoc_tyBM *asso = objgetassocpayl_BM (obj);
if (!asso)
return;
if (!isobject_BM ((value_tyBM) obattr))
return;
anyassoc_tyBM *newasso = assoc_removeattr_BM (asso, obattr);
if (newasso != asso)
objputpayload_BM (obj, newasso);
} /* end objassocremoveattrpayl_BM */
void
objassocreorganizepayl_BM (objectval_tyBM * obj, unsigned gap)
{
anyassoc_tyBM *asso = objgetassocpayl_BM (obj);
if (!asso)
return;
assoc_reorganize_BM (&asso, gap);
anyassoc_tyBM *newasso = asso;
if (newasso != asso)
objputpayload_BM (obj, newasso);
} /* end objassocreorganizepayl_BM */
////////////////
unsigned
datavectlen_BM (const struct datavectval_stBM *dvec)
{
if (valtype_BM ((value_tyBM) dvec) != typayl_vectval_BM)
return 0;
return ((typedsize_tyBM *) dvec)->size;
} /* end datavectlen_BM */
const value_tyBM *
datavectdata_BM (const struct datavectval_stBM *dvec)
{
if (valtype_BM ((value_tyBM) dvec) != typayl_vectval_BM)
return NULL;
return dvec->vec_data;
} /* end datavectdata_BM */
value_tyBM
datavectnth_BM (const struct datavectval_stBM *dvec, int rk)
{
unsigned sz = datavectlen_BM (dvec);
if (rk < 0)
rk += (int) sz;
if (rk >= 0 && rk < (int) sz)
return dvec->vec_data[rk];
return NULL;
} /* end datavectnth_BM */
value_tyBM
datavectlast_BM (const struct datavectval_stBM *dvec)
{
unsigned sz = datavectlen_BM (dvec);
if (!sz)
return NULL;
return dvec->vec_data[sz - 1];
} /* end datavectlast_BM */
void
datavectputnth_BM (struct datavectval_stBM *dvec,
int rk, const value_tyBM valcomp)
{
unsigned sz = datavectlen_BM (dvec);
if (rk < 0)
rk += (int) sz;
if (rk >= 0 && rk < (int) sz)
dvec->vec_data[rk] = valcomp;
} /* end datavectputnth_BM */
struct datavectval_stBM *
datavect_insertone_BM (struct datavectval_stBM *dvec, int rk, value_tyBM val)
{
return datavect_insert_BM (dvec, rk, &val, 1);
} /* end datavect_insertone_BM */
////////////////
struct datavectval_stBM *
objgetdatavectpayl_BM (objectval_tyBM * obj)
{
if (!isobject_BM ((value_tyBM) obj))
return NULL;
void *payl = obj->ob_payl;
if (!payl)
return NULL;
if (valtype_BM (payl) == typayl_vectval_BM)
return (struct datavectval_stBM *) payl;
return NULL;
} /* end objgetdatavectpayl_BM */
bool
objhasdatavectpayl_BM (objectval_tyBM * obj)
{
return objgetdatavectpayl_BM (obj) != NULL;
} /* end objhasdatavectpayl_BM */
unsigned
objdatavectlengthpayl_BM (objectval_tyBM * obj)
{
struct datavectval_stBM *dvec = objgetdatavectpayl_BM (obj);
if (dvec)
return datavectlen_BM (dvec);
return 0;
} /* end objdatavectlengthpayl_BM */
const value_tyBM *
objdatavectdatapayl_BM (objectval_tyBM * obj)
{
struct datavectval_stBM *dvec = objgetdatavectpayl_BM (obj);
if (dvec)
return datavectdata_BM (dvec);
return NULL;
} /* end objdatavectdatapayl_BM */
void
objdatavectgrowpayl_BM (objectval_tyBM * obj, unsigned gap)
{
struct datavectval_stBM *dvec = objgetdatavectpayl_BM (obj);