Repository navigation
Expand file tree
/
Copy pathexec.cc
More file actions
1364 lines (1267 loc) · 42 KB
/
Copy pathexec.cc
File metadata and controls
1364 lines (1267 loc) · 42 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
#define ICI_CORE
#include "exec.h"
#include "catcher.h"
#include "debugger.h"
#include "float.h"
#include "forall.h"
#include "func.h"
#include "int.h"
#include "map.h"
#include "mark.h"
#include "method.h"
#include "null.h"
#include "op.h"
#include "parse.h"
#include "pc.h"
#include "primes.h"
#include "ptr.h"
#include "re.h"
#include "set.h"
#include "src.h"
#include "str.h"
#include "userop.h"
#include "vec.h"
#include <signal.h>
namespace ici
{
/*
* List of all active execution structures.
*/
exec *execs;
/*
* The global pointer to the current execution context and cached pointers
* to the three stacks (execution, operand and variable (scope)). These are
* set every time we switch ICI threads.
*/
exec *ex;
/*
* A cached copy of ex->x_count for the current thread.
*/
int exec_count;
/*
* The arrays that form the current execution, operand and variable (scope)
* stacks. These are actually swapped-in copies of the stacks that are
* referenced from the current execution context. They get copied into
* these fixed-address locations when we switch into a particular context
* to save a level of indirection on top-of-stack references (it can make
* up to 20% difference in CPU time). While we are executing in a particular
* context, the "real" arrays have their a_base pointer zapped to nullptr so
* those copies of the base, limit and top pointers. When we switch away
* from a particular context, we copies these stacks back to real array
* structs (see thread.c).
*/
array xs;
array os;
array vs;
integer *o_zero;
integer *o_one;
/*
* Set this to non-zero to cause an "aborted" failure even when the ICI
* program is stuck in an infinite loop. For use in embeded systems etc
* to provide protection against badly behaved user programs. How it gets
* set is not addressed here (by an interupt perhaps). Remember to clear
* it before re-running any ICI code.
*/
volatile int aborted;
/*
* The limit to the number of recursive invocations of evaluate().
*/
int evaluate_recursion_limit = 50;
static sigset_t empty_sigset;
inline bool isempty(const sigset_t *s)
{
return memcmp(s, &empty_sigset, sizeof empty_sigset) == 0;
}
void init_exec()
{
sigemptyset(&empty_sigset);
}
/*
* Create and return a pointer to a new ICI execution context.
* On return, all stacks (execution, operand and variable) are empty.
* Returns nullptr on failure, in which case error has been set.
* The new exec struct is linked onto the global list of all exec
* structs (execs).
*/
exec *new_exec()
{
exec *x;
static src default_src;
if ((x = ici_talloc(exec)) == nullptr)
{
return nullptr;
}
memset((void *)x, 0, sizeof *x);
set_tfnz(x, TC_EXEC, 0, 1, 0);
rego(x);
x->x_src = &default_src;
if ((x->x_xs = new_array(80)) == nullptr)
{
goto fail;
}
decref(x->x_xs);
if ((x->x_os = new_array(80)) == nullptr)
{
goto fail;
}
decref(x->x_os);
if ((x->x_vs = new_array(80)) == nullptr)
{
goto fail;
}
decref(x->x_vs);
if ((x->x_pc_closet = new_array(80)) == nullptr)
{
goto fail;
}
decref(x->x_pc_closet);
if ((x->x_os_temp_cache = new_array(80)) == nullptr)
{
goto fail;
}
decref(x->x_os_temp_cache);
x->x_semaphore = new std::condition_variable;
x->x_state = XS_ACTIVE;
x->x_count = 100;
x->x_n_engine_recurse = 0;
x->x_next = execs;
x->x_error = nullptr;
execs = x;
return x;
fail:
return nullptr;
}
/*
* The main execution loop avoids continuous checks for available space
* on its three stacks (operand, execution, and scope) by knowing that
* no ordinary operation increase the stack depth by more than 3 levels
* at a time. Knowing this, every N times round the loop it checks that
* there is room for N * 3 objects.
*/
int engine_stack_check()
{
array *pcs;
int depth;
if (xs.push_check(60))
{
return 1;
}
if (os.push_check(60))
{
return 1;
}
if (vs.push_check(60))
{
return 1;
}
pcs = ex->x_pc_closet;
depth = (xs.a_top - xs.a_base) + 60;
if ((depth -= (pcs->a_top - pcs->a_base)) > 0)
{
if (pcs->push_check(depth))
{
return 1;
}
while (pcs->a_top < pcs->a_limit)
{
if ((*pcs->a_top = new_pc()) == nullptr)
{
return 1;
}
++pcs->a_top;
}
}
return 0;
}
/*
* Faster lookup for string keys.
*/
inline object *fetch(object *s, object *k)
{
if (isstring(k) && stringof(k)->s_map == mapof(s) && stringof(k)->s_vsver == vsver)
{
return stringof(k)->s_slot->sl_value;
}
else
{
return ici_fetch(s, k);
}
}
/*
* Unwind the execution stack until a catcher is found. Then unwind
* the scope and operand stacks to the matching depth (but only if it is).
* Returns the catcher, or nullptr if there wasn't one.
*/
static catcher *unwind()
{
for (auto p = xs.a_top - 1; p >= xs.a_base; --p)
{
if (iscatcher(*p))
{
auto c = catcherof(*p);
xs.a_top = p;
os.a_top = &os.a_base[c->c_odepth];
vs.a_top = &vs.a_base[c->c_vdepth];
return c;
}
}
assert(0);
return nullptr;
}
/*
* Execute 'code' (any object, normally an array of code or a
* parse). The execution procedes on top of the current stacks
* (execution, operand and variable). This call to evaluate will return when
* the execution stack again returns to the level it was when entered. It
* then returns the object left on the operand stack, or null if there
* wasn't one. The returned object is ici_incref()ed. Returns nullptr on error,
* usual conventions (i.e. 'error' points to the error message).
*
* n_operands is the number of objects on the operand stack that are arguments
* to this call. They will all be poped off before evaluate returns.
*
* The execution loop knows when the execution stack returns to its origional
* level because it puts a catcher object on it. This object also records
* the levels of the other two stacks that match.
*
* This is the main execution loop. All of the nasty optimisations are
* concentrated here. It used to be clean, elegant and 20 lines long. Now it
* goes faster.
*
* Originally each type had an execution method, which was a function pointer
* like all the other type specific methods. This was unrolled into a switch
* within the main loop for speed and variable optimisation. Then many of the
* op_type operations got unrolled in the loop in the same way. Gotos got
* added to short-circuit some of the steps where possible. Then they got
* removed, apart from the fail exits. Then one got added again. And again.
*
* Note that binop.h is included half way down this function.
*/
object *evaluate(object *code, int n_operands)
{
object *o;
object *pc;
int flags;
catcher frame;
if (++ex->x_n_engine_recurse > evaluate_recursion_limit)
{
set_error("excessive recursive invocations of main interpreter");
goto badfail;
}
if (engine_stack_check())
{
goto badfail;
}
/*
* This is pretty scary. An object on the C stack. But it should be OK
* because it's only on the execution stack and there should be no way for
* it to escape into the world at large, so no-one should be able to have
* a reference to it after we return. It will get poped off before we do.
* It's not registered with the garbage collector, so after that, it's
* just gone. We do this to save allocation/collection of an object on
* every call from C to ICI. This object *will* be seen by the mark phase
* of the garbage collection, which may occur in a thread other than this
* one. This is likely to cause a good memory integrity checking system
* to complain.
*/
set_tfnz(&frame, TC_CATCHER, CF_EVAL_BASE, 0, 0);
frame.c_catcher = nullptr;
frame.c_odepth = (os.a_top - os.a_base) - n_operands;
frame.c_vdepth = vs.a_top - vs.a_base;
xs.push(&frame);
if (isarray(code))
{
set_pc(arrayof(code), xs.a_top);
}
else
{
*xs.a_top = code;
}
++xs.a_top;
/*
* The execution loop.
*/
for (;;)
{
if (UNLIKELY(--exec_count == 0))
{
if (UNLIKELY(aborted))
{
set_error("aborted");
goto fail;
}
/*
* Ensure that there is enough room on all stacks for at
* least 20 more worst case operations. See also f_call().
*/
if (UNLIKELY(engine_stack_check()))
{
goto fail;
}
exec_count = 100;
if (UNLIKELY(++ex->x_yield_count > 10))
{
yield();
ex->x_yield_count = 0;
}
/*
* Check for, and handle, pending signals.
*/
sigset_t *p = (sigset_t *)(void *)&signals_pending;
if (UNLIKELY(!isempty(p)))
{
invoke_signal_handlers();
}
}
/*
* Places which would be inclined to continue in this loop, that
* know that they have not increased any stack depths, can just
* goto this label to avoid the check above.
*/
stable_stacks_continue:
/*
* In principle our execution model is pretty simple. We execute
* the thing on the top of the execution stack. When that is a pc
* we push the thing the pc points to (with post increment) onto
* the execution stack and continue.
*
* So technically the following test for a pc on top of the
* execution stack should just be part of the main switch (as it
* once was). But 90% of the time we execute: pc then other;
* pc then other etc... Doing this test here means that normally
* we run these two operations into one another without going
* round the main loop. And then, enough of the things we do are
* operators to make a short-circuit of the switch worth while.
*
* Code arrays never contain pcs, so the thing picked up from
* indirecting the pc is not a pc, so there is no general case
* in the switch.
*/
assert(os.a_top >= os.a_base);
pc = xs.a_top[-1];
if (ispc(pc))
{
continue_with_same_pc:
o = *pcof(pc)->pc_next++;
if (isop(o))
{
goto an_op;
}
}
else
{
o = pc;
--xs.a_top;
}
/*
* Formally, the thing being executed should be on top of the
* execution stack when we do this switch. But the value is
* known to be pointed to by o, and most things pop it off.
* We get a net gain if we assume it is pre-popped, because we
* can avoid pushing things that are comming out of code arrays
* on at all. Some of the cases below must push it on to restore
* the formal model. The code just above here assumes this, but
* has to explicitly pop the stack in the non-pc case.
*/
switch (o->o_tcode)
{
case TC_SRC:
ex->x_src = srcof(o);
if (UNLIKELY(debug_active))
{
xs.push(o); /* Restore formal state. */
debugger->source_line(srcof(o));
--xs.a_top;
continue;
}
goto stable_stacks_continue;
case TC_PARSE:
xs.push(o); /* Restore formal state. */
if (parse_exec())
{
goto fail;
}
continue;
case TC_STRING:
/*
* Executing a string is the operation of variable lookup.
* Look up the value of the string on the execution stack
* in the current scope and push the value onto the operand
* stack.
*
* First check for lookup lookaside.
*/
if (stringof(o)->s_map == mapof(vs.a_top[-1]) && stringof(o)->s_vsver == vsver)
{
/*
* We know directly where the value is because we have
* looked up this name since the last change to the scope
* or structures etc.
*/
assert(ici_fetch_super(vs.a_top[-1], o, os.a_top, nullptr) == 1);
assert(*os.a_top == stringof(o)->s_slot->sl_value);
os.push(stringof(o)->s_slot->sl_value);
}
else
{
object *f;
/*
* This is an in-line version of fetch_map because
* (a) we know that the top of the variable stack is
* always a struct, and (b) we want to detect when the
* value is not found so we can do auto-loading.
*/
switch (ici_fetch_super(vs.a_top[-1], o, os.a_top, mapof(vs.a_top[-1])))
{
case -1:
goto fail;
case 0:
/*
* We failed to find that name on first lookup.
* Try to load a library of that name and repeat
* the lookup before deciding it is undefined.
*/
if ((f = ici_fetch(vs.a_top[-1], SS(load))) == null)
{
set_error("\"%s\" undefined", stringof(o)->s_chars);
goto fail;
}
xs.push(o); /* Temp restore formal state. */
{
src *srco = ex->x_src;
incref(srco);
if (call(f, "o", o))
{
decref(srco);
goto fail;
}
ex->x_src = srco;
decref(srco);
}
--xs.a_top;
switch (ici_fetch_super(vs.a_top[-1], o, os.a_top, mapof(vs.a_top[-1])))
{
case -1:
goto fail;
case 0:
set_error("load() failed to define \"%s\"", stringof(o)->s_chars);
goto fail;
}
}
++os.a_top;
}
continue;
case TC_CATCHER:
/*
* This can either be an error catcher which is being poped
* off (having done its job, but it never got used) or it
* can be the guard catch (frame marker) indicating it is time
* to return from evaluate().
*
* First note the top of the operand stack, if there is anything
* on it, it becomes the return value, else we return null.
* The caller knows if there is really a value to return.
*/
xs.push(o); /* Restore formal state. */
if (o->hasflag(CF_EVAL_BASE))
{
/*
* This is the base of a call to evaluate(). It is now
* time to return.
*/
if (catcherof(o)->c_odepth < uint32_t(os.a_top - os.a_base))
{
o = os.a_top[-1];
}
else
{
o = null;
}
incref(o);
unwind();
--ex->x_n_engine_recurse;
return o;
}
if (o->hasflag(CF_CRIT_SECT))
{
--ex->x_critsect;
/*
* Force a check for a yield (see top of loop). If we
* don't do this, there is a chance a loop that spends
* much of its time in critsects could sync with the
* stack check countdown and never yield.
*/
exec_count = 1;
}
unwind();
goto stable_stacks_continue;
case TC_FORALL:
xs.push(o); /* Restore formal state. */
if (exec_forall())
{
goto fail;
}
continue;
default:
os.push(o);
continue;
case TC_OP:
an_op:
switch (opof(o)->op_ecode)
{
case OP_OTHER:
xs.push(o); /* Restore to formal state. */
if ((*opof(o)->op_func)())
{
goto fail;
}
continue;
case OP_SUPER_CALL:
flags = OPC_COLON_CALL | OPC_COLON_CARET;
goto do_colon;
case OP_METHOD_CALL:
flags = OPC_COLON_CALL;
goto do_colon;
case OP_COLON:
/*
* aggr key => method (os) (normal case)
*/
{
object *o1;
object *t;
flags = opof(o)->op_code;
do_colon:
o1 = o;
t = os.a_top[-2];
if (flags & OPC_COLON_CARET)
{
if ((o = fetch(vs.a_top[-1], SS(class))) == nullptr)
{
goto fail;
}
if (!hassuper(o))
{
char n1[objnamez];
set_error("\"class\" evaluated to %s in :^ operation", objname(n1, o));
goto fail;
}
if ((t = objwsupof(o)->o_super) == nullptr)
{
set_error("class has no super class in :^ operation");
goto fail;
}
}
if (t->icitype()->can_fetch_method())
{
if ((o = t->icitype()->fetch_method(t, os.a_top[-1])) == nullptr)
{
goto fail;
}
}
else
{
if ((o = fetch(t, os.a_top[-1])) == nullptr)
{
goto fail;
}
if (isnull(o))
{
if ((o = fetch(t, SS(unknown_method))) == nullptr)
{
goto fail;
}
if (!isnull(o))
{
object *nam = os.a_top[-1];
long nargs = intof(os.a_top[-3])->i_value;
++os.a_top;
os.a_top[-1] = SS(unknown_method);
os.a_top[-2] = os.a_top[-3];
if ((os.a_top[-3] = new_int(nargs + 1)) == nullptr)
{
goto fail;
}
decref(os.a_top[-3]);
os.a_top[-4] = nam;
}
}
}
if ((flags & OPC_COLON_CALL) == 0)
{
method *m;
if ((m = new_method(os.a_top[-2], o)) == nullptr)
{
goto fail;
}
--os.a_top;
os.a_top[-1] = m;
decref(m);
goto stable_stacks_continue;
}
/*
* This is a direct call, don't form the method object.
*/
xs.push(o1); /* Restore xs to formal state. */
o1 = os.a_top[-2]; /* The subject object. */
--os.a_top;
os.a_top[-1] = o; /* The callable object. */
o = o1;
incref(o);
goto do_call;
}
case OP_CALL:
xs.push(o); /* Restore to formal state. */
o = nullptr; /* No subject object. */
do_call:
if (UNLIKELY(!os.a_top[-1]->can_call()))
{
char n1[objnamez];
set_error("attempt to call %s", objname(n1, os.a_top[-1]));
if (o != nullptr)
{
decref(o);
}
goto fail;
}
// if (UNLIKELY(debug_active)) {
// debugger->function_call(os.a_top[-1], ARGS(), NARGS());
// }
if (os.a_top[-1]->call(o))
{
if (o != nullptr)
{
decref(o);
}
goto fail;
}
if (o != nullptr)
{
decref(o);
}
continue;
case OP_QUOTE:
/*
* pc => pc+1 (xs)
* => *pc (os)
*/
o = xs.a_top[-1];
os.push(*pcof(o)->pc_next++);
continue;
case OP_AT:
/*
* obj => obj (os)
*/
os.a_top[-1] = atom(os.a_top[-1], 0);
goto stable_stacks_continue;
case OP_NAMELVALUE:
/*
* pc (xs) => pc+1 (xs)
* => struct *pc (os)
* (Ie. the next thing in the code array is a name, put its
* lvalue on the operand stack.)
*/
os.push(vs.a_top[-1]);
os.push(*pcof(xs.a_top[-1])->pc_next++);
continue;
case OP_DOT:
/*
* aggr key => value (os)
*/
if ((o = fetch(os.a_top[-2], os.a_top[-1])) == nullptr)
{
goto fail;
}
--os.a_top;
os.a_top[-1] = o;
goto stable_stacks_continue;
case OP_DOTKEEP:
/*
* aggr key => aggr key value (os)
*/
if ((o = fetch(os.a_top[-2], os.a_top[-1])) == nullptr)
{
goto fail;
}
os.push(o);
continue;
case OP_DOTRKEEP:
/*
* aggr key => value aggr key value (os)
*
* Used in postfix ++/-- for value.
*/
if ((o = fetch(os.a_top[-2], os.a_top[-1])) == nullptr)
{
goto fail;
}
os.a_top += 2;
os.a_top[-1] = o;
os.a_top[-2] = os.a_top[-3];
os.a_top[-3] = os.a_top[-4];
os.a_top[-4] = o;
continue;
case OP_ASSIGNLOCALVAR:
/*
* name value => - (os, for effect)
* => value (os, for value)
* => aggr key (os, for lvalue)
*/
if (ici_assign_base(vs.a_top[-1], os.a_top[-2], os.a_top[-1]))
{
goto fail;
}
switch (opof(o)->op_code)
{
case FOR_EFFECT:
os.a_top -= 2;
break;
case FOR_VALUE:
os.a_top[-2] = os.a_top[-1];
--os.a_top;
break;
case FOR_LVALUE:
os.a_top[-1] = os.a_top[-2];
os.a_top[-2] = vs.a_top[-1];
break;
}
continue;
case OP_ASSIGN_TO_NAME:
/*
* value on os, next item in code is name.
*/
os.a_top += 2;
os.a_top[-1] = os.a_top[-3];
os.a_top[-2] = *pcof(xs.a_top[-1])->pc_next++;
os.a_top[-3] = vs.a_top[-1];
/* Fall through. */
case OP_ASSIGN:
/*
* aggr key value => - (os, for effect)
* => value (os, for value)
* => aggr key (os, for lvalue)
*/
if (LIKELY(!debug_active) && stringof(os.a_top[-2])->s_map == mapof(os.a_top[-3]) &&
stringof(os.a_top[-2])->s_vsver == vsver && isstring(os.a_top[-2]) &&
!os.a_top[-2]->hasflag(ICI_S_LOOKASIDE_IS_ATOM))
{
stringof(os.a_top[-2])->s_slot->sl_value = os.a_top[-1];
goto assign_finish;
}
if (ici_assign(os.a_top[-3], os.a_top[-2], os.a_top[-1]))
{
goto fail;
}
if (UNLIKELY(debug_active))
{
debugger->watch(os.a_top[-3], os.a_top[-2], os.a_top[-1]);
}
goto assign_finish;
case OP_ASSIGNLOCAL:
/*
* aggr key value => - (os, for effect)
* => value (os, for value)
* => aggr key (os, for lvalue)
*/
if (hassuper(os.a_top[-3]))
{
if (ici_assign_base(os.a_top[-3], os.a_top[-2], os.a_top[-1]))
{
goto fail;
}
}
else
{
if (ici_assign(os.a_top[-3], os.a_top[-2], os.a_top[-1]))
{
goto fail;
}
}
assign_finish:
switch (opof(o)->op_code)
{
case FOR_EFFECT:
os.a_top -= 3;
break;
case FOR_VALUE:
os.a_top[-3] = os.a_top[-1];
os.a_top -= 2;
break;
case FOR_LVALUE:
--os.a_top;
break;
}
continue;
case OP_SWAP:
/*
* aggr1 key1 aggr2 key2 =>
* => value1
* => aggr1 key1
*/
{
object *v1;
object *v2;
if ((v1 = ici_fetch(os.a_top[-4], os.a_top[-3])) == nullptr)
{
goto fail;
}
incref(v1);
if ((v2 = ici_fetch(os.a_top[-2], os.a_top[-1])) == nullptr)
{
decref(v1);
goto fail;
}
incref(v2);
if (ici_assign(os.a_top[-2], os.a_top[-1], v1))
{
decref(v1);
decref(v2);
goto fail;
}
if (ici_assign(os.a_top[-4], os.a_top[-3], v2))
{
decref(v1);
decref(v2);
goto fail;
}
switch (opof(o)->op_code)
{
case FOR_EFFECT:
os.a_top -= 4;
break;
case FOR_VALUE:
os.a_top[-4] = v2;
os.a_top -= 3;
break;
case FOR_LVALUE:
os.a_top -= 2;
break;
}
decref(v1);
decref(v2);
}
continue;
case OP_IF:
/*
* bool => - (os)
*
*/
if (isfalse(os.a_top[-1]))
{
--os.a_top;
++pcof(xs.a_top[-1])->pc_next;
goto stable_stacks_continue;
}
o = *pcof(xs.a_top[-1])->pc_next++;
set_pc(arrayof(o), xs.a_top);
--os.a_top;
++xs.a_top;
continue;
case OP_IFELSE:
/*
* bool => -
*/
if (isfalse(os.a_top[-1]))
{
++pcof(xs.a_top[-1])->pc_next;
o = *pcof(xs.a_top[-1])->pc_next++;
}
else
{
o = *pcof(xs.a_top[-1])->pc_next++;
++pcof(xs.a_top[-1])->pc_next;
}
set_pc(arrayof(o), xs.a_top);
--os.a_top;
++xs.a_top;
goto stable_stacks_continue;
case OP_IFBREAK:
/*
* bool => - (os)
* => [o_break] (xs)
*/
if (isfalse(os.a_top[-1]))
{
--os.a_top;
continue;
}
--os.a_top;
goto do_break;
case OP_IFNOTBREAK:
/*
* bool => - (os)
* => [o_break] (xs)
*/
if (!isfalse(os.a_top[-1]))
{
--os.a_top;
continue;
}
--os.a_top;
/*FALLTHROUGH*/
case OP_BREAK:
do_break:
/*
* Pop the execution stack until a looper or switcher
* is found and disgard it (and the thing under it,
* which is the code array that is the body of the loop).
* Oh, and forall as well.
*/
{
object **s;
for (s = xs.a_top; s > xs.a_base + 1; --s)
{
if (iscatcher(s[-1]))
{
if (s[-1]->hasflag(CF_CRIT_SECT))
{
--ex->x_critsect;
exec_count = 1;
}
else if (s[-1]->hasflag(CF_EVAL_BASE))
{
break;
}
}
else if (s[-1] == &o_looper || s[-1] == &o_switcher)
{
xs.a_top = s - 2;
goto stable_stacks_continue;
}
else if (isforall(s[-1]))
{
xs.a_top = s - 1;
goto stable_stacks_continue;
}