Skip to content

Commit

Permalink
Implement optimized Num.Str coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Nov 24, 2010
1 parent 923d289 commit 8e193aa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ public override Variable Get(Variable obj) {
}
}

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 {
Expand Down Expand Up @@ -1503,6 +1515,8 @@ static Kernel() {
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");
Expand Down

0 comments on commit 8e193aa

Please sign in to comment.