Exemple #1
0
        internal static void AsmStatement(string asm)
        {
            string[] parts = asm.Trim('"').Split();

            OpCode code = (OpCode)Enum.Parse(typeof(OpCode), parts[0]);
            string arg  = parts.Length > 1 ? parts[1] : "";

            OpCodeEmitter asmOp = new OpCodeEmitter(code, arg);

            CStatment stat = new CStatment();

            stat.Add(asmOp);

            PushStatement(stat);
        }
Exemple #2
0
        internal CStatment GetDefinitionStatment()
        {
            if (Init == null)
            {
                return(new CStatment());
            }

            if (type.IsStruct)
            {
                throw new SemanticException("local variables of type struct are not implimentd");
            }
            else if (type.IsArray || Init.IsList)
            {
                throw new SemanticException("local variables of type array are not implimentd");
            }
            else if (type.TypeClass == CTypeClass.CFunction)
            {
                throw new InvalidOperationException("wtf how did you declare a local function varable");
            }
            else if (type.TypeClass == CTypeClass.CVoid)
            {
                throw new InvalidOperationException("wtf how did you declare a local void varable");
            }
            else
            {
                OpCode PushOp;

                if (type.Size == 1)
                {
                    PushOp = OpCode.PUSHB;
                }
                else if (type.Size == 2)
                {
                    PushOp = OpCode.PUSHH;
                }
                else if (type.Size == 4)
                {
                    PushOp = OpCode.PUSHW;
                }
                else
                {
                    throw new InvalidOperationException("local variable of unknown size");
                }

                CStatment initilize = new CStatment();
                initilize.Add(new OpCodeEmitter(PushOp, "0"));

                CExpression localAddr = new CExpression(type, ValueCatagory.LValue);

                localAddr.Add(new OpCodeEmitter(OpCode.PUSHBP));
                localAddr.Add(new OpCodeEmitter(OpCode.PUSHW, stackPointerOffset.ToString()));
                localAddr.Add(new OpCodeEmitter(OpCode.ADD));

                CExpression.PushExpression(localAddr);
                CExpression.PushExpression(Init.Expression);

                CExpression.BasicAssignmentOperator();

                initilize.Add(new CStatment(CExpression.PopExpression()));

                return(initilize);
            }
        }