From 33372512fc32c26913c8385637d20f6d98c8376c Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 22 Oct 2021 10:34:25 +0200 Subject: Add constants operation --- src/bytecode/chunk.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bytecode/chunk.h (limited to 'src/bytecode/chunk.h') diff --git a/src/bytecode/chunk.h b/src/bytecode/chunk.h new file mode 100644 index 0000000..29dd99d --- /dev/null +++ b/src/bytecode/chunk.h @@ -0,0 +1,22 @@ +#ifndef BDL_CHUNK_H +#define BDL_CHUNK_H + +#include "objects.h" +#include "darray.h" + +typedef struct Chunk { + u8 *code; + Object *constants; +} Chunk; + + +size_t add_constant(Chunk chunk, Object obj); + +size_t +add_constant(Chunk chunk, Object obj) { + size_t pos = array_size(chunk.constants); + array_push(chunk.constants, obj); + return pos; +} + +#endif // BDL_CHUNK_H -- cgit v1.2.1