Beispiel #1
0
        public static void NewObj()
        {
            SAR al   = SAS.Pop();
            SAR type = SAS.Pop();

            if (!SymbolTable.NewObj(type, al.argList.ToArray()))
            {
                SemanticError(type);
            }
            string functionSymid = type.symid;

            type.sarType = SAR.SARtype.Ref;
            type.symid   = "t" + uniqueCounter++;
            string[] data     = { "returnType:" + type.dataType, "accessMod:private" };
            Symbol   instance = new Symbol("t", type.symid, "t" + type.value, "tvar", data);

            SymbolTable.Add(instance);
            string[] data2    = { "returnType:" + type.dataType, "accessMod:private" };
            Symbol   peekTemp = new Symbol("t", "t" + uniqueCounter++, "t" + type.value + "ReturnValue", "tvar", data2);

            SymbolTable.Add(peekTemp);
            Symbol staticInit = SymbolTable.GetValue(("Y" + functionSymid.Substring(1)));

            ICode.NEWI(type.size.ToString(), type.symid);
            //call constructor
            ICode.FRAME(functionSymid, type.symid);
            if (al.argList != null && al.argList.Count > 0 && al.argList[0] != "")
            {
                for (int i = 0; i < al.argList.Count; ++i)
                {
                    ICode.PUSH(al.argList[i]);
                }
            }
            ICode.CALL(functionSymid);
            ICode.PEEK(peekTemp.symid);
            type.symid = peekTemp.symid;
            SAS.Push(type);
        }