1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-25 06:33:16 +00:00

Try and fix os.clock on windows.

This commit is contained in:
Calvin Rose 2018-07-08 20:54:41 -04:00
parent f92f358279
commit 5b15ad9ff8
8 changed files with 31 additions and 47 deletions

View File

@ -24,21 +24,6 @@
#include <dst/dst.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 */
typedef struct DstInstructionDef 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;
DST_FIXARITY(args, 1);
DST_ARG_FUNCTION(f, args, 0);

View File

@ -67,10 +67,10 @@ typedef struct DstSpecial DstSpecial;
/* A stack slot */
struct DstSlot {
Dst constant; /* If the slot has a constant value */
int32_t index;
int32_t envindex; /* 0 is local, positive number is an upvalue */
uint32_t flags;
Dst constant; /* If the slot has a constant value */
};
#define DST_SCOPE_FUNCTION 1
@ -80,9 +80,9 @@ struct DstSlot {
/* A symbol and slot pair */
typedef struct SymPair {
DstSlot slot;
const uint8_t *sym;
int keep;
DstSlot slot;
} SymPair;
/* A lexical scope during compilation */
@ -101,12 +101,12 @@ struct DstScope {
/* Map of symbols to slots. Use a simple linear scan for symbols. */
SymPair *syms;
/* Regsiter allocator */
DstcRegisterAllocator ra;
/* FuncDefs */
DstFuncDef **defs;
/* Regsiter allocator */
DstcRegisterAllocator ra;
/* Referenced closure environents. The values at each index correspond
* 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. */
@ -121,7 +121,6 @@ struct DstScope {
/* Compilation state */
struct DstCompiler {
int recursion_guard;
/* Pointer to current scope */
DstScope *scope;
@ -129,16 +128,20 @@ struct DstCompiler {
uint32_t *buffer;
DstSourceMapping *mapbuffer;
/* Keep track of where we are in the source */
DstSourceMapping current_mapping;
/* Hold the environment */
DstTable *env;
/* Name of source to attach to generated functions */
const uint8_t *source;
/* The result of compilation */
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
@ -148,8 +151,8 @@ struct DstCompiler {
/* Options for compiling a single form */
struct DstFopts {
DstCompiler *compiler;
uint32_t flags; /* bit set of accepted primitive types */
DstSlot hint;
uint32_t flags; /* bit set of accepted primitive types */
};
/* Get the default form options */

View File

@ -256,10 +256,11 @@ static int dst_core_gcinterval(DstArgs args) {
static int dst_core_type(DstArgs args) {
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));
} 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]);
kv = dst_struct_next(st, kv);
}
if (kv) {
if (kv)
DST_RETURN(args, kv->key);
}
DST_RETURN_NIL(args);
}
@ -418,7 +418,7 @@ static void templatize_varop(
sizeof(varop_asm));
}
DstTable *dst_stl_env(int flags) {
DstTable *dst_core_env(void) {
static uint32_t error_asm[] = {
DOP_ERROR
};
@ -510,8 +510,5 @@ DstTable *dst_stl_env(int flags) {
/* Run bootstrap source */
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;
}

View File

@ -195,14 +195,14 @@ static int os_exit(DstArgs args) {
return 0;
}
/* Shim for windows */
/* Clock shim for windows */
#ifdef DST_WINDOWS
struct timespec {
long tv_sec;
long tv_nsec;
};
static int clock_gettime(int, struct timespec *spec) {
int64 wintime;
int64_t wintime;
GetSystemTimeAsFileTime((FILETIME*)&wintime);
wintime -= 116444736000000000LL; /* Windows epic is 1601, jan 1 */
spec->tv_sec = wintime / 10000000LL;
@ -210,6 +210,7 @@ static int clock_gettime(int, struct timespec *spec) {
spec->tv_nsec = wintime % 10000000LL * 100;
return 0;
}
#define CLOCK_REALTIME 0
#endif
static int os_clock(DstArgs args) {

View File

@ -209,8 +209,10 @@ static void inc_gensym(void) {
for (int i = sizeof(gensym_counter) - 2; i; i--) {
if (gensym_counter[i] == '9') {
gensym_counter[i] = 'a';
break;
} else if (gensym_counter[i] == 'z') {
gensym_counter[i] = 'A';
break;
} else if (gensym_counter[i] == 'Z') {
gensym_counter[i] = '0';
} else {

View File

@ -1262,7 +1262,7 @@ DstSignal dst_call(
}
/* Setup VM */
int dst_init() {
int dst_init(void) {
/* Garbage collection */
dst_vm_blocks = NULL;
dst_vm_next_collection = 0;
@ -1283,7 +1283,7 @@ int dst_init() {
}
/* Clear all memory associated with the VM */
void dst_deinit() {
void dst_deinit(void) {
dst_clear_memory();
dst_symcache_deinit();
free(dst_vm_roots);

View File

@ -515,9 +515,9 @@ Dst dst_wrap_abstract(void *x);
/* Hold components of arguments passed to DstCFunction. */
struct DstArgs {
int32_t n;
Dst *v;
Dst *ret;
int32_t n;
};
/* Fiber flags */
@ -855,16 +855,16 @@ enum DstCompileStatus {
DST_COMPILE_ERROR
};
struct DstCompileResult {
enum DstCompileStatus status;
DstFuncDef *funcdef;
const uint8_t *error;
DstFiber *macrofiber;
DstSourceMapping error_mapping;
enum DstCompileStatus status;
};
DstCompileResult dst_compile(Dst source, DstTable *env, const uint8_t *where);
/* 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_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_from_string(const uint8_t *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_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);
DstTable *dst_env_arg(DstArgs args);
/* STL */
#define DST_STL_NOGCROOT 1
DstTable *dst_stl_env(int flags);
/* C Function helpers */
int dst_arity_err(DstArgs args, int32_t n, const char *prefix);
int dst_type_err(DstArgs args, int32_t n, DstType expected);

View File

@ -32,7 +32,7 @@ int main(int argc, char **argv) {
/* Set up VM */
dst_init();
env = dst_stl_env(0);
env = dst_core_env();
/* Create args tuple */
args = dst_array(argc);