| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace CLRSharp
- {
- //栈上值类型,拆箱,装箱转换非常频繁,需要处理一下。
- //
- public class ValueOnStack
- {
- static Dictionary<Type, NumberType> typecode = null;
- public static NumberType GetTypeCode(Type type)
- {
- if (typecode == null)
- {
- typecode = new Dictionary<Type, NumberType>();
- //typecode[null] = 0;
- typecode[typeof(bool)] = NumberType.BOOL;
- typecode[typeof(sbyte)] = NumberType.SBYTE;
- typecode[typeof(byte)] = NumberType.BYTE;
- typecode[typeof(Int16)] = NumberType.INT16;
- typecode[typeof(UInt16)] = NumberType.UINT16;
- typecode[typeof(Int32)] = NumberType.INT32;
- typecode[typeof(UInt32)] = NumberType.UINT32;
- typecode[typeof(Int64)] = NumberType.INT64;
- typecode[typeof(UInt64)] = NumberType.UINT64;
- typecode[typeof(float)] = NumberType.FLOAT;
- typecode[typeof(double)] = NumberType.DOUBLE;
- typecode[typeof(IntPtr)] = NumberType.INTPTR;
- typecode[typeof(UIntPtr)] = NumberType.UINTPTR;
- typecode[typeof(decimal)] = NumberType.DECIMAL;
- typecode[typeof(char)] = NumberType.CHAR;
- }
- if (type.IsEnum) return NumberType.ENUM;
- NumberType t = NumberType.IsNotNumber;
- typecode.TryGetValue(type, out t);
- return t;
- }
- ////valuetype
- // public NumberType TypeOnDef;
- // public NumberOnStack TypeOnStack;
- // public IBox box;
- //public static IBox Make(ICLRType type)
- //{
- // return Make(type.TypeForSystem);
- //}
- public static VBox MakeVBox(ICLRType type)
- {
- return MakeVBox(type.TypeForSystem);
- }
- //public static IBox MakeBool(bool b)
- //{
- // BoxInt32 box = Make(NumberType.BOOL) as BoxInt32;
- // box.value = b ? 1 : 0;
- // return box;
- //}
- public static VBox MakeVBoxBool(bool b)
- {
- VBox box = MakeVBox(NumberType.BOOL);
- box.v32 = b ? 1 : 0;
- return box;
- }
- //public static IBox Make(System.Type type)
- //{
- // NumberType code = GetTypeCode(type);
- // return Make(code);
- //}
- public static VBox MakeVBox(System.Type type)
- {
- NumberType code = GetTypeCode(type);
- return MakeVBox(code);
- }
- //public static IBox Make(NumberType code)
- //{
- // switch (code)
- // {
- // case NumberType.BOOL:
- // case NumberType.SBYTE:
- // case NumberType.BYTE:
- // case NumberType.CHAR:
- // case NumberType.INT16:
- // case NumberType.UINT16:
- // case NumberType.INT32:
- // case NumberType.UINT32:
- // if (unusedInt32.Count > 0)
- // {
- // var b = unusedInt32.Dequeue();
- // b.type = code;
- // return b;
- // }
- // else
- // return new BoxInt32(code);
- // case NumberType.INT64:
- // case NumberType.UINT64:
- // if (unusedInt64.Count > 0)
- // {
- // var b = unusedInt64.Dequeue();
- // b.type = code;
- // return b;
- // }
- // else
- // return new BoxInt64(code);
- // case NumberType.FLOAT:
- // case NumberType.DOUBLE:
- // if (unusedIntFL.Count > 0)
- // {
- // var b = unusedIntFL.Dequeue();
- // b.type = code;
- // return b;
- // }
- // else
- // return new BoxDouble(code);
- // default:
- // return null;
- // }
- //}
- public static VBox MakeVBox(NumberType code)
- {
- switch (code)
- {
- case NumberType.BOOL:
- case NumberType.SBYTE:
- case NumberType.BYTE:
- case NumberType.CHAR:
- case NumberType.INT16:
- case NumberType.UINT16:
- case NumberType.INT32:
- case NumberType.UINT32:
- case NumberType.ENUM:
- if (unusedVBox.Count > 0)
- {
- var b = unusedVBox.Dequeue();
- b.typeStack = NumberOnStack.Int32;
- b.type = code;
- return b;
- }
- return new VBox(NumberOnStack.Int32, code);
- case NumberType.INT64:
- case NumberType.UINT64:
- if (unusedVBox.Count > 0)
- {
- var b = unusedVBox.Dequeue();
- b.typeStack = NumberOnStack.Int64;
- b.type = code;
- return b;
- }
- return new VBox(NumberOnStack.Int64, code);
- case NumberType.FLOAT:
- case NumberType.DOUBLE:
- if (unusedVBox.Count > 0)
- {
- var b = unusedVBox.Dequeue();
- b.typeStack = NumberOnStack.Double;
- b.type = code;
- return b;
- }
- return new VBox(NumberOnStack.Double, code);
- default:
- return null;
- }
- }
- //public static IBox Convert(IBox box, NumberType type)
- //{
- // switch (type)
- // {
- // case NumberType.BOOL:
- // case NumberType.SBYTE:
- // case NumberType.BYTE:
- // case NumberType.CHAR:
- // case NumberType.INT16:
- // case NumberType.UINT16:
- // case NumberType.INT32:
- // case NumberType.UINT32:
- // {
- // if (box is BoxInt32) return box;
- // BoxInt32 v32 = ValueOnStack.Make(type) as BoxInt32;
- // BoxInt64 b64 = box as BoxInt64;
- // BoxDouble bdb = box as BoxDouble;
- // if (b64 != null)
- // v32.value = (int)b64.value;
- // else
- // v32.value = (int)bdb.value;
- // return v32;
- // }
- // case NumberType.INT64:
- // case NumberType.UINT64:
- // {
- // if (box is BoxInt64) return box;
- // BoxInt64 v64 = ValueOnStack.Make(type) as BoxInt64;
- // BoxInt32 b32 = box as BoxInt32;
- // BoxDouble bdb = box as BoxDouble;
- // if (b32 != null)
- // v64.value = b32.value;
- // else
- // v64.value = (Int64)bdb.value;
- // return v64;
- // }
- // case NumberType.FLOAT:
- // case NumberType.DOUBLE:
- // {
- // if (box is BoxDouble) return box;
- // BoxDouble vdb = new BoxDouble(type);
- // BoxInt32 b32 = box as BoxInt32;
- // BoxInt64 b64 = box as BoxInt64;
- // if (b32 != null)
- // vdb.value = b32.value;
- // else
- // vdb.value = b64.value;
- // return vdb;
- // }
- // default:
- // return null;
- // }
- //}
- public static VBox Convert(VBox box, NumberType type)
- {
- VBox b = MakeVBox(type);
- b.Set(box);
- return b;
- }
- //public static Queue<IBox> unusedInt32 = new Queue<IBox>();
- //public static Queue<IBox> unusedInt64 = new Queue<IBox>();
- //public static Queue<IBox> unusedIntFL = new Queue<IBox>();
- public static Queue<VBox> unusedVBox = new Queue<VBox>();
- public static void UnUse(VBox box)
- {
- box.refcount = 0;
- unusedVBox.Enqueue(box);
- }
- //public static void UnUse(IBox box)
- //{
- // switch (box.typeStack)
- // {
- // case NumberOnStack.Int32:
- // unusedInt32.Enqueue(box);
- // break;
- // case NumberOnStack.Int64:
- // unusedInt64.Enqueue(box);
- // break;
- // case NumberOnStack.Double:
- // unusedIntFL.Enqueue(box);
- // break;
- // }
- //}
- }
- public enum NumberType
- {
- IsNotNumber = 0,
- SBYTE = 1,
- BYTE = 2,
- INT16 = 3,
- UINT16 = 4,
- INT32 = 5,
- UINT32 = 6,
- INT64 = 7,
- UINT64 = 8,
- FLOAT = 9,
- DOUBLE = 10,
- INTPTR = 11,
- UINTPTR = 12,
- DECIMAL = 13,
- CHAR = 14,
- BOOL = 15,
- ENUM = 16,
- };
- public enum NumberOnStack
- {
- Int32,
- Int64,
- Double,
- }
- public class VBox
- {
- public VBox(NumberOnStack typeStack, NumberType thistype)
- {
- this.typeStack = typeStack;
- this.type = thistype;
- }
- public VBox Clone()
- {
- VBox b = ValueOnStack.MakeVBox(this.type);
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- b.v32 = this.v32;
- break;
- case NumberOnStack.Int64:
- b.v64 = this.v64;
- break;
- case NumberOnStack.Double:
- b.vDF = this.v64;
- break;
- }
- return b;
- }
- public int refcount = 0;
- public NumberOnStack typeStack;
- public NumberType type;
- public Int32 v32;
- public Int64 v64;
- public Double vDF;
- public object BoxStack()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return v32;
- case NumberOnStack.Int64:
- return v64;
- case NumberOnStack.Double:
- return vDF;
- default:
- return null;
- }
- }
- public object BoxDefine()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- switch (type)
- {
- case NumberType.ENUM:
- return v32;
- case NumberType.BOOL:
- return (v32 > 0);
- case NumberType.SBYTE:
- return (sbyte)v32;
- case NumberType.BYTE:
- return (byte)v32;
- case NumberType.CHAR:
- return (char)v32;
- case NumberType.INT16:
- return (Int16)v32;
- case NumberType.UINT16:
- return (UInt16)v32;
- case NumberType.INT32:
- return (Int32)v32;
- case NumberType.UINT32:
- return (UInt32)v32;
- case NumberType.INT64:
- return (Int64)v32;
- case NumberType.UINT64:
- return (UInt64)v32;
- case NumberType.FLOAT:
- return (float)v32;
- case NumberType.DOUBLE:
- return (double)v32;
- default:
- return null;
- }
- case NumberOnStack.Int64:
- switch (type)
- {
- case NumberType.BOOL:
- return (v64 > 0);
- case NumberType.SBYTE:
- return (sbyte)v64;
- case NumberType.BYTE:
- return (byte)v64;
- case NumberType.CHAR:
- return (char)v64;
- case NumberType.INT16:
- return (Int16)v64;
- case NumberType.UINT16:
- return (UInt16)v64;
- case NumberType.INT32:
- return (Int32)v64;
- case NumberType.UINT32:
- return (UInt32)v64;
- case NumberType.INT64:
- return (Int64)v64;
- case NumberType.UINT64:
- return (UInt64)v64;
- case NumberType.FLOAT:
- return (float)v64;
- case NumberType.DOUBLE:
- return (double)v64;
- default:
- return null;
- }
- case NumberOnStack.Double:
- switch (type)
- {
- case NumberType.BOOL:
- return (vDF > 0);
- case NumberType.SBYTE:
- return (sbyte)vDF;
- case NumberType.BYTE:
- return (byte)vDF;
- case NumberType.CHAR:
- return (char)vDF;
- case NumberType.INT16:
- return (Int16)vDF;
- case NumberType.UINT16:
- return (UInt16)vDF;
- case NumberType.INT32:
- return (Int32)vDF;
- case NumberType.UINT32:
- return (UInt32)vDF;
- case NumberType.INT64:
- return (Int64)vDF;
- case NumberType.UINT64:
- return (UInt64)vDF;
- case NumberType.FLOAT:
- return (float)vDF;
- case NumberType.DOUBLE:
- return (double)vDF;
- default:
- return null;
- }
- default:
- return null;
- }
- }
- public void Add(VBox right)
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- v32 += right.v32;
- break;
- case NumberOnStack.Int64:
- v64 += right.v64;
- break;
- case NumberOnStack.Double:
- vDF += right.vDF;
- break;
- }
- }
- public void Sub(VBox right)
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- v32 -= right.v32;
- break;
- case NumberOnStack.Int64:
- v64 -= right.v64;
- break;
- case NumberOnStack.Double:
- vDF -= right.vDF;
- break;
- }
- }
- public void Mul(VBox right)
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- v32 *= right.v32;
- break;
- case NumberOnStack.Int64:
- v64 *= right.v64;
- break;
- case NumberOnStack.Double:
- vDF *= right.vDF;
- break;
- }
- }
- public void Div(VBox right)
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- v32 /= right.v32;
- break;
- case NumberOnStack.Int64:
- v64 /= right.v64;
- break;
- case NumberOnStack.Double:
- vDF /= right.vDF;
- break;
- }
- }
- public void Mod(VBox right)
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- v32 %= right.v32;
- break;
- case NumberOnStack.Int64:
- v64 %= right.v64;
- break;
- case NumberOnStack.Double:
- vDF %= right.vDF;
- break;
- }
- }
- //似乎Clone可以替代New系列
- public VBox Mod_New(VBox right)
- {
- VBox newbox = ValueOnStack.MakeVBox(type);
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- newbox.v32 = v32 % right.v32;
- break;
- case NumberOnStack.Int64:
- newbox.v64 = v64 % right.v64;
- break;
- case NumberOnStack.Double:
- newbox.vDF = vDF % right.vDF;
- break;
- }
- return newbox;
- }
- //SetValue
- public void SetDirect(object value)
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- if (value is bool)
- {
- v32 = ((bool)value) ? 1 : 0;
- }
- else
- {
- v32 = (int)value;
- }
- break;
- case NumberOnStack.Int64:
- v64 = (Int64)value;
- break;
- case NumberOnStack.Double:
- vDF = (double)Convert.ToDecimal(value);
- break;
- }
- }
- public void Set(VBox value)
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- if (value.typeStack == typeStack)
- v32 = value.v32;
- else
- v32 = value.ToInt();
- break;
- case NumberOnStack.Int64:
- if (value.typeStack == typeStack)
- v64 = value.v64;
- else
- v64 = value.ToInt64();
- break;
- case NumberOnStack.Double:
- if (value.typeStack == typeStack)
- vDF = value.vDF;
- else
- vDF = value.ToDouble();
- break;
- }
- }
- public bool logic_eq(VBox right)//=
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return v32 == right.v32;
- case NumberOnStack.Int64:
- return v64 == right.v64;
- case NumberOnStack.Double:
- return vDF == right.vDF;
- default:
- return false;
- }
- }
- public bool logic_ne(VBox right)//!=
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return v32 != right.v32;
- case NumberOnStack.Int64:
- return v64 != right.v64;
- case NumberOnStack.Double:
- return vDF != right.vDF;
- default:
- return false;
- }
- }
- public bool logic_ne_Un(VBox right)//!=
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (uint)v32 != (uint)right.v32;
- case NumberOnStack.Int64:
- return (UInt64)v64 != (UInt64)right.v64;
- case NumberOnStack.Double:
- return vDF != right.vDF;
- default:
- return false;
- }
- }
- public bool logic_ge(VBox right)//>=
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return v32 >= right.v32;
- case NumberOnStack.Int64:
- return v64 >= right.v64;
- case NumberOnStack.Double:
- return vDF >= right.vDF;
- default:
- return false;
- }
- }
- public bool logic_ge_Un(VBox right)//>=
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (uint)v32 >= (uint)right.v32;
- case NumberOnStack.Int64:
- return (UInt64)v64 >= (UInt64)right.v64;
- case NumberOnStack.Double:
- return vDF >= right.vDF;
- default:
- return false;
- }
- }
- public bool logic_le(VBox right)//<=
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return v32 <= right.v32;
- case NumberOnStack.Int64:
- return v64 <= right.v64;
- case NumberOnStack.Double:
- return vDF <= right.vDF;
- default:
- return false;
- }
- }
- public bool logic_le_Un(VBox right)
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (uint)v32 <= (uint)right.v32;
- case NumberOnStack.Int64:
- return (UInt64)v64 <= (UInt64)right.v64;
- case NumberOnStack.Double:
- return vDF <= right.vDF;
- default:
- return false;
- }
- }
- public bool logic_gt(VBox right)//>
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return v32 > right.v32;
- case NumberOnStack.Int64:
- return v64 > right.v64;
- case NumberOnStack.Double:
- return vDF > right.vDF;
- default:
- return false;
- }
- }
- public bool logic_gt_Un(VBox right)//>
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (uint)v32 > (uint)right.v32;
- case NumberOnStack.Int64:
- return (UInt64)v64 > (UInt64)right.v64;
- case NumberOnStack.Double:
- return vDF > right.vDF;
- default:
- return false;
- }
- }
- public bool logic_lt(VBox right)//<
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return v32 < right.v32;
- case NumberOnStack.Int64:
- return v64 < right.v64;
- case NumberOnStack.Double:
- return vDF < right.vDF;
- default:
- return false;
- }
- }
- public bool logic_lt_Un(VBox right)//<
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (uint)v32 < (uint)right.v32;
- case NumberOnStack.Int64:
- return (UInt64)v64 < (UInt64)right.v64;
- case NumberOnStack.Double:
- return vDF < right.vDF;
- default:
- return false;
- }
- }
- //////////////////////
- //To
- public bool ToBool()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return v32 > 0;
- case NumberOnStack.Int64:
- return v64 > 0;
- default:
- return false;
- }
- }
- public char ToChar()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (char)v32;
- case NumberOnStack.Int64:
- return (char)v64;
- case NumberOnStack.Double:
- return (char)vDF;
- default:
- return (char)0;
- }
- }
- public byte ToByte()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (byte)v32;
- case NumberOnStack.Int64:
- return (byte)v64;
- case NumberOnStack.Double:
- return (byte)vDF;
- default:
- return 0;
- }
- }
- public sbyte ToSByte()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (sbyte)v32;
- case NumberOnStack.Int64:
- return (sbyte)v64;
- case NumberOnStack.Double:
- return (sbyte)vDF;
- default:
- return 0;
- }
- }
- public Int16 ToInt16()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (Int16)v32;
- case NumberOnStack.Int64:
- return (Int16)v64;
- case NumberOnStack.Double:
- return (Int16)vDF;
- default:
- return 0;
- }
- }
- public UInt16 ToUInt16()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (UInt16)v32;
- case NumberOnStack.Int64:
- return (UInt16)v64;
- case NumberOnStack.Double:
- return (UInt16)vDF;
- default:
- return 0;
- }
- }
- public int ToInt()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (int)v32;
- case NumberOnStack.Int64:
- return (int)v64;
- case NumberOnStack.Double:
- return (int)vDF;
- default:
- return 0;
- }
- }
- public uint ToUInt()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (uint)v32;
- case NumberOnStack.Int64:
- return (uint)v64;
- case NumberOnStack.Double:
- return (uint)vDF;
- default:
- return 0;
- }
- }
- public Int64 ToInt64()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (Int64)v32;
- case NumberOnStack.Int64:
- return (Int64)v64;
- case NumberOnStack.Double:
- return (Int64)vDF;
- default:
- return 0;
- }
- }
- public UInt64 ToUInt64()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (UInt64)v32;
- case NumberOnStack.Int64:
- return (UInt64)v64;
- case NumberOnStack.Double:
- return (UInt64)vDF;
- default:
- return 0;
- }
- }
- public float ToFloat()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (float)v32;
- case NumberOnStack.Int64:
- return (float)v64;
- case NumberOnStack.Double:
- return (float)vDF;
- default:
- return 0;
- }
- }
- public double ToDouble()
- {
- switch (typeStack)
- {
- case NumberOnStack.Int32:
- return (double)v32;
- case NumberOnStack.Int64:
- return (double)v64;
- case NumberOnStack.Double:
- return (double)vDF;
- default:
- return 0;
- }
- }
- }
- //public interface IBox
- //{
- // object BoxStack();
- // object BoxDefine();
- // void Add(IBox right);
- // void Sub(IBox right);
- // void Mul(IBox right);
- // void Div(IBox right);
- // void Mod(IBox right);
- // IBox Mod_New(IBox right);
- // void SetDirect(object value);
- // void Set(IBox value);
- // NumberType type
- // {
- // get;
- // set;
- // }
- // NumberOnStack typeStack
- // {
- // get;
- // }
- // bool logic_eq(IBox right);//=
- // bool logic_ne(IBox right);//!=
- // bool logic_ne_Un(IBox right);//!=
- // bool logic_ge(IBox right);//>=
- // bool logic_ge_Un(IBox right);//>=
- // bool logic_le(IBox right);//<=
- // bool logic_le_Un(IBox right);
- // bool logic_gt(IBox right);//>
- // bool logic_gt_Un(IBox right);//>
- // bool logic_lt(IBox right);//<
- // bool logic_lt_Un(IBox right);//<
- // bool ToBool();
- // int ToInt();
- // uint ToUint();
- // Int64 ToInt64();
- // float ToFloat();
- // double ToDouble();
- // int refcount
- // {
- // get;
- // set;
- // }
- //}
- //public class BoxInt32 : IBox
- //{
- // public int refcount
- // {
- // get;
- // set;
- // }
- // public BoxInt32(NumberType type)
- // {
- // this.type = type;
- // }
- // public NumberType type
- // {
- // get;
- // set;
- // }
- // public NumberOnStack typeStack
- // {
- // get
- // {
- // return NumberOnStack.Int32;
- // }
- // }
- // public Int32 value;
- // public object BoxStack()
- // {
- // return value;
- // }
- // public object BoxDefine()
- // {
- // switch (type)
- // {
- // case NumberType.BOOL:
- // return (value > 0);
- // case NumberType.SBYTE:
- // return (sbyte)value;
- // case NumberType.BYTE:
- // return (byte)value;
- // case NumberType.CHAR:
- // return (char)value;
- // case NumberType.INT16:
- // return (Int16)value;
- // case NumberType.UINT16:
- // return (UInt16)value;
- // case NumberType.INT32:
- // return (Int32)value;
- // case NumberType.UINT32:
- // return (UInt32)value;
- // case NumberType.INT64:
- // return (Int64)value;
- // case NumberType.UINT64:
- // return (UInt64)value;
- // case NumberType.FLOAT:
- // return (float)value;
- // case NumberType.DOUBLE:
- // return (double)value;
- // default:
- // return null;
- // }
- // }
- // public void Set(IBox value)
- // {
- // this.value = (value as BoxInt32).value;
- // }
- // public void SetDirect(object value)
- // {
- // if (value is bool)
- // {
- // this.value = (bool)value ? 1 : 0;
- // }
- // else
- // {
- // this.value = (int)value;
- // }
- // }
- // public void Add(IBox right)
- // {
- // this.value += (right as BoxInt32).value;
- // }
- // public void Sub(IBox right)
- // {
- // this.value -= (right as BoxInt32).value;
- // }
- // public void Mul(IBox right)
- // {
- // this.value *= (right as BoxInt32).value;
- // }
- // public void Div(IBox right)
- // {
- // this.value /= (right as BoxInt32).value;
- // }
- // public void Mod(IBox right)
- // {
- // this.value %= (right as BoxInt32).value;
- // }
- // public IBox Mod_New(IBox right)
- // {
- // BoxInt32 b = ValueOnStack.Make(this.type) as BoxInt32;
- // b.value = this.value % (right as BoxInt32).value;
- // return b;
- // }
- // public bool logic_eq(IBox right)
- // {
- // return value == (right as BoxInt32).value;
- // }
- // public bool logic_ne(IBox right)
- // {
- // return value != (right as BoxInt32).value;
- // }
- // public bool logic_ne_Un(IBox right)
- // {
- // return (UInt32)value != (UInt32)(right as BoxInt32).value;
- // }
- // public bool logic_ge(IBox right)
- // {
- // return value >= (right as BoxInt32).value;
- // }
- // public bool logic_ge_Un(IBox right)
- // {
- // return (UInt32)value >= (UInt32)(right as BoxInt32).value;
- // }
- // public bool logic_le(IBox right)
- // {
- // return value <= (right as BoxInt32).value;
- // }
- // public bool logic_le_Un(IBox right)
- // {
- // return (UInt32)value <= (UInt32)(right as BoxInt32).value;
- // }
- // public bool logic_gt(IBox right)
- // {
- // return value > (right as BoxInt32).value;
- // }
- // public bool logic_gt_Un(IBox right)
- // {
- // return (UInt32)value > (UInt32)(right as BoxInt32).value;
- // }
- // public bool logic_lt(IBox right)
- // {
- // return value < (right as BoxInt32).value;
- // }
- // public bool logic_lt_Un(IBox right)
- // {
- // return (UInt32)value < (UInt32)(right as BoxInt32).value;
- // }
- // public bool ToBool()
- // {
- // return value > 0;
- // }
- // public int ToInt()
- // {
- // return (int)value;
- // }
- // public uint ToUint()
- // {
- // return (uint)value;
- // }
- // public Int64 ToInt64()
- // {
- // return (Int64)value;
- // }
- // public float ToFloat()
- // {
- // return (float)value;
- // }
- // public double ToDouble()
- // {
- // return (double)value;
- // }
- //}
- //public class BoxInt64 : IBox
- //{
- // public int refcount
- // {
- // get;
- // set;
- // }
- // public BoxInt64(NumberType type)
- // {
- // this.type = type;
- // }
- // public NumberType type
- // {
- // get;
- // set;
- // }
- // public NumberOnStack typeStack
- // {
- // get
- // {
- // return NumberOnStack.Int64;
- // }
- // }
- // public Int64 value;
- // public object BoxStack()
- // {
- // return value;
- // }
- // public object BoxDefine()
- // {
- // switch (type)
- // {
- // case NumberType.BOOL:
- // return (value > 0);
- // case NumberType.SBYTE:
- // return (sbyte)value;
- // case NumberType.BYTE:
- // return (byte)value;
- // case NumberType.CHAR:
- // return (char)value;
- // case NumberType.INT16:
- // return (Int16)value;
- // case NumberType.UINT16:
- // return (UInt16)value;
- // case NumberType.INT32:
- // return (Int32)value;
- // case NumberType.UINT32:
- // return (UInt32)value;
- // case NumberType.INT64:
- // return (Int64)value;
- // case NumberType.UINT64:
- // return (UInt64)value;
- // case NumberType.FLOAT:
- // return (float)value;
- // case NumberType.DOUBLE:
- // return (double)value;
- // default:
- // return null;
- // }
- // }
- // public void Set(IBox value)
- // {
- // this.value = (value as BoxInt64).value;
- // }
- // public void SetDirect(object value)
- // {
- // this.value = (Int64)value;
- // }
- // public void Add(IBox right)
- // {
- // this.value += (right as BoxInt64).value;
- // }
- // public void Sub(IBox right)
- // {
- // this.value -= (right as BoxInt64).value;
- // }
- // public void Mul(IBox right)
- // {
- // this.value *= (right as BoxInt64).value;
- // }
- // public void Div(IBox right)
- // {
- // this.value /= (right as BoxInt64).value;
- // }
- // public void Mod(IBox right)
- // {
- // this.value %= (right as BoxInt64).value;
- // }
- // public IBox Mod_New(IBox right)
- // {
- // BoxInt64 b = ValueOnStack.Make(this.type) as BoxInt64;
- // b.value = this.value % (right as BoxInt64).value;
- // return b;
- // }
- // public bool logic_eq(IBox right)
- // {
- // return value == (right as BoxInt64).value;
- // }
- // public bool logic_ne(IBox right)
- // {
- // return value != (right as BoxInt64).value;
- // }
- // public bool logic_ne_Un(IBox right)
- // {
- // return (UInt64)value != (UInt64)(right as BoxInt64).value;
- // }
- // public bool logic_ge(IBox right)
- // {
- // return value >= (right as BoxInt64).value;
- // }
- // public bool logic_ge_Un(IBox right)
- // {
- // return (UInt64)value >= (UInt64)(right as BoxInt64).value;
- // }
- // public bool logic_le(IBox right)
- // {
- // return value <= (right as BoxInt64).value;
- // }
- // public bool logic_le_Un(IBox right)
- // {
- // return (UInt64)value <= (UInt64)(right as BoxInt64).value;
- // }
- // public bool logic_gt(IBox right)
- // {
- // return value > (right as BoxInt64).value;
- // }
- // public bool logic_gt_Un(IBox right)
- // {
- // return (UInt64)value > (UInt64)(right as BoxInt64).value;
- // }
- // public bool logic_lt(IBox right)
- // {
- // return value < (right as BoxInt64).value;
- // }
- // public bool logic_lt_Un(IBox right)
- // {
- // return (UInt64)value < (UInt64)(right as BoxInt64).value;
- // }
- // public bool ToBool()
- // {
- // return value > 0;
- // }
- // public int ToInt()
- // {
- // return (int)value;
- // }
- // public uint ToUint()
- // {
- // return (uint)value;
- // }
- // public Int64 ToInt64()
- // {
- // return (Int64)value;
- // }
- // public float ToFloat()
- // {
- // return (float)value;
- // }
- // public double ToDouble()
- // {
- // return (double)value;
- // }
- //}
- //public class BoxDouble : IBox
- //{
- // public int refcount
- // {
- // get;
- // set;
- // }
- // public BoxDouble(NumberType type)
- // {
- // this.type = type;
- // }
- // public NumberType type
- // {
- // get;
- // set;
- // }
- // public NumberOnStack typeStack
- // {
- // get
- // {
- // return NumberOnStack.Double;
- // }
- // }
- // public double value;
- // public object BoxStack()
- // {
- // return value;
- // }
- // public object BoxDefine()
- // {
- // switch (type)
- // {
- // case NumberType.BOOL:
- // return (value > 0);
- // case NumberType.SBYTE:
- // return (sbyte)value;
- // case NumberType.BYTE:
- // return (byte)value;
- // case NumberType.CHAR:
- // return (char)value;
- // case NumberType.INT16:
- // return (Int16)value;
- // case NumberType.UINT16:
- // return (UInt16)value;
- // case NumberType.INT32:
- // return (Int32)value;
- // case NumberType.UINT32:
- // return (UInt32)value;
- // case NumberType.INT64:
- // return (Int64)value;
- // case NumberType.UINT64:
- // return (UInt64)value;
- // case NumberType.FLOAT:
- // return (float)value;
- // case NumberType.DOUBLE:
- // return (double)value;
- // default:
- // return null;
- // }
- // }
- // public void Set(IBox value)
- // {
- // this.value = (value as BoxDouble).value;
- // }
- // public void SetDirect(object value)
- // {
- // this.value = (double)Convert.ToDecimal(value);
- // }
- // public void Add(IBox right)
- // {
- // this.value += (right as BoxDouble).value;
- // }
- // public void Sub(IBox right)
- // {
- // this.value -= (right as BoxDouble).value;
- // }
- // public void Mul(IBox right)
- // {
- // this.value *= (right as BoxDouble).value;
- // }
- // public void Div(IBox right)
- // {
- // this.value /= (right as BoxDouble).value;
- // }
- // public void Mod(IBox right)
- // {
- // this.value %= (right as BoxDouble).value;
- // }
- // public IBox Mod_New(IBox right)
- // {
- // BoxDouble b = new BoxDouble(this.type);
- // b.value = this.value % (right as BoxDouble).value;
- // return b;
- // }
- // public bool logic_eq(IBox right)
- // {
- // return value == (right as BoxDouble).value;
- // }
- // public bool logic_ne(IBox right)
- // {
- // return value != (right as BoxDouble).value;
- // }
- // public bool logic_ne_Un(IBox right)
- // {
- // return value != (right as BoxDouble).value;
- // }
- // public bool logic_ge(IBox right)
- // {
- // return value >= (right as BoxDouble).value;
- // }
- // public bool logic_ge_Un(IBox right)
- // {
- // return value >= (right as BoxDouble).value;
- // }
- // public bool logic_le(IBox right)
- // {
- // return value <= (right as BoxDouble).value;
- // }
- // public bool logic_le_Un(IBox right)
- // {
- // return value <= (right as BoxDouble).value;
- // }
- // public bool logic_gt(IBox right)
- // {
- // return value > (right as BoxDouble).value;
- // }
- // public bool logic_gt_Un(IBox right)
- // {
- // return value > (right as BoxDouble).value;
- // }
- // public bool logic_lt(IBox right)
- // {
- // return value < (right as BoxDouble).value;
- // }
- // public bool logic_lt_Un(IBox right)
- // {
- // return value < (right as BoxDouble).value;
- // }
- // public bool ToBool()
- // {
- // throw new NotImplementedException();
- // }
- // public int ToInt()
- // {
- // return (int)value;
- // }
- // public uint ToUint()
- // {
- // return (uint)value;
- // }
- // public Int64 ToInt64()
- // {
- // return (Int64)value;
- // }
- // public float ToFloat()
- // {
- // return (float)value;
- // }
- // public double ToDouble()
- // {
- // return (double)value;
- // }
- //}
- }
|