diff --git a/compiler/index.js b/compiler/index.js index 8268380c..f6d8045a 100644 --- a/compiler/index.js +++ b/compiler/index.js @@ -4,7 +4,7 @@ import render from './render.js'; import './prefs.js'; const fs = (typeof process?.version !== 'undefined' ? (await import('node:fs')) : undefined); -const { execSync, spawn } = (typeof process?.version !== 'undefined' ? (await import('node:child_process')) : {}); +const { execSync } = (typeof process?.version !== 'undefined' ? (await import('node:child_process')) : {}); const uwebsockets = (typeof process?.version !== 'undefined' ? (await import('./uwebsockets.js')) : undefined); const formatTime = ms => ms >= 60_000 ? `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1000)}s` : ms >= 1000 ? `${(ms / 1000).toFixed(1)}s` : `${ms.toFixed(0)}ms`; @@ -13,7 +13,6 @@ const formatSize = bytes => bytes >= 1_000_000 ? `${(bytes / 1_000_000).toFixed( let progressLines = 0, progressInterval; let spinner = ['-', '\\', '|', '/'], spin = 0; const progressStart = msg => { - if (globalThis.onProgress) return; if (!process.stdout.isTTY) return; const log = (extra, after) => { @@ -22,13 +21,10 @@ const progressStart = msg => { }; log(); - globalThis.progress = log; // selfhosted timers keep the process spinning forever: animate node-hosted only if (process.argv0 === 'node') progressInterval = setInterval(log, 100); }; const progressDone = (msg, start) => { - if (globalThis.onProgress) return globalThis.onProgress(msg, performance.now() - start); - clearInterval(progressInterval); const timeStr = (performance.now() - start).toFixed(0); @@ -36,14 +32,13 @@ const progressDone = (msg, start) => { progressLines++; }; const progressClear = () => { - if (globalThis.onProgress) return; if (!process.stdout.isTTY) return; clearInterval(progressInterval); process.stdout.write(`\u001b[${progressLines}F\u001b[0J`); progressLines = 0; }; -export default (code, module = Prefs.module, run = false) => { +export default (code, module = Prefs.module) => { Prefs.module = module; const optPref = process.argv.find(x => x.startsWith('-O'))?.[2] ?? Prefs.O; @@ -61,17 +56,18 @@ export default (code, module = Prefs.module, run = false) => { if (logProgress) progressDone('parsed', t0); // --parse-only: stop after parsing - if (Prefs.parseOnly) return { program }; + if (Prefs.parseOnly) return; if (logProgress) progressStart('generating IR...'); const t1 = performance.now(); const cg = codegen(program); - if (globalThis.compileCallback) globalThis.compileCallback(cg); - cg.times = [ t0, t1, performance.now() ]; if (logProgress) progressDone('generated IR', t1); - if (globalThis.precompile) return cg; + if (globalThis.precompile) { + cg.times = [ t0, t1, performance.now() ]; + return cg; + } if (logProgress) progressStart('rendering C...'); const t4 = performance.now(); @@ -90,12 +86,12 @@ export default (code, module = Prefs.module, run = false) => { if (logProgress) { const total = performance.now(); progressClear(); - if (!outFile) return cg; + if (!outFile) return; const detail = Prefs.nativeFetch ? 'C bundle' : formatSize(fs.statSync(outFile).size); console.log(`\u001b[2m[${formatTime(total)}]\u001b[0m \u001b[32mcompiled ${globalThis.file} \u001b[90m->\u001b[0m \u001b[92m${outFile}\u001b[90m (${detail})\u001b[0m`); } - return cg; + return; } if (target === 'native') { @@ -229,8 +225,6 @@ export default (code, module = Prefs.module, run = false) => { console.log(`\u001b[2m[${formatTime(total)}]\u001b[0m \u001b[32mcompiled ${globalThis.file} \u001b[90m->\u001b[0m \u001b[92m${outFile}\u001b[90m (${formatSize(fs.statSync(outFile).size)})\u001b[0m`); } - return cg; + return; } - - return cg; }; diff --git a/runtime/index.js b/runtime/index.js index c9726505..865e777f 100644 --- a/runtime/index.js +++ b/runtime/index.js @@ -151,11 +151,7 @@ entrypoint: { if ((Prefs.target === 'c' || Prefs.target === 'native') && DEFAULT_EXPORT_PATTERN.test(source) && source.includes('fetch')) { (await import('./native-fetch.js')).default(inputFile, source); } else { - const result = (await import('../compiler/index.js')).default(source, Prefs.module ?? looksLikeModule(inputFile, source), runAfterCompile); - if (result?.runStatus != null) { - runAfterCompile = false; - runStatus = result.runStatus; - } + (await import('../compiler/index.js')).default(source, Prefs.module ?? looksLikeModule(inputFile, source)); } if (runAfterCompile) { diff --git a/selfhosted/build.mjs b/selfhosted/build.mjs index 2c2518a6..6adfbd10 100644 --- a/selfhosted/build.mjs +++ b/selfhosted/build.mjs @@ -21,9 +21,8 @@ export const renameSync = fs.renameSync; export const symlinkSync = fs.symlinkSync; export const cpSync = fs.cpSync; export default fs;` ], - [ 'node:child_process', `export const execSync = globalThis.__porfforNode.child_process.execSync; -export const execFileSync = globalThis.__porfforNode.child_process.execFileSync; -export const spawn = globalThis.__porfforNode.child_process.spawn;` ], +[ 'node:child_process', `export const execSync = globalThis.__porfforNode.child_process.execSync; +export const execFileSync = globalThis.__porfforNode.child_process.execFileSync;` ], [ 'node:path', `const normalizeParts = parts => { const out = []; for (let i = 0; i < parts.length; i++) { @@ -243,7 +242,7 @@ const load = file => { if (file.endsWith('/compiler/index.js')) { source = source.replace(`const fs = (typeof process?.version !== 'undefined' ? (await import('node:fs')) : undefined);`, `const fs = globalThis.__porfforNode.fs;`); - source = source.replace(`const { execSync, spawn } = (typeof process?.version !== 'undefined' ? (await import('node:child_process')) : {});`, `const { execSync, spawn } = globalThis.__porfforNode.child_process;`); + source = source.replace(`const { execSync } = (typeof process?.version !== 'undefined' ? (await import('node:child_process')) : {});`, `const { execSync } = globalThis.__porfforNode.child_process;`); source = `import * as uwebsockets from './uwebsockets.js';\n` + source; source = source.replace(`const uwebsockets = (typeof process?.version !== 'undefined' ? (await import('./uwebsockets.js')) : undefined);`, ``); source = source.replace(`outFile ??= file.split('/').at(-1).split('.')[0];`, `outFile ??= globalThis.file.split('/').at(-1).split('.')[0];`); @@ -702,7 +701,6 @@ var Prefs, argvChanged, Buffer, process, __porfforNode; var version, porfforFile, typedInput, precompile, noi32F64CallConv; var pageSize, _uniqId = 0, funcBodies, precompileI32SignsFor; var importFuncs, importDelta; -var onProgress, progress, compileCallback; `; for (const mod of modules) { @@ -750,10 +748,7 @@ const optimizedGlobals = [ 'funcBodies', 'precompileI32SignsFor', 'importFuncs', - 'importDelta', - 'onProgress', - 'progress', - 'compileCallback' + 'importDelta' ]; for (const name of optimizedGlobals) { output = output.replaceAll(`globalThis.${name}`, name); diff --git a/selfhosted/native.js b/selfhosted/native.js index de98992c..38c37c78 100644 --- a/selfhosted/native.js +++ b/selfhosted/native.js @@ -844,7 +844,6 @@ globalThis.__porfforNode = { }, child_process: { execSync, - execFileSync, - spawn: () => { throw new Error('spawn not implemented'); } + execFileSync } };