File: byte_def.cc

package info (click to toggle)
gnu-smalltalk 3.2.4-2.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,688 kB
  • ctags: 14,104
  • sloc: ansic: 87,424; sh: 22,729; asm: 8,465; perl: 4,513; cpp: 3,548; xml: 1,669; awk: 1,581; yacc: 1,357; makefile: 1,237; lisp: 855; lex: 843; sed: 258; objc: 124
file content (596 lines) | stat: -rw-r--r-- 18,342 bytes parent folder | download | duplicates (4)
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
/////////////////////////////// -*- C++ -*- ///////////////////////////
//
//	Program to extract superoperators from a GNU Smalltalk image.
//	byte.def creation routines.
//
///////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////
//
// Copyright 2003, 2007 Free Software Foundation, Inc.
// Written by Paolo Bonzini.
//
// This file is part of GNU Smalltalk.
//
// GNU Smalltalk is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2, or (at your option) any later
// version.
//
// GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// GNU Smalltalk; see the file COPYING.	 If not, write to the Free Software
// Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
///////////////////////////////////////////////////////////////////////

#if defined __GNUC__ && __GNUC__ < 3
#error Sorry, you need a recent C++ compiler to compile this program.
#endif

#include "byte_def.h"
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>

namespace {

struct bytecode {
  static bytecode *bytecodes[256];

  std::string str;
  int num;

  bytecode (int _num);
  bytecode (int _num, const char *_str);
  virtual void write_byte_def (std::ostream &os);
  virtual void write_byte_def_ext_arg (std::ostream &os, int arg) = 0;
  virtual void write_byte_def_fixed_arg (std::ostream &os, int arg) = 0;
  virtual void write_byte_def_var_arg (std::ostream &os) = 0;
};

struct bytecode_elementary : bytecode {
  const char *name;
  bytecode_elementary (int _num, const char *_name, const char *_str);
};

struct bytecode_noarg : bytecode_elementary {
  bytecode_noarg (int _num, const char *_name, const char *_str);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

struct bytecode_fast_send : bytecode_noarg {
  bytecode_fast_send (int _num, const char *_name, const char *_str);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
};

struct bytecode_invalid : bytecode {
  bytecode_invalid (int _num);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

struct bytecode_unary : bytecode_elementary {
  bytecode_unary (int _num, const char *_name, const char *_str);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

struct bytecode_ext : bytecode_elementary {
  bytecode_ext (int _num, const char *_name, const char *_str);
  void write_byte_def (std::ostream &os);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

struct bytecode_jump : bytecode_elementary {
  const char *sign;
  bytecode_jump (int _num, const char *_name, bool minus, const char *_str);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

struct bytecode_binary : bytecode_elementary {
  bytecode_binary (int _num, const char *_name, const char *_str);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

struct bytecode_send : bytecode_elementary {
  bytecode_send (int _num, const char *_name, const char *_str);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

struct bytecode_send_imm : bytecode_elementary {
  bytecode_send_imm (int _num, const char *_name, const char *_str);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

struct bytecode_superoperator : bytecode {
  bytecode *bc1, *bc2;
  int fixed_arg;

