NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
types.h File Reference
#include <map>
#include <set>
#include <iosfwd>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <thread>
#include <future>
#include <vector>
#include <deque>
#include <iterator>
#include <iomanip>
#include <variant>
#include <algorithm>
#include <stdexcept>
#include <type_traits>
#include <string_view>
#include <cmath>
#include <random>
#include <typeindex>
#include <locale>
#include <codecvt>
#include <functional>
#include <regex>
#include <filesystem>
#include <utility>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <source_location>
#include <stacktrace>
#include <sstream>
#include <iostream>
#include <fstream>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/limits.h>
#include <wait.h>
#include <dlfcn.h>
#include <sys/param.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "logger.h"
#include "rational.h"
#include "build_options.data"
#include "variable.h"
Include dependency graph for types.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  newlang::VariablePair
 
class  newlang::GlobalObjects
 
class  newlang::InternalName
 

Namespaces

namespace  newlang
 
namespace  newlang::runtime
 

Macros

#define LOG_LEVEL_ERROR_MESSAGE   LOG_LEVEL_INFO
 
#define NL_PARSER(term, format, ...)
 
#define NL_MESSAGE(level, term, format, ...)
 
#define NL_CHECK(cond, format, ...)
 
#define NL_TYPECHECK(term, from, to)
 
#define NL_TYPES(_)
 
#define DEFINE_ENUM(name, value)   name = static_cast<uint8_t>(value),
 
#define MAKE_TYPE_NAME(type_name)   type_name
 
#define DEFINE_CASE(name, _)
 

Typedefs

typedef std::vector< std::string > newlang::StringArray
 
typedef std::shared_ptr< Modulenewlang::ModulePtr
 
typedef std::shared_ptr< runtime::Buildinnewlang::BuildinPtr
 
typedef std::vector< TermPtrnewlang::BlockType
 
typedef std::vector< ObjPtrnewlang::ArrayObjType
 
typedef std::shared_ptr< RunTimenewlang::RuntimePtr
 
typedef std::shared_ptr< Diagnewlang::DiagPtr
 
typedef std::shared_ptr< Macronewlang::MacroPtr
 
typedef std::shared_ptr< Parsernewlang::ParserPtr
 
typedef std::shared_ptr< Contextnewlang::RunnerPtr
 
typedef ObjPtr newlang::FunctionType(Context *ctx, Obj &in)
 
typedef ObjPtr(* newlang::EvalFunction) (Context *ctx, const TermPtr &term, Obj *args, bool eval_block)
 
typedef std::shared_ptr< std::string > newlang::SourceType
 
typedef std::vector< std::string > newlang::PostLexerType
 

Enumerations

