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
//! ## `insc.rs`: defines instruction set for the VM.

use std::ptr::NonNull;

use crate::data::generic::{GenericTypeCtor, GenericTypeVT};
use crate::data::tyck::TyckInfo;

/// An VM instruction
///
/// This is a tri-address like instruction set for register machine.
#[cfg_attr(test, derive(Debug), derive(VariantCount))]
pub enum Insc {
    /// `ADD-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Add integers in register `SRC1` and `SRC2`, put result to register `DEST`,
    /// **No type checking.**
    AddInt(usize, usize, usize),

    /// `ADD-FLOAT [FLOAT@SRC1] [FLOAT@SRC2] [DEST]`
    ///
    /// Add floats in register `SRC1` and `SRC2`, put result to register `DEST`,
    /// **No type checking.**
    AddFloat(usize, usize, usize),

    /// `ADD-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Load numbers in register `SRC1` and `SRC2`, **check types at run time** and perform
    /// appropriate addition calculation accordingly, and put result to register `DEST`.
    AddAny(usize, usize, usize),

    /// `INCR [INT@POS]`
    ///
    /// Increment the integer stored in register `POS`, in place. **No type checking.**
    IncrInt(usize),

    /// `DECR [INT@POS]`
    ///
    /// Decrement the integer stored in register `POS`, in place. **No type checking.**
    DecrInt(usize),

    /// `SUB-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Subtract integers in register `SRC1` and `SRC2`, put result to register `DEST`,
    /// **No type checking.**
    SubInt(usize, usize, usize),

    /// `SUB-FLOAT [FLOAT@SRC1] [FLOAT@SRC1] [DEST]`
    ///
    /// Subtract floats in register `SRC1` and `SRC2`, put result to register `DEST`,
    /// **No type checking.**
    SubFloat(usize, usize, usize),

    /// `SUB-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Load numbers in register `SRC1` and `SRC2`, **check types at run time** and perform
    /// appropriate subtraction calculation accordingly, and put result to register `DEST`.
    SubAny(usize, usize, usize),

    /// `MUL-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Multiply integers in register `SRC1` and `SRC2`, put result to register `DEST`,
    /// **No type checking.**
    MulInt(usize, usize, usize),

    /// `MUL-FLOAT [FLOAT@SRC1] [FLOAT@SRC2] [DEST]`
    ///
    /// Multiply floats in register `SRC1` and `SRC2`, put result to register `DEST`,
    /// **No type checking.**
    MulFloat(usize, usize, usize),

    /// `MUL-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Load numbers in register `SRC1` and `SRC2`, **check types at run time** and perform
    /// appropriate multiplication calculation accordingly, and put result to register `DEST`.
    MulAny(usize, usize, usize),

    /// `DIV-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Divide integer in register `SRC1` by integer in register `SRC2`, put result to register
    /// `DEST`, **No type checking.**
    DivInt(usize, usize, usize),

    /// `DIV-FLOAT [FLOAT@SRC1] [FLOAT@SRC2] [DEST]`
    ///
    /// Divide float in register `SRC1` by float in register `SRC2`, put result to register
    /// `DEST`, **No type checking.**
    DivFloat(usize, usize, usize),

    /// `DIV-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Load numbers in register `SRC1` and `SRC2`, **check types at run time** and perform
    /// appropriate division calculation accordingly, and put result to register `DEST`.
    DivAny(usize, usize, usize),

    /// `MOD-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Take the remainder of dividing integer in register `SRC1` by integer in register `SRC2`,
    /// put result to register `DEST`, **No type checking.**.
    ModInt(usize, usize, usize),

    /// `MOD-ANY [FLOAT@SRC1] [FLOAT@SRC2] [DEST]`
    ///
    /// **Check data in both `SRC1` and `SRC2` to be integer**, perform integer remainder operation,
    /// and put result to register `DEST`.
    ModAny(usize, usize, usize),

    /// `EQ-VALUE [VALUE@SRC1] [VALUE@SRC2] [DEST]`
    ///
    /// Assume that `SRC1` and `SRC2` are **values of same type**, check their equality. This
    /// instruction should not be used for float comparison. For comparing float values, use
    /// `EQ-FLOAT`.
    EqValue(usize, usize, usize),

