nimrod compiles again
This commit is contained in:
parent
281609c358
commit
3710309d39
5 changed files with 28 additions and 16 deletions
|
|
@ -2276,7 +2276,7 @@ top-level symbols that are marked with an asterisk (``*``) are exported.
|
||||||
|
|
||||||
The algorithm for compiling modules is:
|
The algorithm for compiling modules is:
|
||||||
|
|
||||||
- Compile the whole module as usual, following import statements recursively
|
- compile the whole module as usual, following import statements recursively
|
||||||
- if there is a cycle only import the already parsed symbols (that are
|
- if there is a cycle only import the already parsed symbols (that are
|
||||||
exported); if an unknown identifier occurs then abort
|
exported); if an unknown identifier occurs then abort
|
||||||
|
|
||||||
|
|
@ -2408,6 +2408,11 @@ time only. No code will be generated for it. Compile time procs are useful
|
||||||
as helpers for macros.
|
as helpers for macros.
|
||||||
|
|
||||||
|
|
||||||
|
noReturn pragma
|
||||||
|
---------------
|
||||||
|
The `noreturn`:idx: pragma is used to mark a proc that it never returns.
|
||||||
|
|
||||||
|
|
||||||
error pragma
|
error pragma
|
||||||
------------
|
------------
|
||||||
The `error`:idx: pragma is used to make the compiler output an error message
|
The `error`:idx: pragma is used to make the compiler output an error message
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
## This module contains various string utility routines.
|
## This module contains various string utility routines.
|
||||||
## See the module `regexprs` for regular expression support.
|
## See the module `regexprs` for regular expression support.
|
||||||
## All the routines here are avaiable for the EMCAScript target too!
|
|
||||||
|
|
||||||
{.deadCodeElim: on.}
|
{.deadCodeElim: on.}
|
||||||
|
|
||||||
|
|
@ -27,7 +26,7 @@ template newException(exceptn, message: expr): expr =
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
TCharSet* = set[char] # for compability with Nim
|
TCharSet* = set[char] # for compatibility with Nim
|
||||||
|
|
||||||
const
|
const
|
||||||
Whitespace* = {' ', '\t', '\v', '\r', '\l', '\f'}
|
Whitespace* = {' ', '\t', '\v', '\r', '\l', '\f'}
|
||||||
|
|
|
||||||
|
|
@ -1376,9 +1376,9 @@ begin
|
||||||
// type alias:
|
// type alias:
|
||||||
|
|
||||||
end;
|
end;
|
||||||
tkEnum:
|
tkEnum: begin end;
|
||||||
tkObject:
|
tkObject: begin end;
|
||||||
tkTuple:
|
tkTuple: begin end;
|
||||||
else break;
|
else break;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1401,7 +1401,8 @@ begin
|
||||||
tkTemplate: result := parseRoutine(p, nkTemplateDef);
|
tkTemplate: result := parseRoutine(p, nkTemplateDef);
|
||||||
tkConverter: result := parseRoutine(p, nkConverterDef);
|
tkConverter: result := parseRoutine(p, nkConverterDef);
|
||||||
tkType, tkEnum, tkObject, tkTuple:
|
tkType, tkEnum, tkObject, tkTuple:
|
||||||
result := parseTypeAlias(p, nkTypeSection, parseTypeDef);
|
result := nil;
|
||||||
|
//result := parseTypeAlias(p, nkTypeSection, parseTypeDef);
|
||||||
tkConst: result := parseConstSection(p);
|
tkConst: result := parseConstSection(p);
|
||||||
tkWhen: result := parseIfOrWhen(p, nkWhenStmt);
|
tkWhen: result := parseIfOrWhen(p, nkWhenStmt);
|
||||||
tkVar: result := parseSection(p, nkVarSection, parseVariable);
|
tkVar: result := parseSection(p, nkVarSection, parseVariable);
|
||||||
|
|
|
||||||
|
|
@ -916,6 +916,12 @@ begin
|
||||||
result := transformAddrDeref(c, n, nkAddr, nkHiddenAddr);
|
result := transformAddrDeref(c, n, nkAddr, nkHiddenAddr);
|
||||||
nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
||||||
result := transformConv(c, n);
|
result := transformConv(c, n);
|
||||||
|
nkDiscardStmt: begin
|
||||||
|
for i := 0 to sonsLen(n)-1 do
|
||||||
|
result.sons[i] := transform(c, n.sons[i]);
|
||||||
|
if isConstExpr(result.sons[0]) then
|
||||||
|
result := newNode(nkCommentStmt)
|
||||||
|
end;
|
||||||
nkCommentStmt, nkTemplateDef: exit;
|
nkCommentStmt, nkTemplateDef: exit;
|
||||||
nkConstSection: exit; // do not replace ``const c = 3`` with ``const 3 = 3``
|
nkConstSection: exit; // do not replace ``const c = 3`` with ``const 3 = 3``
|
||||||
else begin
|
else begin
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import
|
import
|
||||||
math, strutils
|
strutils
|
||||||
|
|
||||||
## Convert an integer to a Roman numeral
|
## Convert an integer to a Roman numeral
|
||||||
# See http://en.wikipedia.org/wiki/Roman_numerals for reference
|
# See http://en.wikipedia.org/wiki/Roman_numerals for reference
|
||||||
|
|
@ -15,7 +15,7 @@ proc raiseInvalidValue(msg: string) {.noreturn.} =
|
||||||
# --> No. Why introduce additional state into such a simple and nice
|
# --> No. Why introduce additional state into such a simple and nice
|
||||||
# interface? State is evil. :D
|
# interface? State is evil. :D
|
||||||
|
|
||||||
proc ConvertRomanToDecimal(romanVal: string): int =
|
proc RomanToDecimal(romanVal: string): int =
|
||||||
result = 0
|
result = 0
|
||||||
var prevVal = 0
|
var prevVal = 0
|
||||||
for i in countdown(romanVal.len - 1, 0):
|
for i in countdown(romanVal.len - 1, 0):
|
||||||
|
|
@ -36,7 +36,7 @@ proc ConvertRomanToDecimal(romanVal: string): int =
|
||||||
dec(result, val)
|
dec(result, val)
|
||||||
prevVal = val
|
prevVal = val
|
||||||
|
|
||||||
proc ConvertDecimalToRoman(decValParam: int): string =
|
proc DecimalToRoman(decValParam: int): string =
|
||||||
# Apparently numbers cannot be above 4000
|
# Apparently numbers cannot be above 4000
|
||||||
# Well, they can be (using overbar or parenthesis notation)
|
# Well, they can be (using overbar or parenthesis notation)
|
||||||
# but I see little interest (beside coding challenge) in coding them as
|
# but I see little interest (beside coding challenge) in coding them as
|
||||||
|
|
@ -55,10 +55,11 @@ proc ConvertDecimalToRoman(decValParam: int): string =
|
||||||
dec(decVal, val)
|
dec(decVal, val)
|
||||||
result.add(key)
|
result.add(key)
|
||||||
|
|
||||||
randomize()
|
for i in 1..100:
|
||||||
for i in 1 .. 10:
|
if RomanToDecimal(DecimalToRoman(i)) != i: quit "BUG"
|
||||||
var rnd = 1 + random(3990)
|
|
||||||
var roman = ConvertDecimalToRoman(rnd)
|
for i in items([1238, 1777, 3830, 2401, 379, 33, 940, 3973]):
|
||||||
var decimal = ConvertRomanToDecimal(roman)
|
if RomanToDecimal(DecimalToRoman(i)) != i: quit "BUG"
|
||||||
echo("$# => $# => $#" % [ $rnd, roman, $decimal ])
|
|
||||||
|
echo "success" #OUT success
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue