Post Reply 
HP50g: local LBL and GOTO in user or sysRPL
09-09-2016, 10:35 AM
Post: #11
RE: HP50g: local LBL and GOTO in user or sysRPL
I guess I should showcase my version in a program as well...

The major differences to the other solutions are:
- I'm using the on-board compiler
- the offset is not embedded inside the code object but placed behind it, so the code object can be re-used.

Here I'm using one of my favorite tricks, storing a subroutine (the goto code) in a local variable:
Code:
::
  ' CODE
    C=DAT0.A
    AD0EX
    A+C.A
    AD0EX
    GOVLNG Loop
  ENDCODE
  ' LAM goto BINT1 DOBIND (store goto code in LAM goto)

  %0
  LAM goto !ASM G5 label1 !RPL
  %10 %+ (skip this)
  LABEL label1
  %5 %+
  LAM goto !ASM G5 label2 !RPL
  %1+ (skip this too)
  LABEL label2
  %.5 %+
  ABND (get rid of the local variable with the goto code)
;
This program will output 5.5, the lines adding 10 and 1 will be skipped.
I used a named LAM here to improve readability; unnamed LAMs would be faster and smaller, but unfortunately NULLLAM and 2GETEVAL are the only commands fetching and evaluating an unnamed LAM in one go, others need a separate EVAL.

But I'll have to ask: what usecases for goto does SysRPL have? In C I sometimes use goto, but only for errors (either jumping to an error handling section at the end of a function, or jumping to the start from inside nested code blocks when an error prompts a retry). With RPL's error handling functions (ERRSET...ERRTRAP and ERRJMP) these usecases vanish. The former should be obvious, the latter can be handled by letting the error cascade up the return stack to the "code block" (i.e. secondary) that should be repeated, and constructing a BEGIN...UNTIL loop there.
So what do you need this for? (Or are you just curious how it could be implemented?)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP50g: local LBL and GOTO in user or sysRPL - 3298 - 09-09-2016 10:35 AM



User(s) browsing this thread: 1 Guest(s)