internal ElaValue GetField(ElaValue index, ExecutionContext ctx) { if (vm != null) { if (index.TypeId != ElaMachine.STR) { ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), index); return(Default()); } var field = index.DirectGetString(); var frame = vm.Assembly.GetModule(Handle); ScopeVar sc; if (!frame.GlobalScope.Locals.TryGetValue(field, out sc)) { ctx.UnknownField(index.DirectGetString(), new ElaValue(this)); return(Default()); } if ((sc.Flags & ElaVariableFlags.Private) == ElaVariableFlags.Private) { ctx.Fail(new ElaError(ElaRuntimeError.PrivateVariable, field)); return(Default()); } return(vm.modules[Handle][sc.Address]); } ctx.Fail(ElaRuntimeError.Unknown, "VM is non present"); return(Default()); }
internal bool HasField(ElaValue key, ExecutionContext ctx) { var idx = key.I4; if (key.TypeId != ElaMachine.STR) { ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), key); return(false); } return(GetOrdinal(key.DirectGetString()) != -1); }
internal bool HasField(ElaValue index, ExecutionContext ctx) { if (vm != null) { if (index.TypeId != ElaMachine.STR) { ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), index); return(false); } var frame = vm.Assembly.GetModule(Handle); return(frame.GlobalScope.Locals.ContainsKey(index.DirectGetString())); } ctx.Fail(ElaRuntimeError.Unknown, "VM is non present"); return(false); }
internal ElaValue GetField(ElaValue key, ExecutionContext ctx) { if (key.TypeId != ElaMachine.STR) { ctx.InvalidType(TCF.GetShortForm(ElaTypeCode.String), key); return(Default()); } var idx = GetOrdinal(key.DirectGetString()); if (idx == -1) { ctx.UnknownField(key.DirectGetString(), new ElaValue(this)); return(Default()); } return(values[idx]); }
private static Exception InvalidCast(ElaValue val, System.Type target) { return(new InvalidCastException(Strings.GetMessage("InvalidCast", TCF.GetShortForm(val.TypeCode), target.Name))); }
private static Exception InvalidCast(ElaValue val, ElaTypeCode type) { return(new ElaRuntimeException(ElaRuntimeError.InvalidType, TCF.GetShortForm(type), val.GetTypeName())); }
public TypeData(ElaTypeCode typeCode) : this((Int32)typeCode, TCF.GetShortForm(typeCode)) { }
protected internal virtual string GetTypeName() { return(TCF.GetShortForm((ElaTypeCode)TypeId)); }
public static TreeNode Literal(this TreeNode par, ElaExpression exp, ElaTypeCode typeCode, object data) { return(Element(par, exp, TCF.GetShortForm(typeCode), data, "Literal", "{1} ({0})")); }
//Main method for type compilation private void CompileTypeHeader(ElaNewtype v, LabelMap map) { //We need to obtain typeId for a type var tc = -1; var sca = -1; var flags = v.Flags; //A body may be null only if this is a built-in type if (!v.HasBody && v.Extends) { AddError(ElaCompilerError.ExtendsNoDefinition, v, v.Name); } else if (!v.HasBody) { tc = (Int32)TCF.GetTypeCode(v.Name); tc = tc == 0 ? -1 : tc; sca = AddVariable("$$" + v.Name, v, flags | ElaVariableFlags.ClosedType | ElaVariableFlags.CompilerGenerated, tc); var sv = GetVariable("$$" + v.Name, v.Line, v.Column); //OK, type is built-in if (tc > 0) { //We add a special variable that contains a global type ID cw.Emit(Op.PushI4, tc); PopVar(sca); } } else { var tf = flags; if (!v.Opened) { tf |= ElaVariableFlags.ClosedType; } sca = v.Extends ? AddVariable() : AddVariable("$$" + v.Name, v, tf | ElaVariableFlags.CompilerGenerated, -1); } //Type is already declared within the same module (types from different //modules can shadow each, so this is perfectly OK). if (!v.Extends && frame.InternalTypes.ContainsKey(v.Name)) { AddError(ElaCompilerError.TypeAlreadyDeclared, v, v.Name); frame.InternalTypes.Remove(v.Name); } if (v.Prefix != null && !v.Extends) { AddError(ElaCompilerError.InvalidTypeDefinition, v); } if (!v.Extends) { frame.InternalTypes.Add(v.Name, tc); } AddLinePragma(v); //-1 mean "this" module (considered by default). var typeModuleId = -1; //Add a type var for a non built-in type with a body if (tc == -1) { //Add a special variable with global type ID which will be calculated at run-time if (v.Extends) { var sv = EmitSpecName(v.Prefix, "$$" + v.Name, v, ElaCompilerError.UndefinedType, out typeModuleId); //We can only extend type that are explicitly declared as open if ((sv.Flags & ElaVariableFlags.ClosedType) == ElaVariableFlags.ClosedType) { AddError(ElaCompilerError.UnableExtendOpenType, v, v.Name); } } else { cw.Emit(Op.Typeid, AddString(v.Name)); } PopVar(sca); v.TypeModuleId = typeModuleId; v.ScopeVar = sca; //if (v.HasBody) //{ // for (var i = 0; i < v.Constructors.Count; i++) // { // var c = v.Constructors[i]; // var cf = v.ConstructorFlags[i]; // cf = cf == ElaVariableFlags.None ? flags : cf|flags; // CompileConstructor(v.Name, sca, c, cf, typeModuleId); // } //} } else { cw.Emit(Op.Nop); } }