/* poke.pk - Application infrastructure.  */

/* Copyright (C) 2020, 2021, 2022, 2023, 2024 Jose E. Marchesi */

/* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**** Globals. ****/

/* Many of the following variables are modified by poke.c when poke
   initializes, after loading this file.  The initialization values
   below are therefore the defaults.  */

/* The endianness of the running host.  */
var pk_host_endian = ENDIAN_BIG;

/* The endianness of the network to which the running host is
   connected.  */
var pk_network_endian = ENDIAN_BIG;

/* Whether the terminal hyperlinks server is running or not.  */
var pk_hserver_p = 0;

/* Whether auto-maps shall be acknowledged when loading files or
   not. */
var pk_auto_map_p = 0;

/* Whether map information shall be included in the REPL prompt.  */
var pk_prompt_maps_p = 1;

/* The following global contains the name of the program to use to
   display documentation.  Valid values are `info' and `less'.  */
var pk_doc_viewer = "info";

/* Whether poke was built with support for libNBD.  */
var pk_have_libnbd_p = 0;

/* Whether to user the terminal pager.  */
var pk_pager_p = 0;

/* Default exception handler.  Do not do anything here that could
   raise an exception, because it will be silently ignored :P */

fun pk_exception_handler = (Exception exception) void:
  {
   if (exception.code != EC_exit && exception.code != EC_signal)
     {
       printf ("unhandled %<warning:%s%> exception\n",
               exception.name == "" ? "unknown" : exception.name);

       if (exception.location != "" || exception.msg != "")
         {
           if (exception.location != "")
             print (exception.location + " ");
           print (exception.msg + "\n");
         }
     }
  }

/* Bounder for constructing unbounded Poke array types from C.  */

fun pk_bounder_unbounded = any:
{
  /* XXX use `push null' whenever supported.  */
  return asm any: ("push 7");
}

/* Print current dispatching strategy of PVM.  */

fun pk_print_vm_dispatch = void:
{
  printf ("%s\n", vm_dispatch);
}

/* Load some poke subsystems.  */

load "pk-table.pk";
load "pk-info.pk";
load "pk-help.pk";
load "pk-map.pk";
load "pk-settings.pk";
load "pk-tracer.pk";

/* Default value for poke_prompt.  */

fun pk_prompt = string:
{
  return "(poke) ";
}

/* Add the current working directory to the load path.  */
load_path = ".:" + load_path;
