-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
overhaul to validator, closer to being in line with current spec
- Loading branch information
Dave Herman
committed
Mar 10, 2013
1 parent
f8ac3bd
commit 182e4b9
Showing
11 changed files
with
1,119 additions
and
896 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,22 @@ | ||
var dict = require('dict'); | ||
var fail = require('./fail'); | ||
|
||
function Env() { | ||
function Env(v) { | ||
if (!(this instanceof Env)) | ||
return new Env(); | ||
this._frames = [dict()]; | ||
return new Env(v); | ||
this._v = v; | ||
this._dict = dict(); | ||
} | ||
|
||
Env.prototype.lookup = function lookup(x) { | ||
var a = this._frames, n = a.length, i = n - 1; | ||
while (i >= 0) { | ||
var frame = a[i]; | ||
if (frame.has(x)) | ||
return frame.get(x); | ||
i--; | ||
} | ||
return null; | ||
return this._dict.get(x) || null; | ||
}; | ||
|
||
Env.prototype.push = function push() { | ||
this._frames.push(dict()); | ||
}; | ||
|
||
Env.prototype.pop = function pop() { | ||
this._frames.pop(); | ||
}; | ||
|
||
Env.prototype.bind = function bind(x, t) { | ||
Env.prototype.bind = function bind(x, t, loc) { | ||
if (x === 'arguments' || x === 'eval') | ||
fail("illegal binding: '" + x + "'"); | ||
var frame = this._frames[this._frames.length - 1]; | ||
if (frame.has(x)) | ||
fail("duplicate binding: '" + x + "'"); | ||
frame.set(x, t); | ||
this._v.fail("illegal binding: '" + x + "'", loc); | ||
if (this._dict.has(x)) | ||
this._v.fail("duplicate binding for " + x, loc); | ||
this._dict.set(x, t); | ||
}; | ||
|
||
module.exports = Env; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var ty = require('./types'); | ||
|
||
function Report(globals, exports) { | ||
this._globals = globals; | ||
this._exports = exports; | ||
} | ||
|
||
Report.prototype.getFunction = function(f) { | ||
var global = this._globals.lookup(f); | ||
if (!global || !(global.type instanceof ty.Arrow)) | ||
return null; | ||
return global.type; | ||
}; | ||
|
||
Report.prototype.isSingleExport = function() { | ||
return this._exports.type === 'single'; | ||
}; | ||
|
||
// ( this.isSingleExport => () -> string) | ||
// (!this.isSingleExport => (string) -> string) | ||
Report.prototype.getExport = function(f) { | ||
return this._exports.type === 'single' | ||
? this._exports.export.name | ||
: this._exports.exports.lookup(f).name; | ||
}; | ||
|
||
module.exports = Report; |
Oops, something went wrong.