Browse Source

error handling for type applications

pull/8/head
nisstyre56 10 years ago
parent
commit
03dbefcdd9
  1. 1
      closure_conversion.js
  2. 5
      desugar.js
  3. 4
      parse.js
  4. 29
      representation.js

1
closure_conversion.js

@ -152,6 +152,7 @@ function test(src) {
}
//console.log(test(pprint.pprint(parser.parse(pprint.pprint(parser.parse("if something then if a then if b then c else d else rtrrt else some_other_thing")[0]))[0])));
console.log(pprint.pprint(parser.parse("(34 :: A)")[0]));
module.export = {
test : test,
closureConvert : closure_convert_all

5
desugar.js

@ -26,7 +26,6 @@ function desugarDefFunc(def) {
def.body));
}
function curryFunc(ps, body) {
if (_.isEmpty(ps)) {
return desugar(body);
@ -56,10 +55,6 @@ function desugar(stx) {
case "Name":
return stx;
case "Application":
if (stx.func.ident === "::") {
//It's a type binding
return desugarTypeBinding(stx);
}
if ((stx.func.ident === "-" ||
stx.func.ident === "+") &&
stx.p) {

4
parse.js

@ -639,5 +639,5 @@ module.exports = { parse : function(str) {
},
tokenize : tokenizer.tokenize
};
var istr = fs.readFileSync('/dev/stdin').toString();
console.log(parseFull(tokenizer.tokenize(istr)).map(pprint.pprint));
//var istr = fs.readFileSync('/dev/stdin').toString();
//console.log(parseFull(tokenizer.tokenize(istr)).map(pprint.pprint));

29
representation.js

@ -41,7 +41,9 @@ function LetExp(pairs, body) {
return (x.exprType === "Definition" ||
x.exprType === "FunctionDefinition");
})) {
throw "let can only be used to bind things to names or functions";
throw Errors.JInternalError(
"let can only be used to bind things to names or functions"
);
}
this.exprType = "Let";
this.val = [pairs, body];
@ -179,29 +181,28 @@ function TypeVar(name) {
TypeVar.prototype = TypeExpression;
function TypeOp(name, params, body) {
if (!_.every(params, _.compose(
_.partial(_.isEqual, "TypeVar"),
_.property("exprtype")))) {
throw errors.JInternalError(
"Parameters to a type operator must be type variables"
);
}
function TypeOp(name) {
this.name = name;
this.params = params;
this.body = body;
this.val = name;
this.exprType = "TypeOperator";
return this;
}
TypeOp.prototype = TypeExpression;
function TypeBinding(expression, type) {
function TypeApp(expression, type) {
if (expression.prototype.isTypeExpr) {
throw errors.JInternalError(
"Left-hand-side of type application must not be in the type language"
);
}
this.expr = expression;
this.type = type;
this.exprType = "TypeApplication";
return this;
}
TypeBinding.prototype = TypeExpression;
TypeApp.prototype = TypeExpression;
//Applies the function ``name'' to the list of parameters
function makeApp(name, parameters) {
@ -270,6 +271,6 @@ module.exports =
gensym : gensym,
TypeVar : TypeVar,
TypeOp : TypeOp,
TypeBinding : TypeBinding,
TypeApp: TypeApp,
Closure : Closure
};

Loading…
Cancel
Save