made some tests green

This commit is contained in:
Araq 2014-09-21 23:57:54 +02:00
commit 3866820eee
11 changed files with 53 additions and 49 deletions

View file

@ -104,7 +104,7 @@ proc guardGlobal(a: PEffects; n: PNode; guard: PSym) =
# (var x{.guard: y.}: int) # (var x{.guard: y.}: int)
proc guardDotAccess(a: PEffects; n: PNode) = proc guardDotAccess(a: PEffects; n: PNode) =
let ri = n.sons[1] let ri = n.sons[1]
internalAssert ri.kind == nkSym and ri.sym.kind == skField if ri.kind != nkSym or ri.sym.kind != skField: return
var g = ri.sym.guard var g = ri.sym.guard
if g.isNil or a.isTopLevel: return if g.isNil or a.isTopLevel: return
# fixup guard: # fixup guard:

View file

@ -448,7 +448,7 @@ proc semConst(c: PContext, n: PNode): PNode =
if typ == nil: if typ == nil:
localError(a.sons[2].info, errConstExprExpected) localError(a.sons[2].info, errConstExprExpected)
continue continue
if not typeAllowed(typ, skConst): if not typeAllowed(typ, skConst) and def.kind != nkNilLit:
localError(a.info, errXisNoType, typeToString(typ)) localError(a.info, errXisNoType, typeToString(typ))
continue continue
v.typ = typ v.typ = typ

View file

@ -1342,6 +1342,9 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
if def.typ.kind != tyTypeDesc: if def.typ.kind != tyTypeDesc:
typ = newTypeWithSons(c, tyStatic, @[def.typ]) typ = newTypeWithSons(c, tyStatic, @[def.typ])
else: else:
# the following line fixes ``TV2*[T:SomeNumber=TR] = array[0..1, T]``
# from manyloc/named_argument_bug/triengine:
def.typ = def.typ.skipTypes({tyTypeDesc})
if not containsGenericType(def.typ): if not containsGenericType(def.typ):
def = fitNode(c, typ, def) def = fitNode(c, typ, def)

View file

@ -142,9 +142,10 @@ type
TSOBool: SOBool, TRecvLineResult: RecvLineResult, TSOBool: SOBool, TRecvLineResult: RecvLineResult,
TReadLineResult: ReadLineResult, ETimeout: TimeoutError].} TReadLineResult: ReadLineResult, ETimeout: TimeoutError].}
when defined(booting):
let let invalidSocket*: Socket = nil ## invalid socket
invalidSocket*: Socket = nil ## invalid socket else:
const invalidSocket*: Socket = nil ## invalid socket
when defined(windows): when defined(windows):
let let

View file

