Host introspection: Difference between revisions

Add Neko
(Add Neko)
Line 590:
Endianness: Little
</pre>
 
=={{header|Neko}}==
NekoVM can include shared library functions that adhere to an API of passing Neko values and library file naming. A small C helper is included here to get at the Host wordsize. NekoVM link library search path (.ndll files), includes looking in current directory. The endianess test is a BUILTIN (accessible with leading $ identifier).
 
C support file, host-introspection.c
 
<lang C>/* Return wordsize to Neko */
/* From Rosetta Code, C entry, with Neko marshalling */
 
#include <stdio.h>
#include <stddef.h> /* for size_t */
#include <limits.h> /* for CHAR_BIT */
#include <neko.h>
 
value wordsize(void) {
/*
* Best bet: size_t typically is exactly one word.
*/
return alloc_int((int)(CHAR_BIT * sizeof(size_t)));
}
/* Expose symbol to Neko loader */
DEFINE_PRIM(wordsize, 0);</lang>
 
Neko caller, host-introspection.neko
 
<lang ActionScript>/**
Host introspection, in Neko
*/
 
/* higher order byte first? Intel being little ended. */
$print("isbigendian: ", $isbigendian(), "\n")
 
/*
Getting at word size is a little more difficult in Neko source.
Neko is a fixed bit-width VM, Int is 31 bits, 30 signed, etc.
There is no builtin native sizeof, but a few lines of
C data marshalling wrapper, a small change to tectonics, and...
*/
 
var wordsize = $loader.loadprim("native@wordsize", 0)
$print("wordsize: ", wordsize(), " bits\n")</lang>
 
{{out}}
<pre>
prompt$ gcc -shared -fPIC host-introspection.c -o native.ndll
prompt$ nekoc host-introspection.neko
prompt$ neko host-introspection.n
isbigendian: false
wordsize: 64 bits</pre>
 
=={{header|NetRexx}}==
Anonymous user