diff --git a/core/bootstrap/primitives.factor b/core/bootstrap/primitives.factor index 3f8b1da052..297d49e696 100644 --- a/core/bootstrap/primitives.factor +++ b/core/bootstrap/primitives.factor @@ -272,6 +272,7 @@ H{ } clone update-map set { "set-innermost-frame-quot" "kernel.private" } { "call-clear" "kernel" } { "strip-compiled-quotations" "quotations" } + { "(os-envs)" "system" } } dup length [ >r first2 r> make-primitive ] 2each diff --git a/core/inference/known-words/known-words.factor b/core/inference/known-words/known-words.factor index 51c0c5f830..b1624a7650 100644 --- a/core/inference/known-words/known-words.factor +++ b/core/inference/known-words/known-words.factor @@ -577,3 +577,5 @@ t over set-effect-terminated? \ innermost-frame-scan { callstack } { fixnum } "inferred-effect" set-word-prop \ set-innermost-frame-quot { quotation callstack } { } "inferred-effect" set-word-prop + +\ (os-envs) { } { array } "inferred-effect" set-word-prop diff --git a/core/system/system.factor b/core/system/system.factor index 0e42da0908..845ba8265d 100644 --- a/core/system/system.factor +++ b/core/system/system.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2007 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: system -USING: kernel kernel.private sequences math namespaces ; +USING: kernel kernel.private sequences math namespaces +splitting assocs ; : cell ( -- n ) 7 getenv ; foldable @@ -55,3 +56,6 @@ USING: kernel kernel.private sequences math namespaces ; : bootstrap-cells bootstrap-cell * ; inline : bootstrap-cell-bits 8 bootstrap-cells ; inline + +: os-envs ( -- assoc ) + (os-envs) [ "=" split1 ] H{ } map>assoc ; diff --git a/vm/os-macosx.h b/vm/os-macosx.h index e8e50714ff..4c35087752 100644 --- a/vm/os-macosx.h +++ b/vm/os-macosx.h @@ -10,4 +10,9 @@ void early_init(void); const char *vm_executable_path(void); const char *default_image_path(void); -DLLEXPORT void c_to_factor_toplevel(CELL quot); \ No newline at end of file +DLLEXPORT void c_to_factor_toplevel(CELL quot); + +#ifndef environ + extern char ***_NSGetEnviron(void); + #define environ (*_NSGetEnviron()) +#endif \ No newline at end of file diff --git a/vm/os-unix.c b/vm/os-unix.c index 65ae79550c..303c01491a 100644 --- a/vm/os-unix.c +++ b/vm/os-unix.c @@ -128,6 +128,24 @@ DEFINE_PRIMITIVE(cd) chdir(unbox_char_string()); } +DEFINE_PRIMITIVE(os_envs) +{ + GROWABLE_ARRAY(result); + char **env = environ; + + while(*env) + { + REGISTER_UNTAGGED(result); + CELL string = tag_object(from_char_string(*env)); + UNREGISTER_UNTAGGED(result); + GROWABLE_ADD(result,string); + env++; + } + + GROWABLE_TRIM(result); + dpush(tag_object(result)); +} + F_SEGMENT *alloc_segment(CELL size) { int pagesize = getpagesize(); diff --git a/vm/os-windows.c b/vm/os-windows.c index 421d90b223..1c07fd09cd 100755 --- a/vm/os-windows.c +++ b/vm/os-windows.c @@ -205,5 +205,10 @@ long getpagesize(void) void sleep_millis(DWORD msec) { - Sleep(msec); + Sleep(msec); +} + +DEFINE_PRIMITIVE(os_envs) +{ + not_implemented_error(); } diff --git a/vm/primitives.c b/vm/primitives.c index 2438b6b1aa..422096f931 100644 --- a/vm/primitives.c +++ b/vm/primitives.c @@ -195,4 +195,5 @@ void *primitives[] = { primitive_set_innermost_stack_frame_quot, primitive_call_clear, primitive_strip_compiled_quotations, + primitive_os_envs, }; diff --git a/vm/run.h b/vm/run.h index d171e98bc0..52f02c9c08 100644 --- a/vm/run.h +++ b/vm/run.h @@ -235,6 +235,7 @@ DECLARE_PRIMITIVE(getenv); DECLARE_PRIMITIVE(setenv); DECLARE_PRIMITIVE(exit); DECLARE_PRIMITIVE(os_env); +DECLARE_PRIMITIVE(os_envs); DECLARE_PRIMITIVE(eq); DECLARE_PRIMITIVE(millis); DECLARE_PRIMITIVE(sleep);