Skip to content

Commit

Permalink
Lape update (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 11, 2024
1 parent 176da91 commit 21ca68c
Show file tree
Hide file tree
Showing 23 changed files with 417 additions and 694 deletions.
37 changes: 6 additions & 31 deletions Source/ide/codetools/simba.ide_codetools_arrayhelpers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ interface
simba.base, simba.ide_codetools_parser;

const
HELPERS_STRING: TStringArray = (
'property <ArrayName>.Length: Integer;',
'property <ArrayName>.First: <ArrayElementType>;',
'property <ArrayName>.Last: <ArrayElementType>;',
'property <ArrayName>.Pop: <ArrayElementType>;',
'procedure <ArrayName>.SetLength(NewLength: Integer);',
'function <ArrayName>.Copy: <ArrayName>;',
'function <ArrayName>.Copy(StartIndex: Integer; Count: Integer = High(Integer)): <ArrayName>;',
'procedure <ArrayName>.Delete(StartIndex: Integer; Count: Integer = High(Integer));',
'function <ArrayName>.Remove(Value: <ArrayElementType>): <ArrayElementType>;',
'function <ArrayName>.RandomValue: <ArrayElementType>;',
'procedure <ArrayName>.Reverse;',
'function <ArrayName>.Reversed: <ArrayName>;',
'procedure <ArrayName>.Clear;'
);

HELPERS_DYNARRAY: TStringArray = (
'property <ArrayName>.Length: Integer;',
'property <ArrayName>.Low: Integer;',
Expand Down Expand Up @@ -57,19 +41,17 @@ interface
'function <ArrayName>.Sorted(CompareFunc: function(constref L, R: <ArrayElementType>): Integer): <ArrayDef>;',
'function <ArrayName>.Sorted(Weights: TIntegerArray; LowToHigh: Boolean): <ArrayDef>;',
'function <ArrayName>.Copy: <ArrayDef>;',
'function <ArrayName>.Copy(StartIndex: Integer; Count: Integer = High(Integer)): <ArrayDef>;',
'function <ArrayName>.RandomValue: <ArrayElementType>;',
'function <ArrayName>.CopyRange(StartIndex, EndIndex: Integer): <ArrayDef>;',
'function <ArrayName>.Random: <ArrayElementType>;',
'function <ArrayName>.Reversed: <ArrayDef>;',
'function <ArrayName>.Slice(Start, Stop, Step: Integer): <ArrayDef>;',
'function <ArrayName>.Remove(Value: <ArrayElementType>): <ArrayElementType>;',
'procedure <ArrayName>.Delete(Index: Integer; Count: Integer = High(Integer));',
'function <ArrayName>.Delete(Value: <ArrayElementType>): <ArrayElementType>;',
'procedure <ArrayName>.DeleteIndex(Index: Integer; Count: Integer);',
'procedure <ArrayName>.DeleteRange(StartIndex, EndIndex: Integer);',
'procedure <ArrayName>.Insert(Item: <ArrayElementType>; Index: Integer);',
'procedure <ArrayName>.SetLength(NewLength: Integer);',
'function <ArrayName>.RandomValue: <ArrayElementType>;',
'procedure <ArrayName>.Reverse;',
'procedure <ArrayName>.Clear;',
'procedure <ArrayName>.Append(Value: <ArrayElementType>);',
'procedure <ArrayName>.Extend(Value: <ArrayDef>);',
'function <ArrayName>.Equals(Other: <ArrayDef>): Boolean;',
'function <ArrayName>.Intersection(Other: <ArrayDef>): <ArrayDef>;',
'function <ArrayName>.Difference(Other: <ArrayDef>): <ArrayDef>;',
Expand Down Expand Up @@ -143,14 +125,7 @@ function GetArrayHelpers(Decl: TDeclaration): TDeclarationArray;
ElementType := Decl.Items.GetTextOfClass(TDeclaration_VarType);
if (ElementType <> '') then
Parser := Get(HELPERS_DYNARRAY, IfThen(Decl.Name <> '', Decl.Name, 'array'), ElementType, IfThen(Decl.Name <> '', Decl.Name, 'array of ' + ElementType));
end
else if (Decl is TDeclaration_TypeAlias) then
case UpperCase(Decl.Name) of
'STRING': Parser := Get(HELPERS_STRING, 'String', 'Char', 'String');
'ANSISTRING': Parser := Get(HELPERS_STRING, 'AnsiString', 'Char', 'AnsiString');
'WIDESTRING': Parser := Get(HELPERS_STRING, 'WideString', 'WideChar', 'WideString');
'UNICODESTRING': Parser := Get(HELPERS_STRING, 'UnicodeString', 'UnicodeChar', 'UnicodeString');
end;
end;

if (Parser <> nil) then
Result := Parser.Items.ToArray
Expand Down
44 changes: 41 additions & 3 deletions Source/ide/codetools/simba.ide_codetools_generics.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ interface
'procedure <HeapName>.Clear; external;' + LineEnding +
'function <HeapName>.ToString: String; external;' + LineEnding;

ARRAYBUFFER_METHODS =
'property <ArrayBufferName>.First: <ValueType>; external;' + LineEnding +
'property <ArrayBufferName>.Last: <ValueType>; external;' + LineEnding +
'property <ArrayBufferName>.Pop: <ValueType>; external;' + LineEnding +
'property <ArrayBufferName>.ToArray: array of <ValueType>; external;' + LineEnding +
'procedure <ArrayBufferName>.Add(Value: <ValueType>); overload; external;' + LineEnding +
'procedure <ArrayBufferName>.Add(Values: array of <ValueType>); overload; external;' + LineEnding +
'procedure <ArrayBufferName>.Clear; external;' + LineEnding +
'function <ArrayBufferName>.ToString: String; external;' + LineEnding;

function GetGeneric(Decl: TDeclaration): TDeclarationArray;

implementation
Expand Down Expand Up @@ -122,6 +132,27 @@ function GetGeneric(Decl: TDeclaration): TDeclarationArray;
GenericParsers.Add(Result);
end;

function RunArrayBuffer(Name, Value: String): TCodeParser;
var
I: Integer;
Methods, FileName: String;
begin
FileName := '!GenericArrayBuffer::' + Name + '::' + Value;
for I := 0 to GenericParsers.Count - 1 do
if (GenericParsers[I].Lexer.FileName = FileName) then
Exit(GenericParsers[I]);

Methods := ARRAYBUFFER_METHODS;
Methods := Methods.Replace('<ArrayBufferName>', Name);
Methods := Methods.Replace('<ValueType>', Value);

Result := TCodeParser.Create();
Result.SetScript(Methods);
Result.Run();

GenericParsers.Add(Result);
end;

var
Parser: TCodeParser;
Params: TDeclarationArray;
Expand All @@ -137,26 +168,33 @@ function GetGeneric(Decl: TDeclaration): TDeclarationArray;
Name := Kind;

case LowerCase(Kind) of
'stringmap':
'tstringmap':
begin
Params := Decl.Items.GetByClass(TDeclaration_Parameter, True, True);
if Length(Params) = 1 then
Parser := RunStrMap(Name, 'String', Params[0].Name);
end;

'map':
'tmap':
begin
Params := Decl.Items.GetByClass(TDeclaration_Parameter, True, True);
if Length(Params) = 2 then
Parser := RunMap(Name, Params[0].Name, Params[1].Name);
end;

'heap':
'theap':
begin
Params := Decl.Items.GetByClass(TDeclaration_Parameter, True, True);
if Length(Params) = 1 then
Parser := RunHeap(Name, Params[0].Name);
end;

'tarraybuffer':
begin
Params := Decl.Items.GetByClass(TDeclaration_Parameter, True, True);
if Length(Params) = 1 then
Parser := RunArrayBuffer(Name, Params[0].Name);
end;
end;
end;

Expand Down
2 changes: 1 addition & 1 deletion Source/ide/codetools/simba.ide_codetools_pasparser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ procedure TPasParser.TypeKind;
S: String;
begin
S := UpperCase(fLexer.Token);
Result := (S = 'STRINGMAP') or (S = 'MAP') or (S = 'HEAP');
Result := (S = 'TSTRINGMAP') or (S = 'TMAP') or (S = 'THEAP') or (S = 'TARRAYBUFFER');
end;

begin
Expand Down
4 changes: 2 additions & 2 deletions Source/ide/simba.form_main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,8 @@ procedure TSimbaMainForm.MenuGotoClick(Sender: TObject);
if SimbaTabsForm.CurrentEditor <> nil then
begin
Value := '';
if InputQuery('Goto line', 'Goto line:', Value) and Value.IsInteger() then
SimbaTabsForm.CurrentEditor.TopLine := StrToInt(Value) - (SimbaTabsForm.CurrentEditor.LinesInWindow div 2);
if InputQuery('Goto line', 'Goto line:', Value) and Value.IsNumeric then
SimbaTabsForm.CurrentEditor.TopLine := Value.ToInteger - (SimbaTabsForm.CurrentEditor.LinesInWindow div 2);
end;
end;

Expand Down
2 changes: 1 addition & 1 deletion Source/ide/simba.ide_package.pas
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ procedure TSimbaPackageEndpoint.ParseTime(Str: String; out Time: TDateTime; out

if (Str <> '') then
begin
if Str.IsInteger() then
if Str.IsNumeric then
Time := Str.ToDateTime('unix', 0)
else
Time := Str.ToDateTime('iso8601', 0);
Expand Down
131 changes: 0 additions & 131 deletions Source/script/imports/simba.import_pointbuffer.pas

This file was deleted.

Loading

0 comments on commit 21ca68c

Please sign in to comment.