-
Notifications
You must be signed in to change notification settings - Fork 1
/
ARCHSYS.PAS
1004 lines (811 loc) · 28 KB
/
ARCHSYS.PAS
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
{ ARCHSYS.PAS
Description:
Routines which compose the "system object" of Archetype and the primary
link between the player and the language.
Routines which perform the interpretation of the Archetype statements
and expressions, and which perform the inheritance aspect of message
sending and attribute referencing.
}
unit archsys;
interface
uses
Crt,
misc,
linklist, xarray,
keywords, expr, stmt,
saveload, intrptr,
wrap, sysobj;
{ Functions and Procedures }
procedure eval_expr(the_expr: expr_tree; var result: result_type;
var context: context_type; desired: desired_type);
procedure exec_stmt(the_stmt: stmt_ptr; var result: result_type;
var context: context_type);
procedure interpret(var acx_file: string);
implementation
function eval_condition(the_expr: expr_tree;
var context: context_type): boolean; forward;
{ lookup
Description:
Given an object number, attribute number, and desired_type, returns
the value of the lookup in the given result. If the desired_type is
LVALUE, then it creates a new attribute node in the object's own
attribute list (if not already existing) and returns a pointer to
it. If RVALUE, it evaluates any expression it may find, returning
the result of the evaluation.
Also performs inheritance, looking back through the object's family
tree to find the attribute.
}
procedure lookup(the_obj: integer; the_attr: integer;
var result: result_type; var context: context_type;
desired: desired_type);
var
np: node_ptr;
done, first_pass: boolean;
attrs: list_type;
parent: integer;
p, original: pointer;
e: expr_tree;
c: context_type;
begin
cleanup(result);
if desired = NAME then
with result do begin
kind := IDENT;
ident_kind := ATTRIBUTE_ID;
ident_int := the_attr;
exit
end;
if the_obj = 0 then { system object - all attributes UNDEFINED }
exit;
if not index_xarray(Object_List, the_obj, original) then begin
writeln('Internal error: cannot reference object ', the_obj);
exit
end;
{ Return UNDEFINED for attempting to reference any attribute of a destroyed
object. }
if original = nil then exit;
{ It is important to change the context before a lookup so that any
non-scalar expressions that are referenced will be evaluated in the
light of that object's context. }
c := context;
with c do begin
self := the_obj; { references to self must be right }
each := 0
end;
first_pass := TRUE;
p := original;
done := FALSE;
repeat { inheritance loop }
with object_ptr(p)^ do begin
attrs := attributes;
parent := inherited_from
end;
np := find_item(attrs, the_attr);
if (np <> nil) or (parent = 0) then
done := TRUE
else begin { track back }
if not index_xarray(Type_List, parent, p) then begin
writeln('Internal error: lookup cannot find parent type ', parent);
exit
end;
first_pass := FALSE
end;
until done;
if np = nil then { not found anywhere }
exit;
case desired of
RVALUE:
eval_expr(expr_ptr(np^.data), result, c, RVALUE);
{ Getting an inherited LVALUE is tricky. We must remember that since
we have come this far, we definitely will return an ATTR_PTR result. }
LVALUE:
if first_pass then
with result do begin
kind := ATTR_PTR;
acl_attr := np
end
else begin { inherited - must create new node }
result.kind := ATTR_PTR;
new(result.acl_attr);
new(e);
undefine(e^);
eval_expr(expr_ptr(np^.data), e^, c, RVALUE);
with result.acl_attr^ do begin
data := e;
key := the_attr
end;
insert_item(object_ptr(original)^.attributes, result.acl_attr)
end; { LVALUE }
end { case }
end; { lookup }
{ send_message
Description:
Sends the given message number to the object of the given number.
This procedure performs inheritance; that is, it will search back
through the object's ancestry in order to find someone to perform
the message. Has to do something tricky with the default message:
it must first search the entire ancestry for an explicit message,
then search again for a default, if none found.
Arguments:
transport (IN) -- how to send the message: sending to an object,
passing to an object, or sending(passing) to
a type.
message (IN) -- message to send
recipient (IN) -- number of object to receive message
result (OUT) -- result of the sending
Returns:
TRUE if the recipient handles the message; FALSE if it doesn't.
}
function send_message(transport: shortint;
message_sent, recipient: integer;
var result: result_type;
var context: context_type): boolean;
var
done, find_other : boolean;
op, original : object_ptr;
r : result_type;
i : integer;
np : node_ptr;
st : stmt_ptr;
p : pointer;
c : context_type;
begin
if message_sent = 0 then begin
cleanup(result);
send_message := FALSE;
exit
end;
if (Debug and DEBUG_MSGS) > 0 then begin
r.kind := IDENT;
r.ident_kind := OBJECT_ID;
r.ident_int := context.self;
wrapout(' : ', FALSE);
display_result(r);
if transport = OP_SEND then
wrapout(' sending ', FALSE)
else
wrapout(' passing ', FALSE);
if index_xarray(Vocabulary, message_sent, p) then
wrapout(Concat('''', string_ptr(p)^, ''''), FALSE);
if transport = OP_SEND_TO_TYPE then
r.ident_kind := TYPE_ID;
wrapout(' to ', FALSE);
r.ident_int := recipient;
display_result(r);
wrapout('', TRUE)
end;
{ Trying to send a message to a destroyed object results in UNDEFINED }
if (((transport = OP_SEND_TO_TYPE) and
index_xarray(Type_List, recipient, p)) or
index_xarray(Object_List, recipient, p)) and (p <> nil)
then begin
c := context;
with c do begin
each := 0;
message := message_sent;
if transport = OP_SEND then begin
sender := context.self;
self := recipient
end
end;
op := object_ptr(p);
original := op;
done := FALSE;
find_other := FALSE;
while not done do begin
if find_other then
st := op^.other
else begin
np := find_item(op^.methods, message_sent);
if np <> nil then
st := stmt_ptr(np^.data)
else
st := nil
end;
if st <> nil then begin { found it }
exec_stmt(st, result, c);
send_message := TRUE;
exit
end
else { no message for recipient }
if op^.inherited_from = 0 then
if find_other then
done := TRUE
else begin
op := original;
find_other := TRUE
end
else if index_xarray(Type_List, op^.inherited_from, p) then
op := object_ptr(p)
else begin
wraperr('Internal error: invalid inheritance');
send_message := FALSE;
exit
end
end { while }
end; { if }
{ If we get here, it means that there was not even a "default" handler for
the message in the given object or its lineage. Return ABSENT. }
result.kind := RESERVED;
result.keyword := RW_ABSENT;
send_message := FALSE
end; { send_message }
{ eval_expr
Description:
Evaluates the given expression.
}
procedure eval_expr(the_expr: expr_tree; var result: result_type;
var context: context_type; desired: desired_type);
var
r1, r2 : result_type;
i : integer;
p : pointer;
e : expr_tree;
b : boolean;
c : context_type;
begin
{ It is very important to make sure that the "kind" fields of our
temporary result variables are properly set to RESERVED/UNDEFINED
before doing anything with them, so that if someone tries to clean
them up later on, they won't try to dispose of a string that isn't
there. }
undefine(r1);
undefine(r2);
cleanup(result);
if the_expr = nil then
exit;
{ Check: if this is a lone attribute, look it up in this object's table. }
if (the_expr^.kind = IDENT) and
(the_expr^.ident_kind = ATTRIBUTE_ID) then
lookup(context.self, the_expr^.ident_int, result, context, desired)
{ Is it a special reserved word that requires an action? }
else if the_expr^.kind = RESERVED then
case the_expr^.keyword of
RW_READ, RW_KEY:
with result do begin
kind := STR_PTR;
if the_expr^.keyword = RW_READ then
acl_str := ReadLine(TRUE) { read full line }
else
acl_str := ReadLine(FALSE); { read single key }
Rows := 0;
cursor_reset { user will have had to hit <RETURN> }
end;
RW_MESSAGE:
with result do begin
kind := MESSAGE;
index := context.message
end;
RW_EACH, RW_SELF, RW_SENDER:
with result do begin
kind := IDENT;
ident_kind := OBJECT_ID;
case the_expr^.keyword of
RW_EACH: ident_int := context.each;
RW_SELF: ident_int := context.self;
RW_SENDER: ident_int := context.sender;
end
end;
else
result := the_expr^
end { case }
{ If an operator, need to evaulate it }
else if the_expr^.kind = OPER then begin
case the_expr^.op_name of
OP_SEND, OP_PASS:
begin
eval_expr(the_expr^.left, r1, context, RVALUE);
eval_expr(the_expr^.right, r2, context, RVALUE);
if (r2.kind = IDENT) and
((r2.ident_kind = OBJECT_ID) or
(r2.ident_kind = TYPE_ID))
then begin
{ Object 0 is the system object and always receives string messages }
if (r2.ident_kind = OBJECT_ID) and
(r2.ident_int = 0)
then begin
if convert_to(STR_PTR, r1) then
send_to_system(the_expr^.op_name, r1.acl_str^,
result, context)
end
else if convert_to(MESSAGE, r1) then begin
if r2.ident_kind = TYPE_ID then
b := send_message(OP_SEND_TO_TYPE,
r1.index, r2.ident_int,
result, context)
else
b := send_message(the_expr^.op_name,
r1.index, r2.ident_int,
result, context)
end
end
end; { ->, --> }
OP_DOT: begin
eval_expr(the_expr^.left, r1, context, RVALUE);
if (r1.kind = IDENT) and (r1.ident_kind = OBJECT_ID) then begin
eval_expr(the_expr^.right, r2, context, NAME);
if (r2.kind = IDENT) and (r2.ident_kind = ATTRIBUTE_ID) then
lookup(r1.ident_int, r2.ident_int, result, context, desired)
end
end; { . }
OP_ASSIGN:
begin
if desired = NAME then
exit;
eval_expr(the_expr^.right, result, context, RVALUE);
eval_expr(the_expr^.left, r1, context, LVALUE);
if not assignment(r1, result) then
cleanup(result)
else if desired = LVALUE then begin
cleanup(result);
with result do begin
kind := ATTR_PTR;
acl_attr := r1.acl_attr
end
end
end; { := }
OP_C_MULTIPLY, OP_C_DIVIDE, OP_C_PLUS, OP_C_MINUS, OP_C_CONCAT:
begin
if desired = NAME then
exit;
{ Do the two operations using a dummy expression node }
new(e);
e^ := the_expr^;
with e^ do
case the_expr^.op_name of
OP_C_MULTIPLY:
op_name := OP_MULTIPLY;
OP_C_DIVIDE:
op_name := OP_DIVIDE;
OP_C_PLUS:
op_name := OP_PLUS;
OP_C_MINUS:
op_name := OP_MINUS;
OP_C_CONCAT:
op_name := OP_CONCAT;
end; { case }
eval_expr(e, r1, context, RVALUE);
with e^ do begin
op_name := OP_ASSIGN;
right := @r1
end;
eval_expr(e, result, context, desired);
dispose(e)
end; { *:=, /:=, +:=, -:=, &:= }
OP_CHS, OP_NUMERIC: begin
eval_expr(the_expr^.right, result, context, RVALUE);
if not convert_to(NUMERIC, result) then
cleanup(result)
else if the_expr^.op_name = OP_CHS then
with result do
acl_int := -acl_int
end;
OP_STRING: begin
eval_expr(the_expr^.right, result, context, RVALUE);
if not convert_to(STR_PTR, result) then
cleanup(result)
end;
OP_LENGTH: begin
eval_expr(the_expr^.right, r1, context, RVALUE);
if convert_to(STR_PTR, r1) then begin
result.kind := NUMERIC;
result.acl_int := length(r1.acl_str^)
end
end;
{ For the random operator, we must be careful: ? "01234" should
select a random digit out of that set, not attempt to convert it
to 1234 and take a random number in the range 1 - 1234.
However, we can neither immediately convert it to string, because
? 6 should produce a value in the range 1 - 6, not the character "6". }
OP_RANDOM: begin
eval_expr(the_expr^.right, result, context, RVALUE);
if result.kind = NUMERIC then { convert x < range to 1 <= x <= range }
result.acl_int := random(result.acl_int) + 1
else if convert_to(STR_PTR, result) then
with result do acl_str^ := acl_str^[random(length(acl_str^)) + 1]
end; { ? }
OP_NOT: begin
result.kind := RESERVED;
if eval_condition(the_expr^.right, context) then
result.keyword := RW_FALSE
else
result.keyword := RW_TRUE
end;
OP_PLUS, OP_MINUS, OP_MULTIPLY, OP_DIVIDE:
begin
eval_expr(the_expr^.left, r1, context, RVALUE);
eval_expr(the_expr^.right, r2, context, RVALUE);
if convert_to(NUMERIC, r1) and convert_to(NUMERIC, r2) then begin
result.kind := NUMERIC;
case the_expr^.op_name of
OP_PLUS:
result.acl_int := r1.acl_int + r2.acl_int;
OP_MINUS:
result.acl_int := r1.acl_int - r2.acl_int;
OP_MULTIPLY:
result.acl_int := r1.acl_int * r2.acl_int;
OP_DIVIDE:
result.acl_int := r1.acl_int div r2.acl_int;
end
end { if both NUMERIC }
end; { +, -, *, / , and, or }
OP_AND: begin
result.kind := RESERVED;
if eval_condition(the_expr^.left, context) and
eval_condition(the_expr^.right, context)
then
result.keyword := RW_TRUE
else
result.keyword := RW_FALSE
end;
OP_OR: begin
if eval_condition(the_expr^.left, context) or
eval_condition(the_expr^.right, context)
then
result.keyword := RW_TRUE
else
result.keyword := RW_FALSE
end;
OP_POWER: begin
eval_expr(the_expr^.right, r2, context, RVALUE);
eval_expr(the_expr^.left, r1, context, RVALUE);
if convert_to(NUMERIC, r2) and convert_to(NUMERIC, r1) then begin
result.kind := NUMERIC;
result.acl_int := 1;
for i := 1 to r2.acl_int do
result.acl_int := result.acl_int * r1.acl_int
end
end; { ^ }
OP_CONCAT: begin
eval_expr(the_expr^.left, r1, context, RVALUE);
eval_expr(the_expr^.right, r2, context, RVALUE);
if convert_to(STR_PTR, r1) and convert_to(STR_PTR, r2) then begin
result.kind := STR_PTR;
result.acl_str := MakeNewDynStr(r1.acl_str^ + r2.acl_str^)
end
end; { & }
OP_LEFTFROM, OP_RIGHTFROM: begin
eval_expr(the_expr^.left, r1, context, RVALUE);
eval_expr(the_expr^.right, r2, context, RVALUE);
if convert_to(STR_PTR, r1) and convert_to(NUMERIC, r2) then begin
result.kind := STR_PTR;
if the_expr^.op_name = OP_LEFTFROM then
result.acl_str :=
MakeNewDynStr(Copy(r1.acl_str^, 1, r2.acl_int))
else
result.acl_str :=
MakeNewDynStr(Copy(r1.acl_str^, r2.acl_int,
length(r1.acl_str^)))
end
end; { leftfrom, rightfrom }
OP_WITHIN: begin
eval_expr(the_expr^.left, r1, context, RVALUE);
eval_expr(the_expr^.right, r2, context, RVALUE);
if convert_to(STR_PTR, r1) and convert_to(STR_PTR, r2) then begin
result.kind := NUMERIC;
result.acl_int := Pos(r1.acl_str^, r2.acl_str^);
if result.acl_int = 0 then cleanup(result)
end
end;
OP_EQ, OP_NE, OP_LT, OP_GT, OP_LE, OP_GE:
begin
eval_expr(the_expr^.left, r1, context, RVALUE);
eval_expr(the_expr^.right, r2, context, RVALUE);
result.kind := RESERVED;
if result_compare(the_expr^.op_name, r1, r2) then
result.keyword := RW_TRUE
else
result.keyword := RW_FALSE
end; { =, ~=, <, >, <=, >= }
else
writeln('Internal error: "', Operators[the_expr^.op_name],
'" not yet supported.');
end; { case }
cleanup(r1);
cleanup(r2);
if (Debug AND DEBUG_EXPR) > 0 then begin
wrapout(' -- ', FALSE);
display_expr(the_expr);
wrapout(' ==> ', FALSE);
display_result(result);
wrapout('', TRUE)
end
end { else }
else { some scalar }
case desired of
RVALUE:
copy_result(result, the_expr^);
LVALUE:
result := the_expr^;
end
end; { eval_expr }
{ eval_condition
Description:
Evaluates the given expression as though it were a condition.
Will succeed if the given expression is not UNDEFINED and not FALSE.
Arguments:
the_expr (IN) -- expression to evaluate
Returns:
TRUE if the condition can be considered true; FALSE otherwise.
}
function eval_condition;
var
result: result_type;
failure: boolean;
begin
undefine(result);
eval_expr(the_expr, result, context, RVALUE);
with result do
failure := (kind = RESERVED) and
((keyword = RW_UNDEFINED) or
(keyword = RW_FALSE) or
(keyword = RW_ABSENT));
cleanup(result);
eval_condition := not failure
end; { eval_condition }
{ exec_stmt
Description:
Given a pointer to a statement, executes that statement.
Very heavily called.
Arguments:
the_stmt (IN) -- pointer to statement to be executed
result (OUT) -- the "value" of the execution (for example, the
last expression of a compound statement)
}
procedure exec_stmt(the_stmt: stmt_ptr; var result: result_type;
var context: context_type);
var
np: node_ptr;
p, q: pointer;
r1, r2: result_type;
this_case: case_pair_ptr;
b: boolean;
c: context_type;
i: integer;
e: expr_ptr;
the_object: object_ptr;
verbose : boolean;
begin
undefine(r1);
undefine(r2);
cleanup(result);
verbose := (Debug AND DEBUG_STMT) > 0;
if verbose then
wrapout(' == ', FALSE);
with the_stmt^ do
case kind of
COMPOUND:
begin
np := nil;
b := FALSE;
while (not b) and iterate_list(statements, np) do begin
cleanup(result);
exec_stmt(stmt_ptr(np^.data), result, context);
b := (result.kind = RESERVED) and (result.keyword = RW_BREAK)
end
end;
ST_EXPR:
begin
if verbose then
display_expr(expression);
case expression^.kind of
QUOTE_LIT:
if index_xarray(Literals, expression^.index, p) then
with result do begin
kind := TEXT_LIT;
index := expression^.index;
wrapout(string_ptr(p)^, TRUE)
end;
MESSAGE:
b := send_message(OP_PASS, expression^.index,
context.self, result, context);
else
eval_expr(expression, result, context, RVALUE)
end { case }
end; { ST_EXPR }
ST_WRITE, ST_WRITES, ST_STOP:
begin
if verbose then begin
case kind of
ST_WRITE : wrapout('write ', FALSE);
ST_WRITES : wrapout('writes ', FALSE);
ST_STOP : wrapout('stop ', FALSE);
end;
wrapout(' ', FALSE);
np := nil;
while iterate_list(print_list, np) do begin
display_expr(expr_tree(np^.data));
if np^.next <> print_list then
wrapout(', ', FALSE)
end;
wrapout('', TRUE)
end;
np := nil;
while iterate_list(print_list, np) do begin
cleanup(result);
eval_expr(expr_tree(np^.data), result, context, RVALUE);
write_result(result)
end;
if kind = ST_WRITE then
wrapout('', TRUE)
else if kind = ST_STOP then begin
writeln; writeln;
writeln(VERSION);
halt
end
end;
ST_IF: begin
if verbose then begin
wrapout('if: Testing ', FALSE);
display_expr(condition)
end;
if eval_condition(condition, context) then begin
if verbose then
wrapout(' Evaluated TRUE; executing then branch', TRUE);
exec_stmt(then_branch, result, context)
end
else if else_branch <> nil then begin
if verbose then
wrapout(' Evaluated FALSE; executing else branch', TRUE);
exec_stmt(else_branch, result, context)
end
end;
ST_CASE:
begin
if verbose then begin
wrapout('case ', FALSE);
display_expr(test_expr);
wrapout(' of', FALSE);
wrapout('', TRUE)
end;
eval_expr(test_expr, r1, context, RVALUE);
np := nil;
while iterate_list(cases, np) do begin
this_case := case_pair_ptr(np^.data);
with this_case^ do begin
eval_expr(value, r2, context, RVALUE);
if ((r2.kind = RESERVED) and (r2.keyword = RW_DEFAULT)) or
result_compare(OP_EQ, r1, r2)
then begin
exec_stmt(action, result, context);
cleanup(r1);
cleanup(r2);
exit
end
end; { with }
cleanup(r2)
end; { while }
cleanup(result);
cleanup(r1)
end;
ST_BREAK:
with result do begin
kind := RESERVED;
keyword := RW_BREAK
end;
ST_FOR: begin
b := FALSE;
c := context;
c.each := 1;
while (not b) and (c.each <= Object_List.size) do begin
if eval_condition(selection, c) then begin
exec_stmt(action, result, c);
b := (result.kind = RESERVED) and (result.keyword = RW_BREAK);
cleanup(result);
end;
inc(c.each)
end
end;
ST_WHILE: begin
b := FALSE;
while (not b) and eval_condition(selection, context) do begin
exec_stmt(action, result, context);
b := (result.kind = RESERVED) and (result.keyword = RW_BREAK);
cleanup(result)
end
end;
ST_CREATE: begin
eval_expr(new_name, r1, context, LVALUE);
{ Attempt a dummy assignment just to see if it works }
result.kind := IDENT;
result.ident_kind := OBJECT_ID;
result.ident_int := 0;
if not assignment(r1, result) then
cleanup(result)
else begin { do it for real }
new(the_object);
the_object^.inherited_from := archetype;
new_list(the_object^.attributes);
new_list(the_object^.methods);
the_object^.other := nil;
p := the_object;
{ NOTE: Search the list for an empty slot; if none found, append. }
i := Dynamic; b := TRUE;
while access_xarray(Object_List, i, q, PEEK_ACCESS) and
(q <> nil) do
inc(i);
if i > Object_List.size then
append_to_xarray(Object_List, p)
else
b := access_xarray(Object_List, i, p, POKE_ACCESS);
{ Now we know its number; go back and update the result's object reference.
"Return" this same value. }
expr_ptr(r1.acl_attr^.data)^.ident_int := i;
copy_result(result, expr_ptr(r1.acl_attr^.data)^);
cleanup(r1)
end
end;
{ Just dispose of the indicated object in the Object_List. Shrink the
list only if the very last object was destroyed. }
ST_DESTROY:
begin
eval_expr(victim, result, context, RVALUE);
if (result.kind = IDENT) and
(result.ident_kind = OBJECT_ID) and
index_xarray(Object_List, result.ident_int, p)
then begin
the_object := object_ptr(p);
dispose_object(the_object);
p := nil;
b := access_xarray(Object_List, result.ident_int, p,
POKE_ACCESS);
if result.ident_int = Object_List.size then
shrink_xarray(Object_List)
end
else
wraperr('Can only destroy previously created objects');
cleanup(result)
end;
else
wraperr('Internal error: statement not supported yet')
end; { case }
if verbose then wrapout('', TRUE) { finish off dangling lines }
end; { exec_stmt }
{ interpret
Description:
Loads and interprets the given .ACX file.
Arguments:
acx_file (IN) -- name of file
}
procedure interpret(var acx_file: string);
var
f_in : file;
message : string;
result : result_type;
context : context_type;
success : boolean;
begin
assign(f_in, acx_file);
{$I-}
reset(f_in, 1);
{$I+}
if IOResult <> 0 then begin
writeln('Could not open ', acx_file);
exit
end;
writeln('Loading ', acx_file);
Translating := FALSE;
success := load_game(f_in);
close(f_in);
if not success then
writeln('Could not PERFORM ', acx_file)
else begin
with context do begin
sender := 0;
self := 0;
each := 0;
message := 0
end;
undefine(result);
Randomize;
message := 'START';
if not send_message(OP_SEND, find_message(message),
MainObject, result, context)
then
wraperr('Cannot execute; no ''START'' message for main object.');
cleanup(result)
end; { else }
writeln; writeln(VERSION)
end;