Add a condition to builtintMethodYield if the block is empty or not
@@ -210,6 +210,12 @@ func (t *thread) execInstruction(cf *normalCallFrame, i *instruction) {
}
func (t *thread) builtinMethodYield(blockFrame *normalCallFrame, args ...Object) *Pointer {
+ // returns NULL if the block is empty
+ if blockIsEmpty(blockFrame) {
+ st := t.stack.top()
+ st.Target = NULL
+ return st
+ } else {
c := newNormalCallFrame(blockFrame.instructionSet, blockFrame.FileName(), blockFrame.sourceLine)
c.blockFrame = blockFrame
c.ep = blockFrame.ep
@@ -226,6 +232,7 @@ func (t *thread) builtinMethodYield(blockFrame *normalCallFrame, args ...Object)
return t.stack.top()
}
+}
func (t *thread) retrieveBlock(fileName, blockFlag string, sourceLine int) (blockFrame *normalCallFrame) {
var blockName string
@@ -420,3 +427,14 @@ func (t *thread) setErrorObject(receiverPtr, sp int, errorType string, sourceLin
t.sp = sp
panic(err.Message())
}
+
+// Other helper functions ----------------------------------------------
+
+// blockIsEmpty returns true if the block is empty
+func blockIsEmpty(blockFrame *normalCallFrame) bool {
+ if blockFrame.instructionSet.instructions[0].action.name == bytecode.Leave {
+ return true
+ } else {
+ return false
+ }
+}
