update toolbox when reversing a way, or when adding nodes during drawway
[potlatch2.git] / hxasm / OpWriter.as
1 package hxasm {
2         
3         import flash.utils.ByteArray;
4         
5         public class OpWriter {
6                 public function OpWriter() : void {
7                         this.o = new Output();
8                 }
9                 protected var o : Output;
10                 protected function _int(i : int) : void {
11                         writeInt(this.o,i);
12                 }
13                 protected function b(v : int) : void {
14                         this.o.writeChar(v);
15                 }
16                 protected function reg(v : int) : void {
17                         this.o.writeChar(v);
18                 }
19                 protected function idx(i : Index) : void {
20                         var $e : enum = (i);
21                         switch( $e.index ) {
22                         case 0:
23                         var i1 : int = $e.params[0];
24                         {
25                                 this._int(i1);
26                         }break;
27                         }
28                 }
29                 protected function jumpCode(j : JumpStyle) : int {
30                         return function($this:OpWriter) : int {
31                                 var $r : int;
32                                 var $e : enum = (j);
33                                 switch( $e.index ) {
34                                 case 0:
35                                 {
36                                         $r = 12;
37                                 }break;
38                                 case 1:
39                                 {
40                                         $r = 13;
41                                 }break;
42                                 case 2:
43                                 {
44                                         $r = 14;
45                                 }break;
46                                 case 3:
47                                 {
48                                         $r = 15;
49                                 }break;
50                                 case 4:
51                                 {
52                                         $r = 16;
53                                 }break;
54                                 case 5:
55                                 {
56                                         $r = 17;
57                                 }break;
58                                 case 6:
59                                 {
60                                         $r = 18;
61                                 }break;
62                                 case 7:
63                                 {
64                                         $r = 19;
65                                 }break;
66                                 case 8:
67                                 {
68                                         $r = 20;
69                                 }break;
70                                 case 9:
71                                 {
72                                         $r = 21;
73                                 }break;
74                                 case 10:
75                                 {
76                                         $r = 22;
77                                 }break;
78                                 case 11:
79                                 {
80                                         $r = 23;
81                                 }break;
82                                 case 12:
83                                 {
84                                         $r = 24;
85                                 }break;
86                                 case 13:
87                                 {
88                                         $r = 25;
89                                 }break;
90                                 case 14:
91                                 {
92                                         $r = 26;
93                                 }break;
94                                 default:{
95                                         $r = null;
96                                 }break;
97                                 }
98                                 return $r;
99                         }(this);
100                 }
101                 protected function operationCode(o : Operation) : int {
102                         return function($this:OpWriter) : int {
103                                 var $r : int;
104                                 var $e : enum = (o);
105                                 switch( $e.index ) {
106                                 case 0:
107                                 {
108                                         $r = 135;
109                                 }break;
110                                 case 1:
111                                 {
112                                         $r = 144;
113                                 }break;
114                                 case 2:
115                                 {
116                                         $r = 145;
117                                 }break;
118                                 case 3:
119                                 {
120                                         $r = 147;
121                                 }break;
122                                 case 4:
123                                 {
124                                         $r = 150;
125                                 }break;
126                                 case 5:
127                                 {
128                                         $r = 151;
129                                 }break;
130                                 case 6:
131                                 {
132                                         $r = 160;
133                                 }break;
134                                 case 7:
135                                 {
136                                         $r = 161;
137                                 }break;
138                                 case 8:
139                                 {
140                                         $r = 162;
141                                 }break;
142                                 case 9:
143                                 {
144                                         $r = 163;
145                                 }break;
146                                 case 10:
147                                 {
148                                         $r = 164;
149                                 }break;
150                                 case 11:
151                                 {
152                                         $r = 165;
153                                 }break;
154                                 case 12:
155                                 {
156                                         $r = 166;
157                                 }break;
158                                 case 13:
159                                 {
160                                         $r = 167;
161                                 }break;
162                                 case 14:
163                                 {
164                                         $r = 168;
165                                 }break;
166                                 case 15:
167                                 {
168                                         $r = 169;
169                                 }break;
170                                 case 16:
171                                 {
172                                         $r = 170;
173                                 }break;
174                                 case 17:
175                                 {
176                                         $r = 171;
177                                 }break;
178                                 case 18:
179                                 {
180                                         $r = 172;
181                                 }break;
182                                 case 19:
183                                 {
184                                         $r = 173;
185                                 }break;
186                                 case 20:
187                                 {
188                                         $r = 174;
189                                 }break;
190                                 case 21:
191                                 {
192                                         $r = 175;
193                                 }break;
194                                 case 22:
195                                 {
196                                         $r = 176;
197                                 }break;
198                                 case 23:
199                                 {
200                                         $r = 179;
201                                 }break;
202                                 case 24:
203                                 {
204                                         $r = 180;
205                                 }break;
206                                 case 25:
207                                 {
208                                         $r = 192;
209                                 }break;
210                                 case 26:
211                                 {
212                                         $r = 193;
213                                 }break;
214                                 case 27:
215                                 {
216                                         $r = 196;
217                                 }break;
218                                 case 28:
219                                 {
220                                         $r = 197;
221                                 }break;
222                                 case 29:
223                                 {
224                                         $r = 198;
225                                 }break;
226                                 case 30:
227                                 {
228                                         $r = 199;
229                                 }break;
230                                 default:{
231                                         $r = null;
232                                 }break;
233                                 }
234                                 return $r;
235                         }(this);
236                 }
237                 public function write(op : OpCode) : void {
238                         var $e : enum = (op);
239                         switch( $e.index ) {
240                         case 0:
241                         {
242                                 this.b(1);
243                         }break;
244                         case 1:
245                         {
246                                 this.b(2);
247                         }break;
248                         case 2:
249                         {
250                                 this.b(3);
251                         }break;
252                         case 3:
253                         var v : Index = $e.params[0];
254                         {
255                                 this.b(4);
256                                 this.idx(v);
257                         }break;
258                         case 4:
259                         var v2 : Index = $e.params[0];
260                         {
261                                 this.b(5);
262                                 this.idx(v2);
263                         }break;
264                         case 5:
265                         var r : int = $e.params[0];
266                         {
267                                 this.b(8);
268                                 this.reg(r);
269                         }break;
270                         case 6:
271                         {
272                                 this.b(9);
273                         }break;
274                         case 7:
275                         var delta : int = $e.params[1], j : JumpStyle = $e.params[0];
276                         {
277                                 this.b(this.jumpCode(j));
278                                 this.o.writeInt24(delta);
279                         }break;
280                         case 8:
281                         var deltas : Array = $e.params[1], def : int = $e.params[0];
282                         {
283                                 this.b(27);
284                                 this.o.writeInt24(def);
285                                 this._int(deltas.length - 1);
286                                 {
287                                         var _g : int = 0;
288                                         while(_g < deltas.length) {
289                                                 var d : int = deltas[_g];
290                                                 ++_g;
291                                                 this.o.writeInt24(d);
292                                         }
293                                 }
294                         }break;
295                         case 9:
296                         {
297                                 this.b(28);
298                         }break;
299                         case 10:
300                         {
301                                 this.b(29);
302                         }break;
303                         case 11:
304                         {
305                                 this.b(30);
306                         }break;
307                         case 12:
308                         {
309                                 this.b(31);
310                         }break;
311                         case 13:
312                         {
313                                 this.b(32);
314                         }break;
315                         case 14:
316                         {
317                                 this.b(33);
318                         }break;
319                         case 15:
320                         {
321                                 this.b(35);
322                         }break;
323                         case 16:
324                         var v3 : int = $e.params[0];
325                         {
326                                 this.b(36);
327                                 this.o.writeInt8(v3);
328                         }break;
329                         case 17:
330                         var v4 : int = $e.params[0];
331                         {
332                                 this.b(37);
333                                 this._int(v4);
334                         }break;
335                         case 18:
336                         {
337                                 this.b(38);
338                         }break;
339                         case 19:
340                         {
341                                 this.b(39);
342                         }break;
343                         case 20:
344                         {
345                                 this.b(40);
346                         }break;
347                         case 21:
348                         {
349                                 this.b(41);
350                         }break;
351                         case 22:
352                         {
353                                 this.b(42);
354                         }break;
355                         case 23:
356                         {
357                                 this.b(43);
358                         }break;
359                         case 24:
360                         var v5 : Index = $e.params[0];
361                         {
362                                 this.b(44);
363                                 this.idx(v5);
364                         }break;
365                         case 25:
366                         var v6 : Index = $e.params[0];
367                         {
368                                 this.b(45);
369                                 this.idx(v6);
370                         }break;
371                         case 26:
372                         var v7 : Index = $e.params[0];
373                         {
374                                 this.b(47);
375                                 this.idx(v7);
376                         }break;
377                         case 27:
378                         {
379                                 this.b(48);
380                         }break;
381                         case 28:
382                         var v8 : Index = $e.params[0];
383                         {
384                                 this.b(49);
385                                 this.idx(v8);
386                         }break;
387                         case 29:
388                         var r2 : int = $e.params[1], r1 : int = $e.params[0];
389                         {
390                                 this.b(50);
391                                 this._int(r1);
392                                 this._int(r2);
393                         }break;
394                         case 30:
395                         var f : Index = $e.params[0];
396                         {
397                                 this.b(64);
398                                 this.idx(f);
399                         }break;
400                         case 31:
401                         var n : int = $e.params[0];
402                         {
403                                 this.b(65);
404                                 this._int(n);
405                         }break;
406                         case 32:
407                         var n2 : int = $e.params[0];
408                         {
409                                 this.b(66);
410                                 this._int(n2);
411                         }break;
412                         case 33:
413                         var n3 : int = $e.params[1], s : int = $e.params[0];
414                         {
415                                 this.b(67);
416                                 this._int(s);
417                                 this._int(n3);
418                         }break;
419                         case 34:
420                         var n4 : int = $e.params[1], m : Index = $e.params[0];
421                         {
422                                 this.b(68);
423                                 this.idx(m);
424                                 this._int(n4);
425                         }break;
426                         case 35:
427                         var n5 : int = $e.params[1], p : Index = $e.params[0];
428                         {
429                                 this.b(69);
430                                 this.idx(p);
431                                 this._int(n5);
432                         }break;
433                         case 36:
434                         var n6 : int = $e.params[1], p2 : Index = $e.params[0];
435                         {
436                                 this.b(70);
437                                 this.idx(p2);
438                                 this._int(n6);
439                         }break;
440                         case 37:
441                         {
442                                 this.b(71);
443                         }break;
444                         case 38:
445                         {
446                                 this.b(72);
447                         }break;
448                         case 39:
449                         var n7 : int = $e.params[0];
450                         {
451                                 this.b(73);
452                                 this._int(n7);
453                         }break;
454                         case 40:
455                         var n8 : int = $e.params[1], p3 : Index = $e.params[0];
456                         {
457                                 this.b(74);
458                                 this.idx(p3);
459                                 this._int(n8);
460                         }break;
461                         case 41:
462                         var n9 : int = $e.params[1], p4 : Index = $e.params[0];
463                         {
464                                 this.b(76);
465                                 this.idx(p4);
466                                 this._int(n9);
467                         }break;
468                         case 42:
469                         var n10 : int = $e.params[1], p5 : Index = $e.params[0];
470                         {
471                                 this.b(78);
472                                 this.idx(p5);
473                                 this._int(n10);
474                         }break;
475                         case 43:
476                         var n11 : int = $e.params[1], p6 : Index = $e.params[0];
477                         {
478                                 this.b(79);
479                                 this.idx(p6);
480                                 this._int(n11);
481                         }break;
482                         case 44:
483                         var n12 : int = $e.params[0];
484                         {
485                                 this.b(85);
486                                 this._int(n12);
487                         }break;
488                         case 45:
489                         var n13 : int = $e.params[0];
490                         {
491                                 this.b(86);
492                                 this._int(n13);
493                         }break;
494                         case 46:
495                         {
496                                 this.b(87);
497                         }break;
498                         case 47:
499                         var c : Index = $e.params[0];
500                         {
501                                 this.b(88);
502                                 this.idx(c);
503                         }break;
504                         case 48:
505                         var c2 : int = $e.params[0];
506                         {
507                                 this.b(90);
508                                 this._int(c2);
509                         }break;
510                         case 49:
511                         var p7 : Index = $e.params[0];
512                         {
513                                 this.b(93);
514                                 this.idx(p7);
515                         }break;
516                         case 50:
517                         var p8 : Index = $e.params[0];
518                         {
519                                 this.b(94);
520                                 this.idx(p8);
521                         }break;
522                         case 51:
523                         var d2 : Index = $e.params[0];
524                         {
525                                 this.b(95);
526                                 this.idx(d2);
527                         }break;
528                         case 52:
529                         var p9 : Index = $e.params[0];
530                         {
531                                 this.b(96);
532                                 this.idx(p9);
533                         }break;
534                         case 53:
535                         var p10 : Index = $e.params[0];
536                         {
537                                 this.b(97);
538                                 this.idx(p10);
539                         }break;
540                         case 54:
541                         var r3 : int = $e.params[0];
542                         {
543                                 switch(r3) {
544                                 case 0:{
545                                         this.b(208);
546                                 }break;
547                                 case 1:{
548                                         this.b(209);
549                                 }break;
550                                 case 2:{
551                                         this.b(210);
552                                 }break;
553                                 case 3:{
554                                         this.b(211);
555                                 }break;
556                                 default:{
557                                         this.b(98);
558                                         this.reg(r3);
559                                 }break;
560                                 }
561                         }break;
562                         case 55:
563                         var r4 : int = $e.params[0];
564                         {
565                                 switch(r4) {
566                                 case 0:{
567                                         this.b(212);
568                                 }break;
569                                 case 1:{
570                                         this.b(213);
571                                 }break;
572                                 case 2:{
573                                         this.b(214);
574                                 }break;
575                                 case 3:{
576                                         this.b(215);
577                                 }break;
578                                 default:{
579                                         this.b(99);
580                                         this.reg(r4);
581                                 }break;
582                                 }
583                         }break;
584                         case 56:
585                         {
586                                 this.b(100);
587                         }break;
588                         case 57:
589                         var n14 : int = $e.params[0];
590                         {
591                                 this.b(101);
592                                 this.b(n14);
593                         }break;
594                         case 58:
595                         var p11 : Index = $e.params[0];
596                         {
597                                 this.b(102);
598                                 this.idx(p11);
599                         }break;
600                         case 59:
601                         var p12 : Index = $e.params[0];
602                         {
603                                 this.b(104);
604                                 this.idx(p12);
605                         }break;
606                         case 60:
607                         var p13 : Index = $e.params[0];
608                         {
609                                 this.b(106);
610                                 this.idx(p13);
611                         }break;
612                         case 61:
613                         var s2 : int = $e.params[0];
614                         {
615                                 this.b(108);
616                                 this._int(s2);
617                         }break;
618                         case 62:
619                         var s3 : int = $e.params[0];
620                         {
621                                 this.b(109);
622                                 this._int(s3);
623                         }break;
624                         case 63:
625                         {
626                                 this.b(112);
627                         }break;
628                         case 64:
629                         {
630                                 this.b(113);
631                         }break;
632                         case 65:
633                         {
634                                 this.b(114);
635                         }break;
636                         case 66:
637                         {
638                                 this.b(115);
639                         }break;
640                         case 67:
641                         {
642                                 this.b(116);
643                         }break;
644                         case 68:
645                         {
646                                 this.b(117);
647                         }break;
648                         case 69:
649                         {
650                                 this.b(118);
651                         }break;
652                         case 70:
653                         {
654                                 this.b(119);
655                         }break;
656                         case 71:
657                         {
658                                 this.b(120);
659                         }break;
660                         case 72:
661                         var t : Index = $e.params[0];
662                         {
663                                 this.b(128);
664                                 this.idx(t);
665                         }break;
666                         case 73:
667                         {
668                                 this.b(130);
669                         }break;
670                         case 74:
671                         {
672                                 this.b(133);
673                         }break;
674                         case 75:
675                         var t2 : Index = $e.params[0];
676                         {
677                                 this.b(134);
678                                 this.idx(t2);
679                         }break;
680                         case 76:
681                         {
682                                 this.b(137);
683                         }break;
684                         case 77:
685                         var r5 : int = $e.params[0];
686                         {
687                                 this.b(146);
688                                 this.reg(r5);
689                         }break;
690                         case 78:
691                         var r6 : int = $e.params[0];
692                         {
693                                 this.b(148);
694                                 this.reg(r6);
695                         }break;
696                         case 79:
697                         {
698                                 this.b(149);
699                         }break;
700                         case 80:
701                         {
702                                 this.b(177);
703                         }break;
704                         case 81:
705                         var t3 : Index = $e.params[0];
706                         {
707                                 this.b(178);
708                                 this.idx(t3);
709                         }break;
710                         case 82:
711                         var r7 : int = $e.params[0];
712                         {
713                                 this.b(194);
714                                 this.reg(r7);
715                         }break;
716                         case 83:
717                         var r8 : int = $e.params[0];
718                         {
719                                 this.b(195);
720                                 this.reg(r8);
721                         }break;
722                         case 84:
723                         {
724                                 this.b(208);
725                         }break;
726                         case 85:
727                         {
728                                 this.b(212);
729                         }break;
730                         case 86:
731                         var line : int = $e.params[2], r9 : int = $e.params[1], name : Index = $e.params[0];
732                         {
733                                 this.b(239);
734                                 this.idx(name);
735                                 this.reg(r9);
736                                 this._int(line);
737                         }break;
738                         case 87:
739                         var line2 : int = $e.params[0];
740                         {
741                                 this.b(240);
742                                 this._int(line2);
743                         }break;
744                         case 88:
745                         var file : Index = $e.params[0];
746                         {
747                                 this.b(241);
748                                 this.idx(file);
749                         }break;
750                         case 89:
751                         var n15 : int = $e.params[0];
752                         {
753                                 this.b(242);
754                                 this._int(n15);
755                         }break;
756                         case 90:
757                         {
758                                 this.b(243);
759                         }break;
760                         case 91:
761                         var op1 : Operation = $e.params[0];
762                         {
763                                 this.b(this.operationCode(op1));
764                         }break;
765                         case 92:
766                         var byte : int = $e.params[0];
767                         {
768                                 this.b(byte);
769                         }break;
770                         }
771                 }
772                 public function getBytes() : ByteArray {
773                         return this.o.getBytes();
774                 }
775                 static public function writeInt(o : Output,n : int) : void {
776                         var e : int = n >>> 28;
777                         var d : int = (n >> 21) & 127;
778                         var c : int = (n >> 14) & 127;
779                         var b : int = (n >> 7) & 127;
780                         var a : int = n & 127;
781                         if(b != 0 || c != 0 || d != 0 || e != 0) {
782                                 o.writeChar(a | 128);
783                                 if(c != 0 || d != 0 || e != 0) {
784                                         o.writeChar(b | 128);
785                                         if(d != 0 || e != 0) {
786                                                 o.writeChar(c | 128);
787                                                 if(e != 0) {
788                                                         o.writeChar(d | 128);
789                                                         o.writeChar(e);
790                                                 }
791                                                 else o.writeChar(d);
792                                         }
793                                         else o.writeChar(c);
794                                 }
795                                 else o.writeChar(b);
796                         }
797                         else o.writeChar(a);
798                 }
799         }
800 }