Skip to content

Commit

Permalink
fix: cleanup code and adopt platform header detection
Browse files Browse the repository at this point in the history
introduce new platform defines and remove old exec-headers
  • Loading branch information
jaromil committed Dec 22, 2024
1 parent 46efd90 commit a9d188b
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 226 deletions.
32 changes: 8 additions & 24 deletions src/cjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*
*/

#include <cjit.h>

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand All @@ -25,16 +27,12 @@
#include <ctype.h>
#include <unistd.h>

#if !defined(_WIN32)
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/poll.h>
#endif

#include <ketopt.h>
#include <cjit.h>

// from win-compat.c
extern void win_compat_usleep(unsigned int microseconds);
extern ssize_t win_compat_getline(char **lineptr, size_t *n, FILE *stream);
extern bool get_winsdkpath(char *dst, size_t destlen);

void handle_error(void *n, const char *m) {
(void)n;
Expand Down Expand Up @@ -137,17 +135,7 @@ int main(int argc, char **argv) {
_err("CJIT %s by Dyne.org",VERSION);
// _err("Running version: %s\n",VERSION);
// version is always shown
#if defined(CJIT_BUILD_WIN)
_err("Build: WINDOWS");
#elif defined(CJIT_BUILD_MUSL)
_err("Build: MUSL");
#elif defined(CJIT_BUILD_OSX)
_err("Build: OSX");
#elif defined(CJIT_BUILD_LINUX)
_err("Build: LINUX");
#else
_err("Build: UNKNOWN");
#endif
_err("Build: %s",PLATFORM);
#if defined(CJIT_DEBUG_ASAN)
_err("Debug: ASAN");
#elif defined(CJIT_DEBUG_GDB)
Expand Down Expand Up @@ -377,11 +365,7 @@ int main(int argc, char **argv) {
// number of args at the left hand of arg separator, or all of them
int right_args = argc-left_args+1;//arg_separator? argc-arg_separator : 0;
char **right_argv = &argv[left_args-1];//arg_separator?&argv[arg_separator]:0
#if !defined(_WIN32)
res = cjit_exec_fork(TCC, &CJIT, entry, right_args, right_argv);
#else
res = cjit_exec_win(TCC, &CJIT, entry, right_args, right_argv);
#endif
res = cjit_exec(TCC, &CJIT, entry, right_args, right_argv);

endgame:
// free TCC
Expand Down
56 changes: 28 additions & 28 deletions src/cjit.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
/* CJIT https://dyne.org/cjit
*
* Copyright (C) 2024 Dyne.org foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#ifndef _CJIT_H_
#define _CJIT_H_

#include <platforms.h>
#include <stdbool.h>
#include <libtcc.h>

// passed to cjit_exec_fork with CJIT execution parameters
// passed to cjit_exec with CJIT execution parameters
struct CJITState {
char *tmpdir;
char *write_pid; // filename to write the pid of execution
Expand All @@ -13,12 +33,15 @@ struct CJITState {
};
typedef struct CJITState CJITState;

extern bool free_cjit(CJITState *CJIT);


// from embedded.c - generated at build time
extern bool extract_embeddings(CJITState *CJIT);

// implemented in repl.c
extern int cjit_exec(TCCState *TCC, CJITState *CJIT,
const char *ep, int argc, char **argv);

extern bool free_cjit(CJITState *CJIT);

/////////////
// from file.c
extern int detect_bom(const char *filename);
Expand All @@ -28,36 +51,13 @@ extern char *load_stdin();
extern char* dir_load(const char *path);
extern bool write_to_file(const char *path, const char *filename,
const char *buf, unsigned int len);

#if defined(_WIN32)
bool win32_mkdtemp(CJITState *CJIT);
// from win-compat.c
extern void win_compat_usleep(unsigned int microseconds);
extern ssize_t win_compat_getline(char **lineptr, size_t *n, FILE *stream);
extern bool get_winsdkpath(char *dst, size_t destlen);
#else
bool posix_mkdtemp(CJITState *CJIT);
#endif
// from io.c
extern void _out(const char *fmt, ...);
extern void _err(const char *fmt, ...);
// from repl.c
#if defined(_WIN32)
extern int cjit_exec_win(TCCState *TCC, CJITState *CJIT,
const char *ep, int argc, char **argv);
#else
extern int cjit_exec_fork(TCCState *TCC, CJITState *CJIT,
const char *ep, int argc, char **argv);
#endif

extern int cjit_cli_tty(TCCState *TCC);
#ifdef KILO_SUPPORTED
extern int cjit_cli_kilo(TCCState *TCC);
#endif
// from embed-dmon.c
extern char *lib_dmon_dmon_extra_h;
extern unsigned int lib_dmon_dmon_extra_h_len;
extern char *lib_dmon_dmon_h;
extern unsigned int lib_dmon_dmon_h_len;
/////////////

#endif
132 changes: 0 additions & 132 deletions src/exec-headers.c

This file was deleted.

Loading

0 comments on commit a9d188b

Please sign in to comment.