Forgive my lack of documentation. This will be remidied shortly. Also, some instructions remain unimplemented, as I haven't found a use for them yet.
Also, note the absolute lack of references (int &a = b). Haskell has created the idea in my head they are not needed, but I can see them being useful and I will almost undoubtedly implement them at some point.
I look forward to sorting through your abuse to see if anyone says anything constructive.
The reason is pure laziness. I dread maintaining that assembler but it is entirely my fault. Attempts to make a better one (Attempting to improve the current would be like going to sphagetti city to eat baked beans) have been shadowed by the more important matter of maintaining and bettering the virtual machine itself.
The assembler works. I consider that a plus.
Name:
Anonymous2012-03-07 9:23
>>src/exec.c
Why do you use a giant switch instead of dispatching at the end of each instruction handler as a tail-call? Why aren't there statically dispatched movement operations? Why do you use string-based lookups? Why do you use a cavemen-style stack instead of an x86-style stack? Why doesn't it provide support for cooperative threading? Why doesn't it provide array objects?
0/10
>>6
Downward-growing stacks considered harmful. Downward-growing stacks in a reallocatable heap considered harmful as fuck.
Name:
Anonymous2012-03-07 10:22
>>8
x86 can use upward-growing stacks. Also, you can massively over-allocate stack space and the physical memory space won't actually be used until you access it, thanks to virtual memory.
>>8
What exactly do you mean by a downward-growing stack? Does it grow like a bamboo (newer addresses appear at the root) or like a pine (newer addresses appear at the tip)?
>>9 x86 can use upward-growing stacks.
By using a kludge involving adding an ADD/SUB/LEA after each stack instruction. At this point, the stack pointer is a hindrance the programmer is working against. Upward-growing stacks are obviously not what >>7 meant by an "x86-style stack." What else could it mean? Using a separate stack segment?
Name:
6,92012-03-07 11:26
>>14
x86 can use upward-growing stacks without kludges by tickling the direction bit of the stack segment.
I was referring to the ability of performing random access on the stack and the use of enter-leave for allocation instead of push-pop.
Name:
Anonymous2012-03-07 13:57
>>15
That doesn't change the behavior of the push/pop instructions, only the limit check. Look at the Intel manual and you'll see that.
Name:
Anonymous2012-03-07 14:36
>>6
``Why do you use a giant switch instead of dispatching at the end of each instruction handler as a tail-call?''
Because it made sense. I don't know what you're suggesting, could you explain a little more clearly, or are you just trolling?
The size of an object can be dynamically changed and you can use an ``offset pointer'' to access different parts of it. It would be trivial to implement some kind of array. Especially in a higher level language where you can abstract the details away.
Name:
Anonymous2012-03-07 15:40
I'm considering creating seperate stacks: One for general purpose use and one where the VM puts return addresses, which is not accessible to a program. THis wopuld greatly increase safety and freedom in the stack.
>>20
That's funny, because I use git and Linux and the money I make is also real. My landlord hasn't turned any of it down. I wasn't aware there was a correlation between git, Linux and counterfeit money. Do counterfeiters counterfeit with Linux and git?
You better git back to your cubicle and churn out some more [b][i][o]ENTERPRISE[/]o[/i][/b] Java for your PHB, monkey.
No, you're a hobbyist. Sure, you can write some faggy open source bullshit that won't make you any money ever, but that doesn't mean shit to me. In the business world, all those upvotes, karma and forum reputation points and recognition among tens of people in some sub-niche don't mean shit. So yeah, I'll take my job in a real office than your mother's basement any day.
>>26
looool, if you're a programmer working in an office then you'll never be shit. The real money is in Silicon Valley where I happen to be attending a top university. I've been consulting for startups with connections to VCs who throw money around like it's confetti and when I'm ready to start my own business I'll be swimming in it.
Enjoy your praying for raises and inevitable layoff, monkeyboy.
This is a minimal, not executable and untested example and it's very dependent on compiler optimization but it should be the most efficient instruction dispatching design, at least on GCC for x86, mainly because it makes the loop implicit. You might want to directly write assembly in order to avoid overflowing the stack with inferior compilers.
By the way, >>1, your code doesn't react well to malformed instructions.
Interesting. As always, tail calls to arbitrary functions yields the most arbitrary transfers of control. You could potentially leave the cycle loop if you wanted too, transferring control to some other kind of cycle function.
Name:
Anonymous2012-03-08 4:59
>>30
Wouldn't that result in horrificly bloated binaries and slow compile times? I already have > 3KLOC and while the main loop is only a small fraction of that, nigh on abusive use of the preprocesscor like that, while maybe more efficient - Actually, the function pointer array is a brilliant idea for dispatch. I might not use all of your suggestions but that could improve my performance tenfold.
And I can see the thread struct model scaling nicely.
Also, a code integrity checker would be a welcome addition. I might implement it when I am satisfied it knows how to react well for nicely formed instructions. It is working pretty nicely but I'm battling a segfault right now. It's a sneaky bastard.
>>35
that's cool bra. There are advantages and disadvantages to any approach. One thing to keep in mind is the requirement for tail call optimization on the part of the compiler, which makes the code inherently non portable. One could compile tail recursive C to (sometimes unreadable) looping C in most cases, but doing a tail call to a function pointer might bend it beyond hope if the value of the function pointer cannot be predicted.
I think a loop with a giant switch statement inside is simple enough.
and checking for malformed instructions is cool and all, but if the byte code is known to be well formed, it will only slow things down.
Name:
Anonymous2012-03-08 5:27
Hey guise I implemented fibs
Yes
That's right
My VM just reached HASKELL QUALITY
In all seriousness, I like Haskell. I also like what I just achie- GPVM: Fatal: Stack Underflow
Name:
OP2012-03-09 19:52
It can now calculate the first 30 numbers in the fibonacci sequence in 48 seconds.
Yesterday, it would run for 1:3x then be killed due to excessive memory usage (It leaked, which is now fixed), and would usually make it to about the 28th number in the sequence.
Implementing the function pointer array, I expect to see a big increase in speed due to going from O(n) (switch) to O(1) (array)
>>41
Don't they have to compare the subject with every case? I would call that O(n), especially when deciding what an opcode is requires upwards of 60 comparisons (depending on the opcode).
Name:
Anonymous2012-03-09 21:57
>>42
you can make optimizations so the result of the comparison after treatment is the new program counter address
something like:
switch(a){
case 1:
case 2:
case 3:
where
res = a // simple example
label1:
addr_base + res
// code
// padding
label2:
addr_base + res << 1
// code
// padding
label3:
addr_base + res << 2
//code
also depending on the level of virtualization everything can be done with just masking and shifting
>>47
granted, implementing a switch statement necessarily trivial. But an easy and memory expensive way is to create an array of code pointers with enough slots to contain the range of case values. This is a bit psuedo codey, but:
switch(n) {
case 1:
printf("meep");
case 5:
printf("mop");
break;
case 13:
printf("mope");
break;
default:
printf("nope");
}
You could also just do binary search on a statically allocated array with keys and instruction offsets. I'm not sure which would be faster. Using a simple tight implementation of binary search might be more friendly on the instruction cache than this traversal of an inlined data structure.
You can also combine both approaches, where you can do binary search up until you get to a cluster of values, at which point, you can directly index into a prepared array. In this case, you would have a binary tree of arrays of instruction offsets. This can be good when the switch values cluster up in certain places, but have large gaps in between the clusters.
Another approach could be to use a statically allocated hash table. You could calculate a hashing function that perfectly hashes the used keys onto a small array. And then you only need to do a single comparison to see if the matched key matches the input. If it does not match, then the input cannot be any of the other keys, and you can go to the default case.
Name:
Anonymous2012-03-10 3:19
>>51
SBCL doesn't appear to be doing that. That is why it TWO times slower than C/C++. Lisp is shit.
although one could write a macro in lisp to translate the switch statements to a balanced if else chains. If you wanted to involve something akin to a statically allocated look up table, you'd probably need to have the macro define a global array and reference it in the generated code.
>>70 What is the point of this project? Experimenting with fibs. What will it do better than jre? Running fibs.
Name:
Anonymous2012-03-15 8:40
google
I stopped reading there.
Name:
Anonymous2012-03-16 23:35
>>70 What is the point of this project?
Try reading the docs What will it do better than jre?
Not be bloated, overly complex or spam stderr.
Is anyone up for helping testing? I currently only know this will compile on my computer. If anyone's willing to type a few lines into their terminal I'll be grateful
Also, What will it do better than jre?
Not target a single paradigm, therefore crippling any other paradigm despite how much a compiler writer would want to use it because of it's support, speed and maturity.
Name:
jerome2012-03-17 0:35
>>74
did you write this in couple all-nighters?
and now you are aiming for a quick bugfix?
``absolute lack of references'' no 3-operand instructions no exceptions unsafe push/call mechanism with no protection for the return address or way to determine the argument count only two data types (4-byte integer and float)
This VM is shit. Try posting it on esolangs.org, in the category ``Joke Languages''. ``Not target a single paradigm'' IHBT
Name:
Anonymous2012-03-17 1:43
>>77 ``absolute lack of references''
For now. no 3-operand instructions
I'm implementing one right now, which calls object file functions. unsafe push/call mechanism with no protection for the return address or way to determine the argument count
The return address is on a different stack from normal stack data. It's impossible to harm it. only two data types (4-byte integer and float)
Actually, it's typeless. THe only indication of how the VM should tread data is it's size and the instruction beign executed. (ADDF as opposed to ADD). This VM is shit. Try posting it on esolangs.org, in the category ``Joke Languages''.
I don't agree. Also, I'd rather not. Especially considering this isn't a language. And I do enjoy the esolags website. ``Not target a single paradigm''
That's the point.
Name:
Anonymous2012-03-17 3:06
So wait...
how do i actually use this with some language? like limbo?
Name:
Anonymous2012-03-17 22:19
bump
Name:
Anonymous2012-03-17 22:38
>>79
You'd need a compiler. Right now, the instruction set and VM itself arr going through puberty in a massive way. If you're interested I'd recommended helping with the development over using it right now. Many features don't exist yet and many are changing, so a compiler could easily and quickly become obsolete.
Name:
Anonymous2012-03-17 22:40
>>81
I'll write a scheme compiler for your virtual machine in scheme.
Name:
Anonymous2012-03-17 23:04
>>82
Great! I'll need to spend a while on making comprehensive docs
>>82 scheme compiler
It can't even do tail calls or longjmp.
Name:
Anonymous2012-03-17 23:25
It is now possible to call object file functions with the lof (Load object file), cof (Call objectfile function) and cofr (call object file function that returns).
Currently only possibly on x86 as it requeres some asm.
Name:
Anonymous2012-03-17 23:26
>>83
take your time and don't worry. I don't mind reading undocumented code.
>>40 It can now calculate the first 30 numbers in the fibonacci sequence in 48 seconds.
It's all an elaborate troll.
Name:
Anonymous2012-03-17 23:52
>>89
That kinda impressed my at first, considering how it would take about 2 minuites beforehand. Also, I was using the recursive method. Using the iterative algorithm is takes about 0.021s.
Name:
Anonymous2012-03-18 6:33
I included a tiny, Haskell written compiler for a typeless, functionless RPN language in the repo. it can be extended to be an interpreter by adding the line system $ "gpvm " ++ outFile to the end (before return () of course)
Name:
Anonymous2012-03-18 12:29
>>87
It's easier to study this because it has a much smaller scope. LLVM is certainly excellent for what it does but it's otherwise a massive beast of a codebase to learn from.
>>93
Because he's (I hope) a troll. No way could someone code that badly that it runs out of memory after 28 Fibonacci numbers unless they malloc(100000000) for each integer, even with ``memory leaks''. No way could someone take 48 seconds to calculate the first 30 numbers in the Fibonacci sequence unless they added sleep(1) for each level of recursion. These are 32-bit integers, not bignums. >>40 Yesterday, it would run for 1:3x then be killed due to excessive memory usage (It leaked, which is now fixed), and would usually make it to about the 28th number in the sequence.
For reference: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811
What machine are you running this interpreter on? Hopefully it's something like a Commodore 64, but even an interpreter written in C64 BASIC would be faster than this VM. Also, IHBT.
>>96
Your VM is a slow piece of shit. My grandma can calculate Fibs faster than this with pen and paper.
Name:
Anonymous2012-03-25 2:09
>>97
To be honest that's not fair, your grandmother has a very advanced instruction set and implicit memoization so she doesn't recalculate the numbers.