/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> private int PutData(Variant val) { // 直近の20个の中で同じものがあるか调べる TODO 别コンパイルにするのなら、全データでチェックするようにした方がいいか int size = mDataArea.Count; int count = size > SEARCH_CONST_VAL_SIZE ? SEARCH_CONST_VAL_SIZE : size; int offset = size - 1; for (int i = 0; i < count; i++) { int pos = offset - i; if (mDataArea[pos].DiscernCompareStrictReal(val)) { return pos; } } Variant v; if (val.IsString()) { v = new Variant(TJS.MapGlobalStringMap(val.AsString())); } else { v = new Variant(val); object o = v.ToJavaObject(); if (o is InterCodeGenerator) { mInterCodeDataArea.AddItem(v); } } mDataArea.AddItem(v); return mDataArea.Count - 1; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public static object VariantToJavaObject(Variant param, Type type) { if (type.IsPrimitive) { // プリミティブタイプの场合 if (type.Equals(typeof(int))) { return Sharpen.Extensions.ValueOf(param.AsInteger()); } else { if (type.Equals(typeof(double))) { return (param.AsDouble()); } else { if (type.Equals(typeof(bool))) { return Sharpen.Extensions.ValueOf(param.AsInteger() != 0 ? true : false); } else { if (type.Equals(typeof(float))) { return ((float)param.AsDouble()); } else { if (type.Equals(typeof(long))) { return Sharpen.Extensions.ValueOf(param.AsInteger()); } else { if (type.Equals(typeof(char))) { return ((char)param.AsInteger()); } else { if (type.Equals(typeof(byte))) { return (unchecked((byte)param.AsInteger())); } else { if (type.Equals(typeof(short))) { return ((short)param.AsInteger()); } else { // may be Void.TYPE return null; } } } } } } } } } else { if (type.Equals(typeof(string))) { return param.AsString(); } else { if (type.Equals(typeof(ByteBuffer))) { return param.AsOctet(); } else { if (type.Equals(typeof(Variant))) { return param; } else { if (type.Equals(typeof(VariantClosure))) { return param.AsObjectClosure(); } else { if (type.Equals(typeof(Dispatch2))) { return param.AsObject(); } else { if (type.Equals(param.ToJavaObject().GetType())) { return param.ToJavaObject(); } else { // その他 のクラス return null; } } } } } } } }
public int PutVariant(Variant v, Compiler block) { object o = v.ToJavaObject(); int type = GetType(v); switch (type) { case TYPE_VOID: { return 0; } case TYPE_OBJECT: { // 常に0 VariantClosure clo = (VariantClosure)o; if (clo.mObject == null && clo.mObjThis == null) { return 0; } else { // null の VariantClosure は受け入れる return -1; } goto case TYPE_INTER_OBJECT; } case TYPE_INTER_OBJECT: { // その他は入れない。Dictionary と Array は保存できるようにした方がいいが…… VariantClosure clo = (VariantClosure)o; Dispatch2 dsp = clo.mObject; return block.GetObjectIndex((InterCodeObject)dsp); } case TYPE_STRING: { return PutString(((string)o)); } case TYPE_OCTET: { return PutByteBuffer((ByteBuffer)o); } case TYPE_REAL: { return PutDouble(((Number)o)); } case TYPE_BYTE: { return PutByte(((Number)o)); } case TYPE_SHORT: { return PutShort(((Number)o)); } case TYPE_INTEGER: { return PutInteger(((Number)o)); } case TYPE_LONG: { return PutLong(((Number)o)); } case TYPE_INTER_GENERATOR: { return block.GetCodeIndex((InterCodeGenerator)o); } case TYPE_UNKNOWN: { return -1; } } return -1; }
public byte GetType(Variant v) { object o = v.ToJavaObject(); if (o == null) { return TYPE_VOID; } else { if (o is string) { return TYPE_STRING; } else { if (o is int) { int val = ((int)o); if (val >= byte.MinValue && val <= byte.MaxValue) { return TYPE_BYTE; } else { if (val >= short.MinValue && val <= short.MaxValue) { return TYPE_SHORT; } else { return TYPE_INTEGER; } } } else { if (o is double) { return TYPE_REAL; } else { if (o is VariantClosure) { VariantClosure clo = (VariantClosure)o; Dispatch2 dsp = clo.mObject; if (dsp is InterCodeObject) { return TYPE_INTER_OBJECT; } else { return TYPE_OBJECT; } } else { if (o is InterCodeGenerator) { return TYPE_INTER_GENERATOR; } else { if (o is ByteBuffer) { return TYPE_OCTET; } else { if (o is long) { long val = ((long)o); if (val >= byte.MinValue && val <= byte.MaxValue) { return TYPE_BYTE; } else { if (val >= short.MinValue && val <= short.MaxValue) { return TYPE_SHORT; } else { if (val >= int.MinValue && val <= int.MaxValue) { return TYPE_INTEGER; } else { return TYPE_LONG; } } } } } } } } } } } return TYPE_UNKNOWN; }
private byte GetType(Variant v) { object o = v.ToJavaObject(); if (o == null) { return TYPE_VOID; } else { if (o is string) { return TYPE_STRING; } else { if (o is int) { return TYPE_INTEGER; } else { if (o is double) { return TYPE_REAL; } else { if (o is VariantClosure) { VariantClosure clo = (VariantClosure)o; Dispatch2 dsp = clo.mObject; if (dsp is InterCodeObject) { return TYPE_INTER_OBJECT; } else { if (dsp == null) { return TYPE_NULL_CLOSURE; } return TYPE_OBJECT; } } else { if (o is InterCodeGenerator) { return TYPE_INTER_GENERATOR; } else { if (o is ByteBuffer) { return TYPE_OCTET; } else { if (o is long) { return TYPE_INTEGER; } } } } } } } } return TYPE_UNKNOWN; }
/// <exception cref="Kirikiri.Tjs2.CompileException"></exception> private string GetDataToStrOrNum(Variant v) { object o = v.ToJavaObject(); if (o == null) { return "null"; } else { if (o is string) { return "\"" + (string)o + "\""; } else { if (o is int) { return ((int)o).ToString(); } else { if (o is double) { return ((double)o).ToString(); } else { if (o is VariantClosure) { throw new CompileException("非サポートの定数形式"); } else { if (o is InterCodeGenerator) { throw new CompileException("非サポートの定数形式"); } else { if (o is ByteBuffer) { throw new CompileException("非サポートの定数形式"); } else { if (o is long) { return ((long)o).ToString(); } } } } } } } } throw new CompileException("非サポートの定数形式"); }