Skip to content
Snippets Groups Projects
Commit 66adf7af authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Initial commit.

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 292 additions and 0 deletions
# Disable line-ending conversions for this repository.
* -text
# dependencies
/node_modules
# testing
/coverage
# production
/build
# environments
.env.local
.env.development.local
.env.test.local
.env.production.local
# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# misc
*~
.DS_Store
[submodule "eslint-config"]
path = eslint-config
url = git@git.unl.edu:soft-core/soft-260/eslint-config.git
Subproject commit a85278e2bd62f637800bc32fa6b372bc2855546e
This diff is collapsed.
{
"name": "@unlsoft/syntactic-monoids-in-class",
"version": "1.0.0",
"description": "Starter code for the class on syntactic monoids.",
"private": true,
"license": "UNLICENSED",
"scripts": {
"postinstall:eslint-config": "cd eslint-config && npm install",
"postinstall:app": "cd syntactic-monoids && npm install",
"postinstall": "run-s postinstall:**",
"lint:app": "cd syntactic-monoids && npm run lint",
"lint": "run-s --continue-on-error lint:**",
"test-once:quotes": "cd syntactic-monoids && npm run test-once:quotes",
"test-once:attributes": "cd syntactic-monoids && npm run test-once:attributes",
"test-once": "cd syntactic-monoids && npm run test-once",
"test": "run-s test-once"
},
"devDependencies": {
"ghooks": "^2.0.4",
"npm-run-all": "^4.1.5"
},
"config": {
"ghooks": {
"pre-commit": "npm run lint"
}
}
}
{
"folders": [
{
"path": "."
}
],
"settings": {
"files.eol": "\n",
"files.exclude": {
"**/node_modules": true
},
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true
}
}
# dependencies
/node_modules
# testing
/coverage
# production
/build
# environments
.env.local
.env.development.local
.env.test.local
.env.production.local
# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# misc
*~
.DS_Store
This diff is collapsed.
{
"name": "@unlsoft/syntactic-monoids",
"version": "1.0.0",
"description": "Starter code for the class on syntactic monoids.",
"type": "module",
"private": true,
"license": "UNLICENSED",
"scripts": {
"lint:js": "eslint --max-warnings 0 ./src",
"lint": "run-s --continue-on-error lint:**",
"test-once:quotes": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t \"the basic quotes monoid\"",
"test-once:attributes": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t \"the basic attributes monoid\"",
"test-once": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watchAll --coverage"
},
"dependencies": {
"npm-run-all": "^4.1.5"
},
"devDependencies": {
"@unlsoft/eslint-config": "file:../eslint-config",
"eslint": "^8.20.0",
"jest": "^29.5.0",
"jest-environment-node": "^29.5.0"
},
"eslintConfig": {
"extends": "@unlsoft"
},
"jest": {
"clearMocks": true,
"collectCoverageFrom": [
"src/**/*.js",
"!src/testing/**/*.js"
],
"resetMocks": false,
"restoreMocks": false,
"setupFilesAfterEnv": [
"./src/setupTests.js"
],
"testEnvironment": "./src/testing/failFast.js",
"transform": {}
},
"//": [
"See https://github.com/facebook/jest/issues/9430 for information on Jest+ES6."
]
}
// TODO: placeholder
const STATE_COUNT = 0;
class MonoidElement {
constructor(states) {
this.states = states;
}
get valid() {
return false; // TODO: stub
}
}
export const IDENTITY_ELEMENT = new MonoidElement([]); // TODO: placeholder
export function encodeAsMonoidElement(character) {
return IDENTITY_ELEMENT; // TODO: stub
}
export function combineMonoidElements(left, right) {
const states = [];
for (let i = 0; i < STATE_COUNT; ++i) {
states.push(right.states[left.states[i]]);
}
return new MonoidElement(states);
}
This diff is collapsed.
import { Worker } from 'worker_threads';
class ModuleWorker extends Worker {
constructor(path) {
const code = `import '${new URL(path, import.meta.url).href}';`;
super(new URL(`data:text/javascript,${encodeURIComponent(code)}`));
}
dispatch(data) {
this.postMessage(data);
return new Promise((resolve) => this.once('message', resolve));
}
}
function iterativeReduce(identityElement, combineMonoidElements, sequence) {
let result = identityElement;
for (const element of sequence) {
result = combineMonoidElements(result, element);
}
return result;
}
export async function parallelMapReduce(proceduresURL, sequence, workerCount) {
console.assert(workerCount > 0, `Cannot distribute work to a nonpositive (${workerCount}) number of threads.`);
const {
IDENTITY_ELEMENT,
combineMonoidElements,
} = await import(proceduresURL);
const workers = [...Array(workerCount)].map(() => new ModuleWorker('./worker.js'));
const jobs = workers.map((worker, workerIndex) => {
const low = Math.floor(workerIndex * sequence.length / workerCount);
const high = Math.floor((workerIndex + 1) * sequence.length / workerCount);
return worker.dispatch({
proceduresURL,
data: [...sequence.slice(low, high)],
});
});
const threadResults = (await Promise.all(jobs)).map(
(element) => Object.assign(Object.create(Object.getPrototypeOf(IDENTITY_ELEMENT)), element),
);
for (const worker of workers) {
worker.terminate();
}
return iterativeReduce(IDENTITY_ELEMENT, combineMonoidElements, threadResults);
}
This diff is collapsed.
// Extra imports for working around a V8 bug; see below.
import { SourceTextModule } from 'vm';
import { fileURLToPath } from 'url';
import { resolve, dirname } from 'path';
import { readFileSync } from 'fs';
import { jest } from '@jest/globals';
// This is included for consistency with `create-react-app`. It may be become
// unnecessary in future versions of Jest (see
// https://github.com/facebook/jest/issues/9430#issuecomment-616232029), but
// Jest may also choose to move away from magic globals and use imports instead,
// which are already opt-in (see https://github.com/facebook/jest/issues/4473).
globalThis.jest = jest;
// Work around <https://bugs.chromium.org/p/chromium/issues/detail?id=1244145>,
// a rather nasty bug in V8 where source code dynamically imported with
// host-defined options (see, e.g., the `options` parameter to
// <https://nodejs.org/api/vm.html#class-vmsourcetextmodule>) will be cached
// with only its source text as key so that later imports with different options
// are incorrectly treated as cache hits.
//
// Since Jest uses different options (see, e.g., `loadEsmModule` in
// `…/node_modules/jest-runtime/build/index.js`) for each test file, that means
// that while processing any test file after the first, `mapReduce.js` is still
// associated with an old test environment, and any attempts by it to
// dynamically import a monoid go through an environment that has been torn
// down. They therefore fail.
//
// Since `mapReduce.js` is unmocked and code under test, we don't need any of
// Jest's special import handling (e.g., support for mocking) in it or any of
// its imports, so here we preload `mapReduce.js` into V8's cache without any
// host-defined options. There are still false cache hits, but at least none of
// the cache entries are associated with a test environment.
//
// eslint-disable-next-line no-new
new SourceTextModule(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), 'mapReduce.js'), 'utf8'));
import jestEnvironmentNode from 'jest-environment-node';
export default class FailFastEnvironment extends jestEnvironmentNode.default {
constructor(...rest) {
super(...rest);
this.failed = false;
}
async handleTestEvent(event, state) {
switch (event.name) {
case 'hook_failure':
case 'test_fn_failure':
this.failed = true;
break;
case 'test_start':
if (this.failed) {
event.test.mode = 'skip';
}
break;
default:
}
if (super.handleTestEvent !== undefined) {
await super.handleTestEvent(event, state);
}
}
}
import { parentPort } from 'worker_threads';
function iterativeReduce(identityElement, combineMonoidElements, sequence) {
let result = identityElement;
for (const element of sequence) {
result = combineMonoidElements(result, element);
}
return result;
}
parentPort.on('message', async({ proceduresURL, data }) => {
const {
IDENTITY_ELEMENT,
encodeAsMonoidElement,
combineMonoidElements,
} = await import(proceduresURL);
parentPort.postMessage(iterativeReduce(IDENTITY_ELEMENT, combineMonoidElements, data.map(encodeAsMonoidElement)));
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment