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


                               
                               
                                       

                                                      


                     
                                                     

                  
 



                                 
                                  
 
                               








                               
 
 
                             
                                          
                                                        

 



                               



                                



                               



                                



                                
                          


                 
                         
                                        


                
                            
                                    
                                                      


                                                          
                                    
                                       
                 
                      
                                
     
                                   
         

                                                           
                                  
                    
             
                                                    



                                               

                                        
                                                        
                     

                                          
             
                
             



                                                                    
             


            

                                       


                                                    



                                               

                                        
                                                        

                                                                  
                 
             





                                                
         
                  
     
                                     

                              
                       
               
 
 









                                                     
                                                 
                                                  
#include "consts.h"
#include "model.h"
#include "types.h"
#include "exc.h"
#include "gc.h"

#include <cstdio>
#include <set>

static const int REPR_STACK_SIZE = 262144;
extern EmptyList *empty_list;
extern GarbageCollector gc;
typedef std::set<EvalObj*> EvalObjAddrHash;

/** Maintain the current in-stack objects to detect circular structures */
static EvalObjAddrHash hash;
/** The stack for building external representation string */
static ReprCons *repr_stack[REPR_STACK_SIZE];

FrameObj::FrameObj(FrameType _ftype) : ftype(_ftype) {}

EmptyList::EmptyList() : Pair(NULL, NULL) {}

ReprCons *EmptyList::get_repr_cons() { return new ReprStr("()"); }

bool FrameObj::is_parse_bracket() {
    return ftype & CLS_PAR_BRA;
}

EvalObj::EvalObj(int _otype) : 
FrameObj(CLS_EVAL_OBJ), otype(_otype) {
    /** To notify GC when an EvalObj is constructed */
    gc_rec = gc.join(this);
}

EvalObj::~EvalObj() {
    /** To notify GC when an EvalObj is destructed */
    gc.quit(this);
}

bool EvalObj::is_container() {
    return otype & CLS_CONTAINER;
}

void EvalObj::prepare(Pair *pc) {}

bool EvalObj::is_simple_obj() {
    return otype & CLS_SIM_OBJ;
}

bool EvalObj::is_sym_obj() {
    return otype & CLS_SYM_OBJ;
}

bool EvalObj::is_opt_obj() {
    return otype & CLS_OPT_OBJ;
}

bool EvalObj::is_pair_obj() {
    /** an empty list is not a pair obj */
    return this != empty_list && (otype & CLS_PAIR_OBJ);
}

bool EvalObj::is_num_obj() {
    return otype & CLS_NUM_OBJ;
}

bool EvalObj::is_bool_obj() {
    return otype & CLS_BOOL_OBJ;
}

bool EvalObj::is_str_obj() {
    return otype & CLS_STR_OBJ;