@ugo-studio/jspp 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +44 -33
- package/package.json +1 -1
- package/scripts/precompile-headers.ts +9 -7
- package/src/prelude/index.hpp +0 -5
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
+
import { spawn } from "child_process";
|
|
2
3
|
import fs from "fs/promises";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import pkg from "../package.json";
|
|
@@ -7,6 +8,7 @@ import { COLORS } from "./cli-utils/colors";
|
|
|
7
8
|
import { getLatestMtime } from "./cli-utils/file-utils";
|
|
8
9
|
import { Spinner } from "./cli-utils/spinner";
|
|
9
10
|
import { Interpreter } from "./index";
|
|
11
|
+
const pkgDir = path.dirname(__dirname);
|
|
10
12
|
async function main() {
|
|
11
13
|
const { jsFilePath, isRelease, keepCpp, outputExePath, scriptArgs } = parseArgs(process.argv.slice(2));
|
|
12
14
|
const jsFileName = path.basename(jsFilePath, ".js");
|
|
@@ -26,13 +28,11 @@ async function main() {
|
|
|
26
28
|
const mode = isRelease ? "release" : "debug";
|
|
27
29
|
console.log(`${COLORS.bold}JSPP Compiler${COLORS.reset} ${COLORS.dim}v${pkg.version}${COLORS.reset}`);
|
|
28
30
|
console.log(`Mode: ${isRelease ? COLORS.green : COLORS.yellow}${mode.toUpperCase()}${COLORS.reset}\n`);
|
|
29
|
-
const flags = isRelease
|
|
30
|
-
? ["-O3", "-DNDEBUG"]
|
|
31
|
-
: ["-O0"];
|
|
31
|
+
const flags = isRelease ? ["-O3", "-DNDEBUG"] : ["-O0"];
|
|
32
32
|
if (process.platform === "win32") {
|
|
33
33
|
flags.push("-Wa,-mbig-obj");
|
|
34
34
|
}
|
|
35
|
-
const pchDir = path.resolve(
|
|
35
|
+
const pchDir = path.resolve(pkgDir, "prelude-build", mode);
|
|
36
36
|
const spinner = new Spinner("Initializing...");
|
|
37
37
|
try {
|
|
38
38
|
spinner.start();
|
|
@@ -44,7 +44,7 @@ async function main() {
|
|
|
44
44
|
const { cppCode, preludePath } = interpreter.interpret(jsCode);
|
|
45
45
|
// Ensure directory for cpp file exists (should exist as it's source dir, but for safety if we change logic)
|
|
46
46
|
await fs.mkdir(path.dirname(cppFilePath), { recursive: true });
|
|
47
|
-
|
|
47
|
+
await fs.writeFile(cppFilePath, cppCode);
|
|
48
48
|
spinner.succeed(`Generated cpp`);
|
|
49
49
|
// 2. Precompiled Header Check
|
|
50
50
|
spinner.text = "Checking precompiled headers...";
|
|
@@ -64,14 +64,22 @@ async function main() {
|
|
|
64
64
|
if (shouldRebuild) {
|
|
65
65
|
spinner.update("Rebuilding precompiled headers (this may take a while)...");
|
|
66
66
|
// Use spawn (async) instead of spawnSync to keep spinner alive
|
|
67
|
-
const rebuild =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const rebuild = spawn("bun", [
|
|
68
|
+
"run",
|
|
69
|
+
"scripts/precompile-headers.ts",
|
|
70
|
+
], {
|
|
71
|
+
cwd: pkgDir,
|
|
72
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
73
|
+
});
|
|
74
|
+
const stderrChunks = [];
|
|
75
|
+
if (rebuild.stderr) {
|
|
76
|
+
rebuild.stderr.on("data", (chunk) => stderrChunks.push(chunk));
|
|
77
|
+
}
|
|
78
|
+
const exitCode = await new Promise((resolve) => {
|
|
79
|
+
rebuild.on("close", (code) => resolve(code ?? 1));
|
|
71
80
|
});
|
|
72
|
-
const exitCode = await rebuild.exited;
|
|
73
81
|
if (exitCode !== 0) {
|
|
74
|
-
const stderr =
|
|
82
|
+
const stderr = Buffer.concat(stderrChunks).toString();
|
|
75
83
|
spinner.fail("Failed to rebuild precompiled headers");
|
|
76
84
|
console.error(stderr);
|
|
77
85
|
process.exit(1);
|
|
@@ -86,25 +94,28 @@ async function main() {
|
|
|
86
94
|
spinner.start();
|
|
87
95
|
// Ensure output directory exists
|
|
88
96
|
await fs.mkdir(path.dirname(exeFilePath), { recursive: true });
|
|
89
|
-
const compile =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
const compile = spawn("g++", [
|
|
98
|
+
"-std=c++23",
|
|
99
|
+
...flags,
|
|
100
|
+
cppFilePath,
|
|
101
|
+
"-o",
|
|
102
|
+
exeFilePath,
|
|
103
|
+
"-I",
|
|
104
|
+
pchDir,
|
|
105
|
+
"-I",
|
|
106
|
+
preludePath,
|
|
107
|
+
], {
|
|
108
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
109
|
+
});
|
|
110
|
+
const compileStderrChunks = [];
|
|
111
|
+
if (compile.stderr) {
|
|
112
|
+
compile.stderr.on("data", (chunk) => compileStderrChunks.push(chunk));
|
|
113
|
+
}
|
|
114
|
+
const compileExitCode = await new Promise((resolve) => {
|
|
115
|
+
compile.on("close", (code) => resolve(code ?? 1));
|
|
104
116
|
});
|
|
105
|
-
const compileExitCode = await compile.exited;
|
|
106
117
|
if (compileExitCode !== 0) {
|
|
107
|
-
const stderr =
|
|
118
|
+
const stderr = Buffer.concat(compileStderrChunks).toString();
|
|
108
119
|
spinner.fail(`Compilation failed`);
|
|
109
120
|
console.error(stderr);
|
|
110
121
|
process.exit(1);
|
|
@@ -121,12 +132,12 @@ async function main() {
|
|
|
121
132
|
}
|
|
122
133
|
// 4. Execution Phase
|
|
123
134
|
console.log(`\n${COLORS.cyan}--- Running Output ---${COLORS.reset}`);
|
|
124
|
-
const run =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
const run = spawn(exeFilePath, scriptArgs, {
|
|
136
|
+
stdio: "inherit",
|
|
137
|
+
});
|
|
138
|
+
const runExitCode = await new Promise((resolve) => {
|
|
139
|
+
run.on("close", (code) => resolve(code ?? 1));
|
|
128
140
|
});
|
|
129
|
-
const runExitCode = await run.exited;
|
|
130
141
|
console.log(`${COLORS.cyan}----------------------${COLORS.reset}\n`);
|
|
131
142
|
if (runExitCode !== 0) {
|
|
132
143
|
console.error(`${COLORS.red}Execution failed with exit code ${runExitCode}${COLORS.reset}`);
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawnSync } from "child_process";
|
|
1
2
|
import fs from "fs/promises";
|
|
2
3
|
import path from "path";
|
|
3
4
|
|
|
@@ -76,9 +77,9 @@ async function precompileHeaders() {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
console.log(`[${mode.name.toUpperCase()}] Compiling header...`);
|
|
79
|
-
const compile =
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const compile = spawnSync(
|
|
81
|
+
"g++",
|
|
82
|
+
[
|
|
82
83
|
"-x",
|
|
83
84
|
"c++-header",
|
|
84
85
|
"-std=c++23",
|
|
@@ -89,11 +90,12 @@ async function precompileHeaders() {
|
|
|
89
90
|
"-I",
|
|
90
91
|
PRELUDE_DIR,
|
|
91
92
|
],
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
{
|
|
94
|
+
stdio: "inherit",
|
|
95
|
+
}
|
|
96
|
+
);
|
|
95
97
|
|
|
96
|
-
if (compile.
|
|
98
|
+
if (compile.status !== 0) {
|
|
97
99
|
console.error(
|
|
98
100
|
`[${mode.name.toUpperCase()}] Failed to precompile headers.`,
|
|
99
101
|
);
|
package/src/prelude/index.hpp
CHANGED
|
@@ -7,13 +7,8 @@
|
|
|
7
7
|
#include "values/shape.hpp"
|
|
8
8
|
#include "values/symbol.hpp"
|
|
9
9
|
#include "values/non_values.hpp"
|
|
10
|
-
// #include "any_value.hpp"
|
|
11
|
-
// #include "values/object.hpp"
|
|
12
|
-
// #include "values/array.hpp"
|
|
13
|
-
// #include "values/function.hpp"
|
|
14
10
|
#include "values/iterator.hpp"
|
|
15
11
|
#include "values/async_iterator.hpp"
|
|
16
|
-
// #include "values/promise.hpp"
|
|
17
12
|
#include "values/string.hpp"
|
|
18
13
|
|
|
19
14
|
#include "any_value.hpp"
|