Exemplo n.º 1
0
        public void FuncCallStart(string funcName)
        {
            DatSymbol symbol = GetSymbolByName(funcName);

            List <DatSymbolType> parametersTypes = new List <DatSymbolType>();

            for (int i = 1; i <= symbol.ParametersCount; ++i)
            {
                DatSymbol parameter = Symbols[symbol.Index + i];
                parametersTypes.Add(parameter.Type);
            }

            AssemblyInstruction instruction;

            if (symbol.Flags.HasFlag(DatSymbolFlag.External))
            {
                instruction = new CallExternal(symbol);
            }
            else
            {
                instruction = new Call(symbol);
            }

            FuncCallCtx    = new FuncCallContext(_activeContext, FuncCallCtx, parametersTypes, symbol);
            _activeContext = FuncCallCtx;
            _activeContext.SetEndInstruction(instruction);

            IsInsideArgList = true;
        }
Exemplo n.º 2
0
        public AssemblyBuilder(bool verbose = true)
        {
            ExecBlocks          = new List <BaseExecBlockContext>();
            Symbols             = new List <DatSymbol>();
            _symbolsDict        = new Dictionary <string, DatSymbol>();
            _activeContext      = null;
            ActiveExecBlock     = null;
            _assignmentLeftSide = new List <SymbolInstruction>();
            FuncCallCtx         = null;


            _nextStringSymbolNumber     = 10000;
            IsInsideConstDef            = false;
            IsCurrentlyParsingExternals = false;

            IsInsideArgList         = false;
            IsInsideAssignment      = false;
            IsInsideReturnStatement = false;
            AssignmentType          = DatSymbolType.Undefined;
            _nextSymbolIndex        = 0;
            _verbose = verbose;

            Errors       = new List <CompilationMessage>();
            ErrorContext = new ErrorContext(this);
        }
 public FuncCallContext(AssemblyBuilderContext parent, FuncCallContext outerCall, List <DatSymbolType> parametersTypes, DatSymbol symbol) : base(parent)
 {
     _symbol          = symbol;
     _parametersTypes = parametersTypes;
     ArgIndex         = -1;
     OuterCall        = outerCall;
     _instructions    = new List <AssemblyElement>();
 }
Exemplo n.º 4
0
        public void FuncCallEnd()
        {
            List <AssemblyElement> instructions = _activeContext.GetInstructions();

            FuncCallCtx    = FuncCallCtx.OuterCall;
            _activeContext = _activeContext.Parent;
            AddInstructions(instructions);

            if (FuncCallCtx == null)
            {
                IsInsideArgList = false;
            }
        }
        public override void FetchInstructions(AssemblyBuilderContext context)
        {
            switch (context)
            {
            case IfBlockContext ifBlockContext:
                IfBlock = ifBlockContext;
                break;

            case ElseIfBlockContext elseIfBlockContext:
                ElseIfBlocks.Add(elseIfBlockContext);
                break;

            case ElseBlockContext elseBlockContext:
                ElseBlock = elseBlockContext;
                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 6
0
        public void ExecBlockStart(DatSymbol symbol, ExecBlockType blockType)
        {
            switch (blockType)
            {
            case ExecBlockType.Function:
                ActiveExecBlock = new FunctionBlockContext(symbol);
                break;

            case ExecBlockType.Instance:
                ActiveExecBlock = new InstanceBlockContext(symbol);
                break;

            case ExecBlockType.Prototype:
                ActiveExecBlock = new PrototypeBlockContext(symbol);
                break;

            default:
                throw new NotImplementedException();
            }

            _activeContext = ActiveExecBlock;
            ExecBlocks.Add(ActiveExecBlock);
        }
Exemplo n.º 7
0
 public void ExpressionStart()
 {
     _activeContext = new ExpressionContext(_activeContext);
 }
Exemplo n.º 8
0
 public void FuncCallArgStart()
 {
     FuncCallCtx.ArgIndex++;
     _activeContext = new BlockContext(_activeContext);
 }
 public IfBlockStatementContext(AssemblyBuilderContext parent) : base(parent)
 {
     IfBlock      = null;
     ElseIfBlocks = new List <ElseIfBlockContext>();
     ElseBlock    = null;
 }
Exemplo n.º 10
0
 public void SharedBlockStart(List <DatSymbol> symbols)
 {
     ActiveExecBlock = new SharedExecBlockContext(symbols);
     _activeContext  = ActiveExecBlock;
     ExecBlocks.Add(ActiveExecBlock);
 }
 protected ConditionalBlockContext(AssemblyBuilderContext parent) : base(parent)
 {
     Condition = new List <AssemblyElement>();
 }
Exemplo n.º 12
0
 public void ActiveContextEnd()
 {
     _activeContext.Parent?.FetchInstructions(_activeContext);
     _activeContext = _activeContext.Parent;
 }
 public ExpressionContext(AssemblyBuilderContext parent) : base(parent)
 {
     _operatorInstruction = null;
 }
 public virtual void FetchInstructions(AssemblyBuilderContext context)
 {
     AddInstructions(context.GetInstructions());
 }
 protected ArgumentContext(AssemblyBuilderContext parent) : base(parent)
 {
 }
 protected StackBasedContext(AssemblyBuilderContext parent) : base(parent)
 {
     _instructionsStack = new Stack <List <AssemblyElement> >();
 }
 public ElseBlockContext(AssemblyBuilderContext parent) : base(parent)
 {
 }
Exemplo n.º 18
0
 public void IfBlockStart()
 {
     _activeContext = new IfBlockContext(_activeContext);
 }
Exemplo n.º 19
0
 public void ElseBlockStart()
 {
     _activeContext = new ElseBlockContext(_activeContext);
 }
 public BlockContext(AssemblyBuilderContext parent) : base(parent)
 {
     Body = new List <AssemblyElement>();
 }
 protected BaseExecBlockContext(AssemblyBuilderContext parent) : base(parent)
 {
 }
 protected AssemblyBuilderContext(AssemblyBuilderContext parent)
 {
     Parent = parent;
 }