eolang 0.4.0 → 0.6.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/README.md CHANGED
@@ -8,7 +8,7 @@ and [Java SE](https://www.oracle.com/java/technologies/downloads/).
8
8
  Then, you install [eolang](https://www.npmjs.com/package/eolang) package:
9
9
 
10
10
  ```
11
- $ npm install eolang
11
+ $ npm install -g eolang
12
12
  ```
13
13
 
14
14
  Then, you write a simple [EO](https://www.eolang.org) program in `hello.eo` file
@@ -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
 
@@ -42,6 +44,7 @@ You can also do many other things with `eoc` commands
42
44
  There are also commands that help manipulate with XMIR and EO sources (some of them are not implemented as of yet):
43
45
 
44
46
  * `audit` inspects all packages and report their status
47
+ * `foreign` inspects all objects found in the program after `assemble` step
45
48
  * <del>`translate` converts Java/C++/Python/etc. program to EO program</del>
46
49
  * <del>`demu` removes `cage` and `memory` objects</del>
47
50
  * <del>`dejump` removes `goto` objects</del>
package/mvnw/pom.xml CHANGED
@@ -27,6 +27,11 @@ 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
+ <eo.version>0.0.0</eo.version>
34
+ </properties>
30
35
  <dependencies>
31
36
  <dependency>
32
37
  <groupId>org.junit.jupiter</groupId>
@@ -52,6 +57,8 @@ SOFTWARE.
52
57
  <version>${eo.version}</version>
53
58
  <configuration>
54
59
  <excludeSources>.eoc/**</excludeSources>
60
+ <foreign>${project.build.directory}/eo-foreign.json</foreign>
61
+ <foreignFormat>json</foreignFormat>
55
62
  </configuration>
56
63
  </plugin>
57
64
  <plugin>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eolang",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "author": "Yegor Bugayenko <yegor256@gmail.com> (https://www.yegor256.com/)",
5
5
  "license": "MIT",
6
6
  "repository": "objectionary/eoc",
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -25,19 +24,21 @@
25
24
 
26
25
  const path = require('path');
27
26
  const mvnwSync = require('../mvnw');
27
+ const parserVersion = require('../parser-version');
28
28
 
29
29
  /**
30
30
  * Command to assemble .XMIR files.
31
31
  * @param {Hash} opts - All options
32
32
  */
33
- module.exports = function assemble(opts) {
33
+ module.exports = function(opts) {
34
34
  mvnwSync([
35
35
  'eo:assemble',
36
+ '-Deo.version=' + (opts.parserVersion ? opts.parserVersion : parserVersion()),
36
37
  opts.verbose ? '' : '--quiet',
38
+ opts.trackOptimizationSteps ? '-Deo.trackOptimizationSteps' : '',
39
+ opts.hash ? '-Deo.hash=' + opts.hash : '',
37
40
  `-Deo.targetDir=${path.resolve(opts.target)}`,
38
41
  `-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
39
- `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
40
- `-Deo.foreignFormat=csv`,
41
42
  `-Deo.placed=${path.resolve(opts.target, 'eo-placed.csv')}`,
42
43
  `-Deo.placedFormat=csv`,
43
44
  ]);
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -29,6 +28,6 @@ const mvnwSync = require('../mvnw');
29
28
  * Command to audit all packages.
30
29
  * @param {Hash} opts - All options
31
30
  */
32
- module.exports = function audit(opts) {
31
+ module.exports = function(opts) {
33
32
  mvnwSync(['--version']);
34
33
  };
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -30,7 +29,7 @@ const path = require('path');
30
29
  * Deletes all temporary files.
31
30
  * @param {Hash} opts - All options
32
31
  */
33
- module.exports = function clean(opts) {
32
+ module.exports = function(opts) {
34
33
  const home = path.resolve(opts.target);
35
34
  fs.rmSync(home, {recursive: true, force: true});
36
35
  console.debug('The directory %s deleted', home);
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -30,7 +29,7 @@ const path = require('path');
30
29
  * Command to compile target language into binaries.
31
30
  * @param {Hash} opts - All options
32
31
  */
33
- module.exports = function compile(opts) {
32
+ module.exports = function(opts) {
34
33
  const target = path.resolve(opts.target);
35
34
  mvnwSync([
36
35
  'compiler:compile',
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -31,10 +30,14 @@ const path = require('path');
31
30
  * @param {String} obj - Name of object to dataize
32
31
  * @param {Hash} opts - All options
33
32
  */
34
- module.exports = function dataize(obj, opts) {
33
+ module.exports = function(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(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
  *
@@ -30,7 +29,7 @@ const path = require('path');
30
29
  * Command to link binaries into a single executable binary.
31
30
  * @param {Hash} opts - All options
32
31
  */
33
- module.exports = function link(opts) {
32
+ module.exports = function(opts) {
34
33
  mvnwSync([
35
34
  'jar:jar',
36
35
  opts.verbose ? '' : '--quiet',
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -25,20 +24,20 @@
25
24
 
26
25
  const mvnwSync = require('../mvnw');
27
26
  const path = require('path');
27
+ const parserVersion = require('../parser-version');
28
28
 
29
29
  /**
30
30
  * Command to register .EO sources.
31
31
  * @param {Hash} opts - All options
32
32
  */
33
- module.exports = function register(opts) {
34
- const foreign = path.resolve(opts.target, 'eo-foreign.csv');
33
+ module.exports = function(opts) {
34
+ const foreign = path.resolve(opts.target, 'eo-foreign.json');
35
35
  mvnwSync([
36
36
  'eo:register',
37
+ '-Deo.version=' + (opts.parserVersion ? opts.parserVersion : parserVersion()),
37
38
  opts.verbose ? '' : '--quiet',
38
39
  `-Deo.targetDir=${path.resolve(opts.target)}`,
39
40
  `-Deo.sourcesDir=${path.resolve(opts.sources)}`,
40
- `-Deo.foreign=${foreign}`,
41
- `-Deo.foreignFormat=csv`,
42
41
  ]);
43
42
  console.info('EO objects registered in %s', foreign);
44
43
  };
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -30,7 +29,7 @@ const path = require('path');
30
29
  * Command to run all available unit tests.
31
30
  * @param {Hash} opts - All options
32
31
  */
33
- module.exports = function test(opts) {
32
+ module.exports = function(opts) {
34
33
  mvnwSync([
35
34
  'surefire:test',
36
35
  `-Deo.targetDir=${path.resolve(opts.target)}`,
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -25,20 +24,20 @@
25
24
 
26
25
  const mvnwSync = require('../mvnw');
27
26
  const path = require('path');
27
+ const parserVersion = require('../parser-version');
28
28
 
29
29
  /**
30
30
  * Command to transpile XMIR files into target language.
31
31
  * @param {Hash} opts - All options
32
32
  */
33
- module.exports = function transpile(opts) {
33
+ module.exports = function(opts) {
34
34
  const sources = path.resolve(opts.target, 'generated-sources');
35
35
  mvnwSync([
36
36
  'eo:transpile',
37
+ '-Deo.version=' + (opts.parserVersion ? opts.parserVersion : parserVersion()),
37
38
  opts.verbose ? '' : '--quiet',
38
39
  `-Deo.targetDir=${path.resolve(opts.target)}`,
39
40
  `-Deo.generatedDir=${sources}`,
40
- `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
41
- `-Deo.foreignFormat=csv`,
42
41
  ]);
43
42
  console.info('Java sources generated in %s', sources);
44
43
  };
package/src/eoc.js CHANGED
@@ -33,6 +33,7 @@ const transpile = require('./commands/transpile');
33
33
  const compile = require('./commands/compile');
34
34
  const link = require('./commands/link');
35
35
  const dataize = require('./commands/dataize');
36
+ const foreign = require('./commands/foreign');
36
37
  const test = require('./commands/test');
37
38
 
38
39
  if (process.argv.includes('--verbose')) {
@@ -49,7 +50,11 @@ program
49
50
  program
50
51
  .option('-s, --sources <path>', 'directory with .EO sources', '.')
51
52
  .option('-t, --target <path>', 'directory with all generated files', '.eoc')
53
+ .option('--hash <hex>', 'hash in objectionary/home to compile against')
54
+ .option('--parser <version>', 'set the version of parser to use')
52
55
  .option('--alone', 'just run a single command without dependencies')
56
+ .option('--no-color', 'disable colorization of console messages')
57
+ .option('--track-optimization-steps', 'save intermediate XMIR files')
53
58
  .option('--verbose', 'print debug messages and full output of child processes');
54
59
 
55
60
  program.command('audit')
@@ -58,6 +63,12 @@ program.command('audit')
58
63
  audit(program.opts());
59
64
  });
60
65
 
66
+ program.command('foreign')
67
+ .description('inspects and prints the list of foreign objects')
68
+ .action((str, opts) => {
69
+ foreign(program.opts());
70
+ });
71
+
61
72
  program.command('clean')
62
73
  .description('delete all temporary files')
63
74
  .action((str, opts) => {
package/src/mvnw.js CHANGED
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -25,44 +24,17 @@
25
24
 
26
25
  const path = require('path');
27
26
  const {spawnSync} = require('child_process');
28
- const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
29
- const {XMLParser} = require('fast-xml-parser');
30
-
31
- let version = '';
32
-
33
- /**
34
- * Load the latest version from GitHub releases.
35
- * @return {String} Latest version, for example '0.23.1'
36
- */
37
- function latest() {
38
- const repo = 'org/eolang/eo-maven-plugin';
39
- if (version === '') {
40
- const url = 'https://repo.maven.apache.org/maven2/' + repo + '/maven-metadata.xml';
41
- const xhr = new XMLHttpRequest();
42
- xhr.open('GET', url, false);
43
- xhr.send(null);
44
- if (xhr.status != 200) {
45
- throw new Error('Invalid response status ' + xhr.status + ' from ' + url);
46
- }
47
- const xml = new XMLParser().parse(xhr.responseText);
48
- version = xml.metadata.versioning.release;
49
- console.debug('The latest version of %s at %s is %s', repo, url, version);
50
- }
51
- console.debug('Current version of %s is %s', repo, version);
52
- return version;
53
- }
54
27
 
55
28
  /**
56
29
  * Run mvnw with provided commands.
57
30
  * @param {Hash} args - All arguments to pass to it
58
31
  */
59
- module.exports = function mvnwSync(args) {
32
+ module.exports = function(args) {
60
33
  const home = path.resolve(__dirname, '../mvnw');
61
- const bin = path.resolve(home, 'mvnw');
34
+ const bin = path.resolve(home, 'mvnw') + (process.platform == 'win32' ? '.cmd' : '');
62
35
  const params = args.filter(function(t) {
63
36
  return t != '';
64
37
  }).concat([
65
- '-Deo.version=' + latest(),
66
38
  '--errors',
67
39
  '--batch-mode',
68
40
  '--update-snapshots',
@@ -70,7 +42,21 @@ module.exports = function mvnwSync(args) {
70
42
  ]);
71
43
  const cmd = bin + ' ' + params.join(' ');
72
44
  console.debug('+ %s', cmd);
73
- const result = spawnSync(bin, params, {cwd: home, stdio: 'inherit'});
45
+ const result = spawnSync(
46
+ bin,
47
+ process.platform == 'win32' ? params.map((p) => `"${p}"`) : params,
48
+ {
49
+ cwd: home,
50
+ stdio: 'inherit',
51
+ shell: (
52
+ process.platform == 'win32'
53
+ ?
54
+ 'C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe'
55
+ :
56
+ undefined
57
+ ),
58
+ }
59
+ );
74
60
  if (result.status != 0) {
75
61
  throw new Error('The command "' + cmd + '" exited with #' + result.status + ' code');
76
62
  }
@@ -0,0 +1,50 @@
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 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
26
+ const {XMLParser} = require('fast-xml-parser');
27
+
28
+ let version = '';
29
+
30
+ /**
31
+ * Load the latest version from GitHub releases.
32
+ * @return {String} Latest version, for example '0.23.1'
33
+ */
34
+ module.exports = function() {
35
+ const repo = 'org/eolang/eo-maven-plugin';
36
+ if (version === '') {
37
+ const url = 'https://repo.maven.apache.org/maven2/' + repo + '/maven-metadata.xml';
38
+ const xhr = new XMLHttpRequest();
39
+ xhr.open('GET', url, false);
40
+ xhr.send(null);
41
+ if (xhr.status != 200) {
42
+ throw new Error('Invalid response status ' + xhr.status + ' from ' + url);
43
+ }
44
+ const xml = new XMLParser().parse(xhr.responseText);
45
+ version = xml.metadata.versioning.release;
46
+ console.debug('The latest version of %s at %s is %s', repo, url, version);
47
+ }
48
+ console.debug('Current version of %s is %s', repo, version);
49
+ return version;
50
+ };
@@ -1,4 +1,3 @@
1
- #! /usr/bin/env node
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
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.4.0';
25
+ module.exports = '0.6.0';