HP Forums
RPL 32 - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: RPL 32 (/thread-255439.html)



RPL 32 - David Hayden - 11-10-2013

What's cool about this System RPL program that solves the quadratic equation? It's a slighly modified version of the program on page 53 of An Introduction to HP 48 System RPL and Assembly Language Programming by Jim Donnelley (page 63 of the PDF version on hpcalc.org). The change is that it includes the inputs (%1 % -4 %3) and a non-standard "showStack" word at the end:

DEFINE a 6GETLAM
DEFINE b 5GETLAM
DEFINE c 4GETLAM
DEFINE root1 3GETLAM
DEFINE root1STO 3PUTLAM
DEFINE root2 2GETLAM
DEFINE root2STO 2PUTLAM
DEFINE Subr 1GETLAM

%1 % -4 %3

::
0LASTOWDOB! CK3NOLASTWD
CK&DISPATCH0 3REAL
::
%0 %0
' :: a %2 %* %/ ;
{
NULLLAM
NULLLAM
NULLLAM
NULLLAM
NULLLAM
NULLLAM
}
BIND
b DUP %* a c %* %4 %* %-
DUP %0< casedrop
:: "Complex Roots" ABND ;
%SQRT
b %CHS OVER %+ Subr EVAL
root1STO
b %CHS SWAP %- Subr EVAL
root2STO
root1
root2
ABND
;
;
showStack
HALT

The answer is that it runs on my 32-bit RPL system written in C++.

So far the system supports BINTs, secondaries, LISTS, REALs, STRINGs, loop environments, temporary environments and local variables (LAMs). It does error jumps, and argument validation. The garbage collector can run incrementally.

I've taken a few shortcuts of course, but only a few. REALs are currently binary instead of BCD. This let me get them working quickly and it can be fixed later without affecting the rest of the system.

I'm still trying to figure out a way to deal with low memory conditions. Real RPL does garbage collection as soon as it needs to, which means that objects can move around almost any time. The garbage collector fixes RPL pointers but it can't fix C++ pointers that may exist. Dealing with this in C++ would be very error prone.

I should be writing Prime programs but this is just way too much fun :)

Dave


Re: RPL 32 - Tim Wessman - 11-10-2013

Cool!

>but it can't fix C++ pointers that may exist.

Good luck... :-| (this is where it all falls apart)

TW

Edited: 10 Nov 2013, 12:11 p.m.


Re: RPL 32 - David Hayden - 11-10-2013

Quote:
Good luck... :-| (this is where it all falls apart)

:) The voice of experience no doubt.

I have a couple of ideas that might work. I'll let you know how it goes.

Dave


Re: RPL 32 - Marcus von Cube, Germany - 11-10-2013

16 Bit Windows uses handles instead of pointers. All APIs use these handles which allows for moving around the associated memory objects.

If you store a reference count in such a handle, removing unreferenced objects becomes a little easier. Objects containing handles to other objects need a recursive approach for the garbage collector. This is what Java seems to have implemented.


Re: RPL 32 - David Hayden - 11-11-2013

Thanks for the tip Marcus. I'd forgotten about that approach.

Dave