-
Notifications
You must be signed in to change notification settings - Fork 0
/
joy.c
1158 lines (1046 loc) · 23.4 KB
/
joy.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
/*
module : joy.c
version : 1.39
date : 07/12/24
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
#include <setjmp.h>
#include <stdbool.h>
#include <inttypes.h>
/* #define DEBUG */
#ifdef _MSC_VER
#pragma warning(disable: 4244 4267 4996)
#endif
#define CORRECT_GARBAGE
#define READ_LIBRARY_ONCE
#define OBSOLETE_NOTHING
#define RENAME_INDEX
#define RENAME_SELECT
#if 0
#define ADD_SETAUTOPUT
#endif
#ifdef DEBUG
int debug = 1;
#define LOGFILE(s) { if (debug) { FILE *fp = fopen("joy.log",\
strcmp(s, "main") ? "a" : "w");\
fprintf(fp, "%s\n", s); fclose(fp); } }
#else
#define LOGFILE(s)
#endif
typedef unsigned char boolean;
#define true 1
#define false 0
#define errormark "%JOY"
#define lib_filename "42minjoy.lib"
#define list_filename "42minjoy.lst"
#define reslength 8
#define maxrestab 10
#define identlength 16
#define maxstdidenttab 32
typedef enum {
lbrack, rbrack, semic, period, def_equal,
/* compulsory for scanutilities: */
charconst, stringconst, numberconst, leftparenthesis, identifier
/* hyphen */
} symbol;
typedef enum {
lib_, mul_, add_, sub_, div_, lss_, eql_, and_, body_, cons_, dip_, dup_,
false_, get_, getch_, i_,
#ifndef RENAME_INDEX
index_,
#endif
not_,
#ifndef OBSOLETE_NOTHING
nothing_,
#endif
#ifdef RENAME_INDEX
of_,
#endif
#ifdef RENAME_SELECT
opcase_,
#endif
or_, pop_, put_, putch_, sametype_,
#ifndef RENAME_SELECT
select_,
#endif
#ifdef ADD_SETAUTOPUT
setautoput_,
#endif
stack_, step_, swap_, true_,
uncons_, unstack_, boolean_, char_, integer_, list_, unknownident
} standardident;
/*
* pathname of the joy binary, to be used as prefix to library files. That way
* it is not necessary to copy all library files to all working directories.
*/
char *pathname;
/*
* autoput controls whether automatic output of the TOS is required. Initially
* it is set to 1, but it can be turned off with the setautoput instruction.
* This is not a directive, because it has to be similar to the full version of
* Joy.
*/
int autoput = 1;
#define MINJOY
#include "scanutil.c"
static void initialise(void)
{
unsigned i;
LOGFILE(__func__);
iniscanner();
strcpy(specials_repeat, "=>");
erw(".", period);
erw(";", semic);
erw("==", def_equal);
erw("[", lbrack);
erw("]", rbrack);
est("*", mul_);
est("+", add_);
est("-", sub_);
est("/", div_);
est("<", lss_);
est("=", eql_);
est("and", and_);
est("body", body_);
est("cons", cons_);
est("dip", dip_);
est("dup", dup_);
est("false", false_);
est("get", get_);
est("getch", getch_);
est("i", i_);
#ifndef RENAME_INDEX
est("index", index_);
#endif
est("not", not_);
#ifndef OBSOLETE_NOTHING
est("nothing", nothing_);
#endif
#ifdef RENAME_INDEX
est("of", of_);
#endif
#ifdef RENAME_SELECT
est("opcase", opcase_);
#endif
est("or", or_);
est("pop", pop_);
est("put", put_);
est("putch", putch_);
est("sametype", sametype_);
#ifndef RENAME_SELECT
est("select", select_);
#endif
#ifdef ADD_SETAUTOPUT
est("setautoput", setautoput_);
#endif
est("stack", stack_);
est("step", step_);
est("swap", swap_);
est("true", true_);
est("uncons", uncons_);
est("unstack", unstack_);
for (i = mul_; i <= unstack_; i++)
if (i != stdidents[i].symb)
point('F', "bad order in standard idents");
} /* initialise */
#ifndef MAXTABLE
#define MAXTABLE 300
#endif
#ifndef MAXMEM
#define MAXMEM 2000
#endif
typedef short memrange;
typedef struct _REC_table {
identalfa alf;
memrange adr;
} _REC_table;
typedef struct _REC_m {
intptr_t val;
memrange nxt;
unsigned char op;
boolean marked;
} _REC_m;
static _REC_table table[MAXTABLE + 1];
static long lastlibloc, sentinel, lasttable, locatn;
static _REC_m m[MAXMEM + 1];
static memrange firstusernode, freelist, programme;
static memrange s, /* stack */
dump;
#if 0
static standardident last_op_executed;
#endif
static long stat_kons, stat_gc, stat_ops, stat_calls;
static clock_t stat_lib;
static char *standardident_NAMES[] = {
"LIB", "*", "+", "-", "/", "<", "=", "and", "body", "cons", "dip", "dup",
"false", "get", "getch", "i",
#ifndef RENAME_INDEX
"index",
#endif
"not",
#ifndef OBSOLETE_NOTHING
"nothing",
#endif
#ifdef RENAME_INDEX
"of",
#endif
#ifdef RENAME_SELECT
"opcase",
#endif
"or", "pop", "put", "putch", "sametype",
#ifndef RENAME_SELECT
"select",
#endif
#ifdef ADD_SETAUTOPUT
"setautoput",
#endif
"stack", "step", "swap", "true",
"uncons", "unstack", "BOOLEAN", "CHAR", "INTEGER", "LIST", "UNKNOWN"
};
#ifdef DEBUG
void DumpM(void)
{
long i;
FILE *fp = fopen("joy.dmp", "w");
LOGFILE(__func__);
fprintf(fp, "Table\n");
fprintf(fp, " nr %-*.*s adr\n", identlength, identlength, "name");
for (i = 1; i <= MAXTABLE && table[i].adr; i++)
fprintf(fp, "%4ld %-*.*s %4ld\n", i, identlength, identlength,
table[i].alf, (long)table[i].adr);
fprintf(fp, "\nMemory\n");
fprintf(fp, " nr %-*.*s value next M\n", identlength,
identlength, "name");
for (i = 1; i <= MAXMEM && m[i].marked; i++)
fprintf(fp, "%4ld %-*.*s %10ld %4ld %c\n", i, identlength, identlength,
standardident_NAMES[m[i].op], (long)m[i].val, (long)m[i].nxt,
m[i].marked ? 'T' : 'F');
fclose(fp);
}
#endif
static void lookup(void)
{
int i, j;
LOGFILE(__func__);
#ifdef READ_LIBRARY_ONCE
if (!sentinel) {
id = unknownident;
return;
}
#endif
locatn = 0;
if (sentinel > 0) { /* library has been read */
strcpy(table[sentinel].alf, ident);
locatn = lasttable;
while (strcmp(table[locatn].alf, ident))
locatn--;
}
if (locatn > sentinel)
id = lib_;
else {
i = 1;
j = lastlibloc;
do {
locatn = (i + j) / 2;
if (strcmp(ident, table[locatn].alf) <= 0)
j = locatn - 1;
if (strcmp(ident, table[locatn].alf) >= 0)
i = locatn + 1;
} while (i <= j);
if (i - 1 > j)
id = lib_;
else { /* binarysearch through standardidentifiers */
i = 1;
j = laststdident;
do {
locatn = (i + j) / 2;
if (strcmp(ident, stdidents[locatn].alf) <= 0)
j = locatn - 1;
if (strcmp(ident, stdidents[locatn].alf) >= 0)
i = locatn + 1;
} while (i <= j);
if (i - 1 > j)
id = stdidents[locatn].symb;
else {
#ifndef READ_LIBRARY_ONCE
if (!sentinel)
id = unknownident;
else {
#endif
if (lasttable == MAXTABLE)
point('F', "too many library symbols");
strcpy(table[++lasttable].alf, ident);
table[locatn = lasttable].adr = 0;
id = lib_;
#ifndef READ_LIBRARY_ONCE
}
#endif
}
} /* ELSE */
} /* ELSE */
if (writelisting > 4)
fprintf(listing, "lookup : %-*.*s at %ld\n", identlength, identlength,
standardident_NAMES[id], locatn);
} /* lookup */
static void wn(FILE *f, memrange n)
{
LOGFILE(__func__);
#ifdef READ_LIBRARY_ONCE
if (m[n].op == unknownident)
fprintf(f, "%5ld %-*.*s %10ld %10ld %c", (long)n, identlength,
identlength, (char *)m[n].val, 0L, (long)m[n].nxt,
m[n].marked ? 'T' : 'F');
else
#endif
fprintf(f, "%5ld %-*.*s %10ld %10ld %c", (long)n, identlength,
identlength, standardident_NAMES[m[n].op], (long)m[n].val,
(long)m[n].nxt, m[n].marked ? 'T' : 'F');
if (m[n].op == lib_)
fprintf(f, " %-*.*s %4ld", identlength, identlength,
table[m[n].val].alf, (long)table[m[n].val].adr);
putc('\n', f);
}
static void writenode(memrange n)
{
LOGFILE(__func__);
wn(stdout, n);
if (writelisting > 0) {
putc('\t', listing);
wn(listing, n);
}
} /* writenode */
static void mark(memrange n)
{
LOGFILE(__func__);
while (n > 0) {
if (writelisting > 4)
writenode(n);
if (m[n].op == list_ && !m[n].marked)
mark(m[n].val);
m[n].marked = true;
n = m[n].nxt;
}
} /* mark */
static memrange kons(standardident o, intptr_t v, memrange n)
{
memrange i;
long collected;
LOGFILE(__func__);
if (!freelist) {
if (!sentinel)
goto einde;
#if 0
fprintf(stderr, "gc, last_op_executed = %-*.*s\n", identlength,
identlength, standardident_NAMES[last_op_executed]);
#endif
if (writelisting > 2) {
writeident("GC start");
writeline();
}
mark(programme);
mark(s);
mark(dump);
/* mark parameters */
mark(n);
if (o == list_)
mark(v);
if (writelisting > 3) {
writeident("finished marking");
writeline();
}
collected = 0;
for (i = firstusernode; i <= MAXMEM; i++) {
if (!m[i].marked) {
m[i].nxt = freelist;
freelist = i;
collected++;
}
m[i].marked = false;
if (m[i].nxt == i)
point('F', "internal error - selfreference");
}
if (writelisting > 2) {
writeinteger(collected);
putch(' ');
writeident("nodes collected");
writeline();
}
if (!freelist)
einde:
point('F', "dynamic memory exhausted");
stat_gc++;
}
i = freelist;
if (o == list_ && v == i)
point('F', "internal error - selfreference");
if (i == n)
point('F', "internal error - circular");
freelist = m[i].nxt;
m[i].op = o;
m[i].val = v;
m[i].nxt = n;
if (writelisting > 4)
writenode(i);
stat_kons++;
return i;
} /* kons */
static char *my_strdup(char *str)
{
char *ptr;
size_t leng;
leng = strlen(str);
if ((ptr = malloc(leng + 1)) != 0)
strcpy(ptr, str);
return ptr;
}
static void readterm(memrange *);
static void readfactor(memrange *where)
{
memrange here;
LOGFILE(__func__);
switch (sym) {
case lbrack:
getsym();
*where = kons(list_, 0, 0);
m[*where].marked = true;
if (sym == lbrack || sym == identifier || sym == charconst ||
sym == numberconst) { /* sym == hyphen */
readterm(&here);
m[*where].val = here;
}
break;
case identifier:
lookup();
#ifdef READ_LIBRARY_ONCE
if (id == unknownident)
*where = kons(id, (intptr_t)my_strdup(ident), 0);
else
#endif
*where = kons(id, locatn, 0);
break;
case charconst:
*where = kons(char_, num, 0);
break;
case numberconst:
*where = kons(integer_, num, 0);
break;
#if 0
case hyphen:
*where = kons(sub_, sub_, 0);
break;
#endif
case period:
*where = 0;
return;
default:
point('F', "internal in readfactor");
} /* CASE */
m[*where].marked = true;
} /* readfactor */
static void readterm(memrange *first)
{ /* readterm */
/* was forward */
memrange i;
LOGFILE(__func__);
/* this is LL0 */
readfactor(first);
if ((i = *first) == 0)
return;
getsym();
while (sym == lbrack || sym == identifier || sym == charconst ||
sym == numberconst) { /* sym == hyphen */
readfactor(&m[i].nxt);
i = m[i].nxt;
getsym();
}
} /* readterm */
static void writefactor(memrange n, boolean nl);
static void writeterm(memrange n, boolean nl)
{
LOGFILE(__func__);
while (n > 0) {
writefactor(n, false);
if (m[n].nxt > 0)
putch(' ');
n = m[n].nxt;
}
if (nl)
writeline();
} /* writeterm */
static void writefactor(memrange n, boolean nl)
{ /* was forward */
LOGFILE(__func__);
if (n > 0) {
switch (m[n].op) {
case list_:
putch('[');
writeterm(m[n].val, false);
putch(']');
break;
case boolean_:
if (m[n].val == 1)
writeident("true");
else
writeident("false");
break;
case char_:
if (m[n].val == '\n')
writeline();
else
putch(m[n].val);
break;
case integer_:
writeinteger(m[n].val);
break;
case lib_:
writeident(table[m[n].val].alf);
break;
case unknownident:
writeident((char *)m[n].val);
break;
default:
writeident(stdidents[m[n].val].alf);
break;
} /* CASE */
}
if (nl)
writeline();
} /* writefactor */
#ifdef READ_LIBRARY_ONCE
static void patchfactor(memrange n);
static void patchterm(memrange n)
{
LOGFILE(__func__);
while (n > 0) {
patchfactor(n);
n = m[n].nxt;
}
} /* patchterm */
static void patchfactor(memrange n)
{ /* was forward */
LOGFILE(__func__);
if (n > 0) {
switch (m[n].op) {
case list_:
patchterm(m[n].val);
break;
case unknownident:
strncpy(ident, (char *)m[n].val, identlength);
ident[identlength] = 0;
free((char *)m[n].val);
m[n].val = 0;
lookup();
m[n].op = id;
m[n].val = locatn;
break;
} /* CASE */
}
} /* patchfactor */
#endif
static void readlibrary(char *str)
{
#ifdef READ_LIBRARY_ONCE
FILE *fp;
#endif
char *lib;
int loc, must_free = 0;
LOGFILE(__func__);
#if 0
if (writelisting > 5)
fprintf(listing, "first pass through library:\n");
#endif
/*
* Check that the library file is present. If not, this should not be a
* fatal error. Some global variables need to be set in case that happens.
* If the library is not present in the current directory, but is present
* in the same directory as the joy binary, it is read from there. This
* also applies to files that are included in the library.
*/
lastlibloc = 0;
#ifdef READ_LIBRARY_ONCE
if ((fp = fopen(str, "r")) == NULL) {
/*
* Prepend the pathname and try again. The library files are expected
* to exist somewhere.
*/
if (pathname) {
loc = strlen(pathname) + strlen(str) + 1;
lib = malloc(loc);
sprintf(lib, "%s%s", pathname, str);
if ((fp = fopen(lib, "r")) == NULL) {
free(lib);
goto failed;
}
str = lib;
must_free = 1; /* str must be given to free */
goto done;
}
failed:
firstusernode = freelist;
cc = ll;
sentinel = lastlibloc + 1;
lasttable = sentinel;
adjustment = 0;
return;
}
done:
/*
* The file was checked to exist. It is now closed, to be reopened again
* in newfile. It is possible that str now has a pathname prepended. That
* pathname should also be used in subsequent opens of newfile.
*/
fclose(fp);
#endif
newfile(str, 1);
getsym();
#if 0
do {
#else
while (sym != period) {
#endif
if (writelisting > 8)
fprintf(listing, "seen : %-*.*s\n", identlength, identlength,
ident);
if (lastlibloc > 0)
if (strcmp(ident, table[lastlibloc].alf) <= 0)
point('F', "bad order in library");
if (lastlibloc == MAXTABLE)
point('F', "too many library symbols");
strcpy(table[++lastlibloc].alf, ident);
#ifdef READ_LIBRARY_ONCE
loc = lastlibloc;
#else
do
getsym();
while (sym != semic && sym != period);
if (sym == semic)
getsym();
#if 0
} while (sym != period);
#else
}
#endif
if (writelisting > 5)
fprintf(listing, "second pass through library:\n");
newfile(str, 1);
#if 0
do {
getsym();
#else
getsym();
while (sym != period) {
#endif
if (sym != identifier)
point('F', "pass 2: identifier expected");
lookup();
loc = locatn;
#endif
/*
* In case of READ_LIBRARY_ONCE, continue here.
*/
getsym();
if (sym != def_equal)
point('F', "pass 2: \"==\" expected");
getsym();
readterm(&table[loc].adr);
if (writelisting > 8)
writeterm(table[loc].adr, true);
#if 0
} while (sym != period);
#else
if (sym != period)
getsym();
}
#endif
firstusernode = freelist;
if (writelisting > 5)
fprintf(listing, "firstusernode = %ld, total memory = %ld\n",
(long)firstusernode, (long)MAXMEM);
cc = ll;
#ifdef READ_LIBRARY_ONCE
sentinel = lastlibloc + 1;
lasttable = sentinel;
for (loc = 1; loc < lasttable; loc++)
patchterm(table[loc].adr);
adjustment = -1;
#else
adjustment = -2; /* back to file "input" */
#endif
if (must_free)
free(str);
} /* readlibrary */
static jmp_buf JL10;
static memrange ok(memrange x)
{
if (x < 1)
point('F', "null address being referenced");
return x;
} /* ok */
static standardident o(memrange x)
{
return m[ok(x)].op;
}
static intptr_t i(memrange x)
{
if (o(x) == integer_)
return m[x].val;
point('R', "integer value required");
longjmp(JL10, 1);
} /* i */
static memrange l(memrange x)
{
if (o(x) == list_)
return m[x].val;
point('R', "list value required");
longjmp(JL10, 1);
} /* l */
static memrange n(memrange x)
{
if (m[ok(x)].nxt >= 0)
return m[x].nxt;
point('R', "negative next value");
longjmp(JL10, 1);
} /* n */
static intptr_t v(memrange x)
{
return m[ok(x)].val;
}
static boolean b(memrange x)
{
return (boolean)(v(x) > 0);
}
static void binary(standardident o, intptr_t v)
{
s = kons(o, v, n(n(s)));
}
static void joy(memrange nod)
{
#ifdef RENAME_INDEX
intptr_t val;
#endif
memrange temp1, temp2;
LOGFILE(__func__);
while (nod > 0) { /* WHILE */
if (writelisting > 3) {
writeident("joy:");
putch(' ');
writefactor(nod, true);
}
if (writelisting > 4) {
writeident("stack:");
putch(' ');
writeterm(s, true);
writeident("dump:");
putch(' ');
writeterm(dump, true);
}
#if 0
last_op_executed = m[nod].op;
#endif
switch (m[nod].op) {
#ifndef OBSOLETE_NOTHING
case nothing_:
#endif
case char_:
case integer_:
case list_:
s = kons(m[nod].op, m[nod].val, s);
break;
case true_:
case false_:
s = kons(boolean_, m[nod].op == true_, s);
break;
case pop_:
s = n(s);
break;
case dup_:
s = kons(o(s), v(s), s);
break;
case swap_:
s = kons(o(n(s)), v(n(s)), kons(o(s), v(s), n(n(s))));
break;
case stack_:
s = kons(list_, s, s);
break;
case unstack_:
s = l(s);
break;
/* OPERATIONS: */
case not_:
s = kons(boolean_, !b(s), n(s));
break;
case mul_:
binary(integer_, i(n(s)) * i(s));
break;
case add_:
binary(integer_, v(n(s)) + i(s)); /* add integer to character */
break;
case sub_:
binary(integer_, v(n(s)) - i(s)); /* subtract integer from char */
break;
case div_:
binary(integer_, i(n(s)) / i(s));
break;
case and_:
binary(boolean_, b(n(s)) & b(s));
break;
case or_:
binary(boolean_, b(n(s)) | b(s));
break;
case lss_:
if (o(s) == lib_)
binary(boolean_,strcmp(table[v(n(s))].alf,table[v(s)].alf) < 0);
else
binary(boolean_, v(n(s)) < v(s));
break;
case eql_:
binary(boolean_, v(n(s)) == v(s));
break;
case sametype_:
binary(boolean_, o(n(s)) == o(s));
break;
case cons_:
#ifndef OBSOLETE_NOTHING
if (o(n(s)) == nothing_)
s = kons(list_, l(s), n(n(s)));
else
#endif
s = kons(list_, kons(o(n(s)), v(n(s)), v(s)), n(n(s)));
break;
case uncons_:
#ifndef OBSOLETE_NOTHING
if (!v(s))
s = kons(list_, 0, kons(nothing_, nothing_, n(s)));
else
#endif
s = kons(list_, n(l(s)), kons(o(l(s)), v(l(s)), n(s)));
break;
#ifdef RENAME_SELECT
case opcase_:
#else
case select_:
#endif
temp1 = l(s);
while (o(l(temp1)) != o(n(s)))
temp1 = n(temp1);
s = kons(list_, n(l(temp1)), n(s));
break;
#ifdef RENAME_INDEX
case of_:
temp1 = l(s);
for (val = v(n(s)); val > 0; val--)
temp1 = n(temp1);
s = kons(o(temp1), v(temp1), n(n(s)));
break;
#else
case index_:
if (v(n(s)) < 1)
s = kons(o(l(s)), v(l(s)), n(n(s)));
else
s = kons(o(n(l(s))), v(n(l(s))), n(n(s)));
break;
#endif
case body_:
s = kons(list_, table[v(s)].adr, n(s));
break;
#ifdef ADD_SETAUTOPUT
case setautoput_:
autoput = v(s);
s = n(s);
break;
#endif
case put_:
writefactor(s, false);
s = n(s);
break;
case putch_:
putch(v(s));
s = n(s);
break;
case get_:
getsym();
readfactor(&temp1);
s = kons(o(temp1), v(temp1), s);
break;
case getch_:
getch();
s = kons(integer_, chr, s);
break;
/* COMBINATORS: */
case i_:
#ifdef CORRECT_GARBAGE
dump = kons(o(s), l(s), dump);
#endif
temp1 = s;
s = n(s);
joy(l(temp1));
#ifdef CORRECT_GARBAGE
dump = n(dump);
#endif
break;
case dip_:
dump = kons(o(n(s)), v(n(s)), dump);
dump = kons(list_, l(s), dump);
s = n(n(s));
joy(l(dump));
dump = n(dump);
s = kons(o(dump), v(dump), s);
dump = n(dump);
break;
case step_:
dump = kons(o(s), l(s), dump);
dump = kons(o(n(s)), l(n(s)), dump);