summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/cgen.nim4
-rwxr-xr-xcompiler/crc.nim11
-rwxr-xr-xcompiler/nimrod.nim6
-rwxr-xr-xcompiler/treetab.nim47
4 files changed, 26 insertions, 42 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index d76793c9a..619caf250 100755
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -677,8 +677,8 @@ proc genProcAux(m: BModule, prc: PSym) =
     if optStackTrace in prc.options: app(generatedProc, deinitFrame(p))
     if (optProfiler in prc.options) and (gCmd != cmdCompileToLLVM): 
       appf(generatedProc, 
-          "profileData[$1].total += elapsed(getticks(), NIM_profilingStart);$n", 
-           [toRope(prc.loc.a)])
+        "profileData[$1].total += elapsed(getticks(), NIM_profilingStart);$n", 
+        [toRope(prc.loc.a)])
     app(generatedProc, returnStmt)
     app(generatedProc, '}' & tnl)
   app(m.s[cfsProcs], generatedProc)
diff --git a/compiler/crc.nim b/compiler/crc.nim
index be1aee16b..b1801d9dc 100755
--- a/compiler/crc.nim
+++ b/compiler/crc.nim
@@ -100,19 +100,16 @@ proc crcFromBuf(buf: Pointer, length: int): TCrc32 =
   
 proc crcFromFile(filename: string): TCrc32 = 
   const 
-    bufSize = 8 * 1024
+    bufSize = 8000 # don't use 8K for the memory allocator!
   var 
     bin: tfile
-    buf: Pointer
-    readBytes: int
-    p: PByteArray
   result = InitCrc32
   if not open(bin, filename): 
     return                    # not equal if file does not exist
-  buf = alloc(BufSize)
-  p = cast[PByteArray](buf)
+  var buf = alloc(BufSize)
+  var p = cast[PByteArray](buf)
   while true: 
-    readBytes = readBuffer(bin, buf, bufSize)
+    var readBytes = readBuffer(bin, buf, bufSize)
     for i in countup(0, readBytes - 1): result = updateCrc32(p[i], result)
     if readBytes != bufSize: break 
   dealloc(buf)
diff --git a/compiler/nimrod.nim b/compiler/nimrod.nim
index 05c7a2af1..d9580d955 100755
--- a/compiler/nimrod.nim
+++ b/compiler/nimrod.nim
@@ -50,7 +50,7 @@ proc ProcessCmdLine(pass: TCmdLinePass, command, filename: var string) =
       rawMessage(errArgsNeedRunOption, [])
   
 proc HandleCmdLine() = 
-  var start = getTime()
+  var start = epochTime()
   if paramCount() == 0: 
     writeCommandLineUsage()
   else: 
@@ -73,7 +73,8 @@ proc HandleCmdLine() =
         if gCmd == cmdRun:
           tccgen.run()
       if gCmd notin {cmdInterpret, cmdRun}: 
-        rawMessage(hintSuccessX, [$gLinesCompiled, $(getTime() - start)])
+        rawMessage(hintSuccessX, [$gLinesCompiled, 
+                   formatFloat(epochTime() - start, ffDecimal, 3)])
       if optRun in gGlobalOptions: 
         when defined(unix): 
           var prog = "./" & quoteIfContainsWhite(changeFileExt(filename, ""))
@@ -81,6 +82,7 @@ proc HandleCmdLine() =
           var prog = quoteIfContainsWhite(changeFileExt(filename, ""))
         execExternalProgram(prog & ' ' & arguments)
 
+#GC_disableMarkAndSweep()
 cmdLineInfo = newLineInfo("command line", -1, -1)
 condsyms.InitDefines()
 HandleCmdLine()
diff --git a/compiler/treetab.nim b/compiler/treetab.nim
index 797ef5029..92a329ecc 100755
--- a/compiler/treetab.nim
+++ b/compiler/treetab.nim
@@ -1,7 +1,7 @@
 #
 #
 #           The Nimrod Compiler
-#        (c) Copyright 2008 Andreas Rumpf
+#        (c) Copyright 2011 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -12,13 +12,7 @@
 import 
   nhashes, ast, astalgo, types
 
