Author Topic: How is a QB64 exe file made?  (Read 6432 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
How is a QB64 exe file made?
« on: February 23, 2020, 10:22:15 am »
I read this discription from Aurel at Snytax Bomb:
https://www.syntaxbomb.com/index.php/topic,6677.msg347040096.html#msg347040096

Quote
In fact both of them are interpreters with one difference.
Qb64 compile into bytecode and then is this bytecode binded or added to qb64 runtime interpreter which form
one exe file as standalone, so looks like is compiled into machine code.

This is how SdlBasic works and maybe Just Basic because it Tokenizes file for .exe but I am under the impression QB64 is completely compiled through C+ into .exe before it can be run at all.
« Last Edit: February 23, 2020, 10:27:52 am by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: How is a QB64 exe file made?
« Reply #1 on: February 23, 2020, 10:36:23 am »
Aurel is talking through his nose.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How is a QB64 exe file made?
« Reply #2 on: February 23, 2020, 10:41:31 am »
Thanks, is my description accurate (for it's length)?

I don't want to misrepresent or leave something major unsaid about QB64 specially at another forum.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: How is a QB64 exe file made?
« Reply #3 on: February 23, 2020, 10:44:05 am »
Being a math guy, I'd say the shortest representation of qb64 is an equation:

Code: QB64: [Select]
  1. QB64 = BASIC + _GL => C++
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How is a QB64 exe file made?
« Reply #4 on: February 23, 2020, 10:45:49 am »
Being a math guy, I'd say the shortest representation of qb64 is an equation:

Code: QB64: [Select]
  1. QB64 = BASIC + _GL => C++

LOL luv it, so it's C++, two plus signs not one?

Update: Yes I just did a check on Internet C+ is a grade. :)
« Last Edit: February 23, 2020, 11:02:06 am by bplus »

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: How is a QB64 exe file made?
« Reply #5 on: February 23, 2020, 11:02:15 am »
Quote
Aurel is talking through his nose.
That is a nice to know ..heh.
And why that be secret or i don't know what else.
Whole Java is based on bytecode iterpreter, and also many other BASIC dialects.
So i don't see any problem with that.
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Marked as best answer by bplus on February 23, 2020, 04:08:43 pm

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: How is a QB64 exe file made?
« Reply #6 on: February 23, 2020, 04:59:19 pm »
There's no bytecode to be seen here: how fancy do you think we are?

QB64 just reads the source file line by line and generates corresponding C++ code directly using something not entirely unlike
Code: [Select]
IF inputelements$(1) = "DRAW" THEN
    PRINT #outfile, "sub_draw(";
    ' do any arguments
    PRINT #outfile, ");"
END IF
And continues on for each statement.

Then you just run that through g++/clang and link it with some runtime libraries, et voilĂ .

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How is a QB64 exe file made?
« Reply #7 on: February 23, 2020, 09:10:07 pm »
(I am) Not really qualified to judge best answer but if Luke doesn't know...
« Last Edit: February 23, 2020, 09:17:42 pm by bplus »

FellippeHeitor

  • Guest
Re: How is a QB64 exe file made?
« Reply #8 on: February 23, 2020, 09:11:33 pm »
Luke just described the whole process, what doesn't he know?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How is a QB64 exe file made?
« Reply #9 on: February 23, 2020, 09:15:36 pm »
But IF Luke doesn't know THEN we are in deep do-do!

FellippeHeitor

  • Guest
Re: How is a QB64 exe file made?
« Reply #10 on: February 23, 2020, 09:21:27 pm »
Aaaah.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How is a QB64 exe file made?
« Reply #11 on: February 24, 2020, 02:50:03 am »
And all the while I thought it was done with unicorns and pixie dust. Son of a batch! Oh well. I guess if you're looking for a horny horse left in the dust, you need FreeBASIC for that.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: How is a QB64 exe file made?
« Reply #12 on: February 24, 2020, 03:53:03 am »
But IF Luke doesn't know THEN we are in deep do-do!

I just barely made it out of deep do-do a couple of hours ago. I heard water running and after checking the inside of the house for a broken pipe and not finding one I went outside to check the faucet. I never made it to the faucet. The snow was too deep and I fell down and could not get back on my feet. I had to crawl through the snow to get to the driveway and I barely made it. I was almost too weak to stand but somehow made it to my feet. I was extreme hyperventilating and my heart was pounding furiously in my chest. I thought that I was going to pass out. But, somehow I made it into the house and to my bed where I stayed for probably over an hour. Then I got up and went down into the basement to turn off the water. Then of course I sat down in my chair, turned on my computer and visited one of my favorite internet sites, this one! One must have priorities. :)

Concerning the OP and the question of pure interpreter, compiled to bytecode or compiled to native cpu code either jit or to exe before there was never any question in my mind. QB64 executes way to fast to be any type of interpreter. The only question for me is who can write faster C++ code, QB64 or myself. That is complicated by the fact that if the basic code is not fast then the C++ code is also most likely not going to be fast.

I personally do not trust compilers and with good reason. One optimized C routine I wrote took iirc about 23 machine language instructions. I coded it using only 6 machine instructions. Just last week I wrote a function in C++ that looked fast but it confused the bejeebers out of all tested compilers except one. The current experimental Clang compiler was able to handle it quite well. 

