Inheritance: Erlang.Object
コード例 #1
0
ファイル: OtpMsg.cs プロジェクト: trompa/jungerl
 // special case when reason is an atom (i.e. most of the time)
 private OtpMsg(Tag tag, Erlang.Pid from, Object /* Pid or string */ to,
                Erlang.Ref eref, System.String reason, OtpInputStream paybuf)
 {
     this.tag     = tag;
     this.from    = from;
     this.to      = (Erlang.Pid)(to is Erlang.Pid ? to : null);
     this.toName  = (string)(to is string?to : null);
     this.paybuf  = paybuf;
     this.payload = new Erlang.Atom(reason);
     this.eref    = eref;
 }
コード例 #2
0
        /*
         * Create an Erlang {@link Ref reference}. Erlang
         * references are based upon some node specific information; this
         * method creates a reference using the information in this node.
         * Each call to this method produces a unique reference.
         *
         * @return an Erlang reference.
         **/
        public virtual Erlang.Ref createRef()
        {
            lock (this)
            {
                Erlang.Ref r = new Erlang.Ref(_node, refId, _creation);

                // increment ref ids (3 ints: 18 + 32 + 32 bits)
                refId[0]++;
                if (refId[0] > 0x3ffff)
                {
                    refId[0] = 0;

                    refId[1]++;
                    if (refId[1] == 0)
                    {
                        refId[2]++;
                    }
                }

                return(r);
            }
        }
コード例 #3
0
ファイル: OtpMsg.cs プロジェクト: e42s/jungerl
 // special case when reason is an atom (i.e. most of the time)
 private OtpMsg(Tag tag, Erlang.Pid from, Object /* Pid or string */ to,
     Erlang.Ref eref, System.String reason, OtpInputStream paybuf)
 {
     this.tag = tag;
     this.from = from;
     this.to = (Erlang.Pid)(to is Erlang.Pid ? to : null);
     this.toName = (string)(to is string ? to : null);
     this.paybuf = paybuf;
     this.payload = new Erlang.Atom(reason);
     this.eref = eref;
 }
コード例 #4
0
ファイル: OtpOutputStream.cs プロジェクト: yonglehou/otp.net
 public int encode_size(Erlang.Object o)
 {
     if (o is Erlang.Atom)
     {
         return(1 + 2 + o.atomValue().Length);
     }
     else if (o is Erlang.Boolean)
     {
         return(1 + 2 + (o.boolValue()
                                               ? Erlang.Boolean.s_true.atomValue().Length
                                               : Erlang.Boolean.s_false.atomValue().Length));
     }
     else if (o is Erlang.Binary)
     {
         return(5 + o.binaryValue().Length);
     }
     else if (o is Erlang.Long)
     {
         long l = o.longValue();
         if ((l & 0xff) == l)
         {
             return(2);
         }
         else if ((l <= OtpExternal.erlMax) && (l >= OtpExternal.erlMin))
         {
             return(5);
         }
         return(long_arity(l));
     }
     else if (o is Erlang.Byte)
     {
         return(1 + 1);
     }
     else if (o is Erlang.Double)
     {
         return(9);
     }
     else if (o is Erlang.String)
     {
         string l = o.stringValue();
         if (l.Length == 0)
         {
             return(1);
         }
         if (l.Length < 0xffff)
         {
             return(2 + l.Length);
         }
         return(1 + 4 + 2 * l.Length);
     }
     else if (o is Erlang.List)
     {
         Erlang.List l = o.listValue();
         if (l.arity() == 0)
         {
             return(1);
         }
         int sz = 5;
         for (int i = 0; i < l.arity(); i++)
         {
             sz += encode_size(l[i]);
         }
         return(sz);
     }
     else if (o is Erlang.Tuple)
     {
         Erlang.Tuple l  = o.tupleValue();
         int          sz = 1 + (l.arity() < 0xff ? 1 : 4);
         for (int i = 0; i < l.arity(); i++)
         {
             sz += encode_size(l[i]);
         }
         return(sz);
     }
     else if (o is Erlang.Pid)
     {
         Erlang.Pid p = o.pidValue();
         return(1 + (1 + 2 + p.node().Length) + 4 + 4 + 1);
     }
     else if (o is Erlang.Ref)
     {
         Erlang.Ref p   = o.refValue();
         int[]      ids = p.ids();
         return(1 + (1 + 2 + p.node().Length) + 1 + 4 * ids.Length);
     }
     else if (o is Erlang.Port)
     {
         Erlang.Port p = o.portValue();
         return(1 + (1 + 2 + p.node().Length) + 4 + 1);
     }
     else
     {
         throw new Erlang.Exception("Unknown encode size for object: " + o.ToString());
     }
 }
