-
Notifications
You must be signed in to change notification settings - Fork 113
feat(conductor): Source/JS CSE machine evaluators and plugin #2004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Akshay-2007-1
wants to merge
10
commits into
source-academy:master
Choose a base branch
from
Akshay-2007-1:feature/cse-machine-conductor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3a19169
feat(conductor): add Source/JS CSE machine conductor evaluators and p…
Akshay-2007-1 fc280f3
Merge branch 'source-academy:master' into feature/cse-machine-conductor
Akshay-2007-1 fcafa8e
refactor(cse): de-duplicate snapshot schema and plugin using shared p…
Akshay-2007-1 120743e
chore: update conductor dependency from portal link to 0.5.0
Akshay-2007-1 48697ef
chore: replace portal links and deps after yarn install
Akshay-2007-1 0b87c19
fix(lint): remove async from sync collectSnapshots, drop useless cons…
Akshay-2007-1 f74da40
fix(lint): remove unused IRunnerPlugin import from SourceEvaluator1
Akshay-2007-1 6564304
chore: formatting
Akshay-2007-1 2c482e3
fix(conductor): address minor AI review comments
Akshay-2007-1 378b0e6
chore: formatting AGAIN
Akshay-2007-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import alias from '@rollup/plugin-alias'; | ||
| import commonjs from '@rollup/plugin-commonjs'; | ||
| import json from '@rollup/plugin-json'; | ||
| import nodeResolve from '@rollup/plugin-node-resolve'; | ||
| import replace from '@rollup/plugin-replace'; | ||
| import terser from '@rollup/plugin-terser'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import esbuild from 'rollup-plugin-esbuild'; | ||
| import nodePolyfills from 'rollup-plugin-polyfill-node'; | ||
|
|
||
| const EVALUATOR = process.env.EVALUATOR; | ||
| if (!EVALUATOR) { | ||
| throw new Error('EVALUATOR env var must be set. Use scripts/build-evaluators.mjs.'); | ||
| } | ||
|
|
||
| const shim = name => fileURLToPath(new URL(`./scripts/evaluator-shims/${name}`, import.meta.url)); | ||
|
|
||
| // js-slang has a few inline `require('<literal>')` calls inside ES modules that | ||
| // @rollup/plugin-commonjs cannot rewrite (it skips modules its acorn parser rejects as TS). | ||
| // This transform rewrites those static requires into hoisted ESM imports first. | ||
| function rewriteStaticRequires(modules) { | ||
| const pattern = new RegExp(`require\\((['"])(${modules.join('|')})\\1\\)`, 'g'); | ||
| return { | ||
| name: 'rewrite-static-requires', | ||
| transform(code) { | ||
| if (!pattern.test(code)) return null; | ||
| pattern.lastIndex = 0; | ||
| const imports = new Map(); | ||
| const replaced = code.replace(pattern, (_match, _quote, name) => { | ||
| const local = `__req_${name.replace(/[^a-zA-Z0-9]/g, '_')}`; | ||
| imports.set(name, local); | ||
| return local; | ||
| }); | ||
| const header = [...imports].map(([name, local]) => `import ${local} from '${name}';`).join('\n'); | ||
| return { code: `${header}\n${replaced}`, map: null }; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function plugins() { | ||
| return [ | ||
| rewriteStaticRequires(['acorn-class-fields']), | ||
| replace({ | ||
| preventAssignment: true, | ||
| values: { __EVALUATOR__: EVALUATOR }, | ||
| }), | ||
| alias({ | ||
| entries: [ | ||
| { find: 'path', replacement: shim('path.mjs') }, | ||
| { find: 'inspector', replacement: shim('empty.mjs') }, | ||
| ], | ||
| }), | ||
| esbuild({ target: 'es2020', sourceMap: true }), | ||
| commonjs({ transformMixedEsModules: true }), | ||
| json(), | ||
| nodeResolve({ preferBuiltins: false, browser: true }), | ||
| nodePolyfills(), | ||
| terser({ compress: { dead_code: true, passes: 2 } }), | ||
| ]; | ||
| } | ||
|
|
||
| export default { | ||
| treeshake: { moduleSideEffects: false }, | ||
| input: 'src/conductor/initialise.ts', | ||
| output: { | ||
| file: `dist/${EVALUATOR}.js`, | ||
| format: 'iife', | ||
| name: 'JsSlangWorker', | ||
| sourcemap: true, | ||
| banner: [ | ||
| 'var global = typeof globalThis !== "undefined" ? globalThis : self;', | ||
| 'var process = (typeof globalThis !== "undefined" && globalThis.process) || ' + | ||
| '{ env: { NODE_ENV: "production" }, argv: [], platform: "browser", version: "", ' + | ||
| 'versions: {}, nextTick: function (f) { Promise.resolve().then(f); }, ' + | ||
| 'cwd: function () { return "/"; }, browser: true };', | ||
| ].join('\n'), | ||
| }, | ||
| plugins: plugins(), | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/usr/bin/env node | ||
| import { spawn } from 'node:child_process'; | ||
|
|
||
| // Keep in sync with exports in src/conductor/index.ts. | ||
| const targets = ['SourceEvaluator1', 'JSCseEvaluator3', 'JSCseEvaluator4']; | ||
|
|
||
| function buildTarget(target) { | ||
| console.log(`\nBuilding ${target}...\n`); | ||
| return new Promise((resolve, reject) => { | ||
| const child = spawn( | ||
| process.execPath, | ||
| ['--max-old-space-size=4096', 'node_modules/rollup/dist/bin/rollup', '-c', 'rollup.config.evaluator.mjs'], | ||
| { | ||
| env: { ...process.env, EVALUATOR: target }, | ||
| stdio: 'inherit', | ||
| shell: false, | ||
| }, | ||
| ); | ||
| child.on('close', code => { | ||
| if (code === 0) resolve(); | ||
| else reject(new Error(`Build failed for ${target} (exit ${code})`)); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| for (const target of targets) { | ||
| await buildTarget(target); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export default {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import pathBrowserify from 'path-browserify'; | ||
|
|
||
| const path = pathBrowserify.default ?? pathBrowserify; | ||
|
|
||
| export default path; | ||
| export const posix = path.posix ?? path; | ||
| export const win32 = path.win32 ?? path; | ||
| export const { basename, delimiter, dirname, extname, format, isAbsolute, join, normalize, parse, relative, resolve, sep } = path; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.