]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Move function definitions from operations to expressions
authorCharlie Brej <cbrej@cs.man.ac.uk>
Tue, 1 Sep 2009 19:25:38 +0000 (20:25 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Tue, 1 Sep 2009 19:32:05 +0000 (20:32 +0100)
This removes some of the duplication due to the two methods of creating
functions. Now function definitions like:

fun name (foo) {bar}

are treated as

name = fun (foo) {bar};

No script code needs to change as both are still valid.

src/plugins/splash/script/script-execute.c
src/plugins/splash/script/script-parse.c
src/plugins/splash/script/script.h

index 66cc678312bc14e35a76f1a8fee6aed0bd051868..37a027a5492ccfc914c982e492dc0b64f01b4416 100644 (file)
@@ -621,16 +621,6 @@ script_return_t script_execute (script_state_t *state,
           break;
         }
 
-      case SCRIPT_OP_TYPE_FUNCTION_DEF:
-        {
-          script_obj_t *obj = script_evaluate (state, op->data.function_def.name);
-          script_obj_t *function_obj = script_obj_new_function(op->data.function_def.function);
-          script_obj_assign (obj, function_obj);
-          script_obj_unref (function_obj);
-          script_obj_unref (obj);
-          break;
-        }
-
       case SCRIPT_OP_TYPE_RETURN:
         {
           script_obj_t *obj;
index ef9a79d584851e196cc6884f394b92724d7b332e..ec8c665cf8caebd12b5cbab7f2634df6b11b2921 100644 (file)
@@ -666,6 +666,7 @@ static script_op_t *script_parse_function (script_scan_t *scan)
   script_scan_token_t *curtoken = script_scan_get_current_token (scan);
 
   if (!script_scan_token_is_identifier_of_value (curtoken, "fun")) return NULL;
+  script_debug_location_t location = curtoken->location;
   curtoken = script_scan_get_next_token (scan);
   if (!script_scan_token_is_identifier (curtoken))
     {
@@ -679,11 +680,10 @@ static script_op_t *script_parse_function (script_scan_t *scan)
 
   script_function_t *function = script_parse_function_def (scan);
   if (!function) return NULL;
-  
-  script_op_t *op = malloc (sizeof (script_op_t));
-  op->type = SCRIPT_OP_TYPE_FUNCTION_DEF;
-  op->data.function_def.name = name;
-  op->data.function_def.function = function;
+  script_exp_t *func_exp = script_parse_new_exp_function_def (function, &location);
+  script_exp_t *func_def = script_parse_new_exp_dual (SCRIPT_EXP_TYPE_ASSIGN, name, func_exp, &location);
+    
+  script_op_t *op = script_parse_new_op_exp (func_def, &location);
   return op;
 }
 
@@ -882,24 +882,6 @@ void script_parse_op_free (script_op_t *op)
           break;
         }
 
-      case SCRIPT_OP_TYPE_FUNCTION_DEF:
-        {
-          if (op->data.function_def.function->type == SCRIPT_FUNCTION_TYPE_SCRIPT)
-            script_parse_op_free (op->data.function_def.function->data.script);
-          ply_list_node_t *node;
-          for (node = ply_list_get_first_node (op->data.function_def.function->parameters);
-               node;
-               node = ply_list_get_next_node (op->data.function_def.function->parameters, node))
-            {
-              char *arg = ply_list_node_get_data (node);
-              free (arg);
-            }
-          ply_list_free (op->data.function_def.function->parameters);
-          script_parse_exp_free (op->data.function_def.name);
-          free (op->data.function_def.function);
-          break;
-        }
-
       case SCRIPT_OP_TYPE_RETURN:
         {
           if (op->data.exp) script_parse_exp_free (op->data.exp);
index 96ad203bd1ecfe08042fc68c45396de07daffc23..342dab80b13f7acb7ffc52393ac0f165a187804c 100644 (file)
@@ -180,7 +180,6 @@ typedef enum
   SCRIPT_OP_TYPE_IF,
   SCRIPT_OP_TYPE_WHILE,
   SCRIPT_OP_TYPE_FOR,
-  SCRIPT_OP_TYPE_FUNCTION_DEF,
   SCRIPT_OP_TYPE_RETURN,
   SCRIPT_OP_TYPE_BREAK,
   SCRIPT_OP_TYPE_CONTINUE,
@@ -199,11 +198,6 @@ typedef struct script_op_t
       struct script_op_t *op1;
       struct script_op_t *op2;
     } cond_op;
-    struct
-    {
-      script_exp_t *name;
-      script_function_t *function;
-    } function_def;
   } data;
 } script_op_t;