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 Clone() { ScriptTable table = base.m_Script.CreateTable(); ScriptObject obj2 = null; ScriptScriptFunction function = null; foreach (KeyValuePair <object, ScriptObject> pair in this.m_listObject) { if (pair.Value == this) { table.m_listObject[pair.Key] = table; } else { obj2 = pair.Value.Clone(); if (obj2 is ScriptScriptFunction) { function = (ScriptScriptFunction)obj2; if (!function.IsStaticFunction) { function.SetTable(table); } } table.m_listObject[pair.Key] = obj2; } } return(table); }
void ProcessRet() { if (m_scriptInstruction.operand0 == null) { InvokeReturnValue(null); } else { ScriptObject ret = ResolveOperand(m_scriptInstruction.operand0); if (ret is ScriptScriptFunction) { ScriptScriptFunction ssf = ret as ScriptScriptFunction; ssf.isCloure = true; CodeObject co = m_scriptInstruction.operand0; if (co is CodeMember) { CodeMember member = co as CodeMember; if (member.Parent == null) { ssf.SetTable(m_script.GetGlobalTable()); } else { ScriptObject sotable = ResolveOperand(member.Parent); if (sotable is ScriptTable) { ssf.SetTable(sotable as ScriptTable); } } } } InvokeReturnValue(ret); } }
//解析Var关键字 private void ParseVar() { for (; ;) { Token peek = PeekToken(); if (peek.Type == TokenType.Function) { ScriptScriptFunction func = ParseFunctionDeclaration(true); m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.VAR, func.Name)); m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.MOV, new CodeMember(func.Name), new CodeFunction(func, m_strBreviary, peek.SourceLine))); } else { m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.VAR, ReadIdentifier())); peek = PeekToken(); if (peek.Type == TokenType.Assign) { UndoToken(); ParseStatement(); } } peek = ReadToken(); if (peek.Type != TokenType.Comma) { UndoToken(); break; } peek = PeekToken(); if (peek.Type == TokenType.Var) { ReadToken(); } } }
ScriptFunction ParseFunction(CodeFunction func) { ScriptScriptFunction ssf = func.Func.Create(); ssf.SetParentContext(this); return(ssf); }
ScriptTable ParseTable(CodeTable table) { ScriptContext context = new ScriptContext(m_script, null, this, Executable_Block.None); ScriptTable ret = m_script.CreateTable(); foreach (ScriptScriptFunction func in table.Functions) { func.SetTable(ret); ret.SetValue(func.Name, func); context.SetVariableForce(func.Name, func); } foreach (CodeTable.TableVariable variable in table.Variables) { ScriptObject value = context.ResolveOperand(variable.value); if (value is ScriptScriptFunction) { ScriptScriptFunction func = (ScriptScriptFunction)value; if (func.IsStaticFunction) { func.SetTable(ret); } } ret.SetValue(variable.key, value); context.SetVariableForce(variable.key.ToString(), value); } return(ret); }
private void ParseVar() { Token token; Label_0000: token = this.PeekToken(); if (token.Type == Scorpio.Compiler.TokenType.Function) { ScriptScriptFunction func = this.ParseFunctionDeclaration(true); this.m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.VAR, func.Name)); this.m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.MOV, new CodeMember(func.Name), new CodeFunction(func, this.m_strBreviary, token.SourceLine))); } else { this.m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.VAR, this.ReadIdentifier())); if (this.PeekToken().Type == Scorpio.Compiler.TokenType.Assign) { this.UndoToken(); this.ParseStatement(); } } if (this.ReadToken().Type != Scorpio.Compiler.TokenType.Comma) { this.UndoToken(); } else { if (this.PeekToken().Type == Scorpio.Compiler.TokenType.Var) { this.ReadToken(); } goto Label_0000; } }
public override ScriptObject Clone() { ScriptTable ret = Script.CreateTable(); ScriptObject obj = null; ScriptScriptFunction func = null; foreach (KeyValuePair <object, ScriptObject> pair in m_listObject) { if (pair.Value == this) { ret.m_listObject[pair.Key] = ret; } else { obj = pair.Value.Clone(); if (obj is ScriptScriptFunction) { func = (ScriptScriptFunction)obj; if (!func.IsStatic) { func.SetTable(ret); } } ret.m_listObject[pair.Key] = obj; } } return(ret); }
public override ScriptObject AssignCompute(TokenType type, ScriptObject value) { if (type != TokenType.AssignPlus) { return(base.AssignCompute(type, value)); } ScriptTable table = value as ScriptTable; if (table == null) { throw new ExecutionException(Script, "table [+=] 操作只支持两个table " + value.Type); } ScriptObject obj = null; ScriptScriptFunction func = null; foreach (KeyValuePair <object, ScriptObject> pair in table.m_listObject) { obj = pair.Value.Clone(); if (obj is ScriptScriptFunction) { func = (ScriptScriptFunction)obj; if (!func.IsStatic) { func.SetTable(this); } } m_listObject[pair.Key] = obj; } return(this); }
private void ParseFunction() { Token token = this.PeekToken(); this.UndoToken(); ScriptScriptFunction func = this.ParseFunctionDeclaration(true); this.m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.MOV, new CodeMember(func.Name), new CodeFunction(func, this.m_strBreviary, token.SourceLine))); }
public override ScriptObject Compute(TokenType type, ScriptObject value) { if (type != TokenType.Plus) { return(base.Compute(type, value)); } ScriptTable table = value as ScriptTable; if (table == null) { throw new ExecutionException(m_Script, this, "table [+] 操作只限两个[table]之间,传入数据类型:" + value.Type); } ScriptTable ret = m_Script.CreateTable(); ScriptObject obj = null; ScriptScriptFunction func = null; foreach (KeyValuePair <object, ScriptObject> pair in m_listObject) { obj = pair.Value.Clone(); if (obj is ScriptScriptFunction) { func = (ScriptScriptFunction)obj; if (!func.IsStaticFunction) { func.SetTable(ret); } } ret.m_listObject[pair.Key] = obj; } foreach (KeyValuePair <object, ScriptObject> pair in table.m_listObject) { obj = pair.Value.Clone(); if (obj is ScriptScriptFunction) { func = (ScriptScriptFunction)obj; if (!func.IsStaticFunction) { func.SetTable(ret); } } ret.m_listObject[pair.Key] = obj; } return(ret); }
public CodeFunction(ScriptScriptFunction func, string breviary, int line) : base(breviary, line) { this.Func = func; }
public ScriptObject DoString(String strBuffer) { ScriptScriptFunction funBody = LoadString("", strBuffer); return(Do(funBody)); }
public ScriptObject DoString(String strBreviary, String strBuffer) { ScriptScriptFunction funBody = LoadString(strBreviary, strBuffer, null, true); return(Do(funBody)); }
ScriptObject ParseCall(CodeCallFunction scriptFunction, bool needRet) { ScriptObject obj = ResolveOperand(scriptFunction.Member); // 安装function this 信息 if (obj is ScriptScriptFunction) { ScriptScriptFunction suf = obj as ScriptScriptFunction; if (!suf.isCloure) { if (scriptFunction.Member is CodeMember) { CodeMember member = scriptFunction.Member as CodeMember; if (member.Parent == null) { suf.SetTable(m_script.GetGlobalTable()); } else { ScriptObject sotable = ResolveOperand(member.Parent); if (sotable is ScriptTable) { suf.SetTable(sotable as ScriptTable); } } } } } int num = scriptFunction.ParametersCount; ScriptObject[] parameters = new ScriptObject[num]; for (int i = 0; i < num; ++i) { //此处要调用Assign 如果传入number string等基础类型 在函数内自运算的话 会影响 传入的值 parameters[i] = ResolveOperand(scriptFunction.Parameters[i]).Assign(); // 创建闭包 if (parameters[i] is ScriptScriptFunction) { ScriptScriptFunction ssf = parameters[i] as ScriptScriptFunction; ssf.isCloure = true; if (scriptFunction.Parameters[i] is CodeMember) { CodeMember member = scriptFunction.Parameters[i] as CodeMember; if (member.Parent == null) { ssf.SetTable(m_script.GetGlobalTable()); } else { ScriptObject sotable = ResolveOperand(member.Parent); if (sotable is ScriptTable) { ssf.SetTable(sotable as ScriptTable); } } } else if (scriptFunction.Parameters[i] is CodeFunction) { if (obj is ScriptScriptFunction) { ScriptScriptFunction suf = obj as ScriptScriptFunction; ssf.SetTable((ScriptTable)suf.GetValue("this")); } } } } m_script.PushStackInfo(); object ret = obj.Call(parameters); m_script.PopStackInfo(); return(needRet ? m_script.CreateObject(ret) : null); }
public ScriptObject DoSearchPathFile(String fileName) { ScriptScriptFunction funBody = LoadSearchPathFile(fileName); return(Do(funBody)); }
public ScriptObject DoFile(String fileName, Encoding encoding) { ScriptScriptFunction funBody = LoadFile(fileName, encoding); return(Do(funBody)); }
private ScriptObject Do(ScriptScriptFunction func) { ScriptObject ret = (ScriptObject)func.Call(); return(ret); }
public ScriptObject DoBuffer(String strBreviary, byte[] buffer) { ScriptScriptFunction funBody = LoadBuffer(strBreviary, buffer, UTF8); return(Do(funBody)); }
public CodeFunction(ScriptScriptFunction func) { this.Func = func; }
public ScriptObject DoBuffer(byte[] buffer) { ScriptScriptFunction funBody = LoadBuffer("Undefined", buffer, UTF8); return(Do(funBody)); }