mirror of
https://github.com/janet-lang/janet
synced 2025-07-04 19:12:55 +00:00
Try and fix os.clock on windows.
This commit is contained in:
parent
f92f358279
commit
5b15ad9ff8
@ -24,21 +24,6 @@
|
|||||||
#include <dst/dst.h>
|
#include <dst/dst.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/* Convert a slot to to an integer for bytecode */
|
|
||||||
|
|
||||||
/* Types of instructions (some of them) */
|
|
||||||
/* _0arg - op.---.--.-- (return-nil, noop, vararg arguments)
|
|
||||||
* _s - op.src.--.-- (push1)
|
|
||||||
* _l - op.XX.XX.XX (jump)
|
|
||||||
* _ss - op.dest.XX.XX (move, swap)
|
|
||||||
* _sl - op.check.XX.XX (jump-if)
|
|
||||||
* _st - op.check.TT.TT (typecheck)
|
|
||||||
* _si - op.dest.XX.XX (load-integer)
|
|
||||||
* _sss - op.dest.op1.op2 (add, subtract, arithmetic, comparison)
|
|
||||||
* _ses - op.dest.up.which (load-upvalue, save-upvalue)
|
|
||||||
* _sc - op.dest.CC.CC (load-constant, closure)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Definition for an instruction in the assembler */
|
/* Definition for an instruction in the assembler */
|
||||||
typedef struct DstInstructionDef DstInstructionDef;
|
typedef struct DstInstructionDef DstInstructionDef;
|
||||||
struct DstInstructionDef {
|
struct DstInstructionDef {
|
||||||
@ -919,7 +904,7 @@ static int cfun_asm(DstArgs args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cfun_disasm(DstArgs args) {
|
static int cfun_disasm(DstArgs args) {
|
||||||
DstFunction *f;
|
DstFunction *f;
|
||||||
DST_FIXARITY(args, 1);
|
DST_FIXARITY(args, 1);
|
||||||
DST_ARG_FUNCTION(f, args, 0);
|
DST_ARG_FUNCTION(f, args, 0);
|
||||||
|
@ -67,10 +67,10 @@ typedef struct DstSpecial DstSpecial;
|
|||||||
|
|
||||||
/* A stack slot */
|
/* A stack slot */
|
||||||
struct DstSlot {
|
struct DstSlot {
|
||||||
|
Dst constant; /* If the slot has a constant value */
|
||||||
int32_t index;
|
int32_t index;
|
||||||
int32_t envindex; /* 0 is local, positive number is an upvalue */
|
int32_t envindex; /* 0 is local, positive number is an upvalue */
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
Dst constant; /* If the slot has a constant value */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DST_SCOPE_FUNCTION 1
|
#define DST_SCOPE_FUNCTION 1
|
||||||
@ -80,9 +80,9 @@ struct DstSlot {
|
|||||||
|
|
||||||
/* A symbol and slot pair */
|
/* A symbol and slot pair */
|
||||||
typedef struct SymPair {
|
typedef struct SymPair {
|
||||||
|
DstSlot slot;
|
||||||
const uint8_t *sym;
|
const uint8_t *sym;
|
||||||
int keep;
|
int keep;
|
||||||
DstSlot slot;
|
|
||||||
} SymPair;
|
} SymPair;
|
||||||
|
|
||||||
/* A lexical scope during compilation */
|
/* A lexical scope during compilation */
|
||||||
@ -101,12 +101,12 @@ struct DstScope {
|
|||||||
/* Map of symbols to slots. Use a simple linear scan for symbols. */
|
/* Map of symbols to slots. Use a simple linear scan for symbols. */
|
||||||
SymPair *syms;
|
SymPair *syms;
|
||||||
|
|
||||||
/* Regsiter allocator */
|
|
||||||
DstcRegisterAllocator ra;
|
|
||||||
|
|
||||||
/* FuncDefs */
|
/* FuncDefs */
|
||||||
DstFuncDef **defs;
|
DstFuncDef **defs;
|
||||||
|
|
||||||
|
/* Regsiter allocator */
|
||||||
|
DstcRegisterAllocator ra;
|
||||||
|
|
||||||
/* Referenced closure environents. The values at each index correspond
|
/* Referenced closure environents. The values at each index correspond
|
||||||
* to which index to get the environment from in the parent. The environment
|
* to which index to get the environment from in the parent. The environment
|
||||||
* that corresponds to the direct parent's stack will always have value 0. */
|
* that corresponds to the direct parent's stack will always have value 0. */
|
||||||
@ -121,7 +121,6 @@ struct DstScope {
|
|||||||
|
|
||||||
/* Compilation state */
|
/* Compilation state */
|
||||||
struct DstCompiler {
|
struct DstCompiler {
|
||||||
int recursion_guard;
|
|
||||||
|
|
||||||
/* Pointer to current scope */
|
/* Pointer to current scope */
|
||||||
DstScope *scope;
|
DstScope *scope;
|
||||||
@ -129,16 +128,20 @@ struct DstCompiler {
|
|||||||
uint32_t *buffer;
|
uint32_t *buffer;
|
||||||
DstSourceMapping *mapbuffer;
|
DstSourceMapping *mapbuffer;
|
||||||
|
|
||||||
/* Keep track of where we are in the source */
|
|
||||||
DstSourceMapping current_mapping;
|
|
||||||
|
|
||||||
/* Hold the environment */
|
/* Hold the environment */
|
||||||
DstTable *env;
|
DstTable *env;
|
||||||
|
|
||||||
/* Name of source to attach to generated functions */
|
/* Name of source to attach to generated functions */
|
||||||
const uint8_t *source;
|
const uint8_t *source;
|
||||||
|
|
||||||
|
/* The result of compilation */
|
||||||
DstCompileResult result;
|
DstCompileResult result;
|
||||||
|
|
||||||
|
/* Keep track of where we are in the source */
|
||||||
|
DstSourceMapping current_mapping;
|
||||||
|
|
||||||
|
/* Prevent unbounded recursion */
|
||||||
|
int recursion_guard;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DST_FOPTS_TAIL 0x10000
|
#define DST_FOPTS_TAIL 0x10000
|
||||||
@ -148,8 +151,8 @@ struct DstCompiler {
|
|||||||
/* Options for compiling a single form */
|
/* Options for compiling a single form */
|
||||||
struct DstFopts {
|
struct DstFopts {
|
||||||
DstCompiler *compiler;
|
DstCompiler *compiler;
|
||||||
uint32_t flags; /* bit set of accepted primitive types */
|
|
||||||
DstSlot hint;
|
DstSlot hint;
|
||||||
|
uint32_t flags; /* bit set of accepted primitive types */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Get the default form options */
|
/* Get the default form options */
|
||||||
|
@ -256,10 +256,11 @@ static int dst_core_gcinterval(DstArgs args) {
|
|||||||
|
|
||||||
static int dst_core_type(DstArgs args) {
|
static int dst_core_type(DstArgs args) {
|
||||||
DST_FIXARITY(args, 1);
|
DST_FIXARITY(args, 1);
|
||||||
if (dst_checktype(args.v[0], DST_ABSTRACT)) {
|
DstType t = dst_type(args.v[0]);
|
||||||
|
if (t == DST_ABSTRACT) {
|
||||||
DST_RETURN(args, dst_csymbolv(dst_abstract_type(dst_unwrap_abstract(args.v[0]))->name));
|
DST_RETURN(args, dst_csymbolv(dst_abstract_type(dst_unwrap_abstract(args.v[0]))->name));
|
||||||
} else {
|
} else {
|
||||||
DST_RETURN(args, dst_csymbolv(dst_type_names[dst_type(args.v[0])]));
|
DST_RETURN(args, dst_csymbolv(dst_type_names[t]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,9 +283,8 @@ static int dst_core_next(DstArgs args) {
|
|||||||
: dst_struct_find(st, args.v[1]);
|
: dst_struct_find(st, args.v[1]);
|
||||||
kv = dst_struct_next(st, kv);
|
kv = dst_struct_next(st, kv);
|
||||||
}
|
}
|
||||||
if (kv) {
|
if (kv)
|
||||||
DST_RETURN(args, kv->key);
|
DST_RETURN(args, kv->key);
|
||||||
}
|
|
||||||
DST_RETURN_NIL(args);
|
DST_RETURN_NIL(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ static void templatize_varop(
|
|||||||
sizeof(varop_asm));
|
sizeof(varop_asm));
|
||||||
}
|
}
|
||||||
|
|
||||||
DstTable *dst_stl_env(int flags) {
|
DstTable *dst_core_env(void) {
|
||||||
static uint32_t error_asm[] = {
|
static uint32_t error_asm[] = {
|
||||||
DOP_ERROR
|
DOP_ERROR
|
||||||
};
|
};
|
||||||
@ -510,8 +510,5 @@ DstTable *dst_stl_env(int flags) {
|
|||||||
/* Run bootstrap source */
|
/* Run bootstrap source */
|
||||||
dst_dobytes(env, dst_gen_core, sizeof(dst_gen_core), "core.dst");
|
dst_dobytes(env, dst_gen_core, sizeof(dst_gen_core), "core.dst");
|
||||||
|
|
||||||
if (flags & DST_STL_NOGCROOT)
|
|
||||||
dst_gcunroot(dst_wrap_table(env));
|
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
@ -195,14 +195,14 @@ static int os_exit(DstArgs args) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Shim for windows */
|
/* Clock shim for windows */
|
||||||
#ifdef DST_WINDOWS
|
#ifdef DST_WINDOWS
|
||||||
struct timespec {
|
struct timespec {
|
||||||
long tv_sec;
|
long tv_sec;
|
||||||
long tv_nsec;
|
long tv_nsec;
|
||||||
};
|
};
|
||||||
static int clock_gettime(int, struct timespec *spec) {
|
static int clock_gettime(int, struct timespec *spec) {
|
||||||
int64 wintime;
|
int64_t wintime;
|
||||||
GetSystemTimeAsFileTime((FILETIME*)&wintime);
|
GetSystemTimeAsFileTime((FILETIME*)&wintime);
|
||||||
wintime -= 116444736000000000LL; /* Windows epic is 1601, jan 1 */
|
wintime -= 116444736000000000LL; /* Windows epic is 1601, jan 1 */
|
||||||
spec->tv_sec = wintime / 10000000LL;
|
spec->tv_sec = wintime / 10000000LL;
|
||||||
@ -210,6 +210,7 @@ static int clock_gettime(int, struct timespec *spec) {
|
|||||||
spec->tv_nsec = wintime % 10000000LL * 100;
|
spec->tv_nsec = wintime % 10000000LL * 100;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#define CLOCK_REALTIME 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int os_clock(DstArgs args) {
|
static int os_clock(DstArgs args) {
|
||||||
|
@ -209,8 +209,10 @@ static void inc_gensym(void) {
|
|||||||
for (int i = sizeof(gensym_counter) - 2; i; i--) {
|
for (int i = sizeof(gensym_counter) - 2; i; i--) {
|
||||||
if (gensym_counter[i] == '9') {
|
if (gensym_counter[i] == '9') {
|
||||||
gensym_counter[i] = 'a';
|
gensym_counter[i] = 'a';
|
||||||
|
break;
|
||||||
} else if (gensym_counter[i] == 'z') {
|
} else if (gensym_counter[i] == 'z') {
|
||||||
gensym_counter[i] = 'A';
|
gensym_counter[i] = 'A';
|
||||||
|
break;
|
||||||
} else if (gensym_counter[i] == 'Z') {
|
} else if (gensym_counter[i] == 'Z') {
|
||||||
gensym_counter[i] = '0';
|
gensym_counter[i] = '0';
|
||||||
} else {
|
} else {
|
||||||
|
@ -1262,7 +1262,7 @@ DstSignal dst_call(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Setup VM */
|
/* Setup VM */
|
||||||
int dst_init() {
|
int dst_init(void) {
|
||||||
/* Garbage collection */
|
/* Garbage collection */
|
||||||
dst_vm_blocks = NULL;
|
dst_vm_blocks = NULL;
|
||||||
dst_vm_next_collection = 0;
|
dst_vm_next_collection = 0;
|
||||||
@ -1283,7 +1283,7 @@ int dst_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Clear all memory associated with the VM */
|
/* Clear all memory associated with the VM */
|
||||||
void dst_deinit() {
|
void dst_deinit(void) {
|
||||||
dst_clear_memory();
|
dst_clear_memory();
|
||||||
dst_symcache_deinit();
|
dst_symcache_deinit();
|
||||||
free(dst_vm_roots);
|
free(dst_vm_roots);
|
||||||
|
@ -515,9 +515,9 @@ Dst dst_wrap_abstract(void *x);
|
|||||||
|
|
||||||
/* Hold components of arguments passed to DstCFunction. */
|
/* Hold components of arguments passed to DstCFunction. */
|
||||||
struct DstArgs {
|
struct DstArgs {
|
||||||
int32_t n;
|
|
||||||
Dst *v;
|
Dst *v;
|
||||||
Dst *ret;
|
Dst *ret;
|
||||||
|
int32_t n;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Fiber flags */
|
/* Fiber flags */
|
||||||
@ -855,16 +855,16 @@ enum DstCompileStatus {
|
|||||||
DST_COMPILE_ERROR
|
DST_COMPILE_ERROR
|
||||||
};
|
};
|
||||||
struct DstCompileResult {
|
struct DstCompileResult {
|
||||||
enum DstCompileStatus status;
|
|
||||||
DstFuncDef *funcdef;
|
DstFuncDef *funcdef;
|
||||||
const uint8_t *error;
|
const uint8_t *error;
|
||||||
DstFiber *macrofiber;
|
DstFiber *macrofiber;
|
||||||
DstSourceMapping error_mapping;
|
DstSourceMapping error_mapping;
|
||||||
|
enum DstCompileStatus status;
|
||||||
};
|
};
|
||||||
DstCompileResult dst_compile(Dst source, DstTable *env, const uint8_t *where);
|
DstCompileResult dst_compile(Dst source, DstTable *env, const uint8_t *where);
|
||||||
|
|
||||||
/* Get the default environment for dst */
|
/* Get the default environment for dst */
|
||||||
DstTable *dst_stl_env();
|
DstTable *dst_core_env(void);
|
||||||
|
|
||||||
int dst_dobytes(DstTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath);
|
int dst_dobytes(DstTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath);
|
||||||
int dst_dostring(DstTable *env, const char *str, const char *sourcePath);
|
int dst_dostring(DstTable *env, const char *str, const char *sourcePath);
|
||||||
@ -939,7 +939,7 @@ void dst_puts(const uint8_t *str);
|
|||||||
const uint8_t *dst_symbol(const uint8_t *str, int32_t len);
|
const uint8_t *dst_symbol(const uint8_t *str, int32_t len);
|
||||||
const uint8_t *dst_symbol_from_string(const uint8_t *str);
|
const uint8_t *dst_symbol_from_string(const uint8_t *str);
|
||||||
const uint8_t *dst_csymbol(const char *str);
|
const uint8_t *dst_csymbol(const char *str);
|
||||||
const uint8_t *dst_symbol_gen();
|
const uint8_t *dst_symbol_gen(void);
|
||||||
#define dst_symbolv(str, len) dst_wrap_symbol(dst_symbol((str), (len)))
|
#define dst_symbolv(str, len) dst_wrap_symbol(dst_symbol((str), (len)))
|
||||||
#define dst_csymbolv(cstr) dst_wrap_symbol(dst_csymbol(cstr))
|
#define dst_csymbolv(cstr) dst_wrap_symbol(dst_csymbol(cstr))
|
||||||
|
|
||||||
@ -1033,10 +1033,6 @@ void dst_env_cfuns(DstTable *env, const DstReg *cfuns);
|
|||||||
DstBindingType dst_env_resolve(DstTable *env, const uint8_t *sym, Dst *out);
|
DstBindingType dst_env_resolve(DstTable *env, const uint8_t *sym, Dst *out);
|
||||||
DstTable *dst_env_arg(DstArgs args);
|
DstTable *dst_env_arg(DstArgs args);
|
||||||
|
|
||||||
/* STL */
|
|
||||||
#define DST_STL_NOGCROOT 1
|
|
||||||
DstTable *dst_stl_env(int flags);
|
|
||||||
|
|
||||||
/* C Function helpers */
|
/* C Function helpers */
|
||||||
int dst_arity_err(DstArgs args, int32_t n, const char *prefix);
|
int dst_arity_err(DstArgs args, int32_t n, const char *prefix);
|
||||||
int dst_type_err(DstArgs args, int32_t n, DstType expected);
|
int dst_type_err(DstArgs args, int32_t n, DstType expected);
|
||||||
|
@ -32,7 +32,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
/* Set up VM */
|
/* Set up VM */
|
||||||
dst_init();
|
dst_init();
|
||||||
env = dst_stl_env(0);
|
env = dst_core_env();
|
||||||
|
|
||||||
/* Create args tuple */
|
/* Create args tuple */
|
||||||
args = dst_array(argc);
|
args = dst_array(argc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user