Hash :
1a08f436
Author :
Date :
2010-08-25T09:23:17
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
\ objects.fth 2.16 01/05/18
\ Copyright 1985-1990 Bradley Forthware
\ Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved
\ Action definition for multiple-code-field words.
\ Data structures:
\ nth-action-does-clause acfs unnest
\ n-1th-action-does-clause acfs unnest
\ ...
\ 1th-action-does-clause acfs unnest
\ nth-adr
\ n-1th-adr
\ ...
\ 1th-adr
\ n
\ 0th-action-does-clause acfs unnest
\ object-header build-acfs
\ (') 0th-adr uses
needs doaction objsup.fth \ Machine-dependent support routines
decimal
headerless
0 value action#
0 value #actions
0 value action-adr
headers
: actions ( #actions -- )
is #actions
#actions 1- /token * na1+ allot ( #actions ) \ Make the jump table
\ The default action is a code field, which must be aligned
align acf-align here is action-adr
0 is action#
#actions action-adr /n - !
;
headerless
\ Sets the address entry in the action table
: set-action ( -- )
action# #actions > abort" Too many actions defined"
lastacf action-adr action# /token * - /n - token!
;
headers
: action: ( -- )
action# if \ Not the default action
doaction set-action
else \ The default action, like does>
place-does
then
action# 1+ is action#
!csp
]
;
: action-code ( -- )
action# if \ Not the default action
acf-align start-code set-action
else \ The default action, like ;code
start-;code
then
\ For the default action, the apf of the child word is found in
\ the same way as with ;code words.
action# 1+ is action#
do-entercode
;
: use-actions ( -- )
state @ if
compile (') action-adr token, compile used
else
action-adr used
then
; immediate
headerless
: .object-error
( object-acf action-adr false | acf action# #actions true -- ... )
( ... -- object-acf action-adr )
if
." Unimplemented action # " swap .d ." on object " swap .name
." , whose maximum action # is " 1- .d cr
abort
then
;
headers
\ Executes the numbered action of the indicated object
\ It might be worthwhile to implement perform-action entirely in code.
: perform-action ( object-acf action# -- )
dup if
>action-adr .object-error ( object-apf action-adr )
execute
else
drop execute
then
;
1 action-name to
2 action-name addr
\ Add these words to the decompiler case tables so that the
\ debugger will display their arguments and so that the decompiler
\ will not show the action name and its argument on separate lines
\ if it happens to be near the end of a line.
: .action ( ip -- ip' ) dup token@ .name ta1+ dup token@ .name ta1+ ;
also hidden also
' to ' .action ' skip-(') install-decomp
' addr ' .action ' skip-(') install-decomp
previous previous
: ?has-action ( object-acf action-acf -- object-acf action-acf )
2dup >body >action# >action-adr .object-error 2drop
;
: action-compiler: \ name ( -- )
parse-word 2dup $find $?missing drop \ adr len xt
warning @ >r warning off
-rot $create token, immediate
r> warning !
does> ( apf )
' swap token@ ( object-acf action-acf )
?has-action ( object-acf action-acf )
+level ( apf ) \ Enter temporary compile state if necessary
compile, \ Compile run-time action-name word
compile, \ Compile object acf
-level \ Exit temporary compile state, perhaps run word
;
\ action-compiler: to
action-compiler: addr
\ Makes "is" and "to" synonymous. "is" first checks to see if the
\ object is of one of the kernel object types (which don't have multiple
\ code fields), and if so, compiles or executes the "(is) <token>" form.
\ If the object is not of one of the kernel object types, "is" calls
\ "to-hook" to handle the object as a multiple-code field type object.
: (to) ( [data] acf -- ) +level compile to compile, -level ;
' (to) is to-hook
warning @ warning off
alias to is
warning !
\ 3 actions
\ action: @ ;
\ action: ! ; ( is )
\ action: ; ( addr )
\ : value \ name ( initial-value -- )
\ create ,
\ use-actions
\ ;
3 actions
action: >user 2@ ;
action: >user 2! ;
action: >user ;
: 2value ( n1 n2 "name" -- ) create 2 /n* user#, 2! use-actions ;