Merge: Callref syntax
authorJean Privat <jean@pryen.org>
Wed, 14 Aug 2019 15:22:26 +0000 (11:22 -0400)
committerJean Privat <jean@pryen.org>
Wed, 14 Aug 2019 15:22:26 +0000 (11:22 -0400)
Note: I forgot to independently PR the syntax for callrefs (used by #2774), so here it is.

Introduce the `&` syntax to capture and reference calls.
This is used to provide a simple *function pointer* construction that will be used later to implement full lambdas. However, this is not expected to be used by lambda programmers :)

```nit
var ref = &recv.foo
```

Currently, the syntax is analogous to a simple call (recv.foo) with a prefix `&`.

On chains, only the last call is captured (`.` have a higer precedence than `&`)

```nit
var r = &foo.bar.baz
# is equivalent with
var x = foo.bar
var r = &x.baz
```

Since the syntax is analogous to a call (except the &), there is always a receiver (including the implicit self or sys) and arguments are accepted by the parser.

```nit
var r = &foo
# is equivalent with
var r = &self.foo
```

There is no clear syntax proposal to avoid the capture of a receiver since a receiver is statically expected to resolve the method name.

Pull-Request: #2775
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

.gitlab-ci.yml
contrib/nitcc/src/autom.nit
contrib/nitcc/tests/t

index 19cbcd5..8c08847 100644 (file)
@@ -88,7 +88,7 @@ nitunit_some:
   dependencies:
     - build_tools
   script:
-    - git diff --name-only origin/master..HEAD -- "*.nit" "*.res" "README.*" | grep -v "^tests/" > list0.txt || true
+    - git diff --name-only origin/master..HEAD -- "*.nit" "*.res" "README.*" | grep -v "^tests/\|contrib/" > list0.txt || true
     - xargs nitls -pP < list0.txt > list.txt
     - test -s list.txt || exit 0
     - xargs nitunit < list.txt
index bec0f07..c771408 100644 (file)
@@ -358,10 +358,14 @@ class Automaton
                        if not goods.has(s) then bads.add(s)
                end
 
-               # Remove their transitions
+               # Remove their transitions and tags
                for s in bads do
                        for t in s.ins.to_a do t.delete
                        for t in s.outs.to_a do t.delete
+                       if tags.has_key(s) then
+                               for t in tags[s] do retrotags[t].remove(s)
+                               tags.keys.remove(s)
+                       end
                end
 
                # Keep only the good stuff
index c2233ef..37922f6 100755 (executable)
@@ -54,21 +54,26 @@ differ() {
                         echo "[***no sav***] cp 'out/$r' sav/"
                         test $verbose = true && { cat "out/$r" ; echo ; }
                        echo >>"$tap" "not ok $tapcount - $name # TODO no sav"
+                       return 1
                 else
                         echo "[0K]"
                        echo >>"$tap" "ok $tapcount - $name"
+                       return 0
                 fi
         elif diff "sav/$r" "out/$r" >/dev/null
         then
                 echo "[OK]"
                echo >>"$tap" "ok $tapcount - $name"
+               return 0
         else
                 echo "[******failed******] diff -u {sav,out}/$r"
                 test $verbose = true && { diff -u "sav/$r" "out/$r" ; echo ; }
                echo >>"$tap" "not ok $tapcount - $name"
+               return 1
         fi
 }
 
+err=0
 for f in "$@"
 do
         for a in "$f" `./alterner.pl $f`
@@ -107,7 +112,7 @@ do
 
                grep -i "error" "out/$bn.nitcc.log" > "out/$res"
                name="$a"
-                differ $res
+                differ $res || err=1
 
                 if test \! -z $cla
                 then
@@ -129,7 +134,7 @@ do
 
                                cp "$langname.ast.out" "out/$resi"
                                name="$a $i"
-                                differ "$resi"
+                                differ "$resi" || err=1
                         done
                 fi
         done
@@ -137,3 +142,4 @@ done
 
 echo >>"$tap" "1..$tapcount"
 #prove --formatter=TAP::Formatter::JUnit /bin/cat :: tap.output > tap.xml
+exit "$err"