Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/CellV.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations) (download) (as text)
Thu Apr 6 08:50:57 2017 UTC (7 years ago) by yamat0jp
File MIME type: text/x-pascal
File size: 23206 byte(s)
begin

end;
省きました
1 yamat0jp 2 unit CellV;
2    
3     interface
4    
5     uses CellG, SysUtils;
6    
7     const
8     ict = 1;
9     ics = 2;
10     lit = 3;
11     lis = 4;
12     lod = 5;
13     los = 6;
14     lda = 7;
15     las = 8;
16     sto = 9;
17     sts = 10;
18     cal = 11;
19     ret = 12;
20     dit = 13;
21     dik = 14;
22     jmp = 15;
23     jpc = 16;
24     arr = 17;
25     adv = 18;
26     opr = 19;
27    
28     neg = 20;
29     _add = 21;
30     ads = 22;
31     _sub = 23;
32     sus = 24;
33     _mul = 25;
34     mus = 26;
35     _div = 27;
36     dis = 28;
37    
38     eql = 29;
39     eqs = 30;
40     neq = 31;
41     nes = 32;
42     lss = 33;
43     gtr = 34;
44     leq = 35;
45     geq = 36;
46     lid = 37;
47     lds = 38;
48     sid = 39;
49     sls = 40;
50     sds = 41;
51     sld = 42;
52     ini = 43;
53     ins = 44;
54     _inc = 45;
55     _dec = 46;
56     lin = 47;
57     lde = 48;
58     prt = 49;
59     prs = 50;
60     prl = 51;
61     stp = 52;
62    
63     MAXCODE = 200;
64     MAXMEM = 2000;
65     MAXREG = 500;
66     MAXMOJI = 100;
67    
68     type
69     TInst = class
70     private
71     opCode: integer;
72     public
73     constructor Create(const op: integer);
74     function toString: string; virtual;
75     end;
76    
77     TInstAddr = class(TInst)
78     private
79     addr: TRaddr;
80     public
81     constructor Create(const op: integer; a: TRaddr);
82     function toString: string; override;
83     end;
84    
85     TInstRet = class(TInst)
86     private
87     level, pI, pS, modori: integer;
88     public
89 yamat0jp 4 constructor Create(const op, l, pI, pS, m: integer);
90 yamat0jp 2 function toString: string; override;
91     end;
92    
93     TInstCal = class(TInst)
94     private
95     level: integer;
96     code: integer;
97     public
98     constructor Create(op, l, c: integer);
99     function toString: string; override;
100     end;
101    
102     TInstVal = class(TInst)
103     private
104     value: integer;
105     public
106     constructor Create(const op, v: integer);
107     function toString: string; override;
108     end;
109    
110     TStrVal = class(TInst)
111     private
112     value: string;
113     public
114     constructor Create(op: integer; v: string);
115     function toString: string; override;
116     end;
117    
118     TInstPC = class(TInst)
119     private
120     value: integer;
121     public
122     constructor Create(op, v: integer);
123     function toString: string; override;
124     end;
125    
126     TInstOp = class(TInst)
127     private
128     optr: integer;
129     public
130     constructor Create(const op, o: integer);
131     function toString: string; override;
132     end;
133    
134     TCellV = class
135     private
136     _cellG: TCellG;
137 yamat0jp 4 code: array [0 .. MAXCODE] of TInst;
138 yamat0jp 2 cIndex: integer;
139 yamat0jp 4 display, sdisplay: array [0 .. CellG.MaxLevel] of integer;
140 yamat0jp 2 public
141     _cellK: TObject;
142     pCode, pTrace: Boolean;
143 yamat0jp 4 stack: array [0 .. MAXMEM] of integer;
144     sstack: array [0 .. MAXMOJI] of string;
145 yamat0jp 2 top: integer;
146     tos: integer;
147     pc: integer;
148     o1, o2: integer;
149     constructor Create(g: TCellG; c, t: Boolean);
150     destructor Destroy; override;
151     function genCodeT(const op, t: integer): integer;
152     function genCodeA(const op: integer; a: TRaddr): integer;
153     function genCodeV(const op, v: integer): integer;
154 yamat0jp 4 function genCodeP(op, v: integer): integer;
155 yamat0jp 2 function genCodeS(op: integer; v: string): integer;
156     function genCodeO(const p: integer): integer;
157     function genCodeC(l, c: integer): integer;
158     function genCodeR: integer;
159     function genCodeRV: integer;
160     procedure checkMax;
161     procedure backPatch(i, j: integer);
162     procedure backPatchJ(const i: integer);
163     procedure backPatchL(i, j, a: integer);
164     procedure backBreak(const c: integer);
165     procedure backCal(i, l, c: integer);
166     procedure changeS(i, a: integer);
167     function nextCode: integer;
168     procedure printCode;
169     procedure printExe;
170     procedure error;
171     procedure shokika;
172     function execute: integer;
173     end;
174    
175     implementation
176    
177     function codeName(const c: integer): string;
178     begin
179     case c of
180 yamat0jp 4 ict:
181     result := 'ict';
182     ics:
183     result := 'ics';
184     lit:
185     result := 'lit';
186     lis:
187     result := 'lis';
188     lod:
189     result := 'lod';
190     los:
191     result := 'los';
192     cal:
193     result := 'cal';
194     ret:
195     result := 'ret';
196     dit:
197     result := 'dit';
198     dik:
199     result := 'dik';
200     jmp:
201     result := 'jmp';
202     jpc:
203     result := 'jpc';
204     arr:
205     result := 'arr';
206     adv:
207     result := 'adv';
208     sto:
209     result := 'sto';
210     opr:
211     result := 'opr';
212     neg:
213     result := 'neg';
214     _add:
215     result := 'add';
216     _sub:
217     result := 'sub';
218     _mul:
219     result := 'mul';
220     _div:
221     result := 'div';
222     eql:
223     result := 'eql';
224     eqs:
225     result := 'eqs';
226     neq:
227     result := 'neq';
228     nes:
229     result := 'nes';
230     lss:
231     result := 'lss';
232     gtr:
233     result := 'gtr';
234     leq:
235     result := 'leq';
236     geq:
237     result := 'geq';
238     prt:
239     result := 'prt';
240     prs:
241     result := 'prs';
242     prl:
243     result := 'prl';
244     sid:
245     result := 'sid';
246     sld:
247     result := 'sld';
248     sls:
249     result := 'sls';
250     lid:
251     result := 'lid';
252     lda:
253     result := 'lda';
254     las:
255     result := 'las';
256     ini:
257     result := 'ini';
258     _inc:
259     result := 'inc';
260     _dec:
261     result := 'dec';
262     lin:
263     result := 'lin';
264     lde:
265     result := 'lde';
266     ads:
267     result := 'ads';
268     sus:
269     result := 'sus';
270     stp:
271     result := 'stp';
272     lds:
273     result := 'lds';
274     sds:
275     result := 'sds';
276 yamat0jp 2 else
277 yamat0jp 4 result := inttostr(c);
278 yamat0jp 2 end;
279     end;
280    
281     { TInst }
282    
283     constructor TInst.Create(const op: integer);
284     begin
285 yamat0jp 4 inherited Create;
286     opCode := op;
287 yamat0jp 2 end;
288    
289     function TInst.toString: string;
290     begin
291 yamat0jp 4 result := codeName(opCode);
292 yamat0jp 2 end;
293    
294     { TCellV }
295    
296     procedure TCellV.backBreak(const c: integer);
297     var
298     bc, t: integer;
299     begin
300 yamat0jp 4 bc := c;
301 yamat0jp 2 while bc <> 0 do
302     begin
303 yamat0jp 4 t := (code[bc] as TInstPC).value;
304     (code[bc] as TInstPC).value := cIndex + 1;
305     bc := t;
306 yamat0jp 2 end;
307     end;
308    
309     procedure TCellV.backPatch(i, j: integer);
310     begin
311 yamat0jp 4 (code[i] as TInstPC).value := _cellG.numAddr;
312     (code[j] as TInstPC).value := _cellG.snumAddr;
313 yamat0jp 2 end;
314    
315     procedure TCellV.backPatchJ(const i: integer);
316     begin
317 yamat0jp 4 (code[i] as TInstPC).value := cIndex + 1;
318 yamat0jp 2 end;
319    
320     procedure TCellV.backPatchL(i, j, a: integer);
321     begin
322     if a = 0 then
323 yamat0jp 4 code[i].opCode := lda
324     else
325     code[i].opCode := las;
326     (code[i] as TInstAddr).addr := _cellG.tAddr(j);
327 yamat0jp 2 end;
328    
329     procedure TCellV.changeS(i, a: integer);
330     begin
331     with code[i] as TInstOp do
332     begin
333 yamat0jp 4 if a = 0 then
334     if optr = sds then
335     optr := sid
336     else
337     optr := sld
338     else if optr = sid then
339     optr := sds
340     else
341     optr := sls;
342 yamat0jp 2 end;
343     end;
344    
345     procedure TCellV.checkMax;
346     begin
347     if cIndex > MAXCODE then
348 yamat0jp 4 _cellG.error('�R�[�h�I�[�o�[�����B')
349     else
350     inc(cIndex);
351 yamat0jp 2 end;
352    
353     constructor TCellV.Create(g: TCellG; c, t: Boolean);
354     begin
355 yamat0jp 4 inherited Create;
356     _cellG := g;
357     pCode := c;
358     pTrace := t;
359     cIndex := -1;
360     shokika;
361 yamat0jp 2 end;
362    
363     destructor TCellV.Destroy;
364     begin
365 yamat0jp 4 shokika;
366     inherited;
367 yamat0jp 2 end;
368    
369     procedure TCellV.error;
370     begin
371 yamat0jp 4 code[pc] := TInstOp.Create(opr, stp);
372 yamat0jp 2 end;
373    
374     function TCellV.execute: integer;
375     var
376     lev, m, m1, temp: integer;
377     s1, s2, tems: string;
378     t: TInst;
379     p: string;
380     begin
381 yamat0jp 4 genCodeO(stp);
382 yamat0jp 2 if _cellG.exe = 0 then
383     begin
384 yamat0jp 4 display[0] := 0;
385     sdisplay[0] := 0;
386 yamat0jp 2 end;
387 yamat0jp 4 inc(_cellG.exe);
388 yamat0jp 2 if pCode = true then
389     begin
390 yamat0jp 4 printCode;
391     Writeln;
392 yamat0jp 2 end;
393     if pTrace = true then
394 yamat0jp 4 Writeln('--- strat execution ---');
395     temp := 0;
396     tems := '';
397     o1 := 0;
398     o2 := 0;
399 yamat0jp 2 repeat
400     if pTrace = true then
401 yamat0jp 4 printExe;
402     t := code[pc];
403     o1 := t.opCode;
404 yamat0jp 2 case o1 of
405 yamat0jp 4 ict:
406 yamat0jp 2 begin
407 yamat0jp 4 inc(top, (t as TInstPC).value);
408     if top >= MAXMEM - MAXREG then
409     begin
410     Writeln('�I�[�o�[�t���[�����B');
411     error;
412     end;
413     end;
414     lit:
415 yamat0jp 2 begin
416 yamat0jp 4 stack[top] := (t as TInstVal).value;
417     inc(top);
418 yamat0jp 2 end;
419 yamat0jp 4 lod:
420 yamat0jp 2 begin
421 yamat0jp 4 stack[top] := stack[display[(t as TInstAddr).addr.level] +
422     (t as TInstAddr).addr.addr];
423     inc(top);
424     end;
425     los:
426 yamat0jp 2 begin
427 yamat0jp 4 sstack[tos] := sstack[sdisplay[(t as TInstAddr).addr.level] +
428     (t as TInstAddr).addr.addr];
429     inc(tos);
430 yamat0jp 2 end;
431 yamat0jp 4 ics:
432 yamat0jp 2 begin
433 yamat0jp 4 inc(tos, (t as TInstPC).value);
434     if tos >= MAXMEM - MAXMOJI then
435     begin
436     Writeln('�I�[�o�[�t���[�����B');
437     error;
438     end;
439     end;
440     lis:
441 yamat0jp 2 begin
442 yamat0jp 4 sstack[tos] := (t as TStrVal).value;
443     inc(tos);
444 yamat0jp 2 end;
445 yamat0jp 4 lda:
446 yamat0jp 2 begin
447 yamat0jp 4 stack[top] := display[(t as TInstAddr).addr.level] + (t as TInstAddr)
448     .addr.addr;
449     inc(top);
450     end;
451     las:
452 yamat0jp 2 begin
453 yamat0jp 4 stack[top] := sdisplay[(t as TInstAddr).addr.level] + (t as TInstAddr)
454     .addr.addr;
455     inc(top);
456 yamat0jp 2 end;
457 yamat0jp 4 sto:
458 yamat0jp 2 begin
459 yamat0jp 4 dec(top);
460     stack[display[TInstAddr(t).addr.level] + TInstAddr(t).addr.addr] :=
461     stack[top];
462     end;
463     sts:
464 yamat0jp 2 begin
465 yamat0jp 4 dec(tos);
466     sstack[sdisplay[(t as TInstAddr).addr.level] + (t as TInstAddr)
467     .addr.addr] := sstack[tos];
468 yamat0jp 2 end;
469 yamat0jp 4 cal:
470 yamat0jp 2 begin
471 yamat0jp 4 lev := (t as TInstCal).level + 1;
472     stack[top] := display[lev];
473     stack[top + 1] := sdisplay[lev];
474     stack[top + 2] := pc + 1;
475     display[lev] := top;
476     sdisplay[lev] := tos;
477     pc := (t as TInstCal).code;
478     continue;
479     end;
480     ret:
481 yamat0jp 2 begin
482 yamat0jp 4 m := (t as TInstRet).modori;
483     if m = CellG._I then
484     temp := stack[top - 1]
485     else
486     tems := sstack[tos - 1];
487     top := display[(t as TInstRet).level];
488     tos := sdisplay[(t as TInstRet).level];
489     display[(t as TInstRet).level] := stack[top];
490     sdisplay[(t as TInstRet).level] := stack[top + 1];
491     pc := stack[top + 2];
492     dec(top, (t as TInstRet).pI);
493     dec(tos, (t as TInstRet).pS);
494     if m = CellG._I then
495     begin
496     stack[top] := temp;
497     inc(top);
498     end
499     else if m = CellG._S then
500     begin
501     sstack[tos] := tems;
502     inc(tos);
503     end;
504     continue;
505 yamat0jp 2 end;
506 yamat0jp 4 dit:
507 yamat0jp 2 begin
508 yamat0jp 4 lev := (t as TInstPC).value;
509     stack[top] := display[lev];
510     stack[top + 1] := sdisplay[lev];
511     display[lev] := top;
512     sdisplay[lev] := tos;
513     end;
514     dik:
515 yamat0jp 2 begin
516 yamat0jp 4 lev := (t as TInstPC).value;
517     top := display[lev];
518     tos := sdisplay[lev];
519     display[lev] := stack[top];
520     sdisplay[lev] := stack[top + 1];
521 yamat0jp 2 end;
522 yamat0jp 4 jmp:
523 yamat0jp 2 begin
524 yamat0jp 4 pc := (t as TInstPC).value;
525     continue;
526     end;
527     jpc:
528 yamat0jp 2 begin
529 yamat0jp 4 dec(top);
530     if stack[top] = 0 then
531     begin
532     pc := (t as TInstPC).value;
533     continue;
534     end;
535 yamat0jp 2 end;
536 yamat0jp 4 arr:
537     begin
538     m := stack[top - 2];
539     m1 := stack[top - 1];
540     if (m > TInstAddr(t).addr.level) or (m1 > TInstAddr(t).addr.addr) then
541     begin
542     Writeln('�z���I�[�o�[�����B');
543     error;
544     end;
545     stack[top] := TInstAddr(t).addr.level;
546     stack[top - 2] := m * stack[top];
547     stack[top - 3] := stack[top - 3] + stack[top - 2];
548     stack[top - 3] := stack[top - 3] + m1;
549     dec(top, 2);
550     end;
551     opr:
552     begin
553     o2 := TInstOp(t).optr;
554     case o2 of
555     neg:
556     stack[top - 1] := -stack[top - 1];
557     _add:
558     begin
559 yamat0jp 2 dec(top);
560 yamat0jp 4 stack[top - 1] := stack[top - 1] + stack[top];
561     end;
562     _sub:
563     begin
564     dec(top);
565     stack[top - 1] := stack[top - 1] - stack[top];
566     end;
567     _mul:
568     begin
569     dec(top);
570     stack[top - 1] := stack[top - 1] * stack[top];
571     end;
572     _div:
573     begin
574     dec(top);
575     stack[top - 1] := stack[top - 1] div stack[top];
576     end;
577     eql:
578     begin
579     dec(top);
580     if stack[top - 1] = stack[top] then
581     stack[top - 1] := 1
582     else
583     stack[top - 1] := 0;
584     end;
585     neq:
586     begin
587     dec(top);
588     if stack[top - 1] <> stack[top] then
589     stack[top - 1] := 1
590     else
591     stack[top - 1] := 0;
592     end;
593     eqs:
594     begin
595     if CompareText(sstack[tos - 2], sstack[tos - 1]) = 0 then
596     stack[top] := 1
597     else
598     stack[top] := 0;
599     inc(top);
600     dec(tos, 2);
601     end;
602     nes:
603     begin
604     if CompareText(sstack[tos - 2], sstack[tos - 1]) = 1 then
605     stack[top] := 1
606     else
607     stack[top] := 0;
608     inc(top);
609     dec(tos, 2);
610     end;
611     lss:
612     begin
613     dec(top);
614     if stack[top - 1] < stack[top] then
615     stack[top - 1] := 1
616     else
617     stack[top - 1] := 0;
618     end;
619     gtr:
620     begin
621     dec(top);
622     if stack[top - 1] > stack[top] then
623     stack[top - 1] := 1
624     else
625     stack[top - 1] := 0;
626     end;
627     leq:
628     begin
629     dec(top);
630     if stack[top - 1] <= stack[top] then
631     stack[top - 1] := 1
632     else
633     stack[top - 1] := 0;
634     end;
635     geq:
636     begin
637     dec(top);
638     if stack[top - 1] >= stack[top] then
639     stack[top - 1] := 1
640     else
641     stack[top - 1] := 0;
642     end;
643     prt:
644     begin
645     dec(top);
646     Writeln(inttostr(stack[top]));
647     end;
648     prs:
649     begin
650 yamat0jp 2 dec(tos);
651     Writeln(sstack[tos]);
652 yamat0jp 4 end;
653     prl:
654     Writeln;
655     ads:
656     begin
657 yamat0jp 2 dec(tos);
658 yamat0jp 4 sstack[tos - 1] := sstack[tos - 1] + sstack[tos];
659     end;
660     sus:
661     begin
662 yamat0jp 2 dec(tos);
663 yamat0jp 4 s1 := sstack[tos - 1];
664     s2 := sstack[tos];
665     temp := Pos(s2, s1);
666     if temp > 0 then
667     begin
668     Delete(s1, temp, Length(s2));
669     sstack[tos - 1] := s1;
670     end;
671     end;
672     mus:
673     begin
674 yamat0jp 2 dec(top);
675 yamat0jp 4 s1 := '';
676     s2 := sstack[tos - 1];
677     for m := 1 to stack[top] do
678     s1 := s1 + s2;
679     sstack[tos - 1] := s1;
680     end;
681     dis:
682     begin
683     s1 := sstack[tos - 3];
684     s2 := sstack[tos - 2];
685     m := Pos(s2, s1);
686     while m > 0 do
687     begin
688     Delete(s1, m, Length(s2));
689     Insert(sstack[tos - 1], s1, m);
690     m := Pos(s2, s1);
691     end;
692     sstack[tos - 3] := s1;
693     dec(tos, 2);
694     end;
695     ini:
696     begin
697     p := '';
698     while _cellG.checkIn(p) = true do
699     begin
700     Writeln('�����������������������B');
701     Write('>');
702     Readln(p);
703     end;
704     stack[top] := StrToInt(p);
705 yamat0jp 2 inc(top);
706 yamat0jp 4 end;
707     ins:
708     begin
709     p := '';
710 yamat0jp 2 Write('>');
711     Readln(p);
712 yamat0jp 4 sstack[tos] := p;
713 yamat0jp 2 inc(tos);
714 yamat0jp 4 end;
715     sid:
716     begin
717     stack[stack[top - 2]] := stack[top - 1];
718     dec(top, 2);
719     end;
720     lid:
721     stack[top - 1] := stack[stack[top - 1]]; //
722     lds:
723     begin
724 yamat0jp 2 dec(top);
725 yamat0jp 4 sstack[tos] := sstack[stack[top]];
726 yamat0jp 2 inc(tos);
727 yamat0jp 4 end;
728     sld:
729     begin
730 yamat0jp 2 dec(top);
731 yamat0jp 4 stack[stack[top - 1]] := stack[top];
732     stack[top - 1] := stack[top];
733     end;
734     sls:
735     begin
736 yamat0jp 2 dec(top);
737 yamat0jp 4 sstack[stack[top]] := sstack[tos - 1];
738     end;
739     sds:
740     begin
741 yamat0jp 2 dec(top);
742     dec(tos);
743 yamat0jp 4 sstack[stack[top]] := sstack[tos];
744     end;
745     _inc:
746     begin
747 yamat0jp 2 dec(top);
748     inc(stack[top]);
749 yamat0jp 4 end;
750     _dec:
751     begin
752 yamat0jp 2 dec(top);
753     dec(stack[top]);
754 yamat0jp 4 end;
755     lin, lde:
756     begin
757     m := stack[top - 1];
758     if o2 = lin then
759     inc(stack[m])
760     else
761     dec(stack[m]);
762     stack[top - 1] := stack[m];
763     end;
764     end;
765 yamat0jp 2 end;
766     end;
767 yamat0jp 4 inc(pc);
768 yamat0jp 2 until o2 = stp;
769 yamat0jp 4 shokika;
770     _cellG.shokika;
771     _cellG.closeFile;
772     pTrace := false;
773     pCode := false;
774     _cellG.pTable := false;
775 yamat0jp 2 end;
776    
777     function TCellV.genCodeA(const op: integer; a: TRaddr): integer;
778     begin
779 yamat0jp 4 checkMax;
780     code[cIndex] := TInstAddr.Create(op, a);
781     result := cIndex;
782 yamat0jp 2 end;
783    
784     function TCellV.genCodeC(l, c: integer): integer;
785     begin
786 yamat0jp 4 checkMax;
787     code[cIndex] := TInstCal.Create(cal, l, c);
788     result := cIndex;
789 yamat0jp 2 end;
790    
791     function TCellV.genCodeO(const p: integer): integer;
792     begin
793 yamat0jp 4 checkMax;
794     code[cIndex] := TInstOp.Create(opr, p);
795     result := cIndex;
796 yamat0jp 2 end;
797    
798     function TCellV.genCodeR: integer;
799     begin
800     if code[cIndex].opCode = ret then
801     begin
802 yamat0jp 4 result := cIndex;
803     Exit;
804 yamat0jp 2 end;
805 yamat0jp 4 checkMax;
806     code[cIndex] := TInstRet.Create(ret, _cellG.bLevel, _cellG.funcParIs,
807     _cellG.funcParSs, _cellG.funcModori);
808     result := cIndex;
809 yamat0jp 2 end;
810    
811     function TCellV.genCodeS(op: integer; v: string): integer;
812     begin
813 yamat0jp 4 checkMax;
814     code[cIndex] := TStrVal.Create(op, v);
815     result := cIndex;
816 yamat0jp 2 end;
817    
818     function TCellV.genCodeT(const op, t: integer): integer;
819     begin
820 yamat0jp 4 checkMax;
821     code[cIndex] := TInstAddr.Create(op, _cellG.tAddr(t));
822     result := cIndex;
823 yamat0jp 2 end;
824    
825     function TCellV.genCodeV(const op, v: integer): integer;
826     begin
827 yamat0jp 4 checkMax;
828     code[cIndex] := TInstVal.Create(op, v);
829     result := cIndex;
830 yamat0jp 2 end;
831    
832     function TCellV.nextCode: integer;
833     begin
834 yamat0jp 4 result := cIndex + 1;
835 yamat0jp 2 end;
836    
837     procedure TCellV.printCode;
838     var
839     i: integer;
840     begin
841 yamat0jp 4 Writeln('--- code ---');
842     for i := 0 to cIndex do
843     Writeln(inttostr(i) + ' : ' + code[i].toString);
844 yamat0jp 2 end;
845    
846     procedure TCellV.printExe;
847     begin
848     if o1 = 0 then
849 yamat0jp 4 Exit
850     else if o1 = -1 then
851 yamat0jp 2 begin
852 yamat0jp 4 Writeln;
853     Exit;
854     end
855     else if o1 <> opr then
856     Write(codeName(o1) + ' : ');
857 yamat0jp 2 case o1 of
858 yamat0jp 4 ict:
859     Writeln('Istack=' + inttostr(top));
860     ics:
861     Writeln('Sstack=' + inttostr(tos));
862     lit, lod, lda, las, arr:
863     Writeln('Istack=' + inttostr(top - 1) + ' : ' + inttostr(stack[top - 1]));
864     lis, los, lds:
865     Writeln('Sstack=' + inttostr(tos - 1) + ' : ' + sstack[tos - 1]);
866     sto:
867     Writeln(inttostr(stack[top]));
868     ret, jmp, jpc:
869     Writeln(inttostr(pc));
870     cal:
871     Writeln(inttostr(pc));
872     dit, dik:
873     Writeln;
874     opr:
875     begin
876     Write(codeName(o2) + ' : ');
877     if o2 < ini then
878     Writeln('Istack=' + inttostr(top - 1) + ' : ' +
879     inttostr(stack[top - 1]))
880     else if o2 < prt then
881     Writeln(inttostr(stack[top]))
882     else
883     Writeln(sstack[tos]);
884     end;
885 yamat0jp 2 else
886 yamat0jp 4 Writeln(inttostr(o1));
887 yamat0jp 2 end;
888     end;
889    
890     procedure TCellV.backCal(i, l, c: integer);
891     begin
892 yamat0jp 4 (code[i] as TInstCal).code := c;
893     (code[i] as TInstCal).level := l;
894 yamat0jp 2 end;
895    
896     procedure TCellV.shokika;
897     var
898     i: integer;
899     begin
900 yamat0jp 4 for i := 0 to cIndex do
901     code[i].Free;
902     cIndex := -1;
903     top := 0;
904     tos := 0;
905     pc := 0;
906 yamat0jp 2 end;
907    
908     function TCellV.genCodeP(op, v: integer): integer;
909     begin
910 yamat0jp 4 checkMax;
911     code[cIndex] := TInstPC.Create(op, v);
912     result := cIndex;
913 yamat0jp 2 end;
914    
915     function TCellV.genCodeRV: integer;
916     begin
917     if code[cIndex].opCode = ret then
918     begin
919 yamat0jp 4 result := cIndex;
920     Exit;
921 yamat0jp 2 end;
922 yamat0jp 4 checkMax;
923     code[cIndex] := TInstRet.Create(ret, _cellG.bLevel + 1, _cellG.funcParIs,
924     _cellG.funcParSs, _cellG.funcModori);
925     result := cIndex;
926 yamat0jp 2 end;
927    
928     { TInstAddr }
929    
930     constructor TInstAddr.Create(const op: integer; a: TRaddr);
931     begin
932 yamat0jp 4 inherited Create(op);
933     addr := a;
934 yamat0jp 2 end;
935    
936     function TInstAddr.toString: string;
937     begin
938 yamat0jp 4 result := inherited toString + ',addr=' + inttostr(addr.level) +
939     inttostr(addr.addr);
940 yamat0jp 2 end;
941    
942     { TInstRet }
943    
944 yamat0jp 4 constructor TInstRet.Create(const op, l, pI, pS, m: integer);
945 yamat0jp 2 begin
946 yamat0jp 4 inherited Create(op);
947     level := l;
948     self.pI := pI;
949     self.pS := pS;
950     modori := m;
951 yamat0jp 2 end;
952    
953     function TInstRet.toString: string;
954     begin
955 yamat0jp 4 result := inherited toString + ',level=' + inttostr(level) + ',pI=' +
956     inttostr(pI) + ',modori=' + CellG.hyouji(modori);
957 yamat0jp 2 end;
958    
959     { TInstVal }
960    
961     constructor TInstVal.Create(const op, v: integer);
962     begin
963 yamat0jp 4 inherited Create(op);
964     value := v;
965 yamat0jp 2 end;
966    
967     function TInstVal.toString: string;
968     begin
969 yamat0jp 4 result := inherited toString + ',value=' + inttostr(value);
970 yamat0jp 2 end;
971    
972     { TInstOp }
973    
974     constructor TInstOp.Create(const op, o: integer);
975     begin
976 yamat0jp 4 inherited Create(op);
977     optr := o;
978 yamat0jp 2 end;
979    
980     function TInstOp.toString: string;
981     begin
982 yamat0jp 4 result := inherited toString + ',optr=' + codeName(optr);
983 yamat0jp 2 end;
984    
985     { TStrVal }
986    
987     constructor TStrVal.Create(op: integer; v: string);
988     begin
989 yamat0jp 4 inherited Create(op);
990     value := v;
991 yamat0jp 2 end;
992    
993     function TStrVal.toString: string;
994     begin
995 yamat0jp 4 result := (inherited toString) + '.value=' + value;
996 yamat0jp 2 end;
997    
998     { TInstCal }
999    
1000     constructor TInstCal.Create(op, l, c: integer);
1001     begin
1002 yamat0jp 4 inherited Create(op);
1003     level := l;
1004     code := c;
1005 yamat0jp 2 end;
1006    
1007     function TInstCal.toString: string;
1008     begin
1009 yamat0jp 4 result := (inherited toString) + ',' + inttostr(code);
1010 yamat0jp 2 end;
1011    
1012     { TInstPC }
1013    
1014     constructor TInstPC.Create(op, v: integer);
1015     begin
1016 yamat0jp 4 inherited Create(op);
1017     value := v;
1018 yamat0jp 2 end;
1019    
1020     function TInstPC.toString: string;
1021     begin
1022 yamat0jp 4 result := (inherited toString) + '.value' + inttostr(value);
1023 yamat0jp 2 end;
1024    
1025     end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26