ae2f_docs
Loading...
Searching...
No Matches
scale.h
Go to the documentation of this file.
1/**
2 * @file scale.h
3 * @brief Kind of single linked list where only last one could be resized.
4 * */
5
6#ifndef pass_scale_h
7#define pass_scale_h
8
9#include <ae2f/c90/StdInt.h>
10#include "../vec.auto.h"
11#include <assert.h>
12
13
14typedef struct x_scale x_scale;
15typedef x_scale* ae2f_restrict h_scale_t;
16
17struct x_scale {
18 size_t m_id;
19 size_t m_nxt;
20 size_t m_prv;
21 size_t m_buf;
22 size_t m_sz;
23};
24
25#define SCALE_HEADER_SIZE
26 ((size_t)(sizeof(x_scale) + sizeof(size_t)))
27
28#define get_scale_header_from_vec(h_alloc) ((size_t* ae2f_restrict)((h_alloc)->m_p))
29#define get_first_scale_from_vec(h_alloc) ((h_scale_t)(get_scale_header_from_vec(h_alloc) + 1))
30
31#define get_last_scale_from_vec(h_alloc)
32 ((h_scale_t)( (uintptr_t)(*get_scale_header_from_vec(h_alloc)) + (uintptr_t)((h_alloc)->m_p) ))
33
34#define get_buf_from_scale(h_alloc, c_scale)
35 (ae2f_expected((h_alloc)->m_p)
36 ? (void* ae2f_restrict)(((uintptr_t)(h_alloc)->m_p) + ((uintptr_t)(c_scale).m_buf))
37 : ((void* ae2f_restrict)ae2f_NIL))
38
39#define get_buf_from_scale2(buf_T, h_alloc, c_scale)
40 ((buf_T* ae2f_restrict)get_buf_from_scale(h_alloc, c_scale))
41
42#define get_nxt_from_scale(h_alloc, c_scale)
43 (x_scale* ae2f_restrict)(((uintptr_t)(h_alloc)->m_p) + ((uintptr_t)(c_scale).m_nxt))
44
45#define get_prv_from_scale(h_alloc, c_scale)
46 (x_scale* ae2f_restrict)(((uintptr_t)(h_alloc)->m_p) + ((uintptr_t)(c_scale).m_prv))
47
48/**
49 * @fn init_scale
50 * @brief intialise the scale
51 * @return pointer to the first scale of `h_alloc`. `ae2f_NIL` when failed.
52 * */
53ae2f_inline ae2f_retnew static x_scale* init_scale(
54 x_aclspv_vec* ae2f_restrict const h_alloc,
55 const size_t c_init_sz
56 )
57{
58 _aclspv_grow_vec(_aclspv_malloc, _aclspv_free, *h_alloc, c_init_sz + SCALE_HEADER_SIZE);
59
60 unless(h_alloc->m_p)
61 return ae2f_NIL;
62
63 *get_scale_header_from_vec(h_alloc) = sizeof(size_t);
64
66 get_first_scale_from_vec(h_alloc)->m_sz = c_init_sz;
67 get_first_scale_from_vec(h_alloc)->m_nxt = 0;
68 get_first_scale_from_vec(h_alloc)->m_prv = sizeof(size_t);
69 get_first_scale_from_vec(h_alloc)->m_id = 0;
70
71 assert(get_first_scale_from_vec(h_alloc) == get_last_scale_from_vec(h_alloc));
72 return get_first_scale_from_vec(h_alloc);
73}
74
75/**
76 * @fn init_scale
77 * @brief get the pointer of `c_idx`th scale from `h_alloc`
78 * @return `ae2f_NIL` on failure.
79 * */
80ae2f_inline ae2f_ccconst static x_scale* get_scale_from_vec(
81 x_aclspv_vec* ae2f_restrict const h_alloc,
82 const size_t c_idx
83 )
84{
85 size_t i = c_idx;
86 x_scale* ae2f_restrict ret = get_first_scale_from_vec(h_alloc);
88 assert("non-alloc" && 0);
89 return ae2f_NIL;
90 }
91
93 assert("misconfigured" && 0);
94 return ae2f_NIL;
95 }
96
97 while(i--) {
98 ae2f_expected_but_else(ret->m_nxt) {
99 assert("exceeded" && 0);
101 return ae2f_NIL;
102 }
103
104 ret = get_nxt_from_scale(h_alloc, *ret);
105 }
106
107 assert(ret->m_id == c_idx);
108 return ret;
109}
110
111/**
112 * @fn grow_last_scale
113 * @brief grow the last scale of `h_alloc` in `c_newsize`
114 * @return 0 when succeed.
115 * */
116ae2f_inline static int_fast8_t grow_last_scale(
117 x_aclspv_vec* ae2f_restrict const h_alloc,
118 const size_t c_newsize
119 )
120{
121
122 assert(h_alloc);
123 unless(h_alloc->m_p) {
124 assert(0);
125 return 1;
126 }
127
128 if(get_last_scale_from_vec(h_alloc)->m_nxt) return 1;
129
130 _aclspv_grow_vec_with_copy(
131 _aclspv_malloc, _aclspv_free, _aclspv_memcpy
132 , L_new
133 , *h_alloc
134 , c_newsize + get_last_scale_from_vec(h_alloc)->m_buf
135 );
136
137 unless(h_alloc->m_p) return 1;
138
139 get_last_scale_from_vec(h_alloc)->m_sz = c_newsize;
140
141 return !(h_alloc && h_alloc->m_p);
142}
143
144ae2f_retnew ae2f_inline static x_scale* del_scale_from_vec_last(x_aclspv_vec* ae2f_restrict const h_alloc) {
145 h_scale_t lst = get_last_scale_from_vec(h_alloc);
146 h_scale_t lst_prv;
147
149 = lst->m_prv;
150
151 assert(lst);
152 lst_prv = get_prv_from_scale(h_alloc, *lst);
153 assert(lst_prv);
154 lst_prv->m_nxt = 0;
155 return lst_prv;
156}
157
158/**
159 * @fn mk_scale_from_vec
160 * @brief make new scale from `h_alloc` and returns its pointer
161 * @details pointer of new scale or `ae2f_NIL` when failed.
162 * */
163ae2f_retnew ae2f_inline static x_scale* mk_scale_from_vec(
164 x_aclspv_vec* ae2f_restrict const h_alloc,
165 const size_t c_init_size_opt
166 )
167{
168 h_scale_t
169 lst = get_last_scale_from_vec(h_alloc)
170 , nxt;
171 const size_t newsz = lst->m_buf + lst->m_sz + c_init_size_opt + (size_t)sizeof(x_scale);
172
173 assert(lst);
174 assert(h_alloc);
175 assert(h_alloc->m_p);
176 assert(*get_scale_header_from_vec(h_alloc));
177 assert(lst->m_buf);
178
179 _aclspv_grow_vec_with_copy(
180 _aclspv_malloc, _aclspv_free, _aclspv_memcpy, L_new
181 , *h_alloc
182 , newsz
183 );
184
185 assert(h_alloc->m_p);
186 ae2f_expected_but_else(h_alloc->m_p) return ae2f_NIL;
187
188 lst = get_last_scale_from_vec(h_alloc);
189 lst->m_nxt = lst->m_buf + lst->m_sz;
190
192 = lst->m_nxt;
193
194 nxt = get_nxt_from_scale(h_alloc, *lst);
195
196 assert(nxt != lst);
197
198 nxt->m_buf = lst->m_nxt + (size_t)sizeof(x_scale);
199 nxt->m_sz = c_init_size_opt;
200 nxt->m_nxt = 0;
201 nxt->m_id = lst->m_id + 1;
202 nxt->m_prv = lst->m_buf - (size_t)sizeof(x_scale);
203
204 assert(get_first_scale_from_vec(h_alloc) < get_last_scale_from_vec(h_alloc));
205 assert(lst->m_buf);
206 assert(lst->m_nxt);
207 assert(nxt->m_buf);
208
209 return nxt;
210}
211
212
213
214#endif
#define ae2f_IS_SHARED
Definition Call.auto.h:12
#define ae2f_OFF
Definition Call.auto.h:3
#define ae2f_WhenCXX(a)
Appears when the current language is C.
Definition Cxx.h:44
#define ae2f_WhenC(a)
Appears when the current language is C++.
Definition Cxx.h:38
#define unless(a)
Invokes when condition is false.
Definition Keys.h:34
#define ae2f_extern
Suggests the existence of external variable or function, in naming of C. [non-mangling].
Definition Keys.h:25
#define ae2f_NIL
Definition Nil.h:13
#define ACLSPV_ABI_DECL
Declaration as ABI.
Definition abi.h:23
#define STATE_VAL
#define FNINFO
#define cpysz
#define cpypad
#define ae2f_retnew
The returning pointer does not alias to existing object.
Definition cc.h:94
#define ae2f_assume(a)
tells the compiler that value if a is false, below this keyword is not expected to be reached.
Definition cc.h:228
#define ae2f_unexpected_but_if(a)
Definition cc.h:192
#define ae2f_ccpure
Keyword as [[pure]] on C23.
Definition cc.h:52
#define ae2f_expected_but_else(a)
Definition cc.h:201
#define ae2f_expected_if(a)
Definition cc.h:195
#define ae2f_ccconst
Keyword as [[const]] on C23..
Definition cc.h:66
#define ae2f_noexcept
marker that this function does not throw something.
Definition cc.h:133
#define ae2f_restrict
Keyword as restrict on C99.
Definition cc.h:81
#define ae2f_expected_not(a)
expectes a as false.
Definition cc.h:185
#define ae2f_unreachable()
tells the compiler that below this keyword is not expected to be reached.
Definition cc.h:213
#define ae2f_fallthrough
explicitly tells compiler that fallthrough on switch is expected.
Definition cc.h:164
#define ae2f_inline
inline
Definition cc.h:149
#define ae2f_expected(a)
expectes a as true.
Definition cc.h:184
#define wrd_caps
Definition conf.h:11
#define wrd_caps_count
Definition conf.h:12
#define wrd_ext
Definition conf.h:14
#define wrd_ext_count
Definition conf.h:15
#define THIS_FUNCTION
#define CTX
#define THIS_ENTRY_POINT
#define ARG_IDX
#define INTERFACES_MGR
#define EMIT_POS
#define IO_ARG_IDX
#define INTERFACE_COUNT
#define PUSH_SIZE
#define PSH_CONSTANT_ID
#define THIS_ENTP
#define INFO
#define BIND_IDX
#define util_emitx_spec_constant(h_wrds, c_wrdcount, c_ty, c_retid, c_val)
Definition emitx.h:140
#define util_emitx_variable(h_wrds, c_wrdcount, c_type, c_retid, c_storage_class)
Definition emitx.h:131
#define util_emitx_spec_constant_op2(h_wrds, c_wrdcount, c_retid, c_ty, c_operator, c_opr_0, c_opr_1)
Definition emitx.h:146
#define util_emitx_type_array(h_wrds, c_wrdcount, c_retid, c_elm_type_id, c_arrcount_id)
Definition emitx.h:137
#define util_emitx_type_pointer(h_wrds, c_wrdcount, c_retid, c_storage_class, c_elm_type_id)
Definition emitx.h:134
#define ret_count
#define get_buf_from_scale(h_alloc, c_scale)
Definition scale.h:34
#define get_last_scale_from_vec(h_alloc)
Definition scale.h:31
#define get_prv_from_scale(h_alloc, c_scale)
Definition scale.h:45
#define SCALE_HEADER_SIZE
Definition scale.h:25
#define get_first_scale_from_vec(h_alloc)
Definition scale.h:29
#define get_nxt_from_scale(h_alloc, c_scale)
Definition scale.h:42
#define get_scale_header_from_vec(h_alloc)
Definition scale.h:28
#define aclspv_opcode_t
integer as operation code
Definition spvty.h:27
aclspv_wrd_t aclspv_wrdcount_t
the integer type represents the number of word.
Definition spvty.h:61
#define ACLSPV_MASK_OPCODE
mask for opcode
Definition spvty.h:37
#define aclspv_wrd_t
integer as word
Definition spvty.h:16
#define ACLSPV_MASK_NOPRNDS
mask for number of operands
Definition spvty.h:42
x_aclspv_vec m_scale_vars
Definition ctx.h:62
aclspv_wrdcount_t m_num_type_uniques
Definition ctx.h:44
x_aclspv_vec m_cursors
cache for cursors for parsing one function for its use see util/cursor.h
Definition ctx.h:77
x_aclspv_vec m_constant_cache
Definition ctx.h:65
aclspv_id_t m_id
id
Definition ctx.h:50
x_aclspv_vec m_ret
word count for m_ret
Definition ctx.h:56
aclspv_wrd_t m_is_logical
when on, ignores m_is_buffer_64.
Definition ctx.h:23
aclspv_wrdcount_t m_num_cursor
number of m_cursors. for its use see util/cursor.h
Definition ctx.h:41
x_aclspv_vec m_type_uniques
cache for complex types which needs to be stored somewhere for its use see util/type_unique....
Definition ctx.h:86
aclspv_wrd_t m_nprm
Definition entp.h:13
aclspv_wrdcount_t m_arr_count_id
Definition bind.h:34
aclspv_wrd_t m_size
Definition bind.h:47
util_bind_unified m_unified
Definition bind.h:20
aclspv_wrd_t m_set
Definition bind.h:26
aclspv_wrd_t m_pad
Definition bind.h:49
#define mk_noprnds(c_num_opprm)
Definition wrdemit.h:66
#define emit_opcode(h_wrds, c_wrdcount, c_opcode, c_num_opprm_opt)
try emit opcode with num_opprm
Definition wrdemit.h:75
#define sz_to_count(c_sz)
byte size to word count
Definition wrdemit.h:24
#define get_wrd_of_vec(vec)
get word buffer from vector
Definition wrdemit.h:38
aclspv_wrdcount_t spvsz_t
Definition wrdemit.h:18
#define count_to_sz(c_count)
word count to byte size
Definition wrdemit.h:32
#define set_oprnd_count_for_opcode(cr_wrd, c_num_opprm)
Definition wrdemit.h:78
#define opcode_to_wrd(c_opcode, c_num_opprm)
Definition wrdemit.h:69