klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

ksystem.c (1408B)


      1 /*
      2 ** ksystem.c
      3 ** Platform dependent functionality.
      4 ** See Copyright Notice in klisp.h
      5 */
      6 
      7 #include "kobject.h"
      8 #include "kstate.h"
      9 #include "kerror.h"
     10 #include "kinteger.h"
     11 #include "ksystem.h"
     12 
     13 /* detect platform
     14  * TODO: sync with klispconf.h and kgffi.c */
     15 
     16 #if defined(KLISP_USE_POSIX)
     17 #    define KLISP_PLATFORM_POSIX
     18 #elif defined(_WIN32)
     19 #    define KLISP_PLATFORM_WIN32
     20 #endif
     21 
     22 /* Include platform-dependent versions. The platform-dependent
     23  * code #defines macro HAVE_PLATFORM_<functionality>, if it
     24  * actually implements <functionality>.
     25  */
     26 
     27 #if defined(KLISP_PLATFORM_POSIX)
     28 #    include "ksystem.posix.c"
     29 #elif defined(KLISP_PLATFORM_WIN32)
     30 #    include "ksystem.win32.c"
     31 #endif
     32 
     33 /* Fall back to platform-independent versions if necessaty. */
     34 
     35 #ifndef HAVE_PLATFORM_JIFFIES
     36 
     37 #include <time.h>
     38 
     39 /* TEMP for now the best we can do is return the current second */
     40 TValue ksystem_current_jiffy(klisp_State *K)
     41 {
     42     time_t now = time(NULL);
     43 
     44     if (now == -1) {
     45         klispE_throw_simple(K, "couldn't get time");
     46         return KFALSE;
     47     } else {
     48         return kinteger_new_uint64(K, (uint64_t) now);
     49     }
     50 }
     51 
     52 TValue ksystem_jiffies_per_second(klisp_State *K)
     53 {
     54     return i2tv(1);
     55 }
     56 
     57 #endif /* HAVE_PLATFORM_JIFFIES */
     58 
     59 #ifndef HAVE_PLATFORM_ISATTY
     60 
     61 bool ksystem_isatty(klisp_State *K, TValue port)
     62 {
     63     UNUSED(K);
     64     UNUSED(port);
     65     return false;
     66 }
     67 
     68 #endif /* HAVE_PLATFORM_ISATTY */