-proc NodeTableGet*(t: TNodeTable, key: PNode): int
-proc NodeTablePut*(t: var TNodeTable, key: PNode, val: int)
-proc NodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int
-# implementation
-
 proc hashTree(n: PNode): THash = 
-  result = 0
   if n == nil: return 
   result = ord(n.kind)
   case n.kind
@@ -41,7 +35,6 @@ proc hashTree(n: PNode): THash =
       result = concHash(result, hashTree(n.sons[i]))
   
 proc TreesEquivalent(a, b: PNode): bool = 
-  result = false
   if a == b: 
     result = true
   elif (a != nil) and (b != nil) and (a.kind == b.kind): 
@@ -60,36 +53,31 @@ proc TreesEquivalent(a, b: PNode): bool =
     if result: result = sameTypeOrNil(a.typ, b.typ)
   
 proc NodeTableRawGet(t: TNodeTable, k: THash, key: PNode): int = 
-  var h: THash
-  h = k and high(t.data)
+  var h: THash = k and high(t.data)
   while t.data[h].key != nil: 
     if (t.data[h].h == k) and TreesEquivalent(t.data[h].key, key): 
       return h
     h = nextTry(h, high(t.data))
-  result = - 1
+  result = -1
 
-proc NodeTableGet(t: TNodeTable, key: PNode): int = 
-  var index: int
-  index = NodeTableRawGet(t, hashTree(key), key)
+proc NodeTableGet*(t: TNodeTable, key: PNode): int = 
+  var index = NodeTableRawGet(t, hashTree(key), key)
   if index >= 0: result = t.data[index].val
   else: result = low(int)
   
-proc NodeTableRawInsert(data: var TNodePairSeq, k: THash, key: PNode, val: int) = 
-  var h: THash
-  h = k and high(data)
+proc NodeTableRawInsert(data: var TNodePairSeq, k: THash, key: PNode, 
+                        val: int) = 
+  var h: THash = k and high(data)
   while data[h].key != nil: h = nextTry(h, high(data))
   assert(data[h].key == nil)
   data[h].h = k
   data[h].key = key
   data[h].val = val
 
-proc NodeTablePut(t: var TNodeTable, key: PNode, val: int) = 
-  var 
-    index: int
-    n: TNodePairSeq
-    k: THash
-  k = hashTree(key)
-  index = NodeTableRawGet(t, k, key)
+proc NodeTablePut*(t: var TNodeTable, key: PNode, val: int) = 
+  var n: TNodePairSeq
+  var k: THash = hashTree(key)
+  var index = NodeTableRawGet(t, k, key)
   if index >= 0: 
     assert(t.data[index].key != nil)
     t.data[index].val = val
@@ -103,13 +91,10 @@ proc NodeTablePut(t: var TNodeTable, key: PNode, val: int) =
     NodeTableRawInsert(t.data, k, key, val)
     inc(t.counter)
 
-proc NodeTableTestOrSet(t: var TNodeTable, key: PNode, val: int): int = 
-  var 
-    index: int
-    n: TNodePairSeq
-    k: THash
-  k = hashTree(key)
-  index = NodeTableRawGet(t, k, key)
+proc NodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int = 
+  var n: TNodePairSeq
+  var k: THash = hashTree(key)
+  var index = NodeTableRawGet(t, k, key)
   if index >= 0: 
     assert(t.data[index].key != nil)
     result = t.data[index].val
bx?h=hlt&id=76599bb813970f09ddd27d476f5b62be9bf97d4d'>^
fd91f7f6 ^
f0b7e327 ^
fd91f7f6 ^

















bc20cc3d ^
33352536 ^
fd91f7f6 ^
bc20cc3d ^
fd91f7f6 ^

bc20cc3d ^
fd91f7f6 ^
bc20cc3d ^
fd91f7f6 ^


bc20cc3d ^
fd91f7f6 ^
bc20cc3d ^
fd91f7f6 ^
bc20cc3d ^
fd91f7f6 ^

bc20cc3d ^
fd91f7f6 ^


