end
var ci = 0
- for c in self do
+ for c in self.chars do
var local_dispc
if c.override_dispc then
local_dispc = c
b = gets.to_i
printn "Operator (+, -, *, /, %): "
- op_char = gets[0]
+ op_char = gets.chars[0]
printn "Char to display: "
- disp_char = gets[0]
+ disp_char = gets.chars[0]
printn "Size of text: "
disp_size = gets.to_i
do
var inv_base64_chars = new HashMap[Char,Int]
for k in [0..base64_chars.length[ do
- inv_base64_chars[ base64_chars[k] ] = k
+ inv_base64_chars[ base64_chars.chars[k] ] = k
end
return inv_base64_chars
end
for s in [0..steps[ do
var e = 0
for ss in [0..3[ do
- e += self[s*3+ss].ascii.lshift((2-ss)*8)
+ e += self.chars[s*3+ss].ascii.lshift((2-ss)*8)
end
for ss in [0..4[ do
- result[s*4+3-ss] = base64_chars[ e.rshift(ss*6).bin_and( mask_6bit ) ]
+ result[s*4+3-ss] = base64_chars.chars[ e.rshift(ss*6).bin_and( mask_6bit ) ]
end
end
if chars_in_last_step == 1 then
- var e = self[length-1].ascii.lshift(16)
+ var e = self.chars[length-1].ascii.lshift(16)
for ss in [0..2[ do
- result[steps*4+1-ss] = base64_chars[ e.rshift((ss+2)*6).bin_and( mask_6bit ) ]
+ result[steps*4+1-ss] = base64_chars.chars[ e.rshift((ss+2)*6).bin_and( mask_6bit ) ]
end
else if chars_in_last_step == 2 then
- var e = self[length-2].ascii.lshift(16) +
- self[length-1].ascii.lshift(8)
+ var e = self.chars[length-2].ascii.lshift(16) +
+ self.chars[length-1].ascii.lshift(8)
for ss in [0..3[ do
- result[steps*4+2-ss] = base64_chars[ e.rshift((ss+1)*6).bin_and( mask_6bit ) ]
+ result[steps*4+2-ss] = base64_chars.chars[ e.rshift((ss+1)*6).bin_and( mask_6bit ) ]
end
end
for s in [0..steps[ do
var e = 0
for ss in [0..4[ do
- e += inverted_base64_chars[self[s*4+ss]].lshift((3-ss)*6)
+ e += inverted_base64_chars[self.chars[s*4+ss]].lshift((3-ss)*6)
end
for ss in [0..3[ do
if padding_count == 1 then
var e = 0
for ss in [0..3[ do
- e += inverted_base64_chars[self[s*4+ss]].lshift((3-ss)*6)
+ e += inverted_base64_chars[self.chars[s*4+ss]].lshift((3-ss)*6)
end
for ss in [0..2[ do
else if padding_count == 2 then
var e = 0
for ss in [0..2[ do
- e += inverted_base64_chars[self[s*4+ss]].lshift((3-ss)*6)
+ e += inverted_base64_chars[self.chars[s*4+ss]].lshift((3-ss)*6)
end
result[s*3] = e.rshift(2*8).bin_and( mask_8bit ).ascii
clear
return_home
var count = 0
- for c in v do
+ for c in v.chars do
if c == '\n' then
# FIXME, this should work
#write(true, "C0".to_hex)
redef fun to_c: nullable Char
do
- if key_name.length == 1 then return key_name.first
+ if key_name.length == 1 then return key_name.chars.first
return null
end
redef fun read_param(it)
do
super
- if it.is_ok and it.item.first != '-' then
+ if it.is_ok and it.item.chars.first != '-' then
value = convert(it.item)
it.next
else
if str.last_index_of('-') == 0 and str.length > 2 then
var next_called = false
for i in [1..str.length] do
- var short_opt = "-" + str[i].to_s
+ var short_opt = "-" + str.chars[i].to_s
if _optmap.has_key(short_opt) then
var option = _optmap[short_opt]
if option isa OptionParameter then
fun dirname: String
do
var l = _length - 1 # Index of the last char
- if l > 0 and self[l] == '/' then l -= 1 # remove trailing `/`
+ if l > 0 and self.chars[l] == '/' then l -= 1 # remove trailing `/`
var pos = last_index_of_from('/', l)
if pos > 0 then
return substring(0, pos)
do
if path.is_empty then return self
if self.is_empty then return path
- if path[0] == '/' then return path
+ if path.chars[0] == '/' then return path
return "{self}/{path}"
end
module standard
import posix
-import ropes
import environ
import time
import string_search
if eof then return
else
var c = x.ascii
- s.push(c)
+ s.chars.push(c)
if c == '\n' then return
end
end
if _buffer_pos >= _buffer.length then
return -1
end
- var c = _buffer[_buffer_pos]
+ var c = _buffer.chars[_buffer_pos]
_buffer_pos += 1
return c.ascii
end
k = _buffer.length
end
while j < k and i > 0 do
- s.add(_buffer[j])
+ s.add(_buffer.chars[j])
j += 1
i -= 1
end
var j = _buffer_pos
var k = _buffer.length
while j < k do
- s.add(_buffer[j])
+ s.add(_buffer.chars[j])
j += 1
end
_buffer_pos = j
loop
# First phase: look for a '\n'
var i = _buffer_pos
- while i < _buffer.length and _buffer[i] != '\n' do i += 1
+ while i < _buffer.length and _buffer.chars[i] != '\n' do i += 1
# if there is something to append
if i > _buffer_pos then
# Copy from the buffer to the string
var j = _buffer_pos
while j < i do
- s.add(_buffer[j])
+ s.add(_buffer.chars[j])
j += 1
end
end
readable private var _items: NativeString
+ fun chars: StringCharView is abstract
+
# Access a character at `index` in the string.
#
# assert "abcd"[2] == 'c'
if from < count then
var r = new Buffer.with_capacity(count - from)
while from < count do
- r.push(_items[from])
+ r.chars.push(_items[from])
from += 1
end
return r.to_s
var i = 0
var neg = false
- for c in self
+ for c in self.chars
do
var v = c.to_i
if v > base then
fun is_numeric: Bool
do
var has_point_or_comma = false
- for i in self
+ for i in self.chars
do
if not i.is_numeric
then
fun to_upper: String
do
var s = new Buffer.with_capacity(length)
- for i in self do s.add(i.to_upper)
+ for i in self.chars do s.add(i.to_upper)
return s.to_s
end
fun to_lower : String
do
var s = new Buffer.with_capacity(length)
- for i in self do s.add(i.to_lower)
+ for i in self.chars do s.add(i.to_lower)
return s.to_s
end
# assert "\na\nb\tc\t".trim == "a\nb\tc"
fun trim: String
do
- if self._length == 0 then return self.to_s
+ if self.length == 0 then return self.to_s
# find position of the first non white space char (ascii < 32) from the start of the string
var start_pos = 0
- while self[start_pos].ascii <= 32 do
+ while self.chars[start_pos].ascii <= 32 do
start_pos += 1
- if start_pos == _length then return ""
+ if start_pos == length then return ""
end
# find position of the first non white space char from the end of the string
var end_pos = length - 1
- while self[end_pos].ascii <= 32 do
+ while self.chars[end_pos].ascii <= 32 do
end_pos -= 1
- if end_pos == start_pos then return self[start_pos].to_s
+ if end_pos == start_pos then return self.chars[start_pos].to_s
end
return self.substring(start_pos, end_pos - start_pos + 1)
end
do
var res = new Buffer
var underscore = false
- for c in self do
+ for c in self.chars do
if (c >= 'a' and c <= 'z') or (c >='A' and c <= 'Z') then
res.add(c)
underscore = false
fun escape_to_c: String
do
var b = new Buffer
- for c in self do
+ for c in self.chars do
if c == '\n' then
b.append("\\n")
else if c == '\0' then
end
end
+# Abstract class for the SequenceRead compatible
+# views on String and Buffer objects
+abstract class StringCharView
+ super SequenceRead[Char]
+
+ type SELFTYPE: AbstractString
+
+ private var target: SELFTYPE
+
+ private init(tgt: SELFTYPE)
+ do
+ target = tgt
+ end
+
+ redef fun is_empty do return target.is_empty
+
+ redef fun length do return target.length
+
+ redef fun has(c: Char): Bool
+ do
+ for i in self do
+ if i == c then return true
+ end
+ return false
+ end
+
+end
+
+# View on Buffer objects, extends Sequence
+# for mutation operations
+abstract class BufferCharView
+ super StringCharView
+ super Sequence[Char]
+
+ redef type SELFTYPE: Buffer
+
+end
+
# Immutable strings of characters.
class String
super Comparable
# Indes in _items of the last item of the string
readable var _index_to: Int
+ redef var chars: StringCharView = new FlatStringCharView(self)
+
################################################
# AbstractString specific methods #
################################################
var realFrom = _index_from + from
- if (realFrom + count) > _index_to then return new String.from_substring(realFrom, _index_to, _items)
+ if (realFrom + count) > _index_to then return new String.with_infos(_items, _index_to - realFrom + 1, realFrom, _index_to)
if count == 0 then return ""
- return new String.from_substring(realFrom, realFrom + count - 1, _items)
+ var to = realFrom + count - 1
+
+ return new String.with_infos(_items, to - realFrom + 1, realFrom, to)
end
redef fun substring_from(from: Int): String
# String Specific Methods #
##################################################
- # Creates a String object as a substring of another String
- #
- # From : index to start at
- #
- # To : Index to stop at (from + count -1)
- #
- private init from_substring(from: Int, to: Int, internalString: NativeString)
- do
- _items = internalString
- _index_from = from
- _index_to = to
- _length = to - from + 1
- end
-
private init with_infos(items: NativeString, len: Int, from: Int, to: Int)
do
self._items = items
end
end
+private class FlatStringIterator
+ super IndexedIterator[Char]
+
+ var target: String
+
+ var target_items: NativeString
+
+ var curr_pos: Int
+
+ init with_pos(tgt: String, pos: Int)
+ do
+ target = tgt
+ target_items = tgt.items
+ curr_pos = pos + target.index_from
+ end
+
+ redef fun is_ok do return curr_pos <= target.index_to
+
+ redef fun item do return target_items[curr_pos]
+
+ redef fun next do curr_pos += 1
+
+ redef fun index do return curr_pos - target.index_from
+
+end
+
+private class FlatStringCharView
+ super StringCharView
+
+ redef type SELFTYPE: String
+
+ redef fun [](index)
+ do
+ # Check that the index (+ index_from) is not larger than indexTo
+ # In other terms, if the index is valid
+ assert index >= 0
+ assert (index + target._index_from) <= target._index_to
+ return target._items[index + target._index_from]
+ end
+
+ redef fun iterator: IndexedIterator[Char] do return new FlatStringIterator.with_pos(target, 0)
+
+end
+
# Mutable strings of characters.
class Buffer
super AbstractString
redef type OTHER: String
+ redef var chars: BufferCharView = new FlatBufferCharView(self)
+
redef fun []=(index, item)
do
if index == length then
var l1 = length
var l2 = s.length
while i < l1 and i < l2 do
- var c1 = self[i].ascii
- var c2 = s[i].ascii
+ var c1 = self.chars[i].ascii
+ var c2 = s.chars[i].ascii
if c1 < c2 then
return true
else if c2 < c1 then
readable private var _capacity: Int
end
+private class FlatBufferCharView
+ super BufferCharView
+ super StringCapable
+
+ redef type SELFTYPE: Buffer
+
+ init(tgt: Buffer)
+ do
+ self.target = tgt
+ end
+
+ redef fun [](index) do return target._items[index]
+
+ redef fun []=(index, item)
+ do
+ assert index >= 0 and index <= length
+ if index == length then
+ add(item)
+ return
+ end
+ target._items[index] = item
+ end
+
+ redef fun push(c)
+ do
+ target.add(c)
+ end
+
+ redef fun add(c)
+ do
+ target.add(c)
+ end
+
+ fun enlarge(cap: Int)
+ do
+ target.enlarge(cap)
+ end
+
+ redef fun append(s)
+ do
+ var my_items = target.items
+ var s_length = s.length
+ if target.capacity < s.length then enlarge(s_length + target.length)
+ end
+
+ redef fun iterator: IndexedIterator[Char] do return new FlatBufferIterator.with_pos(target, 0)
+
+end
+
+private class FlatBufferIterator
+ super IndexedIterator[Char]
+
+ var target: Buffer
+
+ var target_items: NativeString
+
+ var curr_pos: Int
+
+ init with_pos(tgt: Buffer, pos: Int)
+ do
+ target = tgt
+ target_items = tgt.items
+ curr_pos = pos
+ end
+
+ redef fun index do return curr_pos
+
+ redef fun is_ok do return curr_pos < target.length
+
+ redef fun item do return target_items[curr_pos]
+
+ redef fun next do curr_pos += 1
+
+end
+
###############################################################################
# Refinement #
###############################################################################
# Sign
if self < 0 then
n = - self
- s[0] = '-'
+ s.chars[0] = '-'
else if self == 0 then
- s[0] = '0'
+ s.chars[0] = '0'
return
else
n = self
# Fill digits
var pos = digit_count(base) - 1
while pos >= 0 and n > 0 do
- s[pos] = (n % base).to_c
+ s.chars[pos] = (n % base).to_c
n = n / base # /
pos -= 1
end
var len = str.length
for i in [0..len-1] do
var j = len-1-i
- var c = str[j]
+ var c = str.chars[j]
if c == '0' then
continue
else if c == '.' then
redef fun to_s
do
var s = new Buffer.with_capacity(1)
- s[0] = self
+ s.chars[0] = self
return s.to_s
end
var j = from
while j < n - m + 1 do
var i = m - 1 # Cursor in the pattern
- while i >= 0 and _motif[i] == s[i + j] do i -= 1
+ while i >= 0 and _motif.chars[i] == s.chars[i + j] do i -= 1
if i < 0 then
return j
else
var gs = _gs[i] # Good shift
- var bc = bc(s[i+j]) - m + 1 + i # Bad char
+ var bc = bc(s.chars[i+j]) - m + 1 + i # Bad char
# Both are true, do move to the best
if gs > bc then
j += gs
var m = _length
var i = 0
while i < m - 1 do
- _bc_table[x[i]] = m - i - 1
+ _bc_table[x.chars[i]] = m - i - 1
i += 1
end
end
else
if i < g then g = i
f = i
- while g >= 0 and x[g] == x[g + m - 1 - f] do g -= 1
+ while g >= 0 and x.chars[g] == x.chars[g + m - 1 - f] do g -= 1
suff[i] = f - g
end
i -= 1
do
var stop = s.length
while from < stop do
- if s[from] == self then return from
+ if s.chars[from] == self then return from
from += 1
end
return -1
var stop = s.length - length + 1
while from < stop do
var i = length - 1
- while i >= 0 and self[i] == s[i + from] do i -= 1
+ while i >= 0 and self.chars[i] == s.chars[i + from] do i -= 1
# Test if we found
if i < 0 then return from
# Not found so try next one
fun html_escape: String
do
var ret = self
- if ret.has('&') then ret = ret.replace('&', "&")
- if ret.has('<') then ret = ret.replace('<', "<")
- if ret.has('>') then ret = ret.replace('>', ">")
- if ret.has('"') then ret = ret.replace('"', """)
+ if ret.chars.has('&') then ret = ret.replace('&', "&")
+ if ret.chars.has('<') then ret = ret.replace('<', "<")
+ if ret.chars.has('>') then ret = ret.replace('>', ">")
+ if ret.chars.has('"') then ret = ret.replace('"', """)
return ret
end
end
args = v.frame.arguments
end
- var mproperty = self.mproperty
- if mproperty != null then
- if mproperty.intro.msignature.arity == 0 then
+ var callsite = self.callsite
+ if callsite != null then
+ if callsite.mproperty.intro.msignature.arity == 0 then
args = [recv]
end
# Super init call
- var res = v.send(mproperty, args)
+ var res = v.compile_callsite(callsite, args)
return res
end
redef class ASendExpr
redef fun accept_auto_super_init(v)
do
- var mproperty = self.mproperty
+ var mproperty = self.callsite.mproperty
if mproperty == null then return
if mproperty.is_init then
v.has_explicit_super_init = true
return
end
n.visit_all(self)
- if n isa ASuperExpr and n.mproperty == null then
+ if n isa ASuperExpr and n.callsite == null then
var mprop = mpropdef
assert mprop != null
res.add(mprop)
print "\nEnd of current instruction \n"
else if parts_of_command[1] == "stack" then
print self.stack_trace
- else if parts_of_command[1].has('[') and parts_of_command[1].has(']') then
+ else if parts_of_command[1].chars.has('[') and parts_of_command[1].chars.has(']') then
process_array_command(parts_of_command)
else
var instance = seek_variable(get_real_variable_name(parts_of_command[1]), frame)
var trigger_string_escape = false
var trigger_concat_in_string = false
- for i in instruction do
+ for i in instruction.chars do
if trigger_char_escape then
if i == '\'' then trigger_char_escape = false
else if trigger_string_escape then
if i.is_alphanumeric or i == '_' then
instruction_buffer.add(i)
else if i == '.' then
- if instruction_buffer.is_numeric or (instruction_buffer[0] >= 'A' and instruction_buffer[0] <= 'Z') then
+ if instruction_buffer.is_numeric or (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then
instruction_buffer.clear
else
result_array.push(instruction_buffer.to_s)
trigger_concat_in_string = false
trigger_string_escape = true
else
- if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer[0] >= 'A' and instruction_buffer[0] <= 'Z') then result_array.push(instruction_buffer.to_s)
+ if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then result_array.push(instruction_buffer.to_s)
instruction_buffer.clear
end
end
end
- if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer[0] >= 'A' and instruction_buffer[0] <= 'Z') then result_array.push(instruction_buffer.to_s)
+ if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then result_array.push(instruction_buffer.to_s)
return result_array
end
var buf = new Buffer
var trigger_copy = false
- for i in function do
+ for i in function.chars do
if i == ')' then break
if trigger_copy then buf.add(i)
if i == '(' then trigger_copy = true
var last_was_opening_bracket = false
- for i in braces do
+ for i in braces.chars do
if i == '[' then
if last_was_opening_bracket then
return null
fun get_char(value: String): nullable Instance
do
if value.length >= 1 then
- return char_instance(value[0])
+ return char_instance(value.chars[0])
else
return null
end
v.toolcontext.error(self.hot_location, "Invalid character literal {txt}")
return
end
- self.value = txt[1]
+ self.value = txt.chars[1]
end
end
do
var txt = self.n_string.text
var skip = 1
- if txt[0] == txt[1] and txt.length >= 6 then skip = 3
+ if txt.chars[0] == txt.chars[1] and txt.length >= 6 then skip = 3
self.value = txt.substring(skip, txt.length-(2*skip)).unescape_nit
end
end
var line_start = l.file.line_starts[i-1]
var line_end = line_start
var string = l.file.string
- while line_end+1 < string.length and string[line_end+1] != '\n' and string[line_end+1] != '\r' do
+ while line_end+1 < string.length and string.chars[line_end+1] != '\n' and string.chars[line_end+1] != '\r' do
line_end += 1
end
var lstart = string.substring(line_start, l.column_start - 1)
end
var indent = new Buffer
for j in [line_start..line_start+l.column_start-1[ do
- if string[j] == '\t' then
+ if string.chars[j] == '\t' then
indent.add '\t'
else
indent.add ' '
# Count the number of spaces
lastindent = indent
indent = 0
- while text.length > indent and text[indent] == ' ' do indent += 1
+ while text.length > indent and text.chars[indent] == ' ' do indent += 1
# Is codeblock? Then just collect them
if indent > 4 then
if arg1 >= recvval.length or arg1 < 0 then
debug("Illegal access on {recvval} for element {arg1}/{recvval.length}")
end
- return v.char_instance(recvval[arg1])
+ return v.char_instance(recvval.chars[arg1])
else if pname == "[]=" then
var arg1 = args[1].to_i
if arg1 >= recvval.length or arg1 < 0 then
debug("Illegal access on {recvval} for element {arg1}/{recvval.length}")
end
- recvval[arg1] = args[2].val.as(Char)
+ recvval.chars[arg1] = args[2].val.as(Char)
return null
else if pname == "copy_to" then
# sig= copy_to(dest: NativeString, length: Int, from: Int, to: Int)
var vari = v.frame.map[self.variable.as(not null)]
var value = v.expr(self.n_value)
if value == null then return
- var res = v.send(reassign_property.mproperty, [vari, value])
+ var res = v.send(reassign_callsite.mproperty, [vari, value])
assert res != null
v.frame.map[self.variable.as(not null)] = res
end
if i == null then return null
args.add(i)
end
- var mproperty = self.mproperty.as(not null)
- var res = v.send(mproperty, args)
+ var res = v.send(callsite.mproperty, args)
return res
end
end
var value = v.expr(self.n_value)
if value == null then return
- var mproperty = self.mproperty.as(not null)
- var read = v.send(mproperty, args)
+ var read = v.send(callsite.mproperty, args)
assert read != null
- var write = v.send(self.reassign_property.mproperty, [read, value])
+ var write = v.send(reassign_callsite.mproperty, [read, value])
assert write != null
args.add(write)
- v.send(self.write_mproperty.as(not null), args)
+ v.send(write_callsite.mproperty, args)
end
end
args = v.frame.arguments
end
- var mproperty = self.mproperty
- if mproperty != null then
- if mproperty.intro.msignature.arity == 0 then
+ var callsite = self.callsite
+ if callsite != null then
+ if callsite.mproperty.intro.msignature.arity == 0 then
args = [recv]
end
# Super init call
- var res = v.send(mproperty, args)
+ var res = v.send(callsite.mproperty, args)
return res
end
if i == null then return null
args.add(i)
end
- var mproperty = self.mproperty.as(not null)
- var res2 = v.send(mproperty, args)
+ var res2 = v.send(callsite.mproperty, args)
if res2 != null then
#self.debug("got {res2} from {mproperty}. drop {recv}")
return res2
if value == null then return
var mproperty = self.mproperty.as(not null)
var attr = v.read_attribute(mproperty, recv)
- var res = v.send(reassign_property.mproperty, [attr, value])
+ var res = v.send(reassign_callsite.mproperty, [attr, value])
assert res != null
assert recv isa MutableInstance
recv.attributes[mproperty] = res
do
var loc_buf = new Buffer
if connection.ready_to_read(0) then buf.append(connection.read)
- for i in [buf_pos .. buf.length-1] do loc_buf.add(buf[i])
+ for i in [buf_pos .. buf.length-1] do loc_buf.add(buf.chars[i])
buf.clear
buf_pos = 0
return loc_buf.to_s
buf.append(connection.read)
end
buf_pos += 1
- return buf[buf_pos-1].ascii
+ return buf.chars[buf_pos-1].ascii
end
# Reads a line on the network if available
buf.append(connection.read)
end
buf_pos += 1
- if buf[buf_pos-1] == '\n' then break
- line_buf.add(buf[buf_pos-1])
+ if buf.chars[buf_pos-1] == '\n' then break
+ line_buf.add(buf.chars[buf_pos-1])
end
return line_buf.to_s
end
else
var category = parts[0]
var keyword = parts[1]
- if keyword.first == ' ' then keyword = keyword.substring_from(1)
+ if keyword.chars.first == ' ' then keyword = keyword.substring_from(1)
return new IndexQueryPair(str, keyword, category)
end
end
private fun escape: String
do
var b = new Buffer
- for c in self do
+ for c in self.chars do
if c == '\n' then
b.append("\\n")
else if c == '\0' then
if sp >= string_len then
dfa_state = -1
else
- var c = string[sp].ascii
+ var c = string.chars[sp].ascii
sp += 1
var cr = _cr
if sp >= string_len then
dfa_state = -1
else
- var c = string[sp].ascii
+ var c = string.chars[sp].ascii
sp += 1
var cr = _cr
fun add_send(mtype: MType, mproperty: MMethod) do analysis.add_send(mtype, mproperty)
fun add_cast_type(mtype: MType) do analysis.add_cast(mtype)
+
+ fun add_callsite(callsite: nullable CallSite) do if callsite != null then analysis.add_send(callsite.recv, callsite.mproperty)
end
###
redef class ASendExpr
redef fun accept_rapid_type_visitor(v)
do
- var mproperty = self.mproperty.as(not null)
- var recvtype = self.n_expr.mtype.as(not null)
- v.add_send(recvtype, mproperty)
+ v.add_callsite(callsite)
end
end
redef class ASendReassignFormExpr
redef fun accept_rapid_type_visitor(v)
do
- v.add_send(self.read_type.as(not null), self.reassign_property.mproperty)
- var mproperty = self.mproperty.as(not null)
- var write_mproperty = self.write_mproperty.as(not null)
- if n_expr isa ASelfExpr then
- v.add_monomorphic_send(v.receiver, mproperty)
- v.add_monomorphic_send(v.receiver, write_mproperty)
- else
- var recvtype = self.n_expr.mtype.as(not null)
- v.add_send(recvtype, mproperty)
- v.add_send(recvtype, write_mproperty)
- end
+ v.add_callsite(callsite)
+ v.add_callsite(reassign_callsite)
+ v.add_callsite(write_callsite)
end
end
redef class AVarReassignExpr
redef fun accept_rapid_type_visitor(v)
do
- v.add_send(self.read_type.as(not null), self.reassign_property.mproperty)
+ v.add_callsite(reassign_callsite)
end
end
redef class AAttrReassignExpr
redef fun accept_rapid_type_visitor(v)
do
- v.add_send(self.read_type.as(not null), self.reassign_property.mproperty)
+ v.add_callsite(reassign_callsite)
end
end
redef class ASuperExpr
redef fun accept_rapid_type_visitor(v)
do
- var mproperty = self.mproperty
- if mproperty != null then
- v.add_monomorphic_send(v.receiver, mproperty)
+ var callsite = self.callsite
+ if callsite != null then
+ v.add_callsite(callsite)
return
end
do
var mtype = self.mtype.as(MClassType)
v.add_type(mtype)
- var mproperty = self.mproperty.as(not null)
- v.add_monomorphic_send(mtype, mproperty)
+ v.add_callsite(callsite)
end
end
var need_help = false
var no_file = false
-while not args.is_empty and args.first.first == '-' do
+while not args.is_empty and args.first.chars.first == '-' do
if args.first == "-n" then
no_print = true
else if args.first == "-l" then
end
redef class AReassignFormExpr
- # @depreciated use `reassign_callsite`
- fun reassign_property: nullable MMethodDef do return self.reassign_callsite.mpropdef
-
# The method designed by the reassign operator.
var reassign_callsite: nullable CallSite
## MESSAGE SENDING AND PROPERTY
redef class ASendExpr
- # @depreciated: use `callsite`
- fun mproperty: nullable MMethod do return callsite.mproperty
-
# The property invoked by the send.
var callsite: nullable CallSite
end
redef class ASendReassignFormExpr
- # @depreciated use `write_callsite`
- fun write_mproperty: nullable MMethod do return write_callsite.mproperty
-
# The property invoked for the writing
var write_callsite: nullable CallSite
redef class ASuperExpr
# The method to call if the super is in fact a 'super init call'
# Note: if the super is a normal call-next-method, then this attribute is null
- var mproperty: nullable MMethod
+ var callsite: nullable CallSite
redef fun accept_typing(v)
do
v.error(self, "Error: No super method to call for {mproperty}.")
return
end
- self.mproperty = superprop.mproperty
- var args = self.n_args.to_a
var msignature = v.resolve_signature_for(superprop, recvtype, true)
+ var callsite = new CallSite(self, recvtype, true, superprop.mproperty, superprop, msignature, false)
+ self.callsite = callsite
+
+ var args = self.n_args.to_a
if args.length > 0 then
- v.check_signature(self, args, mproperty.name, msignature)
+ callsite.check_signature(v, args)
else
# TODO: Check signature
end
####
redef class ANewExpr
- # @depreciated use `callsite`
- fun mproperty: nullable MMethod do return self.callsite.mproperty
-
# The constructor invoked by the new.
var callsite: nullable CallSite
redef class String
redef fun output
do
- for c in self do c.output
+ for c in self.chars do c.output
end
end
i = 0
for k in [0..s.length[ do
- var c = s[k]
+ var c = s.chars[k]
if c >= 'a' and c <= 'z' then
i = i + 1
end
do
var result = new Buffer
var i = 0
- while i < s.length and s[i] != ' ' do
- result.add(s[i])
+ while i < s.length and s.chars[i] != ' ' do
+ result.add(s.chars[i])
i = i + 1
end
return result.to_s
Sys Bool Int A B C
Number of live runtime types (instantied resolved type): 6
Sys Bool Int A B C
-Number of live methods: 11
+Number of live methods: 14
Number of live method definitions: 14
Number of live runtime cast types (ie used in as and isa): 0
TKwfalse "false" ../src/test_parser.nit:46,15--19
AWhileExpr ../src/test_parser.nit:48,1--64,3
TKwwhile "while" ../src/test_parser.nit:48,1--5
- AAndExpr ../src/test_parser.nit:48,7--51
+ AAndExpr ../src/test_parser.nit:48,7--57
ANotExpr ../src/test_parser.nit:48,7--23
TKwnot "not" ../src/test_parser.nit:48,7--9
ACallExpr ../src/test_parser.nit:48,11--23
AListExprs ../src/test_parser.nit:48,14
TId "is_empty" ../src/test_parser.nit:48,16--23
AListExprs ../src/test_parser.nit:48,23
- AEqExpr ../src/test_parser.nit:48,29--51
- ACallExpr ../src/test_parser.nit:48,29--44
- ACallExpr ../src/test_parser.nit:48,29--38
- ACallExpr ../src/test_parser.nit:48,29--32
- AImplicitSelfExpr ../src/test_parser.nit:48,29
- TId "args" ../src/test_parser.nit:48,29--32
- AListExprs ../src/test_parser.nit:48,32
- TId "first" ../src/test_parser.nit:48,34--38
- AListExprs ../src/test_parser.nit:48,38
- TId "first" ../src/test_parser.nit:48,40--44
- AListExprs ../src/test_parser.nit:48,44
- ACharExpr ../src/test_parser.nit:48,49--51
- TChar "\'-\'" ../src/test_parser.nit:48,49--51
- TKwdo "do" ../src/test_parser.nit:48,53--54
+ AEqExpr ../src/test_parser.nit:48,29--57
+ ACallExpr ../src/test_parser.nit:48,29--50
+ ACallExpr ../src/test_parser.nit:48,29--44
+ ACallExpr ../src/test_parser.nit:48,29--38
+ ACallExpr ../src/test_parser.nit:48,29--32
+ AImplicitSelfExpr ../src/test_parser.nit:48,29
+ TId "args" ../src/test_parser.nit:48,29--32
+ AListExprs ../src/test_parser.nit:48,32
+ TId "first" ../src/test_parser.nit:48,34--38
+ AListExprs ../src/test_parser.nit:48,38
+ TId "chars" ../src/test_parser.nit:48,40--44
+ AListExprs ../src/test_parser.nit:48,44
+ TId "first" ../src/test_parser.nit:48,46--50
+ AListExprs ../src/test_parser.nit:48,50
+ ACharExpr ../src/test_parser.nit:48,55--57
+ TChar "\'-\'" ../src/test_parser.nit:48,55--57
+ TKwdo "do" ../src/test_parser.nit:48,59--60
ABlockExpr ../src/test_parser.nit:49,2--64,3
AIfExpr ../src/test_parser.nit:49,2--62,4
TKwif "if" ../src/test_parser.nit:49,2--3
Read token at ../src/test_parser.nit:48,33 text='.'
Read token at ../src/test_parser.nit:48,34--38 text='first'
Read token at ../src/test_parser.nit:48,39 text='.'
-Read token at ../src/test_parser.nit:48,40--44 text='first'
-Read token at ../src/test_parser.nit:48,46--47 text='=='
-Read token at ../src/test_parser.nit:48,49--51 text=''-''
-Read token at ../src/test_parser.nit:48,53--54 text='do'
-Read token at ../src/test_parser.nit:48,55--49,0 text='
+Read token at ../src/test_parser.nit:48,40--44 text='chars'
+Read token at ../src/test_parser.nit:48,45 text='.'
+Read token at ../src/test_parser.nit:48,46--50 text='first'
+Read token at ../src/test_parser.nit:48,52--53 text='=='
+Read token at ../src/test_parser.nit:48,55--57 text=''-''
+Read token at ../src/test_parser.nit:48,59--60 text='do'
+Read token at ../src/test_parser.nit:48,61--49,0 text='
'
Read token at ../src/test_parser.nit:49,2--3 text='if'
Read token at ../src/test_parser.nit:49,5--8 text='args'
+++ /dev/null
-Je suis ici.
-Je suis ici.Je suis ici.Je suis ici.
-Je suis ici.Je suis ici.Je suis ici.Je suis ici.Je suis ici.
-Je suis ici.Je suis ici.
-Je su
-je suis ici.hi !je suis ici.hi !
-JE SUIS ICI.HI !JE SUIS ICI.HI !
var count = 0
var array = new Buffer.with_capacity(n)
for i in [0..n[ do
- array[i] = 'o'
+ array.chars[i] = 'o'
end
for i in [2..n[ do
- if array[i] == 'o' then
+ if array.chars[i] == 'o' then
var j = i * 2
while j < n do
- array[j] = 'x'
+ array.chars[j] = 'x'
j = j + i
end
count = count + 1
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# This file is free software, which comes along with NIT. This software is
-# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE. You can modify it if you want, provided this header
-# is kept unaltered, and a notification of the changes is added.
-# You are allowed to redistribute it and sell it, alone or as a part of
-# another product.
-
-module test_ropes
-
-var str_part_1 = "Je"
-
-var str_part_2 = "suis"
-
-var str_part_3 = "ici"
-
-var str_part_4 = "."
-
-var space = " "
-
-var test = "Je suis ici."
-
-var rope_uniq_test = new ImmutableRope.with_string("zzzzzzzzzzzzzzzzzzzzzzzzzzzz")
-
-var not_rope_uniq_test = new ImmutableRope.with_string("zzzzzzzzzzzzzezzzzzzzzzzzzzz")
-
-################################
-# Rope methods tests #
-################################
-
-var buf = new Buffer
-
-buf.append(str_part_1)
-buf.append(space)
-buf.append(str_part_2)
-buf.append(space)
-buf.append(str_part_3)
-buf.append(str_part_4)
-
-print buf
-
-var buf_rope = new BufferRope
-
-buf_rope.append_multi(str_part_1,space,str_part_2,space,str_part_3,str_part_4)
-
-var buf_rope_with_str = new BufferRope.with_string(test)
-
-print buf_rope*3
-
-print buf_rope_with_str*5
-
-print buf_rope + buf_rope_with_str
-
-assert buf_rope.length == buf_rope_with_str.length
-
-assert buf_rope == buf_rope_with_str
-
-assert buf_rope.multi_concat(buf_rope, buf_rope) == buf_rope * 3
-
-print buf_rope.subrope(0, 5)
-
-assert buf_rope.subrope(0, 5) == "Je su"
-
-buf_rope.append("Hi !")
-
-assert buf_rope > buf_rope_with_str
-
-assert buf_rope == buf_rope.chars.to_s
-
-assert buf_rope.chars.to_s == buf_rope
-
-assert buf == buf_rope_with_str
-
-######################################
-# BufferRope methods tests #
-######################################
-
-assert buf_rope + buf_rope == buf_rope.concat(buf_rope)
-
-assert buf_rope == buf_rope.freeze
-
-######################################
-# Rope.chars methods tests #
-######################################
-
-assert buf_rope.chars[3] == 's'
-
-assert buf_rope.chars.index_of('k') == -1
-
-assert buf_rope.chars.index_of('s') == 3
-
-assert buf_rope.chars.count('s') == 4
-
-assert buf_rope.chars.last == '!'
-
-assert rope_uniq_test.chars.has_only('z')
-
-assert not not_rope_uniq_test.chars.has_only('z')
-
-assert (new BufferRope).chars.has_only('l')
-
-print buf_rope.to_lower
-
-print buf_rope.to_upper
-
-
fun test(s: String)
do
print s.length
- print s.first
- print s.last
- print s[2]
+ print s.chars.first
+ print s.chars.last
+ print s.chars[2]
print s.substring(1, 2)
print s.substring(-1, 2)
print s.substring(1, 0)
while i < 5000 do
var j = 0
while j < s.length do
- r.add(s[j])
- r2.add(s[j])
+ r.add(s.chars[j])
+ r2.add(s.chars[j])
j = j + 1
end
i = i + 1
var a = "éè"
print(a.length)
for i in [0..a.length[ do
- print("{i} is {a[i]} ({a[i].ascii})")
+ print("{i} is {a.chars[i]} ({a.chars[i].ascii})")
end
var test = "test"
-print("test[0] == 't' => {test[0] == 't'}")
-print("test[1] == 'e' => {test[1] == 'e'}")
-print("test[2] == 's' => {test[2] == 's'}")
-print("test[3] == 't' => {test[3] == 't'}")
+print("test[0] == 't' => {test.chars[0] == 't'}")
+print("test[1] == 'e' => {test.chars[1] == 'e'}")
+print("test[2] == 's' => {test.chars[2] == 's'}")
+print("test[3] == 't' => {test.chars[3] == 't'}")
print("test.substring(0,1) == \"t\" => {test.substring(0,1) == "t"}")
print("test.substring(0,2) == \"te\" => {test.substring(0,2) == "te"}")