public override IValue interpret(Context context) { // TODO synchronize ConcreteInstance instance = context.loadSingleton(type); Context instanceContext = context.newInstanceContext(instance, true); Context childContext = instanceContext.newChildContext(); return(statements.interpret(childContext)); }
public override IValue getStaticMemberValue(Context context, String name) { IDeclaration decl = getDeclaration(context); if (decl is EnumeratedCategoryDeclaration || decl is EnumeratedNativeDeclaration) { return(decl.GetIType(context).getStaticMemberValue(context, name)); } else if (decl is SingletonCategoryDeclaration) { ConcreteInstance singleton = context.loadSingleton(this); return(singleton.GetMemberValue(context, name, false)); } else { return(base.getStaticMemberValue(context, name)); } }
public ConcreteInstance loadSingleton(CategoryType type) { if (this == globals) { IValue value = null; values.TryGetValue(type.GetTypeName(), out value); if (value == null) { IDeclaration decl = declarations[type.GetTypeName()]; if (!(decl is ConcreteCategoryDeclaration)) { throw new InternalError("No such singleton:" + type.GetTypeName()); } value = new ConcreteInstance(this, (ConcreteCategoryDeclaration)decl); ((IInstance)value).setMutable(true); // a singleton is protected by "with x do", so always mutable in that context ConcreteMethodDeclaration method = ((SingletonCategoryDeclaration)decl).getInitializeMethod(this); if (method != null) { Context instance = newInstanceContext((IInstance)value, false); Context child = instance.newChildContext(); method.interpret(child); } values[type.GetTypeName()] = value; } if (value is ConcreteInstance) { return((ConcreteInstance)value); } else { throw new InternalError("Not a concrete instance:" + value.GetType().Name); } } else { return(this.globals.loadSingleton(type)); } }