The original C++ function is a new way of computing 64 bit bitboards for move generation in chess. The name is Split Index Super Set Yielding bitboards. Or for short, SISSY bitboards.
Code: QB64: [Select]
  1. ' The C++ function
  2. case WQUEEN:
  3.         h->moves[id] = qss[fs][occ.b08.rank1][0]
  4.                      & qss[fs][occ.b08.rank2][1]
  5.                      & qss[fs][occ.b08.rank3][2]
  6.                      & qss[fs][occ.b08.rank4][3]
  7.                      & qss[fs][occ.b08.rank5][4]
  8.                      & qss[fs][occ.b08.rank6][5]
  9.                      & qss[fs][occ.b08.rank7][6]
  10.                      & qss[fs][occ.b08.rank8][7];
  11.  
  12. ' Clang experimental
  13. queenAttacks(int, unsigned long long):                    
  14. .Lfunc_begin0:
  15.         push    rbx
  16. .Ltmp0:
  17.         mov     rdx, rsi
  18.         mov     rcx, rsi
  19.         mov     r11, rsi
  20.         mov     r10, rsi
  21.         mov     r9, rsi
  22.         mov     r8, rsi
  23.         movzx   ebx, sil
  24.         mov     rax, rsi
  25. .Ltmp1:
  26.         shr     rax, 2
  27. .Ltmp2:
  28.         shr     rdx, 10
  29.         shr     rcx, 18
  30.         shr     r11, 26
  31.         shr     r10, 34
  32.         movsxd  rsi, edi
  33.         shl     rbx, 6
  34.         shl     rsi, 14
  35.         and     eax, 16320
  36.         mov     rax, qword ptr [rsi + rax + qss+8]
  37.         and     rax, qword ptr [rsi + rbx + qss]
  38.         shr     r9, 42
  39.         and     edx, 16320
  40.         and     rax, qword ptr [rsi + rdx + qss+16]
  41.         shr     r8, 50
  42.         and     ecx, 16320
  43.         and     rax, qword ptr [rsi + rcx + qss+24]
  44.         and     r8d, -64
  45.         and     r11d, 16320
  46.         and     rax, qword ptr [rsi + r11 + qss+32]
  47.         and     r10d, 16320
  48.         and     rax, qword ptr [rsi + r10 + qss+40]
  49.         and     r9d, 16320
  50.         and     rax, qword ptr [rsi + r9 + qss+48]
  51.         and     rax, qword ptr [rsi + r8 + qss+56]
  52.         pop     rbx
  53.         ret
  54.  
  55. ' My handwritten assembler
  56.  
  57. _DATA SEGMENT
  58.  
  59. bbs STRUCT
  60. r1 BYTE ?
  61. r2 BYTE ?
  62. r3 BYTE ?
  63. r4 BYTE ?
  64. r5 BYTE ?
  65. r6 BYTE ?
  66. r7 BYTE ?
  67. r8 BYTE ?
  68. bbs ENDS
  69.  
  70. bbu UNION
  71. bbs<>
  72. b64 QWORD ?
  73. bbu ENDS
  74.  
  75. occ bbu<>
  76.  
  77. _DATA ENDS
  78.  
  79. _TEXT SEGMENT
  80.  
  81. RayAttacks PROC
  82.  
  83. ; rcx = sq
  84. ; rdx = address of rss
  85. ; r8 = occ
  86.  
  87. shl rcx, 11 ; sq * 2048
  88. mov occ.b64, r8
  89. add rdx, rcx
  90. movzx r8, occ.r1
  91. movzx r9, occ.r2
  92. mov rax, [rdx + r8 * 8]
  93. mov rcx, [rdx + r9 * 8 + 131072]
  94. movzx r8, occ.r3
  95. movzx r9, occ.r4
  96. and rax, [rdx + r8 * 8 + (2 * 131072)]
  97. and rcx, [rdx + r9 * 8 + (3 * 131072)]
  98. movzx r8, occ.r5
  99. movzx r9, occ.r6
  100. and rax, [rdx + r8 * 8 + (4 * 131072)]
  101. and rcx, [rdx + r9 * 8 + (5 * 131072)]
  102. movzx r8, occ.r7
  103. movzx r9, occ.r8
  104. and rax, [rdx + r8 * 8 + (6 * 131072)]
  105. and rcx, [rdx + r9 * 8 + (7 * 131072)]
  106. and rax, rcx
  107. ret
  108.  
  109. RayAttacks ENDP
  110.  
  111. TEXT ENDS
  112.  
  113.  
  114.  

I'd put my hand written assembler up against Clang any day of the week.

This was just in case there is anyone that would be interested in the workings behind the scene.
My name is Michael, but you can call me Mike :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How is a QB64 exe file made?
« Reply #13 on: February 24, 2020, 12:59:49 pm »
Quote
Then of course I sat down in my chair, turned on my computer and visited one of my favorite internet sites, this one! One must have priorities. :)

LOL thank goodness we can laugh about this now.

hmm... love Basic and assembler, Basic + assembler...

@romichess
You might be interested in MasmBasic developed by jj2007 (I met at Retro (RIP) and member at FreeBasic forum)
 https://retrobasic.allbasic.info/index.php?topic=358.msg2397#msg2397
links still work.
« Last Edit: February 24, 2020, 01:02:26 pm by bplus »

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: How is a QB64 exe file made?
« Reply #14 on: February 24, 2020, 03:58:45 pm »
LOL thank goodness we can laugh about this now.

hmm... love Basic and assembler, Basic + assembler...

@romichess
You might be interested in MasmBasic developed by jj2007 (I met at Retro (RIP) and member at FreeBasic forum)
 https://retrobasic.allbasic.info/index.php?topic=358.msg2397#msg2397
links still work.

Just waiting on the plumber to show up. I like the idea of a basic that outputs assembler. That way after having a working program I could rewrite sections one at a time for better performance. But for me and my chess programming goals only 64 bit assembler will do. Thanks for the link though!
My name is Michael, but you can call me Mike :)