  bytecode_superoperator (int _num, int _bc1, int _bc2, int _arg);
};

struct bytecode_with_fixed_arg_1 : bytecode_superoperator {
  bytecode_with_fixed_arg_1 (int _num, int _bc1, int _bc2, int _arg);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

struct bytecode_with_fixed_arg_2 : bytecode_superoperator {
  bytecode_with_fixed_arg_2 (int _num, int _bc1, int _bc2, int _arg);
  void write_byte_def_ext_arg (std::ostream &os, int arg);
  void write_byte_def_fixed_arg (std::ostream &os, int arg);
  void write_byte_def_var_arg (std::ostream &os);
};

void
bytecode::write_byte_def (std::ostream & os)
{
  os << "/* " << str << " */" << std::endl;
  os << num << " {" << std::endl;
  os << "  extract opcode (8), arg_lsb (8);" << std::endl;
  write_byte_def_var_arg (os);
  os << "}" << std::endl << std::endl;
};

bytecode::bytecode (int _num):
  num (_num), str ()
{
  bytecodes[num] = this;
};

bytecode::bytecode (int _num, const char *_str):
  num (_num), str (_str)
{
  bytecodes[num] = this;
};

bytecode_elementary::bytecode_elementary (int _num, const char *_name,
					  const char *_str):
  bytecode (_num, _str), name (_name)
{
};

bytecode_noarg::bytecode_noarg (int _num, const char *_name,
				const char *_str):
  bytecode_elementary (_num, _name, _str)
{
};

void
bytecode_noarg::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  write_byte_def_fixed_arg (os, arg);
}

void
bytecode_noarg::write_byte_def_fixed_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << ';' << std::endl;
}

void
bytecode_noarg::write_byte_def_var_arg (std::ostream & os)
{
  write_byte_def_fixed_arg (os, 0);
}

bytecode_fast_send::bytecode_fast_send (int _num, const char *_name,
					const char *_str):
  bytecode_noarg (_num, _name, _str)
{
};

void
bytecode_fast_send::write_byte_def_fixed_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (" << (num & 15) << ");" << std::endl;
}

bytecode_invalid::bytecode_invalid (int _num):
  bytecode (_num, "invalid bytecode")
{
};

void
bytecode_invalid::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  abort ();
}

void
bytecode_invalid::write_byte_def_fixed_arg (std::ostream & os, int arg)
{
  abort ();
}

void
bytecode_invalid::write_byte_def_var_arg (std::ostream & os)
{
  os << "  dispatch INVALID (" << num << ", arg | arg_lsb);" << std::endl;
}

bytecode_unary::bytecode_unary (int _num, const char *_name,
				const char *_str):
  bytecode_elementary (_num, _name, _str)
{
};

void
bytecode_unary::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (" << (arg << 8) << " | arg_lsb);"
    << std::endl;
}

void
bytecode_unary::write_byte_def_fixed_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (" << arg << ");" << std::endl;
}

void
bytecode_unary::write_byte_def_var_arg (std::ostream & os)
{
  os << "  dispatch " << name << " (arg | arg_lsb);" << std::endl;
}

bytecode_ext::bytecode_ext (int _num, const char *_name, const char *_str):
  bytecode_elementary (_num, _name, _str)
{
};

void
bytecode_ext::write_byte_def (std::ostream & os)
{
  os << "/* " << str << " */" << std::endl;
  os << num << " {" << std::endl;
  os << "  extract opcode (8), arg_lsb (8);" << std::endl;
  write_byte_def_var_arg (os);
  os << "  continue;" << std::endl;
  os << "}" << std::endl << std::endl;
};

void
bytecode_ext::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  write_byte_def_fixed_arg (os, arg);
  write_byte_def_var_arg (os);
}

void
bytecode_ext::write_byte_def_fixed_arg (std::ostream & os, int arg)
{
  os << "  arg = (arg | " << arg << ") << 8);" << std::endl;
}

void
bytecode_ext::write_byte_def_var_arg (std::ostream & os)
{
  os << "  arg = (arg | arg_lsb) << 8;" << std::endl;
}

bytecode_jump::bytecode_jump (int _num, const char *_name, bool minus,
			      const char *_str):
  bytecode_elementary (_num, _name, _str)
{
  sign = minus ? "IP - IP0 - " : "IP - IP0 + ";
}

void
bytecode_jump::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (" << sign << '(' << (arg << 8)
    << " | arg_lsb));" << std::endl;
}

void
bytecode_jump::write_byte_def_fixed_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (" << sign << arg << "));" << std::endl;
}

void
bytecode_jump::write_byte_def_var_arg (std::ostream & os)
{
  os << "  dispatch " << name << " (" << sign << "(arg | arg_lsb));"
    << std::endl;
}

bytecode_binary::bytecode_binary (int _num, const char *_name,
				  const char *_str):
  bytecode_elementary (_num, _name, _str)
{
};

void
bytecode_binary::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (arg | arg_lsb, "
    << arg << ");" << std::endl;
}

void
bytecode_binary::write_byte_def_fixed_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (" << (arg >> 8) << ", "
    << (arg & 255) << ");" << std::endl;
}

void
bytecode_binary::write_byte_def_var_arg (std::ostream & os)
{
  os << "  dispatch " << name << " (arg >> 8, arg_lsb);" << std::endl;
}

bytecode_send::bytecode_send (int _num, const char *_name, const char *_str):
  bytecode_elementary (_num, _name, _str)
{
};

void
bytecode_send::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (arg | arg_lsb, "
    << (num & 1) << ", " << arg << ");" << std::endl;
}

void
bytecode_send::write_byte_def_fixed_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (" << (arg >> 8) << ", "
    << (num & 1) << ", " << (arg & 255) << ");" << std::endl;
}

void
bytecode_send::write_byte_def_var_arg (std::ostream & os)
{
  os << "  dispatch " << name << " (arg >> 8, "
    << (num & 1) << ", arg_lsb);" << std::endl;
}

bytecode_send_imm::bytecode_send_imm (int _num, const char *_name,
				      const char *_str):
  bytecode_elementary (_num, _name, _str)
{
};

void
bytecode_send_imm::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (" << (arg << 8) << " | arg_lsb, "
    << (num & 1) << ");" << std::endl;
}

void
bytecode_send_imm::write_byte_def_fixed_arg (std::ostream & os, int arg)
{
  os << "  dispatch " << name << " (" << arg << ", "
    << (num & 1) << ");" << std::endl;
}

void
bytecode_send_imm::write_byte_def_var_arg (std::ostream & os)
{
  os << "  dispatch " << name << " (arg | arg_lsb, "
    << (num & 1) << ");" << std::endl;
}

bytecode_superoperator::bytecode_superoperator (int _num, int _bc1, int _bc2,
						int _arg):
  bytecode (_num), bc1 (bytecodes[_bc1]), bc2 (bytecodes[_bc2]),
  fixed_arg (_arg)
{
  if (!bc1 || !bc2)
    abort ();
}

bytecode_with_fixed_arg_1::bytecode_with_fixed_arg_1 (int _num, int _bc1,
						      int _bc2, int _arg):
  bytecode_superoperator (_num, _bc1, _bc2, _arg)
{
  std::string::iterator i;
  std::ostringstream os;
  os << _arg;

  str.append (bc1->str);
  str.append ("\n   ");
  str.append (bc2->str);
  for (i = str.begin (); *i != '*'; i++);
  str.replace (i, i + 1, os.str ());
}

void
bytecode_with_fixed_arg_1::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  abort ();
}

