|
Post by aurel on Oct 27, 2021 12:25:49 GMT -6
excuse-moua ..heh this is one UDT variable or have halucination too
loop_stack.top (). counter [0] .nid_value [0] .value [byref_offset]
i have never looked before into RCBasic code but i will hmmm i am really wondering why must be so complex ...to me i see many interpreter code written in C ...i know u use C++ ok..everyone have his own style or mind-flow
ps ...i know only one guy who really get-it C programming and that one is eddavis2
|
|
|
Post by aurel on Oct 27, 2021 12:52:35 GMT -6
well i am looking into github page but ia m not sure about version found for_loop_code:
void for_117(uint64_t nid, int n1, int n2, int n3) { rc_loop for_loop; for_loop.counter = &num_var[nid]; for_loop.f_end = vm_n[n2].value; for_loop.f_step = vm_n[n3].value;
switch(for_offset_dimensions) { case 1: for_loop.counter_offset = for_offset_index[0]; break; case 2: for_loop.counter_offset = for_offset_index[0] * num_var[nid].dim[1] + for_offset_index[1]; break; case 3: for_loop.counter_offset = ( for_offset_index[0] * num_var[nid].dim[1] * num_var[nid].dim[2] ) + (for_offset_index[1] * num_var[nid].dim[2]) + for_offset_index[2]; break; default: for_loop.counter_offset = 0; }
int byref_offset = num_var[nid].byref_offset; num_var[nid].nid_value[0].value[byref_offset + for_loop.counter_offset] = vm_n[n1].value;
//These 3 lines reads the line value passed by the compiler //This line value is the address of the end of the loop unsigned rcbasic_cmd = segment[current_segment][current_address]; current_address++; uint64_t for_end_addr = readInt();
//cout << "next_addr: " << next_addr << endl;
if( vm_n[n2].value < vm_n[n1].value ) { for_loop.isNegative = true;
if(for_loop.f_step > 0) { current_address = for_end_addr; return; } } else { for_loop.isNegative = false;
if(for_loop.f_step < 0) { current_address = for_end_addr; return; } }
if i understand it correctly this part set counter variable // as n1 argument ..right noob?
well to rosy ... i dont see big problem with direction negative <---- or positve -----> looping uff sorry i am not C++ programmer at all
|
|
|
Post by n00b on Oct 27, 2021 18:58:56 GMT -6
if i understand it correctly this part set counter variable // as n1 argument ..right noob? well to rosy ... i dont see big problem with direction negative <---- or positve -----> looping uff sorry i am not C++ programmer at all aurel That is correct. This complex structure is setup the way it is because of how variables work in the runtime. num_var is an array that holds all the number variables in a program. nid_value is a pointer to the n_value structure which holds an array of numbers. aurel rosy So lets say we had some code like this: For i = 3 to 5 step 2 ' Code to execute Next If the variable i was the first variable made in your program it would be num_var[0]. num_var[0].nid_value[0] - This would point to the structure that holds the values. num_var[0].nid_value[0].value[ byref_offset + for_loop.counter_offset ] - All this offset stuff is basically keeping track of what index this variable should start at because it can change depending on whether it is offset in a byref argument to a function like this: Function tst(byref x) For x[0] = 1 to 5 ' Code to execute Next End Function
Dim my_array[5]
tst( my_array[2] ) 'Since my_array is being passed by the second index, inside the tst function x[0] will point to my_array[2]
|
|
|
Post by rosy on Oct 28, 2021 4:03:14 GMT -6
Actually, why did you add the ability to execute a FOR on an array element?
|
|
|
Post by n00b on Oct 29, 2021 16:58:29 GMT -6
Because I wanted this feature.
|
|
|
Post by rosy on Oct 30, 2021 3:01:19 GMT -6
FOR WHAT ?
|
|
|
Post by n00b on Oct 30, 2021 7:06:48 GMT -6
I just wanted it.
|
|
|
Post by aurel on Oct 31, 2021 10:41:07 GMT -6
Actually, why did you add the ability to execute a FOR on an array element?
well i think that is normal that FOR loop can iterate trough array-as indexes
ahh i see you mean that one ...
For x[0] ...using array element as iterator that work in Oxygenbasic too for example and i think that i have it in my ruben interpreter too of course it can cose troubles...i agree on that . simply because array index always must be INT..integer and i suppose array index is NULL based ..right ?
|
|
|
Post by rosy on Oct 31, 2021 12:07:03 GMT -6
I don't know what "NULL based" means, but RCBasic doesn't have an Integer.
I am only surprised, because N00b previously explained that he cares about speed and eliminating errors, and then suddenly, no one knows why, he complicates the code ...
|
|
|
Post by aurel on Oct 31, 2021 13:57:10 GMT -6
RCBasic doesn't have an Integer
maybe that is a problem ...variables are auto-defined ..i dont like it in no mather which programming language we talking...
every index of array is a integer a[0] a[1] a[2]
index cannot be float like
a[0.5] or a[3.14]
and you probably know that
|
|
|
Post by rosy on Oct 31, 2021 16:41:00 GMT -6
To check if an error comes out.
|
|
|
Post by aurel on Nov 1, 2021 4:03:54 GMT -6
i dont get it ...to check if error occur ..ok ?
in this code why is byref x
Function tst(byref x) For x[0] = 1 to 5 ' Code to execute Next End Function
x is array name ?? so that mean that is pointered ? i really don't know
you need to make skeleton program for that which will show printing output or similar i used that methods when i testing my programs
|
|
|
Post by n00b on Nov 1, 2021 5:53:41 GMT -6
I don't know if anyone realized this but ByRef variables were always able to be used as either variables or 1 dimensional arrays. Maybe I should do a better job of explaining that in the manual.
And as far as the FOR array counters effect on speed, it doesn't effect the speed at all. The for_117() function in the runtime only ever gets executed at the start of the FOR loop.
And yes, RCBasic does not have integers but array indexes are converted to integers internally so 0.5 would just be 0.
And here are some examples of valid uses of ByRef in RCBasic:
Function Test(ByRef x) x = 5 'This will set x[0] to 5 x[3] = 4 'This will set x[3] to 4
For x = 0 to 5 'Using x by itself will just use x[0] Print x Next
For x[1] = x[3] to 5 Print x[1] Next End Function
Dim myArray[10]
Test(myArray) 'This is basically the same thing as passing myArray[0] to the function Test(myArray[2]) 'This will set the array offset to 2 which means x[0] will be myArray[2], x[1] will be myArray[3] and so on
|
|
|
Post by aurel on Nov 2, 2021 10:47:52 GMT -6
Well nOOb sorry but that is not standard way of using variables and arrays in the same time x is variable and array x = 5 ....x[0] = 5 and this can make a lot of troubles in most basic-s or other progamming langs variable x and x[index] is not same so in RCbasic every variable is array element arr[0] i understand that this thing work but can make problems. but that is up to you ...
|
|
|
Post by n00b on Nov 2, 2021 11:59:21 GMT -6
Well nOOb sorry but that is not standard way of using variables and arrays in the same time x is variable and array x = 5 ....x[0] = 5 and this can make a lot of troubles in most basic-s or other progamming langs variable x and x[index] is not same so in RCbasic every variable is array element arr[0] i understand that this thing work but can make problems. but that is up to you ... You are right, its not standard. But RCBasic always allowed ByRef variables to be used as arrays so this isn't really a new feature I just added in the latest release. Most coders just never used it. There are a few high level features in RCBasic that are not standard and most people on this forum will probably never use.
|
|