ArkScript
A small, fast, functional and scripting language for video games
Ark::internal Namespace Reference

Namespaces

namespace  Builtins
 

Classes

class  Closure
 Closure management. More...
 
class  ConditionalExecutor
 Handles Conditional macros. More...
 
struct  ExecutionContext
 
class  FunctionExecutor
 Handles function macros. More...
 
class  Future
 
class  Lexer
 The lexer, in charge of creating a list of tokens. More...
 
struct  LineColorContextCounts
 
class  MacroExecutor
 A class that applies macros in a Node. More...
 
class  MacroExecutorPipeline
 The class that initializes the MacroExecutors. More...
 
class  MacroProcessor
 The class handling the macros definitions and calls, given an AST. More...
 
class  MacroScope
 
class  Node
 A node of an Abstract Syntax Tree for ArkScript. More...
 
class  Optimizer
 The ArkScript AST optimizer. More...
 
class  Parser
 The parser is responsible of constructing the Abstract Syntax Tree from a token list. More...
 
class  Scope
 A class to handle the VM scope more efficiently. More...
 
class  SharedLibrary
 Handling a shared library as an ArkScript plugin. More...
 
class  SymbolExecutor
 Handles Symbol macros. More...
 
struct  Token
 
struct  type_uid
 
struct  type_uid_impl
 
struct  ValTableElem
 A Compiler Value class helper to handle multiple types. More...
 

Typedefs

using Scope_t = std::shared_ptr< Scope >
 Scope handling.
 
using PageAddr_t = uint16_t
 

Enumerations

enum class  TokenType {
  Grouping , String , Number , Operator ,
  Identifier , Capture , GetField , Keyword ,
  Skip , Comment , Shorthand , Spread ,
  Mismatch
}
 
enum class  NodeType {
  Symbol , Capture , GetField , Keyword ,
  String , Number , List , Closure ,
  Macro , Spread , Unused
}
 The different node types available. More...
 
enum class  Keyword {
  Fun , Let , Mut , Set ,
  If , While , Begin , Import ,
  Quote , Del
}
 The different keywords available. More...
 
enum  Instruction : uint8_t {
  NOP = 0x00 , SYM_TABLE_START = 0x01 , VAL_TABLE_START = 0x02 , NUMBER_TYPE = 0x01 ,
  STRING_TYPE = 0x02 , FUNC_TYPE = 0x03 , CODE_SEGMENT_START = 0x03 , FIRST_COMMAND = 0x01 ,
  LOAD_SYMBOL = 0x01 , LOAD_CONST = 0x02 , POP_JUMP_IF_TRUE = 0x03 , STORE = 0x04 ,
  LET = 0x05 , POP_JUMP_IF_FALSE = 0x06 , JUMP = 0x07 , RET = 0x08 ,
  HALT = 0x09 , CALL = 0x0a , CAPTURE = 0x0b , BUILTIN = 0x0c ,
  MUT = 0x0d , DEL = 0x0e , SAVE_ENV = 0x0f , GET_FIELD = 0x10 ,
  PLUGIN = 0x11 , LIST = 0x12 , APPEND = 0x13 , CONCAT = 0x14 ,
  APPEND_IN_PLACE = 0x15 , CONCAT_IN_PLACE = 0x16 , POP_LIST = 0x17 , POP_LIST_IN_PLACE = 0x18 ,
  POP = 0x19 , LAST_COMMAND = 0x19 , FIRST_OPERATOR = 0x20 , ADD = 0x20 ,
  SUB = 0x21 , MUL = 0x22 , DIV = 0x23 , GT = 0x24 ,
  LT = 0x25 , LE = 0x26 , GE = 0x27 , NEQ = 0x28 ,
  EQ = 0x29 , LEN = 0x2a , EMPTY = 0x2b , TAIL = 0x2c ,
  HEAD = 0x2d , ISNIL = 0x2e , ASSERT = 0x2f , TO_NUM = 0x30 ,
  TO_STR = 0x31 , AT = 0x32 , AND_ = 0x33 , OR_ = 0x34 ,
  MOD = 0x35 , TYPE = 0x36 , HASFIELD = 0x37 , NOT = 0x38 ,
  LAST_OPERATOR = 0x38 , LAST_INSTRUCTION = 0x38
}
 The different bytecodes are stored here. More...
 
enum class  ValTableElemType { Number , String , PageAddr }
 Enumeration to keep track of the type of a C(ompiler)Value. More...
 
