mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-22 15:37:59 +00:00
neaten
This commit is contained in:
parent
b2e6e63722
commit
c2afceb78b
3 changed files with 48 additions and 49 deletions
|
|
@ -3,16 +3,6 @@
|
|||
#include "lib/mlr_globals.h"
|
||||
#include "containers/local_stack.h"
|
||||
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE
|
||||
static int local_stack_trace_first_call = TRUE;
|
||||
static void local_stack_trace_announce() {
|
||||
if (local_stack_trace_first_call) {
|
||||
fprintf(stderr, "%s: local-stack bounds-checking is enabled\n", MLR_GLOBALS.bargv0);
|
||||
local_stack_trace_first_call = FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// ================================================================
|
||||
static local_stack_frame_t* _local_stack_alloc(int size, int ephemeral) {
|
||||
local_stack_frame_t* pframe = mlr_malloc_or_die(sizeof(local_stack_frame_t));
|
||||
|
|
@ -50,17 +40,11 @@ void local_stack_frame_free(local_stack_frame_t* pframe) {
|
|||
local_stack_frame_t* local_stack_frame_enter(local_stack_frame_t* pframe) {
|
||||
if (!pframe->in_use) {
|
||||
pframe->in_use = TRUE;
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE
|
||||
local_stack_trace_announce();
|
||||
printf("LOCAL STACK FRAME NON-EPH ENTER %p %d\n", pframe, pframe->size);
|
||||
#endif
|
||||
LOCAL_STACK_TRACE(printf("LOCAL STACK FRAME NON-EPH ENTER %p %d\n", pframe, pframe->size));
|
||||
return pframe;
|
||||
} else {
|
||||
local_stack_frame_t* prv = _local_stack_alloc(pframe->size, TRUE);
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE
|
||||
local_stack_trace_announce();
|
||||
printf("LOCAL STACK FRAME EPH ENTER %p/%p %d\n", pframe, prv, pframe->size);
|
||||
#endif
|
||||
LOCAL_STACK_TRACE(printf("LOCAL STACK FRAME EPH ENTER %p/%p %d\n", pframe, prv, pframe->size));
|
||||
prv->in_use = TRUE;
|
||||
return prv;
|
||||
}
|
||||
|
|
@ -73,16 +57,10 @@ void local_stack_frame_exit (local_stack_frame_t* pframe) {
|
|||
mv_free(&pframe->pvars[i]);
|
||||
if (!pframe->ephemeral) {
|
||||
pframe->in_use = FALSE;
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE
|
||||
local_stack_trace_announce();
|
||||
printf("LOCAL STACK FRAME NON-EPH EXIT %p %d\n", pframe, pframe->size);
|
||||
#endif
|
||||
LOCAL_STACK_TRACE(printf("LOCAL STACK FRAME NON-EPH EXIT %p %d\n", pframe, pframe->size));
|
||||
} else {
|
||||
local_stack_frame_free(pframe);
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE
|
||||
local_stack_trace_announce();
|
||||
printf("LOCAL STACK FRAME EPH EXIT %p %d\n", pframe, pframe->size);
|
||||
#endif
|
||||
LOCAL_STACK_TRACE(printf("LOCAL STACK FRAME EPH EXIT %p %d\n", pframe, pframe->size));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ typedef struct _local_stack_frame_t {
|
|||
int size;
|
||||
int subframe_base;
|
||||
mv_t* pvars;
|
||||
// xxx has-absent-read flag ...
|
||||
} local_stack_frame_t;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
|
@ -33,10 +32,11 @@ typedef struct _local_stack_frame_t {
|
|||
local_stack_frame_t* local_stack_frame_alloc(int size);
|
||||
void local_stack_frame_free(local_stack_frame_t* pframe);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// ================================================================
|
||||
//#define LOCAL_STACK_TRACE_ENABLE
|
||||
//#define LOCAL_STACK_BOUNDS_CHECK_ENABLE
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
#ifdef LOCAL_STACK_BOUNDS_CHECK_ENABLE
|
||||
static int local_stack_bounds_check_announce_first_call = TRUE;
|
||||
|
||||
|
|
@ -46,15 +46,18 @@ static void local_stack_bounds_check(local_stack_frame_t* pframe, char* op, int
|
|||
local_stack_bounds_check_announce_first_call = FALSE;
|
||||
}
|
||||
if (vardef_frame_relative_index < 0) {
|
||||
fprintf(stderr, "OP=%s FRAME=%p IDX=%d/%d STACK UNDERFLOW\n", op, pframe, vardef_frame_relative_index, pframe->size);
|
||||
fprintf(stderr, "OP=%s FRAME=%p IDX=%d/%d STACK UNDERFLOW\n",
|
||||
op, pframe, vardef_frame_relative_index, pframe->size);
|
||||
exit(1);
|
||||
}
|
||||
if (set && vardef_frame_relative_index == 0) {
|
||||
fprintf(stderr, "OP=%s FRAME=%p IDX=%d/%d ABSENT WRITE\n", op, pframe, vardef_frame_relative_index, pframe->size);
|
||||
fprintf(stderr, "OP=%s FRAME=%p IDX=%d/%d ABSENT WRITE\n",
|
||||
op, pframe, vardef_frame_relative_index, pframe->size);
|
||||
exit(1);
|
||||
}
|
||||
if (vardef_frame_relative_index >= pframe->size) {
|
||||
fprintf(stderr, "OP=%s FRAME=%p IDX=%d/%d STACK OVERFLOW\n", op, pframe, vardef_frame_relative_index, pframe->size);
|
||||
fprintf(stderr, "OP=%s FRAME=%p IDX=%d/%d STACK OVERFLOW\n",
|
||||
op, pframe, vardef_frame_relative_index, pframe->size);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -67,6 +70,13 @@ static void local_stack_bounds_check(local_stack_frame_t* pframe, char* op, int
|
|||
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE
|
||||
#define LOCAL_STACK_TRACE(p) p
|
||||
#else
|
||||
#define LOCAL_STACK_TRACE(p)
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Sets/clear the in-use flag for top-level statement blocks, and verifies
|
||||
// the contract for absent-null at slot 0.
|
||||
|
|
@ -79,16 +89,12 @@ local_stack_frame_t* local_stack_frame_enter(local_stack_frame_t* pframe);
|
|||
void local_stack_frame_exit(local_stack_frame_t* pframe);
|
||||
|
||||
static inline mv_t* local_stack_frame_get(local_stack_frame_t* pframe, int vardef_frame_relative_index) {
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE // xxx macroify
|
||||
printf("LOCAL STACK FRAME %p GET %d\n", pframe, vardef_frame_relative_index);
|
||||
#endif
|
||||
LOCAL_STACK_TRACE(printf("LOCAL STACK FRAME %p GET %d\n", pframe, vardef_frame_relative_index));
|
||||
LOCAL_STACK_BOUNDS_CHECK(pframe, "GET", FALSE, vardef_frame_relative_index);
|
||||
return &pframe->pvars[vardef_frame_relative_index];
|
||||
}
|
||||
static inline void local_stack_frame_set(local_stack_frame_t* pframe, int vardef_frame_relative_index, mv_t val) {
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE // xxx macroify
|
||||
printf("LOCAL STACK FRAME %p SET %d\n", pframe, vardef_frame_relative_index);
|
||||
#endif
|
||||
LOCAL_STACK_TRACE(printf("LOCAL STACK FRAME %p SET %d\n", pframe, vardef_frame_relative_index));
|
||||
LOCAL_STACK_BOUNDS_CHECK(pframe, "SET", TRUE, vardef_frame_relative_index);
|
||||
// xxx debug after free-flags semantics are in place
|
||||
// xxx pframe->pvars[vardef_frame_relative_index] = val;
|
||||
|
|
@ -101,14 +107,11 @@ static inline void local_stack_frame_set(local_stack_frame_t* pframe, int vardef
|
|||
// the top-level block itself as well as ifs/fors/whiles.
|
||||
|
||||
static inline void local_stack_subframe_enter(local_stack_frame_t* pframe, int count) {
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE // xxx macroify
|
||||
printf("LOCAL STACK SUBFRAME %p ENTER %d->%d\n", pframe, pframe->subframe_base, pframe->subframe_base+count);
|
||||
#endif
|
||||
LOCAL_STACK_TRACE(printf("LOCAL STACK SUBFRAME %p ENTER %d->%d\n",
|
||||
pframe, pframe->subframe_base, pframe->subframe_base+count));
|
||||
mv_t* psubframe = &pframe->pvars[pframe->subframe_base];
|
||||
for (int i = 0; i < count; i++) {
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE // xxx macroify
|
||||
printf("LOCAL STACK FRAME %p CLEAR %d\n", pframe, pframe->subframe_base+i);
|
||||
#endif
|
||||
LOCAL_STACK_TRACE(printf("LOCAL STACK FRAME %p CLEAR %d\n", pframe, pframe->subframe_base+i));
|
||||
LOCAL_STACK_BOUNDS_CHECK(pframe, "CLEAR", FALSE, pframe->subframe_base+i);
|
||||
mv_reset(&psubframe[i]);
|
||||
}
|
||||
|
|
@ -116,9 +119,8 @@ static inline void local_stack_subframe_enter(local_stack_frame_t* pframe, int c
|
|||
}
|
||||
|
||||
static inline void local_stack_subframe_exit(local_stack_frame_t* pframe, int count) {
|
||||
#ifdef LOCAL_STACK_TRACE_ENABLE // xxx macroify
|
||||
printf("LOCAL STACK SUBFRAME %p EXIT %d->%d\n", pframe, pframe->subframe_base, pframe->subframe_base-count);
|
||||
#endif
|
||||
LOCAL_STACK_TRACE(printf("LOCAL STACK SUBFRAME %p EXIT %d->%d\n",
|
||||
pframe, pframe->subframe_base, pframe->subframe_base-count));
|
||||
pframe->subframe_base -= count;
|
||||
}
|
||||
|
||||
|
|
|
|||
25
c/todo.txt
25
c/todo.txt
|
|
@ -21,12 +21,27 @@ FUNCTIONALITY FOR 4.6.0:
|
|||
! triple-for multi-continuation !
|
||||
|
||||
? map-locals into 4.6.0?!?!?
|
||||
- parameter marshal
|
||||
- LHS define/assign
|
||||
- RHS expr eval
|
||||
- maplocal <=> $* / @* / @a[b][c]
|
||||
a = $*
|
||||
a = @*
|
||||
a = @b
|
||||
a = @b[c]
|
||||
a = b
|
||||
$* = a
|
||||
@* = a
|
||||
@b = a
|
||||
@b[c] = a
|
||||
|
||||
- RHS expr eval: terminality as already for oosvars
|
||||
|
||||
- parameter marshal
|
||||
|
||||
- function return value
|
||||
|
||||
? for-oosvar map-valued boundvars?!?
|
||||
|
||||
? runtime type assertion ?
|
||||
|
||||
----------------------------------------------------------------
|
||||
UT FOR 4.6.0:
|
||||
|
||||
|
|
@ -48,6 +63,10 @@ OOSVAR SINGLE FOR:
|
|||
* oosvar-single-for mld
|
||||
* find & update cookbook/ref/whateveritwas ...
|
||||
|
||||
COOK:
|
||||
* n-grams ...
|
||||
* mlr --from words --nidx filter 'n=strlen($1);4<=n&&n<=8' then sample -k 10
|
||||
|
||||
PERF:
|
||||
* mand bench somewhere; other benches.
|
||||
* mkv2/3/4 somewhere; also cookbook. (better w/ mappable vars ... maybe for 4.7.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue