Permalink
Browse files

Implement optimized Num.Str coercion

  • Loading branch information...
1 parent 923d289 commit 8e193aa75ba230bbc080f335a5ba6868705c7aaa @sorear committed Nov 24, 2010
Showing with 14 additions and 0 deletions.
  1. +14 −0 lib/Kernel.cs
View
@@ -445,6 +445,18 @@ class CtxBoolNativeDefined : ContextHandler<Variable> {
}
}
+ class CtxRawNativeNum2Str : ContextHandler<string> {
+ public override string Get(Variable obj) {
+ return ((double) Kernel.UnboxAny(obj.Fetch())).ToString();
+ }
+ }
+
+ class CtxStrNativeNum2Str : ContextHandler<Variable> {
+ public override Variable Get(Variable obj) {
+ return Kernel.BoxAnyMO(((double) Kernel.UnboxAny(obj.Fetch())).ToString(), Kernel.StrMO);
+ }
+ }
+
// NOT IP6; these things should only be exposed through a ClassHOW-like
// façade
public class DynMetaObject {
@@ -1503,6 +1515,8 @@ class ExitRunloopException : Exception { }
NumMO = new DynMetaObject("Num");
NumMO.loc_Numeric = new CtxReturnSelf();
NumMO.loc_raw_Numeric = new CtxJustUnbox<double>();
+ NumMO.loc_Str = new CtxStrNativeNum2Str();
+ NumMO.loc_raw_Str = new CtxRawNativeNum2Str();
NumMO.FillProtoClass(new string[] { "value" });
MuMO = new DynMetaObject("Mu");

0 comments on commit 8e193aa

Please sign in to comment.