/*---------------------------------------------------------------------------
 * Specification of the virtual machine codes and instructions.
 *
 *---------------------------------------------------------------------------
 * For a full explanation, see make_func.y
 *---------------------------------------------------------------------------
 */

/*
 * This file specifies types and arguments for efuns.
 * An argument can have two different types with the syntax 'type1 | type2'.
 * An argument is marked as optional if it also takes the type 'void'.
 *
 * Look at the end for the list of functions that are optionally available.
 * If you don't want them, simply comment out them. All other functions must
 * remain defined.
 */

/*---------------------------------------------------------------------------
 * The tokens used by the lexer but with no code representation.
 */

%tokens

if else
case default
while do for continue
int status string_decl float_decl object closure_decl symbol_decl void mixed
static private no_mask protected public varargs virtual
inherit colon_colon
arrow quoted_aggregate mapping inline_fun

/*---------------------------------------------------------------------------
 * The codes which are used both by the compiler/lexer as well as
 * by the interpreter.
 */

%codes

  /* This code should come first, to detect corrupted code */
	illegal

  /* prefix bytes for multi-byte codes are required to have fixed values
   * for simple bit manipulation to be applicable.
   */
	dummy
	escape
	tefun
	vefun

  /* These are the predefined functions and statements that have a direct
   * counterpart in LPC.
   *
   * The compiler needs to treat sscanf and parse_command specially because
   * these two 'efuns' take lvalues as part of their arguments.
   */
	identifier
	string
        cstring0
        cstring1
        cstring2
        cstring3
	number
        const0
        const1
        clit
        nclit
	float
	closure
	symbol
	return
        return0
	break
	switch
	sscanf
#ifdef SUPPLY_PARSE_COMMAND
	parse_command
#endif
	local
	catch
"++"    inc
"--"    dec
"x++"   post_inc
"x--"   post_dec
"++x"   pre_inc
"--x"   pre_dec
"&&"    land
"||"    lor
"="     assign
"(void)="  void_assign
"+"     add
"-"	subtract
"*"     multiply
"/"     divide
"%"     mod
">"     gt
">="    ge
"<"     lt
"<="    le
"=="    eq
"!="    ne
"~"     compl
"&"     and
"|"     or
"^"     xor
"<<"    lsh
">>"    rsh
"!"     not
".."    range
"..<"   nr_range
"<.."   rn_range
"<..<"  rr_range
"(void)+=" void_add_eq
"+="    add_eq
"-="    sub_eq
"/="    div_eq
"*="    mult_eq
"%="    mod_eq
"&="    and_eq
"|="    or_eq
"^="    xor_eq
"<<="   lsh_eq
">>="   rsh_eq

  /* These values are used by the stack machine, and can not be directly
   * called from LPC.
   */
        pop_value
        dup
        clear_locals
        lbranch
        lbranch_when_zero
        lbranch_when_non_zero
        branch
        branch_when_zero
        branch_when_non_zero
        bbranch_when_zero
        bbranch_when_non_zero
        call_function_by_address
        call_explicit_inherited
        push_identifier_lvalue
        virtual_variable
        push_virtual_variable_lvalue
        identifier16
        push_identifier16_lvalue
        push_local_variable_lvalue
        push_indexed_lvalue
        push_rindexed_lvalue
        index_lvalue
        rindex_lvalue
        index
        rindex
        range_lvalue
        nr_range_lvalue
        rn_range_lvalue
        rr_range_lvalue
        simul_efun
        aggregate
        m_aggregate
        m_caggregate
        extract2
        previous_object0
        lambda_cconstant
        lambda_constant
        map_index
        push_indexed_map_lvalue

#ifdef INITIALIZATION_BY___INIT
        jump
#endif

/*---------------------------------------------------------------------------
 * efuns with a single-byte code
 */

%efuns

        /* Miscellaneous */

int     clonep(string|object default: F_THIS_OBJECT);
int     closurep(mixed);
int     floatp(mixed);
int     intp(mixed);
int     mappingp(mixed);
int     objectp(mixed);
int     pointerp(mixed);
int     stringp(mixed);
int     symbolp(mixed);

