Example #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())));
 }
Example #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]));
 }
Example #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];
            }
        }
Example #4
0
 public NullTypeDef(LayeTypeDef type)
     : base(type)
 {
 }
Example #5
0
 public KitTypeDef(LayeTypeDef type)
     : base(type)
 {
 }
Example #6
0
 public bool TypeOf(LayeState state, LayeTypeDef thatType)
 {
     if (type == null || thatType == null)
         return false;
     return type.InheritsFromOrIs(thatType);
 }
Example #7
0
 public LayeObject(LayeTypeDef type)
 {
     this.type = type;
 }
Example #8
0
 public BoolTypeDef(LayeTypeDef type)
     : base(type)
 {
 }
Example #9
0
 public bool InheritsFromOrIs(LayeTypeDef that)
 {
     if (ReferenceEquals(this, that))
         return true;
     // TODO inheritance
     return false;
 }
Example #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;
 }
Example #11
0
 public bool FindAsCast(LayeTypeDef to, out LayeObject cast)
 {
     if (to == null)
         throw new ArgumentNullException();
     asCasts.TryGetValue(to, out cast);
     return cast != null;
 }
Example #12
0
 public SymbolTypeDef(LayeTypeDef type)
     : base(type)
 {
     type.PutAsCast(LayeString.TYPE, (LayeCallback)((state, ths, args) => new LayeString((ths as LayeSymbol).value)));
 }
Example #13
0
 public IntTypeDef(LayeTypeDef type)
     : base(type)
 {
     type.PutPrefix("#", (LayeCallback)Prefix__DigitCount);
 }
Example #14
0
 public FloatTypeDef(LayeTypeDef type)
     : base(type)
 {
     type.PutAsCast(LayeInt.TYPE, (LayeCallback)As__Int);
 }
Example #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);
 }
Example #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;
        }
Example #17
0
 public FunctionTypeDef(LayeTypeDef type)
     : base(type)
 {
 }