Added TypeArrayCopy, and TypeArrayFill

* Added TypeArrayCopy and TypeArrayFill
* Fixed bug when adding embedded arguments of defined types to compiler
This commit is contained in:
n00b87
2024-04-25 02:19:42 -05:00
parent 308c1944f9
commit 863decff5d
6 changed files with 1443 additions and 1208 deletions

View File

@@ -912,7 +912,18 @@ bool create_variable(string name, int type, string utype_name="", int vec = -1)
int var_index = id.size();
var.num_args = 0;
var.parent_index = -1;
set_vectorPosition(var);
if(vec == -1)
{
set_vectorPosition(var);
//cout << var.name << " <==> " << var.vec_pos << endl;
}
else
{
//cout << "set " << name << " to " << vec << endl;
var.vec_pos = vec;
}
id.push_back(var);
if(isInFunctionScope && !isFunctionArg_flag)
@@ -1078,7 +1089,7 @@ bool embed_function(string name, int type, int fn_utype=-1)
fn.isBuiltin = true;
fn.vmFunctionIndex = current_vmFunction_index;
current_vmFunction_index++;
cout << "current_vmFunction = " << current_vmFunction_index << endl;
//cout << "current_vmFunction = " << current_vmFunction_index << endl;
fn.num_args = 0; //function args default to 0; args are added with add_function_args
current_fn_index = id.size();

View File

