📝 fix typo: `unmutable` -> `immutable`

This commit is contained in:
ValKmjolnir 2024-05-12 00:21:18 +08:00
parent 1c011f0aad
commit a34f90cbd1
8 changed files with 22 additions and 19 deletions

View File

@ -166,7 +166,7 @@ void execute(const std::string& file,
} }
// run // run
auto start = clk::now(); const auto start = clk::now();
if (cmd&VM_DEBUG) { if (cmd&VM_DEBUG) {
auto debugger = std::unique_ptr<nasal::dbg>(new nasal::dbg); auto debugger = std::unique_ptr<nasal::dbg>(new nasal::dbg);
debugger->run(gen, ld, argv, cmd&VM_PROFILE, cmd&VM_PROF_ALL); debugger->run(gen, ld, argv, cmd&VM_PROFILE, cmd&VM_PROF_ALL);
@ -178,7 +178,7 @@ void execute(const std::string& file,
} }
// get running time // get running time
auto end = clk::now(); const auto end = clk::now();
if (cmd&VM_TIME) { if (cmd&VM_TIME) {
std::clog << "process exited after "; std::clog << "process exited after ";
std::clog << (end-start).count()*1.0/den << "s.\n\n"; std::clog << (end-start).count()*1.0/den << "s.\n\n";
@ -211,7 +211,7 @@ i32 main(i32 argc, const char* argv[]) {
} }
// execute with arguments // execute with arguments
const std::unordered_map<std::string, u32> cmdlst = { const std::unordered_map<std::string, u32> command_list = {
{"--raw-ast", VM_RAW_AST}, {"--raw-ast", VM_RAW_AST},
{"--ast", VM_AST}, {"--ast", VM_AST},
{"-a", VM_AST}, {"-a", VM_AST},
@ -233,12 +233,13 @@ i32 main(i32 argc, const char* argv[]) {
{"--ref-file", VM_REF_FILE}, {"--ref-file", VM_REF_FILE},
{"--limit", VM_LIMIT|VM_EXEC} {"--limit", VM_LIMIT|VM_EXEC}
}; };
u32 cmd = 0;
u32 commands = 0;
std::string filename = ""; std::string filename = "";
std::vector<std::string> vm_argv; std::vector<std::string> vm_argv;
for(i32 i = 1; i<argc; ++i) { for(i32 i = 1; i<argc; ++i) {
if (cmdlst.count(argv[i])) { if (command_list.count(argv[i])) {
cmd |= cmdlst.at(argv[i]); commands |= command_list.at(argv[i]);
} else if (!filename.length()) { } else if (!filename.length()) {
filename = argv[i]; filename = argv[i];
} else { } else {
@ -248,6 +249,7 @@ i32 main(i32 argc, const char* argv[]) {
if (!filename.length()) { if (!filename.length()) {
err(); err();
} }
execute(filename, vm_argv, cmd? cmd:VM_EXEC);
execute(filename, vm_argv, commands? commands:VM_EXEC);
return 0; return 0;
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#ifndef __nasver__ #ifndef __nasver__
#define __nasver__ "11.1" #define __nasver__ "11.2"
#endif #endif
#include <cstdint> #include <cstdint>

View File

@ -222,7 +222,7 @@ void gc::init(
continue; continue;
} }
strs[i] = var::gcobj(new nas_val(vm_type::vm_str)); strs[i] = var::gcobj(new nas_val(vm_type::vm_str));
strs[i].val.gcobj->unmutable = 1; strs[i].val.gcobj->immutable = 1;
strs[i].str() = constant_strings[i]; strs[i].str() = constant_strings[i];
} }
@ -234,7 +234,7 @@ void gc::init(
continue; continue;
} }
env_argv[i] = var::gcobj(new nas_val(vm_type::vm_str)); env_argv[i] = var::gcobj(new nas_val(vm_type::vm_str));
env_argv[i].val.gcobj->unmutable = 1; env_argv[i].val.gcobj->immutable = 1;
env_argv[i].str() = argv[i]; env_argv[i].str() = argv[i];
} }
} }

View File

@ -177,7 +177,8 @@ private:
token dots(); token dots();
token calc_opr(); token calc_opr();
public: public:
lexer(): line(1), column(0), ptr(0), filename(""), res(""), invalid_char(0) {} lexer(): line(1), column(0), ptr(0),
filename(""), res(""), invalid_char(0) {}
const error& scan(const std::string&); const error& scan(const std::string&);
const std::vector<token>& result() const {return toks;} const std::vector<token>& result() const {return toks;}
}; };

