Macros

Registered by Federico Razzoli

STK/C will parse and replace Macros like C precompiler.
These are the commands that must be supported.

## DBUG (at the end of a line)
execute this line only if --dbug flag is set

## DEFINE … (like in C)

Defines a Macro, with parameters. This is essential. However, optional parameters and varargs can be done in the future.
We may decide that Macros names start with '%'.

## IFDEF, IFNDEF, IF, ELIF, ENDIF

Like in C. Does Python have a eval() function? It could be used to resolve the IF conditions. Not so clean, but we need a fast solution.

## ERROR message

Stops parsing and outputs message

## INCLUDE includes a file, without parsing
## IMPORT parses a file and include the result

USEAGE EXAMPLE
==============

We want to use the same assert_* Procedures both in STK/Unit and STK/DBUG. So, those procedures will be defined in assert.h file, which will be included in both the projects.

Here's how Unit will include it:

##DEFINE %proj_db 'stk_unit'
##IMPORT 'assert.h'

(well, Unit will include DBUG, so I've simplified the code a bit...)

Here's how procedures will be defined in assert.h. Assert_* s contain an IF and call a assert() procedure, which is in stk_unit database. The only difference for stk_dbug is that the assert() procedure is defined in stk_dbug database (and does different things, of course!). To call assert() from the proper db, we use the %proj_db Macro, defined above.

CREATE PROCEDURE assert_true(cond BOOL, msg TEXT)
BEGIN
    IF cond THEN
        %proj_db.assert(TRUE, msg);
    END IF;
END;

(this code is not correct, but should be more clear than the correct version)

SYSTEM MACROS
==============

When a connection is estabilished, STKC executes:
SELECT VERSION();
and parses the output string.
That string is used to define 2 system Macros:
* DBMS - possible values: 'mysql', 'mariadb', 'percona'
* VERSION - ie '5.5.1'

We'll use them to write code that is specific for a fork/version:
## IF DBMS = 'mariadb' AND VERSION >= 5.5 THEN
do_something that mdb5.3 and mysql can't do
## ENDIF

Blueprint information

Status:
Not started
Approver:
Federico Razzoli
Priority:
Essential
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
Drafting
Series goal:
Accepted for trunk
Implementation:
Deferred
Milestone target:
milestone icon 1.0

Related branches

Sprints

Whiteboard

(?)

Work Items

Dependency tree

* Blueprints in grey have been implemented.

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.