Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#293): added directories options for phi and unphi #294

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const {mvnw, flags} = require('../mvnw');

/**
* Command to convert .XMIR files into .EO files.
* @param {Hash} opts - All options
* @param {Object} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
const input = path.resolve(opts.target, '2-optimize');
const input = path.resolve(opts.target, opts.printInput);
console.debug('Reading from %s', rel(input));
const output = path.resolve(opts.target, 'print');
const output = path.resolve(opts.target, opts.printOutput);
console.debug('Writing into %s', rel(output));
return mvnw(
['eo:print']
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
34 changes: 32 additions & 2 deletions src/eoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,39 @@ 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'
)
.option(
'--phi-output <dir>',
'Directory where translated PHI files are stored (relative to --target)',
'phi'
)
.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'
)
.option(
'--unphi-output <dir>',
'Directory where translated XMIR files are stored (relative to --target)',
'unphi'
)
.description('Generate XMIR files from PHI files')
.action((str, opts) => {
clear(str);
Expand All @@ -200,9 +220,19 @@ program.command('unphi')

program.command('print')
.description('Generate EO files from XMIR files')
.option(
'--print-input <dir>',
'Directory where XMIR files for translation to EO are taken (relative to --target)',
'2-optimize'
)
.option(
'--print-output <dir>',
'Directory where translated EO files are stored (relative to --target)',
'print'
)
.action((str, opts) => {
clear(str);
print(program.opts());
print({...program.opts(), ...str});
});

program.command('verify')
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_print.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe('print', function() {
it('converts XMIR files to EO files', function(done) {
const home = path.resolve('temp/test-print/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'target/2-optimize'), {recursive: true});
fs.mkdirSync(path.resolve(home, 'target/input'), {recursive: true});
fs.writeFileSync(
path.resolve(home, 'target/2-optimize/app.xmir'),
path.resolve(home, 'target/input/app.xmir'),
[
'<program ms="0" name="xx" time="2024-01-01T01:01:01"',
'version="0.0.0" dob="2024-01-01T01:01:01" revision="0">',
Expand All @@ -47,12 +47,14 @@ describe('print', function() {
'--track-optimization-steps',
'--parser=' + parserVersion,
'--home-tag=' + homeTag,
'--print-input=input',
'--print-output=output',
'-t', path.resolve(home, 'target'),
]);
assertFilesExist(
stdout, home,
[
'target/print/app.eo',
'target/output/app.eo',
]
);
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