<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent posts to Compiling BASIC to Go to Binary</title><link>https://sourceforge.net/p/pcbasic/discussion/programs/thread/e68427e82d/</link><description>Recent posts to Compiling BASIC to Go to Binary</description><atom:link href="https://sourceforge.net/p/pcbasic/discussion/programs/thread/e68427e82d/feed.rss" rel="self"/><language>en</language><lastBuildDate>Sun, 03 Feb 2019 18:13:20 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/pcbasic/discussion/programs/thread/e68427e82d/feed.rss" rel="self" type="application/rss+xml"/><item><title>Compiling BASIC to Go to Binary</title><link>https://sourceforge.net/p/pcbasic/discussion/programs/thread/e68427e82d/?limit=25#9286/000f</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Rob, I've added your _GOFUNC suggestion. It looks like this now:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;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 &amp;lt; gofunc/rad.bas &amp;gt; a.go &amp;amp;&amp;amp; go run a.go
 180 degrees in radians is 3.141592653589793 
everton@homeubu:~/basgo$ 
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Everton da Silva Marques</dc:creator><pubDate>Sun, 03 Feb 2019 18:13:20 -0000</pubDate><guid>https://sourceforge.nete28a7b28f7346d6e088e6fd1aef0995bd06be9af</guid></item><item><title>Compiling BASIC to Go to Binary</title><link>https://sourceforge.net/p/pcbasic/discussion/programs/thread/e68427e82d/?limit=25#9286/2678</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks for the &lt;code&gt;_GOFUNC&lt;/code&gt; hint.&lt;/p&gt;
&lt;p&gt;I filed an issue to fix it asap:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/udhos/basgo/issues/3" rel="nofollow"&gt;https://github.com/udhos/basgo/issues/3&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Everton da Silva Marques</dc:creator><pubDate>Sat, 02 Feb 2019 16:20:54 -0000</pubDate><guid>https://sourceforge.netd159ca854df2fa63a8d1b0c04675f474925f7223</guid></item><item><title>Compiling BASIC to Go to Binary</title><link>https://sourceforge.net/p/pcbasic/discussion/programs/thread/e68427e82d/?limit=25#9286</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Everton, that's great! I'll give it a try.&lt;/p&gt;
&lt;p&gt;I noted that you introduce an extension keyword &lt;code&gt;GOFUNC&lt;/code&gt; - could I suggest naming it &lt;code&gt;_GOFUNC&lt;/code&gt; (with a leading underscore)? &lt;/p&gt;
&lt;p&gt;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 &lt;code&gt;GOFUNC$="GO"&lt;/code&gt; or  &lt;code&gt;DEF FNGOFUNC(x)=x+1&lt;/code&gt;. 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.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rob Hagemans</dc:creator><pubDate>Sat, 02 Feb 2019 11:25:10 -0000</pubDate><guid>https://sourceforge.netdd7276e5f62886622451ce9e53dccc053a9a0cf6</guid></item><item><title>Compiling BASIC to Go to Binary</title><link>https://sourceforge.net/p/pcbasic/discussion/programs/thread/e68427e82d/?limit=25#a9b1</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Hi guys,&lt;/p&gt;
&lt;p&gt;First of all, thanks to Rob for PC-BASIC. It is amazing. It brings sweet old memories of fun with BASIC.&lt;/p&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;basgo-build &amp;lt; program.bas &amp;gt; program.go ;# translates to Go
go build program.go ;# compiles to executable
./program ;# executes the binary program
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Right now, it can handle only simple BASIC programs.&lt;/p&gt;
&lt;p&gt;I use the awesome PC-BASIC as authoritative reference for the implementation of that BASIC-to-Go toy compiler. :-)&lt;/p&gt;
&lt;p&gt;One can find the full toy compiler here: &lt;a href="https://github.com/udhos/basgo" rel="nofollow"&gt;https://github.com/udhos/basgo&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you find fun in compiling old BASIC code to executable code, let me know. :-)&lt;/p&gt;
&lt;p&gt;Cheers,&lt;br/&gt;
Everton&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Everton da Silva Marques</dc:creator><pubDate>Sun, 20 Jan 2019 01:45:07 -0000</pubDate><guid>https://sourceforge.netd21502c9f7133a3d9faa8f57c8096eeb8e4f6081</guid></item></channel></rss>