Skip to content

Commit

Permalink
[ADDED] ins / over modes
Browse files Browse the repository at this point in the history
[ADDED] #637 - unit tests for intCopying optimization
  • Loading branch information
arakov committed Apr 4, 2024
1 parent b374afb commit 79e8c03
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 41 deletions.
18 changes: 18 additions & 0 deletions doc/api/extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,24 @@ <H3>Extension Summary</H3>
<CODE>
</CODE></TD>
<TD CLASS="colLast">
<CODE>printWide(<i>params</i> <SPAN CLASS="memberNameLink"><A HREF="system.html#Object">Object</A></SPAN><i>[]</i> list)
</CODE>
</TD>
</TR>
<TR CLASS="altColor">
<TD CLASS="colFirst">
<CODE>
</CODE></TD>
<TD CLASS="colLast">
<CODE>printWideLine(<i>params</i> <SPAN CLASS="memberNameLink"><A HREF="system.html#Object">Object</A></SPAN><i>[]</i> list)
</CODE>
</TD>
</TR>
<TR CLASS="rowColor">
<TD CLASS="colFirst">
<CODE>
</CODE></TD>
<TD CLASS="colLast">
<CODE><i>dispatch</i>()
</CODE>
</TD>
Expand Down
16 changes: 10 additions & 6 deletions doc/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@ In development:
--------------------------------------
dev: #637, windows executable - support manifest, net, #610, #612
opt:pi under 7 sec, #602, #611
maint:#620,#622
ide:vm debugger
tools:
prom:#635,elena in nutshell every 1 week
port:win64 gui,helloworld gui sample (button), chat sample, win64 script samples
--------------------------------------
- #617
- #637 : all bt tests (>=3)
- #617 : dark color scheme, change the window background color
- #620 : check : https://www.reddit.com/r/elena_lang/comments/hyst7t/elena_51_run_elena_code_without_build/
- #620 : data alignment : for normal structs - allign the data to 4/8 and make an operation aligned to 4/8; so all stack allocated data is aligned to 4 / 8; field are allocated to 4 / 8 for all cases except packed flag
- #637 : all bt tests (>=4)
- #622 : pi & e constants
- #622 : conversion to int - raise an error if not valid
- port : net library
--------------------------------------
- #617 : editor - status bar : ins / ovr, editor - modified doc mark,
- #620 : unit tests via postfix pattern

- remove Serializer / ScriptReader from elc project (when no longer is required)
- #637 (2)

=== Iteration 22 ===
--------------------------------------
dev: async programming (instant messagange sample (chat) ), #608, #637 (all bc tests)
op:
opt:pi under 6 sec, #601
maint: #506
maint: #506, #617, #620, #622
exp:
ide:
tools:
Expand Down
31 changes: 25 additions & 6 deletions elenasrc3/elena-tests/bt_optimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ constexpr auto OptimizedBuildTree1_2 = "local_address -4 () saving_stack 1 () cl

constexpr auto SyntaxTree1_3 = "expression(assign_operation(object(type(identifier \"Struct\" ())identifier \"r\"())expression(value_operation(expression(object(identifier \"Tester\"()))))))";

void BTOptimization1 :: SetUp()
constexpr auto Declaration2 = "namespace (class ( nameattr (identifier \"Object\" ())) class (attribute -2147467263 () attribute -2147475455 () attribute -2147479550 () nameattr (identifier \"IntNumber\" ()) field (attribute -2147475454 () attribute -2147481597 () nameattr (identifier \"_value\" ())dimension (integer \"4\" ()))) class ( attribute -2147471359 () nameattr (identifier \"IntNumberReference\" ()) field (attribute -2147475454 () type (identifier \"IntNumber\" ()) nameattr (identifier \"_value\" ())) ))";
constexpr auto SyntaxTree2 = "expression (assign_operation (object (type (identifier \"IntNumber\" ()) identifier \"n\" ()) expression (object (integer \"2\"))))";
constexpr auto BuildTree2 = "int_literal 2 (value 2 ()) copying -4 ( size 4 ())";
constexpr auto OptimizedBuildTree2 = "saving_int - 4 (size 4 ()value 2 ())";

void BTOptimization :: SetUp()
{
PathString appPath;
getAppPath(appPath);
Expand All @@ -63,11 +68,12 @@ void BTOptimization1 :: SetUp()
afterOptimization = buildTree.readRoot().appendChild(BuildKey::Tape);
}

void BTOptimization1 :: runCompilerTest(bool declareOperators)
void BTOptimization :: runCompilerTest(bool declareOperators)
{
// Arrange
ModuleScopeBase* moduleScope = env.createModuleScope(true, false);
moduleScope->buildins.superReference = 1;
moduleScope->buildins.intReference = 2;
moduleScope->buildins.wrapperTemplateReference = 3;

Compiler* compiler = env.createCompiler();
Expand Down Expand Up @@ -99,7 +105,7 @@ void BTOptimization1 :: runCompilerTest(bool declareOperators)
freeobj(moduleScope);
}