string  ctime(int default: F_TIME);
int     ed(void|string, void|string);
mixed   negate(int|float);
  /* Mainly used by the compiler to implement the unary '-' */
void    printf(string, ...);
int     random(int);
void    throw(mixed);
int     time();

        /* Strings */

string  capitalize(string);
string  crypt(string, string|int default: F_CONST0);
string *explode(string, string);
string  implode(string *, string);
string  lower_case(string);
string *regexp(string *, string);
string  sprintf(string, ...);
int     strlen(string);
string  terminal_colour(string, mapping, void|int, void|int );

string  clear_bit(string, int);
string  set_bit(string, int);
int     test_bit(string, int);
string  or_bits(string, string);
string  and_bits(string, string);
string  xor_bits(string, string);
string  invert_bits(string);
int     last_bit(string);
int     next_bit(string, int, int default: F_CONST0);
int     count_bits(string);

        /* Arrays and Mapings */

mixed  *allocate(int);
mixed   filter(mapping|mixed *, string|closure|mapping, ...);
mixed  *filter_array(mixed *, string|closure|mapping, ...);
mapping filter_indices(mapping, string|closure,  ...);
mapping filter_mapping F_FILTER_INDICES (mapping, string|closure,  ...);
mixed   map(mixed *|mapping, string|closure, ...);
mixed  *map_array(mixed *, string|closure, ...);
mapping map_indices(mapping, string|closure, ...);
mapping map_mapping F_MAP_INDICES (mapping, string|closure, ...);
int     member_array(mixed, mixed *|string);
int     member(mixed *|string|mapping, mixed);
mapping mkmapping(mixed *, ...);
mapping m_delete(mapping, mixed);
mixed  *m_indices(mapping);
int     m_sizeof F_SIZEOF (mapping);
mixed  *m_values(mapping, int default: F_CONST0);
int     sizeof(mixed *|mapping);
mixed  *sort_array(mixed *,string|closure,object|string default: F_THIS_OBJECT);
mixed  *unique_array(mixed *, string, mixed default: F_CONST0);
mixed  *unmkmapping(mapping);
int     widthof(mapping);

        /* Functions and Closures */

mixed   apply(closure, mixed|mixed &, ...);
closure bind_lambda(closure, object default: F_CONST1);
unknown call_other(object|string, string, ...);
mixed   funcall (closure, ...);
  /* funcall accepts mixed as a single argument, but the only useful application
   * is with mixed variables that might hold closures, which will work anyways.
   */
closure lambda(mixed *, mixed);
mixed   quote(mixed *|quoted_array|symbol|string);
closure symbol_function(symbol|string, string|object default: F_CONST0);

void    call_out(string|closure, int, void|mixed, ...);
mixed  *call_out_info();
int     find_call_out(string|closure);
int     remove_call_out(string|closure);

int     set_heart_beat(int);

        /* Objects */

object  clone_object(string|object);
void    destruct(object);
int     exec(object, object);
object  find_object(string);
string  function_exists(string, object default: F_THIS_OBJECT);
int     input_to(string, void|int, ...);
int     interactive(object default: F_THIS_OBJECT);
string  load_name(object default: F_THIS_OBJECT);
object  load_object(string);
string  object_name(object default: F_THIS_OBJECT);
string  file_name F_OBJECT_NAME (object default: F_THIS_OBJECT);
void    replace_program(string);
int     set_next_reset(int);
void    set_this_object(object);
int     snoop(object, void|object);
void    tell_object(object, string);
object  this_interactive();
object  this_object();
object *users();
void    write(mixed);

        /* Files */

int     cat(string, void|int, void|int);
int     file_size(string);
mixed  *get_dir(string, int default: F_CONST1);
int     mkdir(string);
string  read_bytes(string, void|int, void|int);
string  read_file(string, void|int, void|int);
int     rename(string, string);
int     restore_object(string);
int     rm(string);
int     rmdir(string);
void    save_object(string);
int     tail(string);
int     write_bytes(string, int, string);
int     write_file(string, string);

        /* Driver and System functions */

string  query_load_average();

        /* Inventories (TODO: should be optional) */

