Skip to content

Commit

Permalink
fix(#293): added directories options for phi and unphi
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Jun 5, 2024
1 parent 84a5321 commit 459ba7f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/commands/phi.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ const {mvnw, flags} = require('../mvnw');

/**
* Command to convert .XMIR files into .PHI files.
* @param {Hash} opts - All options
* @param {Object} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
gte('EO parser', opts.parser, '0.35.2');
const target = path.resolve(opts.target);
const input = path.resolve(opts.target, '2-optimize');
const input = path.resolve(opts.target, opts.phiInput);
console.debug('Reading .XMIR files from %s', rel(input));
const output = path.resolve(opts.target, 'phi');
const output = path.resolve(opts.target, opts.phiOutput);
console.debug('Writing .PHI files to %s', rel(output));
return mvnw(
['eo:xmir-to-phi']
Expand Down
6 changes: 3 additions & 3 deletions src/commands/unphi.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const {gte} = require('../demand');

/**
* Command to convert .PHI files into .XMIR files.
* @param {Hash} opts - All options
* @param {Object} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
gte('EO parser', opts.parser, '0.35.2');
const input = path.resolve(opts.target, 'phi');
const input = path.resolve(opts.target, opts.unphiInput);
console.debug('Reading .PHI files from %s', rel(input));
const output = path.resolve(opts.target, 'unphi');
const output = path.resolve(opts.target, opts.unphiOutput);
console.debug('Writing .XMIR files to %s', rel(output));
return mvnw(
['eo:phi-to-xmir']
Expand Down
6 changes: 5 additions & 1 deletion src/eoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,23 @@ program.command('sodg')

program.command('phi')
.description('Generate PHI files from XMIR')
.option('--phi-input <dir>', 'Directory where XMIR files for translation to PHI are taken (relative to --target)', '2-optimize')

Check failure on line 182 in src/eoc.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

This line has a length of 130. Maximum allowed is 100
.option('--phi-output <dir>', 'Directory where translated PHI files are stored (relative to --target)', 'phi')

Check failure on line 183 in src/eoc.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

This line has a length of 112. Maximum allowed is 100
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
.then((r) => phi(program.opts()));
.then((r) => phi({...program.opts(), ...str}));
} else {
phi(program.opts());
}
});

program.command('unphi')
.option('--tests', 'Add "+tests" meta to result XMIR files')
.option('--unphi-input <dir>', 'Directory where PHI files for translation to XMIR are taken (relative to --target)', 'phi')

Check failure on line 197 in src/eoc.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

This line has a length of 125. Maximum allowed is 100
.option('--unphi-output <dir>', 'Directory where translated XMIR files are stored (relative to --target)', 'unphi')

Check failure on line 198 in src/eoc.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

This line has a length of 117. Maximum allowed is 100
.description('Generate XMIR files from PHI files')
.action((str, opts) => {
clear(str);
Expand Down
4 changes: 3 additions & 1 deletion test/commands/test_phi.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ describe('phi', function() {
'--track-optimization-steps',
'--parser=' + parserVersion,
'--home-tag=' + homeTag,
'--phi-input=2-optimize',
'--phi-output=output',
'-s', path.resolve(home, 'src'),
'-t', path.resolve(home, 'target'),
]);
assertFilesExist(
stdout, home,
[
'target/2-optimize/phi.xmir',
'target/phi/phi.phi',
'target/output/phi.phi',
]
);
done();
Expand Down
8 changes: 5 additions & 3 deletions test/commands/test_unphi.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ describe('unphi', function() {
it('converts PHI files to XMIR files', function(done) {
const home = path.resolve('temp/test-unphi/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'target/phi'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'target/phi/app.phi'), '{ ⟦ app ↦ ⟦ ⟧ ⟧ }');
fs.mkdirSync(path.resolve(home, 'target/input'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'target/input/app.phi'), '{ ⟦ app ↦ ⟦ ⟧ ⟧ }');
const stdout = runSync([
'unphi',
'--verbose',
'--track-optimization-steps',
'--tests',
'--parser=' + parserVersion,
'--home-tag=' + homeTag,
'--unphi-input=input',
'--unphi-output=output',
'-t', path.resolve(home, 'target'),
]);
const unphied = 'target/unphi/app.xmir';
const unphied = 'target/output/app.xmir';
assertFilesExist(
stdout, home,
[unphied]
Expand Down

0 comments on commit 459ba7f

Please sign in to comment.