void BTOptimization1 :: runBTTest()
void BTOptimization :: runBTTest()
{
// Arrange
ByteCodeWriter::BuildTreeOptimizer buildTreeOptimizer;
Expand All @@ -122,7 +128,7 @@ void BTOptimization1 :: runBTTest()

void BTOptimization1_1 :: SetUp()
{
BTOptimization1::SetUp();
BTOptimization::SetUp();

SyntaxTreeSerializer::load(Declaration1_1, declarationNode);
SyntaxTreeSerializer::load(SyntaxTree1_1, exprNode);
Expand All @@ -135,7 +141,7 @@ void BTOptimization1_1 :: SetUp()

void BTOptimization1_2 :: SetUp()
{
BTOptimization1::SetUp();
BTOptimization::SetUp();

SyntaxTreeSerializer::load(Declaration1_2, declarationNode);
SyntaxTreeSerializer::load(SyntaxTree1_2, exprNode);
Expand All @@ -148,11 +154,24 @@ void BTOptimization1_2 :: SetUp()

void BTOptimization1_3 :: SetUp()
{
BTOptimization1::SetUp();
BTOptimization::SetUp();

SyntaxTreeSerializer::load(Declaration1_2, declarationNode);
SyntaxTreeSerializer::load(SyntaxTree1_3, exprNode);

BuildTreeSerializer::load(BuildTree1_2, beforeOptimization);
BuildTreeSerializer::load(OptimizedBuildTree1_2, afterOptimization);
}

// --- BTOptimization2 ---

void BTOptimization2 :: SetUp()
{
BTOptimization::SetUp();

SyntaxTreeSerializer::load(Declaration2, declarationNode);
SyntaxTreeSerializer::load(SyntaxTree2, exprNode);

BuildTreeSerializer::load(BuildTree2, beforeOptimization);
BuildTreeSerializer::load(OptimizedBuildTree2, afterOptimization);
}
21 changes: 14 additions & 7 deletions elenasrc3/elena-tests/bt_optimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace elena_lang
{
class BTOptimization1 : public testing::Test
class BTOptimization : public testing::Test
{
protected:
MemoryDump btRules;
Expand All @@ -36,22 +36,29 @@ namespace elena_lang
void runCompilerTest(bool declareOperators);
};

// Optimization 1 (byRefOp) : "a := b.get()" => "b.get(ref a)"
class BTOptimization1_1 : public BTOptimization1
// Optimization #2 (byRefOp) : "a := b.get()" => "b.get(ref a)"
class BTOptimization1_1 : public BTOptimization
{
protected:
void SetUp() override;
};

// Optimization 1 (byRefOp) : "a := b.Value" => "b.prop:Value(ref a)"
class BTOptimization1_2 : public BTOptimization1
// Optimization #2 (byRefOp) : "a := b.Value" => "b.prop:Value(ref a)"
class BTOptimization1_2 : public BTOptimization
{
protected:
void SetUp() override;
};

// Optimization 1 (byRefOp) : "a := *b" => "b.prop:Value(ref a)"
class BTOptimization1_3 : public BTOptimization1
// Optimization #2 (byRefOp) : "a := *b" => "b.prop:Value(ref a)"
class BTOptimization1_3 : public BTOptimization
{
protected:
void SetUp() override;
};

// Optimization #3 (intCopying) : "int n := 2" => direct assigning
class BTOptimization2 : public BTOptimization
{
protected:
void SetUp() override;
Expand Down
5 changes: 5 additions & 0 deletions elenasrc3/elena-tests/bt_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ TEST_F(BTOptimization1_2, BuildTapeTest)
}

TEST_F(BTOptimization1_3, BuildTapeTest)
{
runBTTest();
}

TEST_F(BTOptimization2, BuildTapeTest)
{
runBTTest();
}
7 changes: 6 additions & 1 deletion elenasrc3/elena-tests/compiler_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ TEST_F(BTOptimization1_2, CompilerTest)
TEST_F(BTOptimization1_3, CompilerTest)
{
runCompilerTest(true);
}
}

TEST_F(BTOptimization2, CompilerTest)
{
runCompilerTest(false);
}
2 changes: 2 additions & 0 deletions elenasrc3/engine/buildtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ namespace elena_lang
map.add("class_reference", BuildKey::ClassReference);
map.add("open_statement", BuildKey::OpenStatement);
map.add("end_statement", BuildKey::EndStatement);
map.add("saving_int", BuildKey::SavingInt);

map.add("value", BuildKey::Value);
map.add("tape", BuildKey::Tape);
map.add("type", BuildKey::Type);
map.add("size", BuildKey::Size);
Expand Down
11 changes: 11 additions & 0 deletions elenasrc3/gui/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ bool TextViewController :: eraseChar(TextViewModelBase* model, bool moveback)
return false;
}

void TextViewController :: setOverwriteMode(TextViewModelBase* model)
{
DocumentChangeStatus status = {};
auto docView = model->DocView();
if (!docView->isReadOnly()) {
docView->setOverwriteMode(status, !docView->isOverwriteMode());

notifyTextModelChange(model, status);
}
}

void TextViewController :: deleteText(TextViewModelBase* model)
{
DocumentChangeStatus status = {};
Expand Down
2 changes: 2 additions & 0 deletions elenasrc3/gui/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ namespace elena_lang
bool insertChar(TextViewModelBase* model, text_c ch) override;
bool eraseChar(TextViewModelBase* model, bool moveback) override;

void setOverwriteMode(TextViewModelBase* model) override;

void indent(TextViewModelBase* model) override;
void outdent(TextViewModelBase* model) override;

Expand Down
8 changes: 8 additions & 0 deletions elenasrc3/gui/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,14 @@ void DocumentView :: eraseChar(DocumentChangeStatus& changeStatus, bool moveback
status.rowDifference += (_text->getRowCount() - rowCount);
}

void DocumentView :: setOverwriteMode(DocumentChangeStatus& changeStatus, bool mode)
{
status.overwriteMode = mode;

changeStatus.caretChanged = true;
changeStatus.modeChanged = true;
}

bool DocumentView :: eraseSelection(DocumentChangeStatus& changeStatus)
{
if (_selection == 0)
Expand Down
6 changes: 6 additions & 0 deletions elenasrc3/gui/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ namespace elena_lang
bool textChanged;
bool modifiedChanged;
bool readOnlyChanged;
bool modeChanged;

bool isViewChanged()
{
Expand All @@ -122,6 +123,7 @@ namespace elena_lang
formatterChanged = false;
textChanged = false;
readOnlyChanged = false;
modeChanged = false;
}

DocumentChangeStatus()
Expand All @@ -137,6 +139,7 @@ namespace elena_lang
frameChanged = true;
selelectionChanged = true;
textChanged = true;
modeChanged = true;
}
}
};
Expand Down Expand Up @@ -281,6 +284,8 @@ namespace elena_lang
status.readOnly = mode;
}

