Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
VM run utility script
Last updated at 11:58 pm UTC on 18 April 2017
http://forum.world.st/VM-Image-magic-numbers-Re-Pharo-users-Pharo-6-snap-install-tp4942160p4942621.html
#!/bin/sh
# dtl Wed May 20 19:49:25 EDT 2015
# Mon Apr 10 19:18:47 EDT 2017
#
# VM run utility script, typicially installed as /usr/local/bin/run
# usage: run <myimage>
#
# Select a VM and run an image based on the image format number
#
# Assume that /usr/local/bin/squeak runs the traditional VM for 32-bit
# and 64-bit images in the traditional image formats. Assume that
# /usr/local/bin/cog runs Cog, /usr/local/bin/spur runs the VM for 32-bit
# Spur images, and /usr/local/bin/spur64 runs the VM for 64-bit Spur
# images.
#
# Use ckformat to determine image requirements. See package ImageFormat
# in the SqueakSource VMMaker repository. The executable is distributed
# with the standard interpreter VM. To generate C source for the ckformat
# utility, evaluate:
#    "ImageFormat createCkStatusProgram"
#

# VMs look for this default name if an image has not been
# specified. Use the same default for this script.
DEFAULT_IMAGENAME="squeak.image"

# Scripts for running various interpreters
INTERP_SCRIPT="squeak"       # Context VM for 32 and 64 bit images
COG_SCRIPT="cog"             # Cog VM
SPUR_SCRIPT="spur"           # Spur VM for 32-bit Spur image
SPUR64_SCRIPT="spur64"       # Spur VM for 64-bit Spur image

# Assume scripts are in the same directory, e.g. /usr/local/bin
BIN=`dirname "$0"`

# The ckformat utility is distributed with interpreter VM builds.
# Find it in the lib directory for the interpreter VM.
CKFORMAT=`squeak -version | grep 'plugin path' | sed 's/^.*default: //' | sed 's/]$//'`ckformat

# Paths to the run scripts
INTERP="$BIN/$INTERP_SCRIPT" # Context interpreter VM
COG="$BIN/$COG_SCRIPT"       # Cog VM for 32-bit images with closure support
SPUR="$BIN/$SPUR_SCRIPT"     # Spur VM for Spur 32-bit image format 6521
SPUR64="$BIN/$SPUR64_SCRIPT" # Spur VM for Spur 64-bit image format 68109

for arg in $*
do
  case ${arg} in
  -*) #ignore
    ;;
  *) # either and option argument or the image name
    if test -f ${arg}
    then
      NUM=`${CKFORMAT} ${arg} 2>/dev/null`
      if test $? -eq 0
      then
        IMAGENAME=${arg}
        break
      fi
    else
      if test -f ${arg}.image
      then
        NUM=`${CKFORMAT} ${arg}.image 2>/dev/null`
        if test $? -eq 0
        then
          IMAGENAME=${arg}.image
          break
        fi
      fi
    fi
    ;;
  esac
done

# if no image name specified on command line, try the default
if test ! ${IMAGENAME}
then
  if test -f ${DEFAULT_IMAGENAME}
  then
    IMAGENAME=${DEFAULT_IMAGENAME}
    NUM=`${CKFORMAT} ${IMAGENAME} 2>/dev/null`
    if test $? -ne 0
    then
      echo image format ${NUM} not recognized for ${IMAGENAME}
      exit 1
    fi
  else
    echo `basename $0` $@: image file not found
    exit 1
  fi
fi

case $NUM in
  6502)
    VM=$INTERP
    ;;
  6504 | 6505)
    VM=$COG
    ;;
  6521)
    VM=$SPUR
    ;;
  68000 | 68002 | 68003)
    VM=$INTERP
    ;;
  68019)
    VM=$SPUR64 # early spur 64
    ;;
  68021)
    VM=$SPUR64
    ;;
  *)  echo image format ${NUM} not recognized for ${IMAGENAME}
    exit -1;;
esac

# Use standard VM as default if preferred VM not present
if test ! -x ${VM}
then
  echo ${VM} not found, using ${INTERP}
  VM="${INTERP}"
fi

### echo running ${IMAGENAME} with image format $NUM using $VM
exec ${VM} $@