]> Nishi Git Mirror - serenade.git/commitdiff
discard op
authornishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Wed, 8 May 2024 03:12:03 +0000 (03:12 +0000)
committernishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Wed, 8 May 2024 03:12:03 +0000 (03:12 +0000)
git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@132 0f02c867-ac3d-714e-8a88-971ba1f6efcf

Serenade/interpreter.c
Serenade/parser.c
Serenade/parser.h
Serenade/run.c

index ef8d8c6ccc8ba97e1d1e39c3924122ccad8249e8..aaf981b8587ccb699aa03e7617eb8e09ca670be3 100644 (file)
@@ -293,6 +293,7 @@ do_again:
 }
 
 struct sn_interpreter_kv* sn_set_variable(struct sn_interpreter* sn, const char* name, struct sn_generic* gen) {
+       if(gen != NULL) gen->reference = true;
        int i;
        bool replaced = false;
        bool global = true;
index 61591ff94ca90864c9c336ddf0581d40ca2d3fff..b61ed0823aef721fec20f96c23e5fd3385b01848 100644 (file)
@@ -123,6 +123,7 @@ struct sn_generic* sn_expr_parse(char* data, unsigned long long size) {
                        argbufmode = SN_TYPE_STRING;
                } else if(c == '(') {
                        gn_stack[br] = malloc(sizeof(struct sn_generic));
+                       gn_stack[br]->reference = false;
                        gn_stack[br]->type = SN_TYPE_TREE;
                        gn_stack[br]->tree = malloc(sizeof(struct sn_tree));
                        gn_stack[br]->tree->args = malloc(sizeof(struct sn_generic*));
@@ -316,7 +317,7 @@ void sn_tree_free(struct sn_interpreter* sn, struct sn_tree* t) {
        if(t->args != NULL) {
                int i;
                for(i = 0; t->args[i] != NULL; i++) {
-                       sn_generic_free(sn, t->args[i]);
+                       if(!t->args[i]->reference) sn_generic_free(sn, t->args[i]);
                }
                free(t->args);
        }
index 7bd91019785b2d39198424991ed07ca8a75b7796..069db0026fff10d2f4ae779133bb03ae7851d175 100644 (file)
@@ -50,6 +50,7 @@ struct sn_generic {
        struct sn_tree* tree;
        bool used;
        void* argvalue;
+       bool reference;
        struct sn_generic* (*handler)(struct sn_interpreter* sn, int, struct sn_generic**);
 };
 
index a32031e3bcb1bb740471314742892883253b0096..818a053b851b906c2911ac6dd543a3d74944d83b 100644 (file)
@@ -187,6 +187,13 @@ struct sn_generic* _sn_run(struct sn_interpreter* sn, struct sn_generic* gen) {
                                        sn->local_variables = old_kv;
                                }
                                return r;
+                       } else if(strcmp(op->name, "discard") == 0) {
+                               r->type = SN_TYPE_VOID;
+                               int i;
+                               for(i = 1; gen->tree->args[i] != NULL; i++){
+                                       sn_generic_free(sn, _sn_run(sn, gen->tree->args[i]));
+                               }
+                               return r;
                        }
                        bool called = false;
                        int j;
@@ -272,5 +279,6 @@ int sn_run(struct sn_interpreter* sn, struct sn_generic* gen) {
                sn_print_to(stdout, rgen);
                printf("\n");
        }
+       if(rgen->type == SN_TYPE_VOID) free(rgen);
        return 0;
 }