From 3edd1f91f9db1ef13dbfa011d30c83bf6b85e3dd Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Thu, 28 Dec 2006 07:42:59 +0100 Subject: [PATCH] new macro expansion (in progress) --- std/std_macros.c | 541 +++++++++++++++++++++++++++++-------------------------- std/std_macros.h | 2 + 2 files changed, 283 insertions(+), 260 deletions(-) diff --git a/std/std_macros.c b/std/std_macros.c index 5ea1556..64cb65c 100644 --- a/std/std_macros.c +++ b/std/std_macros.c @@ -1,7 +1,7 @@ /* - std_parsers.c - MaLa standard module parsers + std_macros.c - MaLa standard module macros - Copyright (C) 2005, Christian Thaeter + Copyright (C) 2005, 2006, Christian Thaeter This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as @@ -22,13 +22,20 @@ #include #include "mala.h" -#include "std.h" +#include "std_macros.h" -//static void -//mala_macrocheck_list (LList list, int * max_arg, int argt[10]); +static void +mala_stringlist_macrocheck (MalaStringList list, int * max_arg, mala_state argt[10]); + +static void +mala_string_macrocheck (MalaString string, int * max_arg, mala_state argt[10]); + +static MalaString +mala_string_new_macrosubst (MalaString src, MalaString args[10], MalaEngine eng); + +static MalaStringList +mala_stringlist_new_macrosubst (MalaStringList src, MalaString args[10], MalaEngine eng); -//static void -//mala_macrocheck_string (MalaString string, int * max_arg, int argt[10]); static @@ -59,8 +66,8 @@ mala_actioninit std_macros[] = //MALA_SIMPLE_PARSER("--DEF", mala_def_parser), - MALA_PARSER_BRIEF("--DEF", "defines a substitution"), - MALA_PARSER_SIGNATURE_TYPE("--DEF", ("WORD", "WORD-OR-BLOCK")), + //MALA_PARSER_BRIEF("--DEF", "defines a substitution"), + //MALA_PARSER_SIGNATURE_TYPE("--DEF", ("WORD", "WORD-OR-BLOCK")), //TODO MALA_PARSER_SIGNATURE_USAGE("--DEF", ("word to be substituted", // "replaced with this")), //TODO MALA_PARSER_HELP("--DEF", ("The second argument can be a block of words enclosed in --BEGIN ... --END with % substitution sequences. See help for --BEGIN for details.")), @@ -72,15 +79,15 @@ mala_actioninit std_macros[] = //TODOMALA_PARSER_HELP("--END", ("an --END without a matching --BEGIN raises an error.")), - MALA_SIMPLE_PARSER("--DEL", mala_delete_parser), + MALA_PARSER_SIMPLE("--DEL", mala_delete_parser), - MALA_PARSER_BRIEF("--DEL", "deletes a macro"), + //MALA_PARSER_BRIEF("--DEL", "deletes a macro"), //TODO MALA_PARSER_SIGNATURE_TYPE("--DEL", ("WORD")), //TODO MALA_PARSER_SIGNATURE_USAGE("--DEL", ("name of the Macro to delete")), //TODO MALA_PARSER_HELP("--DEL", ("Removes the last definition of the most recent definition with the matching name and any childs which where attached to it (see --ATTACH)")), - MALA_SIMPLE_PARSER("--BEGIN", mala_begin_parser), - MALA_PARSER_BRIEF("--BEGIN", "defines a block or list"), + MALA_PARSER_SIMPLE("--BEGIN", mala_begin_parser), + // MALA_PARSER_BRIEF("--BEGIN", "defines a block or list"), //TODO MALA_PARSER_SIGNATURE_TYPE("--BEGIN", ("SEQUENCE","END")), //TODO MALA_PARSER_SIGNATURE_USAGE("--BEGIN", ("content of the block", "a --END which closes the block")), //TODO MALA_PARSER_RESULT_TYPE("--BEGIN", ("BLOCK")), @@ -93,39 +100,37 @@ mala_actioninit std_macros[] = int -mala_substitute_parser (MalaProgram prg, void * data) +mala_substitute_parser (MalaProgram prg) { - MALA_SIDEEFFECT_BEGIN - mala_stringlistnode_substitute_string (mala_program_pos (prg), (MalaString) data); - MALA_SIDEEFFECT_END; + MALA_MUTATOR_BEGIN + { + TODO("treat data_alloc_type"); + + mala_stringlist_next (prg->pptr)->string = (MalaString) mala_program_pptr_action (prg)->string; + } + MALA_MUTATOR_END; return MALA_CONTINUE; } int -mala_expand_parser (MalaProgram prg, void * data) +mala_expand_parser (MalaProgram prg) { - (void) data; - //MalaStringListNode itr; - // MalaStringListNode end; - - MALA_SIDEEFFECT_BEGIN + MALA_MUTATOR_BEGIN { + MalaAction act = mala_program_pptr_action (prg); + MalaStringList pos = mala_stringlist_next (prg->pptr); + MalaStringList itr; -#if 0 - end = mala_stringlistnode_next (mala_program_pos (prg)); - - for (itr = mala_stringlist_tail ((MalaStringList) data); - !mala_stringlist_is_end ((MalaStringList) data, itr); - mala_stringlistnode_rev (&itr)) + for (itr = mala_stringlist_tail_get ((MalaStringList) act->data); + !mala_stringlist_is_end ((MalaStringList) act->data, itr); + mala_stringlist_rev (&itr)) { - // TODO --PROGRAM if (!mala_stringlist_after_new (&eng->program, mala_program_pos (prg), - // mala_stringlistnode_string (itr))) - // goto ealloc_node; + MalaStringList node = mala_stringlist_node_new (mala_stringlist_string (itr), prg->engine); + mala_stringlist_insert_after (pos, node); } -#endif } - MALA_SIDEEFFECT_END; + MALA_MUTATOR_END; mala_program_action_done (prg, 0); return MALA_CONTINUE; @@ -133,151 +138,230 @@ mala_expand_parser (MalaProgram prg, void * data) int -mala_macro_parser (MalaProgram prg, void * data) +mala_macro_parser (MalaProgram prg) { - (void) prg; - (void) data; -#if 0 //TODO - MalaStringListNode itr; - MalaStringListNode last = NULL; - LList list; - const char* c; - int i; - int max_arg = 0; - int argt[10] = {0}; - char *p = NULL; - MalaString args[10]; - MalaString str = NULL; - // scan how much args are needed - mala_macrocheck_list ((LList) data, &max_arg, argt); - - // evaluate args, fill arg-array - args[0] = mala_stringlistnode_string (mala_program_pos (prg)); - - MALA_SIDEEFFECT_BEGIN + NOTICE (mala_module_std_macros, "macro parser"); + int max_arg = -1; + + /* How much to eveluate the argument (for now, likely extended in future): + MALA_REMOVE is used as pseudo tag for unused arguments/initialization + MALA_START doesn't evaluate the argument + MALA_LITERAL will evaluate fully + .. other destination states are reserved for future + */ + mala_state argt[10] = {[0 ... 9] = MALA_REMOVE}; + MalaAction act = mala_program_pptr_action (prg); + + // scan for arguments + AcogcFactory type = mala_action_data_type (act); + if (type == &prg->engine->gcfactory_strings) { - for (i = 1; i <= max_arg; ++i) - { - // TODO %STATEn evaluated to STATE - if (!(last = mala_engine_arg_eval (eng, pptr, i, - argt[i] == 1 ? MALA_LITERAL : MALA_EXCEPTION)) - || eng->state > MALA_EFAULT) - return eng->state; + mala_string_macrocheck (mala_action_string (act), &max_arg, argt); + } + else if (type == &prg->engine->gcfactory_stringlists) + { + mala_stringlist_macrocheck (mala_action_stringlist (act), &max_arg, argt); + } + else + NOTREACHED; + + BUG ("if (max_arg == INT_MAX) syntax error"); + + if (max_arg == -1) + return mala_expand_parser (prg); - args[i] = mala_stringlistnode_string (last); + MALA_MUTATOR_BEGIN + { + ACOGC_STACK_ENTER (&prg->engine->gcroot); + // evaluate args + for (int i=1; i <= max_arg; ++i) + { + if (argt[i] < MALA_START) + { + mala_program_eval_arg (prg, i, argt[i]); + TODO (" return / error handlen"); + } } - // build list with substitutions - list = mala_stringlist_new (); - if (!list) - goto ealloc_list; + // construct result list + MalaString args[10]; + MalaStringList p = mala_stringlist_next (prg->pptr); + for (int i=1; i <= max_arg; ++i) + { + mala_stringlist_fwd (&p); + args[i] = mala_stringlist_string (p); + } - if (!mala_stringlist_tail_new (list, eng->common_string[MALA_STRING_BEGIN])) - goto ealloc; + // constructing list + if (type == &prg->engine->gcfactory_strings) + { + ACOGC_STACK_PTR (MalaString, string); + string.ptr = mala_string_new_macrosubst (mala_action_string (act), + args, prg->engine); - for (itr = mala_stringlist_head ((MalaStringList) data); - !mala_stringlist_is_end ((MalaStringList) data, itr); - mala_stringlistnode_fwd (&itr)) + MalaStringList n = mala_stringlist_node_new (string.ptr, prg->engine); + mala_stringlist_insert_after (p, n); + } + else if (type == &prg->engine->gcfactory_stringlists) { - size_t size = 64; - if (!(p = malloc (size))) - goto ealloc; + ACOGC_STACK_PTR (MalaStringList, list); + list.ptr = mala_stringlist_new_macrosubst (mala_action_stringlist (act), + args, prg->engine); + mala_stringlist_insert_after_stringlist (p, list.ptr); + } + else + NOTREACHED; + + ACOGC_STACK_LEAVE; + } + MALA_MUTATOR_END; - for (c = mala_string_cstr (mala_stringlistnode_string (itr)), i = 0; *c; ++c,++i) + mala_program_action_done (prg, max_arg); + return MALA_CONTINUE; +} + +static void +mala_stringlist_macrocheck (MalaStringList list, int * max_arg, mala_state argt[10]) +{ + LLIST_FOREACH (&list->node, itr) + { + MalaStringList l = LLIST_TO_STRUCTP(itr, mala_stringlist, node); + mala_string_macrocheck (mala_stringlist_string (l), max_arg, argt); + if (*max_arg == INT_MAX) + return; + } +} + +static void +mala_string_macrocheck (MalaString string, int * max_arg, mala_state argt[10]) +{ + const char * c; + for (c = mala_string_cstr (string); *c; ++c) + { + if (*c == '%') + { + ++c; + if (*c == '%') + continue; + if (*c == '-') { - if (*c == '%') + ++c; + if (*c >= '0' && *c <= '9') { - ++c; - if (*c == '%') - { - // %% -> % - goto normal_char; - } - else if (*c >= '0' && *c <= '9') - { - // %0..%9 - if (size <= i+mala_string_length (args[*c-'0']) - && !(size = reserve_string (&p, - size, - 1 + i + mala_string_length (args[*c-'0'])))) - goto ealloc; - strcpy(p+i, mala_string_cstr (args[*c-'0'])); - i += (mala_string_length (args[*c-'0']) - 1); - } - else if (*c == '-') - { - ++c; - if (*c >= '0' && *c <= '9') - { - // %0..%9 - if (size <= i+mala_string_length (args[*c-'0']) - && !(size = reserve_string (&p, - size, - 1 + i + - mala_string_length (args[*c-'0'])))) - goto ealloc; - strcpy(p+i, mala_string_cstr (args[*c-'0'])); - i += (mala_string_length (args[*c-'0']) - 1); - } - } + if (argt[*c - '0'] < MALA_REMOVE && argt[*c - '0'] != MALA_START) + goto esyntax; + if (*c > (char) *max_arg + '0') + *max_arg = *c - '0'; + argt[*c - '0'] = MALA_START; } else - { - normal_char: - // normal char - if (size <= (size_t) i && !(size = reserve_string (&p, size, (size_t) i+1))) - goto ealloc; - p[i] = *c; - } + goto esyntax; } + else if (*c >= '0' && *c <= '9') + { + if (argt[*c - '0'] != MALA_REMOVE && argt[*c - '0'] != MALA_LITERAL) + goto esyntax; + if (*c > (char) *max_arg + '0') + *max_arg = *c - '0'; + argt[*c - '0'] = MALA_LITERAL; + } + else + goto esyntax; + } + } + return; - p[i] = '\0'; - - char* ptmp; - if (!(ptmp = realloc (p, size))) - goto ealloc; + esyntax: + *max_arg = INT_MAX; + return; +} - str = mala_string_new_attach_cstr (ptmp, &eng->words, NULL /*TODO refs*/); // TODO review - - if (!mala_stringlist_tail_new (list, str)) - goto ealloc; - // TODO review mala_string_free (str); +static MalaString +mala_string_new_macrosubst (MalaString src, MalaString args[10], MalaEngine eng) +{ + // 1st pass get size + size_t size = mala_string_length (src); + for (const char *c = mala_string_cstr (src); *c; ++c) + { + if (*c == '%') + { + ++c; + --size; + if (*c == '%') + continue; + if (*c == '-') + { + ++c; + --size; + } + --size; + TODO ("Handle %%-0"); + size += mala_string_length (args[*c - '0']); } + } - if (!mala_stringlist_tail_new (list, eng->common_string[MALA_STRING_END])) - goto ealloc; + // 2nd pass create string + char* cstr = NULL; + acogc_alloc (&cstr, size+1, &eng->gcroot); - // insert list - for (itr = mala_stringlist_tail (list); - !mala_stringlist_is_end (list, itr); - mala_stringlistnode_rev (&itr)) + char* p = cstr; + + for (const char *c = mala_string_cstr (src); *c; ++c) + { + if (*c == '%') { - // if (!mala_stringlist_after_new (&eng->program, last, - // mala_stringlistnode_string (itr))) - // goto ealloc; + ++c; + if (*c == '%') + { + *p++ = *c; + continue; + } + if (*c == '-') + ++c; + + TODO ("Handle %%-0"); + + strcpy (p, mala_string_cstr (args[*c - '0'])); + p += mala_string_length (args[*c - '0']); } + else + *p++ = *c; + } + *p = '\0'; - // cleanup - mala_stringlist_free (list); + return mala_string_new_attach_cstr (cstr, eng->words); +} +static MalaStringList +mala_stringlist_new_macrosubst (MalaStringList src, MalaString args[10], MalaEngine eng) +{ + ACOGC_STACK_ENTER (&eng->gcroot); + ACOGC_STACK_PTR (MalaStringList, ret); + + ret.ptr = mala_stringlist_new (eng); + + LLIST_FOREACH (&src->node, node) + { + ACOGC_STACK_PTR (MalaString, str); + str.ptr = mala_string_new_macrosubst (mala_stringlist_string_from_llist(node), args, eng); + MalaStringList n = mala_stringlist_node_new (str.ptr, eng); + mala_stringlist_insert_tail (ret.ptr, n); } - MALA_SIDEEFFECT_END; - mala_engine_command_done (eng, pptr, max_arg); -#endif - return MALA_CONTINUE; + ACOGC_STACK_LEAVE; + return ret.ptr; } + int -mala_begin_parser (MalaProgram prg, void * data) +mala_begin_parser (MalaProgram prg) { (void) prg; - (void) data; #if 0 // TODO --PROGRAM - MalaStringListNode itr; - MalaStringListNode end; + MalaStringList itr; + MalaStringList end; //MalaStringList list; unsigned depth = 1; MalaString name = NULL; @@ -289,14 +373,14 @@ mala_begin_parser (MalaProgram prg, void * data) // eng->common_string[MALA_STRING_ERROR_MISSING_END]); // find matching --END - for (end = mala_stringlistnode_next (mala_program_pos (prg)); + for (end = mala_stringlist_next (mala_program_pos (prg)); !mala_stringlist_is_end (&eng->program, end); - mala_stringlistnode_fwd (&end)) + mala_stringlist_fwd (&end)) { - //TODO if (mala_string_same(mala_stringlistnode_string (end), + //TODO if (mala_string_same(mala_stringlist_string (end), // eng->common_string[MALA_STRING_BEGIN])) // ++depth; - //else if (mala_string_same(mala_stringlistnode_string (end), + //else if (mala_string_same(mala_stringlist_string (end), // eng->common_string[MALA_STRING_END])) // --depth; if (!depth) @@ -304,18 +388,18 @@ mala_begin_parser (MalaProgram prg, void * data) } if (depth) - return mala_engine_exception (eng, pptr, mala_stringlistnode_prev (end), + return mala_engine_exception (eng, pptr, mala_stringlist_prev (end), eng->common_string[MALA_STRING_ERROR_MISSING_END]); - MALA_SIDEEFFECT_BEGIN + MALA_MUTATOR_BEGIN { //list = mala_stringlist_new (); //if (!list) // return MALA_EALLOC; // copy the block content to list - for (itr = mala_stringlistnode_next (mala_program_pos (prg)); itr != end; mala_stringlistnode_fwd (&itr)) - if (!mala_stringlist_tail_new (list, mala_stringlistnode_string (itr))) + for (itr = mala_stringlist_next (mala_program_pos (prg)); itr != end; mala_stringlist_fwd (&itr)) + if (!mala_stringlist_tail_new (list, mala_stringlist_string (itr))) goto ealloc_node; const char* templ; @@ -369,7 +453,7 @@ mala_begin_parser (MalaProgram prg, void * data) // eng->common_string[MALA_STRING_PASS])) // goto ealloc_pass; } - MALA_SIDEEFFECT_END; + MALA_MUTATOR_END; // and remove definition //TODO --PROGRAM while (mala_program_pos (prg) != end) @@ -388,34 +472,34 @@ int mala_block_parser (MalaProgram prg, void * data) { - MalaStringListNode itr; - MalaStringListNode end; + MalaStringList itr; + MalaStringList end; - MALA_SIDEEFFECT_BEGIN + MALA_MUTATOR_BEGIN { - end = mala_stringlistnode_next (mala_program_pos (prg)); + end = mala_stringlist_next (mala_program_pos (prg)); for (itr = mala_stringlist_tail ((MalaStringList) data); !mala_stringlist_is_end ((MalaStringList) data, itr); - mala_stringlistnode_rev (&itr)) + mala_stringlist_rev (&itr)) { #if 0 // TODO --PROGRAM if (!mala_stringlist_after_new (&eng->program, mala_program_pos (prg), - mala_stringlistnode_string (itr))) + mala_stringlist_string (itr))) goto ealloc_node; #endif } } - MALA_SIDEEFFECT_END; + MALA_MUTATOR_END; - mala_actiondesc_pop_delete (mala_stringlistnode_user_get (mala_program_pos (prg))); + mala_actiondesc_pop_delete (mala_stringlist_user_get (mala_program_pos (prg))); mala_engine_command_done (eng, pptr, 0); return MALA_CONTINUE; ealloc_node: /* remove already added things */ #if 0 - for (itr = mala_stringlistnode_next (mala_program_pos (prg)); + for (itr = mala_stringlist_next (mala_program_pos (prg)); itr != end; mala_stringlist_elem_delete_fwd (&eng->program, &itr)); #endif @@ -431,15 +515,15 @@ mala_macrodelete_parser (MalaProgram prg, void * data) mala_engine_arg_eval (eng, pptr, 1, -1, NULL, NULL); - MALA_SIDEEFFECT_BEGIN + MALA_MUTATOR_BEGIN { if (mala_stringlist_is_tail (&eng->program, mala_program_pos (prg))) return mala_engine_exception (eng, pptr, mala_program_pos (prg), eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]); - mala_actiondesc_pop_delete (mala_stringlistnode_user_get (mala_stringlistnode_next (mala_program_pos (prg)))); + mala_actiondesc_pop_delete (mala_stringlist_user_get (mala_stringlist_next (mala_program_pos (prg)))); } - MALA_SIDEEFFECT_END; + MALA_MUTATOR_END; mala_engine_command_done (eng, pptr, 1); return MALA_SUCCESS; @@ -447,24 +531,22 @@ mala_macrodelete_parser (MalaProgram prg, void * data) #endif // old macrodelete int -mala_delete_parser (MalaProgram prg, void * data) +mala_delete_parser (MalaProgram prg) { - (void) data; - //mala_engine_arg_eval (eng, pptr, 1, MALA_LITERAL); - MALA_SIDEEFFECT_BEGIN + MALA_MUTATOR_BEGIN { #if 0 // TODO --PROGRAM if (mala_stringlist_is_tail (&eng->program, mala_program_pos (prg))) return mala_engine_exception (eng, pptr, mala_program_pos (prg), eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]); #endif - // TODO mala_actiondesc_pop_delete (mala_stringlistnode_user_get (mala_stringlistnode_next (mala_program_pos (prg)))); + // TODO mala_actiondesc_pop_delete (mala_stringlist_user_get (mala_stringlist_next (mala_program_pos (prg)))); } - MALA_SIDEEFFECT_END; + MALA_MUTATOR_END; - mala_program_action_done (prg, 1); + // mala_program_action_done (prg, 1); return MALA_SUCCESS; } @@ -481,71 +563,7 @@ mala_end_parser (MalaProgram prg, } #endif -#if 0 -static void -mala_macrocheck_list (MalaStringList list, int * max_arg, int argt[10]) -{ - MalaStringListNode itr; - for (itr = mala_stringlist_head (list); - !mala_stringlist_is_end (list, itr); - mala_stringlistnode_fwd (&itr)) - { - mala_macrocheck_string (mala_stringlistnode_string (itr), max_arg, argt); - if (*max_arg == -1) - return; - } -} -static void -mala_macrocheck_string (MalaString string, int * max_arg, int argt[10]) -{ - const char * c; - for (c = mala_string_cstr (string); *c; ++c) - { - // "foo%1%-2" - if (*c == '%') - { - // % - ++c; - if (*c == '%') - // %% - continue; - if (*c == '-') - { - // %- - ++c; - if (*c >= '0' && *c <= '9') - { - // %-0 .. %-9 - if (argt[*c - '0'] == 1) - goto esyntax; - if (*c > (char) *max_arg + '0') - *max_arg = *c - '0'; - argt[*c - '0'] = -1; - } - else - goto esyntax; - } - else if (*c >= '0' && *c <= '9') - { - // %0 .. %9 - if (argt[*c - '0'] == -1) - goto esyntax; - if (*c > (char) *max_arg + '0') - *max_arg = *c - '0'; - argt[*c - '0'] = 1; - } - else - goto esyntax; - } - } - return; - - esyntax: - *max_arg = -1; - return; -} -#endif #if 0 // old macrodef parser int @@ -553,8 +571,8 @@ mala_macrodef_parser (MalaProgram prg, void * data) { int i; - MalaStringListNode itr; - MalaStringListNode arg[2]; + MalaStringList itr; + MalaStringList arg[2]; MalaString name; MalaAction act; @@ -566,10 +584,10 @@ mala_macrodef_parser (MalaProgram prg, if (!mala_engine_arg_eval (eng, pptr, 2, -1, NULL, mala_block_parser)) return eng->state; - MALA_SIDEEFFECT_BEGIN + MALA_MUTATOR_BEGIN { // test if 2 arguments left and assign them to arg[], else error - for (i = 0, itr = mala_program_pos (prg); i<2; ++i, mala_stringlistnode_fwd(&itr)) + for (i = 0, itr = mala_program_pos (prg); i<2; ++i, mala_stringlist_fwd(&itr)) { #if 0 // TODO --PROGRAM if (mala_stringlist_is_tail (&eng->program, itr)) @@ -577,18 +595,18 @@ mala_macrodef_parser (MalaProgram prg, eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]); #endif - arg[i] = mala_stringlistnode_next (itr); + arg[i] = mala_stringlist_next (itr); } // if name is a block then error - name = mala_stringlistnode_string (arg[0]); + name = mala_stringlist_string (arg[0]); act = mala_actiondesc_top ((MalaActionDesc) mala_string_user_get (name)); if (act && act->parser == mala_block_parser) return mala_engine_exception (eng, pptr, arg[0], eng->common_string[MALA_STRING_ERROR_BLOCK_NOT_ALLOWED]); //expansion check and optimize block - act = mala_actiondesc_top ((MalaActionDesc) mala_stringlistnode_user_get (arg[1])); + act = mala_actiondesc_top ((MalaActionDesc) mala_stringlist_user_get (arg[1])); if (act && act->factory == (MalaDataFactory) mala_stringlist_factory) { int max_arg = 0; @@ -603,7 +621,7 @@ mala_macrodef_parser (MalaProgram prg, if (!desc) return MALA_EALLOC; - act = mala_actiondesc_pop ((MalaActionDesc) mala_stringlistnode_user_get (arg[1])); + act = mala_actiondesc_pop ((MalaActionDesc) mala_stringlist_user_get (arg[1])); act->name = name; act->parser = mala_macro_parser; mala_actiondesc_push_action (desc, act); @@ -630,7 +648,7 @@ mala_macrodef_parser (MalaProgram prg, if (!desc) return MALA_EALLOC; - act = mala_actiondesc_pop ((MalaActionDesc) mala_stringlistnode_user_get (arg[1])); + act = mala_actiondesc_pop ((MalaActionDesc) mala_stringlist_user_get (arg[1])); act->name = name; act->parser = mala_expand_parser; mala_actiondesc_push_action (desc, act); @@ -644,12 +662,12 @@ mala_macrodef_parser (MalaProgram prg, // single word int max_arg = 0; int argt[10] = {0}; - mala_macrocheck_string (mala_stringlistnode_string (arg[1]), &max_arg, argt); + mala_macrocheck_string (mala_stringlist_string (arg[1]), &max_arg, argt); if (max_arg == 0) { // substitute if (MALA_SUCCESS != mala_engine_add_action (eng, name, - mala_stringlistnode_string_copy (arg[1]), + mala_stringlist_string_copy (arg[1]), mala_substitute_parser, (MalaDataFactory) mala_string_factory, NULL)) @@ -664,7 +682,7 @@ mala_macrodef_parser (MalaProgram prg, if (!list) return MALA_EALLOC; - mala_stringlist_tail_new (list, mala_stringlistnode_string (arg[1])); + mala_stringlist_tail_new (list, mala_stringlist_string (arg[1])); if (MALA_SUCCESS != mala_engine_add_action (eng, name, list, mala_macro_parser, @@ -677,7 +695,7 @@ mala_macrodef_parser (MalaProgram prg, eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]); } } - MALA_SIDEEFFECT_END; + MALA_MUTATOR_END; mala_engine_command_done (eng, pptr, 2); return MALA_SUCCESS; @@ -689,8 +707,8 @@ int mala_def_parser (MalaProgram prg, void * data) { - MalaStringListNode dest; - MalaStringListNode subst; + MalaStringList dest; + MalaStringList subst; MalaString str; MalaStringList list; @@ -710,19 +728,19 @@ mala_def_parser (MalaProgram prg, info bei HELP/RESULT_TYPE ob was ein PREDICATE, EXPANSION, LITERAL oder BLOCK ist */ - MALA_SIDEEFFECT_BEGIN + MALA_MUTATOR_BEGIN { int max_arg = 0; int argt[10] = {0}; - mala_macrocheck_string (mala_stringlistnode_string (subst), &max_arg, argt); + mala_macrocheck_string (mala_stringlist_string (subst), &max_arg, argt); if (max_arg == 0) { // substitute - str = NULL; // TODO mala_stringlistnode_string_copy (subst); + str = NULL; // TODO mala_stringlist_string_copy (subst); #if 0 // TODO if (MALA_SUCCESS != mala_engine_add_action (eng, - mala_stringlistnode_string (dest), + mala_stringlist_string (dest), str, mala_substitute_parser, NULL, //TODO (MalaDataFactory) mala_string_factory, @@ -738,12 +756,12 @@ info bei HELP/RESULT_TYPE ob was ein PREDICATE, EXPANSION, LITERAL oder BLOCK is if (!list) goto ealloc_list; - if (! mala_stringlist_tail_new (list, mala_stringlistnode_string (subst))) + if (! mala_stringlist_tail_new (list, mala_stringlist_string (subst))) goto ealloc_tail; #if 0 // TODO if (MALA_SUCCESS != mala_engine_add_action (eng, - mala_stringlistnode_string (dest), + mala_stringlist_string (dest), list, mala_macro_parser, NULL, NULL /*TODO refs*/)) @@ -754,7 +772,7 @@ info bei HELP/RESULT_TYPE ob was ein PREDICATE, EXPANSION, LITERAL oder BLOCK is return mala_engine_exception (eng, pptr, subst, eng->common_string[MALA_STRING_ERROR_PARAMETER_SYNTAX]); } - MALA_SIDEEFFECT_END; + MALA_MUTATOR_END; mala_engine_command_done (eng, pptr, 2); return MALA_CONTINUE; @@ -797,9 +815,12 @@ reserve_string (char ** s, size_t actual, size_t needed) } #endif +NOBUG_DEFINE_FLAG (mala_module_std_macros); + int mala_module_std_macros_init (MalaEngine self) { + NOBUG_INIT_FLAG (mala_module_std_macros); return mala_engine_actions_register (self, std_macros); } diff --git a/std/std_macros.h b/std/std_macros.h index c18851f..5bced68 100644 --- a/std/std_macros.h +++ b/std/std_macros.h @@ -35,6 +35,8 @@ MALA_PARSER_DEFINE(delete); //MALA_PARSER_DEFINE(end); //MALA_PARSER_DEFINE(def); +NOBUG_DECLARE_FLAG (mala_module_std_macros); + int mala_module_std_macros_init (MalaEngine self); -- 2.11.4.GIT