Changeset a04a05 in git


Ignore:
Timestamp:
Aug 1, 2012, 11:29:10 PM (11 years ago)
Author:
Alexander Dreyer <alexander.dreyer@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
29fc84389b9713cdf07cc538bad5becf4758553e
Parents:
5ebd4bcf7ead1b205b12afeec0793f8bc29e16ec
Message:
chg: encapsulating newstruct's overloaded '=' and use in pyobject
Location:
Singular
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Singular/newstruct.cc

    r5ebd4bc ra04a05  
    134134}
    135135
     136// Used by newstruct_Assign for overloaded '='
     137BOOLEAN newstruct_equal(int op, leftv l, leftv r)
     138{
     139  blackbox *ll=getBlackboxStuff(op);
     140  assume(ll->data != NULL);
     141  newstruct_desc nt=(newstruct_desc)ll->data;
     142  newstruct_proc p=nt->procs;
     143 
     144  while( (p!=NULL) && ((p->t!='=')||(p->args!=1)) ) p=p->next;
     145
     146  if (p!=NULL)
     147  {
     148    idrec hh;
     149    memset(&hh,0,sizeof(hh));
     150    hh.id=Tok2Cmdname(p->t);
     151    hh.typ=PROC_CMD;
     152    hh.data.pinf=p->p;
     153    sleftv tmp;
     154    memset(&tmp,0,sizeof(sleftv));
     155    tmp.Copy(r);
     156    leftv sl = iiMake_proc(&hh, NULL, &tmp);
     157    if (sl != NULL)
     158    {
     159      if (sl->Typ() == op) { l->Copy(sl); return FALSE;}
     160      else sl->CleanUp();
     161    }
     162  }
     163  return TRUE;
     164}
     165
    136166BOOLEAN newstruct_Assign(leftv l, leftv r)
    137167{
     
    193223  else if(l->Typ() > MAX_TOK)
    194224  {
    195     blackbox *ll=getBlackboxStuff(l->Typ());
    196     newstruct_desc nt=(newstruct_desc)ll->data;
    197     newstruct_proc p=nt->procs;
    198 
    199     while( (p!=NULL) && ((p->t!='=')||(p->args!=1)) ) p=p->next;
    200 
    201     if (p!=NULL)
    202     {
    203       idrec hh;
    204       memset(&hh,0,sizeof(hh));
    205       hh.id=Tok2Cmdname(p->t);
    206       hh.typ=PROC_CMD;
    207       hh.data.pinf=p->p;
    208       sleftv tmp;
    209       memset(&tmp,0,sizeof(sleftv));
    210       tmp.Copy(r);
    211       leftv sl = iiMake_proc(&hh, NULL, &tmp);
    212       if (sl != NULL)
    213       {
    214         if (sl->Typ()==l->Typ()) return newstruct_Assign(l, sl);
    215         else sl->CleanUp();
    216       }
    217     }
     225    assume(l->Typ() > MAX_TOK);
     226    sleftv tmp;
     227    if(!newstruct_equal(l->Typ(), &tmp, r)) return newstruct_Assign(l, &tmp);
    218228  }
    219229  Werror("assign %s(%d) = %s(%d)",
  • Singular/pyobject.cc

    r5ebd4bc ra04a05  
    339339    }
    340340
     341    sleftv tmp;
     342    BOOLEAN newstruct_equal(int, leftv, leftv); // declaring overloaded '='
     343    if (!newstruct_equal(PythonInterpreter::id(), &tmp, value)) 
     344      return PythonCastStatic<>(&tmp);       
     345
    341346    if (typeId > MAX_TOK)       // custom types
    342347    {
    343348      blackbox *bbx = getBlackboxStuff(typeId);
    344       sleftv tmp;
    345       if (! bbx->blackbox_Op1(PythonInterpreter::id(), &tmp, value) )
    346         return PythonCastStatic<>(&tmp);
    347     }
    348     else
    349       Werror("type '%s` incompatible with 'pyobject`", iiTwoOps(typeId));
    350 
     349      assume(bbx != NULL);
     350      if (! bbx->blackbox_Op1(PythonInterpreter::id(), &tmp, value))
     351        return PythonCastStatic<>(&tmp);       
     352    }
     353
     354    Werror("type '%s` incompatible with 'pyobject`", iiTwoOps(typeId));
    351355    return PythonObject();
    352356  }
Note: See TracChangeset for help on using the changeset viewer.