A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
3
Task/Host-introspection/0DESCRIPTION
Normal file
3
Task/Host-introspection/0DESCRIPTION
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]]
|
||||
2
Task/Host-introspection/1META.yaml
Normal file
2
Task/Host-introspection/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Programming environment operations
|
||||
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))
|
||||
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;
|
||||
7
Task/Host-introspection/BBC-BASIC/host-introspection.bbc
Normal file
7
Task/Host-introspection/BBC-BASIC/host-introspection.bbc
Normal file
|
|
@ -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 << }
|
||||
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 @@
|
|||
import std.stdio, std.system;
|
||||
|
||||
void main() {
|
||||
writefln("word size = ", size_t.sizeof * 8);
|
||||
writefln(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.
|
||||
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
|
||||
38
Task/Host-introspection/Go/host-introspection-1.go
Normal file
38
Task/Host-introspection/Go/host-introspection-1.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// inspect an int variable to determine endianness
|
||||
x := 1
|
||||
if *(*byte)(unsafe.Pointer(&x)) == 1 {
|
||||
fmt.Println("little endian")
|
||||
} else {
|
||||
fmt.Println("big endian")
|
||||
}
|
||||
// inspect cpuinfo to determine word size (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
|
||||
}
|
||||
}
|
||||
fmt.Println("cpuinfo flags not found")
|
||||
}
|
||||
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)
|
||||
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
|
||||
3
Task/Host-introspection/J/host-introspection-2.j
Normal file
3
Task/Host-introspection/J/host-introspection-2.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"));
|
||||
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,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.
|
||||
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)";
|
||||
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") ) ) )
|
||||
12
Task/Host-introspection/Python/host-introspection.py
Normal file
12
Task/Host-introspection/Python/host-introspection.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
>>> import sys, math
|
||||
>>> int(round(math.log(sys.maxint,2)+1)) # this only works in Python 2.x
|
||||
32
|
||||
>>> import struct
|
||||
>>> struct.calcsize('i') * 8
|
||||
32
|
||||
>>> sys.byteorder
|
||||
little
|
||||
>>> import socket
|
||||
>>> socket.gethostname()
|
||||
'PADDY3118-RESTING'
|
||||
>>>
|
||||
3
Task/Host-introspection/R/host-introspection-1.r
Normal file
3
Task/Host-introspection/R/host-introspection-1.r
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
8 * .Machine$sizeof.long # e.g. 32
|
||||
# or
|
||||
object.size(0L) # e.g. 32 bytes
|
||||
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))
|
||||
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}"
|
||||
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)))
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue