From e0048d3862cad2f0e9d1a45a928495912c5d80da Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Fri, 19 Jan 2007 23:40:05 +0100 Subject: [PATCH] rework states --- engine/engine.c | 2 +- engine/mala_types.h | 9 +++++---- program/mala.c | 2 +- std/std_io.c | 4 ++-- std/std_macros.c | 22 +++++++++++----------- std/std_statements.c | 15 ++++++++++++++- std/std_statements.h | 1 + tests/20basic.tests | 11 ++++++++--- tests/30stdmodule.tests | 17 ++++++++++++----- 9 files changed, 55 insertions(+), 28 deletions(-) diff --git a/engine/engine.c b/engine/engine.c index 22caaca..46fa069 100644 --- a/engine/engine.c +++ b/engine/engine.c @@ -93,7 +93,7 @@ mala_engine_init (MalaEngine self) self->engine_trace = MALA_NOTRACE; self->blockcnt = 0; - self->state = MALA_CONTINUE; + self->state = MALA_SUCCESS; acogc_root_init (&self->gcroot); diff --git a/engine/mala_types.h b/engine/mala_types.h index 9b7f9ee..ba55d39 100644 --- a/engine/mala_types.h +++ b/engine/mala_types.h @@ -42,11 +42,12 @@ NOBUG_DECLARE_FLAG(mala_module_std); /* the first codes are the states of the MaLa VM and never returned from the engine*/ \ MALA_STATE(SUCCESS), /* final state / all succeeded */ \ MALA_STATE(LITERAL), /* don't evaluate argument */ \ - MALA_STATE(LIST), /* evaluated to a list */ \ - MALA_STATE(MACRO), /* evaluated to a macro */ \ - MALA_STATE(CONTINUE), /* command not fully evaluated yet, or removed itself */ \ + MALA_STATE(PREDICATE), /* evaluated to --TRUE or --FALSE only */ \ + MALA_STATE(MACRO), /* evaluated some new code */ \ + MALA_STATE(PROCEDURE), /* evaluated to nothing, but had some side-effect */ \ + MALA_STATE(BLOCK), /* block of code evaluated to a macro */ \ + MALA_STATE(REMOVE), /* tell a command to remove itself recursively */ \ MALA_STATE(START), /* start of the statemachine, nothing evaluated yet */ \ - MALA_STATE(REMOVE), /* no sideeffects remove including arguments */ \ MALA_STATE(EXCEPTION), /* some error occured (in MaLa code) */ \ \ MALA_STATE(EFAULT), /* beyond are runtime errors */ \ diff --git a/program/mala.c b/program/mala.c index 94fda27..2b91e2a 100644 --- a/program/mala.c +++ b/program/mala.c @@ -68,7 +68,7 @@ main(int argc, char * argv[]) // putc ('\n', stdout); // } mala_engine_free (my_engine); - return ret == MALA_CONTINUE ? 0 : ret; + return ret; // == MALA_SUCCESS ? 0 : ret; } diff --git a/std/std_io.c b/std/std_io.c index 7af6b14..6eae2d1 100644 --- a/std/std_io.c +++ b/std/std_io.c @@ -81,7 +81,7 @@ mala_newline_parser (MalaProgram prg) MALA_MUTATOR_END; mala_program_action_done (prg, 0); - return MALA_CONTINUE; + return MALA_PROCEDURE; } mala_state @@ -99,7 +99,7 @@ mala_print_parser (MalaProgram prg) MALA_MUTATOR_END; mala_program_action_done (prg, 1); - return MALA_CONTINUE; + return MALA_PROCEDURE; } diff --git a/std/std_macros.c b/std/std_macros.c index efa4eb0..1a76232 100644 --- a/std/std_macros.c +++ b/std/std_macros.c @@ -148,7 +148,7 @@ mala_begin_parser (MalaProgram prg) TODO ("direct --PASS substitute"); parser = mala_pass_parser; templ = "--BLOCK_%08X"; - ret = MALA_LIST; + ret = MALA_BLOCK; } else if (length == 1) { @@ -167,13 +167,13 @@ mala_begin_parser (MalaProgram prg) TODO ("direct name substitute"); parser = mala_substitute_parser; templ = "--BLOCK_%08X"; - ret = MALA_LIST; + ret = MALA_BLOCK; } else { parser = mala_macro_parser; templ = "--BLOCK_%08X"; - ret = MALA_MACRO; + ret = MALA_BLOCK; } } else @@ -191,13 +191,13 @@ mala_begin_parser (MalaProgram prg) { parser = mala_expand_parser; templ = "--BLOCK_%08X"; - ret = MALA_MACRO; + ret = MALA_BLOCK; } else { parser = mala_macro_parser; templ = "--BLOCK_%08X"; - ret = MALA_MACRO; + ret = MALA_BLOCK; } } @@ -230,7 +230,7 @@ mala_substitute_parser (MalaProgram prg) } MALA_MUTATOR_END; - return MALA_CONTINUE; + return MALA_MACRO; } mala_state @@ -256,7 +256,7 @@ mala_expand_parser (MalaProgram prg) MALA_MUTATOR_END; mala_program_action_done (prg, 0); - return MALA_CONTINUE; + return MALA_MACRO; } @@ -342,7 +342,7 @@ mala_macro_parser (MalaProgram prg) MALA_MUTATOR_END; mala_program_action_done (prg, max_arg); - return MALA_CONTINUE; + return MALA_MACRO; } mala_state @@ -364,7 +364,7 @@ mala_def_parser (MalaProgram prg) name = mala_stringlist_string (dst); - if (mala_program_eval_arg (prg, 2, MALA_MACRO, &dst) > MALA_EFAULT) + if (mala_program_eval_arg (prg, 2, MALA_BLOCK, &dst) > MALA_EFAULT) return mala_program_commonexception (prg, MALA_STRING_ERROR); expand = mala_stringlist_string (dst); @@ -388,7 +388,7 @@ mala_def_parser (MalaProgram prg) MALA_MUTATOR_END; mala_program_action_done (prg, 2); - return MALA_CONTINUE; + return MALA_PROCEDURE; } @@ -411,7 +411,7 @@ mala_delete_parser (MalaProgram prg) MALA_MUTATOR_END; mala_program_action_done (prg, 1); - return MALA_CONTINUE; + return MALA_PROCEDURE; } diff --git a/std/std_statements.c b/std/std_statements.c index d63c20e..1ebe66d 100644 --- a/std/std_statements.c +++ b/std/std_statements.c @@ -47,6 +47,8 @@ mala_actioninit std_statements[] = MALA_PARSER_SIMPLE("--GC", mala_gc_parser), + MALA_PARSER_SIMPLE("--REMOVE", mala_remove_parser), + /* MALA_PARSER("--", mala__parser, NULL, NULL, NULL), MALA_PARSER_BRIEF("--", ""), @@ -173,7 +175,18 @@ mala_gc_parser (MalaProgram prg) { acogc_root_collect (&prg->engine->gcroot, ACOGC_COLLECT_NORMAL); mala_program_action_done (prg, 0); - return MALA_CONTINUE; + return MALA_PROCEDURE; +} + + +mala_state +mala_remove_parser (MalaProgram prg) +{ + if (mala_program_eval_arg (prg, 1, MALA_REMOVE, NULL) > MALA_EFAULT) + return mala_program_commonexception (prg, MALA_STRING_ERROR); + + mala_program_action_done (prg, 0); + return MALA_PROCEDURE; } diff --git a/std/std_statements.h b/std/std_statements.h index d580f31..74481c7 100644 --- a/std/std_statements.h +++ b/std/std_statements.h @@ -25,6 +25,7 @@ MALA_PARSER_DEFINE(literal); MALA_PARSER_DEFINE(pass); MALA_PARSER_DEFINE(gc); +MALA_PARSER_DEFINE(remove); //MALA_PARSER_DEFINE(defined); //MALA_PARSER_DEFINE(not); //MALA_PARSER_DEFINE(ifelse); diff --git a/tests/20basic.tests b/tests/20basic.tests index 6803b13..6782f33 100644 --- a/tests/20basic.tests +++ b/tests/20basic.tests @@ -5,38 +5,43 @@ TESTING "basic tests:" ./test-mala_nopp TEST "no args" <