Browse Source

error handling for type applications

pull/8/head
nisstyre56 11 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(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 = { module.export = {
test : test, test : test,
closureConvert : closure_convert_all closureConvert : closure_convert_all

5
desugar.js

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

4
parse.js

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

29
representation.js

@ -41,7 +41,9 @@ function LetExp(pairs, body) {
return (x.exprType === "Definition" || return (x.exprType === "Definition" ||
x.exprType === "FunctionDefinition"); 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.exprType = "Let";
this.val = [pairs, body]; this.val = [pairs, body];
@ -179,29 +181,28 @@ function TypeVar(name) {
TypeVar.prototype = TypeExpression; TypeVar.prototype = TypeExpression;
function TypeOp(name, params, body) { function TypeOp(name) {
if (!_.every(params, _.compose(
_.partial(_.isEqual, "TypeVar"),
_.property("exprtype")))) {
throw errors.JInternalError(
"Parameters to a type operator must be type variables"
);
}
this.name = name; this.name = name;
this.params = params; this.val = name;
this.body = body; this.exprType = "TypeOperator";
return this; return this;
} }
TypeOp.prototype = TypeExpression; 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.expr = expression;
this.type = type; this.type = type;
this.exprType = "TypeApplication";
return this; return this;
} }
TypeBinding.prototype = TypeExpression; TypeApp.prototype = TypeExpression;
//Applies the function ``name'' to the list of parameters //Applies the function ``name'' to the list of parameters
function makeApp(name, parameters) { function makeApp(name, parameters) {
@ -270,6 +271,6 @@ module.exports =
gensym : gensym, gensym : gensym,
TypeVar : TypeVar, TypeVar : TypeVar,
TypeOp : TypeOp, TypeOp : TypeOp,
TypeBinding : TypeBinding, TypeApp: TypeApp,
Closure : Closure Closure : Closure
}; };

Loading…
Cancel
Save