Skip to content

Commit

Permalink
Refactor to use updated spec
Browse files Browse the repository at this point in the history
  • Loading branch information
disnet committed Dec 27, 2016
1 parent 32990ae commit 647caa5
Show file tree
Hide file tree
Showing 118 changed files with 6,545 additions and 13,481 deletions.
2 changes: 1 addition & 1 deletion .babelrc
@@ -1,5 +1,5 @@
{
"presets": ["es2015-node5"],
"presets": ["node7"],
"plugins": ["transform-flow-strip-types"],
"sourceMaps": "inline"
}
2 changes: 2 additions & 0 deletions .flowconfig
@@ -1,4 +1,6 @@
[ignore]
build/*
dist/*

[include]

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "test/test262-parser-tests"]
path = test/test262-parser-tests
url = https://github.com/tc39/test262-parser-tests.git
5 changes: 2 additions & 3 deletions .travis.yml
@@ -1,5 +1,4 @@
language: node_js
node_js:
- "5"
- "6"
script: npm run test:full
- "7"
script: npm test
1 change: 1 addition & 0 deletions bin/sjs
Expand Up @@ -29,6 +29,7 @@ if (!semver.satisfies(process.version, '>=5.0.0')) {
argv._.forEach(function (file) {
var infile = fs.readFileSync(file, 'utf8');
var fdir = path.dirname(fs.realpathSync(file));
console.log(`compiling ${file}`);
var output = sweetjs.compile(infile, {
cwd: fdir,
noBabel: argv.noBabel,
Expand Down
25 changes: 7 additions & 18 deletions debug.js
@@ -1,28 +1,17 @@
'use strict';
/*
This file makes debugging sweet.js easier. Uses the built version of sweet.js
to compile "test.js". You can use node-inspector to step through the expansion
to compile 'test.js'. You can use node-inspector to step through the expansion
process:
npm install -g node-inspector
node-debug debug.js
*/

var compile = require("./build/src/sweet").compile;
var transform = require('babel-core').transform;
var moduleResolver = require('./build/src/node-module-resolver').default;
var moduleLoader = require('./build/src/node-module-loader').default;

var fs = require("fs");

var source = fs.readFileSync("./test.js", "utf8");
require('babel-register');
var compile = require('./src/sweet-loader.js').default;

debugger;
var result = compile(source, {
cwd: __dirname,
// transform: transform,
filename: './test.js',
moduleResolver: moduleResolver,
moduleLoader: moduleLoader,
enforcePragma: true
});
console.log(result.code);

let mod = compile('./test.js');
console.log(mod.codegen());
11 changes: 4 additions & 7 deletions mod.js
@@ -1,7 +1,4 @@
#lang "sweet.js";

// export var id = function (x) {
// return x;
// }

export syntax m = ctx => #`1`;
#lang 'base';
export function id(x) {
return x;
}
52 changes: 28 additions & 24 deletions package.json
Expand Up @@ -24,17 +24,15 @@
"scripts": {
"clean": "rm -rf build",
"lint": "eslint src && flow",
"prebuild": "npm run lint && mkdir -p build/test build/sweet dist/",
"prebuild": "mkdir -p build/test build/sweet dist/",
"build:src": "babel --out-dir build/src src",
"build:test": "rsync -R test/**/*.js build & cp test/*.js build/test && babel --out-file build/test/assertions.js test/assertions.js",
"build:browser": "webpack build/src/sweet.js --output-library-target amd --output-library sweet",
"build": "npm run build:src && npm run build:test",
"pretest": "npm run build",
"test:curr": "ava build/test/test_default_readtable.js",
"profile": "node --prof profile.js && node --prof-process *v8.log > v8-processed.log && rm *v8.log",
"build": "npm run build:src",
"test:curr": "ava build/test/modules/export.js",
"test:smoke": "ava build/test/*.js !build/test/assertions.js",
"test:full": "npm run build && ava",
"test": "npm run test:smoke",
"profile": "node --prof profile.js && node --prof-process *v8.log > v8-processed.log && rm *v8.log",
"test": "ava",
"report": "nyc ava && nyc report --reporter=html",
"docs": "asciidoctorjs doc/1.0/tutorial.adoc & asciidoctorjs doc/1.0/reference.adoc",
"dist": "npm run build && npm run build:browser && npm run docs && cp -r build/src/ dist"
Expand All @@ -43,11 +41,11 @@
"test": "test"
},
"dependencies": {
"sweet-spec": "1.1.0",
"babel-core": "^6.5.0",
"sweet-spec": "3.0.0-pre.0",
"babel-core": "^6.18.0",
"immutable": "^3.7.4",
"ramda": "^0.19.0",
"ramda-fantasy": "^0.4.1",
"ramda": "^0.22.0",
"ramda-fantasy": "^0.6.0",
"resolve": "^1.1.7",
"semver": "^5.3.0",
"shift-codegen": "^4.0.0",
Expand All @@ -61,17 +59,17 @@
"devDependencies": {
"asciidoctor-cli": "^1.5.2-alpha.3",
"asciidoctor.js": "^1.5.4",
"ava": "^0.15.0",
"babel": "^6.5.0",
"babel-cli": "^6.5.0",
"ava": "^0.17.0",
"babel-cli": "^6.18.0",
"babel-eslint": "^7.0.0",
"babel-plugin-transform-flow-strip-types": "^6.14.0",
"babel-preset-es2015-node5": "^1.2.0",
"babel-preset-node7": "1.4.0",
"babel-register": "6.18.0",
"eslint": "^3.7.1",
"eslint-plugin-flowtype": "^2.11.4",
"event-stream": "^3.3.2",
"expect.js": "0.3.x",
"flow-bin": "^0.32.0",
"flow-bin": "^0.36.0",
"nyc": "^6.0.0",
"source-map": "~0.5.3",
"source-map-support": "^0.4.0",
Expand All @@ -90,13 +88,19 @@
"ava": {
"babel": "inherit",
"files": [
"build/test/*.js",
"build/test/declaration/*.js",
"build/test/destructuring/**/*.js",
"build/test/expressions/**/*.js",
"build/test/modules/**/*.js",
"build/test/statements/**/*.js",
"!build/test/assertions.js"
]
"test/test-sweet-loader.js",
"test/test-run-test262.js",
"test/test-macro-expansion.js",
"test/test-hygiene.js",
"test/test-asi.js",
"test/test-modules.js",
"test/test-syntax.js",
"test/test-symbols.js",
"test/test-macro-context.js"
],
"require": [
"babel-register"
],
"babel": "inherit"
}
}
79 changes: 0 additions & 79 deletions src/apply-scope-in-params-reducer.js

