Changeset bca6c6 in git


Ignore:
Timestamp:
Mar 2, 2011, 9:45:23 AM (13 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
Children:
31a04de9654ef6c91a67d31ba39e3e2f1c9537fe
Parents:
b521f3698286cefec0d2866b873155439fcc9619
Message:
bigintm example code

git-svn-id: file:///usr/local/Singular/svn/trunk@13912 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/bigintm.cc

    rb521f3 rbca6c6  
     1// as this file provides only example code,
     2// no trace of it must appear in Singular and Singularg
     3//
     4#if 0
     5//
    16#include <Singular/mod2.h>
    27#include <Singular/ipid.h>
     
    914
    1015
    11 #define HAVE_BIGINTM 1
    12 
    13 #ifdef HAVE_BIGINTM
    14 static int bigintm_type_id = -1;
    15 #endif
    16 
    17 
    18 #ifdef HAVE_BIGINTM
    1916static char * bigintm_String(blackbox *b, void *d)
    2017{ if (d==NULL) return omStrDup("oo");
     
    3128static BOOLEAN bigintm_Assign(leftv l, leftv r)
    3229{
    33   assume( l->Typ() == bigintm_type_id );
    34  
    3530  blackbox *ll=getBlackboxStuff(l->Typ());
    3631 
    3732  if (r->Typ()>MAX_TOK)
    3833  {
    39     if (bigintm_type_id == r->Typ())
     34    if (l->Typ() == r->Typ())
    4035    {
    4136      blackbox *rr=getBlackboxStuff(r->Typ());
     
    8580{
    8681  // interpreter: a1 is ist bigintm
    87   assume( a1->Typ() == bigintm_type_id );
    8882 
    8983  blackbox *a=getBlackboxStuff(a1->Typ());
     
    112106    }
    113107    default:
    114       Werror("bigintm_Op2: op %d not implemented for type %s (%d)", op, getBlackboxName(a1->Typ()), a1->Typ());
    115       break;
     108      return blackboxDefaultOp2(op,res,a1,a2);
    116109  }
    117110  return blackboxDefaultOp2(op,res,a1,a2);
     
    121114{
    122115  // interpreter: args->1. arg is ist bigintm
    123   assume( args->Typ() == bigintm_type_id );
    124116  blackbox *a=getBlackboxStuff(args->Typ());
    125117  switch(op)
     
    132124    }
    133125    default:
    134       Werror("bigintm_OpM: op %d not implemented for type %s (%d)", op, getBlackboxName(args->Typ()), args->Typ());
     126      return blackboxDefaultOpM(op,res,args);
    135127      break;
    136128  }
    137   return TRUE;
     129  return blackboxDefaultOpM(op,res,args);
    138130}
    139131static void bigintm_destroy(blackbox *b, void *d)
     
    146138}
    147139
    148 #endif
    149140
    150 
    151 
    152 
    153 // this is only a demo
    154141BOOLEAN bigintm_setup()
    155142{
    156 #ifndef HAVE_BIGINTM
    157   Werror("bigintm_setup: Sorry BIGINTM was not compiled in!");
    158   return TRUE; // ok, TRUE = error!
    159 #else
     143  // it is not very usefull to call this setup routine twice,
     144  // but (as this is an example) it is possible.
     145  // Other blackbox type really require multiple setup calls
     146  // (with different names).
     147  // Also the format of this setup routine is not fixed,
     148  // it may take additional parameters, it may return a value or not
     149  // - it really depends.
    160150
    161   if( bigintm_type_id == -1 )
    162   {
    163     blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
    164     // all undefined entries will be set to default in setBlackboxStuff
    165     // the default Print is quite usefule,
    166     // all other are simply error messages
    167     b->blackbox_destroy=bigintm_destroy;
    168     b->blackbox_String=bigintm_String;
    169     //b->blackbox_Print=blackbox_default_Print;
    170     //b->blackbox_Init=blackbox_default_Init;
    171     b->blackbox_Copy=bigintm_Copy;
    172     b->blackbox_Assign=bigintm_Assign;
    173     //b->blackbox_Op1=blackboxDefaultOp1;
    174     b->blackbox_Op2=bigintm_Op2;
    175     //b->blackbox_Op3=blackbox_default_Op3;
    176     b->blackbox_OpM=bigintm_OpM;
     151  blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
     152  // all undefined entries will be set to default in setBlackboxStuff
     153  // the default Print is quite usefule,
     154  // all other are simply error messages
     155  b->blackbox_destroy=bigintm_destroy;
     156  b->blackbox_String=bigintm_String;
     157  //b->blackbox_Print=blackbox_default_Print;
     158  //b->blackbox_Init=blackbox_default_Init;
     159  b->blackbox_Copy=bigintm_Copy;
     160  b->blackbox_Assign=bigintm_Assign;
     161  //b->blackbox_Op1=blackboxDefaultOp1;
     162  b->blackbox_Op2=bigintm_Op2;
     163  //b->blackbox_Op3=blackbox_default_Op3;
     164  b->blackbox_OpM=bigintm_OpM;
     165  int rt=setBlackboxStuff(b,"bigintm");
    177166
    178     bigintm_type_id = setBlackboxStuff(b,"bigintm");
     167  Print("bigintm_setup: create type %d (%s)\n",rt, getBlackboxName(rt));
    179168
    180     Print("bigintm_setup: create type %d (%s)",bigintm_type_id, getBlackboxName(bigintm_type_id));
    181     PrintLn();
    182 
    183     return FALSE; // ok, TRUE = error!
    184   } else
    185   {
    186     Werror("bigintm_setup: Sorry should NOT be run twice!");
    187     return TRUE; // ok, TRUE = error!
    188   }
     169  return FALSE; // ok, TRUE = error!: this example never fails
     170}
    189171
    190172#endif
    191 }
    192 
    193 
    194 
Note: See TracChangeset for help on using the changeset viewer.