Skip to content

Commit

Permalink
AMX: Swapping bytes in a cell is now an API function (previously it w…
Browse files Browse the repository at this point in the history
…as an internal version).

AMX: minor fixes in attribute handling in the curses port.
Compiler: Fix for issue 5 (warning on array initializers with an explicit tag, via symbolic indices).
Test: added a test case for the correction of issue 5 (see above).
  • Loading branch information
compuphase committed Jul 22, 2012
1 parent 01f7fdf commit 8e36a8f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 31 deletions.
28 changes: 9 additions & 19 deletions amx/amx.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*
* Version: $Id: amx.c 4708 2012-05-18 12:52:49Z thiadmer $
* Version: $Id: amx.c 4734 2012-06-25 12:09:56Z $
*/

#define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -408,7 +408,7 @@ typedef enum {
#endif

#if BYTE_ORDER==BIG_ENDIAN || PAWN_CELL_SIZE==16
static void swap16(uint16_t *v)
void amx_Swap16(uint16_t *v)
{
unsigned char *s = (unsigned char *)v;
unsigned char t;
Expand All @@ -422,7 +422,7 @@ typedef enum {
#endif

#if BYTE_ORDER==BIG_ENDIAN || PAWN_CELL_SIZE==32
static void swap32(uint32_t *v)
void amx_Swap32(uint32_t *v)
{
unsigned char *s = (unsigned char *)v;
unsigned char t;
Expand All @@ -440,7 +440,7 @@ typedef enum {
#endif

#if (BYTE_ORDER==BIG_ENDIAN || PAWN_CELL_SIZE==64) && (defined _I64_MAX || defined HAVE_I64)
static void swap64(uint64_t *v)
void amx_Swap64(uint64_t *v)
{
unsigned char *s = (unsigned char *)v;
unsigned char t;
Expand Down Expand Up @@ -471,7 +471,7 @@ uint16_t * AMXAPI amx_Align16(uint16_t *v)
assert_static(sizeof(*v)==2);
assert(check_endian());
#if BYTE_ORDER==BIG_ENDIAN
swap16(v);
amx_Swap16(v);
#endif
return v;
}
Expand All @@ -481,7 +481,7 @@ uint32_t * AMXAPI amx_Align32(uint32_t *v)
assert_static(sizeof(*v)==4);
assert(check_endian());
#if BYTE_ORDER==BIG_ENDIAN
swap32(v);
amx_Swap32(v);
#endif
return v;
}
Expand All @@ -492,23 +492,13 @@ uint64_t * AMXAPI amx_Align64(uint64_t *v)
assert(sizeof(*v)==8);
assert(check_endian());
#if BYTE_ORDER==BIG_ENDIAN
swap64(v);
amx_Swap64(v);
#endif
return v;
}
#endif /* _I64_MAX || HAVE_I64 */
#endif /* AMX_ALIGN || AMX_INIT */

#if PAWN_CELL_SIZE==16
#define swapcell swap16
#elif PAWN_CELL_SIZE==32
#define swapcell swap32
#elif PAWN_CELL_SIZE==64 && (defined _I64_MAX || defined HAVE_I64)
#define swapcell swap64
#else
#error Unsupported cell size
#endif

#if defined AMX_FLAGS
int AMXAPI amx_Flags(AMX *amx,uint16_t *flags)
{
Expand Down Expand Up @@ -1174,7 +1164,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
if ((hdr->flags & AMX_FLAG_COMPACT)==0) {
ucell *code=(ucell *)((unsigned char *)program+(int)hdr->cod);
while (code<(ucell *)((unsigned char *)program+(int)hdr->hea))
swapcell(code++);
amx_SwapCell(code++);
} /* if */
#endif

Expand Down Expand Up @@ -3525,7 +3515,7 @@ int AMXAPI amx_SetString(cell *dest,const char *source,int pack,int use_wchar,si
#if BYTE_ORDER==LITTLE_ENDIAN
len /= sizeof(cell);
while (len>=0)
swapcell((ucell *)&dest[len--]);
amx_SwapCell((ucell *)&dest[len--]);
#endif
} else {
/* create an unpacked string */
Expand Down
21 changes: 17 additions & 4 deletions amx/amx.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*
* Version: $Id: amx.h 4731 2012-06-21 11:11:18Z thiadmer $
* Version: $Id: amx.h 4734 2012-06-25 12:09:56Z $
*/

#ifndef AMX_H_INCLUDED
Expand Down Expand Up @@ -490,11 +490,24 @@ int AMXAPI amx_UTF8Len(const cell *cstr, int *length);
int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value);

#if PAWN_CELL_SIZE==16
#define amx_AlignCell(v) amx_Align16(v)
void amx_Swap16(uint16_t *v);
#endif
#if PAWN_CELL_SIZE==32
void amx_Swap32(uint32_t *v);
#endif
#if PAWN_CELL_SIZE==64 && (defined _I64_MAX || defined INT64_MAX || defined HAVE_I64)
void amx_Swap64(uint64_t *v);
#endif

#if PAWN_CELL_SIZE==16
#define amx_AlignCell(v) amx_Align16((uint16_t*)v)
#define amx_SwapCell(v) amx_Swap16((uint16_t*)v)
#elif PAWN_CELL_SIZE==32
#define amx_AlignCell(v) amx_Align32(v)
#define amx_AlignCell(v) amx_Align32((uint32_t*)v)
#define amx_SwapCell(v) amx_Swap32((uint32_t*)v)
#elif PAWN_CELL_SIZE==64 && (defined _I64_MAX || defined INT64_MAX || defined HAVE_I64)
#define amx_AlignCell(v) amx_Align64(v)
#define amx_AlignCell(v) amx_Align64((uint64_t*)v)
#define amx_SwapCell(v) amx_Swap64((uint64_t*)v)
#else
#error Unsupported cell size
#endif
Expand Down
8 changes: 5 additions & 3 deletions amx/amxcons.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@
#define amx_console(c,l,f) ((void)(c),(void)(l),(void)(f))
unsigned int amx_setattr(int foregr,int backgr,int highlight)
{
int attribs=A_NORMAL;
if (highlight>0)
attribs=(attribs & ~A_NORMAL) | A_STANDOUT;
attrset(attribs);
attron(A_STANDOUT);
else
attroff(A_STANDOUT);
//??? in future, also handle colours
}
void CreateConsole(void);
Expand Down Expand Up @@ -507,6 +507,8 @@
{ static int createdconsole=0;
if (!createdconsole) {
curseswin=initscr();
if (has_colors())
start_color();
cbreak();
noecho();
nonl();
Expand Down
13 changes: 10 additions & 3 deletions compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*
* Version: $Id: sc1.c 4731 2012-06-21 11:11:18Z thiadmer $
* Version: $Id: sc1.c 4731 2012-06-21 11:11:18Z $
*/
#include <assert.h>
#include <ctype.h>
Expand Down Expand Up @@ -2837,7 +2837,7 @@ static cell initvector(int ident,int usage,int tag,cell size,int fillzero,
cell prev1=0,prev2=0;
int ellips=FALSE;
int curlit=litidx;
int ctag;
int ctag,ftag;
int match=0;
int packcount=-1;
cell packitem=0;
Expand Down Expand Up @@ -2877,9 +2877,13 @@ static cell initvector(int ident,int usage,int tag,cell size,int fillzero,
matchbrace='}';
fieldusage=field->usage;
} /* if */
ftag=-1;
for ( ;; ) {
prev2=prev1;
prev1=init(ident,fieldusage,&ctag,errorfound,&packcount,&packitem);
if (ftag!=-1 && ftag!=ctag)
error(213); /* tag mismatch */
ftag=ctag;
if (!matchbrace)
break;
if ((ellips=matchtoken(tELLIPS))!=0)
Expand Down Expand Up @@ -2924,9 +2928,12 @@ static cell initvector(int ident,int usage,int tag,cell size,int fillzero,
litadd(val);
} /* if */
} /* for */
ftag=field->index;
field=field->next;
} else {
ftag=tag;
} /* if */
if (!matchtag(tag,ctag,TRUE))
if (!matchtag(ftag,ctag,TRUE))
error(213); /* tag mismatch */
} while (matchtoken(','));
if (packcount!=0 && match=='}' && !ellips)
Expand Down
20 changes: 20 additions & 0 deletions test/rational.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <rational>

#if defined TAGGED_SYMBOLIC_INDEX
static const Table[][Rational:.key, Rational:.value] =
[
[1.0, 3.0],
[2.0, 3.5],
[3.0, 3.7],
[4.0, 3.8],
[5.0, 3.9]
];
#endif

main()
{
#if defined TAGGED_SYMBOLIC_INDEX
for (new i; i<sizeof(Table); i++)
printf("%d: %r, %r\n", i, Table[i].key, Table[i].value);
#endif
}
5 changes: 3 additions & 2 deletions test/test.rexx
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,11 @@ test102:
return

test103:
say '103. Redundant test, please ignore.'
say '103. The following test should compile successfully (NO warnings 213).'
say ''
say 'This test has become redundant because of syntax changes in Pawn.'
say ' Symbolic array indices with tag overrides.'
say '-----'
pawncc ' TAGGED_SYMBOLIC_INDEX= rational'
return

test104:
Expand Down

0 comments on commit 8e36a8f

Please sign in to comment.