private static void emitByte(byte byte_) { Chunk_t _chunk = currentChunk(); Chunk.writeChunk(ref _chunk, byte_, parser.previous.line); current.function.chunk = _chunk; // workaround }
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); }
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); }
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); }
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); }
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++; }
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); }
public static void writeChunk(ref Chunk_t chunk, OpCode opcode, int line) { writeChunk(ref chunk, (byte)opcode, line); }