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

Fix os.getenv error.

This commit is contained in:
Calvin Rose 2018-07-11 19:11:34 -04:00
parent 24f153a3bf
commit 90496b99e8
4 changed files with 11 additions and 1 deletions

View File

@ -133,6 +133,12 @@ void dstc_popscope(DstCompiler *c) {
}
}
/* Parent scopes inherit child's closure flag. Needed
* for while loops. (if a while loop creates a closure, it
* is compiled to a tail recursive iife) */
if (oldscope->flags & DST_SCOPE_CLOSURE) {
newscope->flags |= DST_SCOPE_CLOSURE;
}
/* Free the old scope */
dst_v_free(oldscope->consts);
dst_v_free(oldscope->syms);

View File

@ -90,6 +90,7 @@ struct DstSlot {
#define DST_SCOPE_ENV 2
#define DST_SCOPE_TOP 4
#define DST_SCOPE_UNUSED 8
#define DST_SCOPE_CLOSURE 16
/* A symbol and slot pair */
typedef struct SymPair {

View File

@ -153,6 +153,9 @@ static int os_getenv(DstArgs args) {
DST_ARG_STRING(k, args, 0);
const char *cstr = (const char *) k;
const char *res = getenv(cstr);
if (!res) {
DST_RETURN_NIL(args);
}
DST_RETURN(args, cstr
? dst_cstringv(res)
: dst_wrap_nil());

View File

@ -1152,7 +1152,7 @@ int dst_lib_compile(DstArgs args);
#define DST_ARG_CFUNCTION(DEST, A, N) _DST_ARG(DST_CFUNCTION, cfunction, DEST, A, N)
#define DST_ARG_ABSTRACT(DEST, A, N) _DST_ARG(DST_ABSTRACT, abstract, DEST, A, N)
#define DST_RETURN_NIL(A) return DST_SIGNAL_OK
#define DST_RETURN_NIL(A) do { return DST_SIGNAL_OK; } while (0)
#define DST_RETURN_FALSE(A) DST_RETURN(A, dst_wrap_false())
#define DST_RETURN_TRUE(A) DST_RETURN(A, dst_wrap_true())
#define DST_RETURN_BOOLEAN(A, X) DST_RETURN(A, dst_wrap_boolean(X))