Esempio n. 1
0
int main() //@ : main
    //@ requires true;
    //@ ensures true;
{
    struct tree *t;
    bool b;
    
    struct list *l = create_list();
    list_push(l, 2);
    list_push(l, 3);
    list_push(l, 3);
    list_push(l, 1);
    //@ note(nat_of_int(3) == succ(succ(succ(zero))));
    b = build(l, &t);
    assert(b);
    char *result = check_tree(t, "NLNNLLL");
    assert(result != 0);
    list_dispose(l);
    
    l = create_list();
    list_push(l, 2);
    list_push(l, 2);
    list_push(l, 3);
    list_push(l, 1);
    b = build(l, &t);
    assert(!b);
    list_dispose(l);
    
    return 0;
}
Esempio n. 2
0
static void
file_information_dispose(file_information* info)
{
    if (info)
    {
        free(info->name);
        list_dispose(info->dependencies);
        free(info);
    }
}
Esempio n. 3
0
void release_command( cmdEntry cmd)
{
    if( NULL != cmd->release)
    {
        (*cmd->release)();
        cmd->release = NULL;
    }
    free(cmd->name);
    free(cmd->desc);
    list_dispose(cmd->para);
    free(cmd);
}
Esempio n. 4
0
File: main.c Progetto: Zeno-/gears
int main(void)
{
	List *mylist = list_new();
	ListNode *cnode;
	int i;
	int r = 0;

	if (!mylist)
		return 1;

#if 1
	for (i = 0; i < 15; i++) {
		struct intnode *newnode = malloc(sizeof(*newnode));
		if (!newnode) {
			r = 1;
			goto mallocerror;
		}
		newnode->v = i;
		list_prepend(mylist, (ListNode *)newnode);
		assert(list_contains_node(mylist, (ListNode *)newnode));
	}


#else
	for (i = 0; i < 5; i++) {
		struct intnode *newnode = malloc(sizeof(*newnode));
		if (!newnode) {
			r = 1;
			goto mallocerror;
		}
		newnode->v = i;
		list_append(mylist, (ListNode *)newnode);
	}


#endif

	printf("List length: %lu\n", (unsigned long)mylist->len);

#if 0
	for (cnode = list_head(mylist); cnode != NULL; cnode = list_next(mylist, cnode)) {
		printf("%d\n", ((struct intnode *)cnode)->v);
	}
#else
	list_traverse(mylist, print_intnode);
#endif

mallocerror:

	list_dispose(mylist);

	return r;
}
Esempio n. 5
0
void main() 
  //@ requires true;
  //@ ensures true;
{
  struct arraylist* a = create_arraylist();
  void* tmp = 0;
  list_add(a, (void *)10);
  list_add(a, (void *)20);
  
  tmp = list_get(a, 1);
  assert tmp == (void*) 20;
  list_dispose(a);
}
Esempio n. 6
0
void parsefile(FILE *f, list *instructions, list *labels) {
    list *lines = list_create();
    list_node *n;
    readfile(f, lines);

    for (n = list_get_root(lines); n != NULL; n = n->next) {
        cur_pos = cur_line = n->data;
        curline++;

        parseline(instructions, labels);
    }

    list_dispose(&lines, &free);
}
Esempio n. 7
0
int main(int argc, char **argv) {
    linked_list *list = list_init();
    void *val;

    printf("pushing \"foo\", \"bar\", \"baz\", and \"asdf\" into a queue\n");
    queue_push(list, (void *)"foo");
    queue_push(list, (void *)"bar");
    queue_push(list, (void *)"baz");
    queue_push(list, (void *)"asdf");
    list_print(list);
    printf("popping from queue: ");
    val = queue_pop(list);
    printf("%s\n", (char *)val);
    list_print(list);
    printf("popping from queue: ");
    val = queue_pop(list);
    printf("%s\n", (char *)val);
    list_print(list);

    printf("clearing list\n");
    list_clear(list);
    list_print(list);

    printf("pushing \"abc\", \"123\", and \"qwerty\" onto the stack\n");
    stack_push(list, (void *)"abc");
    stack_push(list, (void *)"123");
    stack_push(list, (void *)"qwerty");
    list_print(list);
    printf("popping from stack: ");
    val = stack_pop(list);
    printf("%s\n", (char *)val);
    list_print(list);
    printf("popping from stack: ");
    val = stack_pop(list);
    printf("%s\n", (char *)val);
    list_print(list);

    list_dispose(list);
    return 0;
}
Esempio n. 8
0
void parseline(list *instructions, list *labels) {
start:
    ;;
    dcpu16token tok = nexttoken();

    if (tok == T_COLON) {
        /* Label definition */
        if ((tok = nexttoken()) == T_IDENTIFIER) {
            dcpu16label *l = getnewlabel(labels, cur_tok.string);

            if (l->defined)
                error("Redefinition of label '%s' (%04X -> %04X) forbidden",
                        l->label, l->pc, pc);

            l->pc = pc;
            l->defined = 1;

            goto start;
        } else {
            error("Expected label, got %s", toktostr(tok));
        }
    } else if (is_instruction(tok)) {
        dcpu16instruction instr, *newinstr;

        instr.opcode = tok;
        instr.a = parseoperand(labels);

        if (!is_nonbasic_instruction(tok)) {
            if ((tok = nexttoken()) == T_COMMA) {
                instr.b = parseoperand(labels);
            } else {
                error("Expected ',', got %s", toktostr(tok));
            }
        }

        if ((tok = nexttoken()) != T_NEWLINE)
            error("Expected EOL, got %s", toktostr(tok));

        /*
         * All tokens valid, store instructions, advance PC
         */
        newinstr = malloc(sizeof(dcpu16instruction));
        memcpy(newinstr, &instr, sizeof(dcpu16instruction));

        newinstr->pc = pc;
        newinstr->line = curline;

        list_push_back(instructions, newinstr);

        pc += instruction_length(newinstr);

    } else if (is_macro(tok)) {
        if (tok == T_ORG) {
            if ((tok = nexttoken()) == T_NUMBER) {
                if (flag_paranoid && (cur_tok.number < pc)) {
                    warning("new origin precedes old origin! "
                            "This could cause already written code to be "
                            "overriden.");
                }

                pc = cur_tok.number;
            } else {
                error("Expected numeric, got %s", toktostr(tok));
            }
        } else if (tok == T_DAT) {
            /* All of the stuff we are about to read, neatly packed
             * into words */
            list_node *p = NULL;
            list *data = list_create();

            do {
                if ((tok = nexttoken()) == T_STRING) {
                    char *ptr = cur_tok.string;

                    while (*ptr != '\0') {
                        uint16_t *dat = malloc(sizeof(uint16_t));
                        *dat = *ptr++;

                        list_push_back(data, dat);
                    }
                } else if (tok == T_NUMBER) {
                    uint16_t *dat = malloc(sizeof(uint16_t));
                    *dat = cur_tok.number;

                    list_push_back(data, dat);
                } else {
                    error("Expected string or numeric, got %s", toktostr(tok));
                }

                if ((tok = nexttoken()) == T_COMMA)
                    continue;
                else if (tok == T_NEWLINE)
                    break;
                else
                    error("Expected ',' or EOL, got %s", toktostr(tok));
            } while (1);

            /*
            ram[pc++] = cur_tok.number;
            */
            for (p = list_get_root(data); p != NULL; p = p->next) {
                ram[pc++] = *((uint16_t*)p->data);
            }

            list_dispose(&data, &free);
        }
    } else if (tok == T_NEWLINE) {
        return;
    } else {
        error("Expected label-definition or opcode, got %s", toktostr(tok));
    }
}
Esempio n. 9
0
File: pq.c Progetto: rhennigan/code
void pq_dispose(pq_t * pq) {
  if (pq == NULL) return;
  list_dispose(pq->list);
  free(pq);
  pq = NULL;
}