Ejemplo n.º 1
0
Archivo: swt.c Proyecto: 8l/go
static Node*
exprbsw(Case *c0, int ncase, int arg)
{
	NodeList *cas;
	Node *a, *n;
	Case *c;
	int i, half, lno;

	cas = nil;
	if(ncase < Ncase) {
		for(i=0; i<ncase; i++) {
			n = c0->node;
			lno = setlineno(n);

			if(assignop(n->left->type, exprname->type, nil) == OCONVIFACE ||
			   assignop(exprname->type, n->left->type, nil) == OCONVIFACE)
				goto snorm;

			switch(arg) {
			case Strue:
				a = nod(OIF, N, N);
				a->ntest = n->left;			// if val
				a->nbody = list1(n->right);			// then goto l
				break;

			case Sfalse:
				a = nod(OIF, N, N);
				a->ntest = nod(ONOT, n->left, N);	// if !val
				typecheck(&a->ntest, Erv);
				a->nbody = list1(n->right);			// then goto l
				break;

			default:
			snorm:
				a = nod(OIF, N, N);
				a->ntest = nod(OEQ, exprname, n->left);	// if name == val
				typecheck(&a->ntest, Erv);
				a->nbody = list1(n->right);			// then goto l
				break;
			}

			cas = list(cas, a);
			c0 = c0->link;
			lineno = lno;
		}
		return liststmt(cas);
	}

	// find the middle and recur
	c = c0;
	half = ncase>>1;
	for(i=1; i<half; i++)
		c = c->link;
	a = nod(OIF, N, N);
	a->ntest = nod(OLE, exprname, c->node->left);
	typecheck(&a->ntest, Erv);
	a->nbody = list1(exprbsw(c0, half, arg));
	a->nelse = list1(exprbsw(c->link, ncase-half, arg));
	return a;
}
Ejemplo n.º 2
0
Archivo: swt.c Proyecto: 8l/go
static Node*
typeone(Node *t)
{
	NodeList *init;
	Node *a, *b, *var;

	var = t->nname;
	init = nil;
	if(var == N) {
		typecheck(&nblank, Erv | Easgn);
		var = nblank;
	} else
		init = list1(nod(ODCL, var, N));

	a = nod(OAS2, N, N);
	a->list = list(list1(var), boolname);	// var,bool =
	b = nod(ODOTTYPE, facename, N);
	b->type = t->left->type;		// interface.(type)
	a->rlist = list1(b);
	typecheck(&a, Etop);
	init = list(init, a);

	b = nod(OIF, N, N);
	b->ntest = boolname;
	b->nbody = list1(t->right);		// if bool { goto l }
	a = liststmt(list(init, b));
	return a;
}
Ejemplo n.º 3
0
bool SimpleArray_UB16_1::typep(Value type) const
{
  if (consp(type))
    {
      Value type_specifier_atom = xcar(type);
      Value tail = xcdr(type);
      if (type_specifier_atom == S_array || type_specifier_atom == S_simple_array)
        {
          if (consp(tail))
            {
              Value element_type = xcar(tail);
              if (element_type == UNSPECIFIED)
                ; // ok
              else
                {
                  Value upgraded_element_type = upgraded_array_element_type(element_type);
                  if (::equal(upgraded_element_type, UB16_TYPE))
                    ; // ok
                  else if (::equal(upgraded_element_type,
                                   list3(S_integer, FIXNUM_ZERO, make_fixnum(65535))))
                    ; // ok
                  else if (::equal(upgraded_element_type,
                                   list3(S_integer, FIXNUM_ZERO, list1(make_fixnum(65536)))))
                    ; // ok
                  else
                    return false;
                }
              tail = xcdr(tail);
              if (tail == NIL)
                return true;
              if (cdr(tail) == NIL) // i.e. length(tail) == 1
                {
                  Value dimensions = xcar(tail);
                  if (dimensions == UNSPECIFIED)
                    return true;
                  if (dimensions == FIXNUM_ONE)
                    return true;
                  if (::equal(dimensions, list1(UNSPECIFIED)))
                    return true;
                  if (::equal(dimensions, list1(make_fixnum(_capacity))))
                    return true;
                }
            }
        }
    }
  else if (symbolp(type))
    {
      if (type == S_vector || type == S_sequence || type == S_simple_array
          || type == S_array || type == S_atom || type == T)
        return true;
    }
  else
    {
      if (type == C_vector || type == C_array || type == C_sequence || type == C_t)
        return true;
    }
  return false;
}
Ejemplo n.º 4
0
Archivo: nfa.c Proyecto: K0414/xcodexp
State *post2nfa(char *postfix)
{
    char *p = postfix;
    State *s;
    Frag stack[1000], *sp, e, e1, e2;

    #define push(e) *sp++ = e
    #define pop()   *--sp

    sp = stack;
    for(; *p; p++) {
        switch(*p) {
            default:  /* char */
                s = state(*p, NULL, NULL);
                push(frag(s, list1(&s->out)));
                break;
            case '|':  /* alternate */
                e2 = pop();
                e1 = pop();
                s = state(Split, e1.start, e2.start);
                push(frag(s, append(e1.outp, e2.outp)));
                break;
            case '?':  /* zero or one */
                e = pop();
                s = state(Split, e.start, NULL);
                push(frag(s, append(e.outp, list1(&s->out1))));
                break;
            case '+':  /* one or more */
                e = pop();
                s = state(Split, e.start, NULL);
                patch(e.outp, s);
                push(frag(e.start, list1(&s->out1)));
                break;
            case '*':  /* zero or more */
                e = pop();
                s = state(Split, e.start, NULL);
                patch(e.outp, s);
                push(frag(s, list1(&s->out1)));
                break;
            case '.':  /* catenate */
                e2 = pop();
                e1 = pop();
                patch(e1.outp, e2.start);
                push(frag(e1.start, e2.outp));
                break;
        }
    }

    e = pop();
    if(sp != stack)
        return NULL;

    patch(e.outp, &matchstate);
    return e.start;
#undef push
#undef pop
}
Ejemplo n.º 5
0
Node*
typebsw(Case *c0, int ncase)
{
	NodeList *cas;
	Node *a, *n;
	Case *c;
	int i, half;
	Val v;

	cas = nil;

	if(ncase < Ncase) {
		for(i=0; i<ncase; i++) {
			n = c0->node;

			switch(c0->type) {

			case Ttypenil:
				v.ctype = CTNIL;
				a = nod(OIF, N, N);
				a->ntest = nod(OEQ, facename, nodlit(v));
				typecheck(&a->ntest, Erv);
				a->nbody = list1(n->right);		// if i==nil { goto l }
				cas = list(cas, a);
				break;

			case Ttypevar:
				a = typeone(n);
				cas = list(cas, a);
				break;

			case Ttypeconst:
				a = nod(OIF, N, N);
				a->ntest = nod(OEQ, hashname, nodintconst(c0->hash));
				typecheck(&a->ntest, Erv);
				a->nbody = list1(typeone(n));
				cas = list(cas, a);
				break;
			}
			c0 = c0->link;
		}
		return liststmt(cas);
	}

	// find the middle and recur
	c = c0;
	half = ncase>>1;
	for(i=1; i<half; i++)
		c = c->link;
	a = nod(OIF, N, N);
	a->ntest = nod(OLE, hashname, nodintconst(c->hash));
	typecheck(&a->ntest, Erv);
	a->nbody = list1(typebsw(c0, half));
	a->nelse = list1(typebsw(c->link, ncase-half));
	return a;
}
Ejemplo n.º 6
0
void init_coll_functions(void)
{
    define_generic_function("element", list2(obj_CollClass, obj_ObjectClass),
                            false, list1(symbol("default")), false,
                            list1(obj_ObjectClass), obj_False);
    define_generic_function("element-setter",
                            list3(obj_ObjectClass, obj_CollClass,
                                  obj_ObjectClass),
                            false, obj_False, false,
                            list1(obj_ObjectClass), obj_False);
    define_generic_function("size", list1(obj_ObjectClass),
                            false, obj_False, false,
                            obj_Nil, obj_ObjectClass);
}
Ejemplo n.º 7
0
TEST(ContiguousContainerTest, Swap) {
  ContiguousContainer<Point2D, kPointAlignment> list1(kMaxPointSize);
  list1.allocateAndConstruct<Point2D>(1, 2);
  ContiguousContainer<Point2D, kPointAlignment> list2(kMaxPointSize);
  list2.allocateAndConstruct<Point2D>(3, 4);
  list2.allocateAndConstruct<Point2D>(5, 6);

  EXPECT_EQ(1u, list1.size());
  EXPECT_EQ(1, list1[0].x);
  EXPECT_EQ(2, list1[0].y);
  EXPECT_EQ(2u, list2.size());
  EXPECT_EQ(3, list2[0].x);
  EXPECT_EQ(4, list2[0].y);
  EXPECT_EQ(5, list2[1].x);
  EXPECT_EQ(6, list2[1].y);

  list2.swap(list1);

  EXPECT_EQ(1u, list2.size());
  EXPECT_EQ(1, list2[0].x);
  EXPECT_EQ(2, list2[0].y);
  EXPECT_EQ(2u, list1.size());
  EXPECT_EQ(3, list1[0].x);
  EXPECT_EQ(4, list1[0].y);
  EXPECT_EQ(5, list1[1].x);
  EXPECT_EQ(6, list1[1].y);
}
Ejemplo n.º 8
0
/* Add a new watch to watch-descriptor WD watching FILENAME and using
   IMASK and CALLBACK.  Return a cons (DESCRIPTOR . ID) uniquely
   identifying the new watch.  */
