mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 12:46:31 +00:00
99 lines
3.7 KiB
C++
99 lines
3.7 KiB
C++
#include "json.hpp"
|
|
#include "vm.hpp"
|
|
#include <string>
|
|
|
|
using namespace sliger;
|
|
|
|
auto sliger::maybe_op_to_string(uint32_t value) -> std::string
|
|
{
|
|
switch (static_cast<Op>(value)) {
|
|
/* clang-format off */
|
|
case Op::Nop: return "Nop";
|
|
case Op::PushNull: return "PushNull";
|
|
case Op::PushInt: return "PushInt";
|
|
case Op::PushBool: return "PushBool";
|
|
case Op::PushString: return "PushString";
|
|
case Op::PushPtr: return "PushPtr";
|
|
case Op::Pop: return "Pop";
|
|
case Op::ReserveStatic: return "ReserveStatic";
|
|
case Op::LoadStatic: return "LoadStatic";
|
|
case Op::StoreStatic: return "StoreStatic";
|
|
case Op::LoadLocal: return "LoadLocal";
|
|
case Op::StoreLocal: return "StoreLocal";
|
|
case Op::Call: return "Call";
|
|
case Op::Return: return "Return";
|
|
case Op::Jump: return "Jump";
|
|
case Op::JumpIfTrue: return "JumpIfTrue";
|
|
case Op::Builtin: return "Builtin";
|
|
case Op::Duplicate: return "Duplicate";
|
|
case Op::Swap: return "Swap";
|
|
case Op::Add: return "Add";
|
|
case Op::Subtract: return "Subtract";
|
|
case Op::Multiply: return "Multiply";
|
|
case Op::Divide: return "Divide";
|
|
case Op::Remainder: return "Remainder";
|
|
case Op::Equal: return "Equal";
|
|
case Op::LessThan: return "LessThan";
|
|
case Op::And: return "And";
|
|
case Op::Or: return "Or";
|
|
case Op::Xor: return "Xor";
|
|
case Op::Not: return "Not";
|
|
case Op::SourceMap: return "SourceMap";
|
|
/* clang-format on */
|
|
}
|
|
return std::to_string(value);
|
|
}
|
|
|
|
auto sliger::maybe_builtin_to_string(uint32_t value) -> std::string
|
|
{
|
|
switch (static_cast<Builtin>(value)) {
|
|
/* clang-format off */
|
|
case Builtin::IntToString: return "IntToString";
|
|
case Builtin::StringConcat: return "StringConcat";
|
|
case Builtin::StringEqual: return "StringEqual";
|
|
case Builtin::StringCharAt: return "StringCharAt";
|
|
case Builtin::StringLength: return "StringLength";
|
|
case Builtin::StringPushChar: return "StringPushChar";
|
|
case Builtin::StringToInt: return "StringToInt";
|
|
case Builtin::ArrayNew: return "ArrayNew";
|
|
case Builtin::ArraySet: return "ArraySet";
|
|
case Builtin::ArrayPush: return "ArrayPush";
|
|
case Builtin::ArrayAt: return "ArrayAt";
|
|
case Builtin::ArrayLength: return "ArrayLength";
|
|
case Builtin::StructSet: return "StructSet";
|
|
case Builtin::Print: return "Print";
|
|
case Builtin::FileOpen: return "FileOpen";
|
|
case Builtin::FileClose: return "FileClose";
|
|
case Builtin::FileWriteString: return "FileWrite";
|
|
case Builtin::FileReadToString: return "FileReadToString";
|
|
case Builtin::FileFlush: return "FileFlush";
|
|
case Builtin::FileEof: return "FileEof";
|
|
/* clang-format on */
|
|
default:
|
|
return std::to_string(value);
|
|
}
|
|
}
|
|
|
|
auto json::tok_typ_to_string(json::TokTyp typ) -> std::string
|
|
{
|
|
using namespace json;
|
|
|
|
switch (typ) {
|
|
/* clang-format off */
|
|
case TokTyp::Eof: return "Eof";
|
|
case TokTyp::String: return "String";
|
|
case TokTyp::Float: return "Float";
|
|
case TokTyp::False: return "False";
|
|
case TokTyp::True: return "True";
|
|
case TokTyp::Null: return "Null";
|
|
case TokTyp::LBrace: return "LBrace";
|
|
case TokTyp::RBrace: return "RBrace";
|
|
case TokTyp::LBracket: return "LBracket";
|
|
case TokTyp::RBracket: return "RBracket";
|
|
case TokTyp::Comma: return "Comma";
|
|
case TokTyp::Colon: return "Colon";
|
|
/* clang-format on */
|
|
}
|
|
std::unreachable();
|
|
}
|