Skip to content

Commit e56d71b

Browse files
committed
Support custom reporters properly and use procedure state info
1 parent edf9018 commit e56d71b

File tree

3 files changed

+240
-99
lines changed

3 files changed

+240
-99
lines changed

src/compiler/compile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const IRGenerator = require('./irgen');
44
const { IROptimizer } = require('./iroptimizer');
55
const JSGenerator = require('./jsgen');
66

7-
const compile = thread => {
7+
const compile = ( /** @type {import("../engine/thread")} */ thread) => {
88
const irGenerator = new IRGenerator(thread);
99
const ir = irGenerator.generate();
1010

@@ -14,7 +14,7 @@ const compile = thread => {
1414
const procedures = {};
1515
const target = thread.target;
1616

17-
const compileScript = script => {
17+
const compileScript = (/** @type {import("./intermediate").IntermediateScript} */ script) => {
1818
if (script.cachedCompileResult) {
1919
return script.cachedCompileResult;
2020
}

src/compiler/intermediate.js

+25-12
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const log = require('../util/log');
1313
*/
1414
class IntermediateStackBlock {
1515
/**
16-
* @param {import("./enums").StackOpcode} opcode
17-
* @param {Object} inputs
16+
* @param {import("./enums").StackOpcode} opcode
17+
* @param {Object} inputs
1818
* @param {boolean} yields
1919
*/
2020
constructor(opcode, inputs = {}, yields = false) {
@@ -26,7 +26,7 @@ class IntermediateStackBlock {
2626

2727
/**
2828
* The inputs of this block.
29-
* @type {Object}
29+
* @type {Object}
3030
*/
3131
this.inputs = inputs;
3232

@@ -36,6 +36,12 @@ class IntermediateStackBlock {
3636
*/
3737
this.yields = yields;
3838

39+
/**
40+
* Should state changes made by this stack block be ignored? Used for testing.
41+
* @type {boolean}
42+
*/
43+
this.ignoreState = false;
44+
3945
/**
4046
* @type {import("./iroptimizer").TypeState?}
4147
*/
@@ -66,9 +72,9 @@ class IntermediateInput {
6672
}
6773

6874
/**
69-
* @param {InputOpcode} opcode
75+
* @param {InputOpcode} opcode
7076
* @param {InputType} type
71-
* @param {Object} inputs
77+
* @param {Object} inputs
7278
* @param {boolean} yields
7379
*/
7480
constructor(opcode, type, inputs = {}, yields = false) {
@@ -107,7 +113,7 @@ class IntermediateInput {
107113

108114
/**
109115
* Is the type of this input guaranteed to always be the type at runtime.
110-
* @param {InputType} type
116+
* @param {InputType} type
111117
* @returns {boolean}
112118
*/
113119
isAlwaysType(type) {
@@ -116,8 +122,8 @@ class IntermediateInput {
116122

117123
/**
118124
* Is it possible for this input to be the type at runtime.
119-
* @param {InputType} type
120-
* @returns
125+
* @param {InputType} type
126+
* @returns
121127
*/
122128
isSometimesType(type) {
123129
return (this.type & type) !== 0;
@@ -127,7 +133,7 @@ class IntermediateInput {
127133
* Converts this input to a target type.
128134
* If this input is a constant the conversion is performed now, at compile time.
129135
* If the input changes, the conversion is performed at runtime.
130-
* @param {InputType} targetType
136+
* @param {InputType} targetType
131137
* @returns {IntermediateInput} An input with the new type.
132138
*/
133139
toType(targetType) {
@@ -277,11 +283,18 @@ class IntermediateScript {
277283
*/
278284
this.cachedCompileResult = null;
279285

286+
/**
287+
* Cached result of analysing this script.
288+
* @type {import("./iroptimizer").TypeState|null}
289+
*/
290+
this.cachedAnalysisEndState = null;
291+
280292
/**
281293
* Whether the top block of this script is an executable hat.
282294
* @type {boolean}
283295
*/
284296
this.executableHat = false;
297+
285298
}
286299
}
287300

@@ -290,9 +303,9 @@ class IntermediateScript {
290303
*/
291304
class IntermediateRepresentation {
292305
/**
293-
*
294-
* @param {IntermediateScript} entry
295-
* @param {Object.<string, IntermediateScript>} procedures
306+
*
307+
* @param {IntermediateScript} entry
308+
* @param {Object.<string, IntermediateScript>} procedures
296309
*/
297310
constructor(entry, procedures) {
298311
/**

0 commit comments

Comments
 (0)