Beispiel #1
0
 static void Main(string[] args)
 {
     TcpClient mclient = new TcpClient();
     mclient.Connect(IPAddress.Loopback, 6553);
     mclient.Client.Blocking = true;
     Stream srcstre = mclient.GetStream();
     Kernel.ExecutionContext = srcstre;
     Kernel executionkernel = new Kernel();
     executionkernel.Initialize();
     BinaryReader mreader = new BinaryReader(srcstre);
     executionkernel.Run(mreader.ReadString());
     Console.WriteLine("Execution complete");
 }
Beispiel #2
0
 void thetar(object sender)
 {
     StreamReader mreader = new StreamReader(sender as String);
     string code = Link(mreader.ReadToEnd());
     mreader.Dispose();
     mkernl = new Kernel();
     mkernl.parent = mnul;
     mkernl.Initialize();
     mvent.Set();
     mkernl.Run(code);
 }
Beispiel #3
0
 public void InvokeMethod(JSFunctionPtr functionPtr,Kernel kernel, object[] args)
 {
     CallFunction(inst, SerializeDirect(kernel, args), functionPtr.value);
 }
Beispiel #4
0
        void SerializeManaged(BinaryWriter mwriter, Kernel kernel, object value)
        {
            if (value == null)
            {
                mwriter.Write((byte)2);
                mwriter.Write((int)0);
                return;
            }
            Type reflectedtype = value.GetType();
            if (reflectedtype == typeof(Dictionary<string, object>))
            {
                mwriter.Write((byte)0);
                Dictionary<string, object> mdict = value as Dictionary<string, object>;
                mwriter.Write(mdict.Count);
                foreach (KeyValuePair<string, object> et in mdict)
                {
                    mwriter.Write(Encoding.UTF8.GetBytes(et.Key).Length);
                    mwriter.Write(Encoding.UTF8.GetBytes(et.Key));
                    SerializeManaged(mwriter, kernel, et.Value);
                }
                return;
            }
            if (reflectedtype == typeof(double))
            {
                mwriter.Write((byte)5);
                mwriter.Write((double)value);
                return;

            }
            if (reflectedtype == typeof(int))
            {
                mwriter.Write((byte)2);
                mwriter.Write((int)value);
                return;
            }
            if (reflectedtype == typeof(object[]))
            {
                mwriter.Write((byte)1);
                object[] mray = value as object[];
                mwriter.Write((uint)mray.Length);
                foreach (object et in mray)
                {
                    SerializeManaged(mwriter,kernel, et);
                }
                return;
            }
            if (reflectedtype == typeof(string))
            {
                mwriter.Write((byte)3);
                byte[] strdat = Encoding.UTF8.GetBytes(value as string);
                mwriter.Write(strdat.Length);
                mwriter.Write(strdat);
                return;

            }
            if (reflectedtype == typeof(JSFunctionPtr))
            {
                mwriter.Write((byte)4);
                mwriter.Write((value as JSFunctionPtr).value);
                return;
            }
            //No matches!
            kernel.objPtrs.Add(kernel.cpointer, value);
            mwriter.Write((byte)2);
            mwriter.Write(kernel.cpointer);
            kernel.cpointer++;
        }
Beispiel #5
0
        public IntPtr SerializeDirect(Kernel kern, object[] args)
        {
            MemoryStream mstream = new MemoryStream();
            BinaryWriter mwriter = new BinaryWriter(mstream);
            mwriter.Write(args.Length);

            foreach (object et in args)
            {
                SerializeManaged(mwriter, kern, et);
            }
            byte[] data = mstream.ToArray();
            IntPtr retval = NativeAlloc(inst, data.Length);
            Marshal.Copy(data, 0, retval, data.Length);
            return retval;
        }
Beispiel #6
0
        public IntPtr Serialize(Kernel kern,params object[] args)
        {
            MemoryStream mstream = memorystream;
            BinaryWriter mwriter = new BinaryWriter(mstream);
            mwriter.Write(args.Length);

            foreach(object et in args) {
                SerializeManaged(mwriter,kern, et);
            }
            if (mstream.Length > memorycache.Length)
            {
                memorycache = new byte[mstream.Length];
            }
            mstream.Position = 0;
            mstream.Read(memorycache, 0, (int)mstream.Length);
            IntPtr retval = NativeAlloc(inst,(int)mstream.Length);
            Marshal.Copy(memorycache, 0, retval, (int)mstream.Length);
            mstream.SetLength(0);
            return retval;
        }