Check-in [8e6fa743ee]
Not logged in
Overview
SHA1 Hash:8e6fa743ee49475969512fdd62b6424ecd77d001
Date: 2010-11-11 11:40:08
User: kinaba
Comment:added layered parameter AST (only AST. no parser and no evaluator).
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified polemy/ast.d from [b8324439b8512940] to [e950d5b14cc365fe].

62 { 62 { 63 AST fun; 63 AST fun; 64 AST[] args; 64 AST[] args; 65 this(immutable LexPosition pos, AST fun, AST[] args...) 65 this(immutable LexPosition pos, AST fun, AST[] args...) 66 { super(pos); this.fun=fun; this.args=args.dup; } 66 { super(pos); this.fun=fun; this.args=args.dup; } 67 mixin SimpleClass; 67 mixin SimpleClass; 68 } 68 } > 69 > 70 /// > 71 class Parameter > 72 { > 73 string name; > 74 string[] layers; > 75 mixin SimpleClass; > 76 } 69 77 70 /// 78 /// 71 class FunLiteral : AST 79 class FunLiteral : AST 72 { 80 { 73 string[] params; | 81 Parameter[] params; 74 AST funbody; | 82 AST funbody; 75 mixin SimpleClass; 83 mixin SimpleClass; 76 } 84 } 77 85 78 /// Handy Generator for AST nodes. To use this, mixin EasyAst; 86 /// Handy Generator for AST nodes. To use this, mixin EasyAst; 79 87 80 /*mixin*/ 88 /*mixin*/ 81 template EasyAST() 89 template EasyAST() ................................................................................................................................................................................ 82 { 90 { 83 /// 91 /// 84 template genEast(T) 92 template genEast(T) 85 { T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } 93 { T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } 86 94 87 alias genEast!StrLiteral strl; /// 95 alias genEast!StrLiteral strl; /// 88 alias genEast!IntLiteral intl; /// 96 alias genEast!IntLiteral intl; /// > 97 auto fun(string[] xs, AST ps) { > 98 return genEast!FunLiteral(array(map!((string x){return new Param 89 auto fun(string[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } /// | 99 auto funp(Parameter[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } 90 alias genEast!VarExpression var; /// 100 alias genEast!VarExpression var; /// 91 alias genEast!LayeredExpression lay; /// 101 alias genEast!LayeredExpression lay; /// 92 alias genEast!LetExpression let; /// 102 alias genEast!LetExpression let; /// 93 alias genEast!FuncallExpression call; /// 103 alias genEast!FuncallExpression call; /// 94 } 104 }

Modified polemy/eval.d from [ab3a0c217b77981b] to [9d70fd9339035713].

159 { 159 { 160 return new FunValue(delegate Value(immutable LexPosition pos, st 160 return new FunValue(delegate Value(immutable LexPosition pos, st 161 if( e.params.length != args.length ) 161 if( e.params.length != args.length ) 162 throw genex!RuntimeException(e.pos, sprintf!"Arg 162 throw genex!RuntimeException(e.pos, sprintf!"Arg 163 (e.params.length, args.length)); 163 (e.params.length, args.length)); 164 Table ctxNeo = new Table(ctx, Table.Kind.NotPropagateSet 164 Table ctxNeo = new Table(ctx, Table.Kind.NotPropagateSet 165 foreach(i,p; e.params) 165 foreach(i,p; e.params) 166 ctxNeo.set(p, lay, args[i]); | 166 ctxNeo.set(p.name, lay, args[i]); 167 return eval(e.funbody, ctxNeo, true, lay); 167 return eval(e.funbody, ctxNeo, true, lay); 168 }); 168 }); 169 } 169 } 170 throw genex!RuntimeException(_e.pos, sprintf!"Unknown Kind of Expression 170 throw genex!RuntimeException(_e.pos, sprintf!"Unknown Kind of Expression 171 } 171 } 172 172 173 unittest 173 unittest

Modified polemy/parse.d from [2739b95337ae2aab] to [fbe471845b86f859].

219 } 219 } 220 scope(exit) lex.popFront; 220 scope(exit) lex.popFront; 221 return new VarExpression(pos, lex.front.str); 221 return new VarExpression(pos, lex.front.str); 222 } 222 } 223 223 224 AST parseLambdaAfterOpenParen(immutable LexPosition pos) 224 AST parseLambdaAfterOpenParen(immutable LexPosition pos) 225 { 225 { 226 string[] params; | 226 Parameter[] params; 227 while( !tryEat(")") ) 227 while( !tryEat(")") ) 228 { 228 { 229 params ~= eatId("for function parameter"); | 229 params ~= new Parameter(eatId("for function parameter"), 230 if( !tryEat(",") ) { 230 if( !tryEat(",") ) { 231 eat(")", "after function parameters"); 231 eat(")", "after function parameters"); 232 break; 232 break; 233 } 233 } 234 } 234 } 235 eat("{", "after function parameters"); 235 eat("{", "after function parameters"); 236 auto funbody = Body(); 236 auto funbody = Body();