ArkScript
A small, lisp-inspired, functional scripting language
Ark::BytecodeReader Class Referencefinal

This class is just a helper to. More...

#include <BytecodeReader.hpp>

Collaboration diagram for Ark::BytecodeReader:
[legend]

Public Member Functions

 BytecodeReader ()=default
 Construct a new Bytecode Reader object.
 
void feed (const std::string &file)
 Construct needed data before displaying information about a given file.
 
void feed (const bytecode_t &bytecode)
 Construct needed data before displaying information about a given bytecode.
 
bool checkMagic () const
 
Version version () const
 
unsigned long long timestamp () const
 Return the read timestamp from the bytecode file.
 
std::vector< unsigned char > sha256 () const
 
Symbols symbols () const
 
Values values (const Symbols &symbols) const
 
Filenames filenames (const Values &values) const
 
InstLocations instLocations (const Filenames &filenames) const
 
Code code (const InstLocations &instLocations) const
 
void display (BytecodeSegment segment=BytecodeSegment::All, std::optional< uint16_t > sStart=std::nullopt, std::optional< uint16_t > sEnd=std::nullopt, std::optional< uint16_t > cPage=std::nullopt) const
 Display the bytecode opcode in a human friendly way.
 

Private Member Functions

uint16_t readNumber (std::size_t &i) const
 Read a number from the bytecode, under the instruction pointer i.
 

Private Attributes

bytecode_t m_bytecode
 

Friends

class Ark::State
 

Detailed Description

This class is just a helper to.

  • check if a bytecode is valid
  • display it in a human-readable way by using the opcode names

Definition at line 85 of file BytecodeReader.hpp.

Constructor & Destructor Documentation

◆ BytecodeReader()

Ark::BytecodeReader::BytecodeReader ( )
default

Construct a new Bytecode Reader object.

Member Function Documentation

◆ checkMagic()

bool Ark::BytecodeReader::checkMagic ( ) const
nodiscard

Check for the presence of the magic header

Returns
true if the magic 'ark\0' was found

Definition at line 40 of file BytecodeReader.cpp.

References m_bytecode, and Ark::internal::bytecode::Magic.

Referenced by code(), display(), Ark::State::doFile(), Ark::State::feed(), filenames(), instLocations(), main(), sha256(), symbols(), timestamp(), values(), and version().

◆ code()

Code Ark::BytecodeReader::code ( const InstLocations & instLocations) const
nodiscard

◆ display()

void Ark::BytecodeReader::display ( BytecodeSegment segment = BytecodeSegment::All,
std::optional< uint16_t > sStart = std::nullopt,
std::optional< uint16_t > sEnd = std::nullopt,
std::optional< uint16_t > cPage = std::nullopt ) const

Display the bytecode opcode in a human friendly way.

Parameters
segmentselected bytecode segment that will be displayed
sStartstart of the segment slice to display (Ignored in code segment if no page is available)
sEndend of the segment slice to display (Ignored in code segment if no page is available)
cPageselected page of the code segment (Used only for the code segment)

< eg: Stack index, jump address, number

< Builtin, number

< Constant, number

< Symbol, number

< Symbol index, symbol

< Symbol index, constant

< Symbol index, symbol index

Definition at line 274 of file BytecodeReader.cpp.

