1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Values;                            use Values; 
  10.  
  11. private with Ada.Unchecked_Deallocation; 
  12.  
  13. package Scripting is 
  14.  
  15.     type Value_Array is array (Integer range <>) of Value_Ptr; 
  16.  
  17.     type Eval_Context is tagged private; 
  18.     type A_Eval_Context is access all Eval_Context'Class; 
  19.  
  20.     ---------------------------------------------------------------------------- 
  21.  
  22.     -- An Evaluation_Node is capable of evaluating variables and functions as 
  23.     -- part of scripting evaluation. 
  24.     type Evaluation_Node is interface; 
  25.     type A_Evaluation_Node is access all Evaluation_Node'Class; 
  26.  
  27.     -- Evaluates the function 'name' given 'arguments', returning a value as a 
  28.     -- result, null if the function could not be found, or raising an exception 
  29.     -- on error while evaluating the function. 
  30.     function Evaluate_Function( this      : access Evaluation_Node; 
  31.                                 name      : String; 
  32.                                 arguments : Value_Array ) return Value_Ptr is abstract; 
  33.  
  34.     -- Evaluates the symbol named 'symbol' by resolving its value and returning 
  35.     -- the result. null will be returned if the symbol can't be resolved. 
  36.     function Evaluate_Symbol( this   : access Evaluation_Node; 
  37.                               symbol : String ) return Value_Ptr is abstract; 
  38.  
  39.     -- Raised when script evaluation fails 
  40.     Evaluation_Exception : exception; 
  41.  
  42. private 
  43.  
  44.     type Eval_Context is tagged 
  45.         record 
  46.             evalNode : A_Evaluation_Node; 
  47.         end record; 
  48.  
  49.     -- Creates a new Eval_Context using 'evalNode' to evaluate all symbols and 
  50.     -- functions. 
  51.     function Create_Eval_Context( evalNode : A_Evaluation_Node ) return A_Eval_Context; 
  52.     pragma Postcondition( Create_Eval_Context'Result /= null ); 
  53.  
  54.     -- Evaluates function 'name' with arguments, returning the result. Null will 
  55.     -- be returned if the function can't be found. An exception will be raised 
  56.     -- on evaluation error. 
  57.     function Evaluate_Function( this      : access Eval_Context; 
  58.                                 name      : String; 
  59.                                 arguments : Value_Array ) return Value_Ptr; 
  60.  
  61.     -- Evaluates symbol name 'symbol', resolving its value and returning the 
  62.     -- result. Null will be  returned if the symbol can't be resolved. 
  63.     function Evaluate_Symbol( this : access Eval_Context; symbol : String ) return Value_Ptr; 
  64.  
  65.     -- Deletes the Eval_Context object. 
  66.     procedure Delete is new Ada.Unchecked_Deallocation( Eval_Context'Class, A_Eval_Context ); 
  67.  
  68. end Scripting;