diff --git a/src/blocks/scratch3_procedures.js b/src/blocks/scratch3_procedures.js index b91630f12..22e2f788f 100644 --- a/src/blocks/scratch3_procedures.js +++ b/src/blocks/scratch3_procedures.js @@ -13,17 +13,18 @@ class Scratch3ProcedureBlocks { */ getPrimitives () { return { - procedures_defnoreturn: this.defNoReturn, - procedures_callnoreturn: this.callNoReturn, - procedures_param: this.param + procedures_definition: this.definition, + procedures_call: this.call, + argument_reporter_string_number: this.param, + argument_reporter_boolean: this.param }; } - defNoReturn () { + definition () { // No-op: execute the blocks. } - callNoReturn (args, util) { + call (args, util) { if (!util.stackFrame.executed) { const procedureCode = args.mutation.proccode; const paramNames = util.getProcedureParamNames(procedureCode); @@ -47,7 +48,7 @@ class Scratch3ProcedureBlocks { } param (args, util) { - const value = util.getParam(args.mutation.paramname); + const value = util.getParam(args.VALUE); return value; } } diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 92a2d58e7..1aa97d28d 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -152,8 +152,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_definition') { const internal = this._getCustomBlockInternal(block); if (internal && internal.mutation.proccode === name) { return id; // The outer define block id @@ -172,7 +171,7 @@ class Blocks { for (const id in this._blocks) { if (!this._blocks.hasOwnProperty(id)) continue; const block = this._blocks[id]; - if (block.opcode === 'procedures_callnoreturn_internal' && + if (block.opcode === 'procedures_prototype' && block.mutation.proccode === name) { return JSON.parse(block.mutation.argumentnames); } diff --git a/src/engine/thread.js b/src/engine/thread.js index 3b8ce32bd..def1fc1ef 100644 --- a/src/engine/thread.js +++ b/src/engine/thread.js @@ -164,7 +164,7 @@ class Thread { let blockID = this.peekStack(); while (blockID !== null) { const block = this.target.blocks.getBlock(blockID); - if (typeof block !== 'undefined' && block.opcode === 'procedures_callnoreturn') { + if (typeof block !== 'undefined' && block.opcode === 'procedures_call') { break; } this.popStack(); @@ -271,7 +271,7 @@ class Thread { const sp = this.stack.length - 1; for (let i = sp - 1; i >= 0; i--) { const block = this.target.blocks.getBlock(this.stack[i]); - if (block.opcode === 'procedures_callnoreturn' && + if (block.opcode === 'procedures_call' && block.mutation.proccode === procedureCode) { return true; } diff --git a/src/serialization/sb2.js b/src/serialization/sb2.js index 2a54d40a7..16b63da88 100644 --- a/src/serialization/sb2.js +++ b/src/serialization/sb2.js @@ -518,7 +518,7 @@ const parseBlock = function (sb2block, getVariableId, extensions) { }; activeBlock.children = [{ id: inputUid, - opcode: 'procedures_callnoreturn_internal', + opcode: 'procedures_prototype', inputs: {}, fields: {}, next: null, @@ -544,13 +544,15 @@ const parseBlock = function (sb2block, getVariableId, extensions) { argumentids: JSON.stringify(parseProcedureArgIds(sb2block[1])) }; } else if (oldOpcode === 'getParam') { - // Mutation for procedure parameter. - activeBlock.mutation = { - tagName: 'mutation', - children: [], - paramname: sb2block[1], // Name of parameter. - shape: sb2block[2] // Shape - in 2.0, 'r' or 'b'. - }; + // Assign correct opcode based on the block shape. + switch (sb2block[2]) { + case 'r': + activeBlock.opcode = 'argument_reporter_string_number'; + break; + case 'b': + activeBlock.opcode = 'argument_reporter_boolean'; + break; + } } return activeBlock; }; diff --git a/src/serialization/sb2_specmap.js b/src/serialization/sb2_specmap.js index b511d59c8..70bb0345c 100644 --- a/src/serialization/sb2_specmap.js +++ b/src/serialization/sb2_specmap.js @@ -1382,15 +1382,21 @@ const specMap = { ] }, 'procDef': { - opcode: 'procedures_defnoreturn', + opcode: 'procedures_definition', argMap: [] }, 'getParam': { - opcode: 'procedures_param', - argMap: [] + // Doesn't map to single opcode. Import step assigns final correct opcode. + opcode: 'argument_reporter_string_number', + argMap: [ + { + type: 'field', + fieldName: 'VALUE' + } + ] }, 'call': { - opcode: 'procedures_callnoreturn', + opcode: 'procedures_call', argMap: [] } }; diff --git a/test/unit/engine_sequencer.js b/test/unit/engine_sequencer.js index abf7102d2..751e9bb64 100644 --- a/test/unit/engine_sequencer.js +++ b/test/unit/engine_sequencer.js @@ -36,7 +36,7 @@ const generateBlock = function (id) { block: 'fakeBlock', name: 'fakeName', next: null, - opcode: 'procedures_defnoreturn', + opcode: 'procedures_definition', mutation: {proccode: 'fakeCode'}, parent: null, shadow: false, @@ -55,7 +55,7 @@ const generateBlockInput = function (id, next, inp) { block: 'fakeBlock', name: 'fakeName', next: next, - opcode: 'procedures_defnoreturn', + opcode: 'procedures_definition', mutation: {proccode: 'fakeCode'}, parent: null, shadow: false, @@ -156,7 +156,7 @@ test('stepToProcedure', t => { th.target.blocks.createBlock({ id: 'internalId', - opcode: 'procedures_callnoreturn_internal', + opcode: 'procedures_prototype', mutation: { proccode: 'othercode' } diff --git a/test/unit/engine_thread.js b/test/unit/engine_thread.js index 60419d360..6c9a9e4f2 100644 --- a/test/unit/engine_thread.js +++ b/test/unit/engine_thread.js @@ -194,7 +194,7 @@ test('stopThisScript', t => { block: 'fakeBlock', name: 'STEPS', next: null, - opcode: 'procedures_callnoreturn', + opcode: 'procedures_call', mutation: {proccode: 'fakeCode'}, parent: null, shadow: false, @@ -246,7 +246,7 @@ test('isRecursiveCall', t => { block: 'fakeBlock', name: 'STEPS', next: null, - opcode: 'procedures_callnoreturn', + opcode: 'procedures_call', mutation: {proccode: 'fakeCode'}, parent: null, shadow: false,