| |
| /pliant/language/type/set/fixedarray.pli |
| |
| 1 |
# Copyright Hubert Tonneau hubert.tonneau@pliant.cx | |
| 2 |
# | |
| 3 |
# This program is free software; you can redistribute it and/or | |
| 4 |
# modify it under the terms of the GNU General Public License version 2 | |
| 5 |
# as published by the Free Software Foundation. | |
| 6 |
# | |
| 7 |
# This program is distributed in the hope that it will be useful, | |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 |
# GNU General Public License for more details. | |
| 11 |
# | |
| 12 |
# You should have received a copy of the GNU General Public License | |
| 13 |
# version 2 along with this program; if not, write to the Free Software | |
| 14 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 15 |
| |
| 16 |
scope "/pliant/language/" "/pliant/install/" | |
| 17 |
module "/pliant/install/ring2.pli" | |
| 18 |
| |
| 19 |
| |
| 20 |
(gvar Relation 'pliant fixedarray types') 'flags :=' 5 | |
| 21 |
export 'pliant fixedarray types' | |
| 22 |
| |
| 23 |
function Array t n -> tt | |
| 24 |
arg Type t ; arg Int n ; arg_R Type tt | |
| 25 |
has_no_side_effect | |
| 26 |
| |
| 27 |
var Address adr := 'pliant fixedarray types' query addressof:t (cast n Address) | |
| 28 |
if adr<>null | |
| 29 |
return (adr map Type) | |
| 30 |
| |
| 31 |
runtime_compile t t n n array (cast "(FixedArray "+t:name+" "+'convert to string':n+")" Ident) | |
| 32 |
type array | |
| 33 |
void | |
| 34 |
(addressof:array map Type):size := n*t:size | |
| 35 |
(addressof:array map Type):flags := array:flags .and. .not. type_flag_atomic+type_flag_scalar | |
| 36 |
if (t:flags .and. type_flag_scalar)<>0 | |
| 37 |
(addressof:array map Type):flags := array:flags .or. type_flag_scalar | |
| 38 |
| |
| 39 |
if (t:flags .and. type_flag_scalar)=0 | |
| 40 |
function build a | |
| 41 |
arg_w array a | |
| 42 |
for (var Int i) 0 n-1 | |
| 43 |
t build_instance (addressof:a translate t i) | |
| 44 |
| |
| 45 |
if (t:flags .and. type_flag_scalar)=0 | |
| 46 |
function destroy a | |
| 47 |
arg_w array a | |
| 48 |
for (var Int i) 0 n-1 | |
| 49 |
t destroy_instance (addressof:a translate t i) | |
| 50 |
| |
| 51 |
method a '' i -> p | |
| 52 |
arg array a ; arg Int i ; arg_C t p | |
| 53 |
check i>=0 and i<n "out of range array index" | |
| 54 |
p :> (addressof:a translate t i) map t | |
| 55 |
| |
| 56 |
method a size -> s | |
| 57 |
arg array a ; arg Int s | |
| 58 |
s := n | |
| 59 |
| |
| 60 |
function copy src dest | |
| 61 |
arg array src ; arg_w array dest | |
| 62 |
if (t:flags .and. type_flag_scalar)=0 | |
| 63 |
for (var Int i) 0 n-1 | |
| 64 |
dest i := src i | |
| 65 |
else | |
| 66 |
memory_copy addressof:src addressof:dest n*t:size | |
| 67 |
| |
| 68 |
export '' '. size' | |
| 69 |
'pliant fixedarray types' define addressof:t (cast n Address) addressof:array | |
| 70 |
| |
| 71 |
var Address adr := 'pliant fixedarray types' query addressof:t (cast n Address) | |
| 72 |
check adr<>null | |
| 73 |
return (adr map Type) | |
| 74 |
| |
| 75 |
| |
| 76 |
export Array | |
| 77 |
| |
| |