15 #include <sys/types.h>
22 #define PATHS_FN "paths"
25 #define __a_vm_state_fn(buf,dir) __a_vm_fn(buf,dir,"state")
26 #define __a_vmfn(buf,dir) __a_vm_fn(buf,dir,"")
27 void __a_vm_fn(
char *buf,
char *dir,
char *suffix) {
28 sprintf(buf,
"%s/vmhost%s.x",dir,suffix);
31 void __a_serializet(
T *t,
char *name) {
35 __a_vm_fn(fn,G_vm->dir,name);
36 writeFile(fn,s,s->total_size);
41 T *__a_unserializet(
char *dir_path,
char *name) {
43 __a_vm_fn(fn,dir_path,name);
44 S *s = readFile(fn,0);
64 if (stat(dir_path, &st) == -1) {
79 T *t = __a_unserializet(dir_path,SEM_FN);
80 sem->stores[0].definitions = t;
83 T *paths = __a_unserializet(dir_path,PATHS_FN);
90 sem->stores[i-1].definitions = x;
97 __a_vmfn(fn,dir_path);
98 buffer = readFile(fn,0);
101 G_vm = __v_init(r,sem);
106 __a_vm_state_fn(fn,dir_path);
111 H hars; hars.m=h.m; hars.a =
_m_child(h,1);
116 if(!semeq(
_m_symbol(har),RECEPTOR_XADDR)) raise_error(
"expecting RECEPTOR_XADDR!");
121 G_vm->dir = dir_path;
125 _v_start_vmhost(G_vm);
138 _v_join_thread(&G_vm->clock_thread);
139 _v_join_thread(&G_vm->vm_thread);
144 __a_serializet(
_t_root(G_vm->
sem->stores[0].definitions),SEM_FN);
148 for (i=0;i<G_vm->
sem->contexts;i++) {
151 _t_new(paths,RECEPTOR_PATH,p,
sizeof(
int)*(
_t_path_depth(p)+1));
155 _t_newr(paths,STRUCTURE_ANYTHING);
157 __a_serializet(paths,PATHS_FN);
165 __a_vmfn(fn,G_vm->dir);
166 writeFile(fn,surface,length);
171 H har =
_m_newr(h,ACTIVE_RECEPTORS);
172 for (i=0;i<G_vm->active_receptor_count;i++) {
176 __a_vm_state_fn(fn,G_vm->dir);
177 writeFile(fn,s,s->total_size);
200 t =
_t_child(t,InstanceStoreInstancesIdx);
201 if (!t) raise_error(
"Missing INSTANCES");
206 T *x = __a_get_instances(instances);
209 x = _t_newr(x,INSTANCES);
212 T *si = __a_find(x,s);
213 if (!si) si = _t_news(x,SYMBOL_INSTANCES,s);
222 T *t = __a_get_instances(instances);
224 t = __a_find(t,x.symbol);
227 if (t && !semeq(
_t_symbol(t),DELETED_INSTANCE))
return t;
234 T *t = _a_get_instance(instances,x);
244 T *x = __a_get_instances(instances);
250 if (!semeq(
_t_symbol(c),DELETED_INSTANCE))
256 T *t = __a_get_instances(instances);
258 t = __a_find(t,x.symbol);
268 void _a_free_instances(
Instances *instances) {
276 S *__a_serialize_instances(
Instances *instances) {
277 T *x = __a_get_instances(instances);
285 T *sym = _t_news(t,STRUCTURE_SYMBOL,s);
289 if (is_receptor(s)) {
294 c = _t_new(0,SERIALIZED_RECEPTOR,surface,length);
312 void _a_serialize_instances(
Instances *i,
char *file) {
314 S *s = __a_serialize_instances(i);
318 ofp = fopen(file,
"w");
320 raise_error(
"Can't open output file %s!\n",file);
323 fwrite(s,1,s->total_size,ofp);
338 int is_receptor = is_receptor(s);
346 _a_new_instance(instances, i);
355 ofp = fopen(file,
"r");
357 raise_error(
"Can't open input file %s!\n",file);
361 fread(&magic, 1,
sizeof(magic), ofp);
364 fread(&magic, 1,
sizeof(magic), ofp);
365 S *s = malloc(total_size);
367 s->total_size = total_size;
368 size_t read_size = total_size-
sizeof(Mmagic)-
sizeof(total_size);
369 fread(&s->levels,1,read_size,ofp);
371 __a_unserialize_instances(sem,instances,s);
378 if (!t) raise_error(
"uninitialized instances");
379 t =
_t_child(t,InstanceStoreTokensIdx);
384 T *tokens = __a_get_tokens(instances);
387 tokens = _t_newr(*instances,INSTANCE_TOKENS);
388 c = _t_newi64(tokens,LAST_TOKEN,0);
390 else c =
_t_child(tokens,InstanceTokensLastTokenIdx);
394 T *t = _t_newi64(tokens,INSTANCE_TOKEN,*l);
398 _t_new(t,TOKEN_XADDR,&x,
sizeof(
Xaddr));
399 _t_newi(t,DEPENDENCY_HASH,
_t_hash(G_sem,dependency));
405 T *__a_find_token(
T *t,uint64_t token) {
410 if (*(uint64_t *)
_t_surface(p) == token)
return p;
415 T * __a_find_dependency(
T *t,
T *dependency) {
417 TreeHash dh =
_t_hash(G_sem,dependency);
422 if (h == dh)
return p;
428 T *tokens = __a_get_tokens(instances);
430 T *t = __a_find_token(tokens,*(uint64_t *)
_t_surface(token));
432 if (__a_find_dependency(t,dependency))
439 void _a_add_dependency(
Instances *instances,
T *token,
T *dependency) {
440 T *tokens = __a_get_tokens(instances);
442 T *t = __a_find_token(tokens,*(uint64_t *)
_t_surface(token));
444 if (!__a_find_dependency(t,dependency))
445 _t_newi(t,DEPENDENCY_HASH,
_t_hash(G_sem,dependency));
449 raise_error(
"token not found:%s\n",_t2s(G_sem,token));
452 void _a_delete_dependency(
Instances *instances,
T *token,
T *dependency) {
453 T *tokens = __a_get_tokens(instances);
455 T *t = __a_find_token(tokens,*(uint64_t *)
_t_surface(token));
457 T *d = __a_find_dependency(t,dependency);
465 raise_error(
"token not found:%s\n",_t2s(G_sem,token));
468 void _a_delete_token(
Instances *instances,
T *token){
469 T *tokens = __a_get_tokens(instances);
471 T *t = __a_find_token(tokens,*(uint64_t *)
_t_surface(token));
T * _t_new_root(Symbol symbol)
void _r_serialize(Receptor *r, void **surfaceP, size_t *lengthP)
T * _t_detach_by_idx(T *t, int i)
int _t_path_depth(int *p)
Semantic tree regular expression header file.
T * _t_new_receptor(T *parent, Symbol symbol, Receptor *r)
TreeHash _t_hash(SemTable *sem, T *t)
void _v_instantiate_builtins(VMHost *v)
T * _t_child(T *t, int i)
Receptor * __r_get_receptor(T *installed_receptor)
receptor implementation header file
VMHost * _v_new()
Creates a new virtual machine host.
Maddr _m_child(H h, Mindex c)
void _v_activate(VMHost *v, Xaddr x)
SemTable * sem
Semantic Table for definitions on this host.
Receptor * _r_unserialize(SemTable *sem, void *surface)
void _t_replace_node(T *t, T *r)
void _a_boot(char *dir_path)
ActiveReceptor active_receptors[MAX_ACTIVE_RECEPTORS]
pointer to array that holds all currently active receptors
Receptor * r
Receptor data for this vm host.
semantic tree matrix header file ``
header file for the accumulator
void _t_replace(T *t, int i, T *r)
void _t_detach_by_ptr(T *t, T *c)
H _m_newr(H parent, Symbol s)