mirror of
https://github.com/janet-lang/janet
synced 2025-06-11 11:04:13 +00:00
Get dst to compile on windows
This commit is contained in:
parent
776addfc07
commit
ccdf758e83
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,6 +12,9 @@ dst
|
|||||||
# Tools
|
# Tools
|
||||||
xxd
|
xxd
|
||||||
|
|
||||||
|
# VSCode
|
||||||
|
.vs
|
||||||
|
|
||||||
# Swap files
|
# Swap files
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ project(dst)
|
|||||||
# Set Some Variables
|
# Set Some Variables
|
||||||
set(TARGET_NAME ${PROJECT_NAME})
|
set(TARGET_NAME ${PROJECT_NAME})
|
||||||
set (CMAKE_C_STANDARD 99)
|
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(src/include)
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
@ -121,7 +121,9 @@ src/include/dst/dsttypes.h
|
|||||||
|
|
||||||
# Build the executable
|
# Build the executable
|
||||||
add_executable(${TARGET_NAME} ${REPL_SOURCES})
|
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}")
|
set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${DST_PUBLIC_HEADERS}")
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
@ -56,8 +56,6 @@ static const DstReg cfuns[] = {
|
|||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
DstTable *dst_stl_env() {
|
DstTable *dst_stl_env() {
|
||||||
static uint32_t error_asm[] = {
|
static uint32_t error_asm[] = {
|
||||||
DOP_ERROR
|
DOP_ERROR
|
||||||
|
@ -275,7 +275,7 @@ void dst_sweep() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate some memory that is tracked for garbage collection */
|
/* 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;
|
DstGCMemoryHeader *mdata;
|
||||||
size_t total = size + sizeof(DstGCMemoryHeader);
|
size_t total = size + sizeof(DstGCMemoryHeader);
|
||||||
|
|
||||||
@ -298,11 +298,11 @@ void *dst_gcalloc(DstMemoryType type, size_t size) {
|
|||||||
mdata->next = dst_vm_blocks;
|
mdata->next = dst_vm_blocks;
|
||||||
dst_vm_blocks = mdata;
|
dst_vm_blocks = mdata;
|
||||||
|
|
||||||
return mem + sizeof(DstGCMemoryHeader);
|
return (char *) mem + sizeof(DstGCMemoryHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run garbage collection */
|
/* Run garbage collection */
|
||||||
void dst_collect() {
|
void dst_collect(void) {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
if (dst_vm_gc_suspend) return;
|
if (dst_vm_gc_suspend) return;
|
||||||
if (dst_vm_fiber)
|
if (dst_vm_fiber)
|
||||||
@ -362,7 +362,7 @@ int dst_gcunrootall(Dst root) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Free all allocated memory */
|
/* Free all allocated memory */
|
||||||
void dst_clear_memory() {
|
void dst_clear_memory(void) {
|
||||||
DstGCMemoryHeader *current = dst_vm_blocks;
|
DstGCMemoryHeader *current = dst_vm_blocks;
|
||||||
while (NULL != current) {
|
while (NULL != current) {
|
||||||
dst_deinit_block(current);
|
dst_deinit_block(current);
|
||||||
|
@ -48,7 +48,6 @@ struct DstGCMemoryHeader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Memory types for the GC. Different from DstType to include funcenv and funcdef. */
|
/* Memory types for the GC. Different from DstType to include funcenv and funcdef. */
|
||||||
typedef enum DstMemoryType DstMemoryType;
|
|
||||||
enum DstMemoryType {
|
enum DstMemoryType {
|
||||||
DST_MEMORY_NONE,
|
DST_MEMORY_NONE,
|
||||||
DST_MEMORY_STRING,
|
DST_MEMORY_STRING,
|
||||||
@ -67,6 +66,6 @@ enum DstMemoryType {
|
|||||||
|
|
||||||
/* To allocate collectable memory, one must calk dst_alloc, initialize the memory,
|
/* 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) */
|
* 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
|
#endif
|
||||||
|
@ -388,6 +388,6 @@ int dst_lib_math(DstArgs args) {
|
|||||||
|
|
||||||
dst_env_def(env, "pi", dst_wrap_real(3.1415926535897931));
|
dst_env_def(env, "pi", dst_wrap_real(3.1415926535897931));
|
||||||
dst_env_def(env, "e", dst_wrap_real(2.7182818284590451));
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ void dst_symcache_deinit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Mark an entry in the table as deleted. */
|
/* 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.
|
/* Find an item in the cache and return its location.
|
||||||
* If the item is not found, return the 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);
|
const uint8_t **bucket = dst_symcache_findmem(str, len, hash, &success);
|
||||||
if (success)
|
if (success)
|
||||||
return *bucket;
|
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));
|
+ (2 * sizeof(int32_t));
|
||||||
dst_string_hash(newstr) = hash;
|
dst_string_hash(newstr) = hash;
|
||||||
dst_string_length(newstr) = len;
|
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. */
|
* is enough for resolving collisions. */
|
||||||
int32_t newlen = len + 8;
|
int32_t newlen = len + 8;
|
||||||
int32_t newbufsize = newlen + 2 * sizeof(int32_t) + 1;
|
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;
|
dst_string_length(str) = newlen;
|
||||||
memcpy(str, buf, len);
|
memcpy(str, buf, len);
|
||||||
str[len] = '-';
|
str[len] = '-';
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
#include <dst/dst.h>
|
#include <dst/dst.h>
|
||||||
|
|
||||||
/* Initialize the cache (allocate cache memory) */
|
/* Initialize the cache (allocate cache memory) */
|
||||||
void dst_symcache_init();
|
void dst_symcache_init(void);
|
||||||
void dst_symcache_deinit();
|
void dst_symcache_deinit(void);
|
||||||
void dst_symbol_deinit(const uint8_t *sym);
|
void dst_symbol_deinit(const uint8_t *sym);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,7 +99,7 @@ int32_t dst_hash(Dst x) {
|
|||||||
hash ^= (int32_t) (i >> 32);
|
hash ^= (int32_t) (i >> 32);
|
||||||
} else {
|
} else {
|
||||||
/* Assuming 4 byte pointer (or smaller) */
|
/* 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;
|
hash >>= 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -36,12 +36,12 @@ void *dst_nanbox_to_pointer(Dst x) {
|
|||||||
#else
|
#else
|
||||||
x.i64 = (x.i64 << 16) >> 16;
|
x.i64 = (x.i64 << 16) >> 16;
|
||||||
#endif
|
#endif
|
||||||
return x.pointer;
|
return (void *)x.i64;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dst dst_nanbox_from_pointer(void *p, uint64_t tagmask) {
|
Dst dst_nanbox_from_pointer(void *p, uint64_t tagmask) {
|
||||||
Dst ret;
|
Dst ret;
|
||||||
ret.pointer = p;
|
ret.u64 = (int64_t)p;
|
||||||
#if defined (DST_NANBOX_47) || defined (DST_32)
|
#if defined (DST_NANBOX_47) || defined (DST_32)
|
||||||
#else
|
#else
|
||||||
ret.u64 &= DST_NANBOX_POINTERBITS;
|
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 dst_nanbox_from_cpointer(const void *p, uint64_t tagmask) {
|
||||||
Dst ret;
|
Dst ret;
|
||||||
ret.cpointer = p;
|
ret.u64 = (int64_t)p;
|
||||||
#if defined (DST_NANBOX_47) || defined (DST_32)
|
#if defined (DST_NANBOX_47) || defined (DST_32)
|
||||||
#else
|
#else
|
||||||
ret.u64 &= DST_NANBOX_POINTERBITS;
|
ret.u64 &= DST_NANBOX_POINTERBITS;
|
||||||
|
@ -159,9 +159,9 @@ DstCFunction dst_native(const char *name, const uint8_t **error);
|
|||||||
|
|
||||||
/* GC */
|
/* GC */
|
||||||
void dst_mark(Dst x);
|
void dst_mark(Dst x);
|
||||||
void dst_sweep();
|
void dst_sweep(void);
|
||||||
void dst_collect();
|
void dst_collect(void);
|
||||||
void dst_clear_memory();
|
void dst_clear_memory(void);
|
||||||
void dst_gcroot(Dst root);
|
void dst_gcroot(Dst root);
|
||||||
int dst_gcunroot(Dst root);
|
int dst_gcunroot(Dst root);
|
||||||
int dst_gcunrootall(Dst root);
|
int dst_gcunrootall(Dst root);
|
||||||
@ -171,7 +171,7 @@ int dst_gcunrootall(Dst root);
|
|||||||
#define dst_gcunlock() (dst_vm_gc_suspend--)
|
#define dst_gcunlock() (dst_vm_gc_suspend--)
|
||||||
|
|
||||||
/* Functions */
|
/* Functions */
|
||||||
DstFuncDef *dst_funcdef_alloc();
|
DstFuncDef *dst_funcdef_alloc(void);
|
||||||
DstFunction *dst_function(DstFuncDef *def, DstFunction *parent);
|
DstFunction *dst_function(DstFuncDef *def, DstFunction *parent);
|
||||||
int dst_verify(DstFuncDef *def);
|
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);
|
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);
|
int dst_cstrcmp(const uint8_t *str, const char *other);
|
||||||
|
|
||||||
/* VM functions */
|
/* VM functions */
|
||||||
int dst_init();
|
int dst_init(void);
|
||||||
void dst_deinit();
|
void dst_deinit(void);
|
||||||
int dst_run(Dst callee, Dst *returnreg);
|
int dst_run(Dst callee, Dst *returnreg);
|
||||||
int dst_call(Dst callee, Dst *returnreg, int32_t argn, const Dst *argv);
|
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);
|
DstTable *dst_env_arg(DstArgs args);
|
||||||
|
|
||||||
/* STL */
|
/* STL */
|
||||||
DstTable *dst_stl_env();
|
DstTable *dst_stl_env(void);
|
||||||
|
|
||||||
/* AST */
|
/* AST */
|
||||||
Dst dst_ast_wrap(Dst x, int32_t start, int32_t end);
|
Dst dst_ast_wrap(Dst x, int32_t start, int32_t end);
|
||||||
|
@ -60,6 +60,7 @@ extern "C" {
|
|||||||
/* Check 64-bit vs 32-bit */
|
/* Check 64-bit vs 32-bit */
|
||||||
#if ((defined(__x86_64__) || defined(_M_X64)) \
|
#if ((defined(__x86_64__) || defined(_M_X64)) \
|
||||||
&& (defined(DST_UNIX) || defined(DST_WINDOWS))) \
|
&& (defined(DST_UNIX) || defined(DST_WINDOWS))) \
|
||||||
|
|| (defined(_WIN64)) /* Windows 64 bit */ \
|
||||||
|| (defined(__ia64__) && defined(__LP64__)) /* Itanium in LP64 mode */ \
|
|| (defined(__ia64__) && defined(__LP64__)) /* Itanium in LP64 mode */ \
|
||||||
|| defined(__alpha__) /* DEC Alpha */ \
|
|| defined(__alpha__) /* DEC Alpha */ \
|
||||||
|| (defined(__sparc__) && defined(__arch64__) || defined (__sparcv9)) /* BE */ \
|
|| (defined(__sparc__) && defined(__arch64__) || defined (__sparcv9)) /* BE */ \
|
||||||
|
@ -101,8 +101,6 @@ typedef enum DstType {
|
|||||||
union Dst {
|
union Dst {
|
||||||
uint64_t u64;
|
uint64_t u64;
|
||||||
int64_t i64;
|
int64_t i64;
|
||||||
void *pointer;
|
|
||||||
const void *cpointer;
|
|
||||||
double real;
|
double real;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -122,8 +120,8 @@ union Dst {
|
|||||||
|
|
||||||
#if defined (DST_NANBOX_47) || defined (DST_32)
|
#if defined (DST_NANBOX_47) || defined (DST_32)
|
||||||
|
|
||||||
#define DST_NANBOX_TAGBITS 0xFFFF800000000000lu
|
#define DST_NANBOX_TAGBITS 0xFFFF800000000000llu
|
||||||
#define DST_NANBOX_PAYLOADBITS 0x00007FFFFFFFFFFFlu
|
#define DST_NANBOX_PAYLOADBITS 0x00007FFFFFFFFFFFllu
|
||||||
|
|
||||||
|
|
||||||
#define dst_nanbox_lowtag(type) \
|
#define dst_nanbox_lowtag(type) \
|
||||||
@ -139,8 +137,8 @@ union Dst {
|
|||||||
|
|
||||||
#else /* defined (DST_NANBOX_47) || defined (DST_32) */
|
#else /* defined (DST_NANBOX_47) || defined (DST_32) */
|
||||||
|
|
||||||
#define DST_NANBOX_TAGBITS 0xFFFF000000000000lu
|
#define DST_NANBOX_TAGBITS 0xFFFF000000000000llu
|
||||||
#define DST_NANBOX_PAYLOADBITS 0x0000FFFFFFFFFFFFlu
|
#define DST_NANBOX_PAYLOADBITS 0x0000FFFFFFFFFFFFllu
|
||||||
|
|
||||||
#define dst_nanbox_lowtag(type) \
|
#define dst_nanbox_lowtag(type) \
|
||||||
((((uint64_t)(type) & 0x1) << 15) | 0x7FF8 | ((type) >> 1))
|
((((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. */
|
/* 32 bit mode will not use the full payload for pointers. */
|
||||||
#ifdef DST_32
|
#ifdef DST_32
|
||||||
#define DST_NANBOX_POINTERBITS 0xFFFFFFFFlu
|
|
||||||
|
#define DST_NANBOX_POINTERBITS 0xFFFFFFFFllu
|
||||||
#else
|
#else
|
||||||
#define DST_NANBOX_POINTERBITS DST_NANBOX_PAYLOADBITS
|
#define DST_NANBOX_POINTERBITS DST_NANBOX_PAYLOADBITS
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,6 +103,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* On Windows, have a minimal implementation */
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -1197,3 +1202,5 @@ int linenoiseHistoryLoad(const char *filename) {
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -169,8 +169,10 @@ int main(int argc, char **argv) {
|
|||||||
if (!fileRead || (flags & DST_CLIENT_REPL)) {
|
if (!fileRead || (flags & DST_CLIENT_REPL)) {
|
||||||
DstContext ctxt;
|
DstContext ctxt;
|
||||||
dst_context_repl(&ctxt, env);
|
dst_context_repl(&ctxt, env);
|
||||||
|
#ifndef DST_WINDOWS
|
||||||
ctxt.read_chunk = linenoiseread;
|
ctxt.read_chunk = linenoiseread;
|
||||||
linenoiseSetMultiLine(1);
|
linenoiseSetMultiLine(1);
|
||||||
|
#endif
|
||||||
puts(replsplash);
|
puts(replsplash);
|
||||||
status = dst_context_run(&ctxt, DST_PARSEFLAG_SOURCEMAP);
|
status = dst_context_run(&ctxt, DST_PARSEFLAG_SOURCEMAP);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ static double convert(
|
|||||||
if (mantissa == 0)
|
if (mantissa == 0)
|
||||||
return 0.0;
|
return 0.0;
|
||||||
if (exponent > 1022)
|
if (exponent > 1022)
|
||||||
return negative ? -1.0/0.0 : 1.0/0.0;
|
return negative ? -INFINITY : INFINITY;
|
||||||
|
|
||||||
/* TODO add fast paths */
|
/* TODO add fast paths */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user