Work / Virtual Machine

2011-02-19 23:25:24

API Reference

Below is the contents of the vmapi.h header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// $Header: /vm/vm/common/vmapi.h 25    8/01/12 19:05 fusi $

#ifndef vmapi_h
#define vmapi_h

#ifdef WIN32
  #ifdef COMPILING_VM
    #define VM_DECLSPEC __declspec(dllexport)
  #else
    #define VM_DECLSPEC __declspec(dllimport)
  #endif
#else
  #define VM_DECLSPEC
#endif

namespace vm
{
namespace api
{

extern "C"
{
    typedef struct environmentInterface
    {
        uint (*Create)();
        bool (*Destroy)(uint id);
    } environment_i;

    typedef struct compilerInterface
    {
        uint (*Create)(uint envID);
        bool (*Destroy)(uint envID, uint id);

        bool (*Compile)(uint envID, uint id, const char* source, const char* context, uint stackSize);

        util::buffer* (*Retrieve)(uint envID, uint id);
        const char* (*Status)(uint envID, uint id);
    } compiler_i;

    typedef struct prelinkerInterface
    {
        uint (*Create)(uint envID);
        bool (*Destroy)(uint envID, uint id);

        bool (*Add)(uint envID, uint id, util::buffer& buff, const char* sourceName);
        bool (*Prelink)(uint envID, uint id, const char* programName, uint stackSize);

        util::buffer* (*Retrieve)(uint envID, uint id);
        const char* (*Status)(uint envID, uint id);
    } prelinker_i;

    typedef struct runtimeInterface
    {
        bool (*RegisterSymbol)(uint envID, const char* importNamespace, const char* importIdentifier, void (*function)(vm::executive::StackInterface&));

        uint (*CreateProgram)(uint envID);
        bool (*DestroyProgram)(uint envID, uint programObjectID);
        bool (*LoadProgram)(uint envID, uint programObjectID, util::buffer& buff);
        bool (*UnloadProgram)(uint envID, uint programObjectID);
        const char* (*ProgramStatus)(uint envID, uint programObjectID);

        uint (*CreateContext)(uint envID, uint programObjectID);
        bool (*DestroyContext)(uint envID, uint contextObjectID);
        bool (*ResetContext)(uint envID, uint contextObjectID);
        const char* (*ContextStatus)(uint envID, uint id);

        int (*GetEntryPoint)(uint envID, uint contextObjectID, const char* identifier);

        uint (*Execute)(uint envID, uint contextObjectID, uint entryPoint, bool immediate);
                           
        bool (*Push)(uint envID, uint contextObjectID, void* data);
        void* (*Pop)(uint envID, uint contextObjectID, uint programID, uint size);
    } runtime_i;

    typedef struct vmInterface
    {
        uint version;
        environment_i environment;
        compiler_i compiler;
        prelinker_i prelinker;
        runtime_i runtime;
    } vmapi;

    typedef VM_DECLSPEC vmapi* (*vmInterfacePtr)();

    extern vmapi vm_api_;

    VM_DECLSPEC vmapi* GetInterface();
}

}
}

#endif

Note that the contents of this file may change in the future (i.e. removal of the namespacing to avoid name mangling and renaming of the interface functions and structures).