From db88bbf305e6bbee91751bdd5d9255eea56e26c6 Mon Sep 17 00:00:00 2001 From: Eddie Runia Date: Sat, 5 Jun 1999 10:51:34 +0000 Subject: [PATCH] see changelog --- harbour/ChangeLog | 15 ++++++ harbour/source/compiler/harbour.y | 36 ++++++------- harbour/source/rtl/natmsg/msgdut.c | 4 +- harbour/tests/working/funcarr.prg | 35 +++++++------ harbour/tests/working/objarr.prg | 81 ++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 35 deletions(-) create mode 100644 harbour/tests/working/objarr.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3e4287aae6..f6c278f24d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,18 @@ +19990604-11:50 CET Eddie Runia + * source/compiler/harbour.y + support for the following syntax added : + :[] + :()[] + + and increment / decrement for ()[], + :[] and :()[] + * source/rtl/natmsg/msgdut.c + Sunday is the first day ofcourse + + tests/working/objarr.prg + tests for object array syntax + * tests/working/funcarr.prg + tests for function array syntax (inc/dec added) + 19990604-23:15 EDT David G. Holm + include/version.h - New file to specify version info. A future revision will be diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 7e18bc659d..6431963086 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -637,14 +637,14 @@ VarUnary : IDENTIFIER IncDec %prec POST { PushId( $1 ); Duplicate(); $2 ? I | IncDec IDENTIFIER %prec PRE { PushId( $2 ); $1 ? Inc(): Dec(); Duplicate(); PopId( $2 ); } | VarId ArrayIndex IncDec %prec POST { DupPCode( $1 ); GenPCode1( _ARRAYAT ); $3 ? Inc(): Dec(); GenPCode1( _ARRAYPUT ); $3 ? Dec(): Inc(); } | IncDec VarId ArrayIndex %prec PRE { DupPCode( $2 ); GenPCode1( _ARRAYAT ); $1 ? Inc(): Dec(); GenPCode1( _ARRAYPUT ); } - | FunArrayCall IncDec %prec POST {} - | IncDec FunArrayCall %prec PRE {} + | FunArrayCall IncDec %prec POST { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); $2 ? Inc(): Dec(); GenPCode1( _ARRAYPUT ); $2 ? Dec(): Inc(); } + | IncDec FunArrayCall %prec PRE { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); $1 ? Inc(): Dec(); GenPCode1( _ARRAYPUT ); } | ObjectData IncDec %prec POST {} | IncDec ObjectData %prec PRE {} - | ObjectData ArrayIndex IncDec %prec POST {} - | IncDec ObjectData ArrayIndex %prec PRE {} - | ObjectMethod ArrayIndex IncDec %prec POST {} - | IncDec ObjectMethod ArrayIndex %prec PRE {} + | ObjectData ArrayIndex IncDec %prec POST { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); $3 ? Inc(): Dec(); GenPCode1( _ARRAYPUT ); $3 ? Dec(): Inc(); } + | IncDec ObjectData ArrayIndex %prec PRE { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); $1 ? Inc(): Dec(); GenPCode1( _ARRAYPUT ); } + | ObjectMethod ArrayIndex IncDec %prec POST { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); $3 ? Inc(): Dec(); GenPCode1( _ARRAYPUT ); $3 ? Dec(): Inc(); } + | IncDec ObjectMethod ArrayIndex %prec PRE { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); $1 ? Inc(): Dec(); GenPCode1( _ARRAYPUT ); } ; IncDec : INC { $$ = 1; } @@ -698,19 +698,19 @@ VarAssign : IDENTIFIER INASSIGN Expression { PopId( $1 ); PushId( $1 ); } | ObjectData EXPEQ Expression {} | ObjectData MODEQ Expression {} | ObjectData ArrayIndex INASSIGN Expression { GenPCode1( _ARRAYPUT ); } - | ObjectData ArrayIndex PLUSEQ Expression {} - | ObjectData ArrayIndex MINUSEQ Expression {} - | ObjectData ArrayIndex MULTEQ Expression {} - | ObjectData ArrayIndex DIVEQ Expression {} - | ObjectData ArrayIndex EXPEQ Expression {} - | ObjectData ArrayIndex MODEQ Expression {} + | ObjectData ArrayIndex PLUSEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _PLUS ); GenPCode1( _ARRAYPUT ); } + | ObjectData ArrayIndex MINUSEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _MINUS ); GenPCode1( _ARRAYPUT ); } + | ObjectData ArrayIndex MULTEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _MULT ); GenPCode1( _ARRAYPUT ); } + | ObjectData ArrayIndex DIVEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _DIVIDE ); GenPCode1( _ARRAYPUT ); } + | ObjectData ArrayIndex EXPEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _POWER ); GenPCode1( _ARRAYPUT ); } + | ObjectData ArrayIndex MODEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _MODULUS ); GenPCode1( _ARRAYPUT ); } | ObjectMethod ArrayIndex INASSIGN Expression { GenPCode1( _ARRAYPUT ); } - | ObjectMethod ArrayIndex PLUSEQ Expression {} - | ObjectMethod ArrayIndex MINUSEQ Expression {} - | ObjectMethod ArrayIndex MULTEQ Expression {} - | ObjectMethod ArrayIndex DIVEQ Expression {} - | ObjectMethod ArrayIndex EXPEQ Expression {} - | ObjectMethod ArrayIndex MODEQ Expression {} + | ObjectMethod ArrayIndex PLUSEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _PLUS ); GenPCode1( _ARRAYPUT ); } + | ObjectMethod ArrayIndex MINUSEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _MINUS ); GenPCode1( _ARRAYPUT ); } + | ObjectMethod ArrayIndex MULTEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _MULT ); GenPCode1( _ARRAYPUT ); } + | ObjectMethod ArrayIndex DIVEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _DIVIDE ); GenPCode1( _ARRAYPUT ); } + | ObjectMethod ArrayIndex EXPEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _POWER ); GenPCode1( _ARRAYPUT ); } + | ObjectMethod ArrayIndex MODEQ { GenPCode1( _DUPLTWO ); GenPCode1( _ARRAYAT ); } Expression { GenPCode1( _MODULUS ); GenPCode1( _ARRAYPUT ); } | AliasExp INASSIGN Expression {} ; diff --git a/harbour/source/rtl/natmsg/msgdut.c b/harbour/source/rtl/natmsg/msgdut.c index 867fe2139c..385c1fed52 100644 --- a/harbour/source/rtl/natmsg/msgdut.c +++ b/harbour/source/rtl/natmsg/msgdut.c @@ -8,5 +8,5 @@ char *hb_monthsname[ 12 ] = { "november", "december" }; char *hb_daysname[ 7 ] = { - "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag", - "zondag" }; + "zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag", + "zaterdag" }; diff --git a/harbour/tests/working/funcarr.prg b/harbour/tests/working/funcarr.prg index 11d1baaead..493234a242 100644 --- a/harbour/tests/working/funcarr.prg +++ b/harbour/tests/working/funcarr.prg @@ -6,34 +6,39 @@ Function Main local a - QOut( aFunc()[1] ) + QOut( "Direct reference : ", aFunc()[1] ) a := aFunc() - QOut( a[1] ) + QOut( "Ref via array : ", a[1] ) aFunc()[1] := "Something different" - QOut( aFunc()[1] ) + QOut( "Assign new text : ", aFunc()[1] ) aFunc()[1] := 4 - QOut( aFunc()[1] ) + QOut( "Assign 4 : ", aFunc()[1] ) - aFunc()[1] += 1 - QOut( aFunc()[1] ) + QOut( "Post increment : ", aFunc()[1]++ ) + QOut( "After : ", aFunc()[1] ) + QOut( "Pre decrement : ", --aFunc()[1] ) + QOut( "After : ", aFunc()[1] ) - aFunc()[1] -= 1 - QOut( aFunc()[1] ) + aFunc()[1] += 2 + QOut( "Plus 2 : ", aFunc()[1] ) - aFunc()[1] *= 2 - QOut( aFunc()[1] ) + aFunc()[1] -= 3 + QOut( "Minus 3 : ", aFunc()[1] ) - aFunc()[1] /= 2 - QOut( aFunc()[1] ) + aFunc()[1] *= 3 + QOut( "Times 3 : ", aFunc()[1] ) - aFunc()[1] %= 5 - QOut( aFunc()[1] ) + aFunc()[1] /= 1.5 + QOut( "Divide by 1.5 : ", aFunc()[1] ) + + aFunc()[1] %= 4 + QOut( "Modulus 4 : ", aFunc()[1] ) aFunc()[1] ^= 3 - QOut( aFunc()[1] ) + QOut( "To the power 3 : ", aFunc()[1] ) QOut( "Global stack" ) HBDebug( __aGlobalStack() ) // Please note a is a reference to aArray ! diff --git a/harbour/tests/working/objarr.prg b/harbour/tests/working/objarr.prg new file mode 100644 index 0000000000..4371fa0754 --- /dev/null +++ b/harbour/tests/working/objarr.prg @@ -0,0 +1,81 @@ +// +// Object Array syntax test +// + +Function Main + + local o := TNumber():New() + + QOut( "Direct reference : ", ToChar( o:x ) ) + + o:x[1] := "I am a data" + o:Get()[2] := "I am a method" + QOut( "Assign text : ", ToChar( o:x ) ) + + o:x[1] := 4 + o:Get()[2] := 4 + QOut( "Assign 4 : ", ToChar( o:x ) ) + + QOut( "Post increment : ", o:x[1]++ , o:Get()[2]++ ) + QOut( "After : ", o:x[1] , o:Get()[2] ) + QOut( "Pre decrement : ", --o:x[1] , --o:Get()[2] ) + QOut( "After : ", o:x[1] , o:Get()[2] ) + + o:x[1] += 2 + o:Get()[2] += 2 + QOut( "Plus 2 : ", ToChar( o:x ) ) + + o:x[1] -= 3 + o:Get()[2] -= 3 + QOut( "Minus 3 : ", ToChar( o:x ) ) + + o:x[1] *= 3 + o:Get()[2] *= 3 + QOut( "Times 3 : ", ToChar( o:x ) ) + + o:x[1] /= 1.5 + o:Get()[2] /= 1.5 + QOut( "Divide by 1.5 : ", ToChar( o:x ) ) + + o:x[1] %= 4 + o:Get()[2] %= 4 + QOut( "Modulus 4 : ", ToChar( o:x ) ) + + o:x[1] ^= 3 + o:Get()[2] ^= 3 + QOut( "To the power 3 : ", ToChar( o:x ) ) + + QOut( "Global stack" ) + HBDebug( __aGlobalStack() ) // Please note a is a reference to aArray ! + QOut( "Statics") + HBDebug( __aStatic() ) +return NIL + +Function TNumber() // Very simple class + + static oNumber + + if oNumber == NIL + oNumber := TClass():New( "TNumber" ) + + oNumber:AddData ( "x" ) + oNumber:AddMethod( "Get", @Get() ) + oNumber:AddMethod( "New", @New() ) + oNumber:Create() + endif +return oNumber:Instance() + + +static function New() + + local self := QSelf() + + ::x := {1,1} +return self + + +static function Get() + + local self := QSelf() + +return ::x