--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
with Values; use Values;
private with Ada.Unchecked_Deallocation;
package Scripting is
type Value_Array is array (Integer range <>) of Value_Ptr;
type Eval_Context is tagged private;
type A_Eval_Context is access all Eval_Context'Class;
----------------------------------------------------------------------------
-- An Evaluation_Node is capable of evaluating variables and functions as
-- part of scripting evaluation.
type Evaluation_Node is interface;
type A_Evaluation_Node is access all Evaluation_Node'Class;
-- Evaluates the function 'name' given 'arguments', returning a value as a
-- result, null if the function could not be found, or raising an exception
-- on error while evaluating the function.
function Evaluate_Function( this : access Evaluation_Node;
name : String;
arguments : Value_Array ) return Value_Ptr is abstract;
-- Evaluates the symbol named 'symbol' by resolving its value and returning
-- the result. null will be returned if the symbol can't be resolved.
function Evaluate_Symbol( this : access Evaluation_Node;
symbol : String ) return Value_Ptr is abstract;
-- Raised when script evaluation fails
Evaluation_Exception : exception;
private
type Eval_Context is tagged
record
evalNode : A_Evaluation_Node;
end record;
-- Creates a new Eval_Context using 'evalNode' to evaluate all symbols and
-- functions.
function Create_Eval_Context( evalNode : A_Evaluation_Node ) return A_Eval_Context;
pragma Postcondition( Create_Eval_Context'Result /= null );
-- Evaluates function 'name' with arguments, returning the result. Null will
-- be returned if the function can't be found. An exception will be raised
-- on evaluation error.
function Evaluate_Function( this : access Eval_Context;
name : String;
arguments : Value_Array ) return Value_Ptr;
-- Evaluates symbol name 'symbol', resolving its value and returning the
-- result. Null will be returned if the symbol can't be resolved.
function Evaluate_Symbol( this : access Eval_Context; symbol : String ) return Value_Ptr;
-- Deletes the Eval_Context object.
procedure Delete is new Ada.Unchecked_Deallocation( Eval_Context'Class, A_Eval_Context );
end Scripting;