summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-11-29 17:27:48 +0100
committerAraq <rumpf_a@web.de>2011-11-29 17:27:48 +0100
commit7fcbdc6d422c92ec5070bee684c37a42c789dd46 (patch)
treecef1fb3a4b4f68d96e8d3f6b8adbcf6e0cff1a22 /tests
parent31a994cc107100c9c6f84455832ccce0b5fd9661 (diff)
downloadNim-7fcbdc6d422c92ec5070bee684c37a42c789dd46.tar.gz
implemented 'let' statement
Diffstat (limited to 'tests')
-rw-r--r--tests/reject/tlet.nim11
-rw-r--r--tests/reject/tlet2.nim16
-rw-r--r--tests/run/tlet.nim19
-rwxr-xr-xtests/tester.nim18
4 files changed, 55 insertions, 9 deletions
diff --git a/tests/reject/tlet.nim b/tests/reject/tlet.nim
new file mode 100644
index 000000000..3d36432fb
--- /dev/null
+++ b/tests/reject/tlet.nim
@@ -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)
+
diff --git a/tests/reject/tlet2.nim b/tests/reject/tlet2.nim
new file mode 100644
index 000000000..8b1ddf940
--- /dev/null
+++ b/tests/reject/tlet2.nim
@@ -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)
+
diff --git a/tests/run/tlet.nim b/tests/run/tlet.nim
new file mode 100644
index 000000000..ba355c5d8
--- /dev/null
+++ b/tests/run/tlet.nim
@@ -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()
+
diff --git a/tests/tester.nim b/tests/tester.nim
index d50b4f766..15b1bb045 100755
--- a/tests/tester.nim
+++ b/tests/tester.nim
@@ -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)
 
com> 2017-10-18 03:11:56 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2017-10-18 03:11:56 -0700 4085 - done with first cut of the SubX VM' href='/akkartik/mu/commit/subx/016functions.cc?h=main&id=292ccba1bbdc8c2ec6cfacefa15f19c8d215b58c'>292ccba1 ^
c442a5ad ^

292ccba1 ^




ca00f6b9 ^
39c0d1b1 ^
0cb988d0 ^
3ecd66fb ^
292ccba1 ^
ca00f6b9 ^
39c0d1b1 ^
871ea368 ^
b6fdd2e4 ^
292ccba1 ^





0f851e48 ^

aa2e2155 ^
292ccba1 ^
ca00f6b9 ^
39c0d1b1 ^
0cb988d0 ^
292ccba1 ^
ca00f6b9 ^
39c0d1b1 ^
292ccba1 ^





c442a5ad ^

292ccba1 ^
c442a5ad ^
292ccba1 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

         

                                          

                       
                    
      
                                           







                                                                                   
                                                 
                                  

                                                                                   
                                                                   

                
                                                                                







                          
      
                                           
                                                                            
                 

                   





                                            
                                                              
                                                   

                 

                                                                                




                           
                      
                      
                                           
                                                                             
                 
                         
                   
                   
                                           





                                    

                                                                     
 
               
                      
                      
                                           
    
                         
                   





                                   

                                                       
              
                                                                                

        
//:: call

:(before "End Initialize Op Names")
put_new(Name, "e8", "call disp32 (call)");

:(scenario call_disp32)
% Reg[ESP].u = 0x64;
== 0x1
# op  ModR/M  SIB   displacement  immediate
  e8                              a0 00 00 00  # call function offset at 0x000000a0
  # next EIP is 6
+run: call imm32 0x000000a0
+run: decrementing ESP to 0x00000060
+run: pushing value 0x00000006
+run: jumping to 0x000000a6

:(before "End Single-Byte Opcodes")
case 0xe8: {  // call disp32 relative to next EIP
  const int32_t offset = next32();
  ++Callstack_depth;
  trace(Callstack_depth+1, "run") << "call imm32 0x" << HEXWORD << offset << end();
//?   cerr << "push: EIP: " << EIP << " => " << Reg[ESP].u << '\n';
  push(EIP);
  EIP += offset;
  trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
  break;
}

//:

:(scenario call_r32)
% Reg[ESP].u = 0x64;
% Reg[EBX].u = 0x000000a0;
== 0x1
# op  ModR/M  SIB   displacement  immediate
  ff  d3                                       # call function offset at EBX
  # next EIP is 3
+run: call to r/m32
+run: r/m32 is EBX
+run: decrementing ESP to 0x00000060
+run: pushing value 0x00000003
+run: jumping to 0x000000a3

:(before "End Op ff Subops")
case 2: {  // call function pointer at r/m32
  trace(Callstack_depth+1, "run") << "call to r/m32" << end();
  const int32_t* offset = effective_address(modrm);
  push(EIP);
  EIP += *offset;
  trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
  ++Callstack_depth;
  break;
}

:(scenario call_mem_at_r32)
% Reg[ESP].u = 0x64;
% Reg[EBX].u = 0x2000;
== 0x1  # code segment
# op  ModR/M  SIB   displacement  immediate
  ff  13                                       # call function offset at *EBX
  # next EIP is 3
== 0x2000  # data segment
a0 00 00 00  # 0xa0
+run: call to r/m32
+run: effective address is 0x00002000 (EBX)
+run: decrementing ESP to 0x00000060
+run: pushing value 0x00000003
+run: jumping to 0x000000a3

//:: ret

:(before "End Initialize Op Names")
put_new(Name, "c3", "return from most recent unfinished call (ret)");

:(scenario ret)
% Reg[ESP].u = 0x2000;
== 0x1  # code segment
# op  ModR/M  SIB   displacement  immediate
  c3
== 0x2000  # data segment
10 00 00 00  # 0x10
+run: return
+run: popping value 0x00000010
+run: jumping to 0x00000010

:(before "End Single-Byte Opcodes")
case 0xc3: {  // return from a call
  trace(Callstack_depth+1, "run") << "return" << end();
  --Callstack_depth;
  EIP = pop();
  trace(Callstack_depth+1, "run") << "jumping to 0x" << HEXWORD << EIP << end();
  break;
}