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()))); }
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])); }
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]; } }
public NullTypeDef(LayeTypeDef type) : base(type) { }
public KitTypeDef(LayeTypeDef type) : base(type) { }
public bool TypeOf(LayeState state, LayeTypeDef thatType) { if (type == null || thatType == null) return false; return type.InheritsFromOrIs(thatType); }
public LayeObject(LayeTypeDef type) { this.type = type; }
public BoolTypeDef(LayeTypeDef type) : base(type) { }
public bool InheritsFromOrIs(LayeTypeDef that) { if (ReferenceEquals(this, that)) return true; // TODO inheritance return false; }
public void PutAsCast(LayeTypeDef to, LayeObject cast) { if (to == null) throw new ArgumentNullException(); else if (cast == null) throw new ArgumentNullException(); asCasts[to] = cast; }
public bool FindAsCast(LayeTypeDef to, out LayeObject cast) { if (to == null) throw new ArgumentNullException(); asCasts.TryGetValue(to, out cast); return cast != null; }
public SymbolTypeDef(LayeTypeDef type) : base(type) { type.PutAsCast(LayeString.TYPE, (LayeCallback)((state, ths, args) => new LayeString((ths as LayeSymbol).value))); }
public IntTypeDef(LayeTypeDef type) : base(type) { type.PutPrefix("#", (LayeCallback)Prefix__DigitCount); }
public FloatTypeDef(LayeTypeDef type) : base(type) { type.PutAsCast(LayeInt.TYPE, (LayeCallback)As__Int); }
public StringTypeDef(LayeTypeDef type) : base(type) { type.PutPrefix("#", (LayeCallback)((state, ths, args) => new LayeInt((ths as LayeString).value.Length))); type.PutInfix("*", (LayeCallback)Infix__repeat); }
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; }
public FunctionTypeDef(LayeTypeDef type) : base(type) { }