Skip to content

Commit

Permalink
Merge branch 'master' into 207
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 22, 2023
2 parents 7065638 + 6798d32 commit f45c9aa
Show file tree
Hide file tree
Showing 28 changed files with 215 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Then, you write a simple [EO](https://www.eolang.org) program in `hello.eo` file
in the current directory:

```
[args...] > hello
[args] > hello
QQ.io.stdout > @
"Hello, world!\n"
```
Expand Down
2 changes: 1 addition & 1 deletion eo-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.29.4
0.34.1
2 changes: 1 addition & 1 deletion itest/program.eo
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@

+alias story

[args...] > program
[args] > program
QQ.io.stdout > @
story
8 changes: 3 additions & 5 deletions itest/story-test.eo
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
# SOFTWARE.

+junit
+alias org.eolang.hamcrest.assert-that
+alias story

[] > story-is-long-enough
assert-that > @
[] > story-is-not-empty
gt. > @
story.length
$.is
$.greater-than 1
0
8 changes: 1 addition & 7 deletions itest/story.eo
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,4 @@
# SOFTWARE.

[] > story
QQ.txt.sprintf > @
"Hello, Mr. #%d!\n"
as-int.
QQ.math.number
times.
QQ.math.random.pseudo
100.0
"Hello, Jeff" > @
6 changes: 3 additions & 3 deletions mvnw/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ SOFTWARE.
<modelVersion>4.0.0</modelVersion>
<groupId>org.eolang</groupId>
<artifactId>eoc</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<eo.version>0.0.0</eo.version>
<eo.version>undefined</eo.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -87,7 +87,7 @@ SOFTWARE.
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>
<configuration>
<failIfNoTests>true</failIfNoTests>
</configuration>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"xmlhttprequest": "1.8.0"
},
"devDependencies": {
"eslint": "8.55.0",
"eslint": "8.56.0",
"eslint-config-google": "0.14.0",
"grunt": "1.6.1",
"grunt-contrib-clean": "2.0.1",
Expand All @@ -47,6 +47,6 @@
"mocha": "10.2.0"
},
"scripts": {
"test": "mocha --timeout 1200000"
"test": "mocha --timeout 1200000 --files test/**/*.js"
}
}
1 change: 1 addition & 0 deletions src/commands/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = function(opts) {
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.trackOptimizationSteps ? '-Deo.trackOptimizationSteps' : '',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
`-Deo.placed=${path.resolve(opts.target, 'eo-placed.csv')}`,
Expand Down
2 changes: 2 additions & 0 deletions src/commands/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ module.exports = function(opts) {
'compiler:compile',
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Dmaven.compiler.source=1.8`,
`-Dmaven.compiler.target=1.8`,
`-Deo.targetDir=${target}`,
`-Deo.generatedDir=${path.resolve(opts.target, 'generated-sources')}`,
'-Deo.version=' + opts.parser,
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
], opts.target, opts.batch).then((r) => {
console.info('Java .class files compiled into %s', target);
return r;
Expand Down
25 changes: 14 additions & 11 deletions src/commands/dataize.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ const path = require('path');
* @param {Hash} opts - All options
*/
module.exports = function(obj, args, opts) {
spawn(
`java`,
[
'-Dfile.encoding=UTF-8',
`-Xss${opts.stack}`,
'-jar', path.resolve(opts.target, 'eoc.jar'),
obj,
...args,
],
{stdio: 'inherit'}
);
const params = [
'-Dfile.encoding=UTF-8',
`-Xss${opts.stack}`,
'-jar', path.resolve(opts.target, 'eoc.jar'),
obj,
...args,
];
console.debug('+ java ' + params.join(' '));
spawn('java', params, {stdio: 'inherit'}).on('close', (code) => {
if (code !== 0) {
console.error(`Java exited with #${code} code`);
process.exit(1);
}
});
};
1 change: 1 addition & 0 deletions src/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = function(opts) {
'jar:jar',
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
'-Deo.version=' + opts.parser,
], opts.target, opts.batch).then((r) => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = function(opts) {
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
], opts.target, opts.batch).then((r) => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = function(opts) {
'-Deo.version=' + opts.parser,
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.sourcesDir=${path.resolve(opts.sources)}`,
], opts.target, opts.batch).then((r) => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/sodg.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = function(opts) {
'-Deo.version=' + opts.parser,
opts.verbose ? '' : '--quiet',
opts.verbose ? '--errors' : '',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
];
argv.push('-Deo.sodgIncludes=' + opts.include);
Expand Down
1 change: 1 addition & 0 deletions src/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = function(opts) {
'surefire:test',
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
'-Deo.version=' + opts.parser,
`-Deo.targetDir=${path.resolve(opts.target)}`,
]);
Expand Down
1 change: 1 addition & 0 deletions src/commands/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = function(opts) {
'-Deo.version=' + opts.parser,
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.generatedDir=${sources}`,
], opts.target, opts.batch).then((r) => {
Expand Down
47 changes: 47 additions & 0 deletions src/commands/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 verify .XMIR files.
* @param {Hash} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
return mvnw([
'eo:verify',
'-Deo.version=' + opts.parser,
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
], opts.target, opts.batch).then((r) => {
console.info('EO program verified in %s', path.resolve(opts.target));
return r;
});
};
20 changes: 20 additions & 0 deletions src/eoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const parse = require('./commands/parse');
const assemble = require('./commands/assemble');
const sodg = require('./commands/sodg');
const register = require('./commands/register');
const verify = require('./commands/verify');
const transpile = require('./commands/transpile');
const compile = require('./commands/compile');
const link = require('./commands/link');
Expand Down Expand Up @@ -72,6 +73,7 @@ program
.option('--no-color', 'Disable colorization of console messages')
.option('--track-optimization-steps', 'Save intermediate XMIR files')
.option('-c, --clean', 'Delete ./.eoc directory')
.option('--debug', 'Print ALL debug messages, heavily overloading the log')
.option('--verbose', 'Print debug messages and full output of child processes');

program.command('audit')
Expand Down Expand Up @@ -143,13 +145,27 @@ program.command('sodg')
}
});

