mirror of
https://github.com/false-schemers/skint.git
synced 2025-01-21 19:27:27 +01:00
env/file/clock/time ops added
This commit is contained in:
parent
72c49980a8
commit
c1c23eee02
3 changed files with 551 additions and 494 deletions
49
i.c
49
i.c
|
@ -3340,6 +3340,55 @@ define_instruction(pushsub) {
|
|||
gonexti();
|
||||
}
|
||||
|
||||
define_instruction(fexis) {
|
||||
FILE *f; cks(ac);
|
||||
f = fopen(stringchars(ac), "r"); /* todo: pile #ifdefs here */
|
||||
if (f != NULL) fclose(f);
|
||||
ac = bool_obj(f != NULL);
|
||||
gonexti();
|
||||
}
|
||||
|
||||
define_instruction(frem) {
|
||||
int res; cks(ac);
|
||||
res = remove(stringchars(ac));
|
||||
ac = bool_obj(res == 0);
|
||||
gonexti();
|
||||
}
|
||||
|
||||
define_instruction(fren) {
|
||||
int res; cks(ac); cks(sref(0));
|
||||
res = rename(stringchars(ac), stringchars(sref(0)));
|
||||
spop();
|
||||
ac = bool_obj(res == 0);
|
||||
gonexti();
|
||||
}
|
||||
|
||||
define_instruction(getenv) {
|
||||
char *v; cks(ac);
|
||||
v = getenv(stringchars(ac));
|
||||
if (v) ac = string_obj(newstring(v));
|
||||
else ac = bool_obj(0);
|
||||
gonexti();
|
||||
}
|
||||
|
||||
define_instruction(clock) {
|
||||
double d = (double)clock();
|
||||
ac = flonum_obj(d);
|
||||
gonexti();
|
||||
}
|
||||
|
||||
define_instruction(clops) {
|
||||
double d = (double)CLOCKS_PER_SEC;
|
||||
ac = flonum_obj(d);
|
||||
gonexti();
|
||||
}
|
||||
|
||||
define_instruction(cursec) {
|
||||
double d = difftime(time(NULL), 0) + 37.0;
|
||||
ac = flonum_obj(d);
|
||||
gonexti();
|
||||
}
|
||||
|
||||
|
||||
#define VM_GEN_DEFGLOBAL
|
||||
#include "i.h"
|
||||
|
|
7
i.h
7
i.h
|
@ -479,6 +479,13 @@ declare_instruction(wrcw, "W5\0P11", 0, "write", 'b',
|
|||
declare_instruction(wrnl, "W6\0P11", 0, "newline", 'u', AUTOGL)
|
||||
declare_instruction(wrhw, "W7\0P11", 0, "write-shared", 'b', AUTOGL)
|
||||
declare_instruction(wriw, "W8\0P11", 0, "write-simple", 'b', AUTOGL)
|
||||
declare_instruction(fexis, "F0", 0, "file-exists?", '1', AUTOGL)
|
||||
declare_instruction(frem, "F1", 0, "delete-file", '1', AUTOGL)
|
||||
declare_instruction(fren, "F2", 0, "rename-file", '2', AUTOGL)
|
||||
declare_instruction(getenv, "Z1", 0, "get-environment-variable", '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)
|
||||
declare_instruction(panic, "Z7", 0, "%panic", '2', AUTOGL)
|
||||
|
||||
/* serialization and deserialization instructions */
|
||||
|
|
11
src/s.scm
11
src/s.scm
|
@ -1511,15 +1511,16 @@
|
|||
;---------------------------------------------------------------------------------------------
|
||||
|
||||
;load
|
||||
;file-exists?
|
||||
;delete-file
|
||||
; (file-exists? s)
|
||||
; (delete-file s)
|
||||
; (rename-file sold snew) +
|
||||
;command-line
|
||||
;exit
|
||||
;emergency-exit
|
||||
;get-environment-variable
|
||||
;get-environment-variables
|
||||
;current-second
|
||||
;current-jiffy
|
||||
;jiffies-per-second
|
||||
; (current-second)
|
||||
; (current-jiffy)
|
||||
; (jiffies-per-second)
|
||||
;features
|
||||
|
||||
|
|
Loading…
Reference in a new issue