For those professional compiler designer people, can you please check out my idea on how I will go about conveting to bytecode?
This is the text file explaining everything.
NORMAL CODE:
--------------------------------------------------------
void print(char txt)
{
showchr txt[0];
}
void main()
{
print("lol");
}
INSTRUCTION CODE:
--------------------------------------------------------
function - void - print - 1 -- char - txt
action - setdepth - 1
action - showchr - txt[0]
action - setdepth - 0
function - void - main - 0
action - setdepth - 1
action - funcall - print - "lol"
action - setdepth - 0
BYTECODE:
--------------------------------------------------------
1 addp txt
2 setp char
3 vfunc print
4 depth 1
5 sclear
6 push 0
7 var txt
8 showchr
9 sclear
10 pclear
11 depth 0
12 vfunc main
13 depth 1
14 sclear
15 push "lol"
16 fcall print
17 sclear
18 pclear
19 depth 0
20 end
CONVERSION TO BYTECODE:
--------------------------------------------------------
Function found. Loop through data, and add data name and type
Add void function and name
new depth found, set depth
depth 1 after function declaration - clear stack
found showchr action. Parse data
Add firm RPN data - 0
Found variable name - add
showchr found. Show last stack element
Last item was action requiring data. Clear stack
Going to 0 depth (leaving function). Clear parameter data
Function found. Loop through data, and add data name and type
Add void function and name (name = default entry function (set to "main" by default, though can be changed by user), so system must set this (12) as entry point).
depth 1 after function declaration - clear stack
Function call found. Push data, and function name.
Function call done. Clear stack.
Going to depth 0 (leaving function). Clear parameter data
Depth 0 after entry function. End file
NAVIGATION:
--------------------------------------------------------
Enter at "main()" (12))
Find action, push data "lol", action type is funccall. Set backtrack point to 16, and call function "print"
Go to "print()" - 2*par count, (1)
Get number of parameters, and set them to that number of items off top of stack
Found sclear, so clear stack
Push 0 onto stack
Replace with 0th element of txt variable ("l")
show character "l"
clear stack
clear parameter data
depth gone from 1 to 0, so return to backtrack point
clear stack
clear paremeters
depth gone to 0
end
Tell me if you spot any flaws
Thanks.