program.command('verify')
.description('Verify XMIR files and fail if any issues inside')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
.then((r) => verify(program.opts()));
} else {
verify(program.opts());
}
});

program.command('transpile')
.description('Convert EO files into target language')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
.then((r) => verify(program.opts()))
.then((r) => transpile(program.opts()));
} else {
transpile(program.opts());
Expand All @@ -163,6 +179,7 @@ program.command('compile')
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
.then((r) => verify(program.opts()))
.then((r) => transpile(program.opts()))
.then((r) => compile(program.opts()));
} else {
Expand All @@ -177,6 +194,7 @@ program.command('link')
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
.then((r) => verify(program.opts()))
.then((r) => transpile(program.opts()))
.then((r) => compile(program.opts()))
.then((r) => link(program.opts()));
Expand All @@ -193,6 +211,7 @@ program.command('dataize')
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
.then((r) => verify(program.opts()))
.then((r) => transpile(program.opts()))
.then((r) => compile(program.opts()))
.then((r) => link(program.opts()))
Expand All @@ -209,6 +228,7 @@ program.command('test')
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
.then((r) => verify(program.opts()))
.then((r) => transpile(program.opts()))
.then((r) => compile(program.opts()))
.then((r) => link(program.opts()))
Expand Down
10 changes: 6 additions & 4 deletions test/commands/test_assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ describe('assemble', function() {
home = path.resolve('temp/test-assemble/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');
fs.writeFileSync(path.resolve(home, 'src/assemble.eo'), '[] > assemble\n');
const stdout = runSync([
'assemble',
'--verbose',
'--track-optimization-steps',
'--parser=0.34.1',
'--hash=1d605bd872f27494551e9dd2341b9413d0d96d89',
'-s', path.resolve(home, 'src'),
'-t', path.resolve(home, 'target'),
]);
assertFilesExist(
stdout, home,
[
'target/eo-foreign.json',
'target/1-parse/simple.xmir',
'target/2-optimization-steps/simple',
'target/2-optimize/simple.xmir',
'target/1-parse/assemble.xmir',
'target/2-optimization-steps/assemble',
'target/2-optimize/assemble.xmir',
]
);
assert(!fs.existsSync(path.resolve('../../mvnw/target')));
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('clean', function() {
fs.rmSync(eo, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.mkdirSync(eo, {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n');
fs.writeFileSync(path.resolve(home, 'src/clean.eo'), '[] > clean\n');
const stdout = runSync([
'clean', '-s', path.resolve(home, 'src'), '-t', path.resolve(home, 'target'), '--cached',
]);
Expand Down
Loading

0 comments on commit f45c9aa

Please sign in to comment.