~ubuntu-branches/ubuntu/wily/gargoyle-free/wily-proposed

« back to all changes in this revision

Viewing changes to tads/tads3/vmcore.h

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Beucler
  • Date: 2009-09-11 20:09:43 UTC
  • Revision ID: james.westby@ubuntu.com-20090911200943-idgzoyupq6650zpn
Tags: upstream-2009-08-25
ImportĀ upstreamĀ versionĀ 2009-08-25

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 *   Copyright (c) 2002 by Michael J. Roberts.  All Rights Reserved.
 
3
 *   
 
4
 *   Please see the accompanying license file, LICENSE.TXT, for information
 
5
 *   on using and copying this software.  
 
6
 */
 
7
/*
 
8
Name
 
9
  vmcore.h - T3 VM "core" interpreter - example function set definition
 
10
Function
 
11
  This is an example of how to define custom intrinsic (i.e., native C++)
 
12
  functions for the T3 VM.  An intrinsic function is a function written in
 
13
  C++, and part of the application executable, that can be called from TADS
 
14
  code (i.e., from within .t source).
 
15
 
 
16
  This file can be used as a template for creating custom intrinsics.
 
17
  Simply make a copy of this entire file, and then make the following
 
18
  changes:
 
19
 
 
20
  1. Change the #ifndef symbol from VMCORE_H to a different name of your
 
21
  own choosing - usually, the name matches the name of the .h file itself.
 
22
  This symbol appears three times in the file, so you should be careful to
 
23
  change all three to the same new symbol.
 
24
 
 
25
  2. Change the name of class CVmBifSample to a name of your own choosing.
 
26
  Choose a name that describes the custom function set you're defining.  This
 
27
  name appears in the class definition and also in each entry in the list
 
28
  near the bottom of the file, so make sure to change every occurrence of the
 
29
  name to the same new name.
 
30
 
 
31
  3. Change the names of the functions themselves.  Note that each function
 
32
  name appears twice - first in the class definition near the start of the
 
33
  file, then again in the initialization list at the bottom of the file.  You
 
34
  can add and delete functions as you wish.  If you add new functions, simply
 
35
  copy an existing definition and change its name, being sure to add the
 
36
  function in both the class definition and the list at the bottom of the
 
37
  file.
 
38
 
 
39
  4. You must, of course, provide an implementation for each of your
 
40
  functions.  Do that in a new .cpp file corresponding to your new header
 
41
  file.  Make sure you #include your new header file from your new .cpp file.
 
42
  You can use the implementations in vmcore.cpp as a template for your new
 
43
  functions.
 
44
 
 
45
  5. Make a copy of the file vmbifreg_core.cpp.  Add a #include line for
 
46
  the new copy of this file you have created (you can add it right after the
 
47
  #include for vmbiftad.h).  Also add a MAKE_ENTRY() line for your new
 
48
  function set - you can add it where the comments indicate in your copy of
 
49
  vmbifreg_core.cpp.  The MAKE_ENTRY() line would look like this:
 
50
 
 
51
    MAKE_ENTRY("core-sample/010000", G_bif_core_sample);
 
52
 
 
53
  Use the same name you use for the variable defined in the initialization
 
54
  list near the end of the file.  For the string, you can use anything you
 
55
  want, but you should choose something reasonably long and descriptive to
 
56
  avoid overlapping with anyone else's function set identifiers.
 
57
 
 
58
  6. Take vmbifreg_core.obj out of the application build, and replace it
 
59
  with the copy you created in step 5.
 
60
 
 
61
  7. Take vmcore.obj out of the application build, and replace it with your
 
62
  new .cpp file from step 4.
 
63
 
 
64
  8. Change the variable name G_bif_sample near the end of this file to a
 
65
  different name of your own choosing.
 
66
 
 
67
  9. Create a TADS header file, for inclusion in your TADS (.t) source
 
68
  code, defining your intrinsic functions.  See the sample file "core.h"
 
69
 
 
70
    intrinsic 'core-sample/010000'
 
71
    {
 
72
      // display the given string
 
73
      displayText(str);
 
74
 
 
75
      // read a line of text from the keyboard, and return it as a string
 
76
      readText();
 
77
    }
 
78
 
 
79
  You MUST define the intrinsic functions in the EXACT SAME ORDER that they
 
80
  appear in the initialization list near the end of this file.  For the name
 
81
  of the function set (the 'core-sample/010000' string), you must use the
 
82
  EXACT SAME string you used in the MAKE_ENTRY() definition in step 5.
 
83
 
 
84
  Everything else in this file is boilerplate text, so you shouldn't have
 
85
  to change anything else.
 
86
 
 
87
Notes
 
88
  
 
89
Modified
 
90
  04/06/02 MJRoberts  - Creation
 
91
*/
 
92
 
 
93
#ifndef VMCORE_H
 
94
#define VMCORE_H
 
95
 
 
96
#include "vmbif.h"
 
97
 
 
98
/* ------------------------------------------------------------------------ */
 
99
/*
 
100
 *   Our sample built-in functions.  Each function we define here will be
 
101
 *   callable as an intrinsic function from TADS source code.
 
102
 *   
 
103
 *   This is only the interface definition.  The actual implementations of
 
104
 *   these functions appear in our .cpp file.
 
105
 *   
 
106
 *   Note that every function has the same C++ interface.  This has nothing
 
107
 *   to do with the arguments that the TADS program passes to these
 
108
 *   functions; the functions get their TADS arguments from the VM stack.
 
109
 *   See the implementations for details.  
 
110
 */
 
111
class CVmBifSample: public CVmBif
 
112
{
 
113
public:
 
114
    static void display_text(VMG_ uint argc);
 
115
    static void read_text(VMG_ uint argc);
 
116
};
 
117
 
 
118
#endif /* VMCORE_H */
 
119
 
 
120
/* ------------------------------------------------------------------------ */
 
121
/*
 
122
 *   Sample function set vector.  Define this only if VMBIF_DEFINE_VECTOR has
 
123
 *   been defined.
 
124
 *   
 
125
 *   IMPORTANT - this definition is outside the #ifdef VMCORE_H section of
 
126
 *   the header file, because we specifically want this part of the file to
 
127
 *   be able to be included multiple times.
 
128
 *   
 
129
 *   ALSO IMPORTANT - the ORDER of the definitions here is significant.  You
 
130
 *   must use the EXACT SAME ORDER in your "intrinsic" definition in the
 
131
 *   header file you create for inclusion in your TADS (.t) source code.  
 
132
 */
 
133
#ifdef VMBIF_DEFINE_VECTOR
 
134
 
 
135
void (*G_bif_sample[])(VMG_ uint) =
 
136
{
 
137
    &CVmBifSample::display_text,
 
138
    &CVmBifSample::read_text
 
139
};
 
140
 
 
141
#endif