pearc 0.1.0
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/README.md +146 -0
- package/dist/codegen.d.ts +29 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +644 -0
- package/dist/codegen.js.map +1 -0
- package/dist/compiler.d.ts +23 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +370 -0
- package/dist/compiler.js.map +1 -0
- package/dist/decompiler.d.ts +25 -0
- package/dist/decompiler.d.ts.map +1 -0
- package/dist/decompiler.js +294 -0
- package/dist/decompiler.js.map +1 -0
- package/dist/interpreter.d.ts +72 -0
- package/dist/interpreter.d.ts.map +1 -0
- package/dist/interpreter.js +2063 -0
- package/dist/interpreter.js.map +1 -0
- package/dist/lexer.d.ts +125 -0
- package/dist/lexer.d.ts.map +1 -0
- package/dist/lexer.js +563 -0
- package/dist/lexer.js.map +1 -0
- package/dist/mcp-server.d.ts +3 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +228 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/parser.d.ts +307 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +1047 -0
- package/dist/parser.js.map +1 -0
- package/examples/hello.pr +2 -0
- package/examples/pointers.pr +32 -0
- package/examples/structs.pr +6 -0
- package/package.json +40 -0
- package/spec/pear.md +213 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export declare function pearToC(source: string): string;
|
|
3
|
+
export declare function cToPear(cSource: string): string;
|
|
4
|
+
export declare function compileToC(source: string): {
|
|
5
|
+
c: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function compileToBinary(pearSource: string, outputFile: string, options?: {
|
|
9
|
+
compiler?: string;
|
|
10
|
+
flags?: string[];
|
|
11
|
+
}): {
|
|
12
|
+
success: boolean;
|
|
13
|
+
output: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function runInterpreted(pearSource: string, argv?: string[]): number;
|
|
17
|
+
export declare function runPear(pearSource: string, args?: string[], options?: {
|
|
18
|
+
compiler?: string;
|
|
19
|
+
}): {
|
|
20
|
+
exitCode: number;
|
|
21
|
+
error?: string;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":";AAiBA,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAOxE;AAED,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GACpD;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAsFtD;AA8CD,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAE1E;AAED,wBAAgB,OAAO,CACrB,UAAU,EAAE,MAAM,EAClB,IAAI,GAAE,MAAM,EAAO,EACnB,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAClC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CA0BtC"}
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// Pear Language Compiler - Main CLI
|
|
4
|
+
// Usage:
|
|
5
|
+
// pearc <file.pr> → print C output
|
|
6
|
+
// pearc <file.pr> -o <out.c> → write C to file
|
|
7
|
+
// pearc <file.pr> --binary -o <out> → compile to binary via gcc/clang
|
|
8
|
+
// pearc --decompile <file.c> → decompile C to Pear
|
|
9
|
+
// pearc --decompile <file.c> -o <out.pr>
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
+
var ownKeys = function(o) {
|
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
+
var ar = [];
|
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
return ownKeys(o);
|
|
34
|
+
};
|
|
35
|
+
return function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.pearToC = pearToC;
|
|
45
|
+
exports.cToPear = cToPear;
|
|
46
|
+
exports.compileToC = compileToC;
|
|
47
|
+
exports.compileToBinary = compileToBinary;
|
|
48
|
+
exports.runInterpreted = runInterpreted;
|
|
49
|
+
exports.runPear = runPear;
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
52
|
+
const child_process = __importStar(require("child_process"));
|
|
53
|
+
const parser_1 = require("./parser");
|
|
54
|
+
const codegen_1 = require("./codegen");
|
|
55
|
+
const decompiler_1 = require("./decompiler");
|
|
56
|
+
const interpreter_1 = require("./interpreter");
|
|
57
|
+
function pearToC(source) {
|
|
58
|
+
const ast = (0, parser_1.parse)(source);
|
|
59
|
+
return (0, codegen_1.generate)(ast);
|
|
60
|
+
}
|
|
61
|
+
function cToPear(cSource) {
|
|
62
|
+
return (0, decompiler_1.decompile)(cSource);
|
|
63
|
+
}
|
|
64
|
+
function compileToC(source) {
|
|
65
|
+
try {
|
|
66
|
+
const c = pearToC(source);
|
|
67
|
+
return { c };
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
return { c: '', error: String(err) };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function compileToBinary(pearSource, outputFile, options = {}) {
|
|
74
|
+
// Step 1: Pear → C
|
|
75
|
+
let cSource;
|
|
76
|
+
try {
|
|
77
|
+
cSource = pearToC(pearSource);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
return { success: false, output: '', error: `Pear parse error: ${err}` };
|
|
81
|
+
}
|
|
82
|
+
// Step 2: Write C to temp file (use OS temp dir for cross-platform compat)
|
|
83
|
+
const os = require('os');
|
|
84
|
+
const tmpC = path.join(os.tmpdir(), `pear_${Date.now()}.tmp.c`);
|
|
85
|
+
try {
|
|
86
|
+
fs.writeFileSync(tmpC, cSource, 'utf8');
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
return { success: false, output: '', error: `Failed to write temp file: ${err}` };
|
|
90
|
+
}
|
|
91
|
+
// Step 3: Find and invoke compiler
|
|
92
|
+
const compiler = options.compiler ?? findCompiler();
|
|
93
|
+
if (!compiler) {
|
|
94
|
+
fs.unlinkSync(tmpC);
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
output: cSource,
|
|
98
|
+
error: 'No C compiler found. Options:\n' +
|
|
99
|
+
' - Install MinGW/MSYS2 and add gcc to PATH\n' +
|
|
100
|
+
' - Run from a VS Developer Command Prompt (cl.exe)\n' +
|
|
101
|
+
' - Use: npm run compile -- file.pr > out.c then compile out.c manually'
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// MSVC sentinel: "msvc:<clPath>:<vcvarsPath>"
|
|
105
|
+
if (compiler.startsWith('msvc\x00')) {
|
|
106
|
+
const [, clPath, vcvarsPath] = compiler.split('\x00');
|
|
107
|
+
// Convert Unix-style paths to Windows paths for cmd.exe
|
|
108
|
+
const toWin = (p) => p.replace(/\//g, '\\');
|
|
109
|
+
const winTmpC = toWin(tmpC);
|
|
110
|
+
const winOut = toWin(outputFile.endsWith('.exe') ? outputFile : outputFile + '.exe');
|
|
111
|
+
const winCl = toWin(clPath);
|
|
112
|
+
const winVcvars = toWin(vcvarsPath);
|
|
113
|
+
// cmd /c requires outer quotes when inner command path is quoted
|
|
114
|
+
const shellCmd = `call "${winVcvars}" x64 && "${winCl}" /nologo /W3 /O2 "${winTmpC}" /Fe:"${winOut}"`;
|
|
115
|
+
try {
|
|
116
|
+
const result = child_process.spawnSync(shellCmd, [], {
|
|
117
|
+
shell: true,
|
|
118
|
+
encoding: 'utf8', timeout: 60000,
|
|
119
|
+
});
|
|
120
|
+
fs.unlinkSync(tmpC);
|
|
121
|
+
// cl.exe also leaves a .obj file in cwd
|
|
122
|
+
try {
|
|
123
|
+
fs.unlinkSync(tmpC.replace(/\.c$/, '.obj'));
|
|
124
|
+
}
|
|
125
|
+
catch { /* ok */ }
|
|
126
|
+
if (result.status === 0) {
|
|
127
|
+
return { success: true, output: cSource };
|
|
128
|
+
}
|
|
129
|
+
return { success: false, output: cSource, error: result.stderr || result.stdout || `cl.exe exited ${result.status}` };
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
try {
|
|
133
|
+
fs.unlinkSync(tmpC);
|
|
134
|
+
}
|
|
135
|
+
catch { /* ok */ }
|
|
136
|
+
return { success: false, output: cSource, error: `MSVC execution failed: ${err}` };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const flags = options.flags ?? ['-std=c99', '-Wall', '-O2'];
|
|
140
|
+
const args = [...flags, tmpC, '-o', outputFile];
|
|
141
|
+
try {
|
|
142
|
+
const result = child_process.spawnSync(compiler, args, {
|
|
143
|
+
encoding: 'utf8',
|
|
144
|
+
timeout: 30000,
|
|
145
|
+
});
|
|
146
|
+
fs.unlinkSync(tmpC);
|
|
147
|
+
if (result.status === 0) {
|
|
148
|
+
return { success: true, output: cSource };
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
return {
|
|
152
|
+
success: false,
|
|
153
|
+
output: cSource,
|
|
154
|
+
error: (result.stderr || result.stdout || `Compiler exited with code ${result.status}`),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
try {
|
|
160
|
+
fs.unlinkSync(tmpC);
|
|
161
|
+
}
|
|
162
|
+
catch { /* ignore */ }
|
|
163
|
+
return { success: false, output: cSource, error: `Compiler execution failed: ${err}` };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function findCompiler() {
|
|
167
|
+
// Try common Unix compilers first
|
|
168
|
+
for (const cc of ['gcc', 'clang', 'cc']) {
|
|
169
|
+
try {
|
|
170
|
+
const result = child_process.spawnSync(cc, ['--version'], { encoding: 'utf8', timeout: 5000 });
|
|
171
|
+
if (result.status === 0)
|
|
172
|
+
return cc;
|
|
173
|
+
}
|
|
174
|
+
catch { /* not found */ }
|
|
175
|
+
}
|
|
176
|
+
// On Windows, try to find MSVC cl.exe via vswhere
|
|
177
|
+
if (process.platform === 'win32') {
|
|
178
|
+
// Try tcc (Tiny C Compiler) — lightweight, no env setup needed
|
|
179
|
+
try {
|
|
180
|
+
const tcc = child_process.spawnSync('tcc', ['-v'], { encoding: 'utf8', timeout: 5000 });
|
|
181
|
+
if (tcc.status === 0)
|
|
182
|
+
return 'tcc';
|
|
183
|
+
}
|
|
184
|
+
catch { /* not found */ }
|
|
185
|
+
// Try MSVC via vswhere — returns 'msvc:<clPath>:<vcvarsPath>' sentinel
|
|
186
|
+
const vswhere = 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe';
|
|
187
|
+
try {
|
|
188
|
+
const clResult = child_process.spawnSync(vswhere, [
|
|
189
|
+
'-latest', '-products', '*', '-find', '**\\HostX64\\x64\\cl.exe'
|
|
190
|
+
], { encoding: 'utf8', timeout: 10000 });
|
|
191
|
+
const vcvarsResult = child_process.spawnSync(vswhere, [
|
|
192
|
+
'-latest', '-products', '*', '-find', '**\\vcvarsall.bat'
|
|
193
|
+
], { encoding: 'utf8', timeout: 10000 });
|
|
194
|
+
if (clResult.status === 0 && clResult.stdout.trim() &&
|
|
195
|
+
vcvarsResult.status === 0 && vcvarsResult.stdout.trim()) {
|
|
196
|
+
// Use last entry = newest toolset
|
|
197
|
+
const clLines = clResult.stdout.trim().split('\n').map((l) => l.trim()).filter(Boolean);
|
|
198
|
+
const vcLines = vcvarsResult.stdout.trim().split('\n').map((l) => l.trim()).filter(Boolean);
|
|
199
|
+
const clPath = clLines[clLines.length - 1];
|
|
200
|
+
const vcvarsPath = vcLines[vcLines.length - 1];
|
|
201
|
+
// Return a sentinel that compileToBinary recognises
|
|
202
|
+
return `msvc\x00${clPath}\x00${vcvarsPath}`;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch { /* vswhere not found */ }
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
function runInterpreted(pearSource, argv) {
|
|
210
|
+
return (0, interpreter_1.interpret)(pearSource, argv);
|
|
211
|
+
}
|
|
212
|
+
function runPear(pearSource, args = [], options = {}) {
|
|
213
|
+
const os = require('os');
|
|
214
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
215
|
+
const tmpBin = path.join(os.tmpdir(), `pear_run_${Date.now()}${ext}`);
|
|
216
|
+
const compiled = compileToBinary(pearSource, tmpBin, options);
|
|
217
|
+
if (!compiled.success) {
|
|
218
|
+
return { exitCode: 1, error: compiled.error };
|
|
219
|
+
}
|
|
220
|
+
const actualBin = process.platform === 'win32' && !tmpBin.endsWith('.exe')
|
|
221
|
+
? tmpBin + '.exe'
|
|
222
|
+
: tmpBin;
|
|
223
|
+
try {
|
|
224
|
+
// Inherit stdio so output goes directly to terminal
|
|
225
|
+
const result = child_process.spawnSync(actualBin, args, {
|
|
226
|
+
stdio: 'inherit',
|
|
227
|
+
timeout: 30000,
|
|
228
|
+
});
|
|
229
|
+
return { exitCode: result.status ?? 1 };
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
return { exitCode: 1, error: `Execution failed: ${err}` };
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
try {
|
|
236
|
+
fs.unlinkSync(actualBin);
|
|
237
|
+
}
|
|
238
|
+
catch { /* ok */ }
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// ─── CLI Entry Point ─────────────────────────────────────────────────────────
|
|
242
|
+
function main() {
|
|
243
|
+
const args = process.argv.slice(2);
|
|
244
|
+
// Start MCP server
|
|
245
|
+
if (args[0] === '--mcp') {
|
|
246
|
+
require('./mcp-server');
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
|
|
250
|
+
console.log(`Pear Language Compiler v0.1.0
|
|
251
|
+
Usage:
|
|
252
|
+
pearc <file.pr> Compile Pear to C (print to stdout)
|
|
253
|
+
pearc <file.pr> -o <out.c> Compile Pear to C file
|
|
254
|
+
pearc <file.pr> --binary -o <out> Compile Pear to binary via gcc/clang
|
|
255
|
+
pearc run <file.pr> [args...] Interpret and run Pear directly
|
|
256
|
+
pearc --decompile <file.c> Decompile C to Pear (print to stdout)
|
|
257
|
+
pearc --decompile <file.c> -o <out.pr> Decompile C to Pear file
|
|
258
|
+
|
|
259
|
+
Options:
|
|
260
|
+
-o <file> Output file
|
|
261
|
+
--binary Compile all the way to binary (requires gcc or clang)
|
|
262
|
+
--decompile Run decompiler (C → Pear) instead of compiler
|
|
263
|
+
--run, -r Interpret and run Pear directly (same as run subcommand)
|
|
264
|
+
-h, --help Show this help
|
|
265
|
+
`);
|
|
266
|
+
process.exit(0);
|
|
267
|
+
}
|
|
268
|
+
// Handle 'run' subcommand: pearc run <file.pr> [args...]
|
|
269
|
+
if (args[0] === 'run' || args[0] === '--run' || args[0] === '-r') {
|
|
270
|
+
const fileArgStart = (args[0] === 'run' || args[0] === '--run' || args[0] === '-r') ? 1 : 0;
|
|
271
|
+
const fileArg = args[fileArgStart];
|
|
272
|
+
if (!fileArg) {
|
|
273
|
+
console.error('Error: No input file specified for run');
|
|
274
|
+
process.exit(1);
|
|
275
|
+
}
|
|
276
|
+
const inputPath = path.resolve(process.cwd(), fileArg);
|
|
277
|
+
if (!fs.existsSync(inputPath)) {
|
|
278
|
+
console.error(`Error: File not found: ${inputPath}`);
|
|
279
|
+
process.exit(1);
|
|
280
|
+
}
|
|
281
|
+
const source = fs.readFileSync(inputPath, 'utf8');
|
|
282
|
+
const programArgs = args.slice(fileArgStart + 1);
|
|
283
|
+
const exitCode = (0, interpreter_1.interpret)(source, programArgs);
|
|
284
|
+
process.exit(exitCode);
|
|
285
|
+
}
|
|
286
|
+
let decompileMode = false;
|
|
287
|
+
let binaryMode = false;
|
|
288
|
+
let inputFile = '';
|
|
289
|
+
let outputFile = '';
|
|
290
|
+
for (let i = 0; i < args.length; i++) {
|
|
291
|
+
const arg = args[i];
|
|
292
|
+
if (arg === '--decompile') {
|
|
293
|
+
decompileMode = true;
|
|
294
|
+
}
|
|
295
|
+
else if (arg === '--binary') {
|
|
296
|
+
binaryMode = true;
|
|
297
|
+
}
|
|
298
|
+
else if (arg === '-o') {
|
|
299
|
+
outputFile = args[++i];
|
|
300
|
+
}
|
|
301
|
+
else if (!arg.startsWith('-')) {
|
|
302
|
+
inputFile = arg;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (!inputFile) {
|
|
306
|
+
console.error('Error: No input file specified');
|
|
307
|
+
process.exit(1);
|
|
308
|
+
}
|
|
309
|
+
// Resolve relative to cwd
|
|
310
|
+
const inputPath = path.resolve(process.cwd(), inputFile);
|
|
311
|
+
if (!fs.existsSync(inputPath)) {
|
|
312
|
+
console.error(`Error: File not found: ${inputPath}`);
|
|
313
|
+
process.exit(1);
|
|
314
|
+
}
|
|
315
|
+
const source = fs.readFileSync(inputPath, 'utf8');
|
|
316
|
+
if (decompileMode) {
|
|
317
|
+
// C → Pear
|
|
318
|
+
const pearCode = cToPear(source);
|
|
319
|
+
if (outputFile) {
|
|
320
|
+
fs.writeFileSync(path.resolve(process.cwd(), outputFile), pearCode, 'utf8');
|
|
321
|
+
console.log(`Decompiled to ${outputFile}`);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
console.log(pearCode);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
else if (binaryMode) {
|
|
328
|
+
// Pear → binary
|
|
329
|
+
if (!outputFile) {
|
|
330
|
+
outputFile = path.basename(inputPath, '.pr');
|
|
331
|
+
}
|
|
332
|
+
const result = compileToBinary(source, path.resolve(process.cwd(), outputFile));
|
|
333
|
+
if (result.success) {
|
|
334
|
+
console.log(`Compiled to binary: ${outputFile}`);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
console.error('Compilation failed:');
|
|
338
|
+
if (result.error)
|
|
339
|
+
console.error(result.error);
|
|
340
|
+
if (result.output) {
|
|
341
|
+
console.error('\nGenerated C code:');
|
|
342
|
+
console.error(result.output);
|
|
343
|
+
}
|
|
344
|
+
process.exit(1);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
// Pear → C
|
|
349
|
+
let cCode;
|
|
350
|
+
try {
|
|
351
|
+
cCode = pearToC(source);
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
console.error(`Compilation error: ${err}`);
|
|
355
|
+
process.exit(1);
|
|
356
|
+
}
|
|
357
|
+
if (outputFile) {
|
|
358
|
+
fs.writeFileSync(path.resolve(process.cwd(), outputFile), cCode, 'utf8');
|
|
359
|
+
console.log(`Compiled to ${outputFile}`);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
process.stdout.write(cCode);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
// Run main only when executed directly
|
|
367
|
+
if (require.main === module) {
|
|
368
|
+
main();
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":";;AACA,oCAAoC;AACpC,SAAS;AACT,kDAAkD;AAClD,kDAAkD;AAClD,yEAAyE;AACzE,sDAAsD;AACtD,2CAA2C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAU3C,0BAGC;AAED,0BAEC;AAED,gCAOC;AAED,0CA0FC;AA8CD,wCAEC;AAED,0BA8BC;AApMD,uCAAyB;AACzB,2CAA6B;AAC7B,6DAA+C;AAC/C,qCAAiC;A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C;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;YAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YACzE,OAAO,CAAC,GAAG,CAAC,eAAe,UAAU,EAAE,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;AACH,CAAC;AAED,uCAAuC;AACvC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface DecompilerOptions {
|
|
2
|
+
minifyWhitespace: boolean;
|
|
3
|
+
convertTypes: boolean;
|
|
4
|
+
convertKeywords: boolean;
|
|
5
|
+
convertPreprocessor: boolean;
|
|
6
|
+
convertDeclarations: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class Decompiler {
|
|
9
|
+
private options;
|
|
10
|
+
constructor(options?: Partial<DecompilerOptions>);
|
|
11
|
+
decompile(cSource: string): string;
|
|
12
|
+
private convertPreprocessor;
|
|
13
|
+
private convertTypes;
|
|
14
|
+
private convertKeywords;
|
|
15
|
+
private convertDeclarations;
|
|
16
|
+
private convertDeclLine;
|
|
17
|
+
private convertFunctions;
|
|
18
|
+
private convertParams;
|
|
19
|
+
private minifyWhitespace;
|
|
20
|
+
private protectStringsAndComments;
|
|
21
|
+
private restoreStringsAndComments;
|
|
22
|
+
}
|
|
23
|
+
export declare function decompile(cSource: string): string;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=decompiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decompiler.d.ts","sourceRoot":"","sources":["../src/decompiler.ts"],"names":[],"mappings":"AAqEA,UAAU,iBAAiB;IACzB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAUD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAoB;gBAEvB,OAAO,GAAE,OAAO,CAAC,iBAAiB,CAAM;IAIpD,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAkClC,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,eAAe;IAavB,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,eAAe;IAiDvB,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,gBAAgB;IAkCxB,OAAO,CAAC,yBAAyB;IAmCjC,OAAO,CAAC,yBAAyB;CAMlC;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGjD"}
|