Paste: vocab platform suffixes

Author: erg
Mode: factor
Date: Sat, 22 Jan 2022 01:37:32
Plain Text |
! Copyright (c) 2007, 2010 slava pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs classes continuations init io kernel
kernel.private make math.parser namespaces sequences splitting ;
IN: system

PRIMITIVE: (exit) ( n -- * )
PRIMITIVE: disable-ctrl-break ( -- )
PRIMITIVE: enable-ctrl-break ( -- )
PRIMITIVE: nano-count ( -- ns )

SINGLETONS: x86.32 x86.64 arm.32 arm.64 ppc.32 ppc.64 ;

UNION: x86 x86.32 x86.64 ;
UNION: arm arm.32 arm.64 ;
UNION: ppc ppc.32 ppc.64 ;

: cpu ( -- class ) \ cpu get-global ; foldable

SINGLETONS: windows macosx linux freebsd ;

UNION: bsd freebsd ;
UNION: unix macosx linux freebsd bsd ;

CONSTANT: all-oses { unix bsd windows macosx linux freebsd }
CONSTANT: all-cpus { x86.32 x86.64 arm.32 arm.64 ppc.32 ppc.64 }

: os ( -- class ) \ os get-global ; foldable

: vm-version ( -- string ) \ vm-version get-global ;

: vm-git-label ( -- string ) \ vm-git-label get-global ;

: vm-git-ref ( -- string )
    vm-git-label "-" split1-last drop ;

: vm-git-id ( -- string )
    vm-git-label "-" split1-last nip ;

: vm-compiler ( -- string ) \ vm-compiler get-global ;

: vm-compile-time ( -- string ) \ vm-compile-time get-global ;

<PRIVATE

CONSTANT: string>cpu-hash H{
    { "x86.32" x86.32 }
    { "x86.64" x86.64 }
    { "arm.32" arm.32 }
    { "arm.64" arm.64 }
    { "ppc.32" ppc.32 }
    { "ppc.64" ppc.64 }
}

CONSTANT: string>os-hash H{
    { "windows" windows }
    { "macosx" macosx }
    { "freebsd" freebsd }
    { "linux" linux }
}

: string>cpu ( str -- class )
    string>cpu-hash at ;

: string>os ( str -- class )
    string>os-hash at ;

PRIVATE>

: make-platform-suffixes ( oses cpus -- seq )
    [ [ name>> ] map ] bi@
    [ ]
    [ [ [ "-" glue ] curry map ] with map concat ] 2bi 3append ;

MEMO: all-platform-suffixes ( -- seq )
    all-oses all-cpus make-platform-suffixes ;

MEMO: my-os-suffixes ( -- seq )
    all-oses [ os swap instance? ] filter ;

MEMO: my-cpu-suffixes ( -- seq )
    all-cpus [ cpu swap instance? ] filter ;

MEMO: my-platform-suffixes ( -- seq )
    my-os-suffixes my-cpu-suffixes make-platform-suffixes ;

: image-path ( -- path ) \ image-path get-global ;

: vm-path ( -- path ) \ vm-path get-global ;

: embedded? ( -- ? ) OBJ-EMBEDDED special-object ;

: version-info ( -- str )
    ! formatting vocab not available in this context.
    [
        "Factor " % vm-version %
        " " % cpu name>> %
        " (" % build # ", " %
        vm-git-ref % "-" %
        vm-git-id 10 short head % ", " %
        vm-compile-time % ")\n[" %
        vm-compiler % "] on " % os name>> %
    ] "" make ;

: exit ( n -- * )
    [ do-shutdown-hooks (exit) ] ignore-errors
    [ "Unexpected error during shutdown!" print flush ] ignore-errors
    255 (exit) ;



! macosx 64
my-platform-suffixes ...
{ "unix" "macosx" "x86.64" "unix-x86.64" "macosx-x86.64" }

Annotation: forgot x86 arm ppc

Author: erg
Mode: factor
Date: Sat, 22 Jan 2022 01:41:50
Plain Text |
CONSTANT: all-oses { bsd unix windows macosx linux freebsd }
CONSTANT: all-cpus { x86 arm ppc x86.32 x86.64 arm.32 arm.64 ppc.32 ppc.64 }

Annotation: all-platform-suffixes

Author: erg
Mode: factor
Date: Sat, 22 Jan 2022 01:43:35
Plain Text |
all-platform-suffixes ...
{
    "bsd"
    "unix"
    "windows"
    "macosx"
    "linux"
    "freebsd"
    "x86"
    "arm"
    "ppc"
    "x86.32"
    "x86.64"
    "arm.32"
    "arm.64"
    "ppc.32"
    "ppc.64"
    "bsd-x86"
    "unix-x86"
    "windows-x86"
    "macosx-x86"
    "linux-x86"
    "freebsd-x86"
    "bsd-arm"
    "unix-arm"
    "windows-arm"
    "macosx-arm"
    "linux-arm"
    "freebsd-arm"
    "bsd-ppc"
    "unix-ppc"
    "windows-ppc"
    "macosx-ppc"
    "linux-ppc"
    "freebsd-ppc"
    "bsd-x86.32"
    "unix-x86.32"
    "windows-x86.32"
    "macosx-x86.32"
    "linux-x86.32"
    "freebsd-x86.32"
    "bsd-x86.64"
    "unix-x86.64"
    "windows-x86.64"
    "macosx-x86.64"
    "linux-x86.64"
    "freebsd-x86.64"
    "bsd-arm.32"
    "unix-arm.32"
    "windows-arm.32"
    "macosx-arm.32"
    "linux-arm.32"
    "freebsd-arm.32"
    "bsd-arm.64"
    "unix-arm.64"
    "windows-arm.64"
    "macosx-arm.64"
    "linux-arm.64"
    "freebsd-arm.64"
    "bsd-ppc.32"
    "unix-ppc.32"
    "windows-ppc.32"
    "macosx-ppc.32"
    "linux-ppc.32"
    "freebsd-ppc.32"
    "bsd-ppc.64"
    "unix-ppc.64"
    "windows-ppc.64"
    "macosx-ppc.64"
    "linux-ppc.64"
    "freebsd-ppc.64"
}

New Annotation

Summary:
Author:
Mode:
Body: