Skip to content

Commit 805933a

Browse files
committed
separately build evaluators for 4 chapters
1 parent a90d26a commit 805933a

File tree

5 files changed

+126
-3
lines changed

5 files changed

+126
-3
lines changed

rollup.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import terser from "@rollup/plugin-terser";
66
import typescript from "@rollup/plugin-typescript";
77
import nodePolyfills from "rollup-plugin-polyfill-node";
88

9-
export default {
9+
export default [1,2,3,4].map(n => ({
1010
plugins: [alias({ entries: [{ find: "path", replacement: "path-browserify" }] }), nodeResolve(), commonjs(), typescript(), json(), nodePolyfills()],
11-
input: "src/evaluator.ts",
11+
input: `src/evaluator${n}.ts`,
1212
output: {
1313
plugins: [terser()],
1414
dir: "dist",
1515
format: "iife",
1616
sourcemap: true,
1717
}
18-
}
18+
}));

src/evaluator1.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { BasicEvaluator } from 'conductor/dist/conductor/runner'
2+
import { IRunnerPlugin } from 'conductor/dist/conductor/runner/types'
3+
import { initialise } from 'conductor/dist/conductor/runner/util'
4+
import { Context, runInContext, createContext } from './index'
5+
import { Value, Chapter, Variant } from './types'
6+
7+
class JsSlangEvaluator extends BasicEvaluator {
8+
private ctx: Context
9+
10+
async evaluateChunk(chunk: string): Promise<void> {
11+
const res = await runInContext(chunk, this.ctx)
12+
if (res.status === 'error') {
13+
console.error(res)
14+
} else {
15+
this.ctx = res.context
16+
if (res.status === 'finished') return res.value
17+
}
18+
}
19+
20+
constructor(conductor: IRunnerPlugin) {
21+
super(conductor)
22+
23+
const rawDisplay = (value: Value, str: string, _externalContext: any) => {
24+
this.conductor.sendOutput((str === undefined ? '' : str + ' ') + String(value))
25+
return value
26+
}
27+
28+
this.ctx = createContext(Chapter.SOURCE_1, Variant.DEFAULT, undefined, [], undefined, {
29+
rawDisplay: rawDisplay,
30+
prompt: rawDisplay,
31+
alert: rawDisplay,
32+
visualiseList: (_v: Value) => {
33+
throw new Error('List visualizer is not enabled')
34+
}
35+
})
36+
37+
console.log('Evaluator initialised!')
38+
}
39+
}
40+
41+
initialise(JsSlangEvaluator)

src/evaluator2.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { BasicEvaluator } from 'conductor/dist/conductor/runner'
2+
import { IRunnerPlugin } from 'conductor/dist/conductor/runner/types'
3+
import { initialise } from 'conductor/dist/conductor/runner/util'
4+
import { Context, runInContext, createContext } from './index'
5+
import { Value, Chapter, Variant } from './types'
6+
7+
class JsSlangEvaluator extends BasicEvaluator {
8+
private ctx: Context
9+
10+
async evaluateChunk(chunk: string): Promise<void> {
11+
const res = await runInContext(chunk, this.ctx)
12+
if (res.status === 'error') {
13+
console.error(res)
14+
} else {
15+
this.ctx = res.context
16+
if (res.status === 'finished') return res.value
17+
}
18+
}
19+
20+
constructor(conductor: IRunnerPlugin) {
21+
super(conductor)
22+
23+
const rawDisplay = (value: Value, str: string, _externalContext: any) => {
24+
this.conductor.sendOutput((str === undefined ? '' : str + ' ') + String(value))
25+
return value
26+
}
27+
28+
this.ctx = createContext(Chapter.SOURCE_2, Variant.DEFAULT, undefined, [], undefined, {
29+
rawDisplay: rawDisplay,
30+
prompt: rawDisplay,
31+
alert: rawDisplay,
32+
visualiseList: (_v: Value) => {
33+
throw new Error('List visualizer is not enabled')
34+
}
35+
})
36+
37+
console.log('Evaluator initialised!')
38+
}
39+
}
40+
41+
initialise(JsSlangEvaluator)

src/evaluator3.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { BasicEvaluator } from 'conductor/dist/conductor/runner'
2+
import { IRunnerPlugin } from 'conductor/dist/conductor/runner/types'
3+
import { initialise } from 'conductor/dist/conductor/runner/util'
4+
import { Context, runInContext, createContext } from './index'
5+
import { Value, Chapter, Variant } from './types'
6+
7+
class JsSlangEvaluator extends BasicEvaluator {
8+
private ctx: Context
9+
10+
async evaluateChunk(chunk: string): Promise<void> {
11+
const res = await runInContext(chunk, this.ctx)
12+
if (res.status === 'error') {
13+
console.error(res)
14+
} else {
15+
this.ctx = res.context
16+
if (res.status === 'finished') return res.value
17+
}
18+
}
19+
20+
constructor(conductor: IRunnerPlugin) {
21+
super(conductor)
22+
23+
const rawDisplay = (value: Value, str: string, _externalContext: any) => {
24+
this.conductor.sendOutput((str === undefined ? '' : str + ' ') + String(value))
25+
return value
26+
}
27+
28+
this.ctx = createContext(Chapter.SOURCE_3, Variant.DEFAULT, undefined, [], undefined, {
29+
rawDisplay: rawDisplay,
30+
prompt: rawDisplay,
31+
alert: rawDisplay,
32+
visualiseList: (_v: Value) => {
33+
throw new Error('List visualizer is not enabled')
34+
}
35+
})
36+
37+
console.log('Evaluator initialised!')
38+
}
39+
}
40+
41+
initialise(JsSlangEvaluator)
File renamed without changes.

0 commit comments

Comments
 (0)