Page 1 of 3
SuperHack
Posted: Mon Dec 29, 2008 6:07 pm
by MerickOWA
Just trying to understand the instructions.
The '@' instruction i have a little trouble understanding. In the following example.
I'm assume that the direction and PC stored by the first '@' is "right" and (0,1).. meaning the position stored is the position after the PC has been advanced.
After the '$' returns, we end up at (0,2) however? Its as if the PC gets advanced an extra time upon returning?
Theres no more drop top of the stack instruction?? Seems kinda cumbersome to try and get something off the stack now.
Re: SuperHack
Posted: Mon Dec 29, 2008 7:03 pm
by adum
MerickOWA wrote:Just trying to understand the instructions.
The '@' instruction i have a little trouble understanding. In the following example.
I'm assume that the direction and PC stored by the first '@' is "right" and (0,1).. meaning the position stored is the position after the PC has been advanced.
After the '$' returns, we end up at (0,2) however? Its as if the PC gets advanced an extra time upon returning?
Theres no more drop top of the stack instruction?? Seems kinda cumbersome to try and get something off the stack now.
you can use '[' to get something off the stack (because stack and memory are the same thing.)
your @ example is right. the reason you advance a step on the $ is to avoid infinite loops.
Posted: Mon Dec 29, 2008 8:43 pm
by m!nus
HackVM was fun, this isn't. Seriously, no.
edit: i take that back
Posted: Mon Dec 29, 2008 8:54 pm
by therethinker
I'm excited for this
I already raved in the "String Reversal" Solved thread, but I'm becoming confused...
Here's how I'm interpreting it. Please correct me.
HVM had 3, 1D stacks: "the stack", memory, and the call stack (for use w/ c/$).
Now, there is a single 2D stack that is used for both "the stack" and memory.
Memory acts like a 2D stack, whereas "the stack" is only seen one dimension at a time, the 2nd dimension, the X coord., corresponds to the thread.
The call stack remains about the same.
Where is the top of "the stack" in memory? Is it at (0,0), or is it at the high end?
And what does the memory pointer do? How does [ take something off the stack?
And is there a way to drop the top value on the stack in a single instruction? I can only do it in 2...
Posted: Mon Dec 29, 2008 8:58 pm
by lechat
adum,
can you please make the implementation of the SuperHack VM available? I'm not always connected to the internet...
thx
Posted: Mon Dec 29, 2008 9:16 pm
by therethinker
Download
http://hacker.org/sh/index.html to your hard drive, and then you can open it up with a web browser and it will still work.
Posted: Mon Dec 29, 2008 11:13 pm
by adum
therethinker -- you're pretty much on target.
yeah, a drop takes two instructions, but it's more flexible this way.
instead of trying to explain everything here, it's probably easiest just to read the javascript source for the VM. it will explain better than i can. i know it's a bit confusing -- it still confuses me =)
Posted: Tue Dec 30, 2008 2:23 am
by MerickOWA
I see, user input is separate from memory where as in HVM user input was always in the first X locations of memory.
Posted: Tue Dec 30, 2008 5:30 am
by snibril
Two things: with the g/w instruktions, you can modify your program at runtime?
Second, thee is no "drop" instruktion like "d" in HVM?
Posted: Tue Dec 30, 2008 5:53 am
by adum
you can use '[' to drop.
yes, you can modify code at runtime.
Posted: Tue Dec 30, 2008 2:28 pm
by m!nus
how about changing & so that it doesnt throw an exception when 32 threads are reached.
if it just would continue (advance current thread 1 step and jsut create no new one) this would be a nice way to create lots of worker threads
Posted: Tue Dec 30, 2008 8:06 pm
by MerickOWA
I think theres a bug in how threads/memory pointers work.
In both examples
UserInput:
Code:
Javascript implementation prints 'ab'
Php implementation prints 'bb'???
Theoretically, if I understand how this works. I created a new thread who then immedately shifts its memory/stack pointer down (giving it its own stack).
The 2 threads run the same code in parallel then which is effectively ",,PP" which should print 'ab'.
However it appears as tho the '}' instruction is affect thread 0 & 1??
That's my best guess anyway.
Posted: Tue Dec 30, 2008 8:10 pm
by therethinker
I think it makes sense... possibly the javascript version has thread 2 run before thread 1, whereas PHP does it the other way around?
Posted: Tue Dec 30, 2008 8:14 pm
by MerickOWA
If it simply executed the threads in a different order, then it should print 'ba' not 'bb'.
My guess is that the '}' instruction affects both threads, or possibly thread 0 is executing this instruction too?
If the code is
Then both implementations give 'bb'. The two threads are overwriting each other's stack in memory, so thread 1's read of userinput overwrites thread '0' result. Since poping off the stack just adjusts the memory pointer they both pop off the same/only value.
Posted: Tue Dec 30, 2008 8:29 pm
by adum
sorry, there was a bug in the PHP. should be fixed now. thanks!