void
bytecode_with_fixed_arg_1::write_byte_def_fixed_arg (std::ostream & os,
						     int arg)
{
  bc1->write_byte_def_fixed_arg (os, fixed_arg);
  bc2->write_byte_def_fixed_arg (os, arg);
}

void
bytecode_with_fixed_arg_1::write_byte_def_var_arg (std::ostream & os)
{
  bc1->write_byte_def_fixed_arg (os, fixed_arg);
  bc2->write_byte_def_var_arg (os);
}

bytecode_with_fixed_arg_2::bytecode_with_fixed_arg_2 (int _num, int _bc1,
						      int _bc2, int _arg):
  bytecode_with_fixed_arg_2::bytecode_superoperator (_num, _bc1, _bc2, _arg)
{
  std::string::iterator i;
  std::ostringstream os;
  os << _arg;

  str.append (bc1->str);
  str.append ("\n   ");
  str.append (bc2->str);
  for (i = str.end (); *--i != '*';);
  str.replace (i, i + 1, os.str ());
}

void
bytecode_with_fixed_arg_2::write_byte_def_ext_arg (std::ostream & os, int arg)
{
  abort ();
}

void
bytecode_with_fixed_arg_2::write_byte_def_fixed_arg (std::ostream & os,
						     int arg)
{
  if (bc1 == bytecodes[EXT_BYTE])
    bc2->write_byte_def_fixed_arg (os, (arg << 8) + fixed_arg);
  else
    {
      bc1->write_byte_def_fixed_arg (os, arg);
      bc2->write_byte_def_fixed_arg (os, fixed_arg);
    }
}

void
bytecode_with_fixed_arg_2::write_byte_def_var_arg (std::ostream & os)
{
  if (bc1 == bytecodes[EXT_BYTE])
    bc2->write_byte_def_ext_arg (os, fixed_arg);
  else
    {
      bc1->write_byte_def_var_arg (os);
      bc2->write_byte_def_fixed_arg (os, fixed_arg);
    }
}

