implemented 'let' statement

This commit is contained in:
Araq 2011-11-29 17:27:48 +01:00
commit 7fcbdc6d42
33 changed files with 169 additions and 103 deletions

11
tests/reject/tlet.nim Normal file
View file

@ -0,0 +1,11 @@
discard """
line: "10"
errormsg: "'name' cannot be assigned to"
"""
Echo("What's your name? ")
let name = readLine(stdin)
while name == "":
Echo("Please tell me your name: ")
name = readLine(stdin)

16
tests/reject/tlet2.nim Normal file
View file

@ -0,0 +1,16 @@
discard """
line: "13"
errormsg: "for a 'var' type a variable needs to be passed"
"""
proc divmod(a, b: int, res, remainder: var int) =
res = a div b # integer division
remainder = a mod b # integer modulo operation
let
x = 9
y = 3
divmod(8, 5, x, y) # modifies x and y
echo(x)
echo(y)

19
tests/run/tlet.nim Normal file
View file

@ -0,0 +1,19 @@
discard """
output: '''Very funny, your name is name.
nameabc'''
"""
proc main =
let name = "name"
if name == "":
echo("Poor soul, you lost your name?")
elif name == "name":
echo("Very funny, your name is name.")
else:
Echo("Hi, ", name, "!")
let (x, y) = ("abc", name)
echo y, x
main()

View file

@ -103,7 +103,7 @@ proc parseSpec(filename: string): TSpec =
# ----------------------------------------------------------------------------
var
let
pegLineError =
peg"{[^(]*} '(' {\d+} ', ' \d+ ') ' ('Error'/'Warning') ':' \s* {.*}"
pegOtherError = peg"'Error:' \s* {.*}"
@ -111,10 +111,10 @@ var
pegOfInterest = pegLineError / pegOtherError
proc callCompiler(cmdTemplate, filename, options: string): TSpec =
var c = parseCmdLine(cmdTemplate % [options, filename])
let c = parseCmdLine(cmdTemplate % [options, filename])
var p = startProcess(command=c[0], args=c[1.. -1],
options={poStdErrToStdOut, poUseShell})
var outp = p.outputStream
let outp = p.outputStream
var suc = ""
var err = ""
var x = newStringOfCap(120)
@ -222,7 +222,7 @@ proc cmpMsgs(r: var TResults, expected, given: TSpec, test: string) =
inc(r.passed)
proc rejectSingleTest(r: var TResults, test, options: string) =
var test = test.addFileExt(".nim")
let test = test.addFileExt(".nim")
var t = extractFilename(test)
inc(r.total)
echo t
@ -240,10 +240,10 @@ proc reject(r: var TResults, dir, options: string) =
proc compile(r: var TResults, pattern, options: string) =
for test in os.walkFiles(pattern):
var t = extractFilename(test)
let t = extractFilename(test)
echo t
inc(r.total)
var expected = parseSpec(test)
let expected = parseSpec(test)
if expected.disabled:
r.addResult(t, "", reIgnored)
inc(r.skipped)
@ -253,11 +253,11 @@ proc compile(r: var TResults, pattern, options: string) =
if not given.err: inc(r.passed)
proc compileSingleTest(r: var TResults, test, options: string) =
var test = test.addFileExt(".nim")
var t = extractFilename(test)
let test = test.addFileExt(".nim")
let t = extractFilename(test)
inc(r.total)
echo t
var given = callCompiler(cmdTemplate, test, options)
let given = callCompiler(cmdTemplate, test, options)
r.addResult(t, given.msg, if given.err: reFailure else: reSuccess)
if not given.err: inc(r.passed)