os-envs primitive to get current environment

release
Slava Pestov 2007-11-12 23:18:29 -05:00
parent 8cd8a10c47
commit a81a3387bf
8 changed files with 40 additions and 3 deletions

View File

@ -272,6 +272,7 @@ H{ } clone update-map set
{ "set-innermost-frame-quot" "kernel.private" } { "set-innermost-frame-quot" "kernel.private" }
{ "call-clear" "kernel" } { "call-clear" "kernel" }
{ "strip-compiled-quotations" "quotations" } { "strip-compiled-quotations" "quotations" }
{ "(os-envs)" "system" }
} }
dup length [ >r first2 r> make-primitive ] 2each dup length [ >r first2 r> make-primitive ] 2each

View File

@ -577,3 +577,5 @@ t over set-effect-terminated?
\ innermost-frame-scan { callstack } { fixnum } <effect> "inferred-effect" set-word-prop \ innermost-frame-scan { callstack } { fixnum } <effect> "inferred-effect" set-word-prop
\ set-innermost-frame-quot { quotation callstack } { } <effect> "inferred-effect" set-word-prop \ set-innermost-frame-quot { quotation callstack } { } <effect> "inferred-effect" set-word-prop
\ (os-envs) { } { array } <effect> "inferred-effect" set-word-prop

View File

@ -1,7 +1,8 @@
! Copyright (C) 2007 Slava Pestov. ! Copyright (C) 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: system IN: system
USING: kernel kernel.private sequences math namespaces ; USING: kernel kernel.private sequences math namespaces
splitting assocs ;
: cell ( -- n ) 7 getenv ; foldable : cell ( -- n ) 7 getenv ; foldable
@ -55,3 +56,6 @@ USING: kernel kernel.private sequences math namespaces ;
: bootstrap-cells bootstrap-cell * ; inline : bootstrap-cells bootstrap-cell * ; inline
: bootstrap-cell-bits 8 bootstrap-cells ; inline : bootstrap-cell-bits 8 bootstrap-cells ; inline
: os-envs ( -- assoc )
(os-envs) [ "=" split1 ] H{ } map>assoc ;

View File

@ -10,4 +10,9 @@ void early_init(void);
const char *vm_executable_path(void); const char *vm_executable_path(void);
const char *default_image_path(void); const char *default_image_path(void);
DLLEXPORT void c_to_factor_toplevel(CELL quot); DLLEXPORT void c_to_factor_toplevel(CELL quot);
#ifndef environ
extern char ***_NSGetEnviron(void);
#define environ (*_NSGetEnviron())
#endif

View File

@ -128,6 +128,24 @@ DEFINE_PRIMITIVE(cd)
chdir(unbox_char_string()); 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) F_SEGMENT *alloc_segment(CELL size)
{ {
int pagesize = getpagesize(); int pagesize = getpagesize();

View File

@ -205,5 +205,10 @@ long getpagesize(void)
void sleep_millis(DWORD msec) void sleep_millis(DWORD msec)
{ {
Sleep(msec); Sleep(msec);
}
DEFINE_PRIMITIVE(os_envs)
{
not_implemented_error();
} }

View File

@ -195,4 +195,5 @@ void *primitives[] = {
primitive_set_innermost_stack_frame_quot, primitive_set_innermost_stack_frame_quot,
primitive_call_clear, primitive_call_clear,
primitive_strip_compiled_quotations, primitive_strip_compiled_quotations,
primitive_os_envs,
}; };

View File

@ -235,6 +235,7 @@ DECLARE_PRIMITIVE(getenv);
DECLARE_PRIMITIVE(setenv); DECLARE_PRIMITIVE(setenv);
DECLARE_PRIMITIVE(exit); DECLARE_PRIMITIVE(exit);
DECLARE_PRIMITIVE(os_env); DECLARE_PRIMITIVE(os_env);
DECLARE_PRIMITIVE(os_envs);
DECLARE_PRIMITIVE(eq); DECLARE_PRIMITIVE(eq);
DECLARE_PRIMITIVE(millis); DECLARE_PRIMITIVE(millis);
DECLARE_PRIMITIVE(sleep); DECLARE_PRIMITIVE(sleep);