Back to index

texmacs  1.0.7.15
evaluate_quote.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : evaluate_quote.cpp
00004 * DESCRIPTION: quoting and evaluation primitives
00005 * COPYRIGHT  : (C) 2006  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "evaluate_main.hpp"
00013 #include "std_environment.hpp"
00014 
00015 /******************************************************************************
00016 * The eval-args primitive
00017 ******************************************************************************/
00018 
00019 tree
00020 evaluate_eval_args (tree t) {
00021 #ifdef CLASSICAL_MACRO_EXPANSION
00022   if (macro_top_level (std_env) || !is_atomic (t[0]))
00023     return evaluate_error ("undefined", t[0]);
00024   basic_environment local= macro_arguments (std_env);
00025   int key= make_tree_label (t[0]->label);
00026   if (!local->contains (key))
00027     return evaluate_error ("undefined", t[0]);
00028   tree u= local [key];
00029 #else
00030   tree u= t[0];
00031 #endif
00032   if (is_atomic (u)) return evaluate_error ("bad eval-args");
00033 
00034 #ifdef CLASSICAL_MACRO_EXPANSION
00035   macro_up (std_env);
00036 #endif
00037 
00038   int i, n= N(u);
00039   tree r (u, n);
00040   for (i=0; i<n; i++)
00041     r[i]= evaluate (u[i]);
00042 
00043 #ifdef CLASSICAL_MACRO_EXPANSION
00044   macro_redown (std_env, local);
00045 #endif
00046 
00047   return r;
00048 }
00049 
00050 /******************************************************************************
00051 * Quasiquote
00052 ******************************************************************************/
00053 
00054 tree
00055 evaluate_quasiquote (tree t) {
00056   if (is_atomic (t)) return t;
00057   else if (is_func (t, UNQUOTE, 1)) return evaluate (t[0]);
00058   else {
00059     int i, n= N(t);
00060     tree r (L(t));
00061     for (i=0; i<n; i++) {
00062       if (is_func (t[i], VAR_UNQUOTE, 1)) {
00063        tree ins= evaluate (t[i]);
00064        if (is_compound (ins)) r << A(ins);
00065        else r << evaluate_error ("bad unquote*");
00066       }
00067       else r << evaluate_quasiquote (t[i]);
00068     }
00069     return r;
00070   }
00071 }