Back to index

texmacs  1.0.7.15
Classes | Functions | Variables
evaluate_rewrite.cpp File Reference
#include "evaluate_main.hpp"
#include "memorizer.hpp"
#include "std_environment.hpp"
#include "vars.hpp"
#include "scheme.hpp"

Go to the source code of this file.

Classes

class  rewrite_memorizer_rep

Functions

memorizer rewrite_memorizer (environment env, tree t)
tree texmacs_evaluate (environment env, tree t)
tree rewrite_impl (tree t)
tree rewrite (tree t)
tree evaluate_rewrite (tree t)

Variables

int script_status
static tree no_tree (UNINIT)
static environment reenter_rewrite_env

Function Documentation

Definition at line 202 of file evaluate_rewrite.cpp.

                          {
  return evaluate (rewrite (t));
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree rewrite ( tree  t)

Definition at line 180 of file evaluate_rewrite.cpp.

                 {
  cout << "Rewrite "
    //<< "[" << (t.operator -> ())
    //<< ", " << (std_env.operator -> ()) << "] "
       << t << INDENT << LF;
  memorizer mem= rewrite_memorizer (std_env, t);
  if (is_memorized (mem)) {
    cout << UNINDENT << "Memorized " << mem->get_tree () << LF;
    std_env= mem->get_environment ();
    return mem->get_tree ();
  }
  memorize_start ();
  tree r= rewrite_impl (t);
  decorate_ip (t, r);
  mem->set_tree (r);
  mem->set_environment (std_env);
  memorize_end ();
  cout << UNINDENT << "Rewritten as " << mem->get_tree () << LF;
  return mem->get_tree ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 80 of file evaluate_rewrite.cpp.

                      {
  switch (L(t)) {
  case EXTERN:
    {
      int i, n= N(t);
      tree r (TUPLE, n);
      for (i=0; i<n; i++)
       r[i]= evaluate (t[i]);
      object expr= null_object ();
      for (i=n-1; i>0; i--)
       expr= cons (object (r[i]), expr);
      string fun= evaluate_string (t[0]);
      expr= cons (string_to_object (fun), expr);
      bool secure= as_bool (std_env ["secure"]);
      if (!secure && script_status < 2) {
       if (!as_bool (call ("secure?", expr)))
         return tree (ERROR, "insecure script");
      }
      environment old_env= reenter_rewrite_env;
      reenter_rewrite_env= std_env;
      object o= eval (expr);
      reenter_rewrite_env= old_env;
      return content_to_tree (o);
    }
#ifdef CLASSICAL_MACRO_EXPANSION
  case MAP_ARGS:
    {
      if (!(is_atomic (t[0]) && is_atomic (t[1]) && is_atomic (t[2])))
       return evaluate_error ("invalid map-args");
      if (macro_top_level (std_env))
       return evaluate_error ("undefined", t[2]);
      basic_environment local= macro_arguments (std_env);
      int key= make_tree_label (t[2]->label);
      if (!local->contains (key))
       return evaluate_error ("undefined", t[2]);
      tree v= local [key];
      if (is_atomic (v))
       return evaluate_error ("invalid-map-args");
      macro_up (std_env);

      int start= 0, end= N(v);
      if (N(t)>=4) start= as_int (evaluate (t[3]));
      if (N(t)>=5) end  = as_int (evaluate (t[4]));
      int i, n= max (0, end-start);
      tree r (make_tree_label (t[1]->label), n);
      for (i=0; i<n; i++)
       r[i]= tree (make_tree_label (t[0]->label),
                  tree (ARG, copy (t[2]), as_string (start+i)),
                  as_string (start+i));

      macro_redown (std_env, local);
      return r;
    }
#endif // CLASSICAL_MACRO_EXPANSION
  case INCLUDE:
    {
      url base_file_name (as_string (std_env ["base-file-name"]));
      url file_name= url_system (evaluate_string (t[0]));
      return load_inclusion (relative (base_file_name, file_name));
    }
  case REWRITE_INACTIVE:
    {
#ifdef CLASSICAL_MACRO_EXPANSION      
      if ((!is_func (t[0], ARG)) || is_compound (t[0][0]))
       return evaluate_error ("invalid rewrite-inactive");
      if (macro_top_level (std_env))
       return evaluate_error ("undefined", t[0][0]);
      basic_environment local= macro_arguments (std_env);
      int key= make_tree_label (t[0][0]->label);
      if (!local->contains (key))
       return evaluate_error ("undefined", t[0][0]);
      tree val= local [key];
      int i, n= N(t[0]);
      for (i=1; i<n; i++) {
       int j= as_int (t[0][i]);
       if ((j>=0) && (j<N(val))) val= val[j];
       else return evaluate_error ("invalid rewrite-inactive");
      }
#else
      tree val= t[0];
#endif
      int inactive_mode= INACTIVE_INLINE_RECURSE;
      if (t[1] == "recurse") inactive_mode= INACTIVE_INLINE_RECURSE;
      else if (t[1] == "recurse*") inactive_mode= INACTIVE_BLOCK_RECURSE;
      else if (t[1] == "once") inactive_mode= INACTIVE_INLINE_ONCE;
      else if (t[1] == "once*") inactive_mode= INACTIVE_BLOCK_ONCE;
      else if (t[1] == "error") inactive_mode= INACTIVE_INLINE_ERROR;
      else if (t[1] == "error*") inactive_mode= INACTIVE_BLOCK_ERROR;
      return rewrite_inactive (val, inactive_mode);
    }
  default:
    return t;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

memorizer rewrite_memorizer ( environment  env,
tree  t 
) [inline]

Definition at line 52 of file evaluate_rewrite.cpp.

                                            {
  return (memorizer_rep*) tm_new<rewrite_memorizer_rep> (env, t);
}

Here is the caller graph for this function:

Definition at line 65 of file evaluate_rewrite.cpp.

                                           {
  // re-entrancy
  if (!is_nil (reenter_rewrite_env)) env= reenter_rewrite_env;
  environment old_env= std_env;
  std_env= env;
  tree r= evaluate (t);
  std_env= old_env;
  return r;
}

Here is the call graph for this function:


Variable Documentation

tree no_tree(UNINIT) [static]

Definition at line 62 of file evaluate_rewrite.cpp.

Definition at line 25 of file sys_utils.cpp.