summaryrefslogtreecommitdiff
path: root/hieroglyph/vm.h
blob: 943acb7c4acc234e9e7ddb45d211357d5323cc47 (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * vm.h
 * Copyright (C) 2005-2006 Akira TAGOH
 * 
 * Authors:
 *   Akira TAGOH  <at@gclab.org>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef __LIBRETTO_VM_H__
#define __LIBRETTO_VM_H__

#include <hieroglyph/hgtypes.h>

G_BEGIN_DECLS

#define HG_LOCAL_POOL_SIZE	240000 * 100
#define HG_GLOBAL_POOL_SIZE	240000 * 100
#define HG_GRAPHIC_POOL_SIZE	240000 * 50


typedef enum {
	VM_EMULATION_LEVEL_1 = 1,
	VM_EMULATION_LEVEL_2,
	VM_EMULATION_LEVEL_3
} HgVMEmulationType;

typedef enum {
	VM_IO_STDIN = 1,
	VM_IO_STDOUT,
	VM_IO_STDERR,
} HgVMIOType;

typedef enum {
	VM_e_dictfull = 1,
	VM_e_dictstackoverflow,
	VM_e_dictstackunderflow,
	VM_e_execstackoverflow,
	VM_e_handleerror,
	VM_e_interrupt,
	VM_e_invalidaccess,
	VM_e_invalidexit,
	VM_e_invalidfileaccess,
	VM_e_invalidfont,
	VM_e_invalidrestore,
	VM_e_ioerror,
	VM_e_limitcheck,
	VM_e_nocurrentpoint,
	VM_e_rangecheck,
	VM_e_stackoverflow,
	VM_e_stackunderflow,
	VM_e_syntaxerror,
	VM_e_timeout,
	VM_e_typecheck,
	VM_e_undefined,
	VM_e_undefinedfilename,
	VM_e_undefinedresult,
	VM_e_unmatchedmark,
	VM_e_unregistered,
	VM_e_VMerror,
	VM_e_configurationerror,
	VM_e_undefinedresource,
	VM_e_END,
} HgVMError;


/* initializer */
void     hg_vm_init          (void);
void     hg_vm_finalize      (void);
gboolean hg_vm_is_initialized(void);

/* virtual machine */
HgVM                 *hg_vm_new                  (HgVMEmulationType  type);
void                  hg_vm_set_emulation_level  (HgVM              *vm,
						  HgVMEmulationType  type);
HgVMEmulationType     hg_vm_get_emulation_level  (HgVM              *vm);
HgStack              *hg_vm_get_ostack           (HgVM              *vm);
HgStack              *hg_vm_get_estack           (HgVM              *vm);
HgStack              *hg_vm_get_dstack           (HgVM              *vm);
HgDict               *hg_vm_get_dict_errordict   (HgVM              *vm);
HgDict               *hg_vm_get_dict_error       (HgVM              *vm);
HgDict               *hg_vm_get_dict_statusdict  (HgVM              *vm);
HgDict               *hg_vm_get_dict_serverdict  (HgVM              *vm);
HgDict               *hg_vm_get_dict_font        (HgVM              *vm);
HgDict               *hg_vm_get_dict_systemdict  (HgVM              *vm);
HgDict               *hg_vm_get_dict_globalfont  (HgVM              *vm);
HgMemPool            *hg_vm_get_current_pool     (HgVM              *vm);
gboolean              hg_vm_is_global_pool_used  (HgVM              *vm);
void                  hg_vm_use_global_pool      (HgVM              *vm,
						  gboolean           use_global);
gboolean              hg_vm_is_global_object     (HgVM              *vm,
						  HgValueNode       *node);
HgGraphics           *hg_vm_get_graphics         (HgVM              *vm);
gint32                hg_vm_get_current_time     (HgVM              *vm);
GRand                *hg_vm_get_random_generator (HgVM              *vm);
HgFileObject         *hg_vm_get_io               (HgVM              *vm,
						  HgVMIOType         type);
void                  hg_vm_set_io               (HgVM              *vm,
						  HgVMIOType         type,
						  HgFileObject      *file);
HgLineEdit           *hg_vm_get_line_editor      (HgVM              *vm);
void                  hg_vm_set_line_editor      (HgVM              *vm,
						  HgLineEdit        *editor);
gboolean              hg_vm_load_plugin          (HgVM              *vm,
						  const gchar       *filename);
gboolean              hg_vm_unload_plugin        (HgVM              *vm,
						  const gchar       *filename);
void                  hg_vm_load_plugins_all     (HgVM              *vm);
guint                 hg_vm_get_save_level       (HgVM              *vm);
HgValueNode          *hg_vm_get_name_node        (HgVM              *vm,
						  const gchar       *name);
HgValueNode          *hg_vm_lookup               (HgVM              *vm,
						  HgValueNode       *key);
HgValueNode          *hg_vm_lookup_with_string   (HgVM              *vm,
						  const gchar       *key);
gboolean              hg_vm_startjob             (HgVM              *vm,
						  const gchar       *initializer,
						  gboolean           encapsulated);
gboolean              hg_vm_has_error            (HgVM              *vm);
void                  hg_vm_clear_error          (HgVM              *vm);
void                  hg_vm_reset_error          (HgVM              *vm);
void                  hg_vm_set_error            (HgVM              *vm,
						  HgValueNode       *errnode,
						  HgVMError          error,
						  gboolean           drop_self);
void                  hg_vm_set_error_from_file  (HgVM              *vm,
						  HgValueNode       *errnode,
						  HgFileObject      *file,
						  gboolean           drop_self);
gboolean              hg_vm_main                 (HgVM              *vm);
gchar                *hg_vm_find_libfile         (HgVM              *vm,
						  const gchar       *file);
gboolean              hg_vm_run                  (HgVM              *vm,
						  const gchar       *file);
gboolean              hg_vm_eval                 (HgVM              *vm,
						  const gchar       *expression,
						  HgStack           *ostack,
						  HgStack           *estack,
						  HgStack           *dstack,
						  gboolean          *error);
gint32                hg_vm_get_error_code       (HgVM              *vm);
void                  hg_vm_shutdown             (HgVM              *vm,
						  gint32             error_code);
gint32                hg_vm_get_security_level   (HgVM              *vm);
gboolean              hg_vm_set_security_level   (HgVM              *vm,
						  gint32             level);


/* internal use */
HgValueNode *_hg_vm_get_name_node(HgVM        *vm,
				  const gchar *name);

G_END_DECLS

#endif /* __HG_VM_H__ */