Skip to content
Permalink
Browse files

Merge pull request #99 from polserver/unary_inc_dec

Unary inc dec
  • Loading branch information...
frozenblit committed Oct 13, 2019
2 parents 17981ff + 8bbc8a1 commit a7cde56fbe6e2ba9b01c93de657592fef72db6cd
Showing with 1,087 additions and 468 deletions.
  1. +25 −1 docs/docs.polserver.com/pol100/corechanges.xml
  2. +8 −0 pol-core/bscript/bobject.h
  3. +40 −0 pol-core/bscript/compctx.h
  4. +288 −297 pol-core/bscript/compiler.cpp
  5. +3 −2 pol-core/bscript/compilercfg.cpp
  6. +4 −3 pol-core/bscript/compilercfg.h
  7. +6 −2 pol-core/bscript/eprog_read.cpp
  8. +124 −22 pol-core/bscript/executor.cpp
  9. +8 −0 pol-core/bscript/executor.h
  10. +6 −2 pol-core/bscript/object.cpp
  11. +57 −66 pol-core/bscript/parser.cpp
  12. +13 −22 pol-core/bscript/parser.h
  13. +24 −0 pol-core/bscript/tkn_strm.cpp
  14. +10 −0 pol-core/bscript/tokens.h
  15. +2 −2 pol-core/clib/Program/ProgramMain.cpp
  16. +2 −0 pol-core/clib/refptr.h
  17. +21 −0 pol-core/doc/core-changes.txt
  18. +58 −49 pol-core/ecompile/ECompileMain.cpp
  19. +8 −0 pol-core/support/scripts/ecompile.cfg.example
  20. +1 −0 testsuite/escript/ecompile.cfg
  21. +1 −0 testsuite/escript/misc/casesensitivity.err
  22. +1 −0 testsuite/escript/misc/casesensitivity.inc
  23. +2 −0 testsuite/escript/misc/casesensitivity.src
  24. +22 −0 testsuite/escript/oper/minusminus01.out
  25. +49 −0 testsuite/escript/oper/minusminus01.src
  26. +21 −0 testsuite/escript/oper/minusminus03.out
  27. +46 −0 testsuite/escript/oper/minusminus03.src
  28. +7 −0 testsuite/escript/oper/minusminus05.out
  29. +11 −0 testsuite/escript/oper/minusminus05.src
  30. +21 −0 testsuite/escript/oper/plusplus01.out
  31. +54 −0 testsuite/escript/oper/plusplus01.src
  32. +8 −0 testsuite/escript/oper/plusplus02.out
  33. +27 −0 testsuite/escript/oper/plusplus02.src
  34. +20 −0 testsuite/escript/oper/plusplus03.out
  35. +51 −0 testsuite/escript/oper/plusplus03.src
  36. +7 −0 testsuite/escript/oper/plusplus04.out
  37. +13 −0 testsuite/escript/oper/plusplus04.src
  38. +7 −0 testsuite/escript/oper/plusplus05.out
  39. +11 −0 testsuite/escript/oper/plusplus05.src
@@ -2,9 +2,33 @@
<ESCRIPT>
<header>
<topic>Latest Core Changes</topic>
<datemodified>10-03-2019</datemodified>
<datemodified>10-07-2019</datemodified>
</header>
<version name="POL100">
<entry>
<date>10-05-2019</date>
<author>Turley:</author>
<change type="Changed">ECompile reports warnings and errors to cerr instead of printing everything to cout.<br/>
Exit code of ECompile is 1 when at least one file fails to compile.</change>
<change type="Added">ecompile.cfg ErrorOnFileCaseMissmatch (default 0)<br/>
commandline flag -c<br/>
Leads to a compilation error if the capitalization of the include directive does not match the filename.<br/>
This has only a meaning on windows.<br/>
The existing warning is now an official warning meaning that the error on warning flag leads also to an abort.</change>
<change type="Added">pre/post increment/decrement unary operator (++i, i++, --i, i--) for integer and doubles.<br/>
++i is the same as writing i+=1 or i:=i+1<br/>
i++ returns the old value, thus its equal to j:=i; i+=1;<br/>
Since it is an unary operator it can be directly used as function parameter or eg while loops.<br/>
Instead of writing<br/>
while (i&lt;5)<br/>
i+=1;<br/>
...<br/>
you can directly write<br/>
while (++i&lt;5)<br/>
...</change>
<change type="Note">The operators are only implemented for numbers but this includes also eg. arrays or members when it represents a number. So ++a[1], ++who.fire_resist_mod are also valid.<br/>
Performance wise is i:=i+1 the slowest then i+=1 then i++ then ++i. (i++ is slower since it returns the old value).</change>
</entry>
<entry>
<date>10-03-2019</date>
<author>Turley:</author>
@@ -326,6 +326,9 @@ class BObjectImp : public ref_counted

virtual BObjectImp* inverse() const;

virtual void selfPlusPlus();
virtual void selfMinusMinus();

virtual ContIterator* createIterator( BObject* pIterVal );

friend std::ostream& operator<<( std::ostream&, const BObjectImp& );
@@ -664,6 +667,9 @@ class BLong final : public BObjectImp

virtual BObjectImp* bitnot() const override;

virtual void selfPlusPlus() override { ++lval_; }
virtual void selfMinusMinus() override { --lval_; }

virtual std::string getStringRep() const override;
virtual void printOn( std::ostream& ) const override;

@@ -749,6 +755,8 @@ class Double final : public BObjectImp
virtual void selfDividedByObjImp( BObjectImp& objimp, BObject& obj ) override;
virtual void selfDividedByObj( BLong& objimp, BObject& obj ) override;
virtual void selfDividedByObj( Double& objimp, BObject& obj ) override;
virtual void selfPlusPlus() override { ++dval_; }
virtual void selfMinusMinus() override { --dval_; }

virtual BObjectImp* inverse() const override { return new Double( -dval_ ); }
virtual std::string getStringRep() const override;
@@ -6,6 +6,8 @@

#ifndef BSCRIPT_COMPCTX_H
#define BSCRIPT_COMPCTX_H
#include "../clib/logfacility.h"
#include "compilercfg.h"

#include <iosfwd>
#include <string>
@@ -64,6 +66,44 @@ inline fmt::Writer& operator<<( fmt::Writer& writer, const CompilerContext& ctx
ctx.printOn( writer );
return writer;
}

namespace
{
inline void rec_write( fmt::Writer& /*w*/ ) {}
template <typename T, typename... Targs>
inline void rec_write( fmt::Writer& w, T&& value, Targs&&... Fargs )
{
w << value;
rec_write( w, std::forward<Targs>( Fargs )... );
}
} // namespace

template <typename... Args>
inline void compiler_warning( CompilerContext* ctx, Args&&... args )
{
if ( compilercfg.DisplayWarnings || compilercfg.ErrorOnWarning )
{
fmt::Writer w;
rec_write( w, std::forward<Args>( args )... );

if ( compilercfg.ErrorOnWarning )
throw std::runtime_error( w.str() );
else
{
if ( ctx != nullptr )
w << *ctx;
ERROR_PRINT << w.c_str();
}
}
}

template <typename... Args>
inline void compiler_error( Args&&... args )
{
fmt::Writer w;
rec_write( w, std::forward<Args>( args )... );
ERROR_PRINT << w.str();
}
} // namespace Bscript
} // namespace Pol
#endif

0 comments on commit a7cde56

Please sign in to comment.
You can’t perform that action at this time.