bytecode *bytecode::bytecodes[256];

bytecode_fast_send bc0 (0, "SEND_ARITH", "PLUS_SPECIAL(*)");
bytecode_fast_send bc1 (1, "SEND_ARITH", "MINUS_SPECIAL(*)");
bytecode_fast_send bc2 (2, "SEND_ARITH", "LESS_THAN_SPECIAL(*)");
bytecode_fast_send bc3 (3, "SEND_ARITH", "GREATER_THAN_SPECIAL(*)");
bytecode_fast_send bc4 (4, "SEND_ARITH", "LESS_EQUAL_SPECIAL(*)");
bytecode_fast_send bc5 (5, "SEND_ARITH", "GREATER_EQUAL_SPECIAL(*)");
bytecode_fast_send bc6 (6, "SEND_ARITH", "EQUAL_SPECIAL(*)");
bytecode_fast_send bc7 (7, "SEND_ARITH", "NOT_EQUAL_SPECIAL(*)");
bytecode_fast_send bc8 (8, "SEND_ARITH", "TIMES_SPECIAL(*)");
bytecode_fast_send bc9 (9, "SEND_ARITH", "DIVIDE_SPECIAL(*)");
bytecode_fast_send bc10 (10, "SEND_ARITH", "REMAINDER_SPECIAL(*)");
bytecode_fast_send bc11 (11, "SEND_ARITH", "BIT_XOR_SPECIAL(*)");
bytecode_fast_send bc12 (12, "SEND_ARITH", "BIT_SHIFT_SPECIAL(*)");
bytecode_fast_send bc13 (13, "SEND_ARITH", "INTEGER_DIVIDE_SPECIAL(*)");
bytecode_fast_send bc14 (14, "SEND_ARITH", "BIT_AND_SPECIAL(*)");
bytecode_fast_send bc15 (15, "SEND_ARITH", "BIT_OR_SPECIAL(*)");
bytecode_fast_send bc16 (16, "SEND_SPECIAL", "AT_SPECIAL(*)");
bytecode_fast_send bc17 (17, "SEND_SPECIAL", "AT_PUT_SPECIAL(*)");
bytecode_fast_send bc18 (18, "SEND_SPECIAL", "SIZE_SPECIAL(*)");
bytecode_fast_send bc19 (19, "SEND_SPECIAL", "CLASS_SPECIAL(*)");
bytecode_fast_send bc20 (20, "SEND_SPECIAL", "IS_NIL_SPECIAL(*)");
bytecode_fast_send bc21 (21, "SEND_SPECIAL", "NOT_NIL_SPECIAL(*)");
bytecode_fast_send bc22 (22, "SEND_SPECIAL", "VALUE_SPECIAL(*)");
bytecode_fast_send bc23 (23, "SEND_SPECIAL", "VALUE_COLON_SPECIAL(*)");
bytecode_fast_send bc24 (24, "SEND_SPECIAL", "SAME_OBJECT_SPECIAL(*)");
bytecode_fast_send bc25 (25, "SEND_SPECIAL", "JAVA_AS_INT_SPECIAL(*)");
bytecode_fast_send bc26 (26, "SEND_SPECIAL", "JAVA_AS_LONG_SPECIAL(*)");
bytecode_send bc28 (28, "SEND", "SEND(*)");
bytecode_send bc29 (29, "SEND", "SEND_SUPER(*)");
bytecode_send_imm bc30 (30, "SEND_IMMEDIATE", "SEND_IMMEDIATE(*)");
bytecode_send_imm bc31 (31, "SEND_IMMEDIATE", "SEND_SUPER_IMMEDIATE(*)");
bytecode_unary bc32 (32, "PUSH_TEMPORARY_VARIABLE", "PUSH_TEMPORARY_VARIABLE(*)");
bytecode_binary bc33 (33, "PUSH_OUTER_TEMP", "PUSH_OUTER_TEMP(*)");
bytecode_unary bc34 (34, "PUSH_LIT_VARIABLE", "PUSH_LIT_VARIABLE(*)");
bytecode_unary bc35 (35, "PUSH_RECEIVER_VARIABLE", "PUSH_RECEIVER_VARIABLE(*)");
bytecode_unary bc36 (36, "STORE_TEMPORARY_VARIABLE", "STORE_TEMPORARY_VARIABLE(*)");
bytecode_binary bc37 (37, "STORE_OUTER_TEMP", "STORE_OUTER_TEMP(*)");
bytecode_unary bc38 (38, "STORE_LIT_VARIABLE", "STORE_LIT_VARIABLE(*)");
bytecode_unary bc39 (39, "STORE_RECEIVER_VARIABLE", "STORE_RECEIVER_VARIABLE(*)");
bytecode_jump bc40 (40, "JUMP", true, "JUMP_BACK(*)");
bytecode_jump bc41 (41, "JUMP", false, "JUMP(*)");
bytecode_jump bc42 (42, "POP_JUMP_TRUE", false, "POP_JUMP_TRUE(*)");
bytecode_jump bc43 (43, "POP_JUMP_FALSE", false, "POP_JUMP_FALSE(*)");
bytecode_unary bc44 (44, "PUSH_INTEGER", "PUSH_INTEGER(*)");
bytecode_unary bc45 (45, "PUSH_SPECIAL", "PUSH_SPECIAL(*)");
bytecode_unary bc46 (46, "PUSH_LIT_CONSTANT", "PUSH_LIT_CONSTANT(*)");
bytecode_unary bc47 (47, "POP_INTO_NEW_STACKTOP", "POP_INTO_NEW_STACKTOP(*)");
bytecode_noarg bc48 (48, "POP_STACK_TOP", "POP_STACK_TOP(*)");
bytecode_noarg bc49 (49, "MAKE_DIRTY_BLOCK", "MAKE_DIRTY_BLOCK(*)");
bytecode_noarg bc50 (50, "RETURN_METHOD_STACK_TOP", "RETURN_METHOD_STACK_TOP(*)");
bytecode_noarg bc51 (51, "RETURN_CONTEXT_STACK_TOP", "RETURN_CONTEXT_STACK_TOP(*)");
bytecode_noarg bc52 (52, "DUP_STACK_TOP", "DUP_STACK_TOP(*)");
bytecode_noarg bc53 (53, "EXIT_INTERPRETER", "EXIT_INTERPRETER(*)");
bytecode_unary bc54 (54, "LINE_NUMBER_BYTECODE", "LINE_NUMBER_BYTECODE(*)");
bytecode_ext bc55 (55, "EXT_BYTE", "EXT_BYTE(*)");
bytecode_noarg bc56 (56, "PUSH_SELF", "PUSH_SELF(*)");

}

