gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
scope.h File Reference

scope functions More...

Go to the source code of this file.

Data Structures

struct  Scope_
 
struct  scope_iter
 

Typedefs

typedef struct Scope_Scope
 

Functions

ANN Scope new_scope (MemPool)
 
ANN void scope_init (MemPool, Scope)
 
ANEW ANN Vector scope_get (const Scope)
 
ANN vtype scope_lookup0 (const Scope, const vtype)
 
ANN vtype scope_lookup1 (const Scope, const vtype)
 
ANN vtype scope_lookup2 (const Scope, const vtype)
 
ANN void scope_add (const Scope, const vtype, const vtype)
 
ANN void scope_commit (const Scope)
 
ANN void scope_release (Scope)
 
ANN void free_scope (MemPool, Scope)
 
static ANN void scope_push (MemPool p NUSED, const Scope s)
 
static ANN void scope_pop (MemPool p NUSED, const Scope s)
 
static ANN void _scope_init (const Scope s)
 
ANN bool scope_iter (struct scope_iter *iter, void *ret)
 

Detailed Description

scope functions

Definition in file scope.h.

Typedef Documentation

◆ Scope

typedef struct Scope_ * Scope

Function Documentation

◆ _scope_init()

static ANN void _scope_init ( const Scope s)
inlinestatic

Definition at line 38 of file scope.h.

38 {
39 vector_init((Vector)(void *)s);
40}
ANN void vector_init(const Vector v)
Definition vector.c:3

◆ free_scope()

ANN void free_scope ( MemPool p,
Scope a )
extern

Definition at line 58 of file scope.c.

58 {
60 mp_free(p, Scope, a);
61}
#define mp_free(p, name, a)
Definition mpool.h:27
ANN void scope_release(Scope a)
Definition scope.c:52
Definition scope.h:7

◆ new_scope()

ANN Scope new_scope ( MemPool p)
extern

Definition at line 46 of file scope.c.

46 {
47 Scope a = mp_calloc(p, Scope);
48 scope_init(p, a);
49 return a;
50}
#define mp_calloc(p, name)
Definition mpool.h:26
ANN void scope_init(MemPool p, Scope a)
Definition scope.c:40

◆ scope_add()

ANN void scope_add ( const Scope s,
const vtype xid,
const vtype value )
extern

Definition at line 28 of file scope.c.

28 {
29 if (VLEN(s) > 1)
30 map_set(scope_back(s), xid, value);
31 else
32 map_set(&s->map, xid, value);
33}
#define VLEN(v)
Definition container.h:10
ANN void map_set(const Map map, const vtype key, const vtype ptr)
Definition map.c:32
static ANN Map scope_back(const Scope s)
Definition scope.c:3
struct Map_ map
Definition scope.h:9

◆ scope_commit()

ANN void scope_commit ( const Scope s)
extern

Definition at line 35 of file scope.c.

35 {
36 map_commit((Map)&VPTR(s, 0), &s->map);
37 map_clear(&s->map);
38}
#define VPTR(v, i)
Definition container.h:12
ANN void map_clear(const Map v)
Definition map.c:3
ANN void map_commit(const restrict Map map, const restrict Map commit)
Definition map.c:56
Definition map.h:7

◆ scope_get()

ANEW ANN Vector scope_get ( const Scope )
extern

◆ scope_init()

ANN void scope_init ( MemPool p,
Scope a )
extern

Definition at line 40 of file scope.c.

40 {
43 scope_push(p, a);
44}
static ANN void scope_push(MemPool p NUSED, const Scope s)
Definition scope.h:28

◆ scope_iter()

ANN bool scope_iter ( struct scope_iter * iter,
void * ret )

Definition at line 63 of file scope.c.

63 {
64 m_uint size = map_size(&iter->s->map);
65 const m_uint vsize = vector_size((Vector)iter->s);
66 const m_uint vec = vsize - iter->vec;
67 Map map = &iter->s->map;
68 if (vsize == iter->vec) {
69 if (iter->idx == size) return false;
70 } else {
71 map = (Map)&VPTR(iter->s, vec - 1);
72 size = map_size(map);
73 if (iter->idx == size) {
74 ++iter->vec;
75 iter->idx = 0;
76 return scope_iter(iter, ret);
77 }
78 }
79 *(vtype *)ret = map_at(map, size - ++iter->idx);
80 return true;
81}
uintptr_t vtype
Definition container.h:14
uintptr_t m_uint
Definition gwcommon.h:11
static ANN vtype map_size(const Map map)
Definition map.h:28
struct Map_ * Map
static ANN vtype map_at(const Map map, const vtype index)
Definition map.h:19
ANN bool scope_iter(struct scope_iter *iter, void *ret)
Definition scope.c:63
m_uint vec
Definition scope.h:14
m_uint idx
Definition scope.h:15
const Scope s
Definition scope.h:13
static ANN vtype vector_size(Vector const v)
Definition vector.h:29

◆ scope_lookup0()

ANN vtype scope_lookup0 ( const Scope s,
const vtype xid )
extern

Definition at line 7 of file scope.c.

7 {
8 const Map map = scope_back(s);
9 const vtype ret = map_get(map, xid);
10 if (!ret && VLEN(s) == 1) return map_get(&s->map, (vtype)xid);
11 return ret;
12}
ANN vtype map_get(const Map map, const vtype key)
Definition map.c:20

◆ scope_lookup1()

ANN vtype scope_lookup1 ( const Scope s,
const vtype xid )
extern

Definition at line 14 of file scope.c.

14 {
15 for (m_uint i = VLEN(s) + 1; --i;) {
16 const Map map = (Map)&VPTR(s, i - 1);
17 const vtype ret = map_get(map, xid);
18 if (ret) return ret;
19 }
20 return map_get(&s->map, (vtype)xid);
21}

◆ scope_lookup2()

ANN vtype scope_lookup2 ( const Scope s,
const vtype xid )
extern

Definition at line 23 of file scope.c.

23 {
24 const Map map = (Map)&VPTR(s, 0);
25 return map_get(map, xid) ?: map_get(&s->map, (vtype)xid);
26}

◆ scope_pop()

static ANN void scope_pop ( MemPool p NUSED,
const Scope s )
inlinestatic

Definition at line 33 of file scope.h.

33 {
34 const m_uint back = vector_pop((Vector)(void *)s);
35 map_release((Map)&back);
36}
ANN void map_release(const Map map)
Definition map.c:61
ANN vtype vector_pop(const Vector v)
Definition vector.c:61

◆ scope_push()

static ANN void scope_push ( MemPool p NUSED,
const Scope s )
inlinestatic

Definition at line 28 of file scope.h.

28 {
29 vector_add((Vector)(void *)s, 0);
30 map_init((Map)&VPTR(s, VLEN(s) - 1));
31}
ANN void map_init(const Map a)
Definition map.c:9
ANN void vector_add(const Vector v, const vtype data)
Definition vector.c:21

◆ scope_release()

ANN void scope_release ( Scope a)
extern

Definition at line 52 of file scope.c.

52 {
53 map_release((Map)&VPTR(a, 0));
56}
ANN void vector_release(const Vector v)
Definition vector.c:14