public override ScriptObject Compute(Scorpio.Compiler.TokenType type, ScriptObject obj) { ScriptNumber number = obj as ScriptNumber; if (number == null) { throw new ExecutionException(base.m_Script, this, "逻辑计算 右边值必须为数字类型"); } Scorpio.Compiler.TokenType type2 = type; if (type2 != Scorpio.Compiler.TokenType.Plus) { switch (type2) { case Scorpio.Compiler.TokenType.Multiply: return(new ScriptNumberDouble(base.m_Script, this.m_Value * number.ToDouble())); case Scorpio.Compiler.TokenType.Divide: return(new ScriptNumberDouble(base.m_Script, this.m_Value / number.ToDouble())); case Scorpio.Compiler.TokenType.Modulo: return(new ScriptNumberDouble(base.m_Script, this.m_Value % number.ToDouble())); case Scorpio.Compiler.TokenType.Minus: return(new ScriptNumberDouble(base.m_Script, this.m_Value - number.ToDouble())); } } else { return(new ScriptNumberDouble(base.m_Script, this.m_Value + number.ToDouble())); } throw new ExecutionException(base.m_Script, this, "Double不支持的运算符 " + type); }
public override ScriptObject AssignCompute(Scorpio.Compiler.TokenType type, ScriptObject obj) { ScriptNumber number = obj as ScriptNumber; if (number == null) { throw new ExecutionException(base.m_Script, this, "赋值逻辑计算 右边值必须为数字类型"); } switch (type) { case Scorpio.Compiler.TokenType.AssignMinus: this.m_Value -= number.ToDouble(); return(this); case Scorpio.Compiler.TokenType.AssignMultiply: this.m_Value *= number.ToDouble(); return(this); case Scorpio.Compiler.TokenType.AssignDivide: this.m_Value /= number.ToDouble(); return(this); case Scorpio.Compiler.TokenType.AssignModulo: this.m_Value = this.m_Value % number.ToDouble(); return(this); case Scorpio.Compiler.TokenType.AssignPlus: this.m_Value += number.ToDouble(); return(this); } throw new ExecutionException(base.m_Script, this, "Double不支持的运算符 " + type); }
public override ScriptObject AssignCompute(Scorpio.Compiler.TokenType type, ScriptObject value) { if (type != Scorpio.Compiler.TokenType.AssignPlus) { return(base.AssignCompute(type, value)); } ScriptTable table = value as ScriptTable; if (table == null) { throw new ExecutionException(base.m_Script, this, "table [+=] 操作只限两个[table]之间,传入数据类型:" + value.Type); } ScriptObject obj2 = null; ScriptScriptFunction function = null; foreach (KeyValuePair <object, ScriptObject> pair in table.m_listObject) { obj2 = pair.Value.Clone(); if (obj2 is ScriptScriptFunction) { function = (ScriptScriptFunction)obj2; if (!function.IsStaticFunction) { function.SetTable(this); } } this.m_listObject[pair.Key] = obj2; } return(this); }
public override ScriptObject AssignCompute(Scorpio.Compiler.TokenType type, ScriptObject obj) { if (type != Scorpio.Compiler.TokenType.AssignPlus) { throw new ExecutionException(base.m_Script, this, "String类型 操作符[" + type + "]不支持"); } this.m_Value = this.m_Value + obj.ToString(); return(this); }
public static List <Token> Deserialize(byte[] data) { List <Token> list = new List <Token>(); using (MemoryStream stream = new MemoryStream(data)) { using (BinaryReader reader = new BinaryReader(stream)) { reader.ReadSByte(); int num = reader.ReadInt32(); int num2 = 0; for (int i = 0; i < num; i++) { sbyte num4 = reader.ReadSByte(); if (num4 == LineFlag) { num2 = reader.ReadInt32(); num4 = reader.ReadSByte(); } Scorpio.Compiler.TokenType tokenType = (Scorpio.Compiler.TokenType)num4; object lexeme = null; switch (tokenType) { case Scorpio.Compiler.TokenType.Boolean: lexeme = reader.ReadSByte() == 1; goto Label_00DC; case Scorpio.Compiler.TokenType.Number: if (reader.ReadSByte() != 1) { break; } lexeme = reader.ReadDouble(); goto Label_00DC; case Scorpio.Compiler.TokenType.String: case Scorpio.Compiler.TokenType.SimpleString: lexeme = Util.ReadString(reader); goto Label_00DC; case Scorpio.Compiler.TokenType.Identifier: lexeme = Util.ReadString(reader); goto Label_00DC; default: lexeme = tokenType.ToString(); goto Label_00DC; } lexeme = reader.ReadInt64(); Label_00DC: list.Add(new Token(tokenType, lexeme, num2 - 1, 0)); } } } return(list); }
private ScriptObject ParseOperate(CodeOperator operate) { Scorpio.Compiler.TokenType @operator = operate.Operator; ScriptObject obj2 = this.ResolveOperand(operate.Left); switch (@operator) { case Scorpio.Compiler.TokenType.Plus: { ScriptObject obj3 = this.ResolveOperand(operate.Right); if ((obj2 is ScriptString) || (obj3 is ScriptString)) { return(new ScriptString(this.m_script, obj2.ToString() + obj3.ToString())); } return(obj2.Compute(@operator, obj3)); } case Scorpio.Compiler.TokenType.Minus: case Scorpio.Compiler.TokenType.Multiply: case Scorpio.Compiler.TokenType.Divide: case Scorpio.Compiler.TokenType.Modulo: case Scorpio.Compiler.TokenType.InclusiveOr: case Scorpio.Compiler.TokenType.Combine: case Scorpio.Compiler.TokenType.XOR: case Scorpio.Compiler.TokenType.Shi: case Scorpio.Compiler.TokenType.Shr: return(obj2.Compute(@operator, this.ResolveOperand(operate.Right))); case Scorpio.Compiler.TokenType.Or: if (!obj2.LogicOperation()) { return(this.m_script.CreateBool(this.ResolveOperand(operate.Right).LogicOperation())); } return(this.m_script.True); case Scorpio.Compiler.TokenType.And: if (obj2.LogicOperation()) { return(this.m_script.CreateBool(this.ResolveOperand(operate.Right).LogicOperation())); } return(this.m_script.False); case Scorpio.Compiler.TokenType.Equal: return(this.m_script.CreateBool(obj2.Equals(this.ResolveOperand(operate.Right)))); case Scorpio.Compiler.TokenType.NotEqual: return(this.m_script.CreateBool(!obj2.Equals(this.ResolveOperand(operate.Right)))); case Scorpio.Compiler.TokenType.Greater: case Scorpio.Compiler.TokenType.GreaterOrEqual: case Scorpio.Compiler.TokenType.Less: case Scorpio.Compiler.TokenType.LessOrEqual: return(this.m_script.CreateBool(obj2.Compare(@operator, this.ResolveOperand(operate.Right)))); } throw new ExecutionException(this.m_script, "不支持的运算符 " + @operator); }
public override ScriptObject Compute(Scorpio.Compiler.TokenType type, ScriptObject obj) { ScorpioMethod computeMethod = this.m_UserdataType.GetComputeMethod(type); if (computeMethod == null) { throw new ExecutionException(base.m_Script, "找不到运算符重载 " + type); } return(base.m_Script.CreateObject(computeMethod.Call(new ScriptObject[] { this, obj }))); }
public override ScriptObject AssignCompute(Scorpio.Compiler.TokenType type, ScriptObject obj) { ScriptNumber number = obj as ScriptNumber; if (number == null) { throw new ExecutionException(base.m_Script, this, "赋值逻辑计算 右边值必须为数字类型"); } switch (type) { case Scorpio.Compiler.TokenType.AssignShi: this.m_Value = this.m_Value << number.ToInt32(); return(this); case Scorpio.Compiler.TokenType.AssignShr: this.m_Value = this.m_Value >> number.ToInt32(); return(this); case Scorpio.Compiler.TokenType.AssignXOR: this.m_Value ^= number.ToLong(); return(this); case Scorpio.Compiler.TokenType.AssignCombine: this.m_Value &= number.ToLong(); return(this); case Scorpio.Compiler.TokenType.AssignMinus: this.m_Value -= number.ToLong(); return(this); case Scorpio.Compiler.TokenType.AssignMultiply: this.m_Value *= number.ToLong(); return(this); case Scorpio.Compiler.TokenType.AssignDivide: this.m_Value /= number.ToLong(); return(this); case Scorpio.Compiler.TokenType.AssignModulo: this.m_Value = this.m_Value % number.ToLong(); return(this); case Scorpio.Compiler.TokenType.AssignInclusiveOr: this.m_Value |= number.ToLong(); return(this); case Scorpio.Compiler.TokenType.AssignPlus: this.m_Value += number.ToLong(); return(this); } throw new ExecutionException(base.m_Script, this, "Long不支持的运算符 " + type); }
public override ScriptObject Compute(Scorpio.Compiler.TokenType type, ScriptObject obj) { Scorpio.Compiler.TokenType type2 = type; if (type2 != Scorpio.Compiler.TokenType.Plus) { if (type2 != Scorpio.Compiler.TokenType.Minus) { throw new ExecutionException(base.m_Script, "Delegate 不支持的运算符 " + type); } return(base.m_Script.CreateObject(Delegate.Remove(this.m_Delegate, (Delegate)Util.ChangeType(base.m_Script, obj, base.ValueType)))); } return(base.m_Script.CreateObject(Delegate.Combine(this.m_Delegate, (Delegate)Util.ChangeType(base.m_Script, obj, base.ValueType)))); }
public override ScriptObject Compute(Scorpio.Compiler.TokenType type, ScriptObject obj) { ScriptNumber number = obj as ScriptNumber; if (number == null) { throw new ExecutionException(base.m_Script, this, "赋值逻辑计算 右边值必须为数字类型"); } switch (type) { case Scorpio.Compiler.TokenType.Multiply: return(new ScriptNumberLong(base.m_Script, this.m_Value * number.ToLong())); case Scorpio.Compiler.TokenType.Divide: return(new ScriptNumberLong(base.m_Script, this.m_Value / number.ToLong())); case Scorpio.Compiler.TokenType.Modulo: return(new ScriptNumberLong(base.m_Script, this.m_Value % number.ToLong())); case Scorpio.Compiler.TokenType.InclusiveOr: return(new ScriptNumberLong(base.m_Script, this.m_Value | number.ToLong())); case Scorpio.Compiler.TokenType.Minus: return(new ScriptNumberLong(base.m_Script, this.m_Value - number.ToLong())); case Scorpio.Compiler.TokenType.Plus: return(new ScriptNumberLong(base.m_Script, this.m_Value + number.ToLong())); case Scorpio.Compiler.TokenType.Shi: return(new ScriptNumberLong(base.m_Script, this.m_Value << number.ToInt32())); case Scorpio.Compiler.TokenType.Shr: return(new ScriptNumberLong(base.m_Script, this.m_Value >> number.ToInt32())); case Scorpio.Compiler.TokenType.XOR: return(new ScriptNumberLong(base.m_Script, this.m_Value ^ number.ToLong())); case Scorpio.Compiler.TokenType.Combine: return(new ScriptNumberLong(base.m_Script, this.m_Value & number.ToLong())); } throw new ExecutionException(base.m_Script, this, "Long不支持的运算符 " + type); }
public override ScorpioMethod GetComputeMethod(Scorpio.Compiler.TokenType type) { Scorpio.Compiler.TokenType type2 = type; if (type2 != Scorpio.Compiler.TokenType.Plus) { switch (type2) { case Scorpio.Compiler.TokenType.Multiply: return(base.GetValue(null, "op_Multiply") as ScorpioMethod); case Scorpio.Compiler.TokenType.Divide: return(base.GetValue(null, "op_Division") as ScorpioMethod); case Scorpio.Compiler.TokenType.Minus: return(base.GetValue(null, "op_Subtraction") as ScorpioMethod); } } else { return(base.GetValue(null, "op_Addition") as ScorpioMethod); } return(null); }
public override bool Compare(Scorpio.Compiler.TokenType type, ScriptObject num) { ScriptNumberLong @long = num as ScriptNumberLong; if (@long == null) { throw new ExecutionException(base.m_Script, this, "数字比较 两边的数字类型不一致 请先转换再比较 "); } switch (type) { case Scorpio.Compiler.TokenType.Greater: return(this.m_Value > @long.m_Value); case Scorpio.Compiler.TokenType.GreaterOrEqual: return(this.m_Value >= @long.m_Value); case Scorpio.Compiler.TokenType.Less: return(this.m_Value < @long.m_Value); case Scorpio.Compiler.TokenType.LessOrEqual: return(this.m_Value <= @long.m_Value); } throw new ExecutionException(base.m_Script, this, "Long类型 操作符[" + type + "]不支持"); }
public override bool Compare(Scorpio.Compiler.TokenType type, ScriptObject obj) { ScriptString str = obj as ScriptString; if (str == null) { throw new ExecutionException(base.m_Script, this, "字符串比较 右边必须为字符串类型"); } switch (type) { case Scorpio.Compiler.TokenType.Greater: return(string.Compare(this.m_Value, str.m_Value) > 0); case Scorpio.Compiler.TokenType.GreaterOrEqual: return(string.Compare(this.m_Value, str.m_Value) >= 0); case Scorpio.Compiler.TokenType.Less: return(string.Compare(this.m_Value, str.m_Value) < 0); case Scorpio.Compiler.TokenType.LessOrEqual: return(string.Compare(this.m_Value, str.m_Value) <= 0); } throw new ExecutionException(base.m_Script, this, "String类型 操作符[" + type + "]不支持"); }
public override bool Compare(Scorpio.Compiler.TokenType type, ScriptObject obj) { ScriptNumberDouble num = obj as ScriptNumberDouble; if (num == null) { throw new ExecutionException(base.m_Script, this, "数字比较 两边的数字类型不一致 请先转换再比较"); } switch (type) { case Scorpio.Compiler.TokenType.Greater: return(this.m_Value > num.m_Value); case Scorpio.Compiler.TokenType.GreaterOrEqual: return(this.m_Value >= num.m_Value); case Scorpio.Compiler.TokenType.Less: return(this.m_Value < num.m_Value); case Scorpio.Compiler.TokenType.LessOrEqual: return(this.m_Value <= num.m_Value); } throw new ExecutionException(base.m_Script, this, "Double类型 操作符[" + type + "]不支持"); }
public abstract ScorpioMethod GetComputeMethod(Scorpio.Compiler.TokenType type);
public virtual ScriptObject Compute(Scorpio.Compiler.TokenType type, ScriptObject obj) { throw new ExecutionException(this.m_Script, this, string.Concat(new object[] { "类型[", this.Type, "]不支持运算符[", type, "]" })); }
private static string GetTokenString(Scorpio.Compiler.TokenType type) { switch (type) { case Scorpio.Compiler.TokenType.Var: return("var"); case Scorpio.Compiler.TokenType.LeftBrace: return("{"); case Scorpio.Compiler.TokenType.RightBrace: return("}"); case Scorpio.Compiler.TokenType.LeftPar: return("("); case Scorpio.Compiler.TokenType.RightPar: return(")"); case Scorpio.Compiler.TokenType.LeftBracket: return("["); case Scorpio.Compiler.TokenType.RightBracket: return("]"); case Scorpio.Compiler.TokenType.Period: return("."); case Scorpio.Compiler.TokenType.Comma: return(","); case Scorpio.Compiler.TokenType.Colon: return(":"); case Scorpio.Compiler.TokenType.SemiColon: return(";"); case Scorpio.Compiler.TokenType.QuestionMark: return("?"); case Scorpio.Compiler.TokenType.Sharp: return("#"); case Scorpio.Compiler.TokenType.Plus: return("+"); case Scorpio.Compiler.TokenType.Increment: return("++"); case Scorpio.Compiler.TokenType.AssignPlus: return("+="); case Scorpio.Compiler.TokenType.Minus: return("-"); case Scorpio.Compiler.TokenType.Decrement: return("--"); case Scorpio.Compiler.TokenType.AssignMinus: return("-="); case Scorpio.Compiler.TokenType.Multiply: return("*"); case Scorpio.Compiler.TokenType.AssignMultiply: return("*="); case Scorpio.Compiler.TokenType.Divide: return("/"); case Scorpio.Compiler.TokenType.AssignDivide: return("/="); case Scorpio.Compiler.TokenType.Modulo: return("%"); case Scorpio.Compiler.TokenType.AssignModulo: return("%="); case Scorpio.Compiler.TokenType.InclusiveOr: return("|"); case Scorpio.Compiler.TokenType.AssignInclusiveOr: return("|="); case Scorpio.Compiler.TokenType.Or: return("||"); case Scorpio.Compiler.TokenType.Combine: return("&"); case Scorpio.Compiler.TokenType.AssignCombine: return("&="); case Scorpio.Compiler.TokenType.And: return("&&"); case Scorpio.Compiler.TokenType.XOR: return("^"); case Scorpio.Compiler.TokenType.AssignXOR: return("^="); case Scorpio.Compiler.TokenType.Negative: return("~"); case Scorpio.Compiler.TokenType.Shi: return("<<"); case Scorpio.Compiler.TokenType.AssignShi: return("<<="); case Scorpio.Compiler.TokenType.Shr: return(">>"); case Scorpio.Compiler.TokenType.AssignShr: return(">>="); case Scorpio.Compiler.TokenType.Not: return("!"); case Scorpio.Compiler.TokenType.Assign: return("="); case Scorpio.Compiler.TokenType.Equal: return("=="); case Scorpio.Compiler.TokenType.NotEqual: return("!="); case Scorpio.Compiler.TokenType.Greater: return(">"); case Scorpio.Compiler.TokenType.GreaterOrEqual: return(">="); case Scorpio.Compiler.TokenType.Less: return("<"); case Scorpio.Compiler.TokenType.LessOrEqual: return("<="); case Scorpio.Compiler.TokenType.Params: return("..."); case Scorpio.Compiler.TokenType.If: return("if"); case Scorpio.Compiler.TokenType.Else: return("else"); case Scorpio.Compiler.TokenType.ElseIf: return("elif"); case Scorpio.Compiler.TokenType.Ifndef: return("ifndef"); case Scorpio.Compiler.TokenType.Endif: return("endif"); case Scorpio.Compiler.TokenType.For: return("for"); case Scorpio.Compiler.TokenType.Foreach: return("foreach"); case Scorpio.Compiler.TokenType.In: return("in"); case Scorpio.Compiler.TokenType.Switch: return("switch"); case Scorpio.Compiler.TokenType.Case: return("case"); case Scorpio.Compiler.TokenType.Default: return("default"); case Scorpio.Compiler.TokenType.Break: return("break"); case Scorpio.Compiler.TokenType.Continue: return("continue"); case Scorpio.Compiler.TokenType.Return: return("return"); case Scorpio.Compiler.TokenType.While: return("while"); case Scorpio.Compiler.TokenType.Function: return("function"); case Scorpio.Compiler.TokenType.Try: return("try"); case Scorpio.Compiler.TokenType.Catch: return("catch"); case Scorpio.Compiler.TokenType.Throw: return("throw"); case Scorpio.Compiler.TokenType.Define: return("define"); case Scorpio.Compiler.TokenType.Null: return("null"); case Scorpio.Compiler.TokenType.Eval: return("eval"); } return(""); }
public static string DeserializeToString(byte[] data) { StringBuilder builder = new StringBuilder(); using (MemoryStream stream = new MemoryStream(data)) { using (BinaryReader reader = new BinaryReader(stream)) { reader.ReadSByte(); int num = reader.ReadInt32(); for (int i = 0; i < num; i++) { sbyte num3 = reader.ReadSByte(); if (num3 == LineFlag) { int num4 = reader.ReadInt32(); num3 = reader.ReadSByte(); int length = builder.ToString().Split(new char[] { '\n' }).Length; for (int j = length; j < num4; j++) { builder.Append('\n'); } } Scorpio.Compiler.TokenType type = (Scorpio.Compiler.TokenType)num3; object tokenString = null; switch (type) { case Scorpio.Compiler.TokenType.Boolean: tokenString = (reader.ReadSByte() == 1) ? "true" : "false"; goto Label_015C; case Scorpio.Compiler.TokenType.Number: if (reader.ReadSByte() != 1) { break; } tokenString = reader.ReadDouble(); goto Label_015C; case Scorpio.Compiler.TokenType.String: tokenString = "\"" + Util.ReadString(reader).Replace("\n", @"\n") + "\""; goto Label_015C; case Scorpio.Compiler.TokenType.SimpleString: tokenString = "@\"" + Util.ReadString(reader) + "\""; goto Label_015C; case Scorpio.Compiler.TokenType.Identifier: tokenString = Util.ReadString(reader); goto Label_015C; default: tokenString = GetTokenString(type); goto Label_015C; } tokenString = reader.ReadInt64() + "L"; Label_015C: builder.Append(tokenString + " "); } } } return(builder.ToString()); }
public CodeAssign(CodeMember member, CodeObject value, Scorpio.Compiler.TokenType assignType, string breviary, int line) : base(breviary, line) { this.member = member; this.value = value; this.AssignType = assignType; }
public CodeOperator(CodeObject Right, CodeObject Left, Scorpio.Compiler.TokenType type, string breviary, int line) : base(breviary, line) { this.Left = Left; this.Right = Right; this.Operator = type; }