~ubuntu-branches/ubuntu/raring/yorick/raring

« back to all changes in this revision

Viewing changes to yorick/ydata.c

  • Committer: Bazaar Package Importer
  • Author(s): Thibaut Paumard
  • Date: 2010-05-06 17:47:18 UTC
  • mfrom: (1.2.1 upstream) (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100506174718-j26zbusz02k8hf6t
Tags: 2.1.06+dfsg-2
Deactivate check suite on MIPS due to bug #580524.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: ydata.c,v 1.2 2005/11/13 21:01:56 dhmunro Exp $
 
2
 * $Id: ydata.c,v 1.4 2010/04/16 05:23:43 dhmunro Exp $
3
3
 * Implement functions for Yorick-specific types of data.
4
4
 */
5
5
/* Copyright (c) 2005, The Regents of the University of California.
19
19
extern Array *GrowArray(Array *array, long extra);
20
20
 
21
21
extern BuiltIn Y_yorick_stats, Y_symbol_def, Y_symbol_set;
 
22
extern BuiltIn Y_symbol_names, Y_symbol_exists, Y_errs2caller;
22
23
 
23
24
/* Required for FetchLValue, StoreLValue */
24
25
extern void ReadGather(void *dst, void *srcM, long srcD, StructDef *base,
71
72
  func->nKey= nKey;
72
73
  func->nLocal= nLocal;
73
74
  func->hasPosList= hasPL;
 
75
  func->errup = 0;
74
76
  codeSize-= frameSize-1;
75
77
  /* YpFunc puts the frame variables (parameters and locals) at the end
76
78
     of the code, switch them to the beginning now.  */
96
98
  p_free(func);
97
99
}
98
100
 
 
101
void
 
102
Y_errs2caller(int argc)
 
103
{
 
104
  Function *f;
 
105
  int i;
 
106
  for (i=argc-1 ; i>=0 ; i--) {
 
107
    if (sp[-i].ops == &referenceSym) ReplaceRef(sp-i);
 
108
    if (sp[-i].ops!=&dataBlockSym || sp[-i].value.db->ops!=&functionOps)
 
109
      YError("errs2caller accepts only function arguments");
 
110
    f = (Function *)sp[-i].value.db;
 
111
    f->errup = 1;
 
112
  }
 
113
}
 
114
 
99
115
/* Set up a block allocator which grabs space for 64 range objects
100
116
   at a time.  Since Range contains an ops pointer, the alignment
101
117
   of a Range must be at least as strict as a void*.  */
922
938
  glob->ops= sp->ops;
923
939
}
924
940
 
 
941
void Y_symbol_exists(int argc)
 
942
{
 
943
  if (argc != 1) YError("symbol_exists takes exactly one argument");
 
944
  PushIntValue(HashFind(&globalTable, YGetString(sp), 0L));
 
945
}
 
946
 
 
947
#define GET_ARRAY       1
 
948
#define GET_STRUCT      2
 
949
#define GET_RANGE       4
 
950
#define GET_VOID        8
 
951
#define GET_FUNCTION   16
 
952
#define GET_BUILTIN    32
 
953
#define GET_STRUCTDEF  64
 
954
#define GET_STREAM    128
 
955
#define GET_OPAQUE    256
 
956
#define GET_LIST      512
 
957
#define GET_AUTOLOAD 1024
 
958
 
 
959
void Y_symbol_names(int argc)
 
