mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-23 07:59:37 +00:00
45 lines
1.2 KiB
C
45 lines
1.2 KiB
C
#ifndef BIND_STACK_H
|
|
#define BIND_STACK_H
|
|
|
|
#include "containers/mlrval.h"
|
|
#include "containers/lhmsmv.h"
|
|
|
|
// Bound & scoped variables for use in for-loops, function bodies, and
|
|
// subroutine bodies. A frame is 'fenced' if it's at entry to a
|
|
// function/subroutine body. Example:
|
|
//
|
|
// mlr ... put -f '
|
|
// func f(x) {
|
|
// return k;
|
|
// }
|
|
// for (k,v in $*) {
|
|
// $[k] = f(v)
|
|
// }
|
|
// '
|
|
//
|
|
// There is a bind-stack created on entering the put. A frame is pushed in the
|
|
// for-loop. A second frame is pushed in the call to f(x). The former should
|
|
// have access to k; the latter should not.
|
|
|
|
typedef struct _bind_stack_frame_t {
|
|
lhmsmv_t* bindings;
|
|
int fenced;
|
|
} bind_stack_frame_t;
|
|
|
|
typedef struct _bind_stack_t {
|
|
int num_used;
|
|
int num_allocated;
|
|
bind_stack_frame_t* pframes;
|
|
} bind_stack_t;
|
|
|
|
bind_stack_t* bind_stack_alloc();
|
|
void bind_stack_free(bind_stack_t* pstack);
|
|
|
|
void bind_stack_push(bind_stack_t* pstack, lhmsmv_t* bindings);
|
|
void bind_stack_push_fenced(bind_stack_t* pstack, lhmsmv_t* bindings);
|
|
void bind_stack_pop(bind_stack_t* pstack);
|
|
mv_t* bind_stack_resolve(bind_stack_t* pstack, char* key);
|
|
|
|
void bind_stack_print(bind_stack_t* pstack);
|
|
|
|
#endif // BIND_STACK_H
|