File: locals.fth

package info (click to toggle)
pforth 21-11
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 820 kB
  • ctags: 873
  • sloc: ansic: 5,050; makefile: 102
file content (69 lines) | stat: -rw-r--r-- 1,668 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
\ @(#) $M$ 98/01/26 1.2
\ standard { v0 v1 ... vn | l0 l1 .. lm -- } syntax
\ based on ANSI basis words (LOCAL) and TO
\
\ Author: Phil Burk
\ Copyright 1994 3DO, Phil Burk, Larry Polansky, Devid Rosenboom
\
\ The pForth software code is dedicated to the public domain,
\ and any third party may reproduce, distribute and modify
\ the pForth software code or any derivative works thereof
\ without any compensation or license.  The pForth software
\ code is provided on an "as is" basis without any warranty
\ of any kind, including, without limitation, the implied
\ warranties of merchantability and fitness for a particular
\ purpose and their equivalents under the laws of any jurisdiction.

anew task-locals.fth

private{
variable loc-temp-mode    \ if true, declaring temporary variables
variable loc-comment-mode \ if true, in comment section
variable loc-done
}private

: { ( <local-declaration}> -- )
	loc-done off
	loc-temp-mode off
	loc-comment-mode off
	BEGIN
		bl word count
		over c@
		CASE
\ handle special characters
		ascii }  OF  loc-done on          2drop  ENDOF
		ascii |  OF  loc-temp-mode on     2drop  ENDOF
		ascii -  OF  loc-comment-mode on  2drop  ENDOF
		ascii )  OF  ." { ... ) imbalance!" cr abort  ENDOF
		
\ process name
		>r  ( save char )
		( addr len )
		loc-comment-mode @
		IF
			2drop
		ELSE
\ if in temporary mode, assign local var = 0
			loc-temp-mode @
			IF compile false
			THEN
\ otherwise take value from stack
			(local)
		THEN
		r>
		ENDCASE
		loc-done @
	UNTIL
	0 0 (local)
; immediate

privatize

\ tests
: tlv1  { n -- }  n  dup n *  dup n *  ;

: tlv2 { v1 v2 | l1 l2 -- }
	v1 . v2 . cr
	v1 v2 + -> l1
	l1 . l2 . cr
;