enum class  newlang::ObjType : uint8_t {
  newlang::DEFINE_ENUM , newlang::None = static_cast<uint8_t>(0) , newlang::Bool = static_cast<uint8_t>(1) , newlang::Int8 = static_cast<uint8_t>(2) ,
  newlang::Char = static_cast<uint8_t>(3) , newlang::Byte = static_cast<uint8_t>(4) , newlang::Int16 = static_cast<uint8_t>(5) , newlang::Word = static_cast<uint8_t>(6) ,
  newlang::Int32 = static_cast<uint8_t>(7) , newlang::DWord = static_cast<uint8_t>(8) , newlang::Int64 = static_cast<uint8_t>(9) , newlang::DWord64 = static_cast<uint8_t>(10) ,
  newlang::Integer = static_cast<uint8_t>(15) , newlang::Float16 = static_cast<uint8_t>(16) , newlang::Float32 = static_cast<uint8_t>(17) , newlang::Single = static_cast<uint8_t>(18) ,
  newlang::Float64 = static_cast<uint8_t>(19) , newlang::Double = static_cast<uint8_t>(20) , newlang::Number = static_cast<uint8_t>(24) , newlang::Complex16 = static_cast<uint8_t>(25) ,
  newlang::Complex32 = static_cast<uint8_t>(26) , newlang::Complex64 = static_cast<uint8_t>(27) , newlang::Complex = static_cast<uint8_t>(31) , newlang::Tensor = static_cast<uint8_t>(32) ,
  newlang::Rational = static_cast<uint8_t>(33) , newlang::Arithmetic = static_cast<uint8_t>(47) , newlang::StrChar = static_cast<uint8_t>(48) , newlang::StrWide = static_cast<uint8_t>(49) ,
  newlang::FmtChar = static_cast<uint8_t>(50) , newlang::FmtWide = static_cast<uint8_t>(51) , newlang::ViewChar = static_cast<uint8_t>(52) , newlang::ViewWide = static_cast<uint8_t>(53) ,
  newlang::StdChar = static_cast<uint8_t>(54) , newlang::StdWide = static_cast<uint8_t>(55) , newlang::PtrChar = static_cast<uint8_t>(56) , newlang::PtrWide = static_cast<uint8_t>(57) ,
  newlang::String = static_cast<uint8_t>(59) , newlang::Iterator = static_cast<uint8_t>(62) , newlang::IteratorEnd = static_cast<uint8_t>(63) , newlang::Pointer = static_cast<uint8_t>(64) ,
  newlang::NativeFunc = static_cast<uint8_t>(65) , newlang::Function = static_cast<uint8_t>(70) , newlang::PureFunc = static_cast<uint8_t>(71) , newlang::Thread = static_cast<uint8_t>(80) ,
  newlang::Base = static_cast<uint8_t>(84) , newlang::Sys = static_cast<uint8_t>(85) , newlang::TorchTensor = static_cast<uint8_t>(86) , newlang::Range = static_cast<uint8_t>(104) ,
  newlang::Dictionary = static_cast<uint8_t>(105) , newlang::Interface = static_cast<uint8_t>(106) , newlang::Class = static_cast<uint8_t>(107) , newlang::Ellipsis = static_cast<uint8_t>(108) ,
  newlang::EVAL_FUNCTION = static_cast<uint8_t>(110) , newlang::BLOCK = static_cast<uint8_t>(111) , newlang::BLOCK_TRY = static_cast<uint8_t>(112) , newlang::BLOCK_PLUS = static_cast<uint8_t>(113) ,
  newlang::BLOCK_MINUS = static_cast<uint8_t>(114) , newlang::Macro = static_cast<uint8_t>(115) , newlang::Reference = static_cast<uint8_t>(117) , newlang::Virtual = static_cast<uint8_t>(118) ,
  newlang::Eval = static_cast<uint8_t>(119) , newlang::Other = static_cast<uint8_t>(120) , newlang::Plain = static_cast<uint8_t>(121) , newlang::Object = static_cast<uint8_t>(122) ,
  newlang::Any = static_cast<uint8_t>(123) , newlang::Type = static_cast<uint8_t>(200) , newlang::Struct = static_cast<uint8_t>(202) , newlang::Union = static_cast<uint8_t>(203) ,
  newlang::Enum = static_cast<uint8_t>(204) , newlang::RetPlus = static_cast<uint8_t>(210) , newlang::RetMinus = static_cast<uint8_t>(211) , newlang::RetRepeat = static_cast<uint8_t>(212) ,
  newlang::IntParser = static_cast<uint8_t>(213) , newlang::IntError = static_cast<uint8_t>(214) , newlang::Context = static_cast<uint8_t>(227) , newlang::Module = static_cast<uint8_t>(228) ,
  newlang::Undefined = static_cast<uint8_t>(229) , newlang::Error = static_cast<uint8_t>(230) , newlang::Break = static_cast<uint8_t>(231) , newlang::Continue = static_cast<uint8_t>(232) ,
  newlang::ErrorParser = static_cast<uint8_t>(241) , newlang::ErrorRunTime = static_cast<uint8_t>(242) , newlang::ErrorSignal = static_cast<uint8_t>(243)
}
 

Functions

std::string & newlang::rtrim (std::string &s, const char *t=ws)
 
std::string & newlang::ltrim (std::string &s, const char *t=ws)
 
std::string & newlang::trim (std::string &s, const char *t=ws)
 
template<typename T >
newlang::repeat (T str, const std::size_t n)
 
template<class T >
newlang::BaseFileName (T const &path, T const &delims="/\\")
 
template<class T >
newlang::RemoveFileExtension (T const &filename)
 
void newlang::NewLangSignalHandler (int signal)
 
void newlang::ParserException (const char *msg, std::string &buffer, int row, int col)
 
const char * newlang::toString (ObjType type)
 
const char * newlang::toCXXType (ObjType type, bool int_bool)
 
ObjType newlang::GetBaseTypeFromString (const std::string_view type_arg, bool *has_error=nullptr)
 
const char * newlang::toCXXRef (const std::string_view ref)
 
bool newlang::isGenericType (ObjType t)
 
bool newlang::isNativeType (ObjType t)
 
bool newlang::isObjectType (ObjType t)
 
bool newlang::isDefaultType (const TermPtr &term)
 
