aboutsummaryrefslogblamecommitdiff
path: root/eval.cpp
blob: d371838de217ec9c93b6e560d2c159eed3497efc (plain) (tree)
1
2
3
4
5
6
7
8
9
                   

                    
                
               
 

                 
                                          
                        

                                           
                                     
 
                                                                 
                                        
 
                               




                                         
 
                                      
                                                   
 










                                                


                                   
                                   


                                   
                                   
                                  
                                   

                                  

                                                 
                                           



                                               






                                           




                                             
                                        





                                               
                                        

                                       

                                             
 

                                     
                                         
 
                                         

                                           


                                             
                                             
                                            




                                                     


                                                                            


                        
                                                                
                    


                           


                                                          













                                             


                                                 

                                                    

                                                                    

                                                         



                                                                           


                                                  






                                                                  
                                                                 
 
 
                                         
                                        
                                                                             


                                             
                                            


     


                                      
                                          
 
                                   
                    

                                                                           
 


                                                 




                                                                               
                         
                                  
 

                                                                              
     

                                                                   
               
                                          
                                              
         
                                    
                                        


                                                               

                                                                             
             
                                                
                            


                                                              
                                                                      
             
                
                                                                                 

                                                                                        

         
                            
                    
                    

                                                       
 
#include "consts.h"
#include "eval.h"
#include "builtin.h"
#include "exc.h"
#include "gc.h"

#include <cstdio>

static const int EVAL_STACK_SIZE = 262144;
extern Pair *empty_list;

/** The stack for evaluating expressions */
EvalObj *eval_stack[EVAL_STACK_SIZE];

/** Add all kinds of built-in facilities before the evaluation */
void Evaluator::add_builtin_routines() {

#define ADD_ENTRY(name, rout) \
    do { \
        SymObj *tmp = new SymObj(name); \
        envt->add_binding(tmp, rout); \
        delete tmp; \
    } while (0)

#define ADD_BUILTIN_PROC(name, rout) \
    ADD_ENTRY(name, new BuiltinProcObj(rout, name))

    ADD_ENTRY("if", new SpecialOptIf());
    ADD_ENTRY("lambda", new SpecialOptLambda());
    ADD_ENTRY("define", new SpecialOptDefine());
    ADD_ENTRY("set!", new SpecialOptSet());
    ADD_ENTRY("quote", new SpecialOptQuote());
    ADD_ENTRY("eval", new SpecialOptEval());
    ADD_ENTRY("and", new SpecialOptAnd());
    ADD_ENTRY("or", new SpecialOptOr());
    ADD_ENTRY("apply", new SpecialOptApply());
    ADD_ENTRY("delay", new SpecialOptDelay());
    ADD_ENTRY("force", new SpecialOptForce());

    ADD_BUILTIN_PROC("+", num_add);
    ADD_BUILT