@@ -171,6 +171,8 @@ func (u *Ulp) buildAssemblyHelper(vm *VirtualMachine, header string) (string, er
171171 if err != nil {
172172 return "" , err
173173 }
174+ // count the number of calls
175+ u .countCalls ()
174176 // create the different assemblies
175177 asm , err := u .buildAssemblyWords ()
176178 if err != nil {
@@ -327,6 +329,32 @@ func (u *Ulp) replaceOtherChars(str string) string {
327329 return sb .String ()
328330}
329331
332+ // Count the number of times that each word is called,
333+ // not including tail calls.
334+ func (u * Ulp ) countCalls () {
335+ u .resetCalls ()
336+ for _ , w := range u .forthWords {
337+ for _ , c := range w .Cells {
338+ switch cell := c .(type ) {
339+ case CellAddress :
340+ cell .Entry .Flag .calls += 1
341+ }
342+ }
343+ }
344+ }
345+
346+ // Reset the number of times that each word is called.
347+ func (u * Ulp ) resetCalls () {
348+ for _ , w := range u .forthWords {
349+ for _ , c := range w .Cells {
350+ switch cell := c .(type ) {
351+ case CellAddress :
352+ cell .Entry .Flag .calls = 0
353+ }
354+ }
355+ }
356+ }
357+
330358func (u * Ulp ) buildInterpreter () string {
331359 i := []string {
332360 // required data, will be placed at the start of .data
@@ -342,8 +370,8 @@ func (u *Ulp) buildInterpreter() string {
342370 "HOST_FUNC: .int 0" ,
343371 "HOST_PARAM0: .int 0" ,
344372 ".data" ,
345- "__ip: .int __forth_VM .INIT" , // instruction pointer starts at word VM.INIT
346- "__rsp: .int __stack_start" , // return stack pointer starts at the beginning of the stack section
373+ "__ip: .int __body__forth_VM .INIT" , // instruction pointer starts at word VM.INIT
374+ "__rsp: .int __stack_start" , // return stack pointer starts at the beginning of the stack section
347375
348376 // boot labels
349377 ".boot" ,
0 commit comments