5 ms·
Can you give some directions for how to run it? $ git clone https://github.com/tekknolagi/carp $ make $ ./carp $ ./carp --help # after peeking in carp
by akkartik 12y ago
Can you give some directions for how to run it?
$ git clone https://github.com/tekknolagi/carp
$ make
$ ./carp
$ ./carp --help # after peeking in carp.c
help msg
There's a tantalizing target called 'tests' in the Makefile, but it doesn't work.
There's some examples, but no makefile to build them. How do you run them?
I see you used to have some .carp files but you just deleted them: https://github.com/tekknolagi/carp/commit/fa16eeb443 https://github.com/tekknolagi/carp/commit/fa16eeb443
I tried restoring one, but it doesn't work:
$ git checkout fa16eeb443~1 examples/reg.carp
$ ./carp -f examples/reg.carp
Unknown label <add>
So at this point I'm ready to give up..
- tekknolagi 12y agoHi there! Sorry for this. I actually have a help message but for some reason I forgot to commit it. It's coming soon! You run the examples like so: carp -f examples/carp/call.carp You can compile C files that use the Carp API, but I have not written any documentation yet.
- tekknolagi 12y agoOh that's weird. the carp folder from examples disappeared. Gimme a sec.
- tekknolagi 12y agoAlright, try now. Also — thanks for the pull request!
- akkartik 12y agoYou're welcome. I pulled the new commits, but I'm still having trouble running the examples: $ ./carp -f examples/carp/call.carp Unknown label <add> (I am very interested in building easy-to-understand codebases: http://akkartik.name/post/wart http://akkartik.name/post/wart)
- tekknolagi 12y agoThat's strange: http://i.imgur.com/TbF7Izc.png http://i.imgur.com/TbF7Izc.png Try rebuilding carp? o.O That was some very nice documentation!
- akkartik 12y agoNope, rebuilding didn't help.. never mind, I'll look into it later tonight. Edit: I just noticed you changed the target (why?) and are also immediately deleting carp.out. So I was indeed using the stale version in spite of using 'make clean' :) Anyways, so I did this, but still no luck. $ git diff diff --git a/Makefile b/Makefile index f921d96..7c55b4e 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,6 @@ all: $(CC) $(CFLAGS) $(SRCS) ar cr libcarp.a $(OBJS) $(CC) src/carp.c libcarp.a -o $(PROG) - make clean_objs #.PHONY: tests $ make gcc -c -std=c99 -Wall -Werror -Wno-unused-variable -Wno-format-security -O3 -static src/carp_instructions.c src/carp_lexer.c src/carp_machine.c src/carp_tokenizer.c src/lib/carp_stack.c src/lib/carp_ht.c ar cr libcarp.a *.o gcc src/carp.c libcarp.a -o carp.out $ ./carp.out -f reg.carp Unknown label <add>
- tekknolagi 12y agoSo strange.
- akkartik 12y agoIn the process of debugging it I noticed that you're compiling but not linking in c99 mode. When I fix that the problem seems to go away: $ git diff diff --git a/Makefile b/Makefile index 1263dd8..6592c59 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ CC = gcc #/usr/local/bin/gcc-4.2 PREFIX = /usr/local NDEBUG ?= -CFLAGS = -c -std=c99 -Wall -Werror -Wno-unused-variable -Wno-format-security -O3 -static $(NDEBUG) +CFLAGS = -std=c99 -Wall -Werror -Wno-unused-variable -Wno-format-security -O3 -static $(NDEBUG) SRCS = src/carp_instructions.c src/carp_lexer.c src/carp_machine.c src/carp_tokenizer.c src/lib/carp_stack.c src/lib/carp_ht.c #$(wildcard src/*.c src/lib/*.c) OBJS = *.o PROG = carp.out all: - $(CC) $(CFLAGS) $(SRCS) + $(CC) -c $(CFLAGS) $(SRCS) ar cr libcarp.a $(OBJS) - $(CC) src/carp.c libcarp.a -o $(PROG) + $(CC) $(CFLAGS) src/carp.c libcarp.a -o $(PROG) #.PHONY: tests Still, I'm concerned that you might be triggering some sort of undefined behavior, which means it might work for you but not on a slightly different machine or compiler version. I tried printing out token lexemes in carp_run_program, right after the call to tokenize(), and some of the tokens printed binary garbage, suggesting that they might be missing a terminating null, or worse. Does this look right? $ git diff ... diff --git a/src/carp.c b/src/carp.c index 9268d98..19e16d9 100644 --- a/src/carp.c +++ b/src/carp.c @@ -88,6 +88,8 @@ void carp_print_conditions () { void carp_run_program (char *fn) { carp_tok *tokens = carp_lex_tokenize(fn); + for (carp_tok* tt = tokens; tt; tt=tt->next) + printf("%s %d\n", tt->lexeme, tt->type); if (tokens == NULL) { fprintf(stderr, "Something went wrong with tokenization.\n"); exit(1); $ make && ./carp.out -f ./examples/carp/call.carp gcc -c -std=c99 -Wall -Werror -Wno-unused-variable -Wno-format-security -O3 -static src/carp_instructions.c src/carp_lexer.c src/carp_machine.c src/carp_tokenizer.c src/lib/carp_stack.c src/lib/carp_ht.c ar cr libcarp.a *.o gcc -std=c99 -Wall -Werror -Wno-unused-variable -Wno-format-security -O3 -static src/carp.c libcarp.a -o carp.out add 3 gload 6 -5l 1 gload 6 -4l 1 add 6 ret 6 main 3 push 6 7�l 1 push 6 9�l 1 call 6 add 4 2 1 ptop 6 halt 6 0 1 16 The trouble with C/C++ is that it's so easy to end up with undefined behavior :/
- proxyswapi 12y agoA year (or two) ago, I wrote a simple virtual machine [1] of my own. Fun time. Interesting exercise. Wish I had courage to post it here and get feedback from the HN. Anyways, yours is much cleaner and concise code. Kudos. [1] https://github.com/swapi/z9 https://github.com/swapi/z9
- tekknolagi 12y agoDefinitely post it! I've written muuuuch worse and it's still public :D Check out http://github.com/tekknolagi/gecho http://github.com/tekknolagi/gecho — shudder
- proxyswapi 12y agoPosted my reply on wrong comment (Got confused between akkartik and tekknolagi) :). Anyways, thanks for sharing. Are you planning to add memory management opcodes (Allocate memory, free memory)? I see DBS, DBG instruction, but it is like key-value store (since it uses carp_ht internally).
- tekknolagi 12y agoUmm perhaps. Could you give a use case? Not sure how/why.