summary refs log tree commit diff stats
path: root/compiler/semtypinst.nim
Commit message (Expand)AuthorAgeFilesLines
...
* introduce tyFromExpr; fixes #618Zahary Karadjov2014-01-041-0/+4
* Templates will pick the candidate in the nearest scope when symbols are mixed-inZahary Karadjov2013-12-311-7/+8
* migrate the static param handling to ReplaceTypeVars; fix tgenericvariantZahary Karadjov2013-12-301-11/+10
* properly remove intLiterals from proc signatures; fixes trettypeinferenceZahary Karadjov2013-12-301-5/+13
* handle recursive types during the instantiation of meta types; propagate tfHa...Zahary Karadjov2013-12-301-19/+79
* fix the filtering of void params in procs' signaturesZahary Karadjov2013-12-291-4/+20
* Merge branch 'upstream' into develZahary Karadjov2013-12-291-31/+52
|\
| * integrate the logic of fixupProcType into ReplaceTypeVarsZahary Karadjov2013-12-291-15/+27
| * make more tests greenZahary Karadjov2013-12-291-3/+4
| * lift generic parameters from concrete composite type classesZahary Karadjov2013-12-281-4/+5
| * towards support for composite type classes such as seq[Number] and SquareMatr...Zahary Karadjov2013-12-271-8/+13
| * better integration of tyStatic into typeRelZahary Karadjov2013-12-251-4/+4
| * wip type class reforms (the compiler bootstraps fine)Zahary Karadjov2013-12-251-1/+1
| * static params: expr[T] is now static[T]Zahary Karadjov2013-12-191-2/+2
* | case consistency: cs:partial bootstraps on windowsAraq2013-12-291-1/+1
* | case consistency: next stepsAraq2013-12-291-1/+1
* | case consistency part 4Araq2013-12-271-24/+24
* | case consistency part 2Araq2013-12-271-2/+2
* | case consistency part 1Araq2013-12-271-11/+10
|/
* 'noStackFrame' implies 'naked' in the generated C codeAraq2013-10-061-0/+1
* minor improvement towards tgenericshardcasesZahary Karadjov2013-08-281-2/+6
* pass-through of static int generic params to arrays when late instantiation i...Zahary Karadjov2013-08-231-0/+6
* Experimental support for delayed instantiation of genericsZahary Karadjov2013-08-231-2/+2
* implemented large parts of the 'not nil' checkingAraq2013-06-091-0/+2
* Removes executable bit for text files.Grzegorz Adam Hankiewicz2013-03-161-0/+0
* remove any traces of the old global generics cacheZahary Karadjov2013-01-271-67/+48
* minor bug fixes to make some tests greenZahary Karadjov2013-01-211-1/+0
* store the instantiation cache in the generic symbolZahary Karadjov2012-11-281-24/+32
* fixes #211Zahary Karadjov2012-10-131-0/+4
* syntax compatibility between do blocks and stmt blocksZahary Karadjov2012-10-041-1/+2
* the `is` operator now works with type classes and type variablesZahary Karadjov2012-10-031-1/+2
* better error handling for better idetools supportAraq2012-07-291-1/+2
* more fixes for new integer promotion rules; fixes #152; fixes #157; fixes #15...Araq2012-07-091-6/+0
* 'addSon' for types deprecated for 'int literal type' analysisAraq2012-07-091-3/+5
* implicit generics types as return types. removed the error message for captur...Zahary Karadjov2012-04-211-1/+2
* made built-in types primary expressions to allow infix operators to be used w...Zahary Karadjov2012-04-201-1/+2
* generic types can be used like type classes. distinct can be applied to type ...Zahary Karadjov2012-03-251-0/+1
* year 2012 for most copyright headersAraq2012-01-021-1/+1
* bugfix: 'when' sections in generic objects now work, so TThread[void] compilesAraq2011-11-201-16/+46
* compilation cache: various bugfixes; works for the compiler itselfAraq2011-10-271-1/+2
* compilation cache: mostly working; generics not yetAraq2011-10-251-5/+5
* bugfixes for generics; new threads implementation still brokenAraq2011-09-201-30/+70
* added xmltree.innerText; fixes #49Araq2011-08-151-4/+11
* support for C++ code generation; importcpp and importobjc pragmasAraq2011-08-071-2/+0
* fixes #42Araq2011-08-041-29/+39
* bugfix: 'final' not passed to genericAraq2011-07-291-7/+8
* bugfix: typeinfo generation for tuplesAraq2011-06-191-5/+5
* big repo cleanupAraq2011-04-121-0/+151
c3e67436939b03f97e624c11ca6058fedce'>^
db4f617af ^
4d4b3b1c0 ^
db4f617af ^


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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205


                                     
                                         




















                                                                         
                       































                                                                              


                                                         





                                  



                                                             



























                                                                        

                                       
























                                                                            
                                                    



                                                                             
                
                                                                       
                
                                                                              
                
 
                           
                   





                                                                              


                                                         















                                                     









                                                   
  







                                                                            
 
                                                    



                                                                             
                
                                                                       
                
                                                                              
                
 
                           
 
     

                           
                                            
                     


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

