@@ -96,12 +96,8 @@ void Disassembler::Dump(VMClass* cl) {
9696 VMSymbol* cname = cl->GetName ();
9797 DebugDump (" %s>>%s = " , cname->GetStdString ().c_str (),
9898 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 );
105101 }
106102}
107103
@@ -154,6 +150,12 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
154150 }
155151
156152 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+ }
157159 case BC_PUSH_LOCAL_0: {
158160 DebugPrint (" local: 0, context: 0\n " );
159161 break ;
@@ -199,11 +201,16 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
199201 if (method != nullptr && printObjects) {
200202 vm_oop_t constant = method->GetConstant (bc_idx);
201203 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+ }
207214 dispatch (constant);
208215 } else {
209216 DebugPrint (" (index: %d)" , bytecodes[bc_idx + 1 ]);
@@ -235,6 +242,15 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
235242 DebugPrint (" local: %d, context: %d\n " , bytecodes[bc_idx + 1 ],
236243 bytecodes[bc_idx + 2 ]);
237244 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 ;
238254 case BC_POP_ARGUMENT:
239255 DebugPrint (" argument: %d, context: %d\n " , bytecodes[bc_idx + 1 ],
240256 bytecodes[bc_idx + 2 ]);
@@ -266,7 +282,8 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
266282 }
267283 break ;
268284 }
269- case BC_SEND: {
285+ case BC_SEND:
286+ case BC_SEND_1: {
270287 if (method != nullptr && printObjects) {
271288 auto * name =
272289 static_cast <VMSymbol*>(method->GetConstant (bc_idx));
@@ -295,12 +312,22 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
295312 case BC_JUMP_ON_TRUE_POP:
296313 case BC_JUMP_ON_FALSE_TOP_NIL:
297314 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:
298320 case BC_JUMP_BACKWARD:
299321 case BC_JUMP2:
300322 case BC_JUMP2_ON_FALSE_POP:
301323 case BC_JUMP2_ON_TRUE_POP:
302324 case BC_JUMP2_ON_FALSE_TOP_NIL:
303325 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:
304331 case BC_JUMP2_BACKWARD: {
305332 uint16_t const offset =
306333 ComputeOffset (bytecodes[bc_idx + 1 ], bytecodes[bc_idx + 2 ]);
@@ -331,6 +358,47 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes,
331358#define BC_1 method->GetBytecode (bc_idx + 1 )
332359#define BC_2 method->GetBytecode (bc_idx + 2 )
333360
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+
334402/* *
335403 * Dump bytecode from the frame running
336404 */
@@ -361,22 +429,30 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
361429 }
362430
363431 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+ }
364438 case BC_HALT: {
365439 DebugPrint (" <halting>\n\n\n " );
366440 break ;
367441 }
368442 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" );
380456 break ;
381457 }
382458 case BC_PUSH_LOCAL: {
@@ -425,21 +501,22 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
425501 DebugPrint (" >\n " );
426502 break ;
427503 }
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+ }
428516 case BC_PUSH_ARGUMENT: {
429517 uint8_t const bc1 = BC_1;
430518 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);
443520 break ;
444521 }
445522 case BC_PUSH_BLOCK: {
@@ -493,14 +570,19 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
493570 break ;
494571 }
495572 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);
504586 break ;
505587 }
506588 case BC_POP_ARGUMENT: {
@@ -535,7 +617,8 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method,
535617 break ;
536618 }
537619 case BC_SUPER_SEND:
538- case BC_SEND: {
620+ case BC_SEND:
621+ case BC_SEND_1: {
539622 auto * sel = static_cast <VMSymbol*>(method->GetConstant (bc_idx));
540623
541624 DebugPrint (" (index: %d) signature: %s (" , BC_1,
0 commit comments