Skip to content

Commit

Permalink
build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
inimino committed Jun 29, 2024
1 parent 241050e commit c97a92f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ LDFLAGS := -lm
debug: CFLAGS := -g -O0 -Wall -fsanitize=address
debug: dist/cmpr

dev: CFLAGS := -O2 -Wall -Werror -fsanitize=address
# TODO: we should put the different builds in different output directories; currently switching requires `make -B` as the .o files will be incompatible due to libasan

dev: CFLAGS := -g -O2 -Wall -Werror -fsanitize=address
dev: dist/cmpr

dist/cmpr: cmpr.c fdecls.h spanio.c siphash/siphash.o siphash/halfsiphash.o
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ So the block size is determined by the amount of code that the LLM can write "in

## Quick start:

0. Recommended: look at some of the sample code above or watch the 2048 demo video to see if the idea appeals to you; consider experimenting with bare ChatGPT program generation first if you haven't already.
0. Recommended: look at some of the sample code above or watch the 2048 demo video; consider experimenting with bare ChatGPT program generation first.
1. Get the code and build; assuming git repo at ~/cmpr and you have gcc, `cd cmpr && make && sudo make install` should do.
2. Go to (or create) the directory for your project and run `cmpr --init`, this creates a `.cmpr/` directory (like git) with a conf file and some other stuff.
2. Go to (or create) the directory for your project and run `cmpr --init`, this creates a `.cmpr/` directory and makes this a cmpr project.
3. `export EDITOR=emacs` or whatever editor you want to use, otherwise just `vi` will be run by default.
4. Run `cmpr --init` in your project directory, then `cmpr` and it will ask you some configuration questions.
4. Run `cmpr` in your project directory, and it will ask you some configuration questions.
If you want to change the answers later, you can edit the .cmpr/conf file.
5. Right now things are rough and changing all the time, so stop by discord and ask if you hit any roadblocks!

Expand Down
33 changes: 19 additions & 14 deletions cmpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ void call_llm(span model, json messages, void (*cb)(span)) {
}

if (!result.success) {
prt("Error: %.*s", len(result.error), result.error.buf);
prt("Error: %.*s\n", len(result.error), result.error.buf);
prt("Hit any key to continue...\n");
flush();
getch(); // User acknowledgment to move past error
} else {
Expand Down Expand Up @@ -1635,10 +1636,16 @@ We write the filename into our filenames buffer, and then construct a span that
Next we write a comparator function to use with qsort, which compares to spans using span_cmp.
(Note that span_cmp does not have the required signature for use with qsort; we must write a wrapper function directly before the call to qsort that does.)
We use qsort to sort all the filename spans lexicographically (which is also chronologically, due to our naming scheme).
Also, clang does not allow functions to be nested, even though gcc does, so we declare this function immediately before get_revs itself.
Finally, we call get_revs_2, which handles the rest of the work.
*/

// note: fix for clang
int span_cmp_wrapper(const void *a, const void *b) {
return span_cmp(*(span *)a, *(span *)b);
}

void get_revs() {
span revdir = get_revdir();
DIR *dir = opendir(s(revdir));
Expand Down Expand Up @@ -1690,11 +1697,6 @@ void get_revs() {

closedir(dir);

int span_cmp_wrapper(const void *a, const void *b)
{
return span_cmp(*(span *)a, *(span *)b);
}

qsort(state->revs.filenames.a, state->revs.filenames.n, sizeof(span), span_cmp_wrapper);

/*
Expand Down Expand Up @@ -2821,11 +2823,20 @@ We allocate a checksums of this many.
Then we take lines one by one, get the selected checksum for each one, and add it to the checksums.
We sort the checksums using qsort.
For this we need to declare a comparator function inline, handling the void* type that qsort expects.
For this we need to declare a comparator function, handling the void* type that qsort expects.
Though gcc does allow this function to be declared inline, for compatibility with clang we declare it immediately before sorted_line_checksums itself.
We remove duplicates by keeping track of an offset and overwriting forward in a single pass over the sorted list.
*/

// fix for clang
int checksum_cmp(const void* a, const void* b) {
const checksum* cksum1 = (const checksum*)a;
const checksum* cksum2 = (const checksum*)b;
return (cksum1->__u > cksum2->__u) - (cksum1->__u < cksum2->__u);
}

checksums sorted_line_checksums(span input) {
int line_count = 0;
span temp = input;
Expand All @@ -2842,12 +2853,6 @@ checksums sorted_line_checksums(span input) {
checksums_push(&cksums, cksum);
}

int checksum_cmp(const void* a, const void* b) {
const checksum* cksum1 = (const checksum*)a;
const checksum* cksum2 = (const checksum*)b;
return (cksum1->__u > cksum2->__u) - (cksum1->__u < cksum2->__u);
}

qsort(cksums.a, cksums.n, sizeof(checksum), checksum_cmp);

int offset = 0;
Expand Down Expand Up @@ -4843,7 +4848,7 @@ int launch_editor(char* filename) {
editor = "vi"; // Default to vi if EDITOR is not set
}

pid_t pid = fork();
pid_t pid = vfork();
if (pid == -1) {
perror("fork failed");
exit(EXIT_FAILURE);
Expand Down
2 changes: 1 addition & 1 deletion conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmprdir: .cmpr
cmprdir: .cmpr/
buildcmd: make dev && ctags spanio.c cmpr.c
bootstrap: ./bootstrap.sh
cbcopy: xclip -i -selection clipboard
Expand Down

0 comments on commit c97a92f

Please sign in to comment.