960
{
 
961
  extern Operations listOps;
 
962
  long i, nitems, number;
 
963
  char **ret;
 
964
  int match[T_OPAQUE+1];
 
965
  int type, flags, pass;
 
966
  int omit_array, omit_list, omit_autoload, omit_opaque;
 
967
  Dimension *dims = tmpDims;
 
968
 
 
969
  tmpDims = (Dimension *)0;
 
970
  if (dims != (Dimension *)0) FreeDimension(dims);
 
971
  if (argc != 1) YError("symbol_list takes exactly one argument");
 
972
  if (YNotNil(sp)) {
 
973
    flags = YGetInteger(sp);
 
974
  } else {
 
975
    flags = (GET_ARRAY | GET_STRUCT | GET_RANGE | GET_FUNCTION | GET_BUILTIN |
 
976
             GET_STRUCTDEF | GET_STREAM | GET_OPAQUE);
 
977
  }
 
978
  nitems = globalTable.nItems;
 
979
  if (nitems <= 0) {
 
980
    /* No symbols defined. */
 
981
    PushDataBlock(RefNC(&nilDB));
 
982
    return;
 
983
  }
 
984
  if (flags == -1) {
 
985
    /* Return names of all symbols ever defined. */
 
986
    tmpDims = NewDimension(nitems, 1L, (Dimension *)0);
 
987
    ret = ((Array *)PushDataBlock(NewArray(&stringStruct, tmpDims)))->value.q;
 
988
    for (i = 0; i < nitems; ++i) {
 
989
      ret[i] = p_strcpy(globalTable.names[i]);
 
990
    }
 
991
    return;
 
992
  }
 
993
  omit_array = ((flags & GET_ARRAY) == 0);
 
994
  omit_list = ((flags & GET_LIST) == 0);
 
995
  omit_autoload = ((flags & GET_AUTOLOAD) == 0);
 
996
  omit_opaque = ((flags & GET_OPAQUE) == 0);
 
997
  if ((flags & (GET_LIST | GET_AUTOLOAD)) != 0) {
 
998
    flags |= GET_OPAQUE;
 
999
  }
 
1000
  for (i = 0; i <= T_OPAQUE; ++i) {
 
1001
    match[i] = 0;
 
1002
  }
 
1003
  match[T_CHAR]      = ((flags & GET_ARRAY) != 0);
 
1004
  match[T_SHORT]     = ((flags & GET_ARRAY) != 0);
 
1005
  match[T_INT]       = ((flags & GET_ARRAY) != 0);
 
1006
  match[T_LONG]      = ((flags & GET_ARRAY) != 0);
 
1007
  match[T_FLOAT]     = ((flags & GET_ARRAY) != 0);
 
1008
  match[T_DOUBLE]    = ((flags & GET_ARRAY) != 0);
 
1009
  match[T_COMPLEX]   = ((flags & GET_ARRAY) != 0);
 
1010
  match[T_STRING]    = ((flags & GET_ARRAY) != 0);
 
1011
  match[T_POINTER]   = ((flags & GET_ARRAY) != 0);
 
1012
  match[T_STRUCT]    = ((flags & GET_STRUCT) != 0);
 
1013
  match[T_RANGE]     = ((flags & GET_RANGE) != 0);
 
1014
#ifdef GET_LVALUE
 
1015
  match[T_LVALUE]    = ((flags & GET_LVALUE) != 0);
 
1016
#endif
 
1017
  match[T_VOID]      = ((flags & GET_VOID) != 0);
 
1018
  match[T_FUNCTION]  = ((flags & GET_FUNCTION) != 0);
 
1019
  match[T_BUILTIN]   = ((flags & GET_BUILTIN) != 0);
 
1020
  match[T_STRUCTDEF] = ((flags & GET_STRUCTDEF) != 0);
 
1021
  match[T_STREAM]    = ((flags & GET_STREAM) != 0);
 
1022
  match[T_OPAQUE]    = ((flags & GET_OPAQUE) != 0);
 
1023
 
 
1024
  /* Counter number of matching symbols. */
 
1025
  ret = NULL; /* avoids compiler warning */
 
1026
  number = 0;
 
1027
  for (pass = 0; pass <= 1; ++pass) {
 
1028
    if (pass) {
 
1029
      if (number <= 0) {
 
1030
        /* No matching symbols found. */
 
1031
        PushDataBlock(RefNC(&nilDB));
 
1032
        return;
 
1033
      }
 
1034
      tmpDims = NewDimension(number, 1L, (Dimension *)0);
 
1035
      ret = ((Array *)PushDataBlock(NewArray(&stringStruct, tmpDims)))->value.q;
 
1036
    }
 
1037
    for (i=0 ; i<nitems ; ++i) {
 
1038
      OpTable *sym_ops = globTab[i].ops;
 
1039
      if (sym_ops == &dataBlockSym) {
 
1040
        Operations *ops = globTab[i].value.db->ops;
 
1041
        type = ops->typeID;
 
1042
        if ((unsigned int)type > T_OPAQUE || ! match[type]) {
 
1043
          continue;
 
1044
        }
 
1045
        if (type == T_OPAQUE) {
 
1046
          if (ops == &listOps) {
 
1047
            if (omit_list) {
 
1048
              continue;
 
1049
            }
 
1050
          } else if (ops == &auto_ops) {
 
1051
            if (omit_autoload) {
 
1052
              continue;
 
1053
            }
 
1054
          } else {
 
1055
            if (omit_opaque) {
 
1056
              continue;
 
1057
            }
 
1058
          }
 
1059
        }
 
1060
      } else if (sym_ops == &longScalar ||
 
1061
                 sym_ops == &intScalar ||
 
1062
                 sym_ops == &doubleScalar) {
 
1063
        if (omit_array) {
 
1064
          continue;
 
1065
        }
 
1066
      }
 
1067
      if (pass) {
 
1068
        *ret++ = p_strcpy(globalTable.names[i]);
 
1069
      } else {
 
1070
        ++number;
 
1071
      }
 
1072
    }
 
1073
  }
 
1074
}
 
1075
 
 
1076
#undef GET_ARRAY
 
1077
#undef GET_STRUCT
 
1078
#undef GET_RANGE
 
1079
#undef GET_VOID
 
1080
#undef GET_FUNCTION
 
1081
#undef GET_BUILTIN
 
1082
#undef GET_STRUCTDEF
 
1083
#undef GET_STREAM
 
1084
#undef GET_OPAQUE
 
1085
#undef GET_LIST
 
1086
#undef GET_AUTOLOAD
 
1087
 
925
1088
/*--------------------------------------------------------------------------*/