byte_def_builder::byte_def_builder () : fs ("byte.def")
{
  fs << "/* Automatically generated by superops.  Do not modify past this line!  */" << std::endl;
  for (int i = 0; i < 64; i++)
    {
      if (!bytecode::bytecodes[i])
        bytecode::bytecodes[i] = new bytecode_invalid (i);

      bytecode::bytecodes[i]->write_byte_def (fs);
    }
}

byte_def_builder::~byte_def_builder ()
{
  std::cout << "genbc script (recognizer) written to byte.def." << std::endl;
}

void byte_def_builder::with_fixed_arg_1 (int new_bc,
				       int bc1, int arg, int bc2)
{
  bytecode *bc = new bytecode_with_fixed_arg_1 (new_bc, bc1, bc2, arg);
  bc->write_byte_def (fs);

  std::string short_str = bc->str;
  int n;
  while ((n = short_str.find ("\n ")) > -1)
    short_str.replace (n, 3, ",");

  std::cout << short_str << std::endl;
}

void byte_def_builder::with_fixed_arg_2 (int new_bc,
				       int bc1, int bc2, int arg)
{
  bytecode *bc = new bytecode_with_fixed_arg_2 (new_bc, bc1, bc2, arg);

  bc->write_byte_def (fs);

  std::string short_str = bc->str;
  int n;
  while ((n = short_str.find ("\n ")) > -1)
    short_str.replace (n, 3, ",");

  std::cout << short_str << std::endl;
}