" ". Postscript, , , Forth ( , ).
repeat. , loop , exit , .
:
int proc **repeat** -
, repeat, ( , ), ( ).
( , Forth "" ), "" , , , . , .
, . :
operand: -empty-
execute: <stdin>
2 {(Hello World!\n) print} repeat.
2 .
operand: 2
execute: <stdin>
(*) .
operand: 2 {(Hello World!\n) print}
execute: <stdin>
repeat.
operand: 2 {(Hello World!\n) print}
execute: <stdin> repeat
Repeat: expects operands: int proc
if int<0 Error
if int==0 return //do nothing
push `repeat` itself on exec stack
push quoted proc on exec stack
push int-1 on exec stack
push "executable" proc on exec stack
( ) :
operand: -empty-
execute: <stdin> repeat {(Hello World!\n) print} 1 **{(Hello World!\n) print}**
exec, "Hello World!", , op.
operand: 1
execute: <stdin> repeat {(Hello World!\n) print}
, op.
operand: 1 {(Hello World!\n) print}
execute: <stdin> repeat
! ( , ).
, .
Edit
, , , , -, . , . , , !
, ( ( )). - :
struct object {
int type;
union {
int i;
void (*command)(context *);
} u;
};
struct dict {
int sz;
struct rec {
char *key;
object val;
} data[];
};
. : . , . .
. . , .
- Turing Complete. , , ( ): , !
*. , Postscript , . Lisp. Postscript literal/executable, cvx cvlit xcheck. . , "" - - (.. ). - repeat cvx . , postcript repeat :
Repeat: expects operands: int proc
if int<0 Error
if int==0 return //do nothing
push `repeat` itself on exec stack
push 'cvx' on the exec stack
push cvlit(proc) on exec stack
push int-1 on exec stack
push "executable" proc on exec stack
, .
, , , : repeat , . , ghostscript - @repeat-continue @. , . exec; .
, repeat :
int proc **repeat** -
if int<0 Error
if int==0 return //do nothing
push null on exec stack <--- this marks our "frame"
push int-1 on exec stack
push proc on exec stack
push '@repeat-continue' on exec stack
push executable proc on exec stack
.
@repeat-continue
peek proc from exec stack
peek int from exec stack
if int==0 clear-to-null and return
push '@repeat-continue' on exec stack
push executable proc on exec stack
, exit , exec "" . 2- null . 1- .