Exemplo n.º 1
0
        public override P5Scalar Assign(Runtime runtime, IP5Any other)
        {
            var ob = other.AsScalar(runtime).Body;
            var obr = ob as P5Reference;
            var obb = ob as P5TypeglobBody;

            if (obb != null)
                body = globBody = obb;
            else if (obr != null)
            {
                var referred = obr.Referred;
                var code = referred as P5Code;
                var scalar = referred as P5Scalar;
                var array = referred as P5Array;
                var hash = referred as P5Hash;

                if (code != null)
                    globBody.Code = code;
                else if (scalar != null)
                    globBody.Scalar = scalar;
                else if (array != null)
                    globBody.Array = array;
                else if (hash != null)
                    globBody.Hash = hash;
            }
            else
            {
                throw new System.NotImplementedException("Assign either glob or reference");
            }

            return this;
        }
Exemplo n.º 2
0
        public override void Set(Runtime runtime, IP5Any other)
        {
            var scalar = other.AsScalar(runtime);
            if (!scalar.IsDefined(runtime))
            {
                Value.SetPos(runtime, -1, true);

                return;
            }

            int pos = scalar.AsInteger(runtime);
            int length = Value.Length(runtime);

            if (pos < 0 && -pos >= length)
                pos = 0;
            else if (pos < 0)
                pos = length + pos;
            else if (pos > length)
                pos = length;

            Value.SetPos(runtime, pos, true);
        }
Exemplo n.º 3
0
        public P5Scalar ConcatAssign(Runtime runtime, IP5Any other)
        {
            P5StringNumber sn = body as P5StringNumber;
            if (sn == null)
                body = sn = new P5StringNumber(runtime, body.AsString(runtime));
            else
                sn.flags = P5StringNumber.HasString;

            sn.stringValue = sn.stringValue + other.AsScalar(runtime).AsString(runtime);
            sn.pos = -1;

            return this;
        }
Exemplo n.º 4
0
        public virtual P5Scalar Assign(Runtime runtime, IP5Any other)
        {
            body = body.Assign(runtime, other.AsScalar(runtime).body);

            return this;
        }
Exemplo n.º 5
0
        public static IP5Any Return(Runtime runtime, Opcode.ContextValues cxt,
                                    IP5Any value)
        {
            if (cxt == Opcode.ContextValues.SCALAR)
                return value.AsScalar(runtime);
            if (cxt == Opcode.ContextValues.LIST)
                return value as P5Array ?? new P5List(runtime, value);

            return P5List.EmptyList;
        }
Exemplo n.º 6
0
 public P5Vec(Runtime runtime, IP5Any value, IP5Any offset, IP5Any bits)
 {
     body = new P5VecBody(runtime, value.AsScalar(runtime),
                          offset.AsInteger(runtime),
                          bits.AsInteger(runtime));
 }
Exemplo n.º 7
0
        public IP5Any GetItemOrUndef(Runtime runtime, IP5Any key, bool create)
        {
            string k = key.AsScalar(runtime).KeyString(runtime);
            IP5Any v = null;
            if (hash.TryGetValue(k, out v))
                return v;
            if (create)
            {
                v = new P5Scalar(runtime);
                hash[k] = v;

                return v;
            }
            return new P5Scalar(runtime);
        }
Exemplo n.º 8
0
        public IP5Any Exists(Runtime runtime, IP5Any key)
        {
            string k = key.AsScalar(runtime).KeyString(runtime);

            return new P5Scalar(runtime, hash.ContainsKey(k));
        }
Exemplo n.º 9
0
        public IP5Any Delete(Runtime runtime, IP5Any key)
        {
            string k = key.AsScalar(runtime).KeyString(runtime);
            IP5Any value;
            bool has_value = hash.TryGetValue(k, out value);

            if (has_value)
            {
                hash.Remove(k);

                return value;
            }
            else
                return new P5Scalar(runtime);
        }
Exemplo n.º 10
0
 public P5Pos(Runtime runtime, IP5Any value)
 {
     body = new P5PosBody(runtime, value.AsScalar(runtime));
 }
Exemplo n.º 11
0
 public IP5Any CallerWithArg(IP5Any level, Opcode.ContextValues cxt)
 {
     return Caller(false, level.AsScalar(this).AsInteger(this), cxt);
 }
Exemplo n.º 12
0
 public P5Substr(Runtime runtime, IP5Any value, int offset)
 {
     body = new P5SubstrBody(runtime, value.AsScalar(runtime),
                             offset);
 }