Skip to content

Commit

Permalink
[ADDED]#629 : Post increment/decrement operators
Browse files Browse the repository at this point in the history
  • Loading branch information
arakov committed Oct 28, 2023
1 parent 175d797 commit 9817ec1
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 30 deletions.
11 changes: 11 additions & 0 deletions dat/sg/syntax60.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ __define TUPLE_ASSIGNING 6246;
__define CONTINUE_OPERATION 6247;
__define YIELD_OPERATION 6248;
__define REFER_OPERATION 6251;
__define INC_OPERATION 6252;
__define DEC_OPERATION 6253;

__define MESSAGE_OPERATION 6337;
__define PROPERTY_OPERATION 6340;
__define EXPRESSION 6288;
Expand Down Expand Up @@ -297,6 +300,8 @@ ROOT_EXPRESSION ::=
| TRY ^OBJECT TRY_R
| FNL ^OBJECT FNL_R
| ALT ^OBJECT ALT_R
| INC ^OBJECT ^INC_OPERATION
| DEC ^OBJECT ^DEC_OPERATION
| T_EXPRESSION T_EXPRESSION_F ^ TEMPLATE_BLOCK
| "=>" ^OBJECT { SWITCH_OPTION+ SWITCH_LAST_OPTION? } ^SWITCH_OPERATION
| eps ^OBJECT }
Expand Down Expand Up @@ -360,6 +365,8 @@ NESTED_ROOT_EXPRESSION ::=
| TRY ^OBJECT TRY_R
| T_EXPRESSION T_EXPRESSION_F ^ TEMPLATE_BLOCK
| "=>" ^OBJECT { SWITCH_OPTION+ SWITCH_LAST_OPTION? } ^SWITCH_OPERATION
| INC ^OBJECT ^INC_OPERATION
| DEC ^OBJECT ^DEC_OPERATION
| eps ^OBJECT }
| { reference | global } {
L3 ^OBJECT MESSAGE MESSAGE_R
Expand Down Expand Up @@ -416,6 +423,8 @@ EXPRESSION ::=
| ISNIL ^OBJECT SINGLE_EXPRESSION ^ISNIL_OPERATION
| TRY ^OBJECT TRY_R
| NESTED_EXPRESSION ^NESTED L3_OP*
| INC ^OBJECT ^INC_OPERATION
| DEC ^OBJECT ^DEC_OPERATION
| eps ^OBJECT }
| { reference | global } {
L2 ^OBJECT L2_R L3_OP* L4_OP* L5_OP* L6_OP? L7_OP* L9_OP?
Expand Down Expand Up @@ -726,6 +735,8 @@ TRY ::= "\\";
ALT ::= "\";
ISNIL ::= "??";
FNL ::= "$fnl";
INC ::= "++";
DEC ::= "--";

L0_R ::=
EXPRESSION "]" ^INDEXER_OPERATION;
Expand Down
7 changes: 5 additions & 2 deletions doc/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ In development:
ide:backlog, vm debugger, debugger watch - struct
tools:backlog
prom:tutorial 2 - bytecodes / program entry / linker
port:gui samples, db samples, xforms, elenasm / elt for linux
port:gui samples, db samples, xforms, elenavm / elt for linux
--------------------------------------

* #629
* #629 : Post increment/decrement operators
* field += n - test
* field ++ - test

* test ls example
* gui samples - agenda
* #602 : set r:xx, store sp:0 -> one command
* anagram #132
* gui samples
* elenasm for linux

=== Iteration 20 ===
dev:
Expand Down
2 changes: 1 addition & 1 deletion elenasrc3/elc/cliconst.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace elena_lang
{
#define ELC_REVISION_NUMBER 0x0215
#define ELC_REVISION_NUMBER 0x0216

#if defined _M_IX86 || _M_X64

Expand Down
28 changes: 21 additions & 7 deletions elenasrc3/elc/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8152,21 +8152,30 @@ ObjectInfo Compiler :: compileAssignOperation(BuildTreeWriter& writer, ExprScope

ArgumentsInfo updatedOuterArgs;
ObjectInfo loperand = compileExpression(writer, scope, lnode, 0, EAttr::Parameter, &updatedOuterArgs);
ObjectInfo roperand = compileExpression(writer, scope, rnode, 0, EAttr::Parameter, &updatedOuterArgs);

ObjectInfo roperand = {};

size_t argLen = 1;
ref_t arguments[2] = {};
arguments[0] = loperand.typeInfo.typeRef;
arguments[1] = roperand.typeInfo.typeRef;

if (rnode != SyntaxKey::None) {
roperand = compileExpression(writer, scope, rnode, 0, EAttr::Parameter, &updatedOuterArgs);
arguments[1] = roperand.typeInfo.typeRef;
argLen++;
}

ref_t dummy = 0;
BuildKey op = _logic->resolveOp(*scope.moduleScope, operatorId, arguments, 2, dummy);
BuildKey op = _logic->resolveOp(*scope.moduleScope, operatorId, arguments, argLen, dummy);
if (op != BuildKey::None) {
// box argument locally if required
loperand = boxArgumentLocally(writer, scope, loperand, true, true);
roperand = boxArgumentLocally(writer, scope, roperand, true, false);

writeObjectInfo(writer, scope, roperand);
writer.appendNode(BuildKey::SavingInStack, 0);
if (roperand.kind != ObjectKind::Unknown) {
roperand = boxArgumentLocally(writer, scope, roperand, true, false);

writeObjectInfo(writer, scope, roperand);
writer.appendNode(BuildKey::SavingInStack, 0);
}

writer.newNode(op, operatorId);
writer.appendNode(BuildKey::Index, loperand.argument);
Expand Down Expand Up @@ -9859,6 +9868,8 @@ ObjectInfo Compiler :: compileExpression(BuildTreeWriter& writer, ExprScope& sco
case SyntaxKey::SubAssignOperation:
case SyntaxKey::MulAssignOperation:
case SyntaxKey::DivAssignOperation:
case SyntaxKey::IncOperation:
case SyntaxKey::DecOperation:
retVal = compileAssignOperation(writer, scope, current, (int)current.key - OPERATOR_MAKS, targetRef);
break;
case SyntaxKey::AndOperation:
Expand Down Expand Up @@ -10919,6 +10930,9 @@ mssg_t Compiler :: compileInplaceConstructorHandler(BuildTreeWriter& writer, Met
writer.appendNode(BuildKey::OpenFrame);

if (classScope->info.methods.exist(invokerScope.moduleScope->buildins.init_message)) {
ExprScope exprScope(&codeScope);
writeObjectInfo(writer, exprScope, privateScope.mapSelf());

compileInlineInitializing(writer, *classScope, mathodNode);
}
if (mathodNode.existChild(SyntaxKey::FillingAttr)) {
Expand Down
14 changes: 13 additions & 1 deletion elenasrc3/elc/compilerlogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct Op
ref_t output;
};

constexpr auto OperationLength = 150;
constexpr auto OperationLength = 154;
constexpr Op Operations[OperationLength] =
{
{
Expand Down Expand Up @@ -125,6 +125,12 @@ constexpr Op Operations[OperationLength] =
{
BNOT_OPERATOR_ID, BuildKey::IntSOp, V_INT32, 0, 0, V_INT32
},
{
INC_OPERATOR_ID, BuildKey::IntSOp, V_INT32, 0, 0, V_INT32
},
{
DEC_OPERATOR_ID, BuildKey::IntSOp, V_INT32, 0, 0, V_INT32
},
{
SHL_OPERATOR_ID, BuildKey::IntOp, V_INT32, V_INT32, 0, V_INT32
},
Expand Down Expand Up @@ -194,6 +200,12 @@ constexpr Op Operations[OperationLength] =
{
BNOT_OPERATOR_ID, BuildKey::IntSOp, V_UINT32, 0, 0, V_UINT32
},
{
INC_OPERATOR_ID, BuildKey::IntSOp, V_UINT32, 0, 0, V_UINT32
},
{
DEC_OPERATOR_ID, BuildKey::IntSOp, V_UINT32, 0, 0, V_UINT32
},
{
SHL_OPERATOR_ID, BuildKey::IntOp, V_UINT32, V_UINT32, 0, V_UINT32
},
Expand Down
9 changes: 5 additions & 4 deletions elenasrc3/elc/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

using namespace elena_lang;

const char* source_dfa[33] =
const char* source_dfa[34] =
{
".????????BB??B??????????????????BDFIRCDLDQDDDVQHEEEEEEEEEEDDDDYD`CCCCCCCCCCCCCCCCCCCCCCCCCCDDQDC?CCCCCCCCCCCCCCCCCCCCCCCCCCDDDDC",
".????????BB??B??????????????????BDFIRCDLDQDbDVQHEEEEEEEEEEDDDDYD`CCCCCCCCCCCCCCCCCCCCCCCCCCDDQDC?CCCCCCCCCCCCCCCCCCCCCCCCCCDDDDC",
"*********BB*********************B***********************************************************************************************",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAAAACCCCCCCCCCAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCAAAACACCCCCCCCCCCCCCCCCCCCCCCCCCAAAAC",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAQAADQDAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAA",
Expand All @@ -35,7 +35,7 @@ const char* source_dfa[33] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFATAAAAAAAAAAASSSSSSSSSSAAAAAAASSSSSSAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAAAAAAAAAAAAAAAA",
"????????????????????????????????????????????????UUUUUUUUUU??????????????????????????????????????????????????????????????????????",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAGAAAAAAAAAAAUUUUUUUUUUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"-------------------------------------------------------------Q------------------------------------------------------------------",
"---------------------------------------------Q---------------Q------------------------------------------------------------------",
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!EEEEEEEEEE!!!D!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
Expand All @@ -46,7 +46,8 @@ const char* source_dfa[33] =
"???????????????????????????????????????????]?]??]]]]]]]]]]??????????????????????????????????????????????????????????????????????",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"?????????????????????????????????????????????????????????????????aaaaaaaaaaaaaaaaaaaaaaaaaa????a?aaaaaaaaaaaaaaaaaaaaaaaaaa????a",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`AAAAAAAAaaaaaaaaaaAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAaAaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAa"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`AAAAAAAAaaaaaaaaaaAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAaAaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAa",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
};

// --- SourceReader ---
Expand Down
3 changes: 2 additions & 1 deletion elenasrc3/elc/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace elena_lang

bool IsOperator(char state)
{
return (state == dfaOperator || state == dfaAltOperator || state == dfaGrOperator);
return (state == dfaOperator || state == dfaAltOperator
|| state == dfaGrOperator || state == dfaIncOperator);
}
bool IsQuoteToken(char state)
{
Expand Down
6 changes: 6 additions & 0 deletions elenasrc3/engine/bcwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,12 @@ void intSOp(CommandTape& tape, BuildNode& node, TapeScope&)
case BNOT_OPERATOR_ID:
tape.write(ByteCode::INotDPN, targetOffset, 4);
break;
case INC_OPERATOR_ID:
tape.write(ByteCode::NAddDPN, targetOffset, 1);
break;
case DEC_OPERATOR_ID:
tape.write(ByteCode::NAddDPN, targetOffset, -1);
break;
default:
throw InternalError(errFatalError);
}
Expand Down
2 changes: 2 additions & 0 deletions elenasrc3/engine/langcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ namespace elena_lang
constexpr auto CONTINUE_OPERATOR_ID = 0x0027;
constexpr auto YIELD_OPERATOR_ID = 0x0028;
constexpr auto REFERENCE_OPERATOR_ID = 0x002B;
constexpr auto INC_OPERATOR_ID = 0x002C;
constexpr auto DEC_OPERATOR_ID = 0x002D;

constexpr auto ISNIL_OPERATOR_ID = 0x003E;
constexpr auto CLASS_OPERATOR_ID = 0x003F;
Expand Down
2 changes: 2 additions & 0 deletions elenasrc3/engine/syntaxtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ namespace elena_lang
Postfix = 0x001069,
TemplatePostfix = 0x00106A,
ReferOperation = 0x00186B,
IncOperation = 0x00186C,
DecOperation = 0x00186D,
TemplateArg = 0x001070,
Dimension = 0x001471,
NestedBlock = 0x001080,
Expand Down
1 change: 1 addition & 0 deletions elenasrc3/engine/textparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace elena_lang
constexpr char dfaReal = ']';
constexpr char dfaRealPostfix = '_';
constexpr char dfaGlobal = 'a';
constexpr char dfaIncOperator = 'c';

constexpr char dfaPrivate = 'N';
constexpr char dfaLong = '?';
Expand Down
15 changes: 2 additions & 13 deletions tests60/sandbox/sandbox.l
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
public sealed const struct XUnsafePointer
{
embeddable __ptr _pointer;

get static XUnsafePointer Default()
= new XUnsafePointer();

constructor()
{
}
}
import extensions;

public program()
{
XUnsafePointer ptr := XUnsafePointer.Default;
}
}
32 changes: 31 additions & 1 deletion tests60/system_tests/basic.l
Original file line number Diff line number Diff line change
Expand Up @@ -1658,4 +1658,34 @@ public lookaheadTests()
Assert.ifTrue(r2 == 4);

console.writeLine(".");
}
}

struct IncTestStruct
{
int x := 0;
int y := 1;

act()
{
x++;
y--;
}

assert()
{
Assert.ifTrue(x == 1);
Assert.ifTrue(y == 0);
}
}

incTest()
{
console.write("incTest:");

IncTestStruct struct := new IncTestStruct();

struct.act();
struct.assert();

console.writeLine(".");
}
1 change: 1 addition & 0 deletions tests60/system_tests/main.l
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public program()
nilReferenceTest();
structTest();
lookaheadTests();
incTest();

console.writeLine("--- Passed ---")
}

0 comments on commit 9817ec1

Please sign in to comment.