Skip to content

Commit

Permalink
Better var name
Browse files Browse the repository at this point in the history
  • Loading branch information
h3x4n1um committed Sep 30, 2019
1 parent cdfbcba commit 103e36d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 55 deletions.
4 changes: 2 additions & 2 deletions rton-json/include/RTON_number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
using namespace std;

constexpr double log256(double q);
vector <uint8_t> uint64_to_uRTON(uint64_t q);
uint64_t uRTON_to_uint64(vector <uint8_t> q);
vector <uint8_t> uint64_t2uRTON_t(uint64_t q);
uint64_t uRTON_t2uint64_t(vector <uint8_t> q);
2 changes: 1 addition & 1 deletion rton-json/include/json2rton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ using namespace std;

int write_RTON(json js);
int get_utf8_size(string q);
int write_unsigned_RTON_num(vector <uint8_t> a);
int write_uRTON_t(vector <uint8_t> a);
int rton_encode();
int write_RTON_block(json js);
2 changes: 1 addition & 1 deletion rton-json/include/rton2json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ using json = nlohmann::basic_json<workaround_fifo_map>;
template <class T>
T read();
json json_decode();
vector <uint8_t> read_RTON_num();
vector <uint8_t> read_uRTON_t();
json read_RTON();
json read_RTON_block();
6 changes: 3 additions & 3 deletions rton-json/src/RTON_number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ constexpr double log256(double q){
return log2(q) / 8;
}

