📝 change opcode dump format
This commit is contained in:
parent
8759d12eda
commit
00a655a9fc
|
@ -25,7 +25,7 @@ var fib(var* args, usize size, gc* ngc) {
|
||||||
|
|
||||||
var quick_fib(var* args, usize size, gc* ngc) {
|
var quick_fib(var* args, usize size, gc* ngc) {
|
||||||
if (!size) {
|
if (!size) {
|
||||||
return nas_err("quick_fib","lack arguments");
|
return nas_err("quick_fib", "lack arguments");
|
||||||
}
|
}
|
||||||
double num = args[0].to_num();
|
double num = args[0].to_num();
|
||||||
if (num<2) {
|
if (num<2) {
|
||||||
|
|
|
@ -530,7 +530,7 @@ void codegen::single_def(definition_expr* node) {
|
||||||
void codegen::multi_def(definition_expr* node) {
|
void codegen::multi_def(definition_expr* node) {
|
||||||
auto& identifiers = node->get_variables()->get_variables();
|
auto& identifiers = node->get_variables()->get_variables();
|
||||||
usize size = identifiers.size();
|
usize size = identifiers.size();
|
||||||
// (var a,b,c) = (c,b,a);
|
// (var a, b, c) = (c, b, a);
|
||||||
if (node->get_tuple()) {
|
if (node->get_tuple()) {
|
||||||
auto& vals = node->get_tuple()->get_elements();
|
auto& vals = node->get_tuple()->get_elements();
|
||||||
if (identifiers.size()>vals.size()) {
|
if (identifiers.size()>vals.size()) {
|
||||||
|
@ -557,7 +557,7 @@ void codegen::multi_def(definition_expr* node) {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// (var a,b,c) = [0,1,2];
|
// (var a, b, c) = [0, 1, 2];
|
||||||
calc_gen(node->get_value());
|
calc_gen(node->get_value());
|
||||||
for(usize i = 0; i<size; ++i) {
|
for(usize i = 0; i<size; ++i) {
|
||||||
emit(op_callvi, i, node->get_value()->get_location());
|
emit(op_callvi, i, node->get_value()->get_location());
|
||||||
|
|
|
@ -46,7 +46,7 @@ void operand_line_counter::dump_operand_count() const {
|
||||||
if (!rate) {
|
if (!rate) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::clog << " " << opname[i.first] << " : ";
|
std::clog << " " << oprand_name_table[i.first] << " : ";
|
||||||
std::clog << i.second << " (" << rate << "%)\n";
|
std::clog << i.second << " (" << rate << "%)\n";
|
||||||
}
|
}
|
||||||
std::clog << " total : " << total << '\n';
|
std::clog << " total : " << total << '\n';
|
||||||
|
@ -133,7 +133,7 @@ void dbg::help() const {
|
||||||
<< " l, local | see local values\n"
|
<< " l, local | see local values\n"
|
||||||
<< " u, upval | see upvalue\n"
|
<< " u, upval | see upvalue\n"
|
||||||
<< " r, register | show vm register detail\n"
|
<< " r, register | show vm register detail\n"
|
||||||
<< " a, all | show global,local and upvalue\n"
|
<< " a, all | show global, local and upvalue\n"
|
||||||
<< " n, next | execute next bytecode\n"
|
<< " n, next | execute next bytecode\n"
|
||||||
<< " q, exit | exit debugger\n"
|
<< " q, exit | exit debugger\n"
|
||||||
<< "<option> <filename> <line>\n"
|
<< "<option> <filename> <line>\n"
|
||||||
|
@ -171,7 +171,7 @@ void dbg::step_info() {
|
||||||
<< codestream(bytecode[i], i)
|
<< codestream(bytecode[i], i)
|
||||||
<< reset << "\n";
|
<< reset << "\n";
|
||||||
}
|
}
|
||||||
stack_info(10);
|
stack_info(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dbg::interact() {
|
void dbg::interact() {
|
||||||
|
|
|
@ -24,7 +24,7 @@ void gc::mark() {
|
||||||
mark_context_root(bfs);
|
mark_context_root(bfs);
|
||||||
|
|
||||||
// concurrent mark, experimental
|
// concurrent mark, experimental
|
||||||
if (memory.size()>UINT16_MAX && bfs.size()>8192) {
|
if (memory.size()>UINT16_MAX && bfs.size()>32) {
|
||||||
flag_concurrent_mark_triggered = true;
|
flag_concurrent_mark_triggered = true;
|
||||||
usize size = bfs.size();
|
usize size = bfs.size();
|
||||||
std::thread t0(&gc::concurrent_mark, this, std::ref(bfs), 0, size/4);
|
std::thread t0(&gc::concurrent_mark, this, std::ref(bfs), 0, size/4);
|
||||||
|
|
|
@ -116,7 +116,7 @@ public:
|
||||||
// module function type
|
// module function type
|
||||||
typedef var (*module_func)(var*, usize, gc*);
|
typedef var (*module_func)(var*, usize, gc*);
|
||||||
|
|
||||||
// module function stores in tables with this type, end with {nullptr,nullptr}
|
// module function stores in tables with this type, end with {nullptr, nullptr}
|
||||||
struct module_func_info {
|
struct module_func_info {
|
||||||
const char* name;
|
const char* name;
|
||||||
module_func fd;
|
module_func fd;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace nasal {
|
namespace nasal {
|
||||||
|
|
||||||
const char* opname[] = {
|
const char* oprand_name_table[] = {
|
||||||
"exit ", "repl ", "intl ", "loadg ",
|
"exit ", "repl ", "intl ", "loadg ",
|
||||||
"loadl ", "loadu ", "pnum ", "pnil ",
|
"loadl ", "loadu ", "pnum ", "pnil ",
|
||||||
"pstr ", "newv ", "newh ", "newf ",
|
"pstr ", "newv ", "newh ", "newf ",
|
||||||
|
@ -42,67 +42,107 @@ void codestream::dump(std::ostream& out) const {
|
||||||
using std::setfill;
|
using std::setfill;
|
||||||
using std::hex;
|
using std::hex;
|
||||||
using std::dec;
|
using std::dec;
|
||||||
auto op = code.op;
|
|
||||||
auto num = code.num;
|
const auto op = code.op;
|
||||||
|
const auto num = code.num;
|
||||||
|
|
||||||
|
// dump operand index and bytecode(hex format)
|
||||||
out << hex << "0x"
|
out << hex << "0x"
|
||||||
<< setw(6) << setfill('0') << index << " "
|
<< setw(6) << setfill('0') << index << " "
|
||||||
<< setw(2) << setfill('0') << static_cast<u32>(op) << " "
|
<< setw(2) << setfill('0') << static_cast<u32>(op) << ":" << dec;
|
||||||
<< setw(2) << setfill('0') << ((num>>16)&0xff) << " "
|
|
||||||
<< setw(2) << setfill('0') << ((num>>8)&0xff) << " "
|
// dump immediate number(hex format)
|
||||||
<< setw(2) << setfill('0') << (num&0xff) << " "
|
for(i32 i = 64-8; i>=0; i -= 8) {
|
||||||
<<opname[op]<<" "<<dec;
|
out << hex << setw(2) << setfill('0') << ((num>>i)&0xff) << dec << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
// dump operand name
|
||||||
|
out << " " << oprand_name_table[op] << " ";
|
||||||
|
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case op_addeq: case op_subeq:
|
case op_addeq:
|
||||||
case op_muleq: case op_diveq:
|
case op_subeq:
|
||||||
case op_lnkeq: case op_meq:
|
case op_muleq:
|
||||||
case op_btandeq: case op_btoreq:
|
case op_diveq:
|
||||||
|
case op_lnkeq:
|
||||||
|
case op_meq:
|
||||||
|
case op_btandeq:
|
||||||
|
case op_btoreq:
|
||||||
case op_btxoreq:
|
case op_btxoreq:
|
||||||
out << hex << "0x" << num << dec << " sp-" << num; break;
|
out << hex << "0x" << num << dec << " sp-" << num;
|
||||||
case op_addeqc: case op_subeqc:
|
break;
|
||||||
case op_muleqc:case op_diveqc:
|
case op_addeqc:
|
||||||
out << hex << "0x" << num << dec
|
case op_subeqc:
|
||||||
<< " (" << const_number[num] << ")"; break;
|
case op_muleqc:
|
||||||
|
case op_diveqc:
|
||||||
|
out << hex << "0x" << num << dec;
|
||||||
|
out << " (" << const_number[num] << ")";
|
||||||
|
break;
|
||||||
case op_lnkeqc:
|
case op_lnkeqc:
|
||||||
out << hex << "0x" << num << dec
|
out << hex << "0x" << num << dec;
|
||||||
<< " (" << rawstr(const_string[num], 16) << ")"; break;
|
out << " (" << rawstr(const_string[num], 16) << ")";
|
||||||
case op_addecp: case op_subecp:
|
break;
|
||||||
case op_mulecp: case op_divecp:
|
case op_addecp:
|
||||||
out << hex << "0x" << num << dec
|
case op_subecp:
|
||||||
<< " (" << const_number[num] << ") sp-1"; break;
|
case op_mulecp:
|
||||||
|
case op_divecp:
|
||||||
|
out << hex << "0x" << num << dec;
|
||||||
|
out << " (" << const_number[num] << ") sp-1";
|
||||||
|
break;
|
||||||
case op_lnkecp:
|
case op_lnkecp:
|
||||||
out << hex << "0x" << num << dec
|
out << hex << "0x" << num << dec;
|
||||||
<< " (" << rawstr(const_string[num], 16) << ") sp-1"; break;
|
out << " (" << rawstr(const_string[num], 16) << ") sp-1";
|
||||||
case op_addc: case op_subc:
|
break;
|
||||||
case op_mulc: case op_divc:
|
case op_addc:
|
||||||
case op_lessc: case op_leqc:
|
case op_subc:
|
||||||
case op_grtc: case op_geqc:
|
case op_mulc:
|
||||||
|
case op_divc:
|
||||||
|
case op_lessc:
|
||||||
|
case op_leqc:
|
||||||
|
case op_grtc:
|
||||||
|
case op_geqc:
|
||||||
case op_pnum:
|
case op_pnum:
|
||||||
out << hex << "0x" << num << dec
|
out << hex << "0x" << num << dec;
|
||||||
<< " (" << const_number[num] << ")"; break;
|
out << " (" << const_number[num] << ")";
|
||||||
case op_callvi: case op_newv:
|
break;
|
||||||
case op_callfv: case op_repl:
|
case op_callvi:
|
||||||
case op_intl: case op_findex:
|
case op_newv:
|
||||||
case op_feach: case op_newf:
|
case op_callfv:
|
||||||
case op_jmp: case op_jt:
|
case op_repl:
|
||||||
case op_jf: case op_callg:
|
case op_intl:
|
||||||
case op_mcallg: case op_loadg:
|
case op_findex:
|
||||||
case op_calll: case op_mcalll:
|
case op_feach:
|
||||||
|
case op_newf:
|
||||||
|
case op_jmp:
|
||||||
|
case op_jt:
|
||||||
|
case op_jf:
|
||||||
|
case op_callg:
|
||||||
|
case op_mcallg:
|
||||||
|
case op_loadg:
|
||||||
|
case op_calll:
|
||||||
|
case op_mcalll:
|
||||||
case op_loadl:
|
case op_loadl:
|
||||||
out << hex << "0x" << num << dec; break;
|
out << hex << "0x" << num << dec; break;
|
||||||
case op_callb:
|
case op_callb:
|
||||||
out << hex << "0x" << num << " <" << natives[num].name
|
out << hex << "0x" << num << " <" << natives[num].name
|
||||||
<< "@0x" << reinterpret_cast<u64>(natives[num].func)
|
<< "@0x" << reinterpret_cast<u64>(natives[num].func)
|
||||||
<< dec << ">"; break;
|
<< dec << ">"; break;
|
||||||
case op_upval: case op_mupval:
|
case op_upval:
|
||||||
|
case op_mupval:
|
||||||
case op_loadu:
|
case op_loadu:
|
||||||
out << hex << "0x" << ((num>>16)&0xffff)
|
out << hex << "0x" << ((num>>16)&0xffff)
|
||||||
<< "[0x" << (num&0xffff) << "]" << dec; break;
|
<< "[0x" << (num&0xffff) << "]" << dec; break;
|
||||||
case op_happ: case op_pstr:
|
case op_happ:
|
||||||
case op_lnkc: case op_callh:
|
case op_pstr:
|
||||||
case op_mcallh: case op_para:
|
case op_lnkc:
|
||||||
case op_deft: case op_dyn:
|
case op_callh:
|
||||||
out << hex << "0x" << num << dec
|
case op_mcallh:
|
||||||
<< " (" << rawstr(const_string[num], 16) << ")"; break;
|
case op_para:
|
||||||
|
case op_deft:
|
||||||
|
case op_dyn:
|
||||||
|
out << hex << "0x" << num << dec;
|
||||||
|
out << " (" << rawstr(const_string[num], 16) << ")";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (files) {
|
if (files) {
|
||||||
out << hex << "0x" << num << dec;
|
out << hex << "0x" << num << dec;
|
||||||
|
|
|
@ -71,8 +71,8 @@ enum op_code_type: u8 {
|
||||||
op_geqc, // >= const compare operator
|
op_geqc, // >= const compare operator
|
||||||
op_pop, // pop a value out of stack top
|
op_pop, // pop a value out of stack top
|
||||||
op_jmp, // jump absolute address with no condition
|
op_jmp, // jump absolute address with no condition
|
||||||
op_jt, // used in operator and/or,jmp when condition is true and DO NOT POP
|
op_jt, // used in operator and/or, jmp when condition is true and DO NOT POP
|
||||||
op_jf, // used in conditional/loop,jmp when condition is false and POP STACK
|
op_jf, // used in conditional/loop, jmp when condition is false and POP STACK
|
||||||
op_cnt, // add counter for forindex/foreach
|
op_cnt, // add counter for forindex/foreach
|
||||||
op_findex, // index counter on the top of forindex_stack plus 1
|
op_findex, // index counter on the top of forindex_stack plus 1
|
||||||
op_feach, // index counter on the top of forindex_stack plus 1 and get the value in vector
|
op_feach, // index counter on the top of forindex_stack plus 1 and get the value in vector
|
||||||
|
@ -127,6 +127,6 @@ public:
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream&, const codestream&);
|
std::ostream& operator<<(std::ostream&, const codestream&);
|
||||||
|
|
||||||
extern const char* opname[];
|
extern const char* oprand_name_table[];
|
||||||
|
|
||||||
}
|
}
|
|
@ -156,7 +156,7 @@ bool parse::check_in_curve_multi_definition() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse::check_special_call() {
|
bool parse::check_special_call() {
|
||||||
// special call means like this: function_name(a:1,b:2,c:3);
|
// special call means like this: function_name(a:1, b:2, c:3);
|
||||||
u64 check_ptr = ptr, curve = 1, bracket = 0, brace = 0;
|
u64 check_ptr = ptr, curve = 1, bracket = 0, brace = 0;
|
||||||
while(toks[++check_ptr].type!=tok::eof && curve) {
|
while(toks[++check_ptr].type!=tok::eof && curve) {
|
||||||
switch(toks[check_ptr].type) {
|
switch(toks[check_ptr].type) {
|
||||||
|
@ -744,7 +744,7 @@ call_function* parse::callf() {
|
||||||
// this is the FIRST set of calculation/hashmember
|
// this is the FIRST set of calculation/hashmember
|
||||||
// array end with tok::null=0
|
// array end with tok::null=0
|
||||||
const tok panic[] = {
|
const tok panic[] = {
|
||||||
tok::id, tok::str,tok::num, tok::tktrue,
|
tok::id, tok::str, tok::num, tok::tktrue,
|
||||||
tok::tkfalse, tok::opnot, tok::sub, tok::tknil,
|
tok::tkfalse, tok::opnot, tok::sub, tok::tknil,
|
||||||
tok::func, tok::var, tok::lcurve, tok::floater,
|
tok::func, tok::var, tok::lcurve, tok::floater,
|
||||||
tok::lbrace, tok::lbracket, tok::null
|
tok::lbrace, tok::lbracket, tok::null
|
||||||
|
@ -843,7 +843,7 @@ tuple_expr* parse::multi_scalar() {
|
||||||
// if check_call_memory is true,
|
// if check_call_memory is true,
|
||||||
// we will check if value called here can reach a memory space
|
// we will check if value called here can reach a memory space
|
||||||
const tok panic[] = {
|
const tok panic[] = {
|
||||||
tok::id, tok::str,tok::num, tok::tktrue,
|
tok::id, tok::str, tok::num, tok::tktrue,
|
||||||
tok::tkfalse, tok::opnot, tok::sub, tok::tknil,
|
tok::tkfalse, tok::opnot, tok::sub, tok::tknil,
|
||||||
tok::func, tok::var, tok::lcurve, tok::floater,
|
tok::func, tok::var, tok::lcurve, tok::floater,
|
||||||
tok::lbrace, tok::lbracket, tok::null
|
tok::lbrace, tok::lbracket, tok::null
|
||||||
|
|
|
@ -384,7 +384,7 @@ nas_map& var::map() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var nas_err(const std::string& error_function_name, const std::string& info) {
|
var nas_err(const std::string& error_function_name, const std::string& info) {
|
||||||
std::cerr << "[vm] " << error_function_name << ": " << info << "\n";
|
std::cerr << "\n[vm] " << error_function_name << ": " << info << "\n";
|
||||||
return var::none();
|
return var::none();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,8 +78,8 @@ void vm::value_info(var& val) {
|
||||||
<< "> " << rawstr(val.str(), 16)
|
<< "> " << rawstr(val.str(), 16)
|
||||||
<< std::dec; break;
|
<< std::dec; break;
|
||||||
case vm_type::vm_func: std::clog << "| func | <0x" << std::hex << p
|
case vm_type::vm_func: std::clog << "| func | <0x" << std::hex << p
|
||||||
<< "> entry:0x" << val.func().entry
|
<< std::dec << "> " << val.func();
|
||||||
<< std::dec; break;
|
break;
|
||||||
case vm_type::vm_upval:std::clog << "| upval| <0x" << std::hex << p
|
case vm_type::vm_upval:std::clog << "| upval| <0x" << std::hex << p
|
||||||
<< std::dec << "> [" << val.upval().size
|
<< std::dec << "> [" << val.upval().size
|
||||||
<< " val]"; break;
|
<< " val]"; break;
|
||||||
|
@ -124,7 +124,7 @@ void vm::function_detail_info(const nas_func& func) {
|
||||||
}
|
}
|
||||||
if (func.dynamic_parameter_index>=0) {
|
if (func.dynamic_parameter_index>=0) {
|
||||||
std::clog << (argument_list.size()? ", ":"");
|
std::clog << (argument_list.size()? ", ":"");
|
||||||
std::clog << const_string[func.dynamic_parameter_index] << "...";
|
std::clog << func.dynamic_parameter_name << "...";
|
||||||
}
|
}
|
||||||
std::clog << ") ";
|
std::clog << ") ";
|
||||||
const auto& code = bytecode[func.entry];
|
const auto& code = bytecode[func.entry];
|
||||||
|
@ -192,7 +192,7 @@ void vm::trace_back() {
|
||||||
if (same) {
|
if (same) {
|
||||||
std::clog << " 0x" << std::hex
|
std::clog << " 0x" << std::hex
|
||||||
<< std::setw(6) << std::setfill('0')
|
<< std::setw(6) << std::setfill('0')
|
||||||
<< prev << std::dec << " "
|
<< prev << std::dec << " "
|
||||||
<< same << " same call(s)\n";
|
<< same << " same call(s)\n";
|
||||||
same = 0;
|
same = 0;
|
||||||
}
|
}
|
||||||
|
@ -201,12 +201,15 @@ void vm::trace_back() {
|
||||||
// the first called place has no same calls
|
// the first called place has no same calls
|
||||||
}
|
}
|
||||||
|
|
||||||
void vm::stack_info(const u32 limit = 10) {
|
void vm::stack_info(const u64 limit = 16) {
|
||||||
var* top = ctx.top;
|
var* top = ctx.top;
|
||||||
var* bottom = ctx.stack;
|
var* bottom = ctx.stack;
|
||||||
std::clog << "\nstack (0x" << std::hex << reinterpret_cast<u64>(bottom);
|
const auto stack_address = reinterpret_cast<u64>(bottom);
|
||||||
std::clog << std::dec << ", limit " << limit << ", total ";
|
|
||||||
|
std::clog << "\nvm stack (0x" << std::hex << stack_address << std::dec;
|
||||||
|
std::clog << ", limit " << limit << ", total ";
|
||||||
std::clog << (top<bottom? 0:static_cast<i64>(top-bottom+1)) << ")\n";
|
std::clog << (top<bottom? 0:static_cast<i64>(top-bottom+1)) << ")\n";
|
||||||
|
|
||||||
for(u32 i = 0; i<limit && top>=bottom; ++i, --top) {
|
for(u32 i = 0; i<limit && top>=bottom; ++i, --top) {
|
||||||
std::clog << " 0x" << std::hex
|
std::clog << " 0x" << std::hex
|
||||||
<< std::setw(6) << std::setfill('0')
|
<< std::setw(6) << std::setfill('0')
|
||||||
|
@ -388,7 +391,7 @@ std::string vm::type_name_string(const var& value) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void vm::die(const std::string& str) {
|
void vm::die(const std::string& str) {
|
||||||
std::cerr << "[vm] error: " << str << "\n";
|
std::cerr << "\n[vm] error: " << str << "\n";
|
||||||
function_call_trace();
|
function_call_trace();
|
||||||
trace_back();
|
trace_back();
|
||||||
stack_info();
|
stack_info();
|
||||||
|
|
|
@ -66,7 +66,7 @@ protected:
|
||||||
void function_detail_info(const nas_func&);
|
void function_detail_info(const nas_func&);
|
||||||
void function_call_trace();
|
void function_call_trace();
|
||||||
void trace_back();
|
void trace_back();
|
||||||
void stack_info(const u32);
|
void stack_info(const u64);
|
||||||
void register_info();
|
void register_info();
|
||||||
void global_state();
|
void global_state();
|
||||||
void local_state();
|
void local_state();
|
||||||
|
@ -676,7 +676,7 @@ inline void vm::o_callvi() {
|
||||||
die("must use a vector but get "+type_name_string(val));
|
die("must use a vector but get "+type_name_string(val));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// cannot use operator[],because this may cause overflow
|
// cannot use operator[], because this may cause overflow
|
||||||
(++ctx.top)[0] = val.vec().get_value(imm[ctx.pc]);
|
(++ctx.top)[0] = val.vec().get_value(imm[ctx.pc]);
|
||||||
if (ctx.top[0].is_none()) {
|
if (ctx.top[0].is_none()) {
|
||||||
die(report_out_of_range(imm[ctx.pc], val.vec().size()));
|
die(report_out_of_range(imm[ctx.pc], val.vec().size()));
|
||||||
|
|
|
@ -41,7 +41,7 @@ var builtin_u32not(context* ctx, gc* ngc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var builtin_fld(context* ctx, gc* ngc) {
|
var builtin_fld(context* ctx, gc* ngc) {
|
||||||
// bits.fld(s,0,3);
|
// bits.fld(s, 0, 3);
|
||||||
// if s stores 10100010(162)
|
// if s stores 10100010(162)
|
||||||
// will get 101(5)
|
// will get 101(5)
|
||||||
auto local = ctx->localr;
|
auto local = ctx->localr;
|
||||||
|
@ -70,7 +70,7 @@ var builtin_fld(context* ctx, gc* ngc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var builtin_sfld(context* ctx, gc* ngc) {
|
var builtin_sfld(context* ctx, gc* ngc) {
|
||||||
// bits.sfld(s,0,3);
|
// bits.sfld(s, 0, 3);
|
||||||
// if s stores 10100010(162)
|
// if s stores 10100010(162)
|
||||||
// will get 101(5) then this will be signed extended to
|
// will get 101(5) then this will be signed extended to
|
||||||
// 11111101(-3)
|
// 11111101(-3)
|
||||||
|
@ -103,7 +103,7 @@ var builtin_sfld(context* ctx, gc* ngc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var builtin_setfld(context* ctx, gc* ngc) {
|
var builtin_setfld(context* ctx, gc* ngc) {
|
||||||
// bits.setfld(s,0,8,69);
|
// bits.setfld(s, 0, 8, 69);
|
||||||
// set 01000101(69) to string will get this:
|
// set 01000101(69) to string will get this:
|
||||||
// 10100010(162)
|
// 10100010(162)
|
||||||
// so s[0]=162
|
// so s[0]=162
|
||||||
|
|
|
@ -324,7 +324,7 @@ var builtin_substr(context* ctx, gc* ngc) {
|
||||||
if (begin>=str.str().length()) {
|
if (begin>=str.str().length()) {
|
||||||
return nas_err("susbtr", "begin index out of range: "+std::to_string(begin));
|
return nas_err("susbtr", "begin index out of range: "+std::to_string(begin));
|
||||||
}
|
}
|
||||||
return ngc->newstr(str.str().substr(begin,length));
|
return ngc->newstr(str.str().substr(begin, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
var builtin_streq(context* ctx, gc* ngc) {
|
var builtin_streq(context* ctx, gc* ngc) {
|
||||||
|
@ -392,22 +392,22 @@ var builtin_cmp(context* ctx, gc* ngc) {
|
||||||
|
|
||||||
var builtin_chr(context* ctx, gc* ngc) {
|
var builtin_chr(context* ctx, gc* ngc) {
|
||||||
const char* extend[] = {
|
const char* extend[] = {
|
||||||
"€"," ","‚","ƒ","„","…","†","‡",
|
"€", " ", "‚", "ƒ", "„", "…", "†", "‡",
|
||||||
"ˆ","‰","Š","‹","Œ"," ","Ž"," ",
|
"ˆ", "‰", "Š", "‹", "Œ", " ", "Ž", " ",
|
||||||
" ","‘","’","“","”","•","–","—",
|
" ", "‘", "’", "“", "”", "•", "–", "—",
|
||||||
"˜","™","š","›","œ"," ","ž","Ÿ",
|
"˜", "™", "š", "›", "œ", " ", "ž", "Ÿ",
|
||||||
" ","¡","¢","£","¤","¥","¦","§",
|
" ", "¡", "¢", "£", "¤", "¥", "¦", "§",
|
||||||
"¨","©","ª","«","¬"," ","®","¯",
|
"¨", "©", "ª", "«", "¬", " ", "®", "¯",
|
||||||
"°","±","²","³","´","µ","¶","·",
|
"°", "±", "²", "³", "´", "µ", "¶", "·",
|
||||||
"¸","¹","º","»","¼","½","¾","¿",
|
"¸", "¹", "º", "»", "¼", "½", "¾", "¿",
|
||||||
"À","Á","Â","Ã","Ä","Å","Æ","Ç",
|
"À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç",
|
||||||
"È","É","Ê","Ë","Ì","Í","Î","Ï",
|
"È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï",
|
||||||
"Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×",
|
"Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×",
|
||||||
"Ø","Ù","Ú","Û","Ü","Ý","Þ","ß",
|
"Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß",
|
||||||
"à","á","â","ã","ä","å","æ","ç",
|
"à", "á", "â", "ã", "ä", "å", "æ", "ç",
|
||||||
"è","é","ê","ë","ì","í","î","ï",
|
"è", "é", "ê", "ë", "ì", "í", "î", "ï",
|
||||||
"ð","ñ","ò","ó","ô","õ","ö","÷",
|
"ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷",
|
||||||
"ø","ù","ú","û","ü","ý","þ","ÿ"
|
"ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ"
|
||||||
};
|
};
|
||||||
auto num = static_cast<i32>(ctx->localr[1].num());
|
auto num = static_cast<i32>(ctx->localr[1].num());
|
||||||
if (0<=num && num<128) {
|
if (0<=num && num<128) {
|
||||||
|
@ -484,7 +484,7 @@ std::string md5(const std::string& src) {
|
||||||
std::vector<u32> buff;
|
std::vector<u32> buff;
|
||||||
usize num = ((src.length()+8)>>6)+1;
|
usize num = ((src.length()+8)>>6)+1;
|
||||||
usize buffsize = num<<4;
|
usize buffsize = num<<4;
|
||||||
buff.resize(buffsize,0);
|
buff.resize(buffsize, 0);
|
||||||
for(usize i = 0; i<src.length(); i++) {
|
for(usize i = 0; i<src.length(); i++) {
|
||||||
buff[i>>2] |= (static_cast<u8>(src[i]))<<((i&0x3)<<3);
|
buff[i>>2] |= (static_cast<u8>(src[i]))<<((i&0x3)<<3);
|
||||||
}
|
}
|
||||||
|
@ -494,37 +494,45 @@ std::string md5(const std::string& src) {
|
||||||
|
|
||||||
// u32(abs(sin(i+1))*(2pow32))
|
// u32(abs(sin(i+1))*(2pow32))
|
||||||
const u32 k[] = {
|
const u32 k[] = {
|
||||||
0xd76aa478,0xe8c7b756,0x242070db,0xc1bdceee,0xf57c0faf,0x4787c62a,0xa8304613,0xfd469501,
|
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
||||||
0x698098d8,0x8b44f7af,0xffff5bb1,0x895cd7be,0x6b901122,0xfd987193,0xa679438e,0x49b40821,
|
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
||||||
0xf61e2562,0xc040b340,0x265e5a51,0xe9b6c7aa,0xd62f105d,0x02441453,0xd8a1e681,0xe7d3fbc8,
|
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
||||||
0x21e1cde6,0xc33707d6,0xf4d50d87,0x455a14ed,0xa9e3e905,0xfcefa3f8,0x676f02d9,0x8d2a4c8a,
|
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
||||||
0xfffa3942,0x8771f681,0x6d9d6122,0xfde5380c,0xa4beea44,0x4bdecfa9,0xf6bb4b60,0xbebfbc70,
|
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
||||||
0x289b7ec6,0xeaa127fa,0xd4ef3085,0x04881d05,0xd9d4d039,0xe6db99e5,0x1fa27cf8,0xc4ac5665,
|
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
||||||
0xf4292244,0x432aff97,0xab9423a7,0xfc93a039,0x655b59c3,0x8f0ccc92,0xffeff47d,0x85845dd1,
|
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
||||||
0x6fa87e4f,0xfe2ce6e0,0xa3014314,0x4e0811a1,0xf7537e82,0xbd3af235,0x2ad7d2bb,0xeb86d391
|
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
||||||
|
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
||||||
|
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
||||||
|
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
||||||
|
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
||||||
|
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
||||||
|
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
||||||
|
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
||||||
|
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
|
||||||
};
|
};
|
||||||
|
|
||||||
// left shift bits
|
// left shift bits
|
||||||
const u32 s[] = {
|
const u32 s[] = {
|
||||||
7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,
|
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
|
||||||
5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,
|
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
|
||||||
4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,
|
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
|
||||||
6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21
|
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
|
||||||
};
|
};
|
||||||
|
|
||||||
// index
|
// index
|
||||||
const u32 idx[] = {
|
const u32 idx[] = {
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, // g=i
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // g=i
|
||||||
1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12, // g=(5*i+1)%16;
|
1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, // g=(5*i+1)%16;
|
||||||
5,8,11,14,1,4,7,10,13,0,3,6,9,12,15,2, // g=(3*i+5)%16;
|
5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, // g=(3*i+5)%16;
|
||||||
0,7,14,5,12,3,10,1,8,15,6,13,4,11,2,9 // g=(7*i)%16;
|
0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 // g=(7*i)%16;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define shift(x,n) (((x)<<(n))|((x)>>(32-(n)))) // cycle left shift
|
#define shift(x, n) (((x)<<(n))|((x)>>(32-(n)))) // cycle left shift
|
||||||
#define md5f(x,y,z) (((x)&(y))|((~x)&(z)))
|
#define md5f(x, y, z) (((x)&(y))|((~x)&(z)))
|
||||||
#define md5g(x,y,z) (((x)&(z))|((y)&(~z)))
|
#define md5g(x, y, z) (((x)&(z))|((y)&(~z)))
|
||||||
#define md5h(x,y,z) ((x)^(y)^(z))
|
#define md5h(x, y, z) ((x)^(y)^(z))
|
||||||
#define md5i(x,y,z) ((y)^((x)|(~z)))
|
#define md5i(x, y, z) ((y)^((x)|(~z)))
|
||||||
|
|
||||||
u32 atmp = 0x67452301, btmp = 0xefcdab89;
|
u32 atmp = 0x67452301, btmp = 0xefcdab89;
|
||||||
u32 ctmp = 0x98badcfe, dtmp = 0x10325476;
|
u32 ctmp = 0x98badcfe, dtmp = 0x10325476;
|
||||||
|
@ -538,7 +546,7 @@ std::string md5(const std::string& src) {
|
||||||
u32 tmp = d;
|
u32 tmp = d;
|
||||||
d = c;
|
d = c;
|
||||||
c = b;
|
c = b;
|
||||||
b = b+shift((a+f+k[j]+buff[i+idx[j]]),s[j]);
|
b = b+shift((a+f+k[j]+buff[i+idx[j]]), s[j]);
|
||||||
a = tmp;
|
a = tmp;
|
||||||
}
|
}
|
||||||
atmp += a;
|
atmp += a;
|
||||||
|
|
|
@ -82,7 +82,7 @@ var builtin_logtime(context*, gc*);
|
||||||
var builtin_ghosttype(context*, gc*);
|
var builtin_ghosttype(context*, gc*);
|
||||||
|
|
||||||
// register builtin function's name and it's address here in this table below
|
// register builtin function's name and it's address here in this table below
|
||||||
// this table must end with {nullptr,nullptr}
|
// this table must end with {nullptr, nullptr}
|
||||||
struct nasal_builtin_table {
|
struct nasal_builtin_table {
|
||||||
const char* name;
|
const char* name;
|
||||||
var (*func)(context*, gc*);
|
var (*func)(context*, gc*);
|
||||||
|
|
Loading…
Reference in New Issue