From 58e979198e879050137bf2f2c488ef10f6527336 Mon Sep 17 00:00:00 2001 From: Mars Cheng Date: Sun, 2 Jan 2022 20:00:25 +0800 Subject: [PATCH] refactor init logic --- src/exec.c | 19 ++++++++----------- src/init.c | 6 ++++++ src/iter.c | 3 --- src/stat.c | 6 ------ 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/exec.c b/src/exec.c index 6b893b0..e0d43ac 100644 --- a/src/exec.c +++ b/src/exec.c @@ -1029,21 +1029,11 @@ strm_raise(strm_stream* strm, const char* msg) strm_str_value(strm_str_new(msg, strlen(msg)))); } -void strm_array_init(strm_state* state); -void strm_string_init(strm_state* state); -void strm_latch_init(strm_state* state); -void strm_iter_init(strm_state* state); -void strm_socket_init(strm_state* state); -void strm_csv_init(strm_state* state); -void strm_kvs_init(strm_state* state); - void strm_init(strm_state*); static void -node_init(strm_state* state) +strm_misc_init(strm_state* state) { - strm_init(state); - strm_var_def(state, "stdin", strm_io_new(0, STRM_IO_READ)); strm_var_def(state, "stdout", strm_io_new(1, STRM_IO_WRITE)); strm_var_def(state, "stderr", strm_io_new(2, STRM_IO_WRITE)); @@ -1058,6 +1048,13 @@ node_init(strm_state* state) strm_var_def(state, "match", strm_cfunc_value(exec_match)); } +static void +node_init(strm_state* state) +{ + strm_init(state); + strm_misc_init(state); +} + static strm_state top_state = {0}; static strm_stream top_strm = {0}; diff --git a/src/init.c b/src/init.c index 6bbedc8..337e2dc 100644 --- a/src/init.c +++ b/src/init.c @@ -5,6 +5,9 @@ void strm_array_init(strm_state* state); void strm_string_init(strm_state* state); void strm_latch_init(strm_state* state); void strm_iter_init(strm_state* state); +void strm_stat_init(strm_state* state); +void strm_rand_init(strm_state* state); +void strm_sort_init(strm_state* state); void strm_socket_init(strm_state* state); void strm_csv_init(strm_state* state); void strm_kvs_init(strm_state* state); @@ -20,6 +23,9 @@ strm_init(strm_state* state) strm_string_init(state); strm_latch_init(state); strm_iter_init(state); + strm_stat_init(state); + strm_rand_init(state); + strm_sort_init(state); strm_socket_init(state); strm_csv_init(state); strm_kvs_init(state); diff --git a/src/iter.c b/src/iter.c index bcf6b9b..983944b 100644 --- a/src/iter.c +++ b/src/iter.c @@ -878,8 +878,6 @@ exec_uniq(strm_stream* strm, int argc, strm_value* args, strm_value* ret) return STRM_OK; } -void strm_stat_init(strm_state* state); - void strm_iter_init(strm_state* state) { @@ -905,5 +903,4 @@ strm_iter_init(strm_state* state) strm_var_def(strm_ns_array, "each", strm_cfunc_value(ary_each)); strm_var_def(strm_ns_array, "map", strm_cfunc_value(ary_map)); strm_var_def(strm_ns_array, "flatmap", strm_cfunc_value(ary_flatmap)); - strm_stat_init(state); } diff --git a/src/stat.c b/src/stat.c index 6df6e51..9a18982 100644 --- a/src/stat.c +++ b/src/stat.c @@ -531,9 +531,6 @@ ary_correl(strm_stream* strm, int argc, strm_value* args, strm_value* ret) return STRM_OK; } -void strm_rand_init(strm_state* state); -void strm_sort_init(strm_state* state); - void strm_stat_init(strm_state* state) { @@ -553,7 +550,4 @@ strm_stat_init(strm_state* state) strm_var_def(strm_ns_array, "stdev", strm_cfunc_value(ary_stdev)); strm_var_def(strm_ns_array, "variance", strm_cfunc_value(ary_var)); strm_var_def(strm_ns_array, "correl", strm_cfunc_value(ary_correl)); - - strm_rand_init(state); - strm_sort_init(state); }