# Nimrod high-level memory manager: It supports Boehm's GC, no GC and the
# native Nimrod GC. The native Nimrod GC is the default.

#{.push checks:on, assertions:on.}
{.push checks:off.}

const
  debugGC = false # we wish to debug the GC...
  logGC = false
  traceGC = false # extensive debugging
  reallyDealloc = true # for debugging purposes this can be set to false
  cycleGC = true # (de)activate the cycle GC
  stressGC = false
  reallyOsDealloc = true
  coalescRight = true
  coalescLeft = true
  overwriteFree = false

type
  PPointer = ptr pointer
  TByteArray = array[0..1000_0000, byte]
  PByte = ptr TByteArray
  PString = ptr string

# Page size of the system; in most cases 4096 bytes. For exotic OS or
# CPU this needs to be changed:
const
  PageShift = 12
  PageSize = 1 shl PageShift
  PageMask = PageSize-1

  MemAlign = 8 # also minimal allocatable memory block

  BitsPerPage = PageSize div MemAlign
  UnitsPerPage = BitsPerPage div (sizeof(int)*8)
    # how many ints do we need to describe a page:
    # on 32 bit systems this is only 16 (!)

  TrunkShift = 9
  BitsPerTrunk = 1 shl TrunkShift # needs to be power of 2 and divisible by 64
  TrunkMask = BitsPerTrunk - 1
  IntsPerTrunk = BitsPerTrunk div (sizeof(int)*8)
  IntShift = 5 + ord(sizeof(int) == 8) # 5 or 6, depending on int width
  IntMask = 1 shl IntShift - 1

var
  gOutOfMem: ref EOutOfMemory

proc raiseOutOfMem() {.noreturn.} =
  if gOutOfMem == nil: 
    echo("out of memory; cannot even throw an exception")
    quit(1)
  gOutOfMem.msg = "out of memory"
  raise gOutOfMem

