I am currently working on implementing String Arrays in GCBASIC.
The concept is to build upon the existing GCBASIC string handler, where a String Array is essentially a memory allocation to repreent the array (up to the maximum addressable page). Aliases are then created for each of the String Array elements.
I have completed two steps - works well.
The identification of a String Array
DimmyStringArray(3)*10' this will create a string array'This creates the following automatically - these are memory addresses to each element;Setasidememorylocationsforvariables;Shared/AccessRAM=(SA)MYSTRINGARRAYEQU463;0x1CF;AliasesSYSMYSTRINGARRAY_0EQU463SYSMYSTRINGARRAY_1EQU474SYSMYSTRINGARRAY_2EQU486SYSMYSTRINGARRAY_3EQU497
The creation of the Aliases to the different elements of the array.
However, I am facing a challenge with handling the assignment, where the assignment to a String Array element is different from the assignment to an address within a String. For example, an assignment to a String using GCBASIC is straightforward - it like using MID()
myString(2) = "A" ' Sets the 2nd character to "A" in the existing string called myString
I want to achieve a similar functionality for String Arrays:
myStringArray(2) = "A" ' Sets the 2nd element of the String Array to "A"
But, as you can already understand… the array assignment will fail as this will not set the 2nd character of the desired element. It will be treater incorrectly as the compiler, as yet, does not know how to handle.
Proposed Solution
Define a New Command for String Array Assignment
Concepts:
Create a new command (e.g., SetStringArrayElement) to handle the assignment to specific elements within the String Array. This command will calculate the correct position within the String Array and assign the value to that position.
Or,
myStringArray(2,2) = "A" ' Sets the 2nd element of the String Array to "A"
Or,
Some other way ?
Conclusion
This all seems very clunky to me, and, I need more brains to improve.
I would appreciate any feedback or suggestions on this approach. Thank you!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Next steps. Revert all the changes. Recreate this memory allocation to ensure I have only this memory allocation process in the new code base.
Then, work through the list following.
Prevent myStringArray = "000" from creating a new variable called myStringArray. This currently works, incorrectly, as this is string assignment and not an illegal assignment to the multi element array.
Enable assignments. `myStringArray(n) = "string"
Enable reads. newString = myStringArray(n)
Enable assignment to specific bytes within a string element
Enable reads from specific bytes within a string element
I have extended the GCBASIC internal data model for variables to cater for the multielement string arrays.....so, I am thinking should all work by testing the new variable data model. Ha ha.
I think that if the compile handles the string arrays correctly, using the new data model, then these string arrays will simply leverage all the existing compiler methods to generate valid ASM across all chips. After all... an element of an array is simply a string variable - this is what I keep telling myself. :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I hesitate putting in my 2 cents worth, but looking toward a little more ability and conciseness in the future, I would like to see something like this- myarray(2,3)(4:6)="abcd". This would mean replace the forth thru sixth characters of row 2, column 3 of my matrix with "abcd". I know this is way beyond current design plans. I'm not saying do it now, you have enough to do, but don't code yourself into a corner, leave a little room for later expansion notation wise. For now, just myarray(3)(2) for second character of element 3 is fine.
alternates for myarray(2,3)(4:6) -
myarray(2,3:4,6) - more concise but I prefer the colon (4:6) to mean substring rather than having to wrap the whole thing in a mid function,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
myStringArray(2,2) = "A"
It looks like it's a two-dimensional array, i.e. it looks like a matrix of two rows and two columns.
Practically as if it had been sized like this:
Dim myStringArray (2) (2).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This could be ok.
But so you can only replace a character inside the string.
Stringarray (element) = AnotherString to copy a string on the array
Stringarray (element) = "NewString" to copy a string on the array
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For what it's worth, I've look at that for several minutes, and that is not intuitively obvious to me what it is supposed to mean. As well as truly backing you into a corner for future expansion.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am currently working on implementing String Arrays in GCBASIC.
The concept is to build upon the existing GCBASIC string handler, where a String Array is essentially a memory allocation to repreent the array (up to the maximum addressable page). Aliases are then created for each of the String Array elements.
I have completed two steps - works well.
The identification of a String Array
The creation of the Aliases to the different elements of the array.
However, I am facing a challenge with handling the assignment, where the assignment to a String Array element is different from the assignment to an address within a String. For example, an assignment to a String using GCBASIC is straightforward - it like using MID()
myString(2) = "A" ' Sets the 2nd character to "A" in the existing string called myString
I want to achieve a similar functionality for String Arrays:
myStringArray(2) = "A" ' Sets the 2nd element of the String Array to "A"
But, as you can already understand… the array assignment will fail as this will not set the 2nd character of the desired element. It will be treater incorrectly as the compiler, as yet, does not know how to handle.
Proposed Solution
Define a New Command for String Array Assignment
Concepts:
Create a new command (e.g., SetStringArrayElement) to handle the assignment to specific elements within the String Array. This command will calculate the correct position within the String Array and assign the value to that position.
Or,
myStringArray(2,2) = "A" ' Sets the 2nd element of the String Array to "A"
Or,
Some other way ?
Conclusion
This all seems very clunky to me, and, I need more brains to improve.
I would appreciate any feedback or suggestions on this approach. Thank you!
If I were to offer a preference, it would be:
It makes most sense to my tiny mind.
@c-conversion
I think your recommendation is a better solution. Mine was just dumb in comparison. :-)
I have dumped the Alias approach. It created too many issues to be resolved.
The current approach now creates variables at the correct memory location for each element. I can recreate the aliases, if needed.
Now creates memory allocations. With the element address as a suffix.
Next steps. Revert all the changes. Recreate this memory allocation to ensure I have only this memory allocation process in the new code base.
Then, work through the list following.
myStringArray = "000"
from creating a new variable calledmyStringArray
. This currently works, incorrectly, as this is string assignment and not an illegal assignment to the multi element array.newString = myStringArray(n)
I have extended the GCBASIC internal data model for variables to cater for the multielement string arrays.....so, I am thinking should all work by testing the new variable data model. Ha ha.
I think that if the compile handles the string arrays correctly, using the new data model, then these string arrays will simply leverage all the existing compiler methods to generate valid ASM across all chips. After all... an element of an array is simply a string variable - this is what I keep telling myself. :-)
I hesitate putting in my 2 cents worth, but looking toward a little more ability and conciseness in the future, I would like to see something like this- myarray(2,3)(4:6)="abcd". This would mean replace the forth thru sixth characters of row 2, column 3 of my matrix with "abcd". I know this is way beyond current design plans. I'm not saying do it now, you have enough to do, but don't code yourself into a corner, leave a little room for later expansion notation wise. For now, just myarray(3)(2) for second character of element 3 is fine.
alternates for myarray(2,3)(4:6) -
myarray(2,3:4,6) - more concise but I prefer the colon (4:6) to mean substring rather than having to wrap the whole thing in a mid function,
I understand the ask. I will keep this replacement in mind as this approach has to be faster than constructing a subroutine to do the same.
myStringArray(2,2) = "A"
It looks like it's a two-dimensional array, i.e. it looks like a matrix of two rows and two columns.
Practically as if it had been sized like this:
Dim myStringArray (2) (2).
Any syntax needs to be unique, distinctive and syntactically meanful.
Would this work? StringArray( element, position, ascii_code ). Like myStringArray( 2, 4, "A" ).. replace the 4th Ascii byte in Element 2 with "A".
This could be ok.
But so you can only replace a character inside the string.
Stringarray (element) = AnotherString to copy a string on the array
Stringarray (element) = "NewString" to copy a string on the array
For what it's worth, I've look at that for several minutes, and that is not intuitively obvious to me what it is supposed to mean. As well as truly backing you into a corner for future expansion.