vector <uint8_t> uint64_to_uRTON(uint64_t q){
vector <uint8_t> uint64_t2uRTON_t(uint64_t q){
vector <uint8_t> res;
if (q <= 0x7f){
res.push_back(q);
Expand All @@ -18,12 +18,12 @@ vector <uint8_t> uint64_to_uRTON(uint64_t q){
q = q / 0x100 * 2;
if (temp > 0x7f) ++q;
else temp += 0x80; //reverse & 0x7f
res = uint64_to_uRTON(q);
res = uint64_t2uRTON_t(q);
res.insert(res.begin(), temp);
return res;
}

uint64_t uRTON_to_uint64(vector <uint8_t> q){
uint64_t uRTON_t2uint64_t(vector <uint8_t> q){
if (q.size() == 1){
if (q[0] > 0x7f) return UINT_MAX; //return max when RTON number has 1 byte and > 0x7f
else return q[0];
Expand Down
34 changes: 17 additions & 17 deletions rton-json/src/json2rton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int get_utf8_size(string q){
return utf8_size;
}

int write_unsigned_RTON_num(vector <uint8_t> a){
int write_uRTON_t(vector <uint8_t> a){
for (uint8_t i : a) output.write(reinterpret_cast<const char*> (&i), sizeof i);
return 0;
}
Expand Down Expand Up @@ -73,8 +73,8 @@ int write_RTON_block(json js){
debug_js["RTON stats"]["List of bytecodes"][to_hex_string((uint64_t) output.tellp() - 1)] = to_hex_string(rtid*0x100 + subset);
output.write(reinterpret_cast<const char*> (&subset), sizeof subset);

write_unsigned_RTON_num(uint64_to_uRTON(get_utf8_size(first_string)));
write_unsigned_RTON_num(uint64_to_uRTON(first_string.size()));
write_uRTON_t(uint64_t2uRTON_t(get_utf8_size(first_string)));
write_uRTON_t(uint64_t2uRTON_t(first_string.size()));
output << first_string;
if (subset == 0x2){
uint64_t first_uid = strtoull(second_string.c_str(), NULL, 10);
Expand All @@ -83,13 +83,13 @@ int write_RTON_block(json js){
second_string = second_string.substr(second_string.find(".") + 1);
int32_t third_uid = stoi(second_string, nullptr, 16);

write_unsigned_RTON_num(uint64_to_uRTON(second_uid));
write_unsigned_RTON_num(uint64_to_uRTON(first_uid));
write_uRTON_t(uint64_t2uRTON_t(second_uid));
write_uRTON_t(uint64_t2uRTON_t(first_uid));
output.write(reinterpret_cast<const char*> (&third_uid), sizeof third_uid);
}
else if (subset == 0x3){
write_unsigned_RTON_num(uint64_to_uRTON(get_utf8_size(second_string)));
write_unsigned_RTON_num(uint64_to_uRTON(second_string.size()));
write_uRTON_t(uint64_t2uRTON_t(get_utf8_size(second_string)));
write_uRTON_t(uint64_t2uRTON_t(second_string.size()));
output << second_string;
}
}
Expand All @@ -101,34 +101,34 @@ int write_RTON_block(json js){
if (map_0x91[temp] == 0){
debug_js["RTON stats"]["List of bytecodes"][to_hex_string(output.tellp())] = to_hex_string(ascii);
output.write(reinterpret_cast<const char*> (&ascii), sizeof ascii);
write_unsigned_RTON_num(uint64_to_uRTON(temp.size()));
write_uRTON_t(uint64_t2uRTON_t(temp.size()));
output << temp;

debug_js["RTON stats"]["0x91 stack"][to_hex_string(uint64_to_uRTON(map_0x91.size() - 1))] = temp;
debug_js["RTON stats"]["0x91 stack"][to_hex_string(uint64_t2uRTON_t(map_0x91.size() - 1))] = temp;
map_0x91[temp] = map_0x91.size();
}
else{
debug_js["RTON stats"]["List of bytecodes"][to_hex_string(output.tellp())] = to_hex_string(ascii_stack);
output.write(reinterpret_cast<const char*> (&ascii_stack), sizeof ascii_stack);
write_unsigned_RTON_num(uint64_to_uRTON(map_0x91[temp] - 1));
write_uRTON_t(uint64_t2uRTON_t(map_0x91[temp] - 1));
}
}
//utf-8
else{
if (map_0x93[temp] == 0){
debug_js["RTON stats"]["List of bytecodes"][to_hex_string(output.tellp())] = to_hex_string(utf8);
output.write(reinterpret_cast<const char*> (&utf8), sizeof utf8);
write_unsigned_RTON_num(uint64_to_uRTON(utf8_size));
write_unsigned_RTON_num(uint64_to_uRTON(temp.size()));
write_uRTON_t(uint64_t2uRTON_t(utf8_size));
write_uRTON_t(uint64_t2uRTON_t(temp.size()));
output << temp;

debug_js["RTON stats"]["0x93 stack"][to_hex_string(uint64_to_uRTON(map_0x93.size() - 1))] = temp;
debug_js["RTON stats"]["0x93 stack"][to_hex_string(uint64_t2uRTON_t(map_0x93.size() - 1))] = temp;
map_0x93[temp] = map_0x93.size();
}
else{
debug_js["RTON stats"]["List of bytecodes"][to_hex_string(output.tellp())] = to_hex_string(utf8_stack);
output.write(reinterpret_cast<const char*> (&utf8_stack), sizeof utf8_stack);
write_unsigned_RTON_num(uint64_to_uRTON(map_0x93[temp] - 1));
write_uRTON_t(uint64_t2uRTON_t(map_0x93[temp] - 1));
}
}
}
Expand All @@ -138,14 +138,14 @@ int write_RTON_block(json js){
debug_js["RTON stats"]["List of bytecodes"][to_hex_string(output.tellp())] = to_hex_string(RTON_t);
output.write(reinterpret_cast<const char*> (&RTON_t), sizeof RTON_t);
int64_t temp = js.get<int64_t>();
write_unsigned_RTON_num(uint64_to_uRTON(temp < 0 ? -2 * temp - 1 : 2 * temp));
write_uRTON_t(uint64_t2uRTON_t(temp < 0 ? -2 * temp - 1 : 2 * temp));
break;
}
case json::value_t::number_unsigned:{
debug_js["RTON stats"]["List of bytecodes"][to_hex_string(output.tellp())] = to_hex_string(uRTON_t);
output.write(reinterpret_cast<const char*> (&uRTON_t), sizeof uRTON_t);
uint64_t temp = js.get<uint64_t>();
write_unsigned_RTON_num(uint64_to_uRTON(temp));
write_uRTON_t(uint64_t2uRTON_t(temp));
break;
}
case json::value_t::number_float:{
Expand All @@ -168,7 +168,7 @@ int write_RTON_block(json js){
debug_js["RTON stats"]["List of bytecodes"][to_hex_string(output.tellp())] = to_hex_string(arr_begin);
output.write(reinterpret_cast<const char*> (&arr_begin), sizeof arr_begin);

write_unsigned_RTON_num(uint64_to_uRTON(js.size()));
write_uRTON_t(uint64_t2uRTON_t(js.size()));
for (auto i : js) write_RTON_block(i);

debug_js["RTON stats"]["List of bytecodes"][to_hex_string(output.tellp())] = to_hex_string(arr_end);
Expand Down
62 changes: 31 additions & 31 deletions rton-json/src/rton2json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ T read(){
return res;
}

vector <uint8_t> read_RTON_num(){
vector <uint8_t> RTON_num;
vector <uint8_t> read_uRTON_t(){
vector <uint8_t> RTON_t;
uint8_t sub_num;
do{
sub_num = read<uint8_t>();
RTON_num.push_back(sub_num);
RTON_t.push_back(sub_num);
}while(sub_num > 0x7f);
return RTON_num;
return RTON_t;
}

json read_RTON_block(){
Expand Down Expand Up @@ -103,12 +103,12 @@ json read_RTON_block(){
}
//unsigned RTON number
case 0x24:{
res.push_back(uRTON_to_uint64(read_RTON_num()));
res.push_back(uRTON_t2uint64_t(read_uRTON_t()));
break;
}
//RTON number
case 0x25:{
int64_t num = uRTON_to_uint64(read_RTON_num());
int64_t num = uRTON_t2uint64_t(read_uRTON_t());
if (num % 2) num = -(num + 1);
num /= 2;

Expand All @@ -127,12 +127,12 @@ json read_RTON_block(){
}
//unsigned RTON number???
case 0x28:{
res.push_back(uRTON_to_uint64(read_RTON_num()));
res.push_back(uRTON_t2uint64_t(read_uRTON_t()));
break;
}
//RTON number???
case 0x29:{
int64_t num = uRTON_to_uint64(read_RTON_num());
int64_t num = uRTON_t2uint64_t(read_uRTON_t());
if (num % 2) num = -(num + 1);
num /= 2;

Expand Down Expand Up @@ -161,12 +161,12 @@ json read_RTON_block(){
}
//unsigned RTON number???
case 0x44:{
res.push_back(uRTON_to_uint64(read_RTON_num()));
res.push_back(uRTON_t2uint64_t(read_uRTON_t()));
break;
}
//RTON number???
case 0x45:{
int64_t num = uRTON_to_uint64(read_RTON_num());
int64_t num = uRTON_t2uint64_t(read_uRTON_t());
if (num % 2) num = -(num + 1);
num /= 2;

Expand All @@ -185,12 +185,12 @@ json read_RTON_block(){
}
//unsigned RTON number???
case 0x48:{
res.push_back(uRTON_to_uint64(read_RTON_num()));
res.push_back(uRTON_t2uint64_t(read_uRTON_t()));
break;
}
//RTON number???
case 0x49:{
int64_t num = uRTON_to_uint64(read_RTON_num());
int64_t num = uRTON_t2uint64_t(read_uRTON_t());
if (num % 2) num = -(num + 1);
num /= 2;

Expand All @@ -199,7 +199,7 @@ json read_RTON_block(){
}
//string
case 0x81:{
uint64_t buffer = uRTON_to_uint64(read_RTON_num());
uint64_t buffer = uRTON_t2uint64_t(read_uRTON_t());

char temp[buffer + 1];
input.read(temp, buffer);
Expand All @@ -210,8 +210,8 @@ json read_RTON_block(){
}
//utf-8 string
case 0x82:{
uint64_t buffer = uRTON_to_uint64(read_RTON_num());
buffer = uRTON_to_uint64(read_RTON_num());
uint64_t buffer = uRTON_t2uint64_t(read_uRTON_t());
buffer = uRTON_t2uint64_t(read_uRTON_t());

char s[buffer + 1];
input.read(s, buffer);
Expand All @@ -226,15 +226,15 @@ json read_RTON_block(){

switch (subset){
case 0x2:{
uint64_t buffer = uRTON_to_uint64(read_RTON_num());
buffer = uRTON_to_uint64(read_RTON_num());
uint64_t buffer = uRTON_t2uint64_t(read_uRTON_t());
buffer = uRTON_t2uint64_t(read_uRTON_t());

char s[buffer + 1];
input.read(s, buffer);
s[buffer] = 0;

uint64_t second_uid = uRTON_to_uint64(read_RTON_num());
uint64_t first_uid = uRTON_to_uint64(read_RTON_num());
uint64_t second_uid = uRTON_t2uint64_t(read_uRTON_t());
uint64_t first_uid = uRTON_t2uint64_t(read_uRTON_t());
int32_t third_uid = read<int32_t>();

stringstream ss;
Expand All @@ -244,15 +244,15 @@ json read_RTON_block(){
break;
}
case 0x3:{
uint64_t s1_buffer = uRTON_to_uint64(read_RTON_num());
s1_buffer = uRTON_to_uint64(read_RTON_num());
uint64_t s1_buffer = uRTON_t2uint64_t(read_uRTON_t());
s1_buffer = uRTON_t2uint64_t(read_uRTON_t());

char s1[s1_buffer + 1];
input.read(s1, s1_buffer);
s1[s1_buffer] = 0;

uint64_t s2_buffer = uRTON_to_uint64(read_RTON_num());
s2_buffer = uRTON_to_uint64(read_RTON_num());
uint64_t s2_buffer = uRTON_t2uint64_t(read_uRTON_t());
s2_buffer = uRTON_t2uint64_t(read_uRTON_t());

char s2[s2_buffer + 1];
input.read(s2, s2_buffer);
Expand Down Expand Up @@ -282,7 +282,7 @@ json read_RTON_block(){
uint8_t arr_begin = read<uint8_t>();

if (arr_begin == 0xfd){
size_t arr_size = uRTON_to_uint64(read_RTON_num());
size_t arr_size = uRTON_t2uint64_t(read_uRTON_t());

json arr = json::array();
for (size_t i = 0; i < arr_size; ++i) arr.push_back(read_RTON_block()[0]);
Expand All @@ -297,13 +297,13 @@ json read_RTON_block(){
}
//cached string
case 0x90:{
uint64_t buffer = uRTON_to_uint64(read_RTON_num());
uint64_t buffer = uRTON_t2uint64_t(read_uRTON_t());

char temp[buffer + 1];
input.read(temp, buffer);
temp[buffer] = 0;

debug_js["RTON stats"]["0x91 stack"][to_hex_string(uint64_to_uRTON(stack_0x91.size()))] = string(temp);
debug_js["RTON stats"]["0x91 stack"][to_hex_string(uint64_t2uRTON_t(stack_0x91.size()))] = string(temp);
stack_0x91.push_back(temp);

res.push_back(stack_0x91[stack_0x91.size() - 1]);
Expand All @@ -312,7 +312,7 @@ json read_RTON_block(){
//recall
case 0x91:{
try{
res.push_back(stack_0x91.at(uRTON_to_uint64(read_RTON_num())));
res.push_back(stack_0x91.at(uRTON_t2uint64_t(read_uRTON_t())));
}
catch(const out_of_range &oor){
throw out_of_range_error(bytecode);
Expand All @@ -321,14 +321,14 @@ json read_RTON_block(){
}
//cached utf-8 string
case 0x92:{
uint64_t buffer = uRTON_to_uint64(read_RTON_num());
buffer = uRTON_to_uint64(read_RTON_num());
uint64_t buffer = uRTON_t2uint64_t(read_uRTON_t());
buffer = uRTON_t2uint64_t(read_uRTON_t());

char temp[buffer + 1];
input.read(temp, buffer);
temp[buffer] = 0;

debug_js["RTON stats"]["0x93 stack"][to_hex_string(uint64_to_uRTON(stack_0x93.size()))] = string(temp);
debug_js["RTON stats"]["0x93 stack"][to_hex_string(uint64_t2uRTON_t(stack_0x93.size()))] = string(temp);
stack_0x93.push_back(temp);

res.push_back(stack_0x93[stack_0x93.size() - 1]);
Expand All @@ -337,7 +337,7 @@ json read_RTON_block(){
//recall
case 0x93:{
try{
res.push_back(stack_0x93.at(uRTON_to_uint64(read_RTON_num())));
res.push_back(stack_0x93.at(uRTON_t2uint64_t(read_uRTON_t())));
}
catch(const out_of_range &oor){
throw out_of_range_error(bytecode);
Expand Down

0 comments on commit 103e36d

Please sign in to comment.