Get dst to compile on windows

This commit is contained in:
Calvin Rose 2018-02-01 17:09:22 -08:00
parent 776addfc07
commit ccdf758e83
16 changed files with 46 additions and 35 deletions

3
.gitignore vendored
View File

@ -12,6 +12,9 @@ dst
# Tools
xxd
# VSCode
.vs
# Swap files
*.swp

View File

@ -24,7 +24,7 @@ project(dst)
# Set Some Variables
set(TARGET_NAME ${PROJECT_NAME})
set (CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
include_directories(src/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
@ -121,7 +121,9 @@ src/include/dst/dsttypes.h
# Build the executable
add_executable(${TARGET_NAME} ${REPL_SOURCES})
target_link_libraries(${TARGET_NAME} m dl)
if (UNIX)
target_link_libraries(${TARGET_NAME} m dl)
endif (UNIX)
set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${DST_PUBLIC_HEADERS}")
# Install

View File

@ -56,8 +56,6 @@ static const DstReg cfuns[] = {
{NULL, NULL}
};
#include <unistd.h>
DstTable *dst_stl_env() {
static uint32_t error_asm[] = {
DOP_ERROR

View File

@ -275,7 +275,7 @@ void dst_sweep() {
}
/* Allocate some memory that is tracked for garbage collection */
void *dst_gcalloc(DstMemoryType type, size_t size) {
void *dst_gcalloc(enum DstMemoryType type, size_t size) {
DstGCMemoryHeader *mdata;
size_t total = size + sizeof(DstGCMemoryHeader);
@ -298,11 +298,11 @@ void *dst_gcalloc(DstMemoryType type, size_t size) {
mdata->next = dst_vm_blocks;
dst_vm_blocks = mdata;
return mem + sizeof(DstGCMemoryHeader);
return (char *) mem + sizeof(DstGCMemoryHeader);
}
/* Run garbage collection */
void dst_collect() {
void dst_collect(void) {
uint32_t i;
if (dst_vm_gc_suspend) return;
if (dst_vm_fiber)
@ -362,7 +362,7 @@ int dst_gcunrootall(Dst root) {
}
/* Free all allocated memory */
void dst_clear_memory() {
void dst_clear_memory(void) {
DstGCMemoryHeader *current = dst_vm_blocks;
while (NULL != current) {
dst_deinit_block(current);

View File

@ -48,7 +48,6 @@ struct DstGCMemoryHeader {
};
/* Memory types for the GC. Different from DstType to include funcenv and funcdef. */
typedef enum DstMemoryType DstMemoryType;
enum DstMemoryType {
DST_MEMORY_NONE,
DST_MEMORY_STRING,
@ -67,6 +66,6 @@ enum DstMemoryType {
/* To allocate collectable memory, one must calk dst_alloc, initialize the memory,
* and then call when dst_enablegc when it is initailize and reachable by the gc (on the DST stack) */
void *dst_gcalloc(DstMemoryType type, size_t size);
void *dst_gcalloc(enum DstMemoryType type, size_t size);
#endif

View File

@ -388,6 +388,6 @@ int dst_lib_math(DstArgs args) {
dst_env_def(env, "pi", dst_wrap_real(3.1415926535897931));
dst_env_def(env, "e", dst_wrap_real(2.7182818284590451));
dst_env_def(env, "inf", dst_wrap_real(1.0 / 0.0));
dst_env_def(env, "inf", dst_wrap_real(INFINITY));
return 0;
}

View File

@ -56,7 +56,7 @@ void dst_symcache_deinit() {
}
/* Mark an entry in the table as deleted. */
#define DST_SYMCACHE_DELETED ((NULL) + 1)
#define DST_SYMCACHE_DELETED ((const uint8_t *)0 + 1)
/* Find an item in the cache and return its location.
* If the item is not found, return the location
@ -172,7 +172,7 @@ const uint8_t *dst_symbol(const uint8_t *str, int32_t len) {
const uint8_t **bucket = dst_symcache_findmem(str, len, hash, &success);
if (success)
return *bucket;
newstr = dst_gcalloc(DST_MEMORY_SYMBOL, 2 * sizeof(int32_t) + len + 1)
newstr = (uint8_t *) dst_gcalloc(DST_MEMORY_SYMBOL, 2 * sizeof(int32_t) + len + 1)
+ (2 * sizeof(int32_t));
dst_string_hash(newstr) = hash;
dst_string_length(newstr) = len;
@ -226,7 +226,7 @@ const uint8_t *dst_symbol_gen(const uint8_t *buf, int32_t len) {
* is enough for resolving collisions. */
int32_t newlen = len + 8;
int32_t newbufsize = newlen + 2 * sizeof(int32_t) + 1;
uint8_t *str = (uint8_t *)(dst_gcalloc(DST_MEMORY_SYMBOL, newbufsize) + 2 * sizeof(int32_t));
uint8_t *str = (uint8_t *)dst_gcalloc(DST_MEMORY_SYMBOL, newbufsize) + 2 * sizeof(int32_t);
dst_string_length(str) = newlen;
memcpy(str, buf, len);
str[len] = '-';

View File

@ -26,8 +26,8 @@
#include <dst/dst.h>
/* Initialize the cache (allocate cache memory) */
void dst_symcache_init();
void dst_symcache_deinit();
void dst_symcache_init(void);
void dst_symcache_deinit(void);
void dst_symbol_deinit(const uint8_t *sym);
#endif

View File

@ -99,7 +99,7 @@ int32_t dst_hash(Dst x) {
hash ^= (int32_t) (i >> 32);
} else {
/* Assuming 4 byte pointer (or smaller) */
hash = (int32_t) (dst_unwrap_pointer(x) - NULL);
hash = (int32_t) ((char *)dst_unwrap_pointer(x) - (char *)0);
hash >>= 2;
}
break;

View File

@ -36,12 +36,12 @@ void *dst_nanbox_to_pointer(Dst x) {
#else
x.i64 = (x.i64 << 16) >> 16;
#endif
return x.pointer;
return (void *)x.i64;
}
Dst dst_nanbox_from_pointer(void *p, uint64_t tagmask) {
Dst ret;
ret.pointer = p;
ret.u64 = (int64_t)p;
#if defined (DST_NANBOX_47) || defined (DST_32)
#else
ret.u64 &= DST_NANBOX_POINTERBITS;
@ -52,7 +52,7 @@ Dst dst_nanbox_from_pointer(void *p, uint64_t tagmask) {
Dst dst_nanbox_from_cpointer(const void *p, uint64_t tagmask) {
Dst ret;
ret.cpointer = p;
ret.u64 = (int64_t)p;
#if defined (DST_NANBOX_47) || defined (DST_32)
#else
ret.u64 &= DST_NANBOX_POINTERBITS;

View File

@ -159,9 +159,9 @@ DstCFunction dst_native(const char *name, const uint8_t **error);
/* GC */
void dst_mark(Dst x);
void dst_sweep();
void dst_collect();
void dst_clear_memory();
void dst_sweep(void);
void dst_collect(void);
void dst_clear_memory(void);
void dst_gcroot(Dst root);
int dst_gcunroot(Dst root);
int dst_gcunrootall(Dst root);
@ -171,7 +171,7 @@ int dst_gcunrootall(Dst root);
#define dst_gcunlock() (dst_vm_gc_suspend--)
/* Functions */
DstFuncDef *dst_funcdef_alloc();
DstFuncDef *dst_funcdef_alloc(void);
DstFunction *dst_function(DstFuncDef *def, DstFunction *parent);
int dst_verify(DstFuncDef *def);
DstFunction *dst_quick_asm(int32_t arity, int varargs, int32_t slots, const uint32_t *bytecode, size_t bytecode_size);
@ -190,8 +190,8 @@ void dst_setindex(Dst ds, Dst value, int32_t index);
int dst_cstrcmp(const uint8_t *str, const char *other);
/* VM functions */
int dst_init();
void dst_deinit();
int dst_init(void);
void dst_deinit(void);
int dst_run(Dst callee, Dst *returnreg);
int dst_call(Dst callee, Dst *returnreg, int32_t argn, const Dst *argv);
@ -208,7 +208,7 @@ Dst dst_env_resolve(DstTable *env, const char *name);
DstTable *dst_env_arg(DstArgs args);
/* STL */
DstTable *dst_stl_env();
DstTable *dst_stl_env(void);
/* AST */
Dst dst_ast_wrap(Dst x, int32_t start, int32_t end);

View File

@ -60,6 +60,7 @@ extern "C" {
/* Check 64-bit vs 32-bit */
#if ((defined(__x86_64__) || defined(_M_X64)) \
&& (defined(DST_UNIX) || defined(DST_WINDOWS))) \
|| (defined(_WIN64)) /* Windows 64 bit */ \
|| (defined(__ia64__) && defined(__LP64__)) /* Itanium in LP64 mode */ \
|| defined(__alpha__) /* DEC Alpha */ \
|| (defined(__sparc__) && defined(__arch64__) || defined (__sparcv9)) /* BE */ \

View File

@ -101,8 +101,6 @@ typedef enum DstType {
union Dst {
uint64_t u64;
int64_t i64;
void *pointer;
const void *cpointer;
double real;
};
@ -122,8 +120,8 @@ union Dst {
#if defined (DST_NANBOX_47) || defined (DST_32)
#define DST_NANBOX_TAGBITS 0xFFFF800000000000lu
#define DST_NANBOX_PAYLOADBITS 0x00007FFFFFFFFFFFlu
#define DST_NANBOX_TAGBITS 0xFFFF800000000000llu
#define DST_NANBOX_PAYLOADBITS 0x00007FFFFFFFFFFFllu
#define dst_nanbox_lowtag(type) \
@ -139,8 +137,8 @@ union Dst {
#else /* defined (DST_NANBOX_47) || defined (DST_32) */
#define DST_NANBOX_TAGBITS 0xFFFF000000000000lu
#define DST_NANBOX_PAYLOADBITS 0x0000FFFFFFFFFFFFlu
#define DST_NANBOX_TAGBITS 0xFFFF000000000000llu
#define DST_NANBOX_PAYLOADBITS 0x0000FFFFFFFFFFFFllu
#define dst_nanbox_lowtag(type) \
((((uint64_t)(type) & 0x1) << 15) | 0x7FF8 | ((type) >> 1))
@ -157,7 +155,8 @@ union Dst {
/* 32 bit mode will not use the full payload for pointers. */
#ifdef DST_32
#define DST_NANBOX_POINTERBITS 0xFFFFFFFFlu
#define DST_NANBOX_POINTERBITS 0xFFFFFFFFllu
#else
#define DST_NANBOX_POINTERBITS DST_NANBOX_PAYLOADBITS
#endif

View File

@ -103,6 +103,11 @@
*
*/
/* On Windows, have a minimal implementation */
#ifdef WIN32
#else
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
@ -1197,3 +1202,5 @@ int linenoiseHistoryLoad(const char *filename) {
fclose(fp);
return 0;
}
#endif

View File

@ -169,8 +169,10 @@ int main(int argc, char **argv) {
if (!fileRead || (flags & DST_CLIENT_REPL)) {
DstContext ctxt;
dst_context_repl(&ctxt, env);
#ifndef DST_WINDOWS
ctxt.read_chunk = linenoiseread;
linenoiseSetMultiLine(1);
#endif
puts(replsplash);
status = dst_context_run(&ctxt, DST_PARSEFLAG_SOURCEMAP);
}

View File

@ -82,7 +82,7 @@ static double convert(
if (mantissa == 0)
return 0.0;
if (exponent > 1022)
return negative ? -1.0/0.0 : 1.0/0.0;
return negative ? -INFINITY : INFINITY;
/* TODO add fast paths */