when defined(boehmgc):
  when defined(windows):
    const boehmLib = "boehmgc.dll"
  elif defined(macosx):
    const boehmLib = "libgc.dylib"
    
    proc boehmGCinit {.importc: "GC_init", dynlib: boehmLib.}
  else:
    const boehmLib = "/usr/lib/libgc.so.1"

  proc boehmGC_disable {.importc: "GC_disable", dynlib: boehmLib.} 
  proc boehmGC_enable {.importc: "GC_enable", dynlib: boehmLib.} 
  proc boehmGCincremental {.
    importc: "GC_enable_incremental", dynlib: boehmLib.} 
  proc boehmGCfullCollect {.importc: "GC_gcollect", dynlib: boehmLib.}  
  proc boehmAlloc(size: int): pointer {.
    importc: "GC_malloc", dynlib: boehmLib.}
  proc boehmAllocAtomic(size: int): pointer {.
    importc: "GC_malloc_atomic", dynlib: boehmLib.}
  proc boehmRealloc(p: pointer, size: int): pointer {.
    importc: "GC_realloc", dynlib: boehmLib.}
  proc boehmDealloc(p: pointer) {.importc: "GC_free", dynlib: boehmLib.}
    
  proc alloc(size: int): pointer =
    result = boehmAlloc(size)
    if result == nil: raiseOutOfMem()
  proc alloc0(size: int): pointer =
    result = alloc(size)
    zeroMem(result, size)
  proc realloc(p: Pointer, newsize: int): pointer =
    result = boehmRealloc(p, newsize)
    if result == nil: raiseOutOfMem()
  proc dealloc(p: Pointer) =
    boehmDealloc(p)

  proc initGC() = 
    when defined(macosx): boehmGCinit()
  
  #boehmGCincremental()

  proc GC_disable() = boehmGC_disable()
  proc GC_enable() = boehmGC_enable()
  proc GC_fullCollect() = boehmGCfullCollect()
  proc GC_setStrategy(strategy: TGC_Strategy) = nil
  proc GC_enableMarkAndSweep() = nil
  proc GC_disableMarkAndSweep() = nil
  proc GC_getStatistics(): string = return ""
  
  proc getOccupiedMem(): int = return -1
  proc getFreeMem(): int = return -1
  proc getTotalMem(): int = return -1

  proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
    result = alloc(size)
  proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} =
    result = newObj(typ, addInt(mulInt(len, typ.base.size), GenericSeqSize))
    cast[PGenericSeq](result).len = len
    cast[PGenericSeq](result).space = len

  proc growObj(old: pointer, newsize: int): pointer =
    result = realloc(old, newsize)

  proc setStackBottom(theStackBottom: pointer) = nil
  proc nimGCref(p: pointer) {.compilerproc, inline.} = nil
  proc nimGCunref(p: pointer) {.compilerproc, inline.} = nil
  
  proc unsureAsgnRef(dest: ppointer, src: pointer) {.compilerproc, inline.} =
    dest[] = src
  proc asgnRef(dest: ppointer, src: pointer) {.compilerproc, inline.} =
    dest[] = src
  proc asgnRefNoCycle(dest: ppointer, src: pointer) {.compilerproc, inline.} =
    dest[] = src

  include "system/cellsets"
elif defined(nogc):
  # Even though we don't want the GC, we cannot simply use C's memory manager
  # because Nimrod's runtime wants ``realloc`` to zero out the additional
  # space which C's ``realloc`` does not. And we cannot get the old size of an
  # object, because C does not support this operation... Even though every
  # possible implementation has to have a way to determine the object's size.
  # C just sucks.
  when appType == "lib": 
    {.warning: "nogc in a library context may not work".}
  
  include "system/alloc"

  when false:
    proc alloc(size: int): pointer =
      result = c_malloc(size)
      if result == nil: raiseOutOfMem()
    proc alloc0(size: int): pointer =
      result = alloc(size)
      zeroMem(result, size)
    proc realloc(p: Pointer, newsize: int): pointer =
      result = c_realloc(p, newsize)
      if result == nil: raiseOutOfMem()
    proc dealloc(p: Pointer) = c_free(p)
    proc getOccupiedMem(): int = return -1
    proc getFreeMem(): int = return -1
    proc getTotalMem(): int = return -1

  proc initGC() = nil
  proc GC_disable() = nil
  proc GC_enable() = nil
  proc GC_fullCollect() = nil
  proc GC_setStrategy(strategy: TGC_Strategy) = nil
  proc GC_enableMarkAndSweep() = nil
  proc GC_disableMarkAndSweep() = nil
  proc GC_getStatistics(): string = return ""
  
  
  proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
    result = alloc0(size)
  proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} =
    result = newObj(typ, addInt(mulInt(len, typ.base.size), GenericSeqSize))
    cast[PGenericSeq](result).len = len
    cast[PGenericSeq](result).space = len
  proc growObj(old: pointer, newsize: int): pointer =
    result = realloc(old, newsize)

  proc setStackBottom(theStackBottom: pointer) = nil
  proc nimGCref(p: pointer) {.compilerproc, inline.} = nil
  proc nimGCunref(p: pointer) {.compilerproc, inline.} = nil
  
  proc unsureAsgnRef(dest: ppointer, src: pointer) {.compilerproc, inline.} =
    dest[] = src
  proc asgnRef(dest: ppointer, src: pointer) {.compilerproc, inline.} =
    dest[] = src
  proc asgnRefNoCycle(dest: ppointer, src: pointer) {.compilerproc, inline.} =
    dest[] = src

  include "system/cellsets"

else:
  include "system/alloc"
  include "system/cellsets"
  assert(sizeof(TCell) == sizeof(TFreeCell))
  include "system/gc"
  
{.pop.}