fastspin BASIC improvements
ersmith
Posts: 6,053
Edit: I found and was able to fix the bug with using multiple function results as parameters, and have updated the .zip file on github with the new binary.
I've added a number of features to the BASIC support in fastspin, including:
- support for multiple assignment and functions which return multiple values
- new assignment operators like += and -=
- shorter aliases for bitwise operators (& for AND, | for OR, ^ for XOR)
- some additional P2 intrinsics like WRPIN and RDPIN
- support for BYVAL and BYREF parameter modifiers to force parameters to be passed by reference or value
The multiple assignment syntax is very much like that of Spin2, and doesn't need any parentheses. So you can write:
The code isn't very well polished yet and there are probably bugs, which is why this is labelled as a "beta" release. But if you'd like to try it out, the binaries for the new fastspin and spin2cpp are up on github in https://github.com/totalspectrum/spin2cpp/releases.
I've added a number of features to the BASIC support in fastspin, including:
- support for multiple assignment and functions which return multiple values
- new assignment operators like += and -=
- shorter aliases for bitwise operators (& for AND, | for OR, ^ for XOR)
- some additional P2 intrinsics like WRPIN and RDPIN
- support for BYVAL and BYREF parameter modifiers to force parameters to be passed by reference or value
The multiple assignment syntax is very much like that of Spin2, and doesn't need any parentheses. So you can write:
dim as integer a,b function quotrem(x as integer, y as integer) as integer,integer return x/y, x mod y end function a,b = 7, 128 ' assign multiple values a,b = b,a ' swap values a,b = quotrem(a, b) ' assign multiple function results a,b = quotrem(quoterem(a,b)) ' use multiple function results as parameters
The code isn't very well polished yet and there are probably bugs, which is why this is labelled as a "beta" release. But if you'd like to try it out, the binaries for the new fastspin and spin2cpp are up on github in https://github.com/totalspectrum/spin2cpp/releases.
Comments
Oh, ouch! In my zeal to allow Spin and PASM code to port over easily to BASIC I forgot about that . I'll probably revert the &|^ operator change before the final 4.1 release; "&" is also used in some BASICs for concatenation, and while I was willing to give that one up giving up both concatenation and exponentiation is probably a bridge too far.
from https://w3schools.com/python/python_operators.asp
I wonder how easy it would be to align the spin operators with python? Seems a lot are already the same.
Then it might be possible to use the spin interpreter for much of the python interpreter.
Maybe, but it seems that if Micro Python takes over 300K, there must be a lot going on that I'm not aware of.
Then there is the I/O which includes all the formatting options, arrays and lists, date and time, SD drivers, etc.
But I’m sure the basic functions that ate common would be much faster and less code than micropython.
I guess it boils down to how compatible we want to be with other BASICs. If people writing BASIC code expect ^ to be exponentiation, and it's actually XOR, then their code will compile (^ is a legal operator) but won't work at all correctly . Granted, BASIC isn't a very standardized language so some variation between compilers is inevitable, but I don't want to stray too far from what users will expect from a .bas file.
Understood. Maybe for BASIC, it's best to use AND, OR, and XOR.
I'm afraid that's not going to be feasible at all. In Spin "a+b" always means 32 bit addition, so it's very straightforward to compile (fastspin makes an "add a, b" instruction, Spin2 can make an "add" byte code, etc.). In Python "a+b" has to translate into something very complicated: there is something like an "add" bytecode, but to implement it the interpreter has to look up the types of a and b, do any conversions necessary, and invoke the __add__ method of the appropriate class. That's because the types of "a" and "b" are not known in Python and can change dynamically at run time; they could be strings, floats, integers, user classes, or anything else, and the same code may execute with different types at different times. So Spin bytecode and Python bytecode may superficially look similar, but they have very different meanings.
Still, using common operators makes some sense.
Heck, I don't know of a better example of a non-issue for me.
-MS QuickBASIC (MS PDS-7.1 actually)
-BASIC 4 Android (B4A)
-BASIC 4 Arduino (B4R) (for ESP32)
-RFO BASIC
-PropBASIC
-PowerBASIC
-Micromite BASIC
-Tibbo BASIC
And now about to try ANNEX 32 (ESP32 BASIC interpreter) on the M5Stack platform.
They all have their differences but so do the respective platforms. I constantly hop from one to the next because they are still the most productive tools for this part-time programmer which is why I am delighted that BASIC appears to not be going away.
Self employed....time really is money.