const TermPtr newlang::getDefaultType (const std::string_view text)
 
const TermPtr newlang::getDefaultType (ObjType type)
 
const TermPtr newlang::getNoneTerm ()
 
const TermPtr newlang::getEllipsysTerm ()
 
const TermPtr newlang::getRequiredTerm ()
 
const ObjPtr newlang::getNoneObj ()
 
const Variablenewlang::getNoneVar ()
 
const ObjPtr newlang::getEllipsysObj ()
 
const VariablePtr newlang::getEllipsysVar ()
 
const VariablePairnewlang::getNonePair ()
 
bool newlang::isBaseType (ObjType t)
 
bool newlang::isFunction (ObjType t)
 
bool newlang::isNative (ObjType t)
 
bool newlang::isEval (ObjType t)
 
bool newlang::isSimpleType (ObjType t)
 
bool newlang::isIntegralType (ObjType t, bool includeBool)
 
bool newlang::isFloatingType (ObjType t)
 
bool newlang::isComplexType (ObjType t)
 
bool newlang::isTensor (ObjType t)
 
bool newlang::isBooleanType (ObjType t)
 
bool newlang::isArithmeticType (ObjType t)
 
bool newlang::isStringChar (ObjType t)
 
bool newlang::isStringWide (ObjType t)
 
bool newlang::isString (ObjType t)
 
bool newlang::isInterrupt (ObjType t)
 
bool newlang::isPlainDataType (ObjType t)
 
bool newlang::isDictionary (ObjType t)
 
bool newlang::isClass (ObjType t)
 
bool newlang::isEllipsis (ObjType t)
 
bool newlang::isRange (ObjType t)
 
bool newlang::isTypeName (ObjType t)
 
bool newlang::isModule (ObjType t)
 
bool newlang::isIndexingType (ObjType curr, ObjType fix)
 
bool newlang::isLocalType (ObjType)
 
ObjType newlang::typeFromLimit (int64_t value, ObjType type_default=ObjType::Int64)
 
ObjType newlang::typeFromLimit (double value, ObjType type_default=ObjType::Float64)
 
ObjType newlang::typeFromString (TermPtr &term, RunTime *rt, bool *has_error)
 
bool newlang::canCastLimit (const ObjType from, const ObjType to)
 
bool newlang::canCast (const ObjType from, const ObjType to)
 
bool newlang::canCast (const std::string from, const std::string to)
 
bool newlang::canCast (const TermPtr &from, const ObjType to)
 
bool newlang::canCast (const TermPtr &from, const TermPtr &to)
 
int64_t newlang::parseInteger (const char *str)
 
double newlang::parseDouble (const char *str)
 
std::complex< double > newlang::parseComplex (const char *)
 
bool newlang::isReservedName (const std::string_view name)
 
bool newlang::isInternalName (const std::string_view name)
 
bool newlang::isMangledName (const std::string_view name)
 
bool newlang::isModuleName (const std::string_view name)
 
bool newlang::isStaticName (const std::string_view name)
 
bool newlang::isFieldName (const std::string_view name)
 
bool newlang::isTrivialName (const std::string_view name)
 
bool newlang::isLocalName (const std::string_view name)
 
bool newlang::isGlobalScope (const std::string_view name)
 
bool newlang::isModuleScope (const std::string_view name)
 
bool newlang::isTypeName (const std::string_view name)
 
bool newlang::isFullName (const std::string_view name)
 
bool newlang::isMacroName (const std::string_view name)
 
bool newlang::isNativeName (const std::string_view name)
 
bool newlang::isLocalAnyName (const std::string_view name)
 
bool newlang::isSystemName (const std::string_view name)
 
bool newlang::isPrivateName (const std::string_view name)
 
bool newlang::isHidenName (const std::string_view name)
 
bool newlang::isVariableName (const std::string_view name)
 
bool newlang::isConstName (const std::string_view name)
 
std::string newlang::NormalizeName (const std::string_view name)
 
std::string newlang::MakeName (std::string name)
 
std::string newlang::ExtractModuleName (const std::string_view name)
 
bool newlang::CheckCharModuleName (const std::string_view name)
 
std::string newlang::ExtractName (std::string name)
 
bool newlang::isContainsType (ObjType generic, ObjType type)
 

Variables

static constexpr const char * newlang::ws = " \t\n\r\f\v"
 

Macro Definition Documentation

◆ LOG_LEVEL_ERROR_MESSAGE

#define LOG_LEVEL_ERROR_MESSAGE   LOG_LEVEL_INFO

Definition at line 307 of file types.h.

◆ NL_PARSER

#define NL_PARSER ( term,
format,
... )
Value:
do { \
std::string empty; \
std::string message = \
newlang::ParserMessage(term->m_source ? *term->m_source : empty, term->m_line, term->m_col, format, ##__VA_ARGS__); \
LOG_THROW(ParserError, LOG_LEVEL_ERROR_MESSAGE, "", "%s", message.c_str()); \
} while (0)
#define LOG_LEVEL_ERROR_MESSAGE
Definition types.h:307

Definition at line 310 of file types.h.

Referenced by newlang::Diag::Apply(), newlang::AstAnalysis::CheckArgs_(), newlang::Macro::CheckMacro(), newlang::Parser::CheckModuleTerm(), newlang::RunTime::CreateNative(), newlang::Diag::Emit(), newlang::Context::EvalCreateAsEllipsis_(), newlang::Context::EvalCreateAsFilling_(), newlang::Context::EvalCreateAsValue_(), newlang::Context::EvalEval_(), newlang::Context::EvalInterrupt_(), newlang::Context::EvalIterator_(), newlang::Context::EvalLeftVars_(), newlang::Context::EvalOpBitwise_(), newlang::Context::EvalOpCompare_(), newlang::Context::EvalOpLogical_(), newlang::Macro::EvalOpMacros(), newlang::Context::EvalOpMath_(), newlang::Context::EvalTerm(), newlang::Macro::ExpandMacros(), newlang::Parser::ExpandPredefMacro(), newlang::Macro::ExtractArgs(), newlang::Context::GetFieldValue(), newlang::Context::GetIndexValue(), newlang::Parser::GetNextToken(), newlang::JIT::MakeFunctionPrototype(), newlang::Macro::MakeMacroId(), newlang::RunTime::OpLoadModule(), newlang::Parser::ParseTerm(), newlang::Diag::Pop(), newlang::Parser::PragmaEval(), newlang::Parser::PragmaStaticAssert(), newlang::ProcessMacro(), newlang::Term::SetArgs(), newlang::Context::SetFieldValue(), newlang::Context::SetIndexValue(), newlang::Term::SetType(), and newlang::Parser::SkipBrackets().

◆ NL_MESSAGE

◆ NL_CHECK

#define NL_CHECK ( cond,
format,
... )
Value:
do { \
if (!(cond)) { \
LOG_THROW(ParserError, LOG_LEVEL_ERROR_MESSAGE, "", format, ##__VA_ARGS__); \
} \
} while (0)

Definition at line 326 of file types.h.

Referenced by newlang::Context::CallNative_(), newlang::Obj::CloneDataTo(), newlang::Obj::ClonePropTo(), newlang::RunTime::CreateNative(), newlang::RunTime::CreateNative(), newlang::Obj::CreateValue(), and toSlice().

◆ NL_TYPECHECK

#define NL_TYPECHECK ( term,
from,
to )
Value:
do { \
if (!canCast(from, to)) { \
std::string message = "Incompatible data type '"; \
message += newlang::toString(from); \
message += "' and '"; \
message += newlang::toString(to); \
message += "' (" __FILE__ ":" TO_STR(__LINE__) ")"; \
LOG_THROW( \
ParserError, LOG_LEVEL_ERROR_MESSAGE, "", "%s", \
newlang::ParserMessage(*term->m_source, term->m_line, term->m_col, "%s", message.c_str()).c_str()); \
} \
} while (0)
#define TO_STR(ARG)
Definition logger.h:44
std::string ParserMessage(std::string &buffer, int row, int col, const char *format,...)
Definition parser.cpp:525
const char * toString(TermID type)
Definition term.h:126

Definition at line 333 of file types.h.

Referenced by newlang::Context::EvalTerm().

◆ NL_TYPES

#define NL_TYPES ( _)

Definition at line 359 of file types.h.

Referenced by newlang::GetBaseTypeFromString(), and newlang::toString().

◆ DEFINE_ENUM

#define DEFINE_ENUM ( name,
value )   name = static_cast<uint8_t>(value),

Definition at line 525 of file types.h.

◆ MAKE_TYPE_NAME

#define MAKE_TYPE_NAME ( type_name)    type_name

Definition at line 531 of file types.h.

◆ DEFINE_CASE

#define DEFINE_CASE ( name,
_ )
Value:
case ObjType::name: \
return MAKE_TYPE_NAME(":" #name);
#define MAKE_TYPE_NAME(type_name)
Definition types.h:531