Skip to content

Commit

Permalink
Refactor argument parser using cmdopt (#10)
Browse files Browse the repository at this point in the history
* Refactor by cmdopt
  • Loading branch information
mohanson authored Nov 1, 2023
1 parent bffa9b5 commit c8b2fae
Show file tree
Hide file tree
Showing 8 changed files with 542 additions and 101 deletions.
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

0 comments on commit c8b2fae

Please sign in to comment.