diff --git a/environments.js b/environments.js index 44558fc..d88426e 100644 --- a/environments.js +++ b/environments.js @@ -3,13 +3,14 @@ * with a few built-in (a standard Prelude environment) */ -// returns the new environment after mutating it -// values = [(identifier, JLambda expression)] - var errors = require("./errors.js"); var rep = require("./representation.js"); +/* + * returns the new environment after mutating it + * values = [(identifier, JLambda expression)] + */ function extend(env, values) { var new_env = {}; var env_keys = Object.keys(env); diff --git a/free_vars.js b/free_vars.js index da87a60..602c31d 100644 --- a/free_vars.js +++ b/free_vars.js @@ -1,4 +1,4 @@ -/* Takes an AST and converts all of the functions into closures. +/* Takes an AST and converts all of the functions into "closures" * A closure is a triple of: * the bound variables in a function or let * the free variables in a function or let @@ -19,10 +19,8 @@ */ var rep = require("./representation.js"); -var env = require("./environments.js"); var errors = require("./errors.js"); var parser = require("./parse.js"); -var pprint = require("./pprint.js"); var $ = require("./tools.js"); var _ = require("underscore"); @@ -106,6 +104,9 @@ function annotate_fvs(stx) { return new rep.Closure(bound_vars, free_variables, stx, []); } +/* + * This traverse the tree and gathers up all of the free variables of various functions/let bindings + */ function annotate_fvs_all(stx) { var closure; switch (stx.exprType) { diff --git a/parse.js b/parse.js index fa25ccb..2c4e23a 100755 --- a/parse.js +++ b/parse.js @@ -367,12 +367,17 @@ function parseDataType(tokens, linenum, charnum) { typeName.charnum, "Expected a type operator in data type definition"); } - parameters = parseMany(parse, + if (fst(tokens)[0] !== "right_paren") { + parameters = parseMany(parse, validName, validFormPar, tokens, charnum, linenum); + } + else { + parameters = []; + } if (!tokens || (fst(tokens)[0]) !== "right_paren") { throw error.JSyntaxError(_.last(parameters).linenum, _.last(parameters).charnum, @@ -402,7 +407,7 @@ function parseDefType(tokens, linenum, charnum) { } if (fst(tokens)[0] === "left_paren") { /* It's an actual data type definition - * i.e. not just a newtype + * i.e. not just an alias */ tokens.pop(); return parseDataType(tokens, linenum, charnum); @@ -424,7 +429,7 @@ function parseDefType(tokens, linenum, charnum) { if (lhs.exprType !== "TypeOperator") { throw error.JSyntaxError(lhs.linenum, lhs.charnum, - "left-hand side of type definition was not a type operator"); + "left-hand side of type alias was not a type operator"); } rhs = parse(tokens, linenum, charnum); @@ -432,7 +437,7 @@ function parseDefType(tokens, linenum, charnum) { rhs.exprType !== "TypeOperator") { throw error.JSyntaxError(rhs.linenum, rhs.charnum, - "was expecting an application or type operator on the right-hand side of a type definition"); + "was expecting an application or type operator on the right-hand side of a type alias"); } result = addSrcPos(new typ.DefType(lhs, rhs), tokens, rhs.linenum, rhs.charnum); return result; diff --git a/prelude.jl b/prelude.jl index 3fa12cc..1ed259f 100644 --- a/prelude.jl +++ b/prelude.jl @@ -4,24 +4,29 @@ ;; Type definitions -deftype String (A300 Char) +deftype String (Vector Char) -deftype Int Intrinsic +deftype (Int) Intrinsic -deftype Float Intrinsic +deftype (Float) Intrinsic -deftype Char Intrinsic +deftype (Char) Intrinsic -deftype Byte Intrinsic +deftype (Byte) Intrinsic -deftype Void Intrinsic +deftype (Void) Intrinsic -deftype IO Intrinsic +deftype (IO a) Intrinsic + +deftype (Vector a) Intrinsic deftype (List a) (Empty | (Cons a (List a))) +deftype (Bottom) + Undefined + deftype (Maybe a) (Nothing | (Just a)) diff --git a/representation.js b/representation.js index 0a80723..39c3543 100644 --- a/representation.js +++ b/representation.js @@ -368,28 +368,11 @@ function makeGensym() { var gensym = makeGensym(); -//console.log(isTypeExpr(new Name("T"))); - OPInfo = { - /*"+" : [3, "Left"], - "-" : [3, "Left"], - "*" : [4, "Left"], - "/" : [4, "Left"], - "^" : [5, "Right"] - "++" : [3, "Left"], - "==" : [2, "Left"], - ">" : [2, "Left"], - ">=" : [2, "Left"], - "<" : [2, "Left"], - "<=" : [2, "Left"], - "&&" : [2, "Left"], - "||" : [2, "Left"],*/ "::" : [2, "Left"], - /*":" : [1, "Left"], - "$" : [1, "Left"], - "." : [1, "Left"],*/ "," : [1, "Left"], - "->" : [1, "Right"]}; + "->" : [1, "Right"] + }; module.exports = { diff --git a/typecheck.js b/typecheck.js index 7c198c6..e105e94 100644 --- a/typecheck.js +++ b/typecheck.js @@ -13,7 +13,7 @@ var rep = require("./representation.js"); var env = require("./environments.js"); -var TypeOp = rep.TypeOp; -var TypeVar = rep.TypeVar; - - +/* + * Map all bindings with explicit type annotations in the environment + */ +function gather_annotations(stx) {