    /// `EQ-REF [REF@SRC1] [REF@SRC2] [DEST]`
    ///
    /// Assume that `SRC1` and `SRC2` are both **references**, check their equality.
    EqRef(usize, usize, usize),

    /// `EQ-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Make no assumptions on `SRC1` and `SRC2`, check their equality.
    EqAny(usize, usize, usize),

    /// `NE-VALUE [VALUE@SRC1] [VALUE@SRC2] [DEST]`
    ///
    /// Similar to `EQ-VALUE` but yields inverted result.
    NeValue(usize, usize, usize),

    /// `NE-REF [REF@SRC1] [REF@SRC2] [DEST]`
    ///
    /// Similar to `EQ-REF` but yields inverted result.
    NeRef(usize, usize, usize),

    /// `NE-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Similar to `EQ-ANY` but yields inverted result.
    NeAny(usize, usize, usize),

    /// `LT-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Check if integer in register `SRC1` is less than integer in register `SRC2`, put the boolean
    /// result to `DEST`. **No type checking.**
    LtInt(usize, usize, usize),

    /// `LT-FLOAT [SRC1] [SRC2] [DEST]`
    ///
    /// Check if float in register `SRC1` is less than float in register `SRC2`, put the boolean
    /// result to `DEST`. **No type checking.**
    LtFloat(usize, usize, usize),

    /// `LT-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Load numbers in register `SRC1` and `SRC2`, **check types at run time** and perform
    /// appropriate less-than comparison accordingly, and put result to register `DEST`.
    LtAny(usize, usize, usize),

    /// `GT-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Similar to `LT-INT` but yields inverted result.
    GtInt(usize, usize, usize),

    /// `GT-FLOAT [SRC1] [SRC2] [DEST]`
    ///
    /// Similar to `LT-FLOAT` but yields inverted result.
    GtFloat(usize, usize, usize),

    /// `GT-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Similar to `LT-ANY` but yields inverted result.
    GtAny(usize, usize, usize),

    /// `LE-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Check if integer in register `SRC1` is less than or equal to integer in register `SRC2`,
    /// put the boolean result to `DEST`. **No type checking.**
    LeInt(usize, usize, usize),

    /// `LE-FLOAT [SRC1] [SRC2] [DEST]`
    ///
    /// Check if float in register `SRC1` is less than or equal to float in register `SRC2`,
    /// put the boolean result to `DEST`. **No type checking.**
    LeFloat(usize, usize, usize),

    /// `LE-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Load numbers in register `SRC1` and `SRC2`, **check types at run time** and perform
    /// appropriate less-than-or-equal-to comparison accordingly, and put result to register `DEST`.
    LeAny(usize, usize, usize),

    /// `GE-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Similar to `LE-INT` but yields inverted result.
    GeInt(usize, usize, usize),

    /// `GE-FLOAT [SRC1] [SRC2] [DEST]`
    ///
    /// Similar to `LE-FLOAT` but yields inverted result.
    GeFloat(usize, usize, usize),

    /// `GE-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// Similar to `LE-ANY` but yields inverted result.
    GeAny(usize, usize, usize),

    /// `BITAND-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Bit-and integers in register `SRC1` and `SRC2`, put result to register `DEST`.
    /// **No type checking.**
    BAndInt(usize, usize, usize),

    /// `BITAND-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// **Check data in both `SRC1` and `SRC2` to be integer**, perform integer bit-and operation,
    /// and put result to register `DEST`.
    BAndAny(usize, usize, usize),

    /// `BITOR-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Bit-or integers in register `SRC1` and `SRC2`, put result to register `DEST`.
    /// **No type checking.**
    BOrInt(usize, usize, usize),

    /// `BITOR-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// **Check data in both `SRC1` and `SRC2` to be integer**, perform integer bit-or operation,
    /// and put result to register `DEST`.
    BOrAny(usize, usize, usize),

    /// `BITXOR-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Bit-xor integers in register `SRC1` and `SRC2`, put result to register `DEST`.
    /// **No type checking.**
    BXorInt(usize, usize, usize),

    /// `BITXOR-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// **Check data in both `SRC1` and `SRC2` to be integer**, perform integer bit-xor operation,
    /// and put result to register `DEST`.
    BXorAny(usize, usize, usize),

    /// `BITNOT-INT [SRC] [DEST]`
    ///
    /// Bit-not integer in register `SRC`, put the result to register `DEST`.
    /// **No type checking.**
    BNotInt(usize, usize),

    /// `BITNOT-ANY [SRC] [DEST]`
    ///
    /// **Check data in `SRC` to be integer**, perform integer bit-not operation,
    /// and put result to register `DEST`
    BNotAny(usize, usize),

    /// `NEG-INT [SRC] [DEST]`
    ///
    /// Negate the integer in register `SRC`, put the result to register `DEST`,
    /// **No type checking.**
    NegInt(usize, usize),

    /// `NEG-FLOAT [SRC] [DEST]`
    ///
    /// Negate the float in register `SRC`, put the result to register `DEST`.
    /// **No type checking.**
    NegFloat(usize, usize),

    /// `NEG-ANY [SRC] [DEST]`
    ///
    /// **Check data in `SRC` to be integer**, negate the integer and put the result into register
    /// `DEST`.
    NegAny(usize, usize),

    /// `AND-BOOL [SRC1] [SRC2] [DEST]`
    ///
    /// Logic-and booleans in registers `SRC1` and `SRC2`, put result into register `DEST`.
    /// **No type checking.**
    AndBool(usize, usize, usize),

    /// `AND-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// **Check data in both `SRC1` and `SRC2` to be boolean**, perform boolean logic-and operation,
    /// and put result to register `DEST`.
    AndAny(usize, usize, usize),

    /// `OR-BOOL [SRC1] [SRC2] [DEST]`
    ///
    /// Logic-or booleans in registers `SRC1` and `SRC2`, put result into register `DEST`.
    /// **No type checking.**
    OrBool(usize, usize, usize),

    /// `OR-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// **Check data in both `SRC1` and `SRC2` to be boolean**, perform boolean logic-or operation,
    /// and put result to register `DEST`.
    OrAny(usize, usize, usize),

    /// `NOT-BOOL [SRC] [DEST]`
    ///
    /// Logic negate the float in register `SRC`, put the result to register `DEST`.
    /// **No type checking**.
    NotBool(usize, usize),

    /// `NOT-ANY [SRC] [DEST]`
    ///
    /// **Check data in `SRC` to be boolean**, perform boolean logic negate operation, and put
    /// result to register `DEST`.
    NotAny(usize, usize),

    /// `SHL-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Left shift the integer in register `SRC1` with the integer in register `SRC2`, put result to
    /// register `DEST`, **No type checking.**
    ShlInt(usize, usize, usize),

    /// `SHL-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// **Check data in both `SRC1` and `SRC2` to be integer**, perform the left-shift operation,
    /// and put result to register `DEST`.
    ShlAny(usize, usize, usize),

    /// `SHR-INT [INT@SRC1] [INT@SRC2] [DEST]`
    ///
    /// Right shift the integer in register `SRC1` with the integer in register `SRC2`, put result
    /// to register `DEST`, **No type checking.**
    ShrInt(usize, usize, usize),

    /// `SHR-ANY [SRC1] [SRC2] [DEST]`
    ///
    /// **Check data in both `SRC1` and `SRC2` to be integer**, perform the right-shift operation,
    /// and put result to register `DEST`.
    ShrAny(usize, usize, usize),

    /// `MAKE-INT-CONST [INT-LIT] [DEST]`
    ///
    /// Put the integer literal `LIT` to register `DEST`.
    MakeIntConst(i64, usize),

    /// `MAKE-FLOAT-CONST [FLOAT-LIT] [DEST]`
    ///
    /// Put the float literal `LIT` to register `DEST`.
    MakeFloatConst(f64, usize),

    /// `MAKE-CHAR-CONST [CHAR-LIT] [DEST]`
    ///
    /// Put the char literal `LIT` to register `DEST`.
    MakeCharConst(char, usize),

    /// `MAKE-BOOL-CONST [BOOL-LIT] [DEST]`
    ///
    /// Put the boolean literal `LIT` to register `DEST`.
    MakeBoolConst(bool, usize),

    /// `MAKE-NULL [DEST]`
    ///
    /// Put a `null` literal to register `DEST`.
    MakeNull(usize),

