Skip to content

Commit

Permalink
Lib mode is back!
Browse files Browse the repository at this point in the history
+some cleanup
  • Loading branch information
SunSerega committed Apr 11, 2019
1 parent 9736433 commit 16501af
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 19 deletions.
Binary file modified Config.exe
Binary file not shown.
Binary file modified src/Config.exe
Binary file not shown.
Binary file modified src/DrctHelp.exe
Binary file not shown.
Binary file modified src/Editor.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions src/File tests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
var ep: ExecParams;
ep.SupprIO := true;

var s := new Script('D:\Мои программы\SAC\src\TestSuite\TestExec\AllFuncs\Main.sac',ep);
//var s := new Script('0\0.sac', ep);
//var s := new Script('D:\Мои программы\SAC\src\TestSuite\TestExec\AllFuncs\Main.sac',ep);
var s := new Script('0\2.sac', ep);

//SaveObj('test.bin',s);

Expand Down
Binary file modified src/FuncHelp.exe
Binary file not shown.
Binary file modified src/Help.exe
Binary file not shown.
Binary file modified src/LangPacker.exe
Binary file not shown.
Binary file modified src/OperHelp.exe
Binary file not shown.
Binary file modified src/Packs/KCDPacker.exe
Binary file not shown.
Binary file modified src/Packs/LibPacker.exe
Binary file not shown.
Binary file modified src/SAC.exe
Binary file not shown.
14 changes: 13 additions & 1 deletion src/ScriptExecutor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ ScriptExecutionForm=class(Form)
end
);

{$endregion script}
{$endregion Script}

{$region Lib mode}

if ep.lib_mode then
begin
var sfd := new System.Windows.Forms.SaveFileDialog;
sfd.Filter := Translate('PreCompFileFilter');
if sfd.ShowDialog = System.Windows.Forms.DialogResult.OK then scr.SaveLib(sfd.FileName);
Halt;
end;

{$endregion Lib mode}

{$region Form}

Expand Down
35 changes: 20 additions & 15 deletions src/StmParser.pas
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
unit StmParser;
//ToDo я видел очень странный ExpOptCode в каком то тесте, лучше пересмотреть все

//ToDo оператор Assert
//ToDo не удалять лишние блоки при оптимизации в режиме библиотеки

//ToDo в каждом операторе надо хранить имя начального файла
// - иначе оптимизация меняет блок а с ним и файл, и ReadOnly переменные могут перестать работать
Expand Down Expand Up @@ -1065,27 +1063,29 @@ CannotExecInLibModeException = class(WrongSettingsException)
loop br.ReadInt32 do
begin
var vname := br.ReadString;
var val: object;
case br.ReadByte of
1: self.SngDefConsts.Add(vname, nil);
2: self.SngDefConsts.Add(vname, br.ReadString);
3: self.SngDefConsts.Add(vname, br.ReadDouble);
1: val := nil;
2: val := br.ReadString;
3: val := br.ReadDouble;
end;
AddSngDef(vname, val is real, val, VarAccessT.init_only, nil);
end;

loop br.ReadInt32 do
begin
var vname := br.ReadString;
var is_readonly := br.ReadBoolean;
var fname := CombinePaths(load_path, br.ReadString);
self.SngDefStrs.Add(vname, (is_readonly, fname));
AddSngDef(vname,false,nil,is_readonly?VarAccessT.read_only:VarAccessT.none,fname);
end;

loop br.ReadInt32 do
begin
var vname := br.ReadString;
var is_readonly := br.ReadBoolean;
var fname := CombinePaths(load_path, br.ReadString);
self.SngDefNums.Add(vname, (is_readonly, fname));
AddSngDef(vname,true,nil,is_readonly?VarAccessT.read_only:VarAccessT.none,fname);
end;

var lbls := new StmBlock[br.ReadInt32];
Expand Down Expand Up @@ -4483,8 +4483,12 @@ constructor Script.Create(fname: string; ep: ExecParams);
self.SupprIO := new SuppressedIOData;

var sc_sz := System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size;
AddSngDef('WW', true, real(sc_sz.Width), VarAccessT.init_only, nil);
AddSngDef('WH', true, real(sc_sz.Height), VarAccessT.init_only, nil);

if not settings.lib_mode then
begin
AddSngDef('WW', true, real(sc_sz.Width), VarAccessT.init_only, nil);
AddSngDef('WH', true, real(sc_sz.Height), VarAccessT.init_only, nil);
end;

read_start_lbl_name := System.IO.Path.GetFullPath(fname);

Expand Down Expand Up @@ -4650,9 +4654,9 @@ procedure Script.AddSngDef(vname: string; IsNum: boolean; val: object; Access: V
if Access=VarAccessT.init_only then
begin
if
SngDefConsts.ContainsKey(vname) or
SngDefNums.ContainsKey(vname) or
SngDefStrs.ContainsKey(vname)
SngDefStrs.ContainsKey(vname) or
(SngDefConsts.ContainsKey(vname) and not SngDefConsts[vname].Equals(val))
then raise new CannotOverrideConstException(nil);//ToDo надо отдельное исключение, потому что это не совсем отражает проблему

SngDefConsts[vname] := val;
Expand Down Expand Up @@ -4923,10 +4927,11 @@ procedure Script.Optimize;
end;
end;

if not done.Any(bl->bl.GetAllFRefs.Any(ref->ref is DynamicStmBlockRef)) then
foreach var kvp in bls.ToList do
if not done.Contains(kvp.Value) then
bls.Remove(kvp.Key);
if not settings.lib_mode then
if not done.Any(bl->bl.GetAllFRefs.Any(ref->ref is DynamicStmBlockRef)) then
foreach var kvp in bls.ToList do
if not done.Contains(kvp.Value) then
bls.Remove(kvp.Key);

{$endregion Block chaining}

Expand Down
Binary file modified src/Test.exe
Binary file not shown.
Binary file modified src/WK.exe
Binary file not shown.
Binary file modified src/WMP.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion src/version.dat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(1 shl 16) + (53)
(1 shl 16) + (56)

0 comments on commit 16501af

Please sign in to comment.