Skip to content

Commit

Permalink
#207: phi
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 22, 2023
1 parent 3f60f83 commit 7065638
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/commands/phi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const path = require('path');
const mvnw = require('../mvnw');

/**
* Command to convert .XMIR files into .PHI files.
* @param {Hash} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
return mvnw([
'eo:phi',
'-Deo.version=' + opts.parser,
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
], opts.target, opts.batch).then((r) => {
console.info('XMIR files converted into PHI files at %s', path.resolve(opts.target));
return r;
});
};
52 changes: 52 additions & 0 deletions test/commands/test_phi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const {runSync, assertFilesExist} = require('../helpers');

describe('phi', function() {
it('converts XMIR files to PHI files', function(done) {
home = path.resolve('temp/test-phi/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n');
const stdout = runSync([
'phi',
'--verbose',
'--track-optimization-steps',
'-s', path.resolve(home, 'src'),
'-t', path.resolve(home, 'target'),
]);
assertFilesExist(
stdout, home,
[
'target/2-optimize/simple.xmir',
'target/phi/simple.phi',
]
);
done();
});
});

0 comments on commit 7065638

Please sign in to comment.