コード例 #5
0
ファイル: OtpMsg.cs プロジェクト: trompa/jungerl
 // special case when reason is an atom (i.e. most of the time)
 internal OtpMsg(Tag tag, Erlang.Pid from, string toName, Erlang.Ref eref, System.String reason)
     : this(tag, from, toName, eref, reason, null)
 {
 }
コード例 #6
0
ファイル: OtpMsg.cs プロジェクト: trompa/jungerl
 // exit (etc) has from, to, reason
 internal OtpMsg(Tag tag, Erlang.Pid from, Erlang.Pid to, Erlang.Ref eref, Erlang.Object reason)
     : this(tag, from, to, eref, reason, null)
 {
 }
コード例 #7
0
ファイル: OtpLocalNode.cs プロジェクト: e42s/jungerl
        /*
        * Create an Erlang {@link Ref reference}. Erlang
        * references are based upon some node specific information; this
        * method creates a reference using the information in this node.
        * Each call to this method produces a unique reference.
        *
        * @return an Erlang reference.
        **/
        public virtual Erlang.Ref createRef()
        {
            lock(this)
            {
                Erlang.Ref r = new Erlang.Ref(_node, refId, _creation);

                // increment ref ids (3 ints: 18 + 32 + 32 bits)
                refId[0]++;
                if (refId[0] > 0x3ffff)
                {
                    refId[0] = 0;

                    refId[1]++;
                    if (refId[1] == 0)
                    {
                        refId[2]++;
                    }
                }

                return r;
            }
        }
