_impl.h

Go to the documentation of this file.
00001 /* TinyaML
00002  * Copyright (C) 2007 Damien Leroux
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  */
00018 
00019 #ifndef _BML_VM_IMPL_H_
00020 #define  _BML_VM_IMPL_H_
00021 
00022 #include "vm_types.h"
00023 #include "containers.h"
00024 #include <tinyape.h>
00025 
00026 
00030 struct _dynarray_t {
00031         word_t reserved;
00032         word_t size;
00033         dynarray_value_t* data;
00034 };
00040 struct _generic_stack_t {
00041         word_t sz;
00042         word_t sp;
00043         word_t tok_sp;
00044         word_t token_size;
00045         void* stack;
00046 };
00052 struct _vm_engine_t {
00053         void(*_VM_CALL _init)(vm_engine_t);
00054         void(*_VM_CALL _deinit)(vm_engine_t);
00055         void(*_VM_CALL _run_sync)(vm_engine_t, program_t, word_t ip, word_t prio);
00056         void(*_VM_CALL _fg_thread_start_cb)(vm_engine_t);
00057         void(*_VM_CALL _fg_thread_done_cb)(vm_engine_t);
00058         void(*_VM_CALL _run_async)(vm_engine_t, program_t, word_t ip, word_t prio);
00059         void(*_VM_CALL _kill)(vm_engine_t);
00060         void(*_VM_CALL _client_lock)(vm_engine_t);
00061         void(*_VM_CALL _client_unlock)(vm_engine_t);
00062         void(*_VM_CALL _vm_lock)(vm_engine_t);
00063         void(*_VM_CALL _vm_unlock)(vm_engine_t);
00064         void(*_VM_CALL _thread_failed)(vm_t,thread_t);
00065         void(*_VM_CALL _debug)(vm_engine_t);
00066         void(*_VM_CALL _put_std)(const char*);
00067         void(*_VM_CALL _put_err)(const char*);
00068         volatile vm_t vm;
00069 };
00077 struct _opcode_chain_node_t {
00078         opcode_chain_node_type_t type;
00079         const char* name;
00080         const char* arg;
00081         opcode_arg_t arg_type;
00082         word_t lofs;
00083         int row,col;
00084 };
00092 struct _opcode_dict_t {
00093         struct _dynarray_t stub_by_index[OpcodeTypeMax];
00094         /* mnemonic lookup */
00095         struct _hashtab_t stub_by_name[OpcodeTypeMax];
00096         /* reverse lookup */
00097         struct _hashtab_t wordcode_by_stub;
00098         struct _hashtab_t name_by_stub;
00099 };
00107 struct _text_seg_t {
00108         struct _dynarray_t by_index;
00109         struct _hashtab_t by_text;
00110 };
00116 struct _mutex_t {
00117         struct _dlist_t pending;
00118         long int count;
00119         thread_t owner;
00120 };
00126 struct _data_stack_entry_t {
00127         vm_data_type_t type;
00128         word_t data;
00129 };
00135 struct _call_stack_entry_t {
00136         program_t cs;
00137         word_t ip;
00138         word_t has_closure;     /* FIXME : this should be a set of flags, not just one flag */
00139         /* FIXME again : has_closure is used to store call_stack.sp in catch stack */
00140 };
00147 struct _vm_obj_t {
00148         long ref_count;
00149         void (*_free)(vm_t,void*);
00150         void* (*_clone)(vm_t,void*);
00151         word_t magic;
00152 };
00158 struct _vm_dyn_env_t {
00159         vm_dyn_env_t parent;
00160         struct _text_seg_t symbols;
00161         struct _dynarray_t data;
00162 };
00168 struct _vm_dyn_func_t {
00169         program_t cs;
00170         word_t ip;
00171         dynarray_t closure;
00172 };
00178 struct _vm_t {
00179         /* embedded parser */
00180         tinyap_t parser;
00181         /* meta-compiler */
00182         struct _text_seg_t compile_vectors;
00183         opcode_chain_t result;
00184         WalkDirection compile_state;
00185         wast_t current_node;
00186         struct _generic_stack_t cn_stack;
00187         /* support of virtual AST walkers */
00188         const char* virt_walker;
00189         WalkDirection virt_walker_state;
00190         /* meta-language serialized state */
00191         struct _text_seg_t gram_nodes;
00192         /* known opcodes */
00193         struct _opcode_dict_t opcodes;
00194         /* library management */
00195         void* dl_handle;
00196         struct _slist_t all_handles;
00197         /* all programs */
00198         struct _slist_t all_programs;
00199         /* globals */
00200         vm_dyn_env_t env;
00201         vm_data_t exception;
00202         /* threads */
00203         scheduler_algorithm_t scheduler;
00204         word_t threads_count;
00205         struct _dlist_t ready_threads;
00206         struct _dlist_t running_threads;
00207         thread_t current_thread;
00208         struct _dlist_t yielded_threads;
00209         struct _dlist_t zombie_threads;
00210         word_t timeslice;
00211         /* runtime engine */
00212         vm_engine_t engine;
00213         /* stats */
00214         volatile word_t cycles;
00215         /* garbage collecting */
00216         struct _dlist_t gc_pending;
00217 };
00225 struct _label_tab_t {
00226         struct _text_seg_t labels;
00227         struct _dynarray_t offsets;
00228 };
00235 struct _program_t {
00236         /* globals */
00237         vm_dyn_env_t env;
00238         /* segments */
00239         struct _text_seg_t strings;
00240         struct _label_tab_t labels;
00241         struct _dynarray_t gram_nodes_indexes;
00242         struct _dynarray_t data;
00243         struct _dynarray_t code;
00244 };
00250 struct _thread_t {
00251         /* thread is aliased to a dlist_node */
00252         struct _dlist_node_t sched_data;
00253         /* attached program */
00254         volatile program_t program;
00255         /* execution context */
00256         word_t data_sp_backup;
00257         struct _generic_stack_t closures_stack;
00258         struct _generic_stack_t locals_stack;
00259         struct _generic_stack_t data_stack;
00260         struct _generic_stack_t call_stack;
00261         struct _generic_stack_t catch_stack;
00262         volatile word_t IP;
00263         volatile program_t jmp_seg;
00264         volatile word_t jmp_ofs;
00265         /* scheduling */
00266         volatile thread_state_t state;
00267         /*word_t IP_status;*/
00268         int _sync;
00269         word_t prio;
00270         volatile word_t remaining;
00271         volatile mutex_t pending_lock;
00272         struct _mutex_t join_mutex;
00273 };
00279 extern volatile vm_t _glob_vm;
00283 #endif
00284 

Generated on Wed Feb 6 14:46:04 2008 for TinyaML by  doxygen 1.5.3