summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3b952d2)
Since new-style attributes still allows low-level access to the real
attributes, the migration was easy; although some intrude imports where required.
Signed-off-by: Jean Privat <jean@pryen.org>
19 files changed:
# Utilities and performant structure for the FFI with C
module c
# Utilities and performant structure for the FFI with C
module c
+import standard
+intrude import standard::collection::array
# A thin wrapper around a `NativeCArray` adding length information
abstract class CArray[E]
# A thin wrapper around a `NativeCArray` adding length information
abstract class CArray[E]
class DummyArray
super Set[Int]
super ArrayCapable[Int]
class DummyArray
super Set[Int]
super ArrayCapable[Int]
- var _capacity: Int
- var _length: Int
- redef fun length do return _length
- var _keys: NativeArray[Int]
- var _values: NativeArray[Int]
+ private var capacity: Int
+ redef var length: Int
+ private var keys: NativeArray[Int]
+ private var values: NativeArray[Int]
redef fun add(value: Int)
do
redef fun add(value: Int)
do
class DummyIterator
super Iterator[Int]
class DummyIterator
super Iterator[Int]
- var _array: DummyArray
- var _pos: Int
+ private var array: DummyArray
+ private var pos: Int
class StreamCat
super FilterIStream
class StreamCat
super FilterIStream
- var _streams: Iterator[IStream]
+ private var streams: Iterator[IStream]
class StreamDemux
super FilterOStream
class StreamDemux
super FilterOStream
- var _streams: Array[OStream]
+ private var streams: Array[OStream]
redef fun is_writable: Bool
do
redef fun is_writable: Bool
do
redef fun node_at_idx(i,k)
do
sys.gt_count += 1
redef fun node_at_idx(i,k)
do
sys.gt_count += 1
- sys.gt_tot_length += _length
+ sys.gt_tot_length += _the_length
sys.gt_tot_cap += _capacity
var c = _array[i]
if c != null and c._next_in_bucklet != null then gt_collide(i,k)
sys.gt_tot_cap += _capacity
var c = _array[i]
if c != null and c._next_in_bucklet != null then gt_collide(i,k)
do
sys.st_count += 1
if _array[i] != null then st_collide(i,n)
do
sys.st_count += 1
if _array[i] != null then st_collide(i,n)
- sys.st_tot_length += _length
+ sys.st_tot_length += _the_length
sys.st_tot_cap += _capacity
super
sys.st_tot_cap += _capacity
super
#
# Provides PNaCl support for Nit.
module pnacl is platform
#
# Provides PNaCl support for Nit.
module pnacl is platform
+
+import standard
+intrude import standard::stream
+
`{
#include <unistd.h>
#include <stddef.h>
`{
#include <unistd.h>
#include <stddef.h>
module socket
import socket_c
module socket
import socket_c
+intrude import standard::stream
# Portal for communication between two machines
class Socket
# Portal for communication between two machines
class Socket
redef var is_ok: Bool = true
redef var is_ok: Bool = true
- var _container: Container[E]
+ private var container: Container[E]
end
# Items can be removed from this collection
end
# Items can be removed from this collection
- var _iter: Iterator[Couple[K,E]]
+ private var iter: Iterator[Couple[K,E]]
init(i: Iterator[Couple[K,E]]) do _iter = i
end
init(i: Iterator[Couple[K,E]]) do _iter = i
end
abstract class AbstractArrayRead[E]
super SequenceRead[E]
abstract class AbstractArrayRead[E]
super SequenceRead[E]
- var _length: Int = 0
- redef fun length do return _length
redef fun is_empty do return _length == 0
redef fun is_empty do return _length == 0
end
# The internal storage.
end
# The internal storage.
- var _items: nullable NativeArray[E] = null
+ private var items: nullable NativeArray[E] = null
# Do not use this method
# FIXME: Remove it once modules can intrude non local modules
fun intern_items: NativeArray[E] do return _items.as(not null)
# The size of `_items`.
# Do not use this method
# FIXME: Remove it once modules can intrude non local modules
fun intern_items: NativeArray[E] do return _items.as(not null)
# The size of `_items`.
+ private var capacity: Int = 0
- var _index: Int = 0
- redef fun index do return _index
- var _array: AbstractArrayRead[E]
+ redef var index = 0
+
+ private var array: AbstractArrayRead[E]
end
private class ArrayReverseIterator[E]
end
private class ArrayReverseIterator[E]
super Set[E]
# The stored elements.
super Set[E]
# The stored elements.
+ private var array: Array[E]
redef fun has(e) do return _array.has(e)
redef fun has(e) do return _array.has(e)
init(iter: ArrayIterator[E]) do _iter = iter
init(iter: ArrayIterator[E]) do _iter = iter
- var _iter: ArrayIterator[E]
+ private var iter: ArrayIterator[E]
- var _items = new Array[Couple[K,E]]
+ private var items = new Array[Couple[K,E]]
# fast remove the ith element of the array
private fun remove_at_index(i: Int)
# fast remove the ith element of the array
private fun remove_at_index(i: Int)
end
# The last positive result given by a index(1) call
end
# The last positive result given by a index(1) call
- var _last_index: Int = 0
+ private var last_index: Int = 0
# Where is the `key` in `_item`?
# return -1 if not found
# Where is the `key` in `_item`?
# return -1 if not found
private abstract class HashCollection[K: Object, N: HashNode[Object]]
super ArrayCapable[nullable N]
private abstract class HashCollection[K: Object, N: HashNode[Object]]
super ArrayCapable[nullable N]
- var _array: nullable NativeArray[nullable N] = null # Used to store items
- var _capacity: Int = 0 # Size of _array
- var _length: Int = 0 # Number of items in the map
+ private var array: nullable NativeArray[nullable N] = null # Used to store items
+ private var capacity: Int = 0 # Size of _array
+ private var the_length: Int = 0 # Number of items in the map
- var _first_item: nullable N = null # First added item (used to visit items in nice order)
- var _last_item: nullable N = null # Last added item (same)
+ private var first_item: nullable N = null # First added item (used to visit items in nice order)
+ private var last_item: nullable N = null # Last added item (same)
# The last key accessed (used for cache)
# The last key accessed (used for cache)
- var _last_accessed_key: nullable K = null
+ private var last_accessed_key: nullable K = null
# The last node accessed (used for cache)
# The last node accessed (used for cache)
- var _last_accessed_node: nullable N = null
+ private var last_accessed_node: nullable N = null
# Return the index of the key k
fun index_at(k: K): Int
# Return the index of the key k
fun index_at(k: K): Int
_last_accessed_node = node
# Enlarge if needed
_last_accessed_node = node
# Enlarge if needed
- var l = _length
- _length = l + 1
+ var l = _the_length
+ _the_length = l + 1
# Magic values determined empirically
# We do not want to enlarge too much
# Magic values determined empirically
# We do not want to enlarge too much
end
# Remove the item in the array
end
# Remove the item in the array
prev = node._prev_in_bucklet
next = node._next_in_bucklet
if prev != null then
prev = node._prev_in_bucklet
next = node._next_in_bucklet
if prev != null then
_array[i] = null
i -= 1
end
_array[i] = null
i -= 1
end
_first_item = null
_last_item = null
_last_accessed_key = null
_first_item = null
_last_item = null
_last_accessed_key = null
do
var old_cap = _capacity
# get a new capacity
do
var old_cap = _capacity
# get a new capacity
- if cap < _length + 1 then cap = _length + 1
+ if cap < _the_length + 1 then cap = _the_length + 1
if cap <= _capacity then return
_capacity = cap
_last_accessed_key = null
if cap <= _capacity then return
_capacity = cap
_last_accessed_key = null
end
private abstract class HashNode[K: Object]
end
private abstract class HashNode[K: Object]
- var _next_item: nullable N = null
- var _prev_item: nullable N = null
- var _prev_in_bucklet: nullable N = null
- var _next_in_bucklet: nullable N = null
+ private var next_item: nullable N = null
+ private var prev_item: nullable N = null
+ private var prev_in_bucklet: nullable N = null
+ private var next_in_bucklet: nullable N = null
redef fun iterator: HashMapIterator[K, V] do return new HashMapIterator[K,V](self)
redef fun iterator: HashMapIterator[K, V] do return new HashMapIterator[K,V](self)
- redef fun length do return _length
+ redef fun length do return _the_length
- redef fun is_empty do return _length == 0
+ redef fun is_empty do return _the_length == 0
private class HashMapNode[K: Object, V]
super HashNode[K]
redef type N: HashMapNode[K, V]
private class HashMapNode[K: Object, V]
super HashNode[K]
redef type N: HashMapNode[K, V]
end
# The map to iterate on
end
# The map to iterate on
- var _map: HashMap[K, V]
+ private var map: HashMap[K, V]
- var _node: nullable HashMapNode[K, V]
+ private var node: nullable HashMapNode[K, V]
init(map: HashMap[K, V])
do
init(map: HashMap[K, V])
do
super Set[E]
super HashCollection[E, HashSetNode[E]]
super Set[E]
super HashCollection[E, HashSetNode[E]]
- redef fun length do return _length
+ redef fun length do return _the_length
- redef fun is_empty do return _length == 0
+ redef fun is_empty do return _the_length == 0
return _first_item._key
end
return _first_item._key
end
end
# The set to iterate on
end
# The set to iterate on
+ private var set: HashSet[E]
# The position in the internal map storage
# The position in the internal map storage
- var _node: nullable HashSetNode[E]
+ private var node: nullable HashSetNode[E]
init from(coll: Collection[E]) do append(coll)
# The first node of the list
init from(coll: Collection[E]) do append(coll)
# The first node of the list
- var _head: nullable ListNode[E]
+ private var head: nullable ListNode[E]
# The last node of the list
# The last node of the list
- var _tail: nullable ListNode[E]
+ private var tail: nullable ListNode[E]
# Get the `i`th node. get `null` otherwise.
private fun get_node(i: Int): nullable ListNode[E]
# Get the `i`th node. get `null` otherwise.
private fun get_node(i: Int): nullable ListNode[E]
+ private var list: List[E]
# The current node of the list
# The current node of the list
- var _node: nullable ListNode[E]
+ private var node: nullable ListNode[E]
# The index of the current node
# The index of the current node
- var _index: Int
-
- redef fun index do return _index
# Remove the current item
fun delete
# Remove the current item
fun delete
private class IteratorRange[E: Discrete]
# Iterator on ranges.
super Iterator[E]
private class IteratorRange[E: Discrete]
# Iterator on ranges.
super Iterator[E]
- var _range: Range[E]
- var _item: E
- redef fun item do return _item
+ private var range: Range[E]
+ redef var item
redef fun is_ok do return _item < _range.after
redef fun is_ok do return _item < _range.after
var path: nullable String = null
# The FILE *.
var path: nullable String = null
# The FILE *.
- var _file: nullable NativeFile = null
+ private var file: nullable NativeFile = null
fun file_stat: FileStat do return _file.file_stat
fun file_stat: FileStat do return _file.file_stat
if s isa FlatText then
write_native(s.to_cstring, s.length)
else
if s isa FlatText then
write_native(s.to_cstring, s.length)
else
- redef fun is_writable do return _writable
-
redef fun close
do
var i = _file.io_close
redef fun close
do
var i = _file.io_close
- # Is the file open in write mode
- var _writable: Bool
+ redef var is_writable = false
# Write `len` bytes from `native`.
private fun write_native(native: NativeString, len: Int)
do
# Write `len` bytes from `native`.
private fun write_native(native: NativeString, len: Int)
do
var err = _file.io_write(native, len)
if err != len then
# Big problem
var err = _file.io_write(native, len)
if err != len then
# Big problem
print "Error: Opening file at '{path}' failed with '{sys.errno.strerror}'"
end
self.path = path
print "Error: Opening file at '{path}' failed with '{sys.errno.strerror}'"
end
self.path = path
private init do
_file = new NativeFile.native_stdout
path = "/dev/stdout"
private init do
_file = new NativeFile.native_stdout
path = "/dev/stdout"
private init do
_file = new NativeFile.native_stderr
path = "/dev/stderr"
private init do
_file = new NativeFile.native_stderr
path = "/dev/stderr"
redef fun eof do return _buffer_pos >= _buffer.length and end_reached
# The buffer
redef fun eof do return _buffer_pos >= _buffer.length and end_reached
# The buffer
- var _buffer: nullable FlatBuffer = null
+ private var buffer: nullable FlatBuffer = null
# The current position in the buffer
# The current position in the buffer
- var _buffer_pos: Int = 0
+ private var buffer_pos: Int = 0
# Fill the buffer
protected fun fill_buffer is abstract
# Fill the buffer
protected fun fill_buffer is abstract
import math
import collection
import math
import collection
+intrude import collection::array
- var _args_cache: nullable Sequence[String]
+ private var args_cache: nullable Sequence[String]
# The arguments of the program as given by the OS
fun program_args: Sequence[String]
# The arguments of the program as given by the OS
fun program_args: Sequence[String]
+ private var motif: String
+ private var length: Int
private fun bc(e: Char): Int
do
private fun bc(e: Char): Int
do
+ private var gs: Array[Int]
- var _bc_table: Map[Char, Int]
+ private var bc_table: Map[Char, Int]
private fun compute_bc
do
private fun compute_bc
do
redef class OFStream
redef fun write(s)
do
redef class OFStream
redef fun write(s)
do
if s isa FlatText then
if s isa FlatString then
write_native(s.to_cstring, s.bytelen)
if s isa FlatText then
if s isa FlatString then
write_native(s.to_cstring, s.bytelen)
redef class OFStream
redef fun write(s)
do
redef class OFStream
redef fun write(s)
do
if s isa FlatText then
write_native(s.to_cstring, s.bytelen)
else for i in s.substrings do write_native(i.to_cstring, i.length)
if s isa FlatText then
write_native(s.to_cstring, s.bytelen)
else for i in s.substrings do write_native(i.to_cstring, i.length)
# A symbol is a unique immutable string
class Symbol
# A symbol is a unique immutable string
class Symbol
+ private var string: String
redef fun to_s do return _string.to_s
# Only used by String::to_symbol
redef fun to_s do return _string.to_s
# Only used by String::to_symbol
import sha1
import base64
import sha1
import base64
+intrude import standard::stream
+
# Websocket compatible server, works as an extra layer to the original Sockets
class WebSocket
super BufferedIStream
# Websocket compatible server, works as an extra layer to the original Sockets
class WebSocket
super BufferedIStream