Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Str.Bool and Hash.Bool context accelerators
  • Loading branch information
sorear committed Dec 4, 2010
1 parent 6157c41 commit d8c3188
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/Kernel.cs
Expand Up @@ -761,6 +761,11 @@ class CtxHashIterator : ContextHandler<VarDeque> {
return Builtins.HashIterRaw(3, obj);
}
}
class CtxHashBool : ContextHandler<bool> {
public override bool Get(Variable obj) {
return Kernel.UnboxAny<Dictionary<string,Variable>>(obj.Fetch()).Count != 0;
}
}

class CtxRawNativeDefined : ContextHandler<bool> {
public override bool Get(Variable obj) {
Expand All @@ -785,6 +790,12 @@ class CtxNum2Bool : ContextHandler<bool> {
}
}

class CtxStrBool : ContextHandler<bool> {
public override bool Get(Variable obj) {
return Kernel.UnboxAny<string>(obj.Fetch()) != "";
}
}

class CtxListBool : ContextHandler<bool> {
public override bool Get(Variable obj) {
IP6 o = obj.Fetch();
Expand Down Expand Up @@ -1912,18 +1923,20 @@ class ExitRunloopException : Exception { }
public static IP6 ProcessO;

static Kernel() {
StrMO = new DynMetaObject("Str");
StrMO.loc_Str = new CtxReturnSelf();
StrMO.loc_raw_Str = new CtxJustUnbox<string>();
StrMO.FillProtoClass(new string[] { });

BoolMO = new DynMetaObject("Bool");
BoolMO.loc_Bool = new CtxReturnSelf();
BoolMO.loc_raw_Bool = new CtxJustUnbox<bool>();
BoolMO.FillProtoClass(new string[] { });
TrueV = NewROScalar(BoxRaw<bool>(true, BoolMO));
FalseV = NewROScalar(BoxRaw<bool>(false, BoolMO));

StrMO = new DynMetaObject("Str");
StrMO.loc_Str = new CtxReturnSelf();
StrMO.loc_raw_Str = new CtxJustUnbox<string>();
StrMO.loc_raw_Bool = new CtxStrBool();
StrMO.loc_Bool = new CtxBoxify<bool>(StrMO.loc_raw_Bool, BoolMO);
StrMO.FillProtoClass(new string[] { });

NumMO = new DynMetaObject("Num");
NumMO.loc_Numeric = new CtxReturnSelf();
NumMO.loc_raw_Numeric = new CtxJustUnbox<double>();
Expand Down Expand Up @@ -1973,6 +1986,8 @@ class ExitRunloopException : Exception { }
HashMO.loc_raw_iterator = new CtxHashIterator();
HashMO.loc_at_key = new IxHashAtKey();
HashMO.loc_exists_key = new IxHashExistsKey();
HashMO.loc_raw_Bool = new CtxHashBool();
HashMO.loc_Bool = new CtxBoxify<bool>(HashMO.loc_raw_Bool, BoolMO);
HashMO.FillProtoClass(new string[] { });

AnyMO = new DynMetaObject("Any");
Expand Down

0 comments on commit d8c3188

Please sign in to comment.