eolang 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CITATION.cff ADDED
@@ -0,0 +1,11 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below."
3
+ authors:
4
+ - family-names: "Bugayenko"
5
+ given-names: "Yegor"
6
+ orcid: "https://orcid.org/0000-0001-6370-0678"
7
+ title: "EOLANG and 𝜑-calculus"
8
+ version: 0.23.0
9
+ doi: 10.48550/arXiv.2111.13384
10
+ date-released: 2022-05-09
11
+ url: "https://github.com/objectionary/eoc"
package/README.md CHANGED
@@ -28,6 +28,8 @@ $ eoc dataize hello
28
28
 
29
29
  That's it.
30
30
 
31
+ ## Commands
32
+
31
33
  You can also do many other things with `eoc` commands
32
34
  (the flow is explained in [this blog post](https://www.yegor256.com/2021/10/21/objectionary.html)):
33
35
 
@@ -37,15 +39,17 @@ You can also do many other things with `eoc` commands
37
39
  * `compile` converts target language to binaries
38
40
  * `link` puts all binaries together into a single executable binary
39
41
  * `dataize` executes the binary and dataize a single object
42
+ * `test` executes all visible unit tests
40
43
 
41
- There are also commands that help manipulate with XMIR and EO sources:
44
+ There are also commands that help manipulate with XMIR and EO sources (some of them are not implemented as of yet):
42
45
 
43
46
  * `audit` inspects all packages and report their status
44
- * `translate` converts Java/C++/Python/etc. program to EO program
45
- * `demu` removes `cage` and `memory` objects
46
- * `dejump` removes `goto` objects
47
- * `infer` suggests object names where it's possible to infer them
48
- * `flatten` moves inner objects to upper level
47
+ * `foreign` inspects all objects found in the program after `assemble` step
48
+ * <del>`translate` converts Java/C++/Python/etc. program to EO program</del>
49
+ * <del>`demu` removes `cage` and `memory` objects</del>
50
+ * <del>`dejump` removes `goto` objects</del>
51
+ * <del>`infer` suggests object names where it's possible to infer them</del>
52
+ * <del>`flatten` moves inner objects to upper level</del>
49
53
 
50
54
  This command line toolkit simply integrates other tools available in
51
55
  [@objectionary](https://github.com/objectionary) GitHub organization.
package/itest/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  [![grunt](https://github.com/objectionary/eoc/actions/workflows/itest.yml/badge.svg)](https://github.com/objectionary/eoc/actions/workflows/itest.yml)
2
2
 
3
- There is a simple integration here. Just run this to make sure
3
+ There is a simple integration test here. Just run this to make sure
4
4
  it works:
5
5
 
6
6
  ```
7
- $ ../src/eoc.js dataize foo.program
7
+ $ ../src/eoc.js dataize program
8
8
  ```
9
9
 
10
10
  Then, you can execute the unit tests too:
package/mvnw/pom.xml CHANGED
@@ -27,6 +27,10 @@ SOFTWARE.
27
27
  <groupId>org.eolang</groupId>
28
28
  <artifactId>eoc</artifactId>
29
29
  <version>1.0-SNAPSHOT</version>
30
+ <properties>
31
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
33
+ </properties>
30
34
  <dependencies>
31
35
  <dependency>
32
36
  <groupId>org.junit.jupiter</groupId>
@@ -52,6 +56,8 @@ SOFTWARE.
52
56
  <version>${eo.version}</version>
53
57
  <configuration>
54
58
  <excludeSources>.eoc/**</excludeSources>
59
+ <foreign>${project.build.directory}/eo-foreign.json</foreign>
60
+ <foreignFormat>json</foreignFormat>
55
61
  </configuration>
56
62
  </plugin>
57
63
  <plugin>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eolang",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "author": "Yegor Bugayenko <yegor256@gmail.com> (https://www.yegor256.com/)",
5
5
  "license": "MIT",
6
6
  "repository": "objectionary/eoc",
@@ -21,6 +21,7 @@
21
21
  "eoc": "./src/eoc.js"
22
22
  },
23
23
  "dependencies": {
24
+ "colors": "1.4.0",
24
25
  "commander": "9.2.0",
25
26
  "fast-xml-parser": "4.0.0",
26
27
  "xmlhttprequest": "1.8.0"
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -33,11 +32,12 @@ const mvnwSync = require('../mvnw');
33
32
  module.exports = function assemble(opts) {
34
33
  mvnwSync([
35
34
  'eo:assemble',
35
+ opts.verbose ? '' : '--quiet',
36
+ opts.trackOptimizationSteps ? '-Deo.trackOptimizationSteps' : '',
36
37
  `-Deo.targetDir=${path.resolve(opts.target)}`,
37
38
  `-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
38
- `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
39
- `-Deo.foreignFormat=csv`,
40
39
  `-Deo.placed=${path.resolve(opts.target, 'eo-placed.csv')}`,
41
40
  `-Deo.placedFormat=csv`,
42
41
  ]);
42
+ console.info('EO program assembled in %s', path.resolve(opts.target));
43
43
  };
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -33,4 +32,5 @@ const path = require('path');
33
32
  module.exports = function clean(opts) {
34
33
  const home = path.resolve(opts.target);
35
34
  fs.rmSync(home, {recursive: true, force: true});
35
+ console.debug('The directory %s deleted', home);
36
36
  };
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -31,11 +30,14 @@ const path = require('path');
31
30
  * @param {Hash} opts - All options
32
31
  */
33
32
  module.exports = function compile(opts) {
33
+ const target = path.resolve(opts.target);
34
34
  mvnwSync([
35
35
  'compiler:compile',
36
+ opts.verbose ? '' : '--quiet',
36
37
  `-Dmaven.compiler.source=1.8`,
37
38
  `-Dmaven.compiler.target=1.8`,
38
- `-Deo.targetDir=${path.resolve(opts.target)}`,
39
+ `-Deo.targetDir=${target}`,
39
40
  `-Deo.generatedDir=${path.resolve(opts.target, 'generated-sources')}`,
40
41
  ]);
42
+ console.info('Java .class files compiled into %s', target);
41
43
  };
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -34,7 +33,11 @@ const path = require('path');
34
33
  module.exports = function dataize(obj, opts) {
35
34
  spawn(
36
35
  `java`,
37
- ['-jar', path.resolve(opts.target, 'eoc.jar'), obj],
36
+ [
37
+ '-Dfile.encoding=UTF-8',
38
+ '-jar', path.resolve(opts.target, 'eoc.jar'),
39
+ obj,
40
+ ],
38
41
  {stdio: 'inherit'}
39
42
  );
40
43
  };
@@ -0,0 +1,39 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2022 Yegor Bugayenko
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included
14
+ * in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const path = require('path');
26
+ const fs = require('fs');
27
+
28
+ /**
29
+ * Inspects and prints the list of foreign objects.
30
+ * @param {Hash} opts - All options
31
+ */
32
+ module.exports = function foreign(opts) {
33
+ const file = path.resolve(opts.target, 'eo-foreign.json');
34
+ const all = JSON.parse(fs.readFileSync(file, 'utf8'));
35
+ console.info('There are %d objects in %s:', all.length, file);
36
+ all.forEach((obj) => {
37
+ console.info(' %s', obj['id']);
38
+ });
39
+ };
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -33,6 +32,8 @@ const path = require('path');
33
32
  module.exports = function link(opts) {
34
33
  mvnwSync([
35
34
  'jar:jar',
35
+ opts.verbose ? '' : '--quiet',
36
36
  `-Deo.targetDir=${path.resolve(opts.target)}`,
37
37
  ]);
38
+ console.info('Executable JAR created at %s', path.resolve(opts.target, 'eoc.jar'));
38
39
  };
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -31,11 +30,12 @@ const path = require('path');
31
30
  * @param {Hash} opts - All options
32
31
  */
33
32
  module.exports = function register(opts) {
33
+ const foreign = path.resolve(opts.target, 'eo-foreign.json');
34
34
  mvnwSync([
35
35
  'eo:register',
36
+ opts.verbose ? '' : '--quiet',
36
37
  `-Deo.targetDir=${path.resolve(opts.target)}`,
37
38
  `-Deo.sourcesDir=${path.resolve(opts.sources)}`,
38
- `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
39
- `-Deo.foreignFormat=csv`,
40
39
  ]);
40
+ console.info('EO objects registered in %s', foreign);
41
41
  };
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -31,11 +30,12 @@ const path = require('path');
31
30
  * @param {Hash} opts - All options
32
31
  */
33
32
  module.exports = function transpile(opts) {
33
+ const sources = path.resolve(opts.target, 'generated-sources');
34
34
  mvnwSync([
35
35
  'eo:transpile',
36
+ opts.verbose ? '' : '--quiet',
36
37
  `-Deo.targetDir=${path.resolve(opts.target)}`,
37
- `-Deo.generatedDir=${path.resolve(opts.target, 'generated-sources')}`,
38
- `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
39
- `-Deo.foreignFormat=csv`,
38
+ `-Deo.generatedDir=${sources}`,
40
39
  ]);
40
+ console.info('Java sources generated in %s', sources);
41
41
  };
package/src/eoc.js CHANGED
@@ -23,9 +23,8 @@
23
23
  * SOFTWARE.
24
24
  */
25
25
 
26
- const {Command} = require('commander');
27
- const program = new Command();
28
-
26
+ const {program} = require('commander');
27
+ const tinted = require('./tinted-console');
29
28
  const audit = require('./commands/audit');
30
29
  const clean = require('./commands/clean');
31
30
  const assemble = require('./commands/assemble');
@@ -34,8 +33,15 @@ const transpile = require('./commands/transpile');
34
33
  const compile = require('./commands/compile');
35
34
  const link = require('./commands/link');
36
35
  const dataize = require('./commands/dataize');
36
+ const foreign = require('./commands/foreign');
37
37
  const test = require('./commands/test');
38
38
 
39
+ if (process.argv.includes('--verbose')) {
40
+ tinted.enable('debug');
41
+ console.debug('Debug output is turned ON');
42
+ console.info('INFO');
43
+ }
44
+
39
45
  program
40
46
  .name('eoc')
41
47
  .description('EO command-line toolkit')
@@ -44,7 +50,10 @@ program
44
50
  program
45
51
  .option('-s, --sources <path>', 'directory with .EO sources', '.')
46
52
  .option('-t, --target <path>', 'directory with all generated files', '.eoc')
47
- .option('--alone', 'just run a single command without dependencies');
53
+ .option('--alone', 'just run a single command without dependencies')
54
+ .option('--no-color', 'disable colorization of console messages')
55
+ .option('--track-optimization-steps', 'save intermediate XMIR files')
56
+ .option('--verbose', 'print debug messages and full output of child processes');
48
57
 
49
58
  program.command('audit')
50
59
  .description('inspects all packages and reports their status')
@@ -52,6 +61,12 @@ program.command('audit')
52
61
  audit(program.opts());
53
62
  });
54
63
 
64
+ program.command('foreign')
65
+ .description('inspects and prints the list of foreign objects')
66
+ .action((str, opts) => {
67
+ foreign(program.opts());
68
+ });
69
+
55
70
  program.command('clean')
56
71
  .description('delete all temporary files')
57
72
  .action((str, opts) => {
@@ -135,6 +150,7 @@ program.command('test')
135
150
  try {
136
151
  program.parse(process.argv);
137
152
  } catch (e) {
138
- console.log('eoc failed: "' + e.message + '"');
153
+ console.error(e.message);
154
+ console.debug(e.stack);
139
155
  process.exit(1);
140
156
  }
package/src/mvnw.js CHANGED
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -46,9 +45,9 @@ function latest() {
46
45
  }
47
46
  const xml = new XMLParser().parse(xhr.responseText);
48
47
  version = xml.metadata.versioning.release;
49
- console.log('The latest version of ' + repo + ' at ' + url + ' is ' + version);
48
+ console.debug('The latest version of %s at %s is %s', repo, url, version);
50
49
  }
51
- console.log('Current version of ' + repo + ' is ' + version);
50
+ console.debug('Current version of %s is %s', repo, version);
52
51
  return version;
53
52
  }
54
53
 
@@ -58,8 +57,10 @@ function latest() {
58
57
  */
59
58
  module.exports = function mvnwSync(args) {
60
59
  const home = path.resolve(__dirname, '../mvnw');
61
- const bin = path.resolve(home, 'mvnw');
62
- const params = args.concat([
60
+ const bin = path.resolve(home, 'mvnw') + (process.platform == 'win32' ? '.cmd' : '');
61
+ const params = args.filter(function(t) {
62
+ return t != '';
63
+ }).concat([
63
64
  '-Deo.version=' + latest(),
64
65
  '--errors',
65
66
  '--batch-mode',
@@ -67,8 +68,22 @@ module.exports = function mvnwSync(args) {
67
68
  '--fail-fast',
68
69
  ]);
69
70
  const cmd = bin + ' ' + params.join(' ');
70
- console.log('+ ' + cmd);
71
- const result = spawnSync(bin, params, {cwd: home, stdio: 'inherit'});
71
+ console.debug('+ %s', cmd);
72
+ const result = spawnSync(
73
+ bin,
74
+ process.platform == 'win32' ? params.map((p) => `"${p}"`) : params,
75
+ {
76
+ cwd: home,
77
+ stdio: 'inherit',
78
+ shell: (
79
+ process.platform == 'win32'
80
+ ?
81
+ 'C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe'
82
+ :
83
+ undefined
84
+ ),
85
+ }
86
+ );
72
87
  if (result.status != 0) {
73
88
  throw new Error('The command "' + cmd + '" exited with #' + result.status + ' code');
74
89
  }
@@ -0,0 +1,73 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2022 Yegor Bugayenko
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included
14
+ * in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const safe = require('colors/safe');
26
+ const util = require('node:util');
27
+
28
+ const levels = {
29
+ 'trace': false,
30
+ 'debug': false,
31
+ 'info': true,
32
+ 'warn': true,
33
+ 'error': true,
34
+ };
35
+
36
+ const colors = {
37
+ 'trace': 'gray',
38
+ 'debug': 'gray',
39
+ 'info': 'white',
40
+ 'warn': 'orange',
41
+ 'error': 'red',
42
+ };
43
+
44
+ for (const level in levels) {
45
+ if (levels.hasOwnProperty(level)) {
46
+ const lvl = level;
47
+ const before = console[lvl];
48
+ console[level] = function(...args) {
49
+ if (!levels[lvl]) {
50
+ return;
51
+ }
52
+ before.call(
53
+ before,
54
+ safe[colors[lvl]](util.format(...args))
55
+ );
56
+ };
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Enable this particular logging level.
62
+ * @param {String} level - The level to enable
63
+ */
64
+ module.exports.enable = function enable(level) {
65
+ for (const key in levels) {
66
+ if (levels.hasOwnProperty(level)) {
67
+ levels[key] = true;
68
+ if (key === level) {
69
+ break;
70
+ }
71
+ }
72
+ }
73
+ };
package/src/version.js CHANGED
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -23,4 +22,4 @@
23
22
  * SOFTWARE.
24
23
  */
25
24
 
26
- module.exports = '0.3.0';
25
+ module.exports = '0.5.0';