예제 #1
0
        /// <summary>
        /// Create methods corresponding to a var declaration,
        /// backed by a cell, and store those methods under a
        /// given name.
        /// </summary>
        /// <param name="name">Name of var</param>
        /// <param name="methods">
        /// Mapping of names to methods to update
        /// </param>
        /// <param name="readable">
        /// True if this var is readable.
        /// </param>
        /// <param name="writable">
        /// True if this var is writable.
        /// </param>
        /// <param name="cell">
        /// Cell storing the value of this var
        /// </param>
        public virtual ReaderWriterPair CreateVar(
            string name,
            Dictionary <string, Method> methods,
            bool readable, bool writable,
            out Cell cell
            )
        {
            cell = new Cell(GraceObject.Uninitialised);
            var r = new FieldReaderMethod(cell);

            methods[name] = r;
            var w = new FieldWriterMethod(cell);

            methods[name + " :=(_)"] = w;
            if (!readable)
            {
                r.Confidential = true;
            }
            if (!writable)
            {
                w.Confidential = true;
            }
            cell.Writer = w;
            return(new ReaderWriterPair {
                Read = r, Write = w
            });
        }
예제 #2
0
파일: UserObject.cs 프로젝트: smarr/kernan
        /// <summary>
        /// Add method to this object representing a def
        /// declaration
        /// </summary>
        /// <param name="name">Name of the def to add</param>
        /// <param name="val">Value of this def</param>
        /// <returns>Added method</returns>
        public virtual Method AddLocalDef(string name, GraceObject val)
        {
            var c    = new Cell(val);
            var read = new FieldReaderMethod(c);

            AddMethod(name, read);
            return(read);
        }
예제 #3
0
파일: UserObject.cs 프로젝트: smarr/kernan
        /// <summary>
        /// Add methods to this object representing a var
        /// declaration
        /// </summary>
        /// <param name="name">Name of the var to add</param>
        /// <param name="val">Initial value of this var</param>
        /// <returns>Object encapsulating the added methods</returns>
        public virtual ReaderWriterPair AddLocalVar(string name,
                                                    GraceObject val)
        {
            var c      = new Cell(val == null ? GraceObject.Uninitialised : val);
            var reader = new FieldReaderMethod(c);
            var writer = new FieldWriterMethod(c);

            AddMethod(name, reader);
            AddMethod(name + " :=(_)", writer);
            return(new ReaderWriterPair {
                Read = reader, Write = writer
            });
        }
예제 #4
0
파일: UserObject.cs 프로젝트: smarr/kernan
        /// <summary>
        /// Create a method corresponding to a def declaration,
        /// backed by a cell, and store that method under a given
        /// name.
        /// </summary>
        /// <param name="name">Name of def</param>
        /// <param name="methods">
        /// Mapping of names to methods to update
        /// </param>
        /// <param name="readable">
        /// True if this def is public.
        /// </param>
        /// <param name="cell">
        /// Cell storing the value of this def
        /// </param>
        public virtual void CreateDef(
            string name,
            Dictionary <string, Method> methods,
            bool readable,
            out Cell cell
            )
        {
            cell = new Cell(GraceObject.Uninitialised);
            var m = new FieldReaderMethod(cell);

            methods[name] = m;
            if (!readable)
            {
                m.Confidential = true;
            }
        }