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
4565 if( !emit_engine_emit_stmt( emit, func_def->code, FALSE ) )4565 if( !emit_engine_emit_stmt( emit, func_def->code, FALSE ) )
4566 return FALSE;4566 return FALSE;
4567 4567
4568 // added by spencer June 2014 (1.3.5.0)4568 // added by spencer June 2014 (1.3.5.0) | ensure return
4569 // ensure return
4570 if( func_def->ret_type && func_def->ret_type != emit->env->t_void )4569 if( func_def->ret_type && func_def->ret_type != emit->env->t_void )
4571 {4570 {
4572 emit->append( new Chuck_Instr_Reg_Push_Imm(0) );4571 // 1.4.2.1 (ge) | account for differences in return type size
4573 4572 // push 0 for the width of the return type in question
4574 Chuck_Instr_Goto * instr = new Chuck_Instr_Goto( 0 );4573 emit->append( new Chuck_Instr_Reg_Push_Zero( func_def->ret_type->size ) );
4575 emit->append( instr );4574 // previously this pushed 0 as int, regardless of return type size
4576 emit->code->stack_return.push_back( instr );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 );
4577 }4582 }
4578 4583
4579 // ge: pop scope (2012 april | added 1.3.0.0)4584 // 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