diff options
-rw-r--r-- | data/messages.yml | 2 | ||||
-rw-r--r-- | doc/manual.txt | 4 | ||||
-rw-r--r-- | doc/theindex.txt | 369 | ||||
-rw-r--r-- | lib/arithm.nim | 12 | ||||
-rw-r--r-- | lib/base/postgres.nim | 384 | ||||
-rw-r--r-- | lib/nimbase.h | 22 | ||||
-rw-r--r-- | lib/system.nim | 5 | ||||
-rw-r--r-- | nim/ast.pas | 2378 | ||||
-rw-r--r-- | nim/ccgexprs.pas | 31 | ||||
-rw-r--r-- | nim/ccgstmts.pas | 21 | ||||
-rw-r--r-- | nim/ccgtypes.pas | 14 | ||||
-rw-r--r-- | nim/msgs.pas | 1102 | ||||
-rw-r--r-- | nim/semfold.pas | 35 | ||||
-rw-r--r-- | nim/sigmatch.pas | 2 | ||||
-rw-r--r-- | nim/transf.pas | 10 |
15 files changed, 2402 insertions, 1989 deletions
diff --git a/data/messages.yml b/data/messages.yml index 4a2154613..271fadfe4 100644 --- a/data/messages.yml +++ b/data/messages.yml @@ -287,7 +287,7 @@ {'hintConvFromXtoItselfNotNeeded': 'conversion from $1 to itself is pointless'}, {'hintExprAlwaysX': "expression evaluates always to '$1'"}, {'hintQuitCalled': "quit() called"}, -{'hintProcessing': "processing $1"}, +{'hintProcessing': "$1"}, {'hintCodeBegin': "generated code listing:"}, {'hintCodeEnd': "end of listing"}, {'hintConf': "used config file '$1'"}, diff --git a/doc/manual.txt b/doc/manual.txt index 9acaae3cd..393363a47 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -1514,8 +1514,8 @@ above example is equivalent to: .. code-block:: nimrod proc divmod(a, b: int, res, remainder: ptr int) = - res = a div b - remainder = a mod b + res^ = a div b + remainder^ = a mod b var x, y: int diff --git a/doc/theindex.txt b/doc/theindex.txt index 06be1fc5d..24d58ec68 100644 --- a/doc/theindex.txt +++ b/doc/theindex.txt @@ -10,17 +10,17 @@ Index `macros.html#115 <macros.html#115>`_ `!=`:idx: - `system.html#351 <system.html#351>`_ + `system.html#353 <system.html#353>`_ `$`:idx: - * `system.html#422 <system.html#422>`_ - * `system.html#423 <system.html#423>`_ * `system.html#424 <system.html#424>`_ * `system.html#425 <system.html#425>`_ * `system.html#426 <system.html#426>`_ * `system.html#427 <system.html#427>`_ * `system.html#428 <system.html#428>`_ * `system.html#429 <system.html#429>`_ + * `system.html#430 <system.html#430>`_ + * `system.html#431 <system.html#431>`_ * `times.html#109 <times.html#109>`_ * `times.html#110 <times.html#110>`_ * `macros.html#116 <macros.html#116>`_ @@ -31,21 +31,21 @@ Index * `strtabs.html#112 <strtabs.html#112>`_ `%%`:idx: - * `system.html#296 <system.html#296>`_ - * `system.html#297 <system.html#297>`_ * `system.html#298 <system.html#298>`_ * `system.html#299 <system.html#299>`_ * `system.html#300 <system.html#300>`_ + * `system.html#301 <system.html#301>`_ + * `system.html#302 <system.html#302>`_ `&`:idx: - * `system.html#362 <system.html#362>`_ - * `system.html#363 <system.html#363>`_ * `system.html#364 <system.html#364>`_ * `system.html#365 <system.html#365>`_ - * `system.html#453 <system.html#453>`_ - * `system.html#454 <system.html#454>`_ + * `system.html#366 <system.html#366>`_ + * `system.html#367 <system.html#367>`_ * `system.html#455 <system.html#455>`_ * `system.html#456 <system.html#456>`_ + * `system.html#457 <system.html#457>`_ + * `system.html#458 <system.html#458>`_ `*`:idx: * `system.html#206 <system.html#206>`_ @@ -53,16 +53,16 @@ Index * `system.html#208 <system.html#208>`_ * `system.html#209 <system.html#209>`_ * `system.html#210 <system.html#210>`_ - * `system.html#315 <system.html#315>`_ - * `system.html#323 <system.html#323>`_ + * `system.html#317 <system.html#317>`_ + * `system.html#325 <system.html#325>`_ * `complex.html#107 <complex.html#107>`_ `*%`:idx: - * `system.html#286 <system.html#286>`_ - * `system.html#287 <system.html#287>`_ * `system.html#288 <system.html#288>`_ * `system.html#289 <system.html#289>`_ * `system.html#290 <system.html#290>`_ + * `system.html#291 <system.html#291>`_ + * `system.html#292 <system.html#292>`_ `+`:idx: * `system.html#181 <system.html#181>`_ @@ -75,17 +75,17 @@ Index * `system.html#198 <system.html#198>`_ * `system.html#199 <system.html#199>`_ * `system.html#200 <system.html#200>`_ - * `system.html#311 <system.html#311>`_ * `system.html#313 <system.html#313>`_ - * `system.html#324 <system.html#324>`_ + * `system.html#315 <system.html#315>`_ + * `system.html#326 <system.html#326>`_ * `complex.html#103 <complex.html#103>`_ `+%`:idx: - * `system.html#276 <system.html#276>`_ - * `system.html#277 <system.html#277>`_ * `system.html#278 <system.html#278>`_ * `system.html#279 <system.html#279>`_ * `system.html#280 <system.html#280>`_ + * `system.html#281 <system.html#281>`_ + * `system.html#282 <system.html#282>`_ `-`:idx: * `system.html#186 <system.html#186>`_ @@ -98,34 +98,34 @@ Index * `system.html#203 <system.html#203>`_ * `system.html#204 <system.html#204>`_ * `system.html#205 <system.html#205>`_ - * `system.html#312 <system.html#312>`_ * `system.html#314 <system.html#314>`_ - * `system.html#325 <system.html#325>`_ + * `system.html#316 <system.html#316>`_ + * `system.html#327 <system.html#327>`_ * `complex.html#104 <complex.html#104>`_ * `complex.html#105 <complex.html#105>`_ * `times.html#113 <times.html#113>`_ `-%`:idx: - * `system.html#281 <system.html#281>`_ - * `system.html#282 <system.html#282>`_ * `system.html#283 <system.html#283>`_ * `system.html#284 <system.html#284>`_ * `system.html#285 <system.html#285>`_ + * `system.html#286 <system.html#286>`_ + * `system.html#287 <system.html#287>`_ `-+-`:idx: - `system.html#326 <system.html#326>`_ + `system.html#328 <system.html#328>`_ `/`:idx: - * `system.html#316 <system.html#316>`_ + * `system.html#318 <system.html#318>`_ * `os.html#119 <os.html#119>`_ * `complex.html#106 <complex.html#106>`_ `/%`:idx: - * `system.html#291 <system.html#291>`_ - * `system.html#292 <system.html#292>`_ * `system.html#293 <system.html#293>`_ * `system.html#294 <system.html#294>`_ * `system.html#295 <system.html#295>`_ + * `system.html#296 <system.html#296>`_ + * `system.html#297 <system.html#297>`_ `/../`:idx: `os.html#123 <os.html#123>`_ @@ -136,23 +136,26 @@ Index * `system.html#258 <system.html#258>`_ * `system.html#259 <system.html#259>`_ * `system.html#260 <system.html#260>`_ - * `system.html#319 <system.html#319>`_ - * `system.html#343 <system.html#343>`_ - * `system.html#344 <system.html#344>`_ + * `system.html#321 <system.html#321>`_ * `system.html#345 <system.html#345>`_ * `system.html#346 <system.html#346>`_ * `system.html#347 <system.html#347>`_ * `system.html#348 <system.html#348>`_ * `system.html#349 <system.html#349>`_ * `system.html#350 <system.html#350>`_ + * `system.html#351 <system.html#351>`_ + * `system.html#352 <system.html#352>`_ * `times.html#114 <times.html#114>`_ `<%`:idx: - * `system.html#306 <system.html#306>`_ - * `system.html#307 <system.html#307>`_ * `system.html#308 <system.html#308>`_ * `system.html#309 <system.html#309>`_ * `system.html#310 <system.html#310>`_ + * `system.html#311 <system.html#311>`_ + * `system.html#312 <system.html#312>`_ + + `<=`:idx: + `times.html#115 <times.html#115>`_ `<=`:idx: * `system.html#251 <system.html#251>`_ @@ -160,24 +163,21 @@ Index * `system.html#253 <system.html#253>`_ * `system.html#254 <system.html#254>`_ * `system.html#255 <system.html#255>`_ - * `system.html#318 <system.html#318>`_ - * `system.html#336 <system.html#336>`_ - * `system.html#337 <system.html#337>`_ + * `system.html#320 <system.html#320>`_ * `system.html#338 <system.html#338>`_ * `system.html#339 <system.html#339>`_ * `system.html#340 <system.html#340>`_ * `system.html#341 <system.html#341>`_ * `system.html#342 <system.html#342>`_ - - `<=`:idx: - `times.html#115 <times.html#115>`_ + * `system.html#343 <system.html#343>`_ + * `system.html#344 <system.html#344>`_ `<=%`:idx: - * `system.html#301 <system.html#301>`_ - * `system.html#302 <system.html#302>`_ * `system.html#303 <system.html#303>`_ * `system.html#304 <system.html#304>`_ * `system.html#305 <system.html#305>`_ + * `system.html#306 <system.html#306>`_ + * `system.html#307 <system.html#307>`_ `==`:idx: * `md5.html#107 <md5.html#107>`_ @@ -186,9 +186,7 @@ Index * `system.html#248 <system.html#248>`_ * `system.html#249 <system.html#249>`_ * `system.html#250 <system.html#250>`_ - * `system.html#317 <system.html#317>`_ - * `system.html#327 <system.html#327>`_ - * `system.html#328 <system.html#328>`_ + * `system.html#319 <system.html#319>`_ * `system.html#329 <system.html#329>`_ * `system.html#330 <system.html#330>`_ * `system.html#331 <system.html#331>`_ @@ -196,7 +194,9 @@ Index * `system.html#333 <system.html#333>`_ * `system.html#334 <system.html#334>`_ * `system.html#335 <system.html#335>`_ - * `system.html#458 <system.html#458>`_ + * `system.html#336 <system.html#336>`_ + * `system.html#337 <system.html#337>`_ + * `system.html#460 <system.html#460>`_ * `complex.html#102 <complex.html#102>`_ * `macros.html#117 <macros.html#117>`_ @@ -204,25 +204,25 @@ Index `regexprs.html#111 <regexprs.html#111>`_ `>`:idx: - `system.html#353 <system.html#353>`_ + `system.html#355 <system.html#355>`_ `>%`:idx: - `system.html#421 <system.html#421>`_ + `system.html#423 <system.html#423>`_ `>=`:idx: - `system.html#352 <system.html#352>`_ + `system.html#354 <system.html#354>`_ `>=%`:idx: - `system.html#420 <system.html#420>`_ + `system.html#422 <system.html#422>`_ `@`:idx: - `system.html#361 <system.html#361>`_ + `system.html#363 <system.html#363>`_ `[]`:idx: - `strtabs.html#107 <strtabs.html#107>`_ + `macros.html#113 <macros.html#113>`_ `[]`:idx: - `macros.html#113 <macros.html#113>`_ + `strtabs.html#107 <strtabs.html#107>`_ `[]=`:idx: `strtabs.html#106 <strtabs.html#106>`_ @@ -242,7 +242,7 @@ Index * `system.html#263 <system.html#263>`_ * `system.html#264 <system.html#264>`_ * `system.html#265 <system.html#265>`_ - * `system.html#320 <system.html#320>`_ + * `system.html#322 <system.html#322>`_ * `complex.html#108 <complex.html#108>`_ `acronym`:idx: @@ -252,11 +252,11 @@ Index `nimrodc.html#113 <nimrodc.html#113>`_ `add`:idx: - * `system.html#366 <system.html#366>`_ - * `system.html#367 <system.html#367>`_ * `system.html#368 <system.html#368>`_ * `system.html#369 <system.html#369>`_ * `system.html#370 <system.html#370>`_ + * `system.html#371 <system.html#371>`_ + * `system.html#372 <system.html#372>`_ * `macros.html#119 <macros.html#119>`_ * `macros.html#120 <macros.html#120>`_ @@ -269,7 +269,7 @@ Index * `zipfiles.html#107 <zipfiles.html#107>`_ `addQuitProc`:idx: - `system.html#404 <system.html#404>`_ + `system.html#406 <system.html#406>`_ `address`:idx: `xmlgen.html#109 <xmlgen.html#109>`_ @@ -284,10 +284,10 @@ Index `strutils.html#152 <strutils.html#152>`_ `alloc`:idx: - `system.html#413 <system.html#413>`_ + `system.html#415 <system.html#415>`_ `alloc0`:idx: - `system.html#414 <system.html#414>`_ + `system.html#416 <system.html#416>`_ `ALLOC_MAX_BLOCK_TO_DROP`:idx: `mysql.html#317 <mysql.html#317>`_ @@ -344,7 +344,7 @@ Index `manual.html#196 <manual.html#196>`_ `assert`:idx: - `system.html#418 <system.html#418>`_ + `system.html#420 <system.html#420>`_ `AST`:idx: `macros.html#101 <macros.html#101>`_ @@ -379,10 +379,10 @@ Index `xmlgen.html#113 <xmlgen.html#113>`_ `BiggestFloat`:idx: - `system.html#374 <system.html#374>`_ + `system.html#376 <system.html#376>`_ `BiggestInt`:idx: - `system.html#373 <system.html#373>`_ + `system.html#375 <system.html#375>`_ `BINARY_FLAG`:idx: `mysql.html#131 <mysql.html#131>`_ @@ -446,16 +446,16 @@ Index `manual.html#181 <manual.html#181>`_ `cchar`:idx: - `system.html#375 <system.html#375>`_ + `system.html#377 <system.html#377>`_ `cdecl`:idx: `manual.html#165 <manual.html#165>`_ `cdouble`:idx: - `system.html#382 <system.html#382>`_ + `system.html#384 <system.html#384>`_ `cfloat`:idx: - `system.html#381 <system.html#381>`_ + `system.html#383 <system.html#383>`_ `cgiError`:idx: `cgi.html#106 <cgi.html#106>`_ @@ -500,7 +500,7 @@ Index `system.html#171 <system.html#171>`_ `cint`:idx: - `system.html#378 <system.html#378>`_ + `system.html#380 <system.html#380>`_ `cite`:idx: `xmlgen.html#119 <xmlgen.html#119>`_ @@ -575,13 +575,13 @@ Index `mysql.html#169 <mysql.html#169>`_ `clong`:idx: - `system.html#379 <system.html#379>`_ + `system.html#381 <system.html#381>`_ `clongdouble`:idx: - `system.html#383 <system.html#383>`_ + `system.html#385 <system.html#385>`_ `clonglong`:idx: - `system.html#380 <system.html#380>`_ + `system.html#382 <system.html#382>`_ `close`:idx: * `lexbase.html#105 <lexbase.html#105>`_ @@ -591,14 +591,14 @@ Index * `zipfiles.html#103 <zipfiles.html#103>`_ `CloseFile`:idx: - `system.html#489 <system.html#489>`_ + `system.html#492 <system.html#492>`_ `closure`:idx: `manual.html#170 <manual.html#170>`_ `cmp`:idx: - * `system.html#359 <system.html#359>`_ - * `system.html#360 <system.html#360>`_ + * `system.html#361 <system.html#361>`_ + * `system.html#362 <system.html#362>`_ `cmpIgnoreCase`:idx: `strutils.html#137 <strutils.html#137>`_ @@ -639,10 +639,10 @@ Index `mysql.html#266 <mysql.html#266>`_ `CompileDate`:idx: - `system.html#391 <system.html#391>`_ + `system.html#393 <system.html#393>`_ `CompileTime`:idx: - `system.html#392 <system.html#392>`_ + `system.html#394 <system.html#394>`_ `complex statements`:idx: `manual.html#175 <manual.html#175>`_ @@ -658,7 +658,7 @@ Index * `tut1.html#104 <tut1.html#104>`_ `contains`:idx: - * `system.html#354 <system.html#354>`_ + * `system.html#356 <system.html#356>`_ * `strutils.html#139 <strutils.html#139>`_ * `strutils.html#140 <strutils.html#140>`_ * `strutils.html#141 <strutils.html#141>`_ @@ -667,14 +667,14 @@ Index `manual.html#195 <manual.html#195>`_ `copy`:idx: - * `system.html#405 <system.html#405>`_ - * `system.html#406 <system.html#406>`_ + * `system.html#407 <system.html#407>`_ + * `system.html#408 <system.html#408>`_ `copyFile`:idx: `os.html#134 <os.html#134>`_ `copyMem`:idx: - `system.html#410 <system.html#410>`_ + `system.html#412 <system.html#412>`_ `copyNimNode`:idx: `macros.html#136 <macros.html#136>`_ @@ -695,13 +695,13 @@ Index `math.html#109 <math.html#109>`_ `countdown`:idx: - `system.html#439 <system.html#439>`_ + `system.html#441 <system.html#441>`_ `countup`:idx: - `system.html#440 <system.html#440>`_ + `system.html#442 <system.html#442>`_ `cpuEndian`:idx: - `system.html#397 <system.html#397>`_ + `system.html#399 <system.html#399>`_ `createDir`:idx: * `os.html#138 <os.html#138>`_ @@ -711,16 +711,16 @@ Index `mysql.html#269 <mysql.html#269>`_ `cschar`:idx: - `system.html#376 <system.html#376>`_ + `system.html#378 <system.html#378>`_ `cshort`:idx: - `system.html#377 <system.html#377>`_ + `system.html#379 <system.html#379>`_ `cstring`:idx: `system.html#112 <system.html#112>`_ `cstringArray`:idx: - `system.html#384 <system.html#384>`_ + `system.html#386 <system.html#386>`_ `CSV`:idx: `parsecsv.html#101 <parsecsv.html#101>`_ @@ -1095,7 +1095,7 @@ Index `manual.html#176 <manual.html#176>`_ `dbgLineHook`:idx: - `system.html#435 <system.html#435>`_ + `system.html#437 <system.html#437>`_ `dd`:idx: `xmlgen.html#123 <xmlgen.html#123>`_ @@ -1104,7 +1104,7 @@ Index `nimrodc.html#114 <nimrodc.html#114>`_ `dealloc`:idx: - `system.html#416 <system.html#416>`_ + `system.html#418 <system.html#418>`_ `debugger`:idx: `nimrodc.html#110 <nimrodc.html#110>`_ @@ -1176,6 +1176,9 @@ Index `EAccessViolation`:idx: `system.html#143 <system.html#143>`_ + `each`:idx: + `system.html#463 <system.html#463>`_ + `EArithmetic`:idx: `system.html#140 <system.html#140>`_ @@ -1192,8 +1195,8 @@ Index `cgi.html#104 <cgi.html#104>`_ `echo`:idx: - * `system.html#475 <system.html#475>`_ - * `system.html#476 <system.html#476>`_ + * `system.html#478 <system.html#478>`_ + * `system.html#479 <system.html#479>`_ `ECMAScript`:idx: `nimrodc.html#115 <nimrodc.html#115>`_ @@ -1244,7 +1247,7 @@ Index `endb.html#102 <endb.html#102>`_ `EndOfFile`:idx: - * `system.html#490 <system.html#490>`_ + * `system.html#493 <system.html#493>`_ * `lexbase.html#101 <lexbase.html#101>`_ `endsWith`:idx: @@ -1260,12 +1263,12 @@ Index `enum_cursor_type`:idx: `mysql.html#237 <mysql.html#237>`_ - `Enumeration`:idx: - `manual.html#148 <manual.html#148>`_ - `enumeration`:idx: `tut1.html#113 <tut1.html#113>`_ + `Enumeration`:idx: + `manual.html#148 <manual.html#148>`_ + `enum_field_types`:idx: `mysql.html#202 <mysql.html#202>`_ @@ -1299,7 +1302,7 @@ Index `system.html#142 <system.html#142>`_ `equalMem`:idx: - `system.html#412 <system.html#412>`_ + `system.html#414 <system.html#414>`_ `EraseLine`:idx: `terminal.html#108 <terminal.html#108>`_ @@ -1506,7 +1509,7 @@ Index `mysql.html#218 <mysql.html#218>`_ `fileHandle`:idx: - `system.html#514 <system.html#514>`_ + `system.html#517 <system.html#517>`_ `fileNewer`:idx: `os.html#141 <os.html#141>`_ @@ -1524,7 +1527,7 @@ Index `manual.html#188 <manual.html#188>`_ `find`:idx: - * `system.html#459 <system.html#459>`_ + * `system.html#461 <system.html#461>`_ * `strutils.html#124 <strutils.html#124>`_ * `strutils.html#125 <strutils.html#125>`_ * `strutils.html#126 <strutils.html#126>`_ @@ -1554,7 +1557,7 @@ Index `macros.html#130 <macros.html#130>`_ `FlushFile`:idx: - `system.html#492 <system.html#492>`_ + `system.html#495 <system.html#495>`_ `for`:idx: * `manual.html#203 <manual.html#203>`_ @@ -1583,35 +1586,35 @@ Index `manual.html#198 <manual.html#198>`_ `GC_disable`:idx: - `system.html#461 <system.html#461>`_ + `system.html#464 <system.html#464>`_ `GC_disableMarkAndSweep`:idx: - `system.html#467 <system.html#467>`_ + `system.html#470 <system.html#470>`_ `GC_enable`:idx: - `system.html#462 <system.html#462>`_ + `system.html#465 <system.html#465>`_ `GC_enableMarkAndSweep`:idx: - `system.html#466 <system.html#466>`_ + `system.html#469 <system.html#469>`_ `GC_fullCollect`:idx: - `system.html#463 <system.html#463>`_ + `system.html#466 <system.html#466>`_ `GC_getStatistics`:idx: - `system.html#468 <system.html#468>`_ + `system.html#471 <system.html#471>`_ `GC_ref`:idx: - * `system.html#469 <system.html#469>`_ - * `system.html#470 <system.html#470>`_ - * `system.html#471 <system.html#471>`_ + * `system.html#472 <system.html#472>`_ + * `system.html#473 <system.html#473>`_ + * `system.html#474 <system.html#474>`_ `GC_setStrategy`:idx: - `system.html#465 <system.html#465>`_ + `system.html#468 <system.html#468>`_ `GC_unref`:idx: - * `system.html#472 <system.html#472>`_ - * `system.html#473 <system.html#473>`_ - * `system.html#474 <system.html#474>`_ + * `system.html#475 <system.html#475>`_ + * `system.html#476 <system.html#476>`_ + * `system.html#477 <system.html#477>`_ `generic character types`:idx: `regexprs.html#102 <regexprs.html#102>`_ @@ -1649,7 +1652,7 @@ Index `os.html#112 <os.html#112>`_ `getCurrentExceptionMsg`:idx: - `system.html#431 <system.html#431>`_ + `system.html#433 <system.html#433>`_ `getCurrentLine`:idx: `lexbase.html#106 <lexbase.html#106>`_ @@ -1668,13 +1671,13 @@ Index * `parsexml.html#119 <parsexml.html#119>`_ `getFilePos`:idx: - `system.html#512 <system.html#512>`_ + `system.html#515 <system.html#515>`_ `getFileSize`:idx: - `system.html#504 <system.html#504>`_ + `system.html#507 <system.html#507>`_ `getFreeMem`:idx: - `system.html#437 <system.html#437>`_ + `system.html#439 <system.html#439>`_ `getGatewayInterface`:idx: `cgi.html#113 <cgi.html#113>`_ @@ -1726,7 +1729,7 @@ Index `md5.html#106 <md5.html#106>`_ `getOccupiedMem`:idx: - `system.html#436 <system.html#436>`_ + `system.html#438 <system.html#438>`_ `getopt`:idx: `parseopt.html#106 <parseopt.html#106>`_ @@ -1741,7 +1744,7 @@ Index `cgi.html#125 <cgi.html#125>`_ `getRefcount`:idx: - `system.html#430 <system.html#430>`_ + `system.html#432 <system.html#432>`_ `getRemoteAddr`:idx: `cgi.html#126 <cgi.html#126>`_ @@ -1810,7 +1813,7 @@ Index `times.html#105 <times.html#105>`_ `getTotalMem`:idx: - `system.html#438 <system.html#438>`_ + `system.html#440 <system.html#440>`_ `get_tty_password`:idx: `mysql.html#282 <mysql.html#282>`_ @@ -1882,13 +1885,13 @@ Index * `macros.html#140 <macros.html#140>`_ `hostCPU`:idx: - `system.html#399 <system.html#399>`_ + `system.html#401 <system.html#401>`_ `HOSTNAME_LENGTH`:idx: `mysql.html#111 <mysql.html#111>`_ `hostOS`:idx: - `system.html#398 <system.html#398>`_ + `system.html#400 <system.html#400>`_ `hr`:idx: `xmlgen.html#140 <xmlgen.html#140>`_ @@ -1959,7 +1962,7 @@ Index `nimrodc.html#101 <nimrodc.html#101>`_ `in`:idx: - `system.html#355 <system.html#355>`_ + `system.html#357 <system.html#357>`_ `inc`:idx: `system.html#159 <system.html#159>`_ @@ -1974,7 +1977,7 @@ Index `manual.html#113 <manual.html#113>`_ `inf`:idx: - `system.html#432 <system.html#432>`_ + `system.html#434 <system.html#434>`_ `information hiding`:idx: * `manual.html#213 <manual.html#213>`_ @@ -2020,7 +2023,7 @@ Index `macros.html#129 <macros.html#129>`_ `is`:idx: - `system.html#357 <system.html#357>`_ + `system.html#359 <system.html#359>`_ `isAlpha`:idx: `unicode.html#111 <unicode.html#111>`_ @@ -2032,18 +2035,18 @@ Index `unicode.html#109 <unicode.html#109>`_ `isMainModule`:idx: - `system.html#390 <system.html#390>`_ + `system.html#392 <system.html#392>`_ `isNil`:idx: - * `system.html#447 <system.html#447>`_ - * `system.html#448 <system.html#448>`_ * `system.html#449 <system.html#449>`_ * `system.html#450 <system.html#450>`_ * `system.html#451 <system.html#451>`_ * `system.html#452 <system.html#452>`_ + * `system.html#453 <system.html#453>`_ + * `system.html#454 <system.html#454>`_ `is_not`:idx: - `system.html#358 <system.html#358>`_ + `system.html#360 <system.html#360>`_ `IS_NOT_NULL`:idx: `mysql.html#303 <mysql.html#303>`_ @@ -2073,12 +2076,12 @@ Index `mysql.html#255 <mysql.html#255>`_ `items`:idx: - * `system.html#441 <system.html#441>`_ - * `system.html#442 <system.html#442>`_ * `system.html#443 <system.html#443>`_ * `system.html#444 <system.html#444>`_ * `system.html#445 <system.html#445>`_ * `system.html#446 <system.html#446>`_ + * `system.html#447 <system.html#447>`_ + * `system.html#448 <system.html#448>`_ `iterator`:idx: `manual.html#204 <manual.html#204>`_ @@ -2149,7 +2152,7 @@ Index `nimrodc.html#107 <nimrodc.html#107>`_ `lines`:idx: - `system.html#513 <system.html#513>`_ + `system.html#516 <system.html#516>`_ `line_trace`:idx: `nimrodc.html#109 <nimrodc.html#109>`_ @@ -2235,12 +2238,13 @@ Index `nimrodc.html#118 <nimrodc.html#118>`_ `max`:idx: - * `system.html#271 <system.html#271>`_ * `system.html#272 <system.html#272>`_ * `system.html#273 <system.html#273>`_ * `system.html#274 <system.html#274>`_ * `system.html#275 <system.html#275>`_ - * `system.html#322 <system.html#322>`_ + * `system.html#276 <system.html#276>`_ + * `system.html#277 <system.html#277>`_ + * `system.html#324 <system.html#324>`_ `MAX_BIGINT_WIDTH`:idx: `mysql.html#194 <mysql.html#194>`_ @@ -2308,7 +2312,8 @@ Index * `system.html#268 <system.html#268>`_ * `system.html#269 <system.html#269>`_ * `system.html#270 <system.html#270>`_ - * `system.html#321 <system.html#321>`_ + * `system.html#271 <system.html#271>`_ + * `system.html#323 <system.html#323>`_ `mod`:idx: * `system.html#216 <system.html#216>`_ @@ -2328,7 +2333,7 @@ Index `os.html#135 <os.html#135>`_ `moveMem`:idx: - `system.html#411 <system.html#411>`_ + `system.html#413 <system.html#413>`_ `MULTIPLE_KEY_FLAG`:idx: `mysql.html#127 <mysql.html#127>`_ @@ -2848,13 +2853,13 @@ Index `mysql.html#110 <mysql.html#110>`_ `nan`:idx: - `system.html#434 <system.html#434>`_ + `system.html#436 <system.html#436>`_ `Natural`:idx: `system.html#129 <system.html#129>`_ `neginf`:idx: - `system.html#433 <system.html#433>`_ + `system.html#435 <system.html#435>`_ `nestList`:idx: `macros.html#152 <macros.html#152>`_ @@ -2933,7 +2938,7 @@ Index `system.html#161 <system.html#161>`_ `newString`:idx: - `system.html#408 <system.html#408>`_ + `system.html#410 <system.html#410>`_ `newStringStream`:idx: `streams.html#117 <streams.html#117>`_ @@ -2957,16 +2962,16 @@ Index `manual.html#169 <manual.html#169>`_ `NimrodMajor`:idx: - `system.html#394 <system.html#394>`_ + `system.html#396 <system.html#396>`_ `NimrodMinor`:idx: - `system.html#395 <system.html#395>`_ + `system.html#397 <system.html#397>`_ `NimrodPatch`:idx: - `system.html#396 <system.html#396>`_ + `system.html#398 <system.html#398>`_ `NimrodVersion`:idx: - `system.html#393 <system.html#393>`_ + `system.html#395 <system.html#395>`_ `nl`:idx: `strutils.html#108 <strutils.html#108>`_ @@ -2995,7 +3000,7 @@ Index * `system.html#195 <system.html#195>`_ `not_in`:idx: - `system.html#356 <system.html#356>`_ + `system.html#358 <system.html#358>`_ `NOT_NULL_FLAG`:idx: `mysql.html#124 <mysql.html#124>`_ @@ -3034,8 +3039,8 @@ Index * `system.html#125 <system.html#125>`_ `OpenFile`:idx: - * `system.html#487 <system.html#487>`_ - * `system.html#488 <system.html#488>`_ + * `system.html#490 <system.html#490>`_ + * `system.html#491 <system.html#491>`_ `operator`:idx: `manual.html#138 <manual.html#138>`_ @@ -3235,10 +3240,10 @@ Index `streams.html#118 <streams.html#118>`_ `PFloat32`:idx: - `system.html#386 <system.html#386>`_ + `system.html#388 <system.html#388>`_ `PFloat64`:idx: - `system.html#387 <system.html#387>`_ + `system.html#389 <system.html#389>`_ `Pgptr`:idx: `mysql.html#104 <mysql.html#104>`_ @@ -3250,10 +3255,10 @@ Index `parsexml.html#115 <parsexml.html#115>`_ `PInt32`:idx: - `system.html#389 <system.html#389>`_ + `system.html#391 <system.html#391>`_ `PInt64`:idx: - `system.html#388 <system.html#388>`_ + `system.html#390 <system.html#390>`_ `PIRest`:idx: `parsexml.html#116 <parsexml.html#116>`_ @@ -3338,7 +3343,7 @@ Index * `tut1.html#120 <tut1.html#120>`_ `pop`:idx: - `system.html#460 <system.html#460>`_ + `system.html#462 <system.html#462>`_ `Positive`:idx: `system.html#130 <system.html#130>`_ @@ -3489,14 +3494,14 @@ Index `xmlgen.html#160 <xmlgen.html#160>`_ `quit`:idx: - * `system.html#479 <system.html#479>`_ - * `system.html#480 <system.html#480>`_ + * `system.html#482 <system.html#482>`_ + * `system.html#483 <system.html#483>`_ `QuitFailure`:idx: - `system.html#478 <system.html#478>`_ + `system.html#481 <system.html#481>`_ `QuitSuccess`:idx: - `system.html#477 <system.html#477>`_ + `system.html#480 <system.html#480>`_ `quotation mark`:idx: `manual.html#128 <manual.html#128>`_ @@ -3526,23 +3531,23 @@ Index `streams.html#106 <streams.html#106>`_ `readBuffer`:idx: - `system.html#507 <system.html#507>`_ + `system.html#510 <system.html#510>`_ `ReadBytes`:idx: - `system.html#505 <system.html#505>`_ + `system.html#508 <system.html#508>`_ `readChar`:idx: - * `system.html#491 <system.html#491>`_ + * `system.html#494 <system.html#494>`_ * `streams.html#105 <streams.html#105>`_ `ReadChars`:idx: - `system.html#506 <system.html#506>`_ + `system.html#509 <system.html#509>`_ `readData`:idx: `cgi.html#108 <cgi.html#108>`_ `readFile`:idx: - `system.html#493 <system.html#493>`_ + `system.html#496 <system.html#496>`_ `readFloat32`:idx: `streams.html#111 <streams.html#111>`_ @@ -3563,7 +3568,7 @@ Index `streams.html#107 <streams.html#107>`_ `readLine`:idx: - * `system.html#501 <system.html#501>`_ + * `system.html#504 <system.html#504>`_ * `streams.html#114 <streams.html#114>`_ `readRow`:idx: @@ -3573,7 +3578,7 @@ Index `streams.html#113 <streams.html#113>`_ `realloc`:idx: - `system.html#415 <system.html#415>`_ + `system.html#417 <system.html#417>`_ `reBinary`:idx: `regexprs.html#116 <regexprs.html#116>`_ @@ -3661,7 +3666,7 @@ Index * `strutils.html#128 <strutils.html#128>`_ `repr`:idx: - `system.html#371 <system.html#371>`_ + `system.html#373 <system.html#373>`_ `ResetAttributes`:idx: `terminal.html#110 <terminal.html#110>`_ @@ -3742,7 +3747,7 @@ Index `system.html#126 <system.html#126>`_ `seqToPtr`:idx: - `system.html#457 <system.html#457>`_ + `system.html#459 <system.html#459>`_ `Sequences`:idx: * `manual.html#153 <manual.html#153>`_ @@ -3804,7 +3809,7 @@ Index `terminal.html#103 <terminal.html#103>`_ `setFilePos`:idx: - `system.html#511 <system.html#511>`_ + `system.html#514 <system.html#514>`_ `SET_FLAG`:idx: `mysql.html#135 <mysql.html#135>`_ @@ -3813,8 +3818,8 @@ Index `terminal.html#115 <terminal.html#115>`_ `setLen`:idx: - * `system.html#407 <system.html#407>`_ - * `system.html#417 <system.html#417>`_ + * `system.html#409 <system.html#409>`_ + * `system.html#419 <system.html#419>`_ `setTestData`:idx: `cgi.html#142 <cgi.html#142>`_ @@ -4401,13 +4406,13 @@ Index `manual.html#164 <manual.html#164>`_ `stderr`:idx: - `system.html#486 <system.html#486>`_ + `system.html#489 <system.html#489>`_ `stdin`:idx: - `system.html#484 <system.html#484>`_ + `system.html#487 <system.html#487>`_ `stdout`:idx: - `system.html#485 <system.html#485>`_ + `system.html#488 <system.html#488>`_ `st_dynamic_array`:idx: `mysql.html#339 <mysql.html#339>`_ @@ -4517,7 +4522,7 @@ Index `xmlgen.html#169 <xmlgen.html#169>`_ `swap`:idx: - `system.html#419 <system.html#419>`_ + `system.html#421 <system.html#421>`_ `symbol`:idx: `macros.html#125 <macros.html#125>`_ @@ -4538,7 +4543,7 @@ Index `manual.html#125 <manual.html#125>`_ `TAddress`:idx: - `system.html#372 <system.html#372>`_ + `system.html#374 <system.html#374>`_ `tan`:idx: `math.html#130 <math.html#130>`_ @@ -4751,19 +4756,19 @@ Index `manual.html#209 <manual.html#209>`_ `TEndian`:idx: - `system.html#385 <system.html#385>`_ + `system.html#387 <system.html#387>`_ `textarea`:idx: `xmlgen.html#173 <xmlgen.html#173>`_ `TFile`:idx: - `system.html#481 <system.html#481>`_ + `system.html#484 <system.html#484>`_ `TFileHandle`:idx: - `system.html#483 <system.html#483>`_ + `system.html#486 <system.html#486>`_ `TFileMode`:idx: - `system.html#482 <system.html#482>`_ + `system.html#485 <system.html#485>`_ `TFileStream`:idx: `streams.html#119 <streams.html#119>`_ @@ -4781,7 +4786,7 @@ Index `strtabs.html#111 <strtabs.html#111>`_ `TGC_Strategy`:idx: - `system.html#464 <system.html#464>`_ + `system.html#467 <system.html#467>`_ `th`:idx: `xmlgen.html#175 <xmlgen.html#175>`_ @@ -4826,10 +4831,10 @@ Index `macros.html#105 <macros.html#105>`_ `toBiggestFloat`:idx: - `system.html#401 <system.html#401>`_ + `system.html#403 <system.html#403>`_ `toBiggestInt`:idx: - `system.html#403 <system.html#403>`_ + `system.html#405 <system.html#405>`_ `toBin`:idx: `strutils.html#155 <strutils.html#155>`_ @@ -4838,13 +4843,13 @@ Index `system.html#131 <system.html#131>`_ `toFloat`:idx: - `system.html#400 <system.html#400>`_ + `system.html#402 <system.html#402>`_ `toHex`:idx: `strutils.html#142 <strutils.html#142>`_ `toInt`:idx: - `system.html#402 <system.html#402>`_ + `system.html#404 <system.html#404>`_ `toLower`:idx: * `strutils.html#115 <strutils.html#115>`_ @@ -5108,31 +5113,31 @@ Index `strutils.html#102 <strutils.html#102>`_ `write`:idx: - * `system.html#494 <system.html#494>`_ - * `system.html#495 <system.html#495>`_ - * `system.html#496 <system.html#496>`_ * `system.html#497 <system.html#497>`_ * `system.html#498 <system.html#498>`_ * `system.html#499 <system.html#499>`_ * `system.html#500 <system.html#500>`_ + * `system.html#501 <system.html#501>`_ + * `system.html#502 <system.html#502>`_ + * `system.html#503 <system.html#503>`_ * `streams.html#103 <streams.html#103>`_ * `streams.html#104 <streams.html#104>`_ `writeBuffer`:idx: - `system.html#510 <system.html#510>`_ + `system.html#513 <system.html#513>`_ `writeBytes`:idx: - `system.html#508 <system.html#508>`_ + `system.html#511 <system.html#511>`_ `writeChars`:idx: - `system.html#509 <system.html#509>`_ + `system.html#512 <system.html#512>`_ `writeContentType`:idx: `cgi.html#143 <cgi.html#143>`_ `writeln`:idx: - * `system.html#502 <system.html#502>`_ - * `system.html#503 <system.html#503>`_ + * `system.html#505 <system.html#505>`_ + * `system.html#506 <system.html#506>`_ `WriteStyled`:idx: `terminal.html#112 <terminal.html#112>`_ @@ -5172,4 +5177,4 @@ Index `mysql.html#130 <mysql.html#130>`_ `zeroMem`:idx: - `system.html#409 <system.html#409>`_ \ No newline at end of file + `system.html#411 <system.html#411>`_ \ No newline at end of file diff --git a/lib/arithm.nim b/lib/arithm.nim index b307daba3..a0e8e3338 100644 --- a/lib/arithm.nim +++ b/lib/arithm.nim @@ -117,7 +117,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc): mov eax, `a` add eax, `b` jno theEnd - call raiseOverflow + call `raiseOverflow` theEnd: """ @@ -126,7 +126,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc): mov eax, `a` sub eax, `b` jno theEnd - call raiseOverflow + call `raiseOverflow` theEnd: """ @@ -135,7 +135,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc): mov eax, `a` neg eax jno theEnd - call raiseOverflow + call `raiseOverflow` theEnd: """ @@ -146,7 +146,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc): xor edx, edx idiv ecx jno theEnd - call raiseOverflow + call `raiseOverflow` theEnd: """ @@ -157,7 +157,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc): xor edx, edx idiv ecx jno theEnd - call raiseOverflow + call `raiseOverflow` theEnd: mov eax, edx """ @@ -169,7 +169,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc): xor edx, edx imul ecx jno theEnd - call raiseOverflow + call `raiseOverflow` theEnd: """ diff --git a/lib/base/postgres.nim b/lib/base/postgres.nim new file mode 100644 index 000000000..c61edaa1e --- /dev/null +++ b/lib/base/postgres.nim @@ -0,0 +1,384 @@ +# This module contains the definitions for structures and externs for +# functions used by frontend postgres applications. It is based on +# Postgresql's libpq-fe.h. +# +# It is for postgreSQL version 7.4 and higher with support for the v3.0 +# connection-protocol +# + +when defined(windows): + const dllName = "pq.dll" +elif defined(macosx): + const dllName = "libpq.dylib" +else: + const dllName = "libpq.so" + +type + POid* = ptr Oid + Oid* = int32 + +const + ERROR_MSG_LENGTH* = 4096 + CMDSTATUS_LEN* = 40 + +type + TSockAddr* = array[1..112, int8] + TPGresAttDesc*{.pure, final.} = object + name*: cstring + adtid*: Oid + adtsize*: int + + PPGresAttDesc* = ptr TPGresAttDesc + PPPGresAttDesc* = ptr PPGresAttDesc + TPGresAttValue*{.pure, final.} = object + length*: int32 + value*: cstring + + PPGresAttValue* = ptr TPGresAttValue + PPPGresAttValue* = ptr PPGresAttValue + PExecStatusType* = ptr TExecStatusType + TExecStatusType* = enum + PGRES_EMPTY_QUERY = 0, PGRES_COMMAND_OK, PGRES_TUPLES_OK, PGRES_COPY_OUT, + PGRES_COPY_IN, PGRES_BAD_RESPONSE, PGRES_NONFATAL_ERROR, PGRES_FATAL_ERROR + TPGlobjfuncs*{.pure, final.} = object + fn_lo_open*: Oid + fn_lo_close*: Oid + fn_lo_creat*: Oid + fn_lo_unlink*: Oid + fn_lo_lseek*: Oid + fn_lo_tell*: Oid + fn_lo_read*: Oid + fn_lo_write*: Oid + + PPGlobjfuncs* = ptr TPGlobjfuncs + PConnStatusType* = ptr TConnStatusType + TConnStatusType* = enum + CONNECTION_OK, CONNECTION_BAD, CONNECTION_STARTED, CONNECTION_MADE, + CONNECTION_AWAITING_RESPONSE, CONNECTION_AUTH_OK, CONNECTION_SETENV, + CONNECTION_SSL_STARTUP, CONNECTION_NEEDED + TPGconn* {.pure, final.} = object + pghost*: cstring + pgtty*: cstring + pgport*: cstring + pgoptions*: cstring + dbName*: cstring + status*: TConnStatusType + errorMessage*: array[0..(ERROR_MSG_LENGTH) - 1, char] + Pfin*: TFile + Pfout*: TFile + Pfdebug*: TFile + sock*: int32 + laddr*: TSockAddr + raddr*: TSockAddr + salt*: array[0..(2) - 1, char] + asyncNotifyWaiting*: int32 + notifyList*: pointer + pguser*: cstring + pgpass*: cstring + lobjfuncs*: PPGlobjfuncs + + PPGconn* = ptr TPGconn + TPGresult* {.pure, final.} = object + ntups*: int32 + numAttributes*: int32 + attDescs*: PPGresAttDesc + tuples*: PPPGresAttValue + tupArrSize*: int32 + resultStatus*: TExecStatusType + cmdStatus*: array[0..(CMDSTATUS_LEN) - 1, char] + binary*: int32 + conn*: PPGconn + + PPGresult* = ptr TPGresult + PPostgresPollingStatusType* = ptr PostgresPollingStatusType + PostgresPollingStatusType* = enum + PGRES_POLLING_FAILED = 0, PGRES_POLLING_READING, PGRES_POLLING_WRITING, + PGRES_POLLING_OK, PGRES_POLLING_ACTIVE + PPGTransactionStatusType* = ptr PGTransactionStatusType + PGTransactionStatusType* = enum + PQTRANS_IDLE, PQTRANS_ACTIVE, PQTRANS_INTRANS, PQTRANS_INERROR, + PQTRANS_UNKNOWN + PPGVerbosity* = ptr PGVerbosity + PGVerbosity* = enum + PQERRORS_TERSE, PQERRORS_DEFAULT, PQERRORS_VERBOSE + PpgNotify* = ptr pgNotify + pgNotify* {.pure, final.} = object + relname*: cstring + be_pid*: int32 + extra*: cstring + + PQnoticeReceiver* = proc (arg: pointer, res: PPGresult){.cdecl.} + PQnoticeProcessor* = proc (arg: pointer, message: cstring){.cdecl.} + Ppqbool* = ptr pqbool + pqbool* = char + P_PQprintOpt* = ptr PQprintOpt + PQprintOpt* {.pure, final.} = object + header*: pqbool + align*: pqbool + standard*: pqbool + html3*: pqbool + expanded*: pqbool + pager*: pqbool + fieldSep*: cstring + tableOpt*: cstring + caption*: cstring + fieldName*: ptr cstring + + P_PQconninfoOption* = ptr PQconninfoOption + PQconninfoOption* {.pure, final.} = object + keyword*: cstring + envvar*: cstring + compiled*: cstring + val*: cstring + label*: cstring + dispchar*: cstring + dispsize*: int32 + + PPQArgBlock* = ptr PQArgBlock + PQArgBlock* {.pure, final.} = object + length*: int32 + isint*: int32 + p*: pointer + +proc PQconnectStart*(conninfo: cstring): PPGconn{.cdecl, dynlib: dllName, + importc: "PQconnectStart".} +proc PQconnectPoll*(conn: PPGconn): PostgresPollingStatusType{.cdecl, + dynlib: dllName, importc: "PQconnectPoll".} + +proc PQconnectdb*(conninfo: cstring): PPGconn{.cdecl, dynlib: dllName, + importc: "PQconnectdb".} +proc PQsetdbLogin*(pghost: cstring, pgport: cstring, pgoptions: cstring, + pgtty: cstring, dbName: cstring, login: cstring, pwd: cstring): PPGconn{. + cdecl, dynlib: dllName, importc: "PQsetdbLogin".} + +proc PQsetdb*(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME: cstring): ppgconn + +proc PQfinish*(conn: PPGconn){.cdecl, dynlib: dllName, importc: "PQfinish".} + +proc PQconndefaults*(): PPQconninfoOption{.cdecl, dynlib: dllName, + importc: "PQconndefaults".} + +proc PQconninfoFree*(connOptions: PPQconninfoOption){.cdecl, dynlib: dllName, + importc: "PQconninfoFree".} + +proc PQresetStart*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQresetStart".} +proc PQresetPoll*(conn: PPGconn): PostgresPollingStatusType{.cdecl, + dynlib: dllName, importc: "PQresetPoll".} + +proc PQreset*(conn: PPGconn){.cdecl, dynlib: dllName, importc: "PQreset".} + +proc PQrequestCancel*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQrequestCancel".} + +proc PQdb*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQdb".} +proc PQuser*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQuser".} +proc PQpass*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQpass".} +proc PQhost*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQhost".} +proc PQport*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQport".} +proc PQtty*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQtty".} +proc PQoptions*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, + importc: "PQoptions".} +proc PQstatus*(conn: PPGconn): TConnStatusType{.cdecl, dynlib: dllName, + importc: "PQstatus".} +proc PQtransactionStatus*(conn: PPGconn): PGTransactionStatusType{.cdecl, + dynlib: dllName, importc: "PQtransactionStatus".} +proc PQparameterStatus*(conn: PPGconn, paramName: cstring): cstring{.cdecl, + dynlib: dllName, importc: "PQparameterStatus".} +proc PQprotocolVersion*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQprotocolVersion".} +proc PQerrorMessage*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, + importc: "PQerrorMessage".} +proc PQsocket*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQsocket".} +proc PQbackendPID*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQbackendPID".} +proc PQclientEncoding*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQclientEncoding".} +proc PQsetClientEncoding*(conn: PPGconn, encoding: cstring): int32{.cdecl, + dynlib: dllName, importc: "PQsetClientEncoding".} +when defined(USE_SSL): + # Get the SSL structure associated with a connection + proc PQgetssl*(conn: PPGconn): PSSL{.cdecl, dynlib: dllName, + importc: "PQgetssl".} + +proc PQsetErrorVerbosity*(conn: PPGconn, verbosity: PGVerbosity): PGVerbosity{. + cdecl, dynlib: dllName, importc: "PQsetErrorVerbosity".} + +proc PQtrace*(conn: PPGconn, debug_port: TFile){.cdecl, dynlib: dllName, + importc: "PQtrace".} +proc PQuntrace*(conn: PPGconn){.cdecl, dynlib: dllName, importc: "PQuntrace".} + +proc PQsetNoticeReceiver*(conn: PPGconn, theProc: PQnoticeReceiver, + arg: pointer): PQnoticeReceiver {. + cdecl, dynlib: dllName, importc: "PQsetNoticeReceiver".} +proc PQsetNoticeProcessor*(conn: PPGconn, theProc: PQnoticeProcessor, + arg: pointer): PQnoticeProcessor{. + cdecl, dynlib: dllName, importc: "PQsetNoticeProcessor".} + +proc PQexec*(conn: PPGconn, query: cstring): PPGresult{.cdecl, dynlib: dllName, + importc: "PQexec".} +proc PQexecParams*(conn: PPGconn, command: cstring, nParams: int32, + paramTypes: POid, paramValues: cstringArray, + paramLengths, paramFormats: ptr int32, + resultFormat: int32): PPGresult {.cdecl, dynlib: dllName, + importc: "PQexecParams".} +proc PQexecPrepared*(conn: PPGconn, stmtName: cstring, nParams: int32, + paramValues: cstringArray, + paramLengths, paramFormats: ptr int32, + resultFormat: int32): PPGresult {. + cdecl, dynlib: dllName, importc: "PQexecPrepared".} + +proc PQsendQuery*(conn: PPGconn, query: cstring): int32{.cdecl, dynlib: dllName, + importc: "PQsendQuery".} +proc PQsendQueryParams*(conn: PPGconn, command: cstring, nParams: int32, + paramTypes: POid, paramValues: cstringArray, + paramLengths, paramFormats: ptr int32, + resultFormat: int32): int32 {.cdecl, dynlib: dllName, + importc: "PQsendQueryParams".} +proc PQsendQueryPrepared*(conn: PPGconn, stmtName: cstring, nParams: int32, + paramValues: cstringArray, + paramLengths, paramFormats: ptr int32, + resultFormat: int32): int32{. + cdecl, dynlib: dllName, importc: "PQsendQueryPrepared".} +proc PQgetResult*(conn: PPGconn): PPGresult{.cdecl, dynlib: dllName, + importc: "PQgetResult".} +proc PQisBusy*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQisBusy".} +proc PQconsumeInput*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQconsumeInput".} + +proc PQnotifies*(conn: PPGconn): PPGnotify{.cdecl, dynlib: dllName, + importc: "PQnotifies".} + +proc PQputCopyData*(conn: PPGconn, buffer: cstring, nbytes: int32): int32{. + cdecl, dynlib: dllName, importc: "PQputCopyData".} +proc PQputCopyEnd*(conn: PPGconn, errormsg: cstring): int32{.cdecl, + dynlib: dllName, importc: "PQputCopyEnd".} +proc PQgetCopyData*(conn: PPGconn, buffer: cstringArray, async: int32): int32{.cdecl, + dynlib: dllName, importc: "PQgetCopyData".} + +proc PQgetline*(conn: PPGconn, str: cstring, len: int32): int32{.cdecl, + dynlib: dllName, importc: "PQgetline".} +proc PQputline*(conn: PPGconn, str: cstring): int32{.cdecl, dynlib: dllName, + importc: "PQputline".} +proc PQgetlineAsync*(conn: PPGconn, buffer: cstring, bufsize: int32): int32{. + cdecl, dynlib: dllName, importc: "PQgetlineAsync".} +proc PQputnbytes*(conn: PPGconn, buffer: cstring, nbytes: int32): int32{.cdecl, + dynlib: dllName, importc: "PQputnbytes".} +proc PQendcopy*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQendcopy".} + +proc PQsetnonblocking*(conn: PPGconn, arg: int32): int32{.cdecl, + dynlib: dllName, importc: "PQsetnonblocking".} +proc PQisnonblocking*(conn: PPGconn): int32{.cdecl, dynlib: dllName, + importc: "PQisnonblocking".} + +proc PQflush*(conn: PPGconn): int32{.cdecl, dynlib: dllName, importc: "PQflush".} + +proc PQfn*(conn: PPGconn, fnid: int32, result_buf, + result_len: ptr int32, result_is_int: int32, args: PPQArgBlock, + nargs: int32): PPGresult{.cdecl, dynlib: dllName, importc: "PQfn".} + +proc PQresultStatus*(res: PPGresult): TExecStatusType{.cdecl, dynlib: dllName, + importc: "PQresultStatus".} +proc PQresStatus*(status: TExecStatusType): cstring{.cdecl, dynlib: dllName, + importc: "PQresStatus".} +proc PQresultErrorMessage*(res: PPGresult): cstring{.cdecl, dynlib: dllName, + importc: "PQresultErrorMessage".} +proc PQresultErrorField*(res: PPGresult, fieldcode: int32): cstring{.cdecl, + dynlib: dllName, importc: "PQresultErrorField".} +proc PQntuples*(res: PPGresult): int32{.cdecl, dynlib: dllName, + importc: "PQntuples".} +proc PQnfields*(res: PPGresult): int32{.cdecl, dynlib: dllName, + importc: "PQnfields".} +proc PQbinaryTuples*(res: PPGresult): int32{.cdecl, dynlib: dllName, + importc: "PQbinaryTuples".} +proc PQfname*(res: PPGresult, field_num: int32): cstring{.cdecl, + dynlib: dllName, importc: "PQfname".} +proc PQfnumber*(res: PPGresult, field_name: cstring): int32{.cdecl, + dynlib: dllName, importc: "PQfnumber".} +proc PQftable*(res: PPGresult, field_num: int32): Oid{.cdecl, dynlib: dllName, + importc: "PQftable".} +proc PQftablecol*(res: PPGresult, field_num: int32): int32{.cdecl, + dynlib: dllName, importc: "PQftablecol".} +proc PQfformat*(res: PPGresult, field_num: int32): int32{.cdecl, + dynlib: dllName, importc: "PQfformat".} +proc PQftype*(res: PPGresult, field_num: int32): Oid{.cdecl, dynlib: dllName, + importc: "PQftype".} +proc PQfsize*(res: PPGresult, field_num: int32): int32{.cdecl, dynlib: dllName, + importc: "PQfsize".} +proc PQfmod*(res: PPGresult, field_num: int32): int32{.cdecl, dynlib: dllName, + importc: "PQfmod".} +proc PQcmdStatus*(res: PPGresult): cstring{.cdecl, dynlib: dllName, + importc: "PQcmdStatus".} +proc PQoidStatus*(res: PPGresult): cstring{.cdecl, dynlib: dllName, + importc: "PQoidStatus".} + +proc PQoidValue*(res: PPGresult): Oid{.cdecl, dynlib: dllName, + importc: "PQoidValue".} + +proc PQcmdTuples*(res: PPGresult): cstring{.cdecl, dynlib: dllName, + importc: "PQcmdTuples".} +proc PQgetvalue*(res: PPGresult, tup_num: int32, field_num: int32): cstring{. + cdecl, dynlib: dllName, importc: "PQgetvalue".} +proc PQgetlength*(res: PPGresult, tup_num: int32, field_num: int32): int32{. + cdecl, dynlib: dllName, importc: "PQgetlength".} +proc PQgetisnull*(res: PPGresult, tup_num: int32, field_num: int32): int32{. + cdecl, dynlib: dllName, importc: "PQgetisnull".} + +proc PQclear*(res: PPGresult){.cdecl, dynlib: dllName, importc: "PQclear".} + +proc PQfreemem*(p: pointer){.cdecl, dynlib: dllName, importc: "PQfreemem".} + +proc PQmakeEmptyPGresult*(conn: PPGconn, status: TExecStatusType): PPGresult{. + cdecl, dynlib: dllName, importc: "PQmakeEmptyPGresult".} + +proc PQescapeString*(till, `from`: cstring, len: int): int{.cdecl, + dynlib: dllName, importc: "PQescapeString".} +proc PQescapeBytea*(bintext: cstring, binlen: int, + bytealen: var int): cstring{. + cdecl, dynlib: dllName, importc: "PQescapeBytea".} +proc PQunescapeBytea*(strtext: cstring, retbuflen: var int): cstring{.cdecl, + dynlib: dllName, importc: "PQunescapeBytea".} + +proc PQprint*(fout: TFile, res: PPGresult, ps: PPQprintOpt){.cdecl, + dynlib: dllName, importc: "PQprint".} + +proc PQdisplayTuples*(res: PPGresult, fp: TFile, fillAlign: int32, + fieldSep: cstring, printHeader: int32, quiet: int32){. + cdecl, dynlib: dllName, importc: "PQdisplayTuples".} + +proc PQprintTuples*(res: PPGresult, fout: TFile, printAttName: int32, + terseOutput: int32, width: int32){.cdecl, dynlib: dllName, + importc: "PQprintTuples".} + +proc lo_open*(conn: PPGconn, lobjId: Oid, mode: int32): int32{.cdecl, + dynlib: dllName, importc: "lo_open".} +proc lo_close*(conn: PPGconn, fd: int32): int32{.cdecl, dynlib: dllName, + importc: "lo_close".} +proc lo_read*(conn: PPGconn, fd: int32, buf: cstring, length: int): int32{. + cdecl, dynlib: dllName, importc: "lo_read".} +proc lo_write*(conn: PPGconn, fd: int32, buf: cstring, length: int): int32{. + cdecl, dynlib: dllName, importc: "lo_write".} +proc lo_lseek*(conn: PPGconn, fd: int32, offset: int32, whence: int32): int32{. + cdecl, dynlib: dllName, importc: "lo_lseek".} +proc lo_creat*(conn: PPGconn, mode: int32): Oid{.cdecl, dynlib: dllName, + importc: "lo_creat".} +proc lo_tell*(conn: PPGconn, fd: int32): int32{.cdecl, dynlib: dllName, + importc: "lo_tell".} +proc lo_unlink*(conn: PPGconn, lobjId: Oid): int32{.cdecl, dynlib: dllName, + importc: "lo_unlink".} +proc lo_import*(conn: PPGconn, filename: cstring): Oid{.cdecl, dynlib: dllName, + importc: "lo_import".} +proc lo_export*(conn: PPGconn, lobjId: Oid, filename: cstring): int32{.cdecl, + dynlib: dllName, importc: "lo_export".} + +proc PQmblen*(s: cstring, encoding: int32): int32{.cdecl, dynlib: dllName, + importc: "PQmblen".} + +proc PQenv2encoding*(): int32{.cdecl, dynlib: dllName, importc: "PQenv2encoding".} + +proc PQsetdb(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME: cstring): ppgconn = + result = PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, "", "") + diff --git a/lib/nimbase.h b/lib/nimbase.h index 5041edf63..e62ad7096 100644 --- a/lib/nimbase.h +++ b/lib/nimbase.h @@ -286,17 +286,7 @@ static unsigned long nimInf[2]={0xffffffff, 0x7fffffff}; #define NIM_NIL ((void*)0) /* C's NULL is fucked up in some C compilers, so the generated code does not rely on it anymore */ -#if defined(HAVE_STDINT_H) -# include <stdint.h> -typedef int8_t NI8; -typedef int16_t NI16; -typedef int32_t NI32; -typedef int64_t NI64; -typedef uint64_t NU64; -typedef uint8_t NU8; -typedef uint16_t NU16; -typedef uint32_t NU32; -#elif defined(__BORLANDC__) || defined(__DMC__) \ +#if defined(__BORLANDC__) || defined(__DMC__) \ || defined(__WATCOMC__) || defined(_MSC_VER) typedef signed char NI8; typedef signed short int NI16; @@ -307,6 +297,16 @@ typedef unsigned short int NU16; typedef unsigned __int64 NU64; typedef __int64 NI64; typedef unsigned int NU32; +#elif defined(HAVE_STDINT_H) +# include <stdint.h> +typedef int8_t NI8; +typedef int16_t NI16; +typedef int32_t NI32; +typedef int64_t NI64; +typedef uint64_t NU64; +typedef uint8_t NU8; +typedef uint16_t NU16; +typedef uint32_t NU32; #else typedef signed char NI8; typedef signed short int NI16; diff --git a/lib/system.nim b/lib/system.nim index ca7ef0bc6..3be233b50 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1488,6 +1488,11 @@ elif defined(NimrodVM): if x == y: return 0 if x < y: return -1 return 1 + + proc dealloc(p: pointer) = nil + proc alloc(size: int): pointer = nil + proc alloc0(size: int): pointer = nil + proc realloc(p: Pointer, newsize: int): pointer = nil {.pop.} # checks {.pop.} # hints diff --git a/nim/ast.pas b/nim/ast.pas index 0c3137b2b..aa83af4ed 100644 --- a/nim/ast.pas +++ b/nim/ast.pas @@ -1,70 +1,70 @@ -// -// -// The Nimrod Compiler -// (c) Copyright 2008 Andreas Rumpf -// -// See the file "copying.txt", included in this -// distribution, for details about the copyright. -// -unit ast; - -// abstract syntax tree + symbol table - -interface - -{$include 'config.inc'} - -uses - nsystem, charsets, msgs, nhashes, - nversion, options, strutils, crc, ropes, idents, lists; - -const - ImportTablePos = 0; - ModuleTablePos = 1; - -type - TCallingConvention = ( - ccDefault, // proc has no explicit calling convention - ccStdCall, // procedure is stdcall - ccCDecl, // cdecl - ccSafeCall, // safecall - ccSysCall, // system call - ccInline, // proc should be inlined - ccNoInline, // proc should not be inlined - ccFastCall, // fastcall (pass parameters in registers) - ccClosure, // proc has a closure - ccNoConvention // needed for generating proper C procs sometimes - ); - -const - CallingConvToStr: array [TCallingConvention] of string = ( - '', 'stdcall', 'cdecl', 'safecall', 'syscall', 'inline', 'noinline', - 'fastcall', 'closure', 'noconv'); - -(*[[[cog -def toEnum(name, elems, prefixlen=0): - body = "" - strs = "" - prefix = "" - counter = 0 - for e in elems: - if counter % 4 == 0: prefix = "\n " - else: prefix = "" - body = body + prefix + e + ', ' - strs = strs + prefix + "'%s', " % e[prefixlen:] - counter = counter + 1 - - return ("type\n T%s = (%s);\n T%ss = set of T%s;\n" - % (name, body[:-2], name, name), - "const\n %sToStr: array [T%s] of string = (%s);\n" - % (name, name, strs[:-2])) - -enums = eval(open("data/ast.yml").read()) -for key, val in enums.items(): - (a, b) = toEnum(key, val) - cog.out(a) - cog.out(b) -]]]*) +// +// +// The Nimrod Compiler +// (c) Copyright 2008 Andreas Rumpf +// +// See the file "copying.txt", included in this +// distribution, for details about the copyright. +// +unit ast; + +// abstract syntax tree + symbol table + +interface + +{$include 'config.inc'} + +uses + nsystem, charsets, msgs, nhashes, + nversion, options, strutils, crc, ropes, idents, lists; + +const + ImportTablePos = 0; + ModuleTablePos = 1; + +type + TCallingConvention = ( + ccDefault, // proc has no explicit calling convention + ccStdCall, // procedure is stdcall + ccCDecl, // cdecl + ccSafeCall, // safecall + ccSysCall, // system call + ccInline, // proc should be inlined + ccNoInline, // proc should not be inlined + ccFastCall, // fastcall (pass parameters in registers) + ccClosure, // proc has a closure + ccNoConvention // needed for generating proper C procs sometimes + ); + +const + CallingConvToStr: array [TCallingConvention] of string = ( + '', 'stdcall', 'cdecl', 'safecall', 'syscall', 'inline', 'noinline', + 'fastcall', 'closure', 'noconv'); + +(*[[[cog +def toEnum(name, elems, prefixlen=0): + body = "" + strs = "" + prefix = "" + counter = 0 + for e in elems: + if counter % 4 == 0: prefix = "\n " + else: prefix = "" + body = body + prefix + e + ', ' + strs = strs + prefix + "'%s', " % e[prefixlen:] + counter = counter + 1 + + return ("type\n T%s = (%s);\n T%ss = set of T%s;\n" + % (name, body[:-2], name, name), + "const\n %sToStr: array [T%s] of string = (%s);\n" + % (name, name, strs[:-2])) + +enums = eval(open("data/ast.yml").read()) +for key, val in enums.items(): + (a, b) = toEnum(key, val) + cog.out(a) + cog.out(b) +]]]*) type TNodeKind = ( nkNone, nkEmpty, nkIdent, nkSym, @@ -207,18 +207,18 @@ const 'skVar', 'skProc', 'skIterator', 'skConverter', 'skMacro', 'skTemplate', 'skField', 'skEnumField', 'skForVar', 'skModule', 'skLabel', 'skStub'); -{[[[end]]]} - -type - // symbols that require compiler magic: - TMagic = ( - //[[[cog - //magics = eval(open("data/magic.yml").read()) - //for i in range(0, len(magics)-1): - // cog.out("m" + magics[i] + ", ") - // if (i+1) % 6 == 0: cog.outl("") - //cog.outl("m" + magics[-1]) - //]]] +{[[[end]]]} + +type + // symbols that require compiler magic: + TMagic = ( + //[[[cog + //magics = eval(open("data/magic.yml").read()) + //for i in range(0, len(magics)-1): + // cog.out("m" + magics[i] + ", ") + // if (i+1) % 6 == 0: cog.outl("") + //cog.outl("m" + magics[-1]) + //]]] mNone, mDefined, mLow, mHigh, mSizeOf, mIs, mSucc, mPred, mInc, mDec, mOrd, mNew, mNewFinalize, mNewSeq, mRegisterFinalizer, mLengthOpenArray, mLengthStr, mLengthArray, @@ -257,227 +257,227 @@ type mNStrVal, mNSetIntVal, mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal, mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent, mIdentToStr, mEqIdent, mNHint, mNWarning, mNError - //[[[end]]] - ); - -type - PNode = ^TNode; - PNodePtr = ^{@ptr}PNode; - TNodeSeq = array of PNode; - - PType = ^TType; - PSym = ^TSym; - - TNode = {@ignore} record - typ: PType; - strVal: string; - comment: string; - sons: TNodeSeq; // else! - info: TLineInfo; - flags: TNodeFlags; - case Kind: TNodeKind of - nkCharLit, nkIntLit, nkInt8Lit, nkInt16Lit, nkInt32Lit, nkInt64Lit: - (intVal: biggestInt); - nkFloatLit, nkFloat32Lit, nkFloat64Lit: - (floatVal: biggestFloat); - nkSym: (sym: PSym); - nkIdent: (ident: PIdent); - nkMetaNode: (nodePtr: PNodePtr); - end; - {@emit - record // on a 32bit machine, this takes 32 bytes - typ: PType; - comment: string; - info: TLineInfo; - flags: TNodeFlags; - case Kind: TNodeKind of - nkCharLit..nkInt64Lit: - (intVal: biggestInt); - nkFloatLit..nkFloat64Lit: - (floatVal: biggestFloat); - nkStrLit..nkTripleStrLit: - (strVal: string); - nkSym: (sym: PSym); - nkIdent: (ident: PIdent); - nkMetaNode: (nodePtr: PNodePtr); - else (sons: TNodeSeq); - end acyclic; } - - TSymSeq = array of PSym; - TStrTable = object // a table[PIdent] of PSym - counter: int; - data: TSymSeq; - end; - -// -------------- backend information ------------------------------- - - TLocKind = ( - locNone, // no location - locTemp, // temporary location - locLocalVar, // location is a local variable - locGlobalVar, // location is a global variable - locParam, // location is a parameter - locField, // location is a record field - locArrayElem, // location is an array element - locExpr, // "location" is really an expression - locProc, // location is a proc (an address of a procedure) - locData, // location is a constant - locCall, // location is a call expression - locOther // location is something other - ); - - TLocFlag = ( - lfIndirect, // backend introduced a pointer - lfParamCopy, // backend introduced a parameter copy (LLVM) - lfNoDeepCopy, // no need for a deep copy - lfNoDecl, // do not declare it in C - lfDynamicLib, // link symbol to dynamic library - lfHeader // include header file for symbol - ); - - TStorageLoc = ( - OnUnknown, // location is unknown (stack, heap or static) - OnStack, // location is on hardware stack - OnHeap // location is on heap or global (reference counting needed) - ); - - TLocFlags = set of TLocFlag; - TLoc = record - k: TLocKind; // kind of location - s: TStorageLoc; - flags: TLocFlags; // location's flags - t: PType; // type of location - r: PRope; // rope value of location (code generators) - a: int; // location's "address", i.e. slot for temporaries - end; - -// ---------------- end of backend information ------------------------------ - TLibKind = (libHeader, libDynamic); - TLib = object(lists.TListEntry) // also misused for headers! - kind: TLibKind; - generated: bool; - // needed for the backends: - name: PRope; - path: string; - end; - PLib = ^TLib; - - TSym = object(TIdObj) // symbols are identical iff they have the same - // id! - kind: TSymKind; - magic: TMagic; - typ: PType; - name: PIdent; - info: TLineInfo; - owner: PSym; - flags: TSymFlags; - tab: TStrTable; // interface table for modules - ast: PNode; // syntax tree of proc, iterator, etc.: - // the whole proc including header; this is used - // for easy generation of proper error messages - // for variant record fields the discriminant - // expression - options: TOptions; - position: int; // used for many different things: - // for enum fields its position; - // for fields its offset - // for parameters its position - // for a conditional: - // 1 iff the symbol is defined, else 0 - // (or not in symbol table) - offset: int; // offset of record field - loc: TLoc; - annex: PLib; // additional fields (seldom used, so we use a - // reference to another object to safe space) - end; - - TTypeSeq = array of PType; - TType = object(TIdObj) // types are identical iff they have the - // same id; there may be multiple copies of a type - // in memory! - kind: TTypeKind; // kind of type - sons: TTypeSeq; // base types, etc. - n: PNode; // node for types: - // for range types a nkRange node - // for record types a nkRecord node - // for enum types a list of symbols - // else: unused - flags: TTypeFlags; // flags of the type - callConv: TCallingConvention; // for procs - owner: PSym; // the 'owner' of the type - sym: PSym; // types have the sym associated with them - // it is used for converting types to strings - size: BiggestInt; // the size of the type in bytes - // -1 means that the size is unkwown - align: int; // the type's alignment requirements - containerID: int; // used for type checking of generics - loc: TLoc; - end; - - // these are not part of the syntax tree, but nevertherless inherit from TNode - TPair = record - key, val: PObject; - end; - TPairSeq = array of TPair; - - TTable = record // the same as table[PObject] of PObject - counter: int; - data: TPairSeq; - end; - - TIdPair = record - key: PIdObj; - val: PObject; - end; - TIdPairSeq = array of TIdPair; - - TIdTable = record // the same as table[PIdent] of PObject - counter: int; - data: TIdPairSeq; - end; - - TIdNodePair = record - key: PIdObj; - val: PNode; - end; - TIdNodePairSeq = array of TIdNodePair; - - TIdNodeTable = record // the same as table[PIdObj] of PNode - counter: int; - data: TIdNodePairSeq; - end; - - TNodePair = record - h: THash; // because it is expensive to compute! - key: PNode; - val: int; - end; - TNodePairSeq = array of TNodePair; - - TNodeTable = record // the same as table[PNode] of int; - // nodes are compared by structure! - counter: int; - data: TNodePairSeq; - end; - - TObjectSeq = array of PObject; - - TObjectSet = record - counter: int; - data: TObjectSeq; - end; - -const - OverloadableSyms = {@set}[skProc, skIterator, skConverter]; - -const // "MagicToStr" array: - MagicToStr: array [TMagic] of string = ( - //[[[cog - //for i in range(0, len(magics)-1): - // cog.out("'%s', " % magics[i]) - // if (i+1) % 6 == 0: cog.outl("") - //cog.outl("'%s'" % magics[-1]) - //]]] + //[[[end]]] + ); + +type + PNode = ^TNode; + PNodePtr = ^{@ptr}PNode; + TNodeSeq = array of PNode; + + PType = ^TType; + PSym = ^TSym; + + TNode = {@ignore} record + typ: PType; + strVal: string; + comment: string; + sons: TNodeSeq; // else! + info: TLineInfo; + flags: TNodeFlags; + case Kind: TNodeKind of + nkCharLit, nkIntLit, nkInt8Lit, nkInt16Lit, nkInt32Lit, nkInt64Lit: + (intVal: biggestInt); + nkFloatLit, nkFloat32Lit, nkFloat64Lit: + (floatVal: biggestFloat); + nkSym: (sym: PSym); + nkIdent: (ident: PIdent); + nkMetaNode: (nodePtr: PNodePtr); + end; + {@emit + record // on a 32bit machine, this takes 32 bytes + typ: PType; + comment: string; + info: TLineInfo; + flags: TNodeFlags; + case Kind: TNodeKind of + nkCharLit..nkInt64Lit: + (intVal: biggestInt); + nkFloatLit..nkFloat64Lit: + (floatVal: biggestFloat); + nkStrLit..nkTripleStrLit: + (strVal: string); + nkSym: (sym: PSym); + nkIdent: (ident: PIdent); + nkMetaNode: (nodePtr: PNodePtr); + else (sons: TNodeSeq); + end acyclic; } + + TSymSeq = array of PSym; + TStrTable = object // a table[PIdent] of PSym + counter: int; + data: TSymSeq; + end; + +// -------------- backend information ------------------------------- + + TLocKind = ( + locNone, // no location + locTemp, // temporary location + locLocalVar, // location is a local variable + locGlobalVar, // location is a global variable + locParam, // location is a parameter + locField, // location is a record field + locArrayElem, // location is an array element + locExpr, // "location" is really an expression + locProc, // location is a proc (an address of a procedure) + locData, // location is a constant + locCall, // location is a call expression + locOther // location is something other + ); + + TLocFlag = ( + lfIndirect, // backend introduced a pointer + lfParamCopy, // backend introduced a parameter copy (LLVM) + lfNoDeepCopy, // no need for a deep copy + lfNoDecl, // do not declare it in C + lfDynamicLib, // link symbol to dynamic library + lfHeader // include header file for symbol + ); + + TStorageLoc = ( + OnUnknown, // location is unknown (stack, heap or static) + OnStack, // location is on hardware stack + OnHeap // location is on heap or global (reference counting needed) + ); + + TLocFlags = set of TLocFlag; + TLoc = record + k: TLocKind; // kind of location + s: TStorageLoc; + flags: TLocFlags; // location's flags + t: PType; // type of location + r: PRope; // rope value of location (code generators) + a: int; // location's "address", i.e. slot for temporaries + end; + +// ---------------- end of backend information ------------------------------ + TLibKind = (libHeader, libDynamic); + TLib = object(lists.TListEntry) // also misused for headers! + kind: TLibKind; + generated: bool; + // needed for the backends: + name: PRope; + path: string; + end; + PLib = ^TLib; + + TSym = object(TIdObj) // symbols are identical iff they have the same + // id! + kind: TSymKind; + magic: TMagic; + typ: PType; + name: PIdent; + info: TLineInfo; + owner: PSym; + flags: TSymFlags; + tab: TStrTable; // interface table for modules + ast: PNode; // syntax tree of proc, iterator, etc.: + // the whole proc including header; this is used + // for easy generation of proper error messages + // for variant record fields the discriminant + // expression + options: TOptions; + position: int; // used for many different things: + // for enum fields its position; + // for fields its offset + // for parameters its position + // for a conditional: + // 1 iff the symbol is defined, else 0 + // (or not in symbol table) + offset: int; // offset of record field + loc: TLoc; + annex: PLib; // additional fields (seldom used, so we use a + // reference to another object to safe space) + end; + + TTypeSeq = array of PType; + TType = object(TIdObj) // types are identical iff they have the + // same id; there may be multiple copies of a type + // in memory! + kind: TTypeKind; // kind of type + sons: TTypeSeq; // base types, etc. + n: PNode; // node for types: + // for range types a nkRange node + // for record types a nkRecord node + // for enum types a list of symbols + // else: unused + flags: TTypeFlags; // flags of the type + callConv: TCallingConvention; // for procs + owner: PSym; // the 'owner' of the type + sym: PSym; // types have the sym associated with them + // it is used for converting types to strings + size: BiggestInt; // the size of the type in bytes + // -1 means that the size is unkwown + align: int; // the type's alignment requirements + containerID: int; // used for type checking of generics + loc: TLoc; + end; + + // these are not part of the syntax tree, but nevertherless inherit from TNode + TPair = record + key, val: PObject; + end; + TPairSeq = array of TPair; + + TTable = record // the same as table[PObject] of PObject + counter: int; + data: TPairSeq; + end; + + TIdPair = record + key: PIdObj; + val: PObject; + end; + TIdPairSeq = array of TIdPair; + + TIdTable = record // the same as table[PIdent] of PObject + counter: int; + data: TIdPairSeq; + end; + + TIdNodePair = record + key: PIdObj; + val: PNode; + end; + TIdNodePairSeq = array of TIdNodePair; + + TIdNodeTable = record // the same as table[PIdObj] of PNode + counter: int; + data: TIdNodePairSeq; + end; + + TNodePair = record + h: THash; // because it is expensive to compute! + key: PNode; + val: int; + end; + TNodePairSeq = array of TNodePair; + + TNodeTable = record // the same as table[PNode] of int; + // nodes are compared by structure! + counter: int; + data: TNodePairSeq; + end; + + TObjectSeq = array of PObject; + + TObjectSet = record + counter: int; + data: TObjectSeq; + end; + +const + OverloadableSyms = {@set}[skProc, skIterator, skConverter]; + +const // "MagicToStr" array: + MagicToStr: array [TMagic] of string = ( + //[[[cog + //for i in range(0, len(magics)-1): + // cog.out("'%s', " % magics[i]) + // if (i+1) % 6 == 0: cog.outl("") + //cog.outl("'%s'" % magics[-1]) + //]]] 'None', 'Defined', 'Low', 'High', 'SizeOf', 'Is', 'Succ', 'Pred', 'Inc', 'Dec', 'Ord', 'New', 'NewFinalize', 'NewSeq', 'RegisterFinalizer', 'LengthOpenArray', 'LengthStr', 'LengthArray', @@ -516,892 +516,892 @@ const // "MagicToStr" array: 'NStrVal', 'NSetIntVal', 'NSetFloatVal', 'NSetSymbol', 'NSetIdent', 'NSetType', 'NSetStrVal', 'NNewNimNode', 'NCopyNimNode', 'NCopyNimTree', 'StrToIdent', 'IdentToStr', 'EqIdent', 'NHint', 'NWarning', 'NError' - //[[[end]]] - ); - -const - GenericTypes: TTypeKinds = {@set}[tyGeneric, tyGenericParam]; - - StructuralEquivTypes: TTypeKinds = {@set}[ - tyArrayConstr, tyNil, tyTuple, - tyArray, - tySet, - tyRange, - tyPtr, tyRef, - tyVar, - tySequence, - tyProc, tyOpenArray - ]; - - ConcreteTypes: TTypeKinds = {@set}[ - // types of the expr that may occur in:: - // var x = expr - tyBool, tyChar, tyEnum, tyArray, tyObject, tySet, tyTuple, - tyRange, tyPtr, tyRef, tyVar, tySequence, tyProc, - tyPointer, tyOpenArray, - tyString, tyCString, - tyInt..tyInt64, - tyFloat..tyFloat128 - ]; - ConstantDataTypes: TTypeKinds = {@set}[tyArray, tySet, tyTuple]; - ExportableSymKinds = {@set}[skVar, skConst, skProc, skType, - skIterator, skMacro, skTemplate, skConverter, - skStub]; - PersistentNodeFlags: TNodeFlags = {@set}[ - nfBase2, nfBase8, nfBase16, nfAllConst]; - namePos = 0; - genericParamsPos = 1; - paramsPos = 2; - pragmasPos = 3; - codePos = 4; - resultPos = 5; - -var - gId: int; - -function getID: int; -procedure setID(id: int); -procedure IDsynchronizationPoint(idRange: int); - -// creator procs: -function NewSym(symKind: TSymKind; Name: PIdent; owner: PSym): PSym; - -function NewType(kind: TTypeKind; owner: PSym): PType; overload; - -function newNode(kind: TNodeKind): PNode; -function newIntNode(kind: TNodeKind; const intVal: BiggestInt): PNode; -function newIntTypeNode(kind: TNodeKind; const intVal: BiggestInt; - typ: PType): PNode; -function newFloatNode(kind: TNodeKind; const floatVal: BiggestFloat): PNode; -function newStrNode(kind: TNodeKind; const strVal: string): PNode; -function newIdentNode(ident: PIdent; const info: TLineInfo): PNode; -function newSymNode(sym: PSym): PNode; -function newNodeI(kind: TNodeKind; const info: TLineInfo): PNode; -function newNodeIT(kind: TNodeKind; const info: TLineInfo; typ: PType): PNode; - -procedure initStrTable(out x: TStrTable); -procedure initTable(out x: TTable); -procedure initIdTable(out x: TIdTable); -procedure initObjectSet(out x: TObjectSet); -procedure initIdNodeTable(out x: TIdNodeTable); -procedure initNodeTable(out x: TNodeTable); - -// copy procs: -function copyType(t: PType; owner: PSym; keepId: bool): PType; -function copySym(s: PSym; keepId: bool = false): PSym; -procedure assignType(dest, src: PType); - -procedure copyStrTable(out dest: TStrTable; const src: TStrTable); -procedure copyTable(out dest: TTable; const src: TTable); -procedure copyObjectSet(out dest: TObjectSet; const src: TObjectSet); -procedure copyIdTable(var dest: TIdTable; const src: TIdTable); - -function sonsLen(n: PNode): int; overload; -function sonsLen(n: PType): int; overload; - -function lastSon(n: PNode): PNode; overload; -function lastSon(n: PType): PType; overload; -procedure newSons(father: PNode; len: int); overload; -procedure newSons(father: PType; len: int); overload; - -procedure addSon(father, son: PNode); overload; -procedure addSon(father, son: PType); overload; - -procedure addSonIfNotNil(father, n: PNode); -procedure delSon(father: PNode; idx: int); -function hasSonWith(n: PNode; kind: TNodeKind): boolean; -function hasSubnodeWith(n: PNode; kind: TNodeKind): boolean; -procedure replaceSons(n: PNode; oldKind, newKind: TNodeKind); -function sonsNotNil(n: PNode): bool; // for assertions - -function copyNode(src: PNode): PNode; -// does not copy its sons! - -function copyTree(src: PNode): PNode; -// does copy its sons! - -procedure discardSons(father: PNode); - -const // for all kind of hash tables: - GrowthFactor = 2; // must be power of 2, > 0 - StartSize = 8; // must be power of 2, > 0 - -function SameValue(a, b: PNode): Boolean; // a, b are literals -function leValue(a, b: PNode): Boolean; // a <= b? a, b are literals - -function ValueToString(a: PNode): string; - -// ------------- efficient integer sets ------------------------------------- -{@ignore} -type - TBitScalar = int32; // FPC produces wrong code for ``int`` -{@emit -type - TBitScalar = int; } - -const - InitIntSetSize = 8; // must be a power of two! - TrunkShift = 9; - BitsPerTrunk = 1 shl TrunkShift; - // needs to be a power of 2 and divisible by 64 - TrunkMask = BitsPerTrunk-1; - IntsPerTrunk = BitsPerTrunk div (sizeof(TBitScalar)*8); - IntShift = 5+ord(sizeof(TBitScalar)=8); // 5 or 6, depending on int width - IntMask = 1 shl IntShift -1; - -type - PTrunk = ^TTrunk; - TTrunk = record - next: PTrunk; // all nodes are connected with this pointer - key: int; // start address at bit 0 - bits: array [0..IntsPerTrunk-1] of TBitScalar; // a bit vector - end; - TTrunkSeq = array of PTrunk; - TIntSet = record - counter, max: int; - head: PTrunk; - data: TTrunkSeq; - end; - -function IntSetContains(const s: TIntSet; key: int): bool; -procedure IntSetIncl(var s: TIntSet; key: int); -procedure IntSetInit(var s: TIntSet); - -function IntSetContainsOrIncl(var s: TIntSet; key: int): bool; - - -const - debugIds = false; - -procedure registerID(id: PIdObj); - -implementation - -var - usedIds: TIntSet; - -procedure registerID(id: PIdObj); -begin - if debugIDs then - if (id.id = -1) or IntSetContainsOrIncl(usedIds, id.id) then - InternalError('ID already used: ' + toString(id.id)); -end; - -function getID: int; -begin - result := gId; - inc(gId) -end; - -procedure setId(id: int); -begin - gId := max(gId, id+1); -end; - -procedure IDsynchronizationPoint(idRange: int); -begin - gId := (gId div IdRange +1) * IdRange + 1; -end; - -function leValue(a, b: PNode): Boolean; // a <= b? -begin - result := false; - case a.kind of - nkCharLit..nkInt64Lit: - if b.kind in [nkCharLit..nkInt64Lit] then - result := a.intVal <= b.intVal; - nkFloatLit..nkFloat64Lit: - if b.kind in [nkFloatLit..nkFloat64Lit] then - result := a.floatVal <= b.floatVal; - nkStrLit..nkTripleStrLit: begin - if b.kind in [nkStrLit..nkTripleStrLit] then - result := a.strVal <= b.strVal; - end - else InternalError(a.info, 'leValue'); - end -end; - -function SameValue(a, b: PNode): Boolean; -begin - result := false; - case a.kind of - nkCharLit..nkInt64Lit: - if b.kind in [nkCharLit..nkInt64Lit] then - result := a.intVal = b.intVal; - nkFloatLit..nkFloat64Lit: - if b.kind in [nkFloatLit..nkFloat64Lit] then - result := a.floatVal = b.floatVal; - nkStrLit..nkTripleStrLit: begin - if b.kind in [nkStrLit..nkTripleStrLit] then - result := a.strVal = b.strVal; - end - else InternalError(a.info, 'SameValue'); - end -end; - -function ValueToString(a: PNode): string; -begin - case a.kind of - nkCharLit..nkInt64Lit: - result := ToString(a.intVal); - nkFloatLit, nkFloat32Lit, nkFloat64Lit: - result := toStringF(a.floatVal); - nkStrLit..nkTripleStrLit: - result := a.strVal; - else begin - InternalError(a.info, 'valueToString'); - result := '' - end - end -end; - -procedure copyStrTable(out dest: TStrTable; const src: TStrTable); -var - i: int; -begin - dest.counter := src.counter; -{@emit - if isNil(src.data) then exit; -} - setLength(dest.data, length(src.data)); - for i := 0 to high(src.data) do - dest.data[i] := src.data[i]; -end; - -procedure copyIdTable(var dest: TIdTable; const src: TIdTable); -var - i: int; -begin - dest.counter := src.counter; -{@emit - if isNil(src.data) then exit; -} -{@ignore} - setLength(dest.data, length(src.data)); -{@emit - newSeq(dest.data, length(src.data)); } - for i := 0 to high(src.data) do - dest.data[i] := src.data[i]; -end; - -procedure copyTable(out dest: TTable; const src: TTable); -var - i: int; -begin - dest.counter := src.counter; -{@emit - if isNil(src.data) then exit; -} - setLength(dest.data, length(src.data)); - for i := 0 to high(src.data) do - dest.data[i] := src.data[i]; -end; - -procedure copyObjectSet(out dest: TObjectSet; const src: TObjectSet); -var - i: int; -begin - dest.counter := src.counter; -{@emit - if isNil(src.data) then exit; -} - setLength(dest.data, length(src.data)); - for i := 0 to high(src.data) do - dest.data[i] := src.data[i]; -end; - -procedure discardSons(father: PNode); -begin - father.sons := nil; -end; - -function newNode(kind: TNodeKind): PNode; -begin - new(result); -{@ignore} - FillChar(result^, sizeof(result^), 0); -{@emit} - result.kind := kind; - //result.info := UnknownLineInfo(); inlined: - result.info.fileIndex := int32(-1); - result.info.col := int16(-1); - result.info.line := int16(-1); -end; - -function newIntNode(kind: TNodeKind; const intVal: BiggestInt): PNode; -begin - result := newNode(kind); - result.intVal := intVal -end; - -function newIntTypeNode(kind: TNodeKind; const intVal: BiggestInt; - typ: PType): PNode; -begin - result := newIntNode(kind, intVal); - result.typ := typ; -end; - -function newFloatNode(kind: TNodeKind; const floatVal: BiggestFloat): PNode; -begin - result := newNode(kind); - result.floatVal := floatVal -end; - -function newStrNode(kind: TNodeKind; const strVal: string): PNode; -begin - result := newNode(kind); - result.strVal := strVal -end; - -function newIdentNode(ident: PIdent; const info: TLineInfo): PNode; -begin - result := newNode(nkIdent); - result.ident := ident; - result.info := info; -end; - -function newSymNode(sym: PSym): PNode; -begin - result := newNode(nkSym); - result.sym := sym; - result.typ := sym.typ; - result.info := sym.info; -end; - -function newNodeI(kind: TNodeKind; const info: TLineInfo): PNode; -begin - result := newNode(kind); - result.info := info; -end; - -function newNodeIT(kind: TNodeKind; const info: TLineInfo; typ: PType): PNode; -begin - result := newNode(kind); - result.info := info; - result.typ := typ; -end; - -function NewType(kind: TTypeKind; owner: PSym): PType; overload; -begin - new(result); -{@ignore} - FillChar(result^, sizeof(result^), 0); -{@emit} - result.kind := kind; - result.owner := owner; - result.size := -1; - result.align := 2; // default alignment - result.id := getID(); - if debugIds then RegisterId(result); - //if result.id < 2000 then - // MessageOut(typeKindToStr[kind] +{&} ' has id: ' +{&} toString(result.id)); -end; - -procedure assignType(dest, src: PType); -var - i: int; -begin - dest.kind := src.kind; - dest.flags := src.flags; - dest.callConv := src.callConv; - dest.n := src.n; - dest.size := src.size; - dest.align := src.align; - dest.containerID := src.containerID; - newSons(dest, sonsLen(src)); - for i := 0 to sonsLen(src)-1 do - dest.sons[i] := src.sons[i]; -end; - -function copyType(t: PType; owner: PSym; keepId: bool): PType; -begin - result := newType(t.Kind, owner); - assignType(result, t); - if keepId then result.id := t.id - else begin - result.id := getID(); - if debugIds then RegisterId(result); - end; - result.sym := t.sym; - // backend-info should not be copied -end; - -function copySym(s: PSym; keepId: bool = false): PSym; -begin - result := newSym(s.kind, s.name, s.owner); - result.ast := nil; // BUGFIX; was: s.ast which made problems - result.info := s.info; - result.typ := s.typ; - if keepId then result.id := s.id - else begin - result.id := getID(); - if debugIds then RegisterId(result); - end; - result.flags := s.flags; - result.magic := s.magic; - copyStrTable(result.tab, s.tab); - result.options := s.options; - result.position := s.position; - result.loc := s.loc; - result.annex := s.annex; // BUGFIX -end; - -function NewSym(symKind: TSymKind; Name: PIdent; owner: PSym): PSym; -// generates a symbol and initializes the hash field too -begin - new(result); -{@ignore} - FillChar(result^, sizeof(result^), 0); -{@emit} - result.Name := Name; - result.Kind := symKind; - result.flags := {@set}[]; - result.info := UnknownLineInfo(); - result.options := gOptions; - result.owner := owner; - result.offset := -1; - result.id := getID(); - if debugIds then RegisterId(result); - //if result.id < 2000 then - // MessageOut(name.s +{&} ' has id: ' +{&} toString(result.id)); -end; - -procedure initStrTable(out x: TStrTable); -begin - x.counter := 0; -{@emit - newSeq(x.data, startSize); } -{@ignore} - setLength(x.data, startSize); - fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); -{@emit} -end; - -procedure initTable(out x: TTable); -begin - x.counter := 0; -{@emit - newSeq(x.data, startSize); } -{@ignore} - setLength(x.data, startSize); - fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); -{@emit} -end; - -procedure initIdTable(out x: TIdTable); -begin - x.counter := 0; -{@emit - newSeq(x.data, startSize); } -{@ignore} - setLength(x.data, startSize); - fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); -{@emit} -end; - -procedure initObjectSet(out x: TObjectSet); -begin - x.counter := 0; -{@emit - newSeq(x.data, startSize); } -{@ignore} - setLength(x.data, startSize); - fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); -{@emit} -end; - -procedure initIdNodeTable(out x: TIdNodeTable); -begin - x.counter := 0; -{@emit - newSeq(x.data, startSize); } -{@ignore} - setLength(x.data, startSize); - fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); -{@emit} -end; - -procedure initNodeTable(out x: TNodeTable); -begin - x.counter := 0; -{@emit - newSeq(x.data, startSize); } -{@ignore} - setLength(x.data, startSize); - fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); -{@emit} -end; - -function sonsLen(n: PType): int; -begin -{@ignore} - result := length(n.sons); -{@emit - if isNil(n.sons) then result := 0 - else result := length(n.sons); } -end; - -procedure newSons(father: PType; len: int); -var - i, L: int; -begin -{@emit - if isNil(father.sons) then father.sons := @[]; } - L := length(father.sons); - setLength(father.sons, L + len); -{@ignore} - for i := L to L+len-1 do father.sons[i] := nil // needed for FPC -{@emit} -end; - -procedure addSon(father, son: PType); -var - L: int; -begin -{@ignore} - L := length(father.sons); - setLength(father.sons, L+1); - father.sons[L] := son; -{@emit - if isNil(father.sons) then father.sons := @[]; } -{@emit add(father.sons, son); } -end; - -function sonsLen(n: PNode): int; -begin -{@ignore} - result := length(n.sons); -{@emit - if isNil(n.sons) then result := 0 - else result := length(n.sons); } -end; - -procedure newSons(father: PNode; len: int); -var - i, L: int; -begin -{@emit - if isNil(father.sons) then father.sons := @[]; } - L := length(father.sons); - setLength(father.sons, L + len); -{@ignore} - for i := L to L+len-1 do father.sons[i] := nil // needed for FPC -{@emit} -end; - -procedure addSon(father, son: PNode); -var - L: int; -begin -{@ignore} - L := length(father.sons); - setLength(father.sons, L+1); - father.sons[L] := son; -{@emit - if isNil(father.sons) then father.sons := @[]; } -{@emit add(father.sons, son); } -end; - -procedure delSon(father: PNode; idx: int); -var - len, i: int; -begin -{@emit - if isNil(father.sons) then exit; } - len := sonsLen(father); - for i := idx to len-2 do - father.sons[i] := father.sons[i+1]; - setLength(father.sons, len-1); -end; - -function copyNode(src: PNode): PNode; -// does not copy its sons! -begin - if src = nil then begin result := nil; exit end; - result := newNode(src.kind); - result.info := src.info; - result.typ := src.typ; - result.flags := src.flags * PersistentNodeFlags; - case src.Kind of - nkCharLit..nkInt64Lit: - result.intVal := src.intVal; - nkFloatLit, nkFloat32Lit, nkFloat64Lit: - result.floatVal := src.floatVal; - nkSym: - result.sym := src.sym; - nkIdent: - result.ident := src.ident; - nkStrLit..nkTripleStrLit: - result.strVal := src.strVal; - nkMetaNode: - result.nodePtr := src.nodePtr; - else begin end; - end; -end; - -function copyTree(src: PNode): PNode; -// copy a whole syntax tree; performs deep copying -var - i: int; -begin - if src = nil then begin result := nil; exit end; - result := newNode(src.kind); - result.info := src.info; - result.typ := src.typ; - result.flags := src.flags * PersistentNodeFlags; - case src.Kind of - nkCharLit..nkInt64Lit: - result.intVal := src.intVal; - nkFloatLit, nkFloat32Lit, nkFloat64Lit: - result.floatVal := src.floatVal; - nkSym: - result.sym := src.sym; - nkIdent: - result.ident := src.ident; - nkStrLit..nkTripleStrLit: - result.strVal := src.strVal; - nkMetaNode: - result.nodePtr := src.nodePtr; - else begin - result.sons := nil; - newSons(result, sonsLen(src)); - for i := 0 to sonsLen(src)-1 do - result.sons[i] := copyTree(src.sons[i]); - end; - end -end; - -function lastSon(n: PNode): PNode; -begin - result := n.sons[sonsLen(n)-1]; -end; - -function lastSon(n: PType): PType; -begin - result := n.sons[sonsLen(n)-1]; -end; - -function hasSonWith(n: PNode; kind: TNodeKind): boolean; -var - i: int; -begin - for i := 0 to sonsLen(n)-1 do begin - if (n.sons[i] <> nil) and (n.sons[i].kind = kind) then begin - result := true; exit - end - end; - result := false -end; - -function hasSubnodeWith(n: PNode; kind: TNodeKind): boolean; -var - i: int; -begin - case n.kind of - nkEmpty..nkNilLit: result := n.kind = kind; - else begin - for i := 0 to sonsLen(n)-1 do begin - if (n.sons[i] <> nil) and (n.sons[i].kind = kind) - or hasSubnodeWith(n.sons[i], kind) then begin - result := true; exit - end - end; - result := false - end - end -end; - -procedure replaceSons(n: PNode; oldKind, newKind: TNodeKind); -var - i: int; -begin - for i := 0 to sonsLen(n)-1 do - if n.sons[i].kind = oldKind then n.sons[i].kind := newKind -end; - -function sonsNotNil(n: PNode): bool; -var - i: int; -begin - for i := 0 to sonsLen(n)-1 do - if n.sons[i] = nil then begin result := false; exit end; - result := true -end; - -procedure addSonIfNotNil(father, n: PNode); -begin - if n <> nil then addSon(father, n) -end; - -// ---------------- efficient integer sets ---------------------------------- -// Same algorithm as the one the GC uses - -function mustRehash(len, counter: int): bool; -begin - assert(len > counter); - result := (len * 2 < counter * 3) or (len-counter < 4); -end; - -function nextTry(h, maxHash: THash): THash; -begin - result := ((5*h) + 1) and maxHash; - // For any initial h in range(maxHash), repeating that maxHash times - // generates each int in range(maxHash) exactly once (see any text on - // random-number generation for proof). -end; - -procedure IntSetInit(var s: TIntSet); -begin -{@ignore} - fillChar(s, sizeof(s), 0); -{@emit} -{@ignore} - setLength(s.data, InitIntSetSize); - fillChar(s.data[0], length(s.data)*sizeof(s.data[0]), 0); -{@emit - newSeq(s.data, InitIntSetSize); } - s.max := InitIntSetSize-1; - s.counter := 0; - s.head := nil -end; - -function IntSetGet(const t: TIntSet; key: int): PTrunk; -var - h: int; -begin - h := key and t.max; - while t.data[h] <> nil do begin - if t.data[h].key = key then begin - result := t.data[h]; exit - end; - h := nextTry(h, t.max) - end; - result := nil -end; - -procedure IntSetRawInsert(const t: TIntSet; var data: TTrunkSeq; desc: PTrunk); -var - h: int; -begin - h := desc.key and t.max; - while data[h] <> nil do begin - assert(data[h] <> desc); - h := nextTry(h, t.max) - end; - assert(data[h] = nil); - data[h] := desc -end; - -procedure IntSetEnlarge(var t: TIntSet); -var - n: TTrunkSeq; - i, oldMax: int; -begin - oldMax := t.max; - t.max := ((t.max+1)*2)-1; -{@ignore} - setLength(n, t.max + 1); - fillChar(n[0], length(n)*sizeof(n[0]), 0); -{@emit - newSeq(n, t.max+1); } - for i := 0 to oldmax do - if t.data[i] <> nil then - IntSetRawInsert(t, n, t.data[i]); -{@ignore} - t.data := n; -{@emit - swap(t.data, n); } -end; - -function IntSetPut(var t: TIntSet; key: int): PTrunk; -var - h: int; -begin - h := key and t.max; - while t.data[h] <> nil do begin - if t.data[h].key = key then begin - result := t.data[h]; exit - end; - h := nextTry(h, t.max) - end; - - if mustRehash(t.max+1, t.counter) then IntSetEnlarge(t); - inc(t.counter); - h := key and t.max; - while t.data[h] <> nil do h := nextTry(h, t.max); - assert(t.data[h] = nil); - new(result); -{@ignore} - fillChar(result^, sizeof(result^), 0); -{@emit} - result.next := t.head; - result.key := key; - t.head := result; - t.data[h] := result; -end; - -// ---------- slightly higher level procs ---------------------------------- - -function IntSetContains(const s: TIntSet; key: int): bool; -var - u: TBitScalar; - t: PTrunk; -begin - t := IntSetGet(s, shru(key, TrunkShift)); - if t <> nil then begin - u := key and TrunkMask; - result := (t.bits[shru(u, IntShift)] and shlu(1, u and IntMask)) <> 0 - end - else - result := false -end; - -procedure IntSetIncl(var s: TIntSet; key: int); -var - u: TBitScalar; - t: PTrunk; -begin - t := IntSetPut(s, shru(key, TrunkShift)); - u := key and TrunkMask; - t.bits[shru(u, IntShift)] := t.bits[shru(u, IntShift)] - or shlu(1, u and IntMask); -end; - -function IntSetContainsOrIncl(var s: TIntSet; key: int): bool; -var - u: TBitScalar; - t: PTrunk; -begin - t := IntSetGet(s, shru(key, TrunkShift)); - if t <> nil then begin - u := key and TrunkMask; - result := (t.bits[shru(u, IntShift)] and shlu(1, u and IntMask)) <> 0; - if not result then - t.bits[shru(u, IntShift)] := t.bits[shru(u, IntShift)] - or shlu(1, u and IntMask); - end - else begin - IntSetIncl(s, key); - result := false - end -end; -(* -procedure IntSetDebug(const s: TIntSet); -var - it: PTrunk; - i, j: int; -begin - it := s.head; - while it <> nil do begin - for i := 0 to high(it.bits) do - for j := 0 to BitsPerInt-1 do begin - if (it.bits[j] and (1 shl j)) <> 0 then - MessageOut('Contains key: ' + toString(it.key + i * BitsPerInt + j)); - end; - it := it.next - end -end;*) - -initialization - if debugIDs then IntSetInit(usedIds); -end. + //[[[end]]] + ); + +const + GenericTypes: TTypeKinds = {@set}[tyGeneric, tyGenericParam]; + + StructuralEquivTypes: TTypeKinds = {@set}[ + tyArrayConstr, tyNil, tyTuple, + tyArray, + tySet, + tyRange, + tyPtr, tyRef, + tyVar, + tySequence, + tyProc, tyOpenArray + ]; + + ConcreteTypes: TTypeKinds = {@set}[ + // types of the expr that may occur in:: + // var x = expr + tyBool, tyChar, tyEnum, tyArray, tyObject, tySet, tyTuple, + tyRange, tyPtr, tyRef, tyVar, tySequence, tyProc, + tyPointer, tyOpenArray, + tyString, tyCString, + tyInt..tyInt64, + tyFloat..tyFloat128 + ]; + ConstantDataTypes: TTypeKinds = {@set}[tyArray, tySet, tyTuple]; + ExportableSymKinds = {@set}[skVar, skConst, skProc, skType, + skIterator, skMacro, skTemplate, skConverter, + skStub]; + PersistentNodeFlags: TNodeFlags = {@set}[ + nfBase2, nfBase8, nfBase16, nfAllConst]; + namePos = 0; + genericParamsPos = 1; + paramsPos = 2; + pragmasPos = 3; + codePos = 4; + resultPos = 5; + +var + gId: int; + +function getID: int; +procedure setID(id: int); +procedure IDsynchronizationPoint(idRange: int); + +// creator procs: +function NewSym(symKind: TSymKind; Name: PIdent; owner: PSym): PSym; + +function NewType(kind: TTypeKind; owner: PSym): PType; overload; + +function newNode(kind: TNodeKind): PNode; +function newIntNode(kind: TNodeKind; const intVal: BiggestInt): PNode; +function newIntTypeNode(kind: TNodeKind; const intVal: BiggestInt; + typ: PType): PNode; +function newFloatNode(kind: TNodeKind; const floatVal: BiggestFloat): PNode; +function newStrNode(kind: TNodeKind; const strVal: string): PNode; +function newIdentNode(ident: PIdent; const info: TLineInfo): PNode; +function newSymNode(sym: PSym): PNode; +function newNodeI(kind: TNodeKind; const info: TLineInfo): PNode; +function newNodeIT(kind: TNodeKind; const info: TLineInfo; typ: PType): PNode; + +procedure initStrTable(out x: TStrTable); +procedure initTable(out x: TTable); +procedure initIdTable(out x: TIdTable); +procedure initObjectSet(out x: TObjectSet); +procedure initIdNodeTable(out x: TIdNodeTable); +procedure initNodeTable(out x: TNodeTable); + +// copy procs: +function copyType(t: PType; owner: PSym; keepId: bool): PType; +function copySym(s: PSym; keepId: bool = false): PSym; +procedure assignType(dest, src: PType); + +procedure copyStrTable(out dest: TStrTable; const src: TStrTable); +procedure copyTable(out dest: TTable; const src: TTable); +procedure copyObjectSet(out dest: TObjectSet; const src: TObjectSet); +procedure copyIdTable(var dest: TIdTable; const src: TIdTable); + +function sonsLen(n: PNode): int; overload; +function sonsLen(n: PType): int; overload; + +function lastSon(n: PNode): PNode; overload; +function lastSon(n: PType): PType; overload; +procedure newSons(father: PNode; len: int); overload; +procedure newSons(father: PType; len: int); overload; + +procedure addSon(father, son: PNode); overload; +procedure addSon(father, son: PType); overload; + +procedure addSonIfNotNil(father, n: PNode); +procedure delSon(father: PNode; idx: int); +function hasSonWith(n: PNode; kind: TNodeKind): boolean; +function hasSubnodeWith(n: PNode; kind: TNodeKind): boolean; +procedure replaceSons(n: PNode; oldKind, newKind: TNodeKind); +function sonsNotNil(n: PNode): bool; // for assertions + +function copyNode(src: PNode): PNode; +// does not copy its sons! + +function copyTree(src: PNode): PNode; +// does copy its sons! + +procedure discardSons(father: PNode); + +const // for all kind of hash tables: + GrowthFactor = 2; // must be power of 2, > 0 + StartSize = 8; // must be power of 2, > 0 + +function SameValue(a, b: PNode): Boolean; // a, b are literals +function leValue(a, b: PNode): Boolean; // a <= b? a, b are literals + +function ValueToString(a: PNode): string; + +// ------------- efficient integer sets ------------------------------------- +{@ignore} +type + TBitScalar = int32; // FPC produces wrong code for ``int`` +{@emit +type + TBitScalar = int; } + +const + InitIntSetSize = 8; // must be a power of two! + TrunkShift = 9; + BitsPerTrunk = 1 shl TrunkShift; + // needs to be a power of 2 and divisible by 64 + TrunkMask = BitsPerTrunk-1; + IntsPerTrunk = BitsPerTrunk div (sizeof(TBitScalar)*8); + IntShift = 5+ord(sizeof(TBitScalar)=8); // 5 or 6, depending on int width + IntMask = 1 shl IntShift -1; + +type + PTrunk = ^TTrunk; + TTrunk = record + next: PTrunk; // all nodes are connected with this pointer + key: int; // start address at bit 0 + bits: array [0..IntsPerTrunk-1] of TBitScalar; // a bit vector + end; + TTrunkSeq = array of PTrunk; + TIntSet = record + counter, max: int; + head: PTrunk; + data: TTrunkSeq; + end; + +function IntSetContains(const s: TIntSet; key: int): bool; +procedure IntSetIncl(var s: TIntSet; key: int); +procedure IntSetInit(var s: TIntSet); + +function IntSetContainsOrIncl(var s: TIntSet; key: int): bool; + + +const + debugIds = false; + +procedure registerID(id: PIdObj); + +implementation + +var + usedIds: TIntSet; + +procedure registerID(id: PIdObj); +begin + if debugIDs then + if (id.id = -1) or IntSetContainsOrIncl(usedIds, id.id) then + InternalError('ID already used: ' + toString(id.id)); +end; + +function getID: int; +begin + result := gId; + inc(gId) +end; + +procedure setId(id: int); +begin + gId := max(gId, id+1); +end; + +procedure IDsynchronizationPoint(idRange: int); +begin + gId := (gId div IdRange +1) * IdRange + 1; +end; + +function leValue(a, b: PNode): Boolean; // a <= b? +begin + result := false; + case a.kind of + nkCharLit..nkInt64Lit: + if b.kind in [nkCharLit..nkInt64Lit] then + result := a.intVal <= b.intVal; + nkFloatLit..nkFloat64Lit: + if b.kind in [nkFloatLit..nkFloat64Lit] then + result := a.floatVal <= b.floatVal; + nkStrLit..nkTripleStrLit: begin + if b.kind in [nkStrLit..nkTripleStrLit] then + result := a.strVal <= b.strVal; + end + else InternalError(a.info, 'leValue'); + end +end; + +function SameValue(a, b: PNode): Boolean; +begin + result := false; + case a.kind of + nkCharLit..nkInt64Lit: + if b.kind in [nkCharLit..nkInt64Lit] then + result := a.intVal = b.intVal; + nkFloatLit..nkFloat64Lit: + if b.kind in [nkFloatLit..nkFloat64Lit] then + result := a.floatVal = b.floatVal; + nkStrLit..nkTripleStrLit: begin + if b.kind in [nkStrLit..nkTripleStrLit] then + result := a.strVal = b.strVal; + end + else InternalError(a.info, 'SameValue'); + end +end; + +function ValueToString(a: PNode): string; +begin + case a.kind of + nkCharLit..nkInt64Lit: + result := ToString(a.intVal); + nkFloatLit, nkFloat32Lit, nkFloat64Lit: + result := toStringF(a.floatVal); + nkStrLit..nkTripleStrLit: + result := a.strVal; + else begin + InternalError(a.info, 'valueToString'); + result := '' + end + end +end; + +procedure copyStrTable(out dest: TStrTable; const src: TStrTable); +var + i: int; +begin + dest.counter := src.counter; +{@emit + if isNil(src.data) then exit; +} + setLength(dest.data, length(src.data)); + for i := 0 to high(src.data) do + dest.data[i] := src.data[i]; +end; + +procedure copyIdTable(var dest: TIdTable; const src: TIdTable); +var + i: int; +begin + dest.counter := src.counter; +{@emit + if isNil(src.data) then exit; +} +{@ignore} + setLength(dest.data, length(src.data)); +{@emit + newSeq(dest.data, length(src.data)); } + for i := 0 to high(src.data) do + dest.data[i] := src.data[i]; +end; + +procedure copyTable(out dest: TTable; const src: TTable); +var + i: int; +begin + dest.counter := src.counter; +{@emit + if isNil(src.data) then exit; +} + setLength(dest.data, length(src.data)); + for i := 0 to high(src.data) do + dest.data[i] := src.data[i]; +end; + +procedure copyObjectSet(out dest: TObjectSet; const src: TObjectSet); +var + i: int; +begin + dest.counter := src.counter; +{@emit + if isNil(src.data) then exit; +} + setLength(dest.data, length(src.data)); + for i := 0 to high(src.data) do + dest.data[i] := src.data[i]; +end; + +procedure discardSons(father: PNode); +begin + father.sons := nil; +end; + +function newNode(kind: TNodeKind): PNode; +begin + new(result); +{@ignore} + FillChar(result^, sizeof(result^), 0); +{@emit} + result.kind := kind; + //result.info := UnknownLineInfo(); inlined: + result.info.fileIndex := int32(-1); + result.info.col := int16(-1); + result.info.line := int16(-1); +end; + +function newIntNode(kind: TNodeKind; const intVal: BiggestInt): PNode; +begin + result := newNode(kind); + result.intVal := intVal +end; + +function newIntTypeNode(kind: TNodeKind; const intVal: BiggestInt; + typ: PType): PNode; +begin + result := newIntNode(kind, intVal); + result.typ := typ; +end; + +function newFloatNode(kind: TNodeKind; const floatVal: BiggestFloat): PNode; +begin + result := newNode(kind); + result.floatVal := floatVal +end; + +function newStrNode(kind: TNodeKind; const strVal: string): PNode; +begin + result := newNode(kind); + result.strVal := strVal +end; + +function newIdentNode(ident: PIdent; const info: TLineInfo): PNode; +begin + result := newNode(nkIdent); + result.ident := ident; + result.info := info; +end; + +function newSymNode(sym: PSym): PNode; +begin + result := newNode(nkSym); + result.sym := sym; + result.typ := sym.typ; + result.info := sym.info; +end; + +function newNodeI(kind: TNodeKind; const info: TLineInfo): PNode; +begin + result := newNode(kind); + result.info := info; +end; + +function newNodeIT(kind: TNodeKind; const info: TLineInfo; typ: PType): PNode; +begin + result := newNode(kind); + result.info := info; + result.typ := typ; +end; + +function NewType(kind: TTypeKind; owner: PSym): PType; overload; +begin + new(result); +{@ignore} + FillChar(result^, sizeof(result^), 0); +{@emit} + result.kind := kind; + result.owner := owner; + result.size := -1; + result.align := 2; // default alignment + result.id := getID(); + if debugIds then RegisterId(result); + //if result.id < 2000 then + // MessageOut(typeKindToStr[kind] +{&} ' has id: ' +{&} toString(result.id)); +end; + +procedure assignType(dest, src: PType); +var + i: int; +begin + dest.kind := src.kind; + dest.flags := src.flags; + dest.callConv := src.callConv; + dest.n := src.n; + dest.size := src.size; + dest.align := src.align; + dest.containerID := src.containerID; + newSons(dest, sonsLen(src)); + for i := 0 to sonsLen(src)-1 do + dest.sons[i] := src.sons[i]; +end; + +function copyType(t: PType; owner: PSym; keepId: bool): PType; +begin + result := newType(t.Kind, owner); + assignType(result, t); + if keepId then result.id := t.id + else begin + result.id := getID(); + if debugIds then RegisterId(result); + end; + result.sym := t.sym; + // backend-info should not be copied +end; + +function copySym(s: PSym; keepId: bool = false): PSym; +begin + result := newSym(s.kind, s.name, s.owner); + result.ast := nil; // BUGFIX; was: s.ast which made problems + result.info := s.info; + result.typ := s.typ; + if keepId then result.id := s.id + else begin + result.id := getID(); + if debugIds then RegisterId(result); + end; + result.flags := s.flags; + result.magic := s.magic; + copyStrTable(result.tab, s.tab); + result.options := s.options; + result.position := s.position; + result.loc := s.loc; + result.annex := s.annex; // BUGFIX +end; + +function NewSym(symKind: TSymKind; Name: PIdent; owner: PSym): PSym; +// generates a symbol and initializes the hash field too +begin + new(result); +{@ignore} + FillChar(result^, sizeof(result^), 0); +{@emit} + result.Name := Name; + result.Kind := symKind; + result.flags := {@set}[]; + result.info := UnknownLineInfo(); + result.options := gOptions; + result.owner := owner; + result.offset := -1; + result.id := getID(); + if debugIds then RegisterId(result); + //if result.id < 2000 then + // MessageOut(name.s +{&} ' has id: ' +{&} toString(result.id)); +end; + +procedure initStrTable(out x: TStrTable); +begin + x.counter := 0; +{@emit + newSeq(x.data, startSize); } +{@ignore} + setLength(x.data, startSize); + fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); +{@emit} +end; + +procedure initTable(out x: TTable); +begin + x.counter := 0; +{@emit + newSeq(x.data, startSize); } +{@ignore} + setLength(x.data, startSize); + fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); +{@emit} +end; + +procedure initIdTable(out x: TIdTable); +begin + x.counter := 0; +{@emit + newSeq(x.data, startSize); } +{@ignore} + setLength(x.data, startSize); + fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); +{@emit} +end; + +procedure initObjectSet(out x: TObjectSet); +begin + x.counter := 0; +{@emit + newSeq(x.data, startSize); } +{@ignore} + setLength(x.data, startSize); + fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); +{@emit} +end; + +procedure initIdNodeTable(out x: TIdNodeTable); +begin + x.counter := 0; +{@emit + newSeq(x.data, startSize); } +{@ignore} + setLength(x.data, startSize); + fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); +{@emit} +end; + +procedure initNodeTable(out x: TNodeTable); +begin + x.counter := 0; +{@emit + newSeq(x.data, startSize); } +{@ignore} + setLength(x.data, startSize); + fillChar(x.data[0], length(x.data)*sizeof(x.data[0]), 0); +{@emit} +end; + +function sonsLen(n: PType): int; +begin +{@ignore} + result := length(n.sons); +{@emit + if isNil(n.sons) then result := 0 + else result := length(n.sons); } +end; + +procedure newSons(father: PType; len: int); +var + i, L: int; +begin +{@emit + if isNil(father.sons) then father.sons := @[]; } + L := length(father.sons); + setLength(father.sons, L + len); +{@ignore} + for i := L to L+len-1 do father.sons[i] := nil // needed for FPC +{@emit} +end; + +procedure addSon(father, son: PType); +var + L: int; +begin +{@ignore} + L := length(father.sons); + setLength(father.sons, L+1); + father.sons[L] := son; +{@emit + if isNil(father.sons) then father.sons := @[]; } +{@emit add(father.sons, son); } +end; + +function sonsLen(n: PNode): int; +begin +{@ignore} + result := length(n.sons); +{@emit + if isNil(n.sons) then result := 0 + else result := length(n.sons); } +end; + +procedure newSons(father: PNode; len: int); +var + i, L: int; +begin +{@emit + if isNil(father.sons) then father.sons := @[]; } + L := length(father.sons); + setLength(father.sons, L + len); +{@ignore} + for i := L to L+len-1 do father.sons[i] := nil // needed for FPC +{@emit} +end; + +procedure addSon(father, son: PNode); +var + L: int; +begin +{@ignore} + L := length(father.sons); + setLength(father.sons, L+1); + father.sons[L] := son; +{@emit + if isNil(father.sons) then father.sons := @[]; } +{@emit add(father.sons, son); } +end; + +procedure delSon(father: PNode; idx: int); +var + len, i: int; +begin +{@emit + if isNil(father.sons) then exit; } + len := sonsLen(father); + for i := idx to len-2 do + father.sons[i] := father.sons[i+1]; + setLength(father.sons, len-1); +end; + +function copyNode(src: PNode): PNode; +// does not copy its sons! +begin + if src = nil then begin result := nil; exit end; + result := newNode(src.kind); + result.info := src.info; + result.typ := src.typ; + result.flags := src.flags * PersistentNodeFlags; + case src.Kind of + nkCharLit..nkInt64Lit: + result.intVal := src.intVal; + nkFloatLit, nkFloat32Lit, nkFloat64Lit: + result.floatVal := src.floatVal; + nkSym: + result.sym := src.sym; + nkIdent: + result.ident := src.ident; + nkStrLit..nkTripleStrLit: + result.strVal := src.strVal; + nkMetaNode: + result.nodePtr := src.nodePtr; + else begin end; + end; +end; + +function copyTree(src: PNode): PNode; +// copy a whole syntax tree; performs deep copying +var + i: int; +begin + if src = nil then begin result := nil; exit end; + result := newNode(src.kind); + result.info := src.info; + result.typ := src.typ; + result.flags := src.flags * PersistentNodeFlags; + case src.Kind of + nkCharLit..nkInt64Lit: + result.intVal := src.intVal; + nkFloatLit, nkFloat32Lit, nkFloat64Lit: + result.floatVal := src.floatVal; + nkSym: + result.sym := src.sym; + nkIdent: + result.ident := src.ident; + nkStrLit..nkTripleStrLit: + result.strVal := src.strVal; + nkMetaNode: + result.nodePtr := src.nodePtr; + else begin + result.sons := nil; + newSons(result, sonsLen(src)); + for i := 0 to sonsLen(src)-1 do + result.sons[i] := copyTree(src.sons[i]); + end; + end +end; + +function lastSon(n: PNode): PNode; +begin + result := n.sons[sonsLen(n)-1]; +end; + +function lastSon(n: PType): PType; +begin + result := n.sons[sonsLen(n)-1]; +end; + +function hasSonWith(n: PNode; kind: TNodeKind): boolean; +var + i: int; +begin + for i := 0 to sonsLen(n)-1 do begin + if (n.sons[i] <> nil) and (n.sons[i].kind = kind) then begin + result := true; exit + end + end; + result := false +end; + +function hasSubnodeWith(n: PNode; kind: TNodeKind): boolean; +var + i: int; +begin + case n.kind of + nkEmpty..nkNilLit: result := n.kind = kind; + else begin + for i := 0 to sonsLen(n)-1 do begin + if (n.sons[i] <> nil) and (n.sons[i].kind = kind) + or hasSubnodeWith(n.sons[i], kind) then begin + result := true; exit + end + end; + result := false + end + end +end; + +procedure replaceSons(n: PNode; oldKind, newKind: TNodeKind); +var + i: int; +begin + for i := 0 to sonsLen(n)-1 do + if n.sons[i].kind = oldKind then n.sons[i].kind := newKind +end; + +function sonsNotNil(n: PNode): bool; +var + i: int; +begin + for i := 0 to sonsLen(n)-1 do + if n.sons[i] = nil then begin result := false; exit end; + result := true +end; + +procedure addSonIfNotNil(father, n: PNode); +begin + if n <> nil then addSon(father, n) +end; + +// ---------------- efficient integer sets ---------------------------------- +// Same algorithm as the one the GC uses + +function mustRehash(len, counter: int): bool; +begin + assert(len > counter); + result := (len * 2 < counter * 3) or (len-counter < 4); +end; + +function nextTry(h, maxHash: THash): THash; +begin + result := ((5*h) + 1) and maxHash; + // For any initial h in range(maxHash), repeating that maxHash times + // generates each int in range(maxHash) exactly once (see any text on + // random-number generation for proof). +end; + +procedure IntSetInit(var s: TIntSet); +begin +{@ignore} + fillChar(s, sizeof(s), 0); +{@emit} +{@ignore} + setLength(s.data, InitIntSetSize); + fillChar(s.data[0], length(s.data)*sizeof(s.data[0]), 0); +{@emit + newSeq(s.data, InitIntSetSize); } + s.max := InitIntSetSize-1; + s.counter := 0; + s.head := nil +end; + +function IntSetGet(const t: TIntSet; key: int): PTrunk; +var + h: int; +begin + h := key and t.max; + while t.data[h] <> nil do begin + if t.data[h].key = key then begin + result := t.data[h]; exit + end; + h := nextTry(h, t.max) + end; + result := nil +end; + +procedure IntSetRawInsert(const t: TIntSet; var data: TTrunkSeq; desc: PTrunk); +var + h: int; +begin + h := desc.key and t.max; + while data[h] <> nil do begin + assert(data[h] <> desc); + h := nextTry(h, t.max) + end; + assert(data[h] = nil); + data[h] := desc +end; + +procedure IntSetEnlarge(var t: TIntSet); +var + n: TTrunkSeq; + i, oldMax: int; +begin + oldMax := t.max; + t.max := ((t.max+1)*2)-1; +{@ignore} + setLength(n, t.max + 1); + fillChar(n[0], length(n)*sizeof(n[0]), 0); +{@emit + newSeq(n, t.max+1); } + for i := 0 to oldmax do + if t.data[i] <> nil then + IntSetRawInsert(t, n, t.data[i]); +{@ignore} + t.data := n; +{@emit + swap(t.data, n); } +end; + +function IntSetPut(var t: TIntSet; key: int): PTrunk; +var + h: int; +begin + h := key and t.max; + while t.data[h] <> nil do begin + if t.data[h].key = key then begin + result := t.data[h]; exit + end; + h := nextTry(h, t.max) + end; + + if mustRehash(t.max+1, t.counter) then IntSetEnlarge(t); + inc(t.counter); + h := key and t.max; + while t.data[h] <> nil do h := nextTry(h, t.max); + assert(t.data[h] = nil); + new(result); +{@ignore} + fillChar(result^, sizeof(result^), 0); +{@emit} + result.next := t.head; + result.key := key; + t.head := result; + t.data[h] := result; +end; + +// ---------- slightly higher level procs ---------------------------------- + +function IntSetContains(const s: TIntSet; key: int): bool; +var + u: TBitScalar; + t: PTrunk; +begin + t := IntSetGet(s, shru(key, TrunkShift)); + if t <> nil then begin + u := key and TrunkMask; + result := (t.bits[shru(u, IntShift)] and shlu(1, u and IntMask)) <> 0 + end + else + result := false +end; + +procedure IntSetIncl(var s: TIntSet; key: int); +var + u: TBitScalar; + t: PTrunk; +begin + t := IntSetPut(s, shru(key, TrunkShift)); + u := key and TrunkMask; + t.bits[shru(u, IntShift)] := t.bits[shru(u, IntShift)] + or shlu(1, u and IntMask); +end; + +function IntSetContainsOrIncl(var s: TIntSet; key: int): bool; +var + u: TBitScalar; + t: PTrunk; +begin + t := IntSetGet(s, shru(key, TrunkShift)); + if t <> nil then begin + u := key and TrunkMask; + result := (t.bits[shru(u, IntShift)] and shlu(1, u and IntMask)) <> 0; + if not result then + t.bits[shru(u, IntShift)] := t.bits[shru(u, IntShift)] + or shlu(1, u and IntMask); + end + else begin + IntSetIncl(s, key); + result := false + end +end; +(* +procedure IntSetDebug(const s: TIntSet); +var + it: PTrunk; + i, j: int; +begin + it := s.head; + while it <> nil do begin + for i := 0 to high(it.bits) do + for j := 0 to BitsPerInt-1 do begin + if (it.bits[j] and (1 shl j)) <> 0 then + MessageOut('Contains key: ' + toString(it.key + i * BitsPerInt + j)); + end; + it := it.next + end +end;*) + +initialization + if debugIDs then IntSetInit(usedIds); +end. diff --git a/nim/ccgexprs.pas b/nim/ccgexprs.pas index 0bb7183e4..a7a364a52 100644 --- a/nim/ccgexprs.pas +++ b/nim/ccgexprs.pas @@ -2243,8 +2243,8 @@ begin end end; -// ---------------------- generation of complex constants ----------------- - +// ---------------------- generation of complex constants --------------------- +(* function transformRecordExpr(n: PNode): PNode; var i: int; @@ -2263,10 +2263,20 @@ begin field := lookupInRecord(t.n, field.name); if field = nil then InternalError(n.sons[i].info, 'transformRecordExpr: unknown field'); - if result.sons[field.position] <> nil then - InternalError(n.sons[i].info, 'transformRecordExpr: value twice'); + if result.sons[field.position] <> nil then begin + InternalError(n.sons[i].info, 'transformRecordExpr: value twice: ' + + renderTree(n.sons[i])); + end; result.sons[field.position] := copyTree(n.sons[i].sons[1]); end; +end; *) + +function genNamedConstExpr(p: BProc; n: PNode): PRope; +begin + if n.kind = nkExprColonExpr then + result := genConstExpr(p, n.sons[1]) + else + result := genConstExpr(p, n); end; function genConstSimpleList(p: BProc; n: PNode): PRope; @@ -2276,8 +2286,8 @@ begin len := sonsLen(n); result := toRope('{'+''); for i := 0 to len - 2 do - appf(result, '$1,$n', [genConstExpr(p, n.sons[i])]); - if len > 0 then app(result, genConstExpr(p, n.sons[len-1])); + appf(result, '$1,$n', [genNamedConstExpr(p, n.sons[i])]); + if len > 0 then app(result, genNamedConstExpr(p, n.sons[len-1])); app(result, '}' + tnl) end; @@ -2293,16 +2303,9 @@ begin toBitSet(n, cs); result := genRawSetData(cs, int(getSize(n.typ))) end; - nkBracket: begin + nkBracket, nkPar: begin // XXX: tySequence! result := genConstSimpleList(p, n); - end; - nkPar: begin - if hasSonWith(n, nkExprColonExpr) then - trans := transformRecordExpr(n) - else - trans := n; - result := genConstSimpleList(p, trans); end else begin // result := genLiteral(p, n) diff --git a/nim/ccgstmts.pas b/nim/ccgstmts.pas index f3fcdf518..6cff9dc8d 100644 --- a/nim/ccgstmts.pas +++ b/nim/ccgstmts.pas @@ -277,6 +277,7 @@ var i: int; sym: PSym; r, s: PRope; + a: TLoc; begin genLineDir(p, t); assert(t.kind = nkAsmStmt); @@ -286,13 +287,19 @@ begin nkStrLit..nkTripleStrLit: app(s, t.sons[i].strVal); nkSym: begin sym := t.sons[i].sym; - r := sym.loc.r; - if r = nil then begin // if no name has already been given, - // it doesn't matter much: - r := mangleName(sym); - sym.loc.r := r; // but be consequent! - end; - app(s, r) + if sym.kind = skProc then begin + initLocExpr(p, t.sons[i], a); + app(s, rdLoc(a)); + end + else begin + r := sym.loc.r; + if r = nil then begin // if no name has already been given, + // it doesn't matter much: + r := mangleName(sym); + sym.loc.r := r; // but be consequent! + end; + app(s, r) + end end else InternalError(t.sons[i].info, 'genAsmStmt()') diff --git a/nim/ccgtypes.pas b/nim/ccgtypes.pas index 600065078..28db6e009 100644 --- a/nim/ccgtypes.pas +++ b/nim/ccgtypes.pas @@ -612,11 +612,14 @@ begin IdTablePut(m.typeCache, t, con(result, '*'+'')); if not isImportedType(t) then begin useMagic(m, 'TGenericSeq'); - appf(m.s[cfsSeqTypes], - 'struct $2 {$n' + - ' TGenericSeq Sup;$n' + - ' $1 data[SEQ_DECL_SIZE];$n' + - '};$n', [getTypeDescAux(m, t.sons[0], check), result]); + if skipGeneric(t.sons[0]).kind <> tyEmpty then + appf(m.s[cfsSeqTypes], + 'struct $2 {$n' + + ' TGenericSeq Sup;$n' + + ' $1 data[SEQ_DECL_SIZE];$n' + + '};$n', [getTypeDescAux(m, t.sons[0], check), result]) + else + result := toRope('TGenericSeq') end; app(result, '*'+''); end; @@ -1018,6 +1021,7 @@ begin end; if dataGenerated then exit; case t.kind of + tyEmpty: result := toRope('0'+''); tyPointer, tyProc, tyBool, tyChar, tyCString, tyString, tyInt..tyFloat128, tyVar: genTypeInfoAuxBase(gmti, t, result, toRope('0'+'')); diff --git a/nim/msgs.pas b/nim/msgs.pas index 53e1b3388..d7f0d9f82 100644 --- a/nim/msgs.pas +++ b/nim/msgs.pas @@ -49,557 +49,557 @@ uses //cog.out(warns) //cog.out(hints) //]]] -type - TMsgKind = ( - errUnknown, - errIllFormedAstX, - errCannotOpenFile, - errInternal, - errGenerated, - errXCompilerDoesNotSupportCpp, - errStringLiteralExpected, - errIntLiteralExpected, - errInvalidCharacterConstant, - errClosingTripleQuoteExpected, - errClosingQuoteExpected, - errTabulatorsAreNotAllowed, - errInvalidToken, - errLineTooLong, - errInvalidNumber, - errNumberOutOfRange, - errNnotAllowedInCharacter, - errClosingBracketExpected, - errMissingFinalQuote, - errIdentifierExpected, - errOperatorExpected, - errTokenExpected, - errStringAfterIncludeExpected, - errRecursiveInclude, - errOnOrOffExpected, - errNoneSpeedOrSizeExpected, - errInvalidPragma, - errUnknownPragma, - errPragmaXHereNotAllowed, - errUnknownDirective, - errInvalidDirective, - errAtPopWithoutPush, - errEmptyAsm, - errAsgnInvalidInExpr, - errInvalidIndentation, - errExceptionExpected, - errExceptionAlreadyHandled, - errReturnNotAllowedHere, - errYieldNotAllowedHere, - errInvalidNumberOfYieldExpr, - errReturnInvalidInIterator, - errCannotReturnExpr, - errAttemptToRedefine, - errStmtInvalidAfterReturn, - errStmtExpected, - errInvalidLabel, - errInvalidCmdLineOption, - errCmdLineArgExpected, - errCmdLineNoArgExpected, - errInvalidVarSubstitution, - errUnknownVar, - errUnknownCcompiler, - errOnOrOffExpectedButXFound, - errNoneBoehmRefcExpectedButXFound, - errNoneSpeedOrSizeExpectedButXFound, - errGuiConsoleOrLibExpectedButXFound, - errUnknownOS, - errUnknownCPU, - errGenOutExpectedButXFound, - errArgsNeedRunOption, - errInvalidMultipleAsgn, - errColonOrEqualsExpected, - errExprExpected, - errUndeclaredIdentifier, - errUseQualifier, - errTwiceForwarded, - errTypeExpected, - errSystemNeeds, - errExecutionOfProgramFailed, - errNotOverloadable, - errInvalidArgForX, - errStmtHasNoEffect, - errXExpectsTypeOrValue, - errXExpectsArrayType, - errIteratorCannotBeInstantiated, - errExprWithNoTypeCannotBeConverted, - errExprWithNoTypeCannotBeCasted, - errConstantDivisionByZero, - errOrdinalTypeExpected, - errOrdinalOrFloatTypeExpected, - errOverOrUnderflow, - errCannotEvalXBecauseIncompletelyDefined, - errChrExpectsRange0_255, - errStaticAssertFailed, - errStaticAssertCannotBeEval, - errDotRequiresRecordOrObjectType, - errUndeclaredFieldX, - errNilAccess, - errIndexOutOfBounds, - errIndexTypesDoNotMatch, - errBracketsInvalidForType, - errValueOutOfSetBounds, - errFieldInitTwice, - errFieldNotInit, - errExprCannotBeCalled, - errExprHasNoType, - errExprXHasNoType, - errCastNotInSafeMode, - errExprCannotBeCastedToX, - errUndefinedPrefixOpr, - errCommaOrParRiExpected, - errCurlyLeOrParLeExpected, - errSectionExpected, - errImplemenationExpected, - errRangeExpected, - errInvalidTypeDescription, - errAttemptToRedefineX, - errMagicOnlyInSystem, - errUnknownOperatorX, - errPowerOfTwoExpected, - errStringMayNotBeEmpty, - errCallConvExpected, - errProcOnlyOneCallConv, - errSymbolMustBeImported, - errExprMustBeBool, - errConstExprExpected, - errDuplicateCaseLabel, - errRangeIsEmpty, - errSelectorMustBeOfCertainTypes, - errSelectorMustBeOrdinal, - errOrdXMustNotBeNegative, - errLenXinvalid, - errWrongNumberOfVariables, - errExprCannotBeRaised, - errBreakOnlyInLoop, - errTypeXhasUnknownSize, - errConstNeedsConstExpr, - errConstNeedsValue, - errResultCannotBeOpenArray, - errSizeTooBig, - errSetTooBig, - errBaseTypeMustBeOrdinal, - errInheritanceOnlyWithNonFinalObjects, - errInheritanceOnlyWithEnums, - errIllegalRecursionInTypeX, - errCannotInstantiateX, - errExprHasNoAddress, - errVarForOutParamNeeded, - errPureTypeMismatch, - errTypeMismatch, - errButExpected, - errButExpectedX, - errAmbigiousCallXYZ, - errWrongNumberOfTypeParams, - errOutParamNoDefaultValue, - errInlineProcHasNoAddress, - errXCannotBeInParamDecl, - errPragmaOnlyInHeaderOfProc, - errImportedProcCannotHaveImpl, - errImplOfXNotAllowed, - errImplOfXexpected, - errDiscardValue, - errInvalidDiscard, - errUnknownPrecedence, - errIllegalConvFromXtoY, - errTypeMismatchExpectedXGotY, - errCannotBindXTwice, - errInvalidOrderInEnumX, - errEnumXHasWholes, - errExceptExpected, - errInvalidTry, - errEofExpectedButXFound, - errOptionExpected, - errCannotEvaluateForwardConst, - errXisNoLabel, - errXNeedsConcreteType, - errNotAllCasesCovered, - errStringRange, - errUnkownSubstitionVar, - errComplexStmtRequiresInd, - errXisNotCallable, - errNoPragmasAllowedForX, - errNoGenericParamsAllowedForX, - errInvalidParamKindX, - errDefaultArgumentInvalid, - errNamedParamHasToBeIdent, - errNoReturnTypeForX, - errConvNeedsOneArg, - errInvalidPragmaX, - errXNotAllowedHere, - errInvalidControlFlowX, - errATypeHasNoValue, - errXisNoType, - errCircumNeedsPointer, - errInvalidContextForBuiltinX, - errInvalidExpression, - errInvalidExpressionX, - errEnumHasNoValueX, - errNamedExprExpected, - errNamedExprNotAllowed, - errXExpectsOneTypeParam, - errArrayExpectsTwoTypeParams, - errInvalidVisibilityX, - errInitHereNotAllowed, - errXCannotBeAssignedTo, - errIteratorNotAllowed, - errIteratorNeedsImplementation, - errIteratorNeedsReturnType, - errInvalidCommandX, - errXOnlyAtModuleScope, - errTypeXNeedsImplementation, - errTemplateInstantiationTooNested, - errInstantiationFrom, - errInvalidIndexValueForTuple, - errCommandExpectsFilename, - errXExpected, - errInvalidSectionStart, - errGridTableNotImplemented, - errGeneralParseError, - errNewSectionExpected, - errWhitespaceExpected, - errXisNoValidIndexFile, - errCannotRenderX, - errVarVarTypeNotAllowed, - errIsExpectsTwoArguments, - errIsExpectsObjectTypes, - errXcanNeverBeOfThisSubtype, - errTooManyIterations, - errCannotInterpretNodeX, - errFieldXNotFound, - errInvalidConversionFromTypeX, - errAssertionFailed, - errCannotGenerateCodeForX, - errXNeedsReturnType, - errXRequiresOneArgument, - errUnhandledExceptionX, - errCyclicTree, - errXisNoMacroOrTemplate, - errUser, - warnCannotOpenFile, - warnOctalEscape, - warnXIsNeverRead, - warnXmightNotBeenInit, - warnCannotWriteMO2, - warnCannotReadMO2, - warnDeprecated, - warnSmallLshouldNotBeUsed, - warnUnknownMagic, - warnRedefinitionOfLabel, - warnUnknownSubstitutionX, - warnLanguageXNotSupported, - warnCommentXIgnored, - warnUser, - hintSuccess, - hintSuccessX, - hintLineTooLong, - hintXDeclaredButNotUsed, - hintConvToBaseNotNeeded, - hintConvFromXtoItselfNotNeeded, - hintExprAlwaysX, - hintQuitCalled, - hintProcessing, - hintCodeBegin, - hintCodeEnd, - hintConf, - hintUser); - -const - MsgKindToStr: array [TMsgKind] of string = ( - 'unknown error', - 'illformed AST: $1', - 'cannot open ''$1''', - 'internal error: $1', - '$1', - '''$1'' compiler does not support C++', - 'string literal expected', - 'integer literal expected', - 'invalid character constant', - 'closing """ expected, but end of file reached', - 'closing " expected', - 'tabulators are not allowed', - 'invalid token: $1', - 'line too long', - '$1 is not a valid number', - 'number $1 out of valid range', - '\n not allowed in character literal', - 'closing '']'' expected, but end of file reached', - 'missing final ''', - 'identifier expected, but found ''$1''', - 'operator expected, but found ''$1''', - '''$1'' expected', - 'string after ''include'' expected', - 'recursive include file: ''$1''', - '''on'' or ''off'' expected', - '''none'', ''speed'' or ''size'' expected', - 'invalid pragma', - 'unknown pragma: ''$1''', - 'pragma ''$1'' here not allowed', - 'unknown directive: ''$1''', - 'invalid directive', - '''pop'' without a ''push'' pragma', - 'empty asm statement makes no sense', - '''='' invalid in an expression; probably ''=='' meant', - 'invalid indentation', - 'exception expected', - 'exception already handled', - '''return'' only allowed in routine', - '''yield'' only allowed in a loop of an iterator', - 'invalid number of ''yield'' expresions', - '''return'' not allowed in iterator', - 'current routine cannot return an expression', - 'attempt to redefine ''$1''', - 'statement not allowed after ''return'', ''break'' or ''raise''', - 'statement expected', - '''$1'' is no label', - 'invalid command line option: ''$1''', - 'argument for command line option expected: ''$1''', - 'invalid argument for command line option: ''$1''', - 'invalid variable substitution in ''$1''', - 'unknown variable: ''$1''', - 'unknown C compiler: ''$1''', - '''on'' or ''off'' expected, but ''$1'' found', - '''none'', ''boehm'' or ''refc'' expected, but ''$1'' found', - '''none'', ''speed'' or ''size'' expected, but ''$1'' found', - '''gui'', ''console'' or ''lib'' expected, but ''$1'' found', - 'unknown OS: ''$1''', - 'unknown CPU: ''$1''', - '''c'', ''c++'' or ''yaml'' expected, but ''$1'' found', - 'arguments can only be given if the ''--run'' option is selected', - 'multiple assignment is not allowed', - ''':'' or ''='' expected, but found ''$1''', - 'expression expected, but found ''$1''', - 'undeclared identifier: ''$1''', - 'ambigious identifier: ''$1'' -- use a qualifier', - '''$1'' is forwarded twice', - 'type expected', - 'system module needs ''$1''', - 'execution of an external program failed', - 'overloaded ''$1'' leads to ambigious calls', - 'invalid argument for ''$1''', - 'statement has no effect', - '''$1'' expects a type or value', - '''$1'' expects an array type', - '''$1'' cannot be instantiated because its body has not been compiled yet', - 'expression with no type cannot be converted', - 'expression with no type cannot be casted', - 'constant division by zero', - 'ordinal type expected', - 'ordinal or float type expected', - 'over- or underflow', - 'cannot evalutate ''$1'' because type is not defined completely', - '''chr'' expects an int in the range 0..255', - '''staticAssert'' failed: condition is false', - 'argument to ''staticAssert'' cannot be evaluated at compile time', - '''.'' requires a record or object type', - 'undeclared field: ''$1''', - 'attempt to access a nil address', - 'index out of bounds', - 'index types do not match', - '''[]'' operator invalid for this type', - 'value out of set bounds', - 'field initialized twice: ''$1''', - 'field ''$1'' not initialized', - 'expression cannot be called', - 'expression has no type', - 'expression ''$1'' has no type', - '''cast'' not allowed in safe mode', - 'expression cannot be casted to $1', - 'undefined prefix operator: $1', - ''','' or '')'' expected', - '''{'' or ''('' expected', - 'section (''type'', ''proc'', etc.) expected', - '''implementation'' or end of file expected', - 'range expected', - 'invalid type description', - 'attempt to redefine ''$1''', - '''magic'' only allowed in system module', - 'unkown operator: ''$1''', - 'power of two expected', - 'string literal may not be empty', - 'calling convention expected', - 'a proc can only have one calling convention', - 'symbol must be imported if ''lib'' pragma is used', - 'expression must be of type ''bool''', - 'constant expression expected', - 'duplicate case label', - 'range is empty', - 'selector must be of an ordinal type, real or string', - 'selector must be of an ordinal type', - 'ord($1) must not be negative', - 'len($1) must be less than 32768', - 'wrong number of variables', - 'only objects can be raised', - '''break'' only allowed in loop construct', - 'type ''$1'' has unknown size', - 'a constant can only be initialized with a constant expression', - 'a constant needs a value', - 'the result type cannot be on open array', - 'computing the type''s size produced an overflow', - 'set is too large', - 'base type of a set must be an ordinal', - 'inheritance only works with non-final objects', - 'inheritance only works with an enum', - 'illegal recursion in type ''$1''', - 'cannot instantiate: ''$1''', - 'expression has no address', - 'for a ''var'' type a variable needs to be passed', - 'type mismatch', - 'type mismatch: got (', - 'but expected one of: ', - 'but expected ''$1''', - 'ambigious call; both $1 and $2 match for: $3', - 'wrong number of type parameters', - 'out parameters cannot have default values', - 'an inline proc has no address', - '$1 cannot be declared in parameter declaration', - 'pragmas are only in the header of a proc allowed', - 'an imported proc cannot have an implementation', - 'implementation of ''$1'' is not allowed here', - 'implementation of ''$1'' expected', - 'value returned by statement has to be discarded', - 'statement returns no value that can be discarded', - 'unknown precedence for operator; use ''infix: prec'' pragma', - 'conversion from $1 to $2 is invalid', - 'type mismatch: expected ''$1'', but got ''$2''', - 'cannot bind parameter ''$1'' twice', - 'invalid order in enum ''$1''', - 'enum ''$1'' has wholes', - '''except'' or ''finally'' expected', - 'after catch all ''except'' or ''finally'' no section may follow', - 'end of file expected, but found token ''$1''', - 'option expected, but found ''$1''', - 'cannot evaluate forwarded constant', - '''$1'' is not a label', - '''$1'' needs to be of a non-generic type', - 'not all cases are covered', - 'string range in case statement not allowed', - 'unknown substitution variable: ''$1''', - 'complex statement requires indentation', - '''$1'' is not callable', - 'no pragmas allowed for $1', - 'no generic parameters allowed for $1', - 'invalid param kind: ''$1''', - 'default argument invalid', - 'named parameter has to be an identifier', - 'no return type for $1 allowed', - 'a type conversion needs exactly one argument', - 'invalid pragma: $1', - '$1 here not allowed', - 'invalid control flow: $1', - 'a type has no value', - 'invalid type: ''$1''', - '''^'' needs a pointer or reference type', - 'invalid context for builtin ''$1''', - 'invalid expression', - 'invalid expression: ''$1''', - 'enum has no value ''$1''', - 'named expression expected', - 'named expression here not allowed', - '''$1'' expects one type parameter', - 'array expects two type parameters', - 'invalid invisibility: ''$1''', - 'initialization here not allowed', - '''$1'' cannot be assigned to', - 'iterators can only be defined at the module''s top level', - 'iterator needs an implementation', - 'iterator needs a return type', - 'invalid command: ''$1''', - '''$1'' is only allowed at top level', - 'type ''$1'' needs an implementation', - 'template instantiation too nested', - 'instantiation from here', - 'invalid index value for tuple subscript', - 'command expects a filename argument', - '''$1'' expected', - 'invalid section start', - 'grid table is not implemented', - 'general parse error', - 'new section expected', - 'whitespace expected, got ''$1''', - '''$1'' is no valid index file', - 'cannot render reStructuredText element ''$1''', - 'type ''var var'' is not allowed', - '''is'' expects two arguments', - '''is'' expects object types', - '''$1'' can never be of this subtype', - 'interpretation requires too many iterations', - 'cannot interpret node kind ''$1''', - 'field ''$1'' cannot be found', - 'invalid conversion from type ''$1''', - 'assertion failed', - 'cannot generate code for ''$1''', - 'converter needs return type', - 'converter requires one parameter', - 'unhandled exception: $1', - 'macro returned a cyclic abstract syntax tree', - '''$1'' is no macro or template', - '$1', - 'cannot open ''$1'' [CannotOpenFile]', - 'octal escape sequences do not exist; leading zero is ignored [OctalEscape]', - '''$1'' is never read [XIsNeverRead]', - '''$1'' might not have been initialized [XmightNotBeenInit]', - 'cannot write file ''$1'' [CannotWriteMO2]', - 'cannot read file ''$1'' [CannotReadMO2]', - '''$1'' is deprecated [Deprecated]', - '''l'' should not be used as an identifier; may look like ''1'' (one) [SmallLshouldNotBeUsed]', - 'unknown magic ''$1'' might crash the compiler [UnknownMagic]', - 'redefinition of label ''$1'' [RedefinitionOfLabel]', - 'unknown substitution ''$1'' [UnknownSubstitutionX]', - 'language ''$1'' not supported [LanguageXNotSupported]', - 'comment ''$1'' ignored [CommentXIgnored]', - '$1 [User]', - 'operation successful [Success]', - 'operation successful ($1 lines compiled; $2 sec total) [SuccessX]', - 'line too long [LineTooLong]', - '''$1'' is declared but not used [XDeclaredButNotUsed]', - 'conversion to base object is not needed [ConvToBaseNotNeeded]', - 'conversion from $1 to itself is pointless [ConvFromXtoItselfNotNeeded]', - 'expression evaluates always to ''$1'' [ExprAlwaysX]', - 'quit() called [QuitCalled]', - 'processing $1 [Processing]', - 'generated code listing: [CodeBegin]', - 'end of listing [CodeEnd]', - 'used config file ''$1'' [Conf]', - '$1 [User]' - ); -const - WarningsToStr: array [0..13] of string = ( - 'CannotOpenFile', - 'OctalEscape', - 'XIsNeverRead', - 'XmightNotBeenInit', - 'CannotWriteMO2', - 'CannotReadMO2', - 'Deprecated', - 'SmallLshouldNotBeUsed', - 'UnknownMagic', - 'RedefinitionOfLabel', - 'UnknownSubstitutionX', - 'LanguageXNotSupported', - 'CommentXIgnored', - 'User' - ); -const - HintsToStr: array [0..12] of string = ( - 'Success', - 'SuccessX', - 'LineTooLong', - 'XDeclaredButNotUsed', - 'ConvToBaseNotNeeded', - 'ConvFromXtoItselfNotNeeded', - 'ExprAlwaysX', - 'QuitCalled', - 'Processing', - 'CodeBegin', - 'CodeEnd', - 'Conf', - 'User' - ); +type + TMsgKind = ( + errUnknown, + errIllFormedAstX, + errCannotOpenFile, + errInternal, + errGenerated, + errXCompilerDoesNotSupportCpp, + errStringLiteralExpected, + errIntLiteralExpected, + errInvalidCharacterConstant, + errClosingTripleQuoteExpected, + errClosingQuoteExpected, + errTabulatorsAreNotAllowed, + errInvalidToken, + errLineTooLong, + errInvalidNumber, + errNumberOutOfRange, + errNnotAllowedInCharacter, + errClosingBracketExpected, + errMissingFinalQuote, + errIdentifierExpected, + errOperatorExpected, + errTokenExpected, + errStringAfterIncludeExpected, + errRecursiveInclude, + errOnOrOffExpected, + errNoneSpeedOrSizeExpected, + errInvalidPragma, + errUnknownPragma, + errPragmaXHereNotAllowed, + errUnknownDirective, + errInvalidDirective, + errAtPopWithoutPush, + errEmptyAsm, + errAsgnInvalidInExpr, + errInvalidIndentation, + errExceptionExpected, + errExceptionAlreadyHandled, + errReturnNotAllowedHere, + errYieldNotAllowedHere, + errInvalidNumberOfYieldExpr, + errReturnInvalidInIterator, + errCannotReturnExpr, + errAttemptToRedefine, + errStmtInvalidAfterReturn, + errStmtExpected, + errInvalidLabel, + errInvalidCmdLineOption, + errCmdLineArgExpected, + errCmdLineNoArgExpected, + errInvalidVarSubstitution, + errUnknownVar, + errUnknownCcompiler, + errOnOrOffExpectedButXFound, + errNoneBoehmRefcExpectedButXFound, + errNoneSpeedOrSizeExpectedButXFound, + errGuiConsoleOrLibExpectedButXFound, + errUnknownOS, + errUnknownCPU, + errGenOutExpectedButXFound, + errArgsNeedRunOption, + errInvalidMultipleAsgn, + errColonOrEqualsExpected, + errExprExpected, + errUndeclaredIdentifier, + errUseQualifier, + errTwiceForwarded, + errTypeExpected, + errSystemNeeds, + errExecutionOfProgramFailed, + errNotOverloadable, + errInvalidArgForX, + errStmtHasNoEffect, + errXExpectsTypeOrValue, + errXExpectsArrayType, + errIteratorCannotBeInstantiated, + errExprWithNoTypeCannotBeConverted, + errExprWithNoTypeCannotBeCasted, + errConstantDivisionByZero, + errOrdinalTypeExpected, + errOrdinalOrFloatTypeExpected, + errOverOrUnderflow, + errCannotEvalXBecauseIncompletelyDefined, + errChrExpectsRange0_255, + errStaticAssertFailed, + errStaticAssertCannotBeEval, + errDotRequiresRecordOrObjectType, + errUndeclaredFieldX, + errNilAccess, + errIndexOutOfBounds, + errIndexTypesDoNotMatch, + errBracketsInvalidForType, + errValueOutOfSetBounds, + errFieldInitTwice, + errFieldNotInit, + errExprCannotBeCalled, + errExprHasNoType, + errExprXHasNoType, + errCastNotInSafeMode, + errExprCannotBeCastedToX, + errUndefinedPrefixOpr, + errCommaOrParRiExpected, + errCurlyLeOrParLeExpected, + errSectionExpected, + errImplemenationExpected, + errRangeExpected, + errInvalidTypeDescription, + errAttemptToRedefineX, + errMagicOnlyInSystem, + errUnknownOperatorX, + errPowerOfTwoExpected, + errStringMayNotBeEmpty, + errCallConvExpected, + errProcOnlyOneCallConv, + errSymbolMustBeImported, + errExprMustBeBool, + errConstExprExpected, + errDuplicateCaseLabel, + errRangeIsEmpty, + errSelectorMustBeOfCertainTypes, + errSelectorMustBeOrdinal, + errOrdXMustNotBeNegative, + errLenXinvalid, + errWrongNumberOfVariables, + errExprCannotBeRaised, + errBreakOnlyInLoop, + errTypeXhasUnknownSize, + errConstNeedsConstExpr, + errConstNeedsValue, + errResultCannotBeOpenArray, + errSizeTooBig, + errSetTooBig, + errBaseTypeMustBeOrdinal, + errInheritanceOnlyWithNonFinalObjects, + errInheritanceOnlyWithEnums, + errIllegalRecursionInTypeX, + errCannotInstantiateX, + errExprHasNoAddress, + errVarForOutParamNeeded, + errPureTypeMismatch, + errTypeMismatch, + errButExpected, + errButExpectedX, + errAmbigiousCallXYZ, + errWrongNumberOfTypeParams, + errOutParamNoDefaultValue, + errInlineProcHasNoAddress, + errXCannotBeInParamDecl, + errPragmaOnlyInHeaderOfProc, + errImportedProcCannotHaveImpl, + errImplOfXNotAllowed, + errImplOfXexpected, + errDiscardValue, + errInvalidDiscard, + errUnknownPrecedence, + errIllegalConvFromXtoY, + errTypeMismatchExpectedXGotY, + errCannotBindXTwice, + errInvalidOrderInEnumX, + errEnumXHasWholes, + errExceptExpected, + errInvalidTry, + errEofExpectedButXFound, + errOptionExpected, + errCannotEvaluateForwardConst, + errXisNoLabel, + errXNeedsConcreteType, + errNotAllCasesCovered, + errStringRange, + errUnkownSubstitionVar, + errComplexStmtRequiresInd, + errXisNotCallable, + errNoPragmasAllowedForX, + errNoGenericParamsAllowedForX, + errInvalidParamKindX, + errDefaultArgumentInvalid, + errNamedParamHasToBeIdent, + errNoReturnTypeForX, + errConvNeedsOneArg, + errInvalidPragmaX, + errXNotAllowedHere, + errInvalidControlFlowX, + errATypeHasNoValue, + errXisNoType, + errCircumNeedsPointer, + errInvalidContextForBuiltinX, + errInvalidExpression, + errInvalidExpressionX, + errEnumHasNoValueX, + errNamedExprExpected, + errNamedExprNotAllowed, + errXExpectsOneTypeParam, + errArrayExpectsTwoTypeParams, + errInvalidVisibilityX, + errInitHereNotAllowed, + errXCannotBeAssignedTo, + errIteratorNotAllowed, + errIteratorNeedsImplementation, + errIteratorNeedsReturnType, + errInvalidCommandX, + errXOnlyAtModuleScope, + errTypeXNeedsImplementation, + errTemplateInstantiationTooNested, + errInstantiationFrom, + errInvalidIndexValueForTuple, + errCommandExpectsFilename, + errXExpected, + errInvalidSectionStart, + errGridTableNotImplemented, + errGeneralParseError, + errNewSectionExpected, + errWhitespaceExpected, + errXisNoValidIndexFile, + errCannotRenderX, + errVarVarTypeNotAllowed, + errIsExpectsTwoArguments, + errIsExpectsObjectTypes, + errXcanNeverBeOfThisSubtype, + errTooManyIterations, + errCannotInterpretNodeX, + errFieldXNotFound, + errInvalidConversionFromTypeX, + errAssertionFailed, + errCannotGenerateCodeForX, + errXNeedsReturnType, + errXRequiresOneArgument, + errUnhandledExceptionX, + errCyclicTree, + errXisNoMacroOrTemplate, + errUser, + warnCannotOpenFile, + warnOctalEscape, + warnXIsNeverRead, + warnXmightNotBeenInit, + warnCannotWriteMO2, + warnCannotReadMO2, + warnDeprecated, + warnSmallLshouldNotBeUsed, + warnUnknownMagic, + warnRedefinitionOfLabel, + warnUnknownSubstitutionX, + warnLanguageXNotSupported, + warnCommentXIgnored, + warnUser, + hintSuccess, + hintSuccessX, + hintLineTooLong, + hintXDeclaredButNotUsed, + hintConvToBaseNotNeeded, + hintConvFromXtoItselfNotNeeded, + hintExprAlwaysX, + hintQuitCalled, + hintProcessing, + hintCodeBegin, + hintCodeEnd, + hintConf, + hintUser); + +const + MsgKindToStr: array [TMsgKind] of string = ( + 'unknown error', + 'illformed AST: $1', + 'cannot open ''$1''', + 'internal error: $1', + '$1', + '''$1'' compiler does not support C++', + 'string literal expected', + 'integer literal expected', + 'invalid character constant', + 'closing """ expected, but end of file reached', + 'closing " expected', + 'tabulators are not allowed', + 'invalid token: $1', + 'line too long', + '$1 is not a valid number', + 'number $1 out of valid range', + '\n not allowed in character literal', + 'closing '']'' expected, but end of file reached', + 'missing final ''', + 'identifier expected, but found ''$1''', + 'operator expected, but found ''$1''', + '''$1'' expected', + 'string after ''include'' expected', + 'recursive include file: ''$1''', + '''on'' or ''off'' expected', + '''none'', ''speed'' or ''size'' expected', + 'invalid pragma', + 'unknown pragma: ''$1''', + 'pragma ''$1'' here not allowed', + 'unknown directive: ''$1''', + 'invalid directive', + '''pop'' without a ''push'' pragma', + 'empty asm statement makes no sense', + '''='' invalid in an expression; probably ''=='' meant', + 'invalid indentation', + 'exception expected', + 'exception already handled', + '''return'' only allowed in routine', + '''yield'' only allowed in a loop of an iterator', + 'invalid number of ''yield'' expresions', + '''return'' not allowed in iterator', + 'current routine cannot return an expression', + 'attempt to redefine ''$1''', + 'statement not allowed after ''return'', ''break'' or ''raise''', + 'statement expected', + '''$1'' is no label', + 'invalid command line option: ''$1''', + 'argument for command line option expected: ''$1''', + 'invalid argument for command line option: ''$1''', + 'invalid variable substitution in ''$1''', + 'unknown variable: ''$1''', + 'unknown C compiler: ''$1''', + '''on'' or ''off'' expected, but ''$1'' found', + '''none'', ''boehm'' or ''refc'' expected, but ''$1'' found', + '''none'', ''speed'' or ''size'' expected, but ''$1'' found', + '''gui'', ''console'' or ''lib'' expected, but ''$1'' found', + 'unknown OS: ''$1''', + 'unknown CPU: ''$1''', + '''c'', ''c++'' or ''yaml'' expected, but ''$1'' found', + 'arguments can only be given if the ''--run'' option is selected', + 'multiple assignment is not allowed', + ''':'' or ''='' expected, but found ''$1''', + 'expression expected, but found ''$1''', + 'undeclared identifier: ''$1''', + 'ambigious identifier: ''$1'' -- use a qualifier', + '''$1'' is forwarded twice', + 'type expected', + 'system module needs ''$1''', + 'execution of an external program failed', + 'overloaded ''$1'' leads to ambigious calls', + 'invalid argument for ''$1''', + 'statement has no effect', + '''$1'' expects a type or value', + '''$1'' expects an array type', + '''$1'' cannot be instantiated because its body has not been compiled yet', + 'expression with no type cannot be converted', + 'expression with no type cannot be casted', + 'constant division by zero', + 'ordinal type expected', + 'ordinal or float type expected', + 'over- or underflow', + 'cannot evalutate ''$1'' because type is not defined completely', + '''chr'' expects an int in the range 0..255', + '''staticAssert'' failed: condition is false', + 'argument to ''staticAssert'' cannot be evaluated at compile time', + '''.'' requires a record or object type', + 'undeclared field: ''$1''', + 'attempt to access a nil address', + 'index out of bounds', + 'index types do not match', + '''[]'' operator invalid for this type', + 'value out of set bounds', + 'field initialized twice: ''$1''', + 'field ''$1'' not initialized', + 'expression cannot be called', + 'expression has no type', + 'expression ''$1'' has no type', + '''cast'' not allowed in safe mode', + 'expression cannot be casted to $1', + 'undefined prefix operator: $1', + ''','' or '')'' expected', + '''{'' or ''('' expected', + 'section (''type'', ''proc'', etc.) expected', + '''implementation'' or end of file expected', + 'range expected', + 'invalid type description', + 'attempt to redefine ''$1''', + '''magic'' only allowed in system module', + 'unkown operator: ''$1''', + 'power of two expected', + 'string literal may not be empty', + 'calling convention expected', + 'a proc can only have one calling convention', + 'symbol must be imported if ''lib'' pragma is used', + 'expression must be of type ''bool''', + 'constant expression expected', + 'duplicate case label', + 'range is empty', + 'selector must be of an ordinal type, real or string', + 'selector must be of an ordinal type', + 'ord($1) must not be negative', + 'len($1) must be less than 32768', + 'wrong number of variables', + 'only objects can be raised', + '''break'' only allowed in loop construct', + 'type ''$1'' has unknown size', + 'a constant can only be initialized with a constant expression', + 'a constant needs a value', + 'the result type cannot be on open array', + 'computing the type''s size produced an overflow', + 'set is too large', + 'base type of a set must be an ordinal', + 'inheritance only works with non-final objects', + 'inheritance only works with an enum', + 'illegal recursion in type ''$1''', + 'cannot instantiate: ''$1''', + 'expression has no address', + 'for a ''var'' type a variable needs to be passed', + 'type mismatch', + 'type mismatch: got (', + 'but expected one of: ', + 'but expected ''$1''', + 'ambigious call; both $1 and $2 match for: $3', + 'wrong number of type parameters', + 'out parameters cannot have default values', + 'an inline proc has no address', + '$1 cannot be declared in parameter declaration', + 'pragmas are only in the header of a proc allowed', + 'an imported proc cannot have an implementation', + 'implementation of ''$1'' is not allowed here', + 'implementation of ''$1'' expected', + 'value returned by statement has to be discarded', + 'statement returns no value that can be discarded', + 'unknown precedence for operator; use ''infix: prec'' pragma', + 'conversion from $1 to $2 is invalid', + 'type mismatch: expected ''$1'', but got ''$2''', + 'cannot bind parameter ''$1'' twice', + 'invalid order in enum ''$1''', + 'enum ''$1'' has wholes', + '''except'' or ''finally'' expected', + 'after catch all ''except'' or ''finally'' no section may follow', + 'end of file expected, but found token ''$1''', + 'option expected, but found ''$1''', + 'cannot evaluate forwarded constant', + '''$1'' is not a label', + '''$1'' needs to be of a non-generic type', + 'not all cases are covered', + 'string range in case statement not allowed', + 'unknown substitution variable: ''$1''', + 'complex statement requires indentation', + '''$1'' is not callable', + 'no pragmas allowed for $1', + 'no generic parameters allowed for $1', + 'invalid param kind: ''$1''', + 'default argument invalid', + 'named parameter has to be an identifier', + 'no return type for $1 allowed', + 'a type conversion needs exactly one argument', + 'invalid pragma: $1', + '$1 here not allowed', + 'invalid control flow: $1', + 'a type has no value', + 'invalid type: ''$1''', + '''^'' needs a pointer or reference type', + 'invalid context for builtin ''$1''', + 'invalid expression', + 'invalid expression: ''$1''', + 'enum has no value ''$1''', + 'named expression expected', + 'named expression here not allowed', + '''$1'' expects one type parameter', + 'array expects two type parameters', + 'invalid invisibility: ''$1''', + 'initialization here not allowed', + '''$1'' cannot be assigned to', + 'iterators can only be defined at the module''s top level', + 'iterator needs an implementation', + 'iterator needs a return type', + 'invalid command: ''$1''', + '''$1'' is only allowed at top level', + 'type ''$1'' needs an implementation', + 'template instantiation too nested', + 'instantiation from here', + 'invalid index value for tuple subscript', + 'command expects a filename argument', + '''$1'' expected', + 'invalid section start', + 'grid table is not implemented', + 'general parse error', + 'new section expected', + 'whitespace expected, got ''$1''', + '''$1'' is no valid index file', + 'cannot render reStructuredText element ''$1''', + 'type ''var var'' is not allowed', + '''is'' expects two arguments', + '''is'' expects object types', + '''$1'' can never be of this subtype', + 'interpretation requires too many iterations', + 'cannot interpret node kind ''$1''', + 'field ''$1'' cannot be found', + 'invalid conversion from type ''$1''', + 'assertion failed', + 'cannot generate code for ''$1''', + 'converter needs return type', + 'converter requires one parameter', + 'unhandled exception: $1', + 'macro returned a cyclic abstract syntax tree', + '''$1'' is no macro or template', + '$1', + 'cannot open ''$1'' [CannotOpenFile]', + 'octal escape sequences do not exist; leading zero is ignored [OctalEscape]', + '''$1'' is never read [XIsNeverRead]', + '''$1'' might not have been initialized [XmightNotBeenInit]', + 'cannot write file ''$1'' [CannotWriteMO2]', + 'cannot read file ''$1'' [CannotReadMO2]', + '''$1'' is deprecated [Deprecated]', + '''l'' should not be used as an identifier; may look like ''1'' (one) [SmallLshouldNotBeUsed]', + 'unknown magic ''$1'' might crash the compiler [UnknownMagic]', + 'redefinition of label ''$1'' [RedefinitionOfLabel]', + 'unknown substitution ''$1'' [UnknownSubstitutionX]', + 'language ''$1'' not supported [LanguageXNotSupported]', + 'comment ''$1'' ignored [CommentXIgnored]', + '$1 [User]', + 'operation successful [Success]', + 'operation successful ($1 lines compiled; $2 sec total) [SuccessX]', + 'line too long [LineTooLong]', + '''$1'' is declared but not used [XDeclaredButNotUsed]', + 'conversion to base object is not needed [ConvToBaseNotNeeded]', + 'conversion from $1 to itself is pointless [ConvFromXtoItselfNotNeeded]', + 'expression evaluates always to ''$1'' [ExprAlwaysX]', + 'quit() called [QuitCalled]', + '$1 [Processing]', + 'generated code listing: [CodeBegin]', + 'end of listing [CodeEnd]', + 'used config file ''$1'' [Conf]', + '$1 [User]' + ); +const + WarningsToStr: array [0..13] of string = ( + 'CannotOpenFile', + 'OctalEscape', + 'XIsNeverRead', + 'XmightNotBeenInit', + 'CannotWriteMO2', + 'CannotReadMO2', + 'Deprecated', + 'SmallLshouldNotBeUsed', + 'UnknownMagic', + 'RedefinitionOfLabel', + 'UnknownSubstitutionX', + 'LanguageXNotSupported', + 'CommentXIgnored', + 'User' + ); +const + HintsToStr: array [0..12] of string = ( + 'Success', + 'SuccessX', + 'LineTooLong', + 'XDeclaredButNotUsed', + 'ConvToBaseNotNeeded', + 'ConvFromXtoItselfNotNeeded', + 'ExprAlwaysX', + 'QuitCalled', + 'Processing', + 'CodeBegin', + 'CodeEnd', + 'Conf', + 'User' + ); //[[[end]]] const diff --git a/nim/semfold.pas b/nim/semfold.pas index fdbad9f4c..261e27fd5 100644 --- a/nim/semfold.pas +++ b/nim/semfold.pas @@ -540,32 +540,35 @@ begin case skipRange(n.typ).kind of tyInt..tyInt64: begin case skipRange(a.typ).kind of - tyFloat..tyFloat64: begin + tyFloat..tyFloat64: result := newIntNodeT(nsystem.toInt(getFloat(a)), n); - exit - end; - tyChar: begin + tyChar: result := newIntNodeT(getOrdValue(a), n); - exit - end; - else begin end + else begin + result := a; + result.typ := n.typ; + end end end; tyFloat..tyFloat64: begin case skipRange(a.typ).kind of - tyInt..tyInt64, tyEnum, tyBool, tyChar: begin + tyInt..tyInt64, tyEnum, tyBool, tyChar: result := newFloatNodeT(toFloat(int(getOrdValue(a))), n); - exit + else begin + result := a; + result.typ := n.typ; end - else begin end end end; - tyOpenArray: exit; - else begin end - end; - result := a; - result.typ := n.typ - end; + tyOpenArray, tyProc: begin end; + else begin + //n.sons[1] := a; + //result := n; + result := a; + result.typ := n.typ; + end + end + end else begin end end diff --git a/nim/sigmatch.pas b/nim/sigmatch.pas index ebcbb2529..5195de26c 100644 --- a/nim/sigmatch.pas +++ b/nim/sigmatch.pas @@ -1,7 +1,7 @@ // // // The Nimrod Compiler -// (c) Copyright 2008 Andreas Rumpf +// (c) Copyright 2009 Andreas Rumpf // // See the file "copying.txt", included in this // distribution, for details about the copyright. diff --git a/nim/transf.pas b/nim/transf.pas index c4ed5740c..476ee4c33 100644 --- a/nim/transf.pas +++ b/nim/transf.pas @@ -440,7 +440,10 @@ begin addSon(result, n.sons[1]); end else result := n.sons[1]; - end; + end; (* + tyArray, tySeq: begin + if skipGeneric(dest + end; *) tyGenericParam, tyAnyEnum: result := n.sons[1]; // happens sometimes for generated assignments, etc. else begin end @@ -450,8 +453,7 @@ end; function skipPassAsOpenArray(n: PNode): PNode; begin result := n; - while result.kind = nkPassAsOpenArray do - result := result.sons[0] + while result.kind = nkPassAsOpenArray do result := result.sons[0] end; type @@ -855,7 +857,7 @@ begin end end; cnst := getConstExpr(c.module, result); - if cnst <> nil then result := cnst; // do not miss an optimization + if cnst <> nil then result := cnst; // do not miss an optimization end; function processTransf(context: PPassContext; n: PNode): PNode; |