MiniM. Saving time.

| About | Download | Tools | Knowledge Base | How to Buy |

MiniM Overview

Getting Started




Cache Tools

GT.M Tools

Knowledge Base




MiniM Knowledge Base | Jun 11, 2010

How to Create Routine Programmatically

In some tasks the programmer may need to create a routine programmatically. Here described, as this can be done in MiniM Database Server

In MiniM Database Server source code routines stored in the global ^ROUTINE. The source text can not be executed. In order for the routine could be executed, it must be compiled. The compilation result is a routine's bytecode, it is stored in the global ^rOBJ.

For globals ^ROUTINE and ^rOBJ in MiniM Database Server at the core level applied the mapping rule: if the routine name begins with the symbol "%", then this routine and its bytecode are stored in the "%SYS" database. Otherwise they are stored in the current database.

Routine source text is stored line-by-line, sequentially with subscripts. First ^ROUTINE index is routine's name. Let it be for example routine ROUNAME with text:

 w 123,!
This routine should be stored in the ^ROUTINE global with first subscript "ROUNAME". Record with one this index describes number of routine lines and total symbols count. One routine symbol is one byte, MiniM Database Server does not support multibyte or UNICODE encodings. Number of lines and number of bytes are delimited by comma. In current example we have 3 lines and 22 bytes and first record is:
First subscript after routine's name is line number and lines counted from 1. Index 0 has special meanung - one describes date and time of last routines modification or creation. Date and time are stored in the $HOROLOG special format. For example, if modification date and time is "61859,40044", we need to create record
Next we need to create line's sequence with routine's text. Lines does not include line feed and carriage return symbols. In current example we need to create records:
^ROUTINE("ROUNAME",2)=" w 123,!"
If the source routine's text can not be an empty strings, ones should be replaced in the ^ROUTINE global to string with whitespace sequence, for example, one whitespace or tab stop character.

MiniM Database Server properly handles the situation it routine's line contains a tab character. If this is in the text line, the bytecode generated string with tab, or in other case tabs is considered by the translator as a whitespace symbols.

Once the routine's source text is stored in the database, it must be compiled, and then it can be executed. To compile routine need to be used the function $view("rou","c",rouname). If it returns 0, then compilation was successful, otherwise function returns number of errors found.

Compile function automatically reads the source text of routine from the ^ROUTINE global and writes the resulting bytecode to the ^rOBJ global. In the compilation process function displays diagnostic messages about syntax errors to the current I/O device.

Eugene Karataev

Copyright (C) 2017 Eugene Karataev
Emails: Info Tech Support