eolang 0.4.1 → 0.6.1

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
@@ -38,12 +38,13 @@ You can also do many other things with `eoc` commands
38
38
  * `transpile` converts XMIR to target programming language
39
39
  * `compile` converts target language to binaries
40
40
  * `link` puts all binaries together into a single executable binary
41
- * `dataize` executes the binary and dataize a single object
41
+ * `dataize` executes the binary and dataizes a single object
42
42
  * `test` executes all visible unit tests
43
43
 
44
44
  There are also commands that help manipulate with XMIR and EO sources (some of them are not implemented as of yet):
45
45
 
46
46
  * `audit` inspects all packages and report their status
47
+ * `foreign` inspects all objects found in the program after `assemble` step
47
48
  * <del>`translate` converts Java/C++/Python/etc. program to EO program</del>
48
49
  * <del>`demu` removes `cage` and `memory` objects</del>
49
50
  * <del>`dejump` removes `goto` objects</del>
package/itest/story.eo CHANGED
@@ -24,6 +24,7 @@
24
24
  QQ.txt.sprintf > @
25
25
  "Hello, Mr. #%d!\n"
26
26
  as-int.
27
- times.
28
- random
29
- 100.0
27
+ QQ.math.number
28
+ times.
29
+ QQ.math.random
30
+ 100.0
package/mvnw/pom.xml CHANGED
@@ -30,6 +30,7 @@ SOFTWARE.
30
30
  <properties>
31
31
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32
32
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
33
+ <eo.version>0.0.0</eo.version>
33
34
  </properties>
34
35
  <dependencies>
35
36
  <dependency>
@@ -56,6 +57,8 @@ SOFTWARE.
56
57
  <version>${eo.version}</version>
57
58
  <configuration>
58
59
  <excludeSources>.eoc/**</excludeSources>
60
+ <foreign>${project.build.directory}/eo-foreign.json</foreign>
61
+ <foreignFormat>json</foreignFormat>
59
62
  </configuration>
60
63
  </plugin>
61
64
  <plugin>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eolang",
3
- "version": "0.4.1",
3
+ "version": "0.6.1",
4
4
  "author": "Yegor Bugayenko <yegor256@gmail.com> (https://www.yegor256.com/)",
5
5
  "license": "MIT",
6
6
  "repository": "objectionary/eoc",
@@ -24,19 +24,21 @@
24
24
 
25
25
  const path = require('path');
26
26
  const mvnwSync = require('../mvnw');
27
+ const parserVersion = require('../parser-version');
27
28
 
28
29
  /**
29
30
  * Command to assemble .XMIR files.
30
31
  * @param {Hash} opts - All options
31
32
  */
32
- module.exports = function assemble(opts) {
33
+ module.exports = function(opts) {
33
34
  mvnwSync([
34
35
  'eo:assemble',
36
+ '-Deo.version=' + (opts.parserVersion ? opts.parserVersion : parserVersion()),
35
37
  opts.verbose ? '' : '--quiet',
38
+ opts.trackOptimizationSteps ? '-Deo.trackOptimizationSteps' : '',
39
+ opts.hash ? '-Deo.hash=' + opts.hash : '',
36
40
  `-Deo.targetDir=${path.resolve(opts.target)}`,
37
41
  `-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
38
- `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
39
- `-Deo.foreignFormat=csv`,
40
42
  `-Deo.placed=${path.resolve(opts.target, 'eo-placed.csv')}`,
41
43
  `-Deo.placedFormat=csv`,
42
44
  ]);
@@ -28,6 +28,6 @@ const mvnwSync = require('../mvnw');
28
28
  * Command to audit all packages.
29
29
  * @param {Hash} opts - All options
30
30
  */
31
- module.exports = function audit(opts) {
31
+ module.exports = function(opts) {
32
32
  mvnwSync(['--version']);
33
33
  };
@@ -29,8 +29,8 @@ const path = require('path');
29
29
  * Deletes all temporary files.
30
30
  * @param {Hash} opts - All options
31
31
  */
32
- module.exports = function clean(opts) {
32
+ module.exports = function(opts) {
33
33
  const home = path.resolve(opts.target);
34
34
  fs.rmSync(home, {recursive: true, force: true});
35
- console.debug('The directory %s deleted', home);
35
+ console.info('The directory %s deleted', home);
36
36
  };
@@ -29,7 +29,7 @@ const path = require('path');
29
29
  * Command to compile target language into binaries.
30
30
  * @param {Hash} opts - All options
31
31
  */
32
- module.exports = function compile(opts) {
32
+ module.exports = function(opts) {
33
33
  const target = path.resolve(opts.target);
34
34
  mvnwSync([
35
35
  'compiler:compile',
@@ -30,7 +30,7 @@ const path = require('path');
30
30
  * @param {String} obj - Name of object to dataize
31
31
  * @param {Hash} opts - All options
32
32
  */
33
- module.exports = function dataize(obj, opts) {
33
+ module.exports = function(obj, opts) {
34
34
  spawn(
35
35
  `java`,
36
36
  [
@@ -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
+ };
@@ -29,7 +29,7 @@ const path = require('path');
29
29
  * Command to link binaries into a single executable binary.
30
30
  * @param {Hash} opts - All options
31
31
  */
32
- module.exports = function link(opts) {
32
+ module.exports = function(opts) {
33
33
  mvnwSync([
34
34
  'jar:jar',
35
35
  opts.verbose ? '' : '--quiet',
@@ -24,20 +24,20 @@
24
24
 
25
25
  const mvnwSync = require('../mvnw');
26
26
  const path = require('path');
27
+ const parserVersion = require('../parser-version');
27
28
 
28
29
  /**
29
30
  * Command to register .EO sources.
30
31
  * @param {Hash} opts - All options
31
32
  */
32
- module.exports = function register(opts) {
33
- const foreign = path.resolve(opts.target, 'eo-foreign.csv');
33
+ module.exports = function(opts) {
34
+ const foreign = path.resolve(opts.target, 'eo-foreign.json');
34
35
  mvnwSync([
35
36
  'eo:register',
37
+ '-Deo.version=' + (opts.parserVersion ? opts.parserVersion : parserVersion()),
36
38
  opts.verbose ? '' : '--quiet',
37
39
  `-Deo.targetDir=${path.resolve(opts.target)}`,
38
40
  `-Deo.sourcesDir=${path.resolve(opts.sources)}`,
39
- `-Deo.foreign=${foreign}`,
40
- `-Deo.foreignFormat=csv`,
41
41
  ]);
42
42
  console.info('EO objects registered in %s', foreign);
43
43
  };
@@ -29,7 +29,7 @@ const path = require('path');
29
29
  * Command to run all available unit tests.
30
30
  * @param {Hash} opts - All options
31
31
  */
32
- module.exports = function test(opts) {
32
+ module.exports = function(opts) {
33
33
  mvnwSync([
34
34
  'surefire:test',
35
35
  `-Deo.targetDir=${path.resolve(opts.target)}`,
@@ -23,21 +23,26 @@
23
23
  */
24
24
 
25
25
  const mvnwSync = require('../mvnw');
26
+ const fs = require('fs');
26
27
  const path = require('path');
28
+ const parserVersion = require('../parser-version');
27
29
 
28
30
  /**
29
31
  * Command to transpile XMIR files into target language.
30
32
  * @param {Hash} opts - All options
31
33
  */
32
- module.exports = function transpile(opts) {
34
+ module.exports = function(opts) {
33
35
  const sources = path.resolve(opts.target, 'generated-sources');
36
+ if (fs.existsSync(sources)) {
37
+ fs.rmSync(sources, {recursive: true, force: true});
38
+ console.info('Previously existed Java sources deleted in %s', sources);
39
+ }
34
40
  mvnwSync([
35
41
  'eo:transpile',
42
+ '-Deo.version=' + (opts.parserVersion ? opts.parserVersion : parserVersion()),
36
43
  opts.verbose ? '' : '--quiet',
37
44
  `-Deo.targetDir=${path.resolve(opts.target)}`,
38
45
  `-Deo.generatedDir=${sources}`,
39
- `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
40
- `-Deo.foreignFormat=csv`,
41
46
  ]);
42
47
  console.info('Java sources generated in %s', sources);
43
48
  };
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')) {
@@ -43,13 +44,17 @@ if (process.argv.includes('--verbose')) {
43
44
 
44
45
  program
45
46
  .name('eoc')
46
- .description('EO command-line toolkit')
47
+ .description('EO command-line toolkit (' + require('./version') + ')')
47
48
  .version(require('./version'));
48
49
 
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
@@ -24,44 +24,17 @@
24
24
 
25
25
  const path = require('path');
26
26
  const {spawnSync} = require('child_process');
27
- const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
28
- const {XMLParser} = require('fast-xml-parser');
29
-
30
- let version = '';
31
-
32
- /**
33
- * Load the latest version from GitHub releases.
34
- * @return {String} Latest version, for example '0.23.1'
35
- */
36
- function latest() {
37
- const repo = 'org/eolang/eo-maven-plugin';
38
- if (version === '') {
39
- const url = 'https://repo.maven.apache.org/maven2/' + repo + '/maven-metadata.xml';
40
- const xhr = new XMLHttpRequest();
41
- xhr.open('GET', url, false);
42
- xhr.send(null);
43
- if (xhr.status != 200) {
44
- throw new Error('Invalid response status ' + xhr.status + ' from ' + url);
45
- }
46
- const xml = new XMLParser().parse(xhr.responseText);
47
- version = xml.metadata.versioning.release;
48
- console.debug('The latest version of %s at %s is %s', repo, url, version);
49
- }
50
- console.debug('Current version of %s is %s', repo, version);
51
- return version;
52
- }
53
27
 
54
28
  /**
55
29
  * Run mvnw with provided commands.
56
30
  * @param {Hash} args - All arguments to pass to it
57
31
  */
58
- module.exports = function mvnwSync(args) {
32
+ module.exports = function(args) {
59
33
  const home = path.resolve(__dirname, '../mvnw');
60
34
  const bin = path.resolve(home, 'mvnw') + (process.platform == 'win32' ? '.cmd' : '');
61
35
  const params = args.filter(function(t) {
62
36
  return t != '';
63
37
  }).concat([
64
- '-Deo.version=' + latest(),
65
38
  '--errors',
66
39
  '--batch-mode',
67
40
  '--update-snapshots',
@@ -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
+ };
package/src/version.js CHANGED
@@ -22,4 +22,4 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- module.exports = '0.4.1';
25
+ module.exports = '0.6.1';