| 1 |
/* |
| 2 |
Copyright(C) 2001-2002 arton |
| 3 |
|
| 4 |
Permission is granted for use, copying, modification, distribution, |
| 5 |
and distribution of modified versions of this work as long as the |
| 6 |
above copyright notice is included. |
| 7 |
*/ |
| 8 |
|
| 9 |
using System; |
| 10 |
using System.Collections; |
| 11 |
using System.Reflection; |
| 12 |
|
| 13 |
namespace arton.NETRuby |
| 14 |
{ |
| 15 |
public class QUndef |
| 16 |
{ |
| 17 |
private QUndef() |
| 18 |
{ |
| 19 |
} |
| 20 |
static QUndef val = new QUndef(); |
| 21 |
static QUndef Value |
| 22 |
{ |
| 23 |
get { return val; } |
| 24 |
} |
| 25 |
public override string ToString() |
| 26 |
{ |
| 27 |
return "Qundef"; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
public class RNil : RBasic, ICloneable |
| 32 |
{ |
| 33 |
internal RNil(NetRuby rb) |
| 34 |
: base(rb, rb.cObject) |
| 35 |
{ |
| 36 |
} |
| 37 |
public override bool IsSpecialConst |
| 38 |
{ |
| 39 |
get { return true; } |
| 40 |
} |
| 41 |
public override string ToString() |
| 42 |
{ |
| 43 |
return "nil"; |
| 44 |
} |
| 45 |
public override RArray ToArray() |
| 46 |
{ |
| 47 |
return new RArray(ruby, true); |
| 48 |
} |
| 49 |
public override RFloat ToFloat() |
| 50 |
{ |
| 51 |
return new RFloat(ruby, 0.0); |
| 52 |
} |
| 53 |
public override RInteger ToInteger() |
| 54 |
{ |
| 55 |
return new RFixnum(ruby, 0); |
| 56 |
} |
| 57 |
public override int id |
| 58 |
{ |
| 59 |
get { return Qnil; } |
| 60 |
} |
| 61 |
public override RMetaObject Class |
| 62 |
{ |
| 63 |
get { return ruby.cNilClass; } |
| 64 |
} |
| 65 |
public override object Inspect() |
| 66 |
{ |
| 67 |
return "nil"; |
| 68 |
} |
| 69 |
public override bool IsNil |
| 70 |
{ |
| 71 |
get { return true; } |
| 72 |
} |
| 73 |
public override object And(object o) |
| 74 |
{ |
| 75 |
return false; |
| 76 |
} |
| 77 |
public override object Or(object o) |
| 78 |
{ |
| 79 |
return RTest(o); |
| 80 |
} |
| 81 |
public override object Xor(object o) |
| 82 |
{ |
| 83 |
return RTest(o); |
| 84 |
} |
| 85 |
public object Clone() |
| 86 |
{ |
| 87 |
throw new eTypeError("can't clone nil"); |
| 88 |
} |
| 89 |
static internal object nil_to_s(RBasic r, params object[] args) |
| 90 |
{ |
| 91 |
return String.Empty; |
| 92 |
} |
| 93 |
internal void Init(NetRuby rb) |
| 94 |
{ |
| 95 |
BindingFlags bf = BindingFlags.InvokeMethod |
| 96 |
| BindingFlags.Static | BindingFlags.Public |
| 97 |
| BindingFlags.NonPublic | BindingFlags.FlattenHierarchy |
| 98 |
| BindingFlags.Instance; |
| 99 |
rb.cNilClass = rb.DefineClass("NilClass", rb.cObject); |
| 100 |
Type obj = typeof(RNil); |
| 101 |
rb.cNilClass.DefineMethod("to_i", obj.GetMethod("ToInteger", bf)); |
| 102 |
rb.cNilClass.DefineMethod("to_a", obj.GetMethod("ToArray", bf)); |
| 103 |
rb.cNilClass.DefineMethod("to_s", new RMethod(nil_to_s), 0); |
| 104 |
rb.cNilClass.DefineMethod("&", new RMethod(ruby_and), 1); |
| 105 |
rb.cNilClass.DefineMethod("|", new RMethod(ruby_or), 1); |
| 106 |
rb.cNilClass.DefineMethod("^", new RMethod(ruby_xor), 1); |
| 107 |
rb.cNilClass.DefineMethod("nil?", new RMethod(ruby_true), 0); |
| 108 |
|
| 109 |
rb.ClassOf(rb.cNilClass).UndefMethod("new"); |
| 110 |
rb.DefineGlobalConst("NIL", null); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
public class RTrue : RBool |
| 115 |
{ |
| 116 |
internal RTrue(NetRuby rb) : |
| 117 |
base(rb, true) |
| 118 |
{ |
| 119 |
} |
| 120 |
public override int id |
| 121 |
{ |
| 122 |
get { return Qtrue; } |
| 123 |
} |
| 124 |
public override string ToString() |
| 125 |
{ |
| 126 |
return "true"; |
| 127 |
} |
| 128 |
public override RMetaObject Class |
| 129 |
{ |
| 130 |
get { return ruby.cTrueClass; } |
| 131 |
} |
| 132 |
public override object Inspect() |
| 133 |
{ |
| 134 |
return "true"; |
| 135 |
} |
| 136 |
public override object And(object o) |
| 137 |
{ |
| 138 |
return RTest(o); |
| 139 |
} |
| 140 |
public override object Or(object o) |
| 141 |
{ |
| 142 |
return true; |
| 143 |
} |
| 144 |
public override object Xor(object o) |
| 145 |
{ |
| 146 |
return !RTest(o); |
| 147 |
} |
| 148 |
internal void Init(NetRuby rb) |
| 149 |
{ |
| 150 |
rb.cTrueClass = rb.DefineClass("TrueClass", rb.cObject); |
| 151 |
rb.cTrueClass.DefineMethod("&", new RMethod(ruby_and), 1); |
| 152 |
rb.cTrueClass.DefineMethod("|", new RMethod(ruby_or), 1); |
| 153 |
rb.cTrueClass.DefineMethod("^", new RMethod(ruby_xor), 1); |
| 154 |
rb.ClassOf(rb.cTrueClass).UndefMethod("new"); |
| 155 |
rb.DefineGlobalConst("TRUE", true); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
public class RFalse : RBool |
| 160 |
{ |
| 161 |
internal RFalse(NetRuby rb) : |
| 162 |
base(rb, false) |
| 163 |
{ |
| 164 |
} |
| 165 |
public override int id |
| 166 |
{ |
| 167 |
get { return Qfalse; } |
| 168 |
} |
| 169 |
public override string ToString() |
| 170 |
{ |
| 171 |
return "false"; |
| 172 |
} |
| 173 |
public override object Inspect() |
| 174 |
{ |
| 175 |
return "false"; |
| 176 |
} |
| 177 |
public override object And(object o) |
| 178 |
{ |
| 179 |
return false; |
| 180 |
} |
| 181 |
public override object Or(object o) |
| 182 |
{ |
| 183 |
return RTest(o); |
| 184 |
} |
| 185 |
public override object Xor(object o) |
| 186 |
{ |
| 187 |
return RTest(o); |
| 188 |
} |
| 189 |
internal void Init(NetRuby rb) |
| 190 |
{ |
| 191 |
rb.cFalseClass = rb.DefineClass("FalseClass", rb.cObject); |
| 192 |
rb.cFalseClass.DefineMethod("&", new RMethod(ruby_and), 1); |
| 193 |
rb.cFalseClass.DefineMethod("|", new RMethod(ruby_or), 1); |
| 194 |
rb.cFalseClass.DefineMethod("^", new RMethod(ruby_xor), 1); |
| 195 |
rb.ClassOf(rb.cFalseClass).UndefMethod("new"); |
| 196 |
rb.DefineGlobalConst("FALSE", false); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
public class RBool : RBasic, ICloneable |
| 201 |
{ |
| 202 |
internal RBool(NetRuby rb, bool f) |
| 203 |
: base(rb, rb.cObject) |
| 204 |
{ |
| 205 |
val = f; |
| 206 |
} |
| 207 |
bool val; |
| 208 |
public bool ToBool() |
| 209 |
{ |
| 210 |
return val; |
| 211 |
} |
| 212 |
public override bool IsSpecialConst |
| 213 |
{ |
| 214 |
get { return true; } |
| 215 |
} |
| 216 |
public object Clone() |
| 217 |
{ |
| 218 |
throw new eTypeError("can't clone Bool"); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
} |