History

ensure function return now accounts for return type size

Ge Wang committed 3 years ago

Commit 2eec4e71 parent 4b6c7693 files · +46 −7Browse files

Showing the changes to src/core/chuck_emit.cpp (1 of 3 files). Show all

Unified · Split

src/core/chuck_emit.cpp+12−7
@@ -4565,15 +4565,20 @@ t_CKBOOL emit_engine_emit_func_def( Chuck_Emitter * emit, a_Func_Def func_def ) · 4564 unmodified lines
45654565 if( !emit_engine_emit_stmt( emit, func_def->code, FALSE ) )
45664566 return FALSE;
45674567
4568− // added by spencer June 2014 (1.3.5.0)
4569− // ensure return
4568+ // added by spencer June 2014 (1.3.5.0) | ensure return
45704569 if( func_def->ret_type && func_def->ret_type != emit->env->t_void )
45714570 {
4572− emit->append( new Chuck_Instr_Reg_Push_Imm(0) );
4573−
4574− Chuck_Instr_Goto * instr = new Chuck_Instr_Goto( 0 );
4575− emit->append( instr );
4576− emit->code->stack_return.push_back( instr );
4571+ // 1.4.2.1 (ge) | account for differences in return type size
4572+ // push 0 for the width of the return type in question
4573+ emit->append( new Chuck_Instr_Reg_Push_Zero( func_def->ret_type->size ) );
4574+ // previously this pushed 0 as int, regardless of return type size
4575+ // emit->append( new Chuck_Instr_Reg_Push_Imm(0) );
4576+
4577+ // 1.4.2.1 (ge) | commented out this goto...
4578+ // (okay as long as the next instruction is Chuck_Instr_Func_Return...)
4579+ // Chuck_Instr_Goto * instr = new Chuck_Instr_Goto( 0 );
4580+ // emit->append( instr );
4581+ // emit->code->stack_return.push_back( instr );
45774582 }
45784583
45794584 // ge: pop scope (2012 april | added 1.3.0.0)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t