ArkScript
A small, fast, functional and scripting language for video games
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
 
const bytecode_tbytecode () noexcept
 Return the bytecode object constructed.
 
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
 
Code code (const Values &values) 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 70 of file BytecodeReader.hpp.

Constructor & Destructor Documentation

◆ BytecodeReader()

Ark::BytecodeReader::BytecodeReader ( )
default

Construct a new Bytecode Reader object.

Member Function Documentation

◆ bytecode()

const bytecode_t & Ark::BytecodeReader::bytecode ( )
nodiscardnoexcept

Return the bytecode object constructed.

Returns
const bytecode_t&

Definition at line 46 of file BytecodeReader.cpp.

References m_bytecode.

Referenced by feed().

◆ 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 39 of file BytecodeReader.cpp.

References m_bytecode, and Ark::internal::NOP.

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

◆ code()

Code Ark::BytecodeReader::code ( const Values & values) 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)

Definition at line 197 of file BytecodeReader.cpp.

References Ark::All, Ark::internal::APPEND, Ark::internal::APPEND_IN_PLACE, Ark::internal::BUILTIN, Ark::internal::Builtins::builtins, Ark::internal::CALL, Ark::internal::CALL_BUILTIN, Ark::internal::CAPTURE, checkMagic(), Ark::Code, code(), Ark::internal::CONCAT, Ark::internal::CONCAT_IN_PLACE, Ark::internal::DEL, Ark::internal::GET_FIELD, Ark::HeadersOnly, Ark::internal::InstructionNames, Ark::internal::JUMP, Ark::internal::LIST, Ark::internal::LOAD_CONST, Ark::internal::LOAD_SYMBOL, Ark::internal::MAKE_CLOSURE, Ark::Number, Ark::PageAddr, Ark::internal::PLUGIN, Ark::internal::POP_JUMP_IF_FALSE, Ark::internal::POP_JUMP_IF_TRUE, Ark::internal::SET_VAL, sha256(), Ark::internal::STORE, Ark::String, Ark::internal::Symbol, Ark::Symbols, symbols(), timestamp(), Ark::types_to_str, 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 16 of file BytecodeReader.cpp.

References bytecode(), and 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 21 of file BytecodeReader.cpp.

References m_bytecode.

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

◆ 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 449 of file BytecodeReader.cpp.

References m_bytecode.

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

◆ sha256()

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

Definition at line 81 of file BytecodeReader.cpp.

References checkMagic(), and m_bytecode.

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

◆ symbols()

Symbols Ark::BytecodeReader::symbols ( ) const
nodiscard

◆ timestamp()

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

Return the read timestamp from the bytecode file.

Returns
unsigned long long

Definition at line 63 of file BytecodeReader.cpp.

References checkMagic(), 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 51 of file BytecodeReader.cpp.

References checkMagic(), and m_bytecode.

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

Friends And Related Symbol Documentation

◆ Ark::State

friend class Ark::State
friend

Definition at line 156 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: