Permalink
Browse files

Started changes to help typchecker doing typechecking

  • Loading branch information...
1 parent a771d1c commit 93126f9e80fa5d4083ff56d447887eb252122326 Mikael Bung committed May 26, 2010
Showing with 31 additions and 18 deletions.
  1. +12 −9 haskell.ast.js
  2. +1 −1 haskell.hiji.primitives.js
  3. +1 −1 haskell.interpreter.js
  4. +17 −7 haskell.parser.js
View
@@ -1,4 +1,4 @@
-(function(ast, interpreter, utilities) {
+(function(ast, interpreter, utilities, typechecker) {
expectType = utilities.expectType;
expectTypeOf = utilities.expectTypeOf;
@@ -422,7 +422,7 @@
/*
data Declaration = Variable Pattern Expression
| Function Identifier [Pattern] [(Guard, Expression)]|Expression
- | Data Identifier [Constructor]
+ | Data Identifier [TVar] [Constructor]
*/
ast.Declaration = function(){};
@@ -438,12 +438,14 @@
return this.pattern.stringify() + " = " + this.expression.stringify();
};
};
-
- ast.Data = function(identifier, constructors) {
+
+ ast.Data = function(identifier, tvars, constructors) {
expectTypeOf(identifier, "string");
+ expectTypeArray(tvars, typechecker.TVar);
expectTypeArray(constructors, ast.Constructor);
this.type = "Data";
this.identifier = identifier;
+ this.tvars = tvars;
this.constructors = constructors;
};
@@ -486,14 +488,15 @@
ast.Function.prototype = new ast.Declaration();
/*
- data Constructor = Constructor Identifier Integer
+ data Constructor = Constructor Identifier [Type]
*/
- ast.Constructor = function(identifier, num) {
+
+ ast.Constructor = function(identifier, types) {
expectTypeOf(identifier, "string");
- expectTypeOf(num, "number");
+ expectTypeArray(t, "number");
this.type = "Constructor";
this.identifier = identifier;
- this.number = num;
+ this.types = types;
};
/*
@@ -605,4 +608,4 @@
ast.Combined.prototype = new ast.Pattern();
ast.ConstantPattern.prototype = new ast.Pattern();
ast.Wildcard.prototype = new ast.Pattern();
-})(haskell.ast,haskell.interpreter, haskell.utilities);
+})(haskell.ast,haskell.interpreter, haskell.utilities, haskell.typechecker);
@@ -46,7 +46,7 @@
return env;
}));
- // hijiOutputLine# :: IO ()
+ // hijiOutputLine# :: a -> IO ()
env.bind("hijiOutputLine#", primitives.createPrimitive(env, 1,
function(env, args) {
var arg = args[0];
View
@@ -31,7 +31,7 @@
else if (decl.type=="Data") {
for (var i in decl.constructors) {
constr = decl.constructors[i];
- env.bind(constr.identifier, primitives.createDataConstructorKludge(env, constr.identifier, constr.number));
+ env.bind(constr.identifier, primitives.createDataConstructorKludge(env, constr.identifier, constr.types.length));
}
}
}
View
@@ -1,6 +1,6 @@
// The parser
-(function(parser, ast) {
+(function(parser, ast, typechecker) {
parser.lastInternalName = 0;
parser.generateInternalName = function() {
@@ -782,8 +782,8 @@
var constr_action = function(p) {
return action(p, function(ast) {
var name = ast[0];
- var count = ast[1].length;
- return new haskell.ast.Constructor(name, count);
+ var arguments = ast[1];
+ return new haskell.ast.Constructor(name, arguments);
});
};
@@ -840,14 +840,24 @@
"(->)",
sequence(ws('('), repeat1(ws(',')), ws(')'))
);
+
+
+
+
+
+ var atype_list_action = function(p) {
+ return action(p, function(ast) {
+ return new typechecker.TAp(new typechecker.TCon("([])", new typechecker.Kfun(new typechecker.Star(), new typechecker.Star())), ast[0]));
+ });
+ };
// redefinition
atype = choice( gtycon,
tyvar,
- sequence(ws('('), list(ws(type), ','), ws(')')),
- sequence(ws('['), ws(type), ws(']')),
- sequence(ws('('), ws(type), ws(')'))
+ sequence(expectws('('), list(ws(type), ws(',')), expectws(')')),
+ atype_list_action(sequence(expectws('['), ws(type), expectws(']'))),
+ sequence(expectws('('), ws(type), expectws(')'))
);
var btype = repeat1(ws(atype));
@@ -1353,4 +1363,4 @@
return result;
};
-})(haskell.parser, haskell.ast);
+})(haskell.parser, haskell.ast, haskell.typechecker);

0 comments on commit 93126f9

Please sign in to comment.