diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | build64.bat | 2 | ||||
-rw-r--r-- | foreign_msvc64.c | 2 | ||||
-rw-r--r-- | win64call.asm | 2 |
5 files changed, 15 insertions, 4 deletions
@@ -19,3 +19,4 @@ docs/*.html *.ilk *.obj *.exe +.vs @@ -30,7 +30,15 @@ See `docs` for more information (in progress). To compile the compiler on a Unix-y system, just run `./build.sh release` (or `make release`). You can supply a compiler by running `CC=tcc ./build.sh release`, or build it in debug mode without the `release`. To disable compile time foreign function support (which you will need to do if you don't have ffcall/dl), prefix this with `COMPILE_TIME_FOREIGN_FN_SUPPORT=no`. -On other systems, you can just compile main.c with a C compiler. `toc` uses several C99 and a couple of C11 features, so it might not work on all compilers. But it does compile on quite a few, including `clang`, `gcc`, and `tcc`. It can also be compiled as if it were C++, so and `g++` can also compile it (it does rely on implicit casting of `void *` though). MSVC can also compile toc. The *outputted* code should be C99-compliant. +On Windows, first make sure the compiler works from the command line. You can follow the instructions here: +https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line . +You can run `build32.bat release` or `build64.bat release` depending on whether you want a 32-bit or 64-bit version of toc. + +On other systems, you can just compile main.c with a C compiler. +By default, toc will use libdl and libffcall. If you don't have these installed, add the preprocessor define `COMPILE_TIME_FOREIGN_FN_SUPPORT=0`. +This is usually done with `-DCOMPILE_TIME_FOREIGN_FN_SUPPORT=0`. + +`toc` uses several C99 and a couple of C11 features, so it might not work on all compilers. But it does compile on quite a few, including `clang`, `gcc`, `tcc`, and MSVC. It can also be compiled as if it were C++, so and `g++` can also compile it (it does rely on implicit casting of `void *` though). The *outputted* code should be C99-compliant. #### Why it compiles to C @@ -54,7 +62,7 @@ See `LICENSE` for the GNU General Public License. ##### Why? This improves compilation speeds (especially from scratch), since you don't have to include headers a bunch of times for each translation unit. This is more of a problem in C++, where, for example, doing `#include <map>` ends up turning into 25,000 lines after preprocessing. All of toc's source code, which includes most of the C standard library, at the time of this writing (Dec 2019) is only 22,000 lines after preprocessing; imagine including all of that once for each translation unit which includes `map`. It also obviates the need for fancy build systems like CMake. -#### New features +#### "New" features Here are all the C99 features which `toc` depends on (I might have forgotten some...): diff --git a/build64.bat b/build64.bat new file mode 100644 index 0000000..979ae3a --- /dev/null +++ b/build64.bat @@ -0,0 +1,2 @@ +if x%1 == xrelease cl /W3 /wd4146 /D_CRT_SECURE_NO_WARNINGS /O2 /Fe:toc.exe main.c win64call.obj +if x%1 == x cl /DTOC_DEBUG /W3 /wd4146 /D_CRT_SECURE_NO_WARNINGS /Od /Fe:toc.exe /DEBUG /Zi main.c win64call.obj diff --git a/foreign_msvc64.c b/foreign_msvc64.c index 4bbb643..d5be6a6 100644 --- a/foreign_msvc64.c +++ b/foreign_msvc64.c @@ -52,7 +52,7 @@ static Status foreign_call(ForeignFnManager *ffmgr, FnExpr *fn, Type *ret_type, U64 *word = words; char *type = (char *)arg_types; for (size_t i = 0; i < nargs; ++i) { - if (!val_to_words(args[i], (Type *)type, call_where, word)) + if (!val_to_word(args[i], (Type *)type, call_where, word)) return false; type += arg_types_stride; ++word; diff --git a/win64call.asm b/win64call.asm index 5c1c76a..1bc6ecb 100644 --- a/win64call.asm +++ b/win64call.asm @@ -30,7 +30,7 @@ ;; first get nasm: https://nasm.us/ ;; add it to your path, then do: ;; nasm -f win64 win64call.asm -;; You will get win64call.lib +;; You will get win64call.obj ;;To use this in a C/C++ program: ;; typedef void (*FnPtr)(); ;; extern unsigned long long win64_call(FnPtr fn, void *args, long long nargs); |