static public int GetId(IntPtr l) { try { Dsl.ValueData self = (Dsl.ValueData)checkSelf(l); var ret = self.GetId(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
private static void GenerateConcreteSyntax(Dsl.ValueData data, StringBuilder sb, int indent, bool firstLineUseIndent, int paramsStart) { s_CurSyntax = data; if (firstLineUseIndent) { sb.AppendFormat("{0}", GetIndentString(indent)); } string id = data.GetId(); switch (data.GetIdType()) { case (int)Dsl.ValueData.ID_TOKEN: case (int)Dsl.ValueData.NUM_TOKEN: sb.Append(id); break; case (int)Dsl.ValueData.STRING_TOKEN: sb.AppendFormat("\"{0}\"", Escape(id)); break; } }
protected override bool Load(Dsl.ValueData valData) { string id = valData.GetId(); if (valData.GetIdType() == Dsl.ValueData.NUM_TOKEN) { if (id.StartsWith("0x")) { m_Val = long.Parse(id.Substring(2), System.Globalization.NumberStyles.HexNumber); } else { m_Val = long.Parse(id); } } else { m_Val = id; } return(true); }
private static bool CompareVariable(Dsl.ValueData data, Dsl.ValueData var) { return(data.GetId() == var.GetId()); }
internal void Load(Dsl.ISyntaxComponent comp) { Dsl.CallData callData = comp as Dsl.CallData; if (null != callData) { if (!callData.HaveId()) { Dsl.ISyntaxComponent param = callData.GetParam(0); Load(param); } else { string op = callData.GetId(); if (op == "=") //赋值 { Dsl.CallData param1 = callData.GetParam(0) as Dsl.CallData; Dsl.ISyntaxComponent param2 = callData.GetParam(1); string name = param1.GetId(); int id = int.Parse(param1.GetParamId(0)); Load(param2); if (name == "attr") { m_Codes.Add(new Instruction(InsEnum.ATTRSET, id)); } else if (name == "var") { m_Codes.Add(new Instruction(InsEnum.VARSET, id)); } } else if (op == "var") //读属性 { int id = int.Parse(callData.GetParamId(0)); m_Codes.Add(new Instruction(InsEnum.VAR, id)); } else if (op == "attr") //读属性 { int id = int.Parse(callData.GetParamId(0)); m_Codes.Add(new Instruction(InsEnum.ATTR, id)); } else if (op == "attr2") //读属性 { int id = int.Parse(callData.GetParamId(0)); m_Codes.Add(new Instruction(InsEnum.ATTR2, id)); } else if (op == "value") //读常量表 { int id = int.Parse(callData.GetParamId(0)); m_Codes.Add(new Instruction(InsEnum.VALUE, id)); } else if (op == "arg") //读参数值 { int index = int.Parse(callData.GetParamId(0)); m_Codes.Add(new Instruction(InsEnum.ARG, index)); } else if (op == "const") //明确标明的常量值 //普通常量 { long val = long.Parse(callData.GetParamId(0)); m_Codes.Add(new Instruction(InsEnum.CONST, val)); } else //二元及以上运算 { Dsl.ISyntaxComponent param1 = callData.GetParam(0); Dsl.ISyntaxComponent param2 = callData.GetParam(1); Load(param1); Load(param2); if (op == "max") { m_Codes.Add(new Instruction(InsEnum.MAX)); } else if (op == "min") { m_Codes.Add(new Instruction(InsEnum.MIN)); } else if (op == "abs") { m_Codes.Add(new Instruction(InsEnum.ABS)); } else if (op == "+") { m_Codes.Add(new Instruction(InsEnum.ADD)); } else if (op == "-") { m_Codes.Add(new Instruction(InsEnum.SUB)); } else if (op == "*") { m_Codes.Add(new Instruction(InsEnum.MUL)); } else if (op == "/") { m_Codes.Add(new Instruction(InsEnum.DIV)); } else if (op == "%") { m_Codes.Add(new Instruction(InsEnum.MOD)); } else //三元及以上运算 { Dsl.ISyntaxComponent param3 = callData.GetParam(2); Load(param3); if (op == "clamp") { m_Codes.Add(new Instruction(InsEnum.CLAMP)); } } } } } else { Dsl.ValueData valueData = comp as Dsl.ValueData; if (null != valueData && valueData.GetIdType() == Dsl.ValueData.NUM_TOKEN) { //普通常量 long val = long.Parse(valueData.GetId()); m_Codes.Add(new Instruction(InsEnum.CONST, val)); } } }
private void CompileSyntaxComponent(Dsl.ISyntaxComponent comp, List <Instruction> codes, StringBuilder err) { var funcData = comp as Dsl.FunctionData; if (null != funcData) { if (funcData.HaveStatement()) { foreach (var p in funcData.Params) { CompileSyntaxComponent(p, codes, err); } } else if (funcData.HaveParam()) { var callData = funcData; if (!callData.HaveId()) { Dsl.ISyntaxComponent param = callData.GetParam(0); CompileSyntaxComponent(param, codes, err); } else { string op = callData.GetId(); if (op == "=") //赋值 { Dsl.ValueData param1 = callData.GetParam(0) as Dsl.ValueData; if (null != param1) { Dsl.ISyntaxComponent param2 = callData.GetParam(1); CompileSyntaxComponent(param2, codes, err); if (param1.GetIdType() == Dsl.ValueData.ID_TOKEN) { string name = param1.GetId(); int id = GetVarId(name); codes.Add(new Instruction(InsEnum.VARSET, id)); } else { err.AppendFormat("operator = illegal, left operand must be a var, code:{0}, line:{1}", callData.ToScriptString(false), callData.GetLine()); err.AppendLine(); } } else { err.AppendFormat("operator = illegal, left operand must be a var, code:{0}, line:{1}", callData.ToScriptString(false), callData.GetLine()); err.AppendLine(); } } else if (op == "arg") //读参数 { int id = int.Parse(callData.GetParamId(0)); codes.Add(new Instruction(InsEnum.ARG, id)); } else { int num = callData.GetParamNum(); for (int i = 0; i < num; ++i) { Dsl.ISyntaxComponent param = callData.GetParam(i); CompileSyntaxComponent(param, codes, err); } if (callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_OPERATOR) { if (num == 2 && op != "!" && op != "~" || num == 1 && (op == "+" || op == "-" || op == "!" || op == "~")) { if (op == "+") { if (num == 2) { codes.Add(new Instruction(InsEnum.ADD)); } } else if (op == "-") { if (num == 2) { codes.Add(new Instruction(InsEnum.SUB)); } else { codes.Add(new Instruction(InsEnum.NEG)); } } else if (op == "*") { codes.Add(new Instruction(InsEnum.MUL)); } else if (op == "/") { codes.Add(new Instruction(InsEnum.DIV)); } else if (op == "%") { codes.Add(new Instruction(InsEnum.MOD)); } else if (op == "&&") { codes.Add(new Instruction(InsEnum.AND)); } else if (op == "||") { codes.Add(new Instruction(InsEnum.OR)); } else if (op == "!") { codes.Add(new Instruction(InsEnum.NOT)); } else if (op == ">") { codes.Add(new Instruction(InsEnum.GT)); } else if (op == ">=") { codes.Add(new Instruction(InsEnum.GE)); } else if (op == "==") { codes.Add(new Instruction(InsEnum.EQ)); } else if (op == "!=") { codes.Add(new Instruction(InsEnum.NE)); } else if (op == "<=") { codes.Add(new Instruction(InsEnum.LE)); } else if (op == "<") { codes.Add(new Instruction(InsEnum.LT)); } else if (op == "<<") { codes.Add(new Instruction(InsEnum.LSHIFT)); } else if (op == ">>") { codes.Add(new Instruction(InsEnum.RSHIFT)); } else if (op == "&") { codes.Add(new Instruction(InsEnum.BITAND)); } else if (op == "|") { codes.Add(new Instruction(InsEnum.BITOR)); } else if (op == "^") { codes.Add(new Instruction(InsEnum.BITXOR)); } else if (op == "~") { codes.Add(new Instruction(InsEnum.BITNOT)); } else { err.AppendFormat("operator '{0}' illegal, code:{1}, line:{2}", op, callData.ToScriptString(false), callData.GetLine()); err.AppendLine(); } } else { err.AppendFormat("operator '{0}' arg num {1} illegal, code:{2}, line:{3}", op, num, callData.ToScriptString(false), callData.GetLine()); err.AppendLine(); } } else { int procId = GetApiOrProcId(op); codes.Add(new Instruction(InsEnum.CALL, procId, num)); } } } } } else { Dsl.ValueData valueData = comp as Dsl.ValueData; if (null != valueData) { if (valueData.GetIdType() == Dsl.ValueData.ID_TOKEN) { //变量 string name = valueData.GetId(); int id = GetVarId(name); codes.Add(new Instruction(InsEnum.VAR, id)); } else if (valueData.GetIdType() == Dsl.ValueData.NUM_TOKEN) { //普通常量 try { long val = long.Parse(valueData.GetId()); codes.Add(new Instruction(InsEnum.PUSH, val)); } catch { err.AppendFormat("const must be integer, code:{0}, line:{1}", comp.ToScriptString(false), comp.GetLine()); err.AppendLine(); } } } } }
protected override bool Load(Dsl.ValueData valData) { m_Variables = Calculator.NamedVariables; m_VarId = valData.GetId(); return(true); }