int main() { // memset(pqueue, 0LL, sizeof(pqueue)); for (int i = 0; i < 3; ++i) { pqueue[i] = 0; } pq_push(0); pq_push(1); printf("popped %4d\n", pq_pop()); printf("popped %4d\n", pq_pop()); printf("popped %4d\n", pq_pop()); pq_print(); // // test for __builtin_ctzll // printf("%d\n", __builtin_ctzll(0LL)); // 64 // printf("%d\n", __builtin_ctzll(1LL)); // 0 // printf("%d\n", __builtin_ctzll(8LL)); // 3 }
void run_script(pq_context *ctx, const char *filename) { char *contents = readfile(filename); const char *current = contents; int num_read_chars; pq_value *val; do { if((val = pq_read(ctx, current, &num_read_chars)) && (val = pq_eval(ctx, val))) { if(pq_is_error(val)) { pq_print(ctx, val); fputc('\n', stdout); break; } current += num_read_chars; } else { break; } } while(num_read_chars); free(contents); }
void repl(pq_context *ctx) { Replxx *replxx = replxx_init(); if(replxx == NULL) { fprintf(stderr, "Error initializing replxx\n"); return; } replxx_history_load(replxx, HISTORY_FILE); pq_value *val; const char *line; do { line = replxx_input(replxx, PROMPT_COLOR "pq" NORMAL_COLOR "> "); if(line == NULL) break; replxx_history_add(replxx, line); if((val = pq_read(ctx, line, NULL)) && (val = pq_eval(ctx, val))) { pq_print(ctx, val); fputc('\n', stdout); } } while(val); replxx_history_save(replxx, HISTORY_FILE); replxx_end(replxx); }