enum class  ErrorKind {
  VM , Module , Mutability , Scope ,
  Type , Index , Arity
}
 

Functions

std::string makeNodeBasedErrorCtx (const std::string &message, const Node &node)
 Construct an error message based on a given node.
 
std::string makeTokenBasedErrorCtx (const std::string &match, std::size_t line, std::size_t col, const std::string &code)
 Construct an error message based on a given match in the code.
 
std::string colorizeLine (const std::string &line, LineColorContextCounts &line_color_context_counts)
 Add colors to highlight matching parentheses/curly braces/square braces on a line.
 
bool isPairableChar (const char c)
 Check if the character passed in can be paired (parentheses, curly braces, or square braces)
 
std::ostream & operator<< (std::ostream &os, const std::vector< Node > &N) noexcept
 
template<typename T >
Node make_node (T &&value, std::size_t line, std::size_t col, const std::string &file)
 
Node make_node_list (std::size_t line, std::size_t col, const std::string &file)
 
std::string typeToString (const Node &node) noexcept
 
NodeType similarNodetypeFromTokentype (TokenType tt)
 
bool operator== (const Closure &A, const Closure &B) noexcept
 
bool operator< (const Closure &A, const Closure &B) noexcept
 
void makeContext (std::ostream &os, const std::string &code, std::size_t line, std::size_t col_start, std::size_t sym_size)
 
void swap (Node &lhs, Node &rhs) noexcept
 
std::ostream & operator<< (std::ostream &os, const Node &N) noexcept
 
bool operator== (const Node &A, const Node &B)
 
bool operator< (const Node &A, const Node &B)
 
bool operator! (const Node &A)
 
std::ostream & operator<< (std::ostream &os, const Parser &P) noexcept
 

Variables

constexpr std::array< std::string_view, 13 > tokentype_string
 
constexpr std::array< std::string_view, 11 > nodeTypes
 
constexpr std::array< std::string_view, 10 > keywords
 List of available keywords in ArkScript.
 
constexpr std::array< std::string_view, 25 > operators
 
constexpr std::array< std::string_view, 7 > errorKinds
 
auto colors
 

Typedef Documentation

◆ PageAddr_t

using Ark::internal::PageAddr_t = typedef uint16_t

Definition at line 38 of file Closure.hpp.

◆ Scope_t

using Ark::internal::Scope_t = typedef std::shared_ptr<Scope>

Scope handling.

A scope is defined as a shared pointer to a list of local variables because a Closure could continue to leave when the local variables list has been closed by the virtual machine

Definition at line 37 of file Closure.hpp.

Enumeration Type Documentation

◆ ErrorKind

enum class Ark::internal::ErrorKind
strong
Enumerator
VM 
Module 
Mutability 
Scope 
Type 
Index 
Arity 

Definition at line 9 of file ErrorKind.hpp.

◆ Instruction

The different bytecodes are stored here.

Adding an operator
It must be referenced as well under include/Ark/Compiler/Common.hpp, in the operators table. The order of the operators below FIRST_OPERATOR must be the same as the one in the operators table from the aforementioned file.
Enumerator
NOP 
SYM_TABLE_START 
VAL_TABLE_START 
NUMBER_TYPE 
STRING_TYPE 
FUNC_TYPE 
CODE_SEGMENT_START 
FIRST_COMMAND 
LOAD_SYMBOL 
LOAD_CONST 
POP_JUMP_IF_TRUE 
STORE 
LET 
POP_JUMP_IF_FALSE 
JUMP 
RET 
HALT 
CALL 
CAPTURE 
BUILTIN 
MUT 
DEL 
SAVE_ENV 
GET_FIELD 
PLUGIN 
LIST 
APPEND 
CONCAT 
APPEND_IN_PLACE 
CONCAT_IN_PLACE 
POP_LIST 
POP_LIST_IN_PLACE 
POP 
LAST_COMMAND 
FIRST_OPERATOR 
ADD 
SUB 
MUL 
DIV 
GT 
LT 
LE 
GE 
NEQ 
EQ 
LEN 
EMPTY 
TAIL 
HEAD 
ISNIL 
ASSERT 
TO_NUM 
TO_STR 
AT 
AND_ 
OR_ 
MOD 
TYPE 
HASFIELD 
NOT 
LAST_OPERATOR 
LAST_INSTRUCTION 

Definition at line 27 of file Instructions.hpp.

◆ Keyword

enum class Ark::internal::Keyword
strong

The different keywords available.

