@@ -96,12 +96,8 @@ void Disassembler::Dump(VMClass* cl) {
96
96
VMSymbol* cname = cl->GetName ();
97
97
DebugDump (" %s>>%s = " , cname->GetStdString ().c_str (),
98
98
sig->GetStdString ().c_str ());
99
- if (inv->IsPrimitive ()) {
100
- DebugPrint (" <primitive>\n " );
101
- continue ;
102
- }
103
- // output actual method
104
- DumpMethod (static_cast <VMMethod*>(inv), " \t " );
99
+
100
+ inv->Dump (" \t " , true );
105
101
}
106
102
}
107
103
@@ -154,6 +150,12 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
154
150
}
155
151
156
152
switch (bytecode) {
153
+ case BC_PUSH_0:
154
+ case BC_PUSH_1:
155
+ case BC_PUSH_NIL: {
156
+ // no more details to be printed
157
+ break ;
158
+ }
157
159
case BC_PUSH_LOCAL_0: {
158
160
DebugPrint (" local: 0, context: 0\n " );
159
161
break ;
@@ -199,11 +201,16 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
199
201
if (method != nullptr && printObjects) {
200
202
vm_oop_t constant = method->GetConstant (bc_idx);
201
203
VMClass* cl = CLASS_OF (constant);
202
- VMSymbol* cname = cl->GetName ();
203
-
204
- DebugPrint (" (index: %d) value: (%s) " ,
205
- bytecodes[bc_idx + 1 ],
206
- cname->GetStdString ().c_str ());
204
+ if (cl == nullptr ) {
205
+ DebugPrint (" (index: %d) value: (%s) " ,
206
+ bytecodes[bc_idx + 1 ],
207
+ " class==nullptr" );
208
+ } else {
209
+ VMSymbol* cname = cl->GetName ();
210
+ DebugPrint (" (index: %d) value: (%s) " ,
211
+ bytecodes[bc_idx + 1 ],
212
+ cname->GetStdString ().c_str ());
213
+ }
207
214
dispatch (constant);
208
215
} else {
209
216
DebugPrint (" (index: %d)" , bytecodes[bc_idx + 1 ]);
@@ -235,6 +242,15 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
235
242
DebugPrint (" local: %d, context: %d\n " , bytecodes[bc_idx + 1 ],
236
243
bytecodes[bc_idx + 2 ]);
237
244
break ;
245
+ case BC_POP_LOCAL_0:
246
+ DebugPrint (" local: 0, context: 0\n " );
247
+ break ;
248
+ case BC_POP_LOCAL_1:
249
+ DebugPrint (" local: 1, context: 0\n " );
250
+ break ;
251
+ case BC_POP_LOCAL_2:
252
+ DebugPrint (" local: 2, context: 0\n " );
253
+ break ;
238
254
case BC_POP_ARGUMENT:
239
255
DebugPrint (" argument: %d, context: %d\n " , bytecodes[bc_idx + 1 ],
240
256
bytecodes[bc_idx + 2 ]);
@@ -266,7 +282,8 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
266
282
}
267
283
break ;
268
284
}
269
- case BC_SEND: {
285
+ case BC_SEND:
286
+ case BC_SEND_1: {
270
287
if (method != nullptr && printObjects) {
271
288
auto * name =
272
289
static_cast <VMSymbol*>(method->GetConstant (bc_idx));
@@ -295,12 +312,22 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
295
312
case BC_JUMP_ON_TRUE_POP:
296
313
case BC_JUMP_ON_FALSE_TOP_NIL:
297
314
case BC_JUMP_ON_TRUE_TOP_NIL:
315
+ case BC_JUMP_ON_NOT_NIL_POP:
316
+ case BC_JUMP_ON_NIL_POP:
317
+ case BC_JUMP_ON_NOT_NIL_TOP_TOP:
318
+ case BC_JUMP_ON_NIL_TOP_TOP:
319
+ case BC_JUMP_IF_GREATER:
298
320
case BC_JUMP_BACKWARD:
299
321
case BC_JUMP2:
300
322
case BC_JUMP2_ON_FALSE_POP:
301
323
case BC_JUMP2_ON_TRUE_POP:
302
324
case BC_JUMP2_ON_FALSE_TOP_NIL:
303
325
case BC_JUMP2_ON_TRUE_TOP_NIL:
326
+ case BC_JUMP2_ON_NOT_NIL_POP:
327
+ case BC_JUMP2_ON_NIL_POP:
328
+ case BC_JUMP2_ON_NOT_NIL_TOP_TOP:
329
+ case BC_JUMP2_ON_NIL_TOP_TOP:
330
+ case BC_JUMP2_IF_GREATER:
304
331
case BC_JUMP2_BACKWARD: {
305
332
uint16_t const offset =
306
333
ComputeOffset (bytecodes[bc_idx + 1 ], bytecodes[bc_idx + 2 ]);
@@ -331,6 +358,47 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
331
358
#define BC_1 method->GetBytecode (bc_idx + 1 )
332
359
#define BC_2 method->GetBytecode (bc_idx + 2 )
333
360
361
+ void Disassembler::printArgument(uint8_t idx, uint8_t ctx, VMClass* cl,
362
+ VMFrame* frame) {
363
+ vm_oop_t o = frame->GetArgument (idx, ctx);
364
+ DebugPrint (" argument: %d, context: %d" , idx, ctx);
365
+
366
+ if (cl != nullptr ) {
367
+ VMClass* c = CLASS_OF (o);
368
+ VMSymbol* cname = c->GetName ();
369
+
370
+ DebugPrint (" <(%s) " , cname->GetStdString ().c_str ());
371
+ dispatch (o);
372
+ DebugPrint (" >" );
373
+ }
374
+ DebugPrint (" \n " );
375
+ }
376
+
377
+ void Disassembler::printPopLocal (uint8_t idx, uint8_t ctx, VMFrame* frame) {
378
+ vm_oop_t o = frame->GetStackElement (0 );
379
+ VMClass* c = CLASS_OF (o);
380
+ VMSymbol* cname = c->GetName ();
381
+
382
+ DebugPrint (" popped local: %d, context: %d <(%s) " , idx, ctx,
383
+ cname->GetStdString ().c_str ());
384
+ dispatch (o);
385
+ DebugPrint (" >\n " );
386
+ }
387
+
388
+ void Disassembler::printNth (uint8_t idx, VMFrame* frame, const char * op) {
389
+ vm_oop_t o = frame->GetStackElement (idx);
390
+ if (o != nullptr ) {
391
+ VMClass* c = CLASS_OF (o);
392
+ VMSymbol* cname = c->GetName ();
393
+
394
+ DebugPrint (" <to %s: (%s) " , op, cname->GetStdString ().c_str ());
395
+ dispatch (o);
396
+ } else {
397
+ DebugPrint (" <to %s: address: %p" , op, (void *)o);
398
+ }
399
+ DebugPrint (" >\n " );
400
+ }
401
+
334
402
/* *
335
403
* Dump bytecode from the frame running
336
404
*/
@@ -361,22 +429,30 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
361
429
}
362
430
363
431
switch (bc) {
432
+ case BC_PUSH_0:
433
+ case BC_PUSH_1:
434
+ case BC_PUSH_NIL: {
435
+ // no more details to be printed
436
+ break ;
437
+ }
364
438
case BC_HALT: {
365
439
DebugPrint (" <halting>\n\n\n " );
366
440
break ;
367
441
}
368
442
case BC_DUP: {
369
- vm_oop_t o = frame->GetStackElement (0 );
370
- if (o != nullptr ) {
371
- VMClass* c = CLASS_OF (o);
372
- VMSymbol* cname = c->GetName ();
373
-
374
- DebugPrint (" <to dup: (%s) " , cname->GetStdString ().c_str ());
375
- dispatch (o);
376
- } else {
377
- DebugPrint (" <to dup: address: %p" , (void *)o);
378
- }
379
- DebugPrint (" >\n " );
443
+ printNth (0 , frame, " dup" );
444
+ break ;
445
+ }
446
+ case BC_DUP_SECOND: {
447
+ printNth (1 , frame, " dup-second" );
448
+ break ;
449
+ }
450
+ case BC_INC: {
451
+ printNth (0 , frame, " inc" );
452
+ break ;
453
+ }
454
+ case BC_DEC: {
455
+ printNth (0 , frame, " dec" );
380
456
break ;
381
457
}
382
458
case BC_PUSH_LOCAL: {
@@ -425,21 +501,22 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
425
501
DebugPrint (" >\n " );
426
502
break ;
427
503
}
504
+ case BC_PUSH_SELF: {
505
+ printArgument (0 , 0 , cl, frame);
506
+ break ;
507
+ }
508
+ case BC_PUSH_ARG_1: {
509
+ printArgument (1 , 0 , cl, frame);
510
+ break ;
511
+ }
512
+ case BC_PUSH_ARG_2: {
513
+ printArgument (2 , 0 , cl, frame);
514
+ break ;
515
+ }
428
516
case BC_PUSH_ARGUMENT: {
429
517
uint8_t const bc1 = BC_1;
430
518
uint8_t const bc2 = BC_2;
431
- vm_oop_t o = frame->GetArgument (bc1, bc2);
432
- DebugPrint (" argument: %d, context: %d" , bc1, bc2);
433
-
434
- if (cl != nullptr ) {
435
- VMClass* c = CLASS_OF (o);
436
- VMSymbol* cname = c->GetName ();
437
-
438
- DebugPrint (" <(%s) " , cname->GetStdString ().c_str ());
439
- dispatch (o);
440
- DebugPrint (" >" );
441
- }
442
- DebugPrint (" \n " );
519
+ printArgument (bc1, bc2, cl, frame);
443
520
break ;
444
521
}
445
522
case BC_PUSH_BLOCK: {
@@ -493,14 +570,19 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
493
570
break ;
494
571
}
495
572
case BC_POP_LOCAL: {
496
- vm_oop_t o = frame->GetStackElement (0 );
497
- VMClass* c = CLASS_OF (o);
498
- VMSymbol* cname = c->GetName ();
499
-
500
- DebugPrint (" popped local: %d, context: %d <(%s) " , BC_1, BC_2,
501
- cname->GetStdString ().c_str ());
502
- dispatch (o);
503
- DebugPrint (" >\n " );
573
+ printPopLocal (BC_1, BC_2, frame);
574
+ break ;
575
+ }
576
+ case BC_POP_LOCAL_0: {
577
+ printPopLocal (0 , 0 , frame);
578
+ break ;
579
+ }
580
+ case BC_POP_LOCAL_1: {
581
+ printPopLocal (1 , 0 , frame);
582
+ break ;
583
+ }
584
+ case BC_POP_LOCAL_2: {
585
+ printPopLocal (2 , 0 , frame);
504
586
break ;
505
587
}
506
588
case BC_POP_ARGUMENT: {
@@ -535,7 +617,8 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
535
617
break ;
536
618
}
537
619
case BC_SUPER_SEND:
538
- case BC_SEND: {
620
+ case BC_SEND:
621
+ case BC_SEND_1: {
539
622
auto * sel = static_cast <VMSymbol*>(method->GetConstant (bc_idx));
540
623
541
624
DebugPrint (" (index: %d) signature: %s (" , BC_1,
@@ -567,12 +650,22 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
567
650
case BC_JUMP_ON_TRUE_POP:
568
651
case BC_JUMP_ON_FALSE_TOP_NIL:
569
652
case BC_JUMP_ON_TRUE_TOP_NIL:
653
+ case BC_JUMP_ON_NOT_NIL_POP:
654
+ case BC_JUMP_ON_NIL_POP:
655
+ case BC_JUMP_ON_NOT_NIL_TOP_TOP:
656
+ case BC_JUMP_ON_NIL_TOP_TOP:
657
+ case BC_JUMP_IF_GREATER:
570
658
case BC_JUMP_BACKWARD:
571
659
case BC_JUMP2:
572
660
case BC_JUMP2_ON_FALSE_POP:
573
661
case BC_JUMP2_ON_TRUE_POP:
574
662
case BC_JUMP2_ON_FALSE_TOP_NIL:
575
663
case BC_JUMP2_ON_TRUE_TOP_NIL:
664
+ case BC_JUMP2_ON_NOT_NIL_POP:
665
+ case BC_JUMP2_ON_NIL_POP:
666
+ case BC_JUMP2_ON_NOT_NIL_TOP_TOP:
667
+ case BC_JUMP2_ON_NIL_TOP_TOP:
668
+ case BC_JUMP2_IF_GREATER:
576
669
case BC_JUMP2_BACKWARD: {
577
670
uint16_t const offset =
578
671
ComputeOffset (method->GetBytecode (bc_idx + 1 ),
0 commit comments