示例#1
0
        public NativeCallContext(NativeMethod source, IElfObject @this, params IElfObject[] args) 
        {
            Stack = new Stack<IElfObject>();

            var callScope = new Scope();
            callScope.Add("@this", @this);
            source.FuncDef.Args.Zip(args, callScope.Add);
            Scopes = new Stack<Scope>();
            Scopes.Push(callScope);

            Source = source;
            if (source.FuncDef.Args.Count() != args.Length)
            {
                throw new UnexpectedElfRuntimeException(@this.VM, String.Format(
                   "Fatal error invoking native call '{0}({1})' with args '{2}'. Reason: args count mismatch.",
                   Source.Name, Source.FuncDef.Args.StringJoin(), args.StringJoin()));
            }

            CurrentEvi = 0;
            PrevEvi = -1;
            if (source.Body.IsNullOrEmpty())
            {
                throw new UnexpectedElfRuntimeException(@this.VM, String.Format(
                   "Fatal error invoking native call '{0}'. Reason: empty method body.", Source.Name));
            } 
        }
示例#2
0
        public static IEntryPoint CreateEntryPoint(this VirtualMachine vm, 
            NativeMethod method, params IElfObject[] args)
        {
            try
            {
                var ctor = method.DeclaringType.Ctors.Single(ctor1 => ctor1.Rtimpl.GetParameters().Length == 0);
                var @this = new ElfScriptDefinedClassInstance(method.DeclaringType, Activator.CreateInstance(ctor.Rtimpl.DeclaringType));
                @this.Bind(vm);

                var ep = new DefaultEntryPoint(method, @this, args);
                ep.Bind(vm);

                return ep;
            }
            catch (Exception e)
            {
                if (e is UnexpectedElfRuntimeException) throw;
                throw new UnexpectedElfRuntimeException(vm, String.Format(
                    "Fatal error parsing entry point '{0}:{1}({2})'. " + "Reason: '{3}'",
                    method.DeclaringType.Name, method.Name, args.StringJoin(), e.Message), e);
            }
        }
示例#3
0
 public DefaultEntryPoint(NativeMethod codePoint, IElfObject @this, IElfObject[] args)
 {
     CodePoint = codePoint;
     This = @this;
     Args = args;
 }
示例#4
0
 private NativeMethod LoadNativeFunc(ElfClass @class, FuncDef funcDef)
 {
     var native = new NativeMethod(funcDef, @class);
     native.Body = VM.Compiler.Compile(native.FuncDef);
     return native;
 }