Exemple #1
0
 internal LayeTypeDef(LayeTypeDef type, string name, bool isSealed = false)
     : base(type)
 {
     if (name == null)
         throw new ArgumentNullException("name");
     this.name = name;
     this.isSealed = isSealed;
     PutInstanceMethod("toString", (LayeCallback)((state, ths, args) => new LayeString(ToString())));
 }
Exemple #2
0
 internal ObjectTypeDef(LayeTypeDef type)
 {
     type.PutInstanceProperty("hashCode", LayeProperty.FromGet((LayeCallback)IPropertyGet__hashCode));
     type.PutAsCast(LayeBool.TYPE, (LayeCallback)As__Bool);
     type.PutInstanceMethod("toString", (LayeCallback)IMethod__toString);
     type.PutInfix("==", (LayeCallback)Infix__equalTo);
     type.PutInfix("!=", (LayeCallback)Infix__notEqualTo);
     type.PutInfix("<>", (LayeCallback)Infix__Concat);
     type.PutInfix("<;", (LayeCallback)((state, ths, args) => ths));
     type.PutInfix(";>", (LayeCallback)((state, ths, args) => args[0]));
     type.PutInfix(";", (LayeCallback)((state, ths, args) => args[0]));
 }
Exemple #3
0
        internal LayeClosure(LayeKit kit, FunctionPrototype proto, LayeTypeDef definedType = null, LayeObject[] defaults = null)
            : base(TYPE)
        {
            if (kit == null)
                throw new ArgumentNullException("kit");
            this.kit = kit;
            this.proto = proto;
            outers = new OuterValue[proto.outers.Length];
            this.definedType = definedType == null ? NULL : definedType;

            var numParams = proto.hasVargs ? proto.numParams - 1 : proto.numParams;
            this.defaults = new LayeObject[numParams];
            if (defaults == null || defaults.Length == 0)
                for (int i = 0; i < numParams; i++)
                    this.defaults[i] = NULL;
            else
            {
                for (uint i = 0; i < numParams - defaults.Length; i++)
                    this.defaults[i] = NULL;
                for (uint i = numParams - (uint)defaults.Length, j = 0; i < numParams; i++, j++)
                    this.defaults[i] = defaults[j];
            }
        }
Exemple #4
0
 public NullTypeDef(LayeTypeDef type)
     : base(type)
 {
 }
Exemple #5
0
 public KitTypeDef(LayeTypeDef type)
     : base(type)
 {
 }
Exemple #6
0
 public bool TypeOf(LayeState state, LayeTypeDef thatType)
 {
     if (type == null || thatType == null)
         return false;
     return type.InheritsFromOrIs(thatType);
 }
Exemple #7
0
 public LayeObject(LayeTypeDef type)
 {
     this.type = type;
 }
Exemple #8
0
 public BoolTypeDef(LayeTypeDef type)
     : base(type)
 {
 }
Exemple #9
0
 public bool InheritsFromOrIs(LayeTypeDef that)
 {
     if (ReferenceEquals(this, that))
         return true;
     // TODO inheritance
     return false;
 }
Exemple #10
0
 public void PutAsCast(LayeTypeDef to, LayeObject cast)
 {
     if (to == null)
         throw new ArgumentNullException();
     else if (cast == null)
         throw new ArgumentNullException();
     asCasts[to] = cast;
 }
Exemple #11
0
 public bool FindAsCast(LayeTypeDef to, out LayeObject cast)
 {
     if (to == null)
         throw new ArgumentNullException();
     asCasts.TryGetValue(to, out cast);
     return cast != null;
 }
Exemple #12
0
 public SymbolTypeDef(LayeTypeDef type)
     : base(type)
 {
     type.PutAsCast(LayeString.TYPE, (LayeCallback)((state, ths, args) => new LayeString((ths as LayeSymbol).value)));
 }
Exemple #13
0
 public IntTypeDef(LayeTypeDef type)
     : base(type)
 {
     type.PutPrefix("#", (LayeCallback)Prefix__DigitCount);
 }
Exemple #14
0
 public FloatTypeDef(LayeTypeDef type)
     : base(type)
 {
     type.PutAsCast(LayeInt.TYPE, (LayeCallback)As__Int);
 }
Exemple #15
0
 public StringTypeDef(LayeTypeDef type)
     : base(type)
 {
     type.PutPrefix("#", (LayeCallback)((state, ths, args) => new LayeInt((ths as LayeString).value.Length)));
     type.PutInfix("*", (LayeCallback)Infix__repeat);
 }
Exemple #16
0
        internal LayeClosure BuildClosure(FunctionPrototype proto, OuterValue[] openOuters, LayeTypeDef definedType, LayeObject[] defaults)
        {
            var top = stack.Top;
            var closure = new LayeClosure(top.closure.kit, proto, definedType, defaults);
            var protoOuters = proto.outers;

            for (var i = 0; i < protoOuters.Length; i++)
                if (protoOuters[i].type == OuterValueType.LOCAL)
                    closure.outers[i] = FindOuterValue(top.Locals, protoOuters[i].location, openOuters);
                else closure.outers[i] = top.closure.outers[protoOuters[i].location];

            return closure;
        }
Exemple #17
0
 public FunctionTypeDef(LayeTypeDef type)
     : base(type)
 {
 }