Enumerator
Fun 
Let 
Mut 
Set 
If 
While 
Begin 
Import 
Quote 
Del 

Definition at line 58 of file Common.hpp.

◆ NodeType

enum class Ark::internal::NodeType
strong

The different node types available.

Enumerator
Symbol 
Capture 
GetField 
Keyword 
String 
Number 
List 
Closure 
Macro 
Spread 
Unused 

Definition at line 28 of file Common.hpp.

◆ TokenType

enum class Ark::internal::TokenType
strong
Enumerator
Grouping 
String 
Number 
Operator 
Identifier 
Capture 
GetField 
Keyword 
Skip 
Comment 
Shorthand 
Spread 
Mismatch 

Definition at line 21 of file Token.hpp.

◆ ValTableElemType

Enumeration to keep track of the type of a C(ompiler)Value.

Enumerator
Number 
String 
PageAddr 

Definition at line 26 of file ValTableElem.hpp.

Function Documentation

◆ colorizeLine()

std::string Ark::internal::colorizeLine ( const std::string &  line,
LineColorContextCounts line_color_context_counts 
)

Add colors to highlight matching parentheses/curly braces/square braces on a line.

Parameters
linethe line of code to colorize
line_color_context_countsa LineColorContextCounts to manipulate the running counts of open pairings
Returns
std::string a colorized line of code

Definition at line 46 of file makeErrorCtx.cpp.

References isPairableChar(), Ark::internal::LineColorContextCounts::open_curly_braces, Ark::internal::LineColorContextCounts::open_parentheses, and Ark::internal::LineColorContextCounts::open_square_braces.

Referenced by makeContext().

◆ isPairableChar()

bool Ark::internal::isPairableChar ( const char  c)
inline

Check if the character passed in can be paired (parentheses, curly braces, or square braces)

Parameters
c
Returns
bool

Definition at line 67 of file makeErrorCtx.hpp.

Referenced by colorizeLine().

◆ make_node()

template<typename T >
Node Ark::internal::make_node ( T &&  value,
std::size_t  line,
std::size_t  col,
const std::string &  file 
)

◆ make_node_list()

Node Ark::internal::make_node_list ( std::size_t  line,
std::size_t  col,
const std::string &  file 
)
inline

◆ makeContext()

void Ark::internal::makeContext ( std::ostream &  os,
const std::string &  code,
std::size_t  line,
std::size_t  col_start,
std::size_t  sym_size 
)

Definition at line 13 of file makeErrorCtx.cpp.

References colorizeLine(), and Ark::Utils::splitString().

Referenced by makeNodeBasedErrorCtx(), and makeTokenBasedErrorCtx().

◆ makeNodeBasedErrorCtx()

std::string Ark::internal::makeNodeBasedErrorCtx ( const std::string &  message,
const Node node 
)

Construct an error message based on a given node.

It opens the related file at the line and column of the node, and display context, plus underline the problem with a serie of ^.

Parameters
message
node
Returns
std::string the complete generated error message

Definition at line 101 of file makeErrorCtx.cpp.

References ARK_NO_NAME_FILE, Ark::internal::Node::col(), Ark::internal::Node::filename(), Ark::internal::Node::line(), makeContext(), Ark::internal::Node::nodeType(), Ark::Utils::readFile(), Spread, Ark::internal::Node::string(), String, and Symbol.

Referenced by Ark::Compiler::compilerWarning(), Ark::Compiler::throwCompilerError(), Ark::internal::MacroProcessor::throwMacroProcessingError(), and Ark::internal::Optimizer::throwOptimizerError().

◆ makeTokenBasedErrorCtx()

std::string Ark::internal::makeTokenBasedErrorCtx ( const std::string &  match,
std::size_t  line,
std::size_t  col,
const std::string &  code 
)

Construct an error message based on a given match in the code.

Mostly used by the Lexer and Parser since they don't have Nodes to work on

Parameters
matchthe identified token, causing a problem
lineline of the token
colstarting column of the token
codethe whole code of the file
Returns
std::string the complete generated error message

Definition at line 119 of file makeErrorCtx.cpp.

References makeContext().

Referenced by Ark::internal::Parser::throwParseError(), and Ark::internal::Lexer::throwTokenizingError().

◆ operator!()

bool Ark::internal::operator! ( const Node A)

Definition at line 321 of file Node.cpp.

◆ operator<() [1/2]

bool Ark::internal::operator< ( const Closure A,
const Closure B 
)
inlinenoexcept

Definition at line 112 of file Closure.hpp.

