Changing parsing of custom procedures for new style

This commit is contained in:
Paul Kaplan committed 2017-10-06 16:26:19 -04:00
1 parent e4830dfe51
commit b0870518a4
4 files changed
+31 -11

No files matched your search

+2 -3
View File
@@ -154,7 +154,7 @@ class Blocks {
const block = this._blocks[id];
if ((block.opcode === 'procedures_defnoreturn' ||
block.opcode === 'procedures_defreturn') &&
block.mutation.proccode === name) {
this._blocks[block.inputs.custom_block.block].mutation.proccode === name) {
return id;
}
}
@@ -170,8 +170,7 @@ class Blocks {
for (const id in this._blocks) {
if (!this._blocks.hasOwnProperty(id)) continue;
const block = this._blocks[id];
if ((block.opcode === 'procedures_defnoreturn' ||
block.opcode === 'procedures_defreturn') &&
if (block.opcode === 'procedures_callnoreturn_internal' &&
block.mutation.proccode === name) {
return JSON.parse(block.mutation.argumentnames);
}
+2
View File
@@ -148,6 +148,8 @@ const execute = function (sequencer, thread) {
// Recursively evaluate input blocks.
for (const inputName in inputs) {
if (!inputs.hasOwnProperty(inputName)) continue;
// Do not evaluate the internal custom command block within definition
if (inputName === 'custom_block') continue;
const input = inputs[inputName];
const inputBlockId = input.block;
// Is there no value for this input waiting in the stack frame?
+3 -1
View File
@@ -225,7 +225,9 @@ class Sequencer {
// Look for warp-mode flag on definition, and set the thread
// to warp-mode if needed.
const definitionBlock = thread.target.blocks.getBlock(definition);
const doWarp = definitionBlock.mutation.warp;
const innerBlock = thread.target.blocks.getBlock(
definitionBlock.inputs.custom_block.block);
const doWarp = innerBlock.mutation.warp;
if (doWarp) {
thread.peekStackFrame().warpMode = true;
} else if (isRecursive) {
+24 -7
View File
@@ -481,14 +481,31 @@ const parseBlock = function (sb2block, getVariableId) {
// Mutation for procedure definition:
// store all 2.0 proc data.
const procData = sb2block.slice(1);
activeBlock.mutation = {
tagName: 'mutation',
proccode: procData[0], // e.g., "abc %n %b %s"
argumentnames: JSON.stringify(procData[1]), // e.g. ['arg1', 'arg2']
argumentdefaults: JSON.stringify(procData[2]), // e.g., [1, 'abc']
warp: procData[3], // Warp mode, e.g., true/false.
children: []
// Create a new block and input metadata.
const inputUid = uid();
const inputName = 'custom_block';
activeBlock.inputs[inputName] = {
name: inputName,
block: inputUid,
shadow: inputUid
};
activeBlock.children = [{
id: inputUid,
opcode: 'procedures_callnoreturn_internal',
inputs: {},
fields: {},
next: null,
shadow: true,
children: [],
mutation: {
tagName: 'mutation',
proccode: procData[0], // e.g., "abc %n %b %s"
argumentnames: JSON.stringify(procData[1]), // e.g. ['arg1', 'arg2']
argumentdefaults: JSON.stringify(procData[2]), // e.g., [1, 'abc']
warp: procData[3], // Warp mode, e.g., true/false.
children: []
}
}];
} else if (oldOpcode === 'call') {
// Mutation for procedure call:
// string for proc code (e.g., "abc %n %b %s").