cfad47cfa3/t3compiler/tads3/vmbifc.cpp

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
1
#ifdef RCSID
2
static char RCSid[] =
3
"$Header$";
4
#endif
5
6
/* 
7
 *   Copyright (c) 1999, 2002 Michael J. Roberts.  All Rights Reserved.
8
 *   
9
 *   Please see the accompanying license file, LICENSE.TXT, for information
10
 *   on using and copying this software.  
11
 */
12
/*
13
Name
14
  vmbifc.cpp - built-in function - Call-time resolution
15
Function
16
  This is a version of the built-in function interface for resolving
17
  built-ins only when each built-in is invoked.  This version allows
18
  loading an image file with unresolved function sets, then checks
19
  on each built-in function's invocation to make sure the function is
20
  available.
21
22
  This version can be used in a version of the interpreter used by
23
  the compiler for running 'preinit' or similar situations in which it
24
  is desirable to be able to load and run a program with unresolved
25
  function sets.  This version is less efficient than the load-time
26
  resolver, so normal stand-alone interpreters should use the load-time
27
  version instead.
28
Notes
29
  
30
Modified
31
  07/21/99 MJRoberts  - Creation
32
*/
33
34
#include <stdlib.h>
35
#include <string.h>
36
37
#include "t3std.h"
38
#include "vmtype.h"
39
#include "vmerr.h"
40
#include "vmerrnum.h"
41
#include "vmglob.h"
42
#include "vmbif.h"
43
#include "vmbifreg.h"
44
#include "vmstr.h"
45
#include "vmobj.h"
46
#include "vmrun.h"
47
48
49
/* ------------------------------------------------------------------------ */
50
/*
51
 *   Call the given function from the given function set.  
52
 */
53
void CVmBifTable::call_func(VMG_ uint set_index, uint func_index, uint argc)
54
{
55
    vm_bif_entry_t *entry;
56
    void (*func)(VMG_ uint argc);
57
    
58
    /* get the function set */
59
    entry = table_[set_index];
60
61
    /* if the function set is null, we can't call the function */
62
    if (entry == 0)
63
        err_throw_a(VMERR_UNKNOWN_FUNC_SET, 1,
64
                    ERR_TYPE_TEXTCHAR, names_[set_index]);
65
66
    /* get the function pointer */
67
    func = entry->func[func_index];
68
69
    /* if the function is null, we can't call it */
70
    if (func == 0)
71
        err_throw_a(VMERR_UNAVAIL_INTRINSIC, 2,
72
                    ERR_TYPE_TEXTCHAR, names_[set_index],
73
                    ERR_TYPE_INT, func_index);
74
75
    /* call the function */
76
    (*func)(vmg_ argc);
77
}
78
79
/*
80
 *   Handle adding a function set entry that's unresolvable at load-time 
81
 */
82
void CVmBifTable::add_entry_unresolved(const char *func_set_id)
83
{
84
    /*
85
     *   Since this is the call-time resolver, allow loading of the image
86
     *   file even though this function set is unresolved.  Store a null
87
     *   entry in the function set table, and store the name of the
88
     *   function set - we'll need this in case the program attempts to
89
     *   invoke a function in this function set, so that we can generate
90
     *   an error containing the unresolved function set name. 
91
     */
92
    table_[count_] = 0;
93
    names_[count_] = lib_copy_str(func_set_id);
94
95
    /* count the new entry */
96
    ++count_;
97
}