Next: , Previous: , Up: Top   [Contents][Index]

8 Internal functioning of m0

8.1 Introduction

In most cases the exact internal execution of the m0 program is not relevant. However, in case of complicated macro systems or emulations it is necessary to know how the detection and execution of the several stages are internally performed.

The source code is the ultimate guide, but in this part an overview is given for a quick understanding.


Next: , Up: Internal functioning of m0   [Contents][Index]

8.2 The execution loop

The main execution loop that is performed is the loop of the bitap and possible macro execution at every input character. The bitap algorithm works per byte. There are thus no word boundaries that determine the execution loop.

The steps of the main execution loop consist of:

It can be seen that at a position multiple macros for execution can be detected. Therefore in Priority the execution priority of macros is explained. It can also be seen that a macro for execution can be detected while at the same time also programs of the pattern are executed. The priority setting in the pattern part determines if a program is then executed or not.


Next: , Previous: , Up: Internal functioning of m0   [Contents][Index]

8.3 The execution of a macro

A macro will normally change the output by removal and insertion. What is removed and what is inserted is completely determined by the macro in its definition and settings.

In The complete working of macros already an overview of this proces is given. In this part only the steps involved when a macro is executed are explained. When a macro is executed the steps are:

This overview might seem a bit confusing because of its recursive nature of calling macros, but it will just execute:

The function calls are explained in Builtin functions and the programming and instructions are explained in Programs for patterns and macros.


Previous: , Up: Internal functioning of m0   [Contents][Index]

8.4 The recursion

The possible depth of recursion is already explained in Recursion.

This recursion is enabled by maintaining the state of the bitap algorithm at each input byte. A new input will generate a new state at this position using the current input and the state of the previous position. This creates a history of states that is actually linked to the output because every input is copied to the output. With no replacements of macros this makes no difference.

When a macro replacement happens, the position in the history is returned to the place where the macro started minus the pre size of the macro. The state of the bitap of this position is used to generate the state for the next input. This enables the depth of recursion of m0.

A virtual character (set by the settings in a macro) breaks the link of the history to the output by processing the virtual character and inserting it into the history without placing it into the output.


Previous: , Up: Internal functioning of m0   [Contents][Index]