/** * This file is part of Gomu. * * Copyright 2016 by Jean Fromentin * * Gomu is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Gomu is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Gomu. If not, see . */ #include "module.hpp" namespace Gomu{ //************** //* ArrayValue * //************** ArrayValue::ArrayValue(size_t s){ size=s; type=nullptr; if(s==0) tab=nullptr; else tab=new void*[size]; } //********* //* Error * //********* void Error::disp(ostream& os,const string& cmd) const{ switch(type){ case errBug: os<<"\033[31mBug\033[0m : "<0) os<copy(ptr); return res; } //--------------- // Value::disp() //--------------- string Value::disp(){ if(type==type_symbol) return ((Value*)ptr)->disp(); if(ptr!=nullptr and type!=nullptr) return type->disp(ptr); else return ""; } //*********************** //* Auxiliary functions * //*********************** //------------------ // get_slong(void*) //------------------ int64 get_slong(void* v){ fmpz* z=(fmpz*)v; if(fmpz_fits_si(z)) return fmpz_get_si(z); else RuntimeError("Integer too huge to fit slong"); } //------------------ // to_boolean(bool) //------------------ void* to_boolean(bool b){ char* res=new char; *res=(b?1:0); return res; } //------------------- // to_integer(slong) //------------------- void* to_integer(slong n){ fmpz* z=new fmpz; fmpz_init(z); fmpz_set_si(z,n); return z; } //---------------- // no_copy(void*) //---------------- void* no_copy(void*){ ContextError("Copy is undefined for this type"); } //---------------------- // no_comp(void*,void*) //---------------------- int no_comp(void*,void*){ ContextError("Comparison is undefined for this type"); } }