Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Host-introspection/00-META.yaml
Normal file
3
Task/Host-introspection/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Host_introspection
|
||||
note: Programming environment operations
|
||||
3
Task/Host-introspection/00-TASK.txt
Normal file
3
Task/Host-introspection/00-TASK.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Print the [[wp:Word_size#Word_size_choice|word size]] and [[wp:Endianness|endianness]] of the host machine.
|
||||
|
||||
See also: [[Variable size/Get]]
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
TestEndianness:
|
||||
LEA UserRam,A0
|
||||
MOVE.L #$0000FFFF,(A0)
|
||||
MOVE.B (A0),D0 ;read the 0th byte stored
|
||||
BEQ isBigEndian ;if this was little endian, the bytes would be stored FF FF 00 00
|
||||
|
||||
;must have been little-endian. Spoiler alert: execution will never reach here
|
||||
LEA LittleEndianMessage,A3
|
||||
JSR PrintString
|
||||
rts
|
||||
isBigEndian:
|
||||
LEA BigEndianMessage,A3
|
||||
JSR PrintString
|
||||
rts
|
||||
|
||||
BigEndianMessage:
|
||||
DC.B "BIG-ENDIAN",0
|
||||
EVEN
|
||||
LittleEndianMessage:
|
||||
DC.B "LITTLE-ENDIAN",0
|
||||
EVEN
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
.model small
|
||||
.stack 1024
|
||||
|
||||
.data
|
||||
|
||||
UserRam BYTE 256 DUP (0)
|
||||
|
||||
.code
|
||||
start:
|
||||
|
||||
mov ax,@data ;assembler calculates this offset for us
|
||||
mov ds,ax ;the 8086 can only load segment registers from other registers, not directly from immediate values.
|
||||
|
||||
mov ax,@code
|
||||
mov es,ax
|
||||
|
||||
mov ax,3422h
|
||||
mov word ptr [ds:UserRam],ax
|
||||
mov bl, byte ptr [ds:UserRam]
|
||||
call doMonitor ;a routine that prints the contents of
|
||||
;the 8086's registers to the screen
|
||||
|
||||
mov ax,4C00h
|
||||
int 21h ;return to MS-DOS
|
||||
|
||||
end start
|
||||
24
Task/Host-introspection/ALGOL-68/host-introspection.alg
Normal file
24
Task/Host-introspection/ALGOL-68/host-introspection.alg
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
INT max abs bit = ABS(BIN 1 SHL 1)-1;
|
||||
INT bits per char = ENTIER (ln(max abs char+1)/ln(max abs bit+1));
|
||||
INT bits per int = ENTIER (1+ln(max int+1.0)/ln(max abs bit+1));
|
||||
|
||||
printf(($"states per bit: "dl$,max abs bit+1));
|
||||
printf(($"bits per char: "z-dl$,bits per char));
|
||||
printf(($"bits per int: "z-dl$,bits per int));
|
||||
printf(($"chars per int: "z-dl$,bits per int OVER bits per char));
|
||||
|
||||
printf(($"bits width: "z-dl$, bits width));
|
||||
|
||||
STRING abcds = "ABCD";
|
||||
FILE abcdf;
|
||||
INT abcdi;
|
||||
|
||||
INT errno := open(abcdf, "abcd.dat",stand back channel);
|
||||
put(abcdf,abcds); # output alphabetically #
|
||||
reset(abcdf);
|
||||
get bin(abcdf,abcdi); # input in word byte order #
|
||||
STRING int byte order := "";
|
||||
FOR shift FROM 0 BY bits per char TO bits per int - bits per char DO
|
||||
int byte order +:= REPR(abcdi OVER (max abs bit+1) ** shift MOD (max abs char+1))
|
||||
OD;
|
||||
printf(($"int byte order: "g,", Hex:",16r8dl$,int byte order, BIN abcdi))
|
||||
10
Task/Host-introspection/ARM-Assembly/host-introspection.arm
Normal file
10
Task/Host-introspection/ARM-Assembly/host-introspection.arm
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
EndianTest:
|
||||
mov r0,#0xFF
|
||||
mov r1,#0x02000000 ;an arbitrary memory location on the Game Boy Advance.
|
||||
;(The GBA is always little-endian but this test doesn't use that knowledge to prove it.)
|
||||
str r0,[r1] ;on a little-endian CPU a hexdump of 0x02000000 would be: FF 00 00 00
|
||||
;on a big-endian CPU it would be: 00 00 00 FF
|
||||
ldrB r0,[r1] ;load just the byte at 0x02000000. If the machine is big-endian this will load 00; if little-endian, 0xFF.
|
||||
cmp r0,#0
|
||||
beq isBigEndian
|
||||
;else, do whatever is needed to display "little-endian" to the screen. This part isn't implemented.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
PROC Main()
|
||||
PrintE("All Atari 8-bit computers use little-endian word of 16-bits size.")
|
||||
RETURN
|
||||
8
Task/Host-introspection/Ada/host-introspection.ada
Normal file
8
Task/Host-introspection/Ada/host-introspection.ada
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with System; use System;
|
||||
|
||||
procedure Host_Introspection is
|
||||
begin
|
||||
Put_Line ("Word size" & Integer'Image (Word_Size));
|
||||
Put_Line ("Endianness " & Bit_Order'Image (Default_Bit_Order));
|
||||
end Host_Introspection;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
1 DATA248,169,153,24,105,1,48
|
||||
2 DATA6,24,251,144,2,251,56
|
||||
3 DATA216,105,0,133,251,96
|
||||
4 FOR I = 768 TO 787
|
||||
5 READ B: POKE I,B: NEXT
|
||||
6 CALL 768:M = PEEK (251)
|
||||
7 PRINT " WORD SIZE: ";
|
||||
8 IF NOT M THEN PRINT 8
|
||||
9 M$ = "HYBRID 8/16"
|
||||
10 IF M THEN PRINT M$
|
||||
11 PRINT "ENDIANNESS: ";
|
||||
12 PRINT "LITTLE-ENDIAN"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
DIM P% 8
|
||||
!P% = -1
|
||||
I% = 0 : REPEAT I% += 1 : UNTIL P%?I%=0
|
||||
PRINT "Word size = " ; I% " bytes"
|
||||
!P% = 1
|
||||
IF P%?0 = 1 THEN PRINT "Little-endian"
|
||||
IF P%?(I%-1) = 1 THEN PRINT "Big-endian"
|
||||
3
Task/Host-introspection/Babel/host-introspection.pb
Normal file
3
Task/Host-introspection/Babel/host-introspection.pb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
main :
|
||||
{ "Word size: " << msize 3 shl %d << " bits" cr <<
|
||||
"Endianness: " << { endian } { "little" } { "big" } ifte cr << }
|
||||
17
Task/Host-introspection/C++/host-introspection.cpp
Normal file
17
Task/Host-introspection/C++/host-introspection.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <bit>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "int is " << sizeof(int) << " bytes\n";
|
||||
std::cout << "a pointer is " << sizeof(int*) << " bytes\n\n";
|
||||
|
||||
if (std::endian::native == std::endian::big)
|
||||
{
|
||||
std::cout << "platform is big-endian\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "host is little-endian\n";
|
||||
}
|
||||
}
|
||||
9
Task/Host-introspection/C-sharp/host-introspection.cs
Normal file
9
Task/Host-introspection/C-sharp/host-introspection.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
static void Main()
|
||||
{
|
||||
Console.WriteLine("Word size = {0} bytes,",sizeof(int));
|
||||
|
||||
if (BitConverter.IsLittleEndian)
|
||||
Console.WriteLine("Little-endian.");
|
||||
else
|
||||
Console.WriteLine("Big-endian.");
|
||||
}
|
||||
22
Task/Host-introspection/C/host-introspection-1.c
Normal file
22
Task/Host-introspection/C/host-introspection-1.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
#include <stddef.h> /* for size_t */
|
||||
#include <limits.h> /* for CHAR_BIT */
|
||||
|
||||
int main() {
|
||||
int one = 1;
|
||||
|
||||
/*
|
||||
* Best bet: size_t typically is exactly one word.
|
||||
*/
|
||||
printf("word size = %d bits\n", (int)(CHAR_BIT * sizeof(size_t)));
|
||||
|
||||
/*
|
||||
* Check if the least significant bit is located
|
||||
* in the lowest-address byte.
|
||||
*/
|
||||
if (*(char *)&one)
|
||||
printf("little endian\n");
|
||||
else
|
||||
printf("big endian\n");
|
||||
return 0;
|
||||
}
|
||||
10
Task/Host-introspection/C/host-introspection-2.c
Normal file
10
Task/Host-introspection/C/host-introspection-2.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
if (htonl(1) == 1)
|
||||
printf("big endian\n");
|
||||
else
|
||||
printf("little endian\n");
|
||||
}
|
||||
2
Task/Host-introspection/Clojure/host-introspection.clj
Normal file
2
Task/Host-introspection/Clojure/host-introspection.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(println "word size: " (System/getProperty "sun.arch.data.model"))
|
||||
(println "endianness: " (System/getProperty "sun.cpu.endian"))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(machine-type) ;; => "X86-64" on SBCL here
|
||||
6
Task/Host-introspection/D/host-introspection.d
Normal file
6
Task/Host-introspection/D/host-introspection.d
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
void main() {
|
||||
import std.stdio, std.system;
|
||||
|
||||
writeln("Word size = ", size_t.sizeof * 8, " bits.");
|
||||
writeln(endian == Endian.littleEndian ? "Little" : "Big", " endian.");
|
||||
}
|
||||
10
Task/Host-introspection/Delphi/host-introspection.delphi
Normal file
10
Task/Host-introspection/Delphi/host-introspection.delphi
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
program HostIntrospection ;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses SysUtils;
|
||||
|
||||
begin
|
||||
Writeln('word size: ', SizeOf(Integer));
|
||||
Writeln('endianness: little endian'); // Windows is always little endian
|
||||
end.
|
||||
2
Task/Host-introspection/Erlang/host-introspection-1.erl
Normal file
2
Task/Host-introspection/Erlang/host-introspection-1.erl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
1> erlang:system_info(wordsize).
|
||||
4
|
||||
6
Task/Host-introspection/Erlang/host-introspection-2.erl
Normal file
6
Task/Host-introspection/Erlang/host-introspection-2.erl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
1> <<1:4/native-unit:8>>.
|
||||
<<1,0,0,0>>
|
||||
2> <<1:4/big-unit:8>>
|
||||
<<0,0,0,1>>
|
||||
3> <<1:4/little-unit:8>>.
|
||||
<<1,0,0,0>>
|
||||
2
Task/Host-introspection/Erlang/host-introspection-3.erl
Normal file
2
Task/Host-introspection/Erlang/host-introspection-3.erl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
endianness() when <<1:4/native-unit:8>> =:= <<1:4/big-unit:8>> -> big;
|
||||
endianness() -> little.
|
||||
14
Task/Host-introspection/F-Sharp/host-introspection.fs
Normal file
14
Task/Host-introspection/F-Sharp/host-introspection.fs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
open System
|
||||
open System.Runtime.InteropServices
|
||||
open System.Diagnostics
|
||||
|
||||
[<DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)>]
|
||||
extern bool IsWow64Process(nativeint hProcess, bool &wow64Process);
|
||||
|
||||
let answerHostInfo =
|
||||
let Is64Bit() =
|
||||
let mutable f64Bit = false;
|
||||
IsWow64Process(Process.GetCurrentProcess().Handle, &f64Bit) |> ignore
|
||||
f64Bit
|
||||
let IsLittleEndian() = BitConverter.IsLittleEndian
|
||||
(IsLittleEndian(), Is64Bit())
|
||||
3
Task/Host-introspection/Factor/host-introspection.factor
Normal file
3
Task/Host-introspection/Factor/host-introspection.factor
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
USING: alien.c-types alien.data io layouts ;
|
||||
"Word size: " write cell 8 * .
|
||||
"Endianness: " write little-endian? "little" "big" ? print
|
||||
4
Task/Host-introspection/Forth/host-introspection.fth
Normal file
4
Task/Host-introspection/Forth/host-introspection.fth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
: endian
|
||||
cr 1 cells . ." address units per cell"
|
||||
s" ADDRESS-UNIT-BITS" environment? if cr . ." bits per address unit" then
|
||||
cr 1 here ! here c@ if ." little" else ." big" then ." endian" ;
|
||||
13
Task/Host-introspection/Fortran/host-introspection.f
Normal file
13
Task/Host-introspection/Fortran/host-introspection.f
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
integer :: i
|
||||
character(len=1) :: c(20)
|
||||
equivalence (c, i)
|
||||
|
||||
WRITE(*,*) bit_size(1) ! number of bits in the default integer type
|
||||
! which may (or may not!) equal the word size
|
||||
i = 1
|
||||
|
||||
IF (ichar(c(1)) == 0) THEN
|
||||
WRITE(*,*) "Big Endian"
|
||||
ELSE
|
||||
WRITE(*,*) "Little Endian"
|
||||
END IF
|
||||
17
Task/Host-introspection/FreeBASIC/host-introspection.basic
Normal file
17
Task/Host-introspection/FreeBASIC/host-introspection.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
' FB 1.05.0 Win64 (so little endian, 8 byte word size, expected)
|
||||
|
||||
' uses intrinsic defines, set by the compiler
|
||||
|
||||
#Ifdef __FB_64BIT__
|
||||
Print "Host has an 8 byte word size"
|
||||
#Else
|
||||
Print "Host has a 4 byte word size"
|
||||
#EndIf
|
||||
|
||||
#Ifdef __FB_BIGENDIAN__
|
||||
Print "Host is big endian"
|
||||
#Else
|
||||
Print "Host is little endian"
|
||||
#EndIf
|
||||
|
||||
Sleep
|
||||
2
Task/Host-introspection/Frink/host-introspection.frink
Normal file
2
Task/Host-introspection/Frink/host-introspection.frink
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
println["Word size: " + callJava["java.lang.System", "getProperty", "sun.arch.data.model"]]
|
||||
println["Endianness: " + callJava["java.lang.System", "getProperty", "sun.cpu.endian"]]
|
||||
71
Task/Host-introspection/Go/host-introspection-1.go
Normal file
71
Task/Host-introspection/Go/host-introspection-1.go
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||
|
||||
// Inspect a uint32 variable to determine endianness.
|
||||
x := uint32(0x01020304)
|
||||
switch *(*byte)(unsafe.Pointer(&x)) {
|
||||
case 0x01:
|
||||
fmt.Println("big endian")
|
||||
case 0x04:
|
||||
fmt.Println("little endian")
|
||||
default:
|
||||
fmt.Println("mixed endian?")
|
||||
}
|
||||
|
||||
// Usually one cares about the size the executible was compiled for
|
||||
// rather than the actual underlying host's size.
|
||||
|
||||
// There are several ways of determining the size of an int/uint.
|
||||
fmt.Println(" strconv.IntSize =", strconv.IntSize)
|
||||
// That uses the following definition we can also be done by hand
|
||||
intSize := 32 << uint(^uint(0)>>63)
|
||||
fmt.Println("32 << uint(^uint(0)>>63) =", intSize)
|
||||
|
||||
// With Go 1.0, 64-bit architectures had 32-bit int and 64-bit
|
||||
// uintptr. This was changed in Go 1.1. In general it would
|
||||
// still be possible that int and uintptr (the type large enough
|
||||
// to hold the bit pattern of any pointer) are of different sizes.
|
||||
const bitsPerByte = 8
|
||||
fmt.Println(" sizeof(int) in bits:", unsafe.Sizeof(int(0))*bitsPerByte)
|
||||
fmt.Println(" sizeof(uintptr) in bits:", unsafe.Sizeof(uintptr(0))*bitsPerByte)
|
||||
// If we really want to know the architecture size the executable was
|
||||
// compiled for and not the size of int it safest to take the max of those.
|
||||
archSize := unsafe.Sizeof(int(0))
|
||||
if psize := unsafe.Sizeof(uintptr(0)); psize > archSize {
|
||||
archSize = psize
|
||||
}
|
||||
fmt.Println(" compiled with word size:", archSize*bitsPerByte)
|
||||
|
||||
// There are some *very* unportable ways to attempt to get the actual
|
||||
// underlying hosts' word size.
|
||||
// Inspect cpuinfo to determine word size (some unix-like OS' only).
|
||||
c, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
ls := strings.Split(string(c), "\n")
|
||||
for _, l := range ls {
|
||||
if strings.HasPrefix(l, "flags") {
|
||||
for _, f := range strings.Fields(l) {
|
||||
if f == "lm" { // "long mode"
|
||||
fmt.Println("64 bit word size")
|
||||
return
|
||||
}
|
||||
}
|
||||
fmt.Println("32 bit word size")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Task/Host-introspection/Go/host-introspection-2.go
Normal file
17
Task/Host-introspection/Go/host-introspection-2.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"debug/elf"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f, err := elf.Open(os.Args[0])
|
||||
if err != nil {
|
||||
fmt.Println(" ", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(f.FileHeader.ByteOrder)
|
||||
f.Close()
|
||||
}
|
||||
2
Task/Host-introspection/Groovy/host-introspection.groovy
Normal file
2
Task/Host-introspection/Groovy/host-introspection.groovy
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
println "word size: ${System.getProperty('sun.arch.data.model')}"
|
||||
println "endianness: ${System.getProperty('sun.cpu.endian')}"
|
||||
8
Task/Host-introspection/Haskell/host-introspection.hs
Normal file
8
Task/Host-introspection/Haskell/host-introspection.hs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import Data.Bits
|
||||
import ADNS.Endian -- http://hackage.haskell.org/package/hsdns
|
||||
|
||||
main = do
|
||||
putStrLn $ "Word size: " ++ bitsize
|
||||
putStrLn $ "Endianness: " ++ show endian
|
||||
where
|
||||
bitsize = show $ bitSize (undefined :: Int)
|
||||
6
Task/Host-introspection/Icon/host-introspection.icon
Normal file
6
Task/Host-introspection/Icon/host-introspection.icon
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
procedure main()
|
||||
write(if 0 = ishift(1,-1) then "little" else "big"," endian")
|
||||
if match("flags",line := !open("/proc/cpuinfo")) then # Unix-like only
|
||||
write(if find(" lm ",line) then 64 else 32," bits per word")
|
||||
else write("Cannot determine word size.")
|
||||
end
|
||||
2
Task/Host-introspection/J/host-introspection-1.j
Normal file
2
Task/Host-introspection/J/host-introspection-1.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
IF64 {32 64
|
||||
64
|
||||
2
Task/Host-introspection/J/host-introspection-2.j
Normal file
2
Task/Host-introspection/J/host-introspection-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
2+2^.>./1&(33 b.)^:a:1
|
||||
64
|
||||
3
Task/Host-introspection/J/host-introspection-3.j
Normal file
3
Task/Host-introspection/J/host-introspection-3.j
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
":&> (|: 32 64 ;"0 big`little) {"_1~ 2 2 #: 16b_e0 + a. i. 0 { 3!:1 ''
|
||||
64
|
||||
little
|
||||
8
Task/Host-introspection/Java/host-introspection-1.java
Normal file
8
Task/Host-introspection/Java/host-introspection-1.java
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import java.nio.ByteOrder;
|
||||
|
||||
public class ShowByteOrder {
|
||||
public static void main(String[] args) {
|
||||
// Print "BIG_ENDIAN" or "LITTLE_ENDIAN".
|
||||
System.out.println(ByteOrder.nativeOrder());
|
||||
}
|
||||
}
|
||||
2
Task/Host-introspection/Java/host-introspection-2.java
Normal file
2
Task/Host-introspection/Java/host-introspection-2.java
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
System.out.println("word size: "+System.getProperty("sun.arch.data.model"));
|
||||
System.out.println("endianness: "+System.getProperty("sun.cpu.endian"));
|
||||
8
Task/Host-introspection/Julia/host-introspection.julia
Normal file
8
Task/Host-introspection/Julia/host-introspection.julia
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
print("This host's word size is ", WORD_SIZE, ".")
|
||||
if ENDIAN_BOM == 0x04030201
|
||||
println("And it is a little-endian machine.")
|
||||
elseif ENDIAN_BOM == 0x01020304
|
||||
println("And it is a big-endian machine.")
|
||||
else
|
||||
println("ENDIAN_BOM = ", ENDIAN_BOM, ", which is confusing")
|
||||
end
|
||||
6
Task/Host-introspection/Kotlin/host-introspection.kotlin
Normal file
6
Task/Host-introspection/Kotlin/host-introspection.kotlin
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// version 1.0.6
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("Word size : ${System.getProperty("sun.arch.data.model")} bits")
|
||||
println("Endianness: ${System.getProperty("sun.cpu.endian")}-endian")
|
||||
}
|
||||
4
Task/Host-introspection/Lua/host-introspection.lua
Normal file
4
Task/Host-introspection/Lua/host-introspection.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
ffi = require("ffi")
|
||||
print("size of int (in bytes): " .. ffi.sizeof(ffi.new("int")))
|
||||
print("size of pointer (in bytes): " .. ffi.sizeof(ffi.new("int*")))
|
||||
print((ffi.abi("le") and "little" or "big") .. " endian")
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
Module CheckIt {
|
||||
\\ Always run in Little-endian, 32 bits (in Wow64 in 64 bit os)
|
||||
Module EndiannessAndSize {
|
||||
Buffer Check as Long
|
||||
Return Check, 0:=1
|
||||
if eval(Check, 0 as byte)=1 then {
|
||||
Print "Little-endian"
|
||||
}
|
||||
\\ 4 bytes
|
||||
Print "Word size:"; Len(Check)*8;" bits"
|
||||
}
|
||||
EndiannessAndSize
|
||||
\\ Access to internal com object clsOsInfo
|
||||
Declare OsInfo Information
|
||||
Print Type$(OsInfo) ="clsOSInfo"
|
||||
\\ Build is a read only property
|
||||
With OsInfo, "Build" as Build, "OSName" as OSName$, "IsElevated" as IsElevated
|
||||
Print OsName$
|
||||
Print "Build=";Build
|
||||
\\ IsWow64 is a function
|
||||
Method OsInfo, "IsWow64" as IsWow64
|
||||
If IsWow64 Then {
|
||||
Print "64 bit Os"
|
||||
} Else {
|
||||
Print "32 bit OS"
|
||||
}
|
||||
Print "IsElevated:";IsElevated
|
||||
}
|
||||
Checkit
|
||||
17
Task/Host-introspection/MATLAB/host-introspection.m
Normal file
17
Task/Host-introspection/MATLAB/host-introspection.m
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
function [endian]=endian()
|
||||
fid=tmpfile();
|
||||
fwrite(fid,1:8,'uint8');
|
||||
|
||||
fseek(fid,0,'bof');
|
||||
t=fread(fid,8,'int8');
|
||||
i8=sprintf('%02X',t);
|
||||
|
||||
fseek(fid,0,'bof');
|
||||
t=fread(fid,4,'int16');
|
||||
i16=sprintf('%04X',t);
|
||||
|
||||
fclose(fid);
|
||||
|
||||
if strcmp(i8,i16) endian='big';
|
||||
else endian='little';
|
||||
end;
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
jal Cls ;Zero Graphics cursor position
|
||||
nop ;on the PlayStation, the instruction AFTER a branch gets executed BEFORE the branch actually occurs.
|
||||
;The Nintendo 64 didn't have this "feature" but for compatibility's sake
|
||||
; it's staying in regardless of which version of the code I'm using.
|
||||
|
||||
la a2,TestData ;Load address of TestData
|
||||
|
||||
lw a0,(a2) ;Load Word into A0 from address in A2
|
||||
|
||||
addiu a2,4 ;pointer arithmetic to load the next word.
|
||||
lw a1,(a2)
|
||||
|
||||
move t6,ra
|
||||
jal MonitorA0A1RAPC
|
||||
nop
|
||||
|
||||
li t6,2 ;Line Count - 2 lines = 16 bytes
|
||||
jal MemDump ;Dump Ram to screen
|
||||
nop
|
||||
|
||||
halt:
|
||||
j halt ;loop forever
|
||||
nop
|
||||
|
||||
|
||||
|
||||
|
||||
TestData:
|
||||
.byte 0xF3,0xF2,0xF1,0xF0 ;this will load as F0F1F2F3 on little-endian machines, and as-is on big-endian
|
||||
.word 0xF0F1F2F3 ;this will load as F0F1F2F3 regardless of endianness.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
If[$ByteOrdering > 0, Print["Big endian"], Print["Little endian" ]]
|
||||
$SystemWordLength "bits"
|
||||
12
Task/Host-introspection/Modula-3/host-introspection.mod3
Normal file
12
Task/Host-introspection/Modula-3/host-introspection.mod3
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
MODULE Host EXPORTS Main;
|
||||
|
||||
IMPORT IO, Fmt, Word, Swap;
|
||||
|
||||
BEGIN
|
||||
IO.Put("Word Size: " & Fmt.Int(Word.Size) & "\n");
|
||||
IF Swap.endian = Swap.Endian.Big THEN
|
||||
IO.Put("Endianness: Big\n");
|
||||
ELSE
|
||||
IO.Put("Endianness: Little\n");
|
||||
END;
|
||||
END Host.
|
||||
16
Task/Host-introspection/Neko/host-introspection-1.neko
Normal file
16
Task/Host-introspection/Neko/host-introspection-1.neko
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/* 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);
|
||||
16
Task/Host-introspection/Neko/host-introspection-2.neko
Normal file
16
Task/Host-introspection/Neko/host-introspection-2.neko
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
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")
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref savelog symbols nobinary
|
||||
|
||||
wordSize = System.getProperty('sun.arch.data.model')
|
||||
endian = System.getProperty('sun.cpu.endian')
|
||||
|
||||
say ' word size:' wordSize
|
||||
say 'endianness:' endian
|
||||
2
Task/Host-introspection/Nim/host-introspection.nim
Normal file
2
Task/Host-introspection/Nim/host-introspection.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
echo cpuEndian
|
||||
echo sizeof(int) * 8
|
||||
2
Task/Host-introspection/OCaml/host-introspection-1.ocaml
Normal file
2
Task/Host-introspection/OCaml/host-introspection-1.ocaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Printf.printf "%d\n" Sys.word_size; (* Print word size *)
|
||||
Printf.printf "%s\n" Sys.os_type; (* Print operating system *)
|
||||
2
Task/Host-introspection/OCaml/host-introspection-2.ocaml
Normal file
2
Task/Host-introspection/OCaml/host-introspection-2.ocaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(* Print endianness *)
|
||||
Printf.printf "%s\n" (if Sys.big_endian then "big endian" else "little endian");
|
||||
8
Task/Host-introspection/OCaml/host-introspection-3.ocaml
Normal file
8
Task/Host-introspection/OCaml/host-introspection-3.ocaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let uname arg =
|
||||
let arg = if arg = "" then "-" else arg in
|
||||
let ic = Unix.open_process_in ("uname -" ^ arg) in
|
||||
(input_line ic)
|
||||
;;
|
||||
|
||||
# uname "sm";;
|
||||
- : string = "Linux i686"
|
||||
34
Task/Host-introspection/OCaml/host-introspection-4.ocaml
Normal file
34
Task/Host-introspection/OCaml/host-introspection-4.ocaml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
(* Reading all the lines from a file.
|
||||
If the loop is implemented by a recursive auxiliary function, the try...with breaks
|
||||
tail recursion if not written carefully *)
|
||||
let lines name =
|
||||
let f = open_in name
|
||||
and r = ref []
|
||||
in
|
||||
(try
|
||||
while true do
|
||||
r := (input_line f)::!r
|
||||
done
|
||||
with End_of_file -> close_in f);
|
||||
(List.rev !r)
|
||||
;;
|
||||
|
||||
# lines "/proc/meminfo";;
|
||||
- : string list =
|
||||
["MemTotal: 2075240 kB"; "MemFree: 469964 kB";
|
||||
"Buffers: 34512 kB"; "Cached: 1296380 kB";
|
||||
"SwapCached: 96 kB"; "Active: 317484 kB";
|
||||
"Inactive: 1233500 kB"; "HighTotal: 1178432 kB";
|
||||
"HighFree: 45508 kB"; "LowTotal: 896808 kB";
|
||||
"LowFree: 424456 kB"; "SwapTotal: 2650684 kB";
|
||||
"SwapFree: 2650588 kB"; "Dirty: 228 kB";
|
||||
"Writeback: 0 kB"; "AnonPages: 220036 kB";
|
||||
"Mapped: 67160 kB"; "Slab: 41540 kB";
|
||||
"SReclaimable: 34872 kB"; "SUnreclaim: 6668 kB";
|
||||
"PageTables: 1880 kB"; "NFS_Unstable: 0 kB";
|
||||
"Bounce: 0 kB"; "WritebackTmp: 0 kB";
|
||||
"CommitLimit: 3688304 kB"; "Committed_AS: 549912 kB";
|
||||
"VmallocTotal: 114680 kB"; "VmallocUsed: 5172 kB";
|
||||
"VmallocChunk: 109320 kB"; "HugePages_Total: 0";
|
||||
"HugePages_Free: 0"; "HugePages_Rsvd: 0";
|
||||
"HugePages_Surp: 0"; "Hugepagesize: 4096 kB"]
|
||||
11
Task/Host-introspection/Objective-C/host-introspection-1.m
Normal file
11
Task/Host-introspection/Objective-C/host-introspection-1.m
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
switch (NSHostByteOrder()) {
|
||||
case NS_BigEndian:
|
||||
NSLog(@"%@", @"Big Endian");
|
||||
break;
|
||||
case NS_LittleEndian:
|
||||
NSLog(@"%@", @"Little Endian");
|
||||
break;
|
||||
case NS_UnknownByteOrder:
|
||||
NSLog(@"%@", @"endianness unknown");
|
||||
break;
|
||||
}
|
||||
21
Task/Host-introspection/Objective-C/host-introspection-2.m
Normal file
21
Task/Host-introspection/Objective-C/host-introspection-2.m
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
switch ([NSRunningApplication currentApplication].executableArchitecture) {
|
||||
case NSBundleExecutableArchitectureI386:
|
||||
NSLog(@"%@", @"i386 32-bit");
|
||||
break;
|
||||
|
||||
case NSBundleExecutableArchitectureX86_64:
|
||||
NSLog(@"%@", @"x86_64 64-bit");
|
||||
break;
|
||||
|
||||
case NSBundleExecutableArchitecturePPC:
|
||||
NSLog(@"%@", @"PPC 32-bit");
|
||||
break;
|
||||
|
||||
case NSBundleExecutableArchitecturePPC64:
|
||||
NSLog(@"%@", @"PPC64 64-bit");
|
||||
break;
|
||||
|
||||
default:
|
||||
NSLog(@"%@", @"Unknown");
|
||||
break;
|
||||
}
|
||||
11
Task/Host-introspection/PL-I/host-introspection.pli
Normal file
11
Task/Host-introspection/PL-I/host-introspection.pli
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
details: procedure options (main); /* 6 July 2012 */
|
||||
declare x float, i fixed binary initial (1);
|
||||
|
||||
put skip list ('word size=', length(unspec(x)));
|
||||
|
||||
if unspec(i) = '0000000000000001'b then
|
||||
put skip list ('Big endian');
|
||||
else
|
||||
put skip list ('Little endian');
|
||||
|
||||
end details;
|
||||
9
Task/Host-introspection/Pascal/host-introspection.pas
Normal file
9
Task/Host-introspection/Pascal/host-introspection.pas
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
program HostIntrospection(output);
|
||||
begin
|
||||
writeln('Pointer size: ', SizeOf(Pointer), ' byte, i.e. ', SizeOf(Pointer)*8, ' bit.');
|
||||
{ NtoBE converts from native endianess to big endianess }
|
||||
if 23453 = NtoBE(23453) then
|
||||
writeln('This host is big endian.')
|
||||
else
|
||||
writeln('This host is little endian.');
|
||||
end.
|
||||
2
Task/Host-introspection/Perl/host-introspection-1.pl
Normal file
2
Task/Host-introspection/Perl/host-introspection-1.pl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
use Config;
|
||||
print "UV size: $Config{uvsize}, byte order: $Config{byteorder}\n";
|
||||
9
Task/Host-introspection/Perl/host-introspection-2.pl
Normal file
9
Task/Host-introspection/Perl/host-introspection-2.pl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use 5.010;
|
||||
use Config;
|
||||
my ($size, $order, $end) = @Config{qw(uvsize byteorder)};
|
||||
given ($order) {
|
||||
when (join '', sort split '') { $end = 'little' }
|
||||
when (join '', reverse sort split '') { $end = 'big' }
|
||||
default { $end = 'mixed' }
|
||||
}
|
||||
say "UV size: $size, byte order: $order ($end-endian)";
|
||||
22
Task/Host-introspection/Phix/host-introspection.phix
Normal file
22
Task/Host-introspection/Phix/host-introspection.phix
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">endianness</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #008000;">"n/a (web browser)"</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">m4</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">allocate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #7060A8;">poke4</span><span style="color: #0000FF;">(</span><span style="color: #000000;">m4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#01020304</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">b1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">peek1s</span><span style="color: #0000FF;">(</span><span style="color: #000000;">m4</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #7060A8;">free</span><span style="color: #0000FF;">(</span><span style="color: #000000;">m4</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">b1</span><span style="color: #0000FF;">=</span><span style="color: #000000;">#01</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #008000;">"big-endian"</span>
|
||||
<span style="color: #008080;">elsif</span> <span style="color: #000000;">b1</span><span style="color: #0000FF;">=</span><span style="color: #000000;">#04</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #008000;">"little-endian"</span>
|
||||
<span style="color: #008080;">else</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #008000;">"???"</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Endianness: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">endianness</span><span style="color: #0000FF;">()})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Word size: %d bytes/%d bits\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">machine_word</span><span style="color: #0000FF;">(),</span><span style="color: #7060A8;">machine_bits</span><span style="color: #0000FF;">()})</span>
|
||||
<!--
|
||||
12
Task/Host-introspection/PicoLisp/host-introspection.l
Normal file
12
Task/Host-introspection/PicoLisp/host-introspection.l
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
(in (cmd) # Inspect ELF header
|
||||
(rd 4) # Skip "7F" and 'E', 'L' and 'F'
|
||||
(prinl
|
||||
(case (rd 1) # Get EI_CLASS byte
|
||||
(1 "32 bits")
|
||||
(2 "64 bits")
|
||||
(T "Bad EI_CLASS") ) )
|
||||
(prinl
|
||||
(case (rd 1) # Get EI_DATA byte
|
||||
(1 "Little endian")
|
||||
(2 "Big endian")
|
||||
(T "Bad EI_DATA") ) ) )
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
Write-Host Word Size: ((Get-WMIObject Win32_Processor).DataWidth)
|
||||
Write-Host -NoNewLine "Endianness: "
|
||||
if ([BitConverter]::IsLittleEndian) {
|
||||
Write-Host Little-Endian
|
||||
} else {
|
||||
Write-Host Big-Endian
|
||||
}
|
||||
24
Task/Host-introspection/PureBasic/host-introspection.basic
Normal file
24
Task/Host-introspection/PureBasic/host-introspection.basic
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Enumeration
|
||||
#LittleEndian
|
||||
#BigEndian
|
||||
EndEnumeration
|
||||
|
||||
ProcedureDLL EndianTest()
|
||||
Protected Endian = #LittleEndian
|
||||
Protected dummy.l= 'ABCD'
|
||||
If "A"=Chr(PeekA(@dummy))
|
||||
Endian=#BigEndian
|
||||
EndIf
|
||||
ProcedureReturn Endian
|
||||
EndProcedure
|
||||
|
||||
;- *** Start of test code
|
||||
If OpenConsole()
|
||||
PrintN("Your word size is "+Str(SizeOf(Integer)) +" bytes,")
|
||||
Select EndianTest()
|
||||
Case #LittleEndian
|
||||
PrintN("and you use Little Endian.")
|
||||
Default
|
||||
PrintN("and you use Big Endian.")
|
||||
EndSelect
|
||||
EndIf
|
||||
14
Task/Host-introspection/Python/host-introspection.py
Normal file
14
Task/Host-introspection/Python/host-introspection.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
>>> import platform, sys, socket
|
||||
>>> platform.architecture()
|
||||
('64bit', 'ELF')
|
||||
>>> platform.machine()
|
||||
'x86_64'
|
||||
>>> platform.node()
|
||||
'yourhostname'
|
||||
>>> platform.system()
|
||||
'Linux'
|
||||
>>> sys.byteorder
|
||||
little
|
||||
>>> socket.gethostname()
|
||||
'yourhostname'
|
||||
>>>
|
||||
1
Task/Host-introspection/R/host-introspection-1.r
Normal file
1
Task/Host-introspection/R/host-introspection-1.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
8 * .Machine$sizeof.long # e.g. 32
|
||||
1
Task/Host-introspection/R/host-introspection-2.r
Normal file
1
Task/Host-introspection/R/host-introspection-2.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
.Platform$endian # e.g. "little"
|
||||
6
Task/Host-introspection/REXX/host-introspection.rexx
Normal file
6
Task/Host-introspection/REXX/host-introspection.rexx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
/*REXX program to examine which operating system that REXX is running under. */
|
||||
|
||||
parse source opSys howInvoked pathName
|
||||
|
||||
/*where opSys will indicate which operating system REXX is running under, and */
|
||||
/*from that, one could make assumptions what the wordsize is, etc. */
|
||||
4
Task/Host-introspection/Racket/host-introspection.rkt
Normal file
4
Task/Host-introspection/Racket/host-introspection.rkt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#lang racket/base
|
||||
|
||||
(printf "Word size: ~a\n" (system-type 'word))
|
||||
(printf "Endianness: ~a\n" (if (system-big-endian?) 'big 'little))
|
||||
4
Task/Host-introspection/Raku/host-introspection-1.raku
Normal file
4
Task/Host-introspection/Raku/host-introspection-1.raku
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
use NativeCall;
|
||||
say $*VM.config<ptr_size>;
|
||||
my $bytes = nativecast(CArray[uint8], CArray[uint16].new(1));
|
||||
say $bytes[0] ?? "little-endian" !! "big-endian";
|
||||
1
Task/Host-introspection/Raku/host-introspection-2.raku
Normal file
1
Task/Host-introspection/Raku/host-introspection-2.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
say blob8.new(1,0).read-int16(0) == 1 ?? "little-endian" !! "big-endian"
|
||||
1
Task/Host-introspection/Raku/host-introspection-3.raku
Normal file
1
Task/Host-introspection/Raku/host-introspection-3.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
say join ', ', $*KERNEL, $*KERNEL.bits, $*KERNEL.arch, $*KERNEL.endian
|
||||
2
Task/Host-introspection/Retro/host-introspection-1.retro
Normal file
2
Task/Host-introspection/Retro/host-introspection-1.retro
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
needs variations'
|
||||
^variations'size
|
||||
2
Task/Host-introspection/Retro/host-introspection-2.retro
Normal file
2
Task/Host-introspection/Retro/host-introspection-2.retro
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
needs variations'
|
||||
^variations'endian
|
||||
10
Task/Host-introspection/Ruby/host-introspection.rb
Normal file
10
Task/Host-introspection/Ruby/host-introspection.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# We assume that a Fixnum occupies one machine word.
|
||||
# Fixnum#size returns bytes (1 byte = 8 bits).
|
||||
word_size = 42.size * 8
|
||||
puts "Word size: #{word_size} bits"
|
||||
|
||||
# Array#pack knows the native byte order. We pack 1 as a 16-bit integer,
|
||||
# then unpack bytes: [0, 1] is big endian, [1, 0] is little endian.
|
||||
bytes = [1].pack('S').unpack('C*')
|
||||
byte_order = (bytes[0] == 0 ? 'big' : 'little') + ' endian'
|
||||
puts "Byte order: #{byte_order}"
|
||||
22
Task/Host-introspection/Rust/host-introspection.rust
Normal file
22
Task/Host-introspection/Rust/host-introspection.rust
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#[derive(Copy, Clone, Debug)]
|
||||
enum Endianness {
|
||||
Big, Little,
|
||||
}
|
||||
|
||||
impl Endianness {
|
||||
fn target() -> Self {
|
||||
#[cfg(target_endian = "big")]
|
||||
{
|
||||
Endianness::Big
|
||||
}
|
||||
#[cfg(not(target_endian = "big"))]
|
||||
{
|
||||
Endianness::Little
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Word size: {} bytes", std::mem::size_of::<usize>());
|
||||
println!("Endianness: {:?}", Endianness::target());
|
||||
}
|
||||
7
Task/Host-introspection/Scala/host-introspection.scala
Normal file
7
Task/Host-introspection/Scala/host-introspection.scala
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import java.nio.ByteOrder
|
||||
|
||||
object ShowByteOrder extends App {
|
||||
println(ByteOrder.nativeOrder())
|
||||
println(s"Word size: ${System.getProperty("sun.arch.data.model")}")
|
||||
println(s"Endianness: ${System.getProperty("sun.cpu.endian")}")
|
||||
}
|
||||
8
Task/Host-introspection/Scheme/host-introspection.ss
Normal file
8
Task/Host-introspection/Scheme/host-introspection.ss
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(define host-info
|
||||
(begin
|
||||
(display "Endianness: ")
|
||||
(display (machine-byte-order))
|
||||
(newline)
|
||||
(display "Word Size: ")
|
||||
(display (if (fixnum? (expt 2 33)) 64 32))
|
||||
(newline)))
|
||||
13
Task/Host-introspection/Seed7/host-introspection.seed7
Normal file
13
Task/Host-introspection/Seed7/host-introspection.seed7
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "cc_conf.s7i";
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
writeln("Word size: " <& ccConf.POINTER_SIZE);
|
||||
write("Endianness: ");
|
||||
if ccConf.LITTLE_ENDIAN_INTTYPE then
|
||||
writeln("Little endian");
|
||||
else
|
||||
writeln("Big endian");
|
||||
end if;
|
||||
end func;
|
||||
2
Task/Host-introspection/Slate/host-introspection.slate
Normal file
2
Task/Host-introspection/Slate/host-introspection.slate
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
inform: 'Endianness: ' ; Platform current endianness.
|
||||
inform: 'Word Size: ' ; (Platform current bytesPerWord * 8) printString.
|
||||
|
|
@ -0,0 +1 @@
|
|||
Disp "32-bit big-endian"
|
||||
10
Task/Host-introspection/Tcl/host-introspection.tcl
Normal file
10
Task/Host-introspection/Tcl/host-introspection.tcl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
% parray tcl_platform
|
||||
tcl_platform(byteOrder) = littleEndian
|
||||
tcl_platform(machine) = intel
|
||||
tcl_platform(os) = Windows NT
|
||||
tcl_platform(osVersion) = 5.1
|
||||
tcl_platform(platform) = windows
|
||||
tcl_platform(pointerSize) = 4
|
||||
tcl_platform(threaded) = 1
|
||||
tcl_platform(user) = glennj
|
||||
tcl_platform(wordSize) = 4
|
||||
5
Task/Host-introspection/UNIX-Shell/host-introspection.sh
Normal file
5
Task/Host-introspection/UNIX-Shell/host-introspection.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Aamrun$ getconf WORD_BIT
|
||||
32
|
||||
Aamrun$ echo -n I | od -to2 | awk 'FNR==1{ print substr($2,6,1)}'
|
||||
1
|
||||
Aamrun$
|
||||
9
Task/Host-introspection/Wren/host-introspection-1.wren
Normal file
9
Task/Host-introspection/Wren/host-introspection-1.wren
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* host_introspection.wren */
|
||||
|
||||
class C {
|
||||
foreign static wordSize
|
||||
foreign static endianness
|
||||
}
|
||||
|
||||
System.print("word size = %(C.wordSize) bits")
|
||||
System.print("endianness = %(C.endianness)")
|
||||
96
Task/Host-introspection/Wren/host-introspection-2.wren
Normal file
96
Task/Host-introspection/Wren/host-introspection-2.wren
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "wren.h"
|
||||
|
||||
void C_wordSize(WrenVM* vm) {
|
||||
/* size_t typically is exactly one word */
|
||||
int ws = (int)(CHAR_BIT * sizeof(size_t));
|
||||
|
||||
/* return result to Wren */
|
||||
wrenSetSlotDouble(vm, 0, (double)ws);
|
||||
}
|
||||
|
||||
void C_endianness(WrenVM* vm) {
|
||||
/* Check if the least significant bit is located in the lowest-address byte. */
|
||||
int one = 1;
|
||||
char *e = (*(char *)&one) ? "little" : "big";
|
||||
|
||||
/* return result to Wren */
|
||||
wrenSetSlotString(vm, 0, e);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn bindForeignMethod(
|
||||
WrenVM* vm,
|
||||
const char* module,
|
||||
const char* className,
|
||||
bool isStatic,
|
||||
const char* signature) {
|
||||
if (strcmp(module, "main") == 0) {
|
||||
if (strcmp(className, "C") == 0) {
|
||||
if (isStatic && strcmp(signature, "wordSize") == 0) {
|
||||
return C_wordSize;
|
||||
} else if (isStatic && strcmp(signature, "endianness") == 0) {
|
||||
return C_endianness;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void writeFn(WrenVM* vm, const char* text) {
|
||||
printf("%s", text);
|
||||
}
|
||||
|
||||
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
|
||||
switch (errorType) {
|
||||
case WREN_ERROR_COMPILE:
|
||||
printf("[%s line %d] [Error] %s\n", module, line, msg);
|
||||
break;
|
||||
case WREN_ERROR_STACK_TRACE:
|
||||
printf("[%s line %d] in %s\n", module, line, msg);
|
||||
break;
|
||||
case WREN_ERROR_RUNTIME:
|
||||
printf("[Runtime Error] %s\n", msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char *readFile(const char *fileName) {
|
||||
FILE *f = fopen(fileName, "r");
|
||||
fseek(f, 0, SEEK_END);
|
||||
long fsize = ftell(f);
|
||||
rewind(f);
|
||||
char *script = malloc(fsize + 1);
|
||||
fread(script, 1, fsize, f);
|
||||
fclose(f);
|
||||
script[fsize] = 0;
|
||||
return script;
|
||||
}
|
||||
|
||||
int main() {
|
||||
WrenConfiguration config;
|
||||
wrenInitConfiguration(&config);
|
||||
config.writeFn = &writeFn;
|
||||
config.errorFn = &errorFn;
|
||||
config.bindForeignMethodFn = &bindForeignMethod;
|
||||
WrenVM* vm = wrenNewVM(&config);
|
||||
const char* module = "main";
|
||||
const char* fileName = "host_introspection.wren";
|
||||
char *script = readFile(fileName);
|
||||
WrenInterpretResult result = wrenInterpret(vm, module, script);
|
||||
switch (result) {
|
||||
case WREN_RESULT_COMPILE_ERROR:
|
||||
printf("Compile Error!\n");
|
||||
break;
|
||||
case WREN_RESULT_RUNTIME_ERROR:
|
||||
printf("Runtime Error!\n");
|
||||
break;
|
||||
case WREN_RESULT_SUCCESS:
|
||||
break;
|
||||
}
|
||||
wrenFreeVM(vm);
|
||||
free(script);
|
||||
return 0;
|
||||
}
|
||||
10
Task/Host-introspection/XPL0/host-introspection.xpl0
Normal file
10
Task/Host-introspection/XPL0/host-introspection.xpl0
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
int A, B;
|
||||
char C;
|
||||
[IntOut(0, @B-@A); CrLf(0); \word size = integer size
|
||||
A:= $1234;
|
||||
C:= @A;
|
||||
Text(0, if C(0)=$34 then "Little" else "Big");
|
||||
Text(0, " endian
|
||||
");
|
||||
]
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
EndianTest:
|
||||
ld hl,&8000
|
||||
ld (&C000),hl ;store &8000 into memory.
|
||||
ld a,(&C000) ;loads the byte at &C000 into A. If the Z80 were big-endian, A would equal &80. But it equals zero.
|
||||
or a ;still, we need to pretend we don't already know the result and compare A to zero.
|
||||
jr z,LittleEndian ;handle the case where Z80 is little-endian (which it is, so this branch is always taken.)
|
||||
|
||||
;else, do whatever you would do to show that the Z80 is big-endian (it isn't, so execution never reaches here.)
|
||||
Loading…
Add table
Add a link
Reference in a new issue