mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
* Simple hash map. Fix of bug preventing cast of typeid. Allow declarations in global "$checks". Fix to non-constant default args. Correctly duplicate macro contracts. Allow typeid to add methods. Fix printing of subarrays. Fix bug when printing a function with a module. Fix bug with initializer and creating local variables. Add the compile-only option to the help.
41 lines
1013 B
C
41 lines
1013 B
C
// Copyright (c) 2021 Christoffer Lerno. All rights reserved.
|
|
// Use of this source code is governed by the MIT license
|
|
// a copy of which can be found in the LICENSE_STDLIB file.
|
|
module std::core::mem::array;
|
|
|
|
/**
|
|
* @require usize.max / elements > $Type.sizeof
|
|
**/
|
|
macro alloc($Type, usize elements)
|
|
{
|
|
$Type* ptr = malloc($Type.sizeof * elements);
|
|
return ptr[:elements];
|
|
}
|
|
|
|
/**
|
|
* @require usize.max / elements > $Type.sizeof
|
|
**/
|
|
macro talloc($Type, usize elements)
|
|
{
|
|
$Type* ptr = tmalloc($Type.sizeof * elements, $alignof($Type[1]));
|
|
return ptr[:elements];
|
|
}
|
|
|
|
/**
|
|
* @require (usize.max / elements > $Type.sizeof)
|
|
**/
|
|
macro make($Type, usize elements, Allocator* allocator = mem::current_allocator())
|
|
{
|
|
$Type* ptr = allocator.calloc($Type.sizeof * elements)!!;
|
|
return ptr[:elements];
|
|
}
|
|
|
|
/**
|
|
* @require (usize.max / elements > $Type.sizeof)
|
|
**/
|
|
macro tmake($Type, usize elements)
|
|
{
|
|
$Type* ptr = tcalloc($Type.sizeof * elements, $alignof($Type[1]));
|
|
return ptr[:elements];
|
|
}
|