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 (3 of 3 files). Show all

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
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)
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
20412041
20422042
20432043
2044+//-----------------------------------------------------------------------------
2045+// name: execute()
2046+// desc: ...
2047+//-----------------------------------------------------------------------------
2048+void 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+
20442061 //-----------------------------------------------------------------------------
20452062 // name: execute()
20462063 // desc: ...
src/core/chuck_instr.h+17−0
@@ -2017,6 +2017,23 @@ protected: · 2016 unmodified lines
20172017
20182018
20192019
2020+//-----------------------------------------------------------------------------
2021+// name: struct Chuck_Instr_Reg_Push_Zero
2022+// desc: push immediate value 0 to reg stack with specific width
2023+//-----------------------------------------------------------------------------
2024+struct Chuck_Instr_Reg_Push_Zero : public Chuck_Instr_Unary_Op
2025+{
2026+public:
2027+ Chuck_Instr_Reg_Push_Zero( t_CKUINT sizeInBytes )
2028+ { this->set( sizeInBytes ); }
2029+
2030+public:
2031+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
2032+};
2033+
2034+
2035+
2036+
20202037 //-----------------------------------------------------------------------------
20212038 // name: struct Chuck_Instr_Reg_Dup_Last
20222039 // 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