Open NeeEoo opened 3 years ago
That's a good idea But I fear it will be a nightmare to implement 😢
In the meantime, what do you say about making the interpreter have 16-bit mode? Something like a flag to the interpreter to treat data cells as 16-bit. (Can be any arbitrary number of bits as well I guess)
If we implement #30 i might try to make this. Since the framework for custom sized variables would exist then
elikaski
That's a good idea But I fear it will be a nightmare to implement 😢
In the meantime, what do you say about making the interpreter have 16-bit mode? Something like a flag to the interpreter to treat data cells as 16-bit. (Can be any arbitrary number of bits as well I guess)
This pr may be what you suggested: #66
This would probably be a long term thing.
A 16-bit is stored as 2 cells since this is an 8-bit compiler. The 16-bit max value is
65535
.A 16-bit int is also called a short.
The number 512 would be stored as
2 0
. The number 12941 would be stored as50 141
.The compiler would have to keep track of the type of the variable. It would also need to keep track of the type of the variable that is going to be assigned.
Bools and chars should still be treated as ints
This would also mean we would have to implement 2 versions of every algorithm since it would have to support shorts.
Casting an 8-bit int to a 16-bit int could be hard but it could be done by making a copy of the 8-bit number and setting the lowest cell of the short to the copy.
A short is defined like this
Converting from an int to a short could be implemented as implicit casting but it would require more work from the compiler.
But it could also be implemented this way.
But there is a problem. What if we do:
The number literal 31 is an int, we would need a short.
The compiler would also need support for short temp variables for copying.
Since printing only supports 8-bit cells in an 8-bit environment, we should print the lowest cell, and reading a char would only fill the lowest cell if it is defined like this:
The library function
readint
would work with shorts but it would need some changes.Since this would also need to support arrays it would need to do some extra math to get the index.
1 dimensional array:
multidimensional array:
Implementation:
The pseudo code of shows some ways to implement some algorithms that would use shorts.
These algorithms only support shorts and not a mix of shorts and ints.
But there are some algorithms where I provided with a mix of shorts and ints
Basic Math:
Multiplication could be implemented in 2 ways: Using the add code, or making a new algorithm.
Relational Operators:
To make a mixed version you could probably just replace
b.high
with 0