    /// `LOAD-CONST [CONST-ID] [DEST]`
    ///
    /// Load constant `CONST-ID` from constant pool, and put it to register `DEST`.
    LoadConst(usize, usize),

    /// `SAVE-CONST [CONST] [CONST-ID]`
    ///
    /// Save the value in register `CONST` to constant pool location `CONST-ID`. Using this
    /// instruction outside the initialization stage is a logical error. Compiler should
    /// not generate codes in such a way.
    SaveConst(usize, usize),

    /// `CAST-FLOAT-INT [FLOAT@SRC] [DEST]`
    ///
    /// Convert the float in `SRC` to integer, put the result to register `DEST`.
    /// **No type checking.**
    CastFloatInt(usize, usize),

    // TODO: Rust forbids case from `char` to `i64`. Should we use this?
    // CastCharInt(usize, usize),

    /// `CAST-BOOL-INT [BOOL@SRC] [DEST]`
    ///
    /// Convert the boolean value in `SRC` to integer, put the result into register `DEST`.
    /// **No type checking.**
    CastBoolInt(usize, usize),

    /// `CAST-ANY-INT [SRC] [DEST]`
    CastAnyInt(usize, usize),

    CastIntFloat(usize, usize),
    CastAnyFloat(usize, usize),
    CastAnyChar(usize, usize),

    CastIntBool(usize, usize),
    CastAnyBool(usize, usize),

    /// `IS-NULL [SRC] [DEST]`
    ///
    /// Check if data stored in `SRC` is `null`, and save the boolean result to `DEST`.
    IsNull(usize, usize),

    /// `NULL-CHECK [SRC]`
    ///
    /// Similar to `IS-NULL`, but throws null pointer exception instead
    NullCheck(usize),

    /// `TYCK [SRC] [TYCK-INFO]`
    ///
    /// Check if data stored `SRC` satisfies `TYCK-INFO`, throws type checking exception if not.
    TypeCheck(usize, NonNull<TyckInfo>),

    /// `CALL-UNCHECKED [FUNC-ID] [ARGS..] [RETS..]`
    ///
    /// Call the function denoted by `FUNC-ID` with given `ARGS`, store the return values to `RETS`.
    /// **No type checking**.
    Call(usize, Box<[usize]>, Box<[usize]>),

    /// `CALL-PTR [SRC] [ARGS..] [RETS..]`
    ///
    /// Call the function stored in function pointer `SRC` with given `ARGS`, store the return
    /// values to `RETS`. **No type checking**.
    CallPtr(usize, Box<[usize]>, Box<[usize]>),

    /// `CALL-OVERLOAD [OVERLOAD-TBL] [ARGS..] [RETS..]`
    CallOverload(usize, Box<[usize]>, Box<[usize]>),

    /// `RETURN-NOTHING`
    ReturnNothing,

    /// `RETURN-ONE [RETURN-VALUE-LOC]`
    ReturnOne(usize),

    /// `RETURN [RETURN-VALUE-LOCS...]`
    Return(Box<[usize]>),

    /// `FFI-CALL-RTLC [FFI-FUNC-ID] [ARGS..] [RETS..]`
    #[cfg(feature = "optimized-rtlc")]
    FFICallRtlc(usize, Box<[usize]>, Box<[usize]>),

    /// `FFI-CALL [FFI-FUNC-ID] [ARGS..] [RETS..]`
    FFICall(usize, Box<[usize]>, Box<[usize]>),

    /// `FFI-CALL-ASYNC [FUNC-ID] [ARGS..] [RET]`
    ///
    /// Call the async function denoted by `FUNC-ID` with given `ARGS`, store the returned
    /// promise to `RET`. **No type checking**. Please note that when feature `optimized-rtlc`
    /// is enabled, all async FFI calls have RTLC.
    #[cfg(all(feature = "async", feature = "optimized-rtlc"))]
    FFICallAsync(usize, Box<[usize]>, usize),

    /// `AWAIT [FUT] [RETS..]`
    ///
    /// Await the given promise, store its results into given destinations.
    #[cfg(feature = "async")]
    Await(usize, Box<[usize]>),

    /// `RAISE [EXCEPTION]`
    Raise(usize),

    JumpIfTrue(usize, usize),
    JumpIfFalse(usize, usize),
    Jump(usize),

