Skip to content

Commit

Permalink
Support custom reporters properly and use procedure state info
Browse files Browse the repository at this point in the history
  • Loading branch information
Tacodiva committed Sep 18, 2023
1 parent edf9018 commit e56d71b
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 99 deletions.
4 changes: 2 additions & 2 deletions src/compiler/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const IRGenerator = require('./irgen');
const { IROptimizer } = require('./iroptimizer');
const JSGenerator = require('./jsgen');

const compile = thread => {
const compile = ( /** @type {import("../engine/thread")} */ thread) => {
const irGenerator = new IRGenerator(thread);
const ir = irGenerator.generate();

Expand All @@ -14,7 +14,7 @@ const compile = thread => {
const procedures = {};
const target = thread.target;

const compileScript = script => {
const compileScript = (/** @type {import("./intermediate").IntermediateScript} */ script) => {
if (script.cachedCompileResult) {
return script.cachedCompileResult;
}
Expand Down
37 changes: 25 additions & 12 deletions src/compiler/intermediate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const log = require('../util/log');
*/
class IntermediateStackBlock {
/**
* @param {import("./enums").StackOpcode} opcode
* @param {Object} inputs
* @param {import("./enums").StackOpcode} opcode
* @param {Object} inputs
* @param {boolean} yields
*/
constructor(opcode, inputs = {}, yields = false) {
Expand All @@ -26,7 +26,7 @@ class IntermediateStackBlock {

/**
* The inputs of this block.
* @type {Object}
* @type {Object}
*/
this.inputs = inputs;

Expand All @@ -36,6 +36,12 @@ class IntermediateStackBlock {
*/
this.yields = yields;

/**
* Should state changes made by this stack block be ignored? Used for testing.
* @type {boolean}
*/
this.ignoreState = false;

/**
* @type {import("./iroptimizer").TypeState?}
*/
Expand Down Expand Up @@ -66,9 +72,9 @@ class IntermediateInput {
}

/**
* @param {InputOpcode} opcode
* @param {InputOpcode} opcode
* @param {InputType} type
* @param {Object} inputs
* @param {Object} inputs
* @param {boolean} yields
*/
constructor(opcode, type, inputs = {}, yields = false) {
Expand Down Expand Up @@ -107,7 +113,7 @@ class IntermediateInput {

/**
* Is the type of this input guaranteed to always be the type at runtime.
* @param {InputType} type
* @param {InputType} type
* @returns {boolean}
*/
isAlwaysType(type) {
Expand All @@ -116,8 +122,8 @@ class IntermediateInput {

/**
* Is it possible for this input to be the type at runtime.
* @param {InputType} type
* @returns
* @param {InputType} type
* @returns
*/
isSometimesType(type) {
return (this.type & type) !== 0;
Expand All @@ -127,7 +133,7 @@ class IntermediateInput {
* Converts this input to a target type.
* If this input is a constant the conversion is performed now, at compile time.
* If the input changes, the conversion is performed at runtime.
* @param {InputType} targetType
* @param {InputType} targetType
* @returns {IntermediateInput} An input with the new type.
*/
toType(targetType) {
Expand Down Expand Up @@ -277,11 +283,18 @@ class IntermediateScript {
*/
this.cachedCompileResult = null;

/**
* Cached result of analysing this script.
* @type {import("./iroptimizer").TypeState|null}
*/
this.cachedAnalysisEndState = null;

/**
* Whether the top block of this script is an executable hat.
* @type {boolean}
*/
this.executableHat = false;

}
}

Expand All @@ -290,9 +303,9 @@ class IntermediateScript {
*/
class IntermediateRepresentation {
/**
*
* @param {IntermediateScript} entry
* @param {Object.<string, IntermediateScript>} procedures
*
* @param {IntermediateScript} entry
* @param {Object.<string, IntermediateScript>} procedures
*/
constructor(entry, procedures) {
/**
Expand Down
Loading

0 comments on commit e56d71b

Please sign in to comment.