(:: : array.arg -- array and pointer manipulations : : Copyright (C) 2009,2010,2011,2014 the Argile authors : : This file is part of libargrt -- Argile runtime library. : : This software is provided 'as-is', without any express or implied : warranty. In no event will the authors be held liable for any damages : arising from the use of this software. : : Permission is granted to anyone to use this software for any purpose, : including commercial applications, and to alter it and redistribute it : freely, subject to the following restrictions: : : 1. The origin of this software must not be misrepresented; you must not : claim that you wrote the original software. If you use this software : in a product, an acknowledgment in the product documentation would be : appreciated but is not required. : : 2. Altered source versions must be plainly marked as such, and must not : be misrepresented as being the original software. : : 3. This notice may not be removed or altered from any source : distribution. :) use std (: array type definition :) =:(raw) array (of () ):= -> type Cgen t.prefix "(" (??3 (Cgen"") (??1 (Cgen"") Cgen"*")) Cgen (??3 (Cgen"["n"]") (??1 Cgen"[]")) ")" (t.suffix) (: cell access :) =: \[]:= -> a.type& {Cgen_ref"&("a")["i"]"} =: \[]:= -> a.type {Cgen "("a")["i"]"} (: for raw types :) =: + := -> array of a.type {Cgen "("a" + "i")"} (: constructor :) =: new array (of () ) := -> array of t memset malloc size * size of t \ 0 \ size * size of t as array of t (: array literals :) =:@\[[...1,]]:= -> array of type of x Cgen "("raw array of type of x"){"@x"}" =:\[] := -> array of (t@) Cgen "("(t@.prefix)"([])"(t@.suffix)")" Cdata data (: pointer type definition :) =:{pointer | *}:= -> type Cgen t.prefix "*" Cgen t.suffix (: pointer dereferencing :) =:*:= -> p.t& {Cgen p} (: address operator :) =:&:= -> type of a& {a} =:&:= -> type of a* {Cgen_ref"&"a} (: pointer constructor :) =:alloc := -> t* {malloc size of t as t*} (: loop :) =:for each in (from ) to := let int for_each_iterator (: avoid C-identifier collisions :) for for_each_iterator=f for_each_iterator<=t for_each_iterator++ x = a[for_each_iterator] call c (: misc. :) #extern argc -> int #extern argv -> array of text