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