static Lisp_Object
add_watch (int wd, Lisp_Object filename,
	   uint32_t imask, Lisp_Object callback)
{
  Lisp_Object descriptor = INTEGER_TO_CONS (wd);
  Lisp_Object tail = assoc_no_quit (descriptor, watch_list);
  Lisp_Object watch, watch_id;
  Lisp_Object mask = INTEGER_TO_CONS (imask);

  EMACS_INT id = 0;
  if (NILP (tail))
    {
      tail = list1 (descriptor);
      watch_list = Fcons (tail, watch_list);
    }
  else
    {
      /* Assign a watch ID that is not already in use, by looking
	 for a gap in the existing sorted list.  */
      for (; ! NILP (XCDR (tail)); tail = XCDR (tail), id++)
	if (!EQ (XCAR (XCAR (XCDR (tail))), make_number (id)))
	  break;
      if (MOST_POSITIVE_FIXNUM < id)
	emacs_abort ();
    }

  /* Insert the newly-assigned ID into the previously-discovered gap,
     which is possibly at the end of the list.  Inserting it there
     keeps the list sorted.  */
  watch_id = make_number (id);
  watch = list4 (watch_id, filename, callback, mask);
  XSETCDR (tail, Fcons (watch, XCDR (tail)));

  return Fcons (descriptor, watch_id);
}
Ejemplo n.º 9
0
TEST(ContiguousContainerTest, AppendByMovingDoesNotDestruct) {
  // GMock mock objects (e.g. MockDestructible) aren't guaranteed to be safe
  // to memcpy (which is required for appendByMoving).
  class DestructionNotifier {
   public:
    DestructionNotifier(bool* flag = nullptr) : m_flag(flag) {}
    ~DestructionNotifier() {
      if (m_flag)
        *m_flag = true;
    }

   private:
    bool* m_flag;
  };

  bool destroyed = false;
  ContiguousContainer<DestructionNotifier> list1(sizeof(DestructionNotifier));
  list1.allocateAndConstruct<DestructionNotifier>(&destroyed);
  {
    // Make sure destructor isn't called during appendByMoving.
    ContiguousContainer<DestructionNotifier> list2(sizeof(DestructionNotifier));
    list2.appendByMoving(list1.last(), sizeof(DestructionNotifier));
    EXPECT_FALSE(destroyed);
  }
  // But it should be destroyed when list2 is.
  EXPECT_TRUE(destroyed);
}
Ejemplo n.º 10
0
INLINE_FUN SEXP lang2(SEXP s, SEXP t)
{
    PROTECT(s);
    s = LCONS(s, list1(t));
    UNPROTECT(1);
    return s;
}
Ejemplo n.º 11
0
// n is a multi-value function call.  Add t1, t2, .. = n to out
// and return the list t1, t2, ...
static NodeList*
copyret(Node *n, NodeList **out)
{
    Type *t;
    Node *tmp, *as;
    NodeList *l1, *l2;
    Iter tl;

    if(n->type->etype != TSTRUCT || !n->type->funarg)
        fatal("copyret %T %d", n->type, n->left->type->outtuple);

    l1 = nil;
    l2 = nil;
    for(t=structfirst(&tl, &n->type); t; t=structnext(&tl)) {
        tmp = temp(t->type);
        l1 = list(l1, tmp);
        l2 = list(l2, tmp);
    }

    as = nod(OAS2, N, N);
    as->list = l1;
    as->rlist = list1(n);
    typecheck(&as, Etop);
    orderstmt(as, out);

    return l2;
}
Ejemplo n.º 12
0
/* As above, but return the menu selection instead of storing in kb buffer.
   If KEYMAPS, return full prefixes to selection. */