    CreateString(usize),
    CreateObject(usize),
    CreateContainer(GenericTypeCtor, NonNull<GenericTypeVT>, usize),

    VecIndex(usize, usize, usize),
    VecIndexPut(usize, usize, usize),
    VecInsert(usize, usize, usize),
    VecRemove(usize, usize, usize),
    VecLen(usize),
    VecClear(usize),

    DenseVecIndex(usize, usize, usize),
    DenseVecIndexPut(usize, usize, usize),
    DenseVecInsert(usize, usize, usize),
    DenseVecRemove(usize, usize, usize),
    DenseVecLen(usize),
    DenseVecClear(usize),

    StrConcat(usize, usize, usize),
    StrFormat(usize, Box<[usize]>, usize),
    StrLen(usize, usize),
    StrSlice(usize, usize, usize, usize),
    StrEquals(usize, usize),

    ObjectGet(usize, NonNull<str>, usize),
    ObjectGetDyn(usize, usize, usize),

    ObjectPut(usize, NonNull<str>, usize),
    ObjectPutDyn(usize, usize, usize)
}

impl Insc {
    pub unsafe fn unsafe_to_string(&self) -> String {
        match self {
            Insc::AddInt(src1, src2, dst) => format!("%{} = add int %{}, %{}", dst, src1, src2),
            Insc::AddFloat(src1, src2, dst) => format!("%{} = add float %{}, %{}", dst, src1, src2),
            Insc::AddAny(src1, src2, dst) =>format!("%{} = add ? %{}, %{}", dst, src1, src2),
            Insc::SubInt(src1, src2, dst) => format!("%{} = sub int %{}, %{}", dst, src1, src2),
            Insc::EqValue(src1, src2, dst) => format!("%{} = eq value %{}, %{}", dst, src1, src2),
            Insc::EqRef(src1, src2, dst) => format!("%{} = eq ref %{}, %{}", dst, src1, src2),
            Insc::EqAny(src1, src2, dst) => format!("%{} = eq ? %{}, %{}", dst, src1, src2),
            Insc::MakeIntConst(int_const, dst) => format!("%{} = int ${}", dst, int_const),
            Insc::LoadConst(const_id, dst) => format!("%{} = load {}", dst, const_id),
            Insc::SaveConst(src, const_id) => format!("store {}, %{}", const_id, src),
            Insc::Call(func_id, args, rets) => {
                let mut result: String = String::from("[");
                for (i, ret) /*: (usize, &usize)*/ in rets.iter().enumerate() {
                    result.push('%');
                    result.push_str(&ret.to_string());
                    if i != rets.len() - 1 {
                        result.push(',');
                        result.push(' ');
                    }
                }
                result.push_str("] = call F.");
                result.push_str(&func_id.to_string());
                result.push(' ');
                for (i, arg) /*: (usize, &usize)*/ in args.iter().enumerate() {
                    result.push('%');
                    result.push_str(&arg.to_string());
                    if i != args.len() - 1 {
                        result.push(',');
                        result.push(' ');
                    }
                }
                result
            },
            Insc::ReturnNothing => "ret".into(),
            Insc::ReturnOne(ret_value_loc) => format!("ret %{}", ret_value_loc),
            Insc::Return(ret_value_locs) => {
                let mut result: String = String::from("ret ");
                for (i, ret_value_loc) /*: (usize, &usize)*/ in ret_value_locs.iter().enumerate() {
                    result.push('%');
                    result.push_str(&ret_value_loc.to_string());
                    if i != ret_value_locs.len() - 1 {
                        result.push(',');
                        result.push(' ');
                    }
                }
                result
            },
            Insc::CreateObject(dest) => format!("%{} = new object", dest),
            Insc::JumpIfTrue(condition, dest) => format!("if %{} goto L.{}", condition, dest),
            Insc::JumpIfFalse(condition, dest) => format!("if not %{} goto L.{}", condition, dest),
            Insc::Jump(dest) => format!("goto L.{}", dest),
            _ => todo!()
        }
    }
}

#[cfg(test)]
#[cfg_attr(miri, ignore)]
#[test] fn count_instructions() {
    eprintln!(" [pr47::vm::al31f::insc] Insc::VARIANT_COUNT = {}", Insc::VARIANT_COUNT);
}