object *all_inventory(object default: F_THIS_OBJECT);
object *deep_inventory(object default: F_THIS_OBJECT);
object  environment(void|object|string);
object  first_inventory(object|string default: F_THIS_OBJECT);
void    move_object(object|string, object|string);
object  next_inventory(object default: F_THIS_OBJECT);
object  present(object|string, void|object);
void    say(string|mixed *, void|object|object *);
void    tell_room(object|string, string|mixed *, void|object *);

        /* Verbs and Commands (TODO: should be optional) */

void    add_action(string, void|string, void|int);
int     command(string, void|object);
void    disable_commands();
void    enable_commands();
int     living(object);
mixed  *query_actions(object|string, int|object|string default: F_CONST1);
string  query_verb();
string  query_command();
object  this_player();

        /* uids and euids */

void    export_uid(object);
string  geteuid(object default: F_THIS_OBJECT);
int     seteuid(string|int);

#ifndef COMPAT_MODE
string  getuid(object default: F_THIS_OBJECT);
#endif

        /* Functions only used in compatibility mode. */

#ifdef COMPAT_MODE
string  creator (object);
int     transfer(object, object|string);
#endif


/* The following functions are optional. Comment out the ones not wanted.
 * Beware that some may be used in mudlib 2.4.5.
 */

        /* Technical efuns */

/* void break_point(); */
mixed  *rusage();

        /* Alists (TODO: Make this xefuns) */

mixed   assoc(mixed, mixed *, mixed|void, mixed|void);
mixed   insert_alist(mixed, mixed, ...);
mixed  *intersect_alist(mixed *,mixed *);
mixed  *order_alist(mixed *, void|mixed *, ...);

        /* Misc */

string  process_string(string);
int     set_light(int);

        /* Backwards compatibility */

mixed  *slice_array F_RANGE (mixed *,int,int);

/*---------------------------------------------------------------------------
 * Machine instructions with 'escape' prefixed codes.
 */

%xcodes

        end_catch
        break_continue
        breakn_continue
        extract1  /* not needed when efun extract() is not defined */
        push_protected_indexed_lvalue
        push_protected_rindexed_lvalue
        push_protected_indexed_map_lvalue
        protected_index_lvalue
        protected_rindex_lvalue
        protected_range_lvalue
        protected_nr_range_lvalue
        protected_rn_range_lvalue
        protected_rr_range_lvalue
        protected_extract_lvalue
        undef

/*---------------------------------------------------------------------------
 * Efuns with 'escape' prefixed codes.
 */

%xefuns

        /* Miscellaneous */

mixed   abs(int|float);
float   sin(float);
float   asin(float);
float   cos(float);
float   acos(float);
float   tan(float);
float   atan(float);
float   atan2(float,float);
float   log(float);
float   exp(float);
float   sqrt(float);
float   ceil(float);
float   floor(float);
float   pow(float,float);

mixed   get_type_info(mixed, int default: F_THIS_OBJECT);
void    raise_error(string);
int     referencep(mixed &);
int     typeof(mixed);

int     to_int(int|string|float|closure);
float   to_float(float|string|int);
string  to_string(mixed);
int    *to_array(string);

void    set_extra_wizinfo_size(int);

        /* Strings */

int     strstr(string, string, int default: F_CONST0);

        /* Arrays and Mappings */

mapping m_allocate(int, int default: F_CONST1);
mapping allocate_mapping F_M_ALLOCATE (int, int default: F_CONST1);
int     m_contains(mixed & | mapping, mixed & | mixed, ...);
int     mapping_contains F_M_CONTAINS (mixed & | mapping, mixed & | mixed, ...);

        /* Functions and Closures */

object *caller_stack(int default: F_CONST0);
int     caller_stack_depth();
int     call_resolved(mixed &, object|string, string, ...);
int     extern_call();
int     get_eval_cost();
object  previous_object(int);

        /* Objects */

int     object_time(object default: F_THIS_OBJECT);
int     program_time(object default: F_THIS_OBJECT);
string  program_name(object default: F_THIS_OBJECT);
int     query_once_interactive(object);

        /* Network IO */

#ifdef CATCH_UDP_PORT
int     query_imp_port();
#endif
object  query_input_pending(object);
string  query_ip_name(object default: F_THIS_PLAYER);
string  query_ip_number(object|mixed &  default: F_THIS_PLAYER);
int     query_mud_port(int|object default: F_THIS_PLAYER);

        /* Driver and System functions */

