Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/github/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
robsimmons committed Nov 18, 2023
2 parents 2fba0f9 + 7f910e8 commit 33747c2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 16 deletions.
16 changes: 4 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dusa",
"version": "0.0.0",
"type": "module",
"main": "lib/engine/choiceengine.js",
"main": "lib/client.js",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
Expand Down Expand Up @@ -39,8 +39,5 @@
"typescript": "^5.0.2",
"vite": "^5.0.0",
"vitest": "^0.34.6"
},
"dependencies": {
"batsat": "^0.0.2"
}
}
65 changes: 65 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Data } from './datastructures/data';
import {
ChoiceTree,
ChoiceTreeNode,
Stats,
pathToString,
stepTreeRandomDFS,
} from './engine/choiceengine';
import { makeInitialDb } from './engine/forwardengine';
import { compile } from './langauge/compile';
import { parse } from './langauge/dusa-parser';
import { IndexedProgram } from './langauge/indexize';
import { check } from './langauge/syntax';
import { Issue } from './parsing/parser';

export type { Issue, Stats };
export type { SourcePosition, SourceLocation } from './parsing/source-location';

export class DusaError extends Error {
issues: Issue[];
constructor(issues: Issue[]) {
super();
this.issues = issues;
}
}

export class Dusa {
private program: IndexedProgram;
private debug: boolean;

constructor(source: string, debug = false) {
const parsed = parse(source);
if (parsed.errors !== null) {
throw new DusaError(parsed.errors);
}

const checked = check(parsed.document);
if (checked.errors !== null) {
throw checked.errors;
}

this.debug = debug;
this.program = compile(checked.decls, debug);
}

run() {
let tree: null | ChoiceTree = { type: 'leaf', db: makeInitialDb(this.program) };
let path: [ChoiceTreeNode, Data | 'defer'][] = [];
const stats: Stats = { cycles: 0, deadEnds: 0 };
for (;;) {
if (tree === null) return null;
if (this.debug) {
console.log(pathToString(tree, path));
}

const result = stepTreeRandomDFS(this.program, tree, path, stats);
tree = result.tree;
path = result.tree === null ? path : result.path;

if (result.solution) {
return stats;
}
}
}
}

0 comments on commit 33747c2

Please sign in to comment.