about summary refs log tree commit diff stats
path: root/README
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-02-22 11:42:08 +0100
committerAnselm R. Garbe <arg@suckless.org>2007-02-22 11:42:08 +0100
commit2c477cf66147d369ae8ff17acdce743c6811ee6a (patch)
tree121a031caf30be9f6931e37e26cf2469c8c7acfa /README
parent986ca73074ef165880c75ee46a4eb6a1b328dc5b (diff)
downloaddwm-2c477cf66147d369ae8ff17acdce743c6811ee6a.tar.gz
replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Diffstat (limited to 'README')
0 files changed, 0 insertions, 0 deletions
mrod version of the compiler' href='/ahoang/Nim/commit/rod/condsyms.nim?h=devel&id=e254741541b0389dfb0b675116c76a6a144b90b7'>e25474154 ^
804e2ac89 ^
e25474154 ^


804e2ac89 ^
e25474154 ^


804e2ac89 ^

f93ca8e42 ^
e25474154 ^
f93ca8e42 ^
e25474154 ^
f93ca8e42 ^
e25474154 ^

804e2ac89 ^

e25474154 ^






3b7ef2288 ^


e25474154 ^



f93ca8e42 ^
e25474154 ^























f93ca8e42 ^
3b7ef2288 ^
e25474154 ^





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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102


                               
                                         







                                                   
                                                        












                                     

                                    







                                                           
                                                   


                                       
                                         


                                               

                                   
                                                       
                  
                                            
                              
                                 

                                  

                                   






                                   


                                                     



                                     
           























                                                                           
           
                                           





                                                             
#
#
#           The Nimrod Compiler
#        (c) Copyright 2011 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# This module handles the conditional symbols.

import 
  ast, astalgo, msgs, hashes, platform, strutils, idents

var gSymbols*: TStrTable

proc InitDefines*()
proc DeinitDefines*()
proc DefineSymbol*(symbol: string)
proc UndefSymbol*(symbol: string)
proc isDefined*(symbol: PIdent): bool
proc ListSymbols*()
proc countDefinedSymbols*(): int
# implementation

proc DefineSymbol(symbol: string) = 
  var i = getIdent(symbol)
  var sym = StrTableGet(gSymbols, i)
  if sym == nil: 
    new(sym)                  # circumvent the ID mechanism
    sym.kind = skConditional
    sym.name = i
    StrTableAdd(gSymbols, sym)
  sym.position = 1

proc UndefSymbol(symbol: string) = 
  var sym = StrTableGet(gSymbols, getIdent(symbol))
  if sym != nil: sym.position = 0
  
proc isDefined(symbol: PIdent): bool = 
  var sym = StrTableGet(gSymbols, symbol)
  result = (sym != nil) and (sym.position == 1)

proc ListSymbols() = 
  var it: TTabIter
  var s = InitTabIter(it, gSymbols)
  OutWriteln("-- List of currently defined symbols --")
  while s != nil: 
    if s.position == 1: OutWriteln(s.name.s)
    s = nextIter(it, gSymbols)
  OutWriteln("-- End of list --")

proc countDefinedSymbols(): int = 
  var it: TTabIter
  var s = InitTabIter(it, gSymbols)
  result = 0
  while s != nil: 
    if s.position == 1: inc(result)
    s = nextIter(it, gSymbols)

proc InitDefines() = 
  initStrTable(gSymbols)
  DefineSymbol("nimrod") # 'nimrod' is always defined
  
  # add platform specific symbols:
  case targetCPU
  of cpuI386: DefineSymbol("x86")
  of cpuIa64: DefineSymbol("itanium")
  of cpuAmd64: DefineSymbol("x8664")
  else: nil
  case targetOS
  of osDOS: 
    DefineSymbol("msdos")
  of osWindows: 
    DefineSymbol("mswindows")
    DefineSymbol("win32")
  of osLinux, osMorphOS, osSkyOS, osIrix, osPalmOS, osQNX, osAtari, osAix: 
    # these are all 'unix-like'
    DefineSymbol("unix")
    DefineSymbol("posix")
  of osSolaris: 
    DefineSymbol("sunos")
    DefineSymbol("unix")
    DefineSymbol("posix")
  of osNetBSD, osFreeBSD, osOpenBSD: 
    DefineSymbol("unix")
    DefineSymbol("bsd")
    DefineSymbol("posix")
  of osMacOS: 
    DefineSymbol("macintosh")
  of osMacOSX: 
    DefineSymbol("macintosh")
    DefineSymbol("unix")
    DefineSymbol("posix")
  else: nil
  DefineSymbol("cpu" & $cpu[targetCPU].bit)
  DefineSymbol(normalize(endianToStr[cpu[targetCPU].endian]))
  DefineSymbol(cpu[targetCPU].name)
  DefineSymbol(platform.os[targetOS].name)

proc DeinitDefines() = 
  nil