nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lib/file: move the call of `stdout.set_buffering_mode` to Stdout
[nit.git]
/
lib
/
c.nit
diff --git
a/lib/c.nit
b/lib/c.nit
index
3732085
..
ae1b875
100644
(file)
--- a/
lib/c.nit
+++ b/
lib/c.nit
@@
-29,7
+29,7
@@
abstract class CArray[E]
# Pointer to the real C array
var native_array: NATIVE is noinit
# Pointer to the real C array
var native_array: NATIVE is noinit
- private init(length: Int) do self._length = length
+ private init(length: Int) is old_style_init do self._length = length
redef fun [](index)
do
redef fun [](index)
do
@@
-38,6
+38,7
@@
abstract class CArray[E]
return native_array[index]
end
return native_array[index]
end
+ # Set `val` at `index`.
fun []=(index: Int, val: E)
do
assert not destroyed
fun []=(index: Int, val: E)
do
assert not destroyed
@@
-45,7
+46,14
@@
abstract class CArray[E]
native_array[index] = val
end
native_array[index] = val
end
+ # Was this instance destroyed?
+ #
+ # See `CArray::destroy`.
var destroyed = false
var destroyed = false
+
+ # Free used memory used by `native_array`.
+ #
+ # Also set `destroyed` to true.
fun destroy
do
if destroyed then return
fun destroy
do
if destroyed then return
@@
-57,10
+65,15
@@
end
# A native C array, as in a pointer to the first element of the array
extern class NativeCArray `{ void * `}
# A native C array, as in a pointer to the first element of the array
extern class NativeCArray `{ void * `}
+
+ # Type of contained elements.
type E: nullable Object
type E: nullable Object
- fun [](index: E): E is abstract
- fun []=(index: E, val: E) is abstract
+ # Get element at `index`.
+ fun [](index: Int): E is abstract
+
+ # Set `val` at `index`.
+ fun []=(index: Int, val: E) is abstract
# Return pointer to the address to the second element of this array
#
# Return pointer to the address to the second element of this array
#
@@
-73,8
+86,8
@@
class CIntArray
super CArray[Int]
redef type NATIVE: NativeCIntArray
super CArray[Int]
redef type NATIVE: NativeCIntArray
- init(size: Int)
- do
+ # Initialize a new CIntArray of `size` elements.
+ init(size: Int) is old_style_init do
native_array = new NativeCIntArray(size)
super size
end
native_array = new NativeCIntArray(size)
super size
end
@@
-95,7
+108,9
@@
extern class NativeCIntArray `{ int* `}
super NativeCArray
redef type E: Int
super NativeCArray
redef type E: Int
+ # Initialize a new NativeCIntArray of `size` elements.
new(size: Int) `{ return calloc(size, sizeof(int)); `}
new(size: Int) `{ return calloc(size, sizeof(int)); `}
+
redef fun [](index) `{ return recv[index]; `}
redef fun []=(index, val) `{ recv[index] = val; `}
redef fun [](index) `{ return recv[index]; `}
redef fun []=(index, val) `{ recv[index] = val; `}
@@
-108,8
+123,7
@@
class CByteArray
redef type NATIVE: NativeCByteArray
# Allocate a new array of `size`
redef type NATIVE: NativeCByteArray
# Allocate a new array of `size`
- init(size: Int)
- do
+ init(size: Int) is old_style_init do
native_array = new NativeCByteArray(size)
super size
end
native_array = new NativeCByteArray(size)
super size
end