This file was deleted.

29 changes: 20 additions & 9 deletions src/binding-map.js
@@ -1,24 +1,37 @@
// @flow
import { List } from "immutable";
import { assert } from "./errors";
import { Maybe } from 'ramda-fantasy';
import type { SymbolClass } from './symbol';
import Syntax from './syntax';

type Scopeset = any;

type ScopesetBinding = {
scopes: Scopeset;
binding: SymbolClass;
alias: Maybe<Syntax>
}

export default class BindingMap {
_map: Map<string, List<ScopesetBinding>>;

constructor() {
this._map = new Map();
}

// given a syntax object and a binding,
// add the binding to the map associating the binding with the syntax object's
// scope set
add(stx, { binding, phase, skipDup = false }) {
add(stx: Syntax, { binding, phase, skipDup = false }: { binding: SymbolClass, phase: number | {}, skipDup: boolean}) {
let stxName = stx.val();
let allScopeset = stx.scopesets.all;
let scopeset = stx.scopesets.phase.has(phase) ? stx.scopesets.phase.get(phase) : List();
scopeset = allScopeset.concat(scopeset);
assert(phase != null, "must provide a phase for binding add");

if (this._map.has(stxName)) {
let scopesetBindingList = this._map.get(stxName);
let scopesetBindingList = this._map.get(stxName);
if (scopesetBindingList) {
if (skipDup && scopesetBindingList.some(s => s.scopes.equals(scopeset))) {
return;
}
Expand All @@ -36,15 +49,15 @@ export default class BindingMap {
}
}

addForward(stx, forwardStx, binding, phase) {
addForward(stx: Syntax, forwardStx: Syntax, binding: SymbolClass, phase: number | {}) {
let stxName = stx.token.value;
let allScopeset = stx.scopesets.all;
let scopeset = stx.scopesets.phase.has(phase) ? stx.scopesets.phase.get(phase) : List();
scopeset = allScopeset.concat(scopeset);
assert(phase != null, "must provide a phase for binding add");

if (this._map.has(stxName)) {
let scopesetBindingList = this._map.get(stxName);
let scopesetBindingList = this._map.get(stxName);
if (scopesetBindingList) {
this._map.set(stxName, scopesetBindingList.push({
scopes: scopeset,
binding: binding,
Expand All @@ -60,9 +73,7 @@ export default class BindingMap {

}

// Syntax -> ?List<{ scopes: ScopeSet, binding: Binding }>
get(stx) {
get(stx: Syntax) {
return this._map.get(stx.token.value);
}

}
12 changes: 12 additions & 0 deletions src/codegen.js
@@ -0,0 +1,12 @@
import reduce from "shift-reducer";
import ParseReducer from "./parse-reducer";
import shiftCodegen, { FormattedCodeGen } from "shift-codegen";
import Term from "./terms";
import { List } from 'immutable';

export default function codegen(modTerm) {
// let ast = reduce(new ParseReducer({phase: 0}), modTerm);
return {
code: shiftCodegen(modTerm, new FormattedCodeGen())
};
}
5 changes: 1 addition & 4 deletions src/compiler.js
Expand Up @@ -23,9 +23,6 @@ export default class Compiler {
store: this.store
}));

return _.pipe(
_.bind(tokenExpander.expand, tokenExpander),
_.map(t => termExpander.expand(t))
)(stxl);
return tokenExpander.expand(stxl).map(t => termExpander.expand(t));
}
}

0 comments on commit 647caa5

Please sign in to comment.