fuzion/sys/internal_array.fz
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation 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. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion standard library feature sys.internal_array
#
# Author: Fridtjof Siebert (siebert@tokiwa.software)
#
# -----------------------------------------------------------------------
# helper to allocate memory for an internal_array.
# returns an internal_array.
#
module internal_array_init(T type, private length i32) =>
private alloc(X type, l i32) fuzion.sys.Pointer => intrinsic
internal_array T (alloc T length) length
# fuzion.sys.internal_array_init -- one-dimensional low-level array
module internal_array(T type, module data fuzion.sys.Pointer, module length i32) is
private get (X type, d fuzion.sys.Pointer, i i32) X => intrinsic
private setel(X type, d fuzion.sys.Pointer, i i32, o X) unit => intrinsic
# make sure that this internal array will no longer be modified. This is just for
# debugging and will be a NOP in case internal checks are disabled or in case the
# backend does not support this.
#
module freeze unit => intrinsic
# check that this internal array was not frozen, i.e., `freeze` was not called.
# Cause a runtime error if this `freeze` was called. Note that this is a NOP if
# the backend does not support these checks or intenal checks are disabled.
#
module ensure_not_frozen unit => intrinsic
# wrap this into an immutable array.
#
module fixed as_array =>
array T (fuzion.sys.internal_array T data length) unit unit unit
module indices => 0..length-1
module index [ ] (i i32) T
pre
safety: 0 ≤ i < length
=>
get T data i
module set [ ] (i i32, o T) unit
pre
safety: 0 ≤ i < length
# post NYI
#array.this[i] == o
=>
setel T data i o
last changed: 2024-03-07