◆ operator<() [2/2]

bool Ark::internal::operator< ( const Node A,
const Node B 
)

Definition at line 301 of file Node.cpp.

◆ operator<<() [1/3]

std::ostream & Ark::internal::operator<< ( std::ostream &  os,
const Node N 
)
noexcept

Definition at line 192 of file Node.cpp.

◆ operator<<() [2/3]

std::ostream & Ark::internal::operator<< ( std::ostream &  os,
const Parser P 
)
noexcept

Definition at line 597 of file Parser.cpp.

◆ operator<<() [3/3]

std::ostream & Ark::internal::operator<< ( std::ostream &  os,
const std::vector< Node > &  N 
)
noexcept

Definition at line 275 of file Node.cpp.

◆ operator==() [1/2]

bool Ark::internal::operator== ( const Closure A,
const Closure B 
)
inlinenoexcept

Definition at line 107 of file Closure.hpp.

◆ operator==() [2/2]

bool Ark::internal::operator== ( const Node A,
const Node B 
)

Definition at line 285 of file Node.cpp.

◆ similarNodetypeFromTokentype()

NodeType Ark::internal::similarNodetypeFromTokentype ( TokenType  tt)
inline

Definition at line 27 of file Parser.hpp.

References Capture, GetField, Spread, and Symbol.

Referenced by Ark::internal::Parser::atom().

◆ swap()

void Ark::internal::swap ( Node lhs,
Node rhs 
)
noexcept

Definition at line 188 of file Node.cpp.

Referenced by Ark::internal::Node::operator=(), and Ark::internal::Node::swap().

◆ typeToString()

std::string Ark::internal::typeToString ( const Node node)
inlinenoexcept

Definition at line 267 of file Node.hpp.

References nodeTypes, and Symbol.

Referenced by Ark::internal::MacroProcessor::evaluate().

Variable Documentation

◆ colors

auto Ark::internal::colors
Initial value:
= std::vector(
{ termcolor::blue,
termcolor::red,
termcolor::green,
termcolor::cyan,
termcolor::magenta })

Definition at line 181 of file Node.cpp.

◆ errorKinds

constexpr std::array<std::string_view, 7> Ark::internal::errorKinds
constexpr
Initial value:
= {
"VMError",
"ModuleError",
"MutabilityError",
"ScopeError",
"TypeError",
"IndexError",
"ArityError"
}

Definition at line 20 of file ErrorKind.hpp.

Referenced by Ark::VM::throwVMError().

◆ keywords

constexpr std::array<std::string_view, 10> Ark::internal::keywords
constexpr
Initial value:
= {
"fun",
"let",
"mut",
"set",
"if",
"while",
"begin",
"import",
"quote",
"del"
}

List of available keywords in ArkScript.

Definition at line 73 of file Common.hpp.

Referenced by Ark::internal::Lexer::isKeyword().

◆ nodeTypes

constexpr std::array<std::string_view, 11> Ark::internal::nodeTypes
constexpr
Initial value:
= {
"Symbol",
"Capture",
"GetField",
"Keyword",
"String",
"Number",
"List",
"Closure",
"Macro",
"Spread",
"Unused"
}

Definition at line 43 of file Common.hpp.

Referenced by Ark::JsonCompiler::_compile(), Ark::internal::MacroProcessor::evaluate(), and typeToString().

◆ operators

constexpr std::array<std::string_view, 25> Ark::internal::operators
constexpr
Initial value:
= {
"+", "-", "*", "/",
">", "<", "<=", ">=", "!=", "=",
"len", "empty?", "tail", "head",
"nil?", "assert",
"toNumber", "toString",
"@", "and", "or", "mod",
"type", "hasField",
"not"
}

Definition at line 89 of file Common.hpp.

Referenced by Ark::Compiler::handleCalls(), Ark::internal::MacroProcessor::isConstEval(), Ark::Compiler::isOperator(), Ark::internal::Lexer::isOperator(), and Ark::internal::Parser::parse().

◆ tokentype_string

constexpr std::array<std::string_view, 13> Ark::internal::tokentype_string
constexpr
Initial value:
= {
"Grouping",
"String",
"Number",
"Operator",
"Identifier",
"Capture",
"GetField",
"Keyword",
"Skip",
"Comment",
"Shorthand",
"Spread",
"Mistmatch"
}

Definition at line 39 of file Token.hpp.

Referenced by Ark::internal::Lexer::feed(), and Ark::internal::Parser::throwParseError().