Diff
Not logged in

Differences From Artifact [2bd159f2e71889e8]:

To Artifact [5c2f449580dd9555]:


73 73 if( auto fe = cast(FunValue)args[2] ) 74 74 return (x.data == 0 ? fe : ft).call(pos,lay,[]); 75 75 throw genex!RuntimeException(pos, "type mismatch in if"); 76 76 })); 77 77 ctx.set("_isint", "@v", native( (Value v){return new IntValue(BigInt(cast(IntValue)v is null ? 0 : 1));} )); 78 78 ctx.set("_isstr", "@v", native( (Value v){return new IntValue(BigInt(cast(StrValue)v is null ? 0 : 1));} )); 79 79 ctx.set("_isfun", "@v", native( (Value v){return new IntValue(BigInt(cast(FunValue)v is null ? 0 : 1));} )); 80 + ctx.set("_isundefined", "@v", native( (Value v){return new IntValue(BigInt(cast(UndValue)v is null ? 0 : 1));} )); 80 81 return ctx; 81 82 } 82 83 83 84 /// Entry point of this module 84 85 85 86 Tuple!(Value,"val",Table,"ctx") evalString(S,T...)(S str, T fn_ln_cn) 86 87 { ................................................................................ 161 162 args ~= eval(a, ctx, true, lay); 162 163 return f.call(e.pos, lay, args); 163 164 } 164 165 throw genex!RuntimeException(e.pos, "Non-funcion is applied"); 165 166 }, 166 167 (FunLiteral e) 167 168 { 169 + Value[Value[]][Layer] memo; 170 + 168 171 // funvalue need not be rised 172 + // no, need to be rised !! suppose @t(fib)("int") 169 173 return new FunValue(delegate Value(immutable LexPosition pos, string lay, Value[] args){ 174 + // TODO: only auto raised ones need memo? no? 175 + // auto memoization 176 + if( lay != "@v" ) 177 + { 178 + if( auto memolay = lay in memo ) 179 + if( auto pv = args in *memolay ) 180 + return *pv; 181 + memo[lay][args] = (cast(FunValue)ctx.get(lay, "(system)", e.pos)).call(e.pos, "@v", 182 + [new UndValue] 183 + ); 184 + } 185 + 170 186 if( e.params.length != args.length ) 171 187 throw genex!RuntimeException(e.pos, sprintf!"Argument Number Mismatch (%d required but %d given)" 172 188 (e.params.length, args.length)); 173 189 Table ctxNeo = new Table(ctx, Table.Kind.NotPropagateSet); 174 190 foreach(i,p; e.params) 175 191 ctxNeo.set(p.name, lay, args[i]); 176 - return eval(e.funbody, ctxNeo, true, lay); 192 + auto v = eval(e.funbody, ctxNeo, true, lay); 193 + // auto memoization 194 + if( lay != "@v" ) 195 + memo[lay][args] = v; 196 + return v; 177 197 }); 178 198 }, 179 199 delegate Value (AST e) 180 200 { 181 201 throw genex!RuntimeException(e.pos, sprintf!"Unknown Kind of Expression %s"(typeid(e))); 182 202 } 183 203 );