コード例 #8
0
 public void TestEncodeDecode()
 {
     {
         OtpOutputStream os  = new OtpOutputStream(new Erlang.Atom("abc"));
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue("abc" == ins.read_atom());
     }
     {
         OtpOutputStream os  = new OtpOutputStream(new Erlang.String("string"));
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue("string" == ins.read_string());
     }
     {
         Erlang.Pid      pid = new Erlang.Pid("abc", 1, 2, 3);
         OtpOutputStream os  = new OtpOutputStream(pid);
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue(pid.Equals(ins.read_pid()));
     }
     {
         Erlang.Port     p   = new Erlang.Port("abc", 1, 2);
         OtpOutputStream os  = new OtpOutputStream(p);
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue(p.Equals(ins.read_port()));
     }
     {
         Erlang.Ref p = new Erlang.Ref("abc", new int[3] {
             1, 2, 3
         }, 2);
         OtpOutputStream os  = new OtpOutputStream(p);
         OtpInputStream  ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         Assert.IsTrue(p.Equals(ins.read_ref()));
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_long(1);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         long           n   = ins.read_long();
         Assert.IsTrue(1 == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_long(0xFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         long           n   = ins.read_long();
         Assert.IsTrue(0xFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_long(0xFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         long           n   = ins.read_long();
         Assert.IsTrue(0xFFFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_ulong((ulong)0xFFFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         ulong          n   = ins.read_ulong();
         Assert.IsTrue((ulong)0xFFFFFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_ulong((ulong)0xFFFFFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         ulong          n   = ins.read_ulong();
         Assert.IsTrue((ulong)0xFFFFFFFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_ulong((ulong)0xFFFFFFFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         ulong          n   = ins.read_ulong();
         Assert.IsTrue((ulong)0xFFFFFFFFFFFFFF == n);
     }
     {
         OtpOutputStream os = new OtpOutputStream();
         os.write_ulong((ulong)0xFFFFFFFFFFFFFFFF);
         OtpInputStream ins = new OtpInputStream(os.getBuffer(), 0, os.size());
         ulong          n   = ins.read_ulong();
         Assert.IsTrue((ulong)0xFFFFFFFFFFFFFFFF == n);
     }
 }
コード例 #9
0
        public void TestPatternMatch()
        {
            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.Object  obj     = Erlang.Object.Format("{snapshot, x12, []}");
                Erlang.Object  pat     = Erlang.Object.Format("{snapshot, N, L}");

                Assert.IsTrue(pat.match(obj, binding));
                Erlang.Atom n = binding.find("N") as Erlang.Atom;
                Erlang.List l = binding.find("L") as Erlang.List;
                Assert.IsNotNull(n);
                Assert.IsNotNull(l);
                Assert.IsTrue(l.Length == 0);
            }
            {
                Erlang.Object pat = Erlang.Object.Format("{test, A, B, C}");
                Erlang.Object obj = Erlang.Object.Format("{test, 10, a, [1,2,3]}");

                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Assert.IsTrue(pat.match(obj, binding));
                Assert.AreEqual(3, binding.Count);
                Assert.AreEqual(10, binding["A"].longValue());
                Assert.AreEqual("a", binding["B"].atomValue());
                Assert.AreEqual("[1,2,3]", binding["C"].ToString());
            }

            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.Object  obj     = Erlang.Object.Format("[1,a,$b,\"xyz\",{1,10.0},[]]");
                Erlang.Object  pat     = Erlang.Object.Format("[A,B,C,D,E,F]");

                Assert.IsTrue(pat.match(obj, binding));
                Assert.IsNotNull(binding.find("A") as Erlang.Long);
                Assert.IsNotNull(binding.find("B") as Erlang.Atom);
                Assert.IsNotNull(binding.find("C") as Erlang.Char);
                Assert.IsNotNull(binding.find("D") as Erlang.String);
                Assert.IsNotNull(binding.find("E") as Erlang.Tuple);
                Assert.IsNotNull(binding.find("F") as Erlang.List);

                Assert.IsTrue(binding.find("E").Cast <Erlang.Tuple>().arity() == 2);
                Assert.IsTrue(binding.find("F").Cast <Erlang.List>().Length == 0);
            }

            Erlang.Object pattern = Erlang.Object.Format("{test, T}");
            string        exp     = "{test, ~w}";
            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.Object  obj     = Erlang.Object.Format(exp, (int)3);
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual(3, binding.find("T").intValue());
            }
            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.Object  obj     = Erlang.Object.Format(exp, (long)100);
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual(100, binding.find("T").longValue());
            }
            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.Object  obj     = Erlang.Object.Format(exp, 100.0);
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual(100.0, binding.find("T").doubleValue());
            }
            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.Object  obj     = Erlang.Object.Format(exp, "test");
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual("test", binding.find("T").stringValue());
            }
            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.Object  obj     = Erlang.Object.Format(exp, true);
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual(true, binding.find("T").boolValue());
            }
            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.Object  obj     = Erlang.Object.Format(exp, 'c');
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual('c', binding.find("T").charValue());
            }
            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.Pid     pid     = new Erlang.Pid("tmp", 1, 2, 3);
                Erlang.Object  obj     = Erlang.Object.Format(exp, pid as Erlang.Object);
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual(pid, binding.find("T").pidValue());

                obj = Erlang.Object.Format(exp, pid);
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual(pid, binding.find("T").pidValue());
            }
            {
                Erlang.VarBind binding   = new Otp.Erlang.VarBind();
                Erlang.Ref     reference = new Erlang.Ref("tmp", 1, 2);
                Erlang.Object  obj       = Erlang.Object.Format(exp, reference);
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual(reference, binding.find("T").refValue());
            }
            {
                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Erlang.List    obj     = new Erlang.List(new Erlang.Int(10), new Erlang.Double(30.0),
                                                         new Erlang.String("abc"), new Erlang.Atom("a"),
                                                         new Erlang.Binary(new byte[] { 1, 2, 3 }), false, new Erlang.Boolean(true));
                Erlang.Object pat = Erlang.Object.Format("T");
                Assert.IsTrue(pat.match(obj, binding));
                Erlang.Object expected = Erlang.Object.Format("[10, 30.0, \"abc\", 'a', ~w, \'false\', true]",
                                                              new Erlang.Binary(new byte[] { 1, 2, 3 }));
                Erlang.Object result = binding.find("T");
                Assert.IsTrue(expected.Equals(result));
            }
        }