Diff
Not logged in

Differences From Artifact [cd1c3d2598ac30ce]:

To Artifact [e0978d70034e5fac]:


245 text("non-function ", _f, " is registered as the lift fu 245 text("non-function ", _f, " is registered as the lift fu 246 } 246 } 247 247 248 Value createNewFunction(Fun e, Table ctx) 248 Value createNewFunction(Fun e, Table ctx) 249 { 249 { 250 class UserDefinedFunValue : FunValue 250 class UserDefinedFunValue : FunValue 251 { 251 { 252 Fun ast; | 252 Fun ast; 253 Table defCtx; | 253 Table defCtx; 254 override const(Parameter[]) params() { return ast.params 254 override const(Parameter[]) params() { return ast.params 255 override Table definitionContext() { return defCtx; } | 255 override Table definitionContext() { return defCtx; } 256 256 257 this(Fun ast, Table defCtx) { this.ast=ast; this.defCtx= 257 this(Fun ast, Table defCtx) { this.ast=ast; this.defCtx= 258 override string toString() const { return sprintf!"(func 258 override string toString() const { return sprintf!"(func 259 override bool opEquals(Object rhs_) const /// member-by- | 259 override int opCmp(Object rhs) { 260 { < > 260 if(auto r = cast(UserDefinedFunValue)rhs) { 261 if( auto rhs = cast(typeof(this))rhs_ ) | 261 if(auto i = this.ast.opCmp(r.ast)) 262 return this.ast==rhs.ast && this.defCtx= | 262 return i; 263 assert(false, sprintf!"Cannot compare %s with %s | 263 return this.defCtx.opCmp(r.defCtx); 264 } | 264 } 265 override hash_t toHash() const /// member-by-member hash | 265 if(auto r = cast(Value)rhs) return typeid(thi 266 { < 267 return typeid(this.ast).getHash(&this.ast) + typ < > 266 throw genex!RuntimeException("comparison with va 268 } 267 } 269 override int opCmp(Object rhs_) /// member-by-member com | 268 mixin SimpleToHash; 270 { < 271 if( auto rhs = cast(typeof(this))rhs_ ) < 272 { < 273 if(auto i = this.ast.opCmp(rhs.ast)) < 274 return i; < 275 return this.defCtx.opCmp(rhs.defCtx); < 276 } < 277 assert(false, sprintf!"Cannot compare %s with %s < 278 } < 279 269 > 270 AST afterMacroAST; 280 override Value invoke(Layer lay, Table ctx, LexPosition 271 override Value invoke(Layer lay, Table ctx, LexPosition 281 { 272 { 282 if( isASTLayer(lay) ) 273 if( isASTLayer(lay) ) 283 return eval(ast.funbody, lay, ctx); 274 return eval(ast.funbody, lay, ctx); 284 if( afterMacroAST is null ) 275 if( afterMacroAST is null ) 285 { 276 { 286 auto va = macroAndEval(e.funbody, lay, c 277 auto va = macroAndEval(e.funbody, lay, c 287 afterMacroAST = va[1]; 278 afterMacroAST = va[1]; 288 return va[0]; 279 return va[0]; 289 } 280 } 290 else 281 else 291 return eval(afterMacroAST, lay, ctx); 282 return eval(afterMacroAST, lay, ctx); 292 } 283 } 293 < 294 AST afterMacroAST; < 295 } 284 } 296 return new UserDefinedFunValue(e,ctx); 285 return new UserDefinedFunValue(e,ctx); 297 } 286 } 298 287 299 public: 288 public: 300 /// Add primitive function to the global context 289 /// Add primitive function to the global context 301 void addPrimitive(R,T...)(string name, Layer defLay, R delegate (T) dg) 290 void addPrimitive(R,T...)(string name, Layer defLay, R delegate (T) dg) ................................................................................................................................................................................ 305 override const(Parameter[]) params() { return params_dat 294 override const(Parameter[]) params() { return params_dat 306 override Table definitionContext() { return theContext 295 override Table definitionContext() { return theContext 307 296 308 override string toString() { return sprintf!"(native:%x) 297 override string toString() { return sprintf!"(native:%x) 309 override int opCmp(Object rhs) { 298 override int opCmp(Object rhs) { 310 if(auto r = cast(NativeFunValue)rhs) return type 299 if(auto r = cast(NativeFunValue)rhs) return type 311 if(auto r = cast(Value)rhs) return type 300 if(auto r = cast(Value)rhs) return type 312 throw genex!RuntimeException(LexPosition.dummy, | 301 throw genex!RuntimeException(LexPosition.dummy, 313 } 302 } 314 mixin SimpleToHash; 303 mixin SimpleToHash; 315 304 316 R delegate(T) dg; 305 R delegate(T) dg; 317 Parameter[] params_data; 306 Parameter[] params_data; 318 307 319 this(R delegate(T) dg) 308 this(R delegate(T) dg)