# HG changeset patch # User Teemu Piippo # Date 1343487457 -10800 # Node ID 3d3f6ed401715599349770e38b11a983d56d22df # Parent 0a9a5902beaa35005d0e44947dd0cb3ad7f6efef Negative literal integers work properly now.. diff -r 0a9a5902beaa -r 3d3f6ed40171 commands.def --- a/commands.def Sat Jul 28 17:41:24 2012 +0300 +++ b/commands.def Sat Jul 28 17:57:37 2012 +0300 @@ -1,3 +1,8 @@ +/* This file defines the commands botc will treat as valid. + * Do not edit unless you know what you are doing! + * + * Syntax: number:name:returntype:numargs:maxargs[:argumentlist] + */ 0:changestate:void:1:1:str(statename) 1:delay:void:1:1:int(tics) 2:rand:int:2:2:int(a):int(b) diff -r 0a9a5902beaa -r 3d3f6ed40171 parser.cxx --- a/parser.cxx Sat Jul 28 17:41:24 2012 +0300 +++ b/parser.cxx Sat Jul 28 17:57:37 2012 +0300 @@ -437,16 +437,22 @@ ParserError ("bad syntax"); break; case TYPE_INT: { - if (!token.isnumber ()) + printf ("value is an integer literal\n"); + /* if (!token.isnumber ()) ParserError ("expected an integer, got `%s`", token.chars()); + */ + MustNumber (true); + printf ("literal is `%s` = %d\n", token.chars(), atoi (token.chars())); // All values are written unsigned - thus we need to write the value's // absolute value, followed by an unary minus if it was negative. b->Write (DH_PUSHNUMBER); long v = atoi (token.chars ()); b->Write (static_cast (abs (v))); - if (v < 0) + if (v < 0) { + printf ("%ld is negative, write abs value %d and unary minus\n", v, abs(v)); b->Write (DH_UNARYMINUS); + } break; } case TYPE_STRING: diff -r 0a9a5902beaa -r 3d3f6ed40171 scriptreader.cxx --- a/scriptreader.cxx Sat Jul 28 17:41:24 2012 +0300 +++ b/scriptreader.cxx Sat Jul 28 17:57:37 2012 +0300 @@ -356,9 +356,10 @@ token = string; } -void ScriptReader::MustNumber () { +void ScriptReader::MustNumber (bool fromthis) { str num; - MustNext (); + if (!fromthis) + MustNext (); num += token; // Cater for a possible minus sign, since it @@ -370,6 +371,8 @@ if (!num.isnumber()) ParserError ("expected a number, got `%s`", num.chars()); + + token = num; } void ScriptReader::MustBool () { diff -r 0a9a5902beaa -r 3d3f6ed40171 scriptreader.h --- a/scriptreader.h Sat Jul 28 17:41:24 2012 +0300 +++ b/scriptreader.h Sat Jul 28 17:57:37 2012 +0300 @@ -81,7 +81,7 @@ void MustNext (const char* c = ""); void MustThis (const char* c); void MustString (bool gotquote = false); - void MustNumber (); + void MustNumber (bool fromthis = false); void MustBool (); void MustValue (int type); bool BoolValue ();