Added REDIM type member support

This commit is contained in:
n00b87
2024-04-22 00:36:27 -05:00
parent c99b8f0b01
commit 96c8366a4b
5 changed files with 264 additions and 27 deletions

View File

@@ -26,6 +26,13 @@ string type_delete_arg = "";
int type_delete_arg_type = 0;
bool type_delete_arg_whole = false;
bool type_redim_flag = false;
string type_redim_arg = "";
int type_redim_arg_type = 0;
string type_redim_arg_utype = "";
string type_redim_dim[3];
int type_redim_dim_count = 0;
struct type_error_exception
{
string error_log;
@@ -1375,7 +1382,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
arg_count++;
}
else if(type_delete_flag)
else if(type_delete_flag || type_redim_flag)
t2--;
}
@@ -1400,7 +1407,15 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
if(arg_count != id[tmp_id].num_args)
{
if(!type_delete_flag)
if(type_redim_flag)
{
if(has_child)
{
rc_setError("[1]Expected " + rc_intToString(id[tmp_id].num_args) + " dimension in " + id[tmp_id].name);
return false;
}
}
else if(!type_delete_flag)
{
if(arg_count != 0)
rc_setError("[0]Expected " + rc_intToString(id[tmp_id].num_args) + " dimension in " + id[tmp_id].name);
@@ -1458,7 +1473,15 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
}
}
if(type_delete_flag && (!has_child))
if(type_redim_flag && (!has_child))
{
cout << "NO CHILD: " << id[tmp_id].name << " -- arg_count = " << arg_count << " -- arg[0] = " << args[0] << endl;
type_redim_dim_count = arg_count;
type_redim_dim[0] = args[0];
type_redim_dim[1] = args[1];
type_redim_dim[2] = args[2];
}
else if(type_delete_flag && (!has_child))
{
//DO NOTHING
cout << "NO CHILD: " << id[tmp_id].name << endl;
@@ -1566,7 +1589,13 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
//START HERE
if(type_delete_flag && (!has_child))
if(type_redim_flag && (!has_child))
{
type_redim_arg = "!" + rc_intToString(id[tmp_id].vec_pos);
type_redim_arg_type = id[tmp_id].type;
type_redim_arg_utype = "!" + rc_intToString(id[tmp_id].type_index);
}
else if(type_delete_flag && (!has_child))
{
//cout << "DELETE_VAR = " << id[tmp_id].name << endl;
type_delete_arg = "!" + rc_intToString(id[tmp_id].vec_pos);
@@ -3593,7 +3622,8 @@ bool check_rule()
}
id_type = id[id_index].type;
id_type = id[id_index].type;
type_redim_arg_type = 0;
//cout << "db1\n";
@@ -3657,13 +3687,25 @@ bool check_rule()
multi_arg[2] = "";
multi_arg_count = 0;
int end_token = token_index+1;
int sq_scope = 1;
int sq_scope = 1;
bool has_child = false;
for(; end_token < token.size(); end_token++)
{
if(token[end_token].compare("</square>")==0)
sq_scope--;
else if(token[end_token].compare("<square>")==0)
sq_scope++;
sq_scope++;
if( (end_token+1) < token.size() )
{
if(token[end_token+1].compare("<child>")==0 || token[end_token].compare("<child>")==0)
{
has_child = true;
continue;
}
else if(token[end_token+1].compare("<square>")==0)
continue;
}
if(sq_scope==0)
break;
@@ -3673,7 +3715,21 @@ bool check_rule()
{
rc_setError("Expected ] in array definition");
return false;
}
}
cout << "DEBUG TOKENS: " << endl;
cout << "----------------------" << endl;
for(int tk = token_index; tk < end_token; tk++) cout << token[tk] << endl;
cout << "-------------------------------------" << endl;
if(has_child)
{
token_index = 1;
type_redim_flag = true;
type_redim_arg_type = 0;
}
else
type_redim_flag = false;
//cout << "debug 1: " << id_index << endl;
@@ -3685,7 +3741,21 @@ bool check_rule()
//cout << "debug 2: " << id_index << endl;
if(multi_arg_count <= 0 || multi_arg_count > 3)
if(type_redim_flag)
{
if(type_redim_dim_count <= 0)
{
rc_setError("Expected 1 to 3 Arguments for array re-dimension, Found " + rc_intToString(multi_arg_count));
return false;
}
dimensions = type_redim_dim_count;
multi_arg[0] = type_redim_dim[0];
multi_arg[1] = type_redim_dim[1];
multi_arg[2] = type_redim_dim[2];
cout << "type arg = " << type_redim_arg << " type = " << type_redim_arg_type << " utype = " << type_redim_arg_utype << endl;
}
else if(multi_arg_count <= 0 || multi_arg_count > 3)
{
rc_setError("Expected 1 to 3 Arguments for array re-dimension, Found " + rc_intToString(multi_arg_count));
return false;
@@ -3697,7 +3767,9 @@ bool check_rule()
//cout << "M_ARG[2] = " << multi_arg[2] << endl;
dimensions = multi_arg_count;
}
token_index = end_token+1;
token_index = end_token+1;
type_redim_flag = false;
//cout << "debug 3: " << id_index << endl;
}
@@ -3745,7 +3817,80 @@ bool check_rule()
//cout << "debug 7: " << id_index << " -- " << id[id_index].type << endl;
if(id[id_index].type == ID_TYPE_NUM || id[id_index].type == ID_TYPE_ARR_NUM)
if(type_redim_arg_type == ID_TYPE_USER)
{
switch(dimensions)
{
case 1:
vm_asm.push_back("redim_type1 " + type_redim_arg + " " + type_redim_arg_utype + " " + multi_arg[0]);
break;
case 2:
vm_asm.push_back("redim_type2 " + type_redim_arg + " " + type_redim_arg_utype + " " + multi_arg[0] + " " + multi_arg[1]);
break;
case 3:
vm_asm.push_back("redim_type3 " + type_redim_arg + " " + type_redim_arg_utype + " " + multi_arg[0] + " " + multi_arg[1] + " " + multi_arg[2]);
break;
default:
rc_setError("Invalid number of dimensions in REDIM");
return false;
}
}
else if(type_redim_arg_type == ID_TYPE_USER_NUM || type_redim_arg_type == ID_TYPE_USER_NUM_ARRAY)
{
switch(dimensions)
{
case 1:
vm_asm.push_back("redim_type_n1 " + type_redim_arg + " " + multi_arg[0]);
break;
case 2:
vm_asm.push_back("redim_type_n2 " + type_redim_arg + " " + multi_arg[0] + " " + multi_arg[1]);
break;
case 3:
vm_asm.push_back("redim_type_n3 " + type_redim_arg + " " + multi_arg[0] + " " + multi_arg[1] + " " + multi_arg[2]);
break;
default:
rc_setError("Invalid number of dimensions in REDIM");
return false;
}
}
else if(type_redim_arg_type == ID_TYPE_USER_STR || type_redim_arg_type == ID_TYPE_USER_STR_ARRAY)
{
switch(dimensions)
{
case 1:
vm_asm.push_back("redim_type_s1 " + type_redim_arg + " " + multi_arg[0]);
break;
case 2:
vm_asm.push_back("redim_type_s2 " + type_redim_arg + " " + multi_arg[0] + " " + multi_arg[1]);
break;
case 3:
vm_asm.push_back("redim_type_s3 " + type_redim_arg + " " + multi_arg[0] + " " + multi_arg[1] + " " + multi_arg[2]);
break;
default:
rc_setError("Invalid number of dimensions in REDIM");
return false;
}
}
else if(id[id_index].type == ID_TYPE_USER)
{
//cout << "debug 8" << endl;
switch(dimensions)
{
case 1:
vm_asm.push_back("redim_type1 !" + rc_intToString(id[id_index].vec_pos) + " !" + rc_intToString(id[id_index].type_index) + " " + multi_arg[0]);
break;
case 2:
vm_asm.push_back("redim_type2 !" + rc_intToString(id[id_index].vec_pos) + " !" + rc_intToString(id[id_index].type_index) + " " + multi_arg[0] + " " + multi_arg[1]);
break;
case 3:
vm_asm.push_back("redim_type3 !" + rc_intToString(id[id_index].vec_pos) + " !" + rc_intToString(id[id_index].type_index) + " " + multi_arg[0] + " " + multi_arg[1] + " " + multi_arg[2]);
break;
default:
rc_setError("Invalid number of dimensions in REDIM");
return false;
}
}
else if(id[id_index].type == ID_TYPE_NUM || id[id_index].type == ID_TYPE_ARR_NUM)
{
//cout << "debug 8" << endl;
switch(dimensions)
@@ -3784,7 +3929,7 @@ bool check_rule()
}
else
{
rc_setError("Invalid type for REDIM");
rc_setError("Invalid type for REDIM: " + rc_intToString(id[id_index].type));
return false;
}
//cout << "balls" << endl;

