-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshutt.s
1240 lines (1104 loc) · 32.5 KB
/
shutt.s
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
@
@ shutt.s -- John Shutt's "Kernel" Language core
@
@ Copyright 2021 Dale Schumacher
@
@ Licensed under the Apache License, Version 2.0 (the "License");
@ you may not use this file except in compliance with the License.
@ You may obtain a copy of the License at
@
@ http://www.apache.org/licenses/LICENSE-2.0
@
@ Unless required by applicable law or agreed to in writing, software
@ distributed under the License is distributed on an "AS IS" BASIS,
@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ See the License for the specific language governing permissions and
@ limitations under the License.
@
@ View this file with hard tabs every 8 positions.
@ | | . | . . . . max width ->
@ | | . | . . . . max width ->
@ If your tabs are set correctly, the lines above should be aligned.
@
.set S_SELF, 0x00 @ "visit"
.set S_GET, 0x01 @ "lookup"
.set S_SET, 0x02 @ "bind"
.set S_EVAL, 0x03
.set S_APPL, 0x04 @ "combine"
.set S_OPER, 0x05 @ "unwrap"
.set S_EXEC, 0x06
.set S_PUSH, 0x07
.set S_POP, 0x08
.set S_PUT, 0x09
.set S_PULL, 0x0A
@ CREATE Fail WITH \msg.[ THROW (#Undefined, SELF, msg) ]
.text
.align 5 @ align to cache-line
.global a_fail
a_fail: @ singleton failure actor
bl fail @ signal an error
b complete @ return to dispatcher
@
@ FIXME!
@ This failure handler allows multiple failures to be reported,
@ but does not ensure that customers, if any, receive a reply.
@ We should implement a top-level error-handler, initially a_exit,
@ that can be called (or sent a message) to signal an error.
@ During sexpr evaluation, it can be a one-shot customer
@ that will either return normally or signal exactly one error
@ and ignore all subsequent responses. This way, if fork/join
@ is still running, it will safely run to completion without
@ confusing a customer that has already received an error signal.
@ We need to think carefully about when a new error handler
@ can be safely installed or removed during asynchronous computation.
@
.global self_eval
self_eval: @ any self-evaluating actor
@ message = (cust, #S_SELF)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req from message
teq r3, #S_SELF
bne 1f @ if req == "visit"
bl reserve @ allocate event block
ldmib ip, {r2-r8} @ copy actor state
stmib r0, {r2-r8} @ write into event
b _a_reply @ reply and return
1:
teq r3, #S_EVAL @ else if req != "eval"
bne a_fail @ signal error and return to dispatcher
bl reserve @ allocate event block
ldr r1, [fp] @ get SELF from message
b _a_answer @ actor is self-evaluating
@ LET Self_EVAL = \(cust, req).[
@ CASE req OF
@ (#eval, _) : [ SEND SELF TO cust ]
@ _ : [ THROW (#Not-Understood, SELF, req) ]
@ END
@ ]
.text
.align 5 @ align to cache-line
.global a_inert
a_inert: @ "#inert" singleton
b self_eval @ self-evaluating
.global a_no_bind
a_no_bind: @ "#ignore" singleton
b self_eval @ self-evaluating
.global a_true
a_true: @ "#t" singleton
b self_eval @ self-evaluating
.global a_false
a_false: @ "#f" singleton
b self_eval @ self-evaluating
@ LET Number(int32) = \(cust, req).[
@ CASE req OF
@ (#eval, env) : [ SEND SELF TO cust ]
@ _ : [ THROW (#Not-Understood, SELF, req) ]
@ END
@ ]
.global b_number
b_number: @ integer constant
@ (example_5: 0x04=int32, 0x08=, 0x0c=)
@ message = (cust, #S_SELF)
@ | (cust, #S_EVAL, env)
@ although numbers are self-evaluating,
@ we need a distinct behavior
@ to serve as a "type" tag
b self_eval @ self-evaluating
@ fill out the cache-line with unique values to help eq_p() function
.int 0x01234567 @ 0x14
.int 0x89ABCDEF @ 0x18
.int 0xda15ef2e @ 0x1c
@ LET Binding(symbol, value, next) = \(cust, req).[
@ CASE req OF
@ (#lookup, $symbol) : [ SEND value TO cust ]
@ (#bind, $symbol, value') : [
@ BECOME Binding(symbol, value', next)
@ SEND Inert TO cust
@ ]
@ (#eval, env) : [ SEND SELF TO cust ]
@ _ : [ SEND (cust, req) TO next ]
@ END
@ ]
.text
.align 5 @ align to cache-line
.global b_binding
b_binding: @ symbol binding
@ (example_5: 0x04=symbol, 0x08=value, 0x0c=next, 0x10=left, 0x14=right)
@ message = (cust, #S_GET, symbol')
@ | (cust, #S_SET, symbol', value')
ldmib ip, {r4-r6} @ r4=symbol, r5=value, r6=next
ldr r3, [fp, #0x08] @ get req
teq r3, #S_GET
bne 1f @ if req == "get"
ldr r3, [fp, #0x0c] @ get symbol'
5:
teq r3, r4
@ bne 3f @ if symbol == symbol'
bne 4f @ if symbol == symbol'
ldr r0, [fp, #0x04] @ get cust
mov r1, r5 @ get value
bl send_1 @ send message
b complete @ return to dispatcher
1:
teq r3, #S_SET
bne 2f @ else if req == "set"
ldr r0, [fp, #0x04] @ get cust
ldr r1, =a_inert @ message is "#inert"
bl send_1 @ send message
ldr r5, [fp, #0x10] @ get value'
str r5, [ip, #0x04] @ set value
b complete @ return to dispatcher
2:
teq r3, #S_EVAL
bne 3f @ else if req == "eval"
bl reserve @ allocate event block
mov r1, ip @ get SELF
b _a_answer @ was are self-evaluating
3:
bl reserve @ allocate event block
mov r1, r6 @ target is next
ldmia fp, {r2-r9} @ copy current event
stmia r0, {r2-r9} @ write new event
b _a_send @ set target, send, and return to dispatcher
4:
mov ip, r6 @ SELF := next
ldr r0, [ip, #0x1c] @ get beh
ldr r1, =b_binding
teq r0, r1 @ if beh == b_binding
bne 3b
ldmib ip, {r4-r6} @ reload: r4=symbol, r5=value, r6=next
b 5b @ check next binding
@ LET Scope(parent) = \(cust, req).[
@ CASE req OF
@ (#bind, symbol, value) : [
@ CREATE next WITH Scope(parent)
@ BECOME Binding(symbol, value, next)
@ SEND Inert TO cust
@ ]
@ (#eval, env) : [ SEND SELF TO cust ]
@ _ : [ SEND (cust, req) TO parent ]
@ END
@ ]
.text
.align 5 @ align to cache-line
.global b_scope
b_scope: @ binding scope
@ (example_5: 0x04=, 0x08=, 0x0c=parent, 0x10=root)
@ message = (cust, #S_SET, symbol, value)
@ | (cust, #S_GET, symbol)
ldr r4, [ip, #0x0c] @ get parent
ldr r5, [ip, #0x10] @ get root
ldr r3, [fp, #0x08] @ get req
teq r3, #S_SET
bne 1f @ if req == "set"
ldr r0, [fp, #0x04] @ get cust
ldr r1, =a_inert @ message is "#inert"
bl send_1 @ send message
ldr r0, =b_scope @ scope behavior
bl create_5 @ create next actor
str r4, [r0, #0x0c] @ set parent
str r5, [r0, #0x10] @ set root
ldr r5, [fp, #0x0c] @ get symbol
ldr r6, [fp, #0x10] @ get value
mov r7, r0 @ get next
mov r8, #0 @ clear left
mov r9, #0 @ clear right
stmib ip, {r5-r9} @
ldr r0, =b_binding @ binding behavior
ldr r0, [ip, #0x1c] @ BECOME
b complete @ return to dispatcher
1:
teq r3, #S_EVAL
bne 2f @ else if req == "eval"
bl reserve @ allocate event block
mov r1, ip @ get SELF
b _a_answer @ was are self-evaluating
2:
teq r3, #S_GET
bne 3f @ else if req == "get"
movs r0, r5 @ get root
beq 3f @ if root != NULL
ldr r1, [fp, #0x0c] @ get symbol
bl splay_search @ binding = splay_search(root, symbol)
movs r5, r0 @ if (binding == NULL)
beq a_empty_env @ report undefined symbol
str r5, [ip, #0x10] @ update root
ldr r1, [r0, #0x08] @ get value
ldr r0, [fp, #0x04] @ get cust
bl send_1 @ send message
b complete @ return to dispatcher
3:
bl reserve @ allocate event block
mov r1, r4 @ target is parent
ldmia fp, {r2-r9} @ copy current event
stmia r0, {r2-r9} @ write new event
b _a_send @ set target, send, and return to dispatcher
@ CREATE Nil WITH \(cust, req).[
@ CASE req OF
@ (#eval, _) : [ SEND SELF TO cust ]
@ _ : [ THROW (#Not-Understood, SELF, req) ]
@ END
@ ]
.text
.align 5 @ align to cache-line
.global a_nil
a_nil: @ "()" singleton
@ message = (cust, #S_SELF)
@ | (cust, #S_EVAL, env)
ldr pc, [ip, #0x1c] @ jump to actor behavior
.int a_nil @ 0x04: self reference
.int a_nil @ 0x08: self reference
.int a_nil @ 0x0c: self reference
.int a_nil @ 0x10: self reference
.int a_nil @ 0x14: self reference
.int a_nil @ 0x18: self reference
.int self_eval @ 0x1c: address of actor behavior
@ LET Symbol(name) = \(cust, req).[
@ CASE req OF
@ (#eval, env) : [ SEND (cust, #lookup, SELF) TO env ]
@ _ : [ THROW (#Not-Understood, SELF, req) ]
@ END
@ ]
.text
.align 5 @ align to cache-line
.global b_symbol
b_symbol: @ symbolic variable name
@ (example_5: [0x04..0x1b]=name)
@ message = (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_SELF
bne 1f @ if req == "visit"
bl reserve @ allocate event block
ldmib ip, {r2-r8} @ copy actor state
stmib r0, {r2-r8} @ write into event
b _a_reply @ reply and return
1:
teq r3, #S_EVAL
bne 2f @ else if req == "eval"
bl reserve @ allocate event block
ldr r4, [fp, #0x0c] @ get env
ldr r5, [fp, #0x04] @ get cust
mov r6, #S_GET
mov r7, ip @ get SELF
stmia r0, {r4-r7} @ write new event
b _a_end @ lookup name in environment
2:
bl fail @ else
b complete @ signal error and return to dispatcher
@ LET Pair(left, right) = \(cust, req).[
@ CASE req OF
@ (#eval, env) : [
@ SEND (k_comb, #eval, env) TO left
@ CREATE k_comb WITH \comb.[
@ SEND (cust, #comb, right, env) TO comb
@ ]
@ ]
@ _ : [ THROW (#Not-Understood, SELF, req) ]
@ END
@ ]
.text
.align 5 @ align to cache-line
.global b_pair
b_pair: @ pair combination
@ (example_5: 0x04=left, 0x08=right, 0x0c=)
@ message = (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_SELF
bne 1f @ if req == "visit"
bl reserve @ allocate event block
ldmib ip, {r2-r8} @ copy actor state
stmib r0, {r2-r8} @ write into event
b _a_reply @ reply and return
1:
teq r3, #S_EVAL
bne 2f @ else if req == "eval"
ldr r0, =k_comb
bl create_5 @ create k_comb actor
ldr r6, [fp, #0x04] @ get cust
mov r7, #S_APPL
ldr r8, [ip, #0x08] @ get right
ldr r9, [fp, #0x0c] @ get env
stmib r0, {r6-r9} @ write actor state
ldr r4, [ip, #0x04] @ get left
mov r5, r0 @ k_comb
mov r6, #S_EVAL
mov r7, r9 @ env
bl send_3x @ send message to left
b complete @ return to dispatch loop
2:
bl fail @ else
b complete @ signal error and return to dispatcher
k_comb: @ combiner continuation
@ (example_5: 0x04=cust, 0x08=#S_APPL, 0x0c=right, 0x10=env)
@ message = (combiner)
ldr r0, [fp, #0x04] @ combiner
bl combiner_p
teq r0, #0 @ if !combiner_p(combiner)
beq a_kernel_err @ signal error
mov r0, ip @ continuation actor becomes an event...
b _a_reply @ delegate to combiner
@
@ "visitor" style evaluator
@
.text
.align 5 @ align to cache-line
.global v_eval
v_eval: @ evaluation visitor
@ (example_5: 0x04=cust, 0x08=sexpr, 0x0c=env, 0x10=)
@ message = (0x04..0x18=state, 0x1c=behavior)
ldr r0, [fp, #0x1c] @ get behavior (type signature)
ldr r1, =b_symbol
teq r0, r1
bne 1f @ if symbol_p(message)
@ (example_5: [0x04..0x1b]=name)
mov r0, ip @ re-use SELF as message-event
ldr r4, [ip, #0x0c] @ target = env
ldr r5, [ip, #0x04] @ get cust
mov r6, #S_GET @ lookup name in environment
mov r7, ip @ get SELF
stmia r0, {r4-r7} @ write data to event
b _a_end @ send and return
1:
ldr r1, =b_pair
teq r0, r1
bne 2f @ else if pair_p(message)
@ (example_5: 0x04=left, 0x08=right)
ldr r0, [fp, #0x08] @ cdr(message)
str r0, [ip, #0x10] @ store params
ldr r0, =v_comb @ new behavior
str r0, [ip, #0x1c] @ BECOME
mov r4, ip @ cust = SELF
ldr r5, [fp, #0x04] @ sexpr = car(message)
ldr r6, [ip, #0x0c] @ get env
ldr r0, =v_eval @ evaluation visitor
bl create_5 @ new visitor actor
stmib r0, {r4-r6} @ store cust, sexpr, env
mov r2, #S_SELF @ "visit" message
mov r1, r0 @ cust = new visitor
mov r0, r5 @ target = sexpr
bl send_2 @ send message
b complete @ return to dispatch loop
2:
mov r0, ip @ else
ldr r4, [ip, #0x04] @ target = cust
ldr r5, [ip, #0x08] @ result = sexpr
stmia r0, {r4-r5} @ write data to event (fka SELF)
b _a_end @ send and return
v_comb: @ combination continuation
@ (example_5: 0x04=cust, 0x08=sexpr, 0x0c=env, 0x10=params)
@ message = (combiner)
ldr r0, [fp, #0x04] @ combiner
bl combiner_p
teq r0, #0 @ if !combiner_p(combiner)
beq a_kernel_err @ signal error
mov r0, ip @ re-use SELF as message-event
ldr r4, [fp, #0x04] @ target = combiner
ldr r5, [ip, #0x04] @ get cust
mov r6, #S_APPL @ "combine" request
ldr r7, [ip, #0x10] @ get params
ldr r8, [ip, #0x0c] @ get env
stmia r0, {r4-r8} @ write data to event
b _a_end @ send and return
@
@ built-in operatives and applicatives
@
.text
.align 5 @ align to cache-line
.global op_list
op_list: @ operative "$list"
@ message = (cust, #S_APPL, opnds, env)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 1f @ if req == "combine"
bl reserve @ allocate event block
ldr r1, [fp, #0x0c] @ get operands
b _a_answer @ send to customer and return
1:
b self_eval @ else we are self-evaluating
.text
.align 5 @ align to cache-line
k_list: @ operative call continuation
@ (example_5: 0x04=cust, 0x08=oper, 0x0c=env)
@ message = (args)
ldr r4, [ip, #0x08] @ target = oper
ldr r5, [ip, #0x04] @ cust
mov r6, #S_APPL @ "combine"
ldr r7, [fp, #0x04] @ args
ldr r8, [ip, #0x0c] @ env
bl reserve @ allocate event block
stmia r0, {r4-r8} @ write data to event
b _a_end @ send and return
.text
.align 5 @ align to cache-line
.global b_appl
b_appl: @ applicative wrapper behavior
@ (example_5: 0x04=oper, 0x08=, 0x0c=)
@ message = (cust, #S_APPL, opnds, env)
@ | (cust, #S_OPER)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 1f @ if req == "combine"
ldr r5, [fp, #0x04] @ get cust
ldr r6, [ip, #0x04] @ get operative
ldr r7, [fp, #0x10] @ get env
ldr r0, =k_list @ k_cust behavior
bl create_5 @ create k_cust
stmib r0, {r5-r7} @ store cust, oper, env
mov r5, r0 @ cust = k_cust
bl reserve @ allocate event block
ldr r4, =a_map_eval @ target
@ mov r5, r5 @ cust (already in r5)
ldr r6, [fp, #0x0c] @ list = opnds
ldr r7, [fp, #0x10] @ env
stmia r0, {r4-r7} @ write data to event
b _a_end @ send and return
1:
teq r3, #S_OPER @ else if req != "unwrap" self-evaluate
bne self_eval @ else
bl reserve @ allocate event block
ldr r1, [ip, #0x04] @ get operative [FIXME: "unwrap" may get oper directly...]
b _a_answer @ send to customer and return
.text
.align 5 @ align to cache-line
.global ap_list
ap_list: @ applicative "list"
ldr pc, [ip, #0x1c] @ jump to actor behavior
.int op_list @ 0x04: operative
.int 0 @ 0x08: -
.int 0 @ 0x0c: --
.int 0 @ 0x10: --
.int 0 @ 0x14: --
.int 0 @ 0x18: --
.int b_appl @ 0x1c: address of actor behavior
.text
.align 5 @ align to cache-line
.global ap_list
a_map_eval: @ sequential list evaluator
@ message = (cust, list, env)
ldr r0, [fp, #0x04] @ get cust
ldr r1, [fp, #0x08] @ get list
ldr r2, =a_nil @ get ()
teq r1, r2
bne 1f @ if list == ()
bl send_1 @ send () to cust
b complete @ return
1: @ else
ldr r7, [fp, #0x0c] @ save env
mov r8, r0 @ save cust
mov r9, r1 @ save list
mov r0, r9 @ get list
bl car
movs r4, r0 @ target = car(list)
beq a_kernel_err @ if (target == NULL) signal error
mov r0, r9 @ get list
bl cdr
movs r5, r0 @ tail = cdr(list)
beq a_kernel_err @ if (tail == NULL) signal error
ldr r0, =k_map_eval_1 @ k_cust behavior
bl create_5 @ create k_cust
str r8, [r0, #0x04] @ store cust
str r5, [r0, #0x08] @ store tail
str r7, [r0, #0x0c] @ store env
mov r5, r0 @ cust = k_cust
bl reserve @ allocate event block
mov r6, #S_EVAL @ "eval"
stmia r0, {r4-r7} @ write data to event
b _a_end @ send and return
k_map_eval_1: @ eval arg continuation
@ (example_5: 0x04=cust, 0x08=tail, 0x0c=env)
@ message = (arg)
bl reserve @ allocate event block
ldr r4, =a_map_eval @ target
mov r5, ip @ k_cust = SELF
ldr r6, [ip, #0x08] @ list
ldr r7, [ip, #0x0c] @ env
stmia r0, {r4-r7} @ write data to event
bl enqueue @ send message
ldr r0, [fp, #0x04] @ get arg
str r0, [ip, #0x08] @ store arg
ldr r0, =k_map_eval_2 @ become...
str r0, [ip, #0x1c] @ ...k_map_eval_2
b complete @ return to dispatch loop
k_map_eval_2: @ eval args continuation
@ (example_5: 0x04=cust, 0x08=arg, 0x0c=)
@ message = (args)
bl reserve @ allocate event block
ldr r1, [ip, #0x04] @ get cust
ldr r2, [ip, #0x08] @ get arg
ldr r3, [fp, #0x04] @ get args
str r2, [ip, #0x04] @ store left
str r3, [ip, #0x08] @ store right
ldr r3, =b_pair @ become...
str r3, [ip, #0x1c] @ ...b_pair
str ip, [r0, #0x04] @ message is SELF
b _a_send @ send to customer and return
.text
.align 5 @ align to cache-line
.global op_wrap
op_wrap: @ operative "$wrap"
@ message = (cust, #S_APPL, opnds, env)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 1f @ if req == "combine"
ldr r0, [fp, #0x0c] @ get opnds
ldr r1, =combiner_p @ predicate
bl match_1_arg
mov r4, r0 @ save combiner
ldr r0, =b_appl @ applicative behavior
bl create_5 @ create applicative
str r4, [r0, #0x04] @ set combiner
mov r4, r0 @ save applicative
bl reserve @ allocate event block
str r4, [r0, #0x04] @ reply with applicative
b _a_reply @ send reply and return
1:
b self_eval @ else we are self-evaluating
.text
.align 5 @ align to cache-line
.global ap_wrap
ap_wrap: @ applicative "wrap"
ldr pc, [ip, #0x1c] @ jump to actor behavior
.int op_wrap @ 0x04: operative
.int 0 @ 0x08: -
.int 0 @ 0x0c: --
.int 0 @ 0x10: --
.int 0 @ 0x14: --
.int 0 @ 0x18: --
.int b_appl @ 0x1c: address of actor behavior
.text
.align 5 @ align to cache-line
.global op_vau
op_vau: @ operative "$vau"
@ message = (cust, #S_APPL, opnds, env)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 2f @ if req == "combine"
ldr r9, [fp, #0x0c] @ get opnds
mov r0, r9
bl car @ formals
movs r4, r0 @ if NULL
beq a_kernel_err @ signal error
mov r0, r9
bl cdr @ next opnd
movs r9, r0 @ if NULL
beq a_kernel_err @ signal error
@ mov r0, r9
bl car @ eformal
movs r5, r0 @ if NULL
beq a_kernel_err @ signal error
ldr r1, =a_no_bind
teq r0, r1
beq 1f @ if (eformal != #ignore)
bl symbol_p
teq r0, #0 @ && !symbol_p(eformal)
beq a_kernel_err @ signal error
1:
mov r0, r9
bl cdr @ body
movs r6, r0 @ if NULL
beq a_kernel_err @ signal error
ldr r7, [fp, #0x10] @ get env
ldr r0, =b_oper
bl create_5 @ create operative
stmib r0, {r4-r7} @ store formals, eformal, body, env
mov r8, r0
bl reserve @ allocate event block
str r8, [r0, #0x04] @ reply with operative
b _a_reply @ send reply and return
2:
b self_eval @ else we are self-evaluating
.text
.align 5 @ align to cache-line
.global b_oper
b_oper: @ compound operative behavior
@ (example_5: 0x04=formals, 0x08=eformal, 0x0c=body, 0x10=senv)
@ message = (cust, #S_APPL, opnds, denv)
@ | (cust, #S_OPER)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 2f @ if req == "combine"
@ (example_5: 0x04=, 0x08=, 0x0c=parent)
ldr r0, =b_scope @ empty env behavior
bl create_5 @ create "local" env
ldr r1, [ip, #0x10] @ get senv
str r1, [r0, #0x0c] @ set parent
mov r2, #0
str r2, [r0, #0x10] @ clear root
mov r4, r0 @ save local env
ldr r5, [ip, #0x04] @ save formals
ldr r6, [fp, #0x0c] @ save opnds
ldr r0, [ip, #0x08] @ get eformal
ldr r1, =a_no_bind
teq r0, r1
beq 1f @ if (eformal != #ignore)
@ mov r0, r0 @ get eformal (already in r0)
mov r1, r5 @ get formals
bl cons @ cons(eformal, formals)
movs r5, r0 @ update formals
beq a_kernel_err @ if NULL signal error
ldr r0, [fp, #0x10] @ get denv
mov r1, r6 @ get opnds
bl cons @ cons(eformal, opnds)
movs r6, r0 @ update opnds
beq a_kernel_err @ if NULL signal error
1:
mov r0, r5 @ def = formals
mov r1, r6 @ arg = opnds
mov r2, r4 @ env = local env
bl match_param_tree
teq r0, #0 @ if NULL
beq a_kernel_err @ signal error
@ <debug>
@ mov r9, r0 @ save ext env
@ ldr r1, [ip, #0x10] @ stop at senv
@ bl dump_env @ dump ext env
@ mov r0, r9 @ restore ext env
@ </debug>
@ mov r0, r0 @ get ext env (already in r0)
mov r1, r4 @ get local env
bl mutate_environment
teq r0, #0 @ if NULL
beq a_kernel_err @ signal error
ldr r5, [fp, #0x04] @ get cust
ldr r6, =a_inert @ result = #inert
mov r7, r0 @ env = local env
ldr r0, =v_sequence @ k_seq behavior
bl create_5 @ create k_seq
stmib r0, {r5-r7} @ store cust, result, env
mov r5, r0 @ cust = k_seq
@ <debug>
@ ldr r0, [ip, #0x0c] @ body sexpr
@ bl print_sexpr @ print body to console
@ bl serial_eol @ newline
@ </debug>
bl reserve @ allocate event block
ldr r4, [ip, #0x0c] @ target = body
@ mov r5, r5 @ cust (already in r5)
mov r6, #S_SELF @ "visit"
stmia r0, {r4-r6} @ write data to event
b _a_end @ send and return
2:
b self_eval @ else we are self-evaluating
.text
.align 5 @ align to cache-line
.global v_sequence
v_sequence: @ sequential evaluation visitor
@ (example_5: 0x04=cust, 0x08=result, 0x0c=env, 0x10=next)
@ message = (0x04..0x18=state, 0x1c=behavior)
ldr r0, [fp, #0x1c] @ get behavior (type signature)
ldr r1, =self_eval
teq r0, r1
bne 1f @ if null_p(message)
@ (example_5: 0x04=a_nil, 0x08=a_nil)
ldr r4, [ip, #0x04] @ target = cust
ldr r5, [ip, #0x08] @ answer = result
mov r0, ip @ re-use k_seq as final message
stmia r0, {r4-r5} @ write data to event
b _a_end @ send and return
1:
ldr r1, =b_pair
teq r0, r1
bne 2f @ else if pair_p(message)
@ (example_5: 0x04=left, 0x08=right)
ldr r0, [fp, #0x08] @ cdr(message)
str r0, [ip, #0x10] @ store next
ldr r0, =k_seq_eval @ new behavior
str r0, [ip, #0x1c] @ BECOME
bl reserve @ allocate event block
ldr r4, [fp, #0x04] @ target = car(message)
mov r5, ip @ cust = SELF
mov r6, #S_EVAL @ "eval"
ldr r7, [ip, #0x0c] @ env
stmia r0, {r4-r7} @ write data to event
b _a_end @ send and return
2:
b a_kernel_err @ else signal error
k_seq_eval: @ sequential evaluation continuation
@ (example_5: 0x04=cust, 0x08=result, 0x0c=env, 0x10=next)
@ message = (result')
ldr r0, [fp, #0x04] @ get result'
str r0, [ip, #0x08] @ update result
ldr r0, =v_sequence @ new behavior
str r0, [ip, #0x1c] @ BECOME
bl reserve @ allocate event block
ldr r4, [ip, #0x10] @ target = next
mov r5, ip @ cust = SELF
mov r6, #S_SELF @ "visit"
stmia r0, {r4-r6} @ write data to event
b _a_end @ send and return
.text
.align 5 @ align to cache-line
.global op_unwrap
op_unwrap: @ operative "$unwrap"
@ message = (cust, #S_APPL, opnds, env)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 1f @ if req == "combine"
ldr r0, [fp, #0x0c] @ get opnds
ldr r1, =applicative_p @ predicate
bl match_1_arg
@ (example_5: 0x04=oper, 0x08=, 0x0c=)
ldr r4, [r0, #0x04] @ get combiner
bl reserve @ allocate event block
mov r1, r4 @ result = combiner
b _a_answer @ send to customer and return
1:
b self_eval @ else we are self-evaluating
.text
.align 5 @ align to cache-line
.global ap_unwrap
ap_unwrap: @ applicative "unwrap"
ldr pc, [ip, #0x1c] @ jump to actor behavior
.int op_unwrap @ 0x04: operative
.int 0 @ 0x08: -
.int 0 @ 0x0c: --
.int 0 @ 0x10: --
.int 0 @ 0x14: --
.int 0 @ 0x18: --
.int b_appl @ 0x1c: address of actor behavior
.text
.align 5 @ align to cache-line
.global op_define
op_define: @ operative "$define!"
@ message = (cust, #S_APPL, opnds, env)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 1f @ if req == "combine"
ldr r0, [fp, #0x0c] @ get opnds
ldr r1, =object_p @ predicate 1
ldr r2, =object_p @ predicate 2
bl match_2_args
mov r6, r0 @ definiend
mov r4, r1 @ expression
ldr r0, =k_bind
bl create_5 @ create k_bind actor
ldr r5, [fp, #0x04] @ get cust
@ mov r6, r6 @ get definiend (already in r6)
ldr r7, [fp, #0x10] @ get env
stmib r0, {r5-r7} @ write actor state
@ mov r4, r4 @ target = expression (already in r4)
mov r5, r0 @ cust = k_bind
mov r6, #S_EVAL
@ ldr r7, [fp, #0x0c] @ get env (already in r7)
bl reserve @ allocate event block
stmia r0, {r4-r7} @ write message
b _a_end @ send message and return
1:
b self_eval @ else we are self-evaluating
k_bind: @ binding continuation
@ (example_5: 0x04=cust, 0x08=definiend, 0x0c=env)
@ message = (arg)
ldr r0, [ip, #0x08] @ get def
ldr r1, [fp, #0x04] @ get arg
ldr r2, [ip, #0x0c] @ get env
bl match_param_tree
teq r0, #0 @ if NULL
beq a_kernel_err @ signal error
ldr r1, [ip, #0x0c] @ get env
bl mutate_environment
teq r0, #0 @ if NULL
beq a_kernel_err @ signal error
ldr r1, [ip, #0x04] @ get cust
mov r0, ip @ continuation actor becomes an event...
ldr r2, =a_inert @ message is #inert
str r2, [ip, #0x04]
b _a_send @ send message and return
.text
.align 5 @ align to cache-line
.global op_sequence
op_sequence: @ operative "$sequence"
@ message = (cust, #S_APPL, opnds, env)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 1f @ if req == "combine"
ldr r5, [fp, #0x04] @ get cust
ldr r6, =a_inert @ result = #inert
ldr r7, [fp, #0x10] @ get env
ldr r0, =v_sequence @ k_seq behavior
bl create_5 @ create k_seq
stmib r0, {r5-r7} @ store cust, result, env
mov r5, r0 @ cust = k_seq
bl reserve @ allocate event block
ldr r4, [fp, #0x0c] @ target = opnds
@ mov r5, r5 @ cust (already in r5)
mov r6, #S_SELF @ "visit"
stmia r0, {r4-r6} @ write data to event
b _a_end @ send and return
1:
b self_eval @ else we are self-evaluating
.text
.align 5 @ align to cache-line
.global op_timed
op_timed: @ operative "$timed"
@ message = (cust, #S_APPL, opnds, env)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 1f @ if req == "combine"
ldr r5, [fp, #0x04] @ get cust
ldr r0, =k_timed @ k_timed behavior
bl create_5 @ create k_timed
str r5, [r0, #0x04] @ store cust
mov r5, r0 @ cust = k_timed
bl timer_start @ start global timer
@ ldr r5, [fp, #0x04] @ k_timed already in r5
ldr r6, =a_inert @ result = #inert
ldr r7, [fp, #0x10] @ get env
ldr r0, =v_sequence @ k_seq behavior
bl create_5 @ create k_seq
stmib r0, {r5-r7} @ store cust, result, env
mov r5, r0 @ cust = k_seq
bl reserve @ allocate event block
ldr r4, [fp, #0x0c] @ target = opnds
@ mov r5, r5 @ cust (already in r5)
mov r6, #S_SELF @ "visit"
stmia r0, {r4-r6} @ write data to event
b _a_end @ send and return
1:
b self_eval @ else we are self-evaluating
k_timed: @ timed continuation
@ (example_5: 0x04=cust, 0x08=, 0x0c=)
@ message = (arg)
@ ldr r4, [fp, #0x04] @ get arg
bl timer_stop @ get elapsed time
bl number @ construct a kernel number
mov r4, r0 @ save elapsed time
ldr r1, [ip, #0x04] @ get cust
mov r0, ip @ continuation actor becomes an event...
str r4, [ip, #0x04] @ message is elapsed time
b _a_send @ send message and return
.text
.align 5 @ align to cache-line
.global op_lambda
op_lambda: @ operative "$lambda"
@ message = (cust, #S_APPL, opnds, env)
@ | (cust, #S_EVAL, env)
ldr r3, [fp, #0x08] @ get req
teq r3, #S_APPL
bne 1f @ if req == "combine"
ldr r9, [fp, #0x0c] @ get opnds
mov r0, r9
bl car @ formals
movs r4, r0 @ if NULL
beq a_kernel_err @ signal error
ldr r5, =a_no_bind @ eformal (always #ignore)
mov r0, r9
bl cdr @ body
movs r6, r0 @ if NULL