-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
1556 lines (1546 loc) · 55.6 KB
/
Copy pathmain.rs
File metadata and controls
1556 lines (1546 loc) · 55.6 KB
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
#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case,
non_upper_case_globals, unused_assignments, unused_mut)]
use libc::{strlen, memcpy, write, exit, close, read, signal, tolower, memcmp, strcmp, open, creat};
pub type size_t = libc::c_ulong;
pub type __mode_t = libc::c_uint;
pub type __ssize_t = libc::c_long;
pub type mode_t = __mode_t;
pub type ssize_t = __ssize_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct __sigset_t {
pub __val: [libc::c_ulong; 16],
}
pub type C2RustUnnamed = libc::c_uint;
pub const _ISalnum: C2RustUnnamed = 8;
pub const _ISpunct: C2RustUnnamed = 4;
pub const _IScntrl: C2RustUnnamed = 2;
pub const _ISblank: C2RustUnnamed = 1;
pub const _ISgraph: C2RustUnnamed = 32768;
pub const _ISprint: C2RustUnnamed = 16384;
pub const _ISspace: C2RustUnnamed = 8192;
pub const _ISxdigit: C2RustUnnamed = 4096;
pub const _ISdigit: C2RustUnnamed = 2048;
pub const _ISalpha: C2RustUnnamed = 1024;
pub const _ISlower: C2RustUnnamed = 512;
pub const _ISupper: C2RustUnnamed = 256;
pub type __jmp_buf = [libc::c_long; 8];
#[derive(Copy, Clone)]
#[repr(C)]
pub struct __jmp_buf_tag {
pub __jmpbuf: __jmp_buf,
pub __mask_was_saved: libc::c_int,
pub __saved_mask: __sigset_t,
}
pub type jmp_buf = [__jmp_buf_tag; 1];
pub type __sighandler_t = Option<unsafe extern "C" fn(_: libc::c_int) -> ()>;
pub const MHALT: C2RustUnnamed_0 = 0;
pub const MEXPR: C2RustUnnamed_0 = 1;
pub const MPROG: C2RustUnnamed_0 = 9;
pub const MSETQ: C2RustUnnamed_0 = 8;
pub const MRETN: C2RustUnnamed_0 = 4;
pub const MAPPL: C2RustUnnamed_0 = 5;
pub const MNOTP: C2RustUnnamed_0 = 7;
pub const MPRED: C2RustUnnamed_0 = 6;
pub const MBETA: C2RustUnnamed_0 = 3;
pub const MLIST: C2RustUnnamed_0 = 2;
pub type C2RustUnnamed_0 = libc::c_uint;
#[no_mangle]
pub static mut Tag: [libc::c_uchar; 8192] = [0; 8192];
#[no_mangle]
pub static mut Car: [libc::c_short; 8192] = [0; 8192];
#[no_mangle]
pub static mut Cdr: [libc::c_short; 8192] = [0; 8192];
#[no_mangle]
pub static mut Freelist: libc::c_int = 0;
#[no_mangle]
pub static mut Acc: libc::c_int = 0;
#[no_mangle]
pub static mut Env: libc::c_int = 0;
#[no_mangle]
pub static mut Stack: libc::c_int = 0;
#[no_mangle]
pub static mut Mstack: libc::c_int = 0;
#[no_mangle]
pub static mut Tmp: libc::c_int = 0;
#[no_mangle]
pub static mut Tmpcar: libc::c_int = 0;
#[no_mangle]
pub static mut Tmpcdr: libc::c_int = 0;
#[no_mangle]
pub static mut Input: libc::c_int = 0;
#[no_mangle]
pub static mut Inp: libc::c_int = 0;
#[no_mangle]
pub static mut Ink: libc::c_int = 0;
#[no_mangle]
pub static mut Inbuf: *mut libc::c_char =
0 as *const libc::c_char as *mut libc::c_char;
#[no_mangle]
pub static mut Buffer: [libc::c_char; 128] = [0; 128];
#[no_mangle]
pub static mut Rejected: libc::c_int = 0;
#[no_mangle]
pub static mut Output: libc::c_int = 0;
#[no_mangle]
pub static mut Outp: libc::c_int = 0;
#[no_mangle]
pub static mut Outbuf: [libc::c_char; 128] = [0; 128];
#[no_mangle]
pub static mut Symbols: libc::c_int = 0;
#[no_mangle]
pub static mut Id: libc::c_int = 0;
#[no_mangle]
pub static mut Restart: jmp_buf =
[__jmp_buf_tag{__jmpbuf: [0; 8],
__mask_was_saved: 0,
__saved_mask: __sigset_t{__val: [0; 16],},}; 1];
#[no_mangle]
pub static mut Error: libc::c_int = 0;
#[no_mangle]
pub static mut Parens: libc::c_int = 0;
#[no_mangle]
pub static mut Loads: libc::c_int = 0;
#[no_mangle]
pub static mut Verbose_GC: libc::c_int = 0;
#[no_mangle]
pub static mut S_apply: libc::c_int = 0;
#[no_mangle]
pub static mut S_if: libc::c_int = 0;
#[no_mangle]
pub static mut S_ifnot: libc::c_int = 0;
#[no_mangle]
pub static mut S_lambda: libc::c_int = 0;
#[no_mangle]
pub static mut S_lamstar: libc::c_int = 0;
#[no_mangle]
pub static mut S_macro: libc::c_int = 0;
#[no_mangle]
pub static mut S_prog: libc::c_int = 0;
#[no_mangle]
pub static mut S_quote: libc::c_int = 0;
#[no_mangle]
pub static mut S_qquote: libc::c_int = 0;
#[no_mangle]
pub static mut S_unquote: libc::c_int = 0;
#[no_mangle]
pub static mut S_splice: libc::c_int = 0;
#[no_mangle]
pub static mut S_setq: libc::c_int = 0;
#[no_mangle]
pub static mut S_t: libc::c_int = 0;
#[no_mangle]
pub static mut S_cons: libc::c_int = 0;
#[no_mangle]
pub static mut S_car: libc::c_int = 0;
#[no_mangle]
pub static mut S_cdr: libc::c_int = 0;
#[no_mangle]
pub static mut S_atom: libc::c_int = 0;
#[no_mangle]
pub static mut S_eq: libc::c_int = 0;
#[no_mangle]
pub static mut S_gensym: libc::c_int = 0;
#[no_mangle]
pub static mut S_it: libc::c_int = 0;
#[no_mangle]
pub static mut S_suspend: libc::c_int = 0;
#[no_mangle]
pub static mut S_gc: libc::c_int = 0;
#[no_mangle]
pub static mut S_eofp: libc::c_int = 0;
#[no_mangle]
pub static mut S_load: libc::c_int = 0;
#[no_mangle]
pub static mut S_setcar: libc::c_int = 0;
#[no_mangle]
pub static mut S_setcdr: libc::c_int = 0;
#[no_mangle]
pub static mut S_read: libc::c_int = 0;
#[no_mangle]
pub static mut S_prin: libc::c_int = 0;
#[no_mangle]
pub static mut S_prin1: libc::c_int = 0;
#[no_mangle]
pub static mut S_print: libc::c_int = 0;
#[no_mangle]
pub static mut S_error: libc::c_int = 0;
#[no_mangle]
pub unsafe extern "C" fn car(mut x: libc::c_int) -> libc::c_int {
return Car[x as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn cdr(mut x: libc::c_int) -> libc::c_int {
return Cdr[x as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn setcar(mut x: libc::c_int, mut v: libc::c_int) {
Car[x as usize] = v as libc::c_short;
}
#[no_mangle]
pub unsafe extern "C" fn setcdr(mut x: libc::c_int, mut v: libc::c_int) {
Cdr[x as usize] = v as libc::c_short;
}
#[no_mangle]
pub unsafe extern "C" fn atomp(mut n: libc::c_int) -> libc::c_int {
return (n >= 8192 as libc::c_int ||
car(n) < 8192 as libc::c_int &&
Tag[car(n) as usize] as libc::c_int & 0x1 as libc::c_int
!= 0) as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn symbolp(mut n: libc::c_int) -> libc::c_int {
return (n < 8192 as libc::c_int && car(n) < 8192 as libc::c_int &&
Tag[car(n) as usize] as libc::c_int & 0x1 as libc::c_int != 0)
as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn caar(mut x: libc::c_int) -> libc::c_int {
return Car[Car[x as usize] as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn cadr(mut x: libc::c_int) -> libc::c_int {
return Car[Cdr[x as usize] as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn cdar(mut x: libc::c_int) -> libc::c_int {
return Cdr[Car[x as usize] as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn cddr(mut x: libc::c_int) -> libc::c_int {
return Cdr[Cdr[x as usize] as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn caadr(mut x: libc::c_int) -> libc::c_int {
return Car[Car[Cdr[x as usize] as usize] as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn cadar(mut x: libc::c_int) -> libc::c_int {
return Car[Cdr[Car[x as usize] as usize] as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn caddr(mut x: libc::c_int) -> libc::c_int {
return Car[Cdr[Cdr[x as usize] as usize] as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn cdadr(mut x: libc::c_int) -> libc::c_int {
return Cdr[Car[Cdr[x as usize] as usize] as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn cddar(mut x: libc::c_int) -> libc::c_int {
return Cdr[Cdr[Car[x as usize] as usize] as usize] as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn caddar(mut x: libc::c_int) -> libc::c_int {
return Car[Cdr[Cdr[Car[x as usize] as usize] as usize] as usize] as
libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn cdddar(mut x: libc::c_int) -> libc::c_int {
return Cdr[Cdr[Cdr[Car[x as usize] as usize] as usize] as usize] as
libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn pr(mut s: *mut libc::c_char) {
let mut k: libc::c_int = 0;
let mut n: libc::c_int = 0;
k = strlen(s) as libc::c_int;
while Outp + k >= 128 as libc::c_int {
if Outp > 0 as libc::c_int {
n = 128 as libc::c_int - Outp;
memcpy(Outbuf.as_mut_ptr().offset(Outp as isize) as
*mut libc::c_void, s as *const libc::c_void,
n.try_into().unwrap());
write(Output, Outbuf.as_mut_ptr() as *const libc::c_void,
128 as libc::c_int as size_t);
k -= n;
s = s.offset(n as isize);
Outp = 0 as libc::c_int
} else {
write(Output, s as *const libc::c_void,
128 as libc::c_int as size_t);
k -= 128 as libc::c_int;
s = s.offset(128 as libc::c_int as isize)
}
}
memcpy(Outbuf.as_mut_ptr().offset(Outp as isize) as *mut libc::c_void,
s as *const libc::c_void, k.try_into().unwrap());
Outp += k;
}
#[no_mangle]
pub unsafe extern "C" fn flush() {
write(Output, Outbuf.as_mut_ptr() as *const libc::c_void, Outp as size_t);
Outp = 0 as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn nl() {
pr(b"\n\x00" as *const u8 as *const libc::c_char as *mut libc::c_char);
flush();
}
#[no_mangle]
pub unsafe extern "C" fn ntoa(mut n: libc::c_int) -> *mut libc::c_char {
static mut buf: [libc::c_char; 20] = [0; 20];
let mut q: *mut libc::c_char = 0 as *mut libc::c_char;
let mut p: *mut libc::c_char = 0 as *mut libc::c_char;
q =
&mut *buf.as_mut_ptr().offset((::std::mem::size_of::<[libc::c_char; 20]>()
as
libc::c_ulong).wrapping_sub(1 as
libc::c_int
as
libc::c_ulong)
as isize) as *mut libc::c_char;
p = q;
*p = 0 as libc::c_int as libc::c_char;
while n != 0 || p == q {
p = p.offset(-1);
*p = (n % 10 as libc::c_int + '0' as i32) as libc::c_char;
n = n / 10 as libc::c_int
}
return p;
}
#[no_mangle]
pub unsafe extern "C" fn prnum(mut n: libc::c_int) { pr(ntoa(n)); }
#[no_mangle]
pub unsafe extern "C" fn error(mut m: *mut libc::c_char, mut n: libc::c_int) {
pr(b"? \x00" as *const u8 as *const libc::c_char as *mut libc::c_char);
pr(m);
if n != 8192 as libc::c_int + 1 as libc::c_int {
pr(b": \x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
print(n);
}
nl();
Input = 0 as libc::c_int;
Inbuf = Buffer.as_mut_ptr();
Ink = 0 as libc::c_int;
Inp = Ink;
Rejected = 8192 as libc::c_int + 4 as libc::c_int;
//longjmp(Restart.as_mut_ptr(), 1 as libc::c_int);
panic!("error");
}
#[no_mangle]
pub unsafe extern "C" fn fatal(mut m: *mut libc::c_char) {
error(m, 8192 as libc::c_int + 1 as libc::c_int);
pr(b"? aborting\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
nl();
exit(1 as libc::c_int);
}
/* Deutsch/Schorr/Waite graph marker */
#[no_mangle]
pub unsafe extern "C" fn mark(mut n: libc::c_int) {
let mut p: libc::c_int = 0;
let mut x: libc::c_int = 0;
p = 8192 as libc::c_int + 5 as libc::c_int;
loop {
if n >= 8192 as libc::c_int ||
Tag[n as usize] as libc::c_int & 0x2 as libc::c_int != 0 {
if 8192 as libc::c_int + 5 as libc::c_int == p { break ; }
if Tag[p as usize] as libc::c_int & 0x4 as libc::c_int != 0 {
x = cdr(p);
setcdr(p, car(p));
setcar(p, n);
Tag[p as usize] =
(Tag[p as usize] as libc::c_int & !(0x4 as libc::c_int))
as libc::c_uchar;
n = x
} else { x = p; p = cdr(x); setcdr(x, n); n = x }
} else if Tag[n as usize] as libc::c_int & 0x1 as libc::c_int != 0 {
x = cdr(n);
setcdr(n, p);
p = n;
n = x;
Tag[p as usize] =
(Tag[p as usize] as libc::c_int | 0x2 as libc::c_int) as
libc::c_uchar
} else {
x = car(n);
setcar(n, p);
Tag[n as usize] =
(Tag[n as usize] as libc::c_int | 0x2 as libc::c_int) as
libc::c_uchar;
p = n;
n = x;
Tag[p as usize] =
(Tag[p as usize] as libc::c_int | 0x4 as libc::c_int) as
libc::c_uchar
}
};
}
#[no_mangle]
pub unsafe extern "C" fn gc(mut v: libc::c_int) -> libc::c_int {
let mut i: libc::c_int = 0;
let mut k: libc::c_int = 0;
k = 0 as libc::c_int;
mark(Acc);
mark(Env);
mark(Symbols);
mark(Stack);
mark(Mstack);
mark(Tmpcar);
mark(Tmpcdr);
mark(Tmp);
Freelist = 8192 as libc::c_int + 5 as libc::c_int;
i = 0 as libc::c_int;
while i < 8192 as libc::c_int {
if 0 as libc::c_int ==
Tag[i as usize] as libc::c_int & 0x2 as libc::c_int {
setcdr(i, Freelist);
Freelist = i;
k += 1
} else {
Tag[i as usize] =
(Tag[i as usize] as libc::c_int & !(0x2 as libc::c_int)) as
libc::c_uchar
}
i += 1
}
if v != 0 || Verbose_GC != 0 {
prnum(k);
pr(b" nodes reclaimed\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
nl();
}
return k;
}
#[no_mangle]
pub unsafe extern "C" fn cons3(mut a: libc::c_int, mut d: libc::c_int,
mut t: libc::c_int) -> libc::c_int {
let mut n: libc::c_int = 0;
if 8192 as libc::c_int + 5 as libc::c_int == Freelist {
Tmpcdr = d;
if 0 as libc::c_int == t { Tmpcar = a }
gc(0 as libc::c_int);
Tmpcdr = 8192 as libc::c_int + 5 as libc::c_int;
Tmpcar = Tmpcdr;
if 8192 as libc::c_int + 5 as libc::c_int == Freelist {
error(b"out of nodes\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char,
8192 as libc::c_int + 1 as libc::c_int);
}
}
n = Freelist;
Freelist = cdr(Freelist);
setcar(n, a);
setcdr(n, d);
Tag[n as usize] = t as libc::c_uchar;
return n;
}
#[no_mangle]
pub unsafe extern "C" fn cons(mut a: libc::c_int, mut d: libc::c_int)
-> libc::c_int {
return cons3(a, d, 0 as libc::c_int);
}
#[no_mangle]
pub unsafe extern "C" fn nrev(mut n: libc::c_int) -> libc::c_int {
let mut m: libc::c_int = 0;
let mut h: libc::c_int = 0;
m = 8192 as libc::c_int + 5 as libc::c_int;
while n != 8192 as libc::c_int + 5 as libc::c_int {
h = cdr(n);
setcdr(n, m);
m = n;
n = h
}
return m;
}
#[no_mangle]
pub unsafe extern "C" fn save(mut n: libc::c_int) { Stack = cons(n, Stack); }
#[no_mangle]
pub unsafe extern "C" fn unsave(mut k: libc::c_int) -> libc::c_int {
let mut n: libc::c_int = 0;
while k != 0 {
if 8192 as libc::c_int + 5 as libc::c_int == Stack {
fatal(b"stack empty\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
}
n = car(Stack);
Stack = cdr(Stack);
k -= 1
}
return n;
}
#[no_mangle]
pub unsafe extern "C" fn msave(mut n: libc::c_int) {
Mstack = cons3(n, Mstack, 0x1 as libc::c_int);
}
#[no_mangle]
pub unsafe extern "C" fn munsave() -> libc::c_int {
let mut n: libc::c_int = 0;
if 8192 as libc::c_int + 5 as libc::c_int == Mstack {
fatal(b"mstack empty\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
}
n = car(Mstack);
Mstack = cdr(Mstack);
return n;
}
#[no_mangle]
pub unsafe extern "C" fn strsym(mut s: *mut libc::c_char) -> libc::c_int {
let mut i: libc::c_int = 0;
let mut n: libc::c_int = 0;
i = 0 as libc::c_int;
if 0 as libc::c_int == *s.offset(i as isize) as libc::c_int {
return 8192 as libc::c_int + 5 as libc::c_int
}
n =
cons3(8192 as libc::c_int + 5 as libc::c_int,
8192 as libc::c_int + 5 as libc::c_int, 0x1 as libc::c_int);
save(n);
loop {
setcar(n,
(*s.offset(i as isize) as libc::c_int) << 8 as libc::c_int |
*s.offset((i + 1 as libc::c_int) as isize) as libc::c_int);
if 0 as libc::c_int ==
*s.offset((i + 1 as libc::c_int) as isize) as libc::c_int ||
0 as libc::c_int ==
*s.offset((i + 2 as libc::c_int) as isize) as libc::c_int {
break ;
}
setcdr(n,
cons3(8192 as libc::c_int + 5 as libc::c_int,
8192 as libc::c_int + 5 as libc::c_int,
0x1 as libc::c_int));
n = cdr(n);
i += 2 as libc::c_int
}
n = unsave(1 as libc::c_int);
return cons(n, 8192 as libc::c_int + 1 as libc::c_int);
}
#[no_mangle]
pub unsafe extern "C" fn symstr(mut n: libc::c_int) -> *mut libc::c_char {
static mut b: [libc::c_char; 66] = [0; 66];
let mut i: libc::c_int = 0;
i = 0 as libc::c_int;
n = car(n);
while n != 8192 as libc::c_int + 5 as libc::c_int {
b[i as usize] = (car(n) >> 8 as libc::c_int) as libc::c_char;
b[(i + 1 as libc::c_int) as usize] =
(car(n) & 0xff as libc::c_int) as libc::c_char;
i += 2 as libc::c_int;
n = cdr(n)
}
b[i as usize] = 0 as libc::c_int as libc::c_char;
return b.as_mut_ptr();
}
#[no_mangle]
pub unsafe extern "C" fn findsym(mut s: *mut libc::c_char) -> libc::c_int {
let mut p: libc::c_int = 0;
p = Symbols;
while p != 8192 as libc::c_int + 5 as libc::c_int {
if strcmp(s, symstr(car(p))) == 0 as libc::c_int { return car(p) }
p = cdr(p)
}
return 8192 as libc::c_int + 5 as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn addsym(mut s: *mut libc::c_char, mut v: libc::c_int)
-> libc::c_int {
let mut n: libc::c_int = 0;
n = findsym(s);
if n != 8192 as libc::c_int + 5 as libc::c_int { return n }
n = strsym(s);
save(n);
if 8192 as libc::c_int == v {
setcdr(n, cons(n, 8192 as libc::c_int + 5 as libc::c_int));
} else { setcdr(n, cons(v, 8192 as libc::c_int + 5 as libc::c_int)); }
Symbols = cons(n, Symbols);
unsave(1 as libc::c_int);
return n;
}
#[no_mangle]
pub unsafe extern "C" fn rdch() -> libc::c_int {
let mut c: libc::c_int = 0;
if Rejected != 8192 as libc::c_int + 4 as libc::c_int {
c = Rejected;
Rejected = 8192 as libc::c_int + 4 as libc::c_int;
return c
}
if Inp >= Ink {
Ink =
read(Input, Inbuf as *mut libc::c_void,
128 as libc::c_int as size_t) as libc::c_int;
if Ink < 1 as libc::c_int {
return 8192 as libc::c_int + 4 as libc::c_int
}
Inp = 0 as libc::c_int
}
let fresh0 = Inp;
Inp = Inp + 1;
return *Inbuf.offset(fresh0 as isize) as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn rdchci() -> libc::c_int {
let mut c: libc::c_int = 0;
c = rdch();
if c >= 8192 as libc::c_int { return c }
return tolower(c);
}
#[no_mangle]
pub unsafe extern "C" fn rdlist() -> libc::c_int {
let mut n: libc::c_int = 0;
let mut lst: libc::c_int = 0;
let mut a: libc::c_int = 0;
let mut count: libc::c_int = 0;
let mut badpair: *mut libc::c_char = 0 as *mut libc::c_char;
badpair =
b"bad pair\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char;
Parens += 1;
lst =
cons(8192 as libc::c_int + 5 as libc::c_int,
8192 as libc::c_int + 5 as libc::c_int);
save(lst);
a = 8192 as libc::c_int + 5 as libc::c_int;
count = 0 as libc::c_int;
loop {
if Error != 0 { return 8192 as libc::c_int + 5 as libc::c_int }
n = xread();
if 8192 as libc::c_int + 4 as libc::c_int == n {
error(b"missing \')\'\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char,
8192 as libc::c_int + 1 as libc::c_int);
}
if 8192 as libc::c_int + 3 as libc::c_int == n {
if count < 1 as libc::c_int {
error(badpair, 8192 as libc::c_int + 1 as libc::c_int);
}
n = xread();
setcdr(a, n);
if 8192 as libc::c_int + 2 as libc::c_int == n ||
xread() != 8192 as libc::c_int + 2 as libc::c_int {
error(badpair, 8192 as libc::c_int + 1 as libc::c_int);
}
unsave(1 as libc::c_int);
Parens -= 1;
return lst
}
if 8192 as libc::c_int + 2 as libc::c_int == n { break ; }
if 8192 as libc::c_int + 5 as libc::c_int == a {
a = lst
} else { a = cdr(a) }
setcar(a, n);
setcdr(a,
cons(8192 as libc::c_int + 5 as libc::c_int,
8192 as libc::c_int + 5 as libc::c_int));
count += 1
}
Parens -= 1;
if a != 8192 as libc::c_int + 5 as libc::c_int {
setcdr(a, 8192 as libc::c_int + 5 as libc::c_int);
}
unsave(1 as libc::c_int);
return if count != 0 {
lst
} else { (8192 as libc::c_int) + 5 as libc::c_int };
}
#[no_mangle]
pub unsafe extern "C" fn symbolic(mut c: libc::c_int) -> libc::c_int {
((c as u8).is_ascii_alphabetic() ||
(c as u8).is_ascii_digit() ||
((c as u8) == b'-') ||
((c as u8) == b'/'))
as libc::c_int
}
#[no_mangle]
pub unsafe extern "C" fn rdsym(mut c: libc::c_int) -> libc::c_int {
let mut s: [libc::c_char; 65] = [0; 65];
let mut i: libc::c_int = 0;
i = 0 as libc::c_int;
while symbolic(c) != 0 {
if '/' as i32 == c { c = rdchci() }
if 64 as libc::c_int == i {
error(b"long symbol\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char,
8192 as libc::c_int + 1 as libc::c_int);
} else if i < 64 as libc::c_int {
s[i as usize] = c as libc::c_char;
i += 1
}
c = rdchci()
}
s[i as usize] = 0 as libc::c_int as libc::c_char;
Rejected = c;
if strcmp(s.as_mut_ptr(), b"nil\x00" as *const u8 as *const libc::c_char)
== 0 {
return 8192 as libc::c_int + 5 as libc::c_int
}
return addsym(s.as_mut_ptr(), 8192 as libc::c_int + 1 as libc::c_int);
}
#[no_mangle]
pub unsafe extern "C" fn syntax(mut x: libc::c_int) {
error(b"syntax\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char, x);
}
#[no_mangle]
pub unsafe extern "C" fn quote(mut q: libc::c_int, mut n: libc::c_int)
-> libc::c_int {
return cons(q, cons(n, 8192 as libc::c_int + 5 as libc::c_int));
}
#[no_mangle]
pub unsafe extern "C" fn rdword() -> libc::c_int {
let mut s: [libc::c_char; 2] = [0; 2];
let mut n: libc::c_int = 0;
let mut c: libc::c_int = 0;
s[1 as libc::c_int as usize] = 0 as libc::c_int as libc::c_char;
c = rdchci();
if symbolic(c) == 0 { syntax(8192 as libc::c_int + 1 as libc::c_int); }
n =
cons(8192 as libc::c_int + 5 as libc::c_int,
8192 as libc::c_int + 5 as libc::c_int);
save(n);
loop {
if '/' as i32 == c { c = rdchci() }
s[0 as libc::c_int as usize] = c as libc::c_char;
setcar(n,
addsym(s.as_mut_ptr(),
8192 as libc::c_int + 1 as libc::c_int));
c = rdchci();
if !(symbolic(c) != 0) { break ; }
setcdr(n,
cons(8192 as libc::c_int + 5 as libc::c_int,
8192 as libc::c_int + 5 as libc::c_int));
n = cdr(n)
}
Rejected = c;
n = unsave(1 as libc::c_int);
return quote(S_quote, n);
}
#[export_name = "type"]
pub unsafe extern "C" fn type_0(mut x: libc::c_int) {
error(b"type\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char, x);
}
#[no_mangle]
pub unsafe extern "C" fn xread() -> libc::c_int {
let mut c: libc::c_int = 0;
c = rdchci();
loop {
while ' ' as i32 == c || '\t' as i32 == c || '\n' as i32 == c ||
'\r' as i32 == c {
if Error != 0 { return 8192 as libc::c_int + 5 as libc::c_int }
c = rdchci()
}
if c != ';' as i32 { break ; }
while c != '\n' as i32 { c = rdchci() }
}
if 8192 as libc::c_int + 4 as libc::c_int == c || '%' as i32 == c {
return 8192 as libc::c_int + 4 as libc::c_int
}
if '(' as i32 == c {
return rdlist()
} else if '\'' as i32 == c {
return quote(S_quote, xread())
} else if '@' as i32 == c {
return quote(S_qquote, xread())
} else if ',' as i32 == c {
c = rdchci();
if '@' as i32 == c { return quote(S_splice, xread()) }
Rejected = c;
return quote(S_unquote, xread())
} else if ')' as i32 == c {
if Parens == 0 {
error(b"extra paren\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char,
8192 as libc::c_int + 1 as libc::c_int);
}
return 8192 as libc::c_int + 2 as libc::c_int
} else if '.' as i32 == c {
if Parens == 0 {
error(b"free dot\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char,
8192 as libc::c_int + 1 as libc::c_int);
}
return 8192 as libc::c_int + 3 as libc::c_int
} else if symbolic(c) != 0 {
return rdsym(c)
} else if '#' as i32 == c {
return rdword()
} else {
syntax(8192 as libc::c_int + 1 as libc::c_int);
return 8192 as libc::c_int + 1 as libc::c_int
};
}
#[no_mangle]
pub unsafe extern "C" fn print2(mut n: libc::c_int, mut d: libc::c_int) {
if d > 128 as libc::c_int {
error(b"print depth\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char, 8192 as libc::c_int + 1 as libc::c_int);
}
if Error != 0 {
error(b"stop\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char, 8192 as libc::c_int + 1 as libc::c_int);
}
if 8192 as libc::c_int + 5 as libc::c_int == n {
pr(b"nil\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
} else if 8192 as libc::c_int + 4 as libc::c_int == n {
pr(b"*eot*\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
} else if n >= 8192 as libc::c_int ||
Tag[n as usize] as libc::c_int & 0x1 as libc::c_int != 0 {
pr(b"*unprintable*\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
} else if symbolp(n) != 0 {
pr(symstr(n));
} else {
/* List */
if atomp(n) == 0 && S_lamstar == car(n) {
pr(b"*closure*\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
return
}
pr(b"(\x00" as *const u8 as *const libc::c_char as *mut libc::c_char);
while n != 8192 as libc::c_int + 5 as libc::c_int {
print2(car(n), d + 1 as libc::c_int);
n = cdr(n);
if symbolp(n) != 0 {
pr(b" . \x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
print2(n, d + 1 as libc::c_int);
n = 8192 as libc::c_int + 5 as libc::c_int
} else if n != 8192 as libc::c_int + 5 as libc::c_int {
pr(b" \x00" as *const u8 as *const libc::c_char as
*mut libc::c_char);
}
}
pr(b")\x00" as *const u8 as *const libc::c_char as *mut libc::c_char);
};
}
#[no_mangle]
pub unsafe extern "C" fn print(mut n: libc::c_int) {
print2(n, 0 as libc::c_int);
}
#[no_mangle]
pub unsafe extern "C" fn lookup(mut x: libc::c_int) -> libc::c_int {
let mut a: libc::c_int = 0;
let mut e: libc::c_int = 0;
e = Env;
while e != 8192 as libc::c_int + 5 as libc::c_int {
a = car(e);
while a != 8192 as libc::c_int + 5 as libc::c_int {
if caar(a) == x { return cdar(a) }
a = cdr(a)
}
e = cdr(e)
}
return cdr(x);
}
#[no_mangle]
pub unsafe extern "C" fn specialp(mut n: libc::c_int) -> libc::c_int {
return (n == S_quote || n == S_if || n == S_prog || n == S_ifnot ||
n == S_lambda || n == S_lamstar || n == S_apply || n == S_setq
|| n == S_macro) as libc::c_int;
}
#[no_mangle]
pub unsafe extern "C" fn check(mut x: libc::c_int, mut k0: libc::c_int,
mut kn: libc::c_int) {
let mut i: libc::c_int = 0;
let mut a: libc::c_int = 0;
i = 0 as libc::c_int;
a = x;
while atomp(a) == 0 { i += 1; a = cdr(a) }
if a != 8192 as libc::c_int + 5 as libc::c_int || i < k0 ||
kn != -(1 as libc::c_int) && i > kn {
syntax(x);
};
}
#[no_mangle]
pub unsafe extern "C" fn load(mut s: *mut libc::c_char) {
let mut buf: [libc::c_char; 128] = [0; 128];
let mut ib: *mut libc::c_char = 0 as *mut libc::c_char;
let mut ip: libc::c_int = 0;
let mut ik: libc::c_int = 0;
let mut in_0: libc::c_int = 0;
let mut re: libc::c_int = 0;
if Loads >= 2 as libc::c_int {
error(b"nested load\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char, 8192 as libc::c_int + 1 as libc::c_int);
}
in_0 = Input;
ip = Inp;
ik = Ink;
ib = Inbuf;
re = Rejected;
Inbuf = buf.as_mut_ptr();
Ink = 0 as libc::c_int;
Inp = Ink;
Rejected = 8192 as libc::c_int + 4 as libc::c_int;
Input = open(s, 0 as libc::c_int);
if Input < 0 as libc::c_int {
error(b"load\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char, strsym(s));
}
Loads += 1;
loop {
Acc = xread();
if 8192 as libc::c_int + 4 as libc::c_int == Acc { break ; }
eval(Acc);
}
Loads -= 1;
Rejected = re;
Inbuf = ib;
Ink = ik;
Inp = ip;
Input = in_0;
}
#[no_mangle]
pub unsafe extern "C" fn dowrite(mut fd: libc::c_int,
mut b: *mut libc::c_void,
mut k: libc::c_int) {
if write(fd, b, k as size_t) != k as libc::c_long {
error(b"write error\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char, 8192 as libc::c_int + 1 as libc::c_int);
};
}
#[no_mangle]
pub unsafe extern "C" fn suspend(mut s: *mut libc::c_char) {
let mut fd: libc::c_int = 0;
let mut k: libc::c_int = 0;
let mut buf: [libc::c_uchar; 128] = [0; 128];
fd = creat(s, 0o644);
if fd < 0 as libc::c_int {
error(b"suspend\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char, strsym(s));
}
memcpy(buf.as_mut_ptr() as *mut libc::c_void,
b"KL21\x00" as *const u8 as *const libc::c_char as
*const libc::c_void,
strlen(b"KL21\x00" as *const u8 as
*const libc::c_char).wrapping_add(1
));
k =
strlen(b"KL21\x00" as *const u8 as
*const libc::c_char).wrapping_add(1
) as
libc::c_int;
buf[k as usize] =
(8192 as libc::c_int >> 8 as libc::c_int) as libc::c_uchar;
buf[(k + 1 as libc::c_int) as usize] =
8192 as libc::c_int as libc::c_uchar;
buf[(k + 2 as libc::c_int) as usize] =
(Freelist >> 8 as libc::c_int) as libc::c_uchar;
buf[(k + 3 as libc::c_int) as usize] = Freelist as libc::c_uchar;
buf[(k + 4 as libc::c_int) as usize] =
(Symbols >> 8 as libc::c_int) as libc::c_uchar;
buf[(k + 5 as libc::c_int) as usize] = Symbols as libc::c_uchar;
buf[(k + 6 as libc::c_int) as usize] =
(Id >> 8 as libc::c_int) as libc::c_uchar;
buf[(k + 7 as libc::c_int) as usize] = Id as libc::c_uchar;
dowrite(fd, buf.as_mut_ptr() as *mut libc::c_void, k + 8 as libc::c_int);
dowrite(fd, Car.as_mut_ptr() as *mut libc::c_void,
(8192 as libc::c_int as
libc::c_ulong).wrapping_mul(::std::mem::size_of::<libc::c_short>()
as libc::c_ulong) as
libc::c_int);
dowrite(fd, Cdr.as_mut_ptr() as *mut libc::c_void,
(8192 as libc::c_int as
libc::c_ulong).wrapping_mul(::std::mem::size_of::<libc::c_short>()
as libc::c_ulong) as
libc::c_int);
dowrite(fd, Tag.as_mut_ptr() as *mut libc::c_void, 8192 as libc::c_int);
close(fd);
}
#[no_mangle]
pub unsafe extern "C" fn doread(mut fd: libc::c_int, mut b: *mut libc::c_void,
mut k: libc::c_int) {
if read(fd, b, k as size_t) != k as libc::c_long {
error(b"read error\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char, 8192 as libc::c_int + 1 as libc::c_int);
};
}
#[no_mangle]
pub unsafe extern "C" fn fasload(mut s: *mut libc::c_char) {
let mut fd: libc::c_int = 0;
let mut k: libc::c_int = 0;
let mut n: libc::c_int = 0;
let mut buf: [libc::c_uchar; 128] = [0; 128];
let mut badimg: *mut libc::c_char = 0 as *mut libc::c_char;
badimg =
b"bad image\x00" as *const u8 as *const libc::c_char as
*mut libc::c_char;
fd = open(s, 0 as libc::c_int);
if fd < 0 as libc::c_int { return }
k =
strlen(b"KL21\x00" as *const u8 as
*const libc::c_char).wrapping_add(1
) as
libc::c_int;
doread(fd, buf.as_mut_ptr() as *mut libc::c_void, k + 8 as libc::c_int);
n =
(buf[k as usize] as libc::c_int) << 8 as libc::c_int |
buf[(k + 1 as libc::c_int) as usize] as libc::c_int;
Freelist =
(buf[(k + 2 as libc::c_int) as usize] as libc::c_int) <<
8 as libc::c_int |
buf[(k + 3 as libc::c_int) as usize] as libc::c_int;
Symbols =
(buf[(k + 4 as libc::c_int) as usize] as libc::c_int) <<
8 as libc::c_int |
buf[(k + 5 as libc::c_int) as usize] as libc::c_int;
Id =
(buf[(k + 6 as libc::c_int) as usize] as libc::c_int) <<
8 as libc::c_int |
buf[(k + 7 as libc::c_int) as usize] as libc::c_int;
if n != 8192 as libc::c_int ||
memcmp(buf.as_mut_ptr() as *const libc::c_void,
b"KL21\x00" as *const u8 as *const libc::c_char as
*const libc::c_void, k.try_into().unwrap()) !=
0 as libc::c_int {
error(badimg, 8192 as libc::c_int + 1 as libc::c_int);
}
doread(fd, Car.as_mut_ptr() as *mut libc::c_void,
(8192 as libc::c_int as
libc::c_ulong).wrapping_mul(::std::mem::size_of::<libc::c_short>()
as libc::c_ulong) as
libc::c_int);