mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
StackMachine.cpp File Reference
#include "backend/StackMachine.hpp"
#include "backend/Interpreter.hpp"
#include <ctime>
#include <functional>
#include <mutable/util/fn.hpp>
#include <regex>
#include "tables/Opcodes.tbl"
Include dependency graph for StackMachine.cpp:

Go to the source code of this file.

Data Structures

struct  m::StackMachineBuilder
 

Macros

#define M_OPCODE(CODE, ...)   { #CODE, StackMachine::Opcode:: CODE },
 
#define M_OPCODE(CODE, ...)   && CODE,
 
#define NEXT   goto *labels[std::size_t(*op_++)]
 
#define PUSH(VAL, NUL)
 
#define POP()   --top_
 
#define TOP_IS_NULL   (null_bits_[top_ - 1UL])
 
#define TOP   (values_[top_ - 1UL])
 
#define LOAD(TO_TYPE, FROM_TYPE)
 
#define STORE(TO_TYPE, FROM_TYPE)
 
#define UNARY(OP, TYPE)
 
#define BINARY(OP, TYPE)
 
#define CMP(TYPE)
 

Functions

const char * tystr (const PrimitiveType *ty)
 Return the type suffix for the given PrimitiveType ty.
 

Macro Definition Documentation

◆ BINARY

#define BINARY (   OP,
  TYPE 
)
Value:
{ \
M_insist(top_ >= 2); \
TYPE rhs = TOP.as<TYPE>(); \
bool is_rhs_null = TOP_IS_NULL; \
POP(); \
TYPE lhs = TOP.as<TYPE>(); \
TOP = OP(lhs, rhs); \
TOP_IS_NULL = TOP_IS_NULL or is_rhs_null; \
} \
#define NEXT
#define TOP_IS_NULL
#define TOP

◆ CMP

#define CMP (   TYPE)
Value:
{ \
M_insist(top_ >= 2); \
TYPE rhs = TOP.as<TYPE>(); \
bool is_rhs_null = TOP_IS_NULL; \
POP(); \
TYPE lhs = TOP.as<TYPE>(); \
bool is_lhs_null = TOP_IS_NULL; \
TOP = int64_t(lhs >= rhs) - int64_t(lhs <= rhs); \
TOP_IS_NULL = is_lhs_null or is_rhs_null; \
} \

◆ LOAD

#define LOAD (   TO_TYPE,
  FROM_TYPE 
)
Value:
{ \
M_insist(top_ >= 1); \
const void *ptr = TOP.as_p(); \
TOP = (TO_TYPE)(*reinterpret_cast<const FROM_TYPE*>(ptr)); \
} \

◆ M_OPCODE [1/2]

#define M_OPCODE (   CODE,
  ... 
)    { #CODE, StackMachine::Opcode:: CODE },

◆ M_OPCODE [2/2]

#define M_OPCODE (   CODE,
  ... 
)    && CODE,

◆ NEXT

#define NEXT   goto *labels[std::size_t(*op_++)]

◆ POP

#define POP ( )    --top_

◆ PUSH

#define PUSH (   VAL,
  NUL 
)
Value:
{ \
M_insist(top_ < required_stack_size(), "index out of bounds"); \
values_[top_] = (VAL); \
null_bits_[top_] = (NUL); \
++top_; \
}

◆ STORE

#define STORE (   TO_TYPE,
  FROM_TYPE 
)
Value:
{ \
M_insist(top_ >= 2); \
if (TOP_IS_NULL) { POP(); POP(); NEXT; } \
TO_TYPE val = TOP.as<FROM_TYPE>(); \
POP(); \
void *ptr = TOP.as_p(); \
*reinterpret_cast<TO_TYPE*>(ptr) = val; \
POP(); \
} \
#define POP()

◆ TOP

#define TOP   (values_[top_ - 1UL])

◆ TOP_IS_NULL

#define TOP_IS_NULL   (null_bits_[top_ - 1UL])

◆ UNARY

#define UNARY (   OP,
  TYPE 
)
Value:
{ \
M_insist(top_ >= 1); \
TYPE val = TOP.as<TYPE>(); \
TOP = OP(val); \
} \

Function Documentation

◆ tystr()

const char * tystr ( const PrimitiveType ty)