View File

@@ -70,7 +70,9 @@ public:
s.substr(0,s.find_first_of(" ")).compare("redim1")==0 || s.substr(0,s.find_first_of(" ")).compare("redim1$")==0 ||
s.substr(0,s.find_first_of(" ")).compare("for_offset_arr2")==0 || s.substr(0,s.find_first_of(" ")).compare("obj_usr_n1")==0 ||
s.substr(0,s.find_first_of(" ")).compare("obj_usr_s1")==0 || s.substr(0,s.find_first_of(" ")).compare("uref_ptr")==0 ||
s.substr(0,s.find_first_of(" ")).compare("obj_usr_init1")==0 || s.substr(0,s.find_first_of(" ")).compare("preset_t")==0)
s.substr(0,s.find_first_of(" ")).compare("obj_usr_init1")==0 || s.substr(0,s.find_first_of(" ")).compare("preset_t")==0 ||
s.substr(0,s.find_first_of(" ")).compare("redim_type")==0 || s.substr(0,s.find_first_of(" ")).compare("redim_type_n1")==0 ||
s.substr(0,s.find_first_of(" ")).compare("redim_type_s1")==0)
{
current_address[current_segment] += 17; //1 byte for instruction and 8 bytes for each argument
}
@@ -128,7 +130,8 @@ public:
s.substr(0,s.find_first_of(" ")).compare("end_x")==0 || s.substr(0,s.find_first_of(" ")).compare("lval")==0 ||
s.substr(0,s.find_first_of(" ")).compare("lval$")==0 || s.substr(0,s.find_first_of(" ")).compare("obj_usr_n")==0 ||
s.substr(0,s.find_first_of(" ")).compare("obj_usr_s")==0 || s.substr(0,s.find_first_of(" ")).compare("obj_usr_get")==0 ||
s.substr(0,s.find_first_of(" ")).compare("obj_usr_init")==0)
s.substr(0,s.find_first_of(" ")).compare("obj_usr_init")==0 || s.substr(0,s.find_first_of(" ")).compare("redim_type_n")==0 ||
s.substr(0,s.find_first_of(" ")).compare("redim_type_s")==0)
{
current_address[current_segment] += 9; //1 byte for instruction and 8 bytes a single argument
}
@@ -139,7 +142,8 @@ public:
s.substr(0,s.find_first_of(" ")).compare("for_offset_arr3")==0 || s.substr(0,s.find_first_of(" ")).compare("dbg")==0 ||
s.substr(0,s.find_first_of(" ")).compare("obj_usr_n2")==0 || s.substr(0,s.find_first_of(" ")).compare("obj_usr_s2")==0 ||
s.substr(0,s.find_first_of(" ")).compare("obj_usr_init2")==0 || s.substr(0,s.find_first_of(" ")).compare("preset_t1")==0 ||
s.substr(0,s.find_first_of(" ")).compare("delete_t")==0)
s.substr(0,s.find_first_of(" ")).compare("delete_t")==0 || s.substr(0,s.find_first_of(" ")).compare("redim_type1")==0 ||
s.substr(0,s.find_first_of(" ")).compare("redim_type_n2")==0 || s.substr(0,s.find_first_of(" ")).compare("redim_type_s2")==0)
{
current_address[current_segment] += 25; //1 byte for instruction and 8 bytes for 3 arguments
}
@@ -149,11 +153,13 @@ public:
s.substr(0,s.find_first_of(" ")).compare("redim3")==0 || s.substr(0,s.find_first_of(" ")).compare("redim3$")==0 ||
s.substr(0,s.find_first_of(" ")).compare("obj_usr_n3")==0 || s.substr(0,s.find_first_of(" ")).compare("obj_usr_s3")==0 ||
s.substr(0,s.find_first_of(" ")).compare("obj_usr3")==0 || s.substr(0,s.find_first_of(" ")).compare("obj_usr_init3")==0 ||
s.substr(0,s.find_first_of(" ")).compare("preset_t2")==0)
s.substr(0,s.find_first_of(" ")).compare("preset_t2")==0 || s.substr(0,s.find_first_of(" ")).compare("redim_type2")==0 ||
s.substr(0,s.find_first_of(" ")).compare("redim_type_n3")==0 || s.substr(0,s.find_first_of(" ")).compare("redim_type_s3")==0)
{
current_address[current_segment] += 33; //1 byte for instruction and 8 bytes for 4 arguments
}
else if(s.substr(0,s.find_first_of(" ")).compare("dim_type3")==0 || s.substr(0,s.find_first_of(" ")).compare("preset_t3")==0)
else if(s.substr(0,s.find_first_of(" ")).compare("dim_type3")==0 || s.substr(0,s.find_first_of(" ")).compare("preset_t3")==0 ||
s.substr(0,s.find_first_of(" ")).compare("redim_type3")==0)
{
current_address[current_segment] += 41; //1 byte for instruction and 8 bytes for 5 arguments
}

