retro pascal
Table of Contents
1 DRAFT retro pascal
A small pascal implementation that works with retro and runs on the ngaro virtual machine.
1.1 the pascal stack
- the pascal stack starts at end of ram and grows backward
- special variable
BASE
works likeHERE
but but gets smaller STACK
<HERE
indicates a potential stack or heap overflow- if the halting problem is unanswerable for the pascal code and it can grow dynamically, then the stack manager needs to check for overflows on each call.
- else we can precompute up front and not worry about it ( In theory, anyway. it would require some analysis to actually do it of course. )
- if using retro routines inside pascal, then retro needs to check for heap overflows too.
1.2 pascal "registers"
1.2.1 the ngaro vm doesn't offer any special registers, so 'registers' would just be fixed locations in ram.
1.2.2 special purpose registers
-
STACK
- holds the depth of the stack
- (no term)
- maybe also:
-
BASE
- stores old value of
STACK
during procedure -
RESV
- holds the result variable?
-
SELF
- hold a reference to
self
in object methods
-
1.2.3 general purpose registers for variables? : maybe
- argument for using registers:
- Using ram to store variables probably makes sense, compared to doing a bunch of shuffling on retro's data stack.
- Using a fixed location in ram (a register) would prevent the need for a lot of pointer arithmetic when looking things up in the pascal stack.
- argument against:
- Register values would need to be pushed and popped to call subroutines anyway, though a smart compiler could probably minimize this.
1.3 calling conventions
- return stack is used as normal
- first argument goes in TOS, second argument goes in NOS ( TOS and NOS refer to the normal retro data stack )
- further arguments are moved to the pascal stack
- local variables use the pascal stack
- arguments are consumed and result ( if any ) will be on TOS
- this means the effect on the retro data stack is always
( arg\ast - )
or( arg\ast - result )
- this means the effect on the retro data stack is always
1.4 integration with retroforth ( for interactive code )
1.4.1 calling pascal code from retro
- in retro's dict, when calling procedures, maybe have
NAME
to pull args directly from stack andNAME(
to precompile arguments separated by commas and ending with)
. - use word
PASCAL
to parse and execute a single pascal statementPASCAL INC(x);
PASCAL BEGIN
…END;
- use
PASCAL MODULE
…END
to define a module (chain
and{{
…}}
in retro ) - use
PASCAL PROGRAM
…END
to define a module and also a single word to trigger execution of the module'sBEGIN
…END
block.
1.4.2 calling retro from pascal
- call any retro word as a procedure or function with pascal syntax, provided it's a valid pascal identifier.
- probably would not be type checked?
- allow arbitrary retro code (using retro syntax) via
RETRO
…END;
statement ( any retro code would be valid, except of course a word calledEND
)