Skip to content

Commit

Permalink
Merge branch 'master' into collections_contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Delja committed Aug 24, 2020
2 parents afbc581 + 15e804c commit 43f4e57
Show file tree
Hide file tree
Showing 207 changed files with 7,444 additions and 2,395 deletions.
15 changes: 15 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:

variables:
NEO4J_AUTH: none
POSTGRES_HOST_AUTH_METHOD: trust

cache:
paths:
Expand Down Expand Up @@ -333,6 +334,20 @@ bench_fast:
- benchmarks/*.gnu
when: always

nitunit_manual:
stage: more_test
dependencies:
- build_tools
script:
- nitunit doc/manual/*.nit
- junit2html nitunit.xml
artifacts:
paths:
- nitunit.xml*
when: always
reports:
junit:
- nitunit.xml

# MORE TOOLS ########################################################

Expand Down
2 changes: 1 addition & 1 deletion contrib/pep8analysis/src/parser/lexer.nit
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ redef class AError

init init_error(message: String, loc: Location)
do
init(loc)
self.location = loc
self.message = message
end
end
Expand Down
30 changes: 15 additions & 15 deletions doc/manual/attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end

Note that from an API point of view, there is no way to distinguish the read access of an attribute with a normal method neither to distinguish a write access of an attribute with a setter. Therefore, the read access of an attribute is called a getter while the write access is called a setter.

~~~
~~~nitish
var x = foo.bar # Is bar an attribute or a method?
foo.bar = y # Is bar an attribute or a setter?
# In fact, we do not need to know.
Expand All @@ -28,12 +28,12 @@ By default, a getter is public and a setter is private. The visibility of getter
additional `writable` keyword.

~~~
class Foo
var pub_pri: X
protected var pro_pri: X
var pub_pub: X is writable
private var pri_pro: X is protected writable
var pub_pri2: X is private writable # the default
class Foo2
var pub_pri: Int
protected var pro_pri: Int
var pub_pub: Int is writable
private var pri_pro: Int is protected writable
var pub_pri2: Int is private writable # the default
end
~~~

Expand All @@ -43,17 +43,17 @@ Getters and setters of attributes behave like genuine methods that can be inheri
a redefinition while `redef writable` declares that the setter is a redefinition.

~~~
interface Foo
interface Foo3
fun derp: Int is abstract
fun derp=(o: Int) is abstract
end
class Bar
super Foo
redef var derp: Int redef writable
class Bar3
super Foo3
redef var derp is redef writable
end
class Baz
super Bar
redef fun derp do ...
redef fun derp=(o) do ...
class Baz3
super Bar3
redef fun derp do return 1
redef fun derp=(o) do end
end
~~~
60 changes: 53 additions & 7 deletions doc/manual/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ assert p.id == "ABC"
In subclasses, additional attributes are automatically collected.

~~~
class Product
var id: String
var description: String
var price: Float
end
class Book
super Product
var author: String
Expand All @@ -44,6 +49,11 @@ It is used to perform additional systematic tasks.
Because the `init` is run at the end of the initialization sequence, initialized attributes are usable in the body.

~~~
class Product
var id: String
var description: String
var price: Float
end
class OverpricedProduct
super Product
init
Expand All @@ -52,7 +62,7 @@ class OverpricedProduct
end
end
var op = new OverpricedProduct("ABC", "Bla bla", 15.95)
assert op.price == 159.50
assert op.price.is_approx(159.50, 0.001)
~~~


Expand All @@ -65,6 +75,11 @@ There is three cases for an attributes to not be collected in the `new`.
* Attributes introduced in refinement of classes

~~~
class Product
var id: String
var description: String
var price: Float
end
class TaxedProduct
super Product
var tax_rate = 9.90
Expand All @@ -75,7 +90,7 @@ class TaxedProduct
end
end
var tp = new TaxedProduct("ABC", "Bla bla", 15.95)
assert tp.total_price == 17.52905
assert tp.total_price.is_approx(17.52905, 0.00001)
~~~

Note: The orchestration here is important. In order, the following is executed:
Expand All @@ -95,6 +110,11 @@ In fact, by default, the setter of an attribute is used as a initializer.
`autoinit` is used to register a method as a setter.

~~~
class Product
var id: String
var description: String
var price: Float
end
class FooProduct
super Product
fun set_xy(x, y: Int) is autoinit do z = x * 10 + y
Expand All @@ -113,15 +133,41 @@ In most case, there is no reason that an argument of a `new` construction is not
As explained above, one of the main advantage of these constructors is their compatibility with multiple inheritance.

~~~
class Product
var id: String
var description: String
var price: Float
end
class OverpricedProduct
super Product
init
do
price = price * 10.0
end
end
class TaxedProduct
super Product
var tax_rate = 9.90
var total_price: Float is noinit
init
do
total_price = price * (1.0 + tax_rate/100.0)
end
end
class FooProduct
super Product
fun set_xy(x, y: Int) is autoinit do z = x * 10 + y
var z: Int is noinit
end
class MultiProduct
super OverpricedProduct
super TaxedProduct
super FooProduct
end
var mp = new MultiProduct("ABC", "Bla bla", 15.96, 1, 3)
assert mp.id == "ABC"
assert mp.price == 159.6
assert mp.total_price == 175.4
assert mp.price.is_approx(159.6, 0.001)
assert mp.total_price.is_approx(175.4, 0.001)
assert mp.z == 13
~~~

Expand Down Expand Up @@ -151,11 +197,11 @@ class Point
redef fun to_s do return "({x},{y})"
end
var p1 = new Point(1.0, 2.0)
assert p1.to_s == "(1,2)"
assert p1.to_s == "(1.0,2.0)"
var p2 = new Point.origin
assert p2.to_s == "(0,0)"
assert p2.to_s == "(0.0,0.0)"
var p3 = new Point.polar(1.0, 2.0)
assert p3.to_s == "(-0.4161,0.9092)"
assert p3.to_s == "(-0.416,0.909)"
~~~


Expand Down
10 changes: 5 additions & 5 deletions doc/manual/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

`fun` declares methods. Methods must have a name, may have parameters, and may have a return type. Parameters are typed; however, a single type can be used for multiple parameters.

~~~
fun foo(x, y: Int, s: String): Bool ...
~~~nitish
fun foo(x, y: Int, s: String): Bool # ...
~~~

`do` declares the body of methods. Alike control structures, a one-liner version is available.
Expand Down Expand Up @@ -38,7 +38,7 @@ print a.length # no () for length, no () for print

However, this last facility requires that the first argument does not start with a parenthesis or a bracket.

~~~
~~~nitish
foo (x).bar # will be interpreted as (foo(x)).bar
foo [x].bar # will be interpreted as (foo[x]).bar
~~~
Expand Down Expand Up @@ -140,7 +140,7 @@ Operators and setters are methods that require a special syntax for their defini

<!-- -->

~~~
~~~nitish
class Foo
fun +(a: Bar): Baz do ...
fun -: Baz do ...
Expand All @@ -162,7 +162,7 @@ a[b] = c # The bracket setter '[]='

`+=` and `-=` are combinations of the assignment (`=`) and a binary operator. These feature are extended to setters where a single `+=` is in fact three method calls: a function call, the operator call, then a setter call.

~~~
~~~nitish
a += c # equiv. a = a + c
a[b] += c # equiv. a[b] = a[b] + c
a.foo += c # equiv. a.foo = a.foo + c
Expand Down
4 changes: 2 additions & 2 deletions doc/manual/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ intrude importers), there is still no restriction.

Visibility of attributes is more specific and is detailed in its own section.

~~~
~~~nitish
module m1
class Foo
fun pub do ...
Expand All @@ -55,7 +55,7 @@ y.pri2

<!-- -->

~~~
~~~nitish
module m2
import m1
class Baz
Expand Down
Loading

0 comments on commit 43f4e57

Please sign in to comment.