Differences From Artifact [cd1c3d2598ac30ce]:
- File
polemy/eval.d
- 2010-11-23 18:28:47 - part of checkin [ba11f1d551] on branch trunk - fixed the macro scoping rules concerning non-macro let (user: kinaba) [annotate]
To Artifact [e0978d70034e5fac]:
- File
polemy/eval.d
- 2010-11-24 03:30:56 - part of checkin [20be503cae] on branch trunk - set up referece manual (user: kinaba) [annotate]
245 245 text("non-function ", _f, " is registered as the lift function for ", lay));
246 246 }
247 247
248 248 Value createNewFunction(Fun e, Table ctx)
249 249 {
250 250 class UserDefinedFunValue : FunValue
251 251 {
252 - Fun ast;
253 - Table defCtx;
252 + Fun ast;
253 + Table defCtx;
254 254 override const(Parameter[]) params() { return ast.params; }
255 - override Table definitionContext() { return defCtx; }
255 + override Table definitionContext() { return defCtx; }
256 256
257 257 this(Fun ast, Table defCtx) { this.ast=ast; this.defCtx=defCtx; }
258 258 override string toString() const { return sprintf!"(function:%x:%x)"(cast(void*)ast, cast(void*)defCtx); }
259 - override bool opEquals(Object rhs_) const /// member-by-member equality
260 - {
261 - if( auto rhs = cast(typeof(this))rhs_ )
262 - return this.ast==rhs.ast && this.defCtx==rhs.defCtx;
263 - assert(false, sprintf!"Cannot compare %s with %s"(typeid(this), typeid(rhs_)));
264 - }
265 - override hash_t toHash() const /// member-by-member hash
266 - {
267 - return typeid(this.ast).getHash(&this.ast) + typeid(this.defCtx).getHash(&this.defCtx);
259 + override int opCmp(Object rhs) {
260 + if(auto r = cast(UserDefinedFunValue)rhs) {
261 + if(auto i = this.ast.opCmp(r.ast))
262 + return i;
263 + return this.defCtx.opCmp(r.defCtx);
264 + }
265 + if(auto r = cast(Value)rhs) return typeid(this).opCmp(typeid(r));
266 + throw genex!RuntimeException("comparison with value and something other");
268 267 }
269 - override int opCmp(Object rhs_) /// member-by-member compare
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"(typeid(this), typeid(rhs_)));
278 - }
268 + mixin SimpleToHash;
279 269
270 + AST afterMacroAST;
280 271 override Value invoke(Layer lay, Table ctx, LexPosition pos)
281 272 {
282 273 if( isASTLayer(lay) )
283 274 return eval(ast.funbody, lay, ctx);
284 275 if( afterMacroAST is null )
285 276 {
286 277 auto va = macroAndEval(e.funbody, lay, ctx);
287 278 afterMacroAST = va[1];
288 279 return va[0];
289 280 }
290 281 else
291 282 return eval(afterMacroAST, lay, ctx);
292 283 }
293 -
294 - AST afterMacroAST;
295 284 }
296 285 return new UserDefinedFunValue(e,ctx);
297 286 }
298 287
299 288 public:
300 289 /// Add primitive function to the global context
301 290 void addPrimitive(R,T...)(string name, Layer defLay, R delegate (T) dg)
................................................................................
305 294 override const(Parameter[]) params() { return params_data; }
306 295 override Table definitionContext() { return theContext; }
307 296
308 297 override string toString() { return sprintf!"(native:%x)"(dg.funcptr); }
309 298 override int opCmp(Object rhs) {
310 299 if(auto r = cast(NativeFunValue)rhs) return typeid(typeof(dg)).compare(&dg,&r.dg);
311 300 if(auto r = cast(Value)rhs) return typeid(this).opCmp(typeid(r));
312 - throw genex!RuntimeException(LexPosition.dummy, "comparison with value and somithing other");
301 + throw genex!RuntimeException(LexPosition.dummy, "comparison with value and something other");
313 302 }
314 303 mixin SimpleToHash;
315 304
316 305 R delegate(T) dg;
317 306 Parameter[] params_data;
318 307
319 308 this(R delegate(T) dg)