History

ensure function return now accounts for return type size

Ge Wang committed 3 years ago

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

Unified · Split

3 files
  1. src/core/chuck_emit.cpp +12 −7
  2. src/core/chuck_instr.cpp +17 −0
  3. src/core/chuck_instr.h +17 −0
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)
src/core/chuck_instr.cpp+17−0
@@ -2041,6 +2041,23 @@ void Chuck_Instr_Reg_Push_Imm4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) · 2040 unmodified lines
2041 2041
2042 2042
2043 2043
2044//-----------------------------------------------------------------------------
2045// name: execute()
2046// desc: ...
2047//-----------------------------------------------------------------------------
2048void Chuck_Instr_Reg_Push_Zero::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
2049{
2050 t_CKBYTE *& reg_sp = (t_CKBYTE *&)shred->reg->sp;
2051
2052 // push val into reg stack
2053 memset( reg_sp, 0, m_val );
2054 // move stack pointer
2055 reg_sp += m_val;
2056}
2057
2058
2059
2060
2044//-----------------------------------------------------------------------------2061//-----------------------------------------------------------------------------
2045// name: execute()2062// name: execute()
2046// desc: ...2063// desc: ...
src/core/chuck_instr.h+17−0
@@ -2017,6 +2017,23 @@ protected: · 2016 unmodified lines
2017 2017
2018 2018
2019 2019
2020//-----------------------------------------------------------------------------
2021// name: struct Chuck_Instr_Reg_Push_Zero
2022// desc: push immediate value 0 to reg stack with specific width
2023//-----------------------------------------------------------------------------
2024struct Chuck_Instr_Reg_Push_Zero : public Chuck_Instr_Unary_Op
2025{
2026public:
2027 Chuck_Instr_Reg_Push_Zero( t_CKUINT sizeInBytes )
2028 { this->set( sizeInBytes ); }
2029
2030public:
2031 virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
2032};
2033
2034
2035
2036
2020//-----------------------------------------------------------------------------2037//-----------------------------------------------------------------------------
2021// name: struct Chuck_Instr_Reg_Dup_Last2038// name: struct Chuck_Instr_Reg_Dup_Last
2022// desc: duplicate last value on reg stack2039// desc: duplicate last value on reg stack

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