envvref (%envv-ref) instruction added

This commit is contained in:
ESL 2024-07-17 00:33:46 -04:00
parent 94ebc0f4d1
commit 76dcf09bcc
3 changed files with 28 additions and 0 deletions

10
i.c
View file

@ -3890,6 +3890,16 @@ define_instruction(getenv) {
gonexti();
}
define_instruction(envvref) {
extern const char *environ_ref(int idx);
int i; char *s; ckk(ac);
i = get_fixnum(ac); /* todo: range-check */
s = (char *)environ_ref(i);
if (s) ac = string_obj(newstring(s));
else ac = bool_obj(0);
gonexti();
}
define_instruction(clock) {
double d = (double)clock();
ac = flonum_obj(d);

1
i.h
View file

@ -519,6 +519,7 @@ declare_instruction(frem, "F1", 0, "delete-file",
declare_instruction(fren, "F2", 0, "rename-file", '2', AUTOGL)
declare_instruction(argvref, "Z0", 0, "%argv-ref", '1', AUTOGL)
declare_instruction(getenv, "Z1", 0, "get-environment-variable", '1', AUTOGL)
declare_instruction(envvref, "Z2", 0, "%envv-ref", '1', AUTOGL)
declare_instruction(clock, "Z3", 0, "current-jiffy", '0', AUTOGL)
declare_instruction(clops, "Z4", 0, "jiffies-per-second", '0', AUTOGL)
declare_instruction(cursec, "Z5", 0, "current-second", '0', AUTOGL)

17
s.c
View file

@ -17,6 +17,23 @@ int dirsep = '\\';
int dirsep = '/';
#endif
#if defined(WIN32)
#define sxc_environ _environ
#elif defined(__linux) || defined(__APPLE__)
#define sxc_environ environ
#else /* add more systems? */
char **sxc_environ = { NULL };
#endif
extern const char *environ_ref(int idx)
{
const char **pe = sxc_environ;
/* be careful with indexing! */
if (idx < 0) return NULL;
while (idx-- > 0) if (*pe++ == NULL) return NULL;
return *pe;
}
char *s_code[] = {
"S", "let-syntax",