testing the a function call

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

testing the a function call

The_Larks
Is there a script/.vm file (that I don't have to write) that will test just the 'call' implementation. I'd rather not jump into that + bootstrapping without knowing that 'call' was implemented correctly.
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

cadet1620
Administrator
There is not a Call Only test.

I'm working at the moment, but should be able to write one sometime this evening.

Off the top oh my head it would be something like
push constant 123
push constant 456
call CallOnly.fn 2
function CallOnly.fn 0
add
label loop
goto loop
--Mark
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

The_Larks
Thanks for the prompt response(s). Ok, well if you're working on one, i'll wait for that :). I'm working on implementing bootstrap and reading from multiple folders.
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

The_Larks
In reply to this post by cadet1620
Ok, I tried that out just copying and pasting. It keeps adding 1 to 123 (at least mine does). At the end, because this function calls no arguments, I try to decrement stack pointer to -1, so it throws an error.

Sound about right?

I haven't considered the case of zero arguments, but once/if you have a fully functioning example (if this isn't already one), i'll tend to that.
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

The_Larks
PS, if I can run it with the VMEmulator, even better!
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

cadet1620
Administrator
I said it was off the top of my head... The "add" is totally bogus since there are no local variables on the stack.

Here is Call test — a naked call to a function with no body.
Call.tstCPUEmulator test script
CallVME.tstVMEmulator test script
Call.cmpcompare file for both scripts
Call.vm
The test setup initializes the system pointers as follows
SP   = 256
LCL  = 300
ARG  = 400
THIS = 3000
THAT = 4000
After the call LCL and ARG should be updated and SP should be 263.
The stack should have 2 pushed arguments and a stack frame.  Note the the Return Address on the stack is dependent upon your ASM implementation.

Let me know how well this works for you and I'll post it in announcements.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

The_Larks
Re: add. Yes, I noticed.

Ok, very much appreciated. I'm going to test this right now.

Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

The_Larks
Also, I saw a thread on here somewhere, where you were going to post bootstrap-no-call code and post on the forum. I responded today asking if that was available.
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

The_Larks
In reply to this post by cadet1620
Ok, looks good! It showed the mistakes I made in implementing 'Call'. I was able to fix them and pass the provided test. It truly would've been a pain trying to make those edits while implementing bootstrap (because I'm not sure how easy/hard bootstrap will be until i've completed it, at which point it's too late!).

I think this is the logical way to test things. Now I can confidently move to the next step.

Thanks again !
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

cadet1620
Administrator
In reply to this post by The_Larks
Found the post. That was back in 2011...

IIRC the poster never replied and I don't recall anyone else asking. I did find the test files in an old directory on my system, but they don't pass with my current VM translator, so I'm guessing that the test was never completed...

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

The_Larks
In reply to this post by The_Larks
Though the halt I think was unnecessary, at least for me. I already have an infinite loop at the end of all my programs, so it basically finishes and renders the last 2 lines of my code (my inf loop) unreachable. No matter, though.
Reply | Threaded
Open this post in threaded view
|

Re: testing the a function call

cadet1620
Administrator
In normal usage, VM code is written by the Jack compiler so all files will always end with a return.

I assume that is why the VM Translator does not spec a halt loop at the end of translation. My philosophy is that test code needs to be belt-and-suspenders, though. That's why there's also a halt loop after the call to Call.fn, which will never return.

--Mark