Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor argument parser using cmdopt #10

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ LDFLAGS += -Ldeps/compiler-rt-builtins-riscv/build -lcompiler-rt
OBJDIR=build

QJS_OBJS=$(OBJDIR)/qjs.o $(OBJDIR)/quickjs.o $(OBJDIR)/libregexp.o $(OBJDIR)/libunicode.o \
$(OBJDIR)/cutils.o $(OBJDIR)/mocked.o $(OBJDIR)/std_module.o $(OBJDIR)/ckb_module.o $(OBJDIR)/ckb_cell_fs.o $(OBJDIR)/libbf.o
$(OBJDIR)/cutils.o $(OBJDIR)/mocked.o $(OBJDIR)/std_module.o $(OBJDIR)/ckb_module.o $(OBJDIR)/ckb_cell_fs.o \
$(OBJDIR)/libbf.o $(OBJDIR)/cmdopt.o

STD_OBJS=$(OBJDIR)/string_impl.o $(OBJDIR)/malloc_impl.o $(OBJDIR)/math_impl.o \
$(OBJDIR)/math_log_impl.o $(OBJDIR)/math_pow_impl.o $(OBJDIR)/printf_impl.o $(OBJDIR)/stdio_impl.o \
Expand Down Expand Up @@ -81,7 +82,7 @@ test:

benchmark:
make -f tests/benchmark/Makefile

clean:
rm -f build/*.o
rm -f build/ckb-js-vm
Expand Down
7 changes: 7 additions & 0 deletions include/c-stdlib/src/printf_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,3 +1011,10 @@ int ckb_printf(const char *format, ...) {
ckb_debug(buf);
return ret;
}

int ckb_vprintf(const char *format, va_list va) {
static char buf[CKB_C_STDLIB_PRINTF_BUFFER_SIZE];
int ret = vsnprintf(buf, CKB_C_STDLIB_PRINTF_BUFFER_SIZE, format, va);
ckb_debug(buf);
return ret;
}
14 changes: 14 additions & 0 deletions quickjs/ckb_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,20 @@ int js_init_module_ckb(JSContext *ctx) {
#define JS_LOADER_ARGS_SIZE 2
#define BLAKE2B_BLOCK_SIZE 32

int load_cell_code_info_explicit(size_t *buf_size, size_t *index, const uint8_t* code_hash, uint8_t hash_type) {
int err = 0;
*index = 0;
err = ckb_look_for_dep_with_hash2(code_hash, hash_type, index);
CHECK(err);

*buf_size = 0;
err = ckb_load_cell_data(NULL, buf_size, 0, *index, CKB_SOURCE_CELL_DEP);
CHECK(err);
CHECK2(*buf_size > 0, -1);
exit:
return err;
}

int load_cell_code_info(size_t *buf_size, size_t *index) {
int err = 0;
unsigned char script[SCRIPT_SIZE];
Expand Down
1 change: 1 addition & 0 deletions quickjs/ckb_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
int js_init_module_ckb(JSContext *ctx);
int read_local_file(char *buf, int size);

int load_cell_code_info_explicit(size_t *buf_size, size_t *index, const uint8_t* code_hash, uint8_t hash_type);
int load_cell_code_info(size_t *buf_size, size_t *index);
int load_cell_code(size_t buf_size, size_t index, uint8_t *buf);

Expand Down
Loading