Skip to content

Commit

Permalink
fix(s2scompiler): read notes
Browse files Browse the repository at this point in the history
- now follows files paths properly. This is basically a real compiler now of simba to simiba code lol.
- Added the option to ignore libraries
  • Loading branch information
Torwent committed Jul 24, 2024
1 parent c44fd5f commit 2574157
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions tools/s2scompiler.simba
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ input.Replace('.simba', '-compiled.simba')

var
input: String = 'flipper.simba';
path: String = ScriptPath + 'FlipperSRL' + DirectorySeparator + 'Include' + DirectorySeparator;
output: String = ScriptPath + 'FlipperSRL' + DirectorySeparator;
path: String = ScriptPath + 'flipper' + DirectorySeparator;
output: String = ScriptPath + 'flipper' + DirectorySeparator;

const
IGNORE_INCLUDES_FOLDER: Boolean = False;
ERASE_DIRECTIVE: TStringArray = ['WS_LAUNCHER', 'SRL_OSR', 'SRL_UTILS', 'WL_OSR', 'WL_UTILS'];
INCLUDE_DIRECTIVES: TStringArray = ['{$INCLUDE_ONCE ', '{$INCLUDE ', '{$I ', '{$include_once ', '{$include ', '{$i '];

Expand All @@ -47,29 +48,48 @@ const
RGXS: String = '\{\$IFNDEF ';
RGXE: String = '\}([\s\S]*?\{\$ENDIF\})';
var
filepath, directives: String;
filepath, directives, currentPath: String;
i: Int32;
begin
filepath := content.After(INCLUDE_DIRECTIVES[directiveIndex]).Before('}').Trim();

if filepath.StartsWith('WaspLib') or filepath.StartsWith('SRL-T') then
Result := ReadFileContents(Includepath + filepath)
if filepath.StartsWith('WaspLib') or filepath.StartsWith('SRL-T') or filepath.StartsWith('SRL') then
begin
if IGNORE_INCLUDES_FOLDER then
Exit(INCLUDE_DIRECTIVES[directiveIndex].Replace(' ', '_') + filepath + '}');

WriteLn('Compiling file: ' , Includepath + filepath);
Result := ReadFileContents(Includepath + filepath);
end
else if filepath.StartsWith('Scripts/') or filepath.StartsWith('Scripts\') then
begin
WriteLn('Compiling file: ' , AppPath + filepath);
Result := ReadFileContents(AppPath + filepath);

for i := 0 to High(INCLUDE_DIRECTIVES) do
begin
Result := Result.Replace(INCLUDE_DIRECTIVES[i] + ' SRL', '{$TEMP_SRL');
Result := Result.Replace(INCLUDE_DIRECTIVES[i] + ' WaspLib', '{$TEMP_Wasplib');
end;

for i := 0 to High(INCLUDE_DIRECTIVES) do
Result := Result.Replace(INCLUDE_DIRECTIVES[i], INCLUDE_DIRECTIVES[i] + ExtractFileDir(filepath) + DirectorySeparator);

Result := Result.Replace('{$TEMP_SRL', '{$I SRL').Replace('{$TEMP_Wasplib', '{$I WaspLib');
end
else
begin
WriteLn('Compiling file: ' , AppPath + filepath);
Result := ReadFileContents(path + filepath);

ClearDebug();
WriteLn path + filepath;
WriteLn content;
Wait(1);
end;

for directives in ERASE_DIRECTIVE do
Result := ReplaceRegExpr(RGXS + directives + RGXE, Result, '', True);

filepath := ExtractFilepath(path + filepath).Replace(Apppath, "Apppath + '") + "'";
filepath := filepath.Replace(DirectorySeparator, "' + DirectorySeparator + '");
filepath := filepath.Replace(" + ''", '');
filepath := filepath.Replace(DirectorySeparator, "' + DirectorySeparator + '").Replace(" + ''", '');

Result := Result.Replace('{$macro CURRENT_DIRECTORY}', filepath);
Result := Result.Replace('{$MACRO CURRENT_DIRECTORY}', filepath);
Result := Result.Replace('{$macro CURRENT_DIRECTORY}', filepath).Replace('{$MACRO CURRENT_DIRECTORY}', filepath);

Result := LineEnding + Result + LineEnding;
end;
Expand Down Expand Up @@ -118,6 +138,10 @@ begin
for index := 0 to High(REPLACES) do
content := content.Replace(REPLACES[index,0], REPLACES[index,1]);

for index := 0 to High(INCLUDE_DIRECTIVES) do
content := content.Replace(INCLUDE_DIRECTIVES[index].Replace(' ', '_'), INCLUDE_DIRECTIVES[index]);


if path = output then
WriteFileContents(path + input.Replace('.simba', '-compiled.simba'), content, False)
else
Expand Down

0 comments on commit 2574157

Please sign in to comment.