bc20cc3d ^
fd91f7f6 ^
bc20cc3d ^
33352536 ^
7a583220 ^
33352536 ^

bc20cc3d ^
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




                                                                                                                                                 




                                                                                          
                                                                       
                

                                                                                                                                                                       
                      
               
















                                                                                                                                                                              
                                                                                                                                                                     
              
                                        
                      
                                                                                                                                                                  


                                                                                                                                                                  
                         


                 
                

                                                                                                                                                                       

             
                       
                

                                                                                                                                                                       

                                         
                   
                                      
              


                                                                                                                                                                  
                                                        
                   
                                                     

















                                                                                                                                                                  
                      
                                                                                                                                                                  
                                                                       
                   

                                             
              
                                     
                      


                                                                                                                                                                  
                   
                                             
              
                         
                      

                                                                                                                                                                  
                   


                                               
              
                                      
                      
                                                                                                                                                                  
                

                                                                                                                                                                       
             
== code
#   instruction                     effective address                                                   register    displacement    immediate
# . op          subop               mod             rm32          base        index         scale       r32
# . 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes

# write an entire stream's contents to a buffered-file
# ways to do this:
#   - construct a 'maximal slice' and pass it to write-slice-buffered
#   - flush the buffered-file and pass the stream directly to its fd (disabling buffering)
# we'll go with the first way for now
write-stream-data:  # f : (address buffered-file), s : (address stream)
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # . save registers
    50/push-eax
    51/push-ecx
    56/push-esi
    # esi = s
    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   0xc/disp8       .                 # copy *(ebp+12) to esi
    # var slice/ecx = {s->data, s->data + s->write}
    # . push s->data + s->write
    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           0/r32/eax   .               .                 # copy *esi to eax
    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    6/base/esi  0/index/eax   .           0/r32/eax   0xc/disp8       .                 # copy esi+eax+12 to eax
    50/push-eax
    # . push s->data
    8d/copy-address                 1/mod/*+disp8   6/rm32/esi    .           .             .           0/r32/eax   0xc/disp8       .                 # copy esi+12 to eax
    50/push-eax
    # . ecx = esp
    89/copy                         3/mod/direct    1/rm32/ecx    .           .             .           4/r32/esp   .               .                 # copy esp to ecx
    # write-slice-buffered(f, slice)
    # . . push args
    51/push-ecx
    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
    # . . call
    e8/call  write-slice-buffered/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
$write-stream-data:end:
    # . restore locals
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # . restore registers
    5e/pop-to-esi
    59/pop-to-ecx
    58/pop-to-eax
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return

test-write-stream-data:
    # . prologue
    55/push-ebp
    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
    # setup
    # . clear-stream(_test-output-stream)
    # . . push args
    68/push  _test-output-stream/imm32
    # . . call
    e8/call  clear-stream/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # . clear-stream(_test-output-buffered-file->buffer)
    # . . push args
    68/push  _test-output-buffered-file->buffer/imm32
    # . . call
    e8/call  clear-stream/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # . clear-stream(_test-input-stream)
    # . . push args
    68/push  _test-input-stream/imm32
    # . . call
    e8/call  clear-stream/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # initialize input
    # . write(_test-input-stream, "abcd")
    # . . push args
    68/push  "abcd"/imm32
    68/push  _test-input-stream/imm32
    # . . call
    e8/call  write/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # write-stream-data(_test-output-buffered-file, _test-input-stream)
    # . . push args
    68/push  _test-input-stream/imm32
    68/push  _test-output-buffered-file/imm32
    # . . call
    e8/call  write-stream-data/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
    # check that the write happened as expected
    # . flush(_test-output-buffered-file)
    # . . push args
    68/push  _test-output-buffered-file/imm32
    # . . call
    e8/call  flush/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
    # . check-stream-equal(_test-output-stream, "abcd", msg)
    # . . push args
    68/push  "F - test-write-stream-data"/imm32
    68/push  "abcd"/imm32
    68/push  _test-output-stream/imm32
    # . . call
    e8/call  check-stream-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
    # . epilogue
    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
    5d/pop-to-ebp
    c3/return