Browse Source

Move compiler/vm.js to util/vm.js

master
Futago-za Ryuu 4 years ago
parent
commit
94ca36469b
  1. 2
      lib/compiler/index.js
  2. 6
      lib/compiler/session.js
  3. 9
      lib/typings/api.d.ts
  4. 13
      lib/typings/modules.d.ts
  5. 2
      lib/util/index.js
  6. 0
      lib/util/vm.js

2
lib/compiler/index.js

@ -13,12 +13,10 @@ const reportUndefinedRules = require( "./passes/report-undefined-rules" );
const inferenceMatchResult = require( "./passes/inference-match-result" );
const Session = require( "./session" );
const util = require( "../util" );
const vm = require( "./vm" );
const compiler = {
Session: Session,
vm: vm,
// Compiler passes.
//

6
lib/compiler/session.js

@ -6,7 +6,7 @@ const ast = require( "../ast" );
const GrammarError = require( "../grammar-error" );
const opcodes = require( "./opcodes" );
const parser = require( "../parser" );
const vm = require( "./vm" );
const util = require( "../util" );
function fatal( message, location ) {
@ -28,7 +28,9 @@ class Session {
this.parser = config.parser || parser;
this.passes = config.passes || {};
this.visitor = config.visitor || ast.visitor;
this.vm = config.vm || vm;
this.vm = config.vm || {
runInContext: util.runInContext
};
if ( typeof config.warn === "function" ) this.warn = config.warn;
if ( typeof config.error === "function" ) this.error = config.error;

9
lib/typings/api.d.ts

@ -325,7 +325,7 @@ declare namespace peg {
}
const build: IVisitorBuilder;
const on: IFor;
const on: IOn;
}
@ -432,12 +432,11 @@ declare namespace peg {
}
interface vm {
interface ISessionVM {
runInContext( code: string, vm$context?: { [ name: string ]: any; } ): any;
}
const vm: vm;
interface ISessionMessageEmitter {
@ -452,7 +451,7 @@ declare namespace peg {
parser?: GeneratedParser<Grammar>;
passes?: IPassesMap;
visitor?: ast.visitor;
vm?: vm;
vm?: ISessionVM;
warn?: ISessionMessageEmitter;
error?: ISessionMessageEmitter;
@ -553,7 +552,7 @@ declare namespace peg {
enforceFastProperties( o: {} ): {};
}
interface util extends IJavaScriptUtils, IObjectUtils {
interface util extends IJavaScriptUtils, IObjectUtils, compiler.ISessionVM {
noop(): void;
convertPasses( stages: IStageMap ): compiler.IPassesMap;

13
lib/typings/modules.d.ts

@ -73,12 +73,6 @@ declare module "pegjs/lib/compiler/session" {
}
declare module "pegjs/lib/compiler/vm" {
export default peg.compiler.vm;
}
declare module "pegjs/lib/compiler/passes/calc-report-failures" {
export default peg.compiler.passes.generate.calcReportFailures;
@ -170,3 +164,10 @@ declare module "pegjs/lib/util/objects" {
export default objects;
}
declare module "pegjs/lib/util/vm" {
const vm: peg.compiler.ISessionVM;
export default vm;
}

2
lib/util/index.js

@ -2,9 +2,11 @@
const js = require( "./js" );
const objects = require( "./objects" );
const vm = require( "./vm" );
objects.extend( exports, js );
objects.extend( exports, objects );
objects.extend( exports, vm );
exports.noop = function noop() { };

0
lib/compiler/vm.js → lib/util/vm.js

Loading…
Cancel
Save