Pod is a module containing Types. A Pod is always backed by a FPod instance which defines all the definition tables. Usually the FPod is in turn backed by a FStore for the pod's zip file. However in the case of memory-only pods defined by the compiler, the fpod.store field will be null. Pods is loaded as soon as it is constructed: 1) All the types defined by the fpod are mapped into hollow Types. 2) It is emitted as a Java class called "fan.{podName}.$Pod". The emitted class is basically a manifestation of the literal tables, after which we can clear the fpod data structures.
Inheritance: FanObj
Ejemplo n.º 1
0
 public Map get(Pod pod, Uri uri, Duration maxAge)
 {
     Key key = new Key(pod, uri);
       CachedProps cp = (CachedProps)m_cache[key];
       if (cp == null || Duration.nowTicks() - cp.m_read > maxAge.m_ticks)
     cp = refresh(key, cp);
       return cp.m_props;
 }
Ejemplo n.º 2
0
        private string sig; // signature being parsed

        #endregion Fields

        #region Constructors

        //////////////////////////////////////////////////////////////////////////
        // Constructor
        //////////////////////////////////////////////////////////////////////////
        private TypeParser(string sig, bool check, Pod loadingPod)
        {
            this.sig        = sig;
              this.len        = sig.Length;
              this.pos        = 0;
              this.cur        = sig[pos];
              this.peek       = sig[pos+1];
              this.check      = check;
              this.loadingPod = loadingPod;
        }
Ejemplo n.º 3
0
 public static Facets mapFacets(Pod pod, FAttrs.FFacet[] ffacets)
 {
     if (ffacets == null || ffacets.Length == 0) return empty();
       Hashtable map = new Hashtable();
       for (int i=0; i<ffacets.Length; ++i)
       {
     FAttrs.FFacet ff = ffacets[i];
     Type t = pod.findType(ff.type);
     map[t] = ff.val;
       }
       return new Facets(map);
 }
Ejemplo n.º 4
0
        //////////////////////////////////////////////////////////////////////////
        // Factory
        //////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Parse the signature into a loaded type.
        /// </summary>
        public static Type load(string sig, bool check, Pod loadingPod)
        {
            // if last character is ?, then parse a nullable
              int len = sig.Length;
              int last = len > 1 ? sig[len-1] : 0;
              if (last == '?')
            return load(sig.Substring(0, len-1), check, loadingPod).toNullable();

              // if the last character isn't ] or |, then this a non-generic
              // type and we don't even need to allocate a parser
              if (last != ']' && last != '|')
              {
            string podName, typeName;
            try
            {
              int colon = sig.IndexOf(':');
              if (sig[colon+1] != ':') throw new System.Exception();
              podName  = sig.Substring(0, colon);
              typeName = sig.Substring(colon+2);
              if (podName.Length == 0 || typeName.Length == 0) throw new System.Exception();
            }
            catch (System.Exception)
            {
              throw ArgErr.make("Invalid type signature '" + sig + "', use <pod>::<type>").val;
            }

            // if the type is from the pod being loaded then return to the pod
            if (loadingPod != null && podName == loadingPod.name())
              return loadingPod.type(typeName, check);

            // do a straight lookup
            return find(podName, typeName, check);
              }

              // we got our work cut out for us - create parser
              try
              {
            return new TypeParser(sig, check, loadingPod).LoadTop();
              }
              catch (Err.Val e)
              {
            throw e;
              }
              catch (System.Exception)
              {
            throw Err(sig).val;
              }
        }
Ejemplo n.º 5
0
 static Map readDef(Pod pod, Uri uri)
 {
     uri = Uri.fromStr(pod.uri() + "/" + uri);
       Fan.Sys.File f = (Fan.Sys.File)pod.file(uri, false);
       Map map = Sys.m_emptyStrStrMap;
       try
       {
     if (f != null) map = (Map)f.readProps().toImmutable();
       }
       catch (System.Exception e)
       {
     System.Console.WriteLine("ERROR: Cannot load props " + pod + "::" + uri);
     System.Console.WriteLine("  " + e);
       }
       return map;
 }
Ejemplo n.º 6
0
 public virtual string config(Pod pod, string key)
 {
     return(config(pod, key, null));
 }
Ejemplo n.º 7
0
 public virtual Map props(Pod pod, Uri uri, Duration maxAge)
 {
     return(m_props.get(pod, uri, maxAge));
 }
