Skip to content

Commit

Permalink
Interpreterの型付けを修正 (aiscript-dev#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikasoba authored Aug 20, 2023
1 parent 49e3156 commit b6ca5fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
7 changes: 6 additions & 1 deletion etc/aiscript.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,12 @@ type InfixOperator = '||' | '&&' | '==' | '!=' | '<=' | '>=' | '<' | '>' | '+' |

// @public (undocumented)
export class Interpreter {
constructor(vars: Interpreter['vars'], opts?: Interpreter['opts']);
constructor(vars: Record<string, Value>, opts?: {
in?(q: string): Promise<string>;
out?(value: Value): void;
log?(type: string, params: Record<string, any>): void;
maxStep?: number;
});
// (undocumented)
abort(): void;
// (undocumented)
Expand Down
19 changes: 9 additions & 10 deletions src/interpreter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ const IRQ_RATE = 300;
const IRQ_AT = IRQ_RATE - 1;

export class Interpreter {
private vars: Record<string, Value>;
private opts: {
in?(q: string): Promise<string>;
out?(value: Value): void;
log?(type: string, params: Record<string, any>): void;
maxStep?: number;
};
public stepCount = 0;
private stop = false;
public scope: Scope;
private abortHandlers: (() => void)[] = [];

constructor(vars: Interpreter['vars'], opts?: Interpreter['opts']) {
this.opts = opts ?? {};

constructor(
private vars: Record<string, Value>,
private opts: {
in?(q: string): Promise<string>;
out?(value: Value): void;
log?(type: string, params: Record<string, any>): void;
maxStep?: number;
} = {},
) {
const io = {
print: FN_NATIVE(([v]) => {
expectAny(v);
Expand Down

0 comments on commit b6ca5fc

Please sign in to comment.