Esempio n. 1
0
static int valueToStringInternal(Value *v, char *s, int n) {
  Node *t;
  int i;
  switch (v->type) {
    case BUILTIN_FUN_VALUE_TYPE:
      return mySnprintf(s, n, "<builtin-function@%p>", v->data);
    case NONE_VALUE_TYPE:
      return mySnprintf(s, n, "none");
    case INT_VALUE_TYPE:
      return mySnprintf(s, n, "%d", v->data);
    case CLOSURE_VALUE_TYPE: {
      int len = 0;
      Node *f = ((Closure *)v->data)->f;
      len += mySnprintf(s + len, n - len, "fun %s(",
                        getStrId((long)chld(f, 0)->data));
      t = chld(f, 1);
      for (i = 0; i < chldNum(t); i++) {
        if (i) {
          len += mySnprintf(s + len, n - len, ", ");
        }
        len += mySnprintf(s + len, n - len, "%s",
                          getStrId((long)chld(t, i)->data));
      }
      len += mySnprintf(s + len, n - len, ")");
      return len;
    }
    case LIST_VALUE_TYPE: {
      int len = 0;
      List *l = v->data;
      len += mySnprintf(s + len, n - len, "[");
      for (i = 0; i < listSize(l); i++) {
        if (i) {
          len += mySnprintf(s + len, n - len, ", ");
        }
        len += valueToStringInternal(listGet(l, i), s + len, n - len);
      }
      len += mySnprintf(s + len, n - len, "]");
      return len;
    }
    case STRING_VALUE_TYPE: {
      return mySnprintf(s, n, "%s", v->data);
    }
    case ENV_VALUE_TYPE: {
      List *keys = envGetAllIds(v->data);
      int len = 0;
      len += mySnprintf(s, n, "env parent->%p { ", getEnvFromValue(v)->parent);
      int keyN = listSize(keys);
      for (i = 0; i < keyN; i++) {
        long key = (long)listGet(keys, i);
        len += mySnprintf(s + len, n - len, "%s->%p ", getStrId(key),
                          envGet(v->data, key));
      }
      len += mySnprintf(s + len, n - len, "}");
      freeList(keys);
      return len;
    }
    default:
      error("cannot print unknown value type: %d at %p\n", v->type, v);
  }
}
int main(int argc, char *argv[]) {
    try {
        m1.lock();
        Thread chld(child);
        chld.run();
        parent();
        chld.join();
        Thread::exit();
    } catch (std::exception &ex) {
        fprintf(stderr, "Exception: %s\n", ex.what());
    }
}
Esempio n. 3
0
/// return a list of all children.  If recursive, flatten out the 
/// nested hierarchy by putting all components and their children, etc
/// in the list in a depth-first-search
std::list<Component *> 
Component::children(bool recursive) const
{
  std::list<Component *> ret;
  for (ComponentList::const_iterator it = childList.begin(); it != childList.end(); ++it) {
    ret.push_back(const_cast<Component *>(*it));
    if (recursive) {
      std::list<Component *> chld ((*it)->children(true));
      ret.splice(ret.end(), chld);
    }
  }
  return ret;
}
Esempio n. 4
0
std::list<Component *>
Component::findAll(const std::string & name, bool recursive) const
{
  std::list<Component *> ret;
  for (ComponentList::const_iterator it = childList.begin(); it != childList.end(); ++it) {
    Component *c = const_cast<Component *>(*it);
    if (c->name() == name) ret.push_back(c);
    if (recursive) {
      std::list<Component *> chld(c->findAll(name, true));
      ret.splice(ret.end(), chld);
    }
  }
  return ret;  
}
Esempio n. 5
0
static void nodeToDotHelper(FILE *o, Node *t, int *nextId, long n, ...) {
    int id = *nextId - 1;
    va_list l;
    char *s;
    int i;
    va_start(l, n);
    s = escapeForDot(nodeTypeToString(t->type));
    fprintf(o, "%d [label=\"{%s|{", id, s);
    tlFree(s);
    for (i = 0; i < n; i++) {
        if (i) fprintf(o, "|");
        fprintf(o, "<%d> %s", i, va_arg(l, char *));
    }
    fprintf(o, "}}\"];\n");
    for (i = 0; i < n; i++) {
        int to = nodeToDotInternal(o, chld(t, i), nextId);
        fprintf(o, "%d:%d -> %d;\n", id, i, to);
    }
    va_end(l);
}
Esempio n. 6
0
static int nodeToDotInternal(FILE *o, Node *t, int *nextId) {
    // printf("%s\n", nodeTypeToString(t->type));
    int id = (*nextId)++;
    switch (t->type) {
    case INT_TYPE:
        fprintf(o, "%d [label=\"INT(%ld)\"];\n", id, (long)t->data);
        break;
    case ID_TYPE:
        fprintf(o, "%d [label=\"ID(%s)\"];\n", id, getStrId((long)t->data));
        break;
    case STRING_TYPE: {
        char *s = maybeTruncateString((char *)t->data);
        char *s2 = escapeForDot(s);
        fprintf(o, "%d [label=\"STRING(%s)\"];\n", id, s2);
        tlFree(s);
        tlFree(s2);
        break;
    }
    case NONE_TYPE:
        fprintf(o, "%d [label=\"none\"];\n", id);
        break;
    case BREAK_TYPE:
        fprintf(o, "%d [label=\"break\"]", id);
        break;
    case CONTINUE_TYPE:
        fprintf(o, "%d [label=\"continue\"]", id);
        break;

    case MODULE_ACCESS_TYPE:
    case EXP_LIST_TYPE:
    case ID_LIST_TYPE:
    case LIST_TYPE:
    case STMTS_TYPE: {
        fprintf(o, "%d [label=\"{%s|{", id, nodeTypeToString(t->type));
        int n = chldNum(t);
        int i;
        for (i = 0; i < n; i++) {
            if (i) fprintf(o, "|");
            fprintf(o, "<%d> %d", i, i);
        }
        fprintf(o, "}}\"];\n");
        for (i = 0; i < n; i++) {
            int to = nodeToDotInternal(o, chld(t, i), nextId);
            fprintf(o, "%d:%d -> %d;\n", id, i, to);
        }
        break;
    }
    case ASSIGN_TYPE:
    case ADD_TYPE:
    case SUB_TYPE:
    case MUL_TYPE:
    case DIV_TYPE:
    case MOD_TYPE:
    case GT_TYPE:
    case LT_TYPE:
    case GE_TYPE:
    case LE_TYPE:
    case EQ_TYPE:
    case NE_TYPE:
    case AND_TYPE:
    case OR_TYPE:
    case ADDEQ_TYPE:
        nodeToDotHelper(o, t, nextId, 2L, "op1", "op2");
        break;
    case TIME_TYPE:
    case THROW_TYPE:
    case RETURN_TYPE:
        nodeToDotHelper(o, t, nextId, 1L, "exp");
        break;
    case NOT_TYPE:
        nodeToDotHelper(o, t, nextId, 1L, "exp");
        break;
    case ADDADD_TYPE:
        nodeToDotHelper(o, t, nextId, 1L, "id");
        break;
    case LOCAL_TYPE:
        nodeToDotHelper(o, t, nextId, 1L, "ids");
        break;
    case IMPORT_TYPE:
        nodeToDotHelper(o, t, nextId, 1L, "ids");
        break;
    case IF_TYPE: {
        int n = chldNum(t);
        if (n == 2) {
            nodeToDotHelper(o, t, nextId, 2L, "cond", "then");
        } else {
            nodeToDotHelper(o, t, nextId, 3L, "cond", "then", "else");
        }
        break;
    }
    case TRY_TYPE: {
        int n = chldNum(t);
        if (n == 3) {
            nodeToDotHelper(o, t, nextId, 3L, "try", "excep id", "catch");
        } else {
            nodeToDotHelper(o, t, nextId, 4L, "try", "excep id", "catch",
                            "finally");
        }
        break;
    }
    case WHILE_TYPE:
        nodeToDotHelper(o, t, nextId, 2L, "cond", "do");
        break;
    case FUN_TYPE:
        nodeToDotHelper(o, t, nextId, 3L, "name", "args", "body");
        break;
    case CALL_TYPE:
    case TAIL_CALL_TYPE:
        nodeToDotHelper(o, t, nextId, 2L, "name", "args");
        break;
    case LIST_ACCESS_TYPE:
        nodeToDotHelper(o, t, nextId, 2L, "list", "index");
        break;
    case FOR_TYPE:
        nodeToDotHelper(o, t, nextId, 4L, "init", "cond", "incr", "body");
        break;
    case FOREACH_TYPE:
        nodeToDotHelper(o, t, nextId, 3L, "id", "list", "body");
        break;
    default:
        error("unknown type %d in valueToStringInternal\n", t->type);
    }
    return id;
}