Skip to content

Commit

Permalink
fix: adjust verbosity and remove debug messages
Browse files Browse the repository at this point in the history
also add demo setup scripts for tutorial
  • Loading branch information
jaromil committed Dec 30, 2024
1 parent 839591d commit 1521a96
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
12 changes: 12 additions & 0 deletions docs/demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Write-Host ""
Write-Host "Welcome to CJIT!"
Write-Host "We'll be downloading our quick demo setup, please wait a bit,"
Write-Host "then all will be found inside the 'cjit-demo' folder right here."
Invoke-WebRequest -OutFile "cjit.exe" -Uri "https://github.com/dyne/cjit/releases/latest/download/cjit.exe"
Invoke-WebRequest -OutFile "cjit-demo.tar.gz" -Uri "https://github.com/dyne/cjit/releases/latest/download/cjit-demo.tar.gz"
.\cjit.exe --xtgz cjit-demo.tar.gz
cp .\cjit.exe cjit-demo
cd cjit-demo
Write-Host "Ready to start! Follow the tutorial:"
Write-Host " --> https://dyne.org/docs/cjit <--"
Write-Host ""
16 changes: 16 additions & 0 deletions docs/demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
set -e
echo
echo "Welcome to CJIT!"
echo "We'll be downloading our quick demo setup, please wait a bit,"
echo "then all will be found inside the 'cjit-demo' folder right here."
curl -sLo cjit https://github.com/dyne/cjit/releases/latest/download/cjit-$(uname)-$(uname -m)
chmod +x cjit
curl -sLo cjit-demo.tar.gz https://github.com/dyne/cjit/releases/latest/download/cjit-demo.tar.gz
./cjit --xtgz cjit-demo.tar.gz
cp ./cjit cjit-demo/
cd cjit-demo
echo "Ready to start! Follow the tutorial:"
echo " --> https://dyne.org/docs/cjit <--"
echo
exit 0
22 changes: 6 additions & 16 deletions src/cjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#define tcc(cjit) (TCCState*)cjit->TCC
#define setup if(!cjit->done_setup)cjit_setup(cjit)
#define debug(fmt,par) if(!cjit->quiet)_err(fmt,par)
#define debug(fmt,par) if(cjit->verbose)_err(fmt,par)
// declared at bottom
void _out(const char *fmt, ...);
void _err(const char *fmt, ...);
Expand Down Expand Up @@ -534,25 +534,25 @@ void cjit_set_output(CJITState *cjit, int output) {
}
void cjit_define_symbol(CJITState *cjit, const char *sym, const char *value) {
tcc_define_symbol(tcc(cjit),sym,value);
if(!cjit->quiet)_err("+D %s",sym,value?value:"");
if(cjit->verbose)_err("+D %s %s",sym,value?value:"");
}
void cjit_add_include_path(CJITState *cjit, const char *path) {
tcc_add_include_path(tcc(cjit), path);
if(!cjit->quiet)_err("+I %s",path);
debug("+I %s",path);
}
// TODO: temporary, to be reimplemented in linker.c
void cjit_add_library_path(CJITState *cjit, const char *path) {
tcc_add_library_path(tcc(cjit), path);
if(!cjit->quiet)_err("+L %s",path);
debug("+L %s",path);
}
// TODO: temporary, to be reimplemented in linker.c
void cjit_add_library(CJITState *cjit, const char *path) {
tcc_add_library(tcc(cjit), path);
if(!cjit->quiet)_err("+l %s",path);
debug("+l %s",path);
}
void cjit_set_tcc_options(CJITState *cjit, const char *opts) {
tcc_set_options(tcc(cjit),opts);
if(!cjit->quiet)_err("+O %s",opts);
debug("+O %s",opts);
}

// stdout message free from context
Expand All @@ -564,11 +564,7 @@ void _out(const char *fmt, ...) {
va_end(args);
msg[len] = '\n';
msg[len+1] = 0x0; //safety
#if defined(__EMSCRIPTEN__)
EM_ASM_({Module.print(UTF8ToString($0))}, msg);
#else
write(fileno(stdout), msg, len+1);
#endif
}

// error message free from context
Expand All @@ -581,11 +577,5 @@ void _err(const char *fmt, ...) {
va_end(args);
msg[len] = '\n';
msg[len+1] = 0x0;
#if defined(__EMSCRIPTEN__)
EM_ASM_({Module.printErr(UTF8ToString($0))}, msg);
#elif defined(__ANDROID__)
__android_log_print(ANDROID_LOG_ERROR, "ZEN", "%s", msg);
#else
write(fileno(stderr),msg,len+1);
#endif
}
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ int main(int argc, char **argv) {

} else if(opt.ind < left_args) {
// process files on commandline before separator
if(!CJIT->quiet)_err("Source code:");
if(CJIT->verbose)_err("Source code:");
for (i = opt.ind; i < left_args; ++i) {
const char *code_path = argv[i];
if(!CJIT->quiet)_err("%c %s",(*code_path=='-'?'|':'+'),
if(CJIT->verbose)_err("%c %s",(*code_path=='-'?'|':'+'),
(*code_path=='-'?"standard input":code_path));
if(*code_path=='-') { // stdin explicit
#if defined(_WIN32)
Expand Down

0 comments on commit 1521a96

Please sign in to comment.