@@ -1064,7 +1064,7 @@ int main(int argc, char * argv[])
{
string line = "";
//rcbasic_dev("embedded_functions.bas"); return 0;
//rcbasic_dev("embedded_functions.bas"); rcbasic_output_debug_info(); return 0;
string rc_filename = "";// = "tst.bas";

View File

@@ -1020,6 +1020,13 @@ int getArrayObjStart(int arg_id)
return 0;
}
bool byref_type_generic(string utype_name)
{
if(utype_name.compare("empty")==0)
return true;
return false;
}
bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_udt)
@@ -1264,15 +1271,15 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
}
else if( ID_TYPE_USER_ALL(expr_id) && eval_udt )
{
cout << "-Parsing User Variable: " << id[expr_id].name << endl;
cout << "----------------------------------------------- : " << eval_udt << endl;
//cout << "-Parsing User Variable: " << id[expr_id].name << endl;
//cout << "----------------------------------------------- : " << eval_udt << endl;
bool udt_id_init = true;
string tmp_scope = id[expr_id].scope;
for(int t = i; t < token.size(); t++)
/*for(int t = i; t < token.size(); t++)
{
try
{
@@ -1282,7 +1289,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
{
cout << "Token Out of Range Error: " << e.what() << endl;
}
}
}*/
int tmp_id = 0;
@@ -1311,7 +1318,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
string full_id = token[t].substr(4);
token[t] = "";
tmp_id = getIDInScope_ByIndex_TypeMatch(full_id, tmp_scope);
cout << "\ntmp_id = " << tmp_id << endl;
//cout << "\ntmp_id = " << tmp_id << endl;
if(tmp_id < 0)
{
@@ -1319,7 +1326,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
return false;
}
cout << "Scope = " << tmp_scope << " ID = " << full_id << " -- " << tmp_id << endl << endl;
//cout << "Scope = " << tmp_scope << " ID = " << full_id << " -- " << tmp_id << endl << endl;
tmp_scope += "." + full_id;
@@ -1339,7 +1346,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
arg_count = 0;
arr_scope = 1;
t2++;
cout << "T2 = " << t2 << endl << endl;
//cout << "T2 = " << t2 << endl << endl;
for(; t2 <= end_token; t2++)
{
@@ -1395,7 +1402,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
{
has_child = true;
}
cout << "Has Child = " << has_child << ", " << t << ", " << t2 << endl;
//cout << "Has Child = " << has_child << ", " << t << ", " << t2 << endl;
}
if(type_delete_flag && (!has_child) && arg_count != 0)
@@ -1420,7 +1427,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
if(arg_count != 0)
rc_setError("[0]Expected " + rc_intToString(id[tmp_id].num_args) + " dimension in " + id[tmp_id].name);
cout << "ID_TYPE = " << id[tmp_id].type << ", " << arg_count << ", " << (has_child ? "true" : "false") << endl;
//cout << "ID_TYPE = " << id[tmp_id].type << ", " << arg_count << ", " << (has_child ? "true" : "false") << endl;
args[0] = "";
args[1] = "";
@@ -1490,7 +1497,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
if(type_redim_flag && (!has_child))
{
cout << "NO CHILD: " << id[tmp_id].name << " -- arg_count = " << arg_count << " -- arg[0] = " << args[0] << endl;
//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];
@@ -1505,12 +1512,12 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
else if(type_delete_flag && (!has_child))
{
//DO NOTHING
cout << "NO CHILD: " << id[tmp_id].name << endl;
//cout << "NO CHILD: " << id[tmp_id].name << endl;
}
else
{
//if(type_delete_flag)
cout << "TESTING STUFF" << endl;
//cout << "TESTING STUFF" << endl;
switch(arg_count)
{
@@ -1627,7 +1634,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
{
case ID_TYPE_USER:
case ID_TYPE_BYREF_USER:
cout << "test --> " << u << ", " << id[tmp_id].name << endl;
//cout << "test --> " << u << ", " << id[tmp_id].name << endl;
vm_asm.push_back("obj_usr_get " + u);
token[i] = u;
resolveID_id_reg.push_back(token[i]);
@@ -1640,7 +1647,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
vm_asm.push_back("obj_usr_get " + n);
token[i] = n;
cout << "GET N: " << n << ", " << id[tmp_id].scope << " :: " << id[tmp_id].name << endl;
//cout << "GET N: " << n << ", " << id[tmp_id].scope << " :: " << id[tmp_id].name << endl;
resolveID_id_reg.push_back(token[i]);
resolveID_id_type.push_back(id[tmp_id].type);
resolveID_id_ut_index.push_back(id[tmp_id].type_index);
@@ -1668,12 +1675,13 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
type_error_exception tx;
tx.error_log = "[0]Expected " + rc_intToString(id[tmp_id].num_args) + " dimension in " + id[tmp_id].name;
tx.tk_reg = token[i];
cout << "store = " << tx.tk_reg << endl;
//cout << "store = " << tx.tk_reg << endl;
byref_type_exception.push_back(tx);
byref_type_flag = false;
}
/*
cout << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
for(int t = 0; t < token.size(); t++)
@@ -1689,6 +1697,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
}
cout << "-----------------------------------------------" << endl;
*/
//for(int t = 0; t < id.size(); t++)
@@ -2045,7 +2054,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
resolve_index = getResolveReg(args[n]);
if(args[n].substr(0,4).compare("<id>")==0)
{
cout << "found id: " << args[n] << " in " << id[expr_id].name << endl;
//cout << "found id: " << args[n] << " in " << id[expr_id].name << endl;
string t_replace = "";
int arg_id = getIDInScope_ByIndex(args[n].substr(4));
if(arg_id < 0)
@@ -2092,17 +2101,17 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
//check if byref_type_exception
bool type_exception_found = false;
cout << "CHECK EXCEPTION: " << args[n] << endl;
//cout << "CHECK EXCEPTION: " << args[n] << endl;
for(int bt_i = 0; bt_i < byref_type_exception.size(); bt_i++)
{
if(args[n].compare(byref_type_exception[bt_i].tk_reg)==0)
{
cout << "FOUND EXCEPTION: " << args[n] << endl;
//cout << "FOUND EXCEPTION: " << args[n] << endl;
byref_type_exception[bt_i].tk_reg = "";
type_exception_found = true;
}
else
cout << "NO MATCH (" << args[n] << ", " << byref_type_exception[bt_i].tk_reg << ")" << endl;
//else
//cout << "NO MATCH (" << args[n] << ", " << byref_type_exception[bt_i].tk_reg << ")" << endl;
}
//----------------
@@ -2124,7 +2133,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
string tmp_fn_name = StringToLower(id[expr_id].name);
if(tmp_fn_name.compare("arraydim")==0)
{
cout << "found array dim" << endl;
//cout << "found array dim" << endl;
int tmp_id_type = -1;
if(args[n].substr(0,4).compare("<id>")==0)
@@ -2154,6 +2163,102 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
return false;
}
}
else if(tmp_fn_name.compare("arraysize")==0)
{
//cout << "found array size: " << args[0] << endl;
int tmp_id_type = -1;
if(args[0].substr(0,4).compare("<id>")==0) // arg[0] is what determines the macro function used
{
int tmp_id = getIDInScope_ByIndex(args[n].substr(4));
if(tmp_id >= 0)
tmp_id_type = id[tmp_id].type;
}
if(args[0].substr(0,1).compare("n")==0 || tmp_id_type == ID_TYPE_NUM || tmp_id_type == ID_TYPE_ARR_NUM || tmp_id_type == ID_TYPE_BYREF_NUM)
expr_id = getIDInScope_ByIndex("numberarraysize");
else if(args[0].substr(0,1).compare("s")==0 || tmp_id_type == ID_TYPE_STR || tmp_id_type == ID_TYPE_ARR_STR || tmp_id_type == ID_TYPE_BYREF_STR)
expr_id = getIDInScope_ByIndex("stringarraysize");
else if(args[0].substr(0,1).compare("u")==0 || tmp_id_type == ID_TYPE_USER || tmp_id_type == ID_TYPE_BYREF_USER)
expr_id = getIDInScope_ByIndex("typearraysize");
else
{
rc_setError("Expected valid array identifier: " + args[0]);
expr_id = -1;
}
if(expr_id < 0)
{
rc_setError("ArraySize macro function does not exists for variable type");
return false;
}
}
else if(tmp_fn_name.compare("arraycopy")==0)
{
//cout << "found array copy: " << args[0] << endl;
int tmp_id_type = -1;
if(args[0].substr(0,4).compare("<id>")==0) // arg[0] is what determines the macro function used
{
int tmp_id = getIDInScope_ByIndex(args[n].substr(4));
if(tmp_id >= 0)
tmp_id_type = id[tmp_id].type;
}
if(args[0].substr(0,1).compare("n")==0 || tmp_id_type == ID_TYPE_NUM || tmp_id_type == ID_TYPE_ARR_NUM || tmp_id_type == ID_TYPE_BYREF_NUM)
expr_id = getIDInScope_ByIndex("numberarraycopy");
else if(args[0].substr(0,1).compare("s")==0 || tmp_id_type == ID_TYPE_STR || tmp_id_type == ID_TYPE_ARR_STR || tmp_id_type == ID_TYPE_BYREF_STR)
expr_id = getIDInScope_ByIndex("stringarraycopy");
else if(args[0].substr(0,1).compare("u")==0 || tmp_id_type == ID_TYPE_USER || tmp_id_type == ID_TYPE_BYREF_USER)
expr_id = getIDInScope_ByIndex("typearraycopy");
else
{
rc_setError("Expected valid array identifier: " + args[0]);
expr_id = -1;
}
if(expr_id < 0)
{
rc_setError("ArrayCopy macro function does not exists for variable type");
return false;
}
}
else if(tmp_fn_name.compare("arrayfill")==0)
{
//cout << "found array fill: " << args[0] << endl;
int tmp_id_type = -1;
if(args[0].substr(0,4).compare("<id>")==0) // arg[0] is what determines the macro function used
{
int tmp_id = getIDInScope_ByIndex(args[n].substr(4));
if(tmp_id >= 0)
tmp_id_type = id[tmp_id].type;
}
if(args[0].substr(0,1).compare("n")==0 || tmp_id_type == ID_TYPE_NUM || tmp_id_type == ID_TYPE_ARR_NUM || tmp_id_type == ID_TYPE_BYREF_NUM)
expr_id = getIDInScope_ByIndex("numberarrayfill");
else if(args[0].substr(0,1).compare("s")==0 || tmp_id_type == ID_TYPE_STR || tmp_id_type == ID_TYPE_ARR_STR || tmp_id_type == ID_TYPE_BYREF_STR)
expr_id = getIDInScope_ByIndex("stringarrayfill");
else if(args[0].substr(0,1).compare("u")==0 || tmp_id_type == ID_TYPE_USER || tmp_id_type == ID_TYPE_BYREF_USER)
expr_id = getIDInScope_ByIndex("typearrayfill");
else
{
rc_setError("Expected valid array identifier: " + args[0]);
expr_id = -1;
}
if(expr_id < 0)
{
rc_setError("ArrayFill macro function does not exists for variable type");
return false;
}
}
//--------------------------------
if(type_exception_found)
@@ -2218,33 +2323,33 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
}
else if(id[expr_id].fn_arg_type[n] == ID_TYPE_BYREF_USER)
{
cout << "BYREF USER TYPE CHECK" << endl;
//cout << "BYREF USER TYPE CHECK" << endl;
//check if byref_type_exception
bool type_exception_found = false;
cout << "CHECK EXCEPTION: " << args[n] << endl;
//cout << "CHECK EXCEPTION: " << args[n] << endl;
for(int bt_i = 0; bt_i < byref_type_exception.size(); bt_i++)
{
if(args[n].compare(byref_type_exception[bt_i].tk_reg)==0)
{
cout << "FOUND EXCEPTION: " << args[n] << endl;
//cout << "FOUND EXCEPTION: " << args[n] << endl;
byref_type_exception[bt_i].tk_reg = "";
type_exception_found = true;
}
else
cout << "NO MATCH (" << args[n] << ", " << byref_type_exception[bt_i].tk_reg << ")" << endl;
//else
//cout << "NO MATCH (" << args[n] << ", " << byref_type_exception[bt_i].tk_reg << ")" << endl;
}
//----------------
int ut_info = -1;
int ut_index = -1;
getRegInfo(args[n], ut_info, ut_index);
if(ut_index != id[expr_id].fn_arg_utype[n])
if(ut_index != id[expr_id].fn_arg_utype[n] && (!byref_type_generic(utype[id[expr_id].fn_arg_utype[n]].name)))
{
rc_setError("Expected \"" + utype[id[expr_id].fn_arg_utype[n]].name + "\" identifier for ByRef argument");
return false;
}
cout << "BYREF USER MATCH ID: " << id[expr_id].fn_arg[n] << endl;
//cout << "BYREF USER MATCH ID: " << id[expr_id].fn_arg[n] << endl;
vm_asm.push_back("uref_ptr !" + rc_intToString(id[expr_id].fn_arg_vec[n]) + " " + args[n]);
}
else if(id[expr_id].fn_arg_type[n] == ID_TYPE_NUM)
@@ -2279,7 +2384,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
int ut_info = -1;
int ut_index = -1;
getRegInfo(args[n], ut_info, ut_index);
if(ut_index != id[expr_id].fn_arg_utype[n])
if(ut_index != id[expr_id].fn_arg_utype[n] && (!byref_type_generic(utype[id[expr_id].fn_arg_utype[n]].name)))
{
rc_setError("Expected \"" + utype[id[expr_id].fn_arg_utype[n]].name + "\" identifier for argument");
return false;
@@ -2425,7 +2530,7 @@ bool pre_parse(int start_token = 0, int end_token = -1, int pp_flags, bool eval_
}
else if(token[i].compare("<child>")==0)
{
cout << "USER DEFINED TYPE REGISTER ARGUMENT" << endl;
//cout << "USER DEFINED TYPE REGISTER ARGUMENT" << endl;
n = "n" + rc_intToString(n_reg);
s = "s" + rc_intToString(s_reg);
@@ -3480,7 +3585,7 @@ bool check_rule()
}
else
{
cout << "create variable (" << id_name << ") of type " << token[3].substr(4) << endl;
//cout << "create variable (" << id_name << ") of type " << token[3].substr(4) << endl;
if(!create_variable(id_name, id_type, token[3].substr(4)))
return false;
}
@@ -3685,10 +3790,10 @@ bool check_rule()
return false;
}
cout << "DEBUG TOKENS: " << endl;
cout << "----------------------" << endl;
for(int tk = token_index; tk < end_token; tk++) cout << token[tk] << endl;
cout << "-------------------------------------" << endl;
//cout << "DEBUG TOKENS: " << endl;
//cout << "----------------------" << endl;
//for(int tk = token_index; tk < end_token; tk++) cout << token[tk] << endl;
//cout << "-------------------------------------" << endl;
if(has_child)
{
@@ -3721,7 +3826,7 @@ bool check_rule()
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;
//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)
{
@@ -6411,7 +6516,7 @@ bool check_rule_embedded()
fn_arg_type = ID_TYPE_BYREF_USER;
}
if(!add_function_arg(fn_arg, fn_arg_type, fn_arg_user_type))
if(!add_embedded_arg(fn_arg, fn_arg_type, getUType(fn_arg_user_type)))
{
return false;
}

File diff suppressed because it is too large Load Diff

View File

@@ -2251,7 +2251,118 @@ uint64_t rc_number_array_dim(rc_numId n_var)
uint64_t rc_type_array_dim(rc_usrId* u_var)
{
return u_var->dimensions;
}
}
uint64_t rc_type_array_size(rc_usrId* u_var, int d_num)
{
switch(d_num)
{
case 1:
return u_var->dim[0];
break;
case 2:
return u_var->dim[1];
break;
case 3:
return u_var->dim[2];
break;
}
return 0;
}
void rc_type_array_copy(rc_usrId* src, rc_usrId* dst)
{
//cout << "Copy Type" << endl;
rc_usrId* parent = dst;
//cout << "freed up" << endl;
//parent[0] = src[0];
//cout << "done" << endl;
//return;
//cout << "db[1]" << endl;
parent->dimensions = src->dimensions;
//cout << "db[2]" << endl;
parent->dim[0] = src->dim[0];
parent->dim[1] = src->dim[1];
parent->dim[2] = src->dim[2];
//cout << "db[3]" << endl;
parent->byref_offset = 0;
//cout << "db[4]" << endl;
parent->uid_value.resize(src->uid_value.size());
//cout << "db[5]" << endl;
parent->var_ref = parent;
parent->var_ref_index = 0;
rc_usrId* p_obj;
uint64_t field_size = 0;
rc_usrId* s_obj;
//cout << "starting field: " << endl;
for(uint64_t i = 0; i < src->uid_value.size(); i++)
{
s_obj = &src->uid_value[i];
p_obj = &parent->uid_value[i];
p_obj->byref_offset = 0;
p_obj->byref_ptr = parent;
p_obj->dim[0] = s_obj->dim[0];
p_obj->dim[1] = s_obj->dim[1];
p_obj->dim[2] = s_obj->dim[2];
p_obj->dimensions = s_obj->dimensions;
p_obj->preset_init = s_obj->preset_init;
p_obj->udt_index = s_obj->udt_index;
p_obj->var_ref = p_obj;
p_obj->var_ref_index = 0;
//cout << "num" << endl;
p_obj->num_var.resize(s_obj->num_var.size());
for(int nfield = 0; nfield < s_obj->num_var.size(); nfield++)
{
p_obj->num_var[nfield] = s_obj->num_var[nfield];
}
//cout << "str" << endl;
p_obj->str_var.resize(s_obj->str_var.size());
for(int sfield = 0; sfield < s_obj->str_var.size(); sfield++)
{
p_obj->str_var[sfield] = s_obj->str_var[sfield];
}
//cout << "copy uid field" << endl;
p_obj->uid_value.resize(s_obj->uid_value.size());
for(int ufield = 0; ufield < s_obj->uid_value.size(); ufield++)
{
rc_type_array_copy(s_obj, p_obj);
}
}
//cout << "done" << endl;
}
void rc_type_array_fill(rc_usrId* src, rc_usrId* fdata)
{
rc_usrId* p_obj;
for(int i = 0; i < src->uid_value.size(); i++)
{
p_obj = &src->uid_value[i];
p_obj[0] = fdata[0];
}
}
uint64_t rc_number_array_size(rc_numId n_var, int d_num)
{
@@ -4096,10 +4207,18 @@ void func_130(uint64_t fn)
arr_ref_id.clear();
break;
case FN_TypeArraySize: //Number Function
rc_push_num( rc_type_array_size( TYPEARRAYSIZE_ID, TYPEARRAYSIZE_ARRAY_DIM ) );
arr_ref_id.clear();
break;
case FN_TypeArrayCopy: //Sub Procedure
//cout << "TAS: " << TYPEARRAYCOPY_SRC->uid_value.size() << endl;
//cout << "TAD: " << TYPEARRAYCOPY_DST->uid_value.size() << endl;
rc_free_type(TYPEARRAYCOPY_DST); //cout << "TA[2]: " << TYPEARRAYCOPY_DST->uid_value.size() << endl;
rc_type_array_copy( TYPEARRAYCOPY_SRC, TYPEARRAYCOPY_DST );
break;
case FN_TypeArrayFill: //Sub Procedure
//cout << "test type fill" << endl;
rc_type_array_fill( TYPEARRAYFILL_SRC, &TYPEARRAYFILL_FDATA );
break;
@@ -5970,7 +6089,7 @@ int main(int argc, char * argv[])
if(rc_filename.compare("--version")==0)
{
cout << "RCBASIC Runtime v4.0a1" << endl;
cout << "RCBASIC Runtime v4.0a" << endl;
return 0;
}

File diff suppressed because it is too large Load Diff