I noted that you introduce an extension keyword GOFUNC - could I suggest naming it _GOFUNC (with a leading underscore)?
The reason is that the GW-BASIC syntax forbids using keywords as identifiers, so adding a keyword will make the compiler incompatible with any program that has for example something like GOFUNC$="GO" or DEF FNGOFUNC(x)=x+1. The underscore is not otherwise legal in GW-BASIC identifiers , so this avoids a namespace clash. It's the same approach taken by QB64 and I've borrowed the idea for PC-BASIC extension functions as well.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Rob, I've added your _GOFUNC suggestion. It looks like this now:
everton@homeubu:~/basgo$ more gofunc/rad.bas
110 rem Using _GOIMPORT and _GODECL to embed Go code within BASIC code
120 rem
130 _goimport("math")
140 _godecl("func degToRad(d float64) float64 {")
150 _godecl(" return d*math.Pi/180")
160 _godecl("}")
170 rem
180 rem Now using _GOFUNC to call that Go function from BASIC code
190 rem
200 d = 180
210 r = _gofunc("degToRad", d)
220 print d;"degrees in radians is";r
everton@homeubu:~/basgo$
everton@homeubu:~/basgo$ basgo-build < gofunc/rad.bas > a.go && go run a.go
180 degrees in radians is 3.141592653589793
everton@homeubu:~/basgo$
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi guys,
First of all, thanks to Rob for PC-BASIC. It is amazing. It brings sweet old memories of fun with BASIC.
Currently I am sketching a toy compiler to translate BASIC programs to Go. Then the Go code can be compiled to native binary. It works like this:
Right now, it can handle only simple BASIC programs.
I use the awesome PC-BASIC as authoritative reference for the implementation of that BASIC-to-Go toy compiler. :-)
One can find the full toy compiler here: https://github.com/udhos/basgo
If you find fun in compiling old BASIC code to executable code, let me know. :-)
Cheers,
Everton
Hi Everton, that's great! I'll give it a try.
I noted that you introduce an extension keyword
GOFUNC
- could I suggest naming it_GOFUNC
(with a leading underscore)?The reason is that the GW-BASIC syntax forbids using keywords as identifiers, so adding a keyword will make the compiler incompatible with any program that has for example something like
GOFUNC$="GO"
orDEF FNGOFUNC(x)=x+1
. The underscore is not otherwise legal in GW-BASIC identifiers , so this avoids a namespace clash. It's the same approach taken by QB64 and I've borrowed the idea for PC-BASIC extension functions as well.Thanks for the
_GOFUNC
hint.I filed an issue to fix it asap:
https://github.com/udhos/basgo/issues/3
Rob, I've added your _GOFUNC suggestion. It looks like this now: