Skip to content

Commit

Permalink
compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyMakesThings committed Sep 30, 2024
1 parent e597ef9 commit ae7f733
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/compiler/irgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class ScriptTreeGenerator {

const [paramNames, _paramIds, _paramDefaults] = paramNamesIdsAndDefaults;
this.script.arguments = paramNames;
this.script.ids = _paramIds; // in an ideal world, we wouldn't have to store these.
}

enableWarp () {
Expand Down Expand Up @@ -796,6 +797,22 @@ class ScriptTreeGenerator {
*/
descendStackedBlock (block) {
switch (block.opcode) {
case 'argument_statement': {
const name = block.fields.VALUE.value;
const index = this.script.arguments.lastIndexOf(name);
const id = this.script.ids[index];
if (index === -1) {
return {
kind: 'noop'
};
}
this.script.yields = true;
return {
kind: 'procedures.statement',
name: name,
id
};
}
case 'control_all_at_once':
// In Unsandboxed, attempts to run the script in 1 frame.
return {
Expand Down Expand Up @@ -1477,9 +1494,16 @@ class ScriptTreeGenerator {
}
}

let substacks = {};

Check failure on line 1497 in src/compiler/irgen.js

View workflow job for this annotation

GitHub Actions / build

'substacks' is never reassigned. Use 'const' instead

Check failure on line 1497 in src/compiler/irgen.js

View workflow job for this annotation

GitHub Actions / build

'substacks' is never reassigned. Use 'const' instead
const args = [];
for (let i = 0; i < paramIds.length; i++) {
let value;

if (paramIds[i].startsWith("SUBSTACK")) {

Check failure on line 1502 in src/compiler/irgen.js

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote

Check failure on line 1502 in src/compiler/irgen.js

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
substacks[paramNames[i]] = this.descendSubstack(block, paramIds[i]);
continue;
}

if (block.inputs[paramIds[i]] && block.inputs[paramIds[i]].block) {
value = this.descendInputOfBlock(block, paramIds[i]);
} else {
Expand All @@ -1495,7 +1519,8 @@ class ScriptTreeGenerator {
kind: 'procedures.call',
code: procedureCode,
variant,
arguments: args
arguments: args,
substacks
};
}

Expand Down
12 changes: 12 additions & 0 deletions src/compiler/jsgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ class JSGenerator {
const procedureCode = node.code;
const procedureVariant = node.variant;
const procedureData = this.ir.procedures[procedureVariant];

if (procedureData.stack === null) {
// TODO still need to evaluate arguments for side effects
return new TypedInput('""', TYPE_STRING);
Expand Down Expand Up @@ -1227,11 +1228,14 @@ class JSGenerator {
const procedureCode = node.code;
const procedureVariant = node.variant;
const procedureData = this.ir.procedures[procedureVariant];
this.substacks = node.substacks;
if (procedureData.stack === null) {
// TODO still need to evaluate arguments
break;
}

this.ir.procedures[procedureVariant].substacks = node.substacks;

const yieldForRecursion = !this.isWarp && procedureCode === this.script.procedureCode;
if (yieldForRecursion) {
this.yieldNotWarp();
Expand All @@ -1254,7 +1258,15 @@ class JSGenerator {
case 'procedures.return':
this.stopScriptAndReturn(this.descendInput(node.value).asSafe());
break;
case 'procedures.statement': {
const procedureVariant = this.script.procedureVariant;
const procedureData = this.ir.procedures[procedureVariant];
const substacks = procedureData.substacks;

this.descendStack(substacks[node.name], new Frame(false));

break;
}
case 'timer.reset':
this.source += 'runtime.ioDevices.clock.resetProjectTimer();\n';
break;
Expand Down

0 comments on commit ae7f733

Please sign in to comment.