/// <summary>Compiles the main method.</summary> public void Compile() { // Create the main method builder now: var main = Module.DefineMethod("__.main", typeof(void), new Type[0]); // Invocation for the 'start' method: if (Index != uint.MaxValue) { // Get the function: int paramCount; Type returnType; MethodInfo method = Module.GetFunction((int)Index, out paramCount, out returnType); if (method != null) { // It shouldn't take any args: if (paramCount != 0 || returnType != typeof(void)) { throw new InvalidOperationException( "WebAssembly start method must not have params or a return type." ); } // Call as-is: main.Call(method); } } // Done! main.Complete("__.main", null, typeof(void), true); }
/// <summary>Get the method signature (or creates it).</summary> public MethodInfo GetSignature(Module module) { if (Signature_ == null) { Generator = module.DefineMethod("Func_" + Index, GetReturnType(), GetParameters()); Signature_ = Generator.Method; } return(Signature_); }
/// <summary>Get the method signature (or creates it).</summary> public MethodInfo GetSignature(Module module, out int paramCount, out Type returnType) { if (Signature_ == null) { returnType = GetReturnType(); Type[] paramSet = GetParameters(); paramCount = paramSet.Length; // Define it: Generator = module.DefineMethod("Func_" + Index, returnType, paramSet); Signature_ = Generator.Method; } else { returnType = ReturnType_; paramCount = Parameters_.Length; } return(Signature_); }