Using the java virtual machine ties you into doing things their way, I had a look and it would be very good to make your language run on the vm (and I may still do that) but there is not a lot of room to play with new ideas. Your language has to look like java in the first place or you have to do a lot of fancy stuff which takes away the ease factor.
I actually have no idea if what I just said it true, but it is my best guess.
@frozenheart
Once you have a parser and lexer you need to do the following:
Build a tree from the parser
Make sure the syntax is correct
Compile the bugger.
- Basically for each part of the tree you have to generate code, for example:
code
a = (b / c) + d * (e - f)
tree
= |+----+----+| |a + | +--+--+ | | / * | | +++ +-+-+ | | | | b c d - | +++ | | e f
bytecode
load e 1
load f 2
sub 1 1 2
load d 2
mult 1 1 2
load b 2
load c 3
div 2 2 3
add 1 1 2
save a 1
You need to work backwards through your tree (from the right) and take each leaf as it goes.
a
|
| |
b c
Bascially calculate c (if it is a variable then load it) and put it in the first available register
Then calculate b not using the register / stack / whatever that c is in (anything past it is okay)
then do the operation, saving the result where c was
The trick is to have a counter that has the currently available register.
It gets compilcated if you run out of registers.
You have to do the following for each node on the tree.
current free variable = n
calculate c using n
....
current free variable = n+1
calculate b using n+1
...
do operation c storing result in n
It gets different when doing function calls (stack etc.) if you haven't already it is a good idea to look at some assembly.