void    garbage_collection();

        /* Inventories */

object *all_environment(void|object);


/* The following functions are optional. Comment out the ones not wanted.
 * Beware that some may be used in mudlib 2.4.5.
 */

mapping copy_mapping(mapping);
string  extract(string, int, int);
  /* If this is not defined, the xcode extract1 is not used either.
   */
/* void swap(object); */ /* debugging only */

/*---------------------------------------------------------------------------
 * Machine instructions with 'tefun' prefixed codes.
 */

%tcodes

extract_lvalue

/*---------------------------------------------------------------------------
 * Tabled efuns with 'tefun'/'vefun' prefixed codes.
 */

%tefuns

        /* Miscellaneous */

mixed   copy(mixed);
mixed   deep_copy(mixed);
object  to_object(object|string|closure);

mixed   get_extra_wizinfo(object|string);
void    set_extra_wizinfo(object|string, mixed);
mixed  *wizlist_info();

        /* Strings */

string  make_shared_string(string);
string *regexplode(string, string);
string  regreplace(string,string,string,int);
string  trim(string, ...);
string  upper_case(string);

        /* Arrays and Mappings */

mapping m_reallocate(mapping, int);
mixed  *transpose_array(mixed *);
void    walk_mapping(mapping, string|closure, ...);

        /* Functions and Closures */

closure symbol_variable(symbol|string|int);
closure unbound_lambda(mixed *, mixed);

        /* Objects */

mixed  *filter_objects(mixed *, string, ...);
string *functionlist(object|string, int default: F_CONST1);
string *inherit_list(object default: F_THIS_OBJECT);
mixed  *map_objects(mixed *, string, ...);
mixed  *object_info(object, int);
object  present_clone(object|string, object default: F_THIS_OBJECT); /* PRELIMINARY */
mixed   query_editing(object);
int     query_idle(object);
object  query_shadowing(object);
object  query_snoop(object);
void    remove_interactive(object);
void    rename_object(object, string);
object  shadow(object, int);
void    unshadow();

        /* Network IO */

int     binary_message(int *|string, int default: F_CONST0);
int     set_buffer_size(int);
void    set_connection_charset(int *, int default: F_CONST1);
string  set_prompt(string|closure|int, object default: F_THIS_PLAYER);

#ifdef ERQ_DEMON
int     attach_erq_demon(object|string, int default: F_CONST0);
int     send_erq(int, int*|string, closure default: F_CONST0);
#endif

#ifdef CATCH_UDP_PORT
#ifdef UDP_SEND
int     send_imp(string, int, string|int*);
#endif
#endif

        /* Driver and System functions */

mixed   debug_info(int, ...);
void    debug_message(string);
string  expand_define(string, string default: F_CONST0);
mixed  *get_error_file(string, int default: F_CONST1);
mixed  *heart_beat_info();
mixed   limited(closure, ...);
#ifdef TRACE_CODE
string *last_instructions(int, int default: F_CONST1);
#endif
mixed  *query_limits(int default: F_CONST0);
void    set_auto_include_string(string);
void    set_driver_hook(int, closure|int|string|mapping|string*);
void    set_limits(int|int*, ...);
void    shutdown();
int     trace(int);
string  traceprefix(string|int);

        /* Inventories */

void    set_environment(object, object);
void    efun308 F_SET_ENVIRONMENT (object, object);

        /* Verbs and Commands */

mixed  *command_stack();
int     command_stack_depth();
int     execute_command(string, object, object);
int     notify_fail(string|closure);
mixed   query_notify_fail();
int     remove_action(string, object default: F_THIS_PLAYER);
object  set_modify_command(object|string default: F_THIS_OBJECT);
void    set_this_player(int|object);


/* The following functions are optional. Comment out the ones not wanted.
 * Beware that some may be used in mudlib 2.4.5.
 */

void    add_verb(string);
void    add_xverb(string);
  /* TODO: Get rid of add_verb(), add_xverb()
   */
int     set_is_wizard(object, int default: F_CONST1);

/***************************************************************************/
