Skip to content

Commit

Permalink
fix prepare.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov committed Jul 5, 2024
1 parent 3d9970d commit 576b354
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions scripts/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ void (async () => {

// Compile func files
for (const p of [{ path: path.join(__dirname, "..", "func") }]) {
const recs = fs.readdirSync(p.path);
for (const r of recs) {
if (!r.endsWith(".fc")) {
const files = fs.readdirSync(p.path);
for (const file of files) {
if (!file.endsWith(".fc")) {
continue;
}

// Precompile
logger.info(`Processing ${path.join(p.path + r)}`);
const funcFileFullPath = path.join(p.path, file);
logger.info(`Processing ${path.join(funcFileFullPath)}`);
let c: FuncCompilationResult;
try {
const stdlibPath = path.resolve(
Expand All @@ -57,16 +58,16 @@ void (async () => {
"stdlib.fc",
);
const stdlib = fs.readFileSync(stdlibPath, "utf-8");
const code = fs.readFileSync(p.path + r, "utf-8");
const code = fs.readFileSync(funcFileFullPath, "utf-8");
c = await funcCompile({
entries: [stdlibPath, p.path + r],
entries: [stdlibPath, funcFileFullPath],
sources: [
{
path: stdlibPath,
content: stdlib,
},
{
path: p.path + r,
path: funcFileFullPath,
content: code,
},
],
Expand All @@ -75,20 +76,20 @@ void (async () => {
if (!c.ok) {
logger.error(c.log);
throw new Error(
`FunC compilation failed for ${path.join(p.path, r)}`,
`FunC compilation failed for ${path.join(p.path, file)}`,
);
}
} catch (e) {
logger.error(e as Error);
logger.error(`Failed for ${path.join(p.path, r)}`);
logger.error(`Failed for ${path.join(p.path, file)}`);
throw e;
}
fs.writeFileSync(p.path + r + ".fift", c.fift!);
fs.writeFileSync(p.path + r + ".cell", c.output!);
fs.writeFileSync(funcFileFullPath + ".fift", c.fift!);
fs.writeFileSync(funcFileFullPath + ".cell", c.output!);

// Cell -> Fift decompiler
const source = decompileAll({ src: c.output! });
fs.writeFileSync(p.path + r + ".rev.fift", source);
fs.writeFileSync(funcFileFullPath + ".rev.fift", source);
}
}
} catch (error) {
Expand Down

0 comments on commit 576b354

Please sign in to comment.