Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed May 12, 2024
2 parents af27146 + 3fbc3ff commit 6dcfa4b
Show file tree
Hide file tree
Showing 26 changed files with 282 additions and 71 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pdd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# The MIT License (MIT)
#
# Copyright (c) 2024 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.
---
name: pdd
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
pdd:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: volodya-lombrozo/pdd-action@master
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# The MIT License (MIT)
#
# Copyright (c) 2024 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.
---
name: test
on:
pull_request:
branches:
- master
jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [16]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm install --force -g grunt-cli
- run: npm test
41 changes: 41 additions & 0 deletions .github/workflows/xcop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The MIT License (MIT)
#
# Copyright (c) 2024 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.
---
name: xcop
"on":
push:
branches:
- master
pull_request:
branches:
- master
jobs:
xcop:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: g4s8/[email protected]
with:
license: LICENSE.txt
files: |
**/*.xml
**/*.xsl
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ eo2js-runtime/node_modules/
eo2js-runtime/coverage/
eo2js-runtime/coverage.html
eo2js-runtime/temp
eo2js-runtime/atom.js
eo2js-runtime/atoms.js
.nyc_output
.idea
mochawesome-report/
Expand Down
2 changes: 2 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
The MIT License (MIT)

Copyright (c) 2024 Objectionary.com

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
2 changes: 2 additions & 0 deletions eo2js-runtime/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
The MIT License (MIT)

