Setters of attributes are private by default. This cause some issue as they are exposed as initializers but still invisible in client modules.
The proposed solution to resolve this inconsistency is to make setters protected by default so they are visible in client modules but only usable in subclasses.
This is a change is the spec, to RFC label is set is people have comments on the sanity/usability/kiss/pola/etc.
Close #1552
Pull-Request: #1567
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
# A finite automaton
class Automaton
# The start state
- var start: State
+ var start: State is noinit
# State that are accept states
var accept = new Array[State]
#
# Used to load achievements from storage.
init from_json(game: Game, json: JsonObject) do
- self.game = game
- id = json["id"].to_s
- name = json["name"].to_s
- desc = json["desc"].to_s
- reward = json["reward"].as(Int)
+ init(game, json["id"].to_s, json["name"].to_s, json["desc"].to_s, json["reward"].as(Int))
end
redef fun to_json do
#
# Used to load events from json storage.
init from_json(game: Game, json: JsonObject) do
- self.game = game
+ init(game, json["kind"].to_s, json["data"].as(JsonObject))
internal_id = json["internal_id"].to_s
- kind = json["kind"].to_s
time = new ISODate.from_string(json["time"].to_s)
- data = json["data"].as(JsonObject)
end
redef fun to_json do
#
# Used to load players from saved data.
init from_json(game: Game, json: JsonObject) do
- self.game = game
- name = json["name"].to_s
+ init(game, json["name"].to_s)
nitcoins = json["nitcoins"].as(Int)
end
# Inits `self` from a float `value`.
init from_float(value: Float) do
- self.value = (value * 100.0).to_i
+ init((value * 100.0).to_i)
end
redef fun to_s do return "{value / 100}.{value % 100}$"
var cavemen_incr = 4
var game : nullable Game = null
- var score = new Container[Int](0)
+ var score = new Ref[Int](0)
var imgs : nullable ImageSet = null
var splash : nullable SplashScreen = null
if game.won then
next_nbr_caveman += cavemen_incr
else
- score = new Container[Int](0)
+ score = new Ref[Int](0)
next_nbr_caveman = cavemen_at_first_level
end
game = new Game( next_nbr_caveman, score )
var over_since = 0
- var score: Container[Int]
+ var score: Ref[Int]
var random_radius_min = 200
var random_radius_max = 400
var entities_sorter = new EntitiesSorter
- init( cavemen_nbr : Int, score: Container[Int] )
+ init( cavemen_nbr : Int, score: Ref[Int] )
do
srand_from(cavemen_nbr)
end
end
-fun display_scale_container: Container[Float] do return once new Container[Float](0.1)
+fun display_scale_container: Ref[Float] do return once new Ref[Float](0.1)
redef fun display_scale do return display_scale_container.item
redef fun display_offset_x: Int do return (300.0*display_scale).to_i
redef fun display_offset_y: Int do return (800.0*display_scale).to_i
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Entropy
+# SEE: <http://rosettacode.org/wiki/Entropy>
+module entropy
+
+import counter
+
+# Basic implementation with a hashmap of chars to count them
+fun entropy(string: String): Float
+do
+ var cpt = new HashMap[Char, Int]
+ for char in string.chars do
+ var occ = cpt.get_or_default(char, 0)
+ cpt[char] = occ + 1
+ end
+
+ var len = string.length.to_f
+ var e = 0.0
+ for char, occ in cpt do
+ var freq = occ.to_f / len
+ e = e - freq * freq.log_base(2.0)
+ end
+ return e
+end
+print entropy("1223334444")
+
+# Alternative one-liner implementation using the `Counter::entropy` method of the library `counter`
+print "1223334444".chars.to_counter.entropy
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Entropy/Narcissist
+# SEE: <http://rosettacode.org/wiki/Entropy/Narcissist>
+module entropy_narcissist
+
+import counter
+
+# Should be run in the right directory
+print "entropy_narcissist.nit".to_path.read_all.chars.to_counter.entropy
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Fibonacci_word
+# SEE: <http://rosettacode.org/wiki/Fibonacci_word>
+module fibonacci_word
+
+import counter
+
+var words = new Array[String]
+words[0] = ""
+words[1] = "1"
+words[2] = "0"
+
+for i in [1..37] do
+ var w
+ if i >= words.length then
+ w = words[i-1] + words[i-2]
+ words[i] = w
+ else
+ w = words[i]
+ end
+ var out = w
+ if w.length > 40 then out = "..."
+ print "{i}\t{w.length}\t{w.chars.to_counter.entropy.to_precision(16)}\t{out}"
+end
end
return (sum / map.length.to_f).sqrt
end
+
+ # The information entropy (Shannon entropy) of the elements in the counter (in bits).
+ fun entropy: Float
+ do
+ var res = 0.0
+ var sum = self.sum.to_f
+ for k, v in self do
+ var f = v.to_f / sum
+ res = res - f * f.log_base(2.0)
+ end
+ return res
+ end
+end
+
+redef class Collection[E]
+ # Create and fill up a counter with the elements of `self.
+ #
+ # ~~~
+ # var cpt = "abaa".chars.to_counter
+ # assert cpt['a'] == 3
+ # assert cpt['b'] == 1
+ # assert cpt.length == 2
+ # assert cpt.sum == 4
+ # ~~~
+ fun to_counter: Counter[E]
+ do
+ var res = new Counter[E]
+ res.inc_all(self)
+ return res
+ end
end
private class CounterComparator[E]
# Request Chars internal information from the CURL session
fun easy_getinfo_chars(opt: CURLInfoChars): nullable String
do
- var answ = new Container[NativeString]("".to_cstring)
+ var answ = new Ref[NativeString]("".to_cstring)
if not native_getinfo_chars(opt, answ).is_ok then return null
if answ.item.address_is_null then return null
return answ.item.to_s
end
# Internal method used to get String object information initially knowns as C Chars type
- private fun native_getinfo_chars(opt: CURLInfoChars, res: Container[NativeString]): CURLCode
- import Container[NativeString].item= `{
+ private fun native_getinfo_chars(opt: CURLInfoChars, res: Ref[NativeString]): CURLCode
+ import Ref[NativeString].item= `{
char *r;
CURLcode c = curl_easy_getinfo( self, opt, &r);
- if (c == CURLE_OK) Container_of_NativeString_item__assign(res, r);
+ if (c == CURLE_OK) Ref_of_NativeString_item__assign(res, r);
return c;
`}
# Request Long internal information from the CURL session
fun easy_getinfo_long(opt: CURLInfoLong): nullable Int
do
- var answ = new Container[Int](0)
+ var answ = new Ref[Int](0)
if not native_getinfo_long(opt, answ).is_ok then return null
return answ.item
end
# Internal method used to get Int object information initially knowns as C Long type
- private fun native_getinfo_long(opt: CURLInfoLong, res: Container[Int]): CURLCode
- import Container[Int].item= `{
+ private fun native_getinfo_long(opt: CURLInfoLong, res: Ref[Int]): CURLCode
+ import Ref[Int].item= `{
long r;
CURLcode c = curl_easy_getinfo( self, opt, &r);
- if (c == CURLE_OK) Container_of_Int_item__assign(res, r);
+ if (c == CURLE_OK) Ref_of_Int_item__assign(res, r);
return c;
`}
# Request Double internal information from the CURL session
fun easy_getinfo_double(opt: CURLInfoDouble): nullable Float
do
- var answ = new Container[Float](0.0)
+ var answ = new Ref[Float](0.0)
if not native_getinfo_double(opt, answ).is_ok then return null
return answ.item
end
# Internal method used to get Int object information initially knowns as C Double type
- private fun native_getinfo_double(opt: CURLInfoDouble, res: Container[Float]): CURLCode
- import Container[Float].item= `{
+ private fun native_getinfo_double(opt: CURLInfoDouble, res: Ref[Float]): CURLCode
+ import Ref[Float].item= `{
double r;
CURLcode c = curl_easy_getinfo(self, opt, &r);
- if (c == CURLE_OK) Container_of_Float_item__assign(res, r);
+ if (c == CURLE_OK) Ref_of_Float_item__assign(res, r);
return c;
`}
# Request SList internal information from the CURL session
fun easy_getinfo_slist(opt: CURLInfoSList): nullable Array[String]
do
- var answ = new Container[CURLSList](new CURLSList)
+ var answ = new Ref[CURLSList](new CURLSList)
if not native_getinfo_slist(opt, answ).is_ok then return null
var native = answ.item
end
# Internal method used to get Array[String] object information initially knowns as C SList type
- private fun native_getinfo_slist(opt: CURLInfoSList, res: Container[CURLSList]): CURLCode
- import Container[CURLSList].item= `{
+ private fun native_getinfo_slist(opt: CURLInfoSList, res: Ref[CURLSList]): CURLCode
+ import Ref[CURLSList].item= `{
struct curl_slist* csl;
CURLcode c = curl_easy_getinfo(self, opt, &csl);
- if (c == CURLE_OK) Container_of_CURLSList_item__assign(res, csl);
+ if (c == CURLE_OK) Ref_of_CURLSList_item__assign(res, csl);
return c;
`}
# Get the current time of the day
init now do
var tm = new Tm.localtime
- hour = tm.hour
- minute = tm.min
- second = tm.sec
+ init(tm.hour, tm.min, tm.sec)
end
# Get the difference between two times in second
# The date of this day
init today do
var tm = new Tm.localtime
- year = 1900 + tm.year
- month = tm.mon + 1
- day = tm.mday
+ init(1900 + tm.year, tm.mon + 1, tm.mday)
end
# `self` formatted according to ISO 8601
assert left != null and right != null and top != null and bottom != null
- self.left = left
- self.right = right
- self.top = top
- self.bottom = bottom
+ init(left, right, top, bottom)
end
# Create a `Box` using left, right, bottom and top
init lrbt(left, right, bottom, top: N)
do
- self.left = left
- self.right = right
- self.top = top
- self.bottom = bottom
+ init(left, right, top, bottom)
end
# Create a `Box` using left, right, top and bottom
init lrtb(left, right, top, bottom: N)
do
- self.left = left
- self.right = right
- self.top = top
- self.bottom = bottom
+ init(left, right, top, bottom)
end
# Create a `Box` using left, bottom, width and height
init lbwh(left, bottom, width, height: N)
do
- self.left = left
- self.bottom = bottom
-
- self.right = left + width
- self.top = bottom + height
+ init(left, left + width, bottom + height, bottom)
end
# Create a `Box` using left, top, width and height
init ltwh(left, top, width, height: N)
do
- self.left = left
- self.top = top
-
- self.right = left + width
- self.bottom = top - height
+ init(left, left+width, top, top - height)
end
redef fun to_s do return "<left: {left}, right: {right}, top: {top}, bottom: {bottom}>"
# init calculating the center
init with_center(pts : Array[Array[Float]]) do
- center = calc_center(pts)
+ init(calc_center(pts))
end
# Calculate the center
private var batch_id: nullable Int = null
# Load the entity from base
- private init from_neo(neo: Neo4jClient, url: String) do
+ private init from_neo(neo: Neo4jClient, url: String) is nosuper do
self.neo = neo
self.url = url
end
# Init entity from JSON representation
- private init from_json(neo: Neo4jClient, obj: JsonObject) do
+ private init from_json(neo: Neo4jClient, obj: JsonObject) is nosuper do
self.neo = neo
self.url = obj["self"].to_s
self.internal_properties = obj["data"].as(JsonObject)
# limitations under the License.
# Provides the noise generators `PerlinNoise` and `InterpolatedNoise`
-module noise
+module noise is serialize
+
+import serialization
# 2D noise generator
abstract class Noise
# Seed to the random number generator `gradient_vector`
#
# By default, `seed` has a random value created with `Int::rand`.
- var seed: Int = 19559.rand is lazy, writable
+ var seed: Int = 19511359.rand is lazy, writable
end
# 2D Perlin noise generator using layered `InterpolatedNoise`
# Used to get seeds for layers from the previous layers or `seed`.
protected fun pseudo_random(value: Int): Int
do
- return value + 2935391 % 954847
+ return (value * 3537391).mask % 1291377
end
end
var ix1 = sx.lerp(n0, n1)
var val = sy.lerp(ix0, ix1)
- # Return value in [min...max] from val in [-0.5...0.5]
+ # Return value in [min...max] from val in [-1.0...1.0]
+ val /= 2.0
val += 0.5
return val.lerp(min, max)
end
#
# These magic prime numbers were determined good enough by
# non-emperical experimentation. They may need to be changed/improved.
- var i = 17957*seed + 45127*x + 22613*y
- var mod = 19031
+ var seed = 817721 + self.seed
+ var i = seed * (x+seed) * 25111217 * (y+seed) * 72233613
+ var mod = 137121
+ var angle = (i.mask.abs%mod).to_f*2.0*pi/mod.to_f
+
+ # Debug code to evaluate the efficiency of the random angle generator
+ # The average of the produced angles should be at pi
+ #
+ #var sum = once new Container[Float](0.0)
+ #var count = once new Container[Float](0.0)
+ #sum.item += angle
+ #count.item += 1.0
+ #if count.item.to_i % 1000 == 0 then print "avg:{sum.item/count.item}/{count.item} i:{i} a:{angle} ({x}, {y}: {seed})"
- var angle = (i%mod).to_f*2.0*pi/mod.to_f
if w == 0 then return angle.cos
return angle.sin
end
return dx*gradient_vector(ix, iy, 0) + dy*gradient_vector(ix, iy, 1)
end
end
+
+redef universal Int
+ # The value of the least-significant 30 bits of `self`
+ #
+ # This mask is used as compatibility with 32 bits architecture.
+ # The missing 2 bits are used to tag integers by the Nit system.
+ private fun mask: Int
+ do
+ return bin_and(0x3FFF_FFFF)
+ end
+end
# - [x] `ConcurrentList`
# - [ ] `ConcurrentHashMap`
# - [ ] `ConcurrentHashSet`
-# - [ ] `ConcurrentContainer`
+# - [ ] `ConcurrentRef`
# - [ ] `ConcurrentQueue`
#
# Introduced collections specialize their critical methods according to the
# - [ ] `List`
# - [ ] `HashMap`
# - [ ] `HashSet`
-# - [ ] `Container`
+# - [ ] `Ref`
# - [ ] `Queue`
module redef_collections
end
end
-redef class Container[E]
+redef class Ref[E]
super Serializable
redef init from_deserializer(v)
# Open a connection to the database file at `path`
init open(path: Text)
do
- native_connection = new NativeSqlite3.open(path.to_s)
+ init(new NativeSqlite3.open(path.to_s))
if native_connection.is_valid then is_open = true
end
init(ns, 0, 0)
end
+ # Init a `Bytes` with capacity `cap`
init with_capacity(cap: Int) do
var ns = new NativeString(cap)
init(ns, 0, cap)
end
end
+ # var b = new Bytes.empty
+ # b.append([0x41u8, 0x41u8, 0x18u8])
+ # b.pop
+ # assert b.to_s == "AA"
+ redef fun pop do
+ assert length >= 1
+ length -= 1
+ return items[length]
+ end
+
redef fun clear do length = 0
# Regenerates the buffer, necessary when it was persisted
end
redef class NativeString
+ # Creates a new `Bytes` object from `self` with `strlen` as length
fun to_bytes: Bytes do
var len = cstring_length
return new Bytes(self, len, len)
#
# Also used when one want to give a single element when a full
# collection is expected
-class Container[E]
+class Ref[E]
super Collection[E]
redef fun first do return item
end
end
- redef fun iterator do return new ContainerIterator[E](self)
+ redef fun iterator do return new RefIterator[E](self)
# The stored item
var item: E is writable
end
# This iterator is quite stupid since it is used for only one item.
-private class ContainerIterator[E]
+private class RefIterator[E]
super Iterator[E]
redef fun item do return _container.item
redef var is_ok = true
- var container: Container[E]
+ var container: Ref[E]
end
# Items can be removed from this collection
do
_index = _array.length - 1
end
+
+ # Do not cache `self`
+ redef fun finish do end
end
# Others collections ##########################################################
# Linked nodes that constitute a linked list.
private class ListNode[E]
- super Container[E]
+ super Ref[E]
# The next node.
var next: nullable ListNode[E] = null
init with_pos(tgt: FlatString, pos: Int)
do
- target = tgt
- curr_pos = pos
+ init(tgt, pos)
end
redef fun is_ok do return curr_pos >= 0
init with_pos(tgt: FlatString, pos: Int)
do
- target = tgt
- curr_pos = pos
- max = tgt.length - 1
+ init(tgt, tgt.length - 1, pos)
end
redef fun is_ok do return curr_pos <= max
init with_pos(tgt: FlatString, pos: Int)
do
- target = tgt
- target_items = tgt.items
- curr_pos = pos + tgt.index_from
+ init(tgt, tgt.items, pos + tgt.index_from)
end
redef fun is_ok do return curr_pos >= target.index_from
init with_pos(tgt: FlatString, pos: Int)
do
- target = tgt
- target_items = tgt.items
- curr_pos = pos + target.index_from
+ init(tgt, tgt.items, pos + tgt.index_from)
end
redef fun is_ok do return curr_pos <= target.index_to
init with_pos(tgt: FlatBuffer, pos: Int)
do
- target = tgt
- if tgt.length > 0 then target_items = tgt.items
- curr_pos = pos
+ init(tgt, tgt.items, pos)
end
redef fun index do return curr_pos
init with_pos(tgt: FlatBuffer, pos: Int)
do
- target = tgt
- if tgt.length > 0 then target_items = tgt.items
- curr_pos = pos
+ init(tgt, tgt.items, pos)
end
redef fun index do return curr_pos
init with_pos(tgt: FlatBuffer, pos: Int)
do
- target = tgt
- curr_pos = pos
+ init(tgt, pos)
end
redef fun index do return curr_pos
init with_pos(tgt: FlatBuffer, pos: Int)
do
- target = tgt
- max = tgt.length - 1
- curr_pos = pos
+ init(tgt, tgt.length - 1, pos)
end
redef fun index do return curr_pos
var v = new_visitor
var rta = runtime_type_analysis
- var is_dead = rta != null and not rta.live_classes.has(mclass) and not mtype.is_c_primitive and mclass.name != "NativeArray" and mclass.name != "Pointer"
+ var is_dead = rta != null and not rta.live_classes.has(mclass)
+ # While the class may be dead, some part of separately compiled code may use symbols associated to the class, so
+ # in order to compile and link correctly the C code, these symbols should be declared and defined.
+ var need_corpse = is_dead and mtype.is_c_primitive or mclass.kind == extern_kind or mclass.kind == enum_kind
- v.add_decl("/* runtime class {c_name} */")
+ v.add_decl("/* runtime class {c_name}: {mclass.full_name} (dead={is_dead}; need_corpse={need_corpse})*/")
# Build class vft
- if not is_dead then
+ if not is_dead or need_corpse then
self.provide_declaration("class_{c_name}", "extern const struct class class_{c_name};")
v.add_decl("const struct class class_{c_name} = \{")
v.add_decl("{self.box_kind_of(mclass)}, /* box_kind */")
self.header.add_decl("{mtype.ctype_extern} value;")
self.header.add_decl("\};")
- if not rta.live_types.has(mtype) and mtype.mclass.name != "Pointer" then return
+ # Pointer is needed by extern types, live or not
+ if is_dead and mtype.mclass.name != "Pointer" then return
#Build BOX
self.provide_declaration("BOX_{c_name}", "val* BOX_{c_name}({mtype.ctype_extern});")
v.add("return (val*)res;")
v.add("\}")
+ # A Pointer class also need its constructor
if mtype.mclass.name != "Pointer" then return
v = new_visitor
var pointer_type = mainmodule.pointer_type
self.provide_declaration("NEW_{c_name}", "{mtype.ctype} NEW_{c_name}(const struct type* type);")
- v.add_decl("/* allocate {mtype} */")
+ v.add_decl("/* allocate extern {mtype} */")
v.add_decl("{mtype.ctype} NEW_{c_name}(const struct type* type) \{")
if is_dead then
v.add_abort("{mclass} is DEAD")
end
return self.new_expr("((struct instance_{mtype.c_name}*){value})->value; /* autounbox from {value.mtype} to {mtype} */", mtype)
else if not mtype.is_c_primitive then
+ assert value.mtype == value.mcasttype
if value.mtype.is_tagged then
+ var res
if value.mtype.name == "Int" then
- return self.new_expr("(val*)({value}<<2|1)", mtype)
+ res = self.new_expr("(val*)({value}<<2|1)", mtype)
else if value.mtype.name == "Char" then
- return self.new_expr("(val*)((long)({value})<<2|2)", mtype)
+ res = self.new_expr("(val*)((long)({value})<<2|2)", mtype)
else if value.mtype.name == "Bool" then
- return self.new_expr("(val*)((long)({value})<<2|3)", mtype)
+ res = self.new_expr("(val*)((long)({value})<<2|3)", mtype)
else
abort
end
+ # Do not loose type info
+ res.mcasttype = value.mcasttype
+ return res
end
var valtype = value.mtype.as(MClassType)
if mtype isa MClassType and mtype.mclass.kind == extern_kind and mtype.mclass.name != "NativeString" then
valtype = compiler.mainmodule.pointer_type
end
var res = self.new_var(mtype)
- if compiler.runtime_type_analysis != null and not compiler.runtime_type_analysis.live_types.has(valtype) then
- self.add("/*no autobox from {value.mtype} to {mtype}: {value.mtype} is not live! */")
- self.add("PRINT_ERROR(\"Dead code executed!\\n\"); fatal_exit(1);")
- return res
- end
+ # Do not loose type info
+ res.mcasttype = value.mcasttype
self.require_declaration("BOX_{valtype.c_name}")
self.add("{res} = BOX_{valtype.c_name}({value}); /* autobox from {value.mtype} to {mtype} */")
return res
mtype.mclass.name != "NativeString" then
var valtype = compiler.mainmodule.pointer_type
var res = self.new_var(mtype)
- if compiler.runtime_type_analysis != null and not compiler.runtime_type_analysis.live_types.has(value.mtype.as(MClassType)) then
- self.add("/*no boxing of {value.mtype}: {value.mtype} is not live! */")
- self.add("PRINT_ERROR(\"Dead code executed!\\n\"); fatal_exit(1);")
- return res
- end
+ compiler.undead_types.add(mtype)
self.require_declaration("BOX_{valtype.c_name}")
self.add("{res} = BOX_{valtype.c_name}({value}); /* boxing {value.mtype} */")
self.require_declaration("type_{mtype.c_name}")
var file: Stream
init native_stdin do
- file = sys.stdin
+ init(sys.stdin)
end
init native_stdout do
- file = sys.stdout
+ init(sys.stdout)
end
init native_stderr do
- file = sys.stderr
+ init(sys.stderr)
end
init io_open_read(path: String) do
- file = new FileReader.open(path.to_s)
+ init(new FileReader.open(path.to_s))
end
init io_open_write(path: String) do
- file = new FileWriter.open(path.to_s)
+ init(new FileWriter.open(path.to_s))
end
fun address_is_null: Bool do
end
# Create a new sourcefile using a dummy filename and a given content
- init from_string(filename: String, string: String)
+ init from_string(filename: String, string: String) is
+ nosuper
do
self.filename = filename
self.string = string
# loc = new Location.from_string("location.nit:82--105,8")
# assert loc.to_s == "location.nit:82,0--105,8"
# ~~~
- init from_string(string: String) do
+ init from_string(string: String) is
+ nosuper
+ do
self.line_start = 0
self.line_end = 0
self.column_start = 0
var i = 0
for p in spd.initializers do
if p != longest.initializers[i] then
- self.error(nclassdef, "Error: conflict for inherited inits {spd}({spd.initializers.join(", ")}) and {longest}({longest.initializers.join(", ")})")
+ var proposal = new ArraySet[MProperty]
+ for spd2 in spropdefs do
+ proposal.add_all spd2.initializers
+ end
+ proposal.add_all initializers
+ self.error(nclassdef, "Error: cannot generate automatic init for class {mclassdef.mclass}. Conflict in the order in inherited initializers {spd}({spd.initializers.join(", ")}) and {longest}({longest.initializers.join(", ")}). Use `autoinit` to order initializers. eg `autoinit {proposal.join(", ")}`")
# TODO: invalidate the initializer to avoid more errors
return
end
return
end
- # Do we inherit for a constructor?
- var skip = true
- for cd in mclassdef.in_hierarchy.direct_greaters do
- if cd.mclass.kind.need_init then skip = false
- end
- if skip then return
-
# Now we search for the absence of any explicit super-init invocation
# * via a "super"
# * via a call of an other init
class D
super B
super C
- #alt3#var b: Int
+ #alt3,5#var b: Int
#alt4#var b = 11
init do 'd'.output #alt2#
end
super D
super E
init do 'f'.output #alt1,2#
+ #alt5#autoinit c=, e=
end
class G
super E
var g: Int
init do 'g'.output #alt2#
+ #alt5#autoinit c=, e=, g=
end
class H
fun maybe: Bool do return true
-var a = new Container[Int](1)
+var a = new Ref[Int](1)
1.output
for i in a do
2.output
end
end
- var t: Array[Int] # The stack of discus (only the diameter is stored).
+ var t = new Array[Int] # The stack of discus (only the diameter is stored).
init full(n: Int)
# Build a new tower with `n' discus.
do
assert positive: n >= 0
- _t = new Array[Int].with_capacity(n)
+ t.enlarge(n)
for i in [0..n[ do
push(n-i)
end
init empty
# Build a empty tower.
do
- _t = new Array[Int]
end
end
blink
input
first_letter_last_letter
+fibonacci_word
blink
input
first_letter_last_letter
+fibonacci_word
-alt/base_init_basic_alt3.nit:47,7: Error: conflict for inherited inits base_init_basic_alt3#E#init(c=, e=) and base_init_basic_alt3#D#init(c=, b=)
-alt/base_init_basic_alt3.nit:53,7: Error: conflict for inherited inits base_init_basic_alt3#E#init(c=, e=) and base_init_basic_alt3#D#init(c=, b=)
+alt/base_init_basic_alt3.nit:47,7: Error: cannot generate automatic init for class F. Conflict in the order in inherited initializers base_init_basic_alt3#E#init(c=, e=) and base_init_basic_alt3#D#init(c=, b=). Use `autoinit` to order initializers. eg `autoinit c=, b=, e=`
+alt/base_init_basic_alt3.nit:54,7: Error: cannot generate automatic init for class G. Conflict in the order in inherited initializers base_init_basic_alt3#E#init(c=, e=) and base_init_basic_alt3#D#init(c=, b=). Use `autoinit` to order initializers. eg `autoinit c=, b=, e=, g=`
--- /dev/null
+alt/base_init_basic_alt5.nit:79,9--11: Error: expected 2 argument(s) for `init(c: Int, b: Int)`; got 1. See introduction at `standard::Object::init`.
1
2
+1
2
3
+1
2
+1
2
5
+1
2
6
1
2
+1
2
3
+1
2
+1
2
5
+1
2
6
A B3
A B4y
C1 C2
-A2z C3z
-D1 B1 A B2 D2 D3
+C1 C2 A2z C3z
+D1 B1 C1 C2 A B2 D2 D3
A B3
A B4y
C1 C2
-A2z C3z
+C1 C2 A2z C3z
C1 C2 D1 D2 D3
A B3
A B4y
C1 C2
-A2z C3z
-D1 B1 A B2 D2 C1 C2 D3
+C1 C2 A2z C3z
+D1 B1 C1 C2 A B2 D2 C1 C2 D3
A B3
A B4y
C1 C2
-A2z C3z
-D1 C1 C2 B1 A B2 D2 D3
+C1 C2 A2z C3z
+D1 C1 C2 B1 C1 C2 A B2 D2 D3
A B3
A B4y
C1 C2
-A2z C3z
-D1 B1 A B2 D2 B1 A B2 D3
+C1 C2 A2z C3z
+D1 B1 C1 C2 A B2 D2 B1 C1 C2 A B2 D3
A
-a
+Aa
A1
-a2
+A1a2
A13
--- /dev/null
+1.846
+1.846
--- /dev/null
+1 1 0.0000000000000000 1
+2 1 0.0000000000000000 0
+3 2 1.0000000000000000 01
+4 3 0.9182958340544894 010
+5 5 0.9709505944546686 01001
+6 8 0.9544340029249650 01001010
+7 13 0.9612366047228760 0100101001001
+8 21 0.9587118829771316 010010100100101001010
+9 34 0.9596868937742170 0100101001001010010100100101001001
+10 55 0.9593160320543778 ...
+11 89 0.9594579158386696 ...
+12 144 0.9594037542210228 ...
+13 233 0.9594244469559864 ...
+14 377 0.9594165437404406 ...
+15 610 0.9594195626031440 ...
+16 987 0.9594184095152248 ...
+17 1597 0.9594188499578102 ...
+18 2584 0.9594186817240320 ...
+19 4181 0.9594187459836638 ...
+20 6765 0.9594187214386752 ...
+21 10946 0.9594187308140276 ...
+22 17711 0.9594187272329618 ...
+23 28657 0.9594187286008076 ...
+24 46368 0.9594187280783368 ...
+25 75025 0.9594187282779028 ...
+26 121393 0.9594187282016752 ...
+27 196418 0.9594187282307916 ...
+28 317811 0.9594187282196702 ...
+29 514229 0.9594187282239182 ...
+30 832040 0.9594187282222962 ...
+31 1346269 0.9594187282229156 ...
+32 2178309 0.9594187282226794 ...
+33 3524578 0.9594187282227690 ...
+34 5702887 0.9594187282227344 ...
+35 9227465 0.9594187282227478 ...
+36 14930352 0.9594187282227430 ...
+37 24157817 0.9594187282227448 ...
# Src:
<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
# Dst:
-<G: hs: ; s: ; hm: ; am: >
+<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
{"__kind": "obj", "__id": 0, "__class": "G", "hs": {"__kind": "obj", "__id": 1, "__class": "HashSet", "__items": [-1, 0]}, "s": {"__kind": "obj", "__id": 2, "__class": "ArraySet", "__items": ["one", "two"]}, "hm": {"__kind": "obj", "__id": 3, "__class": "HashMap", "__length": 2, "__keys": ["one", "two"], "__values": [1, 2]}, "am": {"__kind": "obj", "__id": 4, "__class": "ArrayMap", "__length": 2, "__keys": ["three", "four"], "__values": ["3", "4"]}}
# Back in Nit:
-<G: hs: ; s: ; hm: ; am: >
+<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
sum: 0
## Callsites
-* 22 live callsites
+* 23 live callsites
MMethodDef locally designated (by number of CallSites)
- population: 13
+ population: 14
minimum value: 1
maximum value: 10
- total value: 22
- average value: 1.69
+ total value: 23
+ average value: 1.64
distribution:
- <=1: sub-population=12 (92.30%); cumulated value=12 (54.54%)
- <=16: sub-population=1 (7.69%); cumulated value=10 (45.45%)
+ <=1: sub-population=13 (92.85%); cumulated value=13 (56.52%)
+ <=16: sub-population=1 (7.14%); cumulated value=10 (43.47%)
list:
- base_simple3#Int#output: 10 (45.45%)
- base_simple3#B#val: 1 (4.54%)
- base_simple3#B#val=: 1 (4.54%)
- base_simple3#C#val2: 1 (4.54%)
- base_simple3#C#val1: 1 (4.54%)
+ base_simple3#Int#output: 10 (43.47%)
+ base_simple3#B#val: 1 (4.34%)
+ base_simple3#B#val=: 1 (4.34%)
+ base_simple3#Object#init: 1 (4.34%)
+ base_simple3#C#val2: 1 (4.34%)
...
- base_simple3#A#init: 1 (4.54%)
- base_simple3#Sys#baz: 1 (4.54%)
- base_simple3#Sys#bar: 1 (4.54%)
- base_simple3#Sys#foo: 1 (4.54%)
- base_simple3#C#init: 1 (4.54%)
+ base_simple3#A#init: 1 (4.34%)
+ base_simple3#Sys#baz: 1 (4.34%)
+ base_simple3#Sys#bar: 1 (4.34%)
+ base_simple3#Sys#foo: 1 (4.34%)
+ base_simple3#C#init: 1 (4.34%)
MMethodDef possibly invoked at runtime (by number of CallSites)
- population: 13
+ population: 14
minimum value: 1
maximum value: 10
- total value: 22
- average value: 1.69
+ total value: 23
+ average value: 1.64
distribution:
- <=1: sub-population=12 (92.30%); cumulated value=12 (54.54%)
- <=16: sub-population=1 (7.69%); cumulated value=10 (45.45%)
+ <=1: sub-population=13 (92.85%); cumulated value=13 (56.52%)
+ <=16: sub-population=1 (7.14%); cumulated value=10 (43.47%)
list:
- base_simple3#Int#output: 10 (45.45%)
- base_simple3#B#val: 1 (4.54%)
- base_simple3#B#val=: 1 (4.54%)
- base_simple3#C#val2: 1 (4.54%)
- base_simple3#C#val1: 1 (4.54%)
+ base_simple3#Int#output: 10 (43.47%)
+ base_simple3#B#val: 1 (4.34%)
+ base_simple3#B#val=: 1 (4.34%)
+ base_simple3#Object#init: 1 (4.34%)
+ base_simple3#C#val2: 1 (4.34%)
...
- base_simple3#A#init: 1 (4.54%)
- base_simple3#Sys#baz: 1 (4.54%)
- base_simple3#Sys#bar: 1 (4.54%)
- base_simple3#Sys#foo: 1 (4.54%)
- base_simple3#C#init: 1 (4.54%)
+ base_simple3#A#init: 1 (4.34%)
+ base_simple3#Sys#baz: 1 (4.34%)
+ base_simple3#Sys#bar: 1 (4.34%)
+ base_simple3#Sys#foo: 1 (4.34%)
+ base_simple3#C#init: 1 (4.34%)
class_hierarchy.dot
classdef_hierarchy.dot
inheritance/
-../lib/standard/bytes.nit:49,7--19: Documentation warning: Undocumented property `with_capacity`
-../lib/standard/bytes.nit:162,6--13: Documentation warning: Undocumented property `to_bytes`
../lib/standard/stream.nit:426,6--17: Documentation warning: Undocumented property `buffer_reset`
../lib/standard/file.nit:455,6--19: Documentation warning: Undocumented property `read_all_bytes`
test_advice_repeated_types.nit:36,15--20: Warning: useless type repetition on redefined attribute `_a`
-Runtime error: Cast failed. Expected `E`, got `Bool` (../lib/standard/collection/array.nit:957)
+Runtime error: Cast failed. Expected `E`, got `Bool` (../lib/standard/collection/array.nit:960)
NativeString
0x4e
Nit