-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathffitest.c
1602 lines (1266 loc) · 58.5 KB
/
ffitest.c
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
/* s7 ffi tester
*
* gcc -o ffitest ffitest.c -g3 -Wall s7.o -lm -I. -ldl
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "s7.h"
#define TO_STR(x) s7_object_to_c_string(sc, x)
#define TO_S7_INT(x) s7_make_integer(sc, x)
static s7_pointer a_function(s7_scheme *sc, s7_pointer args)
{
return(s7_car(args));
}
static s7_pointer test_hook_function(s7_scheme *sc, s7_pointer args)
{
s7_pointer val;
val = s7_symbol_local_value(sc, s7_make_symbol(sc, "a"), s7_car(args));
if ((!s7_is_integer(val)) ||
(s7_integer(val) != 1))
{
char *s1;
s1 = TO_STR(val);
fprintf(stderr, "%d: (hook 'a) is %s\n", __LINE__, s1);
free(s1);
}
return(val);
}
static char last_c;
static void my_print(s7_scheme *sc, unsigned char c, s7_pointer port)
{
last_c = c;
}
static s7_pointer my_read(s7_scheme *sc, s7_read_t peek, s7_pointer port)
{
return(s7_make_character(sc, '0'));
}
static bool tested_begin_hook = false;
static void test_begin_hook(s7_scheme *sc, bool *val)
{
tested_begin_hook = true;
}
static s7_pointer test_error_handler(s7_scheme *sc, s7_pointer args)
{
s7_display(sc, s7_make_symbol(sc, "error!"), s7_current_error_port(sc));
return(s7_f(sc));
}
static s7_pointer set_sym, set_val;
static s7_pointer scheme_set_notification(s7_scheme *sc, s7_pointer args)
{
set_sym = s7_car(args);
set_val = s7_cadr(args);
return(set_val);
}
typedef struct {
s7_double x;
s7_pointer data;
} dax;
static char *print_dax(s7_scheme *sc, void *val)
{
char *data_str, *str;
int data_str_len;
dax *o = (dax *)val;
data_str = s7_object_to_c_string(sc, o->data);
data_str_len = strlen(data_str);
str = (char *)calloc(data_str_len + 32, sizeof(char));
snprintf(str, data_str_len + 32, "#<dax %.3f %s>", o->x, data_str);
free(data_str);
return(str);
}
static void free_dax(void *val)
{
if (val) free(val);
}
static bool equal_dax(void *val1, void *val2)
{
return(val1 == val2);
}
static void mark_dax(void *val)
{
dax *o = (dax *)val;
if (o) s7_mark_object(o->data);
}
static int dax_type_tag = 0;
static s7_pointer make_dax(s7_scheme *sc, s7_pointer args)
{
dax *o;
o = (dax *)malloc(sizeof(dax));
o->x = s7_real(s7_car(args));
if (s7_cdr(args) != s7_nil(sc))
o->data = s7_car(s7_cdr(args));
else o->data = s7_nil(sc);
return(s7_make_object(sc, dax_type_tag, (void *)o));
}
static s7_pointer is_dax(s7_scheme *sc, s7_pointer args)
{
return(s7_make_boolean(sc,
s7_is_object(s7_car(args)) &&
s7_object_type(s7_car(args)) == dax_type_tag));
}
static s7_pointer dax_x(s7_scheme *sc, s7_pointer args)
{
dax *o;
o = (dax *)s7_object_value(s7_car(args));
return(s7_make_real(sc, o->x));
}
static s7_pointer set_dax_x(s7_scheme *sc, s7_pointer args)
{
dax *o;
o = (dax *)s7_object_value(s7_car(args));
o->x = s7_real(s7_car(s7_cdr(args)));
return(s7_car(s7_cdr(args)));
}
static s7_pointer dax_data(s7_scheme *sc, s7_pointer args)
{
dax *o;
o = (dax *)s7_object_value(s7_car(args));
return(o->data);
}
static s7_pointer set_dax_data(s7_scheme *sc, s7_pointer args)
{
dax *o;
o = (dax *)s7_object_value(s7_car(args));
o->data = s7_car(s7_cdr(args));
return(o->data);
}
static s7_pointer plus(s7_scheme *sc, s7_pointer args)
{
/* (define* (plus (red 32) blue) (+ (* 2 red) blue)) */
return(TO_S7_INT(2 * s7_integer(s7_car(args)) + s7_integer(s7_car(s7_cdr(args)))));
}
static s7_pointer mac_plus(s7_scheme *sc, s7_pointer args)
{
/* (define-macro (plus a b) `(+ ,a ,b)) */
s7_pointer a, b;
a = s7_car(args);
b = s7_cadr(args);
return(s7_list(sc, 3, s7_make_symbol(sc, "+"), a, b));
}
static s7_pointer mac_plus_mv(s7_scheme *sc, s7_pointer args)
{
/* (define-macro (plus-mv a b) (values `(define a ,a) `(define b ,b))) */
return(s7_values(sc, args));
}
static s7_pointer open_plus(s7_scheme *sc, s7_pointer args)
{
#define plus_help "(plus obj ...) applies obj's plus method to obj and any trailing arguments."
s7_pointer obj, method;
obj = s7_car(args);
if (s7_is_openlet(obj))
{
method = s7_method(sc, obj, s7_make_symbol(sc, "plus"));
if (s7_is_procedure(method))
return(s7_apply_function(sc, method, s7_cdr(args)));
}
return(s7_f(sc));
}
static s7_pointer multivector_ref(s7_scheme *sc, s7_pointer vector, int indices, ...)
{
/* multivector_ref returns an element of a multidimensional vector */
int ndims;
ndims = s7_vector_rank(vector);
if (ndims == indices)
{
va_list ap;
s7_int index = 0;
va_start(ap, indices);
if (ndims == 1)
{
index = va_arg(ap, s7_int);
va_end(ap);
return(s7_vector_ref(sc, vector, index));
}
else
{
int i;
s7_pointer *elements;
s7_int *offsets, *dimensions;
elements = s7_vector_elements(vector);
dimensions = s7_vector_dimensions(vector);
offsets = s7_vector_offsets(vector);
for (i = 0; i < indices; i++)
{
int ind;
ind = va_arg(ap, int);
if ((ind < 0) ||
(ind >= dimensions[i]))
{
va_end(ap);
return(s7_out_of_range_error(sc,
"multivector_ref", i,
s7_make_integer(sc, ind),
"index should be between 0 and the dimension size"));
}
index += (ind * offsets[i]);
}
va_end(ap);
return(elements[index]);
}
}
return(s7_wrong_number_of_args_error(sc,
"multivector_ref: wrong number of indices: ~A",
s7_make_integer(sc, indices)));
}
typedef struct {
size_t size;
double *data;
} g_block;
static int g_block_type = 0;
static s7_pointer g_block_methods;
static s7_pointer g_make_block(s7_scheme *sc, s7_pointer args)
{
#define g_make_block_help "(make-block size) returns a new block of the given size"
g_block *g;
s7_pointer new_g;
g = (g_block *)calloc(1, sizeof(g_block));
g->size = (size_t)s7_integer(s7_car(args));
g->data = (double *)calloc(g->size, sizeof(double));
new_g = s7_make_object(sc, g_block_type, (void *)g);
s7_object_set_let(new_g, g_block_methods);
s7_openlet(sc, new_g);
return(new_g);
}
static s7_pointer g_to_block(s7_scheme *sc, s7_pointer args)
{
#define g_block_help "(block ...) returns a block object with the arguments as its contents."
s7_pointer p, b;
size_t i, len;
g_block *gb;
len = s7_list_length(sc, args);
b = g_make_block(sc, s7_cons(sc, s7_make_integer(sc, len), s7_nil(sc)));
gb = (g_block *)s7_object_value(b);
for (i = 0, p = args; i < len; i++, p = s7_cdr(p))
gb->data[i] = s7_number_to_real(sc, s7_car(p));
return(b);
}
static char *g_block_display(s7_scheme *sc, void *value)
{
return(strdup("#<block>"));
}
static void g_block_free(void *value)
{
g_block *g = (g_block *)value;
free(g->data);
free(g);
}
static bool g_block_is_equal(void *val1, void *val2)
{
return(val1 == val2);
}
static void g_block_mark(void *val)
{
/* nothing to mark */
}
static s7_pointer g_block_ref(s7_scheme *sc, s7_pointer obj, s7_pointer args)
{
g_block *g = (g_block *)s7_object_value(obj);
size_t index;
index = (size_t)s7_integer(s7_car(args));
if (index < g->size)
return(s7_make_real(sc, g->data[index]));
return(s7_out_of_range_error(sc, "block-ref", 2, s7_car(args), "should be less than block length"));
}
static s7_pointer g_block_set(s7_scheme *sc, s7_pointer obj, s7_pointer args)
{
g_block *g = (g_block *)s7_object_value(obj);
s7_int index;
index = s7_integer(s7_car(args));
if ((index >= 0) && (index < g->size))
{
g->data[index] = s7_number_to_real(sc, s7_cadr(args));
return(s7_cadr(args));
}
return(s7_out_of_range_error(sc, "block-set", 2, s7_car(args), "should be less than block length"));
}
static s7_pointer g_block_length(s7_scheme *sc, s7_pointer obj)
{
g_block *g = (g_block *)s7_object_value(obj);
return(s7_make_integer(sc, g->size));
}
static s7_pointer g_block_copy(s7_scheme *sc, s7_pointer args)
{
s7_pointer obj, new_g;
g_block *g, *g1;
obj = s7_car(args);
g = (g_block *)s7_object_value(obj);
new_g = g_make_block(sc, s7_cons(sc, s7_make_integer(sc, g->size), s7_nil(sc)));
g1 = (g_block *)s7_object_value(new_g);
memcpy((void *)(g1->data), (void *)(g->data), g->size * sizeof(double));
return(new_g);
}
static s7_pointer g_block_reverse(s7_scheme *sc, s7_pointer obj)
{
size_t i, j;
g_block *g = (g_block *)s7_object_value(obj);
g_block *g1;
s7_pointer new_g;
new_g = g_make_block(sc, s7_cons(sc, s7_make_integer(sc, g->size), s7_nil(sc)));
g1 = (g_block *)s7_object_value(new_g);
for (i = 0, j = g->size - 1; i < g->size; i++, j--)
g1->data[i] = g->data[j];
return(new_g);
}
static s7_pointer g_block_fill(s7_scheme *sc, s7_pointer args)
{
s7_pointer obj;
size_t i;
double fill_val;
g_block *g;
obj = s7_car(args);
g = (g_block *)s7_object_value(obj);
fill_val = s7_number_to_real(sc, s7_cadr(args));
for (i = 0; i < g->size; i++)
g->data[i] = fill_val;
return(obj);
}
int main(int argc, char **argv)
{
s7_scheme *sc;
s7_pointer p, p1;
int i, gc_loc;
char *s1, *s2;
sc = s7_init();
/* try each straight (no errors) case */
if (!s7_is_null(sc, s7_nil(sc)))
{fprintf(stderr, "%d: %s is not null?\n", __LINE__, s1 = TO_STR(s7_nil(sc))); free(s1);}
if (s7_is_pair(s7_nil(sc)))
{fprintf(stderr, "%d: %s is a pair?\n", __LINE__, s1 = TO_STR(s7_nil(sc))); free(s1);}
if (!s7_is_boolean(s7_t(sc)))
{fprintf(stderr, "%d: %s is not boolean?\n", __LINE__, s1 = TO_STR(s7_t(sc))); free(s1);}
if (!s7_is_boolean(s7_f(sc)))
{fprintf(stderr, "%d: %s is not boolean?\n", __LINE__, s1 = TO_STR(s7_f(sc))); free(s1);}
if (s7_boolean(sc, s7_f(sc)))
{fprintf(stderr, "%d: %s is #t?\n", __LINE__, s1 = TO_STR(s7_f(sc))); free(s1);}
if (!s7_boolean(sc, s7_t(sc)))
{fprintf(stderr, "%d: %s is #f?\n", __LINE__, s1 = TO_STR(s7_t(sc))); free(s1);}
p = s7_make_boolean(sc, true);
if (p != s7_t(sc))
{fprintf(stderr, "%d: %s is not #t?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_make_boolean(sc, false);
if (p != s7_f(sc))
{fprintf(stderr, "%d: %s is not #f?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_eq(s7_f(sc), s7_f(sc)))
{fprintf(stderr, "%d: (eq? %s %s) -> #f?\n", __LINE__, s1 = TO_STR(s7_f(sc)), s2 = TO_STR(s7_f(sc))); free(s1); free(s2);}
if (!s7_is_eqv(s7_f(sc), s7_f(sc)))
{fprintf(stderr, "%d: (eqv? %s %s) -> #f?\n", __LINE__, s1 = TO_STR(s7_f(sc)), s2 = TO_STR(s7_f(sc))); free(s1); free(s2);}
if (!s7_is_equal(sc, s7_f(sc), s7_f(sc)))
{fprintf(stderr, "%d: (equal? %s %s) -> #f?\n", __LINE__, s1 = TO_STR(s7_f(sc)), s2 = TO_STR(s7_f(sc))); free(s1); free(s2);}
if (!s7_is_unspecified(sc, s7_unspecified(sc)))
{fprintf(stderr, "%d: %s is not #<unspecified>?\n", __LINE__, s1 = TO_STR(s7_unspecified(sc))); free(s1);}
if (s7_is_eq(s7_eof_object(sc), s7_undefined(sc)))
{fprintf(stderr, "%d: (eq? %s %s) -> #t?\n", __LINE__, s1 = TO_STR(s7_eof_object(sc)), s2 = TO_STR(s7_undefined(sc))); free(s1); free(s2);}
if (s7_is_eqv(s7_eof_object(sc), s7_undefined(sc)))
{fprintf(stderr, "%d: (eqv? %s %s) -> #t?\n", __LINE__, s1 = TO_STR(s7_eof_object(sc)), s2 = TO_STR(s7_undefined(sc))); free(s1); free(s2);}
if (s7_is_equal(sc, s7_eof_object(sc), s7_undefined(sc)))
{fprintf(stderr, "%d: (equal? %s %s) -> #t?\n", __LINE__, s1 = TO_STR(s7_eof_object(sc)), s2 = TO_STR(s7_undefined(sc))); free(s1); free(s2);}
if (!s7_is_valid(sc, s7_t(sc)))
{fprintf(stderr, "%d: %s is not valid?\n", __LINE__, s1 = TO_STR(s7_t(sc))); free(s1);}
if (s7_is_c_pointer(s7_t(sc)))
{fprintf(stderr, "%d: %s is a raw c pointer?\n", __LINE__, s1 = TO_STR(s7_t(sc))); free(s1);}
i = 32;
p = s7_make_c_pointer(sc, (void *)(&i));
if (!s7_is_c_pointer(p))
{fprintf(stderr, "%d: %s is not a raw c pointer?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
i = (*((int *)s7_c_pointer(p)));
if (i != 32)
fprintf(stderr, "%d: 32 -> %d via raw c pointer?\n", __LINE__, i);
s7_provide(sc, "ffitest");
if (!s7_is_provided(sc, "ffitest"))
{fprintf(stderr, "%d: *features* %s doesn't provide 'ffitest?\n", __LINE__, s1 = TO_STR(s7_name_to_value(sc, "*features*"))); free(s1);}
p = s7_cons(sc, s7_f(sc), s7_t(sc));
gc_loc = s7_gc_protect(sc, p);
if (p != s7_gc_protected_at(sc, gc_loc))
{fprintf(stderr, "%d: %s is not gc protected at %d: %s?\n", __LINE__, s1 = TO_STR(p), gc_loc, s2 = TO_STR(s7_gc_protected_at(sc, gc_loc))); free(s1); free(s2);}
if (s7_car(p) != s7_f(sc))
{fprintf(stderr, "%d: (car %s) is not #f?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_cdr(p) != s7_t(sc))
{fprintf(stderr, "%d: (cdr %s) is not #t?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_pair(p))
{fprintf(stderr, "%d: %s is not a pair?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_set_car(p, s7_eof_object(sc));
if (s7_car(p) != s7_eof_object(sc))
{fprintf(stderr, "%d: (car %s) is not #<eof>?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_set_cdr(p, s7_unspecified(sc));
if (s7_cdr(p) != s7_unspecified(sc))
{fprintf(stderr, "%d: (cdr %s) is not #<unspecified>?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
p = TO_S7_INT(123);
gc_loc = s7_gc_protect(sc, p);
if (!s7_is_integer(p))
{fprintf(stderr, "%d: %s is not integral?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_rational(p))
{fprintf(stderr, "%d: %s is not rational?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_is_ratio(p))
{fprintf(stderr, "%d: %s is a ratio?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_real(p))
{fprintf(stderr, "%d: %s is not real?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_complex(p))
{fprintf(stderr, "%d: %s is not complex?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_number(p))
{fprintf(stderr, "%d: %s is not complex?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p) != 123)
{fprintf(stderr, "%d: %s is not 123?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s2 = s7_number_to_string(sc, p, 10);
if (strcmp(s2, "123") != 0)
{fprintf(stderr, "%d: (number->string %s) is not \"123\"?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
free(s2);
if (s7_number_to_integer(sc, p) != 123)
{fprintf(stderr, "%d: s7_number_to_integer %s is not 123?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
p = s7_make_ratio(sc, 123, 5);
gc_loc = s7_gc_protect(sc, p);
if (s7_is_integer(p))
{fprintf(stderr, "%d: %s is integral?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_rational(p))
{fprintf(stderr, "%d: %s is not rational?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_ratio(p))
{fprintf(stderr, "%d: %s is not a ratio?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_real(p))
{fprintf(stderr, "%d: %s is not real?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_complex(p))
{fprintf(stderr, "%d: %s is not complex?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_number(p))
{fprintf(stderr, "%d: %s is not complex?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_numerator(p) != 123)
{fprintf(stderr, "%d: (numerator %s) is not 123?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_denominator(p) != 5)
{fprintf(stderr, "%d: (denominator %s) is not 5?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s2 = s7_number_to_string(sc, p, 10);
if (strcmp(s2, "123/5") != 0)
{fprintf(stderr, "%d: (number->string %s) is not \"123/5\"?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
free(s2);
s7_gc_unprotect_at(sc, gc_loc);
p = s7_make_real(sc, 1.5);
gc_loc = s7_gc_protect(sc, p);
if (s7_is_integer(p))
{fprintf(stderr, "%d: %s is integral?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_is_rational(p))
{fprintf(stderr, "%d: %s is rational?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_is_ratio(p))
{fprintf(stderr, "%d: %s is a ratio?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_real(p))
{fprintf(stderr, "%d: %s is not real?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_complex(p))
{fprintf(stderr, "%d: %s is not complex?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_number(p))
{fprintf(stderr, "%d: %s is not complex?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_real(p) != 1.5)
{fprintf(stderr, "%d: %s is not 1.5?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s2 = s7_number_to_string(sc, p, 10);
if (strcmp(s2, "1.5") != 0)
{fprintf(stderr, "%d: (number->string %s) is not \"1.5\"?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
free(s2);
if (s7_number_to_real(sc, p) != 1.5)
{fprintf(stderr, "%d: s7_number_to_real %s is not 1.5?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
p = s7_make_complex(sc, 1.0, 1.0);
gc_loc = s7_gc_protect(sc, p);
if (s7_is_integer(p))
{fprintf(stderr, "%d: %s is integral?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_is_rational(p))
{fprintf(stderr, "%d: %s is rational?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_is_ratio(p))
{fprintf(stderr, "%d: %s is a ratio?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_is_real(p))
{fprintf(stderr, "%d: %s is real?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_complex(p))
{fprintf(stderr, "%d: %s is not complex?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_number(p))
{fprintf(stderr, "%d: %s is not complex?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_real_part(p) != 1.0)
{fprintf(stderr, "%d: (real-part %s) is not 1.0?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_imag_part(p) != 1.0)
{fprintf(stderr, "%d: (imag-part %s) is not 1.0?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s2 = s7_number_to_string(sc, p, 10);
if (strcmp(s2, "1+1i") != 0)
{fprintf(stderr, "%d: (number->string %s) is not \"1+1i\"?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
free(s2);
s7_gc_unprotect_at(sc, gc_loc);
p = s7_rationalize(sc, 1.5, 1e-12);
gc_loc = s7_gc_protect(sc, p);
s1 = TO_STR(p);
if (strcmp(s1, "3/2") != 0)
fprintf(stderr, "%d: ratio is %s?\n", __LINE__, s1);
free(s1);
s7_gc_unprotect_at(sc, gc_loc);
p = s7_make_vector(sc, 12);
gc_loc = s7_gc_protect(sc, p);
if (!s7_is_vector(p))
{fprintf(stderr, "%d: %s is not a vector?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_vector_rank(p) != 1)
{fprintf(stderr, "%d: (dimensions %s) is not 1?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_vector_set(sc, p, 1, s7_t(sc));
if (s7_vector_ref(sc, p, 1) != s7_t(sc))
{fprintf(stderr, "%d: (%s 1) is not #t?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_vector_fill(sc, p, TO_S7_INT(123));
if (s7_integer(s7_vector_ref(sc, p, 1)) != 123)
{fprintf(stderr, "%d: (%s 1) is not 123?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
p = s7_make_and_fill_vector(sc, 3, TO_S7_INT(3));
gc_loc = s7_gc_protect(sc, p);
if (s7_integer(s7_vector_ref(sc, p, 1)) != 3)
{fprintf(stderr, "%d: (%s 1) is not 3?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p1 = s7_vector_copy(sc, p);
if ((p == p1) ||
(!s7_is_vector(p1)))
{fprintf(stderr, "%d: copied vector: %s\n", __LINE__, s1 = TO_STR(p1)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
p = s7_make_string(sc, "1234");
gc_loc = s7_gc_protect(sc, p);
if (!s7_is_string(p))
{fprintf(stderr, "%d: %s is not a string?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_string_length(p) != 4)
{fprintf(stderr, "%d: (length %s) is 4?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (strcmp(s7_string(p), "1234") != 0)
{fprintf(stderr, "%d: %s is \"1234\"?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
p = s7_make_character(sc, 65);
if (!s7_is_character(p))
{fprintf(stderr, "%d: %s is not a character?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_character(p) != 'A')
{fprintf(stderr, "%d: %s is not #\\A?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_list(sc, 3, TO_S7_INT(1), TO_S7_INT(2), TO_S7_INT(3));
gc_loc = s7_gc_protect(sc, p);
if (!s7_is_list(sc, p))
{fprintf(stderr, "%d: %s is not a list?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_list_length(sc, p) != 3)
{fprintf(stderr, "%d: (length %s) is not 3?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(s7_list_ref(sc, p, 1)) != 2)
{fprintf(stderr, "%d: (%s 1) is not 2?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(s7_car(p)) != 1)
{fprintf(stderr, "%d: (car %s) is not 1?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(s7_cadr(p)) != 2)
{fprintf(stderr, "%d: (cadr %s) is not 2?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(s7_caddr(p)) != 3)
{fprintf(stderr, "%d: (caddr %s) is not 2?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(s7_car(s7_cddr(p))) != 3)
{fprintf(stderr, "%d: (car (cddr %s)) is not 2?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_list_set(sc, p, 1, s7_f(sc));
if (s7_list_ref(sc, p, 1) != s7_f(sc))
{fprintf(stderr, "%d: (%s 1) is not #f?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
{
s7_pointer c1, c2, c3, c12, c23, c123, c1234, c1d2, c2d3, c3d4, c12d3, c23d4, c123d4, c1234d5;
s7_gc_on(sc, false);
c1 = s7_list(sc, 1, TO_S7_INT(1)); /* (1) */
c2 = s7_list(sc, 1, TO_S7_INT(2)); /* (2) */
c3 = s7_list(sc, 1, TO_S7_INT(3)); /* (3) */
c12 = s7_list(sc, 2, TO_S7_INT(1), TO_S7_INT(2)); /* (1 2) */
c23 = s7_list(sc, 2, TO_S7_INT(2), TO_S7_INT(3)); /* (2 3) */
c123 = s7_list(sc, 3, TO_S7_INT(1), TO_S7_INT(2), TO_S7_INT(3)); /* (1 2 3) */
c1234 = s7_list(sc, 4, TO_S7_INT(1), TO_S7_INT(2), TO_S7_INT(3), TO_S7_INT(4)); /* (1 2 3 4) */
c1d2 = s7_cons(sc, TO_S7_INT(1), TO_S7_INT(2)); /* (1 . 2) */
c2d3 = s7_cons(sc, TO_S7_INT(2), TO_S7_INT(3)); /* (2 . 3) */
c3d4 = s7_cons(sc, TO_S7_INT(3), TO_S7_INT(4)); /* (3 . 4) */
c12d3 = s7_cons(sc, TO_S7_INT(1), s7_cons(sc, TO_S7_INT(2), TO_S7_INT(3))); /* (1 2 . 3) */
c23d4 = s7_cons(sc, TO_S7_INT(2), s7_cons(sc, TO_S7_INT(3), TO_S7_INT(4))); /* (2 3 . 4) */
c123d4 = s7_cons(sc, TO_S7_INT(1), s7_cons(sc, TO_S7_INT(2), s7_cons(sc, TO_S7_INT(3), TO_S7_INT(4)))); /* (1 2 3 . 4) */
c1234d5 = s7_cons(sc, TO_S7_INT(1), s7_cons(sc, TO_S7_INT(2), s7_cons(sc, TO_S7_INT(3), s7_cons(sc, TO_S7_INT(4), TO_S7_INT(5))))); /* (1 2 3 4 . 5) */
if (s7_integer(p = s7_caar(s7_list(sc, 1, c1))) != 1)
{fprintf(stderr, "%d: caar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cadr(c12)) != 2)
{fprintf(stderr, "%d: cadr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cdar(s7_list(sc, 1, c1d2))) != 2)
{fprintf(stderr, "%d: cdar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cddr(c12d3)) != 3)
{fprintf(stderr, "%d: cddr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_caaar(s7_list(sc, 1, s7_list(sc, 1, c1)))) != 1)
{fprintf(stderr, "%d: caaar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_caadr(s7_list(sc, 2, TO_S7_INT(1), c2))) != 2)
{fprintf(stderr, "%d: caadr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cadar(s7_list(sc, 1, c12))) != 2)
{fprintf(stderr, "%d: cadar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cdaar(s7_list(sc, 1, s7_list(sc, 1, c1d2)))) != 2)
{fprintf(stderr, "%d: cdaar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_caddr(c123)) != 3)
{fprintf(stderr, "%d: caddr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cdddr(c123d4)) != 4)
{fprintf(stderr, "%d: cdddr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cdadr(s7_list(sc, 2, TO_S7_INT(1), c2d3))) != 3)
{fprintf(stderr, "%d: cdadr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cddar(s7_list(sc, 1, c12d3))) != 3)
{fprintf(stderr, "%d: cddar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_caaaar(s7_list(sc, 1, s7_list(sc, 1, s7_list(sc, 1, c1))))) != 1)
{fprintf(stderr, "%d: caaaar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_caaadr(s7_list(sc, 2, TO_S7_INT(1), s7_list(sc, 1, c2)))) != 2)
{fprintf(stderr, "%d: caaadr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_caadar(s7_list(sc, 1, s7_list(sc, 2, TO_S7_INT(1), c2)))) != 2)
{fprintf(stderr, "%d: caadar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cadaar(s7_list(sc, 1, s7_list(sc, 1, c12)))) != 2)
{fprintf(stderr, "%d: cadaar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_caaddr(s7_list(sc, 3, TO_S7_INT(1), TO_S7_INT(2), c3))) != 3)
{fprintf(stderr, "%d: caaddr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cadddr(c1234)) != 4)
{fprintf(stderr, "%d: cadddr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cadadr(s7_list(sc, 2, TO_S7_INT(1), c23))) != 3)
{fprintf(stderr, "%d: cadadr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_caddar(s7_list(sc, 1, c123))) != 3)
{fprintf(stderr, "%d: caddar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cdaaar(s7_list(sc, 1, s7_list(sc, 1, s7_list(sc, 1, c1d2))))) != 2)
{fprintf(stderr, "%d: cdaaar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cdaadr(s7_list(sc, 2, TO_S7_INT(1), s7_list(sc, 1, c2d3)))) != 3)
{fprintf(stderr, "%d: cdaadr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cdadar(s7_list(sc, 1, s7_list(sc, 2, TO_S7_INT(1), c2d3)))) != 3)
{fprintf(stderr, "%d: cdadar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cddaar(s7_list(sc, 1, s7_list(sc, 1, c12d3)))) != 3)
{fprintf(stderr, "%d: cddaar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cdaddr(s7_list(sc, 3, TO_S7_INT(1), TO_S7_INT(2), c3d4))) != 4)
{fprintf(stderr, "%d: cdaddr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cddddr(c1234d5)) != 5)
{fprintf(stderr, "%d: cdddd is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cddadr(s7_list(sc, 2, TO_S7_INT(1), c23d4))) != 4)
{fprintf(stderr, "%d: cddadr is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p = s7_cdddar(s7_list(sc, 1, c123d4))) != 4)
{fprintf(stderr, "%d: cdddar is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_reverse(sc, c123);
s1 = TO_STR(p);
if (strcmp(s1, "(3 2 1)") != 0)
{fprintf(stderr, "%d: (reverse '(1 2 3)) is %s?\n", __LINE__, s1);}
free(s1);
p = s7_append(sc, c1, c2);
s1 = TO_STR(p);
if (strcmp(s1, "(1 2)") != 0)
{fprintf(stderr, "%d: (append '(1) '(2)) is %s?\n", __LINE__, s1);}
free(s1);
p = s7_list(sc, 2, s7_cons(sc, s7_make_symbol(sc, "a"), TO_S7_INT(32)), s7_cons(sc, s7_make_symbol(sc, "b"), TO_S7_INT(1)));
p1 = s7_assq(sc, s7_make_symbol(sc, "a"), p);
s1 = TO_STR(p1);
if (strcmp(s1, "(a . 32)") != 0)
{fprintf(stderr, "%d: (assq 'a '((a . 32) (b . 1)))) is %s?\n", __LINE__, s1);}
free(s1);
p1 = s7_assoc(sc, s7_make_symbol(sc, "b"), p);
s1 = TO_STR(p1);
if (strcmp(s1, "(b . 1)") != 0)
{fprintf(stderr, "%d: (assoc 'b '((a . 32) (b . 1))) is %s?\n", __LINE__, s1);}
free(s1);
p = s7_member(sc, TO_S7_INT(2), c1234);
s1 = TO_STR(p);
if (strcmp(s1, "(2 3 4)") != 0)
{fprintf(stderr, "%d: (member 2 '(1 2 3 4)) is %s?\n", __LINE__, s1);}
free(s1);
p = s7_list(sc, 2, s7_make_symbol(sc, "a"), s7_make_symbol(sc, "b"));
p1 = s7_memq(sc, s7_make_symbol(sc, "b"), p);
s1 = TO_STR(p1);
if (strcmp(s1, "(b)") != 0)
{fprintf(stderr, "%d: (memq 'b '(a b)) is %s?\n", __LINE__, s1);}
free(s1);
s7_set_car(c1234, s7_make_symbol(sc, "+"));
p = s7_eval(sc, c1234, s7_sublet(sc, s7_rootlet(sc), s7_nil(sc)));
if (s7_integer(p) != 9)
{fprintf(stderr, "%d: (eval '(+ 2 3 4)) is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_eval_form(sc, c1234, s7_sublet(sc, s7_rootlet(sc), s7_nil(sc)));
if (s7_integer(p) != 9)
{fprintf(stderr, "%d: (eval(form) '(+ 2 3 4)) is %s?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_on(sc, true);
}
p = s7_make_ulong(sc, 123);
gc_loc = s7_gc_protect(sc, p);
if (!s7_is_ulong(p))
{fprintf(stderr, "%d: %s is not a ulong?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_ulong(p) != (unsigned long)123)
{fprintf(stderr, "%d: %s is not 123?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
p = s7_make_ulong_long(sc, 123);
gc_loc = s7_gc_protect(sc, p);
if (!s7_is_ulong_long(p))
{fprintf(stderr, "%d: %s is not a ulong_long?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_ulong_long(p) != (unsigned long long)123)
{fprintf(stderr, "%d: %s is not 123?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
p = s7_make_hash_table(sc, 255);
gc_loc = s7_gc_protect(sc, p);
if (!s7_is_hash_table(p))
{fprintf(stderr, "%d: %s is not a hash-table?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_hash_table_ref(sc, p, s7_eof_object(sc)) != s7_f(sc))
{fprintf(stderr, "%d: (hash-table-ref %s #<eof>) is not #f?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_hash_table_set(sc, p, s7_eof_object(sc), s7_unspecified(sc));
if (s7_hash_table_ref(sc, p, s7_eof_object(sc)) != s7_unspecified(sc))
{fprintf(stderr, "%d: (hash-table-ref %s #<eof>) is not #<unspecified>?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
p = s7_current_input_port(sc);
if (!s7_is_input_port(sc, p))
{fprintf(stderr, "%d: %s is not an input port?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_current_output_port(sc);
if (!s7_is_output_port(sc, p))
{fprintf(stderr, "%d: %s is not an output port?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_name_to_value(sc, "abs");
if (!s7_is_procedure(p))
{fprintf(stderr, "%d: %s is not a procedure?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_make_symbol(sc, "abs");
if (!s7_is_symbol(p))
{fprintf(stderr, "%d: %s is not a symbol?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_gensym(sc, "abs");
if (!s7_is_symbol(p))
{fprintf(stderr, "%d: %s is not a symbol?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_make_keyword(sc, "key");
if (!s7_is_keyword(p))
{fprintf(stderr, "%d: %s is not a keyword?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (!s7_is_eq(p, p))
{fprintf(stderr, "%d: %s is not a self-eq??\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_rootlet(sc);
if (!s7_is_let(p))
{fprintf(stderr, "%d: %s is not an environment?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p = s7_curlet(sc);
if ((!s7_is_null(sc, p)) && (!s7_is_let(p)))
{fprintf(stderr, "%d: %s is not an environment?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s7_define_constant(sc, "a_constant", s7_t(sc));
if (!s7_is_constant(s7_name_to_value(sc, "a_constant")))
{fprintf(stderr, "%d: a_constant is not a constant?\n", __LINE__);}
if (!s7_is_defined(sc, "a_constant"))
{fprintf(stderr, "%d: a_constant is not defined?\n", __LINE__);}
s7_define_function(sc, "a_function", a_function, 1, 0, false, "a function");
if (!s7_is_defined(sc, "a_function"))
{fprintf(stderr, "%d: a_function is not defined?\n", __LINE__);}
if (!s7_is_function(s7_name_to_value(sc, "a_function")))
{fprintf(stderr, "%d: a_function is not a function?\n", __LINE__);}
p = s7_apply_function(sc, s7_name_to_value(sc, "a_function"), s7_cons(sc, TO_S7_INT(32), s7_nil(sc)));
if (!s7_is_integer(p))
{fprintf(stderr, "%d: %s is not an integer?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p) != 32)
{fprintf(stderr, "%d: %s is not 32?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
dax_type_tag = s7_new_type("dax", print_dax, free_dax, equal_dax, mark_dax, NULL, NULL);
s7_define_function(sc, "make-dax", make_dax, 2, 0, false, "(make-dax x data) makes a new dax");
s7_define_function(sc, "dax?", is_dax, 1, 0, false, "(dax? anything) returns #t if its argument is a dax object");
s7_define_variable(sc, "dax-x",
s7_dilambda(sc, "dax-x", dax_x, 1, 0, set_dax_x, 2, 0, "dax x field (a real)"));
s7_define_variable(sc, "dax-data",
s7_dilambda(sc, "dax-data", dax_data, 1, 0, set_dax_data, 2, 0, "dax data field"));
if (!s7_is_procedure_with_setter(s7_name_to_value(sc, "dax-x")))
{fprintf(stderr, "%d: dax-x is not a pws?\n", __LINE__);}
p = make_dax(sc, s7_cons(sc, s7_make_real(sc, 1.0), s7_cons(sc, TO_S7_INT(2), s7_nil(sc))));
gc_loc = s7_gc_protect(sc, p);
if (!s7_is_object(p))
{fprintf(stderr, "%d: %s is not an object?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
p1 = s7_apply_function(sc, s7_name_to_value(sc, "dax?"), s7_cons(sc, p, s7_nil(sc)));
if (p1 != s7_t(sc))
{fprintf(stderr, "%d: %s is not a dax object?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
s1 = TO_STR(p);
if (strcmp(s1, "#<dax 1.000 2>") != 0)
{fprintf(stderr, "%d: dax prints as %s?\n", __LINE__, s2 = TO_STR(p)); free(s2);}
free(s1);
p1 = s7_apply_function(sc, s7_name_to_value(sc, "dax-data"), s7_cons(sc, p, s7_nil(sc)));
if (!s7_is_integer(p1))
{fprintf(stderr, "%d: %s is not an integer?\n", __LINE__, s1 = TO_STR(p1)); free(s1);}
if (s7_integer(p1) != 2)
{fprintf(stderr, "%d: %s is not 2?\n", __LINE__, s1 = TO_STR(p1)); free(s1);}
s7_apply_function(sc, s7_procedure_setter(sc, s7_name_to_value(sc, "dax-data")), s7_cons(sc, p, s7_cons(sc, TO_S7_INT(32), s7_nil(sc))));
p1 = s7_apply_function(sc, s7_name_to_value(sc, "dax-data"), s7_cons(sc, p, s7_nil(sc)));
if (!s7_is_integer(p1))
{fprintf(stderr, "%d: %s is not an integer?\n", __LINE__, s1 = TO_STR(p1)); free(s1);}
if (s7_integer(p1) != 32)
{fprintf(stderr, "%d: %s is not 32?\n", __LINE__, s1 = TO_STR(p1)); free(s1);}
s7_gc_unprotect_at(sc, gc_loc);
s7_define_function_star(sc, "plus", plus, "(red 32) blue", "an example of define* from C");
if (!s7_is_procedure(s7_name_to_value(sc, "plus")))
{fprintf(stderr, "%d: plus is not a function?\n", __LINE__);}
p = s7_apply_function(sc, s7_name_to_value(sc, "plus"), s7_cons(sc, TO_S7_INT(1), s7_cons(sc, TO_S7_INT(2), s7_nil(sc))));
if (!s7_is_integer(p))
{fprintf(stderr, "%d: %s is not an integer?\n", __LINE__, s1 = TO_STR(p)); free(s1);}
if (s7_integer(p) != 4)
{fprintf(stderr, "%d: %s is not 4?\n", __LINE__, s1 = TO_STR(p)); free(s1);}