aboutsummaryrefslogtreecommitdiffhomepage
path: root/notes/macro_expanded_variables.txt
blob: 51f4705c5346eeb4fc6a91c1b592121ac2218933 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

Macros using "expanded variables"
=================================

Goals:
* Macros should be local to the block they are defined in (and if defined
  at top level, they should be local to the file they are defined in)
    - This means that they cannot generate top-levels!
* Macros should be defined before use
* Syntax and semantic checks should happen BEFORE the macros are expanded.
  The only thing that should happen after expansion is IR generation
  (and machine code generation and exec/lib file output).
    - This might be tricky with Alternative 1 (below).
      For the switch with case values, there should be a check whether
      the switch handles all values, for example

Alternative 1:

    func test()
    {
        switch tok {
            %for %t in [newline, kw_if, kw_else] {
                case %t {
                    ...
                }
            }
        }
    }

Alternative 2:

* Use "subcase" for switch/case
* Add a special syntax for data definitions
  (see table_generation_and_macros.txt)


    func test()
    {
        switch tok {
            case newline, kw_if, kw_else {
                ...
                subcase newline { ... }
                ...
                print(tok.name())
                ...
            }
        }
    }