References Ark::All, Ark::internal::APPEND, Ark::internal::APPEND_IN_PLACE, Ark::internal::APPEND_IN_PLACE_SYM, Ark::internal::APPEND_IN_PLACE_SYM_INDEX, Ark::internal::AT_SYM_INDEX_CONST, Ark::internal::AT_SYM_INDEX_SYM_INDEX, Ark::internal::AT_SYM_SYM, Ark::internal::BUILTIN, Ark::internal::Builtins::builtins, Ark::internal::CALL, Ark::internal::CALL_BUILTIN, Ark::internal::CALL_BUILTIN_WITHOUT_RETURN_ADDRESS, Ark::internal::CALL_CURRENT_PAGE, Ark::internal::CALL_SYMBOL, Ark::internal::CAPTURE, Ark::internal::CHECK_TYPE_OF, Ark::internal::CHECK_TYPE_OF_BY_INDEX, checkMagic(), Ark::Code, code(), Ark::internal::CONCAT, Ark::internal::CONCAT_IN_PLACE, Ark::internal::DECREMENT, Ark::internal::DECREMENT_BY_INDEX, Ark::internal::DECREMENT_STORE, Ark::internal::DEL, Ark::internal::EQ_CONST_JUMP_IF_TRUE, Ark::internal::EQ_SYM_INDEX_JUMP_IF_TRUE, filenames(), Ark::internal::GET_CURRENT_PAGE_ADDR, Ark::internal::GET_FIELD, Ark::internal::GET_FIELD_FROM_SYMBOL, Ark::internal::GET_FIELD_FROM_SYMBOL_INDEX, Ark::internal::GT_CONST_JUMP_IF_FALSE, Ark::internal::GT_CONST_JUMP_IF_TRUE, Ark::internal::GT_SYM_JUMP_IF_FALSE, Ark::HeadersOnly, Ark::internal::INCREMENT, Ark::internal::INCREMENT_BY_INDEX, Ark::internal::INCREMENT_STORE, instLocations(), Ark::InstructionLocation, Ark::internal::InstructionNames, Ark::internal::JUMP, Ark::internal::LIST, Ark::internal::LOAD_CONST, Ark::internal::LOAD_CONST_LOAD_CONST, Ark::internal::LOAD_CONST_SET_VAL, Ark::internal::LOAD_CONST_STORE, Ark::internal::LOAD_SYMBOL, Ark::internal::LOAD_SYMBOL_BY_INDEX, Ark::internal::LT_CONST_JUMP_IF_FALSE, Ark::internal::LT_CONST_JUMP_IF_TRUE, Ark::internal::LT_LEN_SYM_JUMP_IF_FALSE, Ark::internal::LT_SYM_JUMP_IF_FALSE, Ark::internal::MAKE_CLOSURE, Ark::internal::NEQ_CONST_JUMP_IF_TRUE, Ark::internal::NEQ_SYM_JUMP_IF_FALSE, Ark::Number, Ark::PageAddr, Ark::internal::PLUGIN, Ark::internal::POP_JUMP_IF_FALSE, Ark::internal::POP_JUMP_IF_TRUE, Ark::internal::Raw, Ark::internal::RENAME_NEXT_CAPTURE, Ark::internal::RESET_SCOPE_JUMP, Ark::internal::SET_VAL, Ark::internal::SET_VAL_FROM, Ark::internal::SET_VAL_FROM_INDEX, Ark::internal::SET_VAL_HEAD, Ark::internal::SET_VAL_HEAD_BY_INDEX, Ark::internal::SET_VAL_TAIL, Ark::internal::SET_VAL_TAIL_BY_INDEX, sha256(), Ark::internal::STORE, Ark::internal::STORE_FROM, Ark::internal::STORE_FROM_INDEX, Ark::internal::STORE_HEAD, Ark::internal::STORE_HEAD_BY_INDEX, Ark::internal::STORE_LEN, Ark::internal::STORE_LIST, Ark::internal::STORE_TAIL, Ark::internal::STORE_TAIL_BY_INDEX, Ark::String, Ark::internal::Symbol, Ark::Symbols, symbols(), timestamp(), std::to_string(), Ark::Values, values(), and version().

Referenced by main().

◆ feed() [1/2]

void Ark::BytecodeReader::feed ( const bytecode_t & bytecode)

Construct needed data before displaying information about a given bytecode.

Parameters
bytecode

Definition at line 17 of file BytecodeReader.cpp.

References m_bytecode.

◆ feed() [2/2]

void Ark::BytecodeReader::feed ( const std::string & file)

Construct needed data before displaying information about a given file.

Parameters
filefilename of the bytecode file

Definition at line 22 of file BytecodeReader.cpp.

References m_bytecode.

Referenced by Ark::State::doFile(), Ark::State::feed(), and main().

◆ filenames()

Filenames Ark::BytecodeReader::filenames ( const Values & values) const
nodiscard

◆ instLocations()

◆ readNumber()

uint16_t Ark::BytecodeReader::readNumber ( std::size_t & i) const
nodiscardprivate

Read a number from the bytecode, under the instruction pointer i.

Parameters
ithis parameter is being modified to point to the next value
Returns
uint16_t the number we read (big endian)

Definition at line 673 of file BytecodeReader.cpp.

References m_bytecode.

Referenced by code(), filenames(), instLocations(), symbols(), and values().

◆ sha256()

std::vector< unsigned char > Ark::BytecodeReader::sha256 ( ) const
nodiscard
Returns
std::vector<unsigned char> bytecode sha

Definition at line 79 of file BytecodeReader.cpp.

References checkMagic(), Ark::internal::bytecode::HeaderSize, and m_bytecode.

Referenced by Ark::State::configure(), and display().

◆ symbols()

◆ timestamp()

unsigned long long Ark::BytecodeReader::timestamp ( ) const
nodiscard

Return the read timestamp from the bytecode file.

Returns
unsigned long long

Definition at line 61 of file BytecodeReader.cpp.

References checkMagic(), Ark::internal::bytecode::HeaderSize, and m_bytecode.

Referenced by display().

◆ values()

◆ version()

Version Ark::BytecodeReader::version ( ) const
nodiscard
Returns
Version compiler version used to create the given bytecode file

Definition at line 49 of file BytecodeReader.cpp.

References checkMagic(), m_bytecode, Ark::internal::bytecode::Magic, and Ark::internal::bytecode::Version.

Referenced by Ark::State::configure(), and display().

Friends And Related Symbol Documentation

◆ Ark::State

friend class Ark::State
friend

Definition at line 176 of file BytecodeReader.hpp.

Member Data Documentation

◆ m_bytecode

bytecode_t Ark::BytecodeReader::m_bytecode
private

The documentation for this class was generated from the following files: