|
|
@ -34,10 +34,11 @@ module.exports = {
|
|
|
|
instruction: instruction
|
|
|
|
instruction: instruction
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Internal: (generator) => {
|
|
|
|
Internal: (generator, name) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
__yieldcoreInternal: true,
|
|
|
|
__yieldcoreInternal: true,
|
|
|
|
generator: generator
|
|
|
|
generator: generator,
|
|
|
|
|
|
|
|
name: name
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// FIXME: propagate NotEnoughInput, handle in custom handler as a retry
|
|
|
|
// FIXME: propagate NotEnoughInput, handle in custom handler as a retry
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -73,16 +74,18 @@ module.exports = {
|
|
|
|
instruction: instruction,
|
|
|
|
instruction: instruction,
|
|
|
|
generator: instruction(),
|
|
|
|
generator: instruction(),
|
|
|
|
done: false,
|
|
|
|
done: false,
|
|
|
|
value: undefined
|
|
|
|
value: undefined,
|
|
|
|
|
|
|
|
name: undefined
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function insertInternalInstruction(generator) {
|
|
|
|
function insertInternalInstruction(generator, name) {
|
|
|
|
increaseStack({
|
|
|
|
increaseStack({
|
|
|
|
instruction: "internal",
|
|
|
|
instruction: "internal",
|
|
|
|
generator: generator,
|
|
|
|
generator: generator,
|
|
|
|
done: false,
|
|
|
|
done: false,
|
|
|
|
value: undefined
|
|
|
|
value: undefined,
|
|
|
|
|
|
|
|
name: name // TODO: Rename this to `tag` or something instead? Doesn't have to be a name string
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -90,7 +93,6 @@ module.exports = {
|
|
|
|
while (finished === false && running === true) {
|
|
|
|
while (finished === false && running === true) {
|
|
|
|
if (currentFrame.done === true) {
|
|
|
|
if (currentFrame.done === true) {
|
|
|
|
// This is a previously completed frame; it doesn't need any further processing
|
|
|
|
// This is a previously completed frame; it doesn't need any further processing
|
|
|
|
// console.log(`deferred-decreasing stack for ${currentFrame.instruction} with`, currentFrame.value);
|
|
|
|
|
|
|
|
decreaseStack(currentFrame.value);
|
|
|
|
decreaseStack(currentFrame.value);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// FIXME: Catch
|
|
|
|
// FIXME: Catch
|
|
|
@ -103,13 +105,11 @@ module.exports = {
|
|
|
|
currentFrame.value = result.value;
|
|
|
|
currentFrame.value = result.value;
|
|
|
|
|
|
|
|
|
|
|
|
let lastFrame = currentFrame;
|
|
|
|
let lastFrame = currentFrame;
|
|
|
|
// console.log(`decreasing stack for ${currentFrame.instruction} with`, result.value);
|
|
|
|
|
|
|
|
decreaseStack(result.value);
|
|
|
|
decreaseStack(result.value);
|
|
|
|
|
|
|
|
|
|
|
|
if (onReturn != null && lastFrame.instruction !== "internal") {
|
|
|
|
if (onReturn != null && lastFrame.instruction !== "internal") {
|
|
|
|
insertInternalInstruction(onReturn(result.value, lastFrame, stack));
|
|
|
|
insertInternalInstruction(onReturn(result.value, lastFrame, stack), "_onReturn");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// console.log(`setting action (no-onReturn) to ${result.value}`);
|
|
|
|
|
|
|
|
action = result.value;
|
|
|
|
action = result.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (isGenerator(result.value)) {
|
|
|
|
} else if (isGenerator(result.value)) {
|
|
|
@ -122,19 +122,17 @@ module.exports = {
|
|
|
|
insertInstruction(result.value);
|
|
|
|
insertInstruction(result.value);
|
|
|
|
continue; // Proceed with the next cycle immediately
|
|
|
|
continue; // Proceed with the next cycle immediately
|
|
|
|
} else if (isPromise(result.value)) {
|
|
|
|
} else if (isPromise(result.value)) {
|
|
|
|
// console.log(`setting action (promise) to ${result.value}`);
|
|
|
|
|
|
|
|
action = await result.value;
|
|
|
|
action = await result.value;
|
|
|
|
} else if (result.value === Pause) {
|
|
|
|
} else if (result.value === Pause) {
|
|
|
|
running = false;
|
|
|
|
running = false;
|
|
|
|
} else if (result.value?.__yieldcoreInternal === true) {
|
|
|
|
} else if (result.value?.__yieldcoreInternal === true) {
|
|
|
|
insertInternalInstruction(result.value);
|
|
|
|
insertInternalInstruction(result.value.generator, result.value.name);
|
|
|
|
continue; // FIXME: Is this correct?
|
|
|
|
continue; // FIXME: Is this correct?
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (onYieldInstruction != null && currentFrame.instruction !== "internal") {
|
|
|
|
if (onYieldInstruction != null) {
|
|
|
|
insertInternalInstruction(onYieldInstruction(result.value, currentFrame, stack));
|
|
|
|
insertInternalInstruction(onYieldInstruction(result.value, currentFrame, stack), "_onYieldInstruction");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// TODO: Is there ever a good reason not to have an onYieldInstruction handler? Should we just disallow that case?
|
|
|
|
// TODO: Is there ever a good reason not to have an onYieldInstruction handler? Should we just disallow that case?
|
|
|
|
// console.log(`setting action (no-onYield) to ${result.value}`);
|
|
|
|
|
|
|
|
action = result.value;
|
|
|
|
action = result.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|