public void CallNativeFunction(string name, Expression[] args) { ScriptNativeFunction function = ScriptNativeFunctionTable.Find(name); if (function == null) { throw new InvalidOperationException("Function not found"); } ScriptNativeFunctionAttribute functionAttribute = function.Method.GetCustomAttribute <ScriptNativeFunctionAttribute>(); ScriptNativeFunctionReturnAttribute[] returnTypes = function.Method.GetCustomAttributes <ScriptNativeFunctionReturnAttribute>(); ScriptNativeFunctionParameterAttribute[] parameterTypes = function.Method.GetCustomAttributes <ScriptNativeFunctionParameterAttribute>(); // return value들을 보관할 영역을 확보합니다. foreach (ScriptNativeFunctionReturnAttribute item in returnTypes) { AllocateN(DeclareVariable.SizeOf(item.Type), true); } Trace.Assert(parameterTypes.Length == args.Length); for (int i = 0; i < args.Length; i++) { Generate(args[i]); } binaryWriter.Write(ScriptInstruction.CallNativeFunction); binaryWriter.Write(functionAttribute.FunctionID); binaryWriter.Write(returnTypes.Length); binaryWriter.Write(parameterTypes.Length); AppendTextCode("<b>call_native</b> {0} [{1}]", functionAttribute.FunctionID, name); Pop(parameterTypes.Length); }
public void CallScriptFunction(string name, Expression[] args) { Function function = FindFunction(name); if (function == null) { throw new InvalidOperationException("Function not found"); } // return value들을 보관할 영역을 확보합니다. foreach (ScriptObjectType item in function.ReturnTypes) { AllocateN(DeclareVariable.SizeOf(item), true); } for (int i = 0; i < args.Length; i++) { Generate(args[i]); } binaryWriter.Write(ScriptInstruction.CallScriptFunction); string addressString = WriteAddress(function.BeginLabel); binaryWriter.Write(args.Length); AppendTextCode("<b>call</b> <a href=\"#{0}\">{0}</a> [{1}]", addressString, name); // 실행에서 Pop은 return에서 해주므로 여기서는 VS에서만 Pop해줍니다. PopVS(args.Length); }
public bool TryGetVariableOffsetFromVS(string name, out int stackIndex, out int localOffset, out int size) { List <List <DeclareVariable> > lvvs = localVariableVirtualStack; stackIndex = -1; localOffset = 0; size = 0; for (int i = lvvs.Count - 1; i >= 0; i--, stackIndex--) { List <DeclareVariable> items = lvvs[i]; if (items == null) { continue; } int k = items.Count - 1; bool found = false; for (k = items.Count - 1; k >= 0; k--) { DeclareVariable item = items[k]; if (item.Name == name) { size = DeclareVariable.SizeOf(item.Type); found = true; break; } } for (k = k - 1; k >= 0; k--) { localOffset += DeclareVariable.SizeOf(items[k].Type); } if (found) { return(true); } } return(false); }