9 ;----- Standard Header ------------------------------------------------------
16 ;----- External dependencies ------------------------------------------------
23 ;----- Other definitions ----------------------------------------------------
25 var__chunkSize EQU 256 ;Chunck size of var stack
27 ;----- Main code ------------------------------------------------------------
29 AREA |TermScript$$Code|,CODE,READONLY
33 ; On entry: R0 == type of variable
34 ; R1 == pointer to variable name
35 ; R12 == pointer to the anchor block
36 ; Other registers depend on the type
37 ; vType_label, vType_proc, vType_fn:
38 ; R2 == file offset of label of DEF
39 ; R3 == line number of label or DEF
40 ; vType_dimInt, vType_dimStr:
41 ; R2 == pointer to subscript block (in *reverse* order)
42 ; R3 == number of subscripts
43 ; R4 == number of items to create
45 ; On exit: R0 == pointer to the variable
47 ; Use: Tries to find the variable given, and return a pointer
48 ; to it if it is found. Otherwise it will try to create the
49 ; variable and return a pointer to the new one.
54 ADD PC,PC,R0,LSL #2 ;Branch to correct dispatcher
55 DCB "TMA!" ;A little padding
69 ; On entry: R0 == type of the variable
70 ; R1 == name of the variable
72 ; On exit: CS if the variable was found, and
73 ; R0 == pointer to the variable block
77 ; Use: Tries to find the given variable in the current tree.
82 STMFD R13!,{R2,R14} ;Save some registers
83 MOV R2,R0 ;Look after the type
84 BL tree_find ;Find the variable
85 LDMCSFD R13!,{R2,PC}^ ;If found, return now
86 CMP R2,#vType_dimInt ;Is it an integer array?
87 CMPNE R2,#vType_dimStr ;Or a string array?
88 MOVEQ R0,#err_ukArray ;Yes -- find `unknown array'
89 MOVNE R0,#err_unknown ;No -- use `unknown var'
90 B error_report ;And report it to the world
94 ;----- Variable creation routines -------------------------------------------
96 ; On entry: R0 == variable type
97 ; R1 == address of variable name
103 STMFD R13!,{R1-R4,R14} ;Stack registers
105 ; --- Allocate space for the variable ---
107 MOV R2,#8 ;Variable requires 16 bytes
108 BL tree_add ;Add it to the symbol table
109 BVS var__error ;Return possible error
111 MOV R14,#0 ;Initialise the value
112 STRCC R14,[R0,#4] ;Set this up nicely
113 LDMFD R13!,{R1-R4,PC}^ ;And return to caller
119 STMFD R13!,{R1-R6,R14} ;Stack registers
120 ADD R5,R2,R3,LSL #2 ;Look after subscript block
121 MOV R2,#12 ;Room for name + num of subs
122 ADD R2,R2,R3,LSL #2 ;Add room for sizes
123 ADD R2,R2,R4,LSL #2 ;And subscripts themselves
124 BL tree_add ;Try to allocate space
125 BVS var__error ;Barf on error
126 STR R3,[R0,#4] ;Store number of subscripts
127 STR R4,[R0,#8] ;Store total number of items
128 ADD R6,R0,#12 ;Point to the first size
130 ; --- Set up the subscript sizes ---
132 00 LDR R14,[R5,#-4]! ;Load the subscript size
133 STR R14,[R6],#4 ;Store that in the block
134 SUBS R3,R3,#1 ;Reduce subscript count
135 BGT %b00 ;Keep filling in block
137 ; --- Initialise all the entries ---
139 MOV R14,#0 ;Initialiser
140 00 STR R14,[R6],#4 ;Set entry to 0
141 SUBS R4,R4,#1 ;Reduce the item count
142 BGT %b00 ;Keep on initialising
144 LDMFD R13!,{R1-R6,PC}^ ;Return to caller
152 STMFD R13!,{R1-R4,R14} ;Stack registers
153 LDR R14,tsc_tokAnchor ;Find anchor of t'ised file
154 LDR R14,[R14] ;I hate WimpExt_Heap
155 SUB R4,R2,R14 ;Make the address an offset
157 ; --- Allocate space for the variable ---
159 MOV R2,#12 ;Variable requires 16 bytes
160 BL tree_add ;Add it to the symbol table
161 BVS var__error ;Return possible error
163 ; --- Fill in the block ---
165 MOV R2,R4 ;Get the file offset
166 STMIB R0,{R2,R3} ;Store the informtion
167 LDMFD R13!,{R1-R4,PC}^ ;Unstack registers
169 var__error MOV R0,#err_noMem ;Get the error number
170 B error_report ;And report the error
174 ;----- Workspace ------------------------------------------------------------
176 ; --- Variable types ---
179 vType_integer # 1 ;Integer
180 vType_string # 1 ;String
181 vType_dimInt # 1 ;DIM of integers
182 vType_dimStr # 1 ;DIM of strings
183 vType_label # 1 ;Label
184 vType_proc # 1 ;Procedure name
185 vType_fn # 1 ;Function name
187 ;----- That's all, folks ----------------------------------------------------