예제 #1
0
        private static void emitByte(byte byte_)
        {
            Chunk_t _chunk = currentChunk();

            Chunk.writeChunk(ref _chunk, byte_, parser.previous.line);
            current.function.chunk = _chunk; // workaround
        }
예제 #2
0
파일: Chunk.cs 프로젝트: drewbanas/cloxcs
 public static int addConstant(ref Chunk_t chunk, Value_t value)
 {
     VM.push(value);
     Value.writeValueArray(ref chunk.constants, value);
     VM.pop();
     return(chunk.constants.count - 1);
 }
예제 #3
0
파일: Chunk.cs 프로젝트: drewbanas/cloxcs
 public static void initChunk(ref Chunk_t chunk)
 {
     chunk.count    = 0;
     chunk.capacity = 0;
     chunk.code     = null;
     chunk.lines    = null;
     Value.initiValueArray(ref chunk.constants);
 }
예제 #4
0
파일: Chunk.cs 프로젝트: drewbanas/cloxcs
        public static void freeChunk(ref Chunk_t chunk)
        {
            Memory.FREE_ARRAY <byte>(typeof(byte), ref chunk.code, chunk.capacity);
            Memory.FREE_ARRAY <int>(typeof(int), ref chunk.lines, chunk.capacity);

            Value.freeValueArray(ref chunk.constants);

            initChunk(ref chunk);
        }
예제 #5
0
        private static byte makeConstant(Value_t value)
        {
            Chunk_t _chunk   = currentChunk();
            int     constant = Chunk.addConstant(ref _chunk, value);

            if (constant > byte.MaxValue)
            {
                error("Too many constant in one chunk.");
                return(0);
            }

            current.function.chunk = _chunk; // work around
            return((byte)constant);
        }
예제 #6
0
파일: Chunk.cs 프로젝트: drewbanas/cloxcs
        public static void writeChunk(ref Chunk_t chunk, byte byte_, int line)
        {
            if (chunk.capacity < chunk.count + 1)
            {
                int oldCapacity = chunk.capacity;
                chunk.capacity = Memory.GROW_CAPACITY(oldCapacity);
                chunk.code     = (byte[])Memory.GROW_ARRAY <byte>(ref chunk.code, typeof(byte), oldCapacity, chunk.capacity);
                chunk.lines    = (int[])Memory.GROW_ARRAY <int>(ref chunk.lines, typeof(int), oldCapacity, chunk.capacity);
            }

            chunk.code[chunk.count]  = byte_;
            chunk.lines[chunk.count] = line;
            chunk.count++;
        }
예제 #7
0
        private static ObjFunction endCompiler()
        {
            emitReturn();
            ObjFunction function = current.function;

#if DEBUG_PRINT_CODE
            if (!parser.hadError)
            {
                Chunk_t _chunk = currentChunk();
                Debug.disassembleChunk(ref _chunk, function.name != null ? function.name.chars : "<script>".ToCharArray());
            }
#endif

            current = current.enclosing;
            return(function);
        }
예제 #8
0
파일: Chunk.cs 프로젝트: drewbanas/cloxcs
 public static void writeChunk(ref Chunk_t chunk, OpCode opcode, int line)
 {
     writeChunk(ref chunk, (byte)opcode, line);
 }