feat: stdをインタプリタから分離 by uzmoi · Pull Request #1022 · aiscript-dev/aiscript
Expand Up
@@ -7,16 +7,18 @@
import * as Ast from '../node.js';
import { nodeToJs } from '../utils/node-to-js.js';
import { Scope } from './scope.js';
import { std } from './lib/std.js';
import { RETURN, unWrapRet, BREAK, CONTINUE, assertValue, isControl, type Control, unWrapLabeledBreak } from './control.js';
import { assertNumber, assertString, assertFunction, assertBoolean, assertObject, assertArray, eq, isObject, isArray, expectAny, reprValue, isFunction } from './util.js';
import { NULL, FN_NATIVE, BOOL, NUM, STR, ARR, OBJ, FN, ERROR } from './value.js';
import { getPrimProp } from './primitive-props.js';
import { Variable } from './variable.js';
import { Reference } from './reference.js';
import { stdCore } from './lib/core.js';
import type { JsValue } from './util.js';
import type { Value, VFn, VUserFn } from './value.js';
export { std } from './lib/std.js';
export type LogObject = { scope?: string; var?: string; Expand All @@ -36,12 +38,11 @@ private abortHandlers: (() => void)[] = []; private pauseHandlers: (() => void)[] = []; private unpauseHandlers: (() => void)[] = []; private vars: Record<string, Variable> = {}; private irqRate: number; private irqSleep: () => Promise<void>;
constructor( consts: Record<string, Value>, globals: Record<string, Value>, private opts: { in?(q: string): Promise<string>; out?(value: Value): void; Expand All @@ -67,13 +68,12 @@ }), };
this.vars = Object.fromEntries(Object.entries({ ...consts, ...std, ...io, }).map(([k, v]) => [k, Variable.const(v)]));
this.scope = new Scope([new Map(Object.entries(this.vars))]); this.scope = new Scope([ new Map( Object.entries({ ...globals,...stdCore, ...io }) .map(([k, v]) => [k, Variable.const(v)]), ), ]); this.scope.opts.log = (type, params): void => { switch (type) { case 'add': this.log('var:add', params); break; Expand Down Expand Up @@ -548,7 +548,7 @@
case 'loop': { // eslint-disable-next-line no-constant-condition while (true) {
const v = await this._run(node.statements, scope.createChildScope(), callStack);
if (v.type === 'break') {
if (v.label != null && v.label !== node.label) {
Expand Down
Expand Up
@@ -1081,7 +1081,7 @@
case 'loop': { // eslint-disable-next-line no-constant-condition while (true) {
const v = this._runSync(node.statements, scope.createChildScope(), callStack);
if (v.type === 'break') {
if (v.label != null && v.label !== node.label) {
Expand Down
Expand Up
@@ -1631,7 +1631,7 @@
public pause(): void {
if (this.pausing) return;
let resolve: () => void;
const promise = new Promise<void>(r => { resolve = () => r(); });
this.pausing = { promise, resolve: resolve! };
for (const handler of this.pauseHandlers) {
handler();
Expand Down
export { std } from './lib/std.js';
export type LogObject = { scope?: string; var?: string; Expand All @@ -36,12 +38,11 @@ private abortHandlers: (() => void)[] = []; private pauseHandlers: (() => void)[] = []; private unpauseHandlers: (() => void)[] = []; private vars: Record<string, Variable> = {}; private irqRate: number; private irqSleep: () => Promise<void>;
constructor( consts: Record<string, Value>, globals: Record<string, Value>, private opts: { in?(q: string): Promise<string>; out?(value: Value): void; Expand All @@ -67,13 +68,12 @@ }), };
this.vars = Object.fromEntries(Object.entries({ ...consts, ...std, ...io, }).map(([k, v]) => [k, Variable.const(v)]));
this.scope = new Scope([new Map(Object.entries(this.vars))]); this.scope = new Scope([ new Map( Object.entries({ ...globals,...stdCore, ...io }) .map(([k, v]) => [k, Variable.const(v)]), ), ]); this.scope.opts.log = (type, params): void => { switch (type) { case 'add': this.log('var:add', params); break; Expand Down Expand Up @@ -548,7 +548,7 @@
case 'loop': { // eslint-disable-next-line no-constant-condition while (true) {
Check warning on line 551 in src/interpreter/index.ts
View workflow job for this annotation
GitHub Actions / lint
Unnecessary conditional, value is always truthy
case 'loop': { // eslint-disable-next-line no-constant-condition while (true) {
Check warning on line 1084 in src/interpreter/index.ts
View workflow job for this annotation
GitHub Actions / lint
Unnecessary conditional, value is always truthy
Check warning on line 1634 in src/interpreter/index.ts
View workflow job for this annotation
GitHub Actions / lint
Missing return type on function