Skip to content

Commit

Permalink
to be continued
Browse files Browse the repository at this point in the history
  • Loading branch information
jwklong authored Sep 10, 2024
1 parent bffe7b1 commit a5cb5f4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/compiler/irgen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const Cast = require('../util/cast');
const StringUtil = require('../util/string-util');
const BlockType = require('../extension-support/block-type');
const Sequencer = require('../engine/sequencer');
const BlockUtility = require('../engine/block-utility');
const Variable = require('../engine/variable');
const Color = require('../util/color');
const log = require('../util/log');
Expand Down Expand Up @@ -69,6 +71,8 @@ class ScriptTreeGenerator {
this.runtime = this.target.runtime;
/** @private */
this.stage = this.runtime.getTargetForStage();
/** @private */
this.util = new BlockUtility(this.runtime.sequencer, this.thread);

/**
* This script's intermediate representation.
Expand Down Expand Up @@ -1575,6 +1579,26 @@ class ScriptTreeGenerator {
param: this.descendInputOfBlock(block, "PARAM"),
val: this.descendInputOfBlock(block, "VALUE")
};
case 'argument_reporter_command': {
const name = block.fields.VALUE.value;
// lastIndexOf because multiple parameters with the same name will use the value of the last definition
const index = this.script.arguments.lastIndexOf(name);
if (index === -1) { return }

const branchInfo = util.getParam(args.VALUE) || {};
if (branchInfo.entry === null) return;
const [branchId, target] = util.getBranchAndTarget(
branchInfo.callerId,
branchInfo.entry
) || [];

return {
kind: 'args.command',
index: index,
branchId: branchId,
target: target
};
}
case 'procedures_call': {
// setting of yields will be handled later in the analysis phase
// patches output previewing
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/jsgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,10 @@ class JSGenerator {
break;
}

case 'args.command':
//TBD
break;

case 'compat': {
// If the last command in a loop returns a promise, immediately continue to the next iteration.
// If you don't do this, the loop effectively yields twice per iteration and will run at half-speed.
Expand Down
14 changes: 14 additions & 0 deletions src/engine/block-utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ class BlockUtility {
this.sequencer.stepToBranch(this.thread, branchNum, isLoop);
}

/**
* Get the branch for a particular C-shaped block, and it's target.
* @param {string} id ID for block to get the branch for.
* @param {string} branchId Which branch to select (e.g. for if-else).
* @return {string} ID of block in the branch.
*/
getBranchAndTarget (id, branchId) {
const result = this.thread.blockContainer.getBranch(id, branchId);
if (result) {
return [result, this.thread.target];
}
return this.sequencer.runtime.getBranchAndTarget(id, branchId);
}

/**
* Stop all threads.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -3649,6 +3649,22 @@ class Runtime extends EventEmitter {
this.emit('targetWasRemoved', target);
}

/**
* Get the branch for a particular C-shaped block, and it's target.
* @param {?string} id ID for block to get the branch for.
* @param {?string} branchId Which branch to select (e.g. for if-else).
* @return {?string} ID of block in the branch.
*/
getBranchAndTarget (id, branchId) {
for (const target of this.targets) {
const result = target.blocks.getBranch(id, branchId);
if (result) {
return [result, target];
}
}
return null;
}

/**
* gets a screen, if no screen can be found it will create one
* @param {string} screen the screen to get
Expand Down

0 comments on commit a5cb5f4

Please sign in to comment.