View File

@ -198,7 +198,7 @@ std::ostream& operator<<(std::ostream& out, nas_map& mp) {
nas_val::nas_val(vm_type val_type) { nas_val::nas_val(vm_type val_type) {
mark = gc_status::collected; mark = gc_status::collected;
type = val_type; type = val_type;
unmutable = 0; immutable = 0;
switch(val_type) { switch(val_type) {
case vm_type::vm_str: ptr.str = new std::string; break; case vm_type::vm_str: ptr.str = new std::string; break;
case vm_type::vm_vec: ptr.vec = new nas_vec; break; case vm_type::vm_vec: ptr.vec = new nas_vec; break;

View File

@ -250,7 +250,7 @@ struct nas_map {
}; };
struct nas_val { struct nas_val {
enum class gc_status:u8 { enum class gc_status: u8 {
uncollected = 0, uncollected = 0,
collected, collected,
found found
@ -258,7 +258,7 @@ struct nas_val {
gc_status mark; gc_status mark;
vm_type type; // value type vm_type type; // value type
u8 unmutable; // used to mark if a string is unmutable u8 immutable; // used to mark if a string is immutable
union { union {
std::string* str; std::string* str;
nas_vec* vec; nas_vec* vec;

View File

@ -48,7 +48,7 @@ var builtin_fld(context* ctx, gc* ngc) {
auto str = local[1]; auto str = local[1];
auto startbit = local[2]; auto startbit = local[2];
auto length = local[3]; auto length = local[3];
if (!str.is_str() || str.val.gcobj->unmutable) { if (!str.is_str() || str.val.gcobj->immutable) {
return nas_err("bits::fld", "\"str\" must be mutable string"); return nas_err("bits::fld", "\"str\" must be mutable string");
} }
if (!startbit.is_num() || !length.is_num()) { if (!startbit.is_num() || !length.is_num()) {
@ -78,7 +78,7 @@ var builtin_sfld(context* ctx, gc* ngc) {
auto str = local[1]; auto str = local[1];
auto startbit = local[2]; auto startbit = local[2];
auto length = local[3]; auto length = local[3];
if (!str.is_str() || str.val.gcobj->unmutable) { if (!str.is_str() || str.val.gcobj->immutable) {
return nas_err("bits::sfld", "\"str\" must be mutable string"); return nas_err("bits::sfld", "\"str\" must be mutable string");
} }
if (!startbit.is_num() || !length.is_num()) { if (!startbit.is_num() || !length.is_num()) {
@ -112,7 +112,7 @@ var builtin_setfld(context* ctx, gc* ngc) {
auto startbit = local[2]; auto startbit = local[2];
auto length = local[3]; auto length = local[3];
auto value = local[4]; auto value = local[4];
if (!str.is_str() || str.val.gcobj->unmutable) { if (!str.is_str() || str.val.gcobj->immutable) {
return nas_err("bits::setfld", "\"str\" must be mutable string"); return nas_err("bits::setfld", "\"str\" must be mutable string");
} }
if (!startbit.is_num() || !length.is_num() || !value.is_num()) { if (!startbit.is_num() || !length.is_num() || !value.is_num()) {

View File

@ -84,7 +84,7 @@ var builtin_read(context* ctx, gc* ngc) {
if (!file_descriptor.object_check(file_type_name)) { if (!file_descriptor.object_check(file_type_name)) {
return nas_err("io::read", "not a valid filehandle"); return nas_err("io::read", "not a valid filehandle");
} }
if (!buffer.is_str() || buffer.val.gcobj->unmutable) { if (!buffer.is_str() || buffer.val.gcobj->immutable) {
return nas_err("io::read", "\"buf\" must be mutable string"); return nas_err("io::read", "\"buf\" must be mutable string");
} }
if (!length.is_num()) { if (!length.is_num()) {
@ -102,7 +102,7 @@ var builtin_read(context* ctx, gc* ngc) {
static_cast<FILE*>(file_descriptor.ghost().pointer) static_cast<FILE*>(file_descriptor.ghost().pointer)
); );
buffer.str() = temp_buffer; buffer.str() = temp_buffer;
buffer.val.gcobj->unmutable = true; buffer.val.gcobj->immutable = true;
delete []temp_buffer; delete []temp_buffer;
return var::num(read_size); return var::num(read_size);
} }