View File

@@ -1207,6 +1207,70 @@ namespace rc_cbc_assembler
{
writeSegment(191);
}
else if(line_arg[0].compare("redim_type")==0)
{
string arg_type = line_arg[1].substr(0,1);
if(arg_type.compare("u")==0)
writeSegment(192);
else if(arg_type.compare("!")==0)
writeSegment(204);
}
else if(line_arg[0].compare("redim_type1")==0)
{
string arg_type = line_arg[1].substr(0,1);
if(arg_type.compare("u")==0)
writeSegment(193);
else if(arg_type.compare("!")==0)
writeSegment(205);
}
else if(line_arg[0].compare("redim_type2")==0)
{
string arg_type = line_arg[1].substr(0,1);
if(arg_type.compare("u")==0)
writeSegment(194);
else if(arg_type.compare("!")==0)
writeSegment(206);
}
else if(line_arg[0].compare("redim_type3")==0)
{
string arg_type = line_arg[1].substr(0,1);
if(arg_type.compare("u")==0)
writeSegment(195);
else if(arg_type.compare("!")==0)
writeSegment(207);
}
else if(line_arg[0].compare("redim_type_n")==0)
{
writeSegment(196);
}
else if(line_arg[0].compare("redim_type_n1")==0)
{
writeSegment(197);
}
else if(line_arg[0].compare("redim_type_n2")==0)
{
writeSegment(198);
}
else if(line_arg[0].compare("redim_type_n3")==0)
{
writeSegment(199);
}
else if(line_arg[0].compare("redim_type_s")==0)
{
writeSegment(200);
}
else if(line_arg[0].compare("redim_type_s1")==0)
{
writeSegment(201);
}
else if(line_arg[0].compare("redim_type_s2")==0)
{
writeSegment(202);
}
else if(line_arg[0].compare("redim_type_s3")==0)
{
writeSegment(203);
}
else
{
cout << "unrecognized cmd: " << line_arg[0] << endl;

View File

@@ -114,10 +114,10 @@ OBJ_CURRENT_TYPE
89 - clear_obj
90 - dim_type !id raw_number (user_type)
91 - dim_type1 !id raw_number (user type) n# (dim1)
92 - dim_type2 !id raw_number (user type) n# (dim1) n# (dim2)
93 - dim_type3 !id raw_number (user type) n# (dim1) n# (dim2) n# (dim3)
90 - dim_type !id !id (user_type)
91 - dim_type1 !id !id (user type) n# (dim1)
92 - dim_type2 !id !id (user type) n# (dim1) n# (dim2)
93 - dim_type3 !id !id (user type) n# (dim1) n# (dim2) n# (dim3)
94 - dim_num1 !id n# (dim1)
95 - dim_num2 !id n# (dim1) n# (dim2)
@@ -260,10 +260,10 @@ OBJ_CURRENT_TYPE
174 - delete_t !id !id (0 - top level, 1 - member) !id (0 - num, 1 - str, 2 - type)
175 - dim_type u# raw_number (user_type)
176 - dim_type1 u# raw_number (user type) n# (dim1)
177 - dim_type2 u# raw_number (user type) n# (dim1) n# (dim2)
178 - dim_type3 u# raw_number (user type) n# (dim1) n# (dim2) n# (dim3)
175 - dim_type u# !id (user_type)
176 - dim_type1 u# !id (user type) n# (dim1)
177 - dim_type2 u# !id (user type) n# (dim1) n# (dim2)
178 - dim_type3 u# !id (user type) n# (dim1) n# (dim2) n# (dim3)
179 - dim_tfield raw_number (user_type) raw_number (member_type) raw_number (member_index) raw_number (dimensions) n# (dim1) n# (dim2) n# (dim3)
@@ -283,3 +283,25 @@ OBJ_CURRENT_TYPE
191 - preset_t3 !id raw_number (user_type) n# n# n#
192 - redim_type u# !id (user_type)
193 - redim_type1 u# !id (user type) n# (dim1)
194 - redim_type2 u# !id (user type) n# (dim1) n# (dim2)
195 - redim_type3 u# !id (user type) n# (dim1) n# (dim2) n# (dim3)
196 - redim_type_n !id
197 - redim_type_n1 !id n# (dim1)
198 - redim_type_n2 !id n# (dim1) n# (dim2)
199 - redim_type_n3 !id n# (dim1) n# (dim2) n# (dim3)
200 - redim_type_s !id
201 - redim_type_s1 !id n# (dim1)
202 - redim_type_s2 !id n# (dim1) n# (dim2)
203 - redim_type_s3 !id n# (dim1) n# (dim2) n# (dim3)
204 - redim_type !id !id (user_type)
205 - redim_type1 !id !id (user type) n# (dim1)
206 - redim_type2 !id !id (user type) n# (dim1) n# (dim2)
207 - redim_type3 !id !id (user type) n# (dim1) n# (dim2) n# (dim3)