mirror of
https://github.com/usatiuk/psil.git
synced 2025-10-28 10:47:49 +01:00
Clang format all the things
This commit is contained in:
@@ -2,8 +2,28 @@
|
||||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
OverEmptyLines: 2
|
||||
SpacesBeforeTrailingComments: 1
|
||||
AlignOperands: Align
|
||||
AlignEscapedNewlines: Right
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
@@ -33,7 +53,7 @@ BreakBeforeBinaryOperators: None
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakInheritanceList: BeforeColon
|
||||
ColumnLimit: 120
|
||||
ColumnLimit: 0
|
||||
CompactNamespaces: false
|
||||
ContinuationIndentWidth: 8
|
||||
IndentCaseLabels: true
|
||||
@@ -56,7 +76,6 @@ SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 0
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
|
||||
10
.idea/codeStyles/Project.xml
generated
Normal file
10
.idea/codeStyles/Project.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<RiderCodeStyleSettings>
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="true" type="bool" />
|
||||
</RiderCodeStyleSettings>
|
||||
<clangFormatSettings>
|
||||
<option name="ENABLED" value="true" />
|
||||
</clangFormatSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
7
.idea/editor.xml
generated
Normal file
7
.idea/editor.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="BackendCodeEditorSettings">
|
||||
<option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="true" type="bool" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -29,7 +29,7 @@ void parse_options(int argc, char *argv[]) {
|
||||
std::vector<std::string> split;
|
||||
{
|
||||
std::istringstream ins(rest);
|
||||
std::string cur;
|
||||
std::string cur;
|
||||
while (std::getline(ins, cur, ':')) { split.emplace_back(cur); }
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ int main(int argc, char *argv[]) {
|
||||
parse_options(argc, argv);
|
||||
|
||||
Handle repl = Parser::parse_str("(READ EVAL PRINT STOP)");
|
||||
Handle epl = Parser::parse_str("(EVAL PRINT STOP)");
|
||||
Handle epl = Parser::parse_str("(EVAL PRINT STOP)");
|
||||
|
||||
VM vm;
|
||||
|
||||
|
||||
@@ -14,17 +14,23 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class Logger
|
||||
{
|
||||
class Logger {
|
||||
public:
|
||||
Logger();
|
||||
|
||||
enum LogLevel { ALWAYS = 0, ERROR = 1, INFO = 2, DEBUG = 3, TRACE = 4 };
|
||||
enum LogLevel { ALWAYS = 0,
|
||||
ERROR = 1,
|
||||
INFO = 2,
|
||||
DEBUG = 3,
|
||||
TRACE = 4 };
|
||||
|
||||
enum LogTag { MemoryContext, VM, Compiler, LogTagMax };
|
||||
enum LogTag { MemoryContext,
|
||||
VM,
|
||||
Compiler,
|
||||
LogTagMax };
|
||||
|
||||
static void log(LogTag tag, const std::string& what, int level);
|
||||
static void log(LogTag tag, const std::function<void(std::ostream&)>& fn, int level);
|
||||
static void log(LogTag tag, const std::string &what, int level);
|
||||
static void log(LogTag tag, const std::function<void(std::ostream &)> &fn, int level);
|
||||
|
||||
// 0 - disabled
|
||||
// 1 - error
|
||||
@@ -32,39 +38,43 @@ public:
|
||||
// 3 - debug
|
||||
// 4 - trace
|
||||
static void set_level(LogTag tag, int level);
|
||||
static int get_level(LogTag tag);
|
||||
static int get_level(LogTag tag);
|
||||
static bool en_level(LogTag tag, int level);
|
||||
|
||||
static void set_out(std::ostream& out);
|
||||
static void set_out_err(std::ostream& out_err);
|
||||
static void set_out(std::ostream &out);
|
||||
static void set_out_err(std::ostream &out_err);
|
||||
|
||||
static void reset();
|
||||
|
||||
static Logger& get();
|
||||
static Logger &get();
|
||||
|
||||
static LogTag str_to_tag(const std::string& str) { return _str_to_tag.at(str); }
|
||||
static const std::string& tag_to_str(LogTag tag) { return _tag_to_str.at(tag); }
|
||||
static LogTag str_to_tag(const std::string &str) { return _str_to_tag.at(str); }
|
||||
static const std::string &tag_to_str(LogTag tag) { return _tag_to_str.at(tag); }
|
||||
|
||||
private:
|
||||
std::array<LogLevel, LogTag::LogTagMax> _levels{};
|
||||
std::array<LogLevel, LogTag::LogTagMax> _levels{};
|
||||
static inline std::unordered_map<int, std::string> _level_names{
|
||||
{ALWAYS, "ALWAYS"}, {ERROR, "ERROR"}, {INFO, "INFO"}, {DEBUG, "DEBUG"}, {TRACE, "TRACE"},
|
||||
{ALWAYS, "ALWAYS"},
|
||||
{ERROR, "ERROR"},
|
||||
{INFO, "INFO"},
|
||||
{DEBUG, "DEBUG"},
|
||||
{TRACE, "TRACE"},
|
||||
};
|
||||
static inline std::unordered_map<std::string, LogTag> _str_to_tag{
|
||||
{"VM", VM},
|
||||
{"MemoryContext", MemoryContext},
|
||||
{"Compiler", Compiler},
|
||||
{"VM", VM},
|
||||
{"MemoryContext", MemoryContext},
|
||||
{"Compiler", Compiler},
|
||||
};
|
||||
static inline std::unordered_map<LogTag, std::string> _tag_to_str{
|
||||
{VM, "VM"},
|
||||
{MemoryContext, "MemoryContext"},
|
||||
{Compiler, "Compiler"},
|
||||
{VM, "VM"},
|
||||
{MemoryContext, "MemoryContext"},
|
||||
{Compiler, "Compiler"},
|
||||
};
|
||||
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> _start_time = std::chrono::high_resolution_clock::now();
|
||||
std::reference_wrapper<std::ostream> _out = std::cout;
|
||||
std::reference_wrapper<std::ostream> _out_err = std::cerr;
|
||||
std::reference_wrapper<std::ostream> _out = std::cout;
|
||||
std::reference_wrapper<std::ostream> _out_err = std::cerr;
|
||||
};
|
||||
|
||||
|
||||
#endif//PSIL_LOGGER_H
|
||||
#endif //PSIL_LOGGER_H
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
o._current[opt] = val;
|
||||
}
|
||||
|
||||
static void reset();
|
||||
static void reset();
|
||||
static Options &get();
|
||||
|
||||
private:
|
||||
@@ -45,4 +45,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif//PSIL_OPTIONS_H
|
||||
#endif //PSIL_OPTIONS_H
|
||||
|
||||
@@ -17,17 +17,18 @@ Logger &Logger::get() {
|
||||
void Logger::log(LogTag tag, const std::string &what, int level) {
|
||||
if (!en_level(tag, level)) return;
|
||||
{
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
std::stringstream out;
|
||||
out << std::setprecision(3) << std::fixed << "["
|
||||
<< static_cast<double>(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(now - get()._start_time).count()) /
|
||||
1000.0
|
||||
<< "s]"
|
||||
<< "[" << tag_to_str(tag) << "][" << get()._level_names.at(level) << "] " << what << '\n';
|
||||
<< static_cast<double>(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(now - get()._start_time).count()) /
|
||||
1000.0
|
||||
<< "s]"
|
||||
<< "[" << tag_to_str(tag) << "][" << get()._level_names.at(level) << "] " << what << '\n';
|
||||
|
||||
if (level == 1) get()._out_err.get() << out.str();
|
||||
else get()._out.get() << out.str();
|
||||
else
|
||||
get()._out.get() << out.str();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
enum class CellType { NUMATOM, STRATOM, CONS };
|
||||
enum class CellType { NUMATOM,
|
||||
STRATOM,
|
||||
CONS };
|
||||
|
||||
using CellValType = int64_t;
|
||||
|
||||
@@ -22,7 +24,7 @@ struct Cell {
|
||||
explicit Cell(CellType type) : _type(type) {}
|
||||
virtual ~Cell() = 0;
|
||||
|
||||
CellType _type;
|
||||
CellType _type;
|
||||
std::atomic<bool> _live = false;
|
||||
|
||||
virtual void print(std::ostream &out) const = 0;
|
||||
@@ -90,7 +92,7 @@ struct ConsCell : public Cell {
|
||||
}
|
||||
|
||||
void print(std::ostream &out) const override {
|
||||
std::stringstream res;
|
||||
std::stringstream res;
|
||||
std::set<const Cell *> seen{this};
|
||||
if (_car) {
|
||||
if (_car.load()->_type == CellType::CONS) {
|
||||
@@ -118,4 +120,4 @@ struct ConsCell : public Cell {
|
||||
}
|
||||
};
|
||||
|
||||
#endif//PSIL_CELL_H
|
||||
#endif //PSIL_CELL_H
|
||||
|
||||
@@ -13,56 +13,108 @@
|
||||
|
||||
namespace Command {
|
||||
enum CommandE : CellValType {
|
||||
NIL = 1,
|
||||
LDC = 2,
|
||||
LD = 3,
|
||||
SEL = 4,
|
||||
NIL = 1,
|
||||
LDC = 2,
|
||||
LD = 3,
|
||||
SEL = 4,
|
||||
JOIN = 5,
|
||||
LDF = 6,
|
||||
AP = 7,
|
||||
RET = 8,
|
||||
DUM = 9,
|
||||
RAP = 10,
|
||||
LDF = 6,
|
||||
AP = 7,
|
||||
RET = 8,
|
||||
DUM = 9,
|
||||
RAP = 10,
|
||||
STOP = 11,
|
||||
|
||||
ATOM = 12,
|
||||
ADD = 13,
|
||||
SUB = 14,
|
||||
ADD = 13,
|
||||
SUB = 14,
|
||||
|
||||
// Encountered in tests
|
||||
READCHAR = 15,
|
||||
PUTCHAR = 16,
|
||||
PUTNUM = 17,
|
||||
PUTCHAR = 16,
|
||||
PUTNUM = 17,
|
||||
|
||||
EVAL = 18,
|
||||
EVAL = 18,
|
||||
PRINT = 19,
|
||||
READ = 20,
|
||||
READ = 20,
|
||||
|
||||
CONS = 21,
|
||||
LDG = 22,
|
||||
CAR = 23,
|
||||
CDR = 24,
|
||||
EQ = 25,
|
||||
LT = 26,
|
||||
GT = 27,
|
||||
LDG = 22,
|
||||
CAR = 23,
|
||||
CDR = 24,
|
||||
EQ = 25,
|
||||
LT = 26,
|
||||
GT = 27,
|
||||
NILC = 28,
|
||||
MULT = 29,
|
||||
DIV = 30,
|
||||
DIV = 30,
|
||||
QUIT = 31
|
||||
};
|
||||
|
||||
static inline std::unordered_map<std::string_view, CellValType> str_to_cmd{
|
||||
{"NIL", 1}, {"LDC", 2}, {"LD", 3}, {"SEL", 4}, {"JOIN", 5}, {"LDF", 6}, {"AP", 7},
|
||||
{"RET", 8}, {"DUM", 9}, {"RAP", 10}, {"STOP", 11}, {"ATOM", 12}, {"ADD", 13}, {"SUB", 14},
|
||||
{"READCHAR", 15}, {"PUTCHAR", 16}, {"PUTNUM", 17}, {"EVAL", 18}, {"PRINT", 19}, {"READ", 20}, {"CONS", 21},
|
||||
{"LDG", 22}, {"CAR", 23}, {"CDR", 24}, {"EQ", 25}, {"LT", 26}, {"GT", 27}, {"NILC", 28},
|
||||
{"MULT", 29}, {"DIV", 30}, {"QUIT", 31}};
|
||||
{"NIL", 1},
|
||||
{"LDC", 2},
|
||||
{"LD", 3},
|
||||
{"SEL", 4},
|
||||
{"JOIN", 5},
|
||||
{"LDF", 6},
|
||||
{"AP", 7},
|
||||
{"RET", 8},
|
||||
{"DUM", 9},
|
||||
{"RAP", 10},
|
||||
{"STOP", 11},
|
||||
{"ATOM", 12},
|
||||
{"ADD", 13},
|
||||
{"SUB", 14},
|
||||
{"READCHAR", 15},
|
||||
{"PUTCHAR", 16},
|
||||
{"PUTNUM", 17},
|
||||
{"EVAL", 18},
|
||||
{"PRINT", 19},
|
||||
{"READ", 20},
|
||||
{"CONS", 21},
|
||||
{"LDG", 22},
|
||||
{"CAR", 23},
|
||||
{"CDR", 24},
|
||||
{"EQ", 25},
|
||||
{"LT", 26},
|
||||
{"GT", 27},
|
||||
{"NILC", 28},
|
||||
{"MULT", 29},
|
||||
{"DIV", 30},
|
||||
{"QUIT", 31}};
|
||||
static inline std::unordered_map<CellValType, std::string> cmd_to_str{
|
||||
{1, "NIL"}, {2, "LDC"}, {3, "LD"}, {4, "SEL"}, {5, "JOIN"}, {6, "LDF"}, {7, "AP"},
|
||||
{8, "RET"}, {9, "DUM"}, {10, "RAP"}, {11, "STOP"}, {12, "ATOM"}, {13, "ADD"}, {14, "SUB"},
|
||||
{15, "READCHAR"}, {16, "PUTCHAR"}, {17, "PUTNUM"}, {18, "EVAL"}, {19, "PRINT"}, {20, "READ"}, {21, "CONS"},
|
||||
{22, "LDG"}, {23, "CAR"}, {24, "CDR"}, {25, "EQ"}, {26, "LT"}, {27, "GT"}, {28, "NILC"},
|
||||
{29, "MULT"}, {30, "DIV"}, {31, "QUIT"}};
|
||||
{1, "NIL"},
|
||||
{2, "LDC"},
|
||||
{3, "LD"},
|
||||
{4, "SEL"},
|
||||
{5, "JOIN"},
|
||||
{6, "LDF"},
|
||||
{7, "AP"},
|
||||
{8, "RET"},
|
||||
{9, "DUM"},
|
||||
{10, "RAP"},
|
||||
{11, "STOP"},
|
||||
{12, "ATOM"},
|
||||
{13, "ADD"},
|
||||
{14, "SUB"},
|
||||
{15, "READCHAR"},
|
||||
{16, "PUTCHAR"},
|
||||
{17, "PUTNUM"},
|
||||
{18, "EVAL"},
|
||||
{19, "PRINT"},
|
||||
{20, "READ"},
|
||||
{21, "CONS"},
|
||||
{22, "LDG"},
|
||||
{23, "CAR"},
|
||||
{24, "CDR"},
|
||||
{25, "EQ"},
|
||||
{26, "LT"},
|
||||
{27, "GT"},
|
||||
{28, "NILC"},
|
||||
{29, "MULT"},
|
||||
{30, "DIV"},
|
||||
{31, "QUIT"}};
|
||||
|
||||
static inline Handle make_cmd(CellValType cmd) {
|
||||
if (Options::get<bool>("command_strs")) {
|
||||
@@ -70,7 +122,7 @@ namespace Command {
|
||||
} else
|
||||
return Handle(cmd);
|
||||
};
|
||||
};// namespace Command
|
||||
}; // namespace Command
|
||||
|
||||
|
||||
#endif//PSIL_COMMAND_H
|
||||
#endif //PSIL_COMMAND_H
|
||||
|
||||
@@ -17,4 +17,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif//PSIL_COMPILER_H
|
||||
#endif //PSIL_COMPILER_H
|
||||
|
||||
@@ -90,14 +90,14 @@ public:
|
||||
}
|
||||
|
||||
Handle pop();
|
||||
void push(const Handle &what);
|
||||
void append(const Handle &what);
|
||||
void splice(const Handle &what);
|
||||
void push(const Handle &what);
|
||||
void append(const Handle &what);
|
||||
void splice(const Handle &what);
|
||||
|
||||
static Handle makeNumCell(int64_t val);
|
||||
static Handle makeStrCell(std::string val);
|
||||
void setcar(const Handle &car);
|
||||
void setcdr(const Handle &cdr);
|
||||
void setcar(const Handle &car);
|
||||
void setcdr(const Handle &cdr);
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const Handle &h) {
|
||||
if (h._target) h._target->print(stream);
|
||||
@@ -124,6 +124,6 @@ namespace std {
|
||||
return std::hash<uintptr_t>()((uintptr_t) c.get());
|
||||
}
|
||||
};
|
||||
}// namespace std
|
||||
} // namespace std
|
||||
|
||||
#endif//PSIL_HANDLE_H
|
||||
#endif //PSIL_HANDLE_H
|
||||
|
||||
@@ -126,9 +126,9 @@ private:
|
||||
void add_root(Cell *c);
|
||||
void remove_root(Cell *c);
|
||||
|
||||
std::list<Cell *> _cells;
|
||||
std::list<Cell *> _cells;
|
||||
std::atomic<size_t> _cells_num = 0;
|
||||
std::list<Cell *> _temp_cells;
|
||||
std::list<Cell *> _temp_cells;
|
||||
|
||||
void gc_thread_entry();
|
||||
|
||||
@@ -138,19 +138,19 @@ private:
|
||||
std::recursive_mutex _new_roots_lock;
|
||||
|
||||
std::set<Cell *> _gc_dirty_notif_queue;
|
||||
std::mutex _gc_dirty_notif_queue_lock;
|
||||
std::mutex _gc_dirty_notif_queue_lock;
|
||||
|
||||
std::atomic<bool> _gc_request = false;
|
||||
std::mutex _gc_request_m;
|
||||
std::atomic<bool> _gc_request = false;
|
||||
std::mutex _gc_request_m;
|
||||
std::condition_variable _gc_request_cv;
|
||||
|
||||
std::atomic<bool> _gc_done = false;
|
||||
std::mutex _gc_done_m;
|
||||
std::atomic<bool> _gc_done = false;
|
||||
std::mutex _gc_done_m;
|
||||
std::condition_variable _gc_done_cv;
|
||||
|
||||
std::thread _gc_thread;
|
||||
std::thread _gc_thread;
|
||||
std::atomic<bool> _gc_thread_stop = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif//PSIL_MEMORYCONTEXT_H
|
||||
#endif //PSIL_MEMORYCONTEXT_H
|
||||
|
||||
@@ -20,7 +20,7 @@ class Parser {
|
||||
public:
|
||||
static Handle parse_str(std::string_view input);
|
||||
|
||||
void loadStr(std::string_view input);
|
||||
void loadStr(std::string_view input);
|
||||
Handle parseExpr();
|
||||
|
||||
private:
|
||||
@@ -42,4 +42,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif//PSIL_PARSER_H
|
||||
#endif //PSIL_PARSER_H
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
void run();
|
||||
|
||||
void loadControl(const Handle &h) {
|
||||
_c = h;
|
||||
_c = h;
|
||||
_stop = false;
|
||||
}
|
||||
|
||||
@@ -30,20 +30,20 @@ public:
|
||||
void step();
|
||||
|
||||
private:
|
||||
Handle _globals_names = Handle::cons(Handle::cons(nullptr, nullptr), nullptr);
|
||||
Handle _globals_vals = Handle::cons(nullptr, nullptr);
|
||||
Handle _globals_names = Handle::cons(Handle::cons(nullptr, nullptr), nullptr);
|
||||
Handle _globals_vals = Handle::cons(nullptr, nullptr);
|
||||
std::unordered_map<Handle, std::string> _globals_names_map;
|
||||
size_t _cur_global = 0;
|
||||
size_t _cur_call_level = 0;
|
||||
Handle _s = Handle::cons(nullptr, nullptr);
|
||||
Handle _e = Handle::cons(_globals_vals, nullptr);
|
||||
Handle _c = Handle::cons(nullptr, nullptr);
|
||||
Handle _d = Handle::cons(nullptr, nullptr);
|
||||
bool _stop = false;
|
||||
bool _quit = false;
|
||||
size_t _cur_global = 0;
|
||||
size_t _cur_call_level = 0;
|
||||
Handle _s = Handle::cons(nullptr, nullptr);
|
||||
Handle _e = Handle::cons(_globals_vals, nullptr);
|
||||
Handle _c = Handle::cons(nullptr, nullptr);
|
||||
Handle _d = Handle::cons(nullptr, nullptr);
|
||||
bool _stop = false;
|
||||
bool _quit = false;
|
||||
|
||||
std::istream &_instream;
|
||||
std::ostream &_outstream;
|
||||
};
|
||||
|
||||
#endif//PSIL_VM_H
|
||||
#endif //PSIL_VM_H
|
||||
|
||||
@@ -18,15 +18,29 @@ using namespace Command;
|
||||
|
||||
|
||||
static std::unordered_map<std::string_view, CommandE> builtins{
|
||||
{"+", ADD}, {"-", SUB}, {"cons", CONS}, {"car", CAR}, {"cdr", CDR}, {"=", EQ},
|
||||
{">", GT}, {"<", LT}, {"nil", NIL}, {"nil?", NILC}, {"atom", ATOM}, {"*", MULT},
|
||||
{"/", DIV}, {"read", READ}, {"eval", EVAL}, {"print", PRINT}, {"quit", QUIT}};
|
||||
{"+", ADD},
|
||||
{"-", SUB},
|
||||
{"cons", CONS},
|
||||
{"car", CAR},
|
||||
{"cdr", CDR},
|
||||
{"=", EQ},
|
||||
{">", GT},
|
||||
{"<", LT},
|
||||
{"nil", NIL},
|
||||
{"nil?", NILC},
|
||||
{"atom", ATOM},
|
||||
{"*", MULT},
|
||||
{"/", DIV},
|
||||
{"read", READ},
|
||||
{"eval", EVAL},
|
||||
{"print", PRINT},
|
||||
{"quit", QUIT}};
|
||||
|
||||
Handle Compiler::compile(const Handle &src, Handle fake_env, const Handle &suffix) {
|
||||
Handle out;
|
||||
|
||||
std::function<Handle(Handle)> compileArgsRaw = [&](Handle args) {
|
||||
Handle out;
|
||||
Handle out;
|
||||
std::stack<Handle> rev;
|
||||
while (!args.null()) {
|
||||
rev.push(args.car());
|
||||
@@ -146,8 +160,8 @@ Handle Compiler::findIndex(const Handle &symbol, const Handle &env) {
|
||||
Handle curFrame = env;
|
||||
|
||||
while (!curFrame.null()) {
|
||||
int64_t arg = 1;
|
||||
Handle curArg = curFrame.car();
|
||||
int64_t arg = 1;
|
||||
Handle curArg = curFrame.car();
|
||||
|
||||
while (!curArg.null()) {
|
||||
if (curArg.car() == symbol) return Handle::cons(frame, arg);
|
||||
|
||||
@@ -32,7 +32,7 @@ Handle Handle::cons(const Handle &car, const Handle &cdr) {
|
||||
|
||||
Handle Handle::pop() {
|
||||
auto ret = car();
|
||||
*this = cdr();
|
||||
*this = cdr();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ void MemoryContext::gc_thread_entry() {
|
||||
};
|
||||
|
||||
{
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
decltype(_new_roots) new_roots;
|
||||
{
|
||||
decltype(_temp_cells) temp_cells;
|
||||
@@ -162,7 +162,7 @@ void MemoryContext::gc_thread_entry() {
|
||||
|
||||
#ifndef NO_THREADS
|
||||
{
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
decltype(_gc_dirty_notif_queue) dirtied;
|
||||
{
|
||||
std::lock_guard dql(_gc_dirty_notif_queue_lock);
|
||||
@@ -231,7 +231,7 @@ void MemoryContext::gc_thread_entry() {
|
||||
{
|
||||
std::unique_lock l(_gc_done_m);
|
||||
std::unique_lock l2(_gc_request_m);
|
||||
_gc_done = true;
|
||||
_gc_done = true;
|
||||
_gc_request = false;
|
||||
_gc_done_cv.notify_all();
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ std::string_view Parser::Tokenizer::peek() const {
|
||||
void Parser::Tokenizer::load(std::string_view input) {
|
||||
std::string_view::size_type curpos = input.find_first_not_of(std::string{' ', '\n', '\r'});
|
||||
|
||||
static const std::string alnum = "-+><?=!*/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
static const std::string alnum = "-+><?=!*/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
static const std::string special = "().";
|
||||
|
||||
while (curpos != std::string_view::npos) {
|
||||
|
||||
@@ -22,7 +22,7 @@ void VM::run() {
|
||||
}
|
||||
|
||||
void VM::step() {
|
||||
Handle poppedH = _c.pop();
|
||||
Handle poppedH = _c.pop();
|
||||
CellValType poppedCmd = poppedH.type() == CellType::STRATOM ? str_to_cmd.at(poppedH.strval()) : poppedH.val();
|
||||
|
||||
Logger::log(
|
||||
@@ -57,7 +57,7 @@ void VM::step() {
|
||||
Handle poppedH2 = _c.pop();
|
||||
|
||||
int64_t frame = poppedH2.car().val();
|
||||
int64_t arg = poppedH2.cdr().val();
|
||||
int64_t arg = poppedH2.cdr().val();
|
||||
|
||||
assert(frame > 0);
|
||||
assert(arg > 0);
|
||||
@@ -97,7 +97,7 @@ void VM::step() {
|
||||
}
|
||||
case AP: {
|
||||
Handle closureH = _s.pop();
|
||||
Handle argsH = _s.pop();
|
||||
Handle argsH = _s.pop();
|
||||
|
||||
_d.push(_s);
|
||||
_d.push(_e);
|
||||
@@ -167,7 +167,7 @@ void VM::step() {
|
||||
}
|
||||
case RAP: {
|
||||
Handle closureH = _s.pop();
|
||||
Handle argsH = _s.pop();
|
||||
Handle argsH = _s.pop();
|
||||
|
||||
Handle origE = _e.cdr();
|
||||
|
||||
@@ -292,8 +292,8 @@ void VM::step() {
|
||||
}
|
||||
case PRINT: {
|
||||
if (!_s.null()) {
|
||||
Handle val = _s.pop();
|
||||
bool cons = !val.atom();
|
||||
Handle val = _s.pop();
|
||||
bool cons = !val.atom();
|
||||
if (cons) _outstream << "(";
|
||||
_outstream << val;
|
||||
if (cons) _outstream << ")";
|
||||
|
||||
Reference in New Issue
Block a user