Quote: " As I unserstand it PB's compiler exports to a kind of bytecode "
Yep.
Quote: "- how do you get all of PB's functions into that code"
You don't have to, The compiler generates byte code for the 'language constructs' not the command set. So the compiler only generates the structural framework code, the commands/functions are called from language function library.
A easy example of this is how Dbpro works. While the compiler generates 'machine code' for the core, when it comes to the command sets, it's merely dumping a 'call procedure' to call the function from the library. This is defined in the command definition table. So the parser just matches the command and dumps it's known functions inputs/outputs and name.
So something like
Position object 1,xpos,ypos
in pseudo code ends up looking something like this.
Push Ypos
Push Xpos
Push 1
Call Dll Function, "PositionObject"
Now structural code is dumped directly into the machine/byte code.
So something like this,
B =99
A=B
C=A+5
D=A+B+C
in pseudo code might end up looking something like this (2 register operations).
; B=99
Move B, #99 ; B=99
; A=B
Move A, B ; A=B
; C=A+5
Move Temp,A ; Protect A, moving it's value to a temp register
Add Temp, #5 ; Add the 5 to the temp register
Move C, Temp ; Move the temp into the result
; D=A+B+C
Move Temp, A ; Pull A into a temp register
Add Temp,B ; Add B to the temp
Add Temp,C ; Add C to temp
Move D,Temp ; Move tallied Temp into result
The Byte Code the Virtual Machine in PB uses, is basically a 2 / 3 register version of the above. The VM is a sort of processor simulation. Where the simulated cpu is 'pretend', but obeys much the same rules as a real cpu. Obviously being a 680x0 fan, PB opcodes resemble a dumbed down 68K somewhat, just without most, if not all, of the instruction modes.
So since the PB Vm supports a subset, the opcodes are smarter than a real cpu's opcodes.. (meaning they can deal with mixed register 'types' through a common opcode, rather than through many varied opcodes.
The PB VM instruction set has only a handful of central instructions. For example..
Move (various modes), AddInt, SubInt, MultInt, DivInt, Add, Sub, Mult, Div, Cmp (various modes), And, Or, Xor, Not, Branch, Jump, Jsr , Push, Pop and a bunch of hybrid op-codes to replace 'common' sequences of instructions, mostly for loop structures and scope changes..
So all the Structural code is broken down and output as these op-codes. Which the VM just interprets to execute a program. Obviously if the compiler generates a standard set of tokens for the core stuff, this opens up the door to doing some post processing upon the tokens, and even translation of the byte code op-codes into other languages, and native cpu's..