Copyright (c) 2024 Objectionary.com

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
2 changes: 1 addition & 1 deletion eo2js-runtime/src/objects/org/eolang/int$div.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const int$div = function() {
obj.assets[LAMBDA] = function(self) {
const arg = dataized(self.take('x'), INT)
if (arg === 0) {
// todo: error
// fix: error
}
return data.toObject(
dataized(self.take(RHO), INT) / arg
Expand Down
15 changes: 14 additions & 1 deletion eo2js-runtime/src/runtime/bytes-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const hexToInt = function(bytes) {
/**
* Bytes of.
* @param {string|number|boolean|array.<string>|array.<number>} data - Data to cast to bytes
* @return {{asInt: (function(): number), asBool: (function(): boolean), asString: (function(): string), asFloat: (function(): number), asBytes: (function(): array.<number>)}}
* @return {{asInt: (function(): number), asBool: (function(): boolean), asString: (function(): string), asFloat: (function(): number), asBytes: (function(): array.<number>), verbose: (function(): string)}}
*/
const bytesOf = function(data) {
let bytes
Expand Down Expand Up @@ -73,6 +73,19 @@ const bytesOf = function(data) {
throw new Error(`Byte array must be 1 byte long to convert to bool (${bytes})`)
}
return bytes[0] !== 0
},
verbose: function() {
let str
if (bytes.length === 0) {
str = '[]'
} else if (bytes.length === 1) {
str = bytes[0] ? '[1]' : '[0]'
} else if (bytes.length === 8) {
str = `[${this.asBytes()}] = ${this.asInt()}, or ${this.asFloat()}, or "${this.asString()}"`
} else {
str = `[${this.asBytes()}] = "${this.asString()}"`
}
return str
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion eo2js-runtime/src/runtime/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const found = function(name, full) {
obj = tryFind.call(this, '../../../..', name, split)
}
if (obj == null) {
throw new Error(`Couldn't find object ${name} from ${full}`)
throw new Error(`Couldn't find object '${name}' from '${full}'`)
}
return obj
}
Expand Down
1 change: 0 additions & 1 deletion eo2js-runtime/src/runtime/validated.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const validated = function(callback) {
try {
return callback()
} catch (error) {
console.log(error.message)
if (error instanceof ErFailure) {
throw new ErError(
data.toObject(error.message)
Expand Down
38 changes: 29 additions & 9 deletions eo2js-runtime/test/runtime/bytes-of.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert');
const bytesOf = require('../../temp/runtime/bytes-of');
const assert = require('assert')
const bytesOf = require('../../temp/runtime/bytes-of')

describe('bytesOf', function() {
describe('int', function() {
Expand All @@ -14,10 +14,10 @@ describe('bytesOf', function() {
const value = 1234
const bytes = bytesOf(value).asBytes()
assert.equal(bytesOf(bytes).asInt(), value)
});
})
it('should fail if not 8 bytes given', function() {
assert.throws(() => bytesOf([0, 0, 0, 48, 57]).asInt())
});
})
})
describe('float', function() {
it('should return the same float', function() {
Expand All @@ -26,15 +26,15 @@ describe('bytesOf', function() {
})
it('should return valid float bytes', function() {
assert.deepEqual(bytesOf(374.9).asBytes(), [64, 119, 110, 102, 102, 102, 102, 102])
});
})
it('should convert to bytes and back', function() {
const value = 9412.21
const bytes = bytesOf(value).asBytes()
assert.equal(bytesOf(bytes).asFloat(), value)
});
})
it('should fail if not 8 bytes given', function() {
assert.throws(() => bytesOf([64, 119, 110, 102]).asFloat())
});
})
})
describe('string', function() {
it('should return the same string', function() {
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('bytesOf', function() {
it('should return valid bool from bytes', function() {
assert.equal(bytesOf([1]).asBool(), true)
assert.equal(bytesOf([0]).asBool(), false)
});
})
it('should fail if not 1 byte given', function() {
assert.throws(() => bytesOf([1, 1]).asBool())
})
Expand All @@ -87,6 +87,26 @@ describe('bytesOf', function() {
it('should fail while converting wrong format bytes', function() {
const wrong = [1, 2, 'hello']
assert.throws(() => bytesOf(wrong))
});
})
})
describe('#verbose()', function() {
describe('returns valid array as string if', function() {
it('length is 0', function() {
assert.equal(bytesOf([]).verbose(), '[]')
})
it('length is 1', function() {
assert.equal(bytesOf([1]).verbose(), '[1]')
assert.equal(bytesOf([0]).verbose(), '[0]')
})
it('length is 8', function() {
assert.ok(bytesOf(5).verbose().startsWith('[0,0,0,0,0,0,0,5] = 5, or '))
assert.ok(bytesOf(7.3).verbose().includes(', or 7.3, or'))
assert.ok(bytesOf('abcdefgh').verbose().includes('abcdefgh'))
})
it('length is not 8', function() {
assert.ok(bytesOf('Hello, world!').verbose().includes('Hello, world!'))
assert.ok(bytesOf('some').verbose().includes('some'))
})
})
})
})
2 changes: 2 additions & 0 deletions eo2js/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
The MIT License (MIT)

Copyright (c) 2024 Objectionary.com

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
36 changes: 25 additions & 11 deletions eo2js/src/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,45 @@ const main = '__main__.js'

/**
* Data to insert to package.json file.
* @type {{author: string, name: string, version: string, dependencies: {}}}
* If path to local dependency is present - eo2js-runtime dependency won't be added to
* package.json file.
* @param {String} [runtime] - path to local eo-runtime dependency
* @return {{author: string, name: string, version: string}}
*/
const pckg = {
name: 'project',
version: '1.0.0',
author: 'eoc',
// dependencies: { todo
// 'eo2js-runtime': 'latest'
// },
const pckg = function(runtime) {
const def = {
name: 'project',
version: '1.0.0',
author: 'eoc'
}
if (!runtime) {
def.dependencies = {
'eo2js-runtime': 'latest'
}
}
return def
}

/**
* Build npm project.
* @param {{target: String, project: String, resources: String}} options - Program options
* @param {{target: String, project: String, resources: String, dependency: ?String}} options - Program options
*/
const link = function(options) {
options = {...program.opts(), ...options}
const project = path.resolve(options.target, options.project)
fs.writeFileSync(path.resolve(project, 'package.json'), JSON.stringify(pckg))
console.log(project)
fs.writeFileSync(path.resolve(project, 'package.json'), JSON.stringify(pckg(options.dependency)))
execSync('npm install', {cwd: project})
fs.copyFileSync(
path.resolve(options.resources, `js/${main}`),
path.resolve(project, main)
)
if (options.dependency) {
fs.cpSync(
options.dependency,
path.resolve(project, 'node_modules/eo2js-runtime'),
{recursive: true}
)
}
}

module.exports = link
8 changes: 4 additions & 4 deletions eo2js/src/commands/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {XMLParser} = require('fast-xml-parser');
* @return {String} - path from object name
*/
const pathFromName = function(name) {
return name.replace(/\./g, '/')
return name.replace(/\./g, path.sep)
}

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ const transpile = function(options) {
throw new Error(`File ${foreign} is not found`)
}
if (!foreign.endsWith('.json')) {
throw new Error(`Only .json foreign tojos file is supported, given ${foreign.substring(foreign.lastIndexOf('/'))}`)
throw new Error(`Only .json foreign tojos file is supported, given ${foreign.substring(foreign.lastIndexOf(path.sep))}`)
}
const transformations = [
'objects', 'package', 'attrs', 'data', 'to-js'
Expand All @@ -60,7 +60,7 @@ const transpile = function(options) {
const text = fs.readFileSync(tojo[verified]).toString()
let xml = parser.parse(text)
const transpiled = path.resolve(options['target'], dir, `${pathFromName(xml['program']['@_name'])}.xmir`)
makeDirIfNotExist(transpiled.substring(0, transpiled.lastIndexOf('/')))
makeDirIfNotExist(transpiled.substring(0, transpiled.lastIndexOf(path.sep)))
fs.writeFileSync(transpiled, text)
xml = text
transformations.forEach((transformation) => {
Expand All @@ -80,7 +80,7 @@ const transpile = function(options) {
if (filtered.length > 0) {
const first = filtered[0]
const dest = path.resolve(project, `${pathFromName(first['@_js-name'])}.js`)
makeDirIfNotExist(dest.substring(0, dest.lastIndexOf('/')))
makeDirIfNotExist(dest.substring(0, dest.lastIndexOf(path.sep)))
fs.writeFileSync(dest, first['javascript'])
filtered.slice(1).forEach((obj) => fs.appendFileSync(dest, `\n${obj['javascript']}`))
fs.appendFileSync(dest, exporting(first['@_name']))
Expand Down
1 change: 1 addition & 0 deletions eo2js/src/eo2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ program
.option('-t, --target <path>', 'Target directory with all generated files', '.eoc')
.option('-p, --project <path>', 'Path to result JavaScript project', 'project')
.option('-r, --resources <path>', 'Path to the resources', 'src/resources')
.option('-d --dependency <path>', 'Path to local eo2js-runtime dependency')
.option('--alone', 'Just run a single command without dependencies')
// .option('--hash <hex>', 'Hash in objectionary/home to compile against', parser)
// .option('--parser <version>', 'Set the version of EO parser to use', parser)
Expand Down
3 changes: 2 additions & 1 deletion eo2js/src/resources/js/__main__.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const phi = require('eo2js-runtime/src/runtime/phi')
const dataized = require('eo2js-runtime/src/runtime/dataized')
const bytesOf = require('eo2js-runtime/src/runtime/bytes-of')
const data = require('eo2js-runtime/src/runtime/data')
const ErAbstract = require('eo2js-runtime/src/runtime/error/ErAbstract')

Expand All @@ -20,7 +21,7 @@ const main = function() {
})
app = app.with({0: args})
}
console.log(dataized(app))
console.log(bytesOf(dataized(app)).verbose())
} catch (error) {
if (error instanceof ErAbstract) {
console.error(error.message)
Expand Down
Loading

0 comments on commit 6dcfa4b

Please sign in to comment.