blob: eeb36d8fa91edc3bffba54c8f57a66c7216dfba5 (
plain) (
blame)
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
|
implementation module Wrap
import StdOverloaded
:: WrappedDescriptorId = {descriptorId :: !Int}
:: WrappedDescriptor
= WrappedDescriptorCons
| WrappedDescriptorNil
| WrappedDescriptorTuple
| WrappedDescriptorOther !WrappedDescriptorId
:: WrappedNode
= WrappedInt !Int
| WrappedChar !Char
| WrappedBool !Bool
| WrappedReal !Real
| WrappedFile !File
| WrappedString !{#Char}
| WrappedIntArray !{#Int}
| WrappedBoolArray !{#Bool}
| WrappedRealArray !{#Real}
| WrappedFileArray !{#File}
| WrappedArray !{WrappedNode}
| WrappedRecord !WrappedDescriptor !{WrappedNode}
| WrappedOther !WrappedDescriptor !{WrappedNode}
instance toString WrappedDescriptorId where
toString :: WrappedDescriptorId -> {#Char}
toString {descriptorId}
= descriptorIDtoString descriptorId
where
descriptorIDtoString :: !Int -> {#Char}
descriptorIDtoString id
= code
{
.d 0 1 i
jsr DtoAC
.o 1 0
}
Wrap :: !.a -> WrappedNode
Wrap node
= code
{
| A: <node> <result>
| B:
eq_desc BOOL 0 0
jmp_false not_a_bool
pushB_a 0
pop_a 1
fill_r e_Wrap_kWrappedBool 0 1 0 0 0
pop_b 1
.d 1 0
rtn
:not_a_bool
eq_desc INT 0 0
jmp_false not_an_int
pushI_a 0
pop_a 1
fill_r e_Wrap_kWrappedInt 0 1 0 0 0
pop_b 1
.d 1 0
rtn
:not_an_int
eq_desc CHAR 0 0
jmp_false not_a_char
pushC_a 0
pop_a 1
fill_r e_Wrap_kWrappedChar 0 1 0 0 0
pop_b 1
.d 1 0
rtn
:not_a_char
eq_desc REAL 0 0
jmp_false not_a_real
pushR_a 0
pop_a 1
fill_r e_Wrap_kWrappedReal 0 2 0 0 0
pop_b 2
.d 1 0
rtn
:not_a_real
eq_desc FILE 0 0
jmp_false not_a_file
pushF_a 0
pop_a 1
fill_r e_Wrap_kWrappedFile 0 2 0 0 0
pop_b 2
.d 1 0
rtn
:not_a_file
eq_desc ARRAY 1 0
jmp_true wrap_array
eq_desc _ARRAY_ 0 0
jmp_true wrap__array
eq_desc _STRING_ 0 0
jmp_true wrap__string
is_record 0
.d 2 0
jmp_true wrap_record
get_node_arity 0
| B: <n>
eqI_b 0 0
jmp_true wrap_no_args
:wrap_args
push_a 0
push_b 0
push_b 0
repl_args_b
| A: <arg_1 .. arg_n> <node> <result>
push_b 0
create_array_ _ 1 0
| A: <_{args}> <arg_1 .. arg_n> <node> <result>
pushI 0
:wrap_args_loop
| A: <_{args}> <arg_(i+1) .. arg_n> <node> <result>
| B: <i> <n>
| wrap arg
push_a 1
build e_Wrap_sWrap 1 e_Wrap_nWrap
update_a 0 2
pop_a 1
| update i-th element of _args array with wrapped arg
push_b 0
update _ 1 0
| increment index
incI
push_b 0
push_b 2
eqI
jmp_false wrap_args_loop
pop_b 2
| A: <_{args}> <node> <result>
| B:
.d 3 0
jmp wrap_descriptor
:wrap_no_args
| A: <node> <result>
| B: <0>
create_array_ _ 1 0
.o 3 0
:wrap_descriptor
| A: <_{args}> <node> <result>
push_a 1
update_a 1 2
update_a 0 1
pop_a 1
| A: <node> <_{args}> <result>
eq_nulldesc _Tuple 0
jmp_false not_a_tuple
build e_Wrap_dWrappedDescriptorTuple 0 _hnf
.d 4 0
jmp wrap_other
:not_a_tuple
eq_nulldesc _Cons 0
jmp_false not_a_cons
build e_Wrap_dWrappedDescriptorCons 0 _hnf
jmp wrap_other
:not_a_cons
eq_desc _Nil 0 0
jmp_false not_a_nil
build e_Wrap_dWrappedDescriptorNil 0 _hnf
jmp wrap_other
:not_a_nil
| A: <node> <_{args}> <result>
pushD_a 0
build_r e_Wrap_rWrappedDescriptorId 0 1 0 0
pop_b 1
build_r e_Wrap_kWrappedDescriptorOther 1 0 0 0
update_a 0 1
pop_a 1
.o 4 0
:wrap_other
| A: <descriptor> <node> <_{args}> <result>
update_a 0 1
pop_a 1
| A: <descriptor> <_{args}> <result>
fill_r e_Wrap_kWrappedOther 2 0 2 0 0
pop_a 2
| A: <result>
.d 1 0
rtn
.o 2 0
:wrap_record
pushI 0
pushD_a 0
| A: <node> <result>
| B: <desc> <return>
push_t_r_args
:wrap_record_fields
| A: <afield_1 .. afield_m> <result>
| B: <l> <bfield_1 .. bfield_n> <desc> <return>
| (l: points to record layout,
| desc: record descriptor
| return: return selector)
push_b 0
:count_fields_loop
| A: <afield_1 .. afield_m> <result>
| B: <p> <l> <bfield_1 .. bfield_n> <desc> <return>
| (p=l+offset)
push_b 0
push_r_arg_t
eqI_b 0 0
jmp_true end_count_record_fields
pop_b 1
incI
jmp count_fields_loop
:end_count_record_fields
pop_b 1
push_b 0
update_b 2 1
subI
| A: <afield_1 .. afield_m> <result>
| B: <n+m> <l> <bfield_1 .. bfield_n> <desc> <return>
create_array_ _ 1 0
pushI 0
push_b 1
update_b 1 2
update_b 0 1
pop_b 1
:wrap_fields_loop
| A: <_{fields}> <afield_ .. afield_m> <result>
| B: <p> <i> <bfield_ .. bfield_n> <desc> <return>
push_b 0
push_r_arg_t
eqI_b 0 0
jmp_true end_wrap_record_fields
eqC_b 'i' 0
jmp_true wrap_int_field
eqC_b 'c' 0
jmp_true wrap_char_field
eqC_b 'r' 0
jmp_true wrap_real_field
eqC_b 'b' 0
jmp_true wrap_bool_field
eqC_b 'f' 0
jmp_true wrap_file_field
eqC_b 'a' 0
jmp_true wrap_graph_field
print_sc "Wrap: unimplemented record field type\n"
halt
:wrap_int_field
pop_b 1
| create and fill int node
create
fillI_b 2 0
push_a 1
update_a 1 2
update_a 0 1
pop_a 1
update_b 1 2
update_b 0 1
pop_b 1
jmp wrap_field
:wrap_char_field
pop_b 1
| create and fill char node
create
fillC_b 2 0
push_a 1
update_a 1 2
update_a 0 1
pop_a 1
update_b 1 2
update_b 0 1
pop_b 1
jmp wrap_field
:wrap_bool_field
pop_b 1
| create and fill bool node
create
fillB_b 2 0
push_a 1
update_a 1 2
update_a 0 1
pop_a 1
update_b 1 2
update_b 0 1
pop_b 1
jmp wrap_field
:wrap_real_field
pop_b 1
| create and fill real node
create
fillR_b 2 0
push_a 1
update_a 1 2
update_a 0 1
pop_a 1
update_b 1 3
update_b 0 2
pop_b 2
jmp wrap_field
:wrap_file_field
pop_b 1
| create and fill file node
create
fillF_b 2 0
push_a 1
update_a 1 2
update_a 0 1
pop_a 1
update_b 1 3
update_b 0 2
pop_b 2
jmp wrap_field
:wrap_graph_field
pop_b 1
jmp wrap_field
:wrap_field
| A: <_{fields}> <field> <afield_ .. afield_m>
| wrap field
push_a 1
build e_Wrap_sWrap 1 e_Wrap_nWrap
update_a 0 2
pop_a 1
| update i-th element of _fields array with wrapped field
push_b 1
update _ 1 0
| A: <_{fields}> <afield_ .. afield_m> <result>
| B: <p> <i> <bfield_ .. bfield_n> <desc> <return>
| increment index
push_b 1
incI
update_b 0 2
| increment pointer in layout string
pop_b 1
incI
jmp wrap_fields_loop
:end_wrap_record_fields
| A: <_{fields}> <result>
| B: <i=0> <p> <i> <desc> <return>
pop_b 3
| A: <_{fields}> <result>
| B: <desc> <return>
| create WrappedDescriptorOther node
build_r e_Wrap_rWrappedDescriptorId 0 1 0 0
pop_b 1
build_r e_Wrap_kWrappedDescriptorOther 1 0 0 0
update_a 0 1
pop_a 1
| A: <descriptor> <{fields}> <result>
| fill result node
fill_r e_Wrap_kWrappedRecord 2 0 2 0 0
pop_a 2
| A: <result>
| B: <return>
| return to caller (determined by the return selector)
eqI_b 0 0
jmp_true wrap_record_return_node
eqI_b 1 0
jmp_true wrap_record_array_return
print_sc "Wrap: (record fields) unknown return selector\n"
halt
:wrap_record_return_node
| A: <result>
| B: <return>
pop_b 1
.d 1 0
| A: <result>
| B:
rtn
:wrap_array
| A: <array> <result>
| replace ARRAY by _ARRAY_
pushA_a 0
update_a 0 1
pop_a 1
:wrap__array
| A: <_array> <result>
eq_desc _STRING_ 0 0
jmp_false not_a_string
:wrap__string
| fill result node
fill_r e_Wrap_kWrappedString 1 0 1 0 0
pop_a 1
.d 1 0
| A: <result>
rtn
:not_a_string
| push array element descriptor
push_r_args_b 0 0 2 2 1
| A: <_array> <result>
| B: <desc>
push_b 0
eq_desc_b BOOL 0
jmp_true wrap_bool_array
push_b 0
eq_desc_b INT 0
jmp_true wrap_int_array
push_b 0
eq_desc_b REAL 0
jmp_true wrap_real_array
push_b 0
eq_desc_b FILE 0
jmp_true wrap_file_array
pushI 0
push_a 0
push_arraysize _ 0 1
| A: <_array> <result>
| B: <n> <i> <desc>
push_b 2
update_b 2 3
update_b 1 2
update_b 0 1
pop_b 1
| B: <desc> <n> <i>
pushI 0
eqI
| B: <n> <i>
jmp_false wrap_record_array
push_b 0
create_array_ _ 1 0
| A: <_wrapped_array> <_array> <result>
| B: <n> <i>
.d 3 2 i i
jmp wrap_array_test
.o 3 2 i i
:wrap_array_elements
| A: <_wrapped_array> <_array> <result>
| B: <n> <i>
| wrap element
push_b 1
push_a 1
select _ 1 0
build e_Wrap_sWrap 1 e_Wrap_nWrap
| A: <element> <_wrapped_array> <_array> <result>
| B: <n> <i>
| update i-th element of _wrapped_array with wrapped element
push_a 1
push_b 1
update _ 1 0
update_a 0 1
pop_a 1
| B: <n> <i>
| increment index
push_b 1
incI
update_b 0 2
| decrement n
pop_b 1
decI
.o 3 2 i i
:wrap_array_test
| B: <n> <i>
eqI_b 0 0
.d 3 2 i i
jmp_false wrap_array_elements
| A: <_wrapped_array> <_array> <result>
| B: <n> <i>
pop_b 2
update_a 0 1
pop_a 1
| A: <_wrapped_array> <result>
| B:
| fill result node
fill_r e_Wrap_kWrappedArray 1 0 1 0 0
pop_a 1
.d 1 0
| A: <result>
| B:
rtn
:wrap_bool_array
| A: <_array> <result>
| B: <desc>
pop_b 1
| fill result node
fill_r e_Wrap_kWrappedBoolArray 1 0 1 0 0
pop_a 1
.d 1 0
| A: <result>
| B:
rtn
:wrap_int_array
| A: <_array> <result>
| B: <desc>
pop_b 1
| fill result node
fill_r e_Wrap_kWrappedIntArray 1 0 1 0 0
pop_a 1
.d 1 0
| A: <result>
| B:
rtn
:wrap_real_array
| A: <_array> <result>
| B: <desc>
pop_b 1
| fill result node
fill_r e_Wrap_kWrappedRealArray 1 0 1 0 0
pop_a 1
.d 1 0
| A: <result>
| B:
rtn
:wrap_file_array
| A: <_array> <result>
| B: <desc>
pop_b 1
| fill result node
fill_r e_Wrap_kWrappedFileArray 1 0 1 0 0
pop_a 1
.d 1 0
| A: <result>
| B:
rtn
:wrap_record_array
| A: <_array> <result>
| B: <n> <i>
push_b 0
create_array_ _ 1 0
| A: <_wrapped_array> <_array> <result>
| B: <n> <i>
jmp wrap_record_array_test
:wrap_record_array_loop
| B: <n> <i>
pushI 1
| push record element descriptor
push_r_args_b 1 0 2 2 1
| B: <desc> <return> <n> <i>
| create result node for wrap_record_fields
create
| push fields from i-th array element
push_b 3
push_a 2
push_a_r_args
| A: <afield_1 .. afield_m> <elresult> <_wrapped_array> <_array> <result>
| B: <l> <bfieldb_1 .. bfield_n> <desc> <return> <n> <i>
| wrap record element
jmp wrap_record_fields
:wrap_record_array_return
| A: <element> <_wrapped_array> <_array> <result>
| B: <return> <n> <i>
pop_b 1
| A: <element> <_wrapped_array> <_array> <result>
| B: <n> <i>
| update i-th of _wrapped_array with wrapped record element
push_a 1
push_b 1
update _ 1 0
update_a 0 1
pop_a 1
| A: <_wrapped_array> <_array> <result>
| B: <n> <i>
| increment index
push_b 1
incI
update_b 0 2
pop_b 1
| decrement n
decI
:wrap_record_array_test
eqI_b 0 0
jmp_false wrap_record_array_loop
| A: <_wrapped_array> <_array> <result>
| B: <n> <i>
pop_b 2
| B:
update_a 0 1
pop_a 1
| A: <_wrapped_array> <result>
| fill result node
fill_r e_Wrap_kWrappedArray 1 0 1 0 0
pop_a 1
.d 1 0
| A: <result>
| B:
rtn
}
|