#!/bin/bash # # Author: Arnold Doray # Date: 06 Feb 2023 # Compiles Smojo VM (C++) and runs any app. # Requires C++ compiler. # function missing(){ if [ -z "$1" ]; then echo "Missing $2" exit 1 fi } CURL=$(which curl) missing "$CURL" "Curl" CPP=$(which g++) missing "$CPP" "C++ compiler" function help(){ echo -ne " Usage: -c -- to grab and compile the latest C++ SmojoVM -r username/program -- to run a program from a user. -h -- this help. " } TEMP=. if [ ! -d $TEMP ]; then TEMP=$TMPDIR fi if [ ! -d $TEMP ]; then TEMP=. fi function getoptions(){ $CPP -std=c++20 -E -v - < /dev/null > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "-std=c++20" else $CPP -std=c++2a -E -v - < /dev/null > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "-std=c++2a" else echo "-std=c++20" fi fi } function compile(){ cd $TEMP $CURL -k https://app.smojo.org/arnold/vm.cpp > vm.cpp OPTIONS="$(getoptions)" $CPP $OPTIONS -Wall -W -O3 -o smojovm vm.cpp -lcurl rm vm.cpp } function run(){ $TEMP/smojovm https://app.smojo.org/$1.json } # Check for smojovm and compile immediately if not found. if [ ! -f $TEMP/smojovm ]; then compile fi while getopts chr: flag do case "${flag}" in h) help;; c) compile;; r) run "$OPTARG";; esac done