Ejemplo n.º 8
0
Archivo: Fant.cs Proyecto: nomit007/f4
        private Type[] tests(Pod pod, string testName)
        {
            // named test
              if (testName != "*") return new Type[] { pod.type(testName, true) };

              // all types which subclass Test
              List all = pod.types();
              ArrayList acc = new ArrayList();
              for (int i=0; i<all.sz(); i++)
              {
            Type x = (Type)all.get(i);
            if (x.@is(Sys.TestType) && !x.isAbstract()) acc.Add(x);
              }
              return (Type[])acc.ToArray(System.Type.GetType("Fan.Sys.Type"));
        }
Ejemplo n.º 9
0
Archivo: Pod.cs Proyecto: nomit007/f4
        public static Pod load(InStream @in)
        {
            FPod fpod = null;
              try
              {
            fpod = new FPod(null, null);
            fpod.readFully(new ZipInputStream(SysInStream.dotnet(@in)));
              }
              catch (Exception e)
              {
            throw Err.make(e).val;
              }

              string name = fpod.m_podName;
              lock (m_podsByName)
              {
            // check for duplicate pod name
            if (m_podsByName[name] != null)
              throw Err.make("Duplicate pod name: " + name).val;

            // create Pod and add to master table
            Pod pod = new Pod(fpod);
            m_podsByName[name] = pod; //new SoftReference(pod);
            return pod;
              }
        }
Ejemplo n.º 10
0
Archivo: Pod.cs Proyecto: nomit007/f4
        public static Pod doFind(string name, bool check, FPod fpod)
        {
            try
              {
            lock (m_podsByName)
            {
              // TODO - .NET does not have soft references, so how could
              // we implement this?  See the Pod.java for the java impl.

              Pod pod = (Pod)m_podsByName[name];
              if (pod == null)
              {
            // if fpod is non-null, then we are "creating" this pod in
            // memory direct from the compiler, otherwise we need to
            // find the pod zip file and load it's meta-data
            if (fpod == null) fpod = readFPod(name);

            // sanity check
            if (fpod.m_podName != name)
              throw new Exception("Mismatched pod name b/w pod.def and pod zip filename: " + fpod.m_podName + " != " + name);

            // create the pod and register it
            pod = new Pod(fpod);
            m_podsByName[name] = pod;
              }
              return pod;
            }
              }
              catch (UnknownPodErr.Val e)
              {
            if (!check) return null;
            throw e;
              }
              catch (Exception e)
              {
            Err.dumpStack(e);
            if (!check) return null;
            throw UnknownPodErr.make(name, e).val;
              }
        }
Ejemplo n.º 11
0
 public virtual string locale(Pod pod, string key, string def)
 {
     return(locale(pod, key, def, Locale.cur()));
 }
Ejemplo n.º 12
0
Archivo: Env.cs Proyecto: nomit007/f4
 public virtual Map props(Pod pod, Uri uri, Duration maxAge)
 {
     return m_props.get(pod, uri, maxAge);
 }
Ejemplo n.º 13
0
Archivo: Env.cs Proyecto: nomit007/f4
        public virtual string locale(Pod pod, string key, string def, Locale locale)
        {
            object val;
              Duration maxAge = Duration.m_maxVal;

              // 1. 'props(pod, `locale/{locale}.props`)'
              val = props(pod, locale.m_strProps, maxAge).get(key, null);
              if (val != null) return (string)val;

              // 2. 'props(pod, `locale/{lang}.props`)'
              val = props(pod, locale.m_langProps, maxAge).get(key, null);
              if (val != null) return (string)val;

              // 3. 'props(pod, `locale/en.props`)'
              val = props(pod, m_localeEnProps, maxAge).get(key, null);
              if (val != null) return (string)val;

              // 4. Fallback to 'pod::key' unless 'def' specified
              if (def == m_noDef) return pod + "::" + key;
              return def;
        }
Ejemplo n.º 14
0
Archivo: Env.cs Proyecto: nomit007/f4
 public virtual string locale(Pod pod, string key, string def)
 {
     return locale(pod, key, def, Locale.cur());
 }
Ejemplo n.º 15
0
Archivo: Env.cs Proyecto: nomit007/f4
 public virtual string locale(Pod pod, string key)
 {
     return locale(pod, key, m_noDef, Locale.cur());
 }
Ejemplo n.º 16
0
Archivo: Env.cs Proyecto: nomit007/f4
 public virtual string config(Pod pod, string key, string def)
 {
     return (string)m_props.get(pod, m_configProps, Duration.m_oneMin).get(key, def);
 }
Ejemplo n.º 17
0
Archivo: Env.cs Proyecto: nomit007/f4
 public virtual string config(Pod pod, string key)
 {
     return config(pod, key, null);
 }
Ejemplo n.º 18
0
 public virtual string config(Pod pod, string key, string def)
 {
     return((string)m_props.get(pod, m_configProps, Duration.m_oneMin).get(key, def));
 }
Ejemplo n.º 19
0
 public virtual string locale(Pod pod, string key)
 {
     return(locale(pod, key, m_noDef, Locale.cur()));
 }
Ejemplo n.º 20
0
 // parameterized type constructor
 public ClassType(Pod pod, string name, int flags, Facets facets)
 {
     this.m_pod      = pod;
       this.m_name     = name;
       this.m_qname    = pod.m_name + "::" + name;
       this.m_nullable = new NullableType(this);
       this.m_flags    = flags;
       this.m_facets   = facets;
 }
Ejemplo n.º 21
0
 //////////////////////////////////////////////////////////////////////////
 // Constructor
 //////////////////////////////////////////////////////////////////////////
 internal ClassType(Pod pod, FType ftype)
 {
     this.m_pod      = pod;
       this.m_ftype    = ftype;
       this.m_name     = pod.fpod.typeRef(ftype.m_self).typeName;
       this.m_qname    = pod.m_name + "::" + m_name;
       this.m_nullable = new NullableType(this);
       this.m_flags    = ftype.m_flags;
       if (Debug) Console.WriteLine("-- init:   " + m_qname);
 }
Ejemplo n.º 22
0
 public Key(Pod p, Uri u)
 {
     m_pod = p; m_uri = u;
 }
Ejemplo n.º 23
0
        //////////////////////////////////////////////////////////////////////////
        // Locale
        //////////////////////////////////////////////////////////////////////////

        public string toLocale()
        {
            long          ticks  = this.m_ticks;
            Pod           pod    = Sys.m_sysPod;
            Env           env    = Env.cur();
            Locale        locale = Locale.cur();
            StringBuilder s;

            // less than 1000ns Xns
            if (ticks < 1000L)
            {
                return(ticks + env.locale(pod, "nsAbbr", "ns", locale));
            }

            // less than 2ms X.XXXms
            if (ticks < 2 * nsPerMilli)
            {
                s = new StringBuilder();
                long ms = ticks / nsPerMilli;
                long us = (ticks - ms * nsPerMilli) / 1000L;
                s.Append(ms);
                s.Append('.');
                if (us < 100)
                {
                    s.Append('0');
                }
                if (us < 10)
                {
                    s.Append('0');
                }
                s.Append(us);
                if (s[s.Length - 1] == '0')
                {
                    s.Length = s.Length - 1;
                }
                if (s[s.Length - 1] == '0')
                {
                    s.Length = s.Length - 1;
                }
                s.Append(env.locale(pod, "msAbbr", "ms", locale));
                return(s.ToString());
            }

            // less than 2sec Xms
            if (ticks < 2L * nsPerSec)
            {
                return((ticks / nsPerMilli) + env.locale(pod, "msAbbr", "ms", locale));
            }

            // less than 2min Xsec
            if (ticks < 1L * nsPerMin)
            {
                return((ticks / nsPerSec) + env.locale(pod, "secAbbr", "sec", locale));
            }

            // [Xdays] [Xhr] Xmin Xsec
            long days = ticks / nsPerDay; ticks -= days * nsPerDay;
            long hr   = ticks / nsPerHr;    ticks -= hr * nsPerHr;
            long min  = ticks / nsPerMin;   ticks -= min * nsPerMin;
            long sec  = ticks / nsPerSec;

            s = new StringBuilder();
            if (days > 0)
            {
                s.Append(days).Append(days == 1 ? env.locale(pod, "dayAbbr", "day", locale) : env.locale(pod, "daysAbbr", "days", locale)).Append(" ");
            }
            if (hr > 0)
            {
                s.Append(hr).Append(env.locale(pod, "hourAbbr", "hr", locale)).Append(" ");
            }
            if (min > 0)
            {
                s.Append(min).Append(env.locale(pod, "minAbbr", "min", locale)).Append(" ");
            }
            if (sec > 0)
            {
                s.Append(sec).Append(env.locale(pod, "secAbbr", "sec", locale)).Append(" ");
            }
            s.Length = s.Length - 1;
            return(s.ToString());
        }
Ejemplo n.º 24
0
 internal UsingPod(Pod p)
 {
     pod = p;
 }