Lisp_Object
find_and_return_menu_selection (struct frame *f, bool keymaps, void *client_data)
{
  Lisp_Object prefix, entry;
  int i;
  Lisp_Object *subprefix_stack;
  int submenu_depth = 0;

  prefix = entry = Qnil;
  i = 0;
  subprefix_stack = alloca (menu_items_used * word_size);

  while (i < menu_items_used)
    {
      if (EQ (AREF (menu_items, i), Qnil))
        {
          subprefix_stack[submenu_depth++] = prefix;
          prefix = entry;
          i++;
        }
      else if (EQ (AREF (menu_items, i), Qlambda))
        {
          prefix = subprefix_stack[--submenu_depth];
          i++;
        }
      else if (EQ (AREF (menu_items, i), Qt))
        {
          prefix
            = AREF (menu_items, i + MENU_ITEMS_PANE_PREFIX);
          i += MENU_ITEMS_PANE_LENGTH;
        }
      /* Ignore a nil in the item list.
         It's meaningful only for dialog boxes.  */
      else if (EQ (AREF (menu_items, i), Qquote))
        i += 1;
      else
        {
          entry
            = AREF (menu_items, i + MENU_ITEMS_ITEM_VALUE);
          if (aref_addr (menu_items, i) == client_data)
            {
              if (keymaps)
                {
                  int j;

                  entry = list1 (entry);
                  if (!NILP (prefix))
                    entry = Fcons (prefix, entry);
                  for (j = submenu_depth - 1; j >= 0; j--)
                    if (!NILP (subprefix_stack[j]))
                      entry = Fcons (subprefix_stack[j], entry);
                }
              return entry;
            }
          i += MENU_ITEMS_ITEM_LENGTH;
        }
    }
  return Qnil;
}
Ejemplo n.º 13
0
inline SimpleArray_UB32_1 * check_simple_array_ub32_1(Value value)
{
    if (simple_array_ub32_1_p(value))
        return the_simple_array_ub32_1(value);
    Value expected_type = list3(S_simple_array, S_unsigned_byte, list1(make_fixnum(32)));
    signal_type_error(value, expected_type);
    // Not reached.
    return NULL;
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
	std::vector<double> vdouble{1,2,3,4,5,6,7,8,9};	
	std::list<int> list1(vdouble.cbegin(),vdouble.cend());
	print_list(list1,"vector double initialize list<int>");

	std::vector<int> vint{4,5,6,8,9,10};
	std::list<int> list2(vint.cbegin(),vint.cend());
	print_list(list2,"vector int  initialize list<int>");

}
Ejemplo n.º 15
0
static Lisp_Object
make_dom (xmlNode *node)
{
    if (node->type == XML_ELEMENT_NODE)
    {
        Lisp_Object result = list1 (intern ((char *) node->name));
        xmlNode *child;
        xmlAttr *property;
        Lisp_Object plist = Qnil;

        /* First add the attributes. */
        property = node->properties;
        while (property != NULL)
        {
            if (property->children &&
                    property->children->content)
            {
                char *content = (char *) property->children->content;
                plist = Fcons (Fcons (intern ((char *) property->name),
                                      build_string (content)),
                               plist);
            }
            property = property->next;
        }
        result = Fcons (Fnreverse (plist), result);

        /* Then add the children of the node. */
        child = node->children;
        while (child != NULL)
        {
            result = Fcons (make_dom (child), result);
            child = child->next;
        }

        return Fnreverse (result);
    }
    else if (node->type == XML_TEXT_NODE || node->type == XML_CDATA_SECTION_NODE)
    {
        if (node->content)
            return build_string ((char *) node->content);
        else
            return Qnil;
    }
    else if (node->type == XML_COMMENT_NODE)
    {
        if (node->content)
            return list3 (intern ("comment"), Qnil,
                          build_string ((char *) node->content));
        else
            return Qnil;
    }
    else
        return Qnil;
}
Ejemplo n.º 16
0
int OMP_output_st_pragma(expv v)
{
    switch(OMP_st_flag){
    case OMP_ST_ATOMIC:
	output_statement(OMP_pragma_list(OMP_ATOMIC, list0(LIST), 
					 list1(EXPR_STATEMENT, v)));
	return TRUE;
    default:
	return FALSE;
    }
}
Ejemplo n.º 17
0
// create a tuple of signals
Tree sigCartesianProd (Tree s1, Tree s2)
{
	Tree 	l1, l2;
	int		m1, m2;

	if (isSigTuple(s1, &m1, l1) && (m1 == 0)) {
		// nothing to do
	} else {
		l1 = list1(s1);
	}

	if (isSigTuple(s2, &m2, l2) && (m2 == 0)) {
		// nothing to do
	} else {
		l2 = list1(s2);
	}


	return sigTuple(0, concat(l1,l2));
}
Ejemplo n.º 18
0
/* NOTE: retuns a *protected* object */
SEXP dybuf_alloc(unsigned long size, SEXP sConn) {
    SEXP s = PROTECT(allocVector(VECSXP, 2));
    SEXP r = SET_VECTOR_ELT(s, 0, list1(allocVector(RAWSXP, size)));
    dybuf_info_t *d = (dybuf_info_t*) RAW(SET_VECTOR_ELT(s, 1, allocVector(RAWSXP, sizeof(dybuf_info_t))));
    d->pos  = 0;
    d->size = size;
    d->tail = r;
    d->data = (char*) RAW(CAR(r));
    d->con  = (sConn && inherits(sConn, "connection")) ? R_GetConnection(sConn) : 0;
    return s;
}
Ejemplo n.º 19
0
TEST(ContiguousContainerTest, AppendByMovingReturnsMovedPointer) {
  ContiguousContainer<Point2D, kPointAlignment> list1(kMaxPointSize);
  ContiguousContainer<Point2D, kPointAlignment> list2(kMaxPointSize);

  Point2D& point = list1.allocateAndConstruct<Point2D>();
  Point2D& movedPoint1 = list2.appendByMoving(point, sizeof(Point2D));
  EXPECT_EQ(&movedPoint1, &list2.last());

  Point2D& movedPoint2 = list1.appendByMoving(movedPoint1, sizeof(Point2D));
  EXPECT_EQ(&movedPoint2, &list1.last());
  EXPECT_NE(&movedPoint1, &movedPoint2);
}
Ejemplo n.º 20
0
Archivo: swt.c Proyecto: 8l/go
static Node*
typebsw(Case *c0, int ncase)
{
	NodeList *cas;
	Node *a, *n;
	Case *c;
	int i, half;

	cas = nil;

	if(ncase < Ncase) {
		for(i=0; i<ncase; i++) {
			n = c0->node;
			if(c0->type != Ttypeconst)
				fatal("typebsw");
			a = nod(OIF, N, N);
			a->ntest = nod(OEQ, hashname, nodintconst(c0->hash));
			typecheck(&a->ntest, Erv);
			a->nbody = list1(n->right);
			cas = list(cas, a);
			c0 = c0->link;
		}
		return liststmt(cas);
	}

	// find the middle and recur
	c = c0;
	half = ncase>>1;
	for(i=1; i<half; i++)
		c = c->link;
	a = nod(OIF, N, N);
	a->ntest = nod(OLE, hashname, nodintconst(c->hash));
	typecheck(&a->ntest, Erv);
	a->nbody = list1(typebsw(c0, half));
	a->nelse = list1(typebsw(c->link, ncase-half));
	return a;
}
Ejemplo n.º 21
0
void
unexec (const char *new_name, const char *old_name)
{
  Lisp_Object data;
  Lisp_Object errstring;

  if (! dldump (0, new_name, RTLD_MEMORY))
    return;

  data = list1 (build_string (new_name));
  synchronize_system_messages_locale ();
  errstring = code_convert_string_norecord (build_string (dlerror ()),
					    Vlocale_coding_system, 0);

  xsignal (Qfile_error,
	   Fcons (build_string ("Cannot unexec"), Fcons (errstring, data)));
}
Ejemplo n.º 22
0
TEST(ContiguousContainerTest, AppendByMovingReplacesSourceWithNewElement) {
  ContiguousContainer<Point2D, kPointAlignment> list1(kMaxPointSize);
  ContiguousContainer<Point2D, kPointAlignment> list2(kMaxPointSize);

  list1.allocateAndConstruct<Point2D>(1, 2);
  EXPECT_EQ(1, list1.first().x);
  EXPECT_EQ(2, list1.first().y);

  list2.appendByMoving(list1.first(), sizeof(Point2D));
  EXPECT_EQ(0, list1.first().x);
  EXPECT_EQ(0, list1.first().y);
  EXPECT_EQ(1, list2.first().x);
  EXPECT_EQ(2, list2.first().y);

  EXPECT_EQ(1u, list1.size());
  EXPECT_EQ(1u, list2.size());
}
Ejemplo n.º 23
0
bool BackendIntegrationTests::contentsEqual( const TaskList& listref1,
                                             const TaskList& listref2 )
{
    TaskList list1( listref1 );
    TaskList list2( listref2 );

    for ( int i = 0; i < list1.size(); ++i )
    {
        for ( int j = 0; j < list2.size(); ++j )
        {
            if ( list2[j] == list1[i] ) {
                list2.removeAt( j );
            }
        }
    }

    return list2.isEmpty();
}
Ejemplo n.º 24
0
/*
	void GetAppList(const char *signature, BList *teamIDList) const
	@case 3			teamIDList is not NULL and not empty, signature is not
					NULL and app(s) with this signature is (are) running
	@results		Should append the team IDs of all running apps with the
					supplied signature to teamIDList.
*/
void GetAppListTester::GetAppListTestB3()
{
	const char *signature = "application/x-vnd.obos-app-run-testapp1";
	// create a list with some dummy entries
	BList list;
	list.AddItem((void*)-7);
	list.AddItem((void*)-42);
	// get a list of running applications for reference
	BRoster roster;
	BList list1(list);
	roster.GetAppList(signature, &list1);
	check_list(list1, list);
	// run some apps
	AppRunner runner1(true);
	AppRunner runner2(true);
	AppRunner runner3(true);
	CHK(runner1.Run("AppRunTestApp1") == B_OK);
	CHK(runner2.Run("AppRunTestApp2") == B_OK);
	CHK(runner3.Run("BMessengerTestApp1") == B_OK);
	BList expectedApps;
	expectedApps.AddItem((void*)runner1.Team());
	expectedApps.AddItem((void*)runner2.Team());
	// get a new app list and check it
	BList list2(list);
	roster.GetAppList(signature, &list2);
	check_list(list2, list, expectedApps);
	// quit app 1
	runner1.WaitFor(true);
	expectedApps.RemoveItem((void*)runner1.Team());
	BList list3(list);
	roster.GetAppList(signature, &list3);
	check_list(list3, list, expectedApps);
	// quit app 2
	runner2.WaitFor(true);
	expectedApps.RemoveItem((void*)runner2.Team());
	BList list4(list);
	roster.GetAppList(signature, &list4);
	check_list(list4, list, expectedApps);
	// quit app 3
	runner3.WaitFor(true);
	BList list5(list);
	roster.GetAppList(signature, &list5);
	check_list(list5, list, expectedApps);
}
Ejemplo n.º 25
0
int main(int argc, char *argv[]) {
	char *s;
	main_argv = argv;
	main_argc = argc;
	if (argc >= 2 && !strcmp(argv[1], "-t")) {
		timing_info = 1;
		s = argv[2];
	} else if (argc > 1) {
		s = argv[1];
	} else
		s = REPL_FILE;
	gettimeofday(&launch_time,NULL);
	init_scheme(HEAPSIZE,STACKSIZE,CODESIZE);
	define("system:*search-path*",list1(make_string(schemelib)));
	define("system:*repl-filename*",make_string(s));
	execute_file(BOOT_FILE);
	quit(0);
	return 0;
}
Ejemplo n.º 26
0
/* =========== CompareLists ================*/
TEST(LinkedListExcercisesTestSuite, CompareLists)
{
    int data1[5] = { 2, 4, 6, 7, 8 };
    LinkedList<int> list1(data1, 5);

    //test identical list
    LinkedList<int> list2(data1, 5);
    EXPECT_TRUE(LinkedListExercises::CompareLists(list1, list2));
    //test identical but shorter list
    LinkedList<int> list3(data1, 4);
    EXPECT_FALSE(LinkedListExercises::CompareLists(list1, list3));
    //test diffrent list
    int data2[4] = { 1, 3, 6, 7 };
    LinkedList<int> list4(data2, 4);
    EXPECT_FALSE(LinkedListExercises::CompareLists(list1, list4));
    //test empty
    LinkedList<int> empty_list1;
    LinkedList<int> empty_list2;
    EXPECT_TRUE(LinkedListExercises::CompareLists(empty_list1, empty_list2));
}
Ejemplo n.º 27
0
int _tmain(int argc, _TCHAR* argv[])
{
	LinerList<int> list(5);
	list.Insert(0,2);
	list.Insert(1,6);
	int z;
	list.Find(1,z);
	std::cout << z << std::endl;
	list.Insert(2,7);
	std ::cout << list << std::endl;

	LinerList<int> list1(list);
	list1.Insert(3,3);
	list1.Insert(4,89);
	std ::cout << list1 << std::endl;
	
	LinerList<int> list3 = list1.Half();
	std ::cout << list3 << std::endl;

	return 0;
}
Ejemplo n.º 28
0
void dybuf_add(SEXP s, const char *data, unsigned long len) {
    dybuf_info_t *d = (dybuf_info_t*) RAW(VECTOR_ELT(s, 1));
    unsigned long n = (d->pos + len > d->size) ? (d->size - d->pos) : len;
    if (!len) return;
    /* printf("[%lu/%lu] %lu\n", d->pos, d->size, len); */
    if (n) {
	memcpy(d->data + d->pos, data, n);
	d->pos += n;
	if (len == n) return;
	data += n;
	len -= n;
    }
    /* printf("[%lu/%lu] filled, need %lu more", d->pos, d->size, len); */

    /* if the output is connection-based, flush */
    if (d->con) {
	long wr;
	/* FIXME: should we try partial sends as well ? */
	if ((wr = R_WriteConnection(d->con, d->data, d->pos)) != d->pos)
	    Rf_error("write failed, expected %lu, got %ld", d->pos, wr);
	d->pos = 0;
	/* if the extra content is substantially big, don't even
	   bother storing it and send right away */
	if (len > (d->size / 2)) {
	    /* FIXME: (actually FIX R): WriteConnection should be using const void* */
	    if ((wr = R_WriteConnection(d->con, (void*) data, len)) != len)
		Rf_error("write failed, expected %lu, got %ld", len, wr);
	} else { /* otherwise copy into the buffer */
	    memcpy(d->data, data, len);
	    d->pos = len;
	}
    } else { /* need more buffers */
	SEXP nb;
	while (len > d->size) d->size *= 2;
	/* printf(", creating %lu more\n", d->size); */
	d->tail = SETCDR(d->tail, list1(nb = allocVector(RAWSXP, d->size)));
	memcpy(d->data = (char*) RAW(nb), data, len);
	d->pos = len;
    }
}
Ejemplo n.º 29
0
static Lisp_Object
x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
			 Lisp_Object time_stamp, Lisp_Object frame)
{
  struct frame *f = XFRAME (frame);
  OSStatus err;
  Selection sel;
  Lisp_Object result = Qnil;

  if (!FRAME_LIVE_P (f))
    return Qnil;

  block_input ();

  err = mac_get_selection_from_symbol (selection_symbol, 0, &sel);
  if (err == noErr && sel)
    {
      if (EQ (target_type, QTARGETS))
	{
	  Lisp_Object args[2];

	  args[0] = list1 (QTARGETS);
	  args[1] = mac_get_selection_target_list (sel);
	  result = Fvconcat (2, args);
	}
      else
	{
	  result = mac_get_selection_value (sel, target_type);
	  if (STRINGP (result))
	    Fput_text_property (make_number (0), make_number (SBYTES (result)),
				Qforeign_selection, target_type, result);
	}
    }

  unblock_input ();

  return result;
}
Ejemplo n.º 30
0
Archivo: racewalk.c Proyecto: 8l/go
void
racewalk(Node *fn)
{
	Node *nd;
	Node *nodpc;
	char s[1024];

	if(ispkgin(omit_pkgs, nelem(omit_pkgs)) || isforkfunc(fn))
		return;

	if(!ispkgin(noinst_pkgs, nelem(noinst_pkgs))) {
		racewalklist(fn->nbody, nil);
		// nothing interesting for race detector in fn->enter
		racewalklist(fn->exit, nil);
	}

	// nodpc is the PC of the caller as extracted by
	// getcallerpc. We use -widthptr(FP) for x86.
	// BUG: this will not work on arm.
	nodpc = nod(OXXX, nil, nil);
	*nodpc = *nodfp;
	nodpc->type = types[TUINTPTR];
	nodpc->xoffset = -widthptr;
	nd = mkcall("racefuncenter", T, nil, nodpc);
	fn->enter = concat(list1(nd), fn->enter);
	nd = mkcall("racefuncexit", T, nil);
	fn->exit = list(fn->exit, nd);

	if(debug['W']) {
		snprint(s, sizeof(s), "after racewalk %S", fn->nname->sym);
		dumplist(s, fn->nbody);
		snprint(s, sizeof(s), "enter %S", fn->nname->sym);
		dumplist(s, fn->enter);
		snprint(s, sizeof(s), "exit %S", fn->nname->sym);
		dumplist(s, fn->exit);
	}
}