@ -5,13 +5,13 @@ discard """
#bug #442 #bug #442
import scgi, sockets, asyncio, strtabs import scgi, sockets, asyncio, strtabs
proc handleSCGIRequest[TScgi: TScgiState | PAsyncScgiState](s: TScgi) = proc handleSCGIRequest[TScgi: ScgiState | AsyncScgiState](s: TScgi) =
discard discard
proc handleSCGIRequest(client: PAsyncSocket, headers: PStringTable, proc handleSCGIRequest(client: AsyncSocket, headers: StringTableRef,
input: string) = input: string) =
discard discard
proc test(handle: proc (client: PAsyncSocket, headers: PStringTable, proc test(handle: proc (client: AsyncSocket, headers: StringTableRef,
input: string), b: int) = input: string), b: int) =
discard discard

View file

@ -76,14 +76,14 @@ type
case kind*: Tparam_kind case kind*: Tparam_kind
of PK_EMPTY: nil of PK_EMPTY: nil
of PK_INT: int_val*: int of PK_INT: int_val*: int
of PK_BIGGEST_INT: big_int_val*: biggestInt of PK_BIGGEST_INT: big_int_val*: BiggestInt
of PK_FLOAT: float_val*: float of PK_FLOAT: float_val*: float
of PK_BIGGEST_FLOAT: big_float_val*: biggestFloat of PK_BIGGEST_FLOAT: big_float_val*: BiggestFloat
of PK_STRING: str_val*: string of PK_STRING: str_val*: string
of PK_BOOL: bool_val*: bool of PK_BOOL: bool_val*: bool
of PK_HELP: nil of PK_HELP: nil
Tcommandline_results* = object of TObject ## \ Tcommandline_results* = object of RootObj ## \
## Contains the results of the parsing. ## Contains the results of the parsing.
## ##
## Usually this is the result of the parse() call, but you can inherit from ## Usually this is the result of the parse() call, but you can inherit from
@ -97,7 +97,7 @@ type
## the first name variant for all options to avoid you repeating the test ## the first name variant for all options to avoid you repeating the test
## with different keys. ## with different keys.
positional_parameters*: seq[Tparsed_parameter] positional_parameters*: seq[Tparsed_parameter]
options*: TOrderedTable[string, Tparsed_parameter] options*: OrderedTable[string, Tparsed_parameter]
# - Tparam_kind procs # - Tparam_kind procs
@ -193,7 +193,7 @@ template new_parsed_parameter*(tkind: Tparam_kind, expr): Tparsed_parameter =
proc init*(param: var Tcommandline_results; proc init*(param: var Tcommandline_results;
positional_parameters: seq[Tparsed_parameter] = @[]; positional_parameters: seq[Tparsed_parameter] = @[];
options: TOrderedTable[string, Tparsed_parameter] = options: OrderedTable[string, Tparsed_parameter] =
initOrderedTable[string, Tparsed_parameter](4)) = initOrderedTable[string, Tparsed_parameter](4)) =
## Initialization helper with default parameters. ## Initialization helper with default parameters.
param.positional_parameters = positional_parameters param.positional_parameters = positional_parameters
@ -231,12 +231,12 @@ template run_custom_proc(parsed_parameter: Tparsed_parameter,
## Pass in the string of the parameter triggering the call. If the ## Pass in the string of the parameter triggering the call. If the
if not custom_validator.isNil: if not custom_validator.isNil:
except: except:
raise_or_quit(EInvalidValue, ("Couldn't run custom proc for " & raise_or_quit(ValueError, ("Couldn't run custom proc for " &
"parameter $1:\n$2" % [escape(parameter), "parameter $1:\n$2" % [escape(parameter),
getCurrentExceptionMsg()])) getCurrentExceptionMsg()]))
let message = custom_validator(parameter, parsed_parameter) let message = custom_validator(parameter, parsed_parameter)
if not message.isNil and message.len > 0: if not message.isNil and message.len > 0:
raise_or_quit(EInvalidValue, ("Failed to validate value for " & raise_or_quit(ValueError, ("Failed to validate value for " &
"parameter $1:\n$2" % [escape(parameter), message])) "parameter $1:\n$2" % [escape(parameter), message]))
@ -246,50 +246,50 @@ proc parse_parameter(quit_on_failure: bool, param, value: string,
## ##
## Pass the parameter string which requires a value and the text the user ## Pass the parameter string which requires a value and the text the user
## passed in for it. It will be parsed according to the param_kind. This proc ## passed in for it. It will be parsed according to the param_kind. This proc
## will raise (EInvalidValue, EOverflow) if something can't be parsed. ## will raise (ValueError, EOverflow) if something can't be parsed.
result.kind = param_kind result.kind = param_kind
case param_kind: case param_kind:
of PK_INT: of PK_INT:
try: result.int_val = value.parseInt try: result.int_val = value.parseInt
except EOverflow: except OverflowError:
raise_or_quit(EOverflow, ("parameter $1 requires an " & raise_or_quit(OverflowError, ("parameter $1 requires an " &
"integer, but $2 is too large to fit into one") % [param, "integer, but $2 is too large to fit into one") % [param,
escape(value)]) escape(value)])
except EInvalidValue: except ValueError:
raise_or_quit(EInvalidValue, ("parameter $1 requires an " & raise_or_quit(ValueError, ("parameter $1 requires an " &
"integer, but $2 can't be parsed into one") % [param, escape(value)]) "integer, but $2 can't be parsed into one") % [param, escape(value)])
of PK_STRING: of PK_STRING:
result.str_val = value result.str_val = value
of PK_FLOAT: of PK_FLOAT:
try: result.float_val = value.parseFloat try: result.float_val = value.parseFloat
except EInvalidValue: except ValueError:
raise_or_quit(EInvalidValue, ("parameter $1 requires a " & raise_or_quit(ValueError, ("parameter $1 requires a " &
"float, but $2 can't be parsed into one") % [param, escape(value)]) "float, but $2 can't be parsed into one") % [param, escape(value)])
of PK_BOOL: of PK_BOOL:
try: result.bool_val = value.parseBool try: result.bool_val = value.parseBool
except EInvalidValue: except ValueError:
raise_or_quit(EInvalidValue, ("parameter $1 requires a " & raise_or_quit(ValueError, ("parameter $1 requires a " &
"boolean, but $2 can't be parsed into one. Valid values are: " & "boolean, but $2 can't be parsed into one. Valid values are: " &
"y, yes, true, 1, on, n, no, false, 0, off") % [param, escape(value)]) "y, yes, true, 1, on, n, no, false, 0, off") % [param, escape(value)])
of PK_BIGGEST_INT: of PK_BIGGEST_INT:
try: try:
let parsed_len = parseBiggestInt(value, result.big_int_val) let parsed_len = parseBiggestInt(value, result.big_int_val)
if value.len != parsed_len or parsed_len < 1: if value.len != parsed_len or parsed_len < 1:
raise_or_quit(EInvalidValue, ("parameter $1 requires an " & raise_or_quit(ValueError, ("parameter $1 requires an " &
"integer, but $2 can't be parsed completely into one") % [ "integer, but $2 can't be parsed completely into one") % [
param, escape(value)]) param, escape(value)])
except EInvalidValue: except ValueError:
raise_or_quit(EInvalidValue, ("parameter $1 requires an " & raise_or_quit(ValueError, ("parameter $1 requires an " &
"integer, but $2 can't be parsed into one") % [param, escape(value)]) "integer, but $2 can't be parsed into one") % [param, escape(value)])
of PK_BIGGEST_FLOAT: of PK_BIGGEST_FLOAT:
try: try:
let parsed_len = parseBiggestFloat(value, result.big_float_val) let parsed_len = parseBiggestFloat(value, result.big_float_val)
if value.len != parsed_len or parsed_len < 1: if value.len != parsed_len or parsed_len < 1:
raise_or_quit(EInvalidValue, ("parameter $1 requires a " & raise_or_quit(ValueError, ("parameter $1 requires a " &
"float, but $2 can't be parsed completely into one") % [ "float, but $2 can't be parsed completely into one") % [
param, escape(value)]) param, escape(value)])
except EInvalidValue: except ValueError:
raise_or_quit(EInvalidValue, ("parameter $1 requires a " & raise_or_quit(ValueError, ("parameter $1 requires a " &
"float, but $2 can't be parsed into one") % [param, escape(value)]) "float, but $2 can't be parsed into one") % [param, escape(value)])
of PK_EMPTY: of PK_EMPTY:
discard discard
@ -298,15 +298,15 @@ proc parse_parameter(quit_on_failure: bool, param, value: string,
template build_specification_lookup(): template build_specification_lookup():
TOrderedTable[string, ptr Tparameter_specification] = OrderedTable[string, ptr Tparameter_specification] =
## Returns the table used to keep pointers to all of the specifications. ## Returns the table used to keep pointers to all of the specifications.
var result {.gensym.}: TOrderedTable[string, ptr Tparameter_specification] var result {.gensym.}: OrderedTable[string, ptr Tparameter_specification]
result = initOrderedTable[string, ptr Tparameter_specification]( result = initOrderedTable[string, ptr Tparameter_specification](
nextPowerOfTwo(expected.len)) nextPowerOfTwo(expected.len))
for i in 0..expected.len-1: for i in 0..expected.len-1:
for param_to_detect in expected[i].names: for param_to_detect in expected[i].names:
if result.hasKey(param_to_detect): if result.hasKey(param_to_detect):
raise_or_quit(EInvalidKey, raise_or_quit(KeyError,
"Parameter $1 repeated in input specification" % param_to_detect) "Parameter $1 repeated in input specification" % param_to_detect)
else: else:
result[param_to_detect] = addr(expected[i]) result[param_to_detect] = addr(expected[i])
@ -344,7 +344,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
## ##
## If there is any kind of error and quit_on_failure is true, the quit proc ## If there is any kind of error and quit_on_failure is true, the quit proc
## will be called with a user error message. If quit_on_failure is false ## will be called with a user error message. If quit_on_failure is false
## errors will raise exceptions (usually EInvalidValue or EOverflow) instead ## errors will raise exceptions (usually ValueError or EOverflow) instead
## for you to catch and handle. ## for you to catch and handle.
assert type_of_positional_parameters != PK_EMPTY and assert type_of_positional_parameters != PK_EMPTY and
@ -359,7 +359,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
# Prepare the input parameter list, maybe get it from the OS if not available. # Prepare the input parameter list, maybe get it from the OS if not available.
var args = args var args = args
if args == nil: if args == nil:
let total_params = ParamCount() let total_params = paramCount()
#echo "Got no explicit args, retrieving from OS. Count: ", total_params #echo "Got no explicit args, retrieving from OS. Count: ", total_params
newSeq(args, total_params) newSeq(args, total_params)
for i in 0..total_params - 1: for i in 0..total_params - 1:
@ -387,7 +387,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
if param.consumes == PK_HELP: if param.consumes == PK_HELP:
echo_help(expected, type_of_positional_parameters, echo_help(expected, type_of_positional_parameters,
bad_prefixes, end_of_options) bad_prefixes, end_of_options)
raise_or_quit(EInvalidKey, "") raise_or_quit(KeyError, "")
if param.consumes != PK_EMPTY: if param.consumes != PK_EMPTY:
if i + 1 < args.len: if i + 1 < args.len:
@ -396,14 +396,14 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
run_custom_proc(parsed, param.custom_validator, arg) run_custom_proc(parsed, param.custom_validator, arg)
i += 1 i += 1
else: else:
raise_or_quit(EInvalidValue, ("parameter $1 requires a " & raise_or_quit(ValueError, ("parameter $1 requires a " &
"value, but none was provided") % [arg]) "value, but none was provided") % [arg])
result.options[param.names[0]] = parsed result.options[param.names[0]] = parsed
break adding_positional_parameter break adding_positional_parameter
else: else:
for bad_prefix in bad_prefixes: for bad_prefix in bad_prefixes:
if arg.startsWith(bad_prefix): if arg.startsWith(bad_prefix):
raise_or_quit(EInvalidValue, ("Found ambiguos parameter '$1' " & raise_or_quit(ValueError, ("Found ambiguos parameter '$1' " &
"starting with '$2', put '$3' as the previous parameter " & "starting with '$2', put '$3' as the previous parameter " &
"if you want to force it as positional parameter.") % [arg, "if you want to force it as positional parameter.") % [arg,
bad_prefix, end_of_options]) bad_prefix, end_of_options])
@ -415,7 +415,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
i += 1 i += 1
proc toString(runes: seq[TRune]): string = proc toString(runes: seq[Rune]): string =
result = "" result = ""
for rune in runes: result.add(rune.toUTF8) for rune in runes: result.add(rune.toUTF8)
@ -424,7 +424,7 @@ proc ascii_cmp(a, b: string): int =
## Comparison ignoring non ascii characters, for better switch sorting. ## Comparison ignoring non ascii characters, for better switch sorting.
let a = filterIt(toSeq(runes(a)), it.isAlpha()) let a = filterIt(toSeq(runes(a)), it.isAlpha())
# Can't use filterIt twice, github bug #351. # Can't use filterIt twice, github bug #351.
let b = filter(toSeq(runes(b)), proc(x: TRune): bool = x.isAlpha()) let b = filter(toSeq(runes(b)), proc(x: Rune): bool = x.isAlpha())
return system.cmp(toString(a), toString(b)) return system.cmp(toString(a), toString(b))

View file

@ -84,7 +84,7 @@ task "download", "download game assets":
skipAssets = false skipAssets = false
path = expandFilename("data") path = expandFilename("data")
path.add DirSep path.add DirSep
path.add(extractFilename(gameAssets)) path.add(extractFilename(GameAssets))
if existsFile(path): if existsFile(path):
echo "The file already exists\n", echo "The file already exists\n",
"[R]emove [M]ove [Q]uit [S]kip Source: ", GameAssets "[R]emove [M]ove [Q]uit [S]kip Source: ", GameAssets
@ -92,7 +92,7 @@ task "download", "download game assets":
of "r": of "r":
removeFile path removeFile path
of "m": of "m":
moveFile path, path/../(extractFilename(gameAssets)&"-old") moveFile path, path/../(extractFilename(GameAssets)&"-old")
of "s": of "s":
skipAssets = true skipAssets = true
else: else:
@ -101,7 +101,7 @@ task "download", "download game assets":
echo "Downloading from ", GameAssets echo "Downloading from ", GameAssets
if not skipAssets: if not skipAssets:
echo "Downloading to ", path echo "Downloading to ", path
downloadFile gameAssets, path downloadFile GameAssets, path
echo "Download finished" echo "Download finished"
let targetDir = parentDir(parentDir(path)) let targetDir = parentDir(parentDir(path))

View file

@ -3,10 +3,10 @@ import
tri_engine/config tri_engine/config
type type
TV2*[T:TNumber=TR] = array[0..1, T] TV2*[T:SomeNumber=TR] = array[0..1, T]
TV3*[T:TNumber=TR] = array[0..2, T] TV3*[T:SomeNumber=TR] = array[0..2, T]
TV4*[T:TNumber=TR] = array[0..3, T] TV4*[T:SomeNumber=TR] = array[0..3, T]
TVT*[T:TNumber=TR] = TV2|TV3|TV4 TVT*[T:SomeNumber=TR] = TV2|TV3|TV4
#TV2* = array[0..1, TR] #TV2* = array[0..1, TR]
#TV3* = array[0..2, TR] #TV3* = array[0..2, TR]
#TV4* = array[0..3, TR] #TV4* = array[0..3, TR]

View file

@ -1,6 +1,7 @@
discard """ discard """
output: '''foobarfoobar output: '''foobarfoobar
bazbearbazbear bazbearbazbear
1''' 1'''
cmd: "nim $target --threads:on $options $file" cmd: "nim $target --threads:on $options $file"
""" """

View file

@ -18,5 +18,5 @@ type
PSDL_Sem = ptr TSDL_Sem PSDL_Sem = ptr TSDL_Sem
TSDL_Sem = TSDL_Semaphore TSDL_Sem = TSDL_Semaphore
proc SDL_CreateSemaphore(initial_value: Int32): PSDL_Sem {. proc SDL_CreateSemaphore(initial_value: int32): PSDL_Sem {.
importc: "SDL_CreateSemaphore".} importc: "SDL_CreateSemaphore".}

View file

@ -8,7 +8,6 @@ version 0.10
version 0.9.6 version 0.9.6
============= =============
- fix tflowvar codegen test
- allow simple read accesses to global variables --> difficult to ensure that - allow simple read accesses to global variables --> difficult to ensure that
no data races happen no data races happen
- split idetools into separate tool - split idetools into separate tool