[
  {
    "path": ".cirrus.yml",
    "content": "# LTO is disabled on ubuntu 14.04 and freebsd 10.4\n# because clang 3.4 does work correctly with it\ntask:\n  name: Ubuntu 14.04 gcc 4.8.4\n  container:\n    image: ubuntu:14.04\n  install_script: apt-get update && apt-get install -y libgmp-dev libmpfr-dev libmpc-dev g++ cmake make\n  compile_script: mkdir build && cd build && cmake .. && make -j$(nproc)\n  tests_script: build/bin/et ./perform_tests.et\n\ntask:\n  name: Ubuntu 14.04 clang 3.4.0\n  container:\n    image: teeks99/clang-ubuntu:3.4\n  env:\n    CXX: clang++-3.4\n    SKIP_LTO: true\n  install_script: apt update && apt install -y libgmp-dev libmpfr-dev libmpc-dev cmake make\n  compile_script: mkdir build && cd build && cmake .. && make -j$(nproc)\n  tests_script: build/bin/et ./perform_tests.et\n\ntask:\n  name: Debian 8 gcc 6.5.0\n  container:\n    image: gcc:6\n  env:\n    CXX: g++\n  install_script: apt update && apt install -y libgmp-dev libmpfr-dev libmpc-dev cmake make\n  compile_script: mkdir build && cd build && cmake .. && make -j$(nproc)\n  tests_script: build/bin/et ./perform_tests.et\n\ntask:\n  name: FreeBSD 10.4 clang 3.4.1\n  freebsd_instance:\n    image: freebsd-10-4-release-amd64\n  env:\n    SKIP_LTO: true\n  install_script: pkg install -y gmp mpfr mpc cmake\n  compile_script: mkdir build && cd build && cmake .. && make -j$(sysctl -n hw.ncpu)\n  tests_script: build/bin/et ./perform_tests.et\n\ntask:\n  name: macOS Mojave apple llvm 10.0.1\n  osx_instance:\n    image: mojave-base\n  install_script: brew install gmp mpfr libmpc cmake make\n  compile_script: mkdir build && cd build && cmake .. && make -j$(sysctl -n hw.ncpu)\n  tests_script: build/bin/et ./perform_tests.et\n"
  },
  {
    "path": ".gitignore",
    "content": "# Editor files #\n################\n.vscode/\n*.swp\n\n# TeX intermediate files #\n##########################\n*.out\n*.aux\n\n# Build files #\n###############\ntestbin/\nbin/\nlib/\nbuild/\ndockerbuild/\nbuildfiles/\nCMakeFiles/\ndoxygen/\nflag_cache\nbook/book/\nsrc/Config.hpp\n\n# Extra data #\n#######################\ntmp*\n*.json\ntests/*.json\n\n# Build file on BSD #\n#####################\n*.core\n\n# Compiled source #\n###################\n*.com\n*.class\n*.dll\n*.exe\n*.o\n*.so\n*.out\n\n# Packages #\n############\n# it's better to unpack these files and commit the raw source\n# git has its own built in compression methods\n*.7z\n*.dmg\n*.gz\n*.iso\n*.jar\n*.rar\n*.tar\n*.zip\n\n# Logs and databases #\n######################\n*.log\n*.sql\n*.sqlite\n*.swp\n\n# OS generated files #\n######################\n.DS_Store\n.DS_Store?\n._*\n.Spotlight-V100\n.Trashes\nehthumbs.db\nThumbs.db\n"
  },
  {
    "path": "CMakeLists.txt",
    "content": "cmake_minimum_required(VERSION 2.8)\n\nproject(Ethereal C CXX)\n\nset(CMAKE_CXX_STANDARD 11)\nif(CMAKE_VERSION VERSION_LESS \"3.1\")\n\tadd_compile_options(-std=c++11)\nendif()\n\n# add cmake_modules path\nlist(APPEND CMAKE_MODULE_PATH \"${PROJECT_SOURCE_DIR}/third_party/cmake_modules\")\n\nset(ETHEREAL_VERSION_MAJOR 0)\nset(ETHEREAL_VERSION_MINOR 1)\nset(ETHEREAL_VERSION_PATCH 2)\nexecute_process(COMMAND date \"+%a %b %d, %Y at %H:%M:%S\" OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)\n\nset(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)\nset(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)\nset(CMAKE_MACOSX_RPATH TRUE)\n\ninclude(CheckCXXCompilerFlag)\n\nfind_library(gmp REQUIRED)\nfind_library(gmpxx REQUIRED)\nfind_package(MPFR REQUIRED)\nif(NOT MPFR_FOUND)\n\terror(\"MPFR library is required but missing\")\nendif()\nfind_package(MPC REQUIRED)\nif(NOT MPC_FOUND)\n\terror(\"MPC library is required but missing\")\nendif()\nset(CMAKE_THREAD_PREFER_PTHREAD TRUE)\nset(THREADS_PREFER_PTHREAD_FLAG ON)\nfind_package(Threads REQUIRED)\nif(CMAKE_USE_PTHREADS_INIT)\n\tmessage(\"-- Using thread flags: -pthread\")\n\tset(CMAKE_CXX_FLAGS  \"${CMAKE_CXX_FLAGS} -pthread\")\n\tset(CMAKE_EXE_LINKER_FLAGS  \"${CMAKE_EXE_LINKER_FLAGS} -pthread\")\nelse()\n\tmessage(\"-- Using thread flags: ${CMAKE_THREAD_LIBS_INIT}\")\n\tset(CMAKE_CXX_FLAGS  \"${CMAKE_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}\")\n\tset(CMAKE_EXE_LINKER_FLAGS  \"${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}\")\nendif()\n\n# For libGMP on macOS and BSD\nif(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES \".*BSD.*\")\n\tinclude_directories(/usr/local/include)\n\tlink_directories(/usr/local/lib)\nendif()\n\nif(WIN32)\n\terror(\"Project not supported on Windows yet\")\nendif()\n\nfind_program(CCACHE_PROGRAM ccache)\nif(CCACHE_PROGRAM)\n    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE \"${CCACHE_PROGRAM}\")\nendif()\n\nif(${CMAKE_SYSTEM_NAME} MATCHES \".*BSD.*\")\n\tadd_definitions(-D_WITH_GETLINE)\nendif()\n\nif(DEFINED ENV{DEBUG})\n\tadd_definitions(-DDEBUG_MODE)\n\tmessage(\"-- Running in debug mode\")\nelse()\n\tif(NOT DEFINED ENV{SKIP_LTO})\n\t\tset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -flto\")\n\tendif()\n\tset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -O2\")\nendif()\n\ncheck_cxx_compiler_flag(-march=native COMPILER_SUPPORTS_MARCH_NATIVE)\nif(COMPILER_SUPPORTS_MARCH_NATIVE)\n\tset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -march=native\")\nendif()\n\nif(DEFINED ENV{PREFIX_DIR} AND NOT \"$ENV{PREFIX_DIR}\" STREQUAL \"\")\n\tset(CMAKE_INSTALL_PREFIX \"$ENV{PREFIX_DIR}\")\nelse()\n\tset(CMAKE_INSTALL_PREFIX \"${CMAKE_BINARY_DIR}\")\nendif()\nadd_definitions(-DBUILD_PREFIX_DIR=${CMAKE_INSTALL_PREFIX})\nset(CMAKE_INSTALL_RPATH \"${CMAKE_INSTALL_PREFIX}/lib/ethereal\")\nmessage(\"-- Using PREFIX = ${CMAKE_INSTALL_PREFIX}\")\n\n# Finally! The sources!!!!!\n\n# Set Config.hpp.in template\nconfigure_file(\"${PROJECT_SOURCE_DIR}/src/Config.hpp.in\" \"${PROJECT_SOURCE_DIR}/src/Config.hpp\" @ONLY)\n\n# Includes\nfile(COPY \"${CMAKE_SOURCE_DIR}/include\" DESTINATION \"${CMAKE_INSTALL_PREFIX}/\")\n\n# Ethereal Core\nfile(GLOB_RECURSE INCS RELATIVE \"${PROJECT_SOURCE_DIR}\" \"include/*.hpp\")\nfile(GLOB_RECURSE SRCS RELATIVE \"${PROJECT_SOURCE_DIR}\" \"src/*.cpp\")\nlist(REMOVE_ITEM SRCS \"src/FE/Main.cpp\" \"src/VM/Main.cpp\")\n\nadd_library(et-lib SHARED ${SRCS} ${INCS})\ntarget_link_libraries(et-lib ${CMAKE_DL_LIBS})\ntarget_link_libraries(et-lib mpfr gmp gmpxx)\nset_target_properties(et-lib\n    PROPERTIES\n    OUTPUT_NAME et\n    LIBRARY_OUTPUT_DIRECTORY \"${CMAKE_BINARY_DIR}/lib/ethereal\"\n    INSTALL_RPATH_USE_LINK_PATH TRUE\n)\ninstall(TARGETS et-lib\n\tLIBRARY\n\t  DESTINATION lib/ethereal\n\t  COMPONENT Libraries\n\tPUBLIC_HEADER\n\t  DESTINATION include/ethereal\n)\n\nadd_executable(et-bin \"${PROJECT_SOURCE_DIR}/src/FE/Main.cpp\")\ntarget_link_libraries(et-bin et-lib)\nset_target_properties(et-bin\n\tPROPERTIES\n\tOUTPUT_NAME et\n\tRUNTIME_OUTPUT_DIRECTORY \"${CMAKE_BINARY_DIR}/bin\"\n\tINSTALL_RPATH_USE_LINK_PATH TRUE\n)\ninstall(TARGETS et-bin\n\tRUNTIME\n\t  DESTINATION bin\n\t  COMPONENT Binaries\n)\n\n# Libraries\nfile(GLOB_RECURSE mods RELATIVE \"${PROJECT_SOURCE_DIR}\" \"modules/*.cpp\")\nforeach(m ${mods})\n\tget_filename_component(mod ${m} NAME_WE)\n\tget_filename_component(moddir ${m} DIRECTORY)\n\tstring(SUBSTRING ${moddir} 8 -1 moddir)\n\tadd_library(${mod} SHARED \"${m}\")\n\ttarget_link_libraries(${mod} mpc et-lib)\n\tif(${mod} STREQUAL \"complex\")\n\t\ttarget_link_libraries(${mod} mpc et-lib)\n\tendif()\n\tset_target_properties(${mod}\n\t    PROPERTIES\n\t    LIBRARY_OUTPUT_DIRECTORY \"${CMAKE_BINARY_DIR}/lib/ethereal/${moddir}\"\n\t    INSTALL_RPATH_USE_LINK_PATH TRUE\n\t)\n\tinstall(TARGETS ${mod}\n\t\tLIBRARY\n\t\t  DESTINATION lib/ethereal/${moddir}\n\t\t  COMPONENT Libraries\n\t)\nendforeach()\n\n# Playground\nset(BINARY_LOC \"${CMAKE_INSTALL_PREFIX}/bin/et\")\nconfigure_file(\"${PROJECT_SOURCE_DIR}/playground.et\" \"${CMAKE_BINARY_DIR}/artifacts/et-repl\" @ONLY)\ninstall(PROGRAMS \"${CMAKE_BINARY_DIR}/artifacts/et-repl\" DESTINATION \"${CMAKE_INSTALL_PREFIX}/bin/\")\n\n# EPM\nconfigure_file(\"${PROJECT_SOURCE_DIR}/tools/epm/epm.et\" \"${CMAKE_BINARY_DIR}/artifacts/epm\" @ONLY)\ninstall(PROGRAMS \"${CMAKE_BINARY_DIR}/artifacts/epm\" DESTINATION \"${CMAKE_INSTALL_PREFIX}/bin/\")\ninstall(DIRECTORY \"${CMAKE_SOURCE_DIR}/tools/epm/epm/\" DESTINATION \"${CMAKE_INSTALL_PREFIX}/include/ethereal/epm\")\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Introduction\n\nFirst things first, I would like to thank you for considering to contribute to this project.\nIt is thanks to people like you that this project lives on and continues to improve.\n\nThis document defines some guidelines for contributing to the project.\nThese guidelines help you ease out in the process of contributing to this project,\nand helps the existing contributors and maintainers to quickly start working with you!\n\nTherefore, to contribute to this project, please follow the following guidelines.\n\n# Code Formatting\n\n## C++\nThe C++ codebase follows the **[Linux Kernel's](https://www.kernel.org/doc/html/v4.10/process/coding-style.html)** code style with some minor changes:\n1. Having a conditional/loop statement with single line block does not require surrounding it with braces and must be on the same line as the conditional/loop statement itself - **as long as neither of those are too long** (about 120 characters).\n2. All the subscripts/indices, arguments for functions, and conditions for conditionals/loops must have spaces between the parentheses/brackets/braces and the arguments.\nFor example,\n```cpp\nint func( int a, int b )\n{\n\n}\n\nfunc( a, b );\n\nif( a == b ) {}\n\nwhile( a ) {}\n\np[ q ];\n{ a, b };\n```\n3. Classes have similar pattern as functions, and the access modifier keywords are indented at the level of the `class` keyword inside which they reside.\nFor example,\n```cpp\nclass A\n{\n\tint a;\npublic:\n\tint get_a() const;\n}\n```\n4. Same applies for switch cases and goto labels - the cases and labels are at the indentation level of the switch statement and parent block of the goto label respectively. For example,\n```cpp\nint func()\n{\n\tgoto label;\nlabel:\n\tsome_code();\n}\n\nswitch( x ) {\ncase 'a':\n\tfunc_a();\ncase 'b':\n\tfunc_b();\n}\n```\n\n## Ethereal\nEthereal's code style is same as **[Linux Kernel's](https://www.kernel.org/doc/html/v4.10/process/coding-style.html)** and this project's C++ style,\nwith the following changes.\n1. All opening braces are on the same line as the entity for which they are used, ie., opening braces are never on new lines - unlike the C++ code.\nFor example,\n```go\nfunc( a ) {\n\tprintln( x );\n}\n```\n2. All the Ethereal test scripts (in `tests/` directory) have a shebang at the top with the following contents.\n```bash\n#!/usr/bin/env et\n```\n\n# Issues\n\n## Creation\nAs of right now, a particular standard format has not been devised for issues, however, please be as thorough as possible in describing an issue -\npossibly with examples, links, images, or anything relevant. That would help a lot in resolving the problem as soon as possible.\n\n## Solving\nBefore working on any issues, please post a reply on the issue stating that you are working on it (and possibly assign yourself to it).\nThis will save everyone time by saving them from working on something that is already undertaken by someone else.\n\nDo not start working on any issue that someone is already working on. If the issue seems old and inactive,\nyou can comment on the issue stating your interest in it. In such case, you will most likely be allowed to takeover that issue -\nassuming there are no special circumstances."
  },
  {
    "path": "Design/parser_keywords.gv",
    "content": "# notes\n# 1. STR = any const string\n# 2. a BLOCK can contain only EXPR, struct, conditionals, loops, import, ldmod\n# 3. maybe import identifier can be used as a variable too\n\ndigraph ParserKeywords {\n\tsize = \"10,10\";\n\tbegin;\n\n\t# Keywords\n\tbegin -> { enum, import, struct, fn, mfn, if, for, ldmod };\n\n\t# enum\n\tENUMNAME [ label = \"IDEN\" ];\n\tENUMLBRACE [ label = \"{\" ];\n\tENUMRBRACE [ label = \"}\" ];\n\tENUMKEY [ label = \"IDEN\" ];\n\tENUMSEPAR [ label = \",\" ];\n\tenum -> ENUMNAME -> ENUMLBRACE -> ENUMKEY -> { ENUMRBRACE, ENUMSEPAR };\n\tENUMSEPAR -> ENUMKEY;\n\tENUMRBRACE -> end;\n\n\n\t# import\n\tIMPORTNAME [ label = \"IDEN/STR\" ];\n\tIMPORTASNAME [ label = \"IDEN\" ];\n\timport -> IMPORTNAME -> { as, end };\n\tas -> IMPORTASNAME -> end;\n\n\t# struct\n\tSTRUCTNAME [ label = \"IDEN\" ];\n\tSTRUCTATTR [ label = \"IDEN\" ];\n\tSTRUCTLBRACE [ label = \"{\" ];\n\tSTRUCTRBRACE [ label = \"}\" ];\n\tSTRUCTSEMICOL [ label = \";\" ];\n\tstruct -> STRUCTNAME -> STRUCTLBRACE -> STRUCTATTR -> \"=\"\n\t       -> EXPR -> STRUCTSEMICOL -> { STRUCTATTR, STRUCTRBRACE };\n\tSTRUCTRBRACE -> end;\n\n\t# fn\n\tFNNAME [ label = \"IDEN\" ];\n\tFNARG [ label = \"EXPR (no pop stack)\" ];\n\tFNLPAREN [ label = \"(\" ];\n\tFNARGCOMMA [ label = \",\" ];\n\tFNRPAREN [ label = \")\" ];\n\tFNLBRACE [ label = \"{\" ];\n\tFNRBRACE [ label = \"}\" ];\n\tFNBLOCK [ label = \"BLOCK\" ];\n\tfn -> FNNAME -> FNLPAREN -> { FNRPAREN, FNARG };\n\tFNARG -> { FNARGCOMMA, FNRPAREN };\n\tFNARGCOMMA -> FNARG;\n\tFNRPAREN -> FNLBRACE -> FNBLOCK -> FNRBRACE -> end;\n\n\t# mfn\n\tMEMBEROF [ label = \"IDEN/STR\" ];\n\tMFNLANGLEBRACK [ label = \"<\" ];\n\tMFNRANGLEBRACK [ label = \">\" ];\n\tmfn -> MFNLANGLEBRACK -> MEMBEROF -> MFNRANGLEBRACK -> FNNAME;\n\n\t# if\n\tIFCOND [ label = \"EXPR\" ];\n\tIFLBRACE [ label = \"{\" ];\n\tIFBLOCK [ label = \"BLOCK\" ];\n\tIFRBRACE [ label = \"}\" ];\n\tELSELBRACE [ label = \"{\" ];\n\tELSEBLOCK [ label = \"BLOCK\" ];\n\tELSERBRACE [ label = \"}\" ];\n\tif -> IFCOND -> IFLBRACE -> IFBLOCK -> IFRBRACE -> { elif, else, end };\n\telif -> IFCOND;\n\telse -> ELSELBRACE -> ELSEBLOCK -> ELSERBRACE -> end;\n\n\t# for\n\tFORINIT [ label = \"INIT EXPR\" ];\n\tFORINITSEMICOL [ label = \";\" ];\n\tFORCOND [ label = \"COND EXPR\" ];\n\tFORCONDSEMICOL [ label = \";\" ];\n\tFORITER [ label = \"ITER EXPR\" ];\n\tFORLBRACE [ label = \"{\" ];\n\tFORBLOCK [ label = \"BLOCK\" ];\n\tFORRBRACE [ label = \"}\" ];\n\tfor -> FORINIT -> FORINITSEMICOL -> FORCOND -> FORCONDSEMICOL -> FORITER -> FORLBRACE;\n\tfor -> FORINITSEMICOL; FORINITSEMICOL -> FORCONDSEMICOL; FORCONDSEMICOL -> FORLBRACE;\n\tFORLBRACE -> FORBLOCK -> FORRBRACE -> end;\n\n\t# ldmod\n\tldmod -> IMPORTNAME;\n\n\t# at the end\n\tbegin -> EXPR -> end;\n\tend;\n}"
  },
  {
    "path": "Dockerfile",
    "content": "FROM archlinux/base:latest\n\nRUN pacman -Sy base-devel vim valgrind git bc ccache cmake gmp --needed --noconfirm\nWORKDIR /et\nRUN echo 'export PREFIX_DIR=\"/usr\"' >> ~/.bashrc\nRUN echo 'alias bs=\"rm -rf dockerbuild && mkdir -p dockerbuild && cd dockerbuild && cmake .. && make -j$(nproc) && make install && cd ..\"' >> ~/.bashrc\n"
  },
  {
    "path": "Doxyfile",
    "content": "# Doxyfile 1.8.16\n\n# This file describes the settings to be used by the documentation system\n# doxygen (www.doxygen.org) for a project.\n#\n# All text after a double hash (##) is considered a comment and is placed in\n# front of the TAG it is preceding.\n#\n# All text after a single hash (#) is considered a comment and will be ignored.\n# The format is:\n# TAG = value [value, ...]\n# For lists, items can also be appended using:\n# TAG += value [value, ...]\n# Values that contain spaces should be placed between quotes (\\\" \\\").\n\n#---------------------------------------------------------------------------\n# Project related configuration options\n#---------------------------------------------------------------------------\n\n# This tag specifies the encoding used for all characters in the configuration\n# file that follow. The default is UTF-8 which is also the encoding used for all\n# text before the first occurrence of this tag. Doxygen uses libiconv (or the\n# iconv built into libc) for the transcoding. See\n# https://www.gnu.org/software/libiconv/ for the list of possible encodings.\n# The default value is: UTF-8.\n\nDOXYFILE_ENCODING      = UTF-8\n\n# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by\n# double-quotes, unless you are using Doxywizard) that should identify the\n# project for which the documentation is generated. This name is used in the\n# title of most generated pages and in a few other places.\n# The default value is: My Project.\n\nPROJECT_NAME           = \"Ethereal\"\n\n# The PROJECT_NUMBER tag can be used to enter a project or revision number. This\n# could be handy for archiving the generated documentation or if some version\n# control system is used.\n\nPROJECT_NUMBER         = 0.0.3\n\n# Using the PROJECT_BRIEF tag one can provide an optional one line description\n# for a project that appears at the top of each page and should give viewer a\n# quick idea about the purpose of the project. Keep the description short.\n\nPROJECT_BRIEF          = \"A procedural, easy to use, general purpose language\"\n\n# With the PROJECT_LOGO tag one can specify a logo or an icon that is included\n# in the documentation. The maximum height of the logo should not exceed 55\n# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy\n# the logo to the output directory.\n\nPROJECT_LOGO           =\n\n# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path\n# into which the generated documentation will be written. If a relative path is\n# entered, it will be relative to the location where doxygen was started. If\n# left blank the current directory will be used.\n\nOUTPUT_DIRECTORY       = doxygen/\n\n# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-\n# directories (in 2 levels) under the output directory of each output format and\n# will distribute the generated files over these directories. Enabling this\n# option can be useful when feeding doxygen a huge amount of source files, where\n# putting all generated files in the same directory would otherwise causes\n# performance problems for the file system.\n# The default value is: NO.\n\nCREATE_SUBDIRS         = NO\n\n# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII\n# characters to appear in the names of generated files. If set to NO, non-ASCII\n# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode\n# U+3044.\n# The default value is: NO.\n\nALLOW_UNICODE_NAMES    = NO\n\n# The OUTPUT_LANGUAGE tag is used to specify the language in which all\n# documentation generated by doxygen is written. Doxygen will use this\n# information to generate all constant output in the proper language.\n# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,\n# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),\n# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,\n# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),\n# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,\n# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,\n# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,\n# Ukrainian and Vietnamese.\n# The default value is: English.\n\nOUTPUT_LANGUAGE        = English\n\n# The OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all\n# documentation generated by doxygen is written. Doxygen will use this\n# information to generate all generated output in the proper direction.\n# Possible values are: None, LTR, RTL and Context.\n# The default value is: None.\n\nOUTPUT_TEXT_DIRECTION  = None\n\n# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member\n# descriptions after the members that are listed in the file and class\n# documentation (similar to Javadoc). Set to NO to disable this.\n# The default value is: YES.\n\nBRIEF_MEMBER_DESC      = YES\n\n# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief\n# description of a member or function before the detailed description\n#\n# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the\n# brief descriptions will be completely suppressed.\n# The default value is: YES.\n\nREPEAT_BRIEF           = YES\n\n# This tag implements a quasi-intelligent brief description abbreviator that is\n# used to form the text in various listings. Each string in this list, if found\n# as the leading text of the brief description, will be stripped from the text\n# and the result, after processing the whole list, is used as the annotated\n# text. Otherwise, the brief description is used as-is. If left blank, the\n# following values are used ($name is automatically replaced with the name of\n# the entity):The $name class, The $name widget, The $name file, is, provides,\n# specifies, contains, represents, a, an and the.\n\nABBREVIATE_BRIEF       = \"The $name class\" \\\n                         \"The $name widget\" \\\n                         \"The $name file\" \\\n                         is \\\n                         provides \\\n                         specifies \\\n                         contains \\\n                         represents \\\n                         a \\\n                         an \\\n                         the\n\n# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then\n# doxygen will generate a detailed section even if there is only a brief\n# description.\n# The default value is: NO.\n\nALWAYS_DETAILED_SEC    = NO\n\n# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all\n# inherited members of a class in the documentation of that class as if those\n# members were ordinary class members. Constructors, destructors and assignment\n# operators of the base classes will not be shown.\n# The default value is: NO.\n\nINLINE_INHERITED_MEMB  = NO\n\n# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path\n# before files name in the file list and in the header files. If set to NO the\n# shortest path that makes the file name unique will be used\n# The default value is: YES.\n\nFULL_PATH_NAMES        = YES\n\n# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.\n# Stripping is only done if one of the specified strings matches the left-hand\n# part of the path. The tag can be used to show relative paths in the file list.\n# If left blank the directory from which doxygen is run is used as the path to\n# strip.\n#\n# Note that you can specify absolute paths here, but also relative paths, which\n# will be relative from the directory where doxygen is started.\n# This tag requires that the tag FULL_PATH_NAMES is set to YES.\n\nSTRIP_FROM_PATH        =\n\n# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the\n# path mentioned in the documentation of a class, which tells the reader which\n# header file to include in order to use a class. If left blank only the name of\n# the header file containing the class definition is used. Otherwise one should\n# specify the list of include paths that are normally passed to the compiler\n# using the -I flag.\n\nSTRIP_FROM_INC_PATH    =\n\n# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but\n# less readable) file names. This can be useful is your file systems doesn't\n# support long names like on DOS, Mac, or CD-ROM.\n# The default value is: NO.\n\nSHORT_NAMES            = NO\n\n# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the\n# first line (until the first dot) of a Javadoc-style comment as the brief\n# description. If set to NO, the Javadoc-style will behave just like regular Qt-\n# style comments (thus requiring an explicit @brief command for a brief\n# description.)\n# The default value is: NO.\n\nJAVADOC_AUTOBRIEF      = NO\n\n# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line\n# such as\n# /***************\n# as being the beginning of a Javadoc-style comment \"banner\". If set to NO, the\n# Javadoc-style will behave just like regular comments and it will not be\n# interpreted by doxygen.\n# The default value is: NO.\n\nJAVADOC_BANNER         = NO\n\n# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first\n# line (until the first dot) of a Qt-style comment as the brief description. If\n# set to NO, the Qt-style will behave just like regular Qt-style comments (thus\n# requiring an explicit \\brief command for a brief description.)\n# The default value is: NO.\n\nQT_AUTOBRIEF           = NO\n\n# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a\n# multi-line C++ special comment block (i.e. a block of //! or /// comments) as\n# a brief description. This used to be the default behavior. The new default is\n# to treat a multi-line C++ comment block as a detailed description. Set this\n# tag to YES if you prefer the old behavior instead.\n#\n# Note that setting this tag to YES also means that rational rose comments are\n# not recognized any more.\n# The default value is: NO.\n\nMULTILINE_CPP_IS_BRIEF = NO\n\n# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the\n# documentation from any documented member that it re-implements.\n# The default value is: YES.\n\nINHERIT_DOCS           = YES\n\n# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new\n# page for each member. If set to NO, the documentation of a member will be part\n# of the file/class/namespace that contains it.\n# The default value is: NO.\n\nSEPARATE_MEMBER_PAGES  = NO\n\n# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen\n# uses this value to replace tabs by spaces in code fragments.\n# Minimum value: 1, maximum value: 16, default value: 4.\n\nTAB_SIZE               = 4\n\n# This tag can be used to specify a number of aliases that act as commands in\n# the documentation. An alias has the form:\n# name=value\n# For example adding\n# \"sideeffect=@par Side Effects:\\n\"\n# will allow you to put the command \\sideeffect (or @sideeffect) in the\n# documentation, which will result in a user-defined paragraph with heading\n# \"Side Effects:\". You can put \\n's in the value part of an alias to insert\n# newlines (in the resulting output). You can put ^^ in the value part of an\n# alias to insert a newline as if a physical newline was in the original file.\n# When you need a literal { or } or , in the value part of an alias you have to\n# escape them by means of a backslash (\\), this can lead to conflicts with the\n# commands \\{ and \\} for these it is advised to use the version @{ and @} or use\n# a double escape (\\\\{ and \\\\})\n\nALIASES                =\n\n# This tag can be used to specify a number of word-keyword mappings (TCL only).\n# A mapping has the form \"name=value\". For example adding \"class=itcl::class\"\n# will allow you to use the command class in the itcl::class meaning.\n\nTCL_SUBST              =\n\n# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources\n# only. Doxygen will then generate output that is more tailored for C. For\n# instance, some of the names that are used will be different. The list of all\n# members will be omitted, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_FOR_C  = NO\n\n# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or\n# Python sources only. Doxygen will then generate output that is more tailored\n# for that language. For instance, namespaces will be presented as packages,\n# qualified scopes will look different, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_JAVA   = NO\n\n# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran\n# sources. Doxygen will then generate output that is tailored for Fortran.\n# The default value is: NO.\n\nOPTIMIZE_FOR_FORTRAN   = NO\n\n# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL\n# sources. Doxygen will then generate output that is tailored for VHDL.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_VHDL   = NO\n\n# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice\n# sources only. Doxygen will then generate output that is more tailored for that\n# language. For instance, namespaces will be presented as modules, types will be\n# separated into more groups, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_SLICE  = NO\n\n# Doxygen selects the parser to use depending on the extension of the files it\n# parses. With this tag you can assign which parser to use for a given\n# extension. Doxygen has a built-in mapping, but you can override or extend it\n# using this tag. The format is ext=language, where ext is a file extension, and\n# language is one of the parsers supported by doxygen: IDL, Java, Javascript,\n# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice,\n# Fortran (fixed format Fortran: FortranFixed, free formatted Fortran:\n# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser\n# tries to guess whether the code is fixed or free formatted code, this is the\n# default for Fortran type files), VHDL, tcl. For instance to make doxygen treat\n# .inc files as Fortran files (default is PHP), and .f files as C (default is\n# Fortran), use: inc=Fortran f=C.\n#\n# Note: For files without extension you can use no_extension as a placeholder.\n#\n# Note that for custom extensions you also need to set FILE_PATTERNS otherwise\n# the files are not read by doxygen.\n\nEXTENSION_MAPPING      =\n\n# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments\n# according to the Markdown format, which allows for more readable\n# documentation. See https://daringfireball.net/projects/markdown/ for details.\n# The output of markdown processing is further processed by doxygen, so you can\n# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in\n# case of backward compatibilities issues.\n# The default value is: YES.\n\nMARKDOWN_SUPPORT       = YES\n\n# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up\n# to that level are automatically included in the table of contents, even if\n# they do not have an id attribute.\n# Note: This feature currently applies only to Markdown headings.\n# Minimum value: 0, maximum value: 99, default value: 5.\n# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.\n\nTOC_INCLUDE_HEADINGS   = 5\n\n# When enabled doxygen tries to link words that correspond to documented\n# classes, or namespaces to their corresponding documentation. Such a link can\n# be prevented in individual cases by putting a % sign in front of the word or\n# globally by setting AUTOLINK_SUPPORT to NO.\n# The default value is: YES.\n\nAUTOLINK_SUPPORT       = YES\n\n# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want\n# to include (a tag file for) the STL sources as input, then you should set this\n# tag to YES in order to let doxygen match functions declarations and\n# definitions whose arguments contain STL classes (e.g. func(std::string);\n# versus func(std::string) {}). This also make the inheritance and collaboration\n# diagrams that involve STL classes more complete and accurate.\n# The default value is: NO.\n\nBUILTIN_STL_SUPPORT    = NO\n\n# If you use Microsoft's C++/CLI language, you should set this option to YES to\n# enable parsing support.\n# The default value is: NO.\n\nCPP_CLI_SUPPORT        = NO\n\n# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:\n# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen\n# will parse them like normal C++ but will assume all classes use public instead\n# of private inheritance when no explicit protection keyword is present.\n# The default value is: NO.\n\nSIP_SUPPORT            = NO\n\n# For Microsoft's IDL there are propget and propput attributes to indicate\n# getter and setter methods for a property. Setting this option to YES will make\n# doxygen to replace the get and set methods by a property in the documentation.\n# This will only work if the methods are indeed getting or setting a simple\n# type. If this is not the case, or you want to show the methods anyway, you\n# should set this option to NO.\n# The default value is: YES.\n\nIDL_PROPERTY_SUPPORT   = YES\n\n# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC\n# tag is set to YES then doxygen will reuse the documentation of the first\n# member in the group (if any) for the other members of the group. By default\n# all members of a group must be documented explicitly.\n# The default value is: NO.\n\nDISTRIBUTE_GROUP_DOC   = NO\n\n# If one adds a struct or class to a group and this option is enabled, then also\n# any nested class or struct is added to the same group. By default this option\n# is disabled and one has to add nested compounds explicitly via \\ingroup.\n# The default value is: NO.\n\nGROUP_NESTED_COMPOUNDS = NO\n\n# Set the SUBGROUPING tag to YES to allow class member groups of the same type\n# (for instance a group of public functions) to be put as a subgroup of that\n# type (e.g. under the Public Functions section). Set it to NO to prevent\n# subgrouping. Alternatively, this can be done per class using the\n# \\nosubgrouping command.\n# The default value is: YES.\n\nSUBGROUPING            = YES\n\n# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions\n# are shown inside the group in which they are included (e.g. using \\ingroup)\n# instead of on a separate page (for HTML and Man pages) or section (for LaTeX\n# and RTF).\n#\n# Note that this feature does not work in combination with\n# SEPARATE_MEMBER_PAGES.\n# The default value is: NO.\n\nINLINE_GROUPED_CLASSES = NO\n\n# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions\n# with only public data fields or simple typedef fields will be shown inline in\n# the documentation of the scope in which they are defined (i.e. file,\n# namespace, or group documentation), provided this scope is documented. If set\n# to NO, structs, classes, and unions are shown on a separate page (for HTML and\n# Man pages) or section (for LaTeX and RTF).\n# The default value is: NO.\n\nINLINE_SIMPLE_STRUCTS  = NO\n\n# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or\n# enum is documented as struct, union, or enum with the name of the typedef. So\n# typedef struct TypeS {} TypeT, will appear in the documentation as a struct\n# with name TypeT. When disabled the typedef will appear as a member of a file,\n# namespace, or class. And the struct will be named TypeS. This can typically be\n# useful for C code in case the coding convention dictates that all compound\n# types are typedef'ed and only the typedef is referenced, never the tag name.\n# The default value is: NO.\n\nTYPEDEF_HIDES_STRUCT   = NO\n\n# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This\n# cache is used to resolve symbols given their name and scope. Since this can be\n# an expensive process and often the same symbol appears multiple times in the\n# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small\n# doxygen will become slower. If the cache is too large, memory is wasted. The\n# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range\n# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536\n# symbols. At the end of a run doxygen will report the cache usage and suggest\n# the optimal cache size from a speed point of view.\n# Minimum value: 0, maximum value: 9, default value: 0.\n\nLOOKUP_CACHE_SIZE      = 0\n\n#---------------------------------------------------------------------------\n# Build related configuration options\n#---------------------------------------------------------------------------\n\n# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in\n# documentation are documented, even if no documentation was available. Private\n# class members and static file members will be hidden unless the\n# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.\n# Note: This will also disable the warnings about undocumented members that are\n# normally produced when WARNINGS is set to YES.\n# The default value is: NO.\n\nEXTRACT_ALL            = NO\n\n# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will\n# be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PRIVATE        = NO\n\n# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual\n# methods of a class will be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PRIV_VIRTUAL   = NO\n\n# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal\n# scope will be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PACKAGE        = NO\n\n# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be\n# included in the documentation.\n# The default value is: NO.\n\nEXTRACT_STATIC         = NO\n\n# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined\n# locally in source files will be included in the documentation. If set to NO,\n# only classes defined in header files are included. Does not have any effect\n# for Java sources.\n# The default value is: YES.\n\nEXTRACT_LOCAL_CLASSES  = YES\n\n# This flag is only useful for Objective-C code. If set to YES, local methods,\n# which are defined in the implementation section but not in the interface are\n# included in the documentation. If set to NO, only methods in the interface are\n# included.\n# The default value is: NO.\n\nEXTRACT_LOCAL_METHODS  = NO\n\n# If this flag is set to YES, the members of anonymous namespaces will be\n# extracted and appear in the documentation as a namespace called\n# 'anonymous_namespace{file}', where file will be replaced with the base name of\n# the file that contains the anonymous namespace. By default anonymous namespace\n# are hidden.\n# The default value is: NO.\n\nEXTRACT_ANON_NSPACES   = NO\n\n# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all\n# undocumented members inside documented classes or files. If set to NO these\n# members will be included in the various overviews, but no documentation\n# section is generated. This option has no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_MEMBERS     = NO\n\n# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all\n# undocumented classes that are normally visible in the class hierarchy. If set\n# to NO, these classes will be included in the various overviews. This option\n# has no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_CLASSES     = NO\n\n# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend\n# (class|struct|union) declarations. If set to NO, these declarations will be\n# included in the documentation.\n# The default value is: NO.\n\nHIDE_FRIEND_COMPOUNDS  = NO\n\n# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any\n# documentation blocks found inside the body of a function. If set to NO, these\n# blocks will be appended to the function's detailed documentation block.\n# The default value is: NO.\n\nHIDE_IN_BODY_DOCS      = NO\n\n# The INTERNAL_DOCS tag determines if documentation that is typed after a\n# \\internal command is included. If the tag is set to NO then the documentation\n# will be excluded. Set it to YES to include the internal documentation.\n# The default value is: NO.\n\nINTERNAL_DOCS          = NO\n\n# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file\n# names in lower-case letters. If set to YES, upper-case letters are also\n# allowed. This is useful if you have classes or files whose names only differ\n# in case and if your file system supports case sensitive file names. Windows\n# (including Cygwin) ands Mac users are advised to set this option to NO.\n# The default value is: system dependent.\n\nCASE_SENSE_NAMES       = NO\n\n# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with\n# their full class and namespace scopes in the documentation. If set to YES, the\n# scope will be hidden.\n# The default value is: NO.\n\nHIDE_SCOPE_NAMES       = NO\n\n# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will\n# append additional text to a page's title, such as Class Reference. If set to\n# YES the compound reference will be hidden.\n# The default value is: NO.\n\nHIDE_COMPOUND_REFERENCE= NO\n\n# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of\n# the files that are included by a file in the documentation of that file.\n# The default value is: YES.\n\nSHOW_INCLUDE_FILES     = YES\n\n# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each\n# grouped member an include statement to the documentation, telling the reader\n# which file to include in order to use the member.\n# The default value is: NO.\n\nSHOW_GROUPED_MEMB_INC  = NO\n\n# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include\n# files with double quotes in the documentation rather than with sharp brackets.\n# The default value is: NO.\n\nFORCE_LOCAL_INCLUDES   = NO\n\n# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the\n# documentation for inline members.\n# The default value is: YES.\n\nINLINE_INFO            = YES\n\n# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the\n# (detailed) documentation of file and class members alphabetically by member\n# name. If set to NO, the members will appear in declaration order.\n# The default value is: YES.\n\nSORT_MEMBER_DOCS       = YES\n\n# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief\n# descriptions of file, namespace and class members alphabetically by member\n# name. If set to NO, the members will appear in declaration order. Note that\n# this will also influence the order of the classes in the class list.\n# The default value is: NO.\n\nSORT_BRIEF_DOCS        = NO\n\n# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the\n# (brief and detailed) documentation of class members so that constructors and\n# destructors are listed first. If set to NO the constructors will appear in the\n# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.\n# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief\n# member documentation.\n# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting\n# detailed member documentation.\n# The default value is: NO.\n\nSORT_MEMBERS_CTORS_1ST = NO\n\n# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy\n# of group names into alphabetical order. If set to NO the group names will\n# appear in their defined order.\n# The default value is: NO.\n\nSORT_GROUP_NAMES       = NO\n\n# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by\n# fully-qualified names, including namespaces. If set to NO, the class list will\n# be sorted only by class name, not including the namespace part.\n# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.\n# Note: This option applies only to the class list, not to the alphabetical\n# list.\n# The default value is: NO.\n\nSORT_BY_SCOPE_NAME     = NO\n\n# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper\n# type resolution of all parameters of a function it will reject a match between\n# the prototype and the implementation of a member function even if there is\n# only one candidate or it is obvious which candidate to choose by doing a\n# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still\n# accept a match between prototype and implementation in such cases.\n# The default value is: NO.\n\nSTRICT_PROTO_MATCHING  = NO\n\n# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo\n# list. This list is created by putting \\todo commands in the documentation.\n# The default value is: YES.\n\nGENERATE_TODOLIST      = YES\n\n# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test\n# list. This list is created by putting \\test commands in the documentation.\n# The default value is: YES.\n\nGENERATE_TESTLIST      = YES\n\n# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug\n# list. This list is created by putting \\bug commands in the documentation.\n# The default value is: YES.\n\nGENERATE_BUGLIST       = YES\n\n# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)\n# the deprecated list. This list is created by putting \\deprecated commands in\n# the documentation.\n# The default value is: YES.\n\nGENERATE_DEPRECATEDLIST= YES\n\n# The ENABLED_SECTIONS tag can be used to enable conditional documentation\n# sections, marked by \\if <section_label> ... \\endif and \\cond <section_label>\n# ... \\endcond blocks.\n\nENABLED_SECTIONS       =\n\n# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the\n# initial value of a variable or macro / define can have for it to appear in the\n# documentation. If the initializer consists of more lines than specified here\n# it will be hidden. Use a value of 0 to hide initializers completely. The\n# appearance of the value of individual variables and macros / defines can be\n# controlled using \\showinitializer or \\hideinitializer command in the\n# documentation regardless of this setting.\n# Minimum value: 0, maximum value: 10000, default value: 30.\n\nMAX_INITIALIZER_LINES  = 30\n\n# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at\n# the bottom of the documentation of classes and structs. If set to YES, the\n# list will mention the files that were used to generate the documentation.\n# The default value is: YES.\n\nSHOW_USED_FILES        = YES\n\n# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This\n# will remove the Files entry from the Quick Index and from the Folder Tree View\n# (if specified).\n# The default value is: YES.\n\nSHOW_FILES             = YES\n\n# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces\n# page. This will remove the Namespaces entry from the Quick Index and from the\n# Folder Tree View (if specified).\n# The default value is: YES.\n\nSHOW_NAMESPACES        = YES\n\n# The FILE_VERSION_FILTER tag can be used to specify a program or script that\n# doxygen should invoke to get the current version for each file (typically from\n# the version control system). Doxygen will invoke the program by executing (via\n# popen()) the command command input-file, where command is the value of the\n# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided\n# by doxygen. Whatever the program writes to standard output is used as the file\n# version. For an example see the documentation.\n\nFILE_VERSION_FILTER    =\n\n# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed\n# by doxygen. The layout file controls the global structure of the generated\n# output files in an output format independent way. To create the layout file\n# that represents doxygen's defaults, run doxygen with the -l option. You can\n# optionally specify a file name after the option, if omitted DoxygenLayout.xml\n# will be used as the name of the layout file.\n#\n# Note that if you run doxygen from a directory containing a file called\n# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE\n# tag is left empty.\n\nLAYOUT_FILE            =\n\n# The CITE_BIB_FILES tag can be used to specify one or more bib files containing\n# the reference definitions. This must be a list of .bib files. The .bib\n# extension is automatically appended if omitted. This requires the bibtex tool\n# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info.\n# For LaTeX the style of the bibliography can be controlled using\n# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the\n# search path. See also \\cite for info how to create references.\n\nCITE_BIB_FILES         =\n\n#---------------------------------------------------------------------------\n# Configuration options related to warning and progress messages\n#---------------------------------------------------------------------------\n\n# The QUIET tag can be used to turn on/off the messages that are generated to\n# standard output by doxygen. If QUIET is set to YES this implies that the\n# messages are off.\n# The default value is: NO.\n\nQUIET                  = NO\n\n# The WARNINGS tag can be used to turn on/off the warning messages that are\n# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES\n# this implies that the warnings are on.\n#\n# Tip: Turn warnings on while writing the documentation.\n# The default value is: YES.\n\nWARNINGS               = YES\n\n# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate\n# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag\n# will automatically be disabled.\n# The default value is: YES.\n\nWARN_IF_UNDOCUMENTED   = YES\n\n# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for\n# potential errors in the documentation, such as not documenting some parameters\n# in a documented function, or documenting parameters that don't exist or using\n# markup commands wrongly.\n# The default value is: YES.\n\nWARN_IF_DOC_ERROR      = YES\n\n# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that\n# are documented, but have no documentation for their parameters or return\n# value. If set to NO, doxygen will only warn about wrong or incomplete\n# parameter documentation, but not about the absence of documentation. If\n# EXTRACT_ALL is set to YES then this flag will automatically be disabled.\n# The default value is: NO.\n\nWARN_NO_PARAMDOC       = NO\n\n# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when\n# a warning is encountered.\n# The default value is: NO.\n\nWARN_AS_ERROR          = NO\n\n# The WARN_FORMAT tag determines the format of the warning messages that doxygen\n# can produce. The string should contain the $file, $line, and $text tags, which\n# will be replaced by the file and line number from which the warning originated\n# and the warning text. Optionally the format may contain $version, which will\n# be replaced by the version of the file (if it could be obtained via\n# FILE_VERSION_FILTER)\n# The default value is: $file:$line: $text.\n\nWARN_FORMAT            = \"$file:$line: $text\"\n\n# The WARN_LOGFILE tag can be used to specify a file to which warning and error\n# messages should be written. If left blank the output is written to standard\n# error (stderr).\n\nWARN_LOGFILE           =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the input files\n#---------------------------------------------------------------------------\n\n# The INPUT tag is used to specify the files and/or directories that contain\n# documented source files. You may enter file names like myfile.cpp or\n# directories like /usr/src/myproject. Separate the files or directories with\n# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING\n# Note: If this tag is empty the current directory is searched.\n\nINPUT                  =\n\n# This tag can be used to specify the character encoding of the source files\n# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses\n# libiconv (or the iconv built into libc) for the transcoding. See the libiconv\n# documentation (see: https://www.gnu.org/software/libiconv/) for the list of\n# possible encodings.\n# The default value is: UTF-8.\n\nINPUT_ENCODING         = UTF-8\n\n# If the value of the INPUT tag contains directories, you can use the\n# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and\n# *.h) to filter out the source-files in the directories.\n#\n# Note that for custom extensions or not directly supported extensions you also\n# need to set EXTENSION_MAPPING for the extension otherwise the files are not\n# read by doxygen.\n#\n# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,\n# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,\n# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,\n# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08,\n# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, *.qsf and *.ice.\n\nFILE_PATTERNS          = *.c \\\n                         *.cc \\\n                         *.cxx \\\n                         *.cpp \\\n                         *.c++ \\\n                         *.java \\\n                         *.ii \\\n                         *.ixx \\\n                         *.ipp \\\n                         *.i++ \\\n                         *.inl \\\n                         *.idl \\\n                         *.ddl \\\n                         *.odl \\\n                         *.h \\\n                         *.hh \\\n                         *.hxx \\\n                         *.hpp \\\n                         *.h++ \\\n                         *.cs \\\n                         *.d \\\n                         *.php \\\n                         *.php4 \\\n                         *.php5 \\\n                         *.phtml \\\n                         *.inc \\\n                         *.m \\\n                         *.markdown \\\n                         *.md \\\n                         *.mm \\\n                         *.dox \\\n                         *.py \\\n                         *.pyw \\\n                         *.f90 \\\n                         *.f95 \\\n                         *.f03 \\\n                         *.f08 \\\n                         *.f \\\n                         *.for \\\n                         *.tcl \\\n                         *.vhd \\\n                         *.vhdl \\\n                         *.ucf \\\n                         *.qsf \\\n                         *.ice\n\n# The RECURSIVE tag can be used to specify whether or not subdirectories should\n# be searched for input files as well.\n# The default value is: NO.\n\nRECURSIVE              = YES\n\n# The EXCLUDE tag can be used to specify files and/or directories that should be\n# excluded from the INPUT source files. This way you can easily exclude a\n# subdirectory from a directory tree whose root is specified with the INPUT tag.\n#\n# Note that relative paths are relative to the directory from which doxygen is\n# run.\n\nEXCLUDE                =\n\n# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or\n# directories that are symbolic links (a Unix file system feature) are excluded\n# from the input.\n# The default value is: NO.\n\nEXCLUDE_SYMLINKS       = NO\n\n# If the value of the INPUT tag contains directories, you can use the\n# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude\n# certain files from those directories.\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories for example use the pattern */test/*\n\nEXCLUDE_PATTERNS       =\n\n# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names\n# (namespaces, classes, functions, etc.) that should be excluded from the\n# output. The symbol name can be a fully qualified name, a word, or if the\n# wildcard * is used, a substring. Examples: ANamespace, AClass,\n# AClass::ANamespace, ANamespace::*Test\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories use the pattern */test/*\n\nEXCLUDE_SYMBOLS        =\n\n# The EXAMPLE_PATH tag can be used to specify one or more files or directories\n# that contain example code fragments that are included (see the \\include\n# command).\n\nEXAMPLE_PATH           =\n\n# If the value of the EXAMPLE_PATH tag contains directories, you can use the\n# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and\n# *.h) to filter out the source-files in the directories. If left blank all\n# files are included.\n\nEXAMPLE_PATTERNS       = *\n\n# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be\n# searched for input files to be used with the \\include or \\dontinclude commands\n# irrespective of the value of the RECURSIVE tag.\n# The default value is: NO.\n\nEXAMPLE_RECURSIVE      = NO\n\n# The IMAGE_PATH tag can be used to specify one or more files or directories\n# that contain images that are to be included in the documentation (see the\n# \\image command).\n\nIMAGE_PATH             =\n\n# The INPUT_FILTER tag can be used to specify a program that doxygen should\n# invoke to filter for each input file. Doxygen will invoke the filter program\n# by executing (via popen()) the command:\n#\n# <filter> <input-file>\n#\n# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the\n# name of an input file. Doxygen will then use the output that the filter\n# program writes to standard output. If FILTER_PATTERNS is specified, this tag\n# will be ignored.\n#\n# Note that the filter must not add or remove lines; it is applied before the\n# code is scanned, but not when the output code is generated. If lines are added\n# or removed, the anchors will not be placed correctly.\n#\n# Note that for custom extensions or not directly supported extensions you also\n# need to set EXTENSION_MAPPING for the extension otherwise the files are not\n# properly processed by doxygen.\n\nINPUT_FILTER           =\n\n# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern\n# basis. Doxygen will compare the file name with each pattern and apply the\n# filter if there is a match. The filters are a list of the form: pattern=filter\n# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how\n# filters are used. If the FILTER_PATTERNS tag is empty or if none of the\n# patterns match the file name, INPUT_FILTER is applied.\n#\n# Note that for custom extensions or not directly supported extensions you also\n# need to set EXTENSION_MAPPING for the extension otherwise the files are not\n# properly processed by doxygen.\n\nFILTER_PATTERNS        =\n\n# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using\n# INPUT_FILTER) will also be used to filter the input files that are used for\n# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).\n# The default value is: NO.\n\nFILTER_SOURCE_FILES    = NO\n\n# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file\n# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and\n# it is also possible to disable source filtering for a specific pattern using\n# *.ext= (so without naming a filter).\n# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.\n\nFILTER_SOURCE_PATTERNS =\n\n# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that\n# is part of the input, its contents will be placed on the main page\n# (index.html). This can be useful if you have a project on for instance GitHub\n# and want to reuse the introduction page also for the doxygen output.\n\nUSE_MDFILE_AS_MAINPAGE =\n\n#---------------------------------------------------------------------------\n# Configuration options related to source browsing\n#---------------------------------------------------------------------------\n\n# If the SOURCE_BROWSER tag is set to YES then a list of source files will be\n# generated. Documented entities will be cross-referenced with these sources.\n#\n# Note: To get rid of all source code in the generated output, make sure that\n# also VERBATIM_HEADERS is set to NO.\n# The default value is: NO.\n\nSOURCE_BROWSER         = NO\n\n# Setting the INLINE_SOURCES tag to YES will include the body of functions,\n# classes and enums directly into the documentation.\n# The default value is: NO.\n\nINLINE_SOURCES         = NO\n\n# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any\n# special comment blocks from generated source code fragments. Normal C, C++ and\n# Fortran comments will always remain visible.\n# The default value is: YES.\n\nSTRIP_CODE_COMMENTS    = YES\n\n# If the REFERENCED_BY_RELATION tag is set to YES then for each documented\n# entity all documented functions referencing it will be listed.\n# The default value is: NO.\n\nREFERENCED_BY_RELATION = NO\n\n# If the REFERENCES_RELATION tag is set to YES then for each documented function\n# all documented entities called/used by that function will be listed.\n# The default value is: NO.\n\nREFERENCES_RELATION    = NO\n\n# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set\n# to YES then the hyperlinks from functions in REFERENCES_RELATION and\n# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will\n# link to the documentation.\n# The default value is: YES.\n\nREFERENCES_LINK_SOURCE = YES\n\n# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the\n# source code will show a tooltip with additional information such as prototype,\n# brief description and links to the definition and documentation. Since this\n# will make the HTML file larger and loading of large files a bit slower, you\n# can opt to disable this feature.\n# The default value is: YES.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nSOURCE_TOOLTIPS        = YES\n\n# If the USE_HTAGS tag is set to YES then the references to source code will\n# point to the HTML generated by the htags(1) tool instead of doxygen built-in\n# source browser. The htags tool is part of GNU's global source tagging system\n# (see https://www.gnu.org/software/global/global.html). You will need version\n# 4.8.6 or higher.\n#\n# To use it do the following:\n# - Install the latest version of global\n# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file\n# - Make sure the INPUT points to the root of the source tree\n# - Run doxygen as normal\n#\n# Doxygen will invoke htags (and that will in turn invoke gtags), so these\n# tools must be available from the command line (i.e. in the search path).\n#\n# The result: instead of the source browser generated by doxygen, the links to\n# source code will now point to the output of htags.\n# The default value is: NO.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nUSE_HTAGS              = NO\n\n# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a\n# verbatim copy of the header file for each class for which an include is\n# specified. Set to NO to disable this.\n# See also: Section \\class.\n# The default value is: YES.\n\nVERBATIM_HEADERS       = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to the alphabetical class index\n#---------------------------------------------------------------------------\n\n# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all\n# compounds will be generated. Enable this if the project contains a lot of\n# classes, structs, unions or interfaces.\n# The default value is: YES.\n\nALPHABETICAL_INDEX     = YES\n\n# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in\n# which the alphabetical index list will be split.\n# Minimum value: 1, maximum value: 20, default value: 5.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nCOLS_IN_ALPHA_INDEX    = 5\n\n# In case all classes in a project start with a common prefix, all classes will\n# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag\n# can be used to specify a prefix (or a list of prefixes) that should be ignored\n# while generating the index headers.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nIGNORE_PREFIX          =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the HTML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output\n# The default value is: YES.\n\nGENERATE_HTML          = YES\n\n# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_OUTPUT            = html\n\n# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each\n# generated HTML page (for example: .htm, .php, .asp).\n# The default value is: .html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FILE_EXTENSION    = .html\n\n# The HTML_HEADER tag can be used to specify a user-defined HTML header file for\n# each generated HTML page. If the tag is left blank doxygen will generate a\n# standard header.\n#\n# To get valid HTML the header file that includes any scripts and style sheets\n# that doxygen needs, which is dependent on the configuration options used (e.g.\n# the setting GENERATE_TREEVIEW). It is highly recommended to start with a\n# default header using\n# doxygen -w html new_header.html new_footer.html new_stylesheet.css\n# YourConfigFile\n# and then modify the file new_header.html. See also section \"Doxygen usage\"\n# for information on how to generate the default header that doxygen normally\n# uses.\n# Note: The header is subject to change so you typically have to regenerate the\n# default header when upgrading to a newer version of doxygen. For a description\n# of the possible markers and block names see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_HEADER            =\n\n# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each\n# generated HTML page. If the tag is left blank doxygen will generate a standard\n# footer. See HTML_HEADER for more information on how to generate a default\n# footer and what special commands can be used inside the footer. See also\n# section \"Doxygen usage\" for information on how to generate the default footer\n# that doxygen normally uses.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FOOTER            =\n\n# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style\n# sheet that is used by each HTML page. It can be used to fine-tune the look of\n# the HTML output. If left blank doxygen will generate a default style sheet.\n# See also section \"Doxygen usage\" for information on how to generate the style\n# sheet that doxygen normally uses.\n# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as\n# it is more robust and this tag (HTML_STYLESHEET) will in the future become\n# obsolete.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_STYLESHEET        =\n\n# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined\n# cascading style sheets that are included after the standard style sheets\n# created by doxygen. Using this option one can overrule certain style aspects.\n# This is preferred over using HTML_STYLESHEET since it does not replace the\n# standard style sheet and is therefore more robust against future updates.\n# Doxygen will copy the style sheet files to the output directory.\n# Note: The order of the extra style sheet files is of importance (e.g. the last\n# style sheet in the list overrules the setting of the previous ones in the\n# list). For an example see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_STYLESHEET  =\n\n# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the HTML output directory. Note\n# that these files will be copied to the base HTML output directory. Use the\n# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these\n# files. In the HTML_STYLESHEET file, use the file name only. Also note that the\n# files will be copied as-is; there are no commands or markers available.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_FILES       =\n\n# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen\n# will adjust the colors in the style sheet and background images according to\n# this color. Hue is specified as an angle on a colorwheel, see\n# https://en.wikipedia.org/wiki/Hue for more information. For instance the value\n# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300\n# purple, and 360 is red again.\n# Minimum value: 0, maximum value: 359, default value: 220.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_HUE    = 220\n\n# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors\n# in the HTML output. For a value of 0 the output will use grayscales only. A\n# value of 255 will produce the most vivid colors.\n# Minimum value: 0, maximum value: 255, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_SAT    = 100\n\n# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the\n# luminance component of the colors in the HTML output. Values below 100\n# gradually make the output lighter, whereas values above 100 make the output\n# darker. The value divided by 100 is the actual gamma applied, so 80 represents\n# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not\n# change the gamma.\n# Minimum value: 40, maximum value: 240, default value: 80.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_GAMMA  = 80\n\n# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML\n# page will contain the date and time when the page was generated. Setting this\n# to YES can help to show when doxygen was last run and thus if the\n# documentation is up to date.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_TIMESTAMP         = NO\n\n# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML\n# documentation will contain a main index with vertical navigation menus that\n# are dynamically created via Javascript. If disabled, the navigation index will\n# consists of multiple levels of tabs that are statically embedded in every HTML\n# page. Disable this option to support browsers that do not have Javascript,\n# like the Qt help browser.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_DYNAMIC_MENUS     = YES\n\n# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML\n# documentation will contain sections that can be hidden and shown after the\n# page has loaded.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_DYNAMIC_SECTIONS  = NO\n\n# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries\n# shown in the various tree structured indices initially; the user can expand\n# and collapse entries dynamically later on. Doxygen will expand the tree to\n# such a level that at most the specified number of entries are visible (unless\n# a fully collapsed tree already exceeds this amount). So setting the number of\n# entries 1 will produce a full collapsed tree by default. 0 is a special value\n# representing an infinite number of entries and will result in a full expanded\n# tree by default.\n# Minimum value: 0, maximum value: 9999, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_INDEX_NUM_ENTRIES = 100\n\n# If the GENERATE_DOCSET tag is set to YES, additional index files will be\n# generated that can be used as input for Apple's Xcode 3 integrated development\n# environment (see: https://developer.apple.com/xcode/), introduced with OSX\n# 10.5 (Leopard). To create a documentation set, doxygen will generate a\n# Makefile in the HTML output directory. Running make will produce the docset in\n# that directory and running make install will install the docset in\n# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at\n# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy\n# genXcode/_index.html for more information.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_DOCSET        = NO\n\n# This tag determines the name of the docset feed. A documentation feed provides\n# an umbrella under which multiple documentation sets from a single provider\n# (such as a company or product suite) can be grouped.\n# The default value is: Doxygen generated docs.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_FEEDNAME        = \"Doxygen generated docs\"\n\n# This tag specifies a string that should uniquely identify the documentation\n# set bundle. This should be a reverse domain-name style string, e.g.\n# com.mycompany.MyDocSet. Doxygen will append .docset to the name.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_BUNDLE_ID       = org.doxygen.Project\n\n# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify\n# the documentation publisher. This should be a reverse domain-name style\n# string, e.g. com.mycompany.MyDocSet.documentation.\n# The default value is: org.doxygen.Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_ID    = org.doxygen.Publisher\n\n# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.\n# The default value is: Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_NAME  = Publisher\n\n# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three\n# additional HTML index files: index.hhp, index.hhc, and index.hhk. The\n# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop\n# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on\n# Windows.\n#\n# The HTML Help Workshop contains a compiler that can convert all HTML output\n# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML\n# files are now used as the Windows 98 help format, and will replace the old\n# Windows help format (.hlp) on all Windows platforms in the future. Compressed\n# HTML files also contain an index, a table of contents, and you can search for\n# words in the documentation. The HTML workshop also contains a viewer for\n# compressed HTML files.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_HTMLHELP      = NO\n\n# The CHM_FILE tag can be used to specify the file name of the resulting .chm\n# file. You can add a path in front of the file if the result should not be\n# written to the html output directory.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_FILE               =\n\n# The HHC_LOCATION tag can be used to specify the location (absolute path\n# including file name) of the HTML help compiler (hhc.exe). If non-empty,\n# doxygen will try to run the HTML help compiler on the generated index.hhp.\n# The file has to be specified with full path.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nHHC_LOCATION           =\n\n# The GENERATE_CHI flag controls if a separate .chi index file is generated\n# (YES) or that it should be included in the master .chm file (NO).\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nGENERATE_CHI           = NO\n\n# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)\n# and project file content.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_INDEX_ENCODING     =\n\n# The BINARY_TOC flag controls whether a binary table of contents is generated\n# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it\n# enables the Previous and Next buttons.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nBINARY_TOC             = NO\n\n# The TOC_EXPAND flag can be set to YES to add extra items for group members to\n# the table of contents of the HTML help documentation and to the tree view.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nTOC_EXPAND             = NO\n\n# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and\n# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that\n# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help\n# (.qch) of the generated HTML documentation.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_QHP           = NO\n\n# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify\n# the file name of the resulting .qch file. The path specified is relative to\n# the HTML output folder.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQCH_FILE               =\n\n# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help\n# Project output. For more information please see Qt Help Project / Namespace\n# (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_NAMESPACE          = org.doxygen.Project\n\n# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt\n# Help Project output. For more information please see Qt Help Project / Virtual\n# Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-\n# folders).\n# The default value is: doc.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_VIRTUAL_FOLDER     = doc\n\n# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom\n# filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_NAME   =\n\n# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the\n# custom filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_ATTRS  =\n\n# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this\n# project's filter section matches. Qt Help Project / Filter Attributes (see:\n# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_SECT_FILTER_ATTRS  =\n\n# The QHG_LOCATION tag can be used to specify the location of Qt's\n# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the\n# generated .qhp file.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHG_LOCATION           =\n\n# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be\n# generated, together with the HTML files, they form an Eclipse help plugin. To\n# install this plugin and make it available under the help contents menu in\n# Eclipse, the contents of the directory containing the HTML and XML files needs\n# to be copied into the plugins directory of eclipse. The name of the directory\n# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.\n# After copying Eclipse needs to be restarted before the help appears.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_ECLIPSEHELP   = NO\n\n# A unique identifier for the Eclipse help plugin. When installing the plugin\n# the directory name containing the HTML and XML files should also have this\n# name. Each documentation set should have its own identifier.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.\n\nECLIPSE_DOC_ID         = org.doxygen.Project\n\n# If you want full control over the layout of the generated HTML pages it might\n# be necessary to disable the index and replace it with your own. The\n# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top\n# of each HTML page. A value of NO enables the index and the value YES disables\n# it. Since the tabs in the index contain the same information as the navigation\n# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nDISABLE_INDEX          = NO\n\n# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index\n# structure should be generated to display hierarchical information. If the tag\n# value is set to YES, a side panel will be generated containing a tree-like\n# index structure (just like the one that is generated for HTML Help). For this\n# to work a browser that supports JavaScript, DHTML, CSS and frames is required\n# (i.e. any modern browser). Windows users are probably better off using the\n# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can\n# further fine-tune the look of the index. As an example, the default style\n# sheet generated by doxygen has an example that shows how to put an image at\n# the root of the tree instead of the PROJECT_NAME. Since the tree basically has\n# the same information as the tab index, you could consider setting\n# DISABLE_INDEX to YES when enabling this option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_TREEVIEW      = NO\n\n# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that\n# doxygen will group on one line in the generated HTML documentation.\n#\n# Note that a value of 0 will completely suppress the enum values from appearing\n# in the overview section.\n# Minimum value: 0, maximum value: 20, default value: 4.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nENUM_VALUES_PER_LINE   = 4\n\n# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used\n# to set the initial width (in pixels) of the frame in which the tree is shown.\n# Minimum value: 0, maximum value: 1500, default value: 250.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nTREEVIEW_WIDTH         = 250\n\n# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to\n# external symbols imported via tag files in a separate window.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nEXT_LINKS_IN_WINDOW    = NO\n\n# Use this tag to change the font size of LaTeX formulas included as images in\n# the HTML documentation. When you change the font size after a successful\n# doxygen run you need to manually remove any form_*.png images from the HTML\n# output directory to force them to be regenerated.\n# Minimum value: 8, maximum value: 50, default value: 10.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_FONTSIZE       = 10\n\n# Use the FORMULA_TRANSPARENT tag to determine whether or not the images\n# generated for formulas are transparent PNGs. Transparent PNGs are not\n# supported properly for IE 6.0, but are supported on all modern browsers.\n#\n# Note that when changing this option you need to delete any form_*.png files in\n# the HTML output directory before the changes have effect.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_TRANSPARENT    = YES\n\n# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see\n# https://www.mathjax.org) which uses client side Javascript for the rendering\n# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX\n# installed or if you want to formulas look prettier in the HTML output. When\n# enabled you may also need to install MathJax separately and configure the path\n# to it using the MATHJAX_RELPATH option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nUSE_MATHJAX            = NO\n\n# When MathJax is enabled you can set the default output format to be used for\n# the MathJax output. See the MathJax site (see:\n# http://docs.mathjax.org/en/latest/output.html) for more details.\n# Possible values are: HTML-CSS (which is slower, but has the best\n# compatibility), NativeMML (i.e. MathML) and SVG.\n# The default value is: HTML-CSS.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_FORMAT         = HTML-CSS\n\n# When MathJax is enabled you need to specify the location relative to the HTML\n# output directory using the MATHJAX_RELPATH option. The destination directory\n# should contain the MathJax.js script. For instance, if the mathjax directory\n# is located at the same level as the HTML output directory, then\n# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax\n# Content Delivery Network so you can quickly see the result without installing\n# MathJax. However, it is strongly recommended to install a local copy of\n# MathJax from https://www.mathjax.org before deployment.\n# The default value is: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_RELPATH        = https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/\n\n# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax\n# extension names that should be enabled during MathJax rendering. For example\n# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_EXTENSIONS     =\n\n# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces\n# of code that will be used on startup of the MathJax code. See the MathJax site\n# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an\n# example see the documentation.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_CODEFILE       =\n\n# When the SEARCHENGINE tag is enabled doxygen will generate a search box for\n# the HTML output. The underlying search engine uses javascript and DHTML and\n# should work on any modern browser. Note that when using HTML help\n# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)\n# there is already a search function so this one should typically be disabled.\n# For large projects the javascript based search engine can be slow, then\n# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to\n# search using the keyboard; to jump to the search box use <access key> + S\n# (what the <access key> is depends on the OS and browser, but it is typically\n# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down\n# key> to jump into the search results window, the results can be navigated\n# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel\n# the search. The filter options can be selected when the cursor is inside the\n# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>\n# to select a filter and <Enter> or <escape> to activate or cancel the filter\n# option.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nSEARCHENGINE           = YES\n\n# When the SERVER_BASED_SEARCH tag is enabled the search engine will be\n# implemented using a web server instead of a web client using Javascript. There\n# are two flavors of web server based searching depending on the EXTERNAL_SEARCH\n# setting. When disabled, doxygen will generate a PHP script for searching and\n# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing\n# and searching needs to be provided by external tools. See the section\n# \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSERVER_BASED_SEARCH    = NO\n\n# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP\n# script for searching. Instead the search results are written to an XML file\n# which needs to be processed by an external indexer. Doxygen will invoke an\n# external search engine pointed to by the SEARCHENGINE_URL option to obtain the\n# search results.\n#\n# Doxygen ships with an example indexer (doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: https://xapian.org/).\n#\n# See the section \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH        = NO\n\n# The SEARCHENGINE_URL should point to a search engine hosted by a web server\n# which will return the search results when EXTERNAL_SEARCH is enabled.\n#\n# Doxygen ships with an example indexer (doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: https://xapian.org/). See the section \"External Indexing and\n# Searching\" for details.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHENGINE_URL       =\n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed\n# search data is written to a file for indexing by an external tool. With the\n# SEARCHDATA_FILE tag the name of this file can be specified.\n# The default file is: searchdata.xml.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHDATA_FILE        = searchdata.xml\n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the\n# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is\n# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple\n# projects and redirect the results back to the right project.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH_ID     =\n\n# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen\n# projects other than the one defined by this configuration file, but that are\n# all added to the same external search index. Each project needs to have a\n# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of\n# to a relative location where the documentation can be found. The format is:\n# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTRA_SEARCH_MAPPINGS  =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the LaTeX output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.\n# The default value is: YES.\n\nGENERATE_LATEX         = YES\n\n# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: latex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_OUTPUT           = latex\n\n# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be\n# invoked.\n#\n# Note that when not enabling USE_PDFLATEX the default is latex when enabling\n# USE_PDFLATEX the default is pdflatex and when in the later case latex is\n# chosen this is overwritten by pdflatex. For specific output languages the\n# default can have been set differently, this depends on the implementation of\n# the output language.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_CMD_NAME         =\n\n# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate\n# index for LaTeX.\n# Note: This tag is used in the Makefile / make.bat.\n# See also: LATEX_MAKEINDEX_CMD for the part in the generated output file\n# (.tex).\n# The default file is: makeindex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nMAKEINDEX_CMD_NAME     = makeindex\n\n# The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to\n# generate index for LaTeX. In case there is no backslash (\\) as first character\n# it will be automatically added in the LaTeX code.\n# Note: This tag is used in the generated output file (.tex).\n# See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat.\n# The default value is: makeindex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_MAKEINDEX_CMD    = makeindex\n\n# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nCOMPACT_LATEX          = NO\n\n# The PAPER_TYPE tag can be used to set the paper type that is used by the\n# printer.\n# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x\n# 14 inches) and executive (7.25 x 10.5 inches).\n# The default value is: a4.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPAPER_TYPE             = a4\n\n# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names\n# that should be included in the LaTeX output. The package can be specified just\n# by its name or with the correct syntax as to be used with the LaTeX\n# \\usepackage command. To get the times font for instance you can specify :\n# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}\n# To use the option intlimits with the amsmath package you can specify:\n# EXTRA_PACKAGES=[intlimits]{amsmath}\n# If left blank no extra packages will be included.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nEXTRA_PACKAGES         =\n\n# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the\n# generated LaTeX document. The header should contain everything until the first\n# chapter. If it is left blank doxygen will generate a standard header. See\n# section \"Doxygen usage\" for information on how to let doxygen write the\n# default header to a separate file.\n#\n# Note: Only use a user-defined header if you know what you are doing! The\n# following commands have a special meaning inside the header: $title,\n# $datetime, $date, $doxygenversion, $projectname, $projectnumber,\n# $projectbrief, $projectlogo. Doxygen will replace $title with the empty\n# string, for the replacement values of the other commands the user is referred\n# to HTML_HEADER.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HEADER           =\n\n# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the\n# generated LaTeX document. The footer should contain everything after the last\n# chapter. If it is left blank doxygen will generate a standard footer. See\n# LATEX_HEADER for more information on how to generate a default footer and what\n# special commands can be used inside the footer.\n#\n# Note: Only use a user-defined footer if you know what you are doing!\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_FOOTER           =\n\n# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined\n# LaTeX style sheets that are included after the standard style sheets created\n# by doxygen. Using this option one can overrule certain style aspects. Doxygen\n# will copy the style sheet files to the output directory.\n# Note: The order of the extra style sheet files is of importance (e.g. the last\n# style sheet in the list overrules the setting of the previous ones in the\n# list).\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EXTRA_STYLESHEET =\n\n# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the LATEX_OUTPUT output\n# directory. Note that the files will be copied as-is; there are no commands or\n# markers available.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EXTRA_FILES      =\n\n# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is\n# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will\n# contain links (just like the HTML output) instead of page references. This\n# makes the output suitable for online browsing using a PDF viewer.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPDF_HYPERLINKS         = YES\n\n# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate\n# the PDF file directly from the LaTeX files. Set this option to YES, to get a\n# higher quality PDF documentation.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nUSE_PDFLATEX           = YES\n\n# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode\n# command to the generated LaTeX files. This will instruct LaTeX to keep running\n# if errors occur, instead of asking the user for help. This option is also used\n# when generating formulas in HTML.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BATCHMODE        = NO\n\n# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the\n# index chapters (such as File Index, Compound Index, etc.) in the output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HIDE_INDICES     = NO\n\n# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source\n# code with syntax highlighting in the LaTeX output.\n#\n# Note that which sources are shown also depends on other settings such as\n# SOURCE_BROWSER.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_SOURCE_CODE      = NO\n\n# The LATEX_BIB_STYLE tag can be used to specify the style to use for the\n# bibliography, e.g. plainnat, or ieeetr. See\n# https://en.wikipedia.org/wiki/BibTeX and \\cite for more info.\n# The default value is: plain.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BIB_STYLE        = plain\n\n# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated\n# page will contain the date and time when the page was generated. Setting this\n# to NO can help when comparing the output of multiple runs.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_TIMESTAMP        = NO\n\n# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute)\n# path from which the emoji images will be read. If a relative path is entered,\n# it will be relative to the LATEX_OUTPUT directory. If left blank the\n# LATEX_OUTPUT directory will be used.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EMOJI_DIRECTORY  =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the RTF output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The\n# RTF output is optimized for Word 97 and may not look too pretty with other RTF\n# readers/editors.\n# The default value is: NO.\n\nGENERATE_RTF           = NO\n\n# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: rtf.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_OUTPUT             = rtf\n\n# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nCOMPACT_RTF            = NO\n\n# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will\n# contain hyperlink fields. The RTF file will contain links (just like the HTML\n# output) instead of page references. This makes the output suitable for online\n# browsing using Word or some other Word compatible readers that support those\n# fields.\n#\n# Note: WordPad (write) and others do not support links.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_HYPERLINKS         = NO\n\n# Load stylesheet definitions from file. Syntax is similar to doxygen's\n# configuration file, i.e. a series of assignments. You only have to provide\n# replacements, missing definitions are set to their default value.\n#\n# See also section \"Doxygen usage\" for information on how to generate the\n# default style sheet that doxygen normally uses.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_STYLESHEET_FILE    =\n\n# Set optional variables used in the generation of an RTF document. Syntax is\n# similar to doxygen's configuration file. A template extensions file can be\n# generated using doxygen -e rtf extensionFile.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_EXTENSIONS_FILE    =\n\n# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code\n# with syntax highlighting in the RTF output.\n#\n# Note that which sources are shown also depends on other settings such as\n# SOURCE_BROWSER.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_SOURCE_CODE        = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the man page output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for\n# classes and files.\n# The default value is: NO.\n\nGENERATE_MAN           = NO\n\n# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it. A directory man3 will be created inside the directory specified by\n# MAN_OUTPUT.\n# The default directory is: man.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_OUTPUT             = man\n\n# The MAN_EXTENSION tag determines the extension that is added to the generated\n# man pages. In case the manual section does not start with a number, the number\n# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is\n# optional.\n# The default value is: .3.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_EXTENSION          = .3\n\n# The MAN_SUBDIR tag determines the name of the directory created within\n# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by\n# MAN_EXTENSION with the initial . removed.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_SUBDIR             =\n\n# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it\n# will generate one additional man file for each entity documented in the real\n# man page(s). These additional files only source the real man page, but without\n# them the man command would be unable to find the correct page.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_LINKS              = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the XML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that\n# captures the structure of the code including all documentation.\n# The default value is: NO.\n\nGENERATE_XML           = NO\n\n# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: xml.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_OUTPUT             = xml\n\n# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program\n# listings (including syntax highlighting and cross-referencing information) to\n# the XML output. Note that enabling this will significantly increase the size\n# of the XML output.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_PROGRAMLISTING     = YES\n\n# If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include\n# namespace members in file scope as well, matching the HTML output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_NS_MEMB_FILE_SCOPE = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the DOCBOOK output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files\n# that can be used to generate PDF.\n# The default value is: NO.\n\nGENERATE_DOCBOOK       = NO\n\n# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.\n# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in\n# front of it.\n# The default directory is: docbook.\n# This tag requires that the tag GENERATE_DOCBOOK is set to YES.\n\nDOCBOOK_OUTPUT         = docbook\n\n# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the\n# program listings (including syntax highlighting and cross-referencing\n# information) to the DOCBOOK output. Note that enabling this will significantly\n# increase the size of the DOCBOOK output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_DOCBOOK is set to YES.\n\nDOCBOOK_PROGRAMLISTING = NO\n\n#---------------------------------------------------------------------------\n# Configuration options for the AutoGen Definitions output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an\n# AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures\n# the structure of the code including all documentation. Note that this feature\n# is still experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_AUTOGEN_DEF   = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the Perl module output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module\n# file that captures the structure of the code including all documentation.\n#\n# Note that this feature is still experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_PERLMOD       = NO\n\n# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary\n# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI\n# output from the Perl module output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_LATEX          = NO\n\n# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely\n# formatted so it can be parsed by a human reader. This is useful if you want to\n# understand what is going on. On the other hand, if this tag is set to NO, the\n# size of the Perl module output will be much smaller and Perl will parse it\n# just the same.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_PRETTY         = YES\n\n# The names of the make variables in the generated doxyrules.make file are\n# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful\n# so different doxyrules.make files included by the same Makefile don't\n# overwrite each other's variables.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_MAKEVAR_PREFIX =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the preprocessor\n#---------------------------------------------------------------------------\n\n# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all\n# C-preprocessor directives found in the sources and include files.\n# The default value is: YES.\n\nENABLE_PREPROCESSING   = YES\n\n# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names\n# in the source code. If set to NO, only conditional compilation will be\n# performed. Macro expansion can be done in a controlled way by setting\n# EXPAND_ONLY_PREDEF to YES.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nMACRO_EXPANSION        = NO\n\n# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then\n# the macro expansion is limited to the macros specified with the PREDEFINED and\n# EXPAND_AS_DEFINED tags.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_ONLY_PREDEF     = NO\n\n# If the SEARCH_INCLUDES tag is set to YES, the include files in the\n# INCLUDE_PATH will be searched if a #include is found.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSEARCH_INCLUDES        = YES\n\n# The INCLUDE_PATH tag can be used to specify one or more directories that\n# contain include files that are not input files but should be processed by the\n# preprocessor.\n# This tag requires that the tag SEARCH_INCLUDES is set to YES.\n\nINCLUDE_PATH           =\n\n# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard\n# patterns (like *.h and *.hpp) to filter out the header-files in the\n# directories. If left blank, the patterns specified with FILE_PATTERNS will be\n# used.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nINCLUDE_FILE_PATTERNS  =\n\n# The PREDEFINED tag can be used to specify one or more macro names that are\n# defined before the preprocessor is started (similar to the -D option of e.g.\n# gcc). The argument of the tag is a list of macros of the form: name or\n# name=definition (no spaces). If the definition and the \"=\" are omitted, \"=1\"\n# is assumed. To prevent a macro definition from being undefined via #undef or\n# recursively expanded use the := operator instead of the = operator.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nPREDEFINED             =\n\n# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this\n# tag can be used to specify a list of macro names that should be expanded. The\n# macro definition that is found in the sources will be used. Use the PREDEFINED\n# tag if you want to use a different macro definition that overrules the\n# definition found in the source code.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_AS_DEFINED      =\n\n# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will\n# remove all references to function-like macros that are alone on a line, have\n# an all uppercase name, and do not end with a semicolon. Such function macros\n# are typically used for boiler-plate code, and will confuse the parser if not\n# removed.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSKIP_FUNCTION_MACROS   = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to external references\n#---------------------------------------------------------------------------\n\n# The TAGFILES tag can be used to specify one or more tag files. For each tag\n# file the location of the external documentation should be added. The format of\n# a tag file without this location is as follows:\n# TAGFILES = file1 file2 ...\n# Adding location for the tag files is done as follows:\n# TAGFILES = file1=loc1 \"file2 = loc2\" ...\n# where loc1 and loc2 can be relative or absolute paths or URLs. See the\n# section \"Linking to external documentation\" for more information about the use\n# of tag files.\n# Note: Each tag file must have a unique name (where the name does NOT include\n# the path). If a tag file is not located in the directory in which doxygen is\n# run, you must also specify the path to the tagfile here.\n\nTAGFILES               =\n\n# When a file name is specified after GENERATE_TAGFILE, doxygen will create a\n# tag file that is based on the input files it reads. See section \"Linking to\n# external documentation\" for more information about the usage of tag files.\n\nGENERATE_TAGFILE       =\n\n# If the ALLEXTERNALS tag is set to YES, all external class will be listed in\n# the class index. If set to NO, only the inherited external classes will be\n# listed.\n# The default value is: NO.\n\nALLEXTERNALS           = NO\n\n# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed\n# in the modules index. If set to NO, only the current project's groups will be\n# listed.\n# The default value is: YES.\n\nEXTERNAL_GROUPS        = YES\n\n# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in\n# the related pages index. If set to NO, only the current project's pages will\n# be listed.\n# The default value is: YES.\n\nEXTERNAL_PAGES         = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to the dot tool\n#---------------------------------------------------------------------------\n\n# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram\n# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to\n# NO turns the diagrams off. Note that this option also works with HAVE_DOT\n# disabled, but it is recommended to install and use dot, since it yields more\n# powerful graphs.\n# The default value is: YES.\n\nCLASS_DIAGRAMS         = YES\n\n# You can include diagrams made with dia in doxygen documentation. Doxygen will\n# then run dia to produce the diagram and insert it in the documentation. The\n# DIA_PATH tag allows you to specify the directory where the dia binary resides.\n# If left empty dia is assumed to be found in the default search path.\n\nDIA_PATH               =\n\n# If set to YES the inheritance and collaboration graphs will hide inheritance\n# and usage relations if the target is undocumented or is not a class.\n# The default value is: YES.\n\nHIDE_UNDOC_RELATIONS   = YES\n\n# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is\n# available from the path. This tool is part of Graphviz (see:\n# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent\n# Bell Labs. The other options in this section have no effect if this option is\n# set to NO\n# The default value is: NO.\n\nHAVE_DOT               = NO\n\n# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed\n# to run in parallel. When set to 0 doxygen will base this on the number of\n# processors available in the system. You can set it explicitly to a value\n# larger than 0 to get control over the balance between CPU load and processing\n# speed.\n# Minimum value: 0, maximum value: 32, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_NUM_THREADS        = 0\n\n# When you want a differently looking font in the dot files that doxygen\n# generates you can specify the font name using DOT_FONTNAME. You need to make\n# sure dot is able to find the font, which can be done by putting it in a\n# standard location or by setting the DOTFONTPATH environment variable or by\n# setting DOT_FONTPATH to the directory containing the font.\n# The default value is: Helvetica.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTNAME           = Helvetica\n\n# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of\n# dot graphs.\n# Minimum value: 4, maximum value: 24, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTSIZE           = 10\n\n# By default doxygen will tell dot to use the default font as specified with\n# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set\n# the path where dot can find it using this tag.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTPATH           =\n\n# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for\n# each documented class showing the direct and indirect inheritance relations.\n# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCLASS_GRAPH            = YES\n\n# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a\n# graph for each documented class showing the direct and indirect implementation\n# dependencies (inheritance, containment, and class references variables) of the\n# class with other documented classes.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCOLLABORATION_GRAPH    = YES\n\n# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for\n# groups, showing the direct groups dependencies.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGROUP_GRAPHS           = YES\n\n# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and\n# collaboration diagrams in a style similar to the OMG's Unified Modeling\n# Language.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LOOK               = NO\n\n# If the UML_LOOK tag is enabled, the fields and methods are shown inside the\n# class node. If there are many fields or methods and many nodes the graph may\n# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the\n# number of items for each type to make the size more manageable. Set this to 0\n# for no limit. Note that the threshold may be exceeded by 50% before the limit\n# is enforced. So when you set the threshold to 10, up to 15 fields may appear,\n# but if the number exceeds 15, the total amount of fields shown is limited to\n# 10.\n# Minimum value: 0, maximum value: 100, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LIMIT_NUM_FIELDS   = 10\n\n# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and\n# collaboration graphs will show the relations between templates and their\n# instances.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nTEMPLATE_RELATIONS     = NO\n\n# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to\n# YES then doxygen will generate a graph for each documented file showing the\n# direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDE_GRAPH          = YES\n\n# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are\n# set to YES then doxygen will generate a graph for each documented file showing\n# the direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDED_BY_GRAPH      = YES\n\n# If the CALL_GRAPH tag is set to YES then doxygen will generate a call\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable call graphs for selected\n# functions only using the \\callgraph command. Disabling a call graph can be\n# accomplished by means of the command \\hidecallgraph.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALL_GRAPH             = NO\n\n# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable caller graphs for selected\n# functions only using the \\callergraph command. Disabling a caller graph can be\n# accomplished by means of the command \\hidecallergraph.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALLER_GRAPH           = NO\n\n# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical\n# hierarchy of all classes instead of a textual one.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGRAPHICAL_HIERARCHY    = YES\n\n# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the\n# dependencies a directory has on other directories in a graphical way. The\n# dependency relations are determined by the #include relations between the\n# files in the directories.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDIRECTORY_GRAPH        = YES\n\n# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images\n# generated by dot. For an explanation of the image formats see the section\n# output formats in the documentation of the dot tool (Graphviz (see:\n# http://www.graphviz.org/)).\n# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order\n# to make the SVG files visible in IE 9+ (other browsers do not have this\n# requirement).\n# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo,\n# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and\n# png:gdiplus:gdiplus.\n# The default value is: png.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_IMAGE_FORMAT       = png\n\n# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to\n# enable generation of interactive SVG images that allow zooming and panning.\n#\n# Note that this requires a modern browser other than Internet Explorer. Tested\n# and working are Firefox, Chrome, Safari, and Opera.\n# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make\n# the SVG files visible. Older versions of IE do not have SVG support.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINTERACTIVE_SVG        = NO\n\n# The DOT_PATH tag can be used to specify the path where the dot tool can be\n# found. If left blank, it is assumed the dot tool can be found in the path.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_PATH               =\n\n# The DOTFILE_DIRS tag can be used to specify one or more directories that\n# contain dot files that are included in the documentation (see the \\dotfile\n# command).\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOTFILE_DIRS           =\n\n# The MSCFILE_DIRS tag can be used to specify one or more directories that\n# contain msc files that are included in the documentation (see the \\mscfile\n# command).\n\nMSCFILE_DIRS           =\n\n# The DIAFILE_DIRS tag can be used to specify one or more directories that\n# contain dia files that are included in the documentation (see the \\diafile\n# command).\n\nDIAFILE_DIRS           =\n\n# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the\n# path where java can find the plantuml.jar file. If left blank, it is assumed\n# PlantUML is not used or called during a preprocessing step. Doxygen will\n# generate a warning when it encounters a \\startuml command in this case and\n# will not generate output for the diagram.\n\nPLANTUML_JAR_PATH      =\n\n# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a\n# configuration file for plantuml.\n\nPLANTUML_CFG_FILE      =\n\n# When using plantuml, the specified paths are searched for files specified by\n# the !include statement in a plantuml block.\n\nPLANTUML_INCLUDE_PATH  =\n\n# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes\n# that will be shown in the graph. If the number of nodes in a graph becomes\n# larger than this value, doxygen will truncate the graph, which is visualized\n# by representing a node as a red box. Note that doxygen if the number of direct\n# children of the root node in a graph is already larger than\n# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that\n# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.\n# Minimum value: 0, maximum value: 10000, default value: 50.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_GRAPH_MAX_NODES    = 50\n\n# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs\n# generated by dot. A depth value of 3 means that only nodes reachable from the\n# root by following a path via at most 3 edges will be shown. Nodes that lay\n# further from the root node will be omitted. Note that setting this option to 1\n# or 2 may greatly reduce the computation time needed for large code bases. Also\n# note that the size of a graph can be further restricted by\n# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.\n# Minimum value: 0, maximum value: 1000, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nMAX_DOT_GRAPH_DEPTH    = 0\n\n# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent\n# background. This is disabled by default, because dot on Windows does not seem\n# to support this out of the box.\n#\n# Warning: Depending on the platform used, enabling this option may lead to\n# badly anti-aliased labels on the edges of a graph (i.e. they become hard to\n# read).\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_TRANSPARENT        = NO\n\n# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output\n# files in one run (i.e. multiple -o and -T options on the command line). This\n# makes dot run faster, but since only newer versions of dot (>1.8.10) support\n# this, this feature is disabled by default.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_MULTI_TARGETS      = NO\n\n# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page\n# explaining the meaning of the various boxes and arrows in the dot generated\n# graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGENERATE_LEGEND        = YES\n\n# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot\n# files that are used to generate the various graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_CLEANUP            = YES\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>."
  },
  {
    "path": "README.md",
    "content": "# Ethereal\n\n[![Build Status](https://api.cirrus-ci.com/github/Electrux/Ethereal.svg?branch=master)](https://cirrus-ci.com/github/Electrux/Ethereal)\n\nA simple, dynamically typed, interpreted, generic programming language.\n\n# Some Sample Programs\n\n## Hello world using Function:\n```go\nfn hello( to ) {\n\tprintln( 'Hello ', to );\n}\n\nhello( 'world' );\n```\n\n## Taking input from the user - with a prompt:\n```go\ndat = scan( 'Please enter some data: ' );\nprintln( 'The data you entered is: ', dat );\n```\n\n## Iterative Factorial of a number:\n```python\nimport std.str; # for to_int()\n\nnum = scan( \"Enter factorial of: \" ).to_int();\nfact = 1;\n\nfor x = num; x >= 2; x -= 1 {\n        fact *= x;\n}\n\nprintln( \"Factorial of \", num, \": \", fact );\n```\n\n# About\n\nVisit the medium article [here](https://medium.com/p/so-i-created-a-programming-language-4d9c11038d22?source=email-852839018f8a--writer.postDistributed&sk=d09aaa9916783522215c1024f3ef86f2), for an overview of my journey with Ethereal :)\n\nThe language syntax is inspired from Python and C. It contains sufficient features to enjoy working with it, but avoids complex features like OOP.\n\nEthereal does use a concept of member functions which are actually nothing but plain functions bound to a particular struct/type. And they allow the use of `self` to use the calling variable inside the function itself.\n\nOne can easily make extensions for the language in the form of language modules or c++ dynamic libraries (if high performance is needed). See the existing modules for more information about it (language modules: `include/ethereal/`, C++ standard modules: `modules/std/`).\n\nDocumentation is under development and will take some time to build, but till then, feel free to go through the [Code Samples](https://github.com/Electrux/Ethereal/blob/master/Samples.md) and hack around with the programs in the `tests` directory.\n\n# Prerequisites\n\n*  GCC/Clang with full C++ 11 support, tested with:\n    *  Ubuntu 14.04 (GCC 4.8.4, GMP 5.1.3, MPFR 3.1.2, MPC 1.0.1)\n    *  Arch Linux (GCC 9.1.0, GMP 6.1.2, MPFR 3.1.2, MPC 1.0.1)\n    *  macOS 10.13.6 (Homebrew LLVM 9.0.0, Homebrew GMP 6.1.2, MPFR 4.0.2, MPC 1.1.0)\n    *  macOS 10.14.6 (Homebrew LLVM 8.0.1, Apple LLVM 10.0.1, Homebrew GMP 6.1.2, MPFR 4.0.2, MPC 1.1.0)\n    *  FreeBSD 10.4 (clang 3.4.1, GMP 6.1.2, MPFR 3.1.2, MPC 1.0.1)\n    *  Android 9 - Pie (Termux - clang 8.0.0, GMP 6.1.2 manually compiled - see the note below, MPFR 3.1.2, MPC 1.0.1)\n*  GMP library with CXX support (will be almost always built with support for CXX in your official distribution package)\n\nNote that GMP on Termux for android does not come with CXX support, hence it will have to be manually compiled from source with the `--enable-cxx` configure option. You may also need to specify the `PREFIX_DIR` directory using `--prefix` configure option which, for me, is `/data/data/com.termux/files/usr`\n\nThe entire command sequence for installing GMP on android (for me) is: `./configure --prefix /data/data/com.termux/files/usr --enable-cxx && make -j8 && make install`\n\nAlso, compiling with Link Time Optimization won't work on clang < 3.9, so disable LTO by setting `SKIP_LTO=true` before executing the `bootstrap.sh` script\n\n# Installation\n\nOnce the prerequisites are met, just execute the cmake script by doing `mkdir build && cd build && cmake .. && make -j<cpu core count>` commands. They will build the language interpreter along with the stdlib modules. Installation (using `make install`) should be done **ONLY** if the `PREFIX_DIR` variable is set to a directory other than the cmake `build/` directory.\n\nNote that if you use `PREFIX_DIR`, you may need root access depending on the directory you choose.\n\nThe following items will be installed:\n\n*  `buildfiles/et` -> `$PREFIX_DIR/bin/`\n*  `buildfiles/lib*.so` -> `$PREFIX_DIR/lib/ethereal/`\n*  `include/ethereal/*` -> `$PREFIX_DIR/include/ethereal/`\n\nAlso, the interpreter code internally uses `PREFIX_DIR` to locate the `lib` and `include` directories, so you will have to rebuild the codebase if you change `PREFIX_DIR`.\n\nContributions are definitely accepted and greatly appreciated. ❤️\n"
  },
  {
    "path": "Samples.md",
    "content": "# Code Examples\n\n1.  Hello world\n```go\nprintln( 'Hello world' );\n```\n\n2.  Variables\n```go\nvar = 2 + 4 * 6 / 8;\nprintln( var );\n```\n\n3.  Arrays/Lists\n```go\nvar = [ 1, 2, 3, 4 ];\nprintln( var[ 1 ] );\n```\n\n4.  Maps/Dictionaries\n```go\nvar = { 'str', 'test' };\nvar[ 'str' ] = 'test2';\nprintln( var[ 'str' ] );\n```\n\n5.  Functions\n```go\nfn hello( to ) {\n\tprintln( 'Hello ', to );\n}\n\nhello( 'world' );\n```\n\n6.  Conditionals\n```go\nif 1 == 1 {\n\tprint( 'One' );\n} else {\n\tprint( '1 ain\\'t 1' );\n}\n```\n\n7.  Loops (For)\n```go\nnum = int( scan( 'Enter factorial of: ' ) );\nfact = 1;\n\nfor x = num; x >= 2; --x {\n\tfact *= x;\n}\n\nprintln( 'Factorial of ', num, ': ', fact );\n```\n\n8.  Loops (Foreach)\n```go\nimport std.vec;\n\na = [ 1, 2, 3 ];\nfor x in a.iter() {\n\tprintln( x );\n}\n```\n\n9.  Structures & Objects\n```go\nstruct C {\n\ta = 10;\n\tb = 20;\n}\n\nfn mult_by( c, x ) { return c.a * c.b * x; }\n\nc = C{};\nprint( mult_by( c, 5 ) );\n```\n\n10.  Structure Member functions\n```go\n# first argument is implicitly the calling variable itself: used as 'self'\nmfn< str > print() {\n\tprintln( self );\n}\n\nstr = 'string';\nstr.print();\n```\n"
  },
  {
    "path": "book/book.toml",
    "content": "[book]\nauthors = [\"Electrux\"]\nlanguage = \"en\"\nmultilingual = false\nsrc = \"src\"\ntitle = \"Ethereal Lang\"\n"
  },
  {
    "path": "book/src/00-intro.md",
    "content": "# Introduction\n\nWelcome to the Ethereal Language's User Manual. In this manual, you will be able to understand the usage\nof the language and you will be provided with ample examples for the same.\n\nEthereal is an interpreted, procedural, general purpose programming language which is fundamentally developed\nto write scripts in a very simple and efficient manner. It is most suitable for this use case because of ease of use and simplicity.\nOriginally it was just a hobby, fun project, but honestly, this guide wouldn't exist if this was *just another side project*.\n\nBy design, Ethereal is a relatively small language. This is not a shortcoming though.\nIt is meant to be small since its main purpose is in scripting which usually does not require a huge set of complex features\nand hence, it's a rather minimal language, focusing primarily on providing decent performance with ease of use.\n\nThis book is made to guide people who want to understand Ethereal and perhaps use it in their daily life.\nThe book shall be the holy grail for this language as it is meant to go over every feature of the language.\n\nNote that this guide will not dive deep in the technical details of the language unless required instead,\nfocusing on the usage of the language by the user.\n\nThis guide also intends to go over the standard library of the language with some examples to help understand better and quicker.\n\nAnyway, without further ado, let's go to the installation of the language, and start using it!"
  },
  {
    "path": "book/src/01-install.md",
    "content": "# Installation\n\nFirst of all, to install Ethereal, your system must meet the prerequisites mentioned in the **README** file [here](https://github.com/Electrux/Ethereal/blob/master/README.md).\nThe installation steps are given in that script as well, but this chapter will describe it to a bit more extent. Feel free to skip this if you are satisfied with the **README**'s installation procedure.\n\nFor installing the language, first clone the official GitHub repository: [Electrux/Ethereal](https://github.com/Electrux/Ethereal).\n```bash\ngit clone https://github.com/Electrux/Ethereal\n```\n\nThen, `cd` into the directory, create a `build` directory, cd into that, run `cmake ..`, and finally run `make install`.\nThat will build the language interpreter and you will be pretty much ready to go.\n```bash\ncd Ethereal && mkdir build && cd build && cmake .. && make install\n```\n\nNote that you can also specify number of CPU cores using `make -j<number of cores>`. This will greatly improve the build time\nof the project. For example, `cmake .. && make -j8 install`\n\nThis will generate the Ethereal libraries and binaries which can be used to execute Ethereal code. The binary which we will use is called `et` and it should be generated in `build/bin/` directory of the repository (assuming no `PREFIX_DIR` is set).\n\nYou can also install `ccache` to speed up the build process. CMake will autodetect and use it if it finds it.\n\nThe cmake script uses multiple environment variables which can be set for customizing and optimizing the build process. They are described below.\n\n## CMake Environment Variables\n### $CXX\nThis variable is used for specifying the C++ compiler if you do not want to use the ones auto decided by the script which uses `g++` by default for all operating systems except Android and BSD, for which it uses `clang++`.\n\nFor example, to explicitly use `clang++` compiler on an ubuntu (linux) machine, you can use:\n```bash\nCXX=clang++ cmake .. && make install\n```\n\n### $PREFIX_DIR\nThis variable will allow you to set a `PREFIX_DIR` directory for installation of the language after the build.\n\n**NOTE** that once the script is run with a `PREFIX_DIR`, manually moving the generated files to desired directories will not work since the Ethereal's codebase uses this `PREFIX_DIR` internally itself.\n\nGenerally, the `/usr` or `/usr/local` directories are used for setting the `PREFIX_DIR`, however that is totally up to you. Default value for this is the directory `build/` inside the source code folder.\n\nThe script will create these directories with respect to `PREFIX_DIR`:\n*  `buildfiles/et` -> `$PREFIX_DIR/bin/`\n*  `buildfiles/lib*.so` -> `$PREFIX_DIR/lib/ethereal/`\n*  `include/ethereal/*` -> `$PREFIX_DIR/include/ethereal/`\n\nAn example usage is:\n```bash\nPREFIX_DIR=/usr/local cmake .. && make install\n```\n\n### $DEBUG\nThis variable, if set, will disable all compiler optimizations and will cause the interpreter to start displaying its internal execution stack values while running any program. This will be helpful for debugging the language codebase, but otherwise, do **NOT** use it as it will greatly slow the execution proces down.\n\nIt can be used as follows:\n```bash\nDEBUG=true cmake .. && make install\n```"
  },
  {
    "path": "book/src/02-hello-world.md",
    "content": "# Hello World!\n\nA simple **hello world** program in Ethereal can be written as:\n```go\nprintln('hello, world');\n```\n\nSave the code in a file named, say `hello.et`, and run it using the `et` binary which we built in the [installation](./01-install.md) document.\nAssuming that no `PREFIX` was set, the binary would be created in the `build/bin/` directory of the cloned repostory. Hence, the command would be:\n```bash\n./build/bin/et hello.et\n```\n\nThis will output `hello world` on the display.\n\nCongratulations! You have successfully written your first program in Ethereal!\n\n# Additional Notes\nThe `println` function adds a new line at the end of each call, so we did not have to write a new line character (`\\n`).\nBut if we want to explicitly write new line characters wherever required without the function doing that internally, we can use the `print` function for that.\n\nFor example, if we want to display multiple statements, using `print`:\n```go\nprint('first line');\nprint('second line');\n```\n\nThe output would be:\n```\nfirst linesecond line\n```\n\nTo correct this, we will add a new line at the end of the first `print` call.\n```go\nprint('first line\\n');\nprint('second line');\n```\n\nwhich then gives us the correct output:\n```\nfirst line\nsecond line\n```\n\nOne more important thing to add here is that `print` and `println` can take any number of arguments (but at least one for `print`) by separating each\nargument with a comma (,). So, something like this is possible:\n```go\nprintln('Hello, ', 'world');\n```\n\n## Conclusion\nThe `print` function is different from `println` in that it will not automatically add new line character at the end. Also, the `print` function requires at least one argument, whereas the `println` function requires no argument - in which case, it will simply enter a new line. For all other intents and purposes, the `print` and `println` functions are identical.\n\nNext, we are going to dive deeper in the language and understand the variable system of it."
  },
  {
    "path": "book/src/03-vars.md",
    "content": "# Variables\n\n## What are Variables\nVariables are pretty much aliases that the programmers make for using memory to allocate some data.\nObviously, we do not want, for our sanity's sake, to use memory addresses directly for accessing our data.\nThat is really complicated, hard to remember, and absolutely a nightmare to maintain.\nSo, we instead assign these memory locations, containing our data, to names which we can use in our programs as needed.\n\nClearly, variables are a crucial part of a programming language, and hence, Ethereal has it as well.\n\nCreating a variable is really easy. For example, if we want an integer data, say `20`, to be stored in memory (and be accessible later),\nwe can create a variable for that, say `a`, and use that when required. To do this, the variable can be created directly as:\n```go\na = 20;\n```\n\nSince Ethereal is a dynamically typed language, we need not mention the data type, of the value that we want to store, manually.\nWe can then use it later on, say in `println`, to print the value of this variable. To do that, we can do the following:\n```go\nprintln(a);\n```\n\nThe will produce the output:\n```go\n20\n```\n\n## Variable Reassignment\nWe can also reassign the variables to different values later on. However, we need to remember that the `data type` of that variable cannot be changed throughout its lifetime. So, for example, if we create a variable `a` with value `20`, we can change it later to, say `40`, but we cannot change it to `'hi'`.\nIf we do something like that, the interpreter will throw an error.\n\nFor example, if we write this program:\n```go\na = 20;\na = 'hi';\n```\nand execute it, the interpreter will throw the following error:\n```\ntmp.et 2[3]: error: variable 'a' already declared at previous location, but with different data type (original: int, new: str)\na = 'hi';\n  ^\ntmp.et 1[3]: error: original declared here\na = 20;\n  ^\n```\n\nThe interpreter also tells the reason for this error: original data type was `int` but when we assigned `hi`, that would mean changing the type to `str`.\nWe will understand more about these types in the next chapter - [Data Types](./04-data-types.md).\n\n## Variable Scopes\nThe scope of a variable basically defines its lifetime - when it is created to when it is destroyed.\nEthereal, like many other languages, uses braces to define chunks, or **blocks**, of code.\nAny variable that is created, has its lifetime bound to this block. It will not be accessible outside this block.\n\nFor example:\n```go\na = 20;\n```\nis globally scoped - it is not inside any set of braces, which means that it can be globally used anywhere and once created,\nit will not be destroyed until the end of the program (it will be available exactly from the location where it is created).\n\nOn the other hand, if we declare the same variable as:\n```go\n{\n\ta = 20;\n}\n```\nit will be accessible inside the set of braces (albeit after the creation - declaration of the variable), but not outside them.\n\nSo, if we use the variable outside this set of braces (scope), say as follows:\n```go\n{\n\ta = 20;\n}\nprintln(a);\n```\nwe will be greeted with the following error:\n```\ntmp.et 4[9]: error: variable 'a' does not exist\nprintln(a);\n        ^\n```\n\nOf course, if we create another variable named `a` with some data outside the scope, that would work just fine. So something like this works:\n```go\n{\n\ta = 20;\n}\na = 'hi';\nprintln(a);\n```\nwhich will produce the following output:\n```\nhi\n```\n\nNote that we can choose a different data type even when the variable name is same.\nThe reason being that even though having same names, both of the declared variables are actually totally different.\nThe first one, having data `20`, no longer exists after the scope, therefore, the second one, having data `hi`,\nis a new variable declaration rather than reassignment.\n\n## Variable Naming\nOne last important thing about variables is their naming. Ethereal defines specific rules based on which you can name variables,\nquite similar to most other languages. These rules are that variable names:\n1. Must begin with an alphabet (irrelevant of the case) or underscore\n2. Can contain numbers anywhere except the first character\n3. Cannot contain any symbol other than alphabets, numbers, and underscores.\n\nWell, that is basically how variables, their reassignment, and their scopes, work. Not much to learn or understand and pretty easy - which is the goal!\n\nNext up, we'll understand the concept of `data types` and see some of the fundamental data types in Ethereal."
  },
  {
    "path": "book/src/04-data-types.md",
    "content": "# Data Types\n\nThe data we use and store always has some type. The computer does not really need it, but we do because we don't want to work in binary.\nData types are abstractions over binary sequences which define what kind of data will a variable using a said data type will contain,\nand how will that data be represented in memory.\n\nIf you have prior experience in programming, you may know very well about this. Data types are ubiquitous across programming and are virtually essential\nfor writing software.\nSome common data types are:\n```\nchar (character)\nint (integer)\nfloat (floating point)\nbool (boolean)\nstring\n```\n\nIn Ethereal, the `char` data type does not exist as even a single character, in Ethereal, is a string.\nTherefore, all these data types except `char` are the fundamental types in Ethereal.\n\nHowever, Ethereal is a `dynamically typed` language. This means that when we create variables, we do not provide types for the variable.\nInstead, these are deduced by the interpreter at run time based on the value that we provide to the variable. There are some pros and cons\nto this method. The biggest pro being that writing code is quicker, while the biggest con is that the code may be difficult to understand\nat a glance.\n\nFor example, if we write something like:\n```go\ns = 'hi';\ni = 5;\n```\nThen, `s` is a variable which is deduced by the interpreter to be of type `string` because the expression `hi` is a string,\nwhereas `i` is a variable that is deduced by the interpreter to be of type `int` because `5` is an integer.\n\nThere are also complex data types in Ethereal which are created by grouping of fundamental types.\nWe will understand that in later chapters.\n\nFor now, let's understand a bit in-depth about the fundamental data types in Ethereal.\n\n## Fundamental Types\n\nThese data types are always available for the programmer and are easily deduced by the interpreter based on values.\nWithout these types, a lot of things would not be possible in Ethereal. For example, if the `int` type was absent,\nyou would not be able to write any code requiring calculations. Booleans are exceptions to this as you can imitate\nthe booleans using integers (say, integer `1` for `true`, integer `0` for `false`).\n\nThere are some important things to understand about these data types, so let's do that first.\n\n### Integers\n\nIntegers represent all the negative and positive numbers in Ethereal - all the numbers without decimal that is.\nTheoretically, it can contain any number in the range: `(-∞,∞)`.\n\nNote that unlike many (especially compiled) languages, numbers are not limited to 32, 64, or even 128 bit.\nSo yes, you can have as big a number as you like, so long as it fits your system's memory.\n\nFor example,\n```go\nnum = 13721736912389172367234538762354786253478652374587235648923749872394623864;\nnegative = -12378126387512836512678358761253871625365412578631263816287357125387123123768162;\n```\nare both valid integer variables.\n\n### Floats\n\nFloating point numbers are the decimal numbers - any number which is an imperfect fraction.\nThese are useful when precise mathematical calculations are required, as integers won't provide decimal precision.\nAs with integers, floating point values can also be arbitrarily long with a very high precision.\nFor example,\n```go\nflt = 13721736912389172367234538.762354786253478652374587235648923749872394623864;\nnegative = -123781263875128365.12678358761253871625365412578631263816287357125387123123768162;\n```\n\nDo note that to classify a number as floating point, the use of decimal point (.) to signify decimal is a **must**,\neven if the number does not actually have anything after the decimal point (.), in which case,\nwe can simply have a `zero (0)` after that.\nFor example,\n```go\nflt = 12.0;\n```\n\n### Bools\n\nBooleans are the `true` and `false` values in Ethereal. These are used when you want to know something in a yes or no fashion.\nThe `true` and `false` are special (constant) variables in Ethereal which signify their respective boolean values.\nThese two special variables cannot be reassigned and are always available globally throughout the program's life.\n\nFor example,\n```go\nt = true;\nf = false;\n```\n\n### Strings\n\nStrings are, essentially, sequences of characters that are, well, just that! From a single character on your keyboard,\nto even entire articles written by you, can be considered and contained in strings. These strings, in Ethereal, are often referred\nto as constant strings (const strings) when they are hardcoded in your code. Strings are also how input is received in Ethereal,\nwhich will be covered in the next chapter of the book. There are 3 ways to write constant strings in Ethereal:\n\n1. Enclosing in between single quotes ('\\<some string\\>')\n2. Enclosing in between double quotes (\"\\<some string\\>\")\n3. Enclosing in between back ticks (\\`\\<some string\\>\\`)\n\nThe single and double quote techniques are identical but the back tick technique is unique in that it allows multiple line strings.\nFor example,\n```go\ns1 = 'string in single quotes';\ns2 = \"string in single quotes\";\ns3 = `string in between\nback ticks`;\n```\n\nAn important thing to consider is that Ethereal does interpret some escape sequences. They are:\n```\n\\a - Alert bell\n\\b - Backspace\n\\f - Formfeed page break\n\\n - New line\n\\r - Carriage return\n\\t - Tab (horizontal)\n\\v - Tab (vertical)\n\\\\ - Simple backslash\n\\\" - Simple double quote\n\\' - Simple single quote\n```\nWe saw these being used in our hello world program for printing new line with the `print` function.\n\nThe single and double quote constant strings, although identical, do exist for a reason - if we enclose a string inside double quotes,\nwe can use single quotes inside them freely and vice versa. If, say, only single quoted constant strings existed, we would have to\ncontinually escape the single quotes inside it to avoid them being considered end of string quotes.\nFor example:\n```python\n# here, 'this' will be shown in quotes\nprintln('this is a string and \\'this\\' is literally quoted');\n# if we use double quotes, we don't have to use escape sequences\nprintln(\"this is a string and 'this' is literally quoted\");\n# same thing as above, but quotes are swapped\nprintln('this is a string and \"this\" is literally quoted');\n```\nAs we can see, it can be quite useful to have this style. Also, if we want to use both types of quotes as literals, we could enclose them inside\nthe back ticks:\n```go\nprintln(`this is 'a' quoted \"string\"`);\n```\n\n# Conclusion\n\nThat should be more than sufficient information about strings at this point. We will learn as we go.\nFor now, it's time for the next chapter in which we will learn about taking input from the user!"
  },
  {
    "path": "book/src/05-input.md",
    "content": "# Input\n\nWe are making programs for the user and unless we are interested in writing scripts for absolute and utter automation,\nwe will have to take some sort of input from the user. And for this, we have one core function for taking user input.\n\n## scan Function\n\nEthereal has a core function `scan()` which allows the programmer to take user input. It can optionally take in a prompt string\nand returns the input entered by the user as a string. The programmer has complete control to do whatever they want with this input string.\n\nFor example,\n```python\n# taking simple input in a variable\nvar1 = scan();\n# taking input after a prompt\nvar2 = scan('Enter some data: ');\n```\nIn the second case, the user will first be greeted by `Enter some data: ` and they can provide input after that.\nSimilar to the output from `print` function, this prompt will not append a newline character at the end automatically.\nIf we want a newline character at the end, we will have to manually add that like so:\n```python\nvar = scan('Enter some data in next line:\\n');\n```\n\nLet's understand this better using a very simple program extending our `Hello world` program.\n\nThis time, we want to ask the user their name, and we will print `Hello, <their name>`. Basically, we will be doing three things:\n1. Giving prompt and taking input\n2. Storing the input in a variable\n3. Displaying our message\n\nIdeally, you should try to making such a program by yourself first, but for this guide, here is the solution:\n```go\nname = scan('Enter your name: ');\nprintln('Hello, ', name);\n```\nThat's it! Easy right?!\n\nWell, there isn't anything else to learn about input for now. The scan function will most likely be extended later on to perhaps provide\nmore fine grain control over taking input.\n\nThis guide has used the term `function` a lot of times. Next up, it is time to understand what exactly they are and how to work with them\nin Ethereal."
  },
  {
    "path": "book/src/06-functions.md",
    "content": "# Functions\n\n## What are Functions\nIn simple words, functions are groups of statements/instructions that are combined to perform some tasks, and can be used repeatedly. We can say, functions are made to perform a unique and often repetitive function.\n\nWhen we create a function with its group of statements, it is called `function definition`. The group of statements is called\n`function body`. And, when we use the function, it is called function call.\n\nWe may need to provide functions with some additional data, or retrieve some data from it. For that, we use function\narguments and function return values respectively.\n\nNow, let's move on to how these functions are implemented in Ethereal.\n\n## Functions in Ethereal\nEthereal allows functions to be written in two different modes, each with two different styles, totalling four total varities for writing functions.\nThey are:\n1. As C++ functions - Since Ethereal interpreter is written in C++ programming language, its functions can be written in it too, allowing you to bind C++ and Ethereal, essentially, enabling the use of the plethora of C++ libraries.\n2. As Ethereal functions - Ethereal allows you to write functions in the Ethereal language itself, which is what you will be doing for the most part and what this guide will elaborate on.\n\nBoth of these types have 2 styles each - as plain global functions, and as `pseudo member` functions. We will understand this in more detail but let's first grasp the concepts of simple (plain) functions.\n\n### Our First Function!\nIn Ethereal, we define functions using the keyword `fn`. This marks the beginning of a function definition and we then describe the function.\nLet's work on this using our dear old `Hello world` example.\n\nLast time, we were able to ask user to enter their name, store it in a variable, and display our hello message to the user in the `Hello, <user>` format.\nThis time, we will create a function named `hello` to which we will pass the name of the user as an argument and that function will print\nthe hello message for us.\n\nSo, here's the code for that.\n```python\n# function definition\nfn hello( name ) {\n\tprintln('Hello, ', name);\n}\n\n# function call\nname = scan('Enter your name: ');\nhello(name);\n```\nDo note that variable names can be anything you like. The names given here are **not** set in stone.\nBut yes, congratulations on making your first function in Ethereal! Now, to understand what we have written.\n\nSo, as noted before, function definitions start with the keyword `fn`. Then comes the name of the function (here `hello`), then the argument names for\nthe function within parentheses - multiple arguments separated by commas and empty parentheses for no argument, and then we have our function body\nwithin curly braces.\n\nTo use a function, we simply call it by using the function name with parentheses and the actual arguments (our data) within the parentheses.\nAgain, for no arguments, empty parentheses are required."
  },
  {
    "path": "book/src/SUMMARY.md",
    "content": "# Ethereal User Manual\n\n- [Introduction](./00-intro.md)\n- [Installation](./01-install.md)\n- [Hello World!](./02-hello-world.md)\n- [Variables](./03-vars.md)\n- [Data Types](./04-data-types.md)\n- [Input](./05-input.md)\n- [Functions](./06-functions.md)"
  },
  {
    "path": "build.et",
    "content": "#!/usr/bin/env et\n\nimport std.( os, fs, str, term );\nimport cxxproj.cxxproj;\n\n# will set CC variable accordingly\neth = cxx_new_proj();\n\nself_prefix = false;\nprefix = os.get_env( 'PREFIX' );\nif prefix.empty() {\n\tprefix = os.get_env( 'PWD' );\n\tself_prefix = true;\n}\n\neth.add_flags( [ '-fPIC', '-Wall', '-Wextra', '-Wno-unused-parameter',\n\t\t '-DBUILD_PREFIX_DIR='  + prefix, '-Wl,-rpath,' + prefix + '/lib/ethereal/' ] );\n\nif os.get_env( 'CC' ) != 'g++' {\n\teth.add_flags( [ \"-Wno-c99-extensions\", \"-Wno-unused-command-line-argument\" ] );\n}\n\neth.add_lib_dirs( [ '-L./buildfiles' ] );\n\nif args.len() > 1 && args.find( 'debug' ) >= 0 || args.find( 'memlog' ) >= 0 {\n\tif os.exec( 'stat buildfiles 1>/dev/null 2>&1' ) == 0 && os.exec( 'stat buildfiles/.debug_mode 1>/dev/null 2>&1' ) != 0 {\n\t\t#os.exec( 'rm -rf buildfiles && mkdir buildfiles && touch buildfiles/.debug_mode' );\n\t}\n\tif args.find( 'debug' ) >= 0 { eth.add_flags( [ '-DDEBUG_MODE', '-DMEM_LOGS' ] ); }\n\telse { eth.add_flags( [ '-DMEM_LOGS' ] ); }\n} else {\n\tif os.exec( 'stat buildfiles 1>/dev/null 2>&1' ) == 0 && os.exec( 'stat buildfiles/.debug_mode 1>/dev/null 2>&1' ) == 0 {\n\t\t#os.exec( 'rm -rf buildfiles' );\n\t}\n\teth.add_flags( [ '-march=native', '-O2', '-flto' ] );\n}\n\nif !eth.use_lib( 'libdl' ) {\n\tprintln( 'libdl (required) was not found, quitting' );\n\texit( 1 );\n}\n\nif !eth.use_lib( 'gmpxx' ) {\n\tprintln( 'libgmpxx (required) was not found, quitting' );\n\texit( 1 );\n}\n\nsrcs = fs.dir_entries( 'src', fs.ent.RECURSE );\n\neth.add_build( 'et', 'dynamic' ).add_files( srcs, '' );\n\nprintln( eth );\n\nif args.len() > 1 && args.find( 'install' ) >= 0 || self_prefix == true {\n\tif os.get_env( 'EUID' ).empty() || os.name == 'osx' {\n\t\t#os.install( 'buildfiles/et', os.get_env( 'PREFIX' ) + '/bin/' );\n\t} else {\n\t\tcprintln( '{r}Run as root to install the built files{0}' );\n\t}\n}"
  },
  {
    "path": "ethereal-vscode/.vscodeignore",
    "content": ".vscode/**\n.vscode-test/**\n.gitignore\nvsc-extension-quickstart.md\n"
  },
  {
    "path": "ethereal-vscode/CHANGELOG.md",
    "content": "# Change Log\n\nAll notable changes to the \"ethereal\" extension will be documented in this file.\n\n## [Initial release]\n\n- Initial release"
  },
  {
    "path": "ethereal-vscode/README.md",
    "content": "# Ethereal Extension - Visual Studio Code\n\nThis extension provides a basic syntax highlighting for the Ethereal language.\n\n## Features\n\nCurrently, provides syntax highlighting, such as below:\n\n![Syntax Highlighting](images/syntax-highlighting.png)\n\n### 0.0.1\n\nInitial release"
  },
  {
    "path": "include/ethereal/core.et",
    "content": "ldmod pre.core;\n\nfn assert( a ) {\n\tif !( a ) {\n\t\tassert_fail( 'assertion failed for data: ', a );\n\t}\n}\n\nfn assert_msg( a, ... ) {\n\tif !( a ) {\n\t\tassert_fail( __VA__ );\n\t}\n}\n\nfn assert_eq( a, b ) {\n\tif !( a == b ) {\n\t\tassert_fail( 'assertion failed for ', a, ' == ', b );\n\t}\n}\n\nfn assert_ne( a, b ) {\n\tif !( a != b ) {\n\t\tassert_fail( 'assertion failed for ', a, ' != ', b );\n\t}\n}\n\nfn assert_lt( a, b ) {\n\tif !( a < b ) {\n\t\tassert_fail( 'assertion failed for ', a, ' < ', b );\n\t}\n}\n\nfn assert_le( a, b ) {\n\tif !( a <= b ) {\n\t\tassert_fail( 'assertion failed for ', a, ' <= ', b );\n\t}\n}\n\nfn assert_gt( a, b ) {\n\tif !( a > b ) {\n\t\tassert_fail( 'assertion failed for ', a, ' > ', b );\n\t}\n}\n\nfn assert_ge( a, b ) {\n\tif !( a >= b ) {\n\t\tassert_fail( 'assertion failed for ', a, ' >= ', b );\n\t}\n}\n\nfn assert_and( a, b ) {\n\tif !( a && b ) {\n\t\tassert_fail( 'assertion failed for ', a, ' && ', b );\n\t}\n}\n\nfn assert_or( a, b ) {\n\tif !( a || b ) {\n\t\tassert_fail( 'assertion failed for ', a, ' || ', b );\n\t}\n}\n\nfn assert_nt( a ) {\n\tif !( !a ) {\n\t\tassert_fail( 'assertion failed for !', a );\n\t}\n}\n"
  },
  {
    "path": "include/ethereal/cxxproj/cxxbuild.et",
    "content": "import std.vec;\nimport std.regex;\n\nstruct _cxx_build_t {\n\tname = 'tmp';\n\ttype = 'bin';\n\tfiles = [];\n\tflags = [];\n\tinc_dirs = [];\n\tlib_dirs = [];\n\tlib_flags = [];\n}\n\nmfn< _cxx_build_t > add_files( vec, regex ) {\n\t__r__ = re.build( regex );\n\tself.files += __r__.inv_match_in_vec( vec );\n\treturn self;\n}\n\nmfn< _cxx_build_t > rem_files( regex ) {\n\t__r__ = re.build( regex );\n\tself.files = __r__.inv_match_in_vec( self.files );\n\treturn self;\n}"
  },
  {
    "path": "include/ethereal/cxxproj/cxxproj.et",
    "content": "import std.str;\nimport std.vec;\nimport std.fs;\nimport std.os;\n\nimport cxxproj.cxxbuild;\n\nstruct _cxx_proj_t {\n\tflags = [];\n\tinc_dirs = [];\n\tlib_dirs = [];\n\tlib_flags = [];\n\tbuilds = [];\n}\n\nfn cxx_new_proj() {\n\tif os.get_env( 'CC' ).empty() {\n\t\tif os.name == 'linux' {\n\t\t\tos.set_env( 'CC', 'g++' );\n\t\t} else {\n\t\t\tos.set_env( 'CC', 'clang++' );\n\t\t}\n\t}\n\treturn _cxx_proj_t{};\n}\n\nmfn< _cxx_proj_t > add_build( name, type ) {\n\t__b__ = _cxx_build_t{ name, type };\n\tself.builds.push( __b__ );\n\treturn self.builds[ self.builds.len() - 1 ];\n}\n\nmfn< _cxx_proj_t > build() {\n\n}\n\nimport cxxproj.flags;\nimport cxxproj.libs;"
  },
  {
    "path": "include/ethereal/cxxproj/flags.et",
    "content": "fn read_flag_file( file, v ) {\n\t__f__ = fopen( file, 'r' );\n\tif __f__.is_open() {\n\t\t__f__.read_all( v );\n\t}\n}\n\nfn append_flag_file( file, v ) {\n\t__f__ = fopen( file, 'a' );\n\tif __f__.is_open() {\n\t\tfor __e__ in v.iter() {\n\t\t\t__f__.write( __e__ + '\\n' );\n\t\t}\n\t}\n}\n\nfn check_compiler_flag( flag ) {\n\tif flag.len() > 1 && flag[ 1 ] == 'D' { return true; }\n\t__cmd__ = \"g++ -fsyntax-only \" + flag + \" -xc++ /dev/null 2>/dev/null\";\n\t__res__ = os.exec( __cmd__ ) == 0;\n\treturn __res__;\n}\n\nmfn< _cxx_proj_t, _cxx_build_t > add_flags( flags ) {\n\t__avail_flags__ = [];\n\t__not_avail_flags__ = [];\n\tread_flag_file( 'flag_cache', __avail_flags__ );\n\tfor __flag__ in flags.iter() {\n\t\tcprint( '{y}checking if compiler supports {c}', __flag__, ' {0}... ' );\n\t\tflush_out();\n\t\tif __avail_flags__.find( __flag__ ) >= 0 {\n\t\t\tself.flags.push( __flag__ );\n\t\t\tcprintln( '{g}yes (cached){0}' );\n\t\t} elif check_compiler_flag( __flag__ ) {\n\t\t\tself.flags.push( __flag__ );\n\t\t\t__not_avail_flags__.push( __flag__ );\n\t\t\tcprintln( '{g}yes{0}' );\n\t\t} else {\n\t\t\tcprintln( '{r}no{0}' );\n\t\t}\n\t}\n\tappend_flag_file( 'flag_cache', __not_avail_flags__ );\n}\n"
  },
  {
    "path": "include/ethereal/cxxproj/libs.et",
    "content": "import std.map;\n\nmfn< _cxx_proj_t, _cxx_build_t > add_lib_dirs( dirs ) {\n\tself.lib_dirs += dirs;\n}\n\nmfn< _cxx_proj_t, _cxx_build_t > use_lib( lib ) {\n\tcprint( '{y}checking support for library {c}', lib, ' {0}... ' );\n\tflush_out();\n\t__file__ = __SRC_DIR__ + '/tests/' + lib + '.cfg';\n\n\tif !fs.exists( __file__ ) {\n\t\t__file__ = __SRC_DIR__ + '/tests/' + lib + '_cpp.cfg';\n\t\tif !fs.exists( __file__ ) {\n\t\t\tcprintln( '{r}no (library does not exist){0}' );\n\t\t\tprintln( __file__ );\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t__f__ = fopen( __file__, 'r' );\n\t__line__ = \"\";\n\t__map__ = {};\n\tfor ; __f__.read( __line__ ); {\n\t\t__splt__ = __line__.split( '=' );\n\t\t__map__.insert( __splt__[ 0 ].trim(), __splt__[ 1 ].trim() );\n\t}\n\tif !__map__.find( 'file' ) {\n\t\tprintln( 'could not find \\'file\\' declaration in library config: ', __file__ );\n\t\texit( 1 );\n\t}\n\n\t__src__ = __SRC_DIR__ + '/tests/' + __map__[ 'file' ];\n\t__inc_dirs__ = \"\";\n\t__lib_dirs__ = \"\";\n\t__lib_flags__ = \"\";\n\n\t__comp_str__ = os.get_env( 'CC' ) + ' ';\n\tif __map__.find( 'lang' ) {\n\t\t__lang__ = __map__[ 'lang' ];\n\t\tif __lang__ == 'c' {\n\t\t\tif os.get_env( 'CC' ) == 'clang++' {\n\t\t\t\t__comp_str__ = 'clang ';\n\t\t\t} else {\n\t\t\t\t__comp_str__ = 'gcc ';\n\t\t\t}\n\t\t}\n\t}\n\n\tif __map__.find( 'inc_dirs' ) {\n\t\t__inc_dirs__ = __map__[ 'inc_dirs' ];\n\t}\n\tif __map__.find( 'lib_dirs' ) {\n\t\t__lib_dirs__ = __map__[ 'lib_dirs' ];\n\t}\n\tif __map__.find( 'lib_flags' ) {\n\t\t__lib_flags__ = __map__[ 'lib_flags' ];\n\t}\n\t__comp_str__ += __src__ + ' ' + __inc_dirs__ + ' ' + __lib_dirs__ + ' ' + __lib_flags__ + ' -o /dev/null 2>/dev/null';\n\n\tif os.exec( __comp_str__ ) != 0 {\n\t\tcprintln( '{r}no{0}' );\n\t\treturn false;\n\t}\n\tif !__inc_dirs__.empty() { self.inc_dirs.push( __inc_dirs__ ); }\n\tif !__lib_dirs__.empty() { self.lib_dirs.push( __lib_dirs__ ); }\n\tif !__lib_flags__.empty() { self.lib_flags.push( __lib_flags__ ); }\n\tcprintln( '{g}yes{0}' );\n\treturn true;\n}\n"
  },
  {
    "path": "include/ethereal/cxxproj/tests/gmpxx.cfg",
    "content": "lang = cpp\nfile = gmpxx.cpp\nlib_flags = -lgmpxx -lgmp"
  },
  {
    "path": "include/ethereal/cxxproj/tests/gmpxx.cpp",
    "content": "#include <gmpxx.h>\n\nint main()\n{\n\tmpz_class a;\n\treturn 0;\n}\n"
  },
  {
    "path": "include/ethereal/cxxproj/tests/libdl.c",
    "content": "#include <dlfcn.h>\n\nint main() { return 0; }"
  },
  {
    "path": "include/ethereal/cxxproj/tests/libdl.cfg",
    "content": "lang = c\nfile = libdl.c\nlib_flags = -ldl"
  },
  {
    "path": "include/ethereal/eth/vm.et",
    "content": "ldmod eth.vm;\n\nstruct _evm_t {}\n\nevm = _evm_t{};\n"
  },
  {
    "path": "include/ethereal/ini.et",
    "content": "# TODO: add helper functions for working with __ini__, implement ini_write\nimport std.str;\nimport std.vec;\nimport std.map;\nimport std.fs;\n\nfn ini_read( fname ) {\n\t__f__ = fopen( fname, 'r' );\n\tif !__f__.is_open() { return INIRet.FNOP; }\n\t__ini__ = {};\n\t__curr_blk__ = '';\n\t__ini__.insert( '', {} );\n\t__line__ = '';\n\tfor ; __f__.read( __line__ ); {\n\t\t__line__.trim();\n\t\tif __line__.empty() { continue; }\n\t\t# comments\n\t\tif __line__.front() == ';' { continue; }\n\t\t# make block\n\t\tif __line__.front() == '[' && __line__.back() == ']' {\n\t\t\t#__line__.erase_at( 0 );\n\t\t\t#__line__.erase_at( __line__.len() - 1 );\n\t\t\t__line__.pop_front();\n\t\t\t__line__.pop_back();\n\t\t\t__curr_blk__ = __line__;\n\t\t\t__ini__.insert( __curr_blk__, {} );\n\t\t\tcontinue;\n\t\t}\n\t\tif !__line__.find( '=' ) { continue; }\n\t\t# make key value pairs\n\t\t__kvp__ = __line__.split_first( '=' );\n\t\t__kvp__[ 0 ].trim();\n\t\tkey = __kvp__[ 0 ];\n\t\tval = '';\n\t\tif __kvp__.len() > 1 {\n\t\t\tval = __kvp__[ 1 ].trim();\n\t\t}\n\t\t__ini__[ __curr_blk__ ].insert( key, val );\n\t}\n\tif __ini__[ '' ].len() == 0 {\n\t\t__ini__.delete( '' );\n\t}\n\treturn __ini__;\n}"
  },
  {
    "path": "include/ethereal/std/complex.et",
    "content": "ldmod std.complex;\n\nstruct _cplx_t {}\n\ncplx = _cplx_t{};\n"
  },
  {
    "path": "include/ethereal/std/fs.et",
    "content": "ldmod std.fs;\n\nenum_mask _FSEnt {\n\tFILES,\n\tDIRS,\n\tRECURSE,\n}\n\nstruct _fs_t {\n\tent = _FSEnt;\n}\n\nfs = _fs_t{};"
  },
  {
    "path": "include/ethereal/std/map.et",
    "content": "ldmod std.map;\n\nmfn< map > insert( key, val ) {\n\tassert_msg( var_mfn_exists( key, 'hash' ), 'type \\'', key.type(), '\\' does not implement a hash member function' );\n\tself._insert( key.hash(), val );\n\treturn self;\n}\n\nmfn< map > delete( key ) {\n\tassert_msg( var_mfn_exists( key, 'hash' ), 'type \\'', key.type(), '\\' does not implement a hash member function' );\n\treturn self._delete( key.hash() );\n}\n\nmfn< map > '[]'( key ) {\n\tassert_msg( var_mfn_exists( key, 'hash' ), 'type \\'', key.type(), '\\' does not implement a hash member function' );\n\treturn self.get( key.hash() );\n}\n\nmfn< map > find( key ) {\n\tassert_msg( var_mfn_exists( key, 'hash' ), 'type \\'', key.type(), '\\' does not implement a hash member function' );\n\treturn self._find( key.hash() );\n}\n"
  },
  {
    "path": "include/ethereal/std/math.et",
    "content": "ldmod std.math;\n\nstruct _math_t {\n\t# euler's number\n\te =  math_calc_e();\n\tpi = math_calc_pi();\n\t# max times to iterate for precisely calculating a function's result\n\tprecision_iter_max = get_flt_precision() * 2;\n\t# decimal representation for precision\n\tprecision = get_flt_precision_num();\n}\n\nmath = _math_t{};\n\nmfn< _math_t > get_prec() { return get_flt_precision(); }\n\nmfn< _math_t > update_prec( p ) {\n\tset_flt_precision( p );\n\tself = _math_t{ math_calc_e(), math_calc_pi(), get_flt_precision() * 2, get_flt_precision_num() };\n}\n\nmfn< _math_t > to_rad( x ) { return x * self.pi / 180.0; }\nmfn< _math_t > to_deg( x ) { return x * 180.0 / self.pi; }\n"
  },
  {
    "path": "include/ethereal/std/opt.et",
    "content": "ldmod std.opt;"
  },
  {
    "path": "include/ethereal/std/os.et",
    "content": "ldmod std.os;\n\nimport std.str;\nimport std.vec;\nimport std.fs;\n\nstruct _os_t {\n\tname = os_get_name();\n}\n\nmfn< _os_t > find_exec( loc ) {\n\tfor __path__ in os.get_env( 'PATH' ).split( ':' ).iter() {\n\t\tif fs.exists( __path__ + '/' + loc ) {\n\t\t\treturn __path__ + '/' + loc;\n\t\t}\n\t}\n\treturn '';\n}\n\nos = _os_t{};\n"
  },
  {
    "path": "include/ethereal/std/regex.et",
    "content": "ldmod std.regex;\nimport std.vec;\n\nstruct _regex_t {}\n\nre = _regex_t{};\n\nmfn< regex_t > match_in_vec( vec ) {\n\tif self.empty() { return vec; }\n\t__res__ = [];\n\tfor __e__ in vec.iter() {\n\t\tif self.match( __e__ ) { __res__.push( __e__ ); }\n\t}\n\treturn __res__;\n}\n\nmfn< regex_t > inv_match_in_vec( vec ) {\n\tif self.empty() { return vec; }\n\t__res__ = [];\n\tfor __e__ in vec.iter() {\n\t\tif !self.match( __e__ ) { __res__.push( __e__ ); }\n\t}\n\treturn __res__;\n}"
  },
  {
    "path": "include/ethereal/std/runtime.et",
    "content": "ldmod std.runtime;\n\nstruct _runtime_t {}\n\nruntime = _runtime_t{};\n"
  },
  {
    "path": "include/ethereal/std/set.et",
    "content": "ldmod std.set;\n"
  },
  {
    "path": "include/ethereal/std/str.et",
    "content": "ldmod std.str;"
  },
  {
    "path": "include/ethereal/std/term.et",
    "content": "ldmod std.term;\n\nstruct _term_t {}\n\nterm = _term_t{};\n\nstruct _term_size_t {\n\trows = 24;\n\tcols = 80;\n}"
  },
  {
    "path": "include/ethereal/std/threads.et",
    "content": "ldmod std.threads;\n\nstruct _threads_t {\n\tnproc = threads_get_nproc();\n}\n\nthreads = _threads_t{};"
  },
  {
    "path": "include/ethereal/std/time.et",
    "content": "ldmod std.time;\n\nstruct _time_t {}\n\ntime = _time_t{};"
  },
  {
    "path": "include/ethereal/std/tuple.et",
    "content": "ldmod std.tuple;"
  },
  {
    "path": "include/ethereal/std/vec.et",
    "content": "ldmod std.vec;"
  },
  {
    "path": "modules/eth/vm.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../../src/VM/Core.hpp\"\n\n#include \"../../src/FE/CmdArgs.hpp\"\n#include \"../../src/VM/ExecInternal.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////// Class ////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass var_evm_t : public var_base_t\n{\n\tvm_state_t * m_vm;\n\tbool m_copied;\npublic:\n\t// can't use pointer for m_pre_ph because it doesn't get freed correctly\n\t// since it uses reference to m_vm->srcstack.back()\n\tparse_helper_t m_pre_ph;\n\tvar_evm_t( vm_state_t * vm, const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_evm_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tvm_state_t * & get();\n};\n#define AS_EVM( x ) static_cast< var_evm_t * >( x )\n\nvar_evm_t::var_evm_t( vm_state_t * vm, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_vm( vm ),\n\t  m_copied( false ), m_pre_ph( vm->srcstack.back()->toks )\n{}\nvar_evm_t::~var_evm_t()\n{\n\tif( !m_copied ) {\n\t\tm_vm->srclist.clear();\n\t\tm_vm->srcstack.pop_back();\n\t\tdelete m_vm;\n\t}\n}\n\nstd::string var_evm_t::type_str() const { return \"evm_t\"; }\nstd::string var_evm_t::to_str() const\n{\n\tstd::string str = \"evm_t{\";\n\tstr += m_vm->srcstack.back()->file + \"}\";\n\treturn str;\n}\nmpz_class var_evm_t::to_int() const { return m_vm->exit_status; }\nbool var_evm_t::to_bool() const { return m_vm->exit_called; }\nvar_base_t * var_evm_t::copy( const int src_idx, const int parse_ctr )\n{\n\tm_copied = true;\n\treturn new var_evm_t( m_vm, src_idx, parse_ctr );\n}\nvoid var_evm_t::assn( var_base_t * b )\n{\n\tvar_evm_t * tmp = AS_EVM( b );\n\tif( !m_copied ) {\n\t\tdelete tmp->m_vm;\n\t}\n\n\tm_vm = tmp->m_vm;\n\ttmp->m_copied = true;\n\tm_copied = false;\n}\nvm_state_t * & var_evm_t::get() { return m_vm; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * vm_create( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tint err = E_OK;\n\n\tsrc_t * src = new src_t( true );\n\tsrc->ptree = new parse_tree_t;\n\tsrc->dir = vm.srcstack.back()->dir;\n\tsrc->id = 0;\n\tsrc->file = fcd.args.size() > 1 ? fcd.args[ 0 ]->to_str() : \"<repl>\";\n\n\tvm_state_t * v = new vm_state_t();\n\n\tv->flags = vm.flags;\n\tv->srcstack.push_back( src );\n\tv->srclist.push_back( src->file );\n\tv->srcs[ src->id ] = src;\n\n\tvar_base_t * prog = vm.vars->get( \"__PROG__\" );\n\tvar_base_t * ver_major = vm.vars->get( \"__VERSION_MAJOR__\" );\n\tvar_base_t * ver_minor = vm.vars->get( \"__VERSION_MINOR__\" );\n\tvar_base_t * ver_patch = vm.vars->get( \"__VERSION_PATCH__\" );\n\tvar_base_t * args = vm.vars->get( \"args\" );\n\tvar_base_t * tru = vm.vars->get( \"true\" );\n\tvar_base_t * fal = vm.vars->get( \"false\" );\n\n\tVAR_IREF( prog );\n\tVAR_IREF( ver_major );\n\tVAR_IREF( ver_minor );\n\tVAR_IREF( ver_patch );\n\tVAR_IREF( args );\n\tVAR_IREF( tru );\n\tVAR_IREF( fal );\n\n\tv->vars->add( \"__PROG__\", prog );\n\tv->vars->add( \"__VERSION_MAJOR__\", ver_major );\n\tv->vars->add( \"__VERSION_MINOR__\", ver_minor );\n\tv->vars->add( \"__VERSION_PATCH__\", ver_patch );\n\tv->vars->add( \"args\", args );\n\tv->vars->add( \"true\", tru );\n\tv->vars->add( \"false\", fal );\n\n\tif( !set_init_mods( * v ) ) { err = E_VM_FAIL; goto fail; }\n\n\treturn new var_evm_t( v );\nfail:\n\tdelete v;\n\treturn vm.nil;\n}\n\nvar_base_t * vm_is_running( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tvar_evm_t * v = AS_EVM( fcd.args[ 0 ] );\n\treturn TRUE_FALSE( !v->get()->exit_called );\n}\n\nvar_base_t * vm_exec_code( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< std::string > new_code;\n\tstd::vector< var_base_t * > vec = AS_VEC( fcd.args[ 1 ] )->get();\n\tvm_state_t * v = AS_EVM( fcd.args[ 0 ] )->get();\n\tsrc_t * s = v->srcstack.back();\n\tsrc_t src( false );\n\tsrc.file = s->file;\n\tsrc.id = s->id;\n\n\tsize_t code_size = s->code.size();\n\tsize_t toks_size = s->toks.size();\n\tsize_t ptree_size = s->ptree->size();\n\tsize_t bcode_size = s->bcode.size();\n\n\t// add old code and bytecode entries for correct line/bytecode numbers of new ones\n\tfor( size_t i = 0; i < code_size; ++i ) src.code.push_back( \"\" );\n\tfor( size_t i = 0; i < bcode_size; ++i ) src.bcode.push_back( {} );\n\n\t// add the new code\n\tfor( auto & e : vec ) {\n\t\tstd::vector< std::string > tmp = str_delimit( e->to_str(), '\\n' );\n\t\tsrc.code.insert( src.code.end(), tmp.begin(), tmp.end() );\n\t}\n\n\tint err = E_OK;\n\n\terr = tokenize( src );\n\tif( err != E_OK ) return new var_int_t( err );\n\tif( v->flags & OPT_T ) {\n\t\tfprintf( stdout, \"Tokens:\\n\" );\n\t\tauto & toks = src.toks;\n\t\tfor( size_t i = 0; i < toks.size(); ++i ) {\n\t\t\tauto & tok = toks[ i ];\n\t\t\tfprintf( stdout, \"ID: %zu\\tType: %s\\tLine: %d[%d]\\tSymbol: %s\\n\",\n\t\t\t\ti, TokStrs[ tok.type ], tok.line, tok.col, tok.data.c_str() );\n\t\t}\n\t}\n\tsrc.ptree = parse( src );\n\tif( src.ptree == nullptr ) return new var_int_t( E_PARSE_FAIL );\n\n\tif( v->flags & OPT_P ) {\n\t\tfprintf( stdout, \"Parse Tree:\\n\" );\n\t\tfor( auto it = src.ptree->begin(); it != src.ptree->end(); ++it ) {\n\t\t\t( * it )->disp( it != src.ptree->end() - 1 );\n\t\t}\n\t}\n\n\tfor( auto & it : * src.ptree ) {\n\t\tif( !it->bytecode( src ) ) return new var_int_t( E_BYTECODE_FAIL );\n\t}\n\n\tfor( auto & bc : src.bcode ) {\n\t\tbc.parse_ctr += toks_size;\n\t}\n\n\tif( v->flags & OPT_B ) {\n\t\tfprintf( stdout, \"Byte Code:\\n\" );\n\t\tfor( size_t i = 0; i < src.bcode.size(); ++i ) {\n\t\t\tauto & ins = src.bcode[ i ];\n\t\t\tfprintf( stdout, \"%-*zu %-*s%-*s[%s]\\n\",\n\t\t\t\t 5, i, 20, InstrCodeStrs[ ins.opcode ], 7, OperTypeStrs[ ins.oper.type ], ins.oper.val.c_str() );\n\t\t}\n\t}\n\n\ts->code.insert( s->code.end(), src.code.begin() + code_size, src.code.end() );\n\ts->toks.insert( s->toks.end(), src.toks.begin(), src.toks.end() );\n\ts->ptree->insert( s->ptree->end(), src.ptree->begin(), src.ptree->end() );\n\ts->bcode.insert( s->bcode.end(), src.bcode.begin() + bcode_size, src.bcode.end() );\n\n\tint res = exec_internal( * v, bcode_size );\n\tif( res != E_OK ) {\n\t\ts->code.erase( s->code.begin() + code_size, s->code.end() );\n\t\ts->toks.erase( s->toks.begin() + toks_size, s->toks.end() );\n\t\ts->ptree->erase( s->ptree->begin() + ptree_size, s->ptree->end() );\n\t\ts->bcode.erase( s->bcode.begin() + bcode_size, s->bcode.end() );\n\t} else {\n\t\tsrc.ptree->clear();\n\t}\n\tAS_INT( fcd.args[ 2 ] )->get() = v->exit_status;\n\treturn new var_int_t( res );\n}\n\nREGISTER_MODULE( vm )\n{\n\tfunctions_t & vmfns = vm.typefuncs[ \"_evm_t\" ];\n\tvmfns.add( { \"new\", 0, 0, {}, FnType::MODULE, { .modfn = vm_create }, true } );\n\n\tfunctions_t & evmfns = vm.typefuncs[ \"evm_t\" ];\n\tevmfns.add( { \"is_running\", 0, 0, {}, FnType::MODULE, { .modfn = vm_is_running }, false } );\n\tevmfns.add( { \"exec_code\", 2, 2, { \"vec\", \"int\" }, FnType::MODULE, { .modfn = vm_exec_code }, true } );\n}\n"
  },
  {
    "path": "modules/pre/Core/Bool.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_MODULES_CORE_BOOL_HPP\n#define VM_MODULES_CORE_BOOL_HPP\n\n#include \"../../../src/VM/Core.hpp\"\n\n#define DECL_FUNC_ALLOC__BOOL( name, oper )\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t\t\t\t\t\t\t\t\\\n\t\tbool lhs = fcd.args[ 1 ]->to_bool();\t\t\t\\\n\t\tbool rhs = fcd.args[ 0 ]->to_bool();\t\t\t\\\n\t\treturn TRUE_FALSE( lhs oper rhs );\t\t\t\\\n\t}\n\n/*\n * comparison (equals and not equals) for booleans\n */\nDECL_FUNC_ALLOC__BOOL( log_eq, == )\nDECL_FUNC_ALLOC__BOOL( log_ne, != )\n\n/*\n * boolean not (!true => false)\n */\nvar_base_t * not_operb( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tbool val = AS_BOOL( fcd.args[ 0 ] )->get();\n\treturn TRUE_FALSE( !val );\n}\n\n/*\n * convert an object to boolean\n */\nvar_base_t * bool_create( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( fcd.args[ 0 ]->to_bool() );\n}\n\n/*\n * return a hash string from boolean\n */\nvar_base_t * hash_bool( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_str_t( fcd.args[ 0 ]->to_str() );\n}\n\n#endif // VM_MODULES_CORE_BOOL_HPP\n"
  },
  {
    "path": "modules/pre/Core/Flt.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_MODULES_CORE_FLT_HPP\n#define VM_MODULES_CORE_FLT_HPP\n\n#include \"../../../src/VM/Core.hpp\"\n\n#define DECL_FUNC_ALLOC__FLT( name, oper, ret_type )\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t\t\t\t\t\t\t\t\\\n\t\tauto & lhs = AS_FLT( fcd.args[ 1 ] )->get();\t\t\\\n\t\tauto & rhs = AS_FLT( fcd.args[ 0 ] )->get();\t\t\\\n\t\treturn new ret_type( lhs oper rhs );\t\t\t\\\n\t}\n\n#define DECL_FUNC_ALLOC__INT_FLT( name, oper, ret_type )\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t\t\t\t\t\t\t\t\\\n\t\tauto & lhs = AS_INT( fcd.args[ 1 ] )->get();\t\t\\\n\t\tauto & rhs = AS_FLT( fcd.args[ 0 ] )->get();\t\t\\\n\t\treturn new ret_type( lhs.get_mpz_t() oper rhs );\t\\\n\t}\n\n#define DECL_FUNC_ALLOC__FLT_INT( name, oper, ret_type )\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t\t\t\t\t\t\t\t\\\n\t\tauto & lhs = AS_FLT( fcd.args[ 1 ] )->get();\t\t\\\n\t\tauto & rhs = AS_INT( fcd.args[ 0 ] )->get();\t\t\\\n\t\treturn new ret_type( lhs oper rhs.get_mpz_t() );\t\\\n\t}\n\n#define DECL_FUNC_ASSN__FLT( name, oper )\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t/* lhs = 0 because Right to Left associativity */\t\\\n\t\tauto & lhs = AS_FLT( fcd.args[ 0 ] )->get();\t\t\\\n\t\tauto & rhs = AS_FLT( fcd.args[ 1 ] )->get();\t\t\\\n\t\tlhs oper rhs;\t\t\t\t\t\t\\\n\t\treturn fcd.args[ 0 ];\t\t\t\t\t\\\n\t}\n\n#define DECL_FUNC_BOOL__FLT( name, oper )\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t\t\t\t\t\t\t\t\\\n\t\tauto & lhs = AS_FLT( fcd.args[ 1 ] )->get();\t\t\\\n\t\tauto & rhs = AS_FLT( fcd.args[ 0 ] )->get();\t\t\\\n\t\treturn TRUE_FALSE( lhs oper rhs );\t\t\t\\\n\t}\n\n/*\n * Basic arithmetic operators\n */\nDECL_FUNC_ALLOC__FLT( addf, +, var_flt_t )\nDECL_FUNC_ALLOC__FLT( subf, -, var_flt_t )\nDECL_FUNC_ALLOC__FLT( mulf, *, var_flt_t )\nDECL_FUNC_ALLOC__FLT( divf, /, var_flt_t )\n\nDECL_FUNC_ALLOC__INT_FLT( addif, +, var_flt_t )\nDECL_FUNC_ALLOC__INT_FLT( subif, -, var_flt_t )\nDECL_FUNC_ALLOC__INT_FLT( mulif, *, var_flt_t )\nDECL_FUNC_ALLOC__INT_FLT( divif, /, var_flt_t )\n\nDECL_FUNC_ALLOC__FLT_INT( addfi, +, var_flt_t )\nDECL_FUNC_ALLOC__FLT_INT( subfi, -, var_flt_t )\nDECL_FUNC_ALLOC__FLT_INT( mulfi, *, var_flt_t )\nDECL_FUNC_ALLOC__FLT_INT( divfi, /, var_flt_t )\n\n/*\n * Basic arithmetic operators and assign to LHS\n */\nDECL_FUNC_ASSN__FLT( add_assnf, += )\nDECL_FUNC_ASSN__FLT( sub_assnf, -= )\nDECL_FUNC_ASSN__FLT( mul_assnf, *= )\nDECL_FUNC_ASSN__FLT( div_assnf, /= )\n\n/*\n * comparison between floating point values\n */\nDECL_FUNC_BOOL__FLT( eqf, == )\nDECL_FUNC_BOOL__FLT( nef, != )\nDECL_FUNC_BOOL__FLT( ltf, < )\nDECL_FUNC_BOOL__FLT( lef, <= )\nDECL_FUNC_BOOL__FLT( gtf, > )\nDECL_FUNC_BOOL__FLT( gef, >= )\n\n/*\n * raise a floating point number LHS to power integer RHS\n */\nvar_base_t * powerf( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & lhs = AS_FLT( fcd.args[ 1 ] )->get();\n\tmpz_class & rhs = AS_INT( fcd.args[ 0 ] )->get();\n\treturn new var_flt_t( mpfr::pow( lhs, rhs.get_mpz_t() ) );\n}\n\n/*\n * returns negative value of the given floating point argument\n */\nvar_base_t * unary_subf( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 0 ] )->get();\n\treturn new var_flt_t( -num );\n}\n\n/*\n * boolean not: converts float to its negative boolean\n * !(5.0) => false\n * !(0.0) => true\n */\nvar_base_t * not_operf( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 0 ] )->get();\n\treturn TRUE_FALSE( !num );\n}\n\n/*\n * converts a string to float\n */\nvar_base_t * flt( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tconst std::string & flt_str = fcd.args[ 0 ]->to_str();\n\treturn new var_flt_t( flt_str );\n}\n\n/*\n * returns a hash string from float\n */\nvar_base_t * hash_flt( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_str_t( fcd.args[ 0 ]->to_str() );\n}\n\n#endif // VM_MODULES_CORE_FLT_HPP\n"
  },
  {
    "path": "modules/pre/Core/Int.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_MODULES_CORE_INT_HPP\n#define VM_MODULES_CORE_INT_HPP\n\n#include \"../../../src/VM/Core.hpp\"\n\n#define DECL_FUNC_ALLOC__INT( name, oper, ret_type )\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t\t\t\t\t\t\t\t\\\n\t\tauto & lhs = AS_INT( fcd.args[ 1 ] )->get();\t\t\\\n\t\tauto & rhs = AS_INT( fcd.args[ 0 ] )->get();\t\t\\\n\t\treturn new ret_type( lhs oper rhs );\t\t\t\\\n\t}\n\n#define DECL_FUNC_BOOL__INT( name, oper )\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t\t\t\t\t\t\t\t\\\n\t\tauto & lhs = AS_INT( fcd.args[ 1 ] )->get();\t\t\\\n\t\tauto & rhs = AS_INT( fcd.args[ 0 ] )->get();\t\t\\\n\t\treturn TRUE_FALSE( lhs oper rhs );\t\t\t\\\n\t}\n\n#define DECL_FUNC_ASSN__INT( name, oper )\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t/* lhs = 0 because Right to Left associativity */\t\\\n\t\tauto & lhs = AS_INT( fcd.args[ 0 ] )->get();\t\t\\\n\t\tauto & rhs = AS_INT( fcd.args[ 1 ] )->get();\t\t\\\n\t\tlhs oper rhs;\t\t\t\t\t\t\\\n\t\treturn fcd.args[ 0 ];\t\t\t\t\t\\\n\t}\n\n#define DECL_FUNC_BIT__INT( name, oper )\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t/* lhs = 0 because Right to Left associativity */\t\\\n\t\tauto & lhs = AS_INT( fcd.args[ 0 ] )->get();\t\t\\\n\t\tauto & rhs = AS_INT( fcd.args[ 1 ] )->get();\t\t\\\n\t\treturn new var_int_t( lhs oper rhs );\t\t\t\\\n\t}\n\n/*\n * Basic arithmetic operators\n */\nDECL_FUNC_ALLOC__INT( add, +, var_int_t )\nDECL_FUNC_ALLOC__INT( sub, -, var_int_t )\nDECL_FUNC_ALLOC__INT( mul, *, var_int_t )\nDECL_FUNC_ALLOC__INT( div, /, var_int_t )\nDECL_FUNC_ALLOC__INT( mod, %, var_int_t )\n\n/*\n * Basic arithmetic operators and assign to LHS\n */\nDECL_FUNC_ASSN__INT( add_assn, += )\nDECL_FUNC_ASSN__INT( sub_assn, -= )\nDECL_FUNC_ASSN__INT( mul_assn, *= )\nDECL_FUNC_ASSN__INT( div_assn, /= )\nDECL_FUNC_ASSN__INT( mod_assn, %= )\n\n/*\n * comparison between integer values\n */\nDECL_FUNC_BOOL__INT( eqi, == )\nDECL_FUNC_BOOL__INT( nei, != )\nDECL_FUNC_BOOL__INT( lti, < )\nDECL_FUNC_BOOL__INT( lei, <= )\nDECL_FUNC_BOOL__INT( gti, > )\nDECL_FUNC_BOOL__INT( gei, >= )\n\n/*\n * bitwise AND and OR\n */\nDECL_FUNC_BIT__INT( andi, & )\nDECL_FUNC_BIT__INT( ori, | )\n\n/*\n * raise an integer LHS to power integer RHS\n */\nvar_base_t * power( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & lhs = AS_INT( fcd.args[ 1 ] )->get();\n\tmpz_class & rhs = AS_INT( fcd.args[ 0 ] )->get();\n\tvar_int_t * res = new var_int_t( \"0\" );\n\tmpz_pow_ui( res->get().get_mpz_t(), lhs.get_mpz_t(), rhs.get_ui() );\n\treturn res;\n}\n\n/*\n * shifts bits of a number towards MSB\n * basically, number multiplied by (2 raised to the power integer RHS)\n */\nvar_base_t * lshift( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & lhs = AS_INT( fcd.args[ 1 ] )->get();\n\tmpz_class & rhs = AS_INT( fcd.args[ 0 ] )->get();\n\tvar_int_t * res = new var_int_t( \"0\" );\n\tmpz_mul_2exp( res->get().get_mpz_t(), lhs.get_mpz_t(), rhs.get_ui() );\n\treturn res;\n}\n\n/*\n * shifts bits of a number towards LSB\n * basically, number divided by (2 raised to the power integer RHS)\n */\nvar_base_t * rshift( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & lhs = AS_INT( fcd.args[ 1 ] )->get();\n\tmpz_class & rhs = AS_INT( fcd.args[ 0 ] )->get();\n\tvar_int_t * res = new var_int_t( \"0\" );\n\tmpz_div_2exp( res->get().get_mpz_t(), lhs.get_mpz_t(), rhs.get_ui() );\n\treturn res;\n}\n\n/*\n * shifts bits of a number towards MSB and assigns the result to LHS\n * basically, number multiplied by (2 raised to the power integer RHS)\n */\nvar_base_t * lshift_assn( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & lhs = AS_INT( fcd.args[ 0 ] )->get();\n\tmpz_class & rhs = AS_INT( fcd.args[ 1 ] )->get();\n\tmpz_mul_2exp( lhs.get_mpz_t(), lhs.get_mpz_t(), rhs.get_ui() );\n\treturn fcd.args[ 0 ];\n}\n\n/*\n * shifts bits of a number towards LSB and assigns the result to LHS\n * basically, number divided by (2 raised to the power integer RHS)\n */\nvar_base_t * rshift_assn( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & lhs = AS_INT( fcd.args[ 0 ] )->get();\n\tmpz_class & rhs = AS_INT( fcd.args[ 1 ] )->get();\n\tmpz_div_2exp( lhs.get_mpz_t(), lhs.get_mpz_t(), rhs.get_ui() );\n\treturn fcd.args[ 0 ];\n}\n\n/*\n * returns negative value of the given integer argument\n */\nvar_base_t * unary_sub( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & num = AS_INT( fcd.args[ 0 ] )->get();\n\treturn new var_int_t( -num );\n}\n\n/*\n * boolean not: converts int to its negative boolean\n * !(5) => false\n * !(0) => true\n */\nvar_base_t * not_oper( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & num = AS_INT( fcd.args[ 0 ] )->get();\n\treturn TRUE_FALSE( !num );\n}\n\n/*\n * bitwise not: converts int to its bitwise opposite value\n * ~5 => 6\n * ~0 => -1\n */\nvar_base_t * not_oper_bitwise( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & num = AS_INT( fcd.args[ 0 ] )->get();\n\treturn new var_int_t( ~num );\n}\n\n/*\n * converts a string to integer\n */\nvar_base_t * _int( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( fcd.args[ 0 ]->to_int() );\n}\n\n/*\n * returns a hash string from integer\n */\nvar_base_t * hash_int( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_str_t( AS_INT( fcd.args[ 0 ] )->get().get_str() );\n}\n\n#endif // VM_MODULES_CORE_INT_HPP"
  },
  {
    "path": "modules/pre/Core/Range/Flt.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_MODULES_CORE_RANGE_FLT_HPP\n#define VM_MODULES_CORE_RANGE_FLT_HPP\n\n#include \"../../../../src/VM/Core.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////// Classes ///////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass range_iter_flt_t : public var_base_t\n{\n\tmpfr::mpreal m_beg, m_end;\n\tmpfr::mpreal m_step;\n\tmpfr::mpreal m_curr;\npublic:\n\trange_iter_flt_t( const mpfr::mpreal & beg, const mpfr::mpreal & end, const mpfr::mpreal & step, const mpfr::mpreal & curr,\n\t\t\t  const int src_idx = 0, const int parse_ctr = 0 );\n\t~range_iter_flt_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\n\tmpfr::mpreal & get_beg();\n\tmpfr::mpreal & get_end();\n\tmpfr::mpreal & get_step();\n\tmpfr::mpreal & get_curr();\n};\n#define AS_RANGE_ITER_FLT( x ) static_cast< range_iter_flt_t * >( x )\n\nrange_iter_flt_t::range_iter_flt_t( const mpfr::mpreal & beg, const mpfr::mpreal & end, const mpfr::mpreal & step, const mpfr::mpreal & curr,\n\t\t\t\t\t\t\tconst int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_beg( beg ), m_end( end ), m_step( step ), m_curr( curr ) {}\nrange_iter_flt_t::~range_iter_flt_t() {}\n\nstd::string range_iter_flt_t::type_str() const { return \"range_iter_flt_t\"; }\nstd::string range_iter_flt_t::to_str() const\n{\n\treturn m_curr.toString();\n}\nmpz_class range_iter_flt_t::to_int() const { return mpz_class( mpf_class( m_curr.toString() ) ); }\nbool range_iter_flt_t::to_bool() const { return m_curr >= m_beg && m_curr < m_end; }\nvar_base_t * range_iter_flt_t::copy( const int src_idx, const int parse_ctr )\n{\n\treturn new range_iter_flt_t( m_beg, m_end, m_step, m_curr, src_idx, parse_ctr );\n}\nvoid range_iter_flt_t::assn( var_base_t * b )\n{\n\tm_beg = AS_RANGE_ITER_FLT( b )->get_beg();\n\tm_end = AS_RANGE_ITER_FLT( b )->get_end();\n\tm_step = AS_RANGE_ITER_FLT( b )->get_step();\n\tm_curr = AS_RANGE_ITER_FLT( b )->get_curr();\n}\nmpfr::mpreal & range_iter_flt_t::get_beg() { return m_beg; }\nmpfr::mpreal & range_iter_flt_t::get_end() { return m_end; }\nmpfr::mpreal & range_iter_flt_t::get_step() { return m_step; }\nmpfr::mpreal & range_iter_flt_t::get_curr() { return m_curr; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * range_flt( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & a = AS_FLT( fcd.args[ 0 ] )->get();\n\tmpfr::mpreal & b = AS_FLT( fcd.args[ 1 ] )->get();\n\tmpfr::mpreal step = fcd.args.size() > 2 ? AS_FLT( fcd.args[ 2 ] )->get() : 1.0;\n\treturn new range_iter_flt_t( a, b, step, a - step );\n}\n\nvar_base_t * next_flt( vm_state_t & vm, func_call_data_t & fcd )\n{\n\trange_iter_flt_t * it = AS_RANGE_ITER_FLT( fcd.args[ 0 ] );\n\tconst mpfr::mpreal & a = it->get_beg();\n\tconst mpfr::mpreal & b = it->get_end();\n\tconst mpfr::mpreal & s = it->get_step();\n\tmpfr::mpreal & i = it->get_curr();\n\ti += s;\n\tif( i >= b ) return vm.nil;\n\treturn new var_flt_t( i );\n}\n\n#endif // VM_MODULES_CORE_RANGE_FLT_HPP"
  },
  {
    "path": "modules/pre/Core/Range/Int.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_MODULES_CORE_RANGE_INT_HPP\n#define VM_MODULES_CORE_RANGE_INT_HPP\n\n#include \"../../../../src/VM/Core.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////// Classes ///////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass range_iter_int_t : public var_base_t\n{\n\tmpz_class m_beg, m_end;\n\tmpz_class m_step;\n\tmpz_class m_curr;\npublic:\n\trange_iter_int_t( const mpz_class & beg, const mpz_class & end, const mpz_class & step, const mpz_class & curr,\n\t\t\t  const int src_idx = 0, const int parse_ctr = 0 );\n\t~range_iter_int_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\n\tmpz_class & get_beg();\n\tmpz_class & get_end();\n\tmpz_class & get_step();\n\tmpz_class & get_curr();\n};\n#define AS_RANGE_ITER_INT( x ) static_cast< range_iter_int_t * >( x )\n\nrange_iter_int_t::range_iter_int_t( const mpz_class & beg, const mpz_class & end, const mpz_class & step, const mpz_class & curr,\n\t\t\t\t\t\t\tconst int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_beg( beg ), m_end( end ), m_step( step ), m_curr( curr ) {}\nrange_iter_int_t::~range_iter_int_t() {}\n\nstd::string range_iter_int_t::type_str() const { return \"range_iter_int_t\"; }\nstd::string range_iter_int_t::to_str() const\n{\n\treturn m_curr.get_str();\n}\nmpz_class range_iter_int_t::to_int() const { return m_curr; }\nbool range_iter_int_t::to_bool() const { return m_curr >= m_beg && m_curr < m_end; }\nvar_base_t * range_iter_int_t::copy( const int src_idx, const int parse_ctr )\n{\n\treturn new range_iter_int_t( m_beg, m_end, m_step, m_curr, src_idx, parse_ctr );\n}\nvoid range_iter_int_t::assn( var_base_t * b )\n{\n\tm_beg = AS_RANGE_ITER_INT( b )->get_beg();\n\tm_end = AS_RANGE_ITER_INT( b )->get_end();\n\tm_step = AS_RANGE_ITER_INT( b )->get_step();\n\tm_curr = AS_RANGE_ITER_INT( b )->get_curr();\n}\nmpz_class & range_iter_int_t::get_beg() { return m_beg; }\nmpz_class & range_iter_int_t::get_end() { return m_end; }\nmpz_class & range_iter_int_t::get_step() { return m_step; }\nmpz_class & range_iter_int_t::get_curr() { return m_curr; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * range_int( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & a = AS_INT( fcd.args[ 0 ] )->get();\n\tmpz_class & b = AS_INT( fcd.args[ 1 ] )->get();\n\tmpz_class step = fcd.args.size() > 2 ? AS_INT( fcd.args[ 2 ] )->get() : 1;\n\treturn new range_iter_int_t( a, b, step, a - step );\n}\n\nvar_base_t * next_int( vm_state_t & vm, func_call_data_t & fcd )\n{\n\trange_iter_int_t * it = AS_RANGE_ITER_INT( fcd.args[ 0 ] );\n\tconst mpz_class & a = it->get_beg();\n\tconst mpz_class & b = it->get_end();\n\tconst mpz_class & s = it->get_step();\n\tmpz_class & i = it->get_curr();\n\ti += s;\n\tif( i >= b ) return vm.nil;\n\treturn new var_int_t( i );\n}\n\n#endif // VM_MODULES_CORE_RANGE_INT_HPP"
  },
  {
    "path": "modules/pre/core.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../../src/FE/Env.hpp\"\n#include \"../../src/VM/Core.hpp\"\n#include \"../../src/VM/LoadFile.hpp\"\n\n#include \"Core/Int.hpp\"\n#include \"Core/Flt.hpp\"\n#include \"Core/Bool.hpp\"\n\n#include \"Core/Range/Int.hpp\"\n#include \"Core/Range/Flt.hpp\"\n\nconst int MAX_C_STR_LEN = 1025;\n\nvar_base_t * flush_out( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tfflush( stdout );\n\treturn nullptr;\n}\n\nvar_base_t * flush_err( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tfflush( stderr );\n\treturn nullptr;\n}\n\nvar_base_t * print( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tfor( auto & v : fcd.args ) {\n\t\tfprintf( stdout, \"%s\", v->to_str().c_str() );\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * println( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tfor( auto & v : fcd.args ) {\n\t\tfprintf( stdout, \"%s\", v->to_str().c_str() );\n\t}\n\tfprintf( stdout, \"\\n\" );\n\treturn nullptr;\n}\n\nvar_base_t * dprint( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tfor( auto & v : fcd.args ) {\n\t\tfprintf( stderr, \"%s\", v->to_str().c_str() );\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * dprintln( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tfor( auto & v : fcd.args ) {\n\t\tfprintf( stderr, \"%s\", v->to_str().c_str() );\n\t}\n\tfprintf( stderr, \"\\n\" );\n\treturn nullptr;\n}\n\nvar_base_t * scan( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tif( fcd.args.size() > 0 ) fprintf( stdout, \"%s\", fcd.args[ 0 ]->to_str().c_str() );\n\tchar str[ MAX_C_STR_LEN ];\n\tfgets( str, MAX_C_STR_LEN, stdin );\n\tstd::string res( str );\n\twhile( res.back() == '\\n' ) res.pop_back();\n\twhile( res.back() == '\\r' ) res.pop_back();\n\treturn new var_str_t( res );\n}\n\nvar_base_t * type( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_str_t( fcd.args[ 0 ]->type_str() );\n}\n\nvar_base_t * to_str( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_str_t( fcd.args[ 0 ]->to_str() );\n}\n\nvar_base_t * exit_eth( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tvm.exit_called = true;\n\tvm.exit_status = fcd.args.size() == 0 ? 0 : fcd.args[ 0 ]->to_int().get_si();\n\treturn nullptr;\n}\nvar_base_t * assert_eth( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tif( fcd.args[ 0 ]->to_bool() ) { return nullptr; }\n\tvm.exit_called = true;\n\tvm.exit_status = E_ASSERT_LVL2;\n\treturn nullptr;\n\tsrc_t & src = * vm.srcstack.back();\n\tint line = src.bcode[ fcd.bcodectr ].line;\n\tint col = src.bcode[ fcd.bcodectr ].col;\n\tstd::string op;\n\tint sz = fcd.args.size();\n\tfor( int i = 1; i < sz; ++i ) {\n\t\top += fcd.args[ i ]->to_str();\n\t}\n\tsrc_fail( src.file, src.code[ line - 1 ], line, col, \"assertion failed: %s\", op.c_str() );\n\tvm.exit_called = true;\n\tvm.exit_status = 1;\n\treturn nullptr;\n}\nvar_base_t * assert_eth_fail( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tvm.exit_called = true;\n\tvm.exit_status = E_ASSERT_LVL2;\n\tint sz = fcd.args.size();\n\tvm.fail_msg.clear();\n\tfor( int i = 0; i < sz; ++i ) {\n\t\tvm.fail_msg += fcd.args[ i ]->to_str();\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * var_exists( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( vm.vars->exists( fcd.args[ 0 ]->to_str() ) );\n}\n\nvar_base_t * var_mfn_exists( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tif( vm.typefuncs.find( fcd.args[ 0 ]->type_str() ) == vm.typefuncs.end() ) return vm.vars->get( \"false\" );\n\treturn TRUE_FALSE( vm.typefuncs[ fcd.args[ 0 ]->type_str() ].exists_name( fcd.args[ 1 ]->to_str() ) );\n}\n\nvar_base_t * var_ref_count( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tif( !vm.vars->exists( fcd.args[ 0 ]->to_str() ) ) return new var_int_t( -1 );\n\treturn new var_int_t( vm.vars->get( fcd.args[ 0 ]->to_str() )->ref() );\n}\n\nvar_base_t * add_inc_dirs( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tfor( auto & _dir : fcd.args ) {\n\t\tstd::string dir = _dir->to_str();\n\t\tDirFormat( dir );\n\t\tAS_VEC( vm.inc_dirs )->get().insert(\n\t\t\tAS_VEC( vm.inc_dirs )->get().begin(),\n\t\t\tnew var_str_t( dir, fcd.parse_ctr )\n\t\t);\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * add_lib_dirs( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tfor( auto & _dir : fcd.args ) {\n\t\tstd::string dir = _dir->to_str();\n\t\tDirFormat( dir );\n\t\tAS_VEC( vm.lib_dirs )->get().insert(\n\t\t\tAS_VEC( vm.lib_dirs )->get().begin(),\n\t\t\tnew var_str_t( dir, fcd.parse_ctr )\n\t\t);\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * load_module( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string name = fcd.args[ 0 ]->to_str();\n\tauto last_slash = name.find_last_of( '/' );\n\tname.insert( last_slash + 1, \"lib\" );\n\n\tstd::string file = name + LIB_EXT;\n\tstd::string init_fn_str = name.substr( name.find_last_of( '/' ) + 4 );\n\n\tsrc_t & src = * vm.srcstack.back();\n\tint line = src.bcode[ fcd.bcodectr ].line;\n\tint col = src.bcode[ fcd.bcodectr ].col;\n\n\tinit_fnptr_t init_fn = nullptr;\n\n\tif( !mod_exists( file, vm.lib_dirs ) ) {\n\t\tsrc_fail( src.file, src.code[ line - 1 ], line, col,\n\t\t\t  \"could not find module '%s' for loading\",\n\t\t\t  name.c_str() );\n\t\tfprintf( stderr, \"checked the following paths:\\n\" );\n\t\tfor( auto & loc : AS_VEC( vm.lib_dirs )->get() ) {\n\t\t\tfprintf( stderr, \"-> %s\\n\", ( loc->to_str() + \"/\" + file ).c_str() );\n\t\t}\n\t\tgoto fail;\n\t}\n\tif( vm.dlib->load( file ) == nullptr ) goto fail;\n\tinit_fn = ( init_fnptr_t ) vm.dlib->get( file, \"init_\" + init_fn_str );\n\tif( init_fn == nullptr ) {\n\t\tsrc_fail( src.file, src.code[ line - 1 ], line, col,\n\t\t\t  \"failed to find init function '%s' in module '%s'\",\n\t\t\t  init_fn_str.c_str(), file.c_str() );\n\t\tgoto fail;\n\t}\n\tinit_fn( vm );\n\treturn new var_int_t( E_OK );\nfail:\n\treturn new var_int_t( E_FAIL );\n}\n\nvar_base_t * import_module( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string name = fcd.args[ 0 ]->to_str();\n\tstd::string file = name + \".et\";\n\n\tsrc_t & src = * vm.srcstack.back();\n\tint line = src.bcode[ fcd.bcodectr ].line;\n\tint col = src.bcode[ fcd.bcodectr ].col;\n\n\tint ret = E_OK;\n\n\tif( !mod_exists( file, vm.inc_dirs ) ) {\n\t\tsrc_fail( src.file, src.code[ line - 1 ], line, col, \"could not find file '%s' for importing\", name.c_str() );\n\t\tfprintf( stderr, \"checked the following paths:\\n\" );\n\t\tfor( auto & loc : AS_VEC( vm.inc_dirs )->get() ) {\n\t\t\tfprintf( stderr, \"-> %s\\n\", ( loc->to_str() + \"/\" + file ).c_str() );\n\t\t}\n\t\tret = E_FAIL;\n\t\tgoto fail;\n\t}\n\n\tret = load_src( vm, file );\n\tif( ret != E_OK ) {\n\t\tsrc_fail( src.file, src.code[ line - 1 ], line, col,\n\t\t\t  \"could not import '%s', see the error above; aborting\",\n\t\t\t  file.c_str() );\n\t\tgoto fail;\n\t}\n\treturn new var_int_t( E_OK );\nfail:\n\treturn new var_int_t( ret );\n}\n\nvar_base_t * set_float_precision( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tupdate_float_precision( fcd.args[ 0 ]->to_int().get_ui() );\n\treturn nullptr;\n}\n\nvar_base_t * get_float_precision( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( get_float_precision() );\n}\n\nvar_base_t * get_float_precision_num( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_flt_t( \"0.\" + std::string( get_float_precision() - 1, '0' ) + \"1\" );\n}\n\nvar_base_t * nil_eq( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( fcd.args[ 1 ]->type() == fcd.args[ 0 ]->type() );\n}\n\nvar_base_t * nil_ne( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( fcd.args[ 1 ]->type() != fcd.args[ 0 ]->type() );\n}\n\nREGISTER_MODULE( core )\n{\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t///////////////////////////////////////////////////////////////// CORE ////////////////////////////////////////////////////////////////\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\tvm.funcs.add( { \"flush_out\",             0,  0, {}, FnType::MODULE, { .modfn = flush_out }, false } );\n\tvm.funcs.add( { \"flush_err\",             0,  0, {}, FnType::MODULE, { .modfn = flush_err }, false } );\n\tvm.funcs.add( { \"print\",                 1, -1, { \"_any_\", \"_whatever_\" }, FnType::MODULE, { .modfn = print }, false } );\n\tvm.funcs.add( { \"println\",               0, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = println }, false } );\n\tvm.funcs.add( { \"dprint\",                1, -1, { \"_any_\", \"_whatever_\" }, FnType::MODULE, { .modfn = dprint }, false } );\n\tvm.funcs.add( { \"dprintln\",              0, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = dprintln }, false } );\n\tvm.funcs.add( { \"scan\",                  0,  1, { \"_whatever_\" }, FnType::MODULE, { .modfn = scan }, true } );\n\tvm.funcs.add( { \"exit\",                  0,  1, { \"_any_\" }, FnType::MODULE, { .modfn = exit_eth }, false } );\n\tvm.funcs.add( { \"assert_fail\",           1, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = assert_eth_fail }, false } );\n\tvm.funcs.add( { \"var_exists\",            1,  1, { \"str\" }, FnType::MODULE, { .modfn = var_exists }, false } );\n\tvm.funcs.add( { \"var_mfn_exists\",        2,  2, { \"_any_\", \"str\" }, FnType::MODULE, { .modfn = var_mfn_exists }, false } );\n\tvm.funcs.add( { \"var_ref_count\",         1,  1, { \"_any_\" }, FnType::MODULE, { .modfn = var_ref_count }, true } );\n\tvm.funcs.add( { \"__add_incs__\",\t         1, -1, { \"_any_\", \"_whatever_\" }, FnType::MODULE, { .modfn = add_inc_dirs }, false } );\n\tvm.funcs.add( { \"__add_libs__\",\t         1, -1, { \"_any_\", \"_whatever_\" }, FnType::MODULE, { .modfn = add_lib_dirs }, false } );\n\tvm.funcs.add( { \"_ldmod_\",\t         1,  1, { \"str\" }, FnType::MODULE, { .modfn = load_module }, true } );\n\tvm.funcs.add( { \"__import__\",\t         1,  1, { \"str\" }, FnType::MODULE, { .modfn = import_module }, true } );\n\tvm.funcs.add( { \"set_flt_precision\",     1,  1, { \"int\" }, FnType::MODULE, { .modfn = set_float_precision }, false } );\n\tvm.funcs.add( { \"get_flt_precision\",     0,  0, {}, FnType::MODULE, { .modfn = get_float_precision }, true } );\n\tvm.funcs.add( { \"get_flt_precision_num\", 0,  0, {}, FnType::MODULE, { .modfn = get_float_precision_num }, true } );\n\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t////////////////////////////////////////////////////////////////// INT ////////////////////////////////////////////////////////////////\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t// basic arithmetic\n\tvm.funcs.add( { \"+\",   2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = add }, true } );\n\tvm.funcs.add( { \"-\",   2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = sub }, true } );\n\tvm.funcs.add( { \"*\",   2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = mul }, true } );\n\tvm.funcs.add( { \"/\",   2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = div }, true } );\n\tvm.funcs.add( { \"%\",   2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = mod }, true } );\n\n\t// arithmetic assignments\n\tvm.funcs.add( { \"+=\",  2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = add_assn }, false } );\n\tvm.funcs.add( { \"-=\",  2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = sub_assn }, false } );\n\tvm.funcs.add( { \"*=\",  2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = mul_assn }, false } );\n\tvm.funcs.add( { \"/=\",  2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = div_assn }, false } );\n\tvm.funcs.add( { \"%=\",  2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = mod_assn }, false } );\n\n\t// comparisons\n\tvm.funcs.add( { \"==\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = eqi }, false } );\n\tvm.funcs.add( { \"!=\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = nei }, false } );\n\tvm.funcs.add( { \"<\",  2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = lti }, false } );\n\tvm.funcs.add( { \"<=\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = lei }, false } );\n\tvm.funcs.add( { \">\",  2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = gti }, false } );\n\tvm.funcs.add( { \">=\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = gei }, false } );\n\tvm.funcs.add( { \"!\",  1, 1, { \"int\" }, FnType::MODULE, { .modfn = not_oper }, false } );\n\n\t// bitshift\n\tvm.funcs.add( { \"<<\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = lshift }, true } );\n\tvm.funcs.add( { \">>\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = rshift }, true } );\n\n\t// bitwise assignments\n\tvm.funcs.add( { \"<<=\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = lshift_assn }, false } );\n\tvm.funcs.add( { \">>=\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = rshift_assn }, false } );\n\n\t// bitwise\n\tvm.funcs.add( { \"&\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = andi }, true } );\n\tvm.funcs.add( { \"|\", 2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = ori }, true } );\n\tvm.funcs.add( { \"~\", 1, 1, { \"int\" }, FnType::MODULE, { .modfn = not_oper_bitwise }, true } );\n\n\t// cool arithmetic\n\tvm.funcs.add( { \"**\",  2, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = power }, true } );\n\n\t// unary\n\tvm.funcs.add( { \"u-\",  1, 1, { \"int\" }, FnType::MODULE, { .modfn = unary_sub }, true } );\n\n\t// other types to int\n\tvm.funcs.add( { \"int\", 1, 1, { \"_any_\" }, FnType::MODULE, { .modfn = _int }, true } );\n\n\t// hashing\n\tvm.typefuncs[ \"int\" ].add( { \"hash\", 0, 0, {}, FnType::MODULE, { .modfn = hash_int }, true } );\n\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t////////////////////////////////////////////////////////////////// FLT ////////////////////////////////////////////////////////////////\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t// basic arithmetic\n\tvm.funcs.add( { \"+\",   2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = addf }, true } );\n\tvm.funcs.add( { \"-\",   2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = subf }, true } );\n\tvm.funcs.add( { \"*\",   2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = mulf }, true } );\n\tvm.funcs.add( { \"/\",   2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = divf }, true } );\n\t// LHS is int\n\tvm.funcs.add( { \"+\",   2, 2, { \"flt\", \"int\" }, FnType::MODULE, { .modfn = addif }, true } );\n\tvm.funcs.add( { \"-\",   2, 2, { \"flt\", \"int\" }, FnType::MODULE, { .modfn = subif }, true } );\n\tvm.funcs.add( { \"*\",   2, 2, { \"flt\", \"int\" }, FnType::MODULE, { .modfn = mulif }, true } );\n\tvm.funcs.add( { \"/\",   2, 2, { \"flt\", \"int\" }, FnType::MODULE, { .modfn = divif }, true } );\n\t// RHS is int\n\tvm.funcs.add( { \"+\",   2, 2, { \"int\", \"flt\" }, FnType::MODULE, { .modfn = addfi }, true } );\n\tvm.funcs.add( { \"-\",   2, 2, { \"int\", \"flt\" }, FnType::MODULE, { .modfn = subfi }, true } );\n\tvm.funcs.add( { \"*\",   2, 2, { \"int\", \"flt\" }, FnType::MODULE, { .modfn = mulfi }, true } );\n\tvm.funcs.add( { \"/\",   2, 2, { \"int\", \"flt\" }, FnType::MODULE, { .modfn = divfi }, true } );\n\n\t// arithmetic assignments\n\tvm.funcs.add( { \"+=\",  2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = add_assnf }, false } );\n\tvm.funcs.add( { \"-=\",  2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = sub_assnf }, false } );\n\tvm.funcs.add( { \"*=\",  2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = mul_assnf }, false } );\n\tvm.funcs.add( { \"/=\",  2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = div_assnf }, false } );\n\n\t// comparisons\n\tvm.funcs.add( { \"==\", 2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = eqf }, false } );\n\tvm.funcs.add( { \"!=\", 2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = nef }, false } );\n\tvm.funcs.add( { \"<\",  2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = ltf }, false } );\n\tvm.funcs.add( { \"<=\", 2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = lef }, false } );\n\tvm.funcs.add( { \">\",  2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = gtf }, false } );\n\tvm.funcs.add( { \">=\", 2, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = gef }, false } );\n\tvm.funcs.add( { \"!\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = not_operf }, false } );\n\n\t// cool arithmetic\n\tvm.funcs.add( { \"**\",  2, 2, { \"int\", \"flt\" }, FnType::MODULE, { .modfn = powerf }, true } );\n\n\t// unary\n\tvm.funcs.add( { \"u-\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = unary_subf }, true } );\n\n\t// other types to flt\n\tvm.funcs.add( { \"flt\", 1, 1, { \"_any_\" }, FnType::MODULE, { .modfn = flt }, true } );\n\n\t// hashing\n\tvm.typefuncs[ \"flt\" ].add( { \"hash\", 0, 0, {}, FnType::MODULE, { .modfn = hash_flt }, true } );\n\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t////////////////////////////////////////////////////////////////// BOOL ///////////////////////////////////////////////////////////////\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t// basic logical\n\tvm.funcs.add( { \"==\", 2, 2, { \"bool\", \"bool\" }, FnType::MODULE, { .modfn = log_eq }, false } );\n\tvm.funcs.add( { \"!=\", 2, 2, { \"bool\", \"bool\" }, FnType::MODULE, { .modfn = log_ne }, false } );\n\tvm.funcs.add( { \"!\",  1, 1, { \"bool\" }, FnType::MODULE, { .modfn = not_operb }, false } );\n\n\t// other types to bool\n\tvm.funcs.add( { \"bool\", 1, 1, { \"_any_\" }, FnType::MODULE, { .modfn = bool_create }, false } );\n\n\t// hashing\n\tvm.typefuncs[ \"bool\" ].add( { \"hash\", 0, 0, {}, FnType::MODULE, { .modfn = hash_bool }, true } );\n\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t////////////////////////////////////////////////////////////////// NIL ////////////////////////////////////////////////////////////////\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\tvm.funcs.add( { \"==\", 2, 2, { \"nil\", \"_any_\" }, FnType::MODULE, { .modfn = nil_eq }, false } );\n\tvm.funcs.add( { \"==\", 2, 2, { \"_any_\", \"nil\" }, FnType::MODULE, { .modfn = nil_eq }, false } );\n\tvm.funcs.add( { \"!=\", 2, 2, { \"nil\", \"_any_\" }, FnType::MODULE, { .modfn = nil_ne }, false } );\n\tvm.funcs.add( { \"!=\", 2, 2, { \"_any_\", \"nil\" }, FnType::MODULE, { .modfn = nil_ne }, false } );\n\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t////////////////////////////////////////////////////////////////// MISC ///////////////////////////////////////////////////////////////\n\t///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\t// range (int)\n\tfunctions_t & ritifns = vm.typefuncs[ \"range_iter_int_t\" ];\n\tritifns.add(  { \"next\",  0, 0, {}, FnType::MODULE, { .modfn = next_int }, true } );\n\tvm.funcs.add( { \"range\", 2, 3, { \"int\", \"int\", \"int\" }, FnType::MODULE, { .modfn = range_int }, true } );\n\t// range (flt)\n\tfunctions_t & ritffns = vm.typefuncs[ \"range_iter_flt_t\" ];\n\tritffns.add(  { \"next\",  0, 0, {}, FnType::MODULE, { .modfn = next_flt }, true } );\n\tvm.funcs.add( { \"range\", 2, 3, { \"flt\", \"flt\", \"flt\" }, FnType::MODULE, { .modfn = range_flt }, true } );\n\n\t// global object functions\n\tfunctions_t & anyfns = vm.typefuncs[ \"_any_\" ];\n\tanyfns.add( { \"type\",   0, 0, {}, FnType::MODULE, { .modfn = type }, true } );\n\tanyfns.add( { \"to_str\", 0, 0, {}, FnType::MODULE, { .modfn = to_str }, true } );\n}"
  },
  {
    "path": "modules/std/complex.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../../third_party/mpcxx.hpp\"\n\n#include \"../../src/VM/Core.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////// Class ////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass var_cplx_t : public var_base_t\n{\n\tmpc::mpcplx m_val;\npublic:\n\tvar_cplx_t( const mpc::mpcplx & val, const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_cplx_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tmpc::mpcplx & get();\n};\n#define AS_CPLX( x ) static_cast< var_cplx_t * >( x )\n\nvar_cplx_t::var_cplx_t( const mpc::mpcplx & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_cplx_t::~var_cplx_t() {}\n\nstd::string var_cplx_t::type_str() const { return \"cplx_t\"; }\nstd::string var_cplx_t::to_str() const\n{\n\treturn \"cplx_t{\" + m_val.to_str( get_float_precision() ) + \"}\";\n}\nmpz_class var_cplx_t::to_int() const { return mpz_class( mpf_class( m_val.real().toString() ) ); }\nbool var_cplx_t::to_bool() const { return m_val.real() != 0.0 && m_val.imag() != 0.0; }\nvar_base_t * var_cplx_t::copy( const int src_idx, const int parse_ctr )\n{\n\treturn new var_cplx_t( m_val, src_idx, parse_ctr );\n}\nvoid var_cplx_t::assn( var_base_t * b )\n{\n\tm_val = AS_CPLX( b )->get();\n}\nmpc::mpcplx & var_cplx_t::get() { return m_val; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#define DECL_FUNC_ALLOC__CPLX( name, op )\t\t\t\t\t\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\treturn new var_cplx_t( AS_CPLX( fcd.args[ 1 ] )->get() op AS_CPLX( fcd.args[ 0 ] )->get() );\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\n#define DECL_FUNC_ASSN__CPLX( name, op )\t\t\t\t\t\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tauto & lhs = AS_CPLX( fcd.args[ 0 ] )->get();\t\t\t\t\t\t\t\\\n\t\tauto & rhs = AS_CPLX( fcd.args[ 1 ] )->get();\t\t\t\t\t\t\t\\\n\t\tlhs op rhs;\t\t\t\t\t\t\t\t\t\t\t\\\n\t\treturn fcd.args[ 0 ];\t\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\n#define DECL_FUNC_BOOL__CPLX( name, op )\t\t\t\t\t\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\treturn TRUE_FALSE( AS_CPLX( fcd.args[ 1 ] )->get() op AS_CPLX( fcd.args[ 0 ] )->get() );\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\nvar_base_t * cplx_create_z( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & real = AS_INT( fcd.args[ 1 ] )->get();\n\tmpz_class imag   = fcd.args.size() > 2 ? AS_INT( fcd.args[ 2 ] )->get() : 0;\n\treturn new var_cplx_t( mpc::mpcplx( real, imag ) );\n}\n\nvar_base_t * cplx_create_f( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & real = AS_FLT( fcd.args[ 1 ] )->get();\n\tmpfr::mpreal imag   = fcd.args.size() > 2 ? AS_FLT( fcd.args[ 2 ] )->get() : 0.0;\n\treturn new var_cplx_t( mpc::mpcplx( real, imag ) );\n}\n\nDECL_FUNC_ALLOC__CPLX( cplx_add, + )\nDECL_FUNC_ALLOC__CPLX( cplx_sub, - )\nDECL_FUNC_ALLOC__CPLX( cplx_mul, * )\nDECL_FUNC_ALLOC__CPLX( cplx_div, / )\n\nDECL_FUNC_ASSN__CPLX( cplx_add_assn, += )\nDECL_FUNC_ASSN__CPLX( cplx_sub_assn, -= )\nDECL_FUNC_ASSN__CPLX( cplx_mul_assn, *= )\nDECL_FUNC_ASSN__CPLX( cplx_div_assn, /= )\n\nDECL_FUNC_BOOL__CPLX( cplx_eq, == )\nDECL_FUNC_BOOL__CPLX( cplx_ne, != )\n\nvar_base_t * cplx_real( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_flt_t( AS_CPLX( fcd.args[ 0 ] )->get().real() );\n}\n\nvar_base_t * cplx_imag( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_flt_t( AS_CPLX( fcd.args[ 0 ] )->get().imag() );\n}\n\nvar_base_t * cplx_abs( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_flt_t( AS_CPLX( fcd.args[ 0 ] )->get().abs() );\n}\n\nvar_base_t * cplx_arg( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_flt_t( AS_CPLX( fcd.args[ 0 ] )->get().arg() );\n}\n\nvar_base_t * cplx_norm( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_flt_t( AS_CPLX( fcd.args[ 0 ] )->get().norm() );\n}\n\nvar_base_t * cplx_conj( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().conj() );\n}\n\nvar_base_t * cplx_proj( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().proj() );\n}\n\nvar_base_t * cplx_uminus( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( -( AS_CPLX( fcd.args[ 0 ] )->get() ) );\n}\n\nvar_base_t * cplx_exp( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().exp() );\n}\n\nvar_base_t * cplx_log( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpc::mpcplx & num = AS_CPLX( fcd.args[ 0 ] )->get();\n\tmpc::mpcplx base = fcd.args.size() > 1 ? AS_CPLX( fcd.args[ 1 ] )->get() : mpc::mpcplx( mpz_class( 10 ) );\n\treturn new var_cplx_t( num.log() / base.log() );\n}\n\nvar_base_t * cplx_pow( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpc::mpcplx & num = AS_CPLX( fcd.args[ 1 ] )->get();\n\tmpc::mpcplx & exp = AS_CPLX( fcd.args[ 0 ] )->get();\n\treturn new var_cplx_t( num.pow( exp ) );\n}\n\nvar_base_t * cplx_pow_z( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpc::mpcplx & num = AS_CPLX( fcd.args[ 1 ] )->get();\n\tmpz_class & exp = AS_INT( fcd.args[ 0 ] )->get();\n\treturn new var_cplx_t( num.pow( exp ) );\n}\n\nvar_base_t * cplx_pow_f( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpc::mpcplx & num = AS_CPLX( fcd.args[ 1 ] )->get();\n\tmpfr::mpreal & exp = AS_FLT( fcd.args[ 0 ] )->get();\n\treturn new var_cplx_t( num.pow( exp ) );\n}\n\nvar_base_t * cplx_sqrt( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().sqrt() );\n}\n\nvar_base_t * cplx_sin( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().sin() );\n}\n\nvar_base_t * cplx_cos( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().cos() );\n}\n\nvar_base_t * cplx_tan( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().tan() );\n}\n\nvar_base_t * cplx_csc( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().csc() );\n}\n\nvar_base_t * cplx_sec( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().sec() );\n}\n\nvar_base_t * cplx_cot( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_cplx_t( AS_CPLX( fcd.args[ 0 ] )->get().cot() );\n}\n\nREGISTER_MODULE( complex )\n{\n\tfunctions_t & cplxt = vm.typefuncs[ \"_cplx_t\" ];\n\tcplxt.add( { \"new\", 1, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = cplx_create_z }, true } );\n\tcplxt.add( { \"new\", 1, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = cplx_create_f }, true } );\n\n\tvm.funcs.add( { \"+\",  2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_add }, true } );\n\tvm.funcs.add( { \"-\",  2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_sub }, true } );\n\tvm.funcs.add( { \"*\",  2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_mul }, true } );\n\tvm.funcs.add( { \"/\",  2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_div }, true } );\n\n\tvm.funcs.add( { \"+=\", 2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_add_assn }, false } );\n\tvm.funcs.add( { \"-=\", 2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_sub_assn }, false } );\n\tvm.funcs.add( { \"*=\", 2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_mul_assn }, false } );\n\tvm.funcs.add( { \"/=\", 2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_div_assn }, false } );\n\n\tvm.funcs.add( { \"**\", 2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_pow }, true } );\n\tvm.funcs.add( { \"**\", 2, 2, { \"int\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_pow_z }, true } );\n\tvm.funcs.add( { \"**\", 2, 2, { \"flt\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_pow_f }, true } );\n\n\tvm.funcs.add( { \"==\", 2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_eq }, false } );\n\tvm.funcs.add( { \"!=\", 2, 2, { \"cplx_t\", \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_ne }, false } );\n\n\tvm.funcs.add( { \"u-\", 1, 1, { \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_uminus }, true } );\n\n\tfunctions_t & cplx = vm.typefuncs[ \"cplx_t\" ];\n\tcplx.add( { \"real\", 0, 0, {}, FnType::MODULE, { .modfn = cplx_real }, true } );\n\tcplx.add( { \"imag\", 0, 0, {}, FnType::MODULE, { .modfn = cplx_imag }, true } );\n\tcplx.add( { \"abs\",  0, 0, {}, FnType::MODULE, { .modfn = cplx_abs }, true } );\n\tcplx.add( { \"arg\",  0, 0, {}, FnType::MODULE, { .modfn = cplx_arg }, true } );\n\tcplx.add( { \"norm\", 0, 0, {}, FnType::MODULE, { .modfn = cplx_norm }, true } );\n\tcplx.add( { \"conj\", 0, 0, {}, FnType::MODULE, { .modfn = cplx_conj }, true } );\n\tcplx.add( { \"proj\", 0, 0, {}, FnType::MODULE, { .modfn = cplx_proj }, true } );\n\tcplx.add( { \"exp\",  0, 0, {}, FnType::MODULE, { .modfn = cplx_exp }, true } );\n\tcplx.add( { \"log\",  0, 1, { \"cplx_t\" }, FnType::MODULE, { .modfn = cplx_log }, true } );\n\t// pow functions above as '**'\n\tcplx.add( { \"sqrt\", 0, 0, {}, FnType::MODULE, { .modfn = cplx_sqrt }, true } );\n\tcplx.add( { \"sin\",  0, 0, {}, FnType::MODULE, { .modfn = cplx_sin }, true } );\n\tcplx.add( { \"cos\",  0, 0, {}, FnType::MODULE, { .modfn = cplx_cos }, true } );\n\tcplx.add( { \"tan\",  0, 0, {}, FnType::MODULE, { .modfn = cplx_tan }, true } );\n\tcplx.add( { \"csc\",  0, 0, {}, FnType::MODULE, { .modfn = cplx_csc }, true } );\n\tcplx.add( { \"sec\",  0, 0, {}, FnType::MODULE, { .modfn = cplx_sec }, true } );\n\tcplx.add( { \"cot\",  0, 0, {}, FnType::MODULE, { .modfn = cplx_cot }, true } );\n}"
  },
  {
    "path": "modules/std/fs.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <regex>\n\n#include <cstdio>\n#include <cstdlib>\n#include <dirent.h>\n#include <sys/wait.h>\n#include <unistd.h>\n\n#include \"../../src/VM/Core.hpp\"\n\nint exec_internal( const std::string & cmd );\n\nenum FSEnt {\n\tFILES = 1 << 0,\n\tDIRS = 1 << 1,\n\tRECURSE = 1 << 2,\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////// Class ////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass var_file_t : public var_base_t\n{\n\tFILE * m_file;\n\tbool m_copied;\npublic:\n\tvar_file_t( FILE * file, const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_file_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tbool is_copied() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tFILE * & get();\n};\n#define AS_FILE( x ) static_cast< var_file_t * >( x )\n\nvar_file_t::var_file_t( FILE * file, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, false, src_idx, parse_ctr ), m_file( file ),\n\t  m_copied( false ) {}\nvar_file_t::~var_file_t() { if( m_file != nullptr && !m_copied ) { fclose( m_file ); } }\n\nstd::string var_file_t::type_str() const { return \"file_t\"; }\nstd::string var_file_t::to_str() const { return \"file_t\"; }\nmpz_class var_file_t::to_int() const { return m_file == nullptr ? 0 : 1; }\nbool var_file_t::to_bool() const { return m_file != nullptr; }\nvar_base_t * var_file_t::copy( const int src_idx, const int parse_ctr )\n{\n\tm_copied = true;\n\treturn new var_file_t( m_file, src_idx, parse_ctr );\n}\n\nFILE * & var_file_t::get() { return m_file; }\nbool var_file_t::is_copied() const { return m_copied; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * file_open( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tconst std::string & file = AS_STR( fcd.args[ 0 ] )->get();\n\tconst std::string & mode = AS_STR( fcd.args[ 1 ] )->get();\n\treturn new var_file_t( fopen( file.c_str(), mode.c_str() ) );\n}\n\nvar_base_t * file_open_existing( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tvar_file_t * file = AS_FILE( fcd.args[ 0 ] );\n\tconst std::string & fname = AS_STR( fcd.args[ 1 ] )->get();\n\tconst std::string & fmode = AS_STR( fcd.args[ 2 ] )->get();\n\tif( file->get() != NULL && !file->is_copied() ) {\n\t\tfclose( file->get() );\n\t}\n\tfile->get() = fopen( fname.c_str(), fmode.c_str() );\n\treturn TRUE_FALSE( file->get() != NULL );\n}\n\nvar_base_t * file_close_existing( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tvar_file_t * file = AS_FILE( fcd.args[ 0 ] );\n\tif( file->get() != NULL && !file->is_copied() ) {\n\t\tfclose( file->get() );\n\t\tfile->get() = NULL;\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * file_write( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tFILE * & f = AS_FILE( fcd.args[ 0 ] )->get();\n\tif( f == nullptr ) return vm.vars->get( \"false\" );\n\tsize_t sz = fcd.args.size();\n\tfor( size_t i = 1; i < sz; ++i ) {\n\t\tfprintf( f, \"%s\", fcd.args[ i ]->to_str().c_str() );\n\t}\n\treturn vm.vars->get( \"true\" );\n}\n\nvar_base_t * file_read( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tFILE * & f = AS_FILE( fcd.args[ 0 ] )->get();\n\tif( f == nullptr ) return vm.vars->get( \"false\" );\n\n\tchar * line = NULL;\n\tsize_t len = 0;\n\tssize_t read;\n\tstd::string line_str;\n\n\tif( ( read = getline( & line, & len, f ) ) == -1 ) {\n\t\tif( line ) free( line );\n\t\treturn vm.vars->get( \"false\" );\n\t}\n\n\tline_str = line;\n\tif( line_str.size() > 0 && line_str.back() == '\\n' ) {\n\t\tline_str.erase( line_str.end() - 1 );\n\t}\n\tfree( line );\n\n\tAS_STR( fcd.args[ 1 ] )->get() = line_str;\n\n\treturn vm.vars->get( \"true\" );\n}\n\nvar_base_t * file_read_full( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tFILE * & f = AS_FILE( fcd.args[ 0 ] )->get();\n\tif( f == nullptr ) return vm.vars->get( \"false\" );\n\n\tchar * line = NULL;\n\tsize_t len = 0;\n\tssize_t read;\n\tstd::vector< var_base_t * > lines;\n\tstd::string line_str;\n\n\twhile( ( read = getline( & line, & len, f ) ) != -1 ) {\n\t\tline_str = line;\n\t\tif( line_str.size() > 0 && line_str.back() == '\\n' ) {\n\t\t\tline_str.erase( line_str.end() - 1 );\n\t\t}\n\t\tlines.push_back( new var_str_t( line_str ) );\n\t}\n\n\tif( line ) free( line );\n\n\tAS_VEC( fcd.args[ 1 ] )->clear();\n\tAS_VEC( fcd.args[ 1 ] )->get() = lines;\n\n\treturn vm.vars->get( \"true\" );\n}\n\nvar_base_t * is_open( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( AS_FILE( fcd.args[ 0 ] )->get() != NULL );\n}\n\nvoid get_entries_internal( const std::string & dir_str, std::vector< var_base_t * > & v,\n\t\t\t   const size_t & flags, const int src_idx, const int parse_ctr,\n\t\t\t   const std::regex & regex )\n{\n\tDIR * dir;\n\tstruct dirent * ent;\n\tif( ( dir = opendir( dir_str.c_str() ) ) == NULL ) return;\n\n\twhile( ( ent = readdir( dir ) ) != NULL ) {\n\t\tif( strcmp( ent->d_name, \".\" ) == 0 || strcmp( ent->d_name, \"..\" ) == 0 ) continue;\n\t\tstd::string entry = dir_str + ent->d_name;\n\t\tif( ( !( flags & FSEnt::RECURSE ) || ent->d_type != DT_DIR ) && !std::regex_match( entry, regex ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif( ent->d_type == DT_DIR ) {\n\t\t\tif( flags & FSEnt::RECURSE ) {\n\t\t\t\tget_entries_internal( entry + \"/\", v, flags, src_idx, parse_ctr, regex );\n\t\t\t} else if( flags & FSEnt::DIRS ) {\n\t\t\t\tv.push_back( new var_str_t( entry, src_idx, parse_ctr ) );\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif( flags & FSEnt::FILES || flags & FSEnt::RECURSE ) {\n\t\t\tv.push_back( new var_str_t( entry, src_idx, parse_ctr ) );\n\t\t}\n\t}\n\tclosedir( dir );\n}\n\nvar_base_t * get_entries( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > v;\n\tstd::string dir_str = AS_STR( fcd.args[ 1 ] )->get();\n\tsize_t flags = fcd.args.size() <= 2 ? 1 : mpz_to_size_t( AS_INT( fcd.args[ 2 ] )->get() );\n\tstd::string regex_str = fcd.args.size() <= 3 ? \"(.*)\" : fcd.args[ 3 ]->to_str();\n\tstd::regex regex( regex_str );\n\tif( dir_str.size() > 0 && dir_str.back() != '/' ) dir_str += \"/\";\n\tget_entries_internal( dir_str, v, flags, fcd.src_idx, fcd.parse_ctr, regex );\n\treturn new var_vec_t( v );\n}\n\nvar_base_t * _exists( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( access( fcd.args[ 1 ]->to_str().c_str(), F_OK ) != -1 );\n}\n\nvar_base_t * _remove( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( exec_internal( \"rm -rf \" + fcd.args[ 1 ]->to_str() ) == 0 );\n}\n\nREGISTER_MODULE( fs )\n{\n\tvm.funcs.add( { \"fopen\", 2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = file_open }, true } );\n\n\tfunctions_t & ft = vm.typefuncs[ \"file_t\" ];\n\tft.add( { \"reopen\", 2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = file_open_existing }, false } );\n\tft.add( { \"close\", 0, 0, {}, FnType::MODULE, { .modfn = file_close_existing }, false } );\n\tft.add( { \"write\", 1, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = file_write }, false } );\n\tft.add( { \"read\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = file_read }, false } );\n\tft.add( { \"read_all\", 1, 1, { \"vec\" }, FnType::MODULE, { .modfn = file_read_full }, false } );\n\tft.add( { \"is_open\", 0, 0, {}, FnType::MODULE, { .modfn = is_open }, false } );\n\n\tfunctions_t & fst = vm.typefuncs[ \"_fs_t\" ];\n\tfst.add( { \"dir_entries\", 1, 3, { \"str\", \"int\", \"str\" }, FnType::MODULE, { .modfn = get_entries }, true } );\n\tfst.add( { \"exists\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = _exists }, false } );\n\tfst.add( { \"remove\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = _remove }, false } );\n}\n\nint exec_internal( const std::string & cmd )\n{\n\tFILE * pipe = popen( cmd.c_str(), \"r\" );\n\tif( !pipe ) return 1;\n\tchar * line = NULL;\n\tsize_t len = 0;\n\tssize_t nread;\n\n\twhile( ( nread = getline( & line, & len, pipe ) ) != -1 );\n\tfree( line );\n\tint res = pclose( pipe );\n\treturn WEXITSTATUS( res );\n}"
  },
  {
    "path": "modules/std/map.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../../src/VM/Core.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////// Classes ///////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\ntypedef std::unordered_map< std::string, var_base_t * >::iterator map_iter_t;\n\nclass var_map_iter_t : public var_base_t\n{\n\tmap_iter_t m_it;\n\tvar_map_t * m_map;\npublic:\n\tvar_map_iter_t( var_map_t * map, map_iter_t it, bool inc_ref = true, const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_map_iter_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tvar_map_t * & get();\n\tmap_iter_t & iter();\n};\n#define AS_MAP_ITER( x ) static_cast< var_map_iter_t * >( x )\n\nvar_map_iter_t::var_map_iter_t( var_map_t * map, map_iter_t it, bool inc_ref, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_it( it ), m_map( map )\n{ if( inc_ref ) VAR_IREF( m_map ); it = map->get().begin(); }\nvar_map_iter_t::~var_map_iter_t() { VAR_DREF( m_map ); }\n\nstd::string var_map_iter_t::type_str() const { return \"map_iter_t\"; }\nstd::string var_map_iter_t::to_str() const\n{\n\treturn m_it->first;\n}\nmpz_class var_map_iter_t::to_int() const { return 1; }\nbool var_map_iter_t::to_bool() const { return m_it != m_map->get().end(); }\nvar_base_t * var_map_iter_t::copy( const int src_idx, const int parse_ctr )\n{\n\treturn new var_map_iter_t( m_map, m_it, true, src_idx, parse_ctr );\n}\nvoid var_map_iter_t::assn( var_base_t * b )\n{\n\tm_it = AS_MAP_ITER( b )->iter();\n\tVAR_DREF( m_map );\n\tvar_map_t * map = AS_MAP_ITER( b )->get();\n\tVAR_IREF( map );\n\tm_map = map;\n}\nvar_map_t * & var_map_iter_t::get() { return m_map; }\nmap_iter_t & var_map_iter_t::iter() { return m_it; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * insert( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::unordered_map< std::string, var_base_t * > & map = AS_MAP( fcd.args[ 0 ] )->get();\n\tstd::string & key = AS_STR( fcd.args[ 1 ] )->get();\n\tif( map.find( key ) != map.end() ) {\n\t\tVAR_DREF( map[ key ] );\n\t}\n\tmap[ key ] = fcd.args[ 2 ]->copy( fcd.src_idx, fcd.parse_ctr );\n\treturn nullptr;\n}\n\nvar_base_t * _delete( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::unordered_map< std::string, var_base_t * > & map = AS_MAP( fcd.args[ 0 ] )->get();\n\tstd::string & key = AS_STR( fcd.args[ 1 ] )->get();\n\tif( map.find( key ) != map.end() ) {\n\t\tVAR_DREF( map[ key ] );\n\t\tmap.erase( key );\n\t\treturn vm.vars->get( \"true\" );\n\t}\n\treturn vm.vars->get( \"false\" );\n}\n\nvar_base_t * get( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::unordered_map< std::string, var_base_t * > & map = AS_MAP( fcd.args[ 0 ] )->get();\n\tstd::string & key = AS_STR( fcd.args[ 1 ] )->get();\n\tif( map.find( key ) != map.end() ) {\n\t\treturn map[ key ];\n\t}\n\treturn vm.nil;\n}\n\nvar_base_t * len( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( ( int )AS_MAP( fcd.args[ 0 ] )->get().size() );\n}\n\nvar_base_t * clear( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tAS_MAP( fcd.args[ 0 ] )->clear();\n\treturn nullptr;\n}\n\nvar_base_t * find( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::unordered_map< std::string, var_base_t * > & map = AS_MAP( fcd.args[ 0 ] )->get();\n\tstd::string key = fcd.args[ 1 ]->to_str();\n\treturn TRUE_FALSE( map.find( key ) != map.end() );\n}\n\nvar_base_t * iter( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_map_iter_t( AS_MAP( fcd.args[ 0 ] ), AS_MAP( fcd.args[ 0 ] )->get().begin() );\n}\n\nvar_base_t * next( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tvar_map_iter_t * it = AS_MAP_ITER( fcd.args[ 0 ] );\n\tstd::unordered_map< std::string, var_base_t * > & map = it->get()->get();\n\tmap_iter_t & pos = it->iter();\n\tif( pos == map.end() ) return vm.nil;\n\tVAR_IREF( pos->second );\n\tvar_tuple_t * tup = new var_tuple_t( {\n\t\tnew var_str_t( pos->first, fcd.parse_ctr ),\n\t\tpos->second\n\t} );\n\t++pos;\n\treturn tup;\n}\n\nREGISTER_MODULE( map )\n{\n\tfunctions_t & mapfns = vm.typefuncs[ \"map\" ];\n\n\tmapfns.add( { \"_insert\", 2, 2, { \"str\", \"_any_\" }, FnType::MODULE, { .modfn = insert }, false } );\n\tmapfns.add( { \"_delete\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = _delete }, false } );\n\tmapfns.add( { \"get\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = get }, false } );\n\tmapfns.add( { \"len\", 0, 0, {}, FnType::MODULE, { .modfn = len }, true } );\n\tmapfns.add( { \"clear\", 0, 0, {}, FnType::MODULE, { .modfn = clear }, false } );\n\tmapfns.add( { \"_find\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = find }, false } );\n\tmapfns.add( { \"iter\", 0, 0, {}, FnType::MODULE, { .modfn = iter }, true } );\n\n\tfunctions_t & mapiterfns = vm.typefuncs[ \"map_iter_t\" ];\n\tmapiterfns.add( { \"next\", 0, 0, {}, FnType::MODULE, { .modfn = next }, true } );\n}\n"
  },
  {
    "path": "modules/std/math.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../../src/VM/Core.hpp\"\n\nstatic mpz_class factorial( const mpz_class & of );\nstatic mpfr::mpreal high_precision_logn( const mpz_class & num, mpfr::mpreal precision );\n\nvar_base_t * flt_is_nan( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 0 ] )->get();\n\treturn TRUE_FALSE( mpfr::isnan( num ) );\n}\n\nvar_base_t * _abs_int( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & a = AS_INT( fcd.args[ 1 ] )->get();\n\treturn new var_int_t( a >= 0 ? a : -a );\n}\n\nvar_base_t * _abs_flt( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & a = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( a >= 0.0 ? a : -a );\n}\n\nvar_base_t * _ceil( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & a = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_int_t( mpfr::ceil( a ) );\n}\n\nvar_base_t * _floor( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & a = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_int_t( mpfr::floor( a ) );\n}\n\nvar_base_t * _sqrt( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & a = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::sqrt( a ) );\n}\n\nvar_base_t * _log( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\tmpfr::mpreal base = fcd.args.size() > 2 ? AS_FLT( fcd.args[ 2 ] )->get() : 10;\n\n\tif( num < 1 || base < 2 ) {\n\t\tmpfr::mpreal tmp;\n\t\ttmp.setNan();\n\t\treturn new var_flt_t( tmp );\n\t}\n\n\treturn new var_flt_t( mpfr::log( num ) / mpfr::log( base ) );\n}\n\nvar_base_t * _sin( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::sin( num ) );\n}\n\nvar_base_t * _cos( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::cos( num ) );\n}\n\nvar_base_t * _tan( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::tan( num ) );\n}\n\nvar_base_t * _csc( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::csc( num ) );\n}\n\nvar_base_t * _sec( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::sec( num ) );\n}\n\nvar_base_t * _cot( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::cot( num ) );\n}\n\nvar_base_t * _asin( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::asin( num ) );\n}\n\nvar_base_t * _acos( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::acos( num ) );\n}\n\nvar_base_t * _atan( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::atan( num ) );\n}\n\nvar_base_t * _acsc( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::acsc( num ) );\n}\n\nvar_base_t * _asec( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::asec( num ) );\n}\n\nvar_base_t * _acot( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal & num = AS_FLT( fcd.args[ 1 ] )->get();\n\treturn new var_flt_t( mpfr::acot( num ) );\n}\n\nvar_base_t * calc_e( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal precision = \"0.\" + std::string( get_float_precision() + 1, '0' ) + \"1\";\n\n\tmpfr::mpreal res = 0.0;\n\t// 1/0! + 1/1! + 1/2! + 1/3! + 1/4! ...\n\tmpfr::mpreal delta = 1;\n\tfor( mpz_class i = 1; delta > precision; ++i ) {\n\t\tres += delta;\n\t\tdelta /= i.get_mpz_t();\n\t}\n\treturn new var_flt_t( res );\n}\n\nvar_base_t * calc_pi( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpfr::mpreal precision = \"0.\" + std::string( get_float_precision() + 1, '0' ) + \"1\";\n\n\tmpfr::mpreal res = 0.0;\n\t// 1 - 1/3 + 1/5 - 1/7 + 1/9 ...\n\tmpfr::mpreal delta = 1;\n\tfor( mpfr::mpreal i = 1; delta > precision; i += 2 ) {\n\t\tres += 1.0 / i;\n\t\tdelta /= i;\n\t}\n\treturn new var_flt_t( res );\n}\n\nREGISTER_MODULE( math )\n{\n\tvm.funcs.add( { \"math_calc_e\",  0, 0, {}, FnType::MODULE, { .modfn = calc_e  }, true } );\n\tvm.funcs.add( { \"math_calc_pi\", 0, 0, {}, FnType::MODULE, { .modfn = calc_pi }, true } );\n\n\tfunctions_t & fltfns = vm.typefuncs[ \"flt\" ];\n\tfltfns.add( { \"is_nan\", 0, 0, {}, FnType::MODULE, { .modfn = flt_is_nan }, false } );\n\n\tfunctions_t & mathfns = vm.typefuncs[ \"_math_t\" ];\n\tmathfns.add( { \"abs\",   1, 1, { \"int\" }, FnType::MODULE, { .modfn = _abs_int }, true } );\n\tmathfns.add( { \"abs\",   1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _abs_flt }, true } );\n\tmathfns.add( { \"ceil\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _ceil }, true } );\n\tmathfns.add( { \"floor\", 1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _floor }, true } );\n\tmathfns.add( { \"sqrt\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _sqrt }, true } );\n\tmathfns.add( { \"log\",   1, 2, { \"flt\", \"flt\" }, FnType::MODULE, { .modfn = _log }, true } );\n\tmathfns.add( { \"sin\",   1, 1, { \"flt\" }, FnType::MODULE, { .modfn =  _sin }, true } );\n\tmathfns.add( { \"cos\",   1, 1, { \"flt\" }, FnType::MODULE, { .modfn =  _cos }, true } );\n\tmathfns.add( { \"tan\",   1, 1, { \"flt\" }, FnType::MODULE, { .modfn =  _tan }, true } );\n\tmathfns.add( { \"csc\",   1, 1, { \"flt\" }, FnType::MODULE, { .modfn =  _csc }, true } );\n\tmathfns.add( { \"sec\",   1, 1, { \"flt\" }, FnType::MODULE, { .modfn =  _sec }, true } );\n\tmathfns.add( { \"cot\",   1, 1, { \"flt\" }, FnType::MODULE, { .modfn =  _cot }, true } );\n\tmathfns.add( { \"asin\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _asin }, true } );\n\tmathfns.add( { \"acos\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _acos }, true } );\n\tmathfns.add( { \"atan\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _atan }, true } );\n\tmathfns.add( { \"acsc\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _acsc }, true } );\n\tmathfns.add( { \"asec\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _asec }, true } );\n\tmathfns.add( { \"acot\",  1, 1, { \"flt\" }, FnType::MODULE, { .modfn = _acot }, true } );\n}\n\nstatic mpz_class factorial( const mpz_class & of )\n{\n\tmpz_class fact = 1;\n\tfor( mpz_class i = 2; i <= of; ++i ) fact *= i;\n\treturn fact;\n}\n"
  },
  {
    "path": "modules/std/opt.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../../src/VM/Core.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////// Class ////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass var_opt_t : public var_base_t\n{\n\tvar_base_t * m_val;\npublic:\n\tvar_opt_t( var_base_t * val, const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_opt_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid clear();\n\tvoid assn( var_base_t * b );\n\tvar_base_t * & get();\n};\n#define AS_OPT( x ) static_cast< var_opt_t * >( x )\n\nvar_opt_t::var_opt_t( var_base_t * val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_val( val )\n{ if( m_val ) VAR_IREF( m_val ); }\nvar_opt_t::~var_opt_t() { if( m_val ) VAR_DREF( m_val ); }\n\nstd::string var_opt_t::type_str() const { return \"opt_t\"; }\nstd::string var_opt_t::to_str() const\n{\n\tstd::string str = \"opt_t{\";\n\tif( m_val == nullptr ) str += \"null}\";\n\telse str += m_val->to_str() + \"}\";\n\treturn str;\n}\nmpz_class var_opt_t::to_int() const { return m_val == nullptr ? 0 : 1; }\nbool var_opt_t::to_bool() const { return m_val != nullptr; }\nvar_base_t * var_opt_t::copy( const int src_idx, const int parse_ctr )\n{\n\treturn new var_opt_t( m_val, src_idx, parse_ctr );\n}\nvoid var_opt_t::clear() { if( m_val ) { VAR_DREF( m_val ); m_val = nullptr; } }\nvoid var_opt_t::assn( var_base_t * b )\n{\n\tVAR_DREF( m_val );\n\tm_val = AS_OPT( b )->get();\n\tVAR_IREF( m_val );\n}\nvar_base_t * & var_opt_t::get() { return m_val; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * opt_create( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_opt_t( nullptr );\n}\n\nvar_base_t * opt_empty( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( AS_OPT( fcd.args[ 0 ] )->get() == nullptr );\n}\n\nvar_base_t * opt_clear( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tAS_OPT( fcd.args[ 0 ] )->clear();\n\treturn nullptr;\n}\n\nvar_base_t * opt_set( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tAS_OPT( fcd.args[ 0 ] )->clear();\n\tAS_OPT( fcd.args[ 0 ] )->get() = fcd.args[ 1 ]->copy( fcd.src_idx, fcd.parse_ctr );\n\treturn AS_OPT( fcd.args[ 0 ] )->get();\n}\n\nvar_base_t * opt_get( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn AS_OPT( fcd.args[ 0 ] )->get();\n}\n\nREGISTER_MODULE( opt )\n{\n\tvm.funcs.add( { \"opt_new\", 0, 0, {}, FnType::MODULE, { .modfn = opt_create }, true } );\n\n\tfunctions_t & opt = vm.typefuncs[ \"opt_t\" ];\n\topt.add( { \"empty\", 0, 0, {}, FnType::MODULE, { .modfn = opt_empty }, false } );\n\topt.add( { \"clear\", 0, 0, {}, FnType::MODULE, { .modfn = opt_clear }, false } );\n\topt.add( { \"set\",   1, 1, { \"_any_\" }, FnType::MODULE, { .modfn = opt_set }, false } );\n\topt.add( { \"get\",   0, 0, {}, FnType::MODULE, { .modfn = opt_get }, false } );\n}"
  },
  {
    "path": "modules/std/os.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <chrono>\n#include <thread>\n#include <cstdlib>\n#include <sys/wait.h>\n\n#include \"../../src/VM/Core.hpp\"\n\nint exec_internal( const std::string & file );\nstd::string dir_part( const std::string & full_loc );\n\nvar_base_t * sleep_custom( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::this_thread::sleep_for(\n\t\tstd::chrono::milliseconds( fcd.args[ 1 ]->to_int().get_ui() )\n\t);\n\treturn nullptr;\n}\n\nvar_base_t * get_env( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string var = fcd.args[ 1 ]->to_str();\n\tconst char * env = getenv( var.c_str() );\n\treturn new var_str_t( env == NULL ? \"\" : env );\n}\n\nvar_base_t * set_env( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string var = fcd.args[ 1 ]->to_str();\n\tstd::string val = fcd.args[ 2 ]->to_str();\n\n\tbool overwrite = false;\n\tif( fcd.args.size() > 3 ) overwrite = fcd.args[ 3 ]->to_bool();\n\treturn new var_int_t( setenv( var.c_str(), val.c_str(), overwrite ) );\n}\n\nvar_base_t * exec_custom( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string cmd = fcd.args[ 1 ]->to_str();\n\n\tFILE * pipe = popen( cmd.c_str(), \"r\" );\n\tif( !pipe ) return new var_int_t( 1 );\n\tchar * line = NULL;\n\tsize_t len = 0;\n\tssize_t nread;\n\n\twhile( ( nread = getline( & line, & len, pipe ) ) != -1 ) {\n\t\tfprintf( stdout, \"%s\", line );\n\t}\n\tfree( line );\n\tint res = pclose( pipe );\n\n\tres = WEXITSTATUS( res );\n\treturn new var_int_t( res );\n}\n\nvar_base_t * install( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string src = AS_STR( fcd.args[ 1 ] )->get(),\n\t\t    dest = AS_STR( fcd.args[ 2 ] )->get();\n\n\tif( src.empty() || dest.empty() ) {\n\t\treturn new var_int_t( 0 );\n\t}\n\n\tif( exec_internal( \"mkdir -p \" + dest ) != 0 ) {\n\t\treturn new var_int_t( -1 );\n\t}\n\tstd::string cmd_str;\n#if __linux__ || __ANDROID__\n\tcmd_str = \"cp -r --remove-destination \" + src + \" \" + dest;\n#elif __APPLE__ || __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __bsdi__ || __DragonFly__\n\tcmd_str = \"cp -rf \" + src + \" \" + dest;\n#endif\n\treturn new var_int_t( exec_internal( cmd_str ) );\n}\n\nvar_base_t * os_get_name( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string os_str;\n#if __ANDROID__\n\tos_str = \"android\";\n#elif __linux__\n\tos_str = \"linux\";\n#elif __APPLE__\n\tos_str = \"macos\";\n#elif __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __bsdi__ || __DragonFly__\n\tos_str = \"bsd\";\n#endif\n\treturn new var_str_t( os_str, 0 );\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////// Extra Functions ///////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * os_mkdir( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string dest = fcd.args[ 1 ]->to_str();\n\n\tfor( size_t i = 2; i < fcd.args_count; ++i ) {\n\t\tstd::string tmpdest = fcd.args[ i ]->to_str();\n\t\tif( tmpdest.empty() ) continue;\n\t\tdest += \" \" + tmpdest;\n\t}\n\treturn new var_int_t( exec_internal( \"mkdir -p \" + dest ) );\n}\n\nvar_base_t * os_rm( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string dest = fcd.args[ 1 ]->to_str();\n\n\tfor( size_t i = 2; i < fcd.args_count; ++i ) {\n\t\tstd::string tmpdest = fcd.args[ i ]->to_str();\n\t\tif( tmpdest.empty() ) continue;\n\t\tdest += \" \" + tmpdest;\n\t}\n\tif( dest.empty() ) {\n\t\treturn new var_int_t( 0 );\n\t}\n\treturn new var_int_t( exec_internal( \"rm -r \" + dest ) );\n}\n\nREGISTER_MODULE( os )\n{\n\tfunctions_t & os = vm.typefuncs[ \"_os_t\" ];\n\n\tos.add( { \"sleep\", 1, 1, { \"int\" }, FnType::MODULE, { .modfn = sleep_custom }, false } );\n\tos.add( { \"get_env\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = get_env }, true } );\n\tos.add( { \"set_env\", 2, 3, { \"str\", \"str\", \"_any_\" }, FnType::MODULE, { .modfn = set_env }, true } );\n\tos.add( { \"exec\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = exec_custom }, true } );\n\tos.add( { \"install\", 2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = install }, true } );\n\n\tvm.funcs.add( { \"os_get_name\", 0, 0, {}, FnType::MODULE, { .modfn = os_get_name }, true } );\n\n\tos.add( { \"mkdir\", 1, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = os_mkdir }, true } );\n\tos.add( { \"rm\", 1, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = os_rm }, true } );\n}\n\nint exec_internal( const std::string & cmd )\n{\n\tFILE * pipe = popen( cmd.c_str(), \"r\" );\n\tif( !pipe ) return 1;\n\tchar * line = NULL;\n\tsize_t len = 0;\n\tssize_t nread;\n\n\twhile( ( nread = getline( & line, & len, pipe ) ) != -1 );\n\tfree( line );\n\tint res = pclose( pipe );\n\treturn WEXITSTATUS( res );\n}\n\nstd::string dir_part( const std::string & full_loc )\n{\n\tauto loc = full_loc.find_last_of( '/' );\n\tif( loc == std::string::npos ) return \".\";\n\tif( loc == 0 ) return \"/\";\n\treturn full_loc.substr( 0, loc );\n}"
  },
  {
    "path": "modules/std/regex.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <regex>\n\n#include \"../../src/VM/Core.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////// Class ////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass var_regex_t : public var_base_t\n{\n\tstd::string m_str;\n\tstd::regex m_expr;\npublic:\n\tvar_regex_t( const std::string & str, const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_regex_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tconst std::string & get_str();\n\tconst std::regex & get_regex();\n};\n#define AS_REGEX( x ) static_cast< var_regex_t * >( x )\n\nvar_regex_t::var_regex_t( const std::string & str, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_str( str ), m_expr( str ) {}\nvar_regex_t::~var_regex_t() {}\n\nstd::string var_regex_t::type_str() const { return \"regex_t\"; }\nstd::string var_regex_t::to_str() const\n{\n\treturn \"regex_t{\" + m_str + \"}\";\n}\nmpz_class var_regex_t::to_int() const { return m_str.size(); }\nbool var_regex_t::to_bool() const { return !m_str.empty(); }\nvar_base_t * var_regex_t::copy( const int src_idx, const int parse_ctr )\n{\n\treturn new var_regex_t( m_str, src_idx, parse_ctr );\n}\nvoid var_regex_t::assn( var_base_t * b )\n{\n\tm_str = AS_REGEX( b )->m_str;\n\tm_expr = AS_REGEX( b )->m_expr;\n}\nconst std::string & var_regex_t::get_str() { return m_str; }\nconst std::regex & var_regex_t::get_regex() { return m_expr; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * regex_create( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_regex_t( fcd.args[ 1 ]->to_str() );\n}\n\nvar_base_t * regex_match( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tif( AS_REGEX( fcd.args[ 0 ] )->get_str().empty() ) return vm.vars->get( \"true\" );\n\tbool res = std::regex_match( fcd.args[ 1 ]->to_str(), AS_REGEX( fcd.args[ 0 ] )->get_regex() );\n\treturn TRUE_FALSE( res );\n}\n\nvar_base_t * regex_empty( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( AS_REGEX( fcd.args[ 0 ] )->get_str().empty() );\n}\n\nREGISTER_MODULE( regex )\n{\n\tfunctions_t & regex_mod = vm.typefuncs[ \"_regex_t\" ];\n\tregex_mod.add( { \"build\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = regex_create }, true } );\n\n\tfunctions_t & regex = vm.typefuncs[ \"regex_t\" ];\n\tregex.add( { \"match\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = regex_match }, false } );\n\tregex.add( { \"empty\", 0, 0, {}, FnType::MODULE, { .modfn = regex_empty }, false } );\n}"
  },
  {
    "path": "modules/std/runtime.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cmath>\n\n#include \"../../src/VM/Core.hpp\"\n\nvar_base_t * func_count( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( vm.funcs.count() );\n}\n\nREGISTER_MODULE( runtime )\n{\n\tfunctions_t & runtimefns = vm.typefuncs[ \"_runtime_t\" ];\n\truntimefns.add( { \"fn_count\", 0, 0, {}, FnType::MODULE, { .modfn = func_count }, true } );\n}\n"
  },
  {
    "path": "modules/std/set.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <unordered_set>\n\n#include \"../../src/VM/Core.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////// Class ////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass var_set_t : public var_base_t\n{\n\tstd::unordered_set< std::string > m_set;\npublic:\n\tvar_set_t( std::unordered_set< std::string > set, const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_set_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tstd::unordered_set< std::string > & get();\n};\n#define AS_SET( x ) static_cast< var_set_t * >( x )\n\nvar_set_t::var_set_t( std::unordered_set< std::string > set, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_set( set ) {}\nvar_set_t::~var_set_t() {}\n\nstd::string var_set_t::type_str() const { return \"set_t\"; }\nstd::string var_set_t::to_str() const\n{\n\tstd::string str = \"set_t{\";\n\tfor( auto & s : m_set ) {\n\t\tstr += s + \", \";\n\t}\n\t// remove the extra commas\n\tif( m_set.size() > 0 ) {\n\t\tstr.pop_back();\n\t\tstr.pop_back();\n\t}\n\tstr += \"}\";\n\treturn str;\n}\nmpz_class var_set_t::to_int() const { return m_set.size(); }\nbool var_set_t::to_bool() const { return m_set.size() != 0; }\nvar_base_t * var_set_t::copy( const int src_idx, const int parse_ctr )\n{\n\treturn new var_set_t( m_set, src_idx, parse_ctr );\n}\nvoid var_set_t::assn( var_base_t * b )\n{\n\tm_set = AS_SET( b )->get();\n}\nstd::unordered_set< std::string > & var_set_t::get() { return m_set; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * set_create( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_set_t( std::unordered_set< std::string >{}, 0 );\n}\n\nvar_base_t * set_insert( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::unordered_set< std::string > & s = AS_SET( fcd.args[ 0 ] )->get();\n\tfor( size_t i = 1; i < fcd.args.size(); ++i ) {\n\t\ts.insert( fcd.args[ i ]->to_str() );\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * set_erase( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::unordered_set< std::string > & s = AS_SET( fcd.args[ 0 ] )->get();\n\tfor( size_t i = 1; i < fcd.args.size(); ++i ) {\n\t\ts.erase( fcd.args[ i ]->to_str() );\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * set_contains( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::unordered_set< std::string > & s = AS_SET( fcd.args[ 0 ] )->get();\n\treturn TRUE_FALSE( s.find( fcd.args[ 1 ]->to_str() ) != s.end() );\n}\n\nvar_base_t * set_len( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( ( int )AS_SET( fcd.args[ 0 ] )->get().size() );\n}\n\nvar_base_t * set_clear( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::unordered_set< std::string > & s = AS_SET( fcd.args[ 0 ] )->get();\n\ts.clear();\n\treturn nullptr;\n}\n\nREGISTER_MODULE( set )\n{\n\tvm.funcs.add( { \"set_create\", 0, 0, {}, FnType::MODULE, { .modfn = set_create }, true } );\n\n\tfunctions_t & st = vm.typefuncs[ \"set_t\" ];\n\tst.add( { \"insert\", 1, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = set_insert }, false } );\n\tst.add( { \"erase\", 1, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = set_erase }, false } );\n\tst.add( { \"contains\", 1, 1, { \"_any_\" }, FnType::MODULE, { .modfn = set_contains }, false } );\n\tst.add( { \"len\", 0, 0, {}, FnType::MODULE, { .modfn = set_len }, true } );\n\tst.add( { \"clear\", 0, 0, {}, FnType::MODULE, { .modfn = set_clear }, false } );\n}"
  },
  {
    "path": "modules/std/str.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cstdlib>\n#include <cctype>\n\n#include \"../../src/VM/Core.hpp\"\n\nvar_base_t * add( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string res;\n\tstd::string & a = AS_STR( fcd.args[ 1 ] )->get();\n\tstd::string & b = AS_STR( fcd.args[ 0 ] )->get();\n\tres = a + b;\n\treturn new var_str_t( res );\n}\n\nvar_base_t * add_assn( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & a = AS_STR( fcd.args[ 0 ] )->get();\n\tstd::string & b = AS_STR( fcd.args[ 1 ] )->get();\n\ta += b;\n\treturn fcd.args[ 0 ];\n}\n\nvar_base_t * at( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & str = AS_STR( fcd.args[ 0 ] )->get();\n\tsize_t sz = str.size();\n\tint idx = AS_INT( fcd.args[ 1 ] )->get().get_si();\n\tif( idx < 0 || ( size_t )idx >= sz ) {\n\t\treturn vm.nil;\n\t}\n\treturn new var_str_t( std::string( 1, str[ idx ] ) );\n}\n\nvar_base_t * hash( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn fcd.args[ 0 ];\n}\n\nvar_base_t * len( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( ( int )AS_STR( fcd.args[ 0 ] )->get().size() );\n}\n\nvar_base_t * empty( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn TRUE_FALSE( AS_STR( fcd.args[ 0 ] )->get().empty() );\n}\n\nvar_base_t * clear( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tAS_STR( fcd.args[ 0 ] )->get().clear();\n\treturn nullptr;\n}\n\nvar_base_t * is_int( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tchar * p = 0;\n\tstrtol( AS_STR( fcd.args[ 0 ] )->get().c_str(), & p, 10 );\n\treturn TRUE_FALSE( * p == 0 );\n}\n\nvar_base_t * to_int( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( AS_STR( fcd.args[ 0 ] )->get() );\n}\n\nvar_base_t * set_at( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tint idx = fcd.args[ 1 ]->to_int().get_si();\n\tif( idx < 0 || idx >= ( int )dat.size() ) return fcd.args[ 0 ];\n\tif( fcd.args[ 2 ]->to_str().size() > 0 ) dat[ idx ] = fcd.args[ 2 ]->to_str()[ 0 ];\n\treturn fcd.args[ 0 ];\n}\n\nvar_base_t * erase_at( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tint idx = fcd.args[ 1 ]->to_int().get_si();\n\tif( idx < 0 || idx >= ( int )dat.size() ) return fcd.args[ 0 ];\n\tdat.erase( dat.begin() + idx );\n\treturn fcd.args[ 0 ];\n}\n\nvar_base_t * find( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tconst std::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tif( fcd.args[ 1 ]->to_str().size() < 1 ) return vm.vars->get( \"false\" );\n\tchar to_find = fcd.args[ 1 ]->to_str()[ 0 ];\n\treturn TRUE_FALSE( dat.find( to_find ) != std::string::npos );\n}\n\nvar_base_t * front( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tconst std::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tif( dat.empty() ) return new var_str_t( \"\" );\n\treturn new var_str_t( std::string( 1, dat.front() ) );\n}\n\nvar_base_t * back( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tconst std::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tif( dat.empty() ) return new var_str_t( \"\" );\n\treturn new var_str_t( std::string( 1, dat.back() ) );\n}\n\nvar_base_t * pop_front( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tif( !dat.empty() ) dat.erase( dat.begin() );\n\treturn fcd.args[ 0 ];\n}\n\nvar_base_t * pop_back( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tif( !dat.empty() ) dat.pop_back();\n\treturn fcd.args[ 0 ];\n}\n\nvar_base_t * substr( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tconst std::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tif( dat.empty() ) return new var_str_t( \"\" );\n\tconst size_t start = fcd.args[ 1 ]->to_int().get_ui();\n\tconst size_t count = fcd.args.size() > 2 ? fcd.args[ 2 ]->to_int().get_ui() : std::string::npos;\n\tif( start >= dat.size() ) return new var_str_t( \"\" );\n\tstd::string sub = dat.substr( start, count );\n\treturn new var_str_t( sub );\n}\n\nvar_base_t * split( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tconst std::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tconst char delim = fcd.args.size() > 1 && AS_STR( fcd.args[ 1 ] )->get().size() > 0 ? AS_STR( fcd.args[ 1 ] )->get()[ 0 ] : ' ';\n\tstd::vector< std::string > res = str_delimit( dat, delim );\n\tstd::vector< var_base_t * > res_b;\n\tfor( auto & r : res ) {\n\t\tres_b.push_back( new var_str_t( r ) );\n\t}\n\treturn new var_vec_t( res_b );\n}\n\nvar_base_t * split_first( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tconst std::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tconst char delim = fcd.args.size() > 1 && AS_STR( fcd.args[ 1 ] )->get().size() > 0 ? AS_STR( fcd.args[ 1 ] )->get()[ 0 ] : ' ';\n\tstd::vector< std::string > res = str_delimit( dat, delim, true );\n\tstd::vector< var_base_t * > res_b;\n\tfor( auto & r : res ) {\n\t\tres_b.push_back( new var_str_t( r ) );\n\t}\n\treturn new var_vec_t( res_b );\n}\n\nvar_base_t * trim( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\twhile( dat.size() > 0 && isspace( dat.front() ) ) {\n\t\tdat.erase( dat.begin() );\n\t}\n\twhile( dat.size() > 0 && isspace( dat.back() ) ) {\n\t\tdat.pop_back();\n\t}\n\treturn fcd.args[ 0 ];\n}\n\n#define DECL_FUNC_BOOL__STR( name, oper )\t\t\t\t\\\n\tvar_base_t * name( vm_state_t & vm, func_call_data_t & fcd )\t\\\n\t{\t\t\t\t\t\t\t\t\\\n\t\tauto & lhs = AS_STR( fcd.args[ 1 ] )->get();\t\t\\\n\t\tauto & rhs = AS_STR( fcd.args[ 0 ] )->get();\t\t\\\n\t\treturn TRUE_FALSE( lhs oper rhs );\t\t\t\\\n\t}\n\nDECL_FUNC_BOOL__STR( eq, == )\nDECL_FUNC_BOOL__STR( ne, != )\nDECL_FUNC_BOOL__STR( lt, < )\nDECL_FUNC_BOOL__STR( le, <= )\nDECL_FUNC_BOOL__STR( gt, > )\nDECL_FUNC_BOOL__STR( ge, >= )\n\nvar_base_t * mult_lhs( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & dat = AS_STR( fcd.args[ 1 ] )->get();\n\tmpz_class & count = AS_INT( fcd.args[ 0 ] )->get();\n\n\tstd::string res;\n\tfor( mpz_class i = 0; i < count; ++i ) {\n\t\tres += dat;\n\t}\n\treturn new var_str_t( res );\n}\n\nvar_base_t * mult_rhs( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\tmpz_class & count = AS_INT( fcd.args[ 1 ] )->get();\n\n\tstd::string res;\n\tfor( mpz_class i = 0; i < count; ++i ) {\n\t\tres += dat;\n\t}\n\treturn new var_str_t( res );\n}\n\nvar_base_t * char_int_cast( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string & dat = AS_STR( fcd.args[ 0 ] )->get();\n\treturn new var_int_t( dat.size() > 0 ? dat[ 0 ] : 0 );\n}\n\nvar_base_t * int_char_cast( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tmpz_class & dat = AS_INT( fcd.args[ 0 ] )->get();\n\treturn new var_str_t( std::string( 1, dat.get_si() ) );\n}\n\nREGISTER_MODULE( str )\n{\n\t// arithmetic\n\tvm.funcs.add( { \"+\", 2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = add }, true } );\n\tvm.funcs.add( { \"+=\", 2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = add_assn }, false } );\n\tvm.funcs.add( { \"*\", 2, 2, { \"int\", \"str\" }, FnType::MODULE, { .modfn = mult_lhs }, true } );\n\tvm.funcs.add( { \"*\", 2, 2, { \"str\", \"int\" }, FnType::MODULE, { .modfn = mult_rhs }, true } );\n\n\t// comparisons\n\tvm.funcs.add( { \"==\", 2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = eq }, false } );\n\tvm.funcs.add( { \"!=\", 2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = ne }, false } );\n\tvm.funcs.add( { \"<\",  2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = lt }, false } );\n\tvm.funcs.add( { \"<=\", 2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = le }, false } );\n\tvm.funcs.add( { \">\",  2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = gt }, false } );\n\tvm.funcs.add( { \">=\", 2, 2, { \"str\", \"str\" }, FnType::MODULE, { .modfn = ge }, false } );\n\n\t// logical\n\tvm.funcs.add( { \"!\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = empty }, false } );\n\n\tfunctions_t & strfns = vm.typefuncs[ \"str\" ];\n\n\tstrfns.add( { \"[]\", 1, 1, { \"int\" }, FnType::MODULE, { .modfn = at }, true } );\n\tstrfns.add( { \"at\", 1, 1, { \"int\" }, FnType::MODULE, { .modfn = at }, true } );\n\tstrfns.add( { \"hash\", 0, 0, {}, FnType::MODULE, { .modfn = hash }, false } );\n\tstrfns.add( { \"len\", 0, 0, {}, FnType::MODULE, { .modfn = len }, true } );\n\tstrfns.add( { \"empty\", 0, 0, {}, FnType::MODULE, { .modfn = empty }, false } );\n\tstrfns.add( { \"clear\", 0, 0, {}, FnType::MODULE, { .modfn = clear }, false } );\n\tstrfns.add( { \"is_int\", 0, 0, {}, FnType::MODULE, { .modfn = is_int }, false } );\n\tstrfns.add( { \"to_int\", 0, 0, {}, FnType::MODULE, { .modfn = to_int }, true } );\n\tstrfns.add( { \"set_at\", 2, 2, { \"int\", \"str\" }, FnType::MODULE, { .modfn = set_at }, false } );\n\tstrfns.add( { \"erase_at\", 1, 1, { \"int\" }, FnType::MODULE, { .modfn = erase_at }, false } );\n\tstrfns.add( { \"find\", 1, 1, { \"str\" }, FnType::MODULE, { .modfn = find }, false } );\n\tstrfns.add( { \"front\", 0, 0, {}, FnType::MODULE, { .modfn = front }, true } );\n\tstrfns.add( { \"back\", 0, 0, {}, FnType::MODULE, { .modfn = back }, true } );\n\tstrfns.add( { \"pop_front\", 0, 0, {}, FnType::MODULE, { .modfn = pop_front }, false } );\n\tstrfns.add( { \"pop_back\", 0, 0, {}, FnType::MODULE, { .modfn = pop_back }, false } );\n\tstrfns.add( { \"substr\", 1, 2, { \"int\", \"int\" }, FnType::MODULE, { .modfn = substr }, true } );\n\tstrfns.add( { \"split\", 0, 1, { \"str\" }, FnType::MODULE, { .modfn = split }, true } );\n\tstrfns.add( { \"split_first\", 0, 1, { \"str\" }, FnType::MODULE, { .modfn = split_first }, true } );\n\tstrfns.add( { \"trim\", 0, 0, {}, FnType::MODULE, { .modfn = trim }, false } );\n\tstrfns.add( { \"int_cast\", 0, 0, {}, FnType::MODULE, { .modfn = char_int_cast }, true } );\n\n\tfunctions_t & intfns = vm.typefuncs[ \"int\" ];\n\tintfns.add( { \"char_cast\", 0, 0, {}, FnType::MODULE, { .modfn = int_char_cast }, true } );\n}\n"
  },
  {
    "path": "modules/std/term.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <sys/ioctl.h>\n\n#include \"../../src/VM/Core.hpp\"\n\nstatic std::unordered_map< std::string, const char * > COL = {\n\t{ \"0\", \"\\033[0m\" },\n\n\t{ \"r\", \"\\033[0;31m\" },\n\t{ \"g\", \"\\033[0;32m\" },\n\t{ \"y\", \"\\033[0;33m\" },\n\t{ \"b\", \"\\033[0;34m\" },\n\t{ \"m\", \"\\033[0;35m\" },\n\t{ \"c\", \"\\033[0;36m\" },\n\t{ \"w\", \"\\033[0;37m\" },\n\n\t{ \"br\", \"\\033[1;31m\" },\n\t{ \"bg\", \"\\033[1;32m\" },\n\t{ \"by\", \"\\033[1;33m\" },\n\t{ \"bb\", \"\\033[1;34m\" },\n\t{ \"bm\", \"\\033[1;35m\" },\n\t{ \"bc\", \"\\033[1;36m\" },\n\t{ \"bw\", \"\\033[1;37m\" },\n};\n\nint apply_colors( std::string & str )\n{\n\tint chars = 0;\n\tfor( size_t i = 0; i < str.size(); ) {\n\t\tif( str[ i ] == '{' && ( i == 0 || ( str[ i - 1 ] != '$' && str[ i - 1 ] != '%' && str[ i - 1 ] != '#' && str[ i - 1 ] != '\\\\' ) ) ) {\n\t\t\tstr.erase( str.begin() + i );\n\t\t\tif( i < str.size() && str[ i ] == '{' ) {\n\t\t\t\t++i;\n\t\t\t\t++chars;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tstd::string var;\n\n\t\t\twhile( i < str.size() && str[ i ] != '}' ) {\n\t\t\t\tvar += str[ i ];\n\t\t\t\tstr.erase( str.begin() + i );\n\t\t\t}\n\n\t\t\t// Remove the ending brace\n\t\t\tif( i < str.size() ) str.erase( str.begin() + i );\n\n\t\t\tif( var.empty() ) continue;\n\n\t\t\tstd::string val = COL[ var ];\n\n\t\t\tstr.insert( str.begin() + i, val.begin(), val.end() );\n\t\t\ti += val.size();\n\t\t}\n\t\telse {\n\t\t\t++i;\n\t\t\t++chars;\n\t\t}\n\t}\n\treturn chars;\n}\n\nvar_base_t * colorize( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::string data = fcd.args[ 0 ]->to_str();\n\tapply_colors( data );\n\treturn new var_str_t( data );\n}\n\nvar_base_t * col_print( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tint chars = 0;\n\tfor( auto & v : fcd.args ) {\n\t\tstd::string data = v->to_str();\n\t\tchars += apply_colors( data );\n\t\tfprintf( stdout, \"%s\", data.c_str() );\n\t}\n\treturn new var_int_t( chars );\n}\n\nvar_base_t * col_println( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tint chars = 0;\n\tfor( auto & v : fcd.args ) {\n\t\tstd::string data = v->to_str();\n\t\tchars += apply_colors( data );\n\t\tfprintf( stdout, \"%s\", data.c_str() );\n\t}\n\tfprintf( stdout, \"\\n\" );\n\t// + 1 for newline\n\treturn new var_int_t( chars + 1 );\n}\n\nvar_base_t * term_size( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tint rows = 80, cols = 24;\n\n#ifdef TIOCGSIZE\n\tstruct ttysize ts;\n\tioctl( 0, TIOCGSIZE, & ts );\n\tcols = ts.ts_cols;\n\trows = ts.ts_lines;\n#elif defined TIOCGWINSZ\n\tstruct winsize ws;\n\tioctl( 0, TIOCGWINSZ, & ws );\n\tcols = ws.ws_col;\n\trows = ws.ws_row;\n#endif /* TIOCGSIZE */\n\n\tstd::unordered_map< std::string, var_base_t * > term_sz = {\n\t\t{ \"rows\", new var_int_t( rows, fcd.parse_ctr ) },\n\t\t{ \"cols\", new var_int_t( cols, fcd.parse_ctr ) }\n\t};\n\t// _term_size_t struct is defined in include/ethereal/term.et\n\treturn new var_struct_t( \"_term_size_t\", term_sz );\n}\n\nREGISTER_MODULE( term )\n{\n\tvm.funcs.add( { \"colorize\", 1,  1, { \"str\" }, FnType::MODULE, { .modfn = colorize }, true } );\n\tvm.funcs.add( { \"cprint\",   1, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = col_print }, true } );\n\tvm.funcs.add( { \"cprintln\", 0, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = col_println }, true } );\n\n\tfunctions_t & termfns = vm.typefuncs[ \"_term_t\" ];\n\ttermfns.add( { \"size\", 0,  0, {}, FnType::MODULE, { .modfn = term_size }, true } );\n}\n"
  },
  {
    "path": "modules/std/threads.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <thread>\n#include <future>\n#include <chrono>\n#include <mutex>\n#include <sstream>\n#include <sys/wait.h>\n\n#include \"../../src/VM/Core.hpp\"\n\nint exec_command( std::string cmd );\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////// Class ////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass var_thread_t : public var_base_t\n{\n\tstd::thread * m_thread;\n\tstd::shared_future< int > m_res;\n\tbool m_copied;\n\tint m_id;\npublic:\n\tvar_thread_t( std::thread * thread, std::shared_future< int > & res, const int id,\n\t\t      const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_thread_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tbool is_copied() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tstd::thread * & get_thread();\n\tstd::shared_future< int > & get_future();\n\tint get_id();\n\n};\n#define AS_THREAD( x ) static_cast< var_thread_t * >( x )\n\nvar_thread_t::var_thread_t( std::thread * thread, std::shared_future< int > & res, const int id,\n\t\t\t    const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_thread( thread ), m_res( res ),\n\t  m_id( id ), m_copied( false ) {}\nvar_thread_t::~var_thread_t() { if( m_thread != nullptr && !m_copied ) { m_thread->join(); delete m_thread; } }\n\nstd::string var_thread_t::type_str() const { return \"thread_t\"; }\nstd::string var_thread_t::to_str() const\n{\n\tstd::ostringstream oss;\n\toss << m_thread->get_id();\n\treturn oss.str();\n}\n\nmpz_class var_thread_t::to_int() const { return m_res.valid() ? 1 : 0; }\nbool var_thread_t::to_bool() const { return m_res.valid(); }\nvar_base_t * var_thread_t::copy( const int src_idx, const int parse_ctr )\n{\n\tm_copied = true;\n\treturn new var_thread_t( m_thread, m_res, m_id, src_idx, parse_ctr );\n}\nvoid var_thread_t::assn( var_base_t * b )\n{\n\tm_thread = AS_THREAD( b )->m_thread;\n\tAS_THREAD( b )->m_copied = true;\n\tm_res = AS_THREAD( b )->m_res;\n}\n\nstd::thread * & var_thread_t::get_thread() { return m_thread; }\nstd::shared_future< int > & var_thread_t::get_future() { return m_res; }\nint var_thread_t::get_id() { return m_id; }\nbool var_thread_t::is_copied() const { return m_copied; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * threads_get_nproc( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( ( size_t )std::thread::hardware_concurrency() );\n}\n\nvar_base_t * thread_new_exec( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::packaged_task< int( std::string ) > task( exec_command );\n\tstd::shared_future< int > fut( task.get_future() );\n\tint id = fcd.args.size() > 2 ? fcd.args[ 2 ]->to_int().get_si() : -1;\n\treturn new var_thread_t( new std::thread( std::move( task ), fcd.args[ 1 ]->to_str() ), fut, id );\n}\n\nvar_base_t * thread_get_id( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( AS_THREAD( fcd.args[ 0 ] )->get_id() );\n}\n\nvar_base_t * thread_is_done( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::shared_future< int > & fut = AS_THREAD( fcd.args[ 0 ] )->get_future();\n\treturn TRUE_FALSE( fut.valid() && fut.wait_for( std::chrono::seconds( 0 ) ) == std::future_status::ready );\n}\n\nvar_base_t * thread_get_res( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::shared_future< int > & fut = AS_THREAD( fcd.args[ 0 ] )->get_future();\n\tif( !fut.valid() || fut.wait_for( std::chrono::seconds( 0 ) ) != std::future_status::ready ) return vm.nil;\n\treturn new var_int_t( fut.get() );\n}\n\nREGISTER_MODULE( threads )\n{\n\tvm.funcs.add( { \"threads_get_nproc\", 0, 0, {}, FnType::MODULE, { .modfn = threads_get_nproc }, true } );\n\n\tfunctions_t & threadsfns = vm.typefuncs[ \"_threads_t\" ];\n\tthreadsfns.add( { \"new_exec\", 1, 2, { \"str\", \"int\" }, FnType::MODULE, { .modfn = thread_new_exec }, true } );\n\n\tfunctions_t & threadfns = vm.typefuncs[ \"thread_t\" ];\n\tthreadfns.add( { \"id\", 0, 0, {}, FnType::MODULE, { .modfn = thread_get_id }, true } );\n\tthreadfns.add( { \"done\", 0, 0, {}, FnType::MODULE, { .modfn = thread_is_done }, false } );\n\tthreadfns.add( { \"res\", 0, 0, {}, FnType::MODULE, { .modfn = thread_get_res }, true } );\n}\n\n// Required because popen() and pclose() are not seemingly threadsafe\nstatic std::mutex pipe_mtx;\n\nint exec_command( std::string cmd )\n{\n\tFILE * pipe = NULL;\n\t{\n\t\tstd::lock_guard< std::mutex > lock( pipe_mtx );\n\t\tpipe = popen( cmd.c_str(), \"r\" );\n\t}\n\tif( !pipe ) return 1;\n\tchar * line = NULL;\n\tsize_t len = 0;\n\tssize_t nread;\n\n\twhile( ( nread = getline( & line, & len, pipe ) ) != -1 ) {\n\t\tfprintf( stdout, \"%s\", line );\n\t}\n\n\tfree( line );\n\tint res = 0;\n\t{\n\t\tstd::lock_guard< std::mutex > lock( pipe_mtx );\n\t\tres = pclose( pipe );\n\t}\n\tint exit_code = WEXITSTATUS( res );\n\treturn WEXITSTATUS( res );\n}\n"
  },
  {
    "path": "modules/std/time.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <chrono>\n\n#include \"../../src/VM/Core.hpp\"\n\ntypedef std::chrono::high_resolution_clock::time_point time_point_t;\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////// Classes ///////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass var_time_point_t : public var_base_t\n{\n\ttime_point_t m_time;\npublic:\n\tvar_time_point_t( const time_point_t & time, const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_time_point_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\ttime_point_t & get();\n};\n#define AS_TIME_POINT( x ) static_cast< var_time_point_t * >( x )\n\nvar_time_point_t::var_time_point_t( const time_point_t & time, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_time( time ) {}\nvar_time_point_t::~var_time_point_t() {}\n\nstd::string var_time_point_t::type_str() const { return \"time_point_t\"; }\nstd::string var_time_point_t::to_str() const\n{\n\treturn std::to_string( std::chrono::duration_cast< std::chrono::seconds >( m_time.time_since_epoch() ).count() );\n}\nmpz_class var_time_point_t::to_int() const { return ( size_t )std::chrono::duration_cast< std::chrono::seconds >( m_time.time_since_epoch() ).count(); }\nbool var_time_point_t::to_bool() const { return true; }\nvar_base_t * var_time_point_t::copy( const int src_idx, const int parse_ctr )\n{\n\treturn new var_time_point_t( m_time, src_idx, parse_ctr );\n}\nvoid var_time_point_t::assn( var_base_t * b )\n{\n\tm_time = AS_TIME_POINT( b )->get();\n}\ntime_point_t & var_time_point_t::get() { return m_time; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * time_now( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_time_point_t( std::chrono::high_resolution_clock::now() );\n}\n\nvar_base_t * time_to_hrs( vm_state_t & vm, func_call_data_t & fcd )\n{\n\ttime_point_t & time = AS_TIME_POINT( fcd.args[ 0 ] )->get();\n\treturn new var_int_t( ( size_t )std::chrono::duration_cast< std::chrono::hours >( time.time_since_epoch() ).count() );\n}\n\nvar_base_t * time_to_mins( vm_state_t & vm, func_call_data_t & fcd )\n{\n\ttime_point_t & time = AS_TIME_POINT( fcd.args[ 0 ] )->get();\n\treturn new var_int_t( ( size_t )std::chrono::duration_cast< std::chrono::minutes >( time.time_since_epoch() ).count() );\n}\n\nvar_base_t * time_to_secs( vm_state_t & vm, func_call_data_t & fcd )\n{\n\ttime_point_t & time = AS_TIME_POINT( fcd.args[ 0 ] )->get();\n\treturn new var_int_t( ( size_t )std::chrono::duration_cast< std::chrono::seconds >( time.time_since_epoch() ).count() );\n}\n\nvar_base_t * time_to_msecs( vm_state_t & vm, func_call_data_t & fcd )\n{\n\ttime_point_t & time = AS_TIME_POINT( fcd.args[ 0 ] )->get();\n\treturn new var_int_t( ( size_t )std::chrono::duration_cast< std::chrono::milliseconds >( time.time_since_epoch() ).count() );\n}\n\nvar_base_t * time_to_usecs( vm_state_t & vm, func_call_data_t & fcd )\n{\n\ttime_point_t & time = AS_TIME_POINT( fcd.args[ 0 ] )->get();\n\treturn new var_int_t( ( size_t )std::chrono::duration_cast< std::chrono::microseconds >( time.time_since_epoch() ).count() );\n}\n\nvar_base_t * time_diff( vm_state_t & vm, func_call_data_t & fcd )\n{\n\ttime_point_t & time1 = AS_TIME_POINT( fcd.args[ 1 ] )->get();\n\ttime_point_t & time2 = AS_TIME_POINT( fcd.args[ 0 ] )->get();\n\treturn new var_time_point_t( time_point_t( time1 - time2 ) );\n}\n\nREGISTER_MODULE( time )\n{\n\tfunctions_t & timemodfns = vm.typefuncs[ \"_time_t\" ];\n\ttimemodfns.add( { \"now\", 0,  0, {}, FnType::MODULE, { .modfn = time_now }, true } );\n\n\tfunctions_t & timefns = vm.typefuncs[ \"time_point_t\" ];\n\ttimefns.add( { \"hours\", 0,  0, {}, FnType::MODULE, { .modfn = time_to_hrs }, true } );\n\ttimefns.add( { \"mins\",  0,  0, {}, FnType::MODULE, { .modfn = time_to_mins }, true } );\n\ttimefns.add( { \"secs\",  0,  0, {}, FnType::MODULE, { .modfn = time_to_secs }, true } );\n\ttimefns.add( { \"msecs\", 0,  0, {}, FnType::MODULE, { .modfn = time_to_msecs }, true } );\n\ttimefns.add( { \"usecs\", 0,  0, {}, FnType::MODULE, { .modfn = time_to_usecs }, true } );\n\n\tvm.funcs.add( { \"-\", 2,  2, { \"time_point_t\", \"time_point_t\" }, FnType::MODULE, { .modfn = time_diff }, true } );\n}"
  },
  {
    "path": "modules/std/tuple.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../../src/VM/Core.hpp\"\n\nvar_base_t * make_tuple( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > v;\n\tfor( auto & x : fcd.args ) {\n\t\tv.push_back( x->copy( fcd.src_idx, fcd.parse_ctr ) );\n\t}\n\treturn new var_tuple_t( v );\n}\n\nvar_base_t * eqt( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & a = AS_TUPLE( fcd.args[ 1 ] )->get();\n\tstd::vector< var_base_t * > & b = AS_TUPLE( fcd.args[ 0 ] )->get();\n\tif( a.size() != b.size() ) return vm.vars->get( \"false\" );\n\tfor( auto i1 = a.begin(), i2 = b.begin(); i1 != a.end() && i2 != b.end(); ++i1, ++i2 ) {\n\t\tif( ( * i1 )->to_str() != ( * i2 )->to_str() ) return vm.vars->get( \"false\" );\n\t}\n\treturn vm.vars->get( \"true\" );\n}\n\nvar_base_t * net( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & a = AS_TUPLE( fcd.args[ 1 ] )->get();\n\tstd::vector< var_base_t * > & b = AS_TUPLE( fcd.args[ 0 ] )->get();\n\tif( a.size() != b.size() ) return vm.vars->get( \"true\" );\n\tfor( auto i1 = a.begin(), i2 = b.begin(); i1 != a.end() && i2 != b.end(); ++i1, ++i2 ) {\n\t\tif( ( * i1 )->to_str() != ( * i2 )->to_str() ) return vm.vars->get( \"true\" );\n\t}\n\treturn vm.vars->get( \"false\" );\n}\n\nREGISTER_MODULE( tuple )\n{\n\tvm.funcs.add( { \"make_tuple\", 1, -1, { \"_whatever_\" }, FnType::MODULE, { .modfn = make_tuple }, true } );\n\n\tvm.funcs.add( { \"==\", 2, 2, { \"tuple\", \"tuple\" }, FnType::MODULE, { .modfn = eqt }, false } );\n\tvm.funcs.add( { \"!=\", 2, 2, { \"tuple\", \"tuple\" }, FnType::MODULE, { .modfn = net }, false } );\n}\n"
  },
  {
    "path": "modules/std/vec.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../../src/VM/Core.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////// Classes ///////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass var_vec_iter_t : public var_base_t\n{\n\tint m_idx;\n\tvar_vec_t * m_vec;\npublic:\n\tvar_vec_iter_t( var_vec_t * vec, bool inc_ref = true, int idx = -1, const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_vec_iter_t();\n\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tvar_vec_t * & get();\n\tint & pos();\n};\n#define AS_VEC_ITER( x ) static_cast< var_vec_iter_t * >( x )\n\nvar_vec_iter_t::var_vec_iter_t( var_vec_t * vec, bool inc_ref, int idx, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_CUSTOM, true, src_idx, parse_ctr ), m_idx( idx ), m_vec( vec )\n{ if( inc_ref ) VAR_IREF( m_vec ); }\nvar_vec_iter_t::~var_vec_iter_t() { VAR_DREF( m_vec ); }\n\nstd::string var_vec_iter_t::type_str() const { return \"vec_iter_t\"; }\nstd::string var_vec_iter_t::to_str() const\n{\n\treturn std::to_string( m_idx );\n}\nmpz_class var_vec_iter_t::to_int() const { return m_idx; }\nbool var_vec_iter_t::to_bool() const { return m_idx >= 0 && m_idx < m_vec->get().size(); }\nvar_base_t * var_vec_iter_t::copy( const int src_idx, const int parse_ctr )\n{\n\treturn new var_vec_iter_t( m_vec, true, m_idx, src_idx, parse_ctr );\n}\nvoid var_vec_iter_t::assn( var_base_t * b )\n{\n\tm_idx = AS_VEC_ITER( b )->pos();\n\tVAR_DREF( m_vec );\n\tvar_vec_t * vec = AS_VEC_ITER( b )->get();\n\tVAR_IREF( vec );\n\tm_vec = vec;\n}\nvar_vec_t * & var_vec_iter_t::get() { return m_vec; }\nint & var_vec_iter_t::pos() { return m_idx; }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////// Functions //////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nvar_base_t * at( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & v = AS_VEC( fcd.args[ 0 ] )->get();\n\tsize_t sz = v.size();\n\tint idx = AS_INT( fcd.args[ 1 ] )->get().get_si();\n\tif( idx < 0 || ( size_t )idx >= sz ) {\n\t\treturn vm.nil;\n\t}\n\treturn v[ idx ];\n}\n\nvar_base_t * append( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & a = AS_VEC( fcd.args[ 0 ] )->get();\n\tstd::vector< var_base_t * > & b = AS_VEC( fcd.args[ 1 ] )->get();\n\tfor( auto & x : b ) {\n\t\ta.push_back( x->copy( fcd.src_idx, fcd.parse_ctr ) );\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * push( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & v = AS_VEC( fcd.args[ 0 ] )->get();\n\tv.push_back( fcd.args[ 1 ]->copy( fcd.src_idx, fcd.parse_ctr ) );\n\treturn nullptr;\n}\n\nvar_base_t * push_front( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & v = AS_VEC( fcd.args[ 0 ] )->get();\n\tv.insert( v.begin(), fcd.args[ 1 ]->copy( fcd.src_idx, fcd.parse_ctr ) );\n\treturn nullptr;\n}\n\nvar_base_t * pop( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & v = AS_VEC( fcd.args[ 0 ] )->get();\n\tif( v.size() > 0 ) {\n\t\tVAR_DREF( v.back() );\n\t\tv.pop_back();\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * pop_front( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & v = AS_VEC( fcd.args[ 0 ] )->get();\n\tif( v.size() > 0 ) {\n\t\tVAR_DREF( v.front() );\n\t\tv.erase( v.begin() );\n\t}\n\treturn nullptr;\n}\n\nvar_base_t * front( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & v = AS_VEC( fcd.args[ 0 ] )->get();\n\treturn v.size() > 0 ? v.front() : nullptr;\n}\n\nvar_base_t * back( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & v = AS_VEC( fcd.args[ 0 ] )->get();\n\treturn v.size() > 0 ? v.back() : nullptr;\n}\n\nvar_base_t * len( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_int_t( ( int )AS_VEC( fcd.args[ 0 ] )->get().size() );\n}\n\nvar_base_t * clear( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tAS_VEC( fcd.args[ 0 ] )->clear();\n\treturn nullptr;\n}\n\nvar_base_t * erase( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & v = AS_VEC( fcd.args[ 0 ] )->get();\n\tmpz_class & loc = AS_INT( fcd.args[ 1 ] )->get();\n\tif( loc < 0 || loc >= v.size() ) return vm.vars->get( \"false\" );\n\tvar_base_t * dat = v[ loc.get_ui() ];\n\tVAR_DREF( dat );\n\tv.erase( v.begin() + loc.get_ui() );\n\treturn vm.vars->get( \"true\" );\n}\n\nvar_base_t * find( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & v = AS_VEC( fcd.args[ 0 ] )->get();\n\tint loc = -1;\n\tsize_t sz = v.size();\n\tfor( size_t i = 0; i < sz; ++i ) {\n\t\tif( v[ i ]->to_str() == fcd.args[ 1 ]->to_str() ) {\n\t\t\tloc = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn new var_int_t( loc );\n}\n\nvar_base_t * iter( vm_state_t & vm, func_call_data_t & fcd )\n{\n\treturn new var_vec_iter_t( AS_VEC( fcd.args[ 0 ] ) );\n}\n\nvar_base_t * add( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > res;\n\tstd::vector< var_base_t * > & a = AS_VEC( fcd.args[ 1 ] )->get();\n\tstd::vector< var_base_t * > & b = AS_VEC( fcd.args[ 0 ] )->get();\n\tfor( auto & x : a ) {\n\t\tres.push_back( x->copy( fcd.src_idx, fcd.parse_ctr ) );\n\t}\n\tfor( auto & x : b ) {\n\t\tres.push_back( x->copy( fcd.src_idx, fcd.parse_ctr ) );\n\t}\n\treturn new var_vec_t( res );\n}\n\nvar_base_t * add_assn( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & a = AS_VEC( fcd.args[ 0 ] )->get();\n\tstd::vector< var_base_t * > & b = AS_VEC( fcd.args[ 1 ] )->get();\n\tfor( auto & x : b ) {\n\t\ta.push_back( x->copy( fcd.src_idx, fcd.parse_ctr ) );\n\t}\n\treturn fcd.args[ 0 ];\n}\n\nvar_base_t * eqv( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & a = AS_VEC( fcd.args[ 1 ] )->get();\n\tstd::vector< var_base_t * > & b = AS_VEC( fcd.args[ 0 ] )->get();\n\tif( a.size() != b.size() ) return vm.vars->get( \"false\" );\n\tfor( auto i1 = a.begin(), i2 = b.begin(); i1 != a.end() && i2 != b.end(); ++i1, ++i2 ) {\n\t\tif( ( * i1 )->to_str() != ( * i2 )->to_str() ) return vm.vars->get( \"false\" );\n\t}\n\treturn vm.vars->get( \"true\" );\n}\n\nvar_base_t * nev( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tstd::vector< var_base_t * > & a = AS_VEC( fcd.args[ 1 ] )->get();\n\tstd::vector< var_base_t * > & b = AS_VEC( fcd.args[ 0 ] )->get();\n\tif( a.size() != b.size() ) return vm.vars->get( \"true\" );\n\tfor( auto i1 = a.begin(), i2 = b.begin(); i1 != a.end() && i2 != b.end(); ++i1, ++i2 ) {\n\t\tif( ( * i1 )->to_str() != ( * i2 )->to_str() ) return vm.vars->get( \"true\" );\n\t}\n\treturn vm.vars->get( \"false\" );\n}\n\nvar_base_t * next( vm_state_t & vm, func_call_data_t & fcd )\n{\n\tvar_vec_iter_t * it = AS_VEC_ITER( fcd.args[ 0 ] );\n\tstd::vector< var_base_t * > & vec = it->get()->get();\n\tint & pos = it->pos();\n\t++pos;\n\tif( pos >= vec.size() ) return vm.nil;\n\treturn vec[ pos ];\n}\n\nREGISTER_MODULE( vec )\n{\n\tfunctions_t & vecfns = vm.typefuncs[ \"vec\" ];\n\n\tvecfns.add( { \"[]\", 1, 1, { \"int\" }, FnType::MODULE, { .modfn = at }, false } );\n\tvecfns.add( { \"at\", 1, 1, { \"int\" }, FnType::MODULE, { .modfn = at }, false } );\n\tvecfns.add( { \"append\", 1, 1, { \"vec\" }, FnType::MODULE, { .modfn = append }, false } );\n\tvecfns.add( { \"push\", 1, 1, { \"_any_\" }, FnType::MODULE, { .modfn = push }, false } );\n\tvecfns.add( { \"push_front\", 1, 1, { \"_any_\" }, FnType::MODULE, { .modfn = push_front }, false } );\n\tvecfns.add( { \"pop\", 0, 0, {}, FnType::MODULE, { .modfn = pop }, false } );\n\tvecfns.add( { \"pop_front\", 0, 0, {}, FnType::MODULE, { .modfn = pop_front }, false } );\n\tvecfns.add( { \"front\", 0, 0, {}, FnType::MODULE, { .modfn = front }, false } );\n\tvecfns.add( { \"back\", 0, 0, {}, FnType::MODULE, { .modfn = back }, false } );\n\tvecfns.add( { \"len\", 0, 0, {}, FnType::MODULE, { .modfn = len }, true } );\n\tvecfns.add( { \"clear\", 0, 0, {}, FnType::MODULE, { .modfn = clear }, false } );\n\tvecfns.add( { \"erase\", 1, 1, { \"int\" }, FnType::MODULE, { .modfn = erase }, false } );\n\tvecfns.add( { \"find\", 1, 1, { \"_any_\" }, FnType::MODULE, { .modfn = find }, true } );\n\tvecfns.add( { \"iter\", 0, 0, {}, FnType::MODULE, { .modfn = iter }, true } );\n\n\tvm.funcs.add( { \"+\", 2, 2, { \"vec\", \"vec\" }, FnType::MODULE, { .modfn = add }, true } );\n\tvm.funcs.add( { \"+=\", 2, 2, { \"vec\", \"vec\" }, FnType::MODULE, { .modfn = add_assn }, false } );\n\n\tvm.funcs.add( { \"==\", 2, 2, { \"vec\", \"vec\" }, FnType::MODULE, { .modfn = eqv }, false } );\n\tvm.funcs.add( { \"!=\", 2, 2, { \"vec\", \"vec\" }, FnType::MODULE, { .modfn = nev }, false } );\n\n\tfunctions_t & veciterfns = vm.typefuncs[ \"vec_iter_t\" ];\n\tveciterfns.add( { \"next\", 0, 0, {}, FnType::MODULE, { .modfn = next }, false } );\n}\n"
  },
  {
    "path": "perform_tests.et",
    "content": "#!/usr/bin/env et\n\nimport std.( fs, os, str, vec, term, time, threads );\n\nfn wait_procs( tpool, max_procs, with_valgrind, p, f ) {\n\tfor ; tpool.len() >= max_procs; {\n\t\tfor i = 0; i < tpool.len(); i += 1 {\n\t\t\tif tpool[ i ].done() {\n\t\t\t\tt = tpool[ i ];\n\t\t\t\tif t.res() != 0 {\n\t\t\t\t\tf += 1;\n\t\t\t\t\tcprintln( '{r}failed {y}', files[ t.id() ], with_valgrind ? '{c} with valgrind' : '',\n\t\t\t\t\t\t  '{0}, {y}error code{0}: {r}', t.res(),'{0}' );\n\t\t\t\t\tflush_out();\n\t\t\t\t} else {\n\t\t\t\t\tp += 1;\n\t\t\t\t}\n\t\t\t\ttpool.erase( i );\n\t\t\t\ti -= 1;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfiles = fs.dir_entries( 'tests', fs.ent.RECURSE, '(.*)\\\\.et' );\n\ntpool = [];\nmax_procs = threads.nproc;\n\nthreadid = 0;\np = 0;\nf = 0;\nstart = time.now();\n\nfor file in files.iter() {\n\twait_procs( tpool, max_procs, false, p, f );\n\tcprintln( '{c}test{0}: {y}', file, '{0} ...' );\n\tflush_out();\n\ttpool.push( threads.new_exec( __PROG__ + ' ' + file + ' test 1>/dev/null 2>&1', threadid ) );\n\tthreadid += 1;\n}\nwait_procs( tpool, 1, false, p, f );\n\ndiff = time.now() - start;\n\nif f > 0 || args.find( '--with-valgrind' ) == -1 {\n\tcprintln( '=> {y}Passed{0}: {g}', p,\n\t\t  '\\n{0}=> {y}Failed{0}: {r}', f,\n\t\t  '\\n{0}=> {y}Total Time{0}: {b}', diff.msecs(), ' ms{0}' );\n\texit( f );\n}\n\n############################################## Test with Valgrind ###############################################\n\nvalgrind = os.find_exec( 'valgrind' );\nif valgrind.empty() {\n\tcprintln( '=> {y}Passed{0}: {g}', p,\n\t\t  '\\n{0}=> {y}Failed{0}: {r}', f,\n\t\t  '\\n{0}=> {y}Total Time{0}: {b}', diff.msecs(), ' ms{0}' );\n\tcprintln( '{y}valgrind binary is {r}not {y}available in the {m}PATH {y}variable{0}' );\n\texit( f );\n}\n\nthreadid = 0;\nvp = 0;\nvf = 0;\nstart = time.now();\n\nfor file in files.iter() {\n\twait_procs( tpool, max_procs, true, vp, vf );\n\tcprintln( '{c}test {0}({c}valgrind{0}): {y}', file, '{0} ...' );\n\tflush_out();\n\ttpool.push( threads.new_exec( valgrind + ' ' + __PROG__ + ' ' + file + ' test 1>/dev/null 2>&1', threadid ) );\n\tthreadid += 1;\n}\nwait_procs( tpool, 1, true, vp, vf );\n\nvdiff = time.now() - start;\ncprintln( '{y}OS{0}: {m}', os.name,\n\t  '\\n{w}Basic{0}:',\n\t  '\\n{0}=> {y}Passed{0}: {g}', p,\n\t  '\\n{0}=> {y}Failed{0}: {r}', f,\n\t  '\\n{0}=> {y}Total Time{0}: {b}', diff.msecs(), ' ms{0}',\n\t  '\\n{w}Valgrind{0}:',\n\t  '\\n{0}=> {y}Passed{0}: {g}', vp,\n\t  '\\n{0}=> {y}Failed{0}: {r}', vf,\n\t  '\\n{0}=> {y}Total Time{0}: {b}', vdiff.msecs(), ' ms{0}' );\n\nexit( f );\n"
  },
  {
    "path": "playground.et",
    "content": "#!@BINARY_LOC@\n\nimport eth.vm;\nimport std.( str, vec, term );\n\nvm = evm.new();\n\nres = 0;\nexit_code = 0;\n\nindent = 0;\nline_id = 0;\ninput = '';\nlines = [];\nfor ; vm.is_running(); {\n\tif indent == 0 {\n\t\tcprint( res == 0 ? '{g}0' : '{r}' + res.to_str(), ' {c}>{0} ' );\n\t} else {\n\t\tcprint( '{y}...{0} ' );\n\t}\n\tinput = scan();\n\n\tif input == '!!!' { break; }\n\n\tlines.push( input );\n\n\tif input.back() == '{' { indent += 1; continue; }\n\tif input.back() == '}' { if indent > 0 { indent -= 1; } }\n\tif indent > 0 { continue; }\n\n\tres = vm.exec_code( lines, exit_code );\n\n\tlines.clear();\n}\n\nprintln( 'Exiting playground vm with code: ', exit_code );\n\nexit( exit_code );\n"
  },
  {
    "path": "src/Config.hpp.in",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef CONFIG_HPP\n#define CONFIG_HPP\n\n#define ETHEREAL_VERSION_MAJOR @ETHEREAL_VERSION_MAJOR@\n#define ETHEREAL_VERSION_MINOR @ETHEREAL_VERSION_MINOR@\n#define ETHEREAL_VERSION_PATCH @ETHEREAL_VERSION_PATCH@\n\n#define BUILD_CXX_COMPILER \"@CMAKE_CXX_COMPILER_ID@ @CMAKE_CXX_COMPILER_VERSION@\"\n#define BUILD_DATE \"@BUILD_DATE@\"\n\n#endif // CONFIG_HPP"
  },
  {
    "path": "src/FE/CmdArgs.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cstring>\n\n#include \"CmdArgs.hpp\"\n\nconst size_t OPT_A = 1 << 0;\nconst size_t OPT_B = 1 << 1; // show byte code\nconst size_t OPT_C = 1 << 2; // (byte) compile\nconst size_t OPT_D = 1 << 3; // dry run (no execute)\nconst size_t OPT_E = 1 << 4; // REPL (eval)\nconst size_t OPT_F = 1 << 5;\nconst size_t OPT_G = 1 << 6;\nconst size_t OPT_H = 1 << 7;\nconst size_t OPT_I = 1 << 8;\nconst size_t OPT_L = 1 << 9;\nconst size_t OPT_P = 1 << 10; // show parse tree\nconst size_t OPT_R = 1 << 11; // recursively show everything (ex. FrontEnd->VM->Import->FrontEnd...)\nconst size_t OPT_S = 1 << 12;\nconst size_t OPT_T = 1 << 13; // show tokens\nconst size_t OPT_V = 1 << 14; // show version\nconst size_t OPT_1 = 1 << 15;\n\nsize_t cmd_get_args( const int argc, const char ** argv, std::vector< std::string > & args )\n{\n\tsize_t flags = 0;\n\tbool src_found = false;\n\n\tfor( int i = 1; i < argc; ++i ) {\n\t\tif( argv[ i ][ 0 ] != '-' || src_found ) {\n\t\t\tsrc_found = true;\n\t\t\targs.push_back( argv[ i ] );\n\t\t\tcontinue;\n\t\t}\n\n\t\tsize_t len = strlen( argv[ i ] );\n\t\tfor( size_t j = 1; j <= len; ++j ) {\n\t\t\tif( argv[ i ][ j ] == 'a' ) flags |= OPT_A;\n\t\t\telse if( argv[ i ][ j ] == 'b' ) flags |= OPT_B;\n\t\t\telse if( argv[ i ][ j ] == 'c' ) flags |= OPT_C;\n\t\t\telse if( argv[ i ][ j ] == 'd' ) flags |= OPT_D;\n\t\t\telse if( argv[ i ][ j ] == 'e' ) flags |= OPT_E;\n\t\t\telse if( argv[ i ][ j ] == 'f' ) flags |= OPT_F;\n\t\t\telse if( argv[ i ][ j ] == 'g' ) flags |= OPT_G;\n\t\t\telse if( argv[ i ][ j ] == 'h' ) flags |= OPT_H;\n\t\t\telse if( argv[ i ][ j ] == 'i' ) flags |= OPT_I;\n\t\t\telse if( argv[ i ][ j ] == 'l' ) flags |= OPT_L;\n\t\t\telse if( argv[ i ][ j ] == 'p' ) flags |= OPT_P;\n\t\t\telse if( argv[ i ][ j ] == 'r' ) flags |= OPT_R;\n\t\t\telse if( argv[ i ][ j ] == 's' ) flags |= OPT_S;\n\t\t\telse if( argv[ i ][ j ] == 't' ) flags |= OPT_T;\n\t\t\telse if( argv[ i ][ j ] == 'v' ) flags |= OPT_V;\n\t\t\telse if( argv[ i ][ j ] == '1' ) flags |= OPT_1;\n\t\t}\n\t}\n\n\treturn flags;\n}\n"
  },
  {
    "path": "src/FE/CmdArgs.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef CMD_ARGS_HPP\n#define CMD_ARGS_HPP\n\n#include <vector>\n#include <string>\n\n// Option bit masks\nextern const size_t OPT_A;\nextern const size_t OPT_B; // show byte code\nextern const size_t OPT_C; // (byte) compile\nextern const size_t OPT_D; // dry run (no execute)\nextern const size_t OPT_E; // REPL (eval)\nextern const size_t OPT_F;\nextern const size_t OPT_G;\nextern const size_t OPT_H;\nextern const size_t OPT_I;\nextern const size_t OPT_L;\nextern const size_t OPT_P; // show parse tree\nextern const size_t OPT_R; // recursively show everything (ex. FrontEnd->VM->Import->FrontEnd...)\nextern const size_t OPT_S;\nextern const size_t OPT_T; // show tokens\nextern const size_t OPT_V; // show version\nextern const size_t OPT_1;\n\nsize_t cmd_get_args( const int argc, const char ** argv, std::vector< std::string > & args );\n\n#endif // CMD_ARGS_HPP"
  },
  {
    "path": "src/FE/Core.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <string>\n#include <cstdarg>\n\n#include \"Core.hpp\"\n\nvoid src_fail( const std::string & src, const std::string & line_str, const int line, const int col, const char * msg, ... )\n{\n\tfprintf( stderr, \"%s %d[%d]: error: \", src.c_str(), line, col );\n\tva_list vargs;\n\tva_start( vargs, msg );\n\tvfprintf( stderr, msg, vargs );\n\tfprintf( stderr, \"\\n\" );\n\tva_end( vargs );\n\tif( line_str.size() > 0 && line_str.back() == '\\n' ) fprintf( stderr, \"%s\", line_str.c_str() );\n\telse fprintf( stderr, \"%s\\n\", line_str.c_str() );\n\tstd::string spcs;\n\tint tab_count = 0;\n\tfor( auto & ch : line_str ) {\n\t\tif( ch == '\\t' ) ++tab_count;\n\t}\n\tfor( int i = 0; i < tab_count; ++i ) spcs += '\\t';\n\tfor( int i = 0; i < col - 1 - tab_count; ++i ) {\n\t\tspcs += \" \";\n\t}\n\tfprintf( stderr, \"%s^\\n\", spcs.c_str() );\n}"
  },
  {
    "path": "src/FE/Core.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef CORE_HPP\n#define CORE_HPP\n\n#include <cstdio>\n#include <string>\n\n#include \"Err.hpp\"\n\n#ifdef _GNU_SOURCE\n#define ATTR_FALLTHROUGH __attribute__ ( ( fallthrough ) )\n#else\n#define ATTR_FALLTHROUGH\n#endif\n\n#define _STRINGIZE(x) #x\n#define STRINGIFY(x) _STRINGIZE(x)\n\ntemplate< typename T > struct res_t {\n\tint code;\n\tT data;\n};\n\ntemplate< typename T > struct res_ptr_t {\n\tint code;\n\tT * data;\n};\n\nvoid src_fail( const std::string & src, const std::string & line_str, const int line, const int col, const char * msg, ... );\n\n#endif // CORE_HPP"
  },
  {
    "path": "src/FE/Env.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cstdio>\n#include <cstdlib>\n#include <unistd.h>\n\n#include \"Env.hpp\"\n#include \"FS.hpp\"\n\n#define MAX_PATH 2048\n\nstd::string GetEnv( const std::string & key )\n{\n\tconst char * env = std::getenv( key.c_str() );\n\treturn env == NULL ? \"\" : env;\n}\n\nstd::string GetCWD()\n{\n\tchar cwd[ MAX_PATH ];\n\tif( getcwd( cwd, sizeof( cwd ) ) != NULL ) {\n\t\treturn cwd;\n\t}\n\treturn \"\";\n}\n\nvoid SetCWD( std::string dir )\n{\n\tchdir( dir.c_str() );\n}\n\nstd::string GetEtherealBinaryAbsoluteLoc( const std::string & arg0 )\n{\n\tauto last_slash_loc = arg0.find_last_of( '/' );\n\tif( last_slash_loc == std::string::npos ) return arg0;\n\tstd::string bin_dir = arg0.substr( 0, last_slash_loc );\n\tstd::string bin_name = arg0.substr( last_slash_loc + 1 );\n\tDirFormat( bin_dir );\n\treturn bin_dir + \"/\" + bin_name;\n}\n\nvoid DirFormat( std::string & dir )\n{\n\tstd::string cwd = GetCWD();\n\tSetCWD( dir );\n\tstd::string res = GetCWD();\n\tSetCWD( cwd );\n\tdir = res;\n}\n"
  },
  {
    "path": "src/FE/Env.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef ENV_HPP\n#define ENV_HPP\n\n#include <vector>\n#include <string>\n\nstd::string GetEnv( const std::string & key );\n\nstd::string GetCWD();\nvoid SetCWD( std::string dir );\nstd::string GetEtherealBinaryAbsoluteLoc( const std::string & arg0 );\n\nvoid DirFormat( std::string & dir );\n\n#endif // ENV_HPP\n"
  },
  {
    "path": "src/FE/Err.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Err.hpp\"\n\nconst char * ErrStr( Errors code )\n{\n\tswitch( code ) {\n\tcase E_ALLOC_FAIL:\n\t\treturn \"memory allocation failed\";\n\tcase E_LEX_FAIL:\n\t\treturn \"lexical analyzer failed\";\n\tcase E_PARSE_FAIL:\n\t\treturn \"parser failed\";\n\tcase E_BYTECODE_FAIL:\n\t\treturn \"bytecode failed\";\n\tcase E_FILE_EMPTY:\n\t\treturn \"empty file\";\n\tcase E_VM_FAIL:\n\t\treturn \"vm failed\";;\n\tcase E_ASSERT_LVL1:\n\t\treturn \"assertion failed level 1\";;\n\tcase E_ASSERT_LVL2:\n\t\treturn \"assertion failed level 2\";\n\tcase E_FAIL: // fall through\n\tdefault:\n\t\treturn \"unknown error\";\n\t}\n}\n"
  },
  {
    "path": "src/FE/Err.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef ERR_HPP\n#define ERR_HPP\n\nenum Errors\n{\n\tE_OK,\n\tE_FAIL,\n\n\tE_FILE_IO_ERR,\n\tE_FILE_EMPTY,\n\n\tE_ALLOC_FAIL,\n\tE_LEX_FAIL,\n\tE_PARSE_FAIL,\n\tE_BYTECODE_FAIL,\n\n\t// special case for assertion\n\tE_ASSERT_LVL1,\n\tE_ASSERT_LVL2,\n\n\tE_VM_FAIL,\n};\n\nconst char * ErrStr( Errors code );\n\n#endif // ERR_HPP\n"
  },
  {
    "path": "src/FE/Ethereal.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Ethereal.hpp\"\n\nsrc_t::src_t( const bool _is_main_src )\n\t: ptree( nullptr ), is_main_src( _is_main_src ),\n\t  found_assn( false ), bcode_as_const( false )\n{\n\tblock_depth.push_back( {} );\n}\n\nsrc_t::~src_t()\n{\n\tif( ptree != nullptr ) {\n\t\tfor( auto & stmt : * ptree ) delete stmt;\n\t\tdelete ptree;\n\t}\n}"
  },
  {
    "path": "src/FE/Ethereal.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef ETHEREAL_HPP\n#define ETHEREAL_HPP\n\n#include <string>\n#include <vector>\n#include <unordered_map>\n\n#include \"Parser.hpp\"\n#include \"../VM/Instructions.hpp\"\n#include \"../VM/Vars.hpp\"\n\nstruct src_t\n{\n\t// id is unique and used for mapping variables to sources\n\t// file is the name (no dir part) of the source file and is used\n\t// as key for srcs map.\n\tint id;\n\tstd::string file;\n\tstd::string dir;\n\tstd::vector< std::string > code;\n\ttoks_t toks;\n\tstd::vector< std::vector< int > > block_depth;\n\tparse_tree_t * ptree;\n\tbool is_main_src;\n\tbool found_assn;\n\tbool bcode_as_const;\n\n\t// for VM\n\tbytecode_t bcode;\n\n\tsrc_t( const bool _is_main_src );\n\t~src_t();\n};\n\n// for parser\n#define ADD_FUNC()\t\t\t\t\t\t\t\t\t\\\n\tsrc.block_depth.push_back( { 0 } )\n#define ADD_SCOPE()\t\t\t\t\t\t\t\t\t\\\n\tsrc.block_depth.back().push_back( 0 )\n#define INC_SCOPE()\t\t\t\t\t\t\t\t\t\\\n\tsrc.bcode.push_back( { m_tok_ctr, line, col, IC_ADD_SCOPE, { OP_INT, \"1\" } } );\t\\\n\tif( src.block_depth.back().size() > 0 ) ++src.block_depth.back().back()\n\n#define REM_FUNC()\t\t\t\t\t\t\t\t\t\\\n\tsrc.block_depth.pop_back()\n#define REM_SCOPE()\t\t\t\t\t\t\t\t\t\\\n\tsrc.block_depth.back().pop_back()\n#define DEC_SCOPE()\t\t\t\t\t\t\t\t\t\\\n\tsrc.bcode.push_back( { m_tok_ctr, line, col, IC_REM_SCOPE, { OP_INT, \"1\" } } );\t\\\n\tif( src.block_depth.back().size() > 0 ) --src.block_depth.back().back()\n\ntypedef std::unordered_map< int, src_t * > srcs_t;\n\n#endif // ETHEREAL_HPP"
  },
  {
    "path": "src/FE/FS.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cstdio>\n#include <cstdlib>\n#include <vector>\n#include <string>\n#include <unistd.h>\n\n#include \"Env.hpp\"\n#include \"FS.hpp\"\n\nint read_file( src_t & src )\n{\n\tFILE * fp;\n\tchar * line = NULL;\n\tsize_t len = 0;\n\tssize_t read;\n\n\tfp = fopen( ( src.dir + \"/\" + src.file ).c_str(), \"r\" );\n\tif( fp == NULL ) {\n\t\tfprintf( stdout, \"failed to open source file: %s\\n\", src.file.c_str() );\n\t\treturn E_FILE_IO_ERR;\n\t}\n\n\tstd::vector< std::string > lines;\n\n\twhile( ( read = getline( & line, & len, fp ) ) != -1 ) {\n\t\tlines.push_back( line );\n\t}\n\n\tfclose( fp );\n\tif( line ) free( line );\n\n\tif( lines.empty() ) return E_FILE_EMPTY;\n\n\tsrc.code = lines;\n\treturn E_OK;\n}\n\nbool fexists( const std::string & file )\n{\n\treturn access( file.c_str(), F_OK ) != -1;\n}"
  },
  {
    "path": "src/FE/FS.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef FS_HPP\n#define FS_HPP\n\n#include <vector>\n#include <string>\n\n#include \"Ethereal.hpp\"\n\nint read_file( src_t & src );\n\nbool fexists( const std::string & file );\n\n#endif // FS_HPP\n"
  },
  {
    "path": "src/FE/Lexer.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cstdio>\n#include <cstdlib>\n#include <string>\n#include <cctype>\n#include <cstdarg>\n\n#include \"FS.hpp\"\n#include \"Lexer.hpp\"\n\nconst char * TokStrs[ _TOK_LAST ] = {\n\t\"INT\",\n\t\"FLT\",\n\n\t\"STR\",\n\t\"IDEN\",\n\n\t//Keywords\n\t\"enum\",\n\t\"enum_mask\",\n\t\"import\",\n\t\"as\",\n\t\"struct\",\n\t\"fn\",\n\t\"mfn\",\n\t\"return\",\n\t\"if\",\n\t\"elif\",\n\t\"else\",\n\t\"for\",\n\t\"in\",\n\t\"continue\",\n\t\"break\",\n\t\"ldmod\",\n\t\"true\",\n\t\"false\",\n\t\"nil\",\n\t// if the source file is the actual executed one, execute the code between these symbols\n\t\"_MAIN_BEG_\",\n\t\"_MAIN_END_\",\n\n\t// Operators\n\t\"=\",\n\t// Arithmetic\n\t\"+\",\n\t\"-\",\n\t\"*\",\n\t\"/\",\n\t\"%\",\n\t\"+=\",\n\t\"-=\",\n\t\"*=\",\n\t\"/=\",\n\t\"%=\",\n\t\"**\", // power\n\t// Unary (used by parser (in Expression.cpp))\n\t\"u+\",\n\t\"u-\",\n\t// Logic\n\t\"&&\",\n\t\"||\",\n\t\"!\",\n\t\"==\",\n\t\"<\",\n\t\">\",\n\t\"<=\",\n\t\">=\",\n\t\"!=\",\n\t// Bitwise\n\t\"&\",\n\t\"|\",\n\t\"~\",\n\t\"^\",\n\t\"&=\",\n\t\"|=\",\n\t\"~=\",\n\t\"^=\",\n\t// Others\n\t\"<<\",\n\t\">>\",\n\t\"<<=\",\n\t\">>=\",\n\t// Conditional ( ? : )\n\t\"?\",\n\t\":\",\n\n\t// Varargs\n\t\"...\",\n\n\t// Separators\n\t\".\",\n\t\",\",\n\t\"@\",\n\t\"SPC\",\n\t\"TAB\",\n\t\"NEWL\",\n\t\";\",\n\t// Parenthesis, Braces, Brackets\n\t\"(\",\n\t\")\",\n\t\"{\",\n\t\"}\",\n\t\"[\",\n\t\"]\",\n\n\t\"<EOF>\",\n};\n\n#define CURR( line ) ( line[ i ] )\n#define NEXT( line ) ( i + 1 < ( int )line.size() ? line[ i + 1 ] : 0 )\n#define PREV( line ) ( line.size() > 0 && i - 1 >= 0 ? line[ i - 1 ] : 0 )\n#define SET_OP_TYPE_BRK( type ) op_type = type; break\n\n#define SRC_FAIL( ... ) src_fail( src, line, line_num, i + 1, __VA_ARGS__ )\n\nstatic int tokenize_line( const std::string & src, const std::string & dir, const std::string & line,\n\t\t\t  const int line_len, const int line_num, toks_t & toks, const bool is_main_src );\n\nstatic std::string get_name( const std::string & input, const int input_len, int & i );\nstatic int classify_str( const std::string & str );\nstatic std::string get_num( const std::string & src, const std::string & line, const int line_len, const int line_num, int & i, int & num_type );\nstatic int get_const_str( const std::string & src, const std::string & line, const int line_len, const int line_num, int & i, std::string & buf );\nstatic int get_operator( const std::string & src, const std::string & line, const int line_len, const int line_num, int & i );\nstatic inline bool is_valid_num_char( const char c );\nstatic void remove_back_slash( std::string & s );\n\nint tokenize( src_t & src )\n{\n\t// in /modules/eth/vm.cpp, var_evm_t manually inserts code itself so read_file is useless there\n\tint res = src.code.empty() ? read_file( src ) : E_OK;\n\tif( res == E_FILE_IO_ERR ) {\n\t\treturn res;\n\t}\n\tif( res == E_FILE_EMPTY ) {\n\t\tfprintf( stderr, \"error: invalid source (empty file): %s\\n\", src.file.c_str() );\n\t\treturn res;\n\t}\n\tconst auto & lines = src.code;\n\tconst int line_count = lines.size();\n\tauto & toks = src.toks;\n\n\t// tokenize the input\n\tfor( int i = 0; i < line_count; ++i ) {\n\t\tauto & line = lines[ i ];\n\t\tconst int line_len = line.size();\n\t\tint res = tokenize_line( src.file, src.dir, line, line_len, i + 1, toks, src.is_main_src );\n\t\tif( res != E_OK ) return res;\n\t}\n\n\treturn E_OK;\n}\n\nstatic int tokenize_line( const std::string & src, const std::string & dir, const std::string & line,\n\t\t\t  const int line_len, const int line_num, toks_t & toks, const bool is_main_src )\n{\n\tint i = 0;\n\tint err = E_OK;\n\n\tstatic int comment_block = 0;\n\tstatic bool main_src_block = false;\n\n\tstatic bool back_tick_block = false;\n\tstatic std::string back_tick_data = \"\";\n\tstatic int back_tick_begin_line = -1;\n\tstatic int back_tick_begin_col = -1;\n\n\twhile( i < line_len ) {\n\t\tif( back_tick_block && CURR( line ) != '`' ) {\n\t\t\tback_tick_data += CURR( line );\n\t\t\t++i;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif( isspace( line[ i ] ) ) { ++i; continue; }\n\n\t\tif( CURR( line ) == '*' && NEXT( line ) == '/' ) {\n\t\t\tif( comment_block == 0 ) {\n\t\t\t\tSRC_FAIL( \"encountered multi line comment terminator '*/' \"\n\t\t\t\t\t  \"in non commented block\", line_num, i + 1 );\n\t\t\t\terr = E_LEX_FAIL;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ti += 2;\n\t\t\t--comment_block;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif( CURR( line ) == '/' && NEXT( line ) == '*' ) {\n\t\t\ti += 2;\n\t\t\t++comment_block;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif( comment_block ) { ++i; continue; }\n\n\t\tif( CURR( line ) == '#' ) break;\n\n\t\t// for storing correct columns in tokens (+1 for zero indexing)\n\t\tint tmp_i = i + 1;\n\n\t\tif( CURR( line ) == '`' ) {\n\t\t\tif( back_tick_block ) {\n\t\t\t\ttoks.emplace_back( back_tick_begin_line, back_tick_begin_col, TOK_STR, back_tick_data );\n\t\t\t\tback_tick_data.clear();\n\t\t\t\tback_tick_block = false;\n\t\t\t\t++i;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tback_tick_block = true;\n\t\t\tback_tick_begin_line = line_num;\n\t\t\tback_tick_begin_col = tmp_i;\n\t\t\t++i;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// strings\n\t\tif( isalpha( CURR( line ) ) || CURR( line ) == '_' ) {\n\t\t\tstd::string str = get_name( line, line_len, i );\n\t\t\tif( str == TokStrs[ TOK_MAIN_SRC_BEG ] ) {\n\t\t\t\tif( !is_main_src ) main_src_block = true;\n\t\t\t\tcontinue;\n\t\t\t} else if( str == TokStrs[ TOK_MAIN_SRC_END ] ) {\n\t\t\t\tif( !is_main_src ) main_src_block = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif( main_src_block ) continue;\n\t\t\t// check if string is a keyword\n\t\t\tint kw_or_iden = classify_str( str );\n\t\t\t// some magic\n\t\t\tif( str == \"__SRC_DIR__\" ) { str = dir; kw_or_iden = TOK_STR; }\n\t\t\ttoks.emplace_back( line_num, tmp_i, kw_or_iden, str );\n\t\t\tcontinue;\n\t\t}\n\n\t\tif( main_src_block ) { ++i; continue; }\n\n\t\t// numbers\n\t\tif( isdigit( CURR( line ) ) ) {\n\t\t\tint num_type = TOK_INT;\n\t\t\tstd::string num = get_num( src, line, line_len, line_num, i, num_type );\n\t\t\tif( num.empty() ) {\n\t\t\t\terr = E_PARSE_FAIL;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ttoks.emplace_back( line_num, tmp_i, num_type, num );\n\t\t\tcontinue;\n\t\t}\n\n\t\t// const strings\n\t\tif( CURR( line ) == '\\\"' || CURR( line ) == '\\'' ) {\n\t\t\tstd::string str;\n\t\t\tint res = get_const_str( src, line, line_len, line_num, i, str );\n\t\t\tif( res != E_OK ) {\n\t\t\t\terr = res;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ttoks.emplace_back( line_num, tmp_i, TOK_STR, str );\n\t\t\tcontinue;\n\t\t}\n\n\t\t// operators\n\t\tint op_type = get_operator( src, line, line_len, line_num, i );\n\t\tif( op_type < 0 ) {\n\t\t\terr = E_LEX_FAIL;\n\t\t\tbreak;\n\t\t}\n\t\tif( op_type == TOK_TDOT ) {\n\t\t\ttoks.emplace_back( line_num, tmp_i, op_type, TokStrs[ op_type ] );\n\t\t} else {\n\t\t\ttoks.emplace_back( line_num, tmp_i, op_type, \"\" );\n\t\t}\n\t}\n\n\treturn err;\n}\n\nstatic std::string get_name( const std::string & line, const int line_len, int & i )\n{\n\tstd::string buf;\n\tbuf.push_back( line[ i++ ] );\n\twhile( i < line_len ) {\n\t\tif( !isalnum( CURR( line ) ) && CURR( line ) != '_' ) break;\n\t\tbuf.push_back( line[ i++ ] );\n\t}\n\treturn buf;\n}\n\nstatic int classify_str( const std::string & str )\n{\n\tif( str == TokStrs[ TOK_ENUM ] ) return TOK_ENUM;\n\telse if( str == TokStrs[ TOK_ENUM_MASK ] ) return TOK_ENUM_MASK;\n\telse if( str == TokStrs[ TOK_IMPORT ] ) return TOK_IMPORT;\n\telse if( str == TokStrs[ TOK_AS ] ) return TOK_AS;\n\telse if( str == TokStrs[ TOK_STRUCT ] ) return TOK_STRUCT;\n\telse if( str == TokStrs[ TOK_FN ] ) return TOK_FN;\n\telse if( str == TokStrs[ TOK_MFN ] ) return TOK_MFN;\n\telse if( str == TokStrs[ TOK_RETURN ] ) return TOK_RETURN;\n\telse if( str == TokStrs[ TOK_IF ] ) return TOK_IF;\n\telse if( str == TokStrs[ TOK_ELIF ] ) return TOK_ELIF;\n\telse if( str == TokStrs[ TOK_ELSE ] ) return TOK_ELSE;\n\telse if( str == TokStrs[ TOK_FOR ] ) return TOK_FOR;\n\telse if( str == TokStrs[ TOK_IN ] ) return TOK_IN;\n\telse if( str == TokStrs[ TOK_CONTINUE ] ) return TOK_CONTINUE;\n\telse if( str == TokStrs[ TOK_BREAK ] ) return TOK_BREAK;\n\telse if( str == TokStrs[ TOK_LDMOD ] ) return TOK_LDMOD;\n\telse if( str == TokStrs[ TOK_TRUE ] ) return TOK_TRUE;\n\telse if( str == TokStrs[ TOK_FALSE ] ) return TOK_FALSE;\n\telse if( str == TokStrs[ TOK_NIL ] ) return TOK_NIL;\n\n\treturn TOK_IDEN;\n}\n\nstatic std::string get_num( const std::string & src, const std::string & line, const int line_len, const int line_num, int & i, int & num_type )\n{\n\tstd::string buf;\n\tint first_digit_at = i;\n\n\tbool success = true;\n\tint dot_encountered = -1;\n\n\twhile( i < line_len && is_valid_num_char( CURR( line ) ) ) {\n\t\tconst char c = CURR( line );\n\t\tconst char next = NEXT( line );\n\t\tswitch( c ) {\n\t\tcase '0':\n\t\tcase '1':\n\t\tcase '2':\n\t\tcase '3':\n\t\tcase '4':\n\t\tcase '5':\n\t\tcase '6':\n\t\tcase '7':\n\t\tcase '8':\n\t\tcase '9':\n\t\t\tbreak;\n\t\tcase '.':\n\t\t\tif( dot_encountered == -1 ) {\n\t\t\t\tif( next >= '0' && next <= '9' ) {\n\t\t\t\t\tdot_encountered = i;\n\t\t\t\t\tnum_type = TOK_FLT;\n\t\t\t\t} else {\n\t\t\t\t\treturn buf;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tSRC_FAIL( \"encountered dot (.) character \"\n\t\t\t\t\t  \"when the number being retrieved (from column %d) \"\n\t\t\t\t\t  \"already had one at column %d\",\n\t\t\t\t\t  first_digit_at + 1, dot_encountered + 1 );\n\t\t\t\tsuccess = false;\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tif( isalnum( CURR( line ) ) ) {\n\t\t\t\tSRC_FAIL( \"encountered invalid character '%c' \"\n\t\t\t\t\t  \"while retrieving a number (from column %d)\",\n\t\t\t\t\t  c, first_digit_at + 1 );\n\t\t\t\tsuccess = false;\n\t\t\t} else {\n\t\t\t\treturn buf;\n\t\t\t}\n\n\t\t}\n\t\tif( success == false ) {\n\t\t\treturn \"\";\n\t\t}\n\t\tbuf.push_back( c ); ++i;\n\t}\n\treturn buf;\n}\n\nstatic int get_const_str( const std::string & src, const std::string & line, const int line_len, const int line_num, int & i, std::string & buf )\n{\n\tbuf.clear();\n\tconst char quote_type = CURR( line );\n\tint starting_at = i;\n\t// omit beginning quote\n\t++i;\n\twhile( i < line_len ) {\n\t\tif( CURR( line ) == quote_type && PREV( line ) != '\\\\' ) break;\n\n\t\tbuf.push_back( line[ i++ ] );\n\t}\n\tif( CURR( line ) != quote_type ) {\n\t\ti = starting_at;\n\t\tSRC_FAIL( \"no matching quote for '%c' found\",\n\t\t\t  quote_type );\n\t\treturn E_LEX_FAIL;\n\t}\n\t// omit ending quote\n\t++i;\n\tremove_back_slash( buf );\n\treturn E_OK;\n}\n\nstatic int get_operator( const std::string & src, const std::string & line, const int line_len, const int line_num, int & i )\n{\n\tint op_type = -1;\n\tswitch( CURR( line ) ) {\n\tcase '+':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\top_type = TOK_ADD_ASSN;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_ADD );\n\tcase '-':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\top_type = TOK_SUB_ASSN;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_SUB );\n\tcase '*':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '*' || NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\tif( CURR( line ) == '*' ) op_type = TOK_POW;\n\t\t\t\telse if( CURR( line ) == '=' ) op_type = TOK_MUL_ASSN;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_MUL );\n\tcase '/':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\tSET_OP_TYPE_BRK( TOK_DIV_ASSN );\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_DIV );\n\tcase '%':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\tSET_OP_TYPE_BRK( TOK_MOD_ASSN );\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_MOD );\n\tcase '&':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '&' || NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\tif( CURR( line ) == '&' ) op_type = TOK_AND;\n\t\t\t\telse if( CURR( line ) == '=' ) op_type = TOK_BAND_ASSN;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_BAND );\n\tcase '|':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '|' || NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\tif( CURR( line ) == '|' ) op_type = TOK_OR;\n\t\t\t\telse if( CURR( line ) == '=' ) op_type = TOK_BOR_ASSN;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_BOR );\n\tcase '~':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\tSET_OP_TYPE_BRK( TOK_BNOT_ASSN );\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_BNOT );\n\tcase '=':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\tSET_OP_TYPE_BRK( TOK_EQ );\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_ASSN );\n\tcase '<':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' || NEXT( line ) == '<' ) {\n\t\t\t\t++i;\n\t\t\t\tif( CURR( line ) == '=' ) op_type = TOK_LE;\n\t\t\t\telse if( CURR( line ) == '<' ) {\n\t\t\t\t\tif( i < line_len - 1 ) {\n\t\t\t\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t\t\t\t++i;\n\t\t\t\t\t\t\tSET_OP_TYPE_BRK( TOK_LSHIFT_ASSN );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\top_type = TOK_LSHIFT;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_LT );\n\tcase '>':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' || NEXT( line ) == '>' ) {\n\t\t\t\t++i;\n\t\t\t\tif( CURR( line ) == '=' ) op_type = TOK_GE;\n\t\t\t\telse if( CURR( line ) == '>' ) {\n\t\t\t\t\tif( i < line_len - 1 ) {\n\t\t\t\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t\t\t\t++i;\n\t\t\t\t\t\t\tSET_OP_TYPE_BRK( TOK_RSHIFT_ASSN );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\top_type = TOK_RSHIFT;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_GT );\n\tcase '!':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\tSET_OP_TYPE_BRK( TOK_NE );\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_NOT );\n\tcase '^':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '=' ) {\n\t\t\t\t++i;\n\t\t\t\tSET_OP_TYPE_BRK( TOK_BXOR_ASSN );\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_BXOR );\n\tcase '?':\n\t\tSET_OP_TYPE_BRK( TOK_QUEST );\n\tcase ' ':\n\t\tSET_OP_TYPE_BRK( TOK_SPC );\n\tcase '\\t':\n\t\tSET_OP_TYPE_BRK( TOK_TAB );\n\tcase '\\n':\n\t\tSET_OP_TYPE_BRK( TOK_NEWL );\n\tcase '.':\n\t\tif( i < line_len - 1 ) {\n\t\t\tif( NEXT( line ) == '.' ) {\n\t\t\t\t++i;\n\t\t\t\tif( i < line_len - 1 ) {\n\t\t\t\t\tif( NEXT( line ) == '.' ) {\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\tSET_OP_TYPE_BRK( TOK_TDOT );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSET_OP_TYPE_BRK( TOK_DOT );\n\tcase ',':\n\t\tSET_OP_TYPE_BRK( TOK_COMMA );\n\tcase ':':\n\t\tSET_OP_TYPE_BRK( TOK_COL );\n\tcase ';':\n\t\tSET_OP_TYPE_BRK( TOK_COLS );\n\tcase '@':\n\t\tSET_OP_TYPE_BRK( TOK_AT );\n\tcase '(':\n\t\tSET_OP_TYPE_BRK( TOK_LPAREN );\n\tcase '[':\n\t\tSET_OP_TYPE_BRK( TOK_LBRACK );\n\tcase '{':\n\t\tSET_OP_TYPE_BRK( TOK_LBRACE );\n\tcase ')':\n\t\tSET_OP_TYPE_BRK( TOK_RPAREN );\n\tcase ']':\n\t\tSET_OP_TYPE_BRK( TOK_RBRACK );\n\tcase '}':\n\t\tSET_OP_TYPE_BRK( TOK_RBRACE );\n\tdefault:\n\t\tSRC_FAIL( \"unknown operator '%c' found\",\n\t\t\t  CURR( line ) );\n\t\top_type = -1;\n\t}\n\n\t++i;\n\treturn op_type;\n}\n\nstatic inline bool is_valid_num_char( const char c )\n{\n\treturn ( c >= '0' && c <= '9' ) || ( c >= 'a' && c <= 'f' ) || ( c >= 'A' && c <= 'F' )\n\t\t|| c == '.' || c == '-' || c == '+' || c == 'o' || c == 'O' || c == 'x' || c == 'X';\n}\n\nstatic void remove_back_slash( std::string & s )\n{\n\tfor( auto it = s.begin(); it != s.end(); ++it ) {\n\t\tif( * it == '\\\\' ) {\n\t\t\tif( it + 1 >= s.end() ) continue;\n\t\t\tit = s.erase( it );\n\t\t\tif( * it == 'a' ) * it = '\\a';\n\t\t\telse if( * it == 'b' ) * it = '\\b';\n\t\t\telse if( * it == 'f' ) * it = '\\f';\n\t\t\telse if( * it == 'n' ) * it = '\\n';\n\t\t\telse if( * it == 'r' ) * it = '\\r';\n\t\t\telse if( * it == 't' ) * it = '\\t';\n\t\t\telse if( * it == 'v' ) * it = '\\v';\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/FE/Lexer.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef LEXER_HPP\n#define LEXER_HPP\n\n#include <vector>\n#include <string>\n\n#include \"Core.hpp\"\n\n/**\n * \\brief All valid lexical tokens in the language\n */\nenum TokType\n{\n\tTOK_INT,\n\tTOK_FLT,\n\n\tTOK_STR,\n\tTOK_IDEN,\n\n\t//Keywords\n\tTOK_ENUM,\n\tTOK_ENUM_MASK,\n\tTOK_IMPORT,\n\tTOK_AS,\n\tTOK_STRUCT,\n\tTOK_FN,\n\tTOK_MFN,\n\tTOK_RETURN,\n\tTOK_IF,\n\tTOK_ELIF,\n\tTOK_ELSE,\n\tTOK_FOR,\n\tTOK_IN,\n\tTOK_CONTINUE,\n\tTOK_BREAK,\n\tTOK_LDMOD,\n\tTOK_TRUE,\n\tTOK_FALSE,\n\tTOK_NIL,\n\t// if the source file is the actual executed one, execute the code between these symbols\n\tTOK_MAIN_SRC_BEG,\n\tTOK_MAIN_SRC_END,\n\n\t// Operators\n\tTOK_ASSN,\n\t// Arithmetic\n\tTOK_ADD,\n\tTOK_SUB,\n\tTOK_MUL,\n\tTOK_DIV,\n\tTOK_MOD,\n\tTOK_ADD_ASSN,\n\tTOK_SUB_ASSN,\n\tTOK_MUL_ASSN,\n\tTOK_DIV_ASSN,\n\tTOK_MOD_ASSN,\n\tTOK_POW, // **\n\t// Unary\n\tTOK_UADD,\n\tTOK_USUB,\n\t// Logic\n\tTOK_AND,\n\tTOK_OR,\n\tTOK_NOT,\n\tTOK_EQ,\n\tTOK_LT,\n\tTOK_GT,\n\tTOK_LE,\n\tTOK_GE,\n\tTOK_NE,\n\t// Bitwise\n\tTOK_BAND,\n\tTOK_BOR,\n\tTOK_BNOT,\n\tTOK_BXOR,\n\tTOK_BAND_ASSN,\n\tTOK_BOR_ASSN,\n\tTOK_BNOT_ASSN,\n\tTOK_BXOR_ASSN,\n\t// Others\n\tTOK_LSHIFT,\n\tTOK_RSHIFT,\n\tTOK_LSHIFT_ASSN,\n\tTOK_RSHIFT_ASSN,\n\t// Conditional ( ? : )\n\tTOK_QUEST,\n\tTOK_COL,  // :\n\n\t// Varargs\n\tTOK_TDOT,\n\n\t// Separators\n\tTOK_DOT,\n\tTOK_COMMA,\n\tTOK_AT,\n\tTOK_SPC,\n\tTOK_TAB,\n\tTOK_NEWL,\n\tTOK_COLS, // Semi colon\n\t// Parenthesis, Braces, Brackets\n\tTOK_LPAREN,\n\tTOK_RPAREN,\n\tTOK_LBRACE,\n\tTOK_RBRACE,\n\tTOK_LBRACK,\n\tTOK_RBRACK,\n\n\tTOK_INVALID,\n\n\t_TOK_LAST,\n};\n\n/**\n * \\brief String value of each of the lexical tokens\n */\nextern const char * TokStrs[ _TOK_LAST ];\n\n/**\n * \\brief Describes line number, column number,\n * \t  token type, and string data of a token\n */\nstruct tok_t\n{\n\tint line;\n\tint col;\n\tTokType type;\n\tstd::string data;\n\n\ttok_t( int _line, int _col, int _type, std::string _data ) :\n\t       line( _line ), col( _col ), type( ( TokType)_type ), data( _data ) {}\n};\n\n\n/**\n * \\brief A list of tokens\n */\ntypedef std::vector< tok_t > toks_t;\n\nstruct src_t;\n\n/**\n * \\brief Main tokenizing function which is called for generating\n *\t  tokens from source code and store in field: toks of src_t\n * \\param reference to src_t which contains file name in field: name;\n *\n * \\return on success: E_OK, on fail: something else from Errors enum\n */\nint tokenize( src_t & src );\n\n/**\n * \\brief Check if the given type (int) is a variable data\n *\n * A 'variable data' consists of ints, floats, const strings, and identifiers\n *\n * \\param int type - from enum TokType\n * \\return true if the type is one of variable data tokens, false if it isn't\n */\ninline bool token_type_is_data( const int type )\n{\n\treturn type == TOK_INT || type == TOK_FLT ||\n\t       type == TOK_STR || type == TOK_IDEN ||\n\t       type == TOK_TRUE || type == TOK_FALSE ||\n\t       type == TOK_NIL || type == TOK_TDOT;\n}\n\n/**\n * \\brief Check if the given type (int) is an operator\n *\n * \\param int type - from enum TokType\n * \\return true if the type is one of possible operators, false if it isn't\n */\ninline bool token_type_is_oper( const int type )\n{\n\treturn ( type >= TOK_ASSN && type <= TOK_RBRACK );\n}\n\n/**\n * \\brief Check if the given type (int) is an assignment operator\n *\n * \\param int type - from enum TokType\n * \\return true if the type is one of possible assignment operators, false if it isn't\n */\ninline bool token_type_is_one_of_assign( const int type )\n{\n\treturn ( type == TOK_ASSN ||\n\t\t type == TOK_ADD_ASSN ||\n\t\t type == TOK_SUB_ASSN ||\n\t\t type == TOK_MUL_ASSN ||\n\t\t type == TOK_DIV_ASSN ||\n\t\t type == TOK_MOD_ASSN ||\n\t\t type == TOK_BAND_ASSN ||\n\t\t type == TOK_BOR_ASSN ||\n\t\t type == TOK_BNOT_ASSN ||\n\t\t type == TOK_BXOR_ASSN ||\n\t\t type == TOK_LSHIFT_ASSN ||\n\t\t type == TOK_RSHIFT_ASSN\n\t\t);\n}\n\n/**\n * \\brief Check if the given token pointer's type is a variable data\n *\n * A 'variable data' consists of ints, floats, const strings, and identifiers\n *\n * This function calls the equivalent token_type_is_data function\n *\n * \\param tok_t *\n * \\return true if the type is one of variable data tokens, false if it isn't\n */\ninline bool token_is_data( const tok_t * tok )\n{\n\treturn token_type_is_data( tok->type );\n}\n\n/**\n * \\brief Check if the given token pointer's type is an operator\n *\n * This function calls the equivalent token_type_is_oper function\n *\n * \\param tok_t *\n * \\return true if the type is one of operator tokens, false if it isn't\n */\ninline bool token_is_oper( const tok_t * tok )\n{\n\treturn token_type_is_oper( tok->type );\n}\n\n/**\n * \\brief Check if the given token pointer's type is an assignment operator\n *\n * This function calls the equivalent token_type_is_assign function\n *\n * \\param tok_t *\n * \\return true if the type is one of assignment operator tokens, false if it isn't\n */\ninline bool token_is_one_of_assign( const tok_t * tok )\n{\n\treturn token_type_is_one_of_assign( tok->type );\n}\n\n#endif // LEXER_HPP\n"
  },
  {
    "path": "src/FE/Main.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cstdio>\n#include <vector>\n#include <string>\n\n#include \"../Config.hpp\"\n\n#include \"CmdArgs.hpp\"\n#include \"Env.hpp\"\n#include \"FS.hpp\"\n#include \"Parser.hpp\"\n\n#include \"../VM/VM.hpp\"\n\nint main( int argc, char ** argv )\n{\n\tstd::vector< std::string > args;\n\tsize_t flags = cmd_get_args( argc, ( const char ** )argv, args );\n\n\tif( flags & OPT_V ) {\n\t\tfprintf( stdout, \"Ethereal %d.%d.%d\\nBuilt with %s\\nOn %s\\n\", ETHEREAL_VERSION_MAJOR,\n\t\t\t ETHEREAL_VERSION_MINOR, ETHEREAL_VERSION_PATCH, BUILD_CXX_COMPILER, BUILD_DATE );\n\t\treturn E_OK;\n\t}\n\n\tif( args.size() < 1 ) {\n\t\tfprintf( stderr, \"usage: %s [flags] <source file>\\n\", argv[ 0 ] );\n\t\treturn E_FAIL;\n\t}\n\n\t// fetch the absolute ethereal binary path which was executed to set __PROG__ var.\n\tstd::string eth_bin_loc = GetEtherealBinaryAbsoluteLoc( argv[ 0 ] );\n\n\t// source script dir\n\tauto last_slash_loc = args[ 0 ].find_last_of( '/' );\n\tstd::string src_dir = last_slash_loc == std::string::npos ? \".\" : args[ 0 ].substr( 0, last_slash_loc );\n\tDirFormat( src_dir );\n\n\tint err = E_OK;\n\tconst std::string main_src_str = args[ 0 ].substr( last_slash_loc + 1 );\n\n\tsrc_t * main_src = new src_t( true );\n\tmain_src->id = 0;\n\tmain_src->file = main_src_str;\n\tmain_src->dir = src_dir;\n\terr = tokenize( * main_src );\n\tif( err != E_OK ) goto cleanup;\n\n\tif( flags & OPT_T ) {\n\t\tfprintf( stdout, \"Tokens:\\n\" );\n\t\tauto & toks = main_src->toks;\n\t\tfor( size_t i = 0; i < toks.size(); ++i ) {\n\t\t\tauto & tok = toks[ i ];\n\t\t\tfprintf( stdout, \"ID: %zu\\tType: %s\\tLine: %d[%d]\\tSymbol: %s\\n\",\n\t\t\t\t i, TokStrs[ tok.type ], tok.line, tok.col, tok.data.c_str() );\n\t\t}\n\t}\n\n\terr = E_OK;\n\tmain_src->ptree = parse( * main_src );\n\n\tif( main_src->ptree == nullptr ) { err = E_PARSE_FAIL; goto cleanup; }\n\n\tif( flags & OPT_P ) {\n\t\tfprintf( stdout, \"Parse Tree:\\n\" );\n\t\tfor( auto it = main_src->ptree->begin(); it != main_src->ptree->end(); ++it ) {\n\t\t\t( * it )->disp( it != main_src->ptree->end() - 1 );\n\t\t}\n\t}\n\n\terr = E_OK;\n\tfor( auto & it : * main_src->ptree ) {\n\t\tif( !it->bytecode( * main_src ) ) { err = E_BYTECODE_FAIL; goto cleanup; }\n\t}\n\n\tif( flags & OPT_B ) {\n\t\tfprintf( stdout, \"Byte Code:\\n\" );\n\t\tfor( size_t i = 0; i < main_src->bcode.size(); ++i ) {\n\t\t\tauto & ins = main_src->bcode[ i ];\n\t\t\tfprintf( stdout, \"%-*zu %-*s%-*s[%s]\\n\",\n\t\t\t\t 5, i, 20, InstrCodeStrs[ ins.opcode ], 7,\n\t\t\t\t OperTypeStrs[ ins.oper.type ], ins.oper.val.c_str() );\n\t\t}\n\t}\n\n\tif( err != E_OK ) goto cleanup;\n\n\t// actual code execution\n\tif( !( flags & OPT_C ) && !( flags & OPT_D ) ) {\n\t\tvm_state_t vm;\n\t\tvm.flags = flags;\n\t\tvm.srcstack.push_back( main_src );\n\t\tvm.srclist.push_back( main_src->file );\n\t\tvm.srcs[ main_src->id ] = main_src;\n\t\tstd::vector< var_base_t * > arg_vec;\n\t\tfor( auto & v : args ) {\n\t\t\targ_vec.push_back( new var_str_t( v, 0 ) );\n\t\t}\n\t\tvm.vars->add( \"__PROG__\", new var_str_t( eth_bin_loc, 0 ) );\n\t\tvm.vars->add( \"__VERSION_MAJOR__\", new var_int_t( ETHEREAL_VERSION_MAJOR, 0 ) );\n\t\tvm.vars->add( \"__VERSION_MINOR__\", new var_int_t( ETHEREAL_VERSION_MINOR, 0 ) );\n\t\tvm.vars->add( \"__VERSION_PATCH__\", new var_int_t( ETHEREAL_VERSION_PATCH, 0 ) );\n\t\tvm.vars->add( \"args\", new var_vec_t( arg_vec, 0 ) );\n\t\tvm.vars->add( \"true\", new var_bool_t( true, 0 ) );\n\t\tvm.vars->add( \"false\", new var_bool_t( false, 0 ) );\n\t\t// call this to set base precision for mpfr\n\t\tupdate_float_precision();\n\t\tif( !set_init_mods( vm ) ) { err = E_VM_FAIL; goto end; }\n\t\terr = vm_exec( vm );\n\t\tvm.srclist.clear();\n\t\tvm.srcstack.pop_back();\n\t\tgoto end;\n\t}\ncleanup:\n\tdelete main_src;\nend:\n\treturn err;\n}"
  },
  {
    "path": "src/FE/Parser/Block.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Parser.hpp\"\n#include \"../Ethereal.hpp\"\n\nstmt_block_t * parse_block( src_t & src, parse_helper_t * ph, std::vector< GrammarTypes > & parents )\n{\n\tint tok_ctr = ph->tok_ctr();\n\tint end_brace;\n\tint err = find_next_of( ph, end_brace, { TOK_RBRACE }, TOK_LBRACE, true );\n\tstd::vector< stmt_base_t * > * block = nullptr;\n\tif( err < 0 ) {\n\t\tPARSE_FAIL( \"could not find the ending (right) brace for block\" );\n\t\treturn nullptr;\n\t}\n\t// without moving to next point, the parse() and parse_block() will\n\t// go on forever, thereby causing seg fault (stack overflow)\n\tph->next();\n\tblock = parse( src, ph, parents, end_brace );\n\tif( block == nullptr ) return nullptr;\n\treturn new stmt_block_t( block, tok_ctr, parents.size() > 0 && parents.back() == GRAM_FUNC );\n}\n\nbool stmt_block_t::bytecode( src_t & src ) const\n{\n\tint line = src.toks[ m_tok_ctr ].line;\n\tint col = src.toks[ m_tok_ctr ].col;\n\tINC_SCOPE();\n\tfor( auto & stmt : * m_stmts ) {\n\t\tif( !stmt->bytecode( src ) ) return false;\n\t}\n\tif( m_in_func && src.bcode.back().opcode != IC_RETURN && src.bcode.back().opcode != IC_RETURN_EMPTY ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, line, col, IC_PUSH, { OP_NONE, \"\" } } );\n\t}\n\tDEC_SCOPE();\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/Break.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nbool stmt_break_t::bytecode( src_t & src ) const\n{\n\tint line = src.toks[ m_tok_ctr ].line;\n\tint col = src.toks[ m_tok_ctr ].col;\n\tsrc.bcode.push_back( { m_tok_ctr, line, col, IC_REM_SCOPE, { OP_INT, std::to_string( src.block_depth.back().back() - 1 ) } } );\n\tsrc.bcode.push_back( { m_tok_ctr, line, col, IC_JUMP, { OP_INT, \"<break-placeholder>\" } } );\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/Collection.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nbool stmt_collection_t::bytecode( src_t & src ) const\n{\n\tif( m_vals ) m_vals->bytecode( src );\n\n\tsrc.bcode.push_back( { m_tok_ctr, m_line, m_col, m_is_map ? IC_BUILD_MAP : IC_BUILD_VEC,\n\t                       { OP_INT, std::to_string( m_is_map ? m_arg_count / 2 : m_arg_count ) } } );\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/Continue.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nbool stmt_continue_t::bytecode( src_t & src ) const\n{\n\tint line = src.toks[ m_tok_ctr ].line;\n\tint col = src.toks[ m_tok_ctr ].col;\n\tsrc.bcode.push_back( { m_tok_ctr, line, col, IC_REM_SCOPE, { OP_INT, std::to_string( src.block_depth.back().back() - 1 ) } } );\n\tsrc.bcode.push_back( { m_tok_ctr, line, col, IC_JUMP, { OP_INT, \"<continue-placeholder>\" } } );\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/Enum.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nstmt_enum_t * parse_enum( const src_t & src, parse_helper_t * ph )\n{\n\tint tok_ctr = ph->tok_ctr();\n\n\tbool is_mask = false;\n\tif( ph->peak()->type == TOK_ENUM_MASK ) is_mask = true;\n\n\tconst tok_t * name = nullptr;\n\n\tNEXT_VALID( TOK_IDEN );\n\tname = ph->peak();\n\n\tstd::vector< tok_t * > vals;\n\n\tNEXT_VALID( TOK_LBRACE );\n\tNEXT_VALID( TOK_IDEN );\nval_begin:\n\tvals.push_back( ph->peak() );\n\n\tif( ph->peak( 1 )->type == TOK_COMMA ) {\n\t\tph->next();\n\t\tif( ph->peak( 1 )->type == TOK_IDEN ) {\n\t\t\tph->next();\n\t\t\tgoto val_begin;\n\t\t}\n\t}\n\n\tNEXT_VALID( TOK_RBRACE );\n\t// now at RBRACE\n\treturn new stmt_enum_t( name, vals, is_mask, tok_ctr );\n}\n\nbool stmt_enum_t::bytecode( src_t & src ) const\n{\n\tfor( auto v = m_vals.rbegin(); v != m_vals.rend(); ++v ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, ( * v )->line, ( * v )->col, IC_PUSH, { OP_CONST, ( * v )->data } } );\n\t}\n\tsrc.bcode.push_back( { m_tok_ctr, m_name->line, m_name->col, IC_PUSH, { OP_CONST, m_name->data } } );\n\tsrc.bcode.push_back( { m_tok_ctr, m_name->line, m_name->col, m_is_mask ? IC_BUILD_ENUM_MASK : IC_BUILD_ENUM,\n\t\t\t       { OP_INT, std::to_string( m_vals.size() ) } } );\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/Expression.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nstmt_expr_t * gen_tree( const src_t & src, parse_helper_t * ph, std::vector< stmt_base_t * > & data );\n\nexpr_res_t parse_expr( const src_t & src, parse_helper_t * ph, const int end, const bool is_top )\n{\n\tstd::vector< stmt_base_t * > data;\n\tstd::vector< stmt_simple_t * > stack;\n\tstmt_expr_t * res = nullptr;\n\n\tint triple_dot_ctr = 0;\n\tint start = ph->tok_ctr();\n\n\twhile( end == -1 || ( ph->peak()->type != TOK_INVALID && ph->tok_ctr() < end ) ) {\n\t\tif( ph->peak()->type == TOK_COLS ) break;\n\n\t\tif( ph->peak()->type == TOK_IDEN && ( end == -1 || ph->tok_ctr() + 1 < end ) && ph->peak( 1 )->type == TOK_LBRACE ) {\n\t\t\ttok_t * name = ph->peak();\n\t\t\tint tok_val = ph->tok_ctr();\n\t\t\tph->next();\n\t\t\tint rbrace_loc;\n\t\t\tint err = find_next_of( ph, rbrace_loc, { TOK_RBRACE }, TOK_LBRACE );\n\t\t\tif( err < 0 ) {\n\t\t\t\tif( err == -1 ) {\n\t\t\t\t\tPARSE_FAIL( \"could not find the equivalent ending brace for parsing the struct '%s'\", name->data.c_str() );\n\t\t\t\t} else if( err == -2 ) {\n\t\t\t\t\tPARSE_FAIL( \"found end of statement (semicolon) before the equivalent ending brace for struct object\" );\n\t\t\t\t}\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tph->next();\n\t\t\texpr_res_t struct_args = parse_expr( src, ph, rbrace_loc, false );\n\t\t\tif( struct_args.res != 0 ) goto fail;\n\t\t\tstmt_func_struct_subscr_call_t * struct_call = new stmt_func_struct_subscr_call_t(\n\t\t\t\tnew stmt_simple_t( SIMPLE_TOKEN, name, tok_val ),\n\t\t\t\t{ struct_args.expr }, tok_val\n\t\t\t);\n\t\t\tstruct_call->m_ctype = CT_STRUCT;\n\t\t\tif( !stack.empty() && stack.back()->m_val->type == TOK_DOT ) struct_call->m_post_dot = true;\n\t\t\tdata.push_back( struct_call );\n\t\t} else if( ( ( ph->peak()->type == TOK_IDEN || ph->peak()->type == TOK_STR ) &&\n\t\t           ( end == -1 || ph->tok_ctr() + 1 < end ) &&\n\t\t\t   ph->peak( 1 )->type == TOK_LBRACK ) ||\n\t\t\t   ( ph->peak()->type == TOK_LBRACK &&\n\t\t\t   ( data.size() > 0 && data.back()->m_type == GRAM_FN_STRUCT_SUBSCR_CALL ) ) ) {\n\t\t\tif( ph->peak()->type == TOK_LBRACK ) {\n\t\t\t\tint rbrack_loc;\n\t\t\t\tint err = find_next_of( ph, rbrack_loc, { TOK_RBRACK }, TOK_LBRACK );\n\t\t\t\tif( err < 0 ) {\n\t\t\t\t\tif( err == -1 ) {\n\t\t\t\t\t\tPARSE_FAIL( \"could not find the equivalent ending bracket for parsing the sub-subscript\" );\n\t\t\t\t\t} else if( err == -2 ) {\n\t\t\t\t\t\tPARSE_FAIL( \"found end of statement (semicolon) before the equivalent ending bracket for subscript declaration\" );\n\t\t\t\t\t}\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tph->next();\n\t\t\t\texpr_res_t subscr = parse_expr( src, ph, rbrack_loc, false );\n\t\t\t\tif( subscr.res != 0 ) goto fail;\n\t\t\t\tstatic_cast< stmt_func_struct_subscr_call_t * >( data.back() )->m_args.push_back( subscr.expr );\n\t\t\t} else {\n\t\t\t\ttok_t * name = ph->peak();\n\t\t\t\tint tok_val = ph->tok_ctr();\n\t\t\t\tph->next();\n\t\t\t\tint rbrack_loc;\n\t\t\t\tint err = find_next_of( ph, rbrack_loc, { TOK_RBRACK }, TOK_LBRACK );\n\t\t\t\tif( err < 0 ) {\n\t\t\t\t\tif( err == -1 ) {\n\t\t\t\t\t\tPARSE_FAIL( \"could not find the equivalent ending bracket for parsing the subscript of '%s'\", name->data.c_str() );\n\t\t\t\t\t} else if( err == -2 ) {\n\t\t\t\t\t\tPARSE_FAIL( \"found end of statement (semicolon) before the equivalent ending bracket for subscript declaration\" );\n\t\t\t\t\t}\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tph->next();\n\t\t\t\texpr_res_t subscr = parse_expr( src, ph, rbrack_loc, false );\n\t\t\t\tif( subscr.res != 0 ) goto fail;\n\t\t\t\tstmt_func_struct_subscr_call_t * subscr_call = new stmt_func_struct_subscr_call_t(\n\t\t\t\t\tnew stmt_simple_t( SIMPLE_TOKEN, name, tok_val ),\n\t\t\t\t\t{ subscr.expr }, tok_val\n\t\t\t\t);\n\t\t\t\tsubscr_call->m_ctype = CT_SUBSCR;\n\t\t\t\tif( !stack.empty() && stack.back()->m_val->type == TOK_DOT ) subscr_call->m_post_dot = true;\n\t\t\t\tdata.push_back( subscr_call );\n\t\t\t}\n\t\t} else if( ph->peak()->type == TOK_IDEN && ( end == -1 || ph->tok_ctr() + 1 < end ) && ph->peak( 1 )->type == TOK_LPAREN ) {\n\t\t\ttok_t * name = ph->peak();\n\t\t\tint tok_val = ph->tok_ctr();\n\t\t\tph->next();\n\t\t\tint rparen_loc;\n\t\t\tint err = find_next_of( ph, rparen_loc, { TOK_RPAREN }, TOK_LPAREN );\n\t\t\tif( err < 0 ) {\n\t\t\t\tif( err == -1 ) {\n\t\t\t\t\tPARSE_FAIL( \"could not find the equivalent ending parentheses for parsing the function call '%s'\", name->data.c_str() );\n\t\t\t\t} else if( err == -2 ) {\n\t\t\t\t\tPARSE_FAIL( \"found end of statement (semicolon) before the equivalent ending parentheses for function call\" );\n\t\t\t\t}\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tph->next();\n\t\t\texpr_res_t fn_args = parse_expr( src, ph, rparen_loc, false );\n\t\t\tif( fn_args.res != 0 ) goto fail;\n\t\t\tstmt_func_struct_subscr_call_t * fn_call = new stmt_func_struct_subscr_call_t(\n\t\t\t\tnew stmt_simple_t( SIMPLE_TOKEN, name, tok_val ),\n\t\t\t\t{ fn_args.expr }, tok_val\n\t\t\t);\n\t\t\tif( !stack.empty() && stack.back()->m_val->type == TOK_DOT ) fn_call->m_post_dot = true;\n\t\t\tdata.push_back( fn_call );\n\t\t} else if( ph->peak()->type == TOK_LBRACK || ph->peak()->type == TOK_LBRACE ) {\n\t\t\tint tok_val = ph->tok_ctr();\n\t\t\tconst TokType type = ph->peak()->type;\n\t\t\tTokType eq = type == TOK_LBRACE ? TOK_RBRACE : TOK_RBRACK;\n\t\t\tint r_loc;\n\t\t\tint err = find_next_of( ph, r_loc, { eq }, type );\n\t\t\tif( err < 0 ) {\n\t\t\t\tif( err == -1 ) {\n\t\t\t\t\tPARSE_FAIL( \"could not find the equivalent ending bracket for parsing the map/list\" );\n\t\t\t\t} else if( err == -2 ) {\n\t\t\t\t\tPARSE_FAIL( \"found end of statement (semicolon) before the equivalent ending bracket for map/list declaration\" );\n\t\t\t\t}\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tph->next();\n\t\t\texpr_res_t collect = parse_expr( src, ph, r_loc, false );\n\t\t\tif( collect.res != 0 ) goto fail;\n\t\t\tint child_cc = 0, args = 0;\n\t\t\tif( collect.expr ) {\n\t\t\t\tchild_comma_count( collect.expr, child_cc );\n\t\t\t\targs = child_cc + 1;\n\t\t\t}\n\t\t\tif( type == TOK_LBRACE && args % 2 != 0 ) {\n\t\t\t\tPARSE_FAIL( \"map requires arguments in the multiples of 2 for keys and their values\" );\n\t\t\t\tif( collect.expr ) delete collect.expr;\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tstmt_collection_t * collect_call = new stmt_collection_t(\n\t\t\t\tcollect.expr, tok_val, ph->at( tok_val )->line, ph->at( tok_val )->col\n\t\t\t);\n\t\t\tif( type == TOK_LBRACE ) collect_call->m_is_map = true;\n\t\t\tcollect_call->m_arg_count = args;\n\t\t\tdata.push_back( collect_call );\n\t\t} else {\n\t\t\tif( token_is_data( ph->peak() ) ) {\n\t\t\t\tif( triple_dot_ctr > 0 ) {\n\t\t\t\t\tPARSE_FAIL( \"no data can come after the '...' argument\" );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tif( ph->peak()->type == TOK_TDOT ) ++triple_dot_ctr;\n\n\t\t\t\tstmt_simple_t * sim = new stmt_simple_t(\n\t\t\t\t\tph->peak()->data == TokStrs[ ph->peak()->type ] &&\n\t\t\t\t\tph->peak()->type != TOK_IDEN &&\n\t\t\t\t\tph->peak()->type != TOK_STR\n\t\t\t\t\t\t? SIMPLE_KEYWORD : SIMPLE_TOKEN,\n\t\t\t\t\tph->peak(), ph->tok_ctr()\n\t\t\t\t);\n\t\t\t\tif( !stack.empty() && stack.back()->m_val->type == TOK_DOT ) sim->m_post_dot = true;\n\t\t\t\tdata.push_back( sim );\n\t\t\t\tph->next();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif( !token_is_oper( ph->peak() ) ) {\n\t\t\t\tif( ph->peak()->type == TOK_INVALID ) {\n\t\t\t\t\tph->set_tok_ctr( ph->tok_ctr() - 1 );\n\t\t\t\t\tPARSE_FAIL( \"failed parsing expression, possibly missing semicolon after this\" );\n\t\t\t\t} else {\n\t\t\t\t\tPARSE_FAIL( \"invalid token '%s' while parsing expression\", ph->peak()->data.c_str() );\n\t\t\t\t}\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\t// handle parentheses\n\t\t\tif( ph->peak()->type == TOK_RPAREN || ph->peak()->type == TOK_RBRACE || ph->peak()->type == TOK_RBRACK ) {\n\t\t\t\tbool found = false;\n\t\t\t\tTokType eq;\n\t\t\t\tif( ph->peak()->type == TOK_RPAREN ) eq = TOK_LPAREN;\n\t\t\t\telse if( ph->peak()->type == TOK_RBRACE ) eq = TOK_LBRACE;\n\t\t\t\telse eq = TOK_LBRACK;\n\t\t\t\twhile( stack.size() > 0 ) {\n\t\t\t\t\tif( stack.back()->m_val->type == eq ) {\n\t\t\t\t\t\tdelete stack.back();\n\t\t\t\t\t\tstack.pop_back();\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdata.push_back( stack.back() );\n\t\t\t\t\tstack.pop_back();\n\t\t\t\t}\n\t\t\t\tif( !found ) {\n\t\t\t\t\tif( eq == TOK_LPAREN ) PARSE_FAIL( \"could not find equivalent beginning parentheses\" );\n\t\t\t\t\telse if( eq == TOK_LBRACE ) PARSE_FAIL( \"could not find equivalent beginning brace\" );\n\t\t\t\t\telse if( eq == TOK_LBRACK ) PARSE_FAIL( \"could not find equivalent beginning bracket\" );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tph->next();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// handle unary +/-\n\t\t\tif( ( ph->peak()->type == TOK_ADD || ph->peak()->type == TOK_SUB ) &&\n\t\t\t    ( ph->tok_ctr() == start || ( ph->tok_ctr() > start && token_is_oper( ph->peak( -1 ) ) &&\n\t\t\t      ph->peak( -1 )->type != TOK_RPAREN && ph->peak( -1 )->type != TOK_RBRACE && ph->peak( -1 )->type != TOK_RBRACK ) ) ) {\n\t\t\t\tif( ph->peak()->type == TOK_SUB ) {\n\t\t\t\t\tph->peak()->type = TOK_USUB;\n\t\t\t\t}\n\t\t\t\tif( ph->peak()->type == TOK_ADD ) {\n\t\t\t\t\tph->peak()->type = TOK_UADD;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// do the actual work\n\t\t\tint prec = oper_prec( ph->peak() );\n\t\t\tif( stack.size() > 0 ) {\n\t\t\t\t// sop = stack operator\n\t\t\t\tstmt_simple_t * sop = stack.size() > 0 ? stack.back() : nullptr;\n\t\t\t\t// sprec = stack_oper_precedence\n\t\t\t\tint sprec = sop != nullptr ? oper_prec( sop->m_val ) : -10;\n\t\t\t\twhile( sop != nullptr &&\n\t\t\t\t       sop->m_val->type != TOK_LPAREN && sop->m_val->type != TOK_LBRACE && sop->m_val->type != TOK_LBRACK &&\n\t\t\t\t       prec < sprec ) {\n\t\t\t\t\tdata.push_back( sop );\n\t\t\t\t\tstack.pop_back();\n\t\t\t\t\tsop = stack.size() > 0 ? stack.back() : nullptr;\n\t\t\t\t\tsprec = sop != nullptr ? oper_prec( sop->m_val ) : -10;\n\t\t\t\t}\n\t\t\t\tif( sop != nullptr &&\n\t\t\t\t    sop->m_val->type != TOK_LPAREN && sop->m_val->type != TOK_LBRACE && sop->m_val->type != TOK_LBRACK &&\n\t\t\t\t    prec == sprec ) {\n\t\t\t\t\tif( oper_assoc( sop->m_val ) == LTR ) {\n\t\t\t\t\t\tdata.push_back( sop );\n\t\t\t\t\t\tstack.pop_back();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tstack.push_back( new stmt_simple_t( SIMPLE_OPER, ph->peak(), ph->tok_ctr() ) );\n\t\t}\n\t\tph->next();\n\t}\n\n\tfor( auto & s : stack ) {\n\t\tif( s->m_val->type == TOK_LPAREN ) {\n\t\t\tph->set_tok_ctr( s->m_tok_ctr );\n\t\t\tPARSE_FAIL( \"could not find ending parentheses\" );\n\t\t\tgoto fail;\n\t\t}\n\t}\n\n\twhile( !stack.empty() ) {\n\t\tdata.push_back( stack.back() );\n\t\tstack.pop_back();\n\t}\n\n\tif( data.empty() ) {\n\t\treturn { 0, nullptr };\n\t}\n\n\tres = gen_tree( src, ph, data );\n\tif( res == nullptr ) goto fail;\n\n\tif( is_top ) {\n\t\tres->m_is_top_expr = true;\n\t}\n\n\tif( triple_dot_ctr > 0 ) {\n\t\tres->m_triple_dot = true;\n\t}\n\n\treturn { 0, res };\nfail:\n\tfor( auto & s : stack ) delete s;\n\tfor( auto & d : data ) {\n\t\tdelete d;\n\t}\n\tif( end != -1 ) ph->set_tok_ctr( end );\n\treturn { E_PARSE_FAIL, nullptr };\n}\n\nstmt_expr_t * gen_tree( const src_t & src, parse_helper_t * ph, std::vector< stmt_base_t * > & data )\n{\n\tstd::vector< stmt_base_t * > var_stack;\n\tconst int start_tok_ctr = data.front()->m_tok_ctr;\n\n\tfor( auto it = data.begin(); it != data.end(); ) {\n\t\tif( ( * it )->m_type != GRAM_SIMPLE || ( ( stmt_simple_t * )( * it ) )->m_stype != SIMPLE_OPER ) {\n\t\t\tvar_stack.push_back( * it );\n\t\t\tit = data.erase( it );\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst tok_t * op = ( ( stmt_simple_t * )( * it ) )->m_val;\n\t\tif( var_stack.empty() ) {\n\t\t\tph->set_tok_ctr( ( * it )->m_tok_ctr );\n\t\t\tPARSE_FAIL( \"no operands for operator '%s'\", TokStrs[ op->type ] );\n\t\t\tgoto fail;\n\t\t}\n\n\t\tint arg_count = oper_arg_count( op );\n\t\tif( arg_count < 0 ) {\n\t\t\tph->set_tok_ctr( ( * it )->m_tok_ctr );\n\t\t\tPARSE_FAIL( \"the operator '%s' should not be here\", TokStrs[ op->type ] );\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif( ( int )var_stack.size() < arg_count ) {\n\t\t\tint available = 0;\n\t\t\tfor( auto it = var_stack.rbegin(); it != var_stack.rend(); ++it ) {\n\t\t\t\tif( ( ( stmt_simple_t * )( * it ) )->m_stype == SIMPLE_OPER ) break;\n\t\t\t\t++available;\n\t\t\t}\n\t\t\tph->set_tok_ctr( ( * it )->m_tok_ctr );\n\t\t\tPARSE_FAIL( \"not enough arguments for operator '%s' (expected: %d, available: %d) \"\n\t\t\t\t    \"(possibly an extra comma or a trailing dot)\",\n\t\t\t\t    TokStrs[ op->type ], arg_count, available );\n\t\t\tgoto fail;\n\t\t}\n\n\t\tstmt_base_t * top2 = nullptr;\n\t\tif( arg_count >= 1 ) {\n\t\t\ttop2 = var_stack.back();\n\t\t\tvar_stack.pop_back();\n\t\t}\n\n\t\tstmt_base_t * top1 = nullptr;\n\t\tif( arg_count >= 2 ) {\n\t\t\ttop1 = var_stack.back();\n\t\t\tvar_stack.pop_back();\n\t\t}\n\n\t\t/*\toper\n\t\t\t/  \\\n\t\t      top1 top2\n\t\t*/\n\t\tif( token_is_one_of_assign( op ) &&\n\t\t    ( ( top1 == nullptr || ( ( top1->m_type == GRAM_SIMPLE &&\n\t\t    ( ( stmt_simple_t * )top1 )->m_val->type != TOK_IDEN ) && top1->m_type != GRAM_EXPR ) ) ) ) {\n\t\t\tph->set_tok_ctr( ( * it )->m_tok_ctr );\n\t\t\tPARSE_FAIL( \"expected an lvalue on the left of the assignment operator\" );\n\t\t\tif( arg_count >= 1 ) delete top2;\n\t\t\tif( arg_count >= 2 ) delete top1;\n\t\t\tgoto fail;\n\t\t}\n\n\t\tstmt_expr_t * expr = new stmt_expr_t( top1, ( stmt_simple_t * ) * it, top2, ( * it )->m_tok_ctr );\n\t\tit = data.erase( it );\n\t\tvar_stack.push_back( expr );\n\t}\n\n\tif( var_stack.empty() || var_stack.size() > 1 ) {\n\t\tph->set_tok_ctr( start_tok_ctr );\n\t\tPARSE_FAIL( \"invalid expression, should generate single value, but is generating %zu\", var_stack.size() );\n\t\tgoto fail;\n\t}\n\n\tif( var_stack.back()->m_type != GRAM_EXPR ) {\n\t\tstmt_base_t * data = var_stack.back();\n\t\tvar_stack.pop_back();\n\t\tstmt_expr_t * expr = new stmt_expr_t( nullptr, nullptr, data, data->m_tok_ctr );\n\t\tvar_stack.push_back( expr );\n\t}\n\n\treturn ( stmt_expr_t * )var_stack.back();\n\nfail:\n\tfor( auto & vs : var_stack ) delete vs;\n\treturn nullptr;\n}\n\nbool stmt_expr_t::bytecode( src_t & src ) const\n{\n\tint line = m_oper ? m_oper->m_val->line : src.toks[ m_tok_ctr ].line;\n\tint col = m_oper ? m_oper->m_val->col : src.toks[ m_tok_ctr ].col;\n\n\tif( !m_oper ) {\n\t\tif( m_rhs ) {\n\t\t\tif( src.found_assn ) src.bcode_as_const = true;\n\t\t\tm_rhs->bytecode( src );\n\t\t\tif( src.found_assn ) src.bcode_as_const = false;\n\t\t}\n\t\tif( m_lhs ) m_lhs->bytecode( src );\n\t} else {\n\t\tconst tok_t * oper = m_oper->m_val;\n\n\t\tif( oper_assoc( oper ) == LTR ) {\n\t\t\tint ques_col_loc = -1;\n\t\t\tint and_or_jump = -1;\n\n\t\t\tif( m_lhs ) m_lhs->bytecode( src );\n\n\t\t\tif( oper->type == TOK_AND || oper->type == TOK_OR ) {\n\t\t\t\tand_or_jump = src.bcode.size();\n\t\t\t\tsrc.bcode.push_back( { m_oper->m_tok_ctr, oper->line, oper->col,\n\t\t\t\t\t\t       oper->type == TOK_AND ? IC_JUMP_FALSE_NO_POP : IC_JUMP_TRUE_NO_POP,\n\t\t\t\t\t\t       { OP_INT, \"<and-or-placeholder>\" } } );\n\t\t\t\tsrc.bcode.push_back( { m_oper->m_tok_ctr, oper->line, oper->col, IC_POP, { OP_NONE, \"\" } } );\n\t\t\t}\n\n\t\t\tif( oper->type == TOK_QUEST ) {\n\t\t\t\tques_col_loc = src.bcode.size();\n\t\t\t\tsrc.bcode.push_back( { m_oper->m_tok_ctr, oper->line, oper->col, IC_JUMP_FALSE, { OP_INT, \"<placeholder>\" } } );\n\t\t\t}\n\t\t\tif( oper->type == TOK_COL ) {\n\t\t\t\tques_col_loc = src.bcode.size();\n\t\t\t\tsrc.bcode.push_back( { m_oper->m_tok_ctr, oper->line, oper->col, IC_JUMP, { OP_INT, \"<placeholder>\" } } );\n\t\t\t}\n\n\t\t\tint curr_bcode_size = src.bcode.size();\n\t\t\tif( m_rhs ) m_rhs->bytecode( src );\n\n\t\t\tif( oper->type == TOK_AND || oper->type == TOK_OR ) {\n\t\t\t\tsrc.bcode[ and_or_jump ].oper.val = std::to_string( src.bcode.size() );\n\t\t\t}\n\n\t\t\tif( oper->type == TOK_QUEST || oper->type == TOK_COL ) {\n\t\t\t\tint rhs_bcode_size = src.bcode.size() - curr_bcode_size + ( oper->type == TOK_QUEST );\n\t\t\t\tsrc.bcode[ ques_col_loc ].oper.val = std::to_string( ques_col_loc + rhs_bcode_size + 1 );\n\t\t\t}\n\t\t} else {\n\t\t\tif( m_rhs ) m_rhs->bytecode( src );\n\t\t\tif( m_lhs ) {\n\t\t\t\tif( m_oper->m_val->type == TOK_ASSN ) {\n\t\t\t\t\tsrc.found_assn = true;\n\t\t\t\t}\n\t\t\t\tif( src.found_assn && m_lhs->m_type == GRAM_SIMPLE ) src.bcode_as_const = true;\n\t\t\t\tm_lhs->bytecode( src );\n\t\t\t\tif( src.found_assn && m_lhs->m_type == GRAM_SIMPLE ) src.bcode_as_const = false;\n\t\t\t\tsrc.found_assn = false;\n\t\t\t}\n\t\t}\n\t\tconst TokType ttype = m_oper ? m_oper->m_val->type : TOK_INVALID;\n\n\t\tif( ttype == TOK_COMMA || ttype == TOK_QUEST || ttype == TOK_COL || ttype == TOK_AND || ttype == TOK_OR ) return true;\n\n\t\tif( ttype == TOK_DOT ) {\n\t\t\tif( m_rhs != nullptr ) {\n\t\t\t\tif( m_rhs->m_type == GRAM_EXPR || m_rhs->m_type == GRAM_SIMPLE ) {\n\t\t\t\t\tsrc.bcode.push_back( { m_oper->m_tok_ctr, line, col, IC_ATTR, { OP_NONE, \"\" } } );\n\t\t\t\t}\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tif( ttype == TOK_ASSN ) {\n\t\t\tif( src.bcode.back().opcode != IC_PUSH ) {\n\t\t\t\tsrc.bcode.push_back( { m_oper->m_tok_ctr, line, col,\n\t\t\t\t\t\t       m_is_top_expr ? IC_STORE_STACK : IC_STORE_LOAD_STACK, { OP_NONE, \"\" } } );\n\t\t\t} else {\n\t\t\t\tsrc.bcode.push_back( { m_oper->m_tok_ctr, line, col,\n\t\t\t\t\t\t       m_is_top_expr ? IC_STORE : IC_STORE_LOAD, { OP_NONE, \"\" } } );\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tm_oper->bytecode( src );\n\t\tsrc.bcode.push_back( { m_oper->m_tok_ctr, line, col, IC_FN_CALL,\n\t\t\t\t       { OP_INT, std::to_string( oper_arg_count( m_oper->m_val ) ) } } );\n\t}\nend:\n\tif( m_is_top_expr ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, line, col, IC_POP, { OP_NONE, \"\" } } );\n\t}\n\n\treturn true;\n}\n\nvoid child_comma_count( const stmt_expr_t * expr, int & cc )\n{\n\tif( expr->m_lhs && expr->m_lhs->m_type == GRAM_EXPR ) {\n\t\tconst stmt_expr_t * e = ( const stmt_expr_t * )expr->m_lhs;\n\t\tif( e->m_oper != nullptr && e->m_oper->m_val->type == TOK_COMMA ) child_comma_count( e, cc );\n\t}\n\tif( expr->m_rhs && expr->m_rhs->m_type == GRAM_EXPR ) {\n\t\tconst stmt_expr_t * e = ( const stmt_expr_t * )expr->m_rhs;\n\t\tif( e->m_oper != nullptr && e->m_oper->m_val->type == TOK_COMMA ) child_comma_count( e, cc );\n\t}\n\tif( expr->m_oper && expr->m_oper->m_val->type == TOK_COMMA ) ++cc;\n}"
  },
  {
    "path": "src/FE/Parser/For.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nstatic void set_continue_break_lines( bytecode_t & bcode, const int from,\n\t\t\t\t      const int to, const int cont, const int brk );\n\nstmt_for_t * parse_for( src_t & src, parse_helper_t * ph, std::vector< GrammarTypes > & parents )\n{\n\tint tok_ctr = ph->tok_ctr();\n\n\texpr_res_t init = { 0, nullptr }, cond = { 0, nullptr }, step = { 0, nullptr };\n\tstmt_block_t * block = nullptr;\n\n\tint err, init_cols, cond_cols, step_brace;\n\n\t// initialization\n\tph->next();\n\tif( ph->peak()->type == TOK_COLS ) {\n\t\tgoto cond;\n\t}\n\terr = find_next_of( ph, init_cols, { TOK_COLS } );\n\tif( err < 0 ) {\n\t\tif( err == -1 ) {\n\t\t\tPARSE_FAIL( \"could not find the semicolon for the loop's init statement\" );\n\t\t}\n\t\tgoto fail;\n\t}\n\tinit = parse_expr( src, ph, init_cols );\n\tif( init.res != 0 ) goto fail;\n\tph->set_tok_ctr( init_cols );\n\ncond:\n\t// condition\n\tph->next();\n\tif( ph->peak()->type == TOK_COLS ) {\n\t\tgoto step;\n\t}\n\terr = find_next_of( ph, cond_cols, { TOK_COLS } );\n\tif( err < 0 ) {\n\t\tif( err == -1 ) {\n\t\t\tPARSE_FAIL( \"could not find the semicolon for the loop's init statement\" );\n\t\t}\n\t\tgoto fail;\n\t}\n\tcond = parse_expr( src, ph, cond_cols );\n\tif( cond.res != 0 ) goto fail;\n\tif( cond.expr ) cond.expr->m_is_top_expr = false;\n\tph->set_tok_ctr( cond_cols );\n\nstep:\n\t// step\n\tph->next();\n\tif( ph->peak()->type == TOK_LBRACE ) {\n\t\tgoto blk;\n\t}\n\terr = find_next_of( ph, step_brace, { TOK_LBRACE }, TOK_RBRACE );\n\tif( err < 0 ) {\n\t\tif( err == -1 ) {\n\t\t\tPARSE_FAIL( \"could not find the left brace for loop block\" );\n\t\t} else if( err == -2 ) {\n\t\t\tPARSE_FAIL( \"found end of statement (semicolon) before left braces for loop block\" );\n\t\t}\n\t\tgoto fail;\n\t}\n\tstep = parse_expr( src, ph, step_brace );\n\tif( step.res != 0 ) goto fail;\n\tph->set_tok_ctr( step_brace );\n\nblk:\n\t// block\n\tparents.push_back( GRAM_FOR );\n\tblock = parse_block( src, ph, parents );\n\tparents.pop_back();\n\tif( block == nullptr ) goto fail;\n\n\treturn new stmt_for_t( init.expr, cond.expr, step.expr, block, tok_ctr );\n\nfail:\n\tif( init.expr ) delete init.expr;\n\tif( cond.expr ) delete cond.expr;\n\tif( step.expr ) delete step.expr;\n\tif( block ) delete block;\n\treturn nullptr;\n}\n\nbool stmt_for_t::bytecode( src_t & src ) const\n{\n\tint line = src.toks[ m_tok_ctr ].line;\n\tint col = src.toks[ m_tok_ctr ].col;\n\n\tADD_SCOPE();\n\t// add first layer\n\tINC_SCOPE();\n\n\tif( m_init != nullptr ) {\n\t\tif( !m_init->bytecode( src ) ) return false;\n\t}\n\tint cond_end_loc = -1;\n\tif( m_cond != nullptr ) {\n\t\tif( !m_cond->bytecode( src ) ) return false;\n\t\tsrc.bcode.push_back( { src.bcode.back().parse_ctr, src.bcode.back().line,\n\t\t\t\t       src.bcode.back().col, IC_JUMP_FALSE, { OP_INT, \"<placeholder>\" } } );\n\t\tcond_end_loc = src.bcode.size() - 1;\n\t}\n\n\tint block_start_loc = src.bcode.size();\n\n\tint cont_brk_from = -1, cont_brk_to = -1;\n\tif( m_block != nullptr ) {\n\t\tcont_brk_from = src.bcode.size();\n\t\tif( !m_block->bytecode( src ) ) return false;\n\t\tcont_brk_to = src.bcode.size();\n\t}\n\n\tint continue_loc = -1;\n\tif( m_step != nullptr ) {\n\t\tcontinue_loc = src.bcode.size();\n\t\tif( !m_step->bytecode( src ) ) return false;\n\t}\n\n\tif( m_cond != nullptr ) {\n\t\tif( continue_loc == -1 ) continue_loc = src.bcode.size();\n\t\tif( !m_cond->bytecode( src ) ) return false;\n\t}\n\n\tif( continue_loc == -1 ) continue_loc = src.bcode.size() - 1;\n\n\tif( m_cond == nullptr ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, src.bcode.back().line, src.bcode.back().col,\n\t\t\t\t       IC_JUMP, { OP_INT, std::to_string( block_start_loc ) } } );\n\t} else {\n\t\tsrc.bcode.push_back( { m_tok_ctr, src.bcode.back().line, src.bcode.back().col,\n\t\t\t\t       IC_JUMP_TRUE, { OP_INT, std::to_string( block_start_loc ) } } );\n\t}\n\tif( cond_end_loc >= 0 ) {\n\t\tsrc.bcode[ cond_end_loc ].oper.val = std::to_string( src.bcode.size() );\n\t}\n\n\tDEC_SCOPE();\n\t// remove first layer\n\tREM_SCOPE();\n\n\t// set continue and break locations\n\tif( m_block != nullptr ) {\n\t\t// continue to the beginning of step, or condition, or removal of second layer\n\t\t// break to removal of first layer\n\t\tset_continue_break_lines( src.bcode, cont_brk_from, cont_brk_to, continue_loc, src.bcode.size() - 1 );\n\t}\n\treturn true;\n}\n\nstatic void set_continue_break_lines( bytecode_t & bcode, const int from,\n\t\t\t\t      const int to, const int cont, const int brk )\n{\n\tfor( int i = from; i < to; ++i ) {\n\t\tif( bcode[ i ].oper.val == \"<continue-placeholder>\" ) {\n\t\t\tbcode[ i ].oper.val = std::to_string( cont );\n\t\t} else if( bcode[ i ].oper.val == \"<break-placeholder>\" ) {\n\t\t\tbcode[ i ].oper.val = std::to_string( brk );\n\t\t}\n\t}\n}"
  },
  {
    "path": "src/FE/Parser/Foreach.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nstatic void set_continue_break_lines( bytecode_t & bcode, const int from,\n\t\t\t\t      const int to, const int cont, const int brk );\n\nstmt_foreach_t * parse_foreach( src_t & src, parse_helper_t * ph, std::vector< GrammarTypes > & parents )\n{\n\tint tok_ctr = ph->tok_ctr();\n\n\ttok_t * it_name = nullptr;\n\texpr_res_t expr = { 0, nullptr };\n\tstmt_block_t * block = nullptr;\n\n\tint err, expr_brace;\n\n\t// NOTE: for now, checks for iterator name and 'in' are redundant because that is done in Parser.cpp itself\n\t// iterator name\n\tph->next();\n\tif( ph->peak()->type != TOK_IDEN ) {\n\t\tPARSE_FAIL( \"expected identifier as the iterator variable\" );\n\t\tgoto fail;\n\t}\n\tit_name = ph->peak();\n\n\t// in\n\tph->next();\n\tif( ph->peak()->type != TOK_IN ) {\n\t\tPARSE_FAIL( \"expected 'in' here to signify the upcoming expression from which to iterate\" );\n\t\tgoto fail;\n\t}\n\n\t// expr\n\tph->next();\n\terr = find_next_of( ph, expr_brace, { TOK_LBRACE }, TOK_RBRACE );\n\tif( err < 0 ) {\n\t\tif( err == -1 ) {\n\t\t\tPARSE_FAIL( \"could not find the left brace for loop block\" );\n\t\t} else if( err == -2 ) {\n\t\t\tPARSE_FAIL( \"found end of statement (semicolon) before left braces for loop block\" );\n\t\t}\n\t\tgoto fail;\n\t}\n\texpr = parse_expr( src, ph, expr_brace, false );\n\tif( expr.res != E_OK ) goto fail;\n\tph->set_tok_ctr( expr_brace );\n\nblk:\n\t// block\n\tparents.push_back( GRAM_FOREACH );\n\tblock = parse_block( src, ph, parents );\n\tparents.pop_back();\n\tif( block == nullptr ) goto fail;\n\n\treturn new stmt_foreach_t( new stmt_simple_t( SIMPLE_TOKEN, it_name, tok_ctr + 1 ),\n\t\t\t\t   expr.expr, block, tok_ctr );\nfail:\n\tif( expr.expr ) delete expr.expr;\n\tif( block ) delete block;\n\treturn nullptr;\n}\n\nbool stmt_foreach_t::bytecode( src_t & src ) const\n{\n\tint line = src.toks[ m_tok_ctr ].line;\n\tint col = src.toks[ m_tok_ctr ].col;\n\n\tADD_SCOPE();\n\t// add first layer\n\tINC_SCOPE();\n\n\t// bytecode for expression\n\tif( !m_expr->bytecode( src ) ) return false;\n\t// provide for assignment\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_PUSH, { OP_CONST, \"._\" + m_iter->m_val->data } } );\n\t// store the expression result\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr + 1, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_STORE, { OP_NONE, \"\" } } );\n\n\tint iter_end_loc = src.bcode.size();\n\t// add second layer\n\tINC_SCOPE();\n\n\tint expr_line = src.toks[ m_expr->m_tok_ctr ].line;\n\tint expr_col = src.toks[ m_expr->m_tok_ctr ].col;\n\t// assign the ._<iter>.next() values to iterator\n\tsrc.bcode.push_back( { m_expr->m_tok_ctr, expr_line, expr_col,\n\t\t\t       IC_PUSH, { OP_STR, \"._\" + m_iter->m_val->data } } );\n\tsrc.bcode.push_back( { m_expr->m_tok_ctr, expr_line, expr_col,\n\t\t\t       IC_PUSH, { OP_CONST, \"next\" } } );\n\tsrc.bcode.push_back( { m_expr->m_tok_ctr, expr_line, expr_col,\n\t\t\t       IC_MFN_CALL, { OP_INT, \"0\" } } );\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_PUSH, { OP_CONST, m_iter->m_val->data } } );\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_STORE_NO_COPY, { OP_NONE, \"\" } } );\n\n\t// compare the result with nil, break if it is nil\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_PUSH, { OP_STR, m_iter->m_val->data } } );\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_PUSH, { OP_STR, \"nil\" } } );\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_PUSH, { OP_CONST, \"==\" } } );\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_FN_CALL, { OP_INT, \"2\" } } );\n\n\t// jump out of loop if the above comparison results true\n\tint iter_comparison_loc = src.bcode.size();\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_JUMP_TRUE_NO_POP, { OP_INT, \"\" } } );\n\n\tint block_start_loc = src.bcode.size();\n\n\tint cont_brk_from = -1, cont_brk_to = -1;\n\tif( m_block != nullptr ) {\n\t\tcont_brk_from = src.bcode.size();\n\t\tif( !m_block->bytecode( src ) ) return false;\n\t\tcont_brk_to = src.bcode.size();\n\t}\n\n\tint continue_loc = src.bcode.size() + 1;\n\n\tDEC_SCOPE();\n\t// remove second layer\n\n\tsrc.bcode.push_back( { m_iter->m_tok_ctr, m_iter->m_val->line, m_iter->m_val->col,\n\t\t\t       IC_JUMP_FALSE, { OP_INT, std::to_string( iter_end_loc ) } } );\n\n\tDEC_SCOPE();\n\t// remove first layer\n\tREM_SCOPE();\n\n\t// - 3 to go before the 2 layers and the IC_JUMP_FALSE instruction above\n\tsrc.bcode[ iter_comparison_loc ].oper.val = std::to_string( src.bcode.size() - 3 );\n\t// set continue and break locations\n\tif( m_block != nullptr ) {\n\t\t// continue to the beginning of step, or condition, or removal of second layer\n\t\t// break to removal of first layer\n\t\tset_continue_break_lines( src.bcode, cont_brk_from, cont_brk_to, continue_loc, src.bcode.size() - 1 );\n\t}\n\treturn true;\n}\n\nstatic void set_continue_break_lines( bytecode_t & bcode, const int from,\n\t\t\t\t      const int to, const int cont, const int brk )\n{\n\tfor( int i = from; i < to; ++i ) {\n\t\tif( bcode[ i ].oper.val == \"<continue-placeholder>\" ) {\n\t\t\tbcode[ i ].oper.val = std::to_string( cont );\n\t\t} else if( bcode[ i ].oper.val == \"<break-placeholder>\" ) {\n\t\t\tbcode[ i ].oper.val = std::to_string( brk );\n\t\t}\n\t}\n}"
  },
  {
    "path": "src/FE/Parser/FuncStructSubscr.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nbool stmt_func_struct_subscr_call_t::bytecode( src_t & src ) const\n{\n\tint line = src.toks[ m_tok_ctr ].line;\n\tint col = src.toks[ m_tok_ctr ].col;\n\n\tif( m_ctype == CT_SUBSCR ) {\n\t\tbool bcodeasconst = src.bcode_as_const;\n\t\tbool found_assn = src.found_assn;\n\t\tsrc.bcode_as_const = false;\n\t\tsrc.found_assn = false;\n\t\tif( m_name ) {\n\t\t\tif( m_post_dot ) src.bcode_as_const = true;\n\t\t\tm_name->bytecode( src );\n\t\t\tif( m_post_dot ) {\n\t\t\t\tsrc.bcode_as_const = false;\n\t\t\t\tsrc.bcode.push_back( { m_name->m_tok_ctr, line, col, IC_ATTR, { OP_NONE, \"\" } } );\n\t\t\t}\n\t\t}\n\t\tfor( auto & arg : m_args ) {\n\t\t\tif( arg == nullptr ) continue;\n\t\t\targ->bytecode( src );\n\t\t\tsrc.bcode.push_back( { m_tok_ctr, m_name ? m_name->m_val->line : line , m_name ? m_name->m_val->col : col,\n\t\t\t\t\t       IC_PUSH, { OP_CONST, \"[]\" } } );\n\t\t\tsrc.bcode.push_back( { m_tok_ctr, m_name ? m_name->m_val->line : line , m_name ? m_name->m_val->col : col,\n\t\t\t\t\t       IC_MFN_CALL, { OP_INT, \"1\" } } );\n\t\t}\n\t\tsrc.bcode_as_const = bcodeasconst;\n\t\tsrc.found_assn = found_assn;\n\t\treturn true;\n\t}\n\n\tint args = 0;\n\tif( m_args.size() > 0 && m_args[ 0 ] != nullptr ) {\n\t\tm_args[ 0 ]->bytecode( src );\n\t\tint child_cc = 0;\n\t\tchild_comma_count( m_args[ 0 ], child_cc );\n\t\tif( child_cc == 0 ) args = 1;\n\t\telse args = child_cc + 1;\n\t}\n\n\tsrc.bcode.push_back( { m_tok_ctr, m_name->m_val->line, m_name->m_val->col,\n\t\t\t       IC_PUSH, { OP_CONST, m_name->m_val->data } } );\n\tif( m_ctype == CT_FUNC ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_name->m_val->line, m_name->m_val->col,\n\t\t\t\t       m_post_dot ? IC_MFN_CALL : IC_FN_CALL,\n\t\t\t\t       { OP_INT, std::to_string( args ) } } );\n\t} else if( m_ctype == CT_STRUCT ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_name->m_val->line, m_name->m_val->col,\n\t\t\t\t       IC_STRUCT_DECL, { OP_INT, std::to_string( args ) } } );\n\t}\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/Function.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nstmt_func_t * parse_func( src_t & src, parse_helper_t * ph )\n{\n\tint tok_ctr = ph->tok_ctr();\n\n\tbool is_member_func = false;\n\tif( ph->peak()->type == TOK_MFN ) is_member_func = true;\n\n\tstd::vector< GrammarTypes > parents;\n\n\tstd::vector< stmt_simple_t * > mem_types;\n\tif( is_member_func ) {\n\t\tNEXT_VALID( TOK_LT );\n\tbegin_mfn_type:\n\t\tNEXT_VALID2( TOK_IDEN, TOK_STR );\n\t\tmem_types.push_back( new stmt_simple_t( SIMPLE_TOKEN, ph->peak(), ph->tok_ctr() ) );\n\t\tNEXT_VALID2( TOK_GT, TOK_COMMA );\n\t\tif( ph->peak()->type == TOK_COMMA ) goto begin_mfn_type;\n\t}\n\n\tconst tok_t * name = nullptr;\n\tNEXT_VALID2( TOK_IDEN, TOK_STR );\n\tname = ph->peak();\n\n\tNEXT_VALID( TOK_LPAREN );\n\n\texpr_res_t arg_expr = { 0, nullptr };\n\tint arg_expr_end;\n\tint err;\n\tstmt_block_t * block = nullptr;\n\n\tNEXT_VALID3( TOK_RPAREN, TOK_IDEN, TOK_TDOT );\n\n\tif( ph->peak()->type == TOK_RPAREN ) goto end_args;\n\terr = find_next_of( ph, arg_expr_end, { TOK_RPAREN }, TOK_LPAREN );\n\tif( err < 0 ) {\n\t\tif( err == -1 ) {\n\t\t\tPARSE_FAIL( \"could not find the right parenthesis for function '%s'\",\n\t\t\t\t    name->data.c_str() );\n\t\t} else if( err == -2 ) {\n\t\t\tPARSE_FAIL( \"found beginning of block (left braces) before the ')' for arguments of function '%s'\",\n\t\t\t\t    name->data.c_str() );\n\t\t}\n\t\tgoto fail;\n\t}\n\targ_expr = parse_expr( src, ph, arg_expr_end, false );\n\tif( arg_expr.res != 0 ) goto fail;\n\tph->set_tok_ctr( arg_expr_end );\nend_args:\n\tNEXT_VALID_FAIL( TOK_LBRACE );\n\tparents.push_back( GRAM_FUNC );\n\tblock = parse_block( src, ph, parents );\n\tparents.pop_back();\n\tif( block == nullptr ) goto fail;\n\treturn new stmt_func_t( new stmt_simple_t( SIMPLE_TOKEN, name, tok_ctr + 1 ),\n\t\t\t\targ_expr.expr, block, mem_types, tok_ctr );\nfail:\n\tif( arg_expr.expr ) delete arg_expr.expr;\n\tif( block ) delete block;\n\tfor( auto & mem_type : mem_types ) delete mem_type;\n\treturn nullptr;\n}\n\nbool stmt_func_t::bytecode( src_t & src ) const\n{\n\tint block_till_loc = src.bcode.size();\n\tsrc.bcode.push_back( { m_tok_ctr, m_name->m_val->line, m_name->m_val->col, IC_BLOCK_TILL, { OP_INT, \"<func-block-placeholder>\" } } );\n\tADD_FUNC();\n\tm_block->bytecode( src );\n\tREM_FUNC();\n\t// not used src.bcode.size() - 1 because the exec loop runs till < end and not <= end\n\tsrc.bcode[ block_till_loc ].oper.val = std::to_string( src.bcode.size() );\n\n\tif( m_args == nullptr ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_name->m_val->line, m_name->m_val->col, IC_ARGS_TILL, { OP_INT, \"-1\" } } );\n\t} else {\n\t\tint args_till_loc = src.bcode.size();\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_name->m_val->line, m_name->m_val->col, IC_ARGS_TILL, { OP_INT, \"<func-args-placeholder>\" } } );\n\t\tm_args->bytecode( src );\n\t\tsrc.bcode[ args_till_loc ].oper.val = std::to_string( src.bcode.size() - 1 );\n\t}\n\n\tif( m_mem_types.size() > 0 ) {\n\t\tfor( auto & mem_type : m_mem_types ) {\n\t\t\tsrc.bcode.push_back( { m_tok_ctr, mem_type->m_val->line, mem_type->m_val->col, IC_PUSH, { OP_CONST, mem_type->m_val->data } } );\n\t\t}\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_mem_types.front()->m_val->line, m_mem_types.front()->m_val->col, IC_PUSH, { OP_INT, std::to_string( m_mem_types.size() ) } } );\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_mem_types.front()->m_val->line, m_mem_types.front()->m_val->col, IC_BUILD_MFN, { OP_CONST, m_name->m_val->data } } );\n\t} else {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_name->m_val->line, m_name->m_val->col, IC_BUILD_FN, { OP_CONST, m_name->m_val->data } } );\n\t}\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/IO.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cstdarg>\n#include <vector>\n\n#include \"IO.hpp\"\n\nstatic std::vector< bool > & _tab()\n{\n\tstatic std::vector< bool > tabs;\n\treturn tabs;\n}\n\nstatic void _tab_apply( const bool has_next )\n{\n\tfor( size_t i = 0; i < _tab().size(); ++i ) {\n\t\tif( i == _tab().size() - 1 ) {\n\t\t\tif( has_next ) fprintf( stdout, \"  ├─\" );\n\t\t\telse fprintf( stdout, \"  └─\" );\n\t\t}\n\t\telse {\n\t\t\tif( _tab()[ i ] ) fprintf( stdout, \"  │\" );\n\t\t\telse fprintf( stdout, \"   \" );\n\t\t}\n\t}\n}\n\nvoid IO::tab_add( const bool show )\n{\n\t_tab().push_back( show );\n}\n\nvoid IO::tab_rem( const size_t num )\n{\n\tif( num > _tab().size() ) return;\n\tfor( size_t i = 0; i < num; ++i ) _tab().pop_back();\n}\n\nvoid IO::print( const bool has_next, const char * fmt, ... )\n{\n\t_tab_apply( has_next );\n\tva_list args;\n\tva_start( args, fmt );\n\tvfprintf( stdout, fmt, args );\n\tva_end( args );\n}"
  },
  {
    "path": "src/FE/Parser/IO.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef PARSER_IO_HPP\n#define PARSER_IO_HPP\n\n#include <cstdio>\n\nnamespace IO\n{\n\tvoid tab_add( const bool show );\n\tvoid tab_rem( const size_t num = 1 );\n\tvoid print( const bool has_next, const char * fmt, ... );\n}\n\n#endif // PARSER_IO_HPP"
  },
  {
    "path": "src/FE/Parser/If.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nstmt_if_t * parse_if( src_t & src, parse_helper_t * ph, std::vector< GrammarTypes > & parents )\n{\n\tint tok_ctr = ph->tok_ctr();\n\n\texpr_res_t expr = { 0, nullptr };\n\tstmt_block_t * block = nullptr;\n\tstd::vector< condition_t > conds;\n\n\tint err, start_brace;\nbegin_cond:\n\tph->next();\n\terr = find_next_of( ph, start_brace, { TOK_LBRACE }, TOK_RBRACE );\n\tif( err < 0 ) {\n\t\tif( err == -1 ) {\n\t\t\tPARSE_FAIL( \"could not find the left brace for if block\" );\n\t\t} else if( err == -2 ) {\n\t\t\tPARSE_FAIL( \"found end of statement (semicolon) before left braces for if block\" );\n\t\t}\n\t\tgoto fail;\n\t}\n\n\texpr = parse_expr( src, ph, start_brace, false );\n\tif( expr.res != 0 ) goto fail;\n\tph->set_tok_ctr( start_brace );\n\nbegin_block:\n\tparents.push_back( GRAM_IF );\n\tblock = parse_block( src, ph, parents );\n\tparents.pop_back();\n\tif( block == nullptr ) goto fail;\n\tconds.push_back( { expr.expr, block } );\n\texpr = { 0, nullptr };\n\tblock = nullptr;\n\tif( ph->peak( 1 )->type == TOK_ELIF ) {\n\t\tph->next();\n\t\tgoto begin_cond;\n\t} else if( ph->peak( 1 )->type == TOK_ELSE ) {\n\t\tph->next();\n\t\tNEXT_VALID_FAIL( TOK_LBRACE );\n\t\tgoto begin_block;\n\t}\n\n\treturn new stmt_if_t( conds, tok_ctr );\n\nfail:\n\tfor( auto & cond : conds ) {\n\t\tif( cond.cond ) delete cond.cond;\n\t\tdelete cond.block;\n\t}\n\tif( expr.expr ) delete expr.expr;\n\tif( block ) delete block;\n\treturn nullptr;\n}\n\nbool stmt_if_t::bytecode( src_t & src ) const\n{\n\tstd::vector< size_t > unconditional_jumps;\n\tfor( size_t i = 0; i < m_conds.size(); ++i ) {\n\t\tauto & cond = m_conds[ i ];\n\t\tint jump_loc = -1;\n\t\tif( cond.cond != nullptr ) {\n\t\t\tif( !cond.cond->bytecode( src ) ) return false;\n\t\t\tsrc.bcode.push_back( { src.bcode.back().parse_ctr, src.bcode.back().line, src.bcode.back().col,\n\t\t\t\t\t       IC_JUMP_FALSE, { OP_INT, \"<placeholder>\" } } );\n\t\t}\n\t\tint orig_bcode_size = src.bcode.size();\n\t\tjump_loc = orig_bcode_size - 1;\n\t\tint block_size = -1;\n\t\tif( !cond.block->bytecode( src ) ) return false;\n\t\tif( cond.cond != nullptr && i != m_conds.size() - 1 ) {\n\t\t\tsrc.bcode.push_back( { src.bcode.back().parse_ctr, src.bcode.back().line, src.bcode.back().col,\n\t\t\t\t\t       IC_JUMP, { OP_INT, \"<placeholder>\" } } );\n\t\t\tunconditional_jumps.push_back( src.bcode.size() - 1 );\n\t\t}\n\t\tblock_size = src.bcode.size() - orig_bcode_size + 1;\n\t\tsrc.bcode[ jump_loc ].oper.val = std::to_string( jump_loc + block_size );\n\t}\n\tfor( auto & ucj : unconditional_jumps ) {\n\t\tsrc.bcode[ ucj ].oper.val = std::to_string( src.bcode.size() );\n\t}\n\treturn true;\n}\n"
  },
  {
    "path": "src/FE/Parser/Import.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n#include \"../Env.hpp\"\n\nstmt_import_t * parse_import( const src_t & src, parse_helper_t * ph )\n{\n\tint tok_ctr = ph->tok_ctr();\n\n\tstd::vector< std::string > parents = { \"\" };\n\tstd::vector< std::string > full_names = { \"\" };\n\tstd::vector< tok_t * > whats = { nullptr };\n\nbegin:\n\tNEXT_VALID2( TOK_IDEN, TOK_STR );\n\twhats.back() = ph->peak();\n\tfull_names.back() += ph->peak()->data;\n\tNEXT_VALID4( TOK_COMMA, TOK_DOT, TOK_COLS, TOK_RPAREN );\ncomma:\n\tif( ph->peak()->type == TOK_COMMA ) {\n\t\t// add the previous identifer/str to whats as it is complete\n\t\twhats.push_back( nullptr );\n\t\tfull_names.push_back( parents.back() );\n\t\tgoto begin;\n\t}\n\ndot:\n\tif( ph->peak()->type == TOK_DOT ) {\n\t\tfull_names.back() += '/';\n\t\tif( ph->peak( 1 )->type != TOK_LPAREN ) goto begin;\n\t\tph->next();\n\t\t// pass to lparen\n\t}\n\nlparen:\n\tif( ph->peak()->type == TOK_LPAREN ) {\n\t\tparents.push_back( full_names.back() );\n\t\tgoto begin;\n\t}\n\nrparen:\n\tif( ph->peak()->type == TOK_RPAREN ) {\n\t\tif( parents.size() <= 1 ) {\n\t\t\tPARSE_FAIL( \"no matching opening parentheses for this closing one\" );\n\t\t\treturn nullptr;\n\t\t}\n\t\tparents.pop_back();\n\t\tNEXT_VALID2( TOK_COMMA, TOK_COLS );\n\t\tif( ph->peak()->type == TOK_COMMA ) goto comma;\n\t}\n\nend:\n\treturn new stmt_import_t( whats, full_names, tok_ctr );\n}\n\nbool stmt_import_t::bytecode( src_t & src ) const\n{\n\tfor( size_t i = 0; i < m_full_names.size(); ++i ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_whats[ i ]->line, m_whats[ i ]->col,\n\t\t\t\t       IC_IMPORT, { OP_CONST, m_full_names[ i ] } } );\n\t}\n\treturn true;\n}\n"
  },
  {
    "path": "src/FE/Parser/Internal.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <algorithm>\n\n#include \"Internal.hpp\"\n\nint oper_prec( const tok_t * tok )\n{\n\tconst TokType type = tok->type;\n\n\tif( type < TOK_ASSN || type > TOK_RBRACK ) return -1;\n\tif( type == TOK_COMMA ) return 0;\n\tif( token_is_one_of_assign( tok ) ) return 1;\n\tif( type == TOK_QUEST || type == TOK_COL ) return 2;\n\tif( type == TOK_OR ) return 3;\n\tif( type == TOK_AND ) return 4;\n\tif( type == TOK_EQ || type == TOK_NE ) return 5;\n\tif( type == TOK_LT || type == TOK_LE || type == TOK_GT || type == TOK_GE ) return 6;\n\tif( type == TOK_BOR ) return 7;\n\tif( type == TOK_BXOR ) return 8;\n\tif( type == TOK_BAND ) return 9;\n\tif( type == TOK_LSHIFT || type == TOK_RSHIFT ) return 10;\n\tif( type == TOK_ADD || type == TOK_SUB ) return 11;\n\tif( type == TOK_MUL || type == TOK_DIV || type == TOK_MOD || type == TOK_POW ) return 12;\n\tif( type == TOK_UADD || type == TOK_USUB ) return 13;\n\tif( type == TOK_NOT || type == TOK_BNOT ) return 14;\n\tif( type == TOK_LPAREN || type == TOK_RPAREN || type == TOK_LBRACK || type == TOK_RBRACK || type == TOK_LBRACE || type == TOK_RBRACE ) return 15;\n\tif( type == TOK_DOT ) return 16;\n\n\treturn -1;\n}\n\nOperAssoc oper_assoc( const tok_t * tok )\n{\n\tconst TokType type = tok->type;\n\tif( type < TOK_ASSN || type > TOK_RBRACK ) return LTR;\n\tif( type == TOK_COMMA ) return RTL;\n\tif( token_is_one_of_assign( tok ) ) return RTL;\n\tif( type == TOK_NOT || type == TOK_BNOT ) return RTL;\n\n\t// for everything else, it is LTR\n\treturn LTR;\n}\n\nint oper_arg_count( const tok_t * tok )\n{\n\tconst TokType type = tok->type;\n\n\tif( type < TOK_ASSN || type > TOK_RBRACK ) return -1;\n\tif( type == TOK_COMMA ) return 2;\n\tif( token_is_one_of_assign( tok ) ) return 2;\n\tif( type == TOK_QUEST || type == TOK_COL ) return 2;\n\tif( type == TOK_OR || type == TOK_AND ) return 2;\n\tif( type == TOK_EQ || type == TOK_NE || type == TOK_LT || type == TOK_LE || type == TOK_GT || type == TOK_GE ) return 2;\n\tif( type == TOK_BOR || type == TOK_BXOR || type == TOK_BAND ) return 2;\n\tif( type == TOK_LSHIFT || type == TOK_RSHIFT ) return 2;\n\tif( type == TOK_ADD || type == TOK_SUB ) return 2;\n\tif( type == TOK_MUL || type == TOK_DIV || type == TOK_MOD || type == TOK_POW ) return 2;\n\tif( type == TOK_UADD || type == TOK_USUB ) return 1;\n\tif( type == TOK_NOT || type == TOK_BNOT ) return 1;\n\tif( type == TOK_LBRACK ) return 2;\n\tif( type == TOK_LPAREN || type == TOK_RPAREN || type == TOK_LBRACK || type == TOK_RBRACK || type == TOK_LBRACE || type == TOK_RBRACE ) return 0;\n\tif( type == TOK_DOT ) return 2;\n\n\treturn -1;\n}\n\nint find_next_of( parse_helper_t * ph, int & loc, const std::vector< TokType > & types,\n\t\t  const TokType eq, const bool bypass_breaker, const TokType breaker )\n{\n\tint ctr = 1;\n\tint equi = 1;\n\twhile( ph->peak( ctr )->type != TOK_INVALID ) {\n\t\tif( ph->peak( ctr )->type == breaker &&\n\t\t    std::find( types.begin(), types.end(), breaker ) == types.end() &&\n\t\t    !bypass_breaker ) { loc = ctr; return -2; }\n\t\tif( std::find( types.begin(), types.end(), ph->peak( ctr )->type ) != types.end() ) {\n\t\t\tif( eq != TOK_INVALID ) {\n\t\t\t\t--equi;\n\t\t\t\tif( equi == 0 ) { loc = ph->tok_ctr() + ctr; return 0; };\n\t\t\t} else {\n\t\t\t\tloc = ph->tok_ctr() + ctr;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\tif( ph->peak( ctr )->type == eq ) ++equi;\n\t\t++ctr;\n\t}\n\tloc = -1;\n\treturn -1;\n}"
  },
  {
    "path": "src/FE/Parser/Internal.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef PARSER_INTERNAL_HPP\n#define PARSER_INTERNAL_HPP\n\n#include \"Stmts.hpp\"\n\n#define NEXT_VALID( tok )\t\t\t\t\t\t\t\\\ndo {\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak( 1 )->type == TOK_INVALID ) {\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s', but found <EOF>\",\t\t\\\n\t\t\t    TokStrs[ tok ] );\t\t\t\t\t\\\n\t\treturn nullptr;\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\\\n\tph->next();\t\t\t\t\t\t\t\t\\\n\tif( ph->peak()->type != tok ) {\t\t\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s', but found '%s'\",\t\t\\\n\t\t\t    TokStrs[ tok ], TokStrs[ ph->peak()->type ] );\t\\\n\t\treturn nullptr;\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\\\n} while( 0 )\n\n#define NEXT_VALID2( tok1, tok2 )\t\t\t\t\t\t\t\t\\\ndo {\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak( 1 )->type == TOK_INVALID ) {\t\t\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s', but found <EOF>\",\t\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ] );\t\t\t\t\t\\\n\t\treturn nullptr;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n\tph->next();\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak()->type != tok1 && ph->peak()->type != tok2 ) {\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s', but found '%s'\",\t\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ], TokStrs[ ph->peak()->type ] );\t\\\n\t\treturn nullptr;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n} while( 0 )\n\n#define NEXT_VALID3( tok1, tok2, tok3 )\t\t\t\t\t\t\t\t\\\ndo {\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak( 1 )->type == TOK_INVALID ) {\t\t\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s' or '%s', but found <EOF>\",\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ], TokStrs[ tok3 ] );\t\t\\\n\t\treturn nullptr;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n\tph->next();\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak()->type != tok1 && ph->peak()->type != tok2 && ph->peak()->type != tok3 ) {\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s' or '%s', but found '%s'\",\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ],\t\t\t\t\t\\\n\t\t\t    TokStrs[ tok3 ], TokStrs[ ph->peak()->type ] );\t\t\t\\\n\t\treturn nullptr;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n} while( 0 )\n\n#define NEXT_VALID4( tok1, tok2, tok3, tok4 )\t\t\t\t\t\t\t\\\ndo {\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak( 1 )->type == TOK_INVALID ) {\t\t\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s' or '%s' or '%s', but found <EOF>\",\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ], TokStrs[ tok3 ],\t\t\t\\\n\t\t\t    TokStrs[ tok4 ] );\t\t\t\t\t\t\t\\\n\t\treturn nullptr;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n\tph->next();\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak()->type != tok1 && ph->peak()->type != tok2 &&\t\t\t\t\\\n\t    ph->peak()->type != tok3 && ph->peak()->type != tok4 ) {\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s' or '%s', but found '%s'\",\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ],\t\t\t\t\t\\\n\t\t\t    TokStrs[ tok3 ], TokStrs[ tok4 ],\t\t\t\t\t\\\n\t\t\t    TokStrs[ ph->peak()->type ] );\t\t\t\t\t\\\n\t\treturn nullptr;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n} while( 0 )\n\n#define NEXT_VALID_FAIL( tok )\t\t\t\t\t\t\t\\\ndo {\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak( 1 )->type == TOK_INVALID ) {\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s', but found <EOF>\",\t\t\\\n\t\t\t    TokStrs[ tok ] );\t\t\t\t\t\\\n\t\tgoto fail;\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\\\n\tph->next();\t\t\t\t\t\t\t\t\\\n\tif( ph->peak()->type != tok ) {\t\t\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s', but found '%s'\",\t\t\\\n\t\t\t    TokStrs[ tok ], TokStrs[ ph->peak()->type ] );\t\\\n\t\tgoto fail;\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\\\n} while( 0 )\n\n#define NEXT_VALID2_FAIL( tok1, tok2 )\t\t\t\t\t\t\t\t\\\ndo {\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak( 1 )->type == TOK_INVALID ) {\t\t\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s', but found <EOF>\",\t\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ] );\t\t\t\t\t\\\n\t\tgoto fail;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n\tph->next();\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak()->type != tok1 && ph->peak()->type != tok2 ) {\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s', but found '%s'\",\t\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ], TokStrs[ ph->peak()->type ] );\t\\\n\t\tgoto fail;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n} while( 0 )\n\n#define NEXT_VALID3_FAIL( tok1, tok2, tok3 )\t\t\t\t\t\t\t\\\ndo {\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak( 1 )->type == TOK_INVALID ) {\t\t\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s' or '%s', but found <EOF>\",\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ], TokStrs[ tok3 ] );\t\t\\\n\t\tgoto fail;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n\tph->next();\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak()->type != tok1 && ph->peak()->type != tok2 && ph->peak()->type != tok3 ) {\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s' or '%s', but found '%s'\",\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ],\t\t\t\t\t\\\n\t\t\t    TokStrs[ tok3 ], TokStrs[ ph->peak()->type ] );\t\t\t\\\n\t\tgoto fail;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n} while( 0 )\n\n#define NEXT_VALID4_FAIL( tok1, tok2, tok3, tok4 )\t\t\t\t\t\t\\\ndo {\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak( 1 )->type == TOK_INVALID ) {\t\t\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s' or '%s' or '%s', but found <EOF>\",\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ], TokStrs[ tok3 ],\t\t\t\\\n\t\t\t    TokStrs[ tok4 ] );\t\t\t\t\t\t\t\\\n\t\tgoto fail;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n\tph->next();\t\t\t\t\t\t\t\t\t\t\\\n\tif( ph->peak()->type != tok1 && ph->peak()->type != tok2 &&\t\t\t\t\\\n\t    ph->peak()->type != tok3 && ph->peak()->type != tok4 ) {\t\t\t\t\\\n\t\tPARSE_FAIL( \"expected token '%s' or '%s' or '%s', but found '%s'\",\t\t\\\n\t\t\t    TokStrs[ tok1 ], TokStrs[ tok2 ],\t\t\t\t\t\\\n\t\t\t    TokStrs[ tok3 ], TokStrs[ tok4 ],\t\t\t\t\t\\\n\t\t\t    TokStrs[ ph->peak()->type ] );\t\t\t\t\t\\\n\t\tgoto fail;\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n} while( 0 )\n\nstruct expr_res_t\n{\n\tint res;\n\tstmt_expr_t * expr;\n};\n\nvoid child_comma_count( const stmt_expr_t * expr, int & cc );\n\nstmt_enum_t * parse_enum( const src_t & src, parse_helper_t * ph );\nstmt_ldmod_t * parse_ldmod( const src_t & src, parse_helper_t * ph );\nstmt_import_t * parse_import( const src_t & src, parse_helper_t * ph );\nexpr_res_t parse_expr( const src_t & src, parse_helper_t * ph,\n\t\t       const int end = -1, const bool is_top = true );\nstmt_struct_t * parse_struct( const src_t & src, parse_helper_t * ph );\nstmt_block_t * parse_block( src_t & src, parse_helper_t * ph, std::vector< GrammarTypes > & parents );\nstmt_func_t * parse_func( src_t & src, parse_helper_t * ph );\nstmt_if_t * parse_if( src_t & src, parse_helper_t * ph, std::vector< GrammarTypes > & parents );\nstmt_for_t * parse_for( src_t & src, parse_helper_t * ph, std::vector< GrammarTypes > & parents );\nstmt_foreach_t * parse_foreach( src_t & src, parse_helper_t * ph, std::vector< GrammarTypes > & parents );\nstmt_return_t * parse_return( src_t & src, parse_helper_t * ph );\n\n// precedence of a operator (lex type) in ascending order\nint oper_prec( const tok_t * tok );\n\nenum OperAssoc\n{\n\tLTR,\n\tRTL,\n};\n\n// LTR => left->right assoc\n// RTL => right->left assoc\nOperAssoc oper_assoc( const tok_t * tok );\n\nint oper_arg_count( const tok_t * tok );\n\nint find_next_of( parse_helper_t * ph, int & loc, const std::vector< TokType > & types,\n\t\t  const TokType eq = TOK_INVALID, const bool bypass_breaker = false,\n\t\t  const TokType breaker = TOK_COLS );\n\n#endif // PARSER_INTERNAL_HPP"
  },
  {
    "path": "src/FE/Parser/Ldmod.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n#include \"../Env.hpp\"\n\nstmt_ldmod_t * parse_ldmod( const src_t & src, parse_helper_t * ph )\n{\n\tint tok_ctr = ph->tok_ctr();\n\n\tstd::vector< std::string > parents = { \"\" };\n\tstd::vector< std::string > full_names = { \"\" };\n\tstd::vector< tok_t * > whats = { nullptr };\n\nbegin:\n\tNEXT_VALID2( TOK_IDEN, TOK_STR );\n\twhats.back() = ph->peak();\n\tfull_names.back() += ph->peak()->data;\n\tNEXT_VALID4( TOK_COMMA, TOK_DOT, TOK_COLS, TOK_RPAREN );\ncomma:\n\tif( ph->peak()->type == TOK_COMMA ) {\n\t\t// add the previous identifer/str to whats as it is complete\n\t\twhats.push_back( nullptr );\n\t\tfull_names.push_back( parents.back() );\n\t\tgoto begin;\n\t}\n\ndot:\n\tif( ph->peak()->type == TOK_DOT ) {\n\t\tfull_names.back() += '/';\n\t\tif( ph->peak( 1 )->type != TOK_LPAREN ) goto begin;\n\t\tph->next();\n\t\t// pass to lparen\n\t}\n\nlparen:\n\tif( ph->peak()->type == TOK_LPAREN ) {\n\t\tparents.push_back( full_names.back() );\n\t\tgoto begin;\n\t}\n\nrparen:\n\tif( ph->peak()->type == TOK_RPAREN ) {\n\t\tif( parents.size() <= 1 ) {\n\t\t\tPARSE_FAIL( \"no matching opening parentheses for this closing one\" );\n\t\t\treturn nullptr;\n\t\t}\n\t\tparents.pop_back();\n\t\tNEXT_VALID2( TOK_COMMA, TOK_COLS );\n\t\tif( ph->peak()->type == TOK_COMMA ) goto comma;\n\t}\n\n\tfor( auto & full_name : full_names ) {\n\t\tauto last_slash = full_name.find_last_of( '/' );\n\t\tfull_name.insert( last_slash + 1, \"lib\" );\n\t}\n\nend:\n\treturn new stmt_ldmod_t( whats, full_names, tok_ctr );\n}\n\nbool stmt_ldmod_t::bytecode( src_t & src ) const\n{\n\tfor( size_t i = 0; i < m_full_names.size(); ++i ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_whats[ i ]->line, m_whats[ i ]->col,\n\t\t\t\t       IC_LDMOD, { OP_CONST, m_full_names[ i ] } } );\n\t}\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/ParseHelper.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"ParseHelper.hpp\"\n\nparse_helper_t::parse_helper_t( toks_t & toks )\n\t: m_toks( toks ), m_token_ctr( 0 ),\n\t  m_invalid( -1, -1, TOK_INVALID, \"\" ) {}\n\ntok_t * parse_helper_t::peak( const int num )\n{\n\tif( m_token_ctr + num >= ( int )m_toks.size() || m_token_ctr + num < 0 ) return & m_invalid;\n\treturn & m_toks[ m_token_ctr + num ];\n}\n\ntok_t * parse_helper_t::next()\n{\n\t++m_token_ctr;\n\tif( m_token_ctr >= ( int )m_toks.size() ) return & m_invalid;\n\treturn & m_toks[ m_token_ctr ];\n}\n\ntok_t * parse_helper_t::prev()\n{\n\tif( m_token_ctr < 0 ) return & m_invalid;\n\t--m_token_ctr;\n\treturn & m_toks[ m_token_ctr ];\n}\n\ntok_t * parse_helper_t::at( const int idx )\n{\n\treturn & m_toks[ idx ];\n}\n\nbool parse_helper_t::has_next() const { return m_token_ctr + 1 < ( int )m_toks.size(); }\n\nint parse_helper_t::tok_ctr() const { return m_token_ctr; }\n\nvoid parse_helper_t::set_tok_ctr( const int tok_ctr ) { m_token_ctr = tok_ctr; }"
  },
  {
    "path": "src/FE/Parser/ParseHelper.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef PARSER_PARSE_HELPER_HPP\n#define PARSER_PARSE_HELPER_HPP\n\n#include \"../Lexer.hpp\"\n\nclass parse_helper_t\n{\n\ttoks_t & m_toks;\n\tint m_token_ctr;\n\ttok_t m_invalid;\npublic:\n\tparse_helper_t( toks_t & toks );\n\n\ttok_t * peak( const int num = 0 );\n\ttok_t * next();\n\ttok_t * prev();\n\n\ttok_t * at( const int idx );\n\n\tbool has_next() const;\n\n\tint tok_ctr() const;\n\tvoid set_tok_ctr( const int tok_ctr );\n};\n\n#endif // PARSER_PARSE_HELPER_HPP"
  },
  {
    "path": "src/FE/Parser/Return.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nstmt_return_t * parse_return( src_t & src, parse_helper_t * ph )\n{\n\tint tok_ctr = ph->tok_ctr();\n\tph->next();\n\n\tif( ph->peak()->type == TOK_COLS ) {\n\t\treturn new stmt_return_t( nullptr, tok_ctr );\n\t}\n\n\texpr_res_t expr = { 0, nullptr };\n\tint err, cols;\n\terr = find_next_of( ph, cols, { TOK_COLS } );\n\tif( err < 0 ) {\n\t\tif( err == -1 ) {\n\t\t\tPARSE_FAIL( \"could not find the semicolon for the loop's init statement\" );\n\t\t}\n\t\tgoto fail;\n\t}\n\n\texpr = parse_expr( src, ph, cols, false );\n\tph->set_tok_ctr( cols );\n\tif( expr.res != 0 ) goto fail;\n\treturn new stmt_return_t( expr.expr, tok_ctr );\nfail:\n\tif( expr.expr ) delete expr.expr;\n\treturn nullptr;\n}\n\nbool stmt_return_t::bytecode( src_t & src ) const\n{\n\tif( m_ret_val && !m_ret_val->bytecode( src ) ) return false;\n\tint line = src.toks[ m_tok_ctr ].line;\n\tint col = src.toks[ m_tok_ctr ].col;\n\t// assert src.block_depth().size() > 0\n\tint jumps = 0;\n\tfor( auto & blk : src.block_depth.back() ) {\n\t\tjumps += blk;\n\t}\n\tsrc.bcode.push_back( { m_tok_ctr, line, col, m_ret_val ? IC_RETURN : IC_RETURN_EMPTY,\n\t\t\t       { OP_INT, std::to_string( jumps ) } } );\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/Simple.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nbool stmt_simple_t::bytecode( src_t & src ) const\n{\n\tif( m_stype == SIMPLE_OPER ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_val->line, m_val->col, IC_PUSH, { OP_CONST, TokStrs[ m_val->type ] } } );\n\t} else if( m_val->type == TOK_INT ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_val->line, m_val->col, IC_PUSH, { OP_INT, m_val->data } } );\n\t} else if( m_val->type == TOK_FLT ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_val->line, m_val->col, IC_PUSH, { OP_FLT, m_val->data } } );\n\t} else if( m_val->type == TOK_STR || m_val->type == TOK_TDOT || src.bcode_as_const || m_post_dot ) {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_val->line, m_val->col, IC_PUSH, { OP_CONST, m_val->data } } );\n\t} else {\n\t\tsrc.bcode.push_back( { m_tok_ctr, m_val->line, m_val->col, IC_PUSH, { OP_STR, m_val->data } } );\n\t}\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser/Stmts.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Stmts.hpp\"\n\nconst char * GrammarTypeStrs[ _GRAM_LAST ] = {\n\t\"Simple\",\n\t\"Expression\",\n\t\"Enum\",\n\t\"Ldmod\",\n\t\"Import\",\n\t\"Struct\",\n\t\"Block\",\n\t\"Function Def\",\n\t\"Func/Struct/Subscr Call\",\n\t\"If Conditional\",\n\t\"For Loop\",\n\t\"Foreach Loop\",\n\t\"Return\",\n\t\"Continue\",\n\t\"Break\",\n\t\"Collection\",\n};\n\nstmt_base_t::stmt_base_t( const GrammarTypes type, const int tok_ctr )\n\t: m_type( type ), m_tok_ctr( tok_ctr ) {}\nstmt_base_t::~stmt_base_t() {}\n\nvoid * stmt_base_t::operator new( size_t sz )\n{\n\treturn mem::alloc( sz );\n}\nvoid stmt_base_t::operator delete( void * ptr, size_t sz )\n{\n\tmem::free( ptr, sz );\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////// Simple /////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst char * SimpleTypeStrs[ _SIMPLE_LAST ] = {\n\t\"Token\",\n\t\"Operator\",\n\t\"Keyword\",\n};\n\nstmt_simple_t::stmt_simple_t( const SimpleType stype, const tok_t * val,\n\t\t       \t      const int tok_ctr )\n\t: stmt_base_t( GRAM_SIMPLE, tok_ctr ), m_stype( stype ), m_val( val ),\n\t  m_post_dot( false ) {}\nstmt_simple_t::~stmt_simple_t() {}\nvoid stmt_simple_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Simple at %x\\n\", this );\n\tIO::tab_add( false );\n\tIO::print( false, \"Name: %s (type: %s) (post dot: %s)\\n\",\n\t\t   m_stype == SIMPLE_TOKEN && !m_val->data.empty() ? m_val->data.c_str() : TokStrs[ m_val->type ],\n\t\t   SimpleTypeStrs[ m_stype ], m_post_dot ? \"yes\" : \"no\" );\n\tIO::tab_rem( 2 );\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////// Enum //////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_enum_t::stmt_enum_t( const tok_t * name, const std::vector< tok_t * > & vals,\n\t\t\t  const bool is_mask, const int tok_ctr )\n\t: stmt_base_t( GRAM_ENUM, tok_ctr ), m_name( name ), m_vals( vals ),\n\t  m_is_mask( is_mask ) {}\nstmt_enum_t::~stmt_enum_t() {}\n\nvoid stmt_enum_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Enum at: %x (is mask: %s)\\n\", this, m_is_mask ? \"yes\" : \"no\" );\n\n\tIO::tab_add( false );\n\tIO::print( true, \"Name: %s\\n\", m_name->data.c_str() );\n\tIO::print( false, \"Values:\\n\" );\n\tIO::tab_add( false );\n\tfor( size_t i = 0; i < m_vals.size(); ++i ) {\n\t\tIO::print( i != m_vals.size() - 1, \"%s\\n\", m_vals[ i ]->data.c_str() );\n\t}\n\tIO::tab_rem( 3 );\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////// ldmod /////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_ldmod_t::stmt_ldmod_t( const std::vector< tok_t * > & whats,\n\t\t\t    const std::vector< std::string > & full_names,\n\t\t\t    const int tok_ctr )\n\t: stmt_base_t( GRAM_LDMOD, tok_ctr ), m_whats( whats ),\n\t  m_full_names( full_names ) {}\nstmt_ldmod_t::~stmt_ldmod_t() {}\n\nvoid stmt_ldmod_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Load Module(s) at: %x\\n\", this );\n\n\tIO::tab_add( false );\n\tfor( auto it = m_full_names.begin(); it != m_full_names.end(); ++it ) {\n\t\tIO::print( it != m_full_names.end() - 1, \"Name: %s\\n\", it->c_str() );\n\t}\n\tIO::tab_rem( 2 );\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////// import /////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_import_t::stmt_import_t( const std::vector< tok_t * > & whats,\n\t\t\t      const std::vector< std::string > & full_names,\n\t\t\t      const int tok_ctr )\n\t: stmt_base_t( GRAM_IMPORT, tok_ctr ), m_whats( whats ),\n\t  m_full_names( full_names ) {}\nstmt_import_t::~stmt_import_t() {}\n\nvoid stmt_import_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Import(s) at: %x\\n\", this );\n\n\tIO::tab_add( false );\n\tfor( auto it = m_full_names.begin(); it != m_full_names.end(); ++it ) {\n\t\tIO::print( it != m_full_names.end() - 1, \"Name: %s\\n\", it->c_str() );\n\t}\n\tIO::tab_rem( 2 );\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////// Expr //////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_expr_t::stmt_expr_t( const stmt_base_t * lhs, const stmt_simple_t * oper,\n\t\t\t  const stmt_base_t * rhs, const int tok_ctr )\n\t: stmt_base_t( GRAM_EXPR, tok_ctr ), m_lhs( lhs ),\n\t  m_rhs( rhs ), m_oper( oper ), m_is_top_expr( false ),\n\t  m_triple_dot( false ) {}\nstmt_expr_t::~stmt_expr_t()\n{\n\tif( m_lhs ) delete m_lhs;\n\tif( m_rhs ) delete m_rhs;\n\tif( m_oper ) delete m_oper;\n}\n\nvoid stmt_expr_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Expression (top: %s) (contains triple dots: %s) at: %x\\n\",\n\t\t   m_is_top_expr ? \"yes\" : \"no\", m_triple_dot ? \"yes\" : \"no\", this );\n\n\tIO::tab_add( m_lhs != nullptr || m_rhs != nullptr );\n\tIO::print( m_lhs != nullptr || m_rhs != nullptr,\n\t\t   \"Operator: %s\\n\", m_oper != nullptr ? TokStrs[ m_oper->m_val->type ] : \"(null)\" );\n\tif( m_lhs != nullptr ) {\n\t\tIO::print( m_rhs != nullptr, \"LHS:\\n\" );\n\t\tm_lhs->disp( false );\n\t}\n\tIO::tab_rem();\n\tIO::tab_add( false );\n\tif( m_rhs != nullptr ) {\n\t\tIO::print( false, \"RHS:\\n\" );\n\t\tm_rhs->disp( false );\n\t}\n\n\tIO::tab_rem( 2 );\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////// Struct /////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_struct_t::stmt_struct_t( const stmt_simple_t * name, const std::vector< struct_field_t > & fields, const int tok_ctr )\n\t: stmt_base_t( GRAM_STRUCT, tok_ctr ), m_name( name ), m_fields( fields ) {}\nstmt_struct_t::~stmt_struct_t()\n{\n\tdelete m_name;\n\tfor( auto & f : m_fields ) {\n\t\tif( f.name ) delete f.name;\n\t\tif( f.def_val ) delete f.def_val;\n\t}\n}\n\nvoid stmt_struct_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Struct %s at: %x\\n\", m_name->m_val->data.c_str(), this );\n\n\tfor( size_t i = 0; i < m_fields.size(); ++i ) {\n\t\tIO::tab_add( i != m_fields.size() - 1 );\n\t\tIO::print( i != m_fields.size() - 1, \"Field %d:\\n\", i + 1 );\n\t\tm_fields[ i ].name->disp( true );\n\t\tm_fields[ i ].def_val->disp( false );\n\t\tIO::tab_rem();\n\t}\n\tIO::tab_rem();\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////// Block /////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_block_t::stmt_block_t( std::vector< stmt_base_t * > * stmts, const int tok_ctr,\n\t\t\t    const bool in_func )\n\t: stmt_base_t( GRAM_BLOCK, tok_ctr ), m_stmts( stmts ), m_in_func( in_func ) {}\n\nstmt_block_t::~stmt_block_t()\n{\n\tfor( auto & stmt : * m_stmts ) delete stmt;\n\tdelete m_stmts;\n}\n\nvoid stmt_block_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Block at: %x (in function: %s)\\n\", this, m_in_func ? \"yes\" : \"no\" );\n\n\tfor( size_t i = 0; i < m_stmts->size(); ++i ) {\n\t\t( * m_stmts )[ i ]->disp( i != m_stmts->size() - 1 );\n\t}\n\tIO::tab_rem();\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////// Function ////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_func_t::stmt_func_t( const stmt_simple_t * name, const stmt_expr_t * args,\n\t\t\t  const stmt_block_t * block, const std::vector< stmt_simple_t * > & mem_types,\n\t\t\t  const int tok_ctr )\n\t: stmt_base_t( GRAM_FUNC, tok_ctr ), m_name( name ), m_args( args ), m_block( block ),\n\t  m_mem_types( mem_types ) {}\n\nstmt_func_t::~stmt_func_t()\n{\n\tdelete m_name;\n\tif( m_args ) delete m_args;\n\tdelete m_block;\n\tfor( auto & mt : m_mem_types ) delete mt;\n}\n\nvoid stmt_func_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Function %s at: %x\\n\", m_name->m_val->data.c_str(), this );\n\n\tif( m_mem_types.size() > 0 ) {\n\t\tIO::tab_add( true );\n\t\tIO::print( true, \"Member types:\\n\" );\n\t\tIO::tab_add( true );\n\t\tfor( auto mt = m_mem_types.begin(); mt != m_mem_types.end(); ++mt ) {\n\t\t\t( * mt )->disp(  mt != m_mem_types.end() - 1 );\n\t\t}\n\t\tIO::tab_rem( 2 );\n\t}\n\n\tif( m_args ) {\n\t\tIO::tab_add( true );\n\t\tIO::print( true, \"Arguments:\\n\" );\n\t\tm_args->disp( false );\n\t\tIO::tab_rem();\n\t}\n\n\tm_block->disp( false );\n\n\tIO::tab_rem();\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////// Function/Struct Call //////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst char * CallTypeStrs[ _CT_LAST ] = {\n\t\"Function\",\n\t\"Struct\",\n\t\"Subscript\",\n};\n\nstmt_func_struct_subscr_call_t::stmt_func_struct_subscr_call_t( const stmt_simple_t * name,\n\t\t\t\t\t\t\t\tstd::vector< stmt_expr_t * > args,\n\t\t\t\t\t\t\t\tconst int tok_ctr )\n\t: stmt_base_t( GRAM_FN_STRUCT_SUBSCR_CALL, tok_ctr ),\n\t  m_name( name ), m_args( args ), m_ctype( CT_FUNC ),\n\t  m_post_dot( false ) {}\n\nstmt_func_struct_subscr_call_t::~stmt_func_struct_subscr_call_t()\n{\n\tif( m_name ) delete m_name;\n\tfor( auto & arg : m_args ) if( arg ) delete arg;\n}\n\nvoid stmt_func_struct_subscr_call_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tif( m_ctype == CT_FUNC ) {\n\t\tIO::print( has_next, \"Function '%s' call at: %x (inside scope: %s)\\n\",\n\t\t\t   m_name->m_val->data.c_str(), this, m_post_dot ? \"yes\" : \"no\" );\n\t} else if( m_ctype == CT_STRUCT ) {\n\t\tIO::print( has_next, \"Struct '%s' instantiation at: %x (inside scope: %s)\\n\",\n\t\t\t   m_name->m_val->data.c_str(), this, m_post_dot ? \"yes\" : \"no\" );\n\t} else if( m_ctype == CT_SUBSCR ) {\n\t\tIO::print( has_next, \"Subscript of '%s' at: %x (inside scope: %s)\\n\",\n\t\t\t   m_name->m_val->data.c_str(), this, m_post_dot ? \"yes\" : \"no\" );\n\t}\n\tIO::tab_add( false );\n\tIO::print( false, \"Argument(s):\\n\" );\n\tfor( auto & arg : m_args ) {\n\t\tif( arg ) {\n\t\t\targ->disp( false );\n\t\t}\n\t}\n\tIO::tab_rem( 2 );\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////// Collection //////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_collection_t::stmt_collection_t( const stmt_expr_t * vals, const int tok_ctr,\n\t\t\t\t      const int line, const int col )\n\t: stmt_base_t( GRAM_COLLECTION, tok_ctr ), m_vals( vals ),\n\t  m_line( line ), m_col( col ), m_is_map( false ), m_arg_count( 0 ) {}\n\nstmt_collection_t::~stmt_collection_t() { if( m_vals ) delete m_vals; }\n\nvoid stmt_collection_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"%s%s at: %x\\n\", m_vals ? \"\" : \"Empty \", m_is_map ? \"Map\" : \"Vector\", this );\n\tif( m_vals ) m_vals->disp( false );\n\tIO::tab_rem();\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////// Conditional //////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_if_t::stmt_if_t( const std::vector< condition_t > & conds, const int tok_ctr )\n\t: stmt_base_t( GRAM_IF, tok_ctr ), m_conds( conds ) {}\n\nstmt_if_t::~stmt_if_t()\n{\n\tfor( auto & c : m_conds ) {\n\t\tif( c.cond ) delete c.cond;\n\t\tdelete c.block;\n\t}\n}\n\nvoid stmt_if_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Conditional at: %x\\n\", this );\n\n\tfor( size_t i = 0; i < m_conds.size(); ++i ) {\n\t\tIO::tab_add( i != m_conds.size() - 1 );\n\t\tIO::print( i != m_conds.size() - 1, \"Case: %d\\n\", i + 1 );\n\t\tif( m_conds[ i ].cond != nullptr ) {\n\t\t\tm_conds[ i ].cond->disp( true );\n\t\t}\n\t\tm_conds[ i ].block->disp( false );\n\t\tIO::tab_rem( 1 );\n\t}\n\n\tIO::tab_rem();\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////// Loop //////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_for_t::stmt_for_t( stmt_expr_t * init, stmt_expr_t * cond, stmt_expr_t * step,\n\t\t     const stmt_block_t * block, const int tok_ctr )\n\t: stmt_base_t( GRAM_FOR, tok_ctr ), m_init( init ), m_cond( cond ), m_step( step ),\n\t  m_block( block ) {}\n\nstmt_for_t::~stmt_for_t()\n{\n\tif( m_init != nullptr ) delete m_init;\n\tif( m_cond != nullptr ) delete m_cond;\n\tif( m_step != nullptr ) delete m_step;\n\tif( m_block != nullptr ) delete m_block;\n}\n\nvoid stmt_for_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Loop at: %x\\n\", this );\n\n\tIO::tab_add( true );\n\tIO::print( true, \"Expression (init):\\n\" );\n\tif( m_init != nullptr ) m_init->disp( false );\n\tIO::print( true, \"Expression (cond):\\n\" );\n\tif( m_cond != nullptr ) m_cond->disp( false );\n\tIO::print( true, \"Expression (step):\\n\" );\n\tif( m_step != nullptr ) m_step->disp( false );\n\tIO::tab_rem();\n\tIO::tab_add( false );\n\tIO::print( false, \"Block:\\n\" );\n\tif( m_block != nullptr ) m_block->disp( false );\n\n\tIO::tab_rem( 2 );\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////// Foreach Loop //////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\nstmt_foreach_t::stmt_foreach_t( const stmt_simple_t * name, stmt_expr_t * expr,\n\t\t\t\tconst stmt_block_t * block, const int tok_ctr )\n\t: stmt_base_t( GRAM_FOREACH, tok_ctr ), m_iter( name ), m_expr( expr ),\n\t  m_block( block ) {}\n\nstmt_foreach_t::~stmt_foreach_t()\n{\n\tdelete m_iter;\n\tdelete m_expr;\n\tif( m_block != nullptr ) delete m_block;\n}\n\nvoid stmt_foreach_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Foreach Loop at: %x\\n\", this );\n\n\tIO::tab_add( true );\n\tIO::print( true, \"Iterator: %s\\n\", m_iter->m_val->data.c_str() );\n\tIO::print( m_block != nullptr, \"Loop Expression:\\n\" );\n\tif( m_expr != nullptr ) m_expr->disp( false );\n\tIO::tab_rem();\n\tIO::tab_add( false );\n\tIO::print( false, \"Block:\\n\" );\n\tif( m_block != nullptr ) m_block->disp( false );\n\n\tIO::tab_rem( 2 );\n}\n\n////////////////////////////////////////////\n/////////////// stmt_return_t //////////////\n////////////////////////////////////////////\n\nstmt_return_t::stmt_return_t( stmt_expr_t * ret_val, const int tok_ctr )\n\t: stmt_base_t( GRAM_RETURN, tok_ctr ), m_ret_val( ret_val ) {}\nstmt_return_t::~stmt_return_t() { if( m_ret_val != nullptr ) delete m_ret_val; }\n\nvoid stmt_return_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \"Return at: %x\\n\", this );\n\n\tif( m_ret_val ) m_ret_val->disp( false );\n\n\tIO::tab_rem( 1 );\n}\n\n////////////////////////////////////////////\n/////////////// stmt_continue_t //////////////\n////////////////////////////////////////////\n\nstmt_continue_t::stmt_continue_t( const int tok_ctr )\n\t: stmt_base_t( GRAM_CONTINUE, tok_ctr ) {}\nstmt_continue_t::~stmt_continue_t() {}\n\nvoid stmt_continue_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \" Continue statement at: %x\\n\", this );\n\tIO::tab_rem();\n}\n\n////////////////////////////////////////////\n/////////////// stmt_break_t //////////////\n////////////////////////////////////////////\n\nstmt_break_t::stmt_break_t( const int tok_ctr )\n\t: stmt_base_t( GRAM_BREAK, tok_ctr ) {}\nstmt_break_t::~stmt_break_t() {}\n\nvoid stmt_break_t::disp( const bool has_next ) const\n{\n\tIO::tab_add( has_next );\n\tIO::print( has_next, \" Break statement at: %x\\n\", this );\n\tIO::tab_rem();\n}\n"
  },
  {
    "path": "src/FE/Parser/Stmts.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef PARSER_COMMON_HPP\n#define PARSER_COMMON_HPP\n\n#include \"IO.hpp\"\n#include \"ParseHelper.hpp\"\n\n#include \"../../VM/Instructions.hpp\"\n#include \"../../VM/MemPool.hpp\"\n\nenum GrammarTypes\n{\n\tGRAM_INVALID = -1,\n\tGRAM_SIMPLE,\n\tGRAM_EXPR,\n\tGRAM_ENUM,\n\tGRAM_LDMOD,\n\tGRAM_IMPORT,\n\tGRAM_STRUCT,\n\tGRAM_BLOCK,\n\tGRAM_FUNC,\n\tGRAM_FN_STRUCT_SUBSCR_CALL,\n\tGRAM_IF,\n\tGRAM_FOR,\n\tGRAM_FOREACH,\n\tGRAM_RETURN,\n\tGRAM_CONTINUE,\n\tGRAM_BREAK,\n\tGRAM_COLLECTION,\n\n\t_GRAM_LAST,\n};\n\nextern const char * GrammarTypeStrs[ _GRAM_LAST ];\n\nclass stmt_base_t\n{\npublic:\n\tconst GrammarTypes m_type;\n\tconst int m_tok_ctr;\n\tstmt_base_t( const GrammarTypes type, const int tok_ctr );\n\tvirtual ~stmt_base_t();\n\tvirtual void disp( const bool has_next ) const = 0;\n\tvirtual bool bytecode( src_t & src ) const = 0;\n\n\tstatic void * operator new( size_t sz );\n\tstatic void operator delete( void * ptr, size_t sz );\n};\n\nenum SimpleType\n{\n\tSIMPLE_TOKEN,\n\tSIMPLE_OPER,\n\tSIMPLE_KEYWORD,\n\n\t_SIMPLE_LAST,\n};\n\nextern const char * SimpleTypeStrs[ _SIMPLE_LAST ];\n\nclass stmt_simple_t : public stmt_base_t\n{\npublic:\n\tconst SimpleType m_stype;\n\tconst tok_t * m_val;\n\tbool m_post_dot;\n\tstmt_simple_t( const SimpleType stype, const tok_t * val,\n\t\t       const int tok_ctr );\n\t~stmt_simple_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nclass stmt_enum_t : public stmt_base_t\n{\n\tconst tok_t * m_name;\n\tconst std::vector< tok_t * > m_vals;\n\tbool m_is_mask;\npublic:\n\tstmt_enum_t( const tok_t * name, const std::vector< tok_t * > & vals,\n\t\t     const bool is_mask, const int tok_ctr );\n\t~stmt_enum_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nclass stmt_ldmod_t : public stmt_base_t\n{\n\tconst std::vector< tok_t * > m_whats;\n\tconst std::vector< std::string > m_full_names;\npublic:\n\tstmt_ldmod_t( const std::vector< tok_t * > & whats,\n\t\t      const std::vector< std::string > & full_names,\n\t\t      const int tok_ctr );\n\t~stmt_ldmod_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nclass stmt_import_t : public stmt_base_t\n{\n\tconst std::vector< tok_t * > m_whats;\n\tconst std::vector< std::string > m_full_names;\npublic:\n\tstmt_import_t( const std::vector< tok_t * > & whats,\n\t\t       const std::vector< std::string > & full_names,\n\t\t       const int tok_ctr );\n\t~stmt_import_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nclass stmt_expr_t : public stmt_base_t\n{\n\tconst stmt_base_t * m_lhs, * m_rhs;\n\tconst stmt_simple_t * m_oper;\npublic:\n\tbool m_is_top_expr;\n\tbool m_triple_dot;\n\tstmt_expr_t( const stmt_base_t * lhs, const stmt_simple_t * oper,\n\t\t     const stmt_base_t * rhs, const int tok_ctr );\n\t~stmt_expr_t();\n\tfriend void child_comma_count( const stmt_expr_t * expr, int & cc );\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nstruct struct_field_t\n{\n\tconst stmt_simple_t * name;\n\tstmt_expr_t * def_val;\n};\n\nclass stmt_struct_t : public stmt_base_t\n{\n\tconst stmt_simple_t * m_name;\n\tconst std::vector< struct_field_t > m_fields;\npublic:\n\tstmt_struct_t( const stmt_simple_t * name, const std::vector< struct_field_t > & fields,\n\t\t       const int tok_ctr );\n\t~stmt_struct_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nclass stmt_block_t : public stmt_base_t\n{\n\tstd::vector< stmt_base_t * > * m_stmts;\n\tbool m_in_func;\npublic:\n\tstmt_block_t( std::vector< stmt_base_t * > * stmts, const int tok_ctr, const bool in_func = false );\n\t~stmt_block_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nclass stmt_func_t : public stmt_base_t\n{\n\tconst stmt_simple_t * m_name;\n\tconst stmt_expr_t * m_args;\n\tconst stmt_block_t * m_block;\n\tconst std::vector< stmt_simple_t * > m_mem_types;\npublic:\n\tstmt_func_t( const stmt_simple_t * name, const stmt_expr_t * args,\n\t\t     const stmt_block_t * block, const std::vector< stmt_simple_t * > & mem_types,\n\t\t     const int tok_ctr );\n\t~stmt_func_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nenum CallType\n{\n\tCT_FUNC,\n\tCT_STRUCT,\n\tCT_SUBSCR,\n\n\t_CT_LAST,\n};\n\nextern const char * CallTypeStrs[ _CT_LAST ];\n\nclass stmt_func_struct_subscr_call_t : public stmt_base_t\n{\n\tconst stmt_simple_t * m_name;\npublic:\n\tstd::vector< stmt_expr_t * > m_args;\n\tCallType m_ctype;\n\tbool m_post_dot;\n\tstmt_func_struct_subscr_call_t( const stmt_simple_t * name, std::vector< stmt_expr_t * > args,\n\t\t\t\t\tconst int tok_ctr );\n\t~stmt_func_struct_subscr_call_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nclass stmt_collection_t : public stmt_base_t\n{\n\tconst stmt_expr_t * m_vals;\n\tconst int m_line, m_col;\npublic:\n\tbool m_is_map;\n\tint m_arg_count;\n\tstmt_collection_t( const stmt_expr_t * vals, const int tok_ctr,\n\t\t\t   const int line, const int col );\n\t~stmt_collection_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nstruct condition_t\n{\n\tconst stmt_expr_t * cond;\n\tconst stmt_block_t * block;\n};\n\nclass stmt_if_t : public stmt_base_t\n{\n\tstd::vector< condition_t > m_conds;\npublic:\n\tstmt_if_t( const std::vector< condition_t > & conds, const int tok_ctr );\n\t~stmt_if_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nclass stmt_for_t : public stmt_base_t\n{\n\tstmt_expr_t * m_init, * m_cond, * m_step;\n\tconst stmt_block_t * m_block;\npublic:\n\tstmt_for_t( stmt_expr_t * init, stmt_expr_t * cond, stmt_expr_t * step,\n\t\t     const stmt_block_t * block, const int tok_ctr );\n\t~stmt_for_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nclass stmt_foreach_t : public stmt_base_t\n{\n\tconst stmt_simple_t * m_iter;\n\tstmt_expr_t * m_expr;\n\tconst stmt_block_t * m_block;\npublic:\n\tstmt_foreach_t( const stmt_simple_t * name, stmt_expr_t * expr,\n\t\t\tconst stmt_block_t * block, const int tok_ctr );\n\t~stmt_foreach_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nstruct stmt_return_t : public stmt_base_t\n{\n\tstmt_expr_t * m_ret_val;\n\tstmt_return_t( stmt_expr_t * ret_val, const int tok_ctr );\n\t~stmt_return_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nstruct stmt_continue_t : public stmt_base_t\n{\n\tstmt_continue_t( const int tok_ctr );\n\t~stmt_continue_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\nstruct stmt_break_t : public stmt_base_t\n{\n\tstmt_break_t( const int tok_ctr );\n\t~stmt_break_t();\n\tvoid disp( const bool has_next ) const;\n\tbool bytecode( src_t & src ) const;\n};\n\n#define PARSE_FAIL( ... ) src_fail( src.file, src.code[ ph->peak()->line - 1 ], \\\n\t\t\t\t    ph->peak()->line, ph->peak()->col, __VA_ARGS__ )\n\n#endif // PARSER_COMMON_HPP"
  },
  {
    "path": "src/FE/Parser/Struct.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Internal.hpp\"\n#include \"../Ethereal.hpp\"\n\nstmt_struct_t * parse_struct( const src_t & src, parse_helper_t * ph )\n{\n\tint tok_ctr = ph->tok_ctr();\n\ttok_t * name = nullptr;\n\tNEXT_VALID( TOK_IDEN );\n\tname = ph->peak();\n\n\tNEXT_VALID( TOK_LBRACE );\n\n\ttok_t * fname = nullptr;\n\tint fname_tok_ctr;\n\texpr_res_t fdef_val = { 0, nullptr };\n\tstd::vector< struct_field_t > fields;\n\tint semicol_loc = -1;\n\tint err = 0;\nfield_begin:\n\tNEXT_VALID2_FAIL(TOK_IDEN, TOK_RBRACE );\n\tif( ph->peak()->type == TOK_RBRACE ) goto end;\n\tfname = ph->peak();\n\tfname_tok_ctr = ph->tok_ctr();\n\tNEXT_VALID_FAIL( TOK_ASSN );\n\tph->next();\n\terr = find_next_of( ph, semicol_loc, { TOK_COLS } );\n\tif( err < 0 ) {\n\t\tif( err == -1 ) {\n\t\t\tPARSE_FAIL( \"could not find the semicolon for field value expression\" );\n\t\t} else if( err == -2 ) {\n\t\t\tPARSE_FAIL( \"found end of statement (semicolon) before the equivalent ending brace for map\" );\n\t\t}\n\t\tgoto fail;\n\t}\n\tfdef_val = parse_expr( src, ph, semicol_loc, false );\n\tif( fdef_val.res != 0 ) goto fail;\n\tfields.push_back( { new stmt_simple_t( SIMPLE_TOKEN, fname, fname_tok_ctr ), fdef_val.expr } );\n\tfname = nullptr;\n\tfdef_val = { 0, nullptr };\n\tph->set_tok_ctr( semicol_loc );\n\tif( ph->peak( 1 )->type != TOK_RBRACE ) {\n\t\tif( ph->peak( 1 )->type != TOK_IDEN ) {\n\t\t\tph->next();\n\t\t\tPARSE_FAIL( \"expected end of struct '}' or another struct field 'IDEN', found '%s'\",\n\t\t\t\t    ph->peak()->data.c_str() );\n\t\t\tgoto fail;\n\t\t}\n\t\tgoto field_begin;\n\t}\n\tph->next();\nend:\n\t// now at RBRACE\n\treturn new stmt_struct_t( new stmt_simple_t( SIMPLE_TOKEN, name, tok_ctr + 1 ), fields, tok_ctr );\nfail:\n\tfor( auto & f : fields ) {\n\t\tdelete f.name;\n\t\tdelete f.def_val;\n\t}\n\treturn nullptr;\n}\n\nbool stmt_struct_t::bytecode( src_t & src ) const\n{\n\tfor( auto & f : m_fields ) {\n\t\tf.def_val->bytecode( src );\n\t\tsrc.bcode.push_back( { m_tok_ctr, f.name->m_val->line, f.name->m_val->col,\n\t\t\t\t       IC_PUSH, { OP_CONST, f.name->m_val->data } } );\n\t}\n\tsrc.bcode.push_back( { m_tok_ctr, m_name->m_val->line, m_name->m_val->col,\n\t\t\t       IC_PUSH, { OP_CONST, m_name->m_val->data } } );\n\tsrc.bcode.push_back( { m_tok_ctr, m_name->m_val->line, m_name->m_val->col,\n\t\t\t       IC_BUILD_STRUCT, { OP_INT, std::to_string( m_fields.size() ) } } );\n\treturn true;\n}"
  },
  {
    "path": "src/FE/Parser.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <algorithm>\n\n#include \"Parser/Internal.hpp\"\n#include \"Parser.hpp\"\n#include \"Ethereal.hpp\"\n\nbool check_type_correct_parent( const int tok_type, const GrammarTypes parent );\n\n// NOTE: all the parse_* functions return at the point of their respective ending tokens\nparse_tree_t * parse( src_t & src, parse_helper_t * pre_ph, std::vector< GrammarTypes > parent_stack, const int end )\n{\n\tparse_tree_t * ptree = new parse_tree_t();\n\tparse_helper_t * ph = pre_ph != nullptr ? pre_ph : new parse_helper_t( src.toks );\n\n\twhile( ph->peak()->type != TOK_INVALID && ( end == -1 || ph->tok_ctr() < end ) ) {\n\t\tif( !parent_stack.empty() && !check_type_correct_parent( ph->peak()->type, parent_stack.back() ) ) {\n\t\t\tPARSE_FAIL( \"cannot have %s in %s's block\",\n\t\t\t\t    TokStrs[ ph->peak()->type ],\n\t\t\t\t    GrammarTypeStrs[ parent_stack.back() ] );\n\t\t\tgoto fail;\n\t\t}\n\t\tstmt_base_t * res = nullptr;\n\t\tif( ph->peak()->type == TOK_ENUM || ph->peak()->type == TOK_ENUM_MASK ) {\n\t\t\tres = parse_enum( src, ph );\n\t\t} else if( ph->peak()->type == TOK_LDMOD ) {\n\t\t\tres = parse_ldmod( src, ph );\n\t\t} else if( ph->peak()->type == TOK_IMPORT ) {\n\t\t\tres = parse_import( src, ph );\n\t\t} else if( ph->peak()->type == TOK_STRUCT ) {\n\t\t\tres = parse_struct( src, ph );\n\t\t} else if( ph->peak()->type == TOK_FN || ph->peak()->type == TOK_MFN ) {\n\t\t\tres = parse_func( src, ph );\n\t\t} else if( ph->peak()->type == TOK_IF ) {\n\t\t\tres = parse_if( src, ph, parent_stack );\n\t\t} else if( ph->peak()->type == TOK_FOR ) {\n\t\t\tif( ph->peak( 1 )->type == TOK_IDEN && ph->peak( 2 )->type == TOK_IN ) {\n\t\t\t\tres = parse_foreach( src, ph, parent_stack );\n\t\t\t} else {\n\t\t\t\tres = parse_for( src, ph, parent_stack );\n\t\t\t}\n\t\t} else if( ph->peak()->type == TOK_RETURN ) {\n\t\t\tif( std::find( parent_stack.begin(), parent_stack.end(), GRAM_FUNC ) == parent_stack.end() ) {\n\t\t\t\tPARSE_FAIL( \"keyword 'return' can only be used inside a function\" );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tres = parse_return( src, ph );\n\t\t} else if( ph->peak()->type == TOK_CONTINUE ) {\n\t\t\t// TODO: convert two find calls to a single\n\t\t\tif( std::find( parent_stack.begin(), parent_stack.end(), GRAM_FOR ) == parent_stack.end() &&\n\t\t\t    std::find( parent_stack.begin(), parent_stack.end(), GRAM_FOREACH ) == parent_stack.end() ) {\n\t\t\t\tPARSE_FAIL( \"keyword 'continue' can only be used inside a loop\" );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tres = new stmt_continue_t( ph->tok_ctr() );\n\t\t\tph->next();\n\t\t} else if( ph->peak()->type == TOK_BREAK ) {\n\t\t\tif( std::find( parent_stack.begin(), parent_stack.end(), GRAM_FOR ) == parent_stack.end() &&\n\t\t\t    std::find( parent_stack.begin(), parent_stack.end(), GRAM_FOREACH ) == parent_stack.end() ) {\n\t\t\t\tPARSE_FAIL( \"keyword 'break' can only be used inside a loop\" );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tres = new stmt_break_t( ph->tok_ctr() );\n\t\t\tph->next();\n\t\t} else if( ph->peak()->type == TOK_LBRACE ) {\n\t\t\t// simple block\n\t\t\tres = parse_block( src, ph, parent_stack );\n\t\t} else {\n\t\t\t// just expressions remain\n\t\t\texpr_res_t expr = parse_expr( src, ph );\n\t\t\tif( expr.res != 0 ) {\n\t\t\t\tPARSE_FAIL( \"failed parsing expression\" );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tres = expr.expr;\n\t\t\tif( res == nullptr ) {\n\t\t\t\tPARSE_FAIL( \"encountered invalid token\" );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\n\t\tif( res == nullptr ) goto fail;\n\t\tptree->push_back( res );\n\t\tph->next();\n\t}\n\n\tif( pre_ph == nullptr ) delete ph;\n\treturn ptree;\nfail:\n\tfor( auto & base : * ptree ) {\n\t\tdelete base;\n\t}\n\tdelete ptree;\n\tif( pre_ph == nullptr ) delete ph;\n\treturn nullptr;\n}\n\nbool check_type_correct_parent( const int tok_type, const GrammarTypes parent )\n{\n\t//if( parent == GRAM_INVALID ) return true;\n\tif( ( tok_type == TOK_ENUM ||\n\t      tok_type == TOK_STRUCT ||\n\t      tok_type == TOK_FN ) &&\n\t     parent != GRAM_INVALID ) return false;\n\treturn true;\n}\n"
  },
  {
    "path": "src/FE/Parser.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef PARSER_HPP\n#define PARSER_HPP\n\n#include \"Parser/Stmts.hpp\"\n\ntypedef std::vector< stmt_base_t * > parse_tree_t;\n\nparse_tree_t * parse( src_t & src, parse_helper_t * pre_ph = nullptr,\n\t\t      std::vector< GrammarTypes > parent_stack = { GRAM_INVALID },\n\t\t      const int end = -1 );\n\n#endif // PARSER_HPP"
  },
  {
    "path": "src/VM/CallFunc.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"ExecInternal.hpp\"\n#include \"CallFunc.hpp\"\n\nstatic std::string args_types_to_string( const std::vector< var_base_t * > & args, bool is_mem );\nstatic void disp_possible_funcs( vm_state_t & vm, const std::string & fn, const std::string & mem_of );\nstatic void disp_fn_vec( const std::vector< function_t * > & fns );\n\nint CallFunc( vm_state_t & vm, func_call_data_t & fcd, const int ins_ctr )\n{\n\tsrc_t & src = * vm.srcstack.back();\n\tinstr_t & ins = src.bcode[ ins_ctr ];\n\tfcd.bcodectr = ins_ctr;\n\n\tfcd.arg_types.clear();\n\tfcd.rem_locs.clear();\n\tfcd.src_idx = src.id;\n\tfcd.parse_ctr = ins.parse_ctr;\n\tint var_args_count = 0;\n\tvar_base_t * member = nullptr;\n\tconst function_t * fn;\n\tmodfnptr_t mfnptr = nullptr;\n\tconst langfn_t * lfnptr = nullptr;\n\tres_t< var_base_t * > res = { 0, nullptr };\n\n\t// this is so early on in the function because if the execution goes to 'fail',\n\t// it will call unfreeze() which will pop the last element unconditionally\n\t// which will cause segfault if there is nothing in the m_frozen_till vector in\n\t// the first place\n\tvm.vars->freeze_till( vm.vars->layer_size() );\n\n\tfcd.args_count = std::stoi( ins.oper.val );\n\t// + 1 for function name\n\tVERIFY_STACK_MIN( ( size_t )fcd.args_count + 1 );\n\tif( vm.stack->back()->type() != VT_STR ) {\n\t\tVM_FAIL( \"expected a name (identifier) for function call, found '%s'\",\n\t\t\t vm.stack->back()->to_str().c_str() );\n\t\tgoto fail;\n\t}\n\tfcd.fn_name = vm.stack->back()->to_str();\n\tvm.stack->pop_back();\n\t// fetch args\n\tfor( int i = 0; i < fcd.args_count; ++i ) {\n\t\tvar_base_t * back = vm.stack->back();\n\t\tif( back->type() == VarType::VT_VEC && AS_VEC( back )->is_var_arg() ) {\n\t\t\tstd::vector< var_base_t * > & vec = AS_VEC( back )->get();\n\t\t\t// minus 1 because vec replaces the argument, not appends to it\n\t\t\tvar_args_count += vec.size() - 1;\n\t\t\tfor( auto & e : vec ) {\n\t\t\t\tVAR_IREF( e );\n\t\t\t\tfcd.arg_types.push_back( e->type_str() );\n\t\t\t\tfcd.args.push_back( e );\n\t\t\t}\n\t\t\tvm.stack->pop_back();\n\t\t} else {\n\t\t\tfcd.arg_types.push_back( back->type_str() );\n\t\t\tfcd.args.push_back( back );\n\t\t\tvm.stack->pop_back( false );\n\t\t}\n\t}\n\tfcd.args_count += var_args_count;\n\n\tif( ins.opcode == IC_MFN_CALL ) {\n\t\tmember = vm.stack->back();\n\t\tvm.stack->pop_back( false );\n\t\tfcd.args.insert( fcd.args.begin(), member );\n\t\tfn = vm.typefuncs[ member->type_str() ].get( fcd.fn_name, fcd.args_count, fcd.arg_types );\n\t\tif( fn == nullptr ) {\n\t\t\tfn = vm.typefuncs[ \"_any_\" ].get( fcd.fn_name, fcd.args_count, fcd.arg_types );\n\t\t}\n\t} else {\n\t\t// fetch the function pointer from Functions\n\t\tfn = vm.funcs.get( fcd.fn_name, fcd.args_count, fcd.arg_types );\n\t}\n\tif( fn == nullptr ) {\n\t\tVM_FAIL( \"%sfunction with name '%s' %sand arg count %d (%s) does not exist\",\n\t\t\t ins.opcode == IC_MFN_CALL ? \"member \" : \"\",fcd.fn_name.c_str(),\n\t\t\t ins.opcode == IC_MFN_CALL ? ( \"for type '\" + member->type_str() + \"' \" ).c_str() : \"\",\n\t\t\t fcd.args_count, args_types_to_string( fcd.args, member ).c_str() );\n\t\tdisp_possible_funcs( vm, fcd.fn_name, ins.opcode == IC_MFN_CALL ? member->type_str() : \"\" );\n\t\tgoto fail;\n\t}\n\tif( fn->type == FnType::MODULE ) mfnptr = fn->func.modfn;\n\telse lfnptr = & fn->func.langfn;\n\tif( mfnptr == nullptr && lfnptr == nullptr ) {\n\t\tVM_FAIL( \"function with name '%s' is null\", fcd.fn_name.c_str() );\n\t\tgoto fail;\n\t}\n\n\t// execute the function\n\tres.code = E_OK;\n\tif( mfnptr ) {\n\t\tres.data = mfnptr( vm, fcd );\n\t\t// for lang function, args are moved to vars' new layer which is popped at the end\n\t\t// member is also added to args and hence erased\n\t\tfor( auto & arg : fcd.args ) VAR_DREF( arg );\n\t} else {\n\t\tint use_layer = vm.vars->layer_size() + 1;\n\t\tvm.srcstack.push_back( vm.srcs[ lfnptr->src ] );\n\t\tif( member ) {\n\t\t\tfcd.args.erase( fcd.args.begin() );\n\t\t\tvm.vars->add_with_layer( \"self\", member, use_layer );\n\t\t}\n\t\tfor( size_t i = 0; i < fn->arg_count_min; ++i ) {\n\t\t\tvm.vars->add_with_layer( fn->arg_types[ i ], fcd.args[ i ], use_layer );\n\t\t}\n\t\tif( fn->arg_count_max == -1 ) {\n\t\t\tstd::vector< var_base_t * > va;\n\t\t\tfor( size_t i = fn->arg_count_min; i < fcd.args.size(); ++i ) {\n\t\t\t\tva.push_back( fcd.args[ i ] );\n\t\t\t}\n\t\t\tvm.vars->add_with_layer( \"__VA__\", new var_vec_t( va, fcd.src_idx, fcd.parse_ctr, true ), use_layer );\n\t\t}\n\t\tfcd.args.clear();\n\t\tres.code = exec_internal( vm, lfnptr->beg, lfnptr->end, res.data );\n\t\tvm.srcstack.pop_back();\n\t\tif( res.code != E_OK ) {\n\t\t\tVM_FAIL( \"function '%s' failed to execute properly\", fcd.fn_name.c_str() );\n\t\t\tgoto fail;\n\t\t}\n\t}\n\tif( mfnptr ) {\n\t\tif( res.data == nullptr ) {\n\t\t\tvm.stack->push_back( vm.none );\n\t\t} else {\n\t\t\tres.data->set_src_idx( fcd.src_idx );\n\t\t\tres.data->set_parse_ctr( fcd.parse_ctr );\n\t\t\tvm.stack->push_back( res.data, !fn->manual_res_free || res.data->type() == VT_NIL );\n\t\t}\n\t}\n\n\tvm.vars->unfreeze();\n\tfor( auto & rll : fcd.rem_locs ) VAR_DREF( rll );\n\tfcd.args.clear();\n\treturn E_OK;\nfail:\n\tvm.vars->unfreeze();\n\tfor( auto & arg : fcd.args ) VAR_DREF( arg );\n\tfcd.args.clear();\n\tfor( auto & rll : fcd.rem_locs ) VAR_DREF( rll );\n\treturn E_VM_FAIL;\n}\n\nstatic std::string args_types_to_string( const std::vector< var_base_t * > & args, bool is_mem )\n{\n\tstd::string res = \"\";\n\tsize_t size = args.size();\n\tfor( size_t i = 0 + is_mem; i < size; ++i ) {\n\t\tres += args[ i ]->type_str();\n\t\tif( i < size - 1 ) res += \", \";\n\t}\n\treturn res;\n}\n\nstatic void disp_possible_funcs( vm_state_t & vm, const std::string & fn, const std::string & mem_of )\n{\n\tstd::vector< function_t * > fns = vm.funcs.get_all_by_name( fn );\n\tif( fns.size() > 0 ) {\n\t\tfprintf( stderr, \"Other possible functions with same name are:\\n\" );\n\t\tdisp_fn_vec( fns );\n\t}\n\n\tif( mem_of == \"\" ) {\n\t\tfor( auto & type : vm.typefuncs ) {\n\t\t\tstd::vector< function_t * > mfns = type.second.get_all_by_name( fn );\n\t\t\tif( mfns.size() > 0 ) {\n\t\t\t\tfprintf( stderr, \"Possible member functions for type '%s' with same name are:\\n\",\n\t\t\t\t\t type.first.c_str() );\n\t\t\t\tdisp_fn_vec( mfns );\n\t\t\t}\n\t\t}\n\t} else {\n\t\tstd::vector< function_t * > mfns = vm.typefuncs[ mem_of ].get_all_by_name( fn );\n\t\tif( mfns.size() > 0 ) {\n\t\t\tfprintf( stderr, \"Possible member functions for type '%s' with same name are:\\n\",\n\t\t\t\t mem_of.c_str() );\n\t\t\tdisp_fn_vec( mfns );\n\t\t}\n\t}\n}\n\nstatic void disp_fn_vec( const std::vector< function_t * > & fns )\n{\n\tfor( auto & fn : fns ) {\n\t\tfprintf( stderr, \"-> %s with arg count: [%d, %d] \", fn->name.c_str(), fn->arg_count_min, fn->arg_count_max );\n\t\tif( fn->arg_count_min > 0 && fn->arg_types.size() < 1 ) {\n\t\t\tfprintf( stderr, \"(...)\\n\" );\n\t\t} else {\n\t\t\tfprintf( stderr, \"(\" );\n\t\t\tfor( auto & type : fn->arg_types ) {\n\t\t\t\tfprintf( stderr, \"%s, \", type.c_str() );\n\t\t\t}\n\t\t\tif( fn->arg_count_max == -1 ) fprintf( stderr, \"...\" );\n\t\t\telse if( fn->arg_count_min > 0 ) fprintf( stderr, \"\\b\\b\" );\n\t\t\tfprintf( stderr, \")\\n\" );\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/VM/CallFunc.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_CALL_FUNC_HPP\n#define VM_CALL_FUNC_HPP\n\n#include \"Core.hpp\"\n\nint CallFunc( vm_state_t & vm, func_call_data_t & fd, const int ins_ctr );\n\n#endif // VM_CALL_FUNC_HPP"
  },
  {
    "path": "src/VM/Consts.cpp",
    "content": "/*\n  Copyright (c) 2019, Electrux\n  All rights reserved.\n  Using the GNU GPL 3.0 license for the project,\n  main LICENSE file resides in project's root directory.\n  Please read that file and understand the license terms\n  before using or altering the project.\n*/\n\n#include \"Consts.hpp\"\n\nconsts_t::consts_t() {}\nconsts_t::~consts_t()\n{\n\tfor( auto & t : m_consts ) {\n\t\tfor( auto & cons : t.second ) {\n\t\t\tVAR_DREF( cons.second );\n\t\t}\n\t}\n}\n\nvar_base_t * consts_t::get( const std::string & name, const OperTypes type, const int tok_ctr )\n{\n\tif( m_consts[ type ].find( name ) != m_consts[ type ].end() ) {\n\t\tif( name == m_consts[ type ][ name ]->to_str() ) {\n\t\t\treturn m_consts[ type ][ name ];\n\t\t}\n\t\tVAR_DREF( m_consts[ type ][ name ] );\n\t}\n\n\tif( type == OP_INT ) return m_consts[ type ][ name ] = new var_int_t( name, tok_ctr );\n\telse if( type == OP_FLT ) return m_consts[ type ][ name ] = new var_flt_t( name, tok_ctr );\n\telse if( type == OP_STR || type == OP_CONST ) return m_consts[ type ][ name ] = new var_str_t( name, tok_ctr );\n\n\treturn nullptr;\n}"
  },
  {
    "path": "src/VM/Consts.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_CONSTS_HPP\n#define VM_CONSTS_HPP\n\n#include <string>\n#include <unordered_map>\n\n#include \"Instructions.hpp\"\n#include \"Vars/Base.hpp\"\n\ntypedef std::unordered_map< int, std::unordered_map< std::string, var_base_t * > > constmap_t;\n\nclass consts_t\n{\n\tconstmap_t m_consts;\npublic:\n\tconsts_t();\n\t~consts_t();\n\tvar_base_t * get( const std::string & name, const OperTypes type, const int tok_ctr );\n};\n\n#endif // VM_CONSTS_HPP"
  },
  {
    "path": "src/VM/Core.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../FE/Env.hpp\"\n#include \"../FE/FS.hpp\"\n\n#include \"LoadFile.hpp\"\n#include \"Core.hpp\"\n\n#ifdef __APPLE__\nconst char * LIB_EXT = \".dylib\";\n#else\nconst char * LIB_EXT = \".so\";\n#endif\n\nvm_state_t::vm_state_t() : flags( 0 ), exit_called( false ), exit_status( 0 ),\n\tinc_dirs( new var_vec_t( {}, 0 ) ), lib_dirs( new var_vec_t( {}, 0 ) ),\n\tnone( new var_none_t( 0, 0 ) ), nil( new var_nil_t( 0, 0 ) ),\n\tvars( new vars_t ), dlib( new dyn_lib_t() ),\n\tconsts( new consts_t() ), stack( new vm_stack_t() )\n{\n#ifdef BUILD_PREFIX_DIR\n\tAS_VEC( inc_dirs )->get().push_back( new var_str_t( STRINGIFY( BUILD_PREFIX_DIR ) \"/include/ethereal\", 0 ) );\n\tAS_VEC( lib_dirs )->get().push_back( new var_str_t( STRINGIFY( BUILD_PREFIX_DIR ) \"/lib/ethereal\", 0 ) );\n#endif\n\tvars->add( \"__INC_DIRS__\", inc_dirs );\n\tvars->add( \"__LIB_DIRS__\", lib_dirs );\n\tvars->add( \"nil\", nil );\n}\n\nvm_state_t::~vm_state_t()\n{\n\tdelete stack;\n\tdelete consts;\n\tdelete vars;\n\tVAR_DREF( none );\n\tfor( auto & struct_ : structs ) delete struct_.second;\n\t// see: https://gforge.inria.fr/tracker/?func=detail&atid=619&aid=9783&group_id=136\n\t// clears the log(), pow(), ... cache of mpfr library\n\tmpfr_free_cache();\n\tdelete dlib;\n\tfor( auto & src : srcs ) delete src.second;\n}\n\nbool set_init_mods( vm_state_t & vm )\n{\n\tstd::vector< std::string > mods = { \"core\" };\n\n\tfor( auto & m : mods ) {\n\t\tstd::string name = m;\n\t\tstd::string file = name + \".et\";\n\n\t\tif( !mod_exists( file, vm.inc_dirs ) ) {\n\t\t\tfprintf( stderr, \"could not find file '%s' for importing\\n\", name.c_str() );\n\t\t\tfprintf( stderr, \"checked the following paths:\\n\" );\n\t\t\tfor( auto & loc : AS_VEC( vm.inc_dirs )->get() ) {\n\t\t\t\tfprintf( stderr, \"-> %s\\n\", ( loc->to_str() + \"/\" + file ).c_str() );\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tint ret = load_src( vm, file );\n\t\tif( ret != E_OK ) {\n\t\t\tfprintf( stderr, \"could not import '%s', see the error above; aborting\\n\",\n\t\t\t\t file.c_str() );\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nsize_t mpz_to_size_t( const mpz_class & n )\n{\n\tsize_t data;\n\tmpz_export( & data, 0, -1, sizeof( data ), 0, 0, n.get_mpz_t() );\n\treturn data;\n}\n\nstd::vector< std::string > str_delimit( const std::string & str, const char ch, const bool first_only )\n{\n\tstd::string temp;\n\tstd::vector< std::string > vec;\n\tbool done = false;\n\n\tfor( auto c : str ) {\n\t\tif( c == ch && ( !first_only || !done ) ) {\n\t\t\tdone = true;\n\t\t\tif( temp.empty() ) continue;\n\t\t\tvec.push_back( temp );\n\t\t\ttemp.clear();\n\t\t\tcontinue;\n\t\t}\n\n\t\ttemp += c;\n\t}\n\n\tif( !temp.empty() ) vec.push_back( temp );\n\treturn vec;\n}\n\nbool mod_exists( std::string & file, var_vec_t * locs )\n{\n\tif( file.front() != '~' && file.front() != '/' && file.front() != '.' ) {\n\t\tfor( auto & _loc : AS_VEC( locs )->get() ) {\n\t\t\tstd::string loc = _loc->to_str();\n\t\t\tif( fexists( loc + \"/\" + file ) ) {\n\t\t\t\tfile = loc + \"/\" + file;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif( file.front() == '~' ) {\n\t\t\tfile.erase( file.begin() );\n\t\t\tstd::string home = GetEnv( \"HOME\" );\n\t\t\tfile.insert( file.begin(), home.begin(), home.end() );\n\t\t}\n\n\t\treturn fexists( file );\n\t}\n\treturn false;\n}\n"
  },
  {
    "path": "src/VM/Core.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_CORE_HPP\n#define VM_CORE_HPP\n\n#include \"../FE/Ethereal.hpp\"\n\n#include \"../../third_party/mpfrxx.hpp\"\n\n#include \"DynLib.hpp\"\n#include \"Consts.hpp\"\n#include \"VMStack.hpp\"\n\nextern const char * LIB_EXT;\n\ntypedef std::vector< src_t * > src_stack_t;\ntypedef std::vector< std::string > src_list_t;\n\ntypedef std::unordered_map< std::string, functions_t > type_funcs_t;\n\ntypedef std::unordered_map< std::string, var_struct_def_t * > structs_t;\n\nstruct vm_state_t\n{\n\tsize_t flags;\n\tbool exit_called;\n\tint exit_status;\n\t// used for assertions\n\tstd::string fail_msg;\n\n\tvar_vec_t * inc_dirs;\n\tvar_vec_t * lib_dirs;\n\n\tvar_none_t * none;\n\tvar_nil_t * nil;\n\n\tsrc_stack_t srcstack;\n\tsrc_list_t srclist;\n\tsrcs_t srcs;\n\n\tvars_t * vars;\n\tstructs_t structs;\n\n\tdyn_lib_t * dlib;\n\tconsts_t * consts;\n\tfunctions_t funcs;\n\tvm_stack_t * stack;\n\n\ttype_funcs_t typefuncs;\n\n\tvm_state_t();\n\t~vm_state_t();\n};\n\n// for CallFunc()\nstruct func_call_data_t\n{\n\tstd::string fn_name;\n\tint args_count;\n\tint src_idx;\n\tint parse_ctr;\n\tint bcodectr;\n\tstd::vector< std::string > arg_types;\n\tstd::vector< var_base_t * > args;\n\tstd::vector< void * > rem_locs;\n};\n\n#define VM_FAIL( ... ) src_fail( src.file, src.code[ ins.line - 1 ], \\\n\t\t\t\t ins.line, ins.col, __VA_ARGS__ )\n\n#define VM_FAIL_FILE_TOK_CTR( src_idx, tok_ctr, ... )\t\t\t\t\t\t\t\\\n\tsrc_fail( vm.srcs[ src_idx ]->file,\t\t\t\t\t\t\t\t\\\n\t\t  vm.srcs[ src_idx ]->code[ vm.srcs[ src_idx ]->toks[ tok_ctr ].line - 1 ],\t\t\\\n\t\t  vm.srcs[ src_idx ]->toks[ tok_ctr ].line, vm.srcs[ src_idx ]->toks[ tok_ctr ].col,\t\\\n\t\t  __VA_ARGS__ )\n\nbool set_init_mods( vm_state_t & vm );\n\nsize_t mpz_to_size_t( const mpz_class & n );\n\nstd::vector< std::string > str_delimit( const std::string & str, const char ch, const bool first_only = false );\n\nbool mod_exists( std::string & file, var_vec_t * locs );\n\n#define TRUE_FALSE( condition ) ( condition ) ? vm.vars->get( \"true\" ) : vm.vars->get( \"false\" )\n\n#endif // VM_CORE_HPP\n"
  },
  {
    "path": "src/VM/DynLib.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cstdio>\n#include <string>\n#include <unordered_map>\n#include <dlfcn.h>\n\n#include \"DynLib.hpp\"\n\ndyn_lib_t::dyn_lib_t() {}\n\ndyn_lib_t::~dyn_lib_t()\n{\n\tfor( auto & e : m_handles ) {\n\t\tif( e.second != nullptr ) dlclose( e.second );\n\t}\n}\n\nvoid * dyn_lib_t::load( const std::string & file )\n{\n\tif( m_handles.find( file ) == m_handles.end() ) {\n\t\tauto tmp = dlopen( file.c_str(), RTLD_LAZY );\n\t\tif( tmp == nullptr ) {\n\t\t\tfprintf( stderr, \"internal error: dyn lib failed to open %s: %s\\n\", file.c_str(), dlerror() );\n\t\t\treturn nullptr;\n\t\t}\n\t\tm_handles[ file ] = tmp;\n\t}\n\treturn m_handles[ file ];\n}\n\nvoid dyn_lib_t::unload( const std::string & file )\n{\n\tif( m_handles.find( file ) == m_handles.end() ) return;\n\tdlclose( m_handles[ file ] );\n\tm_handles.erase( file );\n}\n\nvoid * dyn_lib_t::get( const std::string & file, const std::string & sym )\n{\n\tif( m_handles.find( file ) == m_handles.end() ) return nullptr;\n\treturn dlsym( m_handles[ file ], sym.c_str() );\n}\n"
  },
  {
    "path": "src/VM/DynLib.hpp",
    "content": "/*\n  Copyright (c) 2019, Electrux\n  All rights reserved.\n  Using the GNU GPL 3.0 license for the project,\n  main LICENSE file resides in project's root directory.\n  Please read that file and understand the license terms\n  before using or altering the project.\n*/\n\n#ifndef VM_DYN_LIB_HPP\n#define VM_DYN_LIB_HPP\n\n#include <string>\n#include <unordered_map>\n\n/* Wrapper class for dlfcn.h library */\nclass dyn_lib_t\n{\n\tstd::unordered_map< std::string, void * > m_handles;\npublic:\n\tdyn_lib_t();\n\t~dyn_lib_t();\n\tvoid * load( const std::string & file );\n\tvoid unload( const std::string & file );\n\tvoid * get( const std::string & file, const std::string & sym );\n\tinline bool fexists( const std::string & file ) { return m_handles.find( file ) != m_handles.end(); }\n};\n\n#endif // VM_DYN_LIB_HPP"
  },
  {
    "path": "src/VM/ExecInternal.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <cstdlib>\n\n#include \"../FE/FS.hpp\"\n#include \"../FE/Env.hpp\"\n\n#include \"ExecInternal.hpp\"\n#include \"CallFunc.hpp\"\n#include \"LoadFile.hpp\"\n\n#ifdef DEBUG_MODE\n#include <chrono>\n#endif\n\nbool copy_data( var_base_t * a, var_base_t * b );\n\nstruct fn_blk_t\n{\n\tint beg, end;\n};\n\nint exec_internal( vm_state_t & vm, long begin, long end, var_base_t * ret )\n{\n\tsrc_t & src = * vm.srcstack.back();\n\tbegin = begin == -1 ? 0 : begin;\n\tend = end == -1 ? src.bcode.size() : end;\n\n\tstd::vector< fn_blk_t > fn_blks;\n\tstd::vector< std::vector< std::string > > fn_args;\n\n\tfunc_call_data_t func_call_data;\n\n#ifdef DEBUG_MODE\n\ttypedef std::chrono::high_resolution_clock clk_t;\n\tstd::chrono::time_point< clk_t > start = clk_t::now();\n\tstd::chrono::time_point< clk_t > stamp;\n#endif\n\n\tfor( int i = begin; i < end; ++i ) {\n\t\tinstr_t & ins = src.bcode[ i ];\n\n#ifdef DEBUG_MODE\n\t\tstamp = clk_t::now();\n\n\t\tfprintf( stdout, \"Current stack (operation [%d]: %s[%s]): \", i, InstrCodeStrs[ ins.opcode ], ins.oper.val.c_str() );\n\t\t//fprintf( stdout, \"%f\", std::chrono::duration_cast< std::chrono::duration< double, std::milli > >( stamp - start ).count() );\n\t\tfor( auto & s : vm.stack->get() ) {\n\t\t\tfprintf( stdout, \"%s \", s->to_str().c_str() );\n\t\t}\n\t\tstart = stamp;\n\t\tfprintf( stdout, \"\\n\" );\n#endif\n\t\tswitch( ins.opcode ) {\n\t\tcase IC_PUSH: {\n\t\t\tvar_base_t * val = nullptr;\n\t\t\tif( ins.oper.type == OP_STR ) {\n\t\t\t\tval = vm.vars->get( ins.oper.val );\n\t\t\t} else if( ins.oper.type == OP_NONE ) {\n\t\t\t\tval = vm.none;\n\t\t\t} else {\n\t\t\t\tval = vm.consts->get( ins.oper.val, ins.oper.type, ins.parse_ctr );\n\t\t\t}\n\t\t\tif( val == nullptr ) {\n\t\t\t\tVM_FAIL( \"%s '%s' does not exist\", ins.oper.type == OP_STR ? \"variable\" : \"constant\",\n\t\t\t\t\t ins.oper.val.c_str() );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tvm.stack->push_back( val );\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_POP: {\n\t\t\tif( vm.stack->size() == 0 ) {\n\t\t\t\tVM_FAIL( \"cannot pop from vm stack since it is already empty\" );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tvm.stack->pop_back();\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_STORE: // fallthrough\n\t\tcase IC_STORE_LOAD:\n\t\tcase IC_STORE_NO_COPY:\n\t\tcase IC_STORE_LOAD_NO_COPY: {\n\t\t\tstd::string var;\n\t\t\tVERIFY_STACK_MIN( 2 );\n\t\t\tvar = vm.stack->back()->to_str();\n\t\t\tvm.stack->pop_back();\n\t\t\tvar_base_t * newval = vm.stack->back();\n\t\t\tif( vm.vars->exists( var ) ) {\n\t\t\t\tvar_base_t * val = vm.vars->get( var );\n\t\t\t\tif( val->type() != newval->type() || ( ( val->type() == VT_STRUCT || val->type() == VT_CUSTOM ) &&\n\t\t\t\t    val->type_str() != newval->type_str() ) ) {\n\t\t\t\t\tVM_FAIL( \"variable '%s' already declared at previous location, but with different data type (original: %s, new: %s)\",\n\t\t\t\t\t\t var.c_str(), val->type_str().c_str(), newval->type_str().c_str() );\n\t\t\t\t\tVM_FAIL_FILE_TOK_CTR( val->src_idx(), val->parse_ctr(), \"original declared here\" );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\n\t\t\t\tif( !copy_data( val, newval ) ) {\n\t\t\t\t\tVM_FAIL( \"copy semantics not implemented for variable type '%s'\", val->type_str().c_str() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\n\t\t\t\tvm.stack->pop_back();\n\t\t\t\tif( ins.opcode == IC_STORE_LOAD ) {\n\t\t\t\t\tvm.stack->push_back( val );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif( ins.opcode == IC_STORE_NO_COPY || ins.opcode == IC_STORE_LOAD_NO_COPY ) {\n\t\t\t\tVAR_IREF( newval );\n\t\t\t\tvm.vars->add( var, newval );\n\t\t\t} else {\n\t\t\t\tvm.vars->add( var, newval->copy( src.id, ins.parse_ctr ) );\n\t\t\t}\n\t\t\tvm.stack->pop_back();\n\t\t\tif( ins.opcode == IC_STORE_LOAD || ins.opcode == IC_STORE_LOAD_NO_COPY ) {\n\t\t\t\tvm.stack->push_back( vm.vars->get( var ) );\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_STORE_STACK: // fallthrough\n\t\tcase IC_STORE_LOAD_STACK: {\n\t\t\tvar_base_t * var;\n\t\t\tVERIFY_STACK_MIN( 1 );\n\t\t\tif( vm.stack->back()->ref() == 1 ) {\n\t\t\t\tVM_FAIL( \"storing a value requires the LHS to be an lvalue\" );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tvar = vm.stack->back();\n\t\t\tvm.stack->pop_back();\n\t\t\tvar_base_t * newval = vm.stack->back();\n\t\t\tif( var->type() != newval->type() || ( ( var->type() == VT_STRUCT || var->type() == VT_CUSTOM ) &&\n\t\t\t    var->type_str() != newval->type_str() ) ) {\n\t\t\t\tVM_FAIL( \"assignment of an existing value expects same type, found lhs: %s and rhs: %s\",\n\t\t\t\t\t var->type_str().c_str(), newval->type_str().c_str() );\n\t\t\t\tgoto fail;\n\t\t\t}\n\n\t\t\tif( !copy_data( var, newval ) ) {\n\t\t\t\tVM_FAIL( \"copy semantics not implemented for variable type '%s'\", var->type_str().c_str() );\n\t\t\t\tgoto fail;\n\t\t\t}\n\n\t\t\tvm.stack->pop_back();\n\t\t\tif( ins.opcode == IC_STORE_LOAD_STACK ) {\n\t\t\t\tvm.stack->push_back( var );\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_ADD_SCOPE: {\n\t\t\tint count = std::stoi( ins.oper.val );\n\t\t\tvm.vars->add_scope( count );\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_REM_SCOPE: {\n\t\t\tint count = std::stoi( ins.oper.val );\n\t\t\tstd::vector< void * > locs;\n\t\t\tvm.vars->pop_scope( & locs, count );\n\t\t\tfor( auto & loc : locs ) VAR_DREF( loc );\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_JUMP_TRUE: // fallthrough\n\t\tcase IC_JUMP_FALSE: // fallthrough\n\t\tcase IC_JUMP_TRUE_NO_POP: // fallthrough\n\t\tcase IC_JUMP_FALSE_NO_POP: // fallthrough\n\t\tcase IC_JUMP: {\n\t\t\tbool res = true;\n\t\t\tconst int idx = std::stoi( ins.oper.val );\n\t\t\tif( idx < begin || idx > end ) {\n\t\t\t\tVM_FAIL( \"bytecode location %d exceeds the beginning and end points: [%d,%d)\",\n\t\t\t\t\t idx, begin, end );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif( ins.opcode != IC_JUMP ) {\n\t\t\t\tVERIFY_STACK_MIN( 1 );\n\t\t\t\tres = vm.stack->back()->to_bool();\n\t\t\t\tif( ins.opcode != IC_JUMP_TRUE_NO_POP && ins.opcode != IC_JUMP_FALSE_NO_POP ) vm.stack->pop_back();\n\t\t\t\tif( ( res  && ( ins.opcode == IC_JUMP_TRUE || ins.opcode == IC_JUMP_TRUE_NO_POP ) ) ||\n\t\t\t\t    ( !res && ( ins.opcode == IC_JUMP_FALSE || ins.opcode == IC_JUMP_FALSE_NO_POP ) ) ) res = true;\n\t\t\t\telse res = false;\n\t\t\t}\n\t\t\tif( res ) i = idx - 1;\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_LDMOD: {\n\t\t\tstd::string file = ins.oper.val + LIB_EXT;\n\t\t\tstd::string init_fn_str = ins.oper.val.substr( ins.oper.val.find_last_of( '/' ) + 4 );\n\t\t\tif( !mod_exists( file, vm.lib_dirs ) ) {\n\t\t\t\tVM_FAIL( \"could not find module '%s' for loading\", ins.oper.val.c_str() );\n\t\t\t\tfprintf( stderr, \"checked the following paths:\\n\" );\n\t\t\t\tfor( auto & loc : AS_VEC( vm.lib_dirs )->get() ) {\n\t\t\t\t\tfprintf( stderr, \"-> %s\\n\", ( loc->to_str() + \"/\" + file ).c_str() );\n\t\t\t\t}\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif( vm.dlib->fexists( file ) ) break;\n\t\t\tif( vm.dlib->load( file ) == nullptr ) goto fail;\n\t\t\tinit_fnptr_t init_fn = ( init_fnptr_t ) vm.dlib->get( file, \"init_\" + init_fn_str );\n\t\t\tif( init_fn == nullptr ) {\n\t\t\t\tVM_FAIL( \"failed to find init function '%s' in module '%s'\", init_fn_str.c_str(), file.c_str() );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tinit_fn( vm );\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_IMPORT: {\n\t\t\tstd::string name = ins.oper.val;\n\t\t\tstd::string file = name + \".et\";\n\n\t\t\tif( !mod_exists( file, vm.inc_dirs ) ) {\n\t\t\t\tVM_FAIL( \"could not find file '%s' for importing\", name.c_str() );\n\t\t\t\tfprintf( stderr, \"checked the following paths:\\n\" );\n\t\t\t\tfor( auto & loc : AS_VEC( vm.inc_dirs )->get() ) {\n\t\t\t\t\tfprintf( stderr, \"-> %s\\n\", ( loc->to_str() + \"/\" + file ).c_str() );\n\t\t\t\t}\n\t\t\t\tgoto fail;\n\t\t\t}\n\n\t\t\tint ret = load_src( vm, file );\n\t\t\tif( ret != E_OK ) {\n\t\t\t\tVM_FAIL( \"could not import '%s', see the error above; aborting\",\n\t\t\t\t\t file.c_str() );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_FN_CALL: // fallthrough\n\t\tcase IC_MFN_CALL: {\n\t\t\tint res = CallFunc( vm, func_call_data, i );\n\t\t\tif( vm.exit_status == E_ASSERT_LVL1 ) {\n\t\t\t\tVM_FAIL( vm.fail_msg.c_str() );\n\t\t\t\tvm.fail_msg.clear();\n\t\t\t\tvm.exit_status = 1;\n\t\t\t}\n\t\t\tif( vm.exit_status == E_ASSERT_LVL2 ) {\n\t\t\t\tvm.exit_status = E_ASSERT_LVL1;\n\t\t\t}\n\t\t\tif( res != E_OK ) goto fail;\n\t\t\tif( vm.exit_called ) return E_OK;\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_ATTR: {\n\t\t\tVERIFY_STACK_MIN( 2 );\n\t\t\tstd::string attr = vm.stack->back()->to_str();\n\t\t\tvm.stack->pop_back();\n\t\t\tvar_base_t * base = vm.stack->back();\n\t\t\tvm.stack->pop_back();\n\t\t\tif( base->type() != VT_ENUM && base->type() != VT_STRUCT && base->type() != VT_TUPLE ) {\n\t\t\t\tVM_FAIL( \"expected one of 'enum', 'struct', or 'tuple' but found: %s\", base->type_str().c_str() );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif( base->type() == VT_ENUM ) {\n\t\t\t\tstd::unordered_map< std::string, var_int_t * > & val = AS_ENUM( base )->get_val();\n\t\t\t\tif( val.find( attr ) == val.end() ) {\n\t\t\t\t\tVM_FAIL( \"the enum '%s' does not contain attribute '%s'\",\n\t\t\t\t\t\t AS_ENUM( base )->get_name().c_str(), attr.c_str() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tvm.stack->push_back( val[ attr ] );\n\t\t\t} else if( base->type() == VT_STRUCT ) {\n\t\t\t\tstd::unordered_map< std::string, var_base_t * > & val = AS_STRUCT( base )->get_val();\n\t\t\t\tif( val.find( attr ) == val.end() ) {\n\t\t\t\t\tVM_FAIL( \"the struct '%s' does not contain attribute '%s'\",\n\t\t\t\t\t\t AS_STRUCT( base )->get_name().c_str(), attr.c_str() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tvm.stack->push_back( val[ attr ] );\n\t\t\t} else if( base->type() == VT_TUPLE ) {\n\t\t\t\tstd::vector< var_base_t * > & val = AS_TUPLE( base )->get();\n\t\t\t\tchar * p = 0;\n\t\t\t\tstrtol( attr.c_str(), & p, 10 );\n\t\t\t\tif( * p != 0 ) {\n\t\t\t\t\tVM_FAIL( \"attribute for tuple must be a positive integer, found: %s\", attr.c_str() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tint idx = std::stoi( attr );\n\t\t\t\tif( idx < 0 || ( size_t )idx >= val.size() ) {\n\t\t\t\t\tVM_FAIL( \"the tuple does not contain '%d' index, possible indices are: [0, %zu)\",\n\t\t\t\t\t\t idx, val.size() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tvm.stack->push_back( val[ idx ] );\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_BUILD_ENUM: // fallthrough\n\t\tcase IC_BUILD_ENUM_MASK: {\n\t\t\tstd::string name = vm.stack->back()->to_str();\n\t\t\tvm.stack->pop_back();\n\t\t\tif( vm.vars->exists( name ) ) {\n\t\t\t\tvar_base_t * val = vm.vars->get( name );\n\t\t\t\tVM_FAIL( \"variable '%s' already declared at another location\" );\n\t\t\t\tVM_FAIL_FILE_TOK_CTR( val->src_idx(), val->parse_ctr(), \"original declared here\" );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tint count = std::stoi( ins.oper.val );\n\t\t\tVERIFY_STACK_MIN( ( size_t )count );\n\t\t\tstd::unordered_map< std::string, var_int_t * > map;\n\t\t\tif( ins.opcode == IC_BUILD_ENUM_MASK ) {\n\t\t\t\tmpz_class mask = 1;\n\t\t\t\twhile( count-- > 0 ) {\n\t\t\t\t\tmap[ vm.stack->back()->to_str() ] = new var_int_t( mask, vm.stack->back()->parse_ctr() );\n\t\t\t\t\tvm.stack->pop_back();\n\t\t\t\t\tmask <<= 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor( int j = 0; j < count; ++j ) {\n\t\t\t\t\tmap[ vm.stack->back()->to_str() ] = new var_int_t( j, vm.stack->back()->parse_ctr() );\n\t\t\t\t\tvm.stack->pop_back();\n\t\t\t\t}\n\t\t\t}\n\t\t\tvm.vars->add( name, new var_enum_t( name, map, ins.parse_ctr ) );\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_BUILD_VEC: {\n\t\t\tint count = std::stoi( ins.oper.val );\n\t\t\tVERIFY_STACK_MIN( ( size_t )count );\n\t\t\tstd::vector< var_base_t * > vec;\n\t\t\twhile( count-- > 0 ) {\n\t\t\t\tvec.push_back( vm.stack->back()->copy( src.id, ins.parse_ctr ) );\n\t\t\t\tvm.stack->pop_back();\n\t\t\t}\n\t\t\tvm.stack->push_back( new var_vec_t( vec, ins.parse_ctr ), false );\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_BUILD_MAP: {\n\t\t\tint count = std::stoi( ins.oper.val );\n\t\t\tVERIFY_STACK_MIN( ( size_t )count * 2 );\n\t\t\tstd::unordered_map< std::string, var_base_t * > map;\n\t\t\twhile( count-- > 0 ) {\n\t\t\t\tstd::string key = vm.stack->back()->to_str();\n\t\t\t\tvm.stack->pop_back();\n\t\t\t\tmap[ key ] = vm.stack->back()->copy( src.id, ins.parse_ctr );\n\t\t\t\tvm.stack->pop_back();\n\t\t\t}\n\t\t\tvm.stack->push_back( new var_map_t( map, ins.parse_ctr ), false );\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_BUILD_STRUCT: {\n\t\t\tint count = std::stoi( ins.oper.val );\n\t\t\tVERIFY_STACK_MIN( ( size_t )count * 2 + 1 );\n\t\t\tstd::string name = vm.stack->back()->to_str();\n\t\t\tif( vm.structs.find( name ) != vm.structs.end() ) {\n\t\t\t\tVM_FAIL( \"struct by name '%s' is already defined\", name.c_str() );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tvm.stack->pop_back();\n\t\t\tstd::unordered_map< std::string, var_base_t * > map;\n\t\t\tstd::vector< std::string > pos;\n\t\t\twhile( count-- > 0 ) {\n\t\t\t\tstd::string fname = vm.stack->back()->to_str();\n\t\t\t\tif( map.find( fname ) != map.end() ) {\n\t\t\t\t\tVM_FAIL_FILE_TOK_CTR( vm.stack->back()->src_idx(),\n\t\t\t\t\t\t\t      vm.stack->back()->parse_ctr(),\n\t\t\t\t\t\t\t      \"field name '%s' has already been used before\",\n\t\t\t\t\t\t\t      fname.c_str() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tvm.stack->pop_back();\n\t\t\t\tvar_base_t * fval = vm.stack->back()->copy( src.id, ins.parse_ctr );\n\t\t\t\tvm.stack->pop_back();\n\t\t\t\tmap[ fname ] = fval;\n\t\t\t\tpos.insert( pos.begin(), fname );\n\t\t\t}\n\t\t\tvm.structs[ name ] = new var_struct_def_t( name, pos, map, ins.parse_ctr );\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_STRUCT_DECL: {\n\t\t\tint count = std::stoi( ins.oper.val );\n\t\t\tstd::string name = vm.stack->back()->to_str();\n\t\t\tvm.stack->pop_back();\n\t\t\tif( vm.structs.find( name ) == vm.structs.end() ) {\n\t\t\t\tVM_FAIL( \"struct by name '%s' does not exist\", name.c_str() );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tvar_struct_def_t * stdef = vm.structs[ name ];\n\t\t\tif( count < 0 || ( size_t )count > stdef->get_pos().size() ) {\n\t\t\t\tVM_FAIL( \"struct '%s' expects at most %zu arguments (provided %d args)\",\n\t\t\t\t\t name.c_str(), stdef->get_pos().size(), count );\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tvar_struct_t * st = ( var_struct_t * )vm.structs[ name ]->copy( src.id, ins.parse_ctr );\n\t\t\tstd::unordered_map< std::string, var_base_t * > & map = st->get_val();\n\t\t\tconst std::vector< std::string > & pos = stdef->get_pos();\n\t\t\tfor( int j = 0; j < count; ++j ) {\n\t\t\t\tif( map[ pos[ j ] ]->type() != vm.stack->back()->type() ) {\n\t\t\t\t\tVM_FAIL_FILE_TOK_CTR( vm.stack->back()->src_idx(),\n\t\t\t\t\t\t\t      vm.stack->back()->parse_ctr(),\n\t\t\t\t\t\t\t      \"argument type mismatch: expected '%s', found '%s'\",\n\t\t\t\t\t\t\t      map[ pos[ j ] ]->type_str().c_str(),\n\t\t\t\t\t\t\t      vm.stack->back()->type_str().c_str() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tif( !copy_data( map[ pos[ j ] ], vm.stack->back() ) ) {\n\t\t\t\t\tVM_FAIL( \"copy semantics not implemented for variable type '%s'\", map[ pos[ j ] ]->type_str().c_str() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tvm.stack->pop_back();\n\t\t\t}\n\t\t\tvm.stack->push_back( st, false );\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_BLOCK_TILL: {\n\t\t\tint from = i + 1;\n\t\t\tint to = std::stoi( ins.oper.val );\n\t\t\tfn_blks.push_back( { from, to } );\n\t\t\ti = to - 1;\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_ARGS_TILL: {\n\t\t\tint till = std::stoi( ins.oper.val );\n\t\t\tstd::vector< std::string > args;\n\t\t\tfor( int j = till; j > i; --j ) {\n\t\t\t\targs.push_back( src.bcode[ j ].oper.val );\n\t\t\t}\n\t\t\tfn_args.push_back( args );\n\t\t\tif( till != -1 ) i = till;\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_BUILD_FN: // fallthrough\n\t\tcase IC_BUILD_MFN: {\n\t\t\tfn_blk_t blk = fn_blks.back();\n\t\t\tfn_blks.pop_back();\n\t\t\tstd::vector< std::string > args = fn_args.back();\n\t\t\tfn_args.pop_back();\n\t\t\tstd::vector< std::string > member_ofs;\n\t\t\tif( ins.opcode == IC_BUILD_MFN ) {\n\t\t\t\tVERIFY_STACK_MIN( 2 );\n\t\t\t\tint count = vm.stack->back()->to_int().get_si();\n\t\t\t\tvm.stack->pop_back();\n\t\t\t\twhile( count-- > 0 ) {\n\t\t\t\t\tmember_ofs.push_back( vm.stack->back()->to_str() );\n\t\t\t\t\tvm.stack->pop_back();\n\t\t\t\t}\n\t\t\t}\n\t\t\tstd::string name = ins.oper.val;\n\t\t\tint args_min = args.size();\n\t\t\tint args_max = args.size();\n\t\t\tif( args.size() > 0 && args.back() == \"...\" ) {\n\t\t\t\t--args_min;\n\t\t\t\targs_max = -1;\n\t\t\t\targs.pop_back();\n\t\t\t}\n\t\t\tfor( auto & member_of : member_ofs ) {\n\t\t\t\tconst function_t * fn = vm.typefuncs[ member_of ].get( name, args_min, {} );\n\t\t\t\tif( fn != nullptr ) {\n\t\t\t\t\tVM_FAIL( \"function '%s::%s' already exists\", member_of.c_str(), name.c_str() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tvm.typefuncs[ member_of ].add( function_t{ name, args_min, args_max, args, FnType::LANG,\n\t\t\t\t\t\t\t\t           { .langfn = { src.id, blk.beg, blk.end } },\n\t\t\t\t\t\t\t\t\t   false } );\n\t\t\t}\n\t\t\tif( member_ofs.size() == 0 ) {\n\t\t\t\tconst function_t * fn = vm.funcs.get( name, args_min, {} );\n\t\t\t\tif( fn != nullptr ) {\n\t\t\t\t\tVM_FAIL( \"function '%s' already exists\", name.c_str() );\n\t\t\t\t\tgoto fail;\n\t\t\t\t}\n\t\t\t\tvm.funcs.add( function_t{ name, args_min, args_max, args, FnType::LANG,\n\t\t\t\t\t                  { .langfn = { src.id, blk.beg, blk.end } },\n\t\t\t\t\t\t\t  false } );\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase IC_RETURN: // fallthrough\n\t\tcase IC_RETURN_EMPTY: {\n\t\t\tif( ins.oper.val != \"0\" ) {\n\t\t\t\tstd::vector< void * > locs;\n\t\t\t\tvm.vars->pop_scope( & locs, std::stoi( ins.oper.val ) );\n\t\t\t\tfor( auto & loc : locs ) VAR_DREF( loc );\n\t\t\t}\n\t\t\tif( ins.opcode == IC_RETURN_EMPTY ) {\n\t\t\t\tvm.stack->push_back( vm.none );\n\t\t\t}\n\t\t\treturn E_OK;\n\t\t}\n\t\tcase _IC_LAST: {}\n\t\t}\n\t}\n\n\treturn E_OK;\nfail:\n\treturn E_VM_FAIL;\n}\n\nbool copy_data( var_base_t * a, var_base_t * b )\n{\n\tif( a->impls_assn() ) {\n\t\ta->assn( b );\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n"
  },
  {
    "path": "src/VM/ExecInternal.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_EXEC_INTERNAL_HPP\n#define VM_EXEC_INTERNAL_HPP\n\n#include \"VM.hpp\"\n\n// TODO: Perhaps use `union` type for operand value of `instr_code_t` to avoid using conversions like `std::stoi` in ExecInternal\nint exec_internal( vm_state_t & vm, long begin = -1, long end = -1, var_base_t * ret = nullptr );\n\n#endif // VM_EXEC_INTERNAL_HPP"
  },
  {
    "path": "src/VM/Functions.cpp",
    "content": "/*\n  Copyright (c) 2019, Electrux\n  All rights reserved.\n  Using the GNU GPL 3.0 license for the project,\n  main LICENSE file resides in project's root directory.\n  Please read that file and understand the license terms\n  before using or altering the project.\n*/\n\n#include <algorithm>\n\n#include \"Vars/Base.hpp\"\n#include \"Functions.hpp\"\n\nstatic bool compare_arg_types( const std::vector< std::string > & ats1, const std::vector< std::string > & ats2, const int min_args );\n\nbool operator ==( const function_t & func1, const function_t & func2 )\n{\n\treturn func1.name == func2.name && func1.arg_count_min == func2.arg_count_min &&\n\t       func1.arg_count_max <= func2.arg_count_max && compare_arg_types( func1.arg_types, func2.arg_types, func1.arg_count_min );\n}\n\n////////////////////////////////// PRIVATE MEMBER FUNCTIONS ///////////////////////////////////\n\n////////////////////////////////// PUBLIC MEMBER FUNCTIONS ////////////////////////////////////\n\nfunctions_t::functions_t() {}\n\nfunctions_t::~functions_t()\n{}\n\nbool functions_t::add( const function_t & func )\n{\n\tif( exists( func ) ) {\n\t\t//fprintf( stderr, \"Function: %s already exists\\n\", func.name.c_str() );\n\t\treturn false;\n\t}\n\tm_funcs.push_back( func );\n\treturn true;\n}\n\nbool functions_t::add_vec( const std::vector< function_t > & funcs )\n{\n\tfor( auto & func : funcs ) {\n\t\tif( exists( func ) ) {\n\t\t\t//fprintf( stderr, \"Function: %s already exists\\n\", func.name.c_str() );\n\t\t\treturn false;\n\t\t}\n\t\tm_funcs.push_back( func );\n\t}\n\treturn true;\n}\n\nbool functions_t::del( const function_t & func )\n{\n\tauto loc = std::find( m_funcs.begin(), m_funcs.end(), func );\n\tif( loc != m_funcs.end() ) {\n\t\tm_funcs.erase( loc );\n\t\treturn true;\n\t}\n\tfprintf( stderr, \"Function: %s does not exist\\n\", func.name.c_str() );\n\treturn false;\n}\n\nbool functions_t::del_vec( const std::vector< function_t > & funcs )\n{\n\tfor( auto & func : funcs ) {\n\t\tif( !del( func ) ) return false;\n\t}\n\treturn true;\n}\n\nbool functions_t::exists_name( const std::string & name )\n{\n\tfor( auto & fn : m_funcs ) {\n\t\tif( fn.name == name ) return true;\n\t}\n\treturn false;\n}\n\nconst function_t * functions_t::get( const std::string & name, const int arg_count,\n\t\t\t\t     const std::vector< std::string > & arg_types )\n{\n\tstd::string mangled_name = name;\n\tfor( auto & arg_type : arg_types ) {\n\t\tmangled_name += \"_\" + arg_type;\n\t}\n\tconst function_t * fnptr = get_cached_func( mangled_name );\n\tif( fnptr != nullptr ) return fnptr;\n\n\tsize_t sz = m_funcs.size();\n\tfor( size_t i = 0; i < sz; ++i ) {\n\t\tfunction_t & func = m_funcs[ i ];\n\t\tif( func.name == name &&\n\t\t    arg_count >= func.arg_count_min &&\n\t\t    ( arg_count <= func.arg_count_max || func.arg_count_max == -1 ) &&\n\t\t    ( func.type == LANG || compare_arg_types( func.arg_types, arg_types, func.arg_count_min ) ) ) {\n\t\t\treturn set_cached_func( mangled_name, i );\n\t\t}\n\t}\n\treturn nullptr;\n}\n\nconst std::vector< function_t * > functions_t::get_all_by_name( const std::string & name )\n{\n\tstd::vector< function_t * > res;\n\tfor( auto & fn : m_funcs ) {\n\t\tif( fn.name == name ) res.push_back( & fn );\n\t}\n\treturn res;\n}\n\nstatic bool compare_arg_types( const std::vector< std::string > & ats1, const std::vector< std::string > & ats2, const int min_args )\n{\n\tif( ats2.empty() ) return true;\n\tauto it = ats2.begin();\n\tfor( auto & at1 : ats1 ) {\n\t\tif( at1 == \"_whatever_\" ) return true;\n\t\t// only last argument can be optional (_any_) (more than one argument will be done by _whatever_)\n\t\tif( it == ats2.end() ) return at1 == \"_any_\" || ats2.size() >= ( size_t )min_args;\n\t\tif( at1 != \"_any_\" && at1 != * it ) return false;\n\t\t++it;\n\t}\n\treturn true;\n}"
  },
  {
    "path": "src/VM/Functions.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_FUNCTIONS_HPP\n#define VM_FUNCTIONS_HPP\n\n#include <vector>\n#include <string>\n#include <algorithm>\n#include <unordered_map>\n\nclass var_base_t;\nstruct vm_state_t;\nstruct func_call_data_t;\n\ntypedef var_base_t * ( * modfnptr_t )( vm_state_t & vm, func_call_data_t & fcd );\nstruct langfn_t\n{\n\tint src;\n\tint beg, end;\n};\n\nenum FnType\n{\n\tMODULE,\n\tLANG,\n};\n\nunion Func\n{\n\tmodfnptr_t modfn;\n\tlangfn_t langfn;\n};\n\nstruct function_t\n{\n\tstd::string name;\n\tint arg_count_min;\n\tint arg_count_max;\n\tstd::vector< std::string > arg_types;\n\tFnType type;\n\tFunc func;\n\tbool manual_res_free;\n};\n\n#define REGISTER_MODULE( name )\t\t\t\t\\\n\textern \"C\" void init_##name( vm_state_t & vm )\n\ntypedef void ( * init_fnptr_t )( vm_state_t & vm );\n\nbool operator ==( const function_t & func1, const function_t & func2 );\n\nclass functions_t\n{\n\tstd::vector< function_t > m_funcs;\n\t// uses mangled names and used for getting functions quickly\n\t// mangled style:\n\t// fnname_argtypes\n\tstd::unordered_map< std::string, int > m_cached_funcs;\n\n\tinline bool exists( const function_t & func )\n\t{\n\t\treturn std::find( m_funcs.begin(), m_funcs.end(), func ) != m_funcs.end();\n\t}\n\n\tinline const function_t * get_cached_func( const std::string & mangled_name )\n\t{\n\t\treturn m_cached_funcs.find( mangled_name ) != m_cached_funcs.end() ? & m_funcs[ m_cached_funcs[ mangled_name ] ] : nullptr;\n\t}\n\n\tinline const function_t * set_cached_func( const std::string & mangled_name, const int fid )\n\t{\n\t\tm_cached_funcs[ mangled_name ] = fid;\n\t\treturn & m_funcs[ fid ];\n\t}\n\npublic:\n\tfunctions_t();\n\t~functions_t();\n\tbool add( const function_t & func );\n\tbool add_vec( const std::vector< function_t > & funcs );\n\n\tbool del( const function_t & func );\n\tbool del_vec( const std::vector< function_t > & funcs );\n\n\tbool exists_name( const std::string & name );\n\n\tconst function_t * get( const std::string & name, const int arg_count,\n\t\t\t\tconst std::vector< std::string > & arg_types );\n\tconst std::vector< function_t * > get_all_by_name( const std::string & name );\n\n\tinline size_t count() const { return m_funcs.size(); }\n};\n\n#endif // VM_FUNCTIONS_HPP"
  },
  {
    "path": "src/VM/Instructions.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Instructions.hpp\"\n\nconst char * InstrCodeStrs[ _IC_LAST ] = {\n\t\"PUSH\",\n\t\"POP\",\n\t\"STORE\",\n\t\"STORE_LOAD\",\n\t\"STORE_NO_COPY\",\n\t\"STORE_LOAD_NO_COPY\",\n\t\"STORE_STACK\",\n\t\"STORE_LOAD_STACK\",\n\n\t\"JUMP\",\n\t\"JUMP_TRUE\",\n\t\"JUMP_FALSE\",\n\t\"JUMP_TRUE_NO_POP\",\n\t\"JUMP_FALSE_NO_POP\",\n\n\t\"BUILD_ENUM\",\n\t\"BUILD_ENUM_MASK\",\n\t\"BUILD_VEC\",\n\t\"BUILD_MAP\",\n\t\"BUILD_STRUCT\",\n\t\"BUILD_FUNC\",\n\t\"BUILD_MEM_FUNC\",\n\n\t\"ADD_SCOPE\",\n\t\"REM_SCOPE\",\n\n\t\"LOAD_MOD\",\n\t\"IMPORT\",\n\n\t\"CALL_FUNC\",\n\t\"CALL_MEM_FUNC\",\n\t\"STRUCT_DECL\",\n\t\"OBJ_ATTR\",\n\n\t\"BLOCK_TILL\",\n\t\"ARGS_TILL\",\n\n\t\"RETURN\",\n\t\"RETURN_EMPTY\",\n};\n\nconst char * OperTypeStrs[ _OP_LAST ] = {\n\t\"const\",\n\t\"string\",\n\t\"int\",\n\t\"float\",\n\n\t\"none\",\n};"
  },
  {
    "path": "src/VM/Instructions.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_INSTRUCTIONS_HPP\n#define VM_INSTRUCTIONS_HPP\n\n#include <vector>\n#include <string>\n\nenum InstrCode\n{\n\tIC_PUSH,\t\t// Push on the VM stack\n\tIC_POP,\t\t\t// Pop from the VM stack\n\tIC_STORE,\t\t// args: none, optionally - count of elements to store\n\tIC_STORE_LOAD,\t\t// same as IC_STORE + push the result back on stack\n\tIC_STORE_NO_COPY,\t// args: none\n\tIC_STORE_LOAD_NO_COPY,\t// args: none\n\tIC_STORE_STACK,\t\t// args: none, optionally - count of elements to store\n\tIC_STORE_LOAD_STACK,\t// same as IC_STORE_STACK + push the result back on stack\n\n\tIC_JUMP,\t\t// args: bcode index (int) on which to jump to\n\tIC_JUMP_TRUE,\t\t// args: bcode index (int) on which to jump to\n\tIC_JUMP_FALSE,\t\t// args: bcode index (int) on which to jump to\n\tIC_JUMP_TRUE_NO_POP,\t// args: bcode index (int) on which to jump to\n\tIC_JUMP_FALSE_NO_POP,\t// args: bcode index (int) on which to jump to\n\n\tIC_BUILD_ENUM,\t\t// args: count of elements to take from stack\n\tIC_BUILD_ENUM_MASK,\t// args: same as IC_BUILD_ENUM\n\tIC_BUILD_VEC,\t\t// args: count of elements to take from stack\n\tIC_BUILD_MAP,\t\t// args: count of elements to take from stack\n\tIC_BUILD_STRUCT,\t// args: count of fields\n\tIC_BUILD_FN,\t\t// args: func name\n\tIC_BUILD_MFN,\t\t// args: func name\n\n\tIC_ADD_SCOPE,\t\t// args: count of scopes to add\n\tIC_REM_SCOPE,\t\t// args: count of scopes to remove\n\n\tIC_LDMOD,\t\t// args: count: 1 = what, 2 = what + as\n\tIC_IMPORT,\t\t// args: count: 1 = what\n\n\tIC_FN_CALL,\t\t// args: count of args (will take name by default)\n\tIC_MFN_CALL,\t\t// args: same as IC_FN_CALL\n\n\tIC_STRUCT_DECL,\t\t// args: same as IC_FN_CALL\n\tIC_ATTR,\t\t// args: same as IC_FN_CALL\n\n\tIC_BLOCK_TILL,\t\t// args: index of bcode uptil where block lasts\n\tIC_ARGS_TILL,\n\n\tIC_RETURN,\t\t// args: count of scopes to remove\n\tIC_RETURN_EMPTY,\t// args: count of scopes to remove\n\n\t_IC_LAST,\n};\n\nextern const char * InstrCodeStrs[ _IC_LAST ];\n\nenum OperTypes\n{\n\tOP_CONST,\n\tOP_STR,\n\tOP_INT,\n\tOP_FLT,\n\n\tOP_NONE,\n\n\t_OP_LAST,\n};\n\nextern const char * OperTypeStrs[ _OP_LAST ];\n\nstruct oper_t\n{\n\tOperTypes type;\n\tstd::string val;\n};\n\nstruct instr_t\n{\n\tint parse_ctr;\n\tint line, col;\n\tInstrCode opcode;\n\toper_t oper;\n};\n\ntypedef std::vector< instr_t > bytecode_t;\n\n#endif // VM_INSTRUCTIONS_HPP"
  },
  {
    "path": "src/VM/LoadFile.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"../FE/CmdArgs.hpp\"\n#include \"../FE/Env.hpp\"\n\n#include \"LoadFile.hpp\"\n\nstatic bool src_exists( const srcs_t & srcs, const std::string & file );\n\nint load_src( vm_state_t & vm, const std::string & file )\n{\n\tsrc_t & src = * vm.srcstack.back();\n\tauto last_slash_loc = file.find_last_of( '/' );\n\tauto last_dot_loc = file.find_last_of( '.' );\n\n\tconst std::string new_src_file = file.substr( last_slash_loc + 1 );\n\n\tif( src_exists( vm.srcs, new_src_file ) ) {\n\t\treturn E_OK;\n\t}\n\n\tstd::string src_dir = file.substr( 0, last_slash_loc );\n\tDirFormat( src_dir );\n\tint err = E_OK;\n\n\tparse_tree_t * ptree = nullptr;\n\tsrc_t * new_src = new src_t( false );\n\tnew_src->id = vm.srclist.size();\n\tnew_src->file = new_src_file;\n\tnew_src->dir = src_dir;\n\terr = tokenize( * new_src );\n\tif( err != E_OK ) goto cleanup;\n\n\tif( vm.flags & OPT_T ) {\n\t\tfprintf( stdout, \"Tokens:\\n\" );\n\t\tauto & toks = new_src->toks;\n\t\tfor( size_t i = 0; i < toks.size(); ++i ) {\n\t\t\tauto & tok = toks[ i ];\n\t\t\tfprintf( stdout, \"ID: %zu\\tType: %s\\tLine: %d[%d]\\tSymbol: %s\\n\",\n\t\t\t\t i, TokStrs[ tok.type ], tok.line, tok.col, tok.data.c_str() );\n\t\t}\n\t}\n\n\terr = E_OK;\n\tptree = parse( * new_src );\n\n\tif( ptree == nullptr ) { err = E_PARSE_FAIL; goto cleanup; }\n\tnew_src->ptree = ptree;\n\n\tif( vm.flags & OPT_P ) {\n\t\tfprintf( stdout, \"Parse Tree:\\n\" );\n\t\tfor( auto it = ptree->begin(); it != ptree->end(); ++it ) {\n\t\t\t( * it )->disp( it != ptree->end() - 1 );\n\t\t}\n\t}\n\n\terr = E_OK;\n\tfor( auto & it : * ptree ) {\n\t\tif( !it->bytecode( * new_src ) ) { err = E_BYTECODE_FAIL; goto cleanup; }\n\t}\n\n\tif( vm.flags & OPT_B ) {\n\t\tfprintf( stdout, \"Byte Code:\\n\" );\n\t\tfor( size_t i = 0; i < new_src->bcode.size(); ++i ) {\n\t\t\tauto & ins = new_src->bcode[ i ];\n\t\t\tfprintf( stdout, \"%-*zu %-*s%-*s[%s]\\n\",\n\t\t\t\t 5, i, 20, InstrCodeStrs[ ins.opcode ], 7, OperTypeStrs[ ins.oper.type ], ins.oper.val.c_str() );\n\t\t}\n\t}\n\n\tif( err != E_OK ) goto cleanup;\n\n\t// actual code execution\n\tif( !( vm.flags & OPT_C ) && !( vm.flags & OPT_D ) ) {\n\t\tvm.srcstack.push_back( new_src );\n\t\tvm.srclist.push_back( new_src_file );\n\t\tvm.srcs[ new_src->id ] = new_src;\n\t\tvm.vars->add_zero( vm.vars->layer_size() );\n\t\terr = vm_exec( vm );\n\t\tvm.vars->pop_zero();\n\t\tvm.srcstack.pop_back();\n\t\tif( err != E_OK ) vm.srcs.erase( new_src->id );\n\t}\n\ncleanup:\n\tif( err != E_OK ) delete new_src;\n\treturn err;\n}\n\nstatic bool src_exists( const srcs_t & srcs, const std::string & file )\n{\n\tfor( auto & item : srcs ) {\n\t\tif( item.second->file == file && !item.second->is_main_src ) return true;\n\t}\n\treturn false;\n}"
  },
  {
    "path": "src/VM/LoadFile.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef LOAD_FILE_HPP\n#define LOAD_FILE_HPP\n\n#include \"VM.hpp\"\n\nint load_src( vm_state_t & vm, const std::string & file );\n\n#endif // LOAD_FILE_HPP"
  },
  {
    "path": "src/VM/Main.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef AS_LIB\n\n// PLACEHOLDER\n\n#endif // AS_LIB"
  },
  {
    "path": "src/VM/MemPool.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"MemPool.hpp\"\n\nstatic inline size_t nearest_mult8( size_t sz )\n{\n\tif( sz > 512 ) return sz;\n\telse if( sz >=   1 && sz <=   8 ) return   8;\n\telse if( sz >=   9 && sz <=  16 ) return  16;\n\telse if( sz >=  17 && sz <=  24 ) return  24;\n\telse if( sz >=  25 && sz <=  32 ) return  32;\n\telse if( sz >=  33 && sz <=  40 ) return  40;\n\telse if( sz >=  41 && sz <=  48 ) return  48;\n\telse if( sz >=  49 && sz <=  56 ) return  56;\n\telse if( sz >=  57 && sz <=  64 ) return  64;\n\telse if( sz >=  65 && sz <=  72 ) return  72;\n\telse if( sz >=  73 && sz <=  80 ) return  80;\n\telse if( sz >=  81 && sz <=  88 ) return  88;\n\telse if( sz >=  89 && sz <=  96 ) return  96;\n\telse if( sz >=  97 && sz <= 104 ) return 104;\n\telse if( sz >= 105 && sz <= 112 ) return 112;\n\telse if( sz >= 113 && sz <= 120 ) return 120;\n\telse if( sz >= 121 && sz <= 128 ) return 128;\n\telse if( sz >= 129 && sz <= 136 ) return 136;\n\telse if( sz >= 137 && sz <= 144 ) return 144;\n\telse if( sz >= 145 && sz <= 152 ) return 152;\n\telse if( sz >= 153 && sz <= 160 ) return 160;\n\telse if( sz >= 161 && sz <= 168 ) return 168;\n\telse if( sz >= 169 && sz <= 176 ) return 176;\n\telse if( sz >= 177 && sz <= 184 ) return 184;\n\telse if( sz >= 185 && sz <= 192 ) return 192;\n\telse if( sz >= 193 && sz <= 200 ) return 200;\n\telse if( sz >= 201 && sz <= 208 ) return 208;\n\telse if( sz >= 209 && sz <= 216 ) return 216;\n\telse if( sz >= 217 && sz <= 224 ) return 224;\n\telse if( sz >= 225 && sz <= 232 ) return 232;\n\telse if( sz >= 233 && sz <= 240 ) return 240;\n\telse if( sz >= 241 && sz <= 248 ) return 248;\n\telse if( sz >= 249 && sz <= 256 ) return 256;\n\telse if( sz >= 257 && sz <= 264 ) return 264;\n\telse if( sz >= 265 && sz <= 272 ) return 272;\n\telse if( sz >= 273 && sz <= 280 ) return 280;\n\telse if( sz >= 281 && sz <= 288 ) return 288;\n\telse if( sz >= 289 && sz <= 296 ) return 296;\n\telse if( sz >= 297 && sz <= 304 ) return 304;\n\telse if( sz >= 305 && sz <= 312 ) return 312;\n\telse if( sz >= 313 && sz <= 320 ) return 320;\n\telse if( sz >= 321 && sz <= 328 ) return 328;\n\telse if( sz >= 329 && sz <= 336 ) return 336;\n\telse if( sz >= 337 && sz <= 344 ) return 344;\n\telse if( sz >= 345 && sz <= 352 ) return 352;\n\telse if( sz >= 353 && sz <= 360 ) return 360;\n\telse if( sz >= 361 && sz <= 368 ) return 368;\n\telse if( sz >= 369 && sz <= 376 ) return 376;\n\telse if( sz >= 377 && sz <= 384 ) return 384;\n\telse if( sz >= 385 && sz <= 392 ) return 392;\n\telse if( sz >= 393 && sz <= 400 ) return 400;\n\telse if( sz >= 401 && sz <= 408 ) return 408;\n\telse if( sz >= 409 && sz <= 416 ) return 416;\n\telse if( sz >= 417 && sz <= 424 ) return 424;\n\telse if( sz >= 425 && sz <= 432 ) return 432;\n\telse if( sz >= 433 && sz <= 440 ) return 440;\n\telse if( sz >= 441 && sz <= 448 ) return 448;\n\telse if( sz >= 449 && sz <= 456 ) return 456;\n\telse if( sz >= 457 && sz <= 464 ) return 464;\n\telse if( sz >= 465 && sz <= 472 ) return 472;\n\telse if( sz >= 473 && sz <= 480 ) return 480;\n\telse if( sz >= 481 && sz <= 488 ) return 488;\n\telse if( sz >= 489 && sz <= 496 ) return 496;\n\telse if( sz >= 497 && sz <= 504 ) return 504;\n\telse if( sz >= 505 && sz <= 512 ) return 512;\n\treturn sz;\n}\n\nmem_mgr_t mem::_memory;\n//static size_t tot_alloc = 0;\n//static size_t tot_alloc_direct = 0;\n//static size_t tot_alloc_req = 0;\nvoid mem_mgr_t::alloc_pool()\n{\n\tu8 * alloc = new u8[ POOL_SIZE ];\n\t//tot_alloc += POOL_SIZE;\n\tm_pools.push_back( { alloc, alloc } );\n}\n\nmem_mgr_t::mem_mgr_t() { alloc_pool(); }\nmem_mgr_t::~mem_mgr_t()\n{\n\tfor( auto & c : m_free_chunks ) {\n\t\tif( c.first > POOL_SIZE ) {\n\t\t\tfor( auto & blk : c.second ) {\n\t\t\t\tdelete[] blk;\n\t\t\t}\n\t\t}\n\t\tc.second.clear();\n\t}\n\tm_free_chunks.clear();\n\tfor( auto & p : m_pools ) {\n\t\tdelete[] p.mem;\n\t}\n\t//fprintf( stdout, \"Total allocated: %zu, directly: %zu, requests: %zu\\n\", tot_alloc, tot_alloc_direct, tot_alloc_req );\n}\n\nvoid * mem_mgr_t::alloc( size_t sz )\n{\n\tif( sz == 0 ) return nullptr;\n\t//tot_alloc_direct += sz;\n\t//++tot_alloc_req;\n\n\tsz = nearest_mult8( sz );\n\n\tif( sz > POOL_SIZE ) {\n\t\t//fprintf( stdout, \"Allocating manually ... %zu\\n\", sz );\n\t\treturn new u8[ sz ];\n\t}\n\n\tif( m_free_chunks[ sz ].size() == 0 ) {\n\t\tfor( auto & p : m_pools ) {\n\t\t\tsize_t free_space = POOL_SIZE - ( p.head - p.mem );\n\t\t\tif( free_space >= sz ) {\n\t\t\t\tu8 * loc = p.head;\n\t\t\t\tp.head += sz;\n\t\t\t\t//fprintf( stdout, \"Allocating from pool ... %zu\\n\", sz );\n\t\t\t\treturn loc;\n\t\t\t}\n\t\t}\n\t\talloc_pool();\n\t\tauto & p = m_pools.back();\n\t\tu8 * loc = p.head;\n\t\tp.head += sz;\n\t\t//fprintf( stdout, \"Allocating from NEW pool ... %zu\\n\", sz );\n\t\treturn loc;\n\t}\n\n\tu8 * loc = m_free_chunks[ sz ].front();\n\tm_free_chunks[ sz ].pop_front();\n\t//fprintf( stdout, \"Using previously allocated ... %zu\\n\", sz );\n\treturn loc;\n}\n\nvoid mem_mgr_t::free( void * ptr, size_t sz )\n{\n\tif( ptr == nullptr || sz == 0 ) return;\n\t//fprintf( stdout, \"Giving back to pool ... %zu\\n\", sz );\n\tm_free_chunks[ sz ].push_front( ( u8 * )ptr );\n}\n"
  },
  {
    "path": "src/VM/MemPool.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef MEM_POOL_HPP\n#define MEM_POOL_HPP\n\n#include <vector>\n#include <map>\n#include <list>\n\ntypedef unsigned char u8;\n\nstruct __sys_align_t\n{\n\tchar c;\n\tsize_t sz;\n};\n\nstatic constexpr size_t POOL_SIZE = 4 * 1024;\nstatic constexpr size_t ALIGNMENT = sizeof( __sys_align_t ) - sizeof( size_t );\n\nstruct mem_pool_t\n{\n\tu8 * head;\n\tu8 * mem;\n};\n\nclass mem_mgr_t\n{\n\tstd::vector< mem_pool_t > m_pools;\t\n\tstd::map< size_t, std::list< u8 * > > m_free_chunks;\n\n\tvoid alloc_pool();\npublic:\n\tmem_mgr_t();\n\t~mem_mgr_t();\n\tvoid * alloc( size_t sz );\n\tvoid free( void * ptr, size_t sz );\n};\n\nnamespace mem\n{\nextern mem_mgr_t _memory;\n\ninline void * alloc( size_t sz )\n{\n\treturn _memory.alloc( sz );\n}\n\ninline void free( void * ptr, size_t sz )\n{\n\treturn _memory.free( ptr, sz );\n}\n}\n\n#endif // MEM_POOL_HPP"
  },
  {
    "path": "src/VM/VM.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"VM.hpp\"\n#include \"ExecInternal.hpp\"\n\nint vm_exec( vm_state_t & vm )\n{\n\tint res = exec_internal( vm );\n\tif( res == E_OK ) res = vm.exit_status;\n\treturn res;\n}"
  },
  {
    "path": "src/VM/VM.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_VM_HPP\n#define VM_VM_HPP\n\n#include \"Core.hpp\"\n\nint vm_exec( vm_state_t & vm );\n\n#endif // VM_VM_HPP"
  },
  {
    "path": "src/VM/VMStack.cpp",
    "content": "\n#include \"VMStack.hpp\"\n\nvm_stack_t::vm_stack_t() {}\n\nvm_stack_t::~vm_stack_t()\n{\n\tfor( auto & val : m_vec ) {\n\t\tVAR_DREF( val );\n\t}\n}"
  },
  {
    "path": "src/VM/VMStack.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_VM_STACK_HPP\n#define VM_VM_STACK_HPP\n\n#include <vector>\n\n#include \"Vars/Base.hpp\"\n\nclass vm_stack_t\n{\n\tstd::vector< var_base_t * > m_vec;\n\tstd::vector< int > m_none_locs;\npublic:\n\tvm_stack_t();\n\t~vm_stack_t();\n\n\tinline void push_back( var_base_t * val, const bool inc_ref = true )\n\t{\n\t\tif( val->type() == VT_NONE ) m_none_locs.push_back( m_vec.size() );\n\t\tif( inc_ref ) VAR_IREF( val );\n\t\tm_vec.push_back( val );\n\t}\n\n\tinline void pop_back( const bool dec_ref = true )\n\t{\n\t\tif( m_vec.back()->type() == VT_NONE ) m_none_locs.pop_back();\n\t\tif( dec_ref ) VAR_DREF( m_vec.back() );\n\t\tm_vec.pop_back();\n\t}\n\n\tinline var_base_t * & back() { return m_vec.back(); }\n\n\tinline std::vector< var_base_t * > & get() { return m_vec; }\n\n\tinline size_t size() const { return m_vec.size(); }\n\n\tinline bool empty() const { return m_vec.empty(); }\n\n\tinline bool has_none( const int range ) { return m_none_locs.size() > 0 && ( int )m_vec.size() - range <= m_none_locs.back(); }\n};\n\n#define VERIFY_STACK_MIN( sz )\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tdo {\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( vm.stack->size() < sz ) {\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tVM_FAIL( \"expected vm stack size to be %zu, but is %zu (verify that a function is returning what it should)\",\t\\\n\t\t\t\t sz, vm.stack->size() );\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tgoto fail;\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( vm.stack->has_none( sz ) ) {\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tVM_FAIL( \"Stack contains value of None which cannot be used\" );\t\t\t\t\t\t\t\\\n\t\t\tgoto fail;\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t} while( 0 )\n\n#endif // VM_VM_STACK_HPP"
  },
  {
    "path": "src/VM/Vars/Base.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nconst char * VarTypeStrs[ _VT_LAST ] = {\n\t\"none\",\n\t\"nil\",\n\t\"int\",\n\t\"str\",\n\t\"flt\",\n\t\"bool\",\n\n\t\"enum\",\n\t\"vec\",\n\t\"map\",\n\t\"tuple\",\n\n\t\"struct\",\n\n\t\"custom\",\n};\n\nstatic int flt_precision = DEFAULT_FLOAT_PRECISION;\n\nvoid update_float_precision( const int precision )\n{\n\tflt_precision = precision;\n\tmpfr::mpreal::set_default_prec( flt_precision + 2 );\n}\n\nint get_float_precision() { return flt_precision; }\n\nvar_info_t::var_info_t( const int rc, const int si ,const int pc, const bool ia ) :\n\tref_ctr( rc ), src_idx( si ), parse_ctr( pc ), implements_assign( ia ) {}\n\nvar_base_t::var_base_t( const VarType type, const bool implements_assign, const int src_idx, const int parse_ctr )\n\t: m_type( type ), m_info( 1, src_idx, parse_ctr, implements_assign ) {}\n\nvar_base_t::~var_base_t() {}\n\nstd::string var_base_t::type_str() const { return VarTypeStrs[ m_type ]; }\nvoid var_base_t::assn( var_base_t * b ) {}\n\nvoid * var_base_t::operator new( size_t sz )\n{\n\treturn mem::alloc( sz );\n}\nvoid var_base_t::operator delete( void * ptr, size_t sz )\n{\n\tmem::free( ptr, sz );\n}\n"
  },
  {
    "path": "src/VM/Vars/Base.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_VARS_BASE_HPP\n#define VM_VARS_BASE_HPP\n\n#include <string>\n#include <gmpxx.h>\n\n#include \"../../../third_party/mpfrxx.hpp\"\n\n#include \"../Functions.hpp\"\n#include \"../MemPool.hpp\"\n\nenum VarType\n{\n\tVT_NONE,\n\tVT_NIL, // difference between NONE and NIL is that NONE is used internally, while NIL can be used in code\n\tVT_INT,\n\tVT_STR,\n\tVT_FLT,\n\tVT_BOOL,\n\n\tVT_ENUM,\n\tVT_VEC,\n\tVT_MAP,\n\tVT_TUPLE,\n\n\tVT_STRUCT,\n\n\tVT_CUSTOM,\n\n\t_VT_LAST,\n};\n\nextern const char * VarTypeStrs[ _VT_LAST ];\n\n#define DEFAULT_FLOAT_PRECISION 20\n\nvoid update_float_precision( const int precision = DEFAULT_FLOAT_PRECISION );\nint get_float_precision();\n\nstruct var_info_t\n{\n\tint ref_ctr;\n\tint src_idx;\n\tint parse_ctr;\n\tbool implements_assign;\n\tvar_info_t( const int rc, const int si ,const int pc, const bool ia );\n};\n\nclass var_base_t\n{\n\tVarType m_type;\n\tvar_info_t m_info;\npublic:\n\tvar_base_t( const VarType type, const bool implements_assign, const int src_idx, const int parse_ctr );\n\tvirtual ~var_base_t();\n\n\tinline VarType type() const { return m_type; }\n\tinline int ref() const { return m_info.ref_ctr; }\n\n\tinline void set_parse_ctr( const int parse_ctr ) { m_info.parse_ctr = parse_ctr; }\n\tinline int parse_ctr() const { return m_info.parse_ctr; }\n\n\tinline void set_src_idx( const int src_idx ) { m_info.src_idx = src_idx; }\n\tinline int src_idx() const { return m_info.src_idx; }\n\n\tinline void inc_ref() { ++m_info.ref_ctr; }\n\tinline void dec_ref() { --m_info.ref_ctr; }\n\tinline bool impls_assn() { return m_info.implements_assign; }\n\n\tvirtual std::string type_str() const;\n\tvirtual std::string to_str() const = 0;\n\tvirtual mpz_class to_int() const = 0;\n\tvirtual bool to_bool() const = 0;\n\tvirtual var_base_t * copy( const int src_idx, const int parse_ctr ) = 0;\n\tvirtual void assn( var_base_t * b );\n\n\tstatic void * operator new( size_t sz );\n\tstatic void operator delete( void * ptr, size_t sz );\n};\n\n#define VAR_IREF( var ) do { ( ( var_base_t * )var )->inc_ref(); } while( 0 )\n\n#define VAR_DREF( var )\t\t\t\t\t\t\\\n\tdo {\t\t\t\t\t\t\t\\\n\t\t( ( var_base_t * )var )->dec_ref();\t\t\\\n\t\tif( ( ( var_base_t * )var )->ref() <= 0 ) {\t\\\n\t\t\tdelete ( var_base_t * )var;\t\t\\\n\t\t\tvar = nullptr;\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\\\n\t} while( 0 )\n\nclass var_none_t : public var_base_t\n{\npublic:\n\tvar_none_t( const int src_idx, const int parse_ctr );\n\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n};\n#define AS_NONE( x ) static_cast< var_none_t * >( x )\n\nclass var_nil_t : public var_base_t\n{\npublic:\n\tvar_nil_t( const int src_idx, const int parse_ctr );\n\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n};\n#define AS_NIL( x ) static_cast< var_nil_t * >( x )\n\nclass var_int_t : public var_base_t\n{\n\tmpz_class m_val;\npublic:\n\tvar_int_t( const int val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_int_t( const size_t val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_int_t( const std::string & val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_int_t( const bool val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_int_t( const float val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_int_t( const mpz_class & val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_int_t( const mpfr::mpreal & val, const int src_idx = 0, const int parse_ctr = 0 );\n\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tmpz_class & get();\n};\n#define AS_INT( x ) static_cast< var_int_t * >( x )\n\nclass var_str_t : public var_base_t\n{\n\tstd::string m_val;\npublic:\n\tvar_str_t( const std::string & val, const int src_idx = 0, const int parse_ctr = 0 );\n\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tstd::string & get();\n};\n#define AS_STR( x ) static_cast< var_str_t * >( x )\n\nclass var_flt_t : public var_base_t\n{\n\tmpfr::mpreal m_val;\npublic:\n\tvar_flt_t( const float val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_flt_t( const int val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_flt_t( const std::string & val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_flt_t( const bool val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_flt_t( const mpfr::mpreal & val, const int src_idx = 0, const int parse_ctr = 0 );\n\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tmpfr::mpreal & get();\n};\n#define AS_FLT( x ) static_cast< var_flt_t * >( x )\n\nclass var_bool_t : public var_base_t\n{\n\tbool m_val;\npublic:\n\tvar_bool_t( const int val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_bool_t( const float val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_bool_t( const std::string & val, const int src_idx = 0, const int parse_ctr = 0 );\n\tvar_bool_t( const bool val, const int src_idx = 0, const int parse_ctr = 0 );\n\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid assn( var_base_t * b );\n\tbool & get();\n};\n#define AS_BOOL( x ) static_cast< var_bool_t * >( x )\n\nclass var_enum_t : public var_base_t\n{\n\tstd::string m_name;\n\tstd::unordered_map< std::string, var_int_t * > m_val;\npublic:\n\tvar_enum_t( const std::string & name, std::unordered_map< std::string, var_int_t * > & val,\n\t\t    const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_enum_t();\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tstd::string get_name();\n\tstd::unordered_map< std::string, var_int_t * > & get_val();\n};\n#define AS_ENUM( x ) static_cast< var_enum_t * >( x )\n\nclass var_vec_t : public var_base_t\n{\n\tstd::vector< var_base_t * > m_val;\n\tbool m_is_var_arg;\npublic:\n\tvar_vec_t( const std::vector< var_base_t * > & val, const int src_idx = 0,\n\t\t   const int parse_ctr = 0, const bool is_var_arg = false );\n\t~var_vec_t();\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid clear();\n\tstd::vector< var_base_t * > & get();\n\tvoid assn( var_base_t * b );\n\tinline bool is_var_arg() const { return m_is_var_arg; }\n\tinline void set_var_arg( const bool is_var_arg ) { m_is_var_arg = is_var_arg; }\n};\n#define AS_VEC( x ) static_cast< var_vec_t * >( x )\n\nclass var_map_t : public var_base_t\n{\n\tstd::unordered_map< std::string, var_base_t * > m_val;\npublic:\n\tvar_map_t( std::unordered_map< std::string, var_base_t * > & val,\n\t\t   const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_map_t();\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid clear();\n\tstd::unordered_map< std::string, var_base_t * > & get();\n\tvoid assn( var_base_t * b );\n};\n#define AS_MAP( x ) static_cast< var_map_t * >( x )\n\nclass var_tuple_t : public var_base_t\n{\n\tstd::vector< var_base_t * > m_val;\npublic:\n\tvar_tuple_t( const std::vector< var_base_t * > & val,\n\t\t     const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_tuple_t();\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid clear();\n\tstd::vector< var_base_t * > & get();\n\tvoid assn( var_base_t * b );\n};\n#define AS_TUPLE( x ) static_cast< var_tuple_t * >( x )\n\nclass var_struct_def_t : public var_base_t\n{\n\tstd::string m_name;\n\tstd::vector< std::string > m_pos;\n\tstd::unordered_map< std::string, var_base_t * > m_val;\npublic:\n\tvar_struct_def_t( const std::string & name, std::vector< std::string > & pos,\n\t\t\t  std::unordered_map< std::string, var_base_t * > & val,\n\t\t\t  const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_struct_def_t();\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tstd::string & get_name();\n\tstd::vector< std::string > & get_pos();\n\tstd::unordered_map< std::string, var_base_t * > & get_val();\n};\n\nclass var_struct_t : public var_base_t\n{\n\tstd::string m_name;\n\tstd::unordered_map< std::string, var_base_t * > m_val;\npublic:\n\tvar_struct_t( const std::string & name, std::unordered_map< std::string, var_base_t * > & val,\n\t\t      const int src_idx = 0, const int parse_ctr = 0 );\n\t~var_struct_t();\n\tstd::string type_str() const;\n\tstd::string to_str() const;\n\tmpz_class to_int() const;\n\tbool to_bool() const;\n\tvar_base_t * copy( const int src_idx, const int parse_ctr );\n\tvoid clear();\n\tstd::string & get_name();\n\tstd::unordered_map< std::string, var_base_t * > & get_val();\n\tvoid assn( var_base_t * b );\n};\n#define AS_STRUCT( x ) static_cast< var_struct_t * >( x )\n\n#endif // VM_VARS_BASE_HPP"
  },
  {
    "path": "src/VM/Vars/Bool.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_bool_t::var_bool_t( const int val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_BOOL, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_bool_t::var_bool_t( const float val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_BOOL, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_bool_t::var_bool_t( const std::string & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_BOOL, true, src_idx, parse_ctr ), m_val( val != \"0\" && val != \"\" ) {}\nvar_bool_t::var_bool_t( const bool val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_BOOL, true, src_idx, parse_ctr ), m_val( val ) {}\n\nstd::string var_bool_t::to_str() const { return m_val ? \"true\" : \"false\"; }\nmpz_class var_bool_t::to_int() const { return mpz_class( m_val ); }\nbool var_bool_t::to_bool() const { return m_val; }\n\nvar_base_t * var_bool_t::copy( const int src_idx, const int parse_ctr )\n\t{ return new var_bool_t( this->m_val, src_idx, parse_ctr ); }\nvoid var_bool_t::assn( var_base_t * b ) { m_val = AS_BOOL( b )->get(); }\nbool & var_bool_t::get() { return m_val; }"
  },
  {
    "path": "src/VM/Vars/Enum.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_enum_t::var_enum_t( const std::string & name, std::unordered_map< std::string, var_int_t * > & val,\n\t\t\tconst int src_idx, const int parse_ctr )\n\t: var_base_t( VT_ENUM, false, src_idx, parse_ctr ), m_name( name ), m_val( val ) {}\nvar_enum_t::~var_enum_t()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v.second );\n\t}\n}\nstd::string var_enum_t::to_str() const { return \"enum:\" + m_name + \"(\" + std::to_string( m_val.size() ) + \")\"; }\nmpz_class var_enum_t::to_int() const { return mpz_class( m_val.size() ); }\nbool var_enum_t::to_bool() const { return m_val.size() > 0; }\n\nvar_base_t * var_enum_t::copy( const int src_idx, const int parse_ctr )\n{\n\tstd::unordered_map< std::string, var_int_t * > newmap;\n\tfor( auto & v : m_val ) {\n\t\tnewmap[ v.first ] = AS_INT( v.second->copy( src_idx, parse_ctr ) );\n\t}\n\treturn new var_enum_t( this->m_name, newmap, src_idx, parse_ctr );\n}\nstd::string var_enum_t::get_name() { return m_name; }\nstd::unordered_map< std::string, var_int_t * > & var_enum_t::get_val() { return m_val; }"
  },
  {
    "path": "src/VM/Vars/Flt.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include <iomanip>\n#include <sstream>\n\n#include \"Base.hpp\"\n\nvar_flt_t::var_flt_t( const float val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_FLT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_flt_t::var_flt_t( const int val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_FLT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_flt_t::var_flt_t( const std::string & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_FLT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_flt_t::var_flt_t( const bool val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_FLT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_flt_t::var_flt_t( const mpfr::mpreal & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_FLT, true, src_idx, parse_ctr ), m_val( val ) {}\n\nstd::string var_flt_t::to_str() const\n{\n\tstd::ostringstream oss;\n\toss << std::setprecision( get_float_precision() + 1 ) << m_val;\n\treturn oss.str();\n}\nmpz_class var_flt_t::to_int() const { return mpz_class( mpf_class( m_val.toString() ) ); }\nbool var_flt_t::to_bool() const { return m_val != 0.0; }\n\nvar_base_t * var_flt_t::copy( const int src_idx, const int parse_ctr )\n\t{ return new var_flt_t( this->m_val, src_idx, parse_ctr ); }\nvoid var_flt_t::assn( var_base_t * b ) { m_val = AS_FLT( b )->get(); }\nmpfr::mpreal & var_flt_t::get() { return m_val; }"
  },
  {
    "path": "src/VM/Vars/Int.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_int_t::var_int_t( const int val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_INT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_int_t::var_int_t( const size_t val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_INT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_int_t::var_int_t( const std::string & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_INT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_int_t::var_int_t( const bool val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_INT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_int_t::var_int_t( const float val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_INT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_int_t::var_int_t( const mpz_class & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_INT, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_int_t::var_int_t( const mpfr::mpreal & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_INT, true, src_idx, parse_ctr ), m_val( mpf_class( val.toString() ) ) {}\n\nstd::string var_int_t::to_str() const { return m_val.get_str(); }\nmpz_class var_int_t::to_int() const { return m_val; }\nbool var_int_t::to_bool() const { return m_val != 0; }\n\nvar_base_t * var_int_t::copy( const int src_idx, const int parse_ctr )\n\t{ return new var_int_t( this->m_val, src_idx, parse_ctr ); }\nvoid var_int_t::assn( var_base_t * b ) { m_val = AS_INT( b )->get(); }\nmpz_class & var_int_t::get() { return m_val; }"
  },
  {
    "path": "src/VM/Vars/Map.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_map_t::var_map_t( std::unordered_map< std::string, var_base_t * > & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_MAP, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_map_t::~var_map_t()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v.second );\n\t}\n}\nstd::string var_map_t::to_str() const\n{\n\tstd::string str = \"{\";\n\tfor( auto it = m_val.begin(); it != m_val.end(); ++it ) {\n\t\tstr += it->first + \": \" + it->second->to_str() + \", \";\n\t}\n\t// remove the extra commas\n\tif( m_val.size() > 0 ) {\n\t\tstr.pop_back();\n\t\tstr.pop_back();\n\t}\n\tstr += \"}\";\n\treturn str;\n}\nmpz_class var_map_t::to_int() const { return mpz_class( m_val.size() ); }\nbool var_map_t::to_bool() const { return m_val.size() > 0; }\n\nvar_base_t * var_map_t::copy( const int src_idx, const int parse_ctr )\n{\n\tstd::unordered_map< std::string, var_base_t * > newmap;\n\tfor( auto & v : m_val ) {\n\t\tnewmap[ v.first ] = v.second->copy( src_idx, parse_ctr );\n\t}\n\treturn new var_map_t( newmap, src_idx, parse_ctr );\n}\n\nvoid var_map_t::clear()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v.second );\n\t}\n\tm_val.clear();\n}\n\nstd::unordered_map< std::string, var_base_t * > & var_map_t::get() { return m_val; }\n\nvoid var_map_t::assn( var_base_t * b )\n{\n\tthis->clear();\n\tvar_map_t * bt = static_cast< var_map_t * >( b );\n\tfor( auto & x : bt->m_val ) {\n\t\tthis->m_val[ x.first ] = x.second->copy( b->src_idx(), b->parse_ctr() );\n\t}\n}"
  },
  {
    "path": "src/VM/Vars/Nil.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_nil_t::var_nil_t( const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_NIL, true, src_idx, parse_ctr ) {}\n\nstd::string var_nil_t::to_str() const { return VarTypeStrs[ VT_NIL ]; }\nmpz_class var_nil_t::to_int() const { return 0; }\nbool var_nil_t::to_bool() const { return false; }\n\nvar_base_t * var_nil_t::copy( const int src_idx, const int parse_ctr )\n\t{ return new var_nil_t( src_idx, parse_ctr ); }\nvoid var_nil_t::assn( var_base_t * b ) {}"
  },
  {
    "path": "src/VM/Vars/None.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_none_t::var_none_t( const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_NONE, true, src_idx, parse_ctr ) {}\n\nstd::string var_none_t::to_str() const { return VarTypeStrs[ VT_NONE ]; }\nmpz_class var_none_t::to_int() const { return 0; }\nbool var_none_t::to_bool() const { return false; }\n\nvar_base_t * var_none_t::copy( const int src_idx, const int parse_ctr )\n\t{ return new var_none_t( src_idx, parse_ctr ); }\nvoid var_none_t::assn( var_base_t * b ) {}"
  },
  {
    "path": "src/VM/Vars/Str.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_str_t::var_str_t( const std::string & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_STR, true, src_idx, parse_ctr ), m_val( val ) {}\n\nstd::string var_str_t::to_str() const { return m_val; }\nmpz_class var_str_t::to_int() const { return mpz_class( m_val ); }\nbool var_str_t::to_bool() const { return !m_val.empty(); }\nvar_base_t * var_str_t::copy( const int src_idx, const int parse_ctr )\n\t{ return new var_str_t( this->m_val, src_idx, parse_ctr ); }\nvoid var_str_t::assn( var_base_t * b ) { m_val = AS_STR( b )->get(); }\nstd::string & var_str_t::get() { return m_val; }"
  },
  {
    "path": "src/VM/Vars/Struct.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_struct_t::var_struct_t( const std::string & name, std::unordered_map< std::string, var_base_t * > & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_STRUCT, true, src_idx, parse_ctr ), m_name( name ), m_val( val ) {}\nvar_struct_t::~var_struct_t()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v.second );\n\t}\n}\nstd::string var_struct_t::type_str() const { return m_name; }\nstd::string var_struct_t::to_str() const\n{\n\tstd::string str = m_name + \"{\";\n\tfor( auto it = m_val.begin(); it != m_val.end(); ++it ) {\n\t\tstr += it->first + \": \" + it->second->to_str() + \", \";\n\t}\n\t// remove the extra commas\n\tif( m_val.size() > 0 ) {\n\t\tstr.pop_back();\n\t\tstr.pop_back();\n\t}\n\tstr += \"}\";\n\treturn str;\n}\nmpz_class var_struct_t::to_int() const { return mpz_class( m_val.size() ); }\nbool var_struct_t::to_bool() const { return m_val.size() > 0; }\n\nvar_base_t * var_struct_t::copy( const int src_idx, const int parse_ctr )\n{\n\tstd::unordered_map< std::string, var_base_t * > newmap;\n\tfor( auto & v : m_val ) {\n\t\tnewmap[ v.first ] = v.second->copy( src_idx, parse_ctr );\n\t}\n\treturn new var_struct_t( m_name, newmap, src_idx, parse_ctr );\n}\n\nvoid var_struct_t::clear()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v.second );\n\t}\n\tm_val.clear();\n}\n\nstd::string & var_struct_t::get_name() { return m_name; }\nstd::unordered_map< std::string, var_base_t * > & var_struct_t::get_val() { return m_val; }\n\nvoid var_struct_t::assn( var_base_t * b )\n{\n\tthis->clear();\n\tvar_struct_t * bt = static_cast< var_struct_t * >( b );\n\tfor( auto & x : bt->m_val ) {\n\t\tthis->m_val[ x.first ] = x.second->copy( b->src_idx(), b->parse_ctr() );\n\t}\n}"
  },
  {
    "path": "src/VM/Vars/StructDef.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_struct_def_t::var_struct_def_t( const std::string & name, std::vector< std::string > & pos,\n\t\t\t\t    std::unordered_map< std::string, var_base_t * > & val,\n\t\t\t\t    const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_STRUCT, false, src_idx, parse_ctr ), m_name( name ), m_pos( pos ), m_val( val ) {}\nvar_struct_def_t::~var_struct_def_t()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v.second );\n\t}\n}\nstd::string var_struct_def_t::type_str() const { return m_name; }\nstd::string var_struct_def_t::to_str() const\n{\n\tstd::string str = m_name + \"{\";\n\tfor( auto it = m_val.begin(); it != m_val.end(); ++it ) {\n\t\tstr += it->first + \": \" + it->second->to_str() + \", \";\n\t}\n\t// remove the extra commas\n\tif( m_val.size() > 0 ) {\n\t\tstr.pop_back();\n\t\tstr.pop_back();\n\t}\n\tstr += \"}\";\n\treturn str;\n}\nmpz_class var_struct_def_t::to_int() const { return mpz_class( m_val.size() ); }\nbool var_struct_def_t::to_bool() const { return m_val.size() > 0; }\n\nvar_base_t * var_struct_def_t::copy( const int src_idx, const int parse_ctr )\n{\n\tstd::unordered_map< std::string, var_base_t * > newmap;\n\tfor( auto & v : m_val ) {\n\t\tnewmap[ v.first ] = v.second->copy( src_idx, parse_ctr );\n\t}\n\treturn new var_struct_t( m_name, newmap, src_idx, parse_ctr );\n}\n\nstd::string & var_struct_def_t::get_name() { return m_name; }\nstd::vector< std::string > & var_struct_def_t::get_pos() { return m_pos; }\nstd::unordered_map< std::string, var_base_t * > & var_struct_def_t::get_val() { return m_val; }"
  },
  {
    "path": "src/VM/Vars/Tuple.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_tuple_t::var_tuple_t( const std::vector< var_base_t * > & val, const int src_idx, const int parse_ctr )\n\t: var_base_t( VT_TUPLE, true, src_idx, parse_ctr ), m_val( val ) {}\nvar_tuple_t::~var_tuple_t()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v );\n\t}\n}\nstd::string var_tuple_t::to_str() const\n{\n\tstd::string str = \"(\";\n\tfor( auto it = m_val.begin(); it != m_val.end(); ++it ) {\n\t\tif( it == m_val.end() - 1 ) str += ( * it )->to_str();\n\t\telse str += ( * it )->to_str() + \", \";\n\t}\n\tstr += \")\";\n\treturn str;\n}\nmpz_class var_tuple_t::to_int() const { return mpz_class( m_val.size() ); }\nbool var_tuple_t::to_bool() const { return m_val.size() > 0; }\n\nvar_base_t * var_tuple_t::copy( const int src_idx, const int parse_ctr )\n{\n\tstd::vector< var_base_t * > newvec;\n\tfor( auto & v : m_val ) {\n\t\tnewvec.push_back( v->copy( src_idx, parse_ctr ) );\n\t}\n\treturn new var_tuple_t( newvec, src_idx, parse_ctr );\n}\n\nvoid var_tuple_t::clear()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v );\n\t}\n\tm_val.clear();\n}\n\nstd::vector< var_base_t * > & var_tuple_t::get() { return m_val; }\n\nvoid var_tuple_t::assn( var_base_t * b )\n{\n\tthis->clear();\n\tvar_tuple_t * bt = static_cast< var_tuple_t * >( b );\n\tfor( auto & x : bt->m_val ) {\n\t\tthis->m_val.push_back( x->copy( b->src_idx(), b->parse_ctr() ) );\n\t}\n}"
  },
  {
    "path": "src/VM/Vars/Vec.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Base.hpp\"\n\nvar_vec_t::var_vec_t( const std::vector< var_base_t * > & val, const int src_idx, const int parse_ctr, const bool is_var_arg )\n\t: var_base_t( VT_VEC, true, src_idx, parse_ctr ), m_val( val ), m_is_var_arg( is_var_arg ) {}\nvar_vec_t::~var_vec_t()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v );\n\t}\n}\nstd::string var_vec_t::to_str() const\n{\n\tstd::string str = \"[\";\n\tfor( auto it = m_val.begin(); it != m_val.end(); ++it ) {\n\t\tif( it == m_val.end() - 1 ) str += ( * it )->to_str();\n\t\telse str += ( * it )->to_str() + \", \";\n\t}\n\tstr += \"]\";\n\treturn str;\n}\nmpz_class var_vec_t::to_int() const { return mpz_class( m_val.size() ); }\nbool var_vec_t::to_bool() const { return m_val.size() > 0; }\n\nvar_base_t * var_vec_t::copy( const int src_idx, const int parse_ctr )\n{\n\tstd::vector< var_base_t * > newvec;\n\tfor( auto & v : m_val ) {\n\t\tnewvec.push_back( v->copy( src_idx, parse_ctr ) );\n\t}\n\treturn new var_vec_t( newvec, src_idx, parse_ctr, m_is_var_arg );\n}\n\nvoid var_vec_t::clear()\n{\n\tfor( auto & v : m_val ) {\n\t\tVAR_DREF( v );\n\t}\n\tm_val.clear();\n}\n\nstd::vector< var_base_t * > & var_vec_t::get() { return m_val; }\n\nvoid var_vec_t::assn( var_base_t * b )\n{\n\tthis->clear();\n\tvar_vec_t * bt = static_cast< var_vec_t * >( b );\n\tfor( auto & x : bt->m_val ) {\n\t\tthis->m_val.push_back( x->copy( b->src_idx(), b->parse_ctr() ) );\n\t}\n}"
  },
  {
    "path": "src/VM/Vars.cpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#include \"Vars.hpp\"\n\nvars_t::vars_t()\n\t: m_layer( 0 ), m_zeroes( { 0 } ) {}\nvars_t::~vars_t()\n{\n\tfor( auto & l : m_vars ) {\n\t\tfor( auto & v : l.second ) {\n\t\t\tVAR_DREF( v.second );\n\t\t}\n\t}\n}\n\nvar_base_t * vars_t::get( const std::string & var_name ) const\n{\n\tint layer_iter = m_layer;\n\twhile( layer_iter >= 0 ) {\n\t\tif( layer_iter != m_zeroes.back() && m_frozen_till.size() > 0 && layer_iter <= m_frozen_till.back() ) {\n\t\t\t--layer_iter;\n\t\t\tcontinue;\n\t\t}\n\t\tif( m_vars.find( layer_iter ) == m_vars.end() ) { --layer_iter; continue; }\n\t\tconst std::unordered_map< std::string, var_base_t * > & layer = m_vars.at( layer_iter );\n\t\tif( layer.find( var_name ) != layer.end() ) return layer.at( var_name );\n\t\t--layer_iter;\n\t}\n\treturn nullptr;\n}\n\nbool vars_t::exists( const std::string & var_name ) const\n{\n\tint layer_iter = m_layer;\n\twhile( layer_iter >= 0 ) {\n\t\tif( layer_iter != m_zeroes.back() && m_frozen_till.size() > 0 && layer_iter <= m_frozen_till.back() ) {\n\t\t\t--layer_iter;\n\t\t\tcontinue;\n\t\t}\n\t\tif( m_vars.find( layer_iter ) == m_vars.end() ) { --layer_iter; continue; }\n\t\tconst std::unordered_map< std::string, var_base_t * > & layer = m_vars.at( layer_iter );\n\t\tif( layer.find( var_name ) != layer.end() ) return true;\n\t\t--layer_iter;\n\t}\n\treturn false;\n}\n\nbool vars_t::del( const std::string & var_name, var_base_t ** loc )\n{\n\tint layer_iter = m_layer;\n\twhile( layer_iter >= 0 ) {\n\t\tif( layer_iter != m_zeroes.back() && m_frozen_till.size() > 0 && layer_iter <= m_frozen_till.back() ) {\n\t\t\t--layer_iter;\n\t\t\tcontinue;\n\t\t}\n\t\tif( m_vars.find( layer_iter ) == m_vars.end() ) { --layer_iter; continue; }\n\t\tstd::unordered_map< std::string, var_base_t * > & layer = m_vars[ layer_iter ];\n\t\tif( layer.find( var_name ) != layer.end() ) {\n\t\t\tif( loc != nullptr ) * loc = layer[ var_name ];\n\t\t\tlayer.erase( var_name );\n\t\t\treturn true;\n\t\t}\n\t\t--layer_iter;\n\t}\n\treturn false;\n}\n\nvoid vars_t::add_scope( const int count ) { m_layer += count; }\nvoid vars_t::pop_scope( std::vector< void * > * locs, const int count )\n{\n\tif( m_layer == 0 ) return;\n\tfor( int i = 0; i < count; ++i ) {\n\t\t// First layer (global) cannot be deleted\n\t\tif( m_layer == 0 ) break;\n\t\tif( m_vars.find( m_layer ) != m_vars.end() ) {\n\t\t\tif( locs != nullptr ) {\n\t\t\t\tfor( auto & vals : m_vars.at( m_layer ) ) {\n\t\t\t\t\tlocs->push_back( vals.second );\n\t\t\t\t}\n\t\t\t}\n\t\t\tm_vars.erase( m_layer );\n\t\t}\n\t\t--m_layer;\n\t}\n}\n\nint vars_t::layer_size() const { return m_layer; }"
  },
  {
    "path": "src/VM/Vars.hpp",
    "content": "/*\n\tCopyright (c) 2019, Electrux\n\tAll rights reserved.\n\tUsing the GNU GPL 3.0 license for the project,\n\tmain LICENSE file resides in project's root directory.\n\tPlease read that file and understand the license terms\n\tbefore using or altering the project.\n*/\n\n#ifndef VM_VARS_HPP\n#define VM_VARS_HPP\n\n#include <vector>\n#include <string>\n#include <unordered_map>\n\n#include \"Vars/Base.hpp\"\n\nclass vars_t\n{\n\tstd::unordered_map< int, std::unordered_map< std::string, var_base_t * > > m_vars;\n\tint m_layer;\n\tstd::vector< int > m_frozen_till;\n\tstd::vector< int > m_zeroes;\npublic:\n\tvars_t();\n\t~vars_t();\n\n\tvar_base_t * get( const std::string & var_name ) const;\n\n\tbool exists( const std::string & var_name ) const;\n\n\tinline void add( const std::string & var_name, var_base_t * const val )\n\t{\n\t\tm_vars[ m_layer ][ var_name ] = val;\n\t}\n\tinline void add_with_layer( const std::string & var_name, var_base_t * const val, const int layer )\n\t{\n\t\tm_vars[ layer ][ var_name ] = val;\n\t}\n\n\tbool del( const std::string & var_name, var_base_t ** loc );\n\n\tvoid add_scope( const int count = 1 );\n\tvoid pop_scope( std::vector< void * > * locs, const int count = 1 );\n\tinline void freeze_till( const int till ) { m_frozen_till.push_back( till ); }\n\tinline void unfreeze() { m_frozen_till.pop_back(); }\n\tinline void add_zero( const int zero_at ) { m_zeroes.push_back( zero_at ); }\n\tinline void pop_zero() { m_zeroes.pop_back(); }\n\n\tint layer_size() const;\n};\n\n#endif // VM_VARS_HPP"
  },
  {
    "path": "tests/ackermann.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\n\n# TODO: optimize speed\nfn ack( m, n ) {\n\tif m == 0 { return n + 1; }\n\tif n == 0 { return ack( m - 1, 1 ); }\n\treturn ack( m - 1, ack( m, n - 1 ) );\n}\n\nM = 4;\nN = 10;\nif args.len() > 1 {\n\tM = 3;\n\tN = 5;\n}\nfor m = 0; m < M; m += 1 {\n\tfor n = 0; n < N; n += 1 {\n\t\tprintln( 'A(', m, ', ', n, ') = ', ack( m, n ) );\n\t}\n}\n"
  },
  {
    "path": "tests/block.et",
    "content": "#!/usr/bin/env et\n\n{\n\ta = 1 + 2;\n\t{\n\t\tc = a - 10;\n\t}\n\tassert_nt( var_exists( 'c' ) );\n}\n"
  },
  {
    "path": "tests/bst.et",
    "content": "#!/usr/bin/env et\n\nimport std.opt;\n\nstruct btree {\n\tdata = 0;\n\tlhs = opt_new();\n\trhs = opt_new();\n}\n\nfn create_tree( d ) {\n\treturn btree{ d };\n}\n\nmfn< btree > add_node( data ) {\n\tif data <= self.data {\n\t\tif self.lhs.empty() {\n\t\t\tself.lhs.set( create_tree( data ) );\n\t\t} else {\n\t\t\tself.lhs.get().add_node( data );\n\t\t}\n\t} else {\n\t\tif self.rhs.empty() {\n\t\t\tself.rhs.set( create_tree( data ) );\n\t\t} else {\n\t\t\tself.rhs.get().add_node( data );\n\t\t}\n\t}\n}\n\nfn show( tree ) {\n\tif !tree.lhs.empty() {\n\t\tshow( tree.lhs.get() );\n\t}\n\tprintln( tree.data );\n\tif !tree.rhs.empty() {\n\t\tshow( tree.rhs.get() );\n\t}\n}\n\ntree = create_tree( 4 );\ntree.add_node( 2 );\ntree.add_node( 1 );\ntree.add_node( 3 );\ntree.add_node( 6 );\ntree.add_node( 5 );\ntree.add_node( 7 );\n\nshow( tree );"
  },
  {
    "path": "tests/bubble_sort.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\n\nv = [ 3, 2, 4, 1 ];\n\nfor i = 0; i < 4; i += 1 {\n\tfor j = 1; j < 4 - i; j += 1 {\n\t\tif v[ j - 1 ] > v[ j ] {\n\t\t\ttmp = v[ j ];\n\t\t\tv[ j ] = v[ j - 1 ];\n\t\t\tv[ j - 1 ] = tmp;\n\t\t}\n\t}\n}\n\nif args.len() > 1 {\n\tassert_eq( v, [ 1, 2, 3, 4 ] );\n} else {\n\tprintln( 'Vector: ', v );\n}"
  },
  {
    "path": "tests/data/test1_ini_parser.ini",
    "content": "; last modified 1 April 2001 by John Doe\n[owner]\nname=John Doe\norganization=Acme Widgets Inc.\n\n[database]\n; use IP address in case network name resolution is not working\nserver=192.0.2.62\nport=143\nfile=\"payroll.dat\"\n"
  },
  {
    "path": "tests/double_bubble_sort.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\n\nv = [ [ 3, 2 ], [ 4, 1 ] ];\n\nfor p = 0; p < 2; p += 1 {\n\tfor i = 0; i < 2; i += 1 {\n\t\tfor j = 1; j < 2 - i; j += 1 {\n\t\t\tif v[ p ][ j - 1 ] > v[ p ][ j ] {\n\t\t\t\ttmp = v[ p ][ j ];\n\t\t\t\tv[ p ][ j ] = v[ p ][ j - 1 ];\n\t\t\t\tv[ p ][ j - 1 ] = tmp;\n\t\t\t}\n\t\t}\n\t}\n}\n\nif args.len() > 1 {\n\tassert_eq( v, [ [ 2, 3 ], [ 1, 4 ] ] );\n} else {\n\tprintln( 'Vector: ', v );\n}"
  },
  {
    "path": "tests/enum.et",
    "content": "#!/usr/bin/env et\n\nenum SomeEnum\n{\n\tE1,\n\tE2,\n\tE3,\n\tE4,\n\tE5,\n}\n\nenum_mask SomeEnumMask\n{\n\tE1,\n\tE2,\n\tE3,\n\tE4,\n\tE5,\n}\n\nenum SomeEnum2 { E6, E7, E8, E9 }\n"
  },
  {
    "path": "tests/facto_iterate.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\nimport std.vec;\n\nif args.len() > 1 {\n\tnum = 5;\n\tfact = 1;\n\tfor x = num; x >= 2; x -= 1 {\n\t\tfact *= x;\n\t}\n\tassert_eq( fact, 120 );\n} else {\n\tnum = scan( \"Enter factorial of: \" ).to_int();\n\tfact = 1;\n\n\tfor x = num; x >= 2; x -= 1 {\n\t\tfact *= x;\n\t}\n\n\tprintln( \"Factorial of \", num, \": \", fact );\n}\n"
  },
  {
    "path": "tests/facto_recurse.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\nimport std.str;\n\nfn facto( n ) {\n\tif n < 2 { return 1; }\n\treturn n * facto( n - 1 );\n}\n\nif args.len() > 1 {\n\tfact = facto( 5 );\n\tassert_eq( fact, 120 );\n} else {\n\tn = scan( 'Enter a number: ' ).to_int();\n\tprintln( 'factorial of ', n, ' is: ', facto( n ) );\n}\n"
  },
  {
    "path": "tests/fast_recurse_fib.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\nimport std.vec;\nimport std.tuple;\n\nfn fib( n ) {\n\tif n == 1 { return make_tuple( 0, 1 ); }\n\tm = n / 2;\n\th = fib( m );\n\tprev = h.0 ** 2 + h.1 ** 2;\n\tcurr = h.1 * ( 2 * h.0 + h.1 );\n\tnext = prev + curr;\n\tif n % 2 == 0 { return make_tuple( prev, curr ); }\n\treturn make_tuple( curr, next );\n}\n\nif args.len() > 1 {\n\tassert_eq( fib( 12 ), make_tuple( 89, 144 ) );\n} else {\n\tn = scan( 'Enter a number: ' ).to_int();\n\tprintln( 'Fib is: ', fib( n ) );\n}\n"
  },
  {
    "path": "tests/fileio.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\nimport std.fs;\nimport std.os;\n\nfn write() {\n\tf = fopen( \"some\", \"w\" );\n\n\tif !f.is_open() {\n\t\tprintln( 'failed to open file' );\n\t} else {\n\t\tfor x = 0; x < 20; x += 1 {\n\t\t\tf.write( x, ': hi there\\n' );\n\t\t}\n\t}\n}\n\nfn read() {\n\tf = fopen( \"some\", \"r\" );\n\n\tif !f.is_open() {\n\t\tprintln( 'failed to open file' );\n\t} else {\n\t\ts = \"\";\n\t\tfor ; f.read( s ); {\n\t\t\tprintln( 'recvd: ', s );\n\t\t}\n\t}\n}\n\nfn read_all() {\n\tf = fopen( \"some\", \"r\" );\n\n\tif !f.is_open() {\n\t\tprintln( 'failed to open file' );\n\t} else {\n\t\ts = [];\n\t\tif f.read_all( s ) {\n\t\t\tfor line in s.iter() {\n\t\t\t\tprintln( '--> ', line );\n\t\t\t}\n\t\t} else {\n\t\t\tprintln( 'nothing to read :(' );\n\t\t}\n\t}\n}\n\nwrite();\nread();\nread_all();\nexit( os.exec( 'rm some' ) );\n"
  },
  {
    "path": "tests/funcs.et",
    "content": "#!/usr/bin/env et\n\nfn fn3() {\n\tprintln( 'hi' );\n}\n\nfn fn2( v ) {\n\tprintln( v );\n}\n\nfn fn1() {\n\tv = [];\n\tfn3();\n\tfn2( v );\n}\n\nfn1();\n"
  },
  {
    "path": "tests/if.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\n\na = 5;\nb = 10;\n\nif a == b {\n\tassert( false );\n}\nif b == a {\n\tassert( false );\n}\n"
  },
  {
    "path": "tests/import.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\nimport 'std/str';\nimport std.( 'str', vec, fs );\n\nassert_ne( __import__( 'a' ), 0 );\nassert_eq( __import__( 'std/os' ), 0 );\nassert( var_exists( 'os' ) );\nif 1 {\n\tassert_eq( __import__( 'std/time' ), 0 );\n}\nassert_nt( var_exists( 'time' ) );"
  },
  {
    "path": "tests/inc_lib_dirs.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\n\nassert_eq( __INC_DIRS__.len(), 1 );\nassert_eq( __LIB_DIRS__.len(), 1 );"
  },
  {
    "path": "tests/ini_parser.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\nimport ini;\n\nini = ini_read( __SRC_DIR__ + '/data/test1_ini_parser.ini' );\nassert_eq( ini[ 'owner' ][ 'name' ], 'John Doe' );\n"
  },
  {
    "path": "tests/int_binary.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\nimport std.str;\n\nnum = 12;\n\nif args.len() < 2 {\n\tnum = scan( 'Enter number for integer to binary: ' ).to_int();\n}\n\nbin = '';\nfor ; num > 0; {\n\tbin = ( num % 2 ).to_str() + bin;\n\tnum /= 2;\n}\n\nif args.len() > 1 {\n\tassert_eq( bin, '1100' );\n} else {\n\tprintln( 'Binary is: ', bin );\n}\n\nsz = bin.len();\npow = 2 ** sz;\nnum = 0;\n\nfor i = 0; i < sz; i += 1 {\n\tnum += bin[ i ].to_int() * ( pow >>= 1 );\n}\n\nif args.len() > 1 {\n\tassert_eq( num, 12 );\n} else {\n\tprintln( 'Original number is: ', num );\n}"
  },
  {
    "path": "tests/json_flat.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\nimport std.fs;\n\nr = fopen( __SRC_DIR__ + '/data/test1_json_flat.json', 'r' );\nif !r.is_open() {\n\tprintln( 'failed to open file \\'' + __SRC_DIR__ +'/data/test1_json_flat.json\\'' );\n\texit( 1 );\n}\nw = fopen( 'op.json', 'w' );\nif !w.is_open() {\n\tprintln( 'failed to open file \\'op.json\\'' );\n\texit( 1 );\n}\n\nline = '';\n\nc = 0;\nfor ; r.read( line ); {\n\tsz = line.len();\n\tfor i = 0; i < sz; i += 1 {\n\t\tif line[ i ] == '{' { c += 1; }\n\t\telif line[ i ] == '}' { c -= 1; }\n\n\t\tif line[ i ] == '\\t' || ( c == 0 && line[ i ] == ',' ) {\n\t\t\tline.erase_at( i );\n\t\t\tsz -= 1;\n\t\t\ti -=1;\n\t\t}\n\t}\n\tif( c == 0 ) { line += '\\n'; }\n\tw.write( line );\n}\n\nexpected = '';\nr.reopen( __SRC_DIR__ + '/data/expected1_json_flat.json', 'r' );\nif !r.is_open() {\n\tprintln( 'failed to open file \\'' + __SRC_DIR__ + '/data/expected1_json_flat.json\\'' );\n\texit( 1 );\n}\nfor ; r.read( line ); {\n\texpected += line;\n}\n\nactual = '';\nw.reopen( 'op.json', 'r' );\nif !w.is_open() {\n\tprintln( 'failed to open file \\'op.json\\'' );\n\texit( 1 );\n}\nfor ; w.read( line ); {\n\tactual += line;\n}\n\nassert_eq( expected, actual );\n"
  },
  {
    "path": "tests/ldmod.et",
    "content": "#!/usr/bin/env et\n\nldmod std.fs;\nldmod std.( str, fs, vec );\n\nimport std.fs;\n\nif fs.exists( '../buildfiles' ) {\n\tldmod '../buildfiles/std/str';\n}\n\nassert_ne( _ldmod_( 'a' ), 0 );\nassert_eq( _ldmod_( 'std/vec' ), 0 );\n"
  },
  {
    "path": "tests/loops.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\n\nfor i = 1; i < 10; i += 1 {\n\tif i == 2 { println( 'continuing on i = 2' ); continue; }\n\tif i == 5 { println( 'breaking on i = 5' ); break; }\n\tfor j = 1; j < 10; j += 1 {\n\t\tif j == 2 { println( 'continuing on j = 2' ); continue; }\n\t\tif j == 5 { println( 'breaking on j = 5' ); break; }\n\t\tprintln( 'i: ', i, ' j: ', j );\n\t}\n\tassert_nt( var_exists( 'j' ) );\n}\n\nassert_nt( var_exists( 'i' ) );\nassert_nt( var_exists( 'j' ) );\n\nfor i in range( 1, 10 ) {\n\tif i == 2 { println( 'continuing on i = 2' ); continue; }\n\tif i == 5 { println( 'breaking on i = 5' ); break; }\n\tfor j in range( 1, 10, 1 ) {\n\t\tif j == 2 { println( 'continuing on j = 2' ); continue; }\n\t\tif j == 5 { println( 'breaking on j = 5' ); break; }\n\t\tprintln( 'i: ', i, ' j: ', j );\n\t}\n\tassert_nt( var_exists( 'j' ) );\n\tassert_nt( var_exists( '._j' ) );\n}\n\nassert_nt( var_exists(   'i' ) );\nassert_nt( var_exists(   'j' ) );\nassert_nt( var_exists( '._i' ) );\nassert_nt( var_exists( '._j' ) );"
  },
  {
    "path": "tests/mandelbrot.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\nimport std.math;\nimport std.complex;\n\nprecision = args.len() > 1 ? 10 : 50;\n\nfor y = -1.0; y < 1.0; y += 0.05 {\n\tfor x = -2.05; x < 0.55; x += 0.03 {\n\t\txy = cplx.new( x, y );\n\t\tz = cplx.new( 0 );\n\t\tfor i in range( 0, precision ) {\n\t\t\tz = ( z ** 2 ) + xy;\n\t\t}\n\t\tprint( z.abs() < 2.0 ? '█' : ' ' );\n\t}\n\tprintln();\n}\n\n"
  },
  {
    "path": "tests/mem_funcs.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\n\nmfn< int > add_one() {\n\tself += 1;\n\treturn self;\n}\n\nmfn< str > append_( s ) {\n\tself += s;\n\tprintln( 'original length: ', self.len() );\n\tprintln( 'length + 1: ', self.len().add_one() );\n\tself += s;\n\tprintln( self );\n}\n\n\"he\".append_( \"llo\" );\n\nmfn< str, int, flt > print2() {\n\tprintln( '2' );\n}\n\n1.print2();\n'some'.print2();\n( 1.2 ).print2();"
  },
  {
    "path": "tests/mods/eth/vm.et",
    "content": "#!/usr/bin/env et\n\nimport eth.vm;\n\nvm = evm.new();\n\nassert_eq( vm.is_running(), true );\n\nexit_code = 0;\nvm.exec_code( [ 'exit( 1 );' ], exit_code );\n\nassert_eq( vm.is_running(), false );\nassert_eq( exit_code, 1 );"
  },
  {
    "path": "tests/mods/pre/core/add_incs.et",
    "content": "#!/usr/bin/env et\n\nimport std.os;\nimport std.str;\n\n__add_incs__( os.get_env( 'PWD' ) + '/tests' );\nassert_eq( __INC_DIRS__.len(), 2 );\n\nimport 'import';"
  },
  {
    "path": "tests/mods/pre/core/add_libs.et",
    "content": "#!/usr/bin/env et\n\nimport std.os;\nimport std.str;\n\n__add_libs__( os.get_env( 'PWD' ) + '/build/lib/ethereal' );\nassert_eq( __LIB_DIRS__.len(), 2 );\n\nimport eth.vm;"
  },
  {
    "path": "tests/mods/pre/core/assert.et",
    "content": "#!/usr/bin/env et\n\nassert( true );\nassert_eq( true, true );\nassert_ne( true, false );\nassert_lt( 1, 2 );\nassert_le( 1, 1 );\nassert_gt( 2.06, 2.05 );\nassert_ge( 0, 0 );\n"
  },
  {
    "path": "tests/mods/pre/core/bool.et",
    "content": "#!/usr/bin/env et\n\na = true;\nb = false;\n\nassert_and( true, true );\nassert_or( true, false );\nassert_eq( true, true );\nassert_ne( true, false );\nassert_nt( false );\nassert_eq( bool( '1' ), true );\n"
  },
  {
    "path": "tests/mods/pre/core/exit.et",
    "content": "#!/usr/bin/env et\n\nexit( 0 );\n"
  },
  {
    "path": "tests/mods/pre/core/flt.et",
    "content": "#!/usr/bin/env et\n\na = 5.5;\nb = 10.5;\n\nassert_eq( 1.1, 1.1 );\nassert_ne( 0.0, 1.0 );\nassert_lt( 1.1, 2.0 );\nassert_le( 1.0, 1.0 );\nassert_gt( 2.0, 1.1 );\nassert_ge( 1.1, 1.1 );\nassert_nt( 0.0 );\n\nassert_eq( 5.0 + 10.0, 15.0 );\nassert_eq( 5.0 - 10.0, -5.0 );\nassert_eq( 5.0 * 10.0, 50.0 );\nassert_eq( 5.0 / 10.0,  0.5 );\n\nassert_eq( a += 10.0, 15.5 );\nassert_eq( a -= 10.0,  5.5 );\nassert_eq( a *= 10.0, 55.0 );\nassert_eq( a /= 10.0,  5.5 );\n\nassert_eq( 2.5 ** 2, 6.25 );\n\nassert_eq( -6.0, -6.0 );\n\nassert_eq( flt( '1252.25' ), 1252.25 );"
  },
  {
    "path": "tests/mods/pre/core/int.et",
    "content": "#!/usr/bin/env et\n\na = 5;\nb = 10;\n\nassert_eq( 1, 1 );\nassert_ne( 0, 1 );\nassert_lt( 1, 2 );\nassert_le( 1, 1 );\nassert_gt( 2, 1 );\nassert_ge( 1, 1 );\nassert( !0 );\n\nassert_eq( 5 + 10, 15 );\nassert_eq( 5 - 10, -5 );\nassert_eq( 5 * 10, 50 );\nassert_eq( 5 / 10,  0 );\nassert_eq( 5 % 10,  5 );\n\nassert_eq( a += 10, 15 );\nassert_eq( a -= 10,  5 );\nassert_eq( a *= 10, 50 );\nassert_eq( a /= 10,  5 );\nassert_eq( a %= 10,  5 );\n\nassert_eq( 2 << 2, 8 );\nassert_eq( 2 >> 1, 1 );\n\nassert_eq( a <<= 2, 20 );\nassert_eq( a >>= 2,  5 );\n\nassert_eq( 5 & 4, 4 );\nassert_eq( 5 | 3, 7 );\nassert_eq( ~5,   -6 );\n\nassert_eq( 5 ** 4, 625 );\n\nassert_eq( -6, -6 );\n\nassert_eq( int( '1252' ), 1252 );\n"
  },
  {
    "path": "tests/mods/pre/core/io.et",
    "content": "#!/usr/bin/env et\n\n############### SIMPLE ################\n\nprint( 'hi' );\nprintln( 'hi' );\n\nprint( 'hi ' );\nflush_out();\nprintln( 'there' );\n\n################ DEBUG ################\n\ndprint( 'hi' );\ndprintln( 'hi' );\n\ndprint( 'hi ' );\nflush_err();\ndprintln( 'there' );"
  },
  {
    "path": "tests/mods/pre/core/nil.et",
    "content": "#!/usr/bin/env et\n\nassert_eq( nil,   nil );\nassert_ne( nil, 'str' );"
  },
  {
    "path": "tests/mods/pre/core/vars.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\n\n# type\nassert_eq( 'hello'.type(), 'str' );\n\n# exists\nassert_nt( var_exists( 'a' ) );\n\n# member functions\nstruct s {}\na = s{};\n\nassert_nt( var_mfn_exists( a, 'len' ) );\nimport std.str;\nassert( var_mfn_exists( 'string', 'len' ) );\n\n# ref count\nv = 5;\nassert_eq( var_ref_count( 'v' ), 1 );"
  },
  {
    "path": "tests/mods/std/complex.et",
    "content": "#!/usr/bin/env et\n\nimport std.math;\nimport std.complex;\n\na = cplx.new( 2, 3 );\nb = cplx.new( 1, 2 );\n\nsum = cplx.new(  3, 5 );\nsub = cplx.new(  1, 1 );\nmul = cplx.new( -4, 7 );\ndiv = cplx.new( 8.0 / 5, -1.0 / 5 );\n\n# arithmetic\nassert_eq( a + b, sum );\nassert_ne( a + b, sub );\nassert_eq( a - b, sub );\nassert_eq( a * b, mul );\nassert_eq( a / b, div );\n\n# arithmetic assign\nc = a;\nassert_eq( c += b, sum );\nassert_eq( c -= b,   a );\nassert_eq( c *= b, mul );\nassert_eq( c /= b,   a );\n\n# powers\nassert_eq( a ** -1, cplx.new( 1 ) / a );\nassert_eq( a **  0, cplx.new( 1 ) );\nassert_eq( a **  1, a );\nassert_eq( a **  2, cplx.new( -5, 12 ) );\nassert_eq( a **  cplx.new( 2 ), cplx.new( -5, 12 ) );\n\n# equality\n# used in all assertions so no need explicitly\n\n# unary minus\nassert_eq( -a, cplx.new( -2, -3 ) );\n\n# real/imaginary\nassert_eq( a.real(), 2.0 );\nassert_eq( a.imag(), 3.0 );\n\n# misc\nassert_eq( a.abs(), math.sqrt( 13.0 ) ); # abs(a) => distance(origin, a)\nassert_eq( a.norm(), 13.0 ); # square of abs()\nassert_eq( a.conj(), cplx.new( 2, -3 ) ); # same real part, opposite imaginary\nassert_eq( a.proj(), a ); # umm... ???\n# TODO: work on the rest of the functions\n\n"
  },
  {
    "path": "tests/mods/std/fs.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\nimport std.vec;\nimport std.fs;\n\nassert( fs.exists( __SRC_DIR__ + '/../pre' ) );\nassert( fs.exists( __SRC_DIR__ + '/vec.et' ) );\n\n# read non existing file\n{\n\tf = fopen( 'some_file', 'r' );\n\tassert( !f.is_open() );\n}\n\n# write file\n{\n\tf = fopen( 'some_file', 'w' );\n\tassert( f.is_open() );\n\tf.write( 'some data\\n' );\n}\n\n# append file\n{\n\tf = fopen( 'some_file', 'a' );\n\tassert( f.is_open() );\n\tf.write( 'some data 2\\n' );\n}\n\n# read each line\n{\n\tf = fopen( 'some_file', 'r' );\n\tassert( f.is_open() );\n\ts = \"\";\n\tf.read( s );\n\tassert_eq( s, 'some data' );\n\tf.read( s );\n\tassert_eq( s, 'some data 2' );\n}\n\n# read entire file in vector\n{\n\tf = fopen( 'some_file', 'r' );\n\tassert( f.is_open() );\n\tv = [];\n\tf.read_all( v );\n\tassert_eq( v, [ 'some data', 'some data 2' ] );\n}\n\nassert( fs.remove( 'some_file' ) );\nassert( !fs.exists( 'some_file' ) );\n"
  },
  {
    "path": "tests/mods/std/map.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\nimport std.map;\n\nm = { 'k', 'v' };\n\nassert_eq( m[ 'k' ], 'v' );\nassert_eq( m[ 'l' ], nil );\n\nassert_nt( m.delete( 'v' ) );\nassert( m.delete( 'k' ) );\nassert_eq( m.len(), 0 );\n\nm.insert( 'k', 'v' ).insert( 'l', 'w' );\nm.clear();\nassert_eq( m.len(), 0 );\n\nm.insert( 'k', 'v' );\nassert( m.find( 'k' ) );\n\nn = { 'l', 'm' };\nm = n;\nm[ 'l' ] = 'b';\nassert_eq( n[ 'l' ], 'm' );\n\n# nested map\nnm = {\n\t'solar system', {\n\t\t'first', 'mercury',\n\t\t'second', 'venus'\n\t}\n};\n\nassert_eq( nm[ 'solar system' ][ 'second' ], 'venus' );\n\nfor nm_n in nm.iter() {\n\tfor nm_m in nm_n.1.iter() {\n\t\tprintln( nm_m );\n\t}\n}"
  },
  {
    "path": "tests/mods/std/math.et",
    "content": "#!/usr/bin/env et\n\nimport std.math;\n\nassert_lt( math.e  - 2.7182818284590452353602874713526624977572470936999, math.precision );\nassert_lt( math.pi - 3.1415926535897932384626433832795028841971693993751, math.precision );\n\nassert_eq( math.abs( -131 ), 131 );\nassert_eq( math.abs(  131 ), 131 );\n\nassert_eq( math.abs( -131.25 ), 131.25 );\nassert_eq( math.abs(  131.25 ), 131.25 );\n\nassert( math.sqrt( -25.0 ).is_nan() );\nassert_eq( math.sqrt( 25.0 ), 5.0 );\nassert_lt( math.sqrt(  5.0 ) - 2.236067977499789805051477742381393909454345703125, math.precision );\n\nassert_eq( math.log( 1.0 ), 0.0 );\nassert( math.log( 1.0, 1.0 ).is_nan() );\nassert( math.log( 0.0, 2.0 ).is_nan() );\nassert_eq( math.log( 1.0, 2.0 ), 0.0 );\nassert_eq( math.log( 10.0, 10.0 ), 1.0 );\nassert_lt( 3 - math.log( 1000.0, 10.0 ), math.precision );\nassert( math.log( -1.0 ).is_nan() );\nassert( math.log( 10.0, -1.0 ).is_nan() );\n\nassert_eq( math.ceil(  0.0 ),  0 );\nassert_eq( math.ceil(  1.0 ),  1 );\nassert_eq( math.ceil( 1.01 ),  2 );\nassert_eq( math.ceil(  1.5 ),  2 );\nassert_eq( math.ceil( -1.5 ), -1 );\n\nassert_eq( math.floor( 0.0 ), 0 );\nassert_eq( math.floor( 1.0 ), 1 );\nassert_eq( math.floor( 1.01 ), 1 );\nassert_eq( math.floor( 1.5 ), 1 );\nassert_eq( math.floor( -1.5 ), -2 );\n\nassert_le( math.sin( 1.0 ) - 0.84147098480789650665, math.precision );\nassert_le( math.cos( 1.0 ) - 0.54030230586813971740, math.precision );\nassert_le( math.tan( 1.0 ) - 1.55740772465490223050, math.precision );\nassert_le( math.csc( 1.0 ) - 1.18839510577812121626, math.precision );\nassert_le( math.sec( 1.0 ) - 1.85081571768092561791, math.precision );\nassert_le( math.cot( 1.0 ) - 0.64209261593433070301, math.precision );\n\nassert_le( math.asin( 1.0 ) - 1.57079632679489661923, math.precision );\nassert_le( math.acos( 1.0 ) - 0.00000000000000000000, math.precision );\nassert_le( math.acos( 0.0 ) - 1.57079632679489661923, math.precision );\nassert_le( math.atan( 1.0 ) - 0.78539816339744830961, math.precision );\nassert_eq( math.acsc( 1.0 ), math.asin( 1.0 ) ); # acsc(x) => asin(1/x)\nassert_le( math.asec( 1.0 ) - 0.63661977236758134307, math.precision ); # # asec(x) => 1/acos(x)\nassert_le( math.acot( 1.0 ) - 1.27323954473516268615, math.precision );\n\nmath.update_prec( 350 );\nassert_eq( math.get_prec(), 350 );\n"
  },
  {
    "path": "tests/mods/std/opt.et",
    "content": "#!/usr/bin/env et\n\nimport std.opt;\n\nstruct rec {\n\ta = opt_new();\n}\n\ns = rec{};\n\ns.a.set( rec{} );\n\ns.a.get().a.set( 'hi' );\n\nprintln( s );\n\ns.a.clear();\n\nprintln( s );\n\nassert( s.a.empty() );\n\n# test for object referring to another object which refers to first object\nstruct tmp1 {\n\tb = opt_new();\n}\n\nstruct tmp2 {\n\td = opt_new();\n}\n\na = tmp1{};\nc = tmp2{};\n\na.b.set( c );\nc.d.set( a );\n\nprintln( a, '\\n', c );"
  },
  {
    "path": "tests/mods/std/os.et",
    "content": "#!/usr/bin/env et\n\nimport std.os;\nimport std.str;\n\nassert( os.name );\n\nassert_eq( os.set_env( 'RANDOM_ENV_VAR', 'temp' ), 0 );\nassert_eq( os.get_env( 'RANDOM_ENV_VAR' ), 'temp' );\n\nassert_eq( os.set_env( 'RANDOM_ENV_VAR', 'temp', false ), 0 );\nassert_eq( os.set_env( 'RANDOM_ENV_VAR', 'temp' ), 0 );\n\nassert_nt( os.find_exec( 'ls' ).empty() );\nassert_eq( os.mkdir( 'tmp_dir1', 'tmp_dir1' ), 0 );\nassert_eq( os.rm( 'tmp_dir1', 'tmp_dir1' ), 0 );"
  },
  {
    "path": "tests/mods/std/regex.et",
    "content": "#!/usr/bin/env et\n\nimport std.regex;\n\nr1 = re.build( 'abc|xyz' );\n\nassert_nt( r1.empty() );\nassert( r1.match( 'abc' ) );\nassert( r1.match( 'xyz' ) );\nassert( !r1.match( 'bcd' ) );"
  },
  {
    "path": "tests/mods/std/runtime.et",
    "content": "#!/usr/bin/env et\n\nimport std.runtime;\nldmod std.fs;\n\nold_fn_count = runtime.fn_count();\nprintln( old_fn_count );\n\nldmod std.fs;\nldmod std.fs;\n\nnew_fn_count = runtime.fn_count();\nprintln( new_fn_count );\nassert_eq( new_fn_count, old_fn_count );\n"
  },
  {
    "path": "tests/mods/std/set.et",
    "content": "#!/usr/bin/env et\n\nimport std.set;\n\ns = set_create();\n\ns.insert( 'hi' );\nassert( s.contains( 'hi' ) );\n\ns.insert( 'yo' );\nassert_eq( s.len(), 2 );\n\ns.erase( 'hi' );\nassert_nt( s.contains( 'hi' ) );\n\ns.clear();\nassert_eq( s.len(), 0 );"
  },
  {
    "path": "tests/mods/std/str.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\nimport std.str;\n\ns1 = 'str1';\ns2 = ' str2 ';\n\nassert_eq( s1 + s2,  'str1 str2 ' );\nassert_eq( s1 += s2, 'str1 str2 ' );\nassert_eq( '5' * 5, '55555' );\nassert_eq( 5 * '5', '55555' );\n\nassert_eq( 'str1', 'str1' );\nassert_ne( 'str1', 'str2' );\nassert_lt( 'str',  'str1' );\nassert_le( 'str1', 'str1' );\nassert_gt( 'str1',  'str' );\nassert_ge( 'str1', 'str1' );\n\ns1 = 'str1';\n\nassert_eq( s1.at( 1 ), 't' );\nassert_eq( s1[ 5 ],    nil );\nassert_eq( s1.hash(),   s1 );\n\nassert_eq( s1.len(), 4 );\n\nassert_nt( s1.empty() );\ns1.clear();\nassert( s1.empty() );\n\ns1 = '52';\n\nassert( s1.is_int() );\nassert_eq( s1.to_int(), 52 );\nassert_eq( s1.set_at( 1, '5' ), '55' );\n\nassert_eq( ''.erase_at( 1 ), '' );\nassert_eq( 'NASA'.erase_at( 1 ),  'NSA' );\nassert_eq( 'NASA'.erase_at( 4 ), 'NASA' );\n\nassert_nt( ''.find( 'a' ) );\nassert( 'abc'.find( 'a' ) );\nassert_nt( 'abc'.find( '' ) );\n\nassert_eq( ''.front(), '' );\nassert_eq( 'ab'.front(), 'a' );\nassert_eq( ''.back(),  '' );\nassert_eq( 'ab'.back(),  'b' );\n\nassert_eq( ''.pop_front(), '' );\nassert_eq( 'ab'.pop_front(), 'b' );\nassert_eq( ''.pop_back(),  '' );\nassert_eq( 'ab'.pop_back(),  'a' );\n\nassert_eq( ''.substr( 0, 2 ), '' );\nassert_eq( 'ab'.substr( 0, 1 ), 'a' );\nassert_eq( 'abc'.substr( 1, 2 ), 'bc' );\n\nassert_eq( 'a,b'.split( ',' ), [ 'a', 'b' ] );\nassert_eq( 'a,b,c'.split_first( ',' ), [ 'a', 'b,c' ] );\n\nassert_eq( s2.trim(), 'str2' );\n"
  },
  {
    "path": "tests/mods/std/term.et",
    "content": "#!/usr/bin/env et\n\nimport std.term;\n\nprintln( colorize( '{r}red{0}' ) );\n\ncprint( '{r}red{0}' );\nassert_eq( cprint( '{r}red{0}' ), 3 );\n\ncprintln( '{r}red{0}' );\nassert_eq( cprintln( '{r}red{0}' ), 4 );\n\ntsz = term.size();\nprintln( 'Rows: ', tsz.rows, '\\tCols: ', tsz.cols );\n"
  },
  {
    "path": "tests/mods/std/time.et",
    "content": "#!/usr/bin/env et\n\nimport std.time;\n\nstart = time.now();\n\nprintln( 'seconds passed since epoch: ', start );\n\nend = time.now();\n\nprintln( 'time in microseconds for a println: ', ( end - start ).usecs() );"
  },
  {
    "path": "tests/mods/std/tuple.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\nimport std.tuple;\n\nt1 = make_tuple( 'a', 5, 1.1 );\nt2 = make_tuple( 'b', 5, 1.1 );\nt3 = t2;\nt3.0 = 'a';\n\nassert_eq( t1.0, 'a' );\nassert_eq( t1.1,   5 );\nassert_eq( t1.2, 1.1 );\n\nassert_eq( t1, t3 );\nassert_ne( t1, t2 );"
  },
  {
    "path": "tests/mods/std/vec.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\n\nv = [];\nv += [ 1, 2 ];\n\nassert_eq( [], [] );\nassert_eq( [ 1, 2 ], [ 1, 2 ] );\nassert_ne( [ 1, 3 ], [ 1, 2 ] );\n\nv2 = [ 5, 6 ];\nv2 = v;\nv2[ 0 ] = 0;\n\nassert_eq( v, [ 1, 2 ] );\nassert_eq( v2, [ 0, 2 ] );\n\nv.push( 3 );\nassert_eq( v, [ 1, 2, 3 ] );\n\nv.pop();\nassert_eq( v, [ 1, 2 ] );\n\nv.pop_front();\nassert_eq( v, [ 2 ] );\n\nv.push_front( 1 );\nassert_eq( v, [ 1, 2 ] );\n\nv.push( 3 );\nassert_eq( v.front(), 1 );\nassert_eq( v.back(), 3 );\nassert_eq( v.len(), 3 );\n\nv.clear();\nassert_eq( v.len(), 0 );\n\nv.push_front( 1 );\nassert_eq( v, [ 1 ] );\n\nassert_eq( v.find( 1 ), 0 );\nassert_eq( v.find( 2 ), -1 );\n\nv = [ 1, 2, 3, 4, 5, 6 ];\n\nassert( v.erase( 3 ) );\nassert_nt( v.erase(  5 ) );\nassert_nt( v.erase( -1 ) );\n\nassert_eq( v.len(), 5 );\nassert_eq( v, [ 1, 2, 3, 5, 6 ] );\n\nfor i = 0; i < v.len(); i += 1 {\n\tv.erase( i );\n\ti -= 1;\n}\n\nassert_eq( v.len(), 0 );"
  },
  {
    "path": "tests/num_loop_replace.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\nimport std.vec;\n\ndest = args.len() > 1 ? 5 : 1000000;\nfor i = 0; i < dest; i +=1 {\n\tlen = i.to_str().len();\n\tprint( i );\n\tprint( '\\b' * len );\n}\nprintln();\n"
  },
  {
    "path": "tests/seq_calc.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\nimport std.str;\n\na = [ '5', '+', '9', '-', '2' ];\n\nsz = a.len();\n\nres = 0;\nop = '';\n\nfor item in a.iter() {\n\tif item.is_int() {\n\t\tif op == '+' {\n\t\t\tres += item.to_int();\n\t\t} elif op == '-' {\n\t\t\tres -= item.to_int();\n\t\t} else {\n\t\t\tres = item.to_int();\n\t\t}\n\t} else {\n\t\top = item;\n\t}\n}\n\nif args.len() < 2 {\n\tprintln( \"final result: \", res );\n} else {\n\tassert_eq( res, 12 );\n}\n"
  },
  {
    "path": "tests/star_pattern.et",
    "content": "#!/usr/bin/env et\n\n/*\n   ......*******\n   .....*     *\n   ....*     *\n   ...*     *\n   ..*     *\n   .*     *\n   *******\n*/\n\nimport std.vec;\n\ncount = 5;\nif args.len() < 2 {\n\tcount = int( scan( \"Enter star count: \" ) );\n}\n\nfor i = 0; i < count; i += 1 {\n\tfor j = 0; j < count - i - 1; j += 1 {\n\t\tprint( ' ' );\n\t}\n\tfor j = 0; j < count; j += 1 {\n\t\t# print( i == 0 || i == count - 1 || j == 0 || j == count - 1 ? '*' : ' ' );\n\t\tif i == 0 || i == count - 1 || j == 0 || j == count - 1 {\n\t\t\tprint( '*' );\n\t\t} else {\n\t\t\tprint( ' ' );\n\t\t}\n\t}\n\tprintln();\n}\n"
  },
  {
    "path": "tests/str_sort.et",
    "content": "#!/usr/bin/env et\n\nimport std.str;\n\nstr = \"string\";\nlen = str.len();\n\nfor i = 0; i < len; i += 1 {\n\tfor j = 0; j < len - i - 1; j += 1 {\n\t\tif str[ j ] > str[ j + 1 ] {\n\t\t\ttmp = str[ j ];\n\t\t\tstr.set_at( j, str[ j + 1 ] );\n\t\t\tstr.set_at( j + 1, tmp );\n\t\t}\n\t}\n}\n\nprintln( str );"
  },
  {
    "path": "tests/struct.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\nimport std.str;\n\nstruct s {\n\tt = 'hi';\n\tu = 5;\n}\n\na = s{ 'hi', 7 };\nb = s{ 'hello', 14 };\nb = a;\na.t = 'true';\nif args.len() < 2 {\n\tprintln( a.t );\n} else {\n\tassert_eq( a.t, 'true' );\n\tassert_eq( b.t,   'hi' );\n}\n"
  },
  {
    "path": "tests/threading.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\nimport std.str;\nimport std.threads;\n\nassert_gt( threads.nproc, 0 );\n\ntpool = [];\n\nmax_procs = threads.nproc;\nif max_procs > 8 { max_procs = 8; }\n\nfor i = 0; i < max_procs; i += 1 {\n\ttpool.push( threads.new_exec( __PROG__ + ' ' + __SRC_DIR__ + '/bst.et ', i ) );\n\tprintln( 'Created thread #', i );\n}\n\n# some work\n\nfailed = 0;\nfor ; tpool.len() > 0; {\n\tfor i = 0; i < tpool.len(); i += 1 {\n\t\tif tpool[ i ].done() {\n\t\t\tt = tpool[ i ];\n\t\t\tprintln( 'Finished ', t.id(), ' with result: ', t.res() );\n\t\t\tif t.res() != 0 { failed += 1; }\n\t\t\ttpool.erase( i );\n\t\t\ti -= 1;\n\t\t}\n\t}\n}\n\nexit( failed );\n"
  },
  {
    "path": "tests/var_args.et",
    "content": "#!/usr/bin/env et\n\nimport std.vec;\n\nfn var_args0( ... ) {\n\tassert_eq( __VA__.len(), 5 );\n\tprintln( __VA__ );\n\tvar_args2( __VA__ );\n}\n\nfn var_args1( a, ... ) {\n\tassert_eq( __VA__.len(), 4 );\n\tprintln( __VA__ );\n}\n\nfn var_args2( a, b, ... ) {\n\tassert_eq( __VA__.len(), 3 );\n\tprintln( __VA__ );\n}\n\nfn va_forward( ... ) {\n\tif __VA__.len() < 1 { return; }\n\tprintln( __VA__.front() );\n\t__VA__.pop_front();\n\tva_forward( __VA__ );\n}\n\nvar_args0( 'str', 1, 2, 3, 4 );\nvar_args1( 'str', 1, 2, 3, 4 );\nvar_args2( 'str', 1, 2, 3, 4 );\n\nva_forward( 1, 2, 3, 4 );\n"
  },
  {
    "path": "third_party/cmake_modules/FindMPC.cmake",
    "content": "# Try to find the MPC library\n#\n# This module supports requiring a minimum version, e.g. you can do\n#   find_package(MPC 1.0.0)\n# to require version 1.0.0 to newer of MPC.\n#\n# Once done, this will define\n#\n#  MPC_FOUND - system has MPC lib with correct version\n#  MPC_INCLUDES - the MPC include directory\n#  MPC_LIBRARIES - the MPC library\n#  MPC_VERSION - MPC version\n\n# Original Credits for the FindMPFR.cmake script:\n# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>\n# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>\n# Copyright (c) 2010 Jitse Niesen, <jitse@maths.leeds.ac.uk>\n# Copyright (c) 2015 Jack Poulson, <jack.poulson@gmail.com>\n# Redistribution and use is allowed according to the terms of the BSD license.\n\n# Modified in 2019 by Electrux for use with MPC, <electruxredsworth@gmail.com>\n\nfind_path(MPC_INCLUDES NAMES mpc.h PATHS $ENV{GMPDIR} $ENV{MPCDIR}\n  ${INCLUDE_INSTALL_DIR})\n\n# Set MPC_FIND_VERSION to 1.0.0 if no minimum version is specified\nif(NOT MPC_FIND_VERSION)\n  if(NOT MPC_FIND_VERSION_MAJOR)\n    set(MPC_FIND_VERSION_MAJOR 1)\n  endif()\n  if(NOT MPC_FIND_VERSION_MINOR)\n    set(MPC_FIND_VERSION_MINOR 0)\n  endif()\n  if(NOT MPC_FIND_VERSION_PATCH)\n    set(MPC_FIND_VERSION_PATCH 0)\n  endif()\n  set(MPC_FIND_VERSION\n    \"${MPC_FIND_VERSION_MAJOR}.${MPC_FIND_VERSION_MINOR}.${MPC_FIND_VERSION_PATCH}\")\nendif()\n\nif(MPC_INCLUDES)\n  # Query MPC_VERSION\n  file(READ \"${MPC_INCLUDES}/mpc.h\" _mpc_version_header)\n\n  string(REGEX MATCH \"define[ \\t]+MPC_VERSION_MAJOR[ \\t]+([0-9]+)\"\n    _mpc_major_version_match \"${_mpc_version_header}\")\n  set(MPC_MAJOR_VERSION \"${CMAKE_MATCH_1}\")\n  string(REGEX MATCH \"define[ \\t]+MPC_VERSION_MINOR[ \\t]+([0-9]+)\"\n    _mpc_minor_version_match \"${_mpc_version_header}\")\n  set(MPC_MINOR_VERSION \"${CMAKE_MATCH_1}\")\n  string(REGEX MATCH \"define[ \\t]+MPC_VERSION_PATCHLEVEL[ \\t]+([0-9]+)\"\n    _mpc_patchlevel_version_match \"${_mpc_version_header}\")\n  set(MPC_PATCHLEVEL_VERSION \"${CMAKE_MATCH_1}\")\n\n  set(MPC_VERSION\n    ${MPC_MAJOR_VERSION}.${MPC_MINOR_VERSION}.${MPC_PATCHLEVEL_VERSION})\n\n  # Check whether found version exceeds minimum required\n  if(${MPC_VERSION} VERSION_LESS ${MPC_FIND_VERSION})\n    set(MPC_VERSION_OK FALSE)\n    message(STATUS \"MPC version ${MPC_VERSION} found in ${MPC_INCLUDES}, \"\n                   \"but at least version ${MPC_FIND_VERSION} is required\")\n  else()\n    set(MPC_VERSION_OK TRUE)\n  endif()\nendif()\n\nfind_library(MPC_LIBRARIES mpc\n  PATHS $ENV{MPCDIR} $ENV{MPFRDIR} $ENV{GMPDIR} ${LIB_INSTALL_DIR})\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(MPC DEFAULT_MSG\n                                  MPC_INCLUDES MPC_LIBRARIES MPC_VERSION_OK)\nmark_as_advanced(MPC_INCLUDES MPC_LIBRARIES)"
  },
  {
    "path": "third_party/cmake_modules/FindMPFR.cmake",
    "content": "# Try to find the MPFR library\n# See http://www.mpfr.org/\n#\n# This module supports requiring a minimum version, e.g. you can do\n#   find_package(MPFR 2.3.0)\n# to require version 2.3.0 to newer of MPFR.\n#\n# Once done this will define\n#\n#  MPFR_FOUND - system has MPFR lib with correct version\n#  MPFR_INCLUDES - the MPFR include directory\n#  MPFR_LIBRARIES - the MPFR library\n#  MPFR_VERSION - MPFR version\n\n# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>\n# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>\n# Copyright (c) 2010 Jitse Niesen, <jitse@maths.leeds.ac.uk>\n# Copyright (c) 2015 Jack Poulson, <jack.poulson@gmail.com>\n# Redistribution and use is allowed according to the terms of the BSD license.\n\nfind_path(MPFR_INCLUDES NAMES mpfr.h PATHS $ENV{GMPDIR} $ENV{MPFRDIR}\n  ${INCLUDE_INSTALL_DIR})\n\n# Set MPFR_FIND_VERSION to 1.0.0 if no minimum version is specified\nif(NOT MPFR_FIND_VERSION)\n  if(NOT MPFR_FIND_VERSION_MAJOR)\n    set(MPFR_FIND_VERSION_MAJOR 1)\n  endif()\n  if(NOT MPFR_FIND_VERSION_MINOR)\n    set(MPFR_FIND_VERSION_MINOR 0)\n  endif()\n  if(NOT MPFR_FIND_VERSION_PATCH)\n    set(MPFR_FIND_VERSION_PATCH 0)\n  endif()\n  set(MPFR_FIND_VERSION\n    \"${MPFR_FIND_VERSION_MAJOR}.${MPFR_FIND_VERSION_MINOR}.${MPFR_FIND_VERSION_PATCH}\")\nendif()\n\nif(MPFR_INCLUDES)\n  # Query MPFR_VERSION\n  file(READ \"${MPFR_INCLUDES}/mpfr.h\" _mpfr_version_header)\n\n  string(REGEX MATCH \"define[ \\t]+MPFR_VERSION_MAJOR[ \\t]+([0-9]+)\"\n    _mpfr_major_version_match \"${_mpfr_version_header}\")\n  set(MPFR_MAJOR_VERSION \"${CMAKE_MATCH_1}\")\n  string(REGEX MATCH \"define[ \\t]+MPFR_VERSION_MINOR[ \\t]+([0-9]+)\"\n    _mpfr_minor_version_match \"${_mpfr_version_header}\")\n  set(MPFR_MINOR_VERSION \"${CMAKE_MATCH_1}\")\n  string(REGEX MATCH \"define[ \\t]+MPFR_VERSION_PATCHLEVEL[ \\t]+([0-9]+)\"\n    _mpfr_patchlevel_version_match \"${_mpfr_version_header}\")\n  set(MPFR_PATCHLEVEL_VERSION \"${CMAKE_MATCH_1}\")\n\n  set(MPFR_VERSION\n    ${MPFR_MAJOR_VERSION}.${MPFR_MINOR_VERSION}.${MPFR_PATCHLEVEL_VERSION})\n\n  # Check whether found version exceeds minimum required\n  if(${MPFR_VERSION} VERSION_LESS ${MPFR_FIND_VERSION})\n    set(MPFR_VERSION_OK FALSE)\n    message(STATUS \"MPFR version ${MPFR_VERSION} found in ${MPFR_INCLUDES}, \"\n                   \"but at least version ${MPFR_FIND_VERSION} is required\")\n  else()\n    set(MPFR_VERSION_OK TRUE)\n  endif()\nendif()\n\nfind_library(MPFR_LIBRARIES mpfr\n  PATHS $ENV{GMPDIR} $ENV{MPFRDIR} ${LIB_INSTALL_DIR})\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(MPFR DEFAULT_MSG\n                                  MPFR_INCLUDES MPFR_LIBRARIES MPFR_VERSION_OK)\nmark_as_advanced(MPFR_INCLUDES MPFR_LIBRARIES)"
  },
  {
    "path": "third_party/mpcxx.hpp",
    "content": "#ifndef MPCXX_HPP\n#define MPCXX_HPP\n\n#include <gmpxx.h>\n#include <mpc.h>\n\n#include \"mpfrxx.hpp\"\n\nnamespace mpc\n{\nclass mpcplx\n{\n\tmpc_t m_val;\npublic:\n\n\tinline static mpc_rnd_t get_default_rnd() { return MPC_RNDNN; }\n\tinline static mp_prec_t get_default_prec() { return mpfr_get_default_prec(); }\n\n\t// destructor\n\t~mpcplx();\n\n\t// constructors\n\tmpcplx();\n\tmpcplx( const mpcplx & v );\n\tmpcplx( const mpz_class & v );\n\tmpcplx( const mpfr::mpreal & v );\n\tmpcplx( const mpz_class & v, const mpz_class & i );\n\tmpcplx( const mpfr::mpreal & v, const mpfr::mpreal & i );\n\n\tmpcplx & operator =( mpcplx v );\n\n\t// unary\n\tmpcplx operator -();\n\n\t// arithmetic\n\tfriend mpcplx operator +( const mpcplx & a, const mpcplx & b );\n\tfriend mpcplx operator +( const mpcplx & a, const mpfr::mpreal & b );\n\tfriend mpcplx operator +( const mpfr::mpreal & a, const mpcplx & b );\n\n\tfriend mpcplx operator -( const mpcplx & a, const mpcplx & b );\n\tfriend mpcplx operator -( const mpcplx & a, const mpfr::mpreal & b );\n\tfriend mpcplx operator -( const mpfr::mpreal & a, const mpcplx & b );\n\n\tfriend mpcplx operator *( const mpcplx & a, const mpcplx & b );\n\tfriend mpcplx operator *( const mpcplx & a, const mpfr::mpreal & b );\n\tfriend mpcplx operator *( const mpfr::mpreal & a, const mpcplx & b );\n\n\tfriend mpcplx operator /( const mpcplx & a, const mpcplx & b );\n\tfriend mpcplx operator /( const mpcplx & a, const mpfr::mpreal & b );\n\tfriend mpcplx operator /( const mpfr::mpreal & a, const mpcplx & b );\n\n\t// arithmetic assign\n\tmpcplx & operator +=( const mpcplx & v );\n\tmpcplx & operator +=( const mpfr::mpreal & v );\n\n\tmpcplx & operator -=( const mpcplx & v );\n\tmpcplx & operator -=( const mpfr::mpreal & v );\n\n\tmpcplx & operator *=( const mpcplx & v );\n\tmpcplx & operator *=( const mpfr::mpreal & v );\n\n\tmpcplx & operator /=( const mpcplx & v );\n\tmpcplx & operator /=( const mpfr::mpreal & v );\n\n\tbool operator ==( const mpcplx & v ) const;\n\tbool operator !=( const mpcplx & v ) const;\n\n\tmpfr::mpreal real() const;\n\tmpfr::mpreal imag() const;\n\n\tmpfr::mpreal abs() const;\n\tmpfr::mpreal arg() const;\n\tmpfr::mpreal norm() const;\n\tmpcplx conj() const;\n\tmpcplx proj() const;\n\n\t// log + power\n\tmpcplx exp() const;\n\tmpcplx log() const;\n\tmpcplx pow( const mpcplx & base ) const;\n\tmpcplx pow( const mpz_class & base ) const;\n\tmpcplx pow( const mpfr::mpreal & base ) const;\n\tmpcplx sqrt() const;\n\n\t// trignometric\n\tmpcplx sin() const;\n\tmpcplx cos() const;\n\tmpcplx tan() const;\n\n\tmpcplx csc() const;\n\tmpcplx sec() const;\n\tmpcplx cot() const;\n\n\tstd::string to_str( size_t prec = get_default_prec(), const int base = 10 ) const;\n};\n\n// destructor\ninline mpcplx::~mpcplx()\n{\n\tmpc_clear( m_val );\n}\n\n// constructors\ninline mpcplx::mpcplx()\n{\n\tmpc_init2( m_val, get_default_prec() );\n}\ninline mpcplx::mpcplx( const mpcplx & v )\n{\n\tmpc_init2( m_val, get_default_prec() );\n\tmpc_set( m_val, v.m_val, get_default_rnd() );\n}\ninline mpcplx::mpcplx( const mpz_class & v )\n{\n\tmpc_init2( m_val, get_default_prec() );\n\tmpc_set_z( m_val, v.get_mpz_t(), get_default_rnd() );\n}\ninline mpcplx::mpcplx( const mpz_class & v, const mpz_class & i )\n{\n\tmpc_init2( m_val, get_default_prec() );\n\tmpc_set_z_z( m_val, v.get_mpz_t(), i.get_mpz_t(), get_default_rnd() );\n}\ninline mpcplx::mpcplx( const mpfr::mpreal & v )\n{\n\tmpc_init2( m_val, get_default_prec() );\n\tmpc_set_fr( m_val, v.mpfr_ptr(), get_default_rnd() );\n}\ninline mpcplx::mpcplx( const mpfr::mpreal & v, const mpfr::mpreal & i )\n{\n\tmpc_init2( m_val, get_default_prec() );\n\tmpc_set_fr_fr( m_val, v.mpfr_ptr(), i.mpfr_ptr(), get_default_rnd() );\n}\n\n// unary\ninline mpcplx mpcplx::operator-()\n{\n\tmpcplx r;\n\tmpc_neg( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\n\n// arithmetic\ninline mpcplx operator +( const mpcplx & a, const mpcplx & b )\n{\n\tmpcplx r;\n\tmpc_add( r.m_val, a.m_val, b.m_val, mpcplx::get_default_rnd() );\n\treturn r;\n}\ninline mpcplx operator +( const mpcplx & a, const mpfr::mpreal & b )\n{\n\tmpcplx r;\n\tmpc_add_fr( r.m_val, a.m_val, b.mpfr_ptr(), mpcplx::get_default_rnd() );\n\treturn r;\n}\ninline mpcplx operator +( const mpfr::mpreal & a, const mpcplx & b )\n{\n\tmpcplx r;\n\tmpc_add_fr( r.m_val, b.m_val, a.mpfr_ptr(), mpcplx::get_default_rnd() );\n\treturn r;\n}\n\ninline mpcplx operator -( const mpcplx & a, const mpcplx & b )\n{\n\tmpcplx r;\n\tmpc_sub( r.m_val, a.m_val, b.m_val, mpcplx::get_default_rnd() );\n\treturn r;\n}\ninline mpcplx operator -( const mpcplx & a, const mpfr::mpreal & b )\n{\n\tmpcplx r;\n\tmpc_sub_fr( r.m_val, a.m_val, b.mpfr_ptr(), mpcplx::get_default_rnd() );\n\treturn r;\n}\ninline mpcplx operator -( const mpfr::mpreal & a, const mpcplx & b )\n{\n\tmpcplx r;\n\tmpc_sub_fr( r.m_val, b.m_val, a.mpfr_ptr(), mpcplx::get_default_rnd() );\n\treturn r;\n}\n\ninline mpcplx operator *( const mpcplx & a, const mpcplx & b )\n{\n\tmpcplx r;\n\tmpc_mul( r.m_val, a.m_val, b.m_val, mpcplx::get_default_rnd() );\n\treturn r;\n}\ninline mpcplx operator *( const mpcplx & a, const mpfr::mpreal & b )\n{\n\tmpcplx r;\n\tmpc_mul_fr( r.m_val, a.m_val, b.mpfr_ptr(), mpcplx::get_default_rnd() );\n\treturn r;\n}\ninline mpcplx operator *( const mpfr::mpreal & a, const mpcplx & b )\n{\n\tmpcplx r;\n\tmpc_mul_fr( r.m_val, b.m_val, a.mpfr_ptr(), mpcplx::get_default_rnd() );\n\treturn r;\n}\n\ninline mpcplx operator /( const mpcplx & a, const mpcplx & b )\n{\n\tmpcplx r;\n\tmpc_div( r.m_val, a.m_val, b.m_val, mpcplx::get_default_rnd() );\n\treturn r;\n}\ninline mpcplx operator /( const mpcplx & a, const mpfr::mpreal & b )\n{\n\tmpcplx r;\n\tmpc_div_fr( r.m_val, a.m_val, b.mpfr_ptr(), mpcplx::get_default_rnd() );\n\treturn r;\n}\ninline mpcplx operator /( const mpfr::mpreal & a, const mpcplx & b )\n{\n\tmpcplx r;\n\tmpc_div_fr( r.m_val, b.m_val, a.mpfr_ptr(), mpcplx::get_default_rnd() );\n\treturn r;\n}\n\n// copy assignment operator\ninline mpcplx & mpcplx::operator =( mpcplx v )\n{\n\tmpc_set( m_val, v.m_val, get_default_rnd() );\n\treturn * this;\n}\n\n// arithmetic assign\ninline mpcplx & mpcplx::operator +=( const mpcplx & v )\n{\n\tmpc_add( m_val, m_val, v.m_val, get_default_rnd() );\n\treturn * this;\n}\ninline mpcplx & mpcplx::operator +=( const mpfr::mpreal & v )\n{\n\tmpc_add_fr( m_val, m_val, v.mpfr_ptr(), get_default_rnd() );\n\treturn * this;\n}\n\ninline mpcplx & mpcplx::operator -=( const mpcplx & v )\n{\n\tmpc_sub( m_val, m_val, v.m_val, get_default_rnd() );\n\treturn * this;\n}\ninline mpcplx & mpcplx::operator -=( const mpfr::mpreal & v )\n{\n\tmpc_sub_fr( m_val, m_val, v.mpfr_ptr(), get_default_rnd() );\n\treturn * this;\n}\n\ninline mpcplx & mpcplx::operator *=( const mpcplx & v )\n{\n\tmpc_mul( m_val, m_val, v.m_val, get_default_rnd() );\n\treturn * this;\n}\ninline mpcplx & mpcplx::operator *=( const mpfr::mpreal & v )\n{\n\tmpc_mul_fr( m_val, m_val, v.mpfr_ptr(), get_default_rnd() );\n\treturn * this;\n}\n\ninline mpcplx & mpcplx::operator /=( const mpcplx & v )\n{\n\tmpc_div( m_val, m_val, v.m_val, get_default_rnd() );\n\treturn * this;\n}\ninline mpcplx & mpcplx::operator /=( const mpfr::mpreal & v )\n{\n\tmpc_div_fr( m_val, m_val, v.mpfr_ptr(), get_default_rnd() );\n\treturn * this;\n}\n\n// logical comparison\ninline bool mpcplx::operator ==( const mpcplx & v ) const\n{\n\t// NOT because ZERO => equal, ANY OTHER => not equal\n\treturn !mpc_cmp( m_val, v.m_val );\n}\ninline bool mpcplx::operator !=( const mpcplx & v ) const\n{\n\treturn mpc_cmp( m_val, v.m_val );\n}\n\n// get real/imaginary\ninline mpfr::mpreal mpcplx::real() const\n{\n\tmpfr::mpreal r;\n\tmpc_real( r.mpfr_ptr(), m_val, mpfr::mpreal::get_default_rnd() );\n\treturn r;\n}\ninline mpfr::mpreal mpcplx::imag() const\n{\n\tmpfr::mpreal r;\n\tmpc_imag( r.mpfr_ptr(), m_val, mpfr::mpreal::get_default_rnd() );\n\treturn r;\n}\n\n// misc\ninline mpfr::mpreal mpcplx::abs() const\n{\n\tmpfr::mpreal r;\n\tmpc_abs( r.mpfr_ptr(), m_val, mpfr::mpreal::get_default_rnd() );\n\treturn r;\n}\ninline mpfr::mpreal mpcplx::arg() const\n{\n\tmpfr::mpreal r;\n\tmpc_arg( r.mpfr_ptr(), m_val, mpfr::mpreal::get_default_rnd() );\n\treturn r;\n}\ninline mpfr::mpreal mpcplx::norm() const\n{\n\tmpfr::mpreal r;\n\tmpc_norm( r.mpfr_ptr(), m_val, mpfr::mpreal::get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::conj() const\n{\n\tmpcplx r;\n\tmpc_conj( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::proj() const\n{\n\tmpcplx r;\n\tmpc_proj( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\n\n// log + power\ninline mpcplx mpcplx::exp() const\n{\n\tmpcplx r;\n\tmpc_exp( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::log() const\n{\n\tmpcplx r;\n\tmpc_log( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::pow( const mpcplx & base ) const\n{\n\tmpcplx r;\n\tmpc_pow( r.m_val, m_val, base.m_val, get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::pow( const mpz_class & base ) const\n{\n\tmpcplx r;\n\tmpc_pow_z( r.m_val, m_val, base.get_mpz_t(), get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::pow( const mpfr::mpreal & base ) const\n{\n\tmpcplx r;\n\tmpc_pow_fr( r.m_val, m_val, base.mpfr_ptr(), get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::sqrt() const\n{\n\tmpcplx r;\n\tmpc_sqrt( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\n\n// trignometric\ninline mpcplx mpcplx::sin() const\n{\n\tmpcplx r;\n\tmpc_sin( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::cos() const\n{\n\tmpcplx r;\n\tmpc_cos( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::tan() const\n{\n\tmpcplx r;\n\tmpc_tan( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\n\ninline mpcplx mpcplx::csc() const\n{\n\tmpcplx r;\n\tmpc_asin( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::sec() const\n{\n\tmpcplx r;\n\tmpc_acos( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\ninline mpcplx mpcplx::cot() const\n{\n\tmpcplx r;\n\tmpc_atan( r.m_val, m_val, get_default_rnd() );\n\treturn r;\n}\n\ninline std::string mpcplx::to_str( size_t prec, const int base ) const\n{\n\tchar * buf = mpc_get_str( base, prec, m_val, get_default_rnd() );\n\tstd::string str( buf );\n\tmpc_free_str( buf );\n\treturn str;\n}\n\ninline std::ostream & operator <<( std::ostream & os, const mpcplx & z )\n{\n    return os << z.to_str( static_cast< size_t >( os.precision() ) );\n}\n\n// end namespace\n}\n\n#endif // MPCXX_HPP\n"
  },
  {
    "path": "third_party/mpfrxx.hpp",
    "content": "/*\n    MPFR C++: Multi-precision floating point number class for C++.\n    Based on MPFR library:    http://mpfr.org\n\n    Project homepage:    http://www.holoborodko.com/pavel/mpfr\n    Contact e-mail:      pavel@holoborodko.com\n\n    Copyright (c) 2008-2015 Pavel Holoborodko\n\n    Contributors:\n    Dmitriy Gubanov, Konstantin Holoborodko, Brian Gladman,\n    Helmut Jarausch, Fokko Beekhof, Ulrich Mutze, Heinz van Saanen,\n    Pere Constans, Peter van Hoof, Gael Guennebaud, Tsai Chia Cheng,\n    Alexei Zubanov, Jauhien Piatlicki, Victor Berger, John Westwood,\n    Petr Aleksandrov, Orion Poplawski, Charles Karney, Arash Partow,\n    Rodney James, Jorge Leitao.\n\n    Licensing:\n    (A) MPFR C++ is under GNU General Public License (\"GPL\").\n\n    (B) Non-free licenses may also be purchased from the author, for users who\n        do not want their programs protected by the GPL.\n\n        The non-free licenses are for users that wish to use MPFR C++ in\n        their products but are unwilling to release their software\n        under the GPL (which would require them to release source code\n        and allow free redistribution).\n\n        Such users can purchase an unlimited-use license from the author.\n        Contact us for more details.\n\n    GNU General Public License (\"GPL\") copyright permissions statement:\n    **************************************************************************\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n*/\n\n#ifndef __MPFRXX_HPP__\n#define __MPFRXX_HPP__\n\n#include <string>\n#include <iostream>\n#include <sstream>\n#include <stdexcept>\n#include <cfloat>\n#include <cmath>\n#include <cstring>\n#include <limits>\n#include <cstdint>\n#include <complex>\n#include <algorithm>\n\n// Options\n#define MPREAL_HAVE_MSVC_DEBUGVIEW              // Enable Debugger Visualizer for \"Debug\" builds in MSVC.\n#define MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS  // Enable extended std::numeric_limits<mpfr::mpreal> specialization.\n                                                // Meaning that \"digits\", \"round_style\" and similar members are defined as functions, not constants.\n                                                // See std::numeric_limits<mpfr::mpreal> at the end of the file for more information.\n\n// Library version\n#define MPREAL_VERSION_MAJOR 3\n#define MPREAL_VERSION_MINOR 6\n#define MPREAL_VERSION_PATCHLEVEL 2\n#define MPREAL_VERSION_STRING \"3.6.2\"\n\n// Detect compiler using signatures from http://predef.sourceforge.net/\n#if defined(__GNUC__) && defined(__INTEL_COMPILER)\n    #define IsInf(x) isinf(x)                   // Intel ICC compiler on Linux\n\n#elif defined(_MSC_VER)                         // Microsoft Visual C++\n    #define IsInf(x) (!_finite(x))\n\n#else\n    #define IsInf(x) std::isinf(x)              // GNU C/C++ (and/or other compilers), just hope for C99 conformance\n#endif\n\n// A Clang feature extension to determine compiler features.\n#ifndef __has_feature\n    #define __has_feature(x) 0\n#endif\n\n// Detect support for r-value references (move semantic). Borrowed from Eigen.\n#if (__has_feature(cxx_rvalue_references) || \\\n       defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \\\n      (defined(_MSC_VER) && _MSC_VER >= 1600))\n\n    #define MPREAL_HAVE_MOVE_SUPPORT\n\n    // Use fields in mpfr_t structure to check if it was initialized / set dummy initialization\n    #define mpfr_is_initialized(x)      (0 != (x)->_mpfr_d)\n    #define mpfr_set_uninitialized(x)   ((x)->_mpfr_d = 0 )\n#endif\n\n// Detect support for explicit converters.\n#if (__has_feature(cxx_explicit_conversions) || \\\n       (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC_MINOR >= 5) || __cplusplus >= 201103L || \\\n       (defined(_MSC_VER) && _MSC_VER >= 1800))\n\n    #define MPREAL_HAVE_EXPLICIT_CONVERTERS\n#endif\n\n#define MPFR_USE_INTMAX_T   // Enable 64-bit integer types - should be defined before mpfr.h\n\n#if defined(MPREAL_HAVE_MSVC_DEBUGVIEW) && defined(_MSC_VER) && defined(_DEBUG)\n    #define MPREAL_MSVC_DEBUGVIEW_CODE     DebugView = toString();\n    #define MPREAL_MSVC_DEBUGVIEW_DATA     std::string DebugView;\n#else\n    #define MPREAL_MSVC_DEBUGVIEW_CODE\n    #define MPREAL_MSVC_DEBUGVIEW_DATA\n#endif\n\n#include <mpfr.h>\n\n#if (MPFR_VERSION < MPFR_VERSION_NUM(3,0,0))\n    #include <cstdlib>                          // Needed for random()\n#endif\n\n// Less important options\n#define MPREAL_DOUBLE_BITS_OVERFLOW -1          // Triggers overflow exception during conversion to double if mpreal\n                                                // cannot fit in MPREAL_DOUBLE_BITS_OVERFLOW bits\n                                                // = -1 disables overflow checks (default)\n\n// Fast replacement for mpfr_set_zero(x, +1):\n// (a) uses low-level data members, might not be compatible with new versions of MPFR\n// (b) sign is not set, add (x)->_mpfr_sign = 1;\n#define mpfr_set_zero_fast(x)  ((x)->_mpfr_exp = __MPFR_EXP_ZERO)\n\n#if defined(__GNUC__)\n  #define MPREAL_PERMISSIVE_EXPR __extension__\n#else\n  #define MPREAL_PERMISSIVE_EXPR\n#endif\n\nnamespace mpfr {\n\nclass mpreal {\nprivate:\n    mpfr_t mp;\n\npublic:\n\n    // Get default rounding mode & precision\n    inline static mp_rnd_t   get_default_rnd()    {    return (mp_rnd_t)(mpfr_get_default_rounding_mode());       }\n    inline static mp_prec_t  get_default_prec()   {    return mpfr_get_default_prec();                            }\n\n    // Constructors && type conversions\n    mpreal();\n    mpreal(const mpreal& u);\n    mpreal(const mpf_t u);\n    mpreal(const mpz_t u,                  mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const mpq_t u,                  mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const double u,                 mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const long double u,            mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const unsigned long long int u, mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const long long int u,          mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const unsigned long int u,      mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const unsigned int u,           mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const long int u,               mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const int u,                    mp_prec_t prec = mpreal::get_default_prec(), mp_rnd_t mode = mpreal::get_default_rnd());\n\n    // Construct mpreal from mpfr_t structure.\n    // shared = true allows to avoid deep copy, so that mpreal and 'u' share the same data & pointers.\n    mpreal(const mpfr_t  u, bool shared = false);\n\n    mpreal(const char* s,             mp_prec_t prec = mpreal::get_default_prec(), int base = 10, mp_rnd_t mode = mpreal::get_default_rnd());\n    mpreal(const std::string& s,      mp_prec_t prec = mpreal::get_default_prec(), int base = 10, mp_rnd_t mode = mpreal::get_default_rnd());\n\n    ~mpreal();\n\n#ifdef MPREAL_HAVE_MOVE_SUPPORT\n    mpreal& operator=(mpreal&& v);\n    mpreal(mpreal&& u);\n#endif\n\n    // Operations\n    // =\n    // +, -, *, /, ++, --, <<, >>\n    // *=, +=, -=, /=,\n    // <, >, ==, <=, >=\n\n    // =\n    mpreal& operator=(const mpreal& v);\n    mpreal& operator=(const mpf_t v);\n    mpreal& operator=(const mpz_t v);\n    mpreal& operator=(const mpq_t v);\n    mpreal& operator=(const long double v);\n    mpreal& operator=(const double v);\n    mpreal& operator=(const unsigned long int v);\n    mpreal& operator=(const unsigned long long int v);\n    mpreal& operator=(const long long int v);\n    mpreal& operator=(const unsigned int v);\n    mpreal& operator=(const long int v);\n    mpreal& operator=(const int v);\n    mpreal& operator=(const char* s);\n    mpreal& operator=(const std::string& s);\n    template <typename real_t> mpreal& operator= (const std::complex<real_t>& z);\n\n    // +\n    mpreal& operator+=(const mpreal& v);\n    mpreal& operator+=(const mpf_t v);\n    mpreal& operator+=(const mpz_t v);\n    mpreal& operator+=(const mpq_t v);\n    mpreal& operator+=(const long double u);\n    mpreal& operator+=(const double u);\n    mpreal& operator+=(const unsigned long int u);\n    mpreal& operator+=(const unsigned int u);\n    mpreal& operator+=(const long int u);\n    mpreal& operator+=(const int u);\n\n    mpreal& operator+=(const long long int  u);\n    mpreal& operator+=(const unsigned long long int u);\n    mpreal& operator-=(const long long int  u);\n    mpreal& operator-=(const unsigned long long int u);\n    mpreal& operator*=(const long long int  u);\n    mpreal& operator*=(const unsigned long long int u);\n    mpreal& operator/=(const long long int  u);\n    mpreal& operator/=(const unsigned long long int u);\n\n    const mpreal operator+() const;\n    mpreal& operator++ ();\n    const mpreal  operator++ (int);\n\n    // -\n    mpreal& operator-=(const mpreal& v);\n    mpreal& operator-=(const mpz_t v);\n    mpreal& operator-=(const mpq_t v);\n    mpreal& operator-=(const long double u);\n    mpreal& operator-=(const double u);\n    mpreal& operator-=(const unsigned long int u);\n    mpreal& operator-=(const unsigned int u);\n    mpreal& operator-=(const long int u);\n    mpreal& operator-=(const int u);\n    const mpreal operator-() const;\n    friend const mpreal operator-(const unsigned long int b, const mpreal& a);\n    friend const mpreal operator-(const unsigned int b,      const mpreal& a);\n    friend const mpreal operator-(const long int b,          const mpreal& a);\n    friend const mpreal operator-(const int b,               const mpreal& a);\n    friend const mpreal operator-(const double b,            const mpreal& a);\n    mpreal& operator-- ();\n    const mpreal  operator-- (int);\n\n    // *\n    mpreal& operator*=(const mpreal& v);\n    mpreal& operator*=(const mpz_t v);\n    mpreal& operator*=(const mpq_t v);\n    mpreal& operator*=(const long double v);\n    mpreal& operator*=(const double v);\n    mpreal& operator*=(const unsigned long int v);\n    mpreal& operator*=(const unsigned int v);\n    mpreal& operator*=(const long int v);\n    mpreal& operator*=(const int v);\n\n    // /\n    mpreal& operator/=(const mpreal& v);\n    mpreal& operator/=(const mpz_t v);\n    mpreal& operator/=(const mpq_t v);\n    mpreal& operator/=(const long double v);\n    mpreal& operator/=(const double v);\n    mpreal& operator/=(const unsigned long int v);\n    mpreal& operator/=(const unsigned int v);\n    mpreal& operator/=(const long int v);\n    mpreal& operator/=(const int v);\n    friend const mpreal operator/(const unsigned long int b, const mpreal& a);\n    friend const mpreal operator/(const unsigned int b,      const mpreal& a);\n    friend const mpreal operator/(const long int b,          const mpreal& a);\n    friend const mpreal operator/(const int b,               const mpreal& a);\n    friend const mpreal operator/(const double b,            const mpreal& a);\n\n    //<<= Fast Multiplication by 2^u\n    mpreal& operator<<=(const unsigned long int u);\n    mpreal& operator<<=(const unsigned int u);\n    mpreal& operator<<=(const long int u);\n    mpreal& operator<<=(const int u);\n\n    //>>= Fast Division by 2^u\n    mpreal& operator>>=(const unsigned long int u);\n    mpreal& operator>>=(const unsigned int u);\n    mpreal& operator>>=(const long int u);\n    mpreal& operator>>=(const int u);\n\n    // Type Conversion operators\n    bool               toBool      (                        )    const;\n    long               toLong      (mp_rnd_t mode = GMP_RNDZ)    const;\n    unsigned long      toULong     (mp_rnd_t mode = GMP_RNDZ)    const;\n    long long          toLLong     (mp_rnd_t mode = GMP_RNDZ)    const;\n    unsigned long long toULLong    (mp_rnd_t mode = GMP_RNDZ)    const;\n    float              toFloat     (mp_rnd_t mode = GMP_RNDN)    const;\n    double             toDouble    (mp_rnd_t mode = GMP_RNDN)    const;\n    long double        toLDouble   (mp_rnd_t mode = GMP_RNDN)    const;\n\n#if defined (MPREAL_HAVE_EXPLICIT_CONVERTERS)\n    explicit operator bool               () const { return toBool();                 }\n    explicit operator int                () const { return int(toLong());            }\n    explicit operator long               () const { return toLong();                 }\n    explicit operator long long          () const { return toLLong();                }\n    explicit operator unsigned           () const { return unsigned(toULong());      }\n    explicit operator unsigned long      () const { return toULong();                }\n    explicit operator unsigned long long () const { return toULLong();               }\n    explicit operator float              () const { return toFloat();                }\n    explicit operator double             () const { return toDouble();               }\n    explicit operator long double        () const { return toLDouble();              }\n#endif\n\n    // Get raw pointers so that mpreal can be directly used in raw mpfr_* functions\n    ::mpfr_ptr    mpfr_ptr();\n    ::mpfr_srcptr mpfr_ptr()    const;\n    ::mpfr_srcptr mpfr_srcptr() const;\n\n    // Convert mpreal to string with n significant digits in base b\n    // n = -1 -> convert with the maximum available digits\n    std::string toString(int n = -1, int b = 10, mp_rnd_t mode = mpreal::get_default_rnd()) const;\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n    std::string toString(const std::string& format) const;\n#endif\n\n    std::ostream& output(std::ostream& os) const;\n\n    // Math Functions\n    friend const mpreal sqr (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal sqrt(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal sqrt(const unsigned long int v, mp_rnd_t rnd_mode);\n    friend const mpreal cbrt(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal root(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode);\n    friend const mpreal pow (const mpreal& a, const mpreal& b, mp_rnd_t rnd_mode);\n    friend const mpreal pow (const mpreal& a, const mpz_t b, mp_rnd_t rnd_mode);\n    friend const mpreal pow (const mpreal& a, const unsigned long int b, mp_rnd_t rnd_mode);\n    friend const mpreal pow (const mpreal& a, const long int b, mp_rnd_t rnd_mode);\n    friend const mpreal pow (const unsigned long int a, const mpreal& b, mp_rnd_t rnd_mode);\n    friend const mpreal pow (const unsigned long int a, const unsigned long int b, mp_rnd_t rnd_mode);\n    friend const mpreal fabs(const mpreal& v, mp_rnd_t rnd_mode);\n\n    friend const mpreal abs(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal dim(const mpreal& a, const mpreal& b, mp_rnd_t rnd_mode);\n    friend inline const mpreal mul_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode);\n    friend inline const mpreal mul_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode);\n    friend inline const mpreal div_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode);\n    friend inline const mpreal div_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode);\n    friend int cmpabs(const mpreal& a,const mpreal& b);\n\n    friend const mpreal log  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal log2 (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal logb (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal log10(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal exp  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal exp2 (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal exp10(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal log1p(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal expm1(const mpreal& v, mp_rnd_t rnd_mode);\n\n    friend const mpreal cos(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal sin(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal tan(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal sec(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal csc(const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal cot(const mpreal& v, mp_rnd_t rnd_mode);\n    friend int sin_cos(mpreal& s, mpreal& c, const mpreal& v, mp_rnd_t rnd_mode);\n\n    friend const mpreal acos  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal asin  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal atan  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal atan2 (const mpreal& y, const mpreal& x, mp_rnd_t rnd_mode);\n    friend const mpreal acot  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal asec  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal acsc  (const mpreal& v, mp_rnd_t rnd_mode);\n\n    friend const mpreal cosh  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal sinh  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal tanh  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal sech  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal csch  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal coth  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal acosh (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal asinh (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal atanh (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal acoth (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal asech (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal acsch (const mpreal& v, mp_rnd_t rnd_mode);\n\n    friend const mpreal hypot (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode);\n\n    friend const mpreal fac_ui (unsigned long int v,  mp_prec_t prec, mp_rnd_t rnd_mode);\n    friend const mpreal eint   (const mpreal& v, mp_rnd_t rnd_mode);\n\n    friend const mpreal gamma    (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal tgamma   (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal lngamma  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal lgamma   (const mpreal& v, int *signp, mp_rnd_t rnd_mode);\n    friend const mpreal zeta     (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal erf      (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal erfc     (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal besselj0 (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal besselj1 (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal besseljn (long n, const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal bessely0 (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal bessely1 (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal besselyn (long n, const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal fma      (const mpreal& v1, const mpreal& v2, const mpreal& v3, mp_rnd_t rnd_mode);\n    friend const mpreal fms      (const mpreal& v1, const mpreal& v2, const mpreal& v3, mp_rnd_t rnd_mode);\n    friend const mpreal agm      (const mpreal& v1, const mpreal& v2, mp_rnd_t rnd_mode);\n    friend const mpreal sum      (const mpreal tab[], const unsigned long int n, int& status, mp_rnd_t rnd_mode);\n    friend int sgn(const mpreal& v); // returns -1 or +1\n\n// MPFR 2.4.0 Specifics\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n    friend int          sinh_cosh   (mpreal& s, mpreal& c, const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal li2         (const mpreal& v,                       mp_rnd_t rnd_mode);\n    friend const mpreal fmod        (const mpreal& x, const mpreal& y,      mp_rnd_t rnd_mode);\n    friend const mpreal rec_sqrt    (const mpreal& v,                       mp_rnd_t rnd_mode);\n\n    // MATLAB's semantic equivalents\n    friend const mpreal rem (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode); // Remainder after division\n    friend const mpreal mod (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode); // Modulus after division\n#endif\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))\n    friend const mpreal digamma (const mpreal& v,        mp_rnd_t rnd_mode);\n    friend const mpreal ai      (const mpreal& v,        mp_rnd_t rnd_mode);\n    friend const mpreal urandom (gmp_randstate_t& state, mp_rnd_t rnd_mode);     // use gmp_randinit_default() to init state, gmp_randclear() to clear\n#endif\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,1,0) && MPFR_VERSION < MPFR_VERSION_NUM(4, 0, 0))\n    friend const mpreal grandom (gmp_randstate_t& state, mp_rnd_t rnd_mode);     // use gmp_randinit_default() to init state, gmp_randclear() to clear\n    friend const mpreal grandom (unsigned int seed);\n#endif\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(4,0,0))\n    friend const mpreal nrandom (gmp_randstate_t& state, mp_rnd_t rnd_mode);     // use gmp_randinit_default() to init state, gmp_randclear() to clear\n    friend const mpreal nrandom (unsigned int seed);\n#endif\n\n    // Uniformly distributed random number generation in [0,1] using\n    // Mersenne-Twister algorithm by default.\n    // Use parameter to setup seed, e.g.: random((unsigned)time(NULL))\n    // Check urandom() for more precise control.\n    friend const mpreal random(unsigned int seed);\n\n    // Exponent and mantissa manipulation\n    friend const mpreal frexp (const mpreal& v, mp_exp_t* exp);\n    friend const mpreal ldexp (const mpreal& v, mp_exp_t exp);\n    friend const mpreal scalbn(const mpreal& v, mp_exp_t exp);\n\n    // Splits mpreal value into fractional and integer parts.\n    // Returns fractional part and stores integer part in n.\n    friend const mpreal modf(const mpreal& v, mpreal& n);\n\n    // Constants\n    // don't forget to call mpfr_free_cache() for every thread where you are using const-functions\n    friend const mpreal const_log2      (mp_prec_t prec, mp_rnd_t rnd_mode);\n    friend const mpreal const_pi        (mp_prec_t prec, mp_rnd_t rnd_mode);\n    friend const mpreal const_euler     (mp_prec_t prec, mp_rnd_t rnd_mode);\n    friend const mpreal const_catalan   (mp_prec_t prec, mp_rnd_t rnd_mode);\n\n    // returns +inf iff sign>=0 otherwise -inf\n    friend const mpreal const_infinity(int sign, mp_prec_t prec);\n\n    // Output/ Input\n    friend std::ostream& operator<<(std::ostream& os, const mpreal& v);\n    friend std::istream& operator>>(std::istream& is, mpreal& v);\n\n    // Integer Related Functions\n    friend const mpreal rint (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal ceil (const mpreal& v);\n    friend const mpreal floor(const mpreal& v);\n    friend const mpreal round(const mpreal& v);\n    friend const mpreal trunc(const mpreal& v);\n    friend const mpreal rint_ceil   (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal rint_floor  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal rint_round  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal rint_trunc  (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal frac        (const mpreal& v, mp_rnd_t rnd_mode);\n    friend const mpreal remainder   (         const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode);\n    friend const mpreal remquo      (long* q, const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode);\n\n    // Miscellaneous Functions\n    friend const mpreal nexttoward (const mpreal& x, const mpreal& y);\n    friend const mpreal nextabove  (const mpreal& x);\n    friend const mpreal nextbelow  (const mpreal& x);\n\n    // use gmp_randinit_default() to init state, gmp_randclear() to clear\n    friend const mpreal urandomb (gmp_randstate_t& state);\n\n// MPFR < 2.4.2 Specifics\n#if (MPFR_VERSION <= MPFR_VERSION_NUM(2,4,2))\n    friend const mpreal random2 (mp_size_t size, mp_exp_t exp);\n#endif\n\n    // Instance Checkers\n    friend bool isnan    (const mpreal& v);\n    friend bool isinf    (const mpreal& v);\n    friend bool isfinite (const mpreal& v);\n\n    friend bool isnum    (const mpreal& v);\n    friend bool iszero   (const mpreal& v);\n    friend bool isint    (const mpreal& v);\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))\n    friend bool isregular(const mpreal& v);\n#endif\n\n    // Set/Get instance properties\n    inline mp_prec_t    get_prec() const;\n    inline void         set_prec(mp_prec_t prec, mp_rnd_t rnd_mode = get_default_rnd());    // Change precision with rounding mode\n\n    // Aliases for get_prec(), set_prec() - needed for compatibility with std::complex<mpreal> interface\n    inline mpreal&      setPrecision(int Precision, mp_rnd_t RoundingMode = get_default_rnd());\n    inline int          getPrecision() const;\n\n    // Set mpreal to +/- inf, NaN, +/-0\n    mpreal&        setInf  (int Sign = +1);\n    mpreal&        setNan  ();\n    mpreal&        setZero (int Sign = +1);\n    mpreal&        setSign (int Sign, mp_rnd_t RoundingMode = get_default_rnd());\n\n    //Exponent\n    mp_exp_t get_exp();\n    int set_exp(mp_exp_t e);\n    int check_range  (int t, mp_rnd_t rnd_mode = get_default_rnd());\n    int subnormalize (int t, mp_rnd_t rnd_mode = get_default_rnd());\n\n    // Inexact conversion from float\n    inline bool fits_in_bits(double x, int n);\n\n    // Set/Get global properties\n    static void            set_default_prec(mp_prec_t prec);\n    static void            set_default_rnd(mp_rnd_t rnd_mode);\n\n    static mp_exp_t  get_emin (void);\n    static mp_exp_t  get_emax (void);\n    static mp_exp_t  get_emin_min (void);\n    static mp_exp_t  get_emin_max (void);\n    static mp_exp_t  get_emax_min (void);\n    static mp_exp_t  get_emax_max (void);\n    static int       set_emin (mp_exp_t exp);\n    static int       set_emax (mp_exp_t exp);\n\n    // Efficient swapping of two mpreal values - needed for std algorithms\n    friend void swap(mpreal& x, mpreal& y);\n\n    friend const mpreal fmax(const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode);\n    friend const mpreal fmin(const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode);\n\nprivate:\n    // Human friendly Debug Preview in Visual Studio.\n    // Put one of these lines:\n    //\n    // mpfr::mpreal=<DebugView>                              ; Show value only\n    // mpfr::mpreal=<DebugView>, <mp[0]._mpfr_prec,u>bits    ; Show value & precision\n    //\n    // at the beginning of\n    // [Visual Studio Installation Folder]\\Common7\\Packages\\Debugger\\autoexp.dat\n    MPREAL_MSVC_DEBUGVIEW_DATA\n\n    // \"Smart\" resources deallocation. Checks if instance initialized before deletion.\n    void clear(::mpfr_ptr);\n};\n\n//////////////////////////////////////////////////////////////////////////\n// Exceptions\nclass conversion_overflow : public std::exception {\npublic:\n    std::string why() { return \"inexact conversion from floating point\"; }\n};\n\n//////////////////////////////////////////////////////////////////////////\n// Constructors & converters\n// Default constructor: creates mp number and initializes it to 0.\ninline mpreal::mpreal()\n{\n    mpfr_init2(mpfr_ptr(), mpreal::get_default_prec());\n    mpfr_set_zero_fast(mpfr_ptr());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const mpreal& u)\n{\n    mpfr_init2(mpfr_ptr(),mpfr_get_prec(u.mpfr_srcptr()));\n    mpfr_set  (mpfr_ptr(),u.mpfr_srcptr(),mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\n#ifdef MPREAL_HAVE_MOVE_SUPPORT\ninline mpreal::mpreal(mpreal&& other)\n{\n    mpfr_set_uninitialized(mpfr_ptr());     // make sure \"other\" holds no pointer to actual data\n    mpfr_swap(mpfr_ptr(), other.mpfr_ptr());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal& mpreal::operator=(mpreal&& other)\n{\n    mpfr_swap(mpfr_ptr(), other.mpfr_ptr());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n#endif\n\ninline mpreal::mpreal(const mpfr_t  u, bool shared)\n{\n    if(shared)\n    {\n        std::memcpy(mpfr_ptr(), u, sizeof(mpfr_t));\n    }\n    else\n    {\n        mpfr_init2(mpfr_ptr(), mpfr_get_prec(u));\n        mpfr_set  (mpfr_ptr(), u, mpreal::get_default_rnd());\n    }\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const mpf_t u)\n{\n    mpfr_init2(mpfr_ptr(),(mp_prec_t) mpf_get_prec(u)); // (gmp: mp_bitcnt_t) unsigned long -> long (mpfr: mp_prec_t)\n    mpfr_set_f(mpfr_ptr(),u,mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const mpz_t u, mp_prec_t prec, mp_rnd_t mode)\n{\n    mpfr_init2(mpfr_ptr(), prec);\n    mpfr_set_z(mpfr_ptr(), u, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const mpq_t u, mp_prec_t prec, mp_rnd_t mode)\n{\n    mpfr_init2(mpfr_ptr(), prec);\n    mpfr_set_q(mpfr_ptr(), u, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const double u, mp_prec_t prec, mp_rnd_t mode)\n{\n     mpfr_init2(mpfr_ptr(), prec);\n\n#if (MPREAL_DOUBLE_BITS_OVERFLOW > -1)\n\tif(fits_in_bits(u, MPREAL_DOUBLE_BITS_OVERFLOW))\n\t{\n\t\tmpfr_set_d(mpfr_ptr(), u, mode);\n\t}else\n\t\tthrow conversion_overflow();\n#else\n\tmpfr_set_d(mpfr_ptr(), u, mode);\n#endif\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const long double u, mp_prec_t prec, mp_rnd_t mode)\n{\n    mpfr_init2 (mpfr_ptr(), prec);\n    mpfr_set_ld(mpfr_ptr(), u, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const unsigned long long int u, mp_prec_t prec, mp_rnd_t mode)\n{\n    mpfr_init2 (mpfr_ptr(), prec);\n    mpfr_set_uj(mpfr_ptr(), u, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const long long int u, mp_prec_t prec, mp_rnd_t mode)\n{\n    mpfr_init2 (mpfr_ptr(), prec);\n    mpfr_set_sj(mpfr_ptr(), u, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const unsigned long int u, mp_prec_t prec, mp_rnd_t mode)\n{\n    mpfr_init2 (mpfr_ptr(), prec);\n    mpfr_set_ui(mpfr_ptr(), u, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const unsigned int u, mp_prec_t prec, mp_rnd_t mode)\n{\n    mpfr_init2 (mpfr_ptr(), prec);\n    mpfr_set_ui(mpfr_ptr(), u, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const long int u, mp_prec_t prec, mp_rnd_t mode)\n{\n    mpfr_init2 (mpfr_ptr(), prec);\n    mpfr_set_si(mpfr_ptr(), u, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const int u, mp_prec_t prec, mp_rnd_t mode)\n{\n    mpfr_init2 (mpfr_ptr(), prec);\n    mpfr_set_si(mpfr_ptr(), u, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const char* s, mp_prec_t prec, int base, mp_rnd_t mode)\n{\n    mpfr_init2  (mpfr_ptr(), prec);\n    mpfr_set_str(mpfr_ptr(), s, base, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mpreal::mpreal(const std::string& s, mp_prec_t prec, int base, mp_rnd_t mode)\n{\n    mpfr_init2  (mpfr_ptr(), prec);\n    mpfr_set_str(mpfr_ptr(), s.c_str(), base, mode);\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline void mpreal::clear(::mpfr_ptr x)\n{\n#ifdef MPREAL_HAVE_MOVE_SUPPORT\n    if(mpfr_is_initialized(x))\n#endif\n    mpfr_clear(x);\n}\n\ninline mpreal::~mpreal()\n{\n    clear(mpfr_ptr());\n}\n\n// internal namespace needed for template magic\nnamespace internal{\n\n    // Use SFINAE to restrict arithmetic operations instantiation only for numeric types\n    // This is needed for smooth integration with libraries based on expression templates, like Eigen.\n    // TODO: Do the same for boolean operators.\n    template <typename ArgumentType> struct result_type {};\n\n    template <> struct result_type<mpreal>              {typedef mpreal type;};\n    template <> struct result_type<mpz_t>               {typedef mpreal type;};\n    template <> struct result_type<mpq_t>               {typedef mpreal type;};\n    template <> struct result_type<long double>         {typedef mpreal type;};\n    template <> struct result_type<double>              {typedef mpreal type;};\n    template <> struct result_type<unsigned long int>   {typedef mpreal type;};\n    template <> struct result_type<unsigned int>        {typedef mpreal type;};\n    template <> struct result_type<long int>            {typedef mpreal type;};\n    template <> struct result_type<int>                 {typedef mpreal type;};\n    template <> struct result_type<long long>           {typedef mpreal type;};\n    template <> struct result_type<unsigned long long>  {typedef mpreal type;};\n}\n\n// + Addition\ntemplate <typename Rhs>\ninline const typename internal::result_type<Rhs>::type\n    operator+(const mpreal& lhs, const Rhs& rhs){ return mpreal(lhs) += rhs;    }\n\ntemplate <typename Lhs>\ninline const typename internal::result_type<Lhs>::type\n    operator+(const Lhs& lhs, const mpreal& rhs){ return mpreal(rhs) += lhs;    }\n\n// - Subtraction\ntemplate <typename Rhs>\ninline const typename internal::result_type<Rhs>::type\n    operator-(const mpreal& lhs, const Rhs& rhs){ return mpreal(lhs) -= rhs;    }\n\ntemplate <typename Lhs>\ninline const typename internal::result_type<Lhs>::type\n    operator-(const Lhs& lhs, const mpreal& rhs){ return mpreal(lhs) -= rhs;    }\n\n// * Multiplication\ntemplate <typename Rhs>\ninline const typename internal::result_type<Rhs>::type\n    operator*(const mpreal& lhs, const Rhs& rhs){ return mpreal(lhs) *= rhs;    }\n\ntemplate <typename Lhs>\ninline const typename internal::result_type<Lhs>::type\n    operator*(const Lhs& lhs, const mpreal& rhs){ return mpreal(rhs) *= lhs;    }\n\n// / Division\ntemplate <typename Rhs>\ninline const typename internal::result_type<Rhs>::type\n    operator/(const mpreal& lhs, const Rhs& rhs){ return mpreal(lhs) /= rhs;    }\n\ntemplate <typename Lhs>\ninline const typename internal::result_type<Lhs>::type\n    operator/(const Lhs& lhs, const mpreal& rhs){ return mpreal(lhs) /= rhs;    }\n\n//////////////////////////////////////////////////////////////////////////\n// sqrt\nconst mpreal sqrt(const unsigned int v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal sqrt(const long int v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal sqrt(const int v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal sqrt(const long double v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal sqrt(const double v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\n// abs\ninline const mpreal abs(const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd());\n\n//////////////////////////////////////////////////////////////////////////\n// pow\nconst mpreal pow(const mpreal& a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const mpreal& a, const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const mpreal& a, const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const mpreal& a, const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\nconst mpreal pow(const unsigned int a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long int a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const int a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long double a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const double a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\nconst mpreal pow(const unsigned long int a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const unsigned long int a, const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const unsigned long int a, const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const unsigned long int a, const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const unsigned long int a, const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\nconst mpreal pow(const unsigned int a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const unsigned int a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const unsigned int a, const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const unsigned int a, const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const unsigned int a, const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const unsigned int a, const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\nconst mpreal pow(const long int a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long int a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long int a, const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long int a, const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long int a, const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long int a, const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\nconst mpreal pow(const int a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const int a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const int a, const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const int a, const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const int a, const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const int a, const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\nconst mpreal pow(const long double a, const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long double a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long double a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long double a, const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const long double a, const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\nconst mpreal pow(const double a, const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const double a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const double a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const double a, const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\nconst mpreal pow(const double a, const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\ninline const mpreal mul_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\ninline const mpreal mul_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\ninline const mpreal div_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\ninline const mpreal div_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode = mpreal::get_default_rnd());\n\n//////////////////////////////////////////////////////////////////////////\n// Estimate machine epsilon for the given precision\n// Returns smallest eps such that 1.0 + eps != 1.0\ninline mpreal machine_epsilon(mp_prec_t prec = mpreal::get_default_prec());\n\n// Returns smallest eps such that x + eps != x (relative machine epsilon)\ninline mpreal machine_epsilon(const mpreal& x);\n\n// Gives max & min values for the required precision,\n// minval is 'safe' meaning 1 / minval does not overflow\n// maxval is 'safe' meaning 1 / maxval does not underflow\ninline mpreal minval(mp_prec_t prec = mpreal::get_default_prec());\ninline mpreal maxval(mp_prec_t prec = mpreal::get_default_prec());\n\n// 'Dirty' equality check 1: |a-b| < min{|a|,|b|} * eps\ninline bool isEqualFuzzy(const mpreal& a, const mpreal& b, const mpreal& eps);\n\n// 'Dirty' equality check 2: |a-b| < min{|a|,|b|} * eps( min{|a|,|b|} )\ninline bool isEqualFuzzy(const mpreal& a, const mpreal& b);\n\n// 'Bitwise' equality check\n//  maxUlps - a and b can be apart by maxUlps binary numbers.\ninline bool isEqualUlps(const mpreal& a, const mpreal& b, int maxUlps);\n\n//////////////////////////////////////////////////////////////////////////\n// Convert precision in 'bits' to decimal digits and vice versa.\n//    bits   = ceil(digits*log[2](10))\n//    digits = floor(bits*log[10](2))\n\ninline mp_prec_t digits2bits(int d);\ninline int       bits2digits(mp_prec_t b);\n\n//////////////////////////////////////////////////////////////////////////\n// min, max\nconst mpreal (max)(const mpreal& x, const mpreal& y);\nconst mpreal (min)(const mpreal& x, const mpreal& y);\n\n//////////////////////////////////////////////////////////////////////////\n// Implementation\n//////////////////////////////////////////////////////////////////////////\n\n//////////////////////////////////////////////////////////////////////////\n// Operators - Assignment\ninline mpreal& mpreal::operator=(const mpreal& v)\n{\n    if (this != &v)\n    {\n\t\tmp_prec_t tp = mpfr_get_prec(  mpfr_srcptr());\n\t\tmp_prec_t vp = mpfr_get_prec(v.mpfr_srcptr());\n\n\t\tif(tp != vp){\n\t\t\tclear(mpfr_ptr());\n\t\t\tmpfr_init2(mpfr_ptr(), vp);\n\t\t}\n\n        mpfr_set(mpfr_ptr(), v.mpfr_srcptr(), mpreal::get_default_rnd());\n\n        MPREAL_MSVC_DEBUGVIEW_CODE;\n    }\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const mpf_t v)\n{\n    mpfr_set_f(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const mpz_t v)\n{\n    mpfr_set_z(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const mpq_t v)\n{\n    mpfr_set_q(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const long double v)\n{\n    mpfr_set_ld(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const double v)\n{\n#if (MPREAL_DOUBLE_BITS_OVERFLOW > -1)\n\tif(fits_in_bits(v, MPREAL_DOUBLE_BITS_OVERFLOW))\n\t{\n\t\tmpfr_set_d(mpfr_ptr(),v,mpreal::get_default_rnd());\n\t}else\n\t\tthrow conversion_overflow();\n#else\n\tmpfr_set_d(mpfr_ptr(),v,mpreal::get_default_rnd());\n#endif\n\n\tMPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const unsigned long int v)\n{\n    mpfr_set_ui(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const unsigned int v)\n{\n    mpfr_set_ui(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const unsigned long long int v)\n{\n    mpfr_set_uj(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const long long int v)\n{\n    mpfr_set_sj(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const long int v)\n{\n    mpfr_set_si(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const int v)\n{\n    mpfr_set_si(mpfr_ptr(), v, mpreal::get_default_rnd());\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const char* s)\n{\n    // Use other converters for more precise control on base & precision & rounding:\n    //\n    //        mpreal(const char* s,        mp_prec_t prec, int base, mp_rnd_t mode)\n    //        mpreal(const std::string& s,mp_prec_t prec, int base, mp_rnd_t mode)\n    //\n    // Here we assume base = 10 and we use precision of target variable.\n\n    mpfr_t t;\n\n    mpfr_init2(t, mpfr_get_prec(mpfr_srcptr()));\n\n    if(0 == mpfr_set_str(t, s, 10, mpreal::get_default_rnd()))\n    {\n        mpfr_set(mpfr_ptr(), t, mpreal::get_default_rnd());\n        MPREAL_MSVC_DEBUGVIEW_CODE;\n    }\n\n    clear(t);\n    return *this;\n}\n\ninline mpreal& mpreal::operator=(const std::string& s)\n{\n    // Use other converters for more precise control on base & precision & rounding:\n    //\n    //        mpreal(const char* s,        mp_prec_t prec, int base, mp_rnd_t mode)\n    //        mpreal(const std::string& s,mp_prec_t prec, int base, mp_rnd_t mode)\n    //\n    // Here we assume base = 10 and we use precision of target variable.\n\n    mpfr_t t;\n\n    mpfr_init2(t, mpfr_get_prec(mpfr_srcptr()));\n\n    if(0 == mpfr_set_str(t, s.c_str(), 10, mpreal::get_default_rnd()))\n    {\n        mpfr_set(mpfr_ptr(), t, mpreal::get_default_rnd());\n        MPREAL_MSVC_DEBUGVIEW_CODE;\n    }\n\n    clear(t);\n    return *this;\n}\n\ntemplate <typename real_t>\ninline mpreal& mpreal::operator= (const std::complex<real_t>& z)\n{\n    return *this = z.real();\n}\n\n//////////////////////////////////////////////////////////////////////////\n// + Addition\ninline mpreal& mpreal::operator+=(const mpreal& v)\n{\n    mpfr_add(mpfr_ptr(), mpfr_srcptr(), v.mpfr_srcptr(), mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+=(const mpf_t u)\n{\n    *this += mpreal(u);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+=(const mpz_t u)\n{\n    mpfr_add_z(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+=(const mpq_t u)\n{\n    mpfr_add_q(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+= (const long double u)\n{\n    *this += mpreal(u);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+= (const double u)\n{\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n    mpfr_add_d(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n#else\n    *this += mpreal(u);\n#endif\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+=(const unsigned long int u)\n{\n    mpfr_add_ui(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+=(const unsigned int u)\n{\n    mpfr_add_ui(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+=(const long int u)\n{\n    mpfr_add_si(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+=(const int u)\n{\n    mpfr_add_si(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator+=(const long long int u)         {    *this += mpreal(u); MPREAL_MSVC_DEBUGVIEW_CODE; return *this;    }\ninline mpreal& mpreal::operator+=(const unsigned long long int u){    *this += mpreal(u); MPREAL_MSVC_DEBUGVIEW_CODE; return *this;    }\ninline mpreal& mpreal::operator-=(const long long int  u)        {    *this -= mpreal(u); MPREAL_MSVC_DEBUGVIEW_CODE; return *this;    }\ninline mpreal& mpreal::operator-=(const unsigned long long int u){    *this -= mpreal(u); MPREAL_MSVC_DEBUGVIEW_CODE; return *this;    }\ninline mpreal& mpreal::operator*=(const long long int  u)        {    *this *= mpreal(u); MPREAL_MSVC_DEBUGVIEW_CODE; return *this;    }\ninline mpreal& mpreal::operator*=(const unsigned long long int u){    *this *= mpreal(u); MPREAL_MSVC_DEBUGVIEW_CODE; return *this;    }\ninline mpreal& mpreal::operator/=(const long long int  u)        {    *this /= mpreal(u); MPREAL_MSVC_DEBUGVIEW_CODE; return *this;    }\ninline mpreal& mpreal::operator/=(const unsigned long long int u){    *this /= mpreal(u); MPREAL_MSVC_DEBUGVIEW_CODE; return *this;    }\n\ninline const mpreal mpreal::operator+()const    {    return mpreal(*this); }\n\ninline const mpreal operator+(const mpreal& a, const mpreal& b)\n{\n\tmpreal c(0, (std::max)(mpfr_get_prec(a.mpfr_ptr()), mpfr_get_prec(b.mpfr_ptr())));\n\tmpfr_add(c.mpfr_ptr(), a.mpfr_srcptr(), b.mpfr_srcptr(), mpreal::get_default_rnd());\n\treturn c;\n}\n\ninline mpreal& mpreal::operator++()\n{\n    return *this += 1;\n}\n\ninline const mpreal mpreal::operator++ (int)\n{\n    mpreal x(*this);\n    *this += 1;\n    return x;\n}\n\ninline mpreal& mpreal::operator--()\n{\n    return *this -= 1;\n}\n\ninline const mpreal mpreal::operator-- (int)\n{\n    mpreal x(*this);\n    *this -= 1;\n    return x;\n}\n\n//////////////////////////////////////////////////////////////////////////\n// - Subtraction\ninline mpreal& mpreal::operator-=(const mpreal& v)\n{\n    mpfr_sub(mpfr_ptr(),mpfr_srcptr(),v.mpfr_srcptr(),mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator-=(const mpz_t v)\n{\n    mpfr_sub_z(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator-=(const mpq_t v)\n{\n    mpfr_sub_q(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator-=(const long double v)\n{\n    *this -= mpreal(v);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator-=(const double v)\n{\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n    mpfr_sub_d(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n#else\n    *this -= mpreal(v);\n#endif\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator-=(const unsigned long int v)\n{\n    mpfr_sub_ui(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator-=(const unsigned int v)\n{\n    mpfr_sub_ui(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator-=(const long int v)\n{\n    mpfr_sub_si(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator-=(const int v)\n{\n    mpfr_sub_si(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline const mpreal mpreal::operator-()const\n{\n    mpreal u(*this);\n    mpfr_neg(u.mpfr_ptr(),u.mpfr_srcptr(),mpreal::get_default_rnd());\n    return u;\n}\n\ninline const mpreal operator-(const mpreal& a, const mpreal& b)\n{\n\tmpreal c(0, (std::max)(mpfr_get_prec(a.mpfr_ptr()), mpfr_get_prec(b.mpfr_ptr())));\n\tmpfr_sub(c.mpfr_ptr(), a.mpfr_srcptr(), b.mpfr_srcptr(), mpreal::get_default_rnd());\n\treturn c;\n}\n\ninline const mpreal operator-(const double  b, const mpreal& a)\n{\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n    mpreal x(0, mpfr_get_prec(a.mpfr_ptr()));\n    mpfr_d_sub(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n#else\n    mpreal x(b, mpfr_get_prec(a.mpfr_ptr()));\n    x -= a;\n    return x;\n#endif\n}\n\ninline const mpreal operator-(const unsigned long int b, const mpreal& a)\n{\n    mpreal x(0, mpfr_get_prec(a.mpfr_ptr()));\n    mpfr_ui_sub(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n}\n\ninline const mpreal operator-(const unsigned int b, const mpreal& a)\n{\n    mpreal x(0, mpfr_get_prec(a.mpfr_ptr()));\n    mpfr_ui_sub(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n}\n\ninline const mpreal operator-(const long int b, const mpreal& a)\n{\n    mpreal x(0, mpfr_get_prec(a.mpfr_ptr()));\n    mpfr_si_sub(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n}\n\ninline const mpreal operator-(const int b, const mpreal& a)\n{\n    mpreal x(0, mpfr_get_prec(a.mpfr_ptr()));\n    mpfr_si_sub(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n}\n\n//////////////////////////////////////////////////////////////////////////\n// * Multiplication\ninline mpreal& mpreal::operator*= (const mpreal& v)\n{\n    mpfr_mul(mpfr_ptr(),mpfr_srcptr(),v.mpfr_srcptr(),mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator*=(const mpz_t v)\n{\n    mpfr_mul_z(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator*=(const mpq_t v)\n{\n    mpfr_mul_q(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator*=(const long double v)\n{\n    *this *= mpreal(v);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator*=(const double v)\n{\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n    mpfr_mul_d(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n#else\n    *this *= mpreal(v);\n#endif\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator*=(const unsigned long int v)\n{\n    mpfr_mul_ui(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator*=(const unsigned int v)\n{\n    mpfr_mul_ui(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator*=(const long int v)\n{\n    mpfr_mul_si(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator*=(const int v)\n{\n    mpfr_mul_si(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline const mpreal operator*(const mpreal& a, const mpreal& b)\n{\n\tmpreal c(0, (std::max)(mpfr_get_prec(a.mpfr_ptr()), mpfr_get_prec(b.mpfr_ptr())));\n\tmpfr_mul(c.mpfr_ptr(), a.mpfr_srcptr(), b.mpfr_srcptr(), mpreal::get_default_rnd());\n\treturn c;\n}\n\n//////////////////////////////////////////////////////////////////////////\n// / Division\ninline mpreal& mpreal::operator/=(const mpreal& v)\n{\n    mpfr_div(mpfr_ptr(),mpfr_srcptr(),v.mpfr_srcptr(),mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator/=(const mpz_t v)\n{\n    mpfr_div_z(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator/=(const mpq_t v)\n{\n    mpfr_div_q(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator/=(const long double v)\n{\n    *this /= mpreal(v);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator/=(const double v)\n{\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n    mpfr_div_d(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n#else\n    *this /= mpreal(v);\n#endif\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator/=(const unsigned long int v)\n{\n    mpfr_div_ui(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator/=(const unsigned int v)\n{\n    mpfr_div_ui(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator/=(const long int v)\n{\n    mpfr_div_si(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator/=(const int v)\n{\n    mpfr_div_si(mpfr_ptr(),mpfr_srcptr(),v,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline const mpreal operator/(const mpreal& a, const mpreal& b)\n{\n\tmpreal c(0, (std::max)(mpfr_get_prec(a.mpfr_srcptr()), mpfr_get_prec(b.mpfr_srcptr())));\n\tmpfr_div(c.mpfr_ptr(), a.mpfr_srcptr(), b.mpfr_srcptr(), mpreal::get_default_rnd());\n\treturn c;\n}\n\ninline const mpreal operator/(const unsigned long int b, const mpreal& a)\n{\n    mpreal x(0, mpfr_get_prec(a.mpfr_srcptr()));\n    mpfr_ui_div(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n}\n\ninline const mpreal operator/(const unsigned int b, const mpreal& a)\n{\n    mpreal x(0, mpfr_get_prec(a.mpfr_srcptr()));\n    mpfr_ui_div(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n}\n\ninline const mpreal operator/(const long int b, const mpreal& a)\n{\n    mpreal x(0, mpfr_get_prec(a.mpfr_srcptr()));\n    mpfr_si_div(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n}\n\ninline const mpreal operator/(const int b, const mpreal& a)\n{\n    mpreal x(0, mpfr_get_prec(a.mpfr_srcptr()));\n    mpfr_si_div(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n}\n\ninline const mpreal operator/(const double  b, const mpreal& a)\n{\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n    mpreal x(0, mpfr_get_prec(a.mpfr_srcptr()));\n    mpfr_d_div(x.mpfr_ptr(), b, a.mpfr_srcptr(), mpreal::get_default_rnd());\n    return x;\n#else\n    mpreal x(0, mpfr_get_prec(a.mpfr_ptr()));\n    x /= a;\n    return x;\n#endif\n}\n\n//////////////////////////////////////////////////////////////////////////\n// Shifts operators - Multiplication/Division by power of 2\ninline mpreal& mpreal::operator<<=(const unsigned long int u)\n{\n    mpfr_mul_2ui(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator<<=(const unsigned int u)\n{\n    mpfr_mul_2ui(mpfr_ptr(),mpfr_srcptr(),static_cast<unsigned long int>(u),mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator<<=(const long int u)\n{\n    mpfr_mul_2si(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator<<=(const int u)\n{\n    mpfr_mul_2si(mpfr_ptr(),mpfr_srcptr(),static_cast<long int>(u),mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator>>=(const unsigned long int u)\n{\n    mpfr_div_2ui(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator>>=(const unsigned int u)\n{\n    mpfr_div_2ui(mpfr_ptr(),mpfr_srcptr(),static_cast<unsigned long int>(u),mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator>>=(const long int u)\n{\n    mpfr_div_2si(mpfr_ptr(),mpfr_srcptr(),u,mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::operator>>=(const int u)\n{\n    mpfr_div_2si(mpfr_ptr(),mpfr_srcptr(),static_cast<long int>(u),mpreal::get_default_rnd());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline const mpreal operator<<(const mpreal& v, const unsigned long int k)\n{\n    return mul_2ui(v,k);\n}\n\ninline const mpreal operator<<(const mpreal& v, const unsigned int k)\n{\n    return mul_2ui(v,static_cast<unsigned long int>(k));\n}\n\ninline const mpreal operator<<(const mpreal& v, const long int k)\n{\n    return mul_2si(v,k);\n}\n\ninline const mpreal operator<<(const mpreal& v, const int k)\n{\n    return mul_2si(v,static_cast<long int>(k));\n}\n\ninline const mpreal operator>>(const mpreal& v, const unsigned long int k)\n{\n    return div_2ui(v,k);\n}\n\ninline const mpreal operator>>(const mpreal& v, const long int k)\n{\n    return div_2si(v,k);\n}\n\ninline const mpreal operator>>(const mpreal& v, const unsigned int k)\n{\n    return div_2ui(v,static_cast<unsigned long int>(k));\n}\n\ninline const mpreal operator>>(const mpreal& v, const int k)\n{\n    return div_2si(v,static_cast<long int>(k));\n}\n\n// mul_2ui\ninline const mpreal mul_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode)\n{\n    mpreal x(v);\n    mpfr_mul_2ui(x.mpfr_ptr(),v.mpfr_srcptr(),k,rnd_mode);\n    return x;\n}\n\n// mul_2si\ninline const mpreal mul_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode)\n{\n    mpreal x(v);\n    mpfr_mul_2si(x.mpfr_ptr(),v.mpfr_srcptr(),k,rnd_mode);\n    return x;\n}\n\ninline const mpreal div_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode)\n{\n    mpreal x(v);\n    mpfr_div_2ui(x.mpfr_ptr(),v.mpfr_srcptr(),k,rnd_mode);\n    return x;\n}\n\ninline const mpreal div_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode)\n{\n    mpreal x(v);\n    mpfr_div_2si(x.mpfr_ptr(),v.mpfr_srcptr(),k,rnd_mode);\n    return x;\n}\n\n//////////////////////////////////////////////////////////////////////////\n//Relational operators\n\n// WARNING:\n//\n// Please note that following checks for double-NaN are guaranteed to work only in IEEE math mode:\n//\n// isnan(b) =  (b != b)\n// isnan(b) = !(b == b)  (we use in code below)\n//\n// Be cautions if you use compiler options which break strict IEEE compliance (e.g. -ffast-math in GCC).\n// Use std::isnan instead (C++11).\n\ninline bool operator >  (const mpreal& a, const mpreal& b           ){  return (mpfr_greater_p(a.mpfr_srcptr(),b.mpfr_srcptr()) != 0 );            }\ninline bool operator >  (const mpreal& a, const unsigned long int b ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) > 0 );                 }\ninline bool operator >  (const mpreal& a, const unsigned int b      ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) > 0 );                 }\ninline bool operator >  (const mpreal& a, const long int b          ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) > 0 );                 }\ninline bool operator >  (const mpreal& a, const int b               ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) > 0 );                 }\ninline bool operator >  (const mpreal& a, const long double b       ){  return !isnan(a) && (b == b) && (mpfr_cmp_ld(a.mpfr_srcptr(),b) > 0 );    }\ninline bool operator >  (const mpreal& a, const double b            ){  return !isnan(a) && (b == b) && (mpfr_cmp_d (a.mpfr_srcptr(),b) > 0 );    }\n\ninline bool operator >= (const mpreal& a, const mpreal& b           ){  return (mpfr_greaterequal_p(a.mpfr_srcptr(),b.mpfr_srcptr()) != 0 );       }\ninline bool operator >= (const mpreal& a, const unsigned long int b ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) >= 0 );                }\ninline bool operator >= (const mpreal& a, const unsigned int b      ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) >= 0 );                }\ninline bool operator >= (const mpreal& a, const long int b          ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) >= 0 );                }\ninline bool operator >= (const mpreal& a, const int b               ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) >= 0 );                }\ninline bool operator >= (const mpreal& a, const long double b       ){  return !isnan(a) && (b == b) && (mpfr_cmp_ld(a.mpfr_srcptr(),b) >= 0 );   }\ninline bool operator >= (const mpreal& a, const double b            ){  return !isnan(a) && (b == b) && (mpfr_cmp_d (a.mpfr_srcptr(),b) >= 0 );   }\n\ninline bool operator <  (const mpreal& a, const mpreal& b           ){  return (mpfr_less_p(a.mpfr_srcptr(),b.mpfr_srcptr()) != 0 );               }\ninline bool operator <  (const mpreal& a, const unsigned long int b ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) < 0 );                 }\ninline bool operator <  (const mpreal& a, const unsigned int b      ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) < 0 );                 }\ninline bool operator <  (const mpreal& a, const long int b          ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) < 0 );                 }\ninline bool operator <  (const mpreal& a, const int b               ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) < 0 );                 }\ninline bool operator <  (const mpreal& a, const long double b       ){  return !isnan(a) && (b == b) && (mpfr_cmp_ld(a.mpfr_srcptr(),b) < 0 );    }\ninline bool operator <  (const mpreal& a, const double b            ){  return !isnan(a) && (b == b) && (mpfr_cmp_d (a.mpfr_srcptr(),b) < 0 );    }\n\ninline bool operator <= (const mpreal& a, const mpreal& b           ){  return (mpfr_lessequal_p(a.mpfr_srcptr(),b.mpfr_srcptr()) != 0 );          }\ninline bool operator <= (const mpreal& a, const unsigned long int b ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) <= 0 );                }\ninline bool operator <= (const mpreal& a, const unsigned int b      ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) <= 0 );                }\ninline bool operator <= (const mpreal& a, const long int b          ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) <= 0 );                }\ninline bool operator <= (const mpreal& a, const int b               ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) <= 0 );                }\ninline bool operator <= (const mpreal& a, const long double b       ){  return !isnan(a) && (b == b) && (mpfr_cmp_ld(a.mpfr_srcptr(),b) <= 0 );   }\ninline bool operator <= (const mpreal& a, const double b            ){  return !isnan(a) && (b == b) && (mpfr_cmp_d (a.mpfr_srcptr(),b) <= 0 );   }\n\ninline bool operator == (const mpreal& a, const mpreal& b           ){  return (mpfr_equal_p(a.mpfr_srcptr(),b.mpfr_srcptr()) != 0 );              }\ninline bool operator == (const mpreal& a, const unsigned long int b ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) == 0 );                }\ninline bool operator == (const mpreal& a, const unsigned int b      ){  return !isnan(a) && (mpfr_cmp_ui(a.mpfr_srcptr(),b) == 0 );                }\ninline bool operator == (const mpreal& a, const long int b          ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) == 0 );                }\ninline bool operator == (const mpreal& a, const int b               ){  return !isnan(a) && (mpfr_cmp_si(a.mpfr_srcptr(),b) == 0 );                }\ninline bool operator == (const mpreal& a, const long double b       ){  return !isnan(a) && (b == b) && (mpfr_cmp_ld(a.mpfr_srcptr(),b) == 0 );   }\ninline bool operator == (const mpreal& a, const double b            ){  return !isnan(a) && (b == b) && (mpfr_cmp_d (a.mpfr_srcptr(),b) == 0 );   }\n\ninline bool operator != (const mpreal& a, const mpreal& b           ){  return !(a == b);  }\ninline bool operator != (const mpreal& a, const unsigned long int b ){  return !(a == b);  }\ninline bool operator != (const mpreal& a, const unsigned int b      ){  return !(a == b);  }\ninline bool operator != (const mpreal& a, const long int b          ){  return !(a == b);  }\ninline bool operator != (const mpreal& a, const int b               ){  return !(a == b);  }\ninline bool operator != (const mpreal& a, const long double b       ){  return !(a == b);  }\ninline bool operator != (const mpreal& a, const double b            ){  return !(a == b);  }\n\ninline bool isnan    (const mpreal& op){    return (mpfr_nan_p    (op.mpfr_srcptr()) != 0 );    }\ninline bool isinf    (const mpreal& op){    return (mpfr_inf_p    (op.mpfr_srcptr()) != 0 );    }\ninline bool isfinite (const mpreal& op){    return (mpfr_number_p (op.mpfr_srcptr()) != 0 );    }\ninline bool iszero   (const mpreal& op){    return (mpfr_zero_p   (op.mpfr_srcptr()) != 0 );    }\ninline bool isint    (const mpreal& op){    return (mpfr_integer_p(op.mpfr_srcptr()) != 0 );    }\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))\ninline bool isregular(const mpreal& op){    return (mpfr_regular_p(op.mpfr_srcptr()));}\n#endif\n\n//////////////////////////////////////////////////////////////////////////\n// Type Converters\ninline bool               mpreal::toBool   (             )  const    {    return  mpfr_zero_p (mpfr_srcptr()) == 0;     }\ninline long               mpreal::toLong   (mp_rnd_t mode)  const    {    return  mpfr_get_si (mpfr_srcptr(), mode);    }\ninline unsigned long      mpreal::toULong  (mp_rnd_t mode)  const    {    return  mpfr_get_ui (mpfr_srcptr(), mode);    }\ninline float              mpreal::toFloat  (mp_rnd_t mode)  const    {    return  mpfr_get_flt(mpfr_srcptr(), mode);    }\ninline double             mpreal::toDouble (mp_rnd_t mode)  const    {    return  mpfr_get_d  (mpfr_srcptr(), mode);    }\ninline long double        mpreal::toLDouble(mp_rnd_t mode)  const    {    return  mpfr_get_ld (mpfr_srcptr(), mode);    }\ninline long long          mpreal::toLLong  (mp_rnd_t mode)  const    {    return  mpfr_get_sj (mpfr_srcptr(), mode);    }\ninline unsigned long long mpreal::toULLong (mp_rnd_t mode)  const    {    return  mpfr_get_uj (mpfr_srcptr(), mode);    }\n\ninline ::mpfr_ptr     mpreal::mpfr_ptr()             { return mp; }\ninline ::mpfr_srcptr  mpreal::mpfr_ptr()    const    { return mp; }\ninline ::mpfr_srcptr  mpreal::mpfr_srcptr() const    { return mp; }\n\ntemplate <class T>\ninline std::string toString(T t, std::ios_base & (*f)(std::ios_base&))\n{\n    std::ostringstream oss;\n    oss << f << t;\n    return oss.str();\n}\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n\ninline std::string mpreal::toString(const std::string& format) const\n{\n    char *s = NULL;\n    std::string out;\n\n    if( !format.empty() )\n    {\n        if(!(mpfr_asprintf(&s, format.c_str(), mpfr_srcptr()) < 0))\n        {\n            out = std::string(s);\n\n            mpfr_free_str(s);\n        }\n    }\n\n    return out;\n}\n\n#endif\n\ninline std::string mpreal::toString(int n, int b, mp_rnd_t mode) const\n{\n    // TODO: Add extended format specification (f, e, rounding mode) as it done in output operator\n    (void)b;\n    (void)mode;\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n\n    std::ostringstream format;\n\n    int digits = (n >= 0) ? n : 1 + bits2digits(mpfr_get_prec(mpfr_srcptr()));\n\n    format << \"%.\" << digits << \"RNg\";\n\n    return toString(format.str());\n\n#else\n\n    char *s, *ns = NULL;\n    size_t slen, nslen;\n    mp_exp_t exp;\n    std::string out;\n\n    if(mpfr_inf_p(mp))\n    {\n        if(mpfr_sgn(mp)>0) return \"+Inf\";\n        else               return \"-Inf\";\n    }\n\n    if(mpfr_zero_p(mp)) return \"0\";\n    if(mpfr_nan_p(mp))  return \"NaN\";\n\n    s  = mpfr_get_str(NULL, &exp, b, 0, mp, mode);\n    ns = mpfr_get_str(NULL, &exp, b, (std::max)(0,n), mp, mode);\n\n    if(s!=NULL && ns!=NULL)\n    {\n        slen  = strlen(s);\n        nslen = strlen(ns);\n        if(nslen<=slen)\n        {\n            mpfr_free_str(s);\n            s = ns;\n            slen = nslen;\n        }\n        else {\n            mpfr_free_str(ns);\n        }\n\n        // Make human eye-friendly formatting if possible\n        if (exp>0 && static_cast<size_t>(exp)<slen)\n        {\n            if(s[0]=='-')\n            {\n                // Remove zeros starting from right end\n                char* ptr = s+slen-1;\n                while (*ptr=='0' && ptr>s+exp) ptr--;\n\n                if(ptr==s+exp) out = std::string(s,exp+1);\n                else           out = std::string(s,exp+1)+'.'+std::string(s+exp+1,ptr-(s+exp+1)+1);\n\n                //out = string(s,exp+1)+'.'+string(s+exp+1);\n            }\n            else\n            {\n                // Remove zeros starting from right end\n                char* ptr = s+slen-1;\n                while (*ptr=='0' && ptr>s+exp-1) ptr--;\n\n                if(ptr==s+exp-1) out = std::string(s,exp);\n                else             out = std::string(s,exp)+'.'+std::string(s+exp,ptr-(s+exp)+1);\n\n                //out = string(s,exp)+'.'+string(s+exp);\n            }\n\n        }else{ // exp<0 || exp>slen\n            if(s[0]=='-')\n            {\n                // Remove zeros starting from right end\n                char* ptr = s+slen-1;\n                while (*ptr=='0' && ptr>s+1) ptr--;\n\n                if(ptr==s+1) out = std::string(s,2);\n                else         out = std::string(s,2)+'.'+std::string(s+2,ptr-(s+2)+1);\n\n                //out = string(s,2)+'.'+string(s+2);\n            }\n            else\n            {\n                // Remove zeros starting from right end\n                char* ptr = s+slen-1;\n                while (*ptr=='0' && ptr>s) ptr--;\n\n                if(ptr==s) out = std::string(s,1);\n                else       out = std::string(s,1)+'.'+std::string(s+1,ptr-(s+1)+1);\n\n                //out = string(s,1)+'.'+string(s+1);\n            }\n\n            // Make final string\n            if(--exp)\n            {\n                if(exp>0) out += \"e+\"+mpfr::toString<mp_exp_t>(exp,std::dec);\n                else       out += \"e\"+mpfr::toString<mp_exp_t>(exp,std::dec);\n            }\n        }\n\n        mpfr_free_str(s);\n        return out;\n    }else{\n        return \"conversion error!\";\n    }\n#endif\n}\n\n\n//////////////////////////////////////////////////////////////////////////\n// I/O\ninline std::ostream& mpreal::output(std::ostream& os) const\n{\n    std::ostringstream format;\n    const std::ios::fmtflags flags = os.flags();\n\n    format << ((flags & std::ios::showpos) ? \"%+\" : \"%\");\n    if (os.precision() >= 0)\n        format << '.' << os.precision() << \"R*\"\n               << ((flags & std::ios::floatfield) == std::ios::fixed ? 'f' :\n                   (flags & std::ios::floatfield) == std::ios::scientific ? 'e' :\n                   'g');\n    else\n        format << \"R*e\";\n\n    char *s = NULL;\n    if(!(mpfr_asprintf(&s, format.str().c_str(),\n                        mpfr::mpreal::get_default_rnd(),\n                        mpfr_srcptr())\n        < 0))\n    {\n        os << std::string(s);\n        mpfr_free_str(s);\n    }\n    return os;\n}\n\ninline std::ostream& operator<<(std::ostream& os, const mpreal& v)\n{\n    return v.output(os);\n}\n\ninline std::istream& operator>>(std::istream &is, mpreal& v)\n{\n    // TODO: use cout::hexfloat and other flags to setup base\n    std::string tmp;\n    is >> tmp;\n    mpfr_set_str(v.mpfr_ptr(), tmp.c_str(), 10, mpreal::get_default_rnd());\n    return is;\n}\n\n//////////////////////////////////////////////////////////////////////////\n//     Bits - decimal digits relation\n//        bits   = ceil(digits*log[2](10))\n//        digits = floor(bits*log[10](2))\n\ninline mp_prec_t digits2bits(int d)\n{\n    const double LOG2_10 = 3.3219280948873624;\n\n    return mp_prec_t(std::ceil( d * LOG2_10 ));\n}\n\ninline int bits2digits(mp_prec_t b)\n{\n    const double LOG10_2 = 0.30102999566398119;\n\n    return int(std::floor( b * LOG10_2 ));\n}\n\n//////////////////////////////////////////////////////////////////////////\n// Set/Get number properties\ninline int sgn(const mpreal& op)\n{\n    return mpfr_sgn(op.mpfr_srcptr());\n}\n\ninline mpreal& mpreal::setSign(int sign, mp_rnd_t RoundingMode)\n{\n    mpfr_setsign(mpfr_ptr(), mpfr_srcptr(), (sign < 0 ? 1 : 0), RoundingMode);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline int mpreal::getPrecision() const\n{\n    return int(mpfr_get_prec(mpfr_srcptr()));\n}\n\ninline mpreal& mpreal::setPrecision(int Precision, mp_rnd_t RoundingMode)\n{\n    mpfr_prec_round(mpfr_ptr(), Precision, RoundingMode);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::setInf(int sign)\n{\n    mpfr_set_inf(mpfr_ptr(), sign);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::setNan()\n{\n    mpfr_set_nan(mpfr_ptr());\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mpreal& mpreal::setZero(int sign)\n{\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))\n    mpfr_set_zero(mpfr_ptr(), sign);\n#else\n    mpfr_set_si(mpfr_ptr(), 0, (mpfr_get_default_rounding_mode)());\n    setSign(sign);\n#endif\n\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return *this;\n}\n\ninline mp_prec_t mpreal::get_prec() const\n{\n    return mpfr_get_prec(mpfr_srcptr());\n}\n\ninline void mpreal::set_prec(mp_prec_t prec, mp_rnd_t rnd_mode)\n{\n    mpfr_prec_round(mpfr_ptr(),prec,rnd_mode);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n}\n\ninline mp_exp_t mpreal::get_exp ()\n{\n    return mpfr_get_exp(mpfr_srcptr());\n}\n\ninline int mpreal::set_exp (mp_exp_t e)\n{\n    int x = mpfr_set_exp(mpfr_ptr(), e);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return x;\n}\n\ninline const mpreal frexp(const mpreal& v, mp_exp_t* exp)\n{\n    mpreal x(v);\n    *exp = x.get_exp();\n    x.set_exp(0);\n    return x;\n}\n\ninline const mpreal ldexp(const mpreal& v, mp_exp_t exp)\n{\n    mpreal x(v);\n\n    // rounding is not important since we are just increasing the exponent (= exact operation)\n    mpfr_mul_2si(x.mpfr_ptr(), x.mpfr_srcptr(), exp, mpreal::get_default_rnd());\n    return x;\n}\n\ninline const mpreal scalbn(const mpreal& v, mp_exp_t exp)\n{\n    return ldexp(v, exp);\n}\n\ninline mpreal machine_epsilon(mp_prec_t prec)\n{\n    /* the smallest eps such that 1 + eps != 1 */\n    return machine_epsilon(mpreal(1, prec));\n}\n\ninline mpreal machine_epsilon(const mpreal& x)\n{\n    /* the smallest eps such that x + eps != x */\n    if( x < 0)\n    {\n        return nextabove(-x) + x;\n    }else{\n        return nextabove( x) - x;\n    }\n}\n\n// minval is 'safe' meaning 1 / minval does not overflow\ninline mpreal minval(mp_prec_t prec)\n{\n    /* min = 1/2 * 2^emin = 2^(emin - 1) */\n    return mpreal(1, prec) << mpreal::get_emin()-1;\n}\n\n// maxval is 'safe' meaning 1 / maxval does not underflow\ninline mpreal maxval(mp_prec_t prec)\n{\n    /* max = (1 - eps) * 2^emax, eps is machine epsilon */\n    return (mpreal(1, prec) - machine_epsilon(prec)) << mpreal::get_emax();\n}\n\ninline bool isEqualUlps(const mpreal& a, const mpreal& b, int maxUlps)\n{\n    return abs(a - b) <= machine_epsilon((max)(abs(a), abs(b))) * maxUlps;\n}\n\ninline bool isEqualFuzzy(const mpreal& a, const mpreal& b, const mpreal& eps)\n{\n    return abs(a - b) <= eps;\n}\n\ninline bool isEqualFuzzy(const mpreal& a, const mpreal& b)\n{\n    return isEqualFuzzy(a, b, machine_epsilon((max)(1, (min)(abs(a), abs(b)))));\n}\n\n//////////////////////////////////////////////////////////////////////////\n// C++11 sign functions.\ninline mpreal copysign(const mpreal& x, const  mpreal& y, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal rop(0, mpfr_get_prec(x.mpfr_ptr()));\n    mpfr_setsign(rop.mpfr_ptr(), x.mpfr_srcptr(), mpfr_signbit(y.mpfr_srcptr()), rnd_mode);\n    return rop;\n}\n\ninline bool signbit(const mpreal& x)\n{\n    return mpfr_signbit(x.mpfr_srcptr());\n}\n\ninline const mpreal modf(const mpreal& v, mpreal& n)\n{\n    mpreal f(v);\n\n    // rounding is not important since we are using the same number\n    mpfr_frac (f.mpfr_ptr(),f.mpfr_srcptr(),mpreal::get_default_rnd());\n    mpfr_trunc(n.mpfr_ptr(),v.mpfr_srcptr());\n    return f;\n}\n\ninline int mpreal::check_range (int t, mp_rnd_t rnd_mode)\n{\n    return mpfr_check_range(mpfr_ptr(),t,rnd_mode);\n}\n\ninline int mpreal::subnormalize (int t,mp_rnd_t rnd_mode)\n{\n    int r = mpfr_subnormalize(mpfr_ptr(),t,rnd_mode);\n    MPREAL_MSVC_DEBUGVIEW_CODE;\n    return r;\n}\n\ninline mp_exp_t mpreal::get_emin (void)\n{\n    return mpfr_get_emin();\n}\n\ninline int mpreal::set_emin (mp_exp_t exp)\n{\n    return mpfr_set_emin(exp);\n}\n\ninline mp_exp_t mpreal::get_emax (void)\n{\n    return mpfr_get_emax();\n}\n\ninline int mpreal::set_emax (mp_exp_t exp)\n{\n    return mpfr_set_emax(exp);\n}\n\ninline mp_exp_t mpreal::get_emin_min (void)\n{\n    return mpfr_get_emin_min();\n}\n\ninline mp_exp_t mpreal::get_emin_max (void)\n{\n    return mpfr_get_emin_max();\n}\n\ninline mp_exp_t mpreal::get_emax_min (void)\n{\n    return mpfr_get_emax_min();\n}\n\ninline mp_exp_t mpreal::get_emax_max (void)\n{\n    return mpfr_get_emax_max();\n}\n\n//////////////////////////////////////////////////////////////////////////\n// Mathematical Functions\n//////////////////////////////////////////////////////////////////////////\n#define MPREAL_UNARY_MATH_FUNCTION_BODY(f)                    \\\n        mpreal y(0, mpfr_get_prec(x.mpfr_srcptr()));          \\\n        mpfr_##f(y.mpfr_ptr(), x.mpfr_srcptr(), r);           \\\n        return y;\n\ninline const mpreal sqr  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd())\n{   MPREAL_UNARY_MATH_FUNCTION_BODY(sqr );    }\n\ninline const mpreal sqrt (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd())\n{   MPREAL_UNARY_MATH_FUNCTION_BODY(sqrt);    }\n\ninline const mpreal sqrt(const unsigned long int x, mp_rnd_t r)\n{\n    mpreal y;\n    mpfr_sqrt_ui(y.mpfr_ptr(), x, r);\n    return y;\n}\n\ninline const mpreal sqrt(const unsigned int v, mp_rnd_t rnd_mode)\n{\n    return sqrt(static_cast<unsigned long int>(v),rnd_mode);\n}\n\ninline const mpreal sqrt(const long int v, mp_rnd_t rnd_mode)\n{\n    if (v>=0)   return sqrt(static_cast<unsigned long int>(v),rnd_mode);\n    else        return mpreal().setNan(); // NaN\n}\n\ninline const mpreal sqrt(const int v, mp_rnd_t rnd_mode)\n{\n    if (v>=0)   return sqrt(static_cast<unsigned long int>(v),rnd_mode);\n    else        return mpreal().setNan(); // NaN\n}\n\ninline const mpreal root(const mpreal& x, unsigned long int k, mp_rnd_t r = mpreal::get_default_rnd())\n{\n    mpreal y(0, mpfr_get_prec(x.mpfr_srcptr()));\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(4,0,0))\n    mpfr_rootn_ui(y.mpfr_ptr(), x.mpfr_srcptr(), k, r);\n#else\n    mpfr_root(y.mpfr_ptr(), x.mpfr_srcptr(), k, r);\n#endif\n    return y;\n}\n\ninline const mpreal dim(const mpreal& a, const mpreal& b, mp_rnd_t r = mpreal::get_default_rnd())\n{\n    mpreal y(0, mpfr_get_prec(a.mpfr_srcptr()));\n    mpfr_dim(y.mpfr_ptr(), a.mpfr_srcptr(), b.mpfr_srcptr(), r);\n    return y;\n}\n\ninline int cmpabs(const mpreal& a,const mpreal& b)\n{\n    return mpfr_cmpabs(a.mpfr_ptr(), b.mpfr_srcptr());\n}\n\ninline int sin_cos(mpreal& s, mpreal& c, const mpreal& v, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    return mpfr_sin_cos(s.mpfr_ptr(), c.mpfr_ptr(), v.mpfr_srcptr(), rnd_mode);\n}\n\ninline const mpreal sqrt  (const long double v, mp_rnd_t rnd_mode)    {   return sqrt(mpreal(v),rnd_mode);    }\ninline const mpreal sqrt  (const double v, mp_rnd_t rnd_mode)         {   return sqrt(mpreal(v),rnd_mode);    }\n\ninline const mpreal cbrt  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(cbrt );    }\ninline const mpreal fabs  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(abs  );    }\ninline const mpreal abs   (const mpreal& x, mp_rnd_t r)                             {   MPREAL_UNARY_MATH_FUNCTION_BODY(abs  );    }\ninline const mpreal log   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(log  );    }\ninline const mpreal log2  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(log2 );    }\ninline const mpreal log10 (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(log10);    }\ninline const mpreal exp   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(exp  );    }\ninline const mpreal exp2  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(exp2 );    }\ninline const mpreal exp10 (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(exp10);    }\ninline const mpreal cos   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(cos  );    }\ninline const mpreal sin   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(sin  );    }\ninline const mpreal tan   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(tan  );    }\ninline const mpreal sec   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(sec  );    }\ninline const mpreal csc   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(csc  );    }\ninline const mpreal cot   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(cot  );    }\ninline const mpreal acos  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(acos );    }\ninline const mpreal asin  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(asin );    }\ninline const mpreal atan  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(atan );    }\n\ninline const mpreal logb  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   return log2 (abs(x),r);                    }\n\ninline const mpreal acot  (const mpreal& v, mp_rnd_t r = mpreal::get_default_rnd()) {   return atan (1/v, r);                      }\ninline const mpreal asec  (const mpreal& v, mp_rnd_t r = mpreal::get_default_rnd()) {   return acos (1/v, r);                      }\ninline const mpreal acsc  (const mpreal& v, mp_rnd_t r = mpreal::get_default_rnd()) {   return asin (1/v, r);                      }\ninline const mpreal acoth (const mpreal& v, mp_rnd_t r = mpreal::get_default_rnd()) {   return atanh(1/v, r);                      }\ninline const mpreal asech (const mpreal& v, mp_rnd_t r = mpreal::get_default_rnd()) {   return acosh(1/v, r);                      }\ninline const mpreal acsch (const mpreal& v, mp_rnd_t r = mpreal::get_default_rnd()) {   return asinh(1/v, r);                      }\n\ninline const mpreal cosh  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(cosh );    }\ninline const mpreal sinh  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(sinh );    }\ninline const mpreal tanh  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(tanh );    }\ninline const mpreal sech  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(sech );    }\ninline const mpreal csch  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(csch );    }\ninline const mpreal coth  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(coth );    }\ninline const mpreal acosh (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(acosh);    }\ninline const mpreal asinh (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(asinh);    }\ninline const mpreal atanh (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(atanh);    }\n\ninline const mpreal log1p   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(log1p  );    }\ninline const mpreal expm1   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(expm1  );    }\ninline const mpreal eint    (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(eint   );    }\ninline const mpreal gamma   (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(gamma  );    }\ninline const mpreal tgamma  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(gamma  );    }\ninline const mpreal lngamma (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(lngamma);    }\ninline const mpreal zeta    (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(zeta   );    }\ninline const mpreal erf     (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(erf    );    }\ninline const mpreal erfc    (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(erfc   );    }\ninline const mpreal besselj0(const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(j0     );    }\ninline const mpreal besselj1(const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(j1     );    }\ninline const mpreal bessely0(const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(y0     );    }\ninline const mpreal bessely1(const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(y1     );    }\n\ninline const mpreal atan2 (const mpreal& y, const mpreal& x, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a(0,(std::max)(y.getPrecision(), x.getPrecision()));\n    mpfr_atan2(a.mpfr_ptr(), y.mpfr_srcptr(), x.mpfr_srcptr(), rnd_mode);\n    return a;\n}\n\ninline const mpreal hypot (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a(0,(std::max)(y.getPrecision(), x.getPrecision()));\n    mpfr_hypot(a.mpfr_ptr(), x.mpfr_srcptr(), y.mpfr_srcptr(), rnd_mode);\n    return a;\n}\n\ninline const mpreal remainder (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a(0,(std::max)(y.getPrecision(), x.getPrecision()));\n    mpfr_remainder(a.mpfr_ptr(), x.mpfr_srcptr(), y.mpfr_srcptr(), rnd_mode);\n    return a;\n}\n\ninline const mpreal remquo (long* q, const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a(0,(std::max)(y.getPrecision(), x.getPrecision()));\n    mpfr_remquo(a.mpfr_ptr(),q, x.mpfr_srcptr(), y.mpfr_srcptr(), rnd_mode);\n    return a;\n}\n\ninline const mpreal fac_ui (unsigned long int v, mp_prec_t prec     = mpreal::get_default_prec(),\n\t\t\t                                     mp_rnd_t  rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x(0, prec);\n    mpfr_fac_ui(x.mpfr_ptr(),v,rnd_mode);\n    return x;\n}\n\n\ninline const mpreal lgamma (const mpreal& v, int *signp = 0, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x(v);\n    int tsignp;\n\n    if(signp)   mpfr_lgamma(x.mpfr_ptr(),  signp,v.mpfr_srcptr(),rnd_mode);\n    else        mpfr_lgamma(x.mpfr_ptr(),&tsignp,v.mpfr_srcptr(),rnd_mode);\n\n    return x;\n}\n\n\ninline const mpreal besseljn (long n, const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd())\n{\n    mpreal  y(0, x.getPrecision());\n    mpfr_jn(y.mpfr_ptr(), n, x.mpfr_srcptr(), r);\n    return y;\n}\n\ninline const mpreal besselyn (long n, const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd())\n{\n    mpreal  y(0, x.getPrecision());\n    mpfr_yn(y.mpfr_ptr(), n, x.mpfr_srcptr(), r);\n    return y;\n}\n\ninline const mpreal fma (const mpreal& v1, const mpreal& v2, const mpreal& v3, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a;\n    mp_prec_t p1, p2, p3;\n\n    p1 = v1.get_prec();\n    p2 = v2.get_prec();\n    p3 = v3.get_prec();\n\n    a.set_prec(p3>p2?(p3>p1?p3:p1):(p2>p1?p2:p1));\n\n    mpfr_fma(a.mp,v1.mp,v2.mp,v3.mp,rnd_mode);\n    return a;\n}\n\ninline const mpreal fms (const mpreal& v1, const mpreal& v2, const mpreal& v3, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a;\n    mp_prec_t p1, p2, p3;\n\n    p1 = v1.get_prec();\n    p2 = v2.get_prec();\n    p3 = v3.get_prec();\n\n    a.set_prec(p3>p2?(p3>p1?p3:p1):(p2>p1?p2:p1));\n\n    mpfr_fms(a.mp,v1.mp,v2.mp,v3.mp,rnd_mode);\n    return a;\n}\n\ninline const mpreal agm (const mpreal& v1, const mpreal& v2, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a;\n    mp_prec_t p1, p2;\n\n    p1 = v1.get_prec();\n    p2 = v2.get_prec();\n\n    a.set_prec(p1>p2?p1:p2);\n\n    mpfr_agm(a.mp, v1.mp, v2.mp, rnd_mode);\n\n    return a;\n}\n\ninline const mpreal sum (const mpreal tab[], const unsigned long int n, int& status, mp_rnd_t mode = mpreal::get_default_rnd())\n{\n    mpfr_srcptr *p = new mpfr_srcptr[n];\n\n    for (unsigned long int  i = 0; i < n; i++)\n        p[i] = tab[i].mpfr_srcptr();\n\n    mpreal x;\n    status = mpfr_sum(x.mpfr_ptr(), (mpfr_ptr*)p, n, mode);\n\n    delete [] p;\n    return x;\n}\n\n//////////////////////////////////////////////////////////////////////////\n// MPFR 2.4.0 Specifics\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))\n\ninline int sinh_cosh(mpreal& s, mpreal& c, const mpreal& v, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    return mpfr_sinh_cosh(s.mp,c.mp,v.mp,rnd_mode);\n}\n\ninline const mpreal li2 (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd())\n{\n    MPREAL_UNARY_MATH_FUNCTION_BODY(li2);\n}\n\ninline const mpreal rem (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    /*  R = rem(X,Y) if Y != 0, returns X - n * Y where n = trunc(X/Y). */\n    return fmod(x, y, rnd_mode);\n}\n\ninline const mpreal mod (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    (void)rnd_mode;\n\n    /*\n\n    m = mod(x,y) if y != 0, returns x - n*y where n = floor(x/y)\n\n    The following are true by convention:\n    - mod(x,0) is x\n    - mod(x,x) is 0\n    - mod(x,y) for x != y and y != 0 has the same sign as y.\n\n    */\n\n    if(iszero(y)) return x;\n    if(x == y) return 0;\n\n    mpreal m = x - floor(x / y) * y;\n\n    m.setSign(sgn(y)); // make sure result has the same sign as Y\n\n    return m;\n}\n\ninline const mpreal fmod (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a;\n    mp_prec_t yp, xp;\n\n    yp = y.get_prec();\n    xp = x.get_prec();\n\n    a.set_prec(yp>xp?yp:xp);\n\n    mpfr_fmod(a.mp, x.mp, y.mp, rnd_mode);\n\n    return a;\n}\n\ninline const mpreal rec_sqrt(const mpreal& v, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x(v);\n    mpfr_rec_sqrt(x.mp,v.mp,rnd_mode);\n    return x;\n}\n#endif //  MPFR 2.4.0 Specifics\n\n//////////////////////////////////////////////////////////////////////////\n// MPFR 3.0.0 Specifics\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))\ninline const mpreal digamma (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(digamma);     }\ninline const mpreal ai      (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(ai);          }\n#endif // MPFR 3.0.0 Specifics\n\n//////////////////////////////////////////////////////////////////////////\n// Constants\ninline const mpreal const_log2 (mp_prec_t p = mpreal::get_default_prec(), mp_rnd_t r = mpreal::get_default_rnd())\n{\n    mpreal x(0, p);\n    mpfr_const_log2(x.mpfr_ptr(), r);\n    return x;\n}\n\ninline const mpreal const_pi (mp_prec_t p = mpreal::get_default_prec(), mp_rnd_t r = mpreal::get_default_rnd())\n{\n    mpreal x(0, p);\n    mpfr_const_pi(x.mpfr_ptr(), r);\n    return x;\n}\n\ninline const mpreal const_euler (mp_prec_t p = mpreal::get_default_prec(), mp_rnd_t r = mpreal::get_default_rnd())\n{\n    mpreal x(0, p);\n    mpfr_const_euler(x.mpfr_ptr(), r);\n    return x;\n}\n\ninline const mpreal const_catalan (mp_prec_t p = mpreal::get_default_prec(), mp_rnd_t r = mpreal::get_default_rnd())\n{\n    mpreal x(0, p);\n    mpfr_const_catalan(x.mpfr_ptr(), r);\n    return x;\n}\n\ninline const mpreal const_infinity (int sign = 1, mp_prec_t p = mpreal::get_default_prec())\n{\n    mpreal x(0, p);\n    mpfr_set_inf(x.mpfr_ptr(), sign);\n    return x;\n}\n\n//////////////////////////////////////////////////////////////////////////\n// Integer Related Functions\ninline const mpreal ceil(const mpreal& v)\n{\n    mpreal x(v);\n    mpfr_ceil(x.mp,v.mp);\n    return x;\n}\n\ninline const mpreal floor(const mpreal& v)\n{\n    mpreal x(v);\n    mpfr_floor(x.mp,v.mp);\n    return x;\n}\n\ninline const mpreal round(const mpreal& v)\n{\n    mpreal x(v);\n    mpfr_round(x.mp,v.mp);\n    return x;\n}\n\ninline const mpreal trunc(const mpreal& v)\n{\n    mpreal x(v);\n    mpfr_trunc(x.mp,v.mp);\n    return x;\n}\n\ninline const mpreal rint       (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(rint      );     }\ninline const mpreal rint_ceil  (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(rint_ceil );     }\ninline const mpreal rint_floor (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(rint_floor);     }\ninline const mpreal rint_round (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(rint_round);     }\ninline const mpreal rint_trunc (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(rint_trunc);     }\ninline const mpreal frac       (const mpreal& x, mp_rnd_t r = mpreal::get_default_rnd()) {   MPREAL_UNARY_MATH_FUNCTION_BODY(frac      );     }\n\n//////////////////////////////////////////////////////////////////////////\n// Miscellaneous Functions\ninline void         swap (mpreal& a, mpreal& b)            {    mpfr_swap(a.mp,b.mp);   }\ninline const mpreal (max)(const mpreal& x, const mpreal& y){    return (x>y?x:y);       }\ninline const mpreal (min)(const mpreal& x, const mpreal& y){    return (x<y?x:y);       }\n\ninline const mpreal fmax(const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a;\n    mpfr_max(a.mp,x.mp,y.mp,rnd_mode);\n    return a;\n}\n\ninline const mpreal fmin(const mpreal& x, const mpreal& y,  mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal a;\n    mpfr_min(a.mp,x.mp,y.mp,rnd_mode);\n    return a;\n}\n\ninline const mpreal nexttoward (const mpreal& x, const mpreal& y)\n{\n    mpreal a(x);\n    mpfr_nexttoward(a.mp,y.mp);\n    return a;\n}\n\ninline const mpreal nextabove  (const mpreal& x)\n{\n    mpreal a(x);\n    mpfr_nextabove(a.mp);\n    return a;\n}\n\ninline const mpreal nextbelow  (const mpreal& x)\n{\n    mpreal a(x);\n    mpfr_nextbelow(a.mp);\n    return a;\n}\n\ninline const mpreal urandomb (gmp_randstate_t& state)\n{\n    mpreal x;\n    mpfr_urandomb(x.mpfr_ptr(),state);\n    return x;\n}\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))\ninline const mpreal urandom (gmp_randstate_t& state, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x;\n    mpfr_urandom(x.mpfr_ptr(), state, rnd_mode);\n    return x;\n}\n#endif\n\n#if (MPFR_VERSION <= MPFR_VERSION_NUM(2,4,2))\ninline const mpreal random2 (mp_size_t size, mp_exp_t exp)\n{\n    mpreal x;\n    mpfr_random2(x.mpfr_ptr(),size,exp);\n    return x;\n}\n#endif\n\n// Uniformly distributed random number generation\n// a = random(seed); <- initialization & first random number generation\n// a = random();     <- next random numbers generation\n// seed != 0\ninline const mpreal random(unsigned int seed = 0)\n{\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))\n    static gmp_randstate_t state;\n    static bool initialize = true;\n\n    if(initialize)\n    {\n        gmp_randinit_default(state);\n        gmp_randseed_ui(state,0);\n        initialize = false;\n    }\n\n    if(seed != 0)    gmp_randseed_ui(state,seed);\n\n    return mpfr::urandom(state);\n#else\n    if(seed != 0)    std::srand(seed);\n    return mpfr::mpreal(std::rand()/(double)RAND_MAX);\n#endif\n\n}\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,1,0) && MPFR_VERSION < MPFR_VERSION_NUM(4, 0, 0))\ninline const mpreal grandom (gmp_randstate_t& state, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x;\n    mpfr_grandom(x.mpfr_ptr(), NULL, state, rnd_mode);\n    return x;\n}\n\ninline const mpreal grandom(unsigned int seed = 0)\n{\n    static gmp_randstate_t state;\n    static bool initialize = true;\n\n    if(initialize)\n    {\n        gmp_randinit_default(state);\n        gmp_randseed_ui(state,0);\n        initialize = false;\n    }\n\n    if(seed != 0) gmp_randseed_ui(state,seed);\n\n    return mpfr::grandom(state);\n}\n#endif\n\n#if (MPFR_VERSION >= MPFR_VERSION_NUM(4,0,0))\ninline const mpreal nrandom (gmp_randstate_t& state, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x;\n    mpfr_nrandom(x.mpfr_ptr(), state, rnd_mode);\n    return x;\n}\n\ninline const mpreal nrandom(unsigned int seed = 0)\n{\n    static gmp_randstate_t state;\n    static bool initialize = true;\n\n    if(initialize)\n    {\n        gmp_randinit_default(state);\n        gmp_randseed_ui(state,0);\n        initialize = false;\n    }\n\n    if(seed != 0) gmp_randseed_ui(state,seed);\n\n    return mpfr::nrandom(state);\n}\n#endif\n\n//////////////////////////////////////////////////////////////////////////\n// Set/Get global properties\ninline void mpreal::set_default_prec(mp_prec_t prec)\n{\n    mpfr_set_default_prec(prec);\n}\n\ninline void mpreal::set_default_rnd(mp_rnd_t rnd_mode)\n{\n    mpfr_set_default_rounding_mode(rnd_mode);\n}\n\ninline bool mpreal::fits_in_bits(double x, int n)\n{\n    int i;\n    double t;\n    return IsInf(x) || (std::modf ( std::ldexp ( std::frexp ( x, &i ), n ), &t ) == 0.0);\n}\n\ninline const mpreal pow(const mpreal& a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x(a);\n    mpfr_pow(x.mp,x.mp,b.mp,rnd_mode);\n    return x;\n}\n\ninline const mpreal pow(const mpreal& a, const mpz_t b, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x(a);\n    mpfr_pow_z(x.mp,x.mp,b,rnd_mode);\n    return x;\n}\n\ninline const mpreal pow(const mpreal& a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x(a);\n    mpfr_pow_ui(x.mp,x.mp,b,rnd_mode);\n    return x;\n}\n\ninline const mpreal pow(const mpreal& a, const unsigned int b, mp_rnd_t rnd_mode)\n{\n    return pow(a,static_cast<unsigned long int>(b),rnd_mode);\n}\n\ninline const mpreal pow(const mpreal& a, const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x(a);\n    mpfr_pow_si(x.mp,x.mp,b,rnd_mode);\n    return x;\n}\n\ninline const mpreal pow(const mpreal& a, const int b, mp_rnd_t rnd_mode)\n{\n    return pow(a,static_cast<long int>(b),rnd_mode);\n}\n\ninline const mpreal pow(const mpreal& a, const long double b, mp_rnd_t rnd_mode)\n{\n    return pow(a,mpreal(b),rnd_mode);\n}\n\ninline const mpreal pow(const mpreal& a, const double b, mp_rnd_t rnd_mode)\n{\n    return pow(a,mpreal(b),rnd_mode);\n}\n\ninline const mpreal pow(const unsigned long int a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd())\n{\n    mpreal x(a);\n    mpfr_ui_pow(x.mp,a,b.mp,rnd_mode);\n    return x;\n}\n\ninline const mpreal pow(const unsigned int a, const mpreal& b, mp_rnd_t rnd_mode)\n{\n    return pow(static_cast<unsigned long int>(a),b,rnd_mode);\n}\n\ninline const mpreal pow(const long int a, const mpreal& b, mp_rnd_t rnd_mode)\n{\n    if (a>=0)     return pow(static_cast<unsigned long int>(a),b,rnd_mode);\n    else          return pow(mpreal(a),b,rnd_mode);\n}\n\ninline const mpreal pow(const int a, const mpreal& b, mp_rnd_t rnd_mode)\n{\n    if (a>=0)     return pow(static_cast<unsigned long int>(a),b,rnd_mode);\n    else          return pow(mpreal(a),b,rnd_mode);\n}\n\ninline const mpreal pow(const long double a, const mpreal& b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),b,rnd_mode);\n}\n\ninline const mpreal pow(const double a, const mpreal& b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),b,rnd_mode);\n}\n\n// pow unsigned long int\ninline const mpreal pow(const unsigned long int a, const unsigned long int b, mp_rnd_t rnd_mode)\n{\n    mpreal x(a);\n    mpfr_ui_pow_ui(x.mp,a,b,rnd_mode);\n    return x;\n}\n\ninline const mpreal pow(const unsigned long int a, const unsigned int b, mp_rnd_t rnd_mode)\n{\n    return pow(a,static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n}\n\ninline const mpreal pow(const unsigned long int a, const long int b, mp_rnd_t rnd_mode)\n{\n    if(b>0)    return pow(a,static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n    else       return pow(a,mpreal(b),rnd_mode); //mpfr_ui_pow\n}\n\ninline const mpreal pow(const unsigned long int a, const int b, mp_rnd_t rnd_mode)\n{\n    if(b>0)    return pow(a,static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n    else       return pow(a,mpreal(b),rnd_mode); //mpfr_ui_pow\n}\n\ninline const mpreal pow(const unsigned long int a, const long double b, mp_rnd_t rnd_mode)\n{\n    return pow(a,mpreal(b),rnd_mode); //mpfr_ui_pow\n}\n\ninline const mpreal pow(const unsigned long int a, const double b, mp_rnd_t rnd_mode)\n{\n    return pow(a,mpreal(b),rnd_mode); //mpfr_ui_pow\n}\n\n// pow unsigned int\ninline const mpreal pow(const unsigned int a, const unsigned long int b, mp_rnd_t rnd_mode)\n{\n    return pow(static_cast<unsigned long int>(a),b,rnd_mode); //mpfr_ui_pow_ui\n}\n\ninline const mpreal pow(const unsigned int a, const unsigned int b, mp_rnd_t rnd_mode)\n{\n    return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n}\n\ninline const mpreal pow(const unsigned int a, const long int b, mp_rnd_t rnd_mode)\n{\n    if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n    else    return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n}\n\ninline const mpreal pow(const unsigned int a, const int b, mp_rnd_t rnd_mode)\n{\n    if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n    else    return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n}\n\ninline const mpreal pow(const unsigned int a, const long double b, mp_rnd_t rnd_mode)\n{\n    return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n}\n\ninline const mpreal pow(const unsigned int a, const double b, mp_rnd_t rnd_mode)\n{\n    return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n}\n\n// pow long int\ninline const mpreal pow(const long int a, const unsigned long int b, mp_rnd_t rnd_mode)\n{\n    if (a>0) return pow(static_cast<unsigned long int>(a),b,rnd_mode); //mpfr_ui_pow_ui\n    else     return pow(mpreal(a),b,rnd_mode); //mpfr_pow_ui\n}\n\ninline const mpreal pow(const long int a, const unsigned int b, mp_rnd_t rnd_mode)\n{\n    if (a>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);  //mpfr_ui_pow_ui\n    else     return pow(mpreal(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_pow_ui\n}\n\ninline const mpreal pow(const long int a, const long int b, mp_rnd_t rnd_mode)\n{\n    if (a>0)\n    {\n        if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n        else    return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n    }else{\n        return pow(mpreal(a),b,rnd_mode); // mpfr_pow_si\n    }\n}\n\ninline const mpreal pow(const long int a, const int b, mp_rnd_t rnd_mode)\n{\n    if (a>0)\n    {\n        if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n        else    return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n    }else{\n        return pow(mpreal(a),static_cast<long int>(b),rnd_mode); // mpfr_pow_si\n    }\n}\n\ninline const mpreal pow(const long int a, const long double b, mp_rnd_t rnd_mode)\n{\n    if (a>=0)   return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n    else        return pow(mpreal(a),mpreal(b),rnd_mode); //mpfr_pow\n}\n\ninline const mpreal pow(const long int a, const double b, mp_rnd_t rnd_mode)\n{\n    if (a>=0)   return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n    else        return pow(mpreal(a),mpreal(b),rnd_mode); //mpfr_pow\n}\n\n// pow int\ninline const mpreal pow(const int a, const unsigned long int b, mp_rnd_t rnd_mode)\n{\n    if (a>0) return pow(static_cast<unsigned long int>(a),b,rnd_mode); //mpfr_ui_pow_ui\n    else     return pow(mpreal(a),b,rnd_mode); //mpfr_pow_ui\n}\n\ninline const mpreal pow(const int a, const unsigned int b, mp_rnd_t rnd_mode)\n{\n    if (a>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);  //mpfr_ui_pow_ui\n    else     return pow(mpreal(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_pow_ui\n}\n\ninline const mpreal pow(const int a, const long int b, mp_rnd_t rnd_mode)\n{\n    if (a>0)\n    {\n        if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n        else    return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n    }else{\n        return pow(mpreal(a),b,rnd_mode); // mpfr_pow_si\n    }\n}\n\ninline const mpreal pow(const int a, const int b, mp_rnd_t rnd_mode)\n{\n    if (a>0)\n    {\n        if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_ui_pow_ui\n        else    return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n    }else{\n        return pow(mpreal(a),static_cast<long int>(b),rnd_mode); // mpfr_pow_si\n    }\n}\n\ninline const mpreal pow(const int a, const long double b, mp_rnd_t rnd_mode)\n{\n    if (a>=0)   return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n    else        return pow(mpreal(a),mpreal(b),rnd_mode); //mpfr_pow\n}\n\ninline const mpreal pow(const int a, const double b, mp_rnd_t rnd_mode)\n{\n    if (a>=0)   return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode); //mpfr_ui_pow\n    else        return pow(mpreal(a),mpreal(b),rnd_mode); //mpfr_pow\n}\n\n// pow long double\ninline const mpreal pow(const long double a, const long double b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),mpreal(b),rnd_mode);\n}\n\ninline const mpreal pow(const long double a, const unsigned long int b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),b,rnd_mode); //mpfr_pow_ui\n}\n\ninline const mpreal pow(const long double a, const unsigned int b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),static_cast<unsigned long int>(b),rnd_mode); //mpfr_pow_ui\n}\n\ninline const mpreal pow(const long double a, const long int b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),b,rnd_mode); // mpfr_pow_si\n}\n\ninline const mpreal pow(const long double a, const int b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),static_cast<long int>(b),rnd_mode); // mpfr_pow_si\n}\n\ninline const mpreal pow(const double a, const double b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),mpreal(b),rnd_mode);\n}\n\ninline const mpreal pow(const double a, const unsigned long int b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),b,rnd_mode); // mpfr_pow_ui\n}\n\ninline const mpreal pow(const double a, const unsigned int b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),static_cast<unsigned long int>(b),rnd_mode); // mpfr_pow_ui\n}\n\ninline const mpreal pow(const double a, const long int b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),b,rnd_mode); // mpfr_pow_si\n}\n\ninline const mpreal pow(const double a, const int b, mp_rnd_t rnd_mode)\n{\n    return pow(mpreal(a),static_cast<long int>(b),rnd_mode); // mpfr_pow_si\n}\n} // End of mpfr namespace\n\n// Explicit specialization of std::swap for mpreal numbers\n// Thus standard algorithms will use efficient version of swap (due to Koenig lookup)\n// Non-throwing swap C++ idiom: http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Non-throwing_swap\nnamespace std\n{\n\t// we are allowed to extend namespace std with specializations only\n    template <>\n    inline void swap(mpfr::mpreal& x, mpfr::mpreal& y)\n    {\n        return mpfr::swap(x, y);\n    }\n\n    template<>\n    class numeric_limits<mpfr::mpreal>\n    {\n    public:\n        static const bool is_specialized    = true;\n        static const bool is_signed         = true;\n        static const bool is_integer        = false;\n        static const bool is_exact          = false;\n        static const int  radix             = 2;\n\n        static const bool has_infinity      = true;\n        static const bool has_quiet_NaN     = true;\n        static const bool has_signaling_NaN = true;\n\n        static const bool is_iec559         = true;        // = IEEE 754\n        static const bool is_bounded        = true;\n        static const bool is_modulo         = false;\n        static const bool traps             = true;\n        static const bool tinyness_before   = true;\n\n        static const float_denorm_style has_denorm  = denorm_absent;\n\n        inline static mpfr::mpreal (min)    (mp_prec_t precision = mpfr::mpreal::get_default_prec()) {  return  mpfr::minval(precision);  }\n        inline static mpfr::mpreal (max)    (mp_prec_t precision = mpfr::mpreal::get_default_prec()) {  return  mpfr::maxval(precision);  }\n        inline static mpfr::mpreal lowest   (mp_prec_t precision = mpfr::mpreal::get_default_prec()) {  return -mpfr::maxval(precision);  }\n\n        // Returns smallest eps such that 1 + eps != 1 (classic machine epsilon)\n        inline static mpfr::mpreal epsilon(mp_prec_t precision = mpfr::mpreal::get_default_prec()) {  return  mpfr::machine_epsilon(precision); }\n\n        // Returns smallest eps such that x + eps != x (relative machine epsilon)\n        inline static mpfr::mpreal epsilon(const mpfr::mpreal& x) {  return mpfr::machine_epsilon(x);  }\n\n        inline static mpfr::mpreal round_error(mp_prec_t precision = mpfr::mpreal::get_default_prec())\n        {\n            mp_rnd_t r = mpfr::mpreal::get_default_rnd();\n\n            if(r == GMP_RNDN)  return mpfr::mpreal(0.5, precision);\n            else               return mpfr::mpreal(1.0, precision);\n        }\n\n        inline static const mpfr::mpreal infinity()         { return mpfr::const_infinity();     }\n        inline static const mpfr::mpreal quiet_NaN()        { return mpfr::mpreal().setNan();    }\n        inline static const mpfr::mpreal signaling_NaN()    { return mpfr::mpreal().setNan();    }\n        inline static const mpfr::mpreal denorm_min()       { return (min)();                    }\n\n        // Please note, exponent range is not fixed in MPFR\n        static const int min_exponent = MPFR_EMIN_DEFAULT;\n        static const int max_exponent = MPFR_EMAX_DEFAULT;\n        MPREAL_PERMISSIVE_EXPR static const int min_exponent10 = (int) (MPFR_EMIN_DEFAULT * 0.3010299956639811);\n        MPREAL_PERMISSIVE_EXPR static const int max_exponent10 = (int) (MPFR_EMAX_DEFAULT * 0.3010299956639811);\n\n#ifdef MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS\n\n        // Following members should be constant according to standard, but they can be variable in MPFR\n        // So we define them as functions here.\n        //\n        // This is preferable way for std::numeric_limits<mpfr::mpreal> specialization.\n        // But it is incompatible with standard std::numeric_limits and might not work with other libraries, e.g. boost.\n        // See below for compatible implementation.\n        inline static float_round_style round_style()\n        {\n            mp_rnd_t r = mpfr::mpreal::get_default_rnd();\n\n            switch (r)\n            {\n            case GMP_RNDN: return round_to_nearest;\n            case GMP_RNDZ: return round_toward_zero;\n            case GMP_RNDU: return round_toward_infinity;\n            case GMP_RNDD: return round_toward_neg_infinity;\n            default: return round_indeterminate;\n            }\n        }\n\n        inline static int digits()                        {    return int(mpfr::mpreal::get_default_prec());    }\n        inline static int digits(const mpfr::mpreal& x)   {    return x.getPrecision();                         }\n\n        inline static int digits10(mp_prec_t precision = mpfr::mpreal::get_default_prec())\n        {\n            return mpfr::bits2digits(precision);\n        }\n\n        inline static int digits10(const mpfr::mpreal& x)\n        {\n            return mpfr::bits2digits(x.getPrecision());\n        }\n\n        inline static int max_digits10(mp_prec_t precision = mpfr::mpreal::get_default_prec())\n        {\n            return digits10(precision);\n        }\n#else\n        // Digits and round_style are NOT constants when it comes to mpreal.\n        // If possible, please use functions digits() and round_style() defined above.\n        //\n        // These (default) values are preserved for compatibility with existing libraries, e.g. boost.\n        // Change them accordingly to your application.\n        //\n        // For example, if you use 256 bits of precision uniformly in your program, then:\n        // digits       = 256\n        // digits10     = 77\n        // max_digits10 = 78\n        //\n        // Approximate formula for decimal digits is: digits10 = floor(log10(2) * digits). See bits2digits() for more details.\n\n        static const std::float_round_style round_style = round_to_nearest;\n        static const int digits       = 53;\n        static const int digits10     = 15;\n        static const int max_digits10 = 16;\n#endif\n    };\n\n}\n\n#endif /* __MPFRXX_HPP__ */\n"
  },
  {
    "path": "tools/epm/epm/base.et",
    "content": "import std.fs;\nimport std.os;\nimport std.str;\n\n# Ethereal Package Manager\nEPM_DIR = os.get_env( 'HOME' ) + '/.epm';\n# Ethereal Package Index\nEPI_DIR = EPM_DIR + '/pkgs';\nEPI_URL = 'https://github.com/Electrux/Ethereal-Pkgs.git';\nGIT_CMD = os.find_exec( 'git' );\n\nif GIT_CMD.empty() {\n\tcprintln( '{w}=> {r}git is probably not installed on the system{0}, {r}please install it first{0}' );\n\texit( 1 );\n}\n\n# create the Ethereal Package Manager directory\nif !fs.exists( EPM_DIR ) {\n\tcprintln( '{w}=> {y}creating EPM home directory {0}({c}', EPM_DIR, '{0}) ...' );\n\tepm_dir_created = os.mkdir( EPM_DIR );\n\tif epm_dir_created != 0 {\n\t\tcprintln( '{w}=> {y}failed to create EPM_DIR {0}= {r}', EPM_DIR, '{0}' );\n\t\texit( epm_dir_created );\n\t}\n}\n\nif !fs.exists( EPI_DIR ) {\n\tcprintln( '{w}=> {y}package index repository does not exist locally{0}, {y}cloning it {0}...' );\n\tres = os.exec( GIT_CMD + ' clone ' + EPI_URL + ' ' + EPI_DIR );\n\tif res != 0 {\n\t\tcprintln( '{w}=> {r}failed to clone package index repository{0}' );\n\t\texit( res );\n\t}\n}\n\n__add_incs__( EPI_DIR );\n"
  },
  {
    "path": "tools/epm/epm/info.et",
    "content": "import std.fs;\nimport std.os;\nimport std.str;\nimport std.term;\n\nimport epm.base;\n\nfn info( of ) {\n\tif !fs.exists( EPI_DIR + '/' + of + '.pkg.et' ) {\n\t\tcprintln( '{w}=> {y}package {r}' + of + ' {y}does not exist{0}' );\n\t\texit( 1 );\n\t}\n\t__import__( of + '.pkg' );\n\tcprintln( '{w}=> {y}Version{0}: {c}', version, '{0}' );\n\tcprintln( '{w}=> {y}URL{0}: {c}', url, '{0}' );\n\tcprintln( '{w}=> {y}Source file{0}: {c}', src, '{0}' );\n\tcprintln( '{w}=> {y}Installation files{0}: {c}', files, '{0}' );\n}\n"
  },
  {
    "path": "tools/epm/epm/update.et",
    "content": "import std.fs;\nimport std.os;\nimport std.str;\nimport std.term;\n\nimport epm.base;\n\nfn update() {\n\tcprintln( '{w}=> {y}updating package index {0}... ' );\n\tres = 0;\n\tif fs.exists( EPI_DIR ) {\n\t\tres = os.exec( GIT_CMD + ' -C ' + EPI_DIR + ' pull' );\n\t} else {\n\t\tres = os.exec( GIT_CMD + ' clone ' + EPI_URL + ' ' + EPI_DIR );\n\t}\n\n\tif res != 0 {\n\t\tcprintln( '{w}=> {r}failed to clone/pull package index repository{0}' );\n\t\texit( res );\n\t}\n}\n"
  },
  {
    "path": "tools/epm/epm.et",
    "content": "#!@BINARY_LOC@\n\nimport std.fs;\nimport std.os;\nimport std.str;\nimport std.term;\nimport std.vec;\n\n# for when not installed at PREFIX_DIR\n__add_incs__( '.' );\n\nimport epm.update;\nimport epm.info;\n\nif args.len() < 2 {\n\tcprintln( '{w}=> {y}please enter a subcommand to execute{0}' );\n\texit( 0 );\n}\n\nif args[ 1 ] == 'update' {\n\tupdate();\n\texit( 0 );\n}\n\nif args[ 1 ] == 'info' {\n\tif args.len() < 3 {\n\t\tcprintln( '{w}=> {y}must specify a {r}package name {y}for which information is to be retrieved{0}' );\n\t\texit( 1 );\n\t}\n\tinfo( args[ 2 ] );\n\texit( 0 );\n}\n\n\n"
  }
]