11#ifndef ARK_COMPILER_BYTECODEREADER_HPP
12#define ARK_COMPILER_BYTECODEREADER_HPP
76 std::vector<bytecode_t>
pages {};
115 return static_cast<uint16_t
>((
padding << 4) | (
arg & 0xf000) >> 12);
140 void feed(
const std::string& file);
153 [[nodiscard]]
bool checkMagic()
const;
159 [[nodiscard]]
Version version()
const;
166 [[nodiscard]]
unsigned long long timestamp()
const;
172 [[nodiscard]] std::vector<unsigned char> sha256()
const;
178 [[nodiscard]]
Symbols symbols()
const;
211 std::optional<internal::InstLoc> findSourceLocation(
const std::vector<internal::InstLoc>& inst_locations, std::size_t ip, std::size_t pp)
const;
222 std::optional<uint16_t> sStart = std::nullopt,
223 std::optional<uint16_t> sEnd = std::nullopt,
224 std::optional<uint16_t> cPage = std::nullopt)
const;
226 void printInstruction(std::ostream& os, uint8_t inst, uint8_t padding, uint16_t imm_arg,
const Symbols& syms,
const Values& vals,
bool colorize =
true)
const;
232 std::unordered_map<internal::Instruction, internal::ArgKind>
m_arg_kinds;
240 [[nodiscard]] uint16_t readNumber(std::size_t& i)
const;
Common code for the compiler.
The different instructions used by the compiler and virtual machine.
Default value type handled by the virtual machine.
This class is just a helper to.
std::unordered_map< internal::Instruction, internal::ArgKind > m_arg_kinds
Ark state to handle the dirty job of loading and compiling ArkScript code.
@ Raw
Keep all text as is without modifying it (useful for the code formatter)
@ RawSym
Symbol index, symbol.
@ RawRaw
Symbol index, symbol index.
@ BuiltinRaw
Builtin, number.
@ RawConst
Symbol index, constant.
@ ConstRaw
Constant, number.
std::vector< uint8_t > bytecode_t
std::vector< bytecode_t > pages
std::size_t start
Point to the CODE_SEGMENT_START byte in the bytecode.
std::size_t end
Point to the byte following the last byte of the table in the bytecode.
std::vector< std::string > filenames
std::size_t start
Point to the FILENAMES_TABLE_START byte in the bytecode.
std::size_t end
Point to the byte following the last byte of the table in the bytecode.
std::size_t start
Point to the INST_LOC_TABLE_START byte in the bytecode.
std::vector< internal::InstLoc > locations
std::vector< std::string > symbols
std::size_t end
Point to the byte following the last byte of the table in the bytecode.
std::size_t start
Point to the SYM_TABLE_START byte in the bytecode.
std::vector< Value > values
std::size_t end
Point to the byte following the last byte of the table in the bytecode.
std::size_t start
Point to the VAL_TABLE_START byte in the bytecode.
uint16_t secondary() const