Browse Source

temp fix

master
wes 8 years ago
parent
commit
25056d788f
  1. 2
      server/assets/bundle.js
  2. 11
      server/desugar.js
  3. 9
      server/parse.js
  4. 118
      server/prelude.js
  5. 2
      server/tags/test.tag
  6. 1
      server/vm.js

2
server/assets/bundle.js

File diff suppressed because one or more lines are too long

11
server/desugar.js

@ -82,10 +82,11 @@ function desugar(stx, typeEnv) {
return new typ.If(desugar(stx.condition, typeEnv), desugar(stx.thenexp, typeEnv), desugar(stx.elseexp, typeEnv)); return new typ.If(desugar(stx.condition, typeEnv), desugar(stx.thenexp, typeEnv), desugar(stx.elseexp, typeEnv));
} }
return new typ.If(desugar(stx.condition, typeEnv), desugar(stx.thenexp, typeEnv)); return new typ.If(desugar(stx.condition, typeEnv), desugar(stx.thenexp, typeEnv));
case "FunctionDefinition": /* FIXME closures not yet working */
return desugarDefFunc(stx); //case "FunctionDefinition":
case "Definition": //return desugarDefFunc(stx);
return new typ.Def(stx.ident, desugar(stx.val, typeEnv)); //case "Definition":
//return new typ.Def(stx.ident, desugar(stx.val, typeEnv));
case "TypeDefinition": case "TypeDefinition":
return desugarDefType(stx, typeEnv); return desugarDefType(stx, typeEnv);
case "Name": case "Name":
@ -108,7 +109,7 @@ function desugar(stx, typeEnv) {
return sugarTypeDecl(stx); return sugarTypeDecl(stx);
} }
if ((stx.func.ident === "-" || stx.func.ident == "+") && if (false &&
stx.p && isAtomicNumber(stx.p)) { stx.p && isAtomicNumber(stx.p)) {
console.log("Matched unary"); console.log("Matched unary");
console.log(stx); console.log(stx);

9
server/parse.js

@ -651,6 +651,8 @@ function computeApp(tokens, charnum, linenum) {
var next; var next;
var result; var result;
var parameters; var parameters;
console.log("computing app");
console.log(tokens);
if (fst(tokens)) { if (fst(tokens)) {
next = fst(tokens); next = fst(tokens);
@ -660,7 +662,9 @@ function computeApp(tokens, charnum, linenum) {
lhs.charnum, lhs.charnum,
"Unexpected end of source"); "Unexpected end of source");
} }
if (typ.OPInfo[next[1]]) { if (typ.OPInfo[next[1]]) {
console.log("matched infix");
/* it's an infix expression */ /* it's an infix expression */
result = parseInfix(tokens, 1, lhs, lhs.linenum, lhs.charnum); result = parseInfix(tokens, 1, lhs, lhs.linenum, lhs.charnum);
if (!fst(tokens) || fst(tokens)[0] !== "right_paren") { if (!fst(tokens) || fst(tokens)[0] !== "right_paren") {
@ -726,6 +730,11 @@ function parseInfix(tokens, minPrec, lhs, linenum, charnum) {
tokens.pop(); tokens.pop();
/*remove the operator token*/ /*remove the operator token*/
var rhs = parseInfix(tokens, nextMinPrec); var rhs = parseInfix(tokens, nextMinPrec);
console.log("~~~~~~~~~~");
console.log(op);
console.log(lhs);
console.log(rhs);
console.log("~~~~~~~~~~");
lhs = addSrcPos(typ.makeApp(op, [lhs, rhs]), tokens, rhs.linenum, rhs.charnum); lhs = addSrcPos(typ.makeApp(op, [lhs, rhs]), tokens, rhs.linenum, rhs.charnum);
} }
return lhs; return lhs;

118
server/prelude.js

@ -2,8 +2,122 @@ var src = `
;; This file declares the various types used by intrinsic/prelude definitions ;; This file declares the various types used by intrinsic/prelude definitions
;; It is sort of special in that it doesn't care whether there are any associated definitions ;; It is sort of special in that it doesn't care whether there are any associated definitions
;; just that there are type definitions for that particular binding's name ;; just that there are type definitions for that particular binding's name
`;
export default {
;; Type definitions
deftype String (Vector Char)
deftype (Int) Intrinsic
deftype (Float) Intrinsic
deftype (Char) Intrinsic
deftype (Byte) Intrinsic
deftype (Void) 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))
deftype (Either a b)
((Left a) |
(Right b))
;; List functions
(: :: (a -> (List a) -> (List a)))
(map :: ((a -> b) -> (List a) -> (List b)))
(head :: ((List a) -> a))
(tail :: ((List a) -> (List a)))
(!! :: (Int -> (List a) -> a))
(take :: (Int -> (List a) -> (Maybe (List a))))
(drop :: (Int -> (List a) -> (Maybe (List a))))
;; Optional functions
(maybe :: (b -> (a -> b) -> (Maybe a) -> b))
(either :: ((b -> c) -> (b -> c) -> (Either a b) -> c))
;; I/O functions
(print :: (String -> (IO Void)))
;; Operator definitions
defop 1 Left (a + b)
(add a b)
defop 1 Left (a - b)
(minus a b)
defop 2 Left (a * b)
(mul a b)
defop 2 Left (a / b)
(div a b)
defop 2 Right (a ^ b)
(pow a b)
defop 3 Left (a ++ b)
(listConcat a b)
defop 3 Left (a == b)
(eq a b)
defop 3 Left (a > b)
(gt a b)
defop 3 Left (a >= b)
(gte a b)
defop 3 Left (a < b)
(lt a b)
defop 3 Left (a <= b)
(lte a b)
defop 3 Left (a && b)
(and a b)
defop 3 Left (a || b)
(or a b)
defop 4 Left (x : xs)
(cons x xs)
defop 5 Left (f $ x)
(fapply f x)
defop 5 Left (f . g)
(compose f g)
defop 3 Left (a | b)
(bitwiseOr a b)
defop 3 Left (a & b)
(bitwiseAnd a b)`;
module.exports = {
"src" : src "src" : src
}; };

2
server/tags/test.tag

@ -1,5 +1,7 @@
<test> <test>
<textarea <textarea
cols=40
rows=12
ref="input" ref="input"
type="text"> type="text">
</textarea> </textarea>

1
server/vm.js

@ -28,6 +28,7 @@ var testenv = env.makeEnv("toplevel",
function lookup(ident, env) { function lookup(ident, env) {
console.log(`trying to look up ${ident}`); console.log(`trying to look up ${ident}`);
var value = env.bindings[ident]; var value = env.bindings[ident];
console.log(env);
console.log(value); console.log(value);
if (value.exprType !== undefined) { if (value.exprType !== undefined) {
console.log("evaluting further"); console.log("evaluting further");

Loading…
Cancel
Save