void setOverwriteMode(DocumentChangeStatus& changeStatus, bool mode);

int getRowCount() const { return _text->getRowCount(); }
int getMaxColumn() const { return _maxColumn; }
disp_t getSelectionLength();
Expand All @@ -290,6 +295,7 @@ namespace elena_lang
bool isUnnamed() { return status.unnamed; }
bool isModified() { return status.modifiedMode; }
bool isIncluded() { return status.included; }
bool isOverwriteMode() { return status.overwriteMode; }

void markAsUnnamed()
{
Expand Down
2 changes: 2 additions & 0 deletions elenasrc3/gui/guieditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ namespace elena_lang
virtual bool insertChar(TextViewModelBase* model, text_c ch) = 0;
virtual bool eraseChar(TextViewModelBase* model, bool moveback) = 0;

virtual void setOverwriteMode(TextViewModelBase* model) = 0;

virtual void undo(TextViewModelBase* model) = 0;
virtual void redo(TextViewModelBase* model) = 0;

Expand Down
6 changes: 5 additions & 1 deletion elenasrc3/gui/windows/wintextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void TextViewWindow :: onResize()
void TextViewWindow :: onSetFocus()
{
if (_model) {
createCaret(_styles->getLineHeight(), /*_view->docView->status.overwriteMode ? _view->styles.getStyle(STYLE_DEFAULT)->avgCharWidth : */1);
createCaret(_styles->getLineHeight(), _model->DocView()->isOverwriteMode() ? _styles->getStyle(STYLE_DEFAULT)->avgCharWidth : 1);
showCaret();

ControlBase::refresh();
Expand Down Expand Up @@ -535,6 +535,10 @@ bool TextViewWindow :: onKeyDown(int keyCode, bool kbShift, bool kbCtrl)
case VK_DELETE:
_controller->eraseChar(_model, false);
break;
case VK_INSERT:
_controller->setOverwriteMode(_model);
onSetFocus();
break;
default:
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion elenasrc3/ide/ideversion.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

#define IDE_REVISION_NUMBER 123
#define IDE_REVISION_NUMBER 124
4 changes: 4 additions & 0 deletions elenasrc3/ide/windows/winidestatusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ void IDEStatusBar :: onDocumentUpdate(DocumentChangeStatus& changeStatus)

setText(2, line.str());
}
if (changeStatus.modeChanged) {
auto docView = _model->viewModel()->DocView();

setText(3, docView->isOverwriteMode() ? _T("OVR") : _T("INS"));
}
}

void IDEStatusBar :: setRectangle(Rectangle rec)
Expand Down
20 changes: 1 addition & 19 deletions tests60/sandbox/sandbox.l
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
public const struct Struct
{
embeddable __int _value[4];
}

public sealed XReference
{
embeddable Struct value;
}

public singleton Tester
{
get Struct Value()
{
^ new Struct();
}
}

public program()
{
Struct r := *Tester
int r := 2;
}

0 comments on commit 79e8c03

Please sign in to comment.