示例#1
0
        public void CheckForUnresolvedReferences()
        {
            bool          hasUndeffed = false;
            StringBuilder undeffed    = new StringBuilder("Undefined references: ");

            foreach (LabelSymbol label in _labels.Values)
            {
                if (label.IsFwdRef)
                {
                    undeffed.Append(label.Name);
                    undeffed.Append(",");
                    hasUndeffed = true;
                }
            }

            foreach (object obj in _constPool.Where(p => p is FunctionSymbol))
            {
                FunctionSymbol sym = (FunctionSymbol)obj;
                if (sym.IsFwdRef)
                {
                    undeffed.Append(sym.Name);
                    undeffed.Append(",");
                    hasUndeffed = true;
                }
            }

            if (hasUndeffed)
            {
                throw new GenerationException(undeffed.ToString());
            }
        }
示例#2
0
        public override bool Equals(object obj)
        {
            FunctionSymbol f = obj as FunctionSymbol;

            if (f != null)
            {
                return(f.Name == this.Name);
            }

            return(false);
        }
示例#3
0
        /// <summary>
        /// Transform FunctionSymbol(s) to the more compact FuncInfo structure
        /// </summary>
        /// <returns></returns>
        private object[] FinalizeConstPool()
        {
            object[] finalConstPool = new object[_constPool.Count];

            for (int i = 0; i < _constPool.Count; ++i)
            {
                object         obj = _constPool[i];
                FunctionSymbol fs  = obj as FunctionSymbol;
                if (fs != null)
                {
                    finalConstPool[i] = fs.ToFunctionInfo();
                }
                else
                {
                    finalConstPool[i] = obj;
                }
            }

            return(finalConstPool);
        }
示例#4
0
        public int GetFunctionIndex(string funcId)
        {
            FunctionSymbol searchSym;

            if (_functions.TryGetValue(funcId, out searchSym))
            {
                if (searchSym.IsFwdRef)
                {
                    searchSym.AddFwdRef(_ip);
                }

                return(searchSym.ConstIndex);
            }
            else
            {
                searchSym = new FunctionSymbol(funcId, _constPool.Count);
                _functions.Add(funcId, searchSym);
                _constPool.Add(searchSym);
                searchSym.AddFwdRef(_ip);
                return(searchSym.ConstIndex);
            }
        }
示例#5
0
        public void DefineFunction(IToken idToken, int nargs, int nlocals)
        {
            FunctionSymbol searchSym;

            if (_functions.TryGetValue(idToken.Text, out searchSym))
            {
                if (searchSym.IsFwdRef)
                {
                    searchSym.Define(_ip, nargs, nlocals);
                    searchSym.ResolveFwdRefs(_code);
                }
                else
                {
                    throw new GenerationException(String.Format("Function '{0}' already defined", idToken.Text));
                }
            }
            else
            {
                searchSym = new FunctionSymbol(idToken.Text, _ip, _constPool.Count, nargs, nlocals);
                _functions.Add(idToken.Text, searchSym);
                _constPool.Add(searchSym);
            }
        }