Changeset 115639 in git


Ignore:
Timestamp:
Mar 1, 2011, 6:21:05 PM (12 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
b521f3698286cefec0d2866b873155439fcc9619
Parents:
2c470d08ccdc9d28a3c5007e5cc99fe10e6d522c
Message:
ADD: call bigintm_setup using system("bigintm_setup"); (due to extra.cc)
ADD: bigintm_setup should better return BOOLEAN
ADD: better development prints for blackbox objects
ADD: save static type (bigintm) ID

From: Oleksandr Motsak <motsak@mathematik.uni-kl.de>

git-svn-id: file:///usr/local/Singular/svn/trunk@13910 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Singular/bigintm.cc

    r2c470d0 r115639  
    88#include <Singular/bigintm.h>
    99
    10 // as this is only a demo,
    11 // we do not included compiled code:
    12 #if 0
    13 char * bigintm_String(blackbox *b, void *d);
    14 void * bigintm_Copy(blackbox*b, void *d);
    15 BOOLEAN bigintm_Assign(leftv l, leftv r);
    16 BOOLEAN bigintm_Op2(int op, leftv res, leftv a1, leftv a2);
    17 BOOLEAN bigintm_OpM(int op, leftv res, leftv args);
    18 void bigintm_destroy(blackbox *b, void *d);
    1910
    20 void bigintm_setup()
    21 {
    22   blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
    23   // all undefined entries will be set to default in setBlackboxStuff
    24   // the default Print is quite usefule,
    25   // all other are simply error messages
    26   b->blackbox_destroy=bigintm_destroy;
    27   b->blackbox_String=bigintm_String;
    28   //b->blackbox_Print=blackbox_default_Print;
    29   //b->blackbox_Init=blackbox_default_Init;
    30   b->blackbox_Copy=bigintm_Copy;
    31   b->blackbox_Assign=bigintm_Assign;
    32   //b->blackbox_Op1=blackboxDefaultOp1;
    33   b->blackbox_Op2=bigintm_Op2;
    34   //b->blackbox_Op3=blackbox_default_Op3;
    35   b->blackbox_OpM=bigintm_OpM;
    36   int rt=setBlackboxStuff(b,"bigintm");
    37   Print("create type %d (bigintm)\n",rt);
    38 }
     11#define HAVE_BIGINTM 1
    3912
    40 char * bigintm_String(blackbox *b, void *d)
     13#ifdef HAVE_BIGINTM
     14static int bigintm_type_id = -1;
     15#endif
     16
     17
     18#ifdef HAVE_BIGINTM
     19static char * bigintm_String(blackbox *b, void *d)
    4120{ if (d==NULL) return omStrDup("oo");
    4221   else
     
    4726    }
    4827}
    49 void * bigintm_Copy(blackbox*b, void *d)
     28static void * bigintm_Copy(blackbox*b, void *d)
    5029{  number n=(number)d; return nlCopy(n); }
    5130
    52 BOOLEAN bigintm_Assign(leftv l, leftv r)
     31static BOOLEAN bigintm_Assign(leftv l, leftv r)
    5332{
     33  assume( l->Typ() == bigintm_type_id );
     34 
    5435  blackbox *ll=getBlackboxStuff(l->Typ());
     36 
    5537  if (r->Typ()>MAX_TOK)
    5638  {
    57     blackbox *rr=getBlackboxStuff(r->Typ());
    58     if (l->Typ()==r->Typ())
     39    if (bigintm_type_id == r->Typ())
    5940    {
     41      blackbox *rr=getBlackboxStuff(r->Typ());
     42     
    6043      if (l->Data()!=NULL) { number n1=(number)l->Data(); nlDelete(&n1,NULL); }
    6144      number n2=(number)r->CopyD();
     
    7255    else
    7356    {
    74       Werror("assign %d = %d",l->Typ(),r->Typ());
     57      Werror("bigintm_Assign: assign %s (%d) = %s (%d)",
     58             getBlackboxName(l->Typ()), l->Typ(),
     59             getBlackboxName(r->Typ()), r->Typ());
    7560      return TRUE;
    7661    }
     
    9479  return TRUE;
    9580}
    96 BOOLEAN bigintm_OpM(int op, leftv res, leftv args);
     81static BOOLEAN bigintm_OpM(int op, leftv res, leftv args);
    9782
    9883
    99 BOOLEAN bigintm_Op2(int op, leftv res, leftv a1, leftv a2)
     84static BOOLEAN bigintm_Op2(int op, leftv res, leftv a1, leftv a2)
    10085{
    10186  // interpreter: a1 is ist bigintm
     87  assume( a1->Typ() == bigintm_type_id );
     88 
    10289  blackbox *a=getBlackboxStuff(a1->Typ());
    10390  number n1=(number)a1->Data();
     
    124111      return TRUE;
    125112    }
     113    default:
     114      Werror("bigintm_Op2: op %d not implemented for type %s (%d)", op, getBlackboxName(a1->Typ()), a1->Typ());
     115      break;
    126116  }
    127117  return blackboxDefaultOp2(op,res,a1,a2);
    128118}
    129119// BOOLEAN opM(int op, leftv res, leftv args)
    130 BOOLEAN bigintm_OpM(int op, leftv res, leftv args)
     120static BOOLEAN bigintm_OpM(int op, leftv res, leftv args)
    131121{
    132122  // interpreter: args->1. arg is ist bigintm
     123  assume( args->Typ() == bigintm_type_id );
    133124  blackbox *a=getBlackboxStuff(args->Typ());
    134125  switch(op)
     
    141132    }
    142133    default:
    143       Werror("op %d not implemented for type %d",op,args->Typ());
     134      Werror("bigintm_OpM: op %d not implemented for type %s (%d)", op, getBlackboxName(args->Typ()), args->Typ());
    144135      break;
    145136  }
    146137  return TRUE;
    147138}
    148 void bigintm_destroy(blackbox *b, void *d)
     139static void bigintm_destroy(blackbox *b, void *d)
    149140{
    150141  if (d!=NULL)
     
    154145  }
    155146}
     147
    156148#endif
     149
     150
     151
     152
     153// this is only a demo
     154BOOLEAN bigintm_setup()
     155{
     156#ifndef HAVE_BIGINTM
     157  Werror("bigintm_setup: Sorry BIGINTM was not compiled in!");
     158  return TRUE; // ok, TRUE = error!
     159#else
     160
     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;
     177
     178    bigintm_type_id = setBlackboxStuff(b,"bigintm");
     179
     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  }
     189
     190#endif
     191}
     192
     193
     194
  • Singular/bigintm.h

    r2c470d0 r115639  
    22#define BIGINTM_H
    33
    4 void bigintm_setup();
     4BOOLEAN bigintm_setup();
    55
    66#endif
  • Singular/blackbox.cc

    r2c470d0 r115639  
    55#include <Singular/blackbox.h>
    66
    7 //#define BLACKBOX_DEVEL 1
    87#define MAX_BB_TYPES 256
     8// #define BLACKBOX_DEVEL 1
    99
    1010static blackbox* blackboxTable[MAX_BB_TYPES];
     
    103103    blackboxName[where]=omStrDup(n);
    104104#ifdef BLACKBOX_DEVEL
    105     Print("define bb:name=%s:rt=%d (table:cnt=%d)\n",blackboxName[where],where+BLACKBOX_OFFSET,where);
     105  Print("setBlackboxStuff: define bb:name=%s:rt=%d (table:cnt=%d)\n",blackboxName[where],where+BLACKBOX_OFFSET,where);
    106106#endif
    107107    if (bb->blackbox_destroy==NULL) bb->blackbox_destroy=blackbox_default_destroy;
     
    138138    {
    139139#ifdef BLACKBOX_DEVEL
    140       Print("found bb:%s:%d (table:%d)\n",n,i+BLACKBOX_OFFSET,i);
     140      Print("blackboxIsCmd: found bb:%s:%d (table:%d)\n",n,i+BLACKBOX_OFFSET,i);
    141141#endif
    142142      tok=i+BLACKBOX_OFFSET;
     
    152152  {
    153153    if (blackboxName[i]!=NULL)
    154       Print("type %d: %s\n",i,blackboxName[i]);
     154      Print("printBlackboxTypes: blackbox-type %d: %s\n",i,blackboxName[i]);
    155155  }
    156156}
  • Singular/extra.cc

    r2c470d0 r115639  
    162162//#endif /* not HAVE_DYNAMIC_LOADING */
    163163
     164#include <Singular/bigintm.h>
     165
    164166#ifdef ix86_Win
    165167//#include <Python.h>
     
    175177#ifdef ix86_Win  /* PySingular initialized? */
    176178static int PyInitialized = 0;
     179#endif
     180
     181#if SIZEOF_LONG == 8
     182static number jjLONG2N(long d)
     183{
     184  int i=(int)d;
     185  if ((long)i == d)
     186  {
     187    return nlInit(i, NULL);
     188  }
     189  else
     190  {
     191#if !defined(OM_NDEBUG) && !defined(NDEBUG)
     192    omCheckBin(rnumber_bin);
     193#endif
     194    number z=(number)omAllocBin(rnumber_bin);
     195#if defined(LDEBUG)
     196    z->debug=123456;
     197#endif
     198    z->s=3;
     199    mpz_init_set_si(z->z,d);
     200    return z;
     201  }
     202}
     203#else
     204#define jjLONG2N(D) nlInit((int)D, NULL)
    177205#endif
    178206
     
    38783906    printBlackboxTypes();
    38793907    return FALSE;
    3880   }
    3881   else
     3908  } else
     3909/*==================== init the bigintm (a sample blackbox) type =========*/
     3910  if(strcmp(sys_cmd,"bigintm_setup") == 0)
     3911  {
     3912    return bigintm_setup();
     3913  } else
    38823914/*==================== Error =================*/
    38833915      Werror( "(extended) system(\"%s\",...) %s", sys_cmd, feNotImplemented );
Note: See TracChangeset for help on using the changeset viewer.