| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/tads3/VMTYPEDH.CPP,v 1.2 1999/05/17 02:52:29 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved. |
| 8 |
* |
| 9 |
* Please see the accompanying license file, LICENSE.TXT, for information |
| 10 |
* on using and copying this software. |
| 11 |
*/ |
| 12 |
/* |
| 13 |
Name |
| 14 |
vmtypedh.cpp - type manipulations for data holders |
| 15 |
Function |
| 16 |
|
| 17 |
Notes |
| 18 |
This is separated from vmtype.cpp so that these functions can be linked |
| 19 |
into an application without dragging in a bunch of things that other |
| 20 |
vmtype.cpp code depends upon. |
| 21 |
Modified |
| 22 |
05/11/99 MJRoberts - Creation |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "t3std.h" |
| 26 |
#include "vmtype.h" |
| 27 |
#include "vmglob.h" |
| 28 |
#include "vmstack.h" |
| 29 |
|
| 30 |
|
| 31 |
/* ------------------------------------------------------------------------ */ |
| 32 |
/* |
| 33 |
* Portable data holder manipulation |
| 34 |
*/ |
| 35 |
|
| 36 |
/* |
| 37 |
* store a vm_val_t value in a portable data holder |
| 38 |
*/ |
| 39 |
void vmb_put_dh(char *buf, const vm_val_t *val) |
| 40 |
{ |
| 41 |
/* store the type code */ |
| 42 |
buf[0] = (char)val->typ; |
| 43 |
|
| 44 |
/* store the value, in the appropriate type-dependent format */ |
| 45 |
switch(val->typ) |
| 46 |
{ |
| 47 |
case VM_OBJ: |
| 48 |
case VM_OBJX: |
| 49 |
/* store the object ID as a UINT4 */ |
| 50 |
oswp4(buf+1, val->val.obj); |
| 51 |
break; |
| 52 |
|
| 53 |
case VM_PROP: |
| 54 |
/* store the property ID as a UINT2 */ |
| 55 |
oswp2(buf+1, val->val.prop); |
| 56 |
break; |
| 57 |
|
| 58 |
case VM_INT: |
| 59 |
oswp4(buf+1, val->val.intval); |
| 60 |
break; |
| 61 |
|
| 62 |
case VM_BIFPTR: |
| 63 |
case VM_BIFPTRX: |
| 64 |
/* store the integer as two UINT2s: function index, set index */ |
| 65 |
oswp2(buf+1, val->val.bifptr.func_idx); |
| 66 |
oswp2(buf+3, val->val.bifptr.set_idx); |
| 67 |
break; |
| 68 |
|
| 69 |
case VM_ENUM: |
| 70 |
/* store the enumerated constant value as a UINT4 */ |
| 71 |
oswp4(buf+1, val->val.enumval); |
| 72 |
break; |
| 73 |
|
| 74 |
case VM_SSTRING: |
| 75 |
case VM_DSTRING: |
| 76 |
case VM_LIST: |
| 77 |
case VM_CODEOFS: |
| 78 |
case VM_FUNCPTR: |
| 79 |
/* store the offset value as a UINT4 */ |
| 80 |
oswp4(buf+1, val->val.ofs); |
| 81 |
break; |
| 82 |
|
| 83 |
default: |
| 84 |
/* other types have no extra data or cannot be put into a DH */ |
| 85 |
break; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
/* |
| 90 |
* Get only the value portion of a vm_val_t from a portable data holder |
| 91 |
*/ |
| 92 |
void vmb_get_dh_val(const char *buf, vm_val_t *val) |
| 93 |
{ |
| 94 |
/* read the format appropriate to the type */ |
| 95 |
switch((vm_datatype_t)buf[0]) |
| 96 |
{ |
| 97 |
case VM_OBJ: |
| 98 |
case VM_OBJX: |
| 99 |
/* get the object ID from the UINT4 */ |
| 100 |
val->val.obj = (vm_obj_id_t)t3rp4u(buf+1); |
| 101 |
break; |
| 102 |
|
| 103 |
case VM_PROP: |
| 104 |
/* get the property ID from the UINT2 */ |
| 105 |
val->val.prop = (vm_prop_id_t)osrp2(buf+1); |
| 106 |
break; |
| 107 |
|
| 108 |
case VM_INT: |
| 109 |
val->val.intval = osrp4(buf+1); |
| 110 |
break; |
| 111 |
|
| 112 |
case VM_BIFPTR: |
| 113 |
case VM_BIFPTRX: |
| 114 |
/* read the function index and set index as UINT2s */ |
| 115 |
val->val.bifptr.func_idx = osrp2(buf+1); |
| 116 |
val->val.bifptr.set_idx = osrp2(buf+3); |
| 117 |
break; |
| 118 |
|
| 119 |
case VM_ENUM: |
| 120 |
/* get the enumerated constant value from the UINT4 */ |
| 121 |
val->val.enumval = t3rp4u(buf+1); |
| 122 |
break; |
| 123 |
|
| 124 |
case VM_SSTRING: |
| 125 |
case VM_DSTRING: |
| 126 |
case VM_LIST: |
| 127 |
case VM_CODEOFS: |
| 128 |
case VM_FUNCPTR: |
| 129 |
/* get the offset value from the UINT4 */ |
| 130 |
val->val.ofs = t3rp4u(buf+1); |
| 131 |
break; |
| 132 |
|
| 133 |
default: |
| 134 |
/* other types have no additional data or cannot be put in a DH */ |
| 135 |
break; |
| 136 |
} |
| 137 |
} |
| 138 |
|