1 /******************************************************************************
2 *
3 * Copyright (C) 2006, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * ID: vmmanage 26.12.06 0.0.A.
11 *
12 * Author: Alexey Krivonogov ( gentee )
13 *
14 * Summary:
15 *
16 ******************************************************************************/
17
18 #include "vmmanage.h"
19 //#include "../bytecode/bytecode.h"
20
21 /*-----------------------------------------------------------------------------
22 *
23 * ID: vmmng_new 26.12.06 0.0.A.
24 *
25 * Summary: Create a new vmmanager
26 *
27 -----------------------------------------------------------------------------*/
28
29 pvmmanager STDCALL vmmng_new( void )
30 {
31 pvmmanager pmng = mem_allocz( sizeof( vmmanager ));
32
33 pmng->next = _pvm->pmng;
34 _pvm->pmng = pmng;
35 pmng->ptr = mem_alloc( 0x100000 );
36 pmng->top = pmng->ptr;
37 pmng->end = ( pubyte )pmng->ptr + 0xFFF00;
38
39 return pmng;
40 }
41
42 /*-----------------------------------------------------------------------------
43 *
44 * ID: vmmng_destroy 26.12.06 0.0.A.
45 *
46 * Summary: Destroy all vm managers
47 *
48 -----------------------------------------------------------------------------*/
49
50 void STDCALL vmmng_destroy( void )
51 {
52 pvmmanager pmng;
53
54 while ( _pvm->pmng )
55 {
56 pmng = _pvm->pmng;
57
58 mem_free( pmng->ptr );
59 _pvm->pmng = pmng->next;
60 mem_free( pmng );
61 }
62 }
63
64 /*-----------------------------------------------------------------------------
65 *
66 * ID: vmmng_begin 26.12.06 0.0.A.
67 *
68 * Summary: Get a pointer for object
69 *
70 -----------------------------------------------------------------------------*/
71
72 pubyte STDCALL vmmng_begin( uint size )
73 {
74 pvmmanager pmng = _pvm->pmng;
75
76 if ( ( pmng->top + 2 * size ) > pmng->end )
77 {
78 pmng = vmmng_new();
79 if ( size + 0xFFFF > 0x100000 )
80 {
81 mem_free( pmng->ptr );
82 pmng->ptr = mem_alloc( size + 0xFFFF );
83 pmng->top = pmng->ptr;
84 pmng->end = ( pubyte )pmng->ptr + size + 0xFF00;
85 }
86 }
87 return pmng->top;
88 }
89
90 /*-----------------------------------------------------------------------------
91 *
92 * ID: vmmng_end 26.12.06 0.0.A.
93 *
94 * Summary: The end of the object
95 *
96 -----------------------------------------------------------------------------*/
97
98 uint STDCALL vmmng_end( pubyte end )
99 {
100 uint ret = end - _pvm->pmng->top;
101
102 (( pvmobj )_pvm->pmng->top)->size = ret;
103
104 _pvm->pmng->top = end;
105 return ret;
106 }
107
108 //-----------------------------------------------------------------------------
109
Редактировать