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

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

159 159 { 160 160 return new FunValue(delegate Value(immutable LexPosition pos, string lay, Value[] args){ 161 161 if( e.params.length != args.length ) 162 162 throw genex!RuntimeException(e.pos, sprintf!"Argument Number Mismatch (%d required but %d given)" 163 163 (e.params.length, args.length)); 164 164 Table ctxNeo = new Table(ctx, Table.Kind.NotPropagateSet); 165 165 foreach(i,p; e.params) 166 - ctxNeo.set(p, lay, args[i]); 166 + ctxNeo.set(p.name, lay, args[i]); 167 167 return eval(e.funbody, ctxNeo, true, lay); 168 168 }); 169 169 } 170 170 throw genex!RuntimeException(_e.pos, sprintf!"Unknown Kind of Expression %s"(typeid(_e))); 171 171 } 172 172 173 173 unittest

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

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