Esempio n. 1
0
 public AssignerExpressionCompiler(CompilerState state, int left, int right)
 {
     State = state;
     NumResults = 1;
     leftPosition = left;
     rightPosition = right;
 }
Esempio n. 2
0
        public FunctionCompiler(CompilerState oldState, AST.Body body, bool selfFunction)
        {
            State = new CompilerState();

            State.initialClosureStackPosition = oldState.closureStackPosition;
            State.closureStackPosition = oldState.closureStackPosition;
            State.closedVars = oldState.closedVars;
            foreach (KeyValuePair<String, int> i in oldState.newClosedVars)
            {
                State.closedVars[i.Key] = i.Value;
            }

            State.stackPosition = 1;

            CompilerState.SavedState savedState = State.SaveState();

            List<String> paramList = body.ParamList.NamedParams;
            if (selfFunction)
            {
                List<String> pList = new List<String>();
                pList.Add("self");
                pList.AddRange(paramList);
                paramList = pList;
            }

            if (paramList.Count > 0)
            {
                State.bytecodes.Add(VirtualMachine.OpCodes.MakePOPVARGS(paramList.Count));
                State.bytecodes.Add(VirtualMachine.OpCodes.MakeCLOSEVAR(paramList.Count));
                State.stackPosition += paramList.Count;
            }

            int stackIndex = 1;
            foreach (String param in paramList)
            {
                State.stackVars[param] = stackIndex;
                stackIndex++;

                State.newClosedVars[param] = State.closureStackPosition;
                State.closureStackPosition++;
            }

            if (body.ParamList.HasVarArgs)
            {
                State.stackVars["..."] = 0;
            }

            new ChunkCompiler(body.Chunk, State, savedState, true);
            State.ResolveJumps();

            Id = Guid.NewGuid().ToString();
        }
Esempio n. 3
0
        public ChunkCompiler(AST.Chunk chunk, CompilerState state, CompilerState.SavedState save, bool returns)
        {
            State = state;

            savedState = save;
            if (save == null)
            {
                savedState = State.SaveState();
            }

            foreach (AST.Statement statement in chunk.Statements)
            {
                state.positions[state.bytecodes.Count] = statement.SourcePos;
                statement.Visit(this);
            }

            CleanupChunk();

            if (!hasReturned && returns)
            {
                state.bytecodes.Add(VirtualMachine.OpCodes.MakeRET(0));
            }
        }
Esempio n. 4
0
 public ExpressionCompiler(CompilerState state, int numResults)
 {
     State = state;
     NumResults = numResults;
 }
Esempio n. 5
0
 public ExpressionCompiler(CompilerState state)
 {
     State = state;
     NumResults = 1;
 }