Skip to content

Commit

Permalink
Lape update
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 16, 2024
1 parent a29be6f commit 74c2fe5
Show file tree
Hide file tree
Showing 49 changed files with 1,424 additions and 1,269 deletions.
16 changes: 16 additions & 0 deletions DocGen/rundocgen.simba
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var
p: TRunningProcessPiped;
s: String;
begin
p := StartProcessPiped('python.exe', ['-u', 'docgen.py'], 'DocGen');
while p.Running do
begin
s := p.ReadString;
if (s <> '') then
WriteLn(s);
Sleep(100);
end;
p.Free();

WriteLn('Link: "' + PathNormalize('DocGen/build/index.html') + '"');
end;
21 changes: 20 additions & 1 deletion DocGen/source/tutorials/Targets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,23 @@ You can declare as many TTarget variables as you like, all with different target
begin
MyOtherTarget.SetWindow(12345); // some window handle
WriteLn MyOtherTarget.CountColor($0000FF, 10); // Count a red color, with 10 tolerance.
end;
end;
----

Searching on a image
====================

:code:`TImage` has basic :code:`FindColor` and :code:`FindImage` methods however if you need the full finder methods you can do:

.. code-block::
var MyTarget: TTarget;
MyTarget.SetImage(MyImage);
Edges := MyTarget.FindEdges(5);
Or use the :code:`TImage.Target` property which returns a :code:`TTarget` already targeted to the image.

.. code-block::
Edges := MyImage.Target.FindEdges(5);
35 changes: 5 additions & 30 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>.DeleteIndex(Index: Integer; Count: Integer): <ArrayElementType>;',
'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
101 changes: 65 additions & 36 deletions Source/ide/codetools/simba.ide_codetools_generics.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ interface
'procedure <HeapName>.Clear; external;' + LineEnding +
'function <HeapName>.ToString: String; external;' + LineEnding;

ARRAYBUFFER_METHODS =
'property <ArrayBufferName>.Count: Integer; external;' + LineEnding +
'property <ArrayBufferName>.Items: array of <ValueType>; external;' + LineEnding +
'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 All @@ -57,7 +69,7 @@ implementation

function GetGeneric(Decl: TDeclaration): TDeclarationArray;

function RunStrMap(Name, Key, Value: String): TCodeParser;
function RunStrMap(Name, Value: String): TCodeParser;
var
I: Integer;
Methods, FileName: String;
Expand All @@ -68,12 +80,12 @@ function GetGeneric(Decl: TDeclaration): TDeclarationArray;
Exit(GenericParsers[I]);

Methods := STRINGMAP_METHODS;
Methods := Methods.Replace('<MapName>', Name);
Methods := Methods.Replace('<KeyType>', Key);
Methods := Methods.Replace('<MapName>', IfThen(Name <> '', Name, 'TStringMap'));
Methods := Methods.Replace('<KeyType>', 'String');
Methods := Methods.Replace('<ValueType>', Value);

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

GenericParsers.Add(Result);
Expand All @@ -90,12 +102,12 @@ function GetGeneric(Decl: TDeclaration): TDeclarationArray;
Exit(GenericParsers[I]);

Methods := MAP_METHODS;
Methods := Methods.Replace('<MapName>', Name);
Methods := Methods.Replace('<MapName>', IfThen(Name <> '', Name, 'TMap'));
Methods := Methods.Replace('<KeyType>', Key);
Methods := Methods.Replace('<ValueType>', Value);

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

GenericParsers.Add(Result);
Expand All @@ -112,51 +124,68 @@ function GetGeneric(Decl: TDeclaration): TDeclarationArray;
Exit(GenericParsers[I]);

Methods := HEAP_METHODS;
Methods := Methods.Replace('<HeapName>', Name);
Methods := Methods.Replace('<HeapName>', IfThen(Name <> '', Name, 'THeap'));
Methods := Methods.Replace('<ValueType>', Value);

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

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>', IfThen(Name <> '', Name, 'TArrayBuffer'));
Methods := Methods.Replace('<ValueType>', Value);

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

GenericParsers.Add(Result);
end;

var
Parser: TCodeParser;
Typ: TDeclaration;
Params: TDeclarationArray;
Name, Kind: String;
begin
Parser := nil;

if (Decl is TDeclaration_TypeFakeGeneric) then
if (Decl is TDeclaration_TypeGeneric) then
begin
Kind := Decl.Items.GetTextOfClass(TDeclaration_Identifier);
Name := Decl.Name;
if (Name = '') then
Name := Kind;

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

'map':
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':
begin
Params := Decl.Items.GetByClass(TDeclaration_Parameter, True, True);
if Length(Params) = 1 then
Parser := RunHeap(Name, Params[0].Name);
end;
Typ := TDeclaration_TypeGeneric(Decl).Typ;
Params := TDeclaration_TypeGeneric(Decl).Params;

if (Typ <> nil) and (Length(Params) > 0) then
begin
case UpperCase(Typ.Text) of
'TSTRINGMAP':
if (Length(Params) = 1) then
Parser := RunStrMap(Decl.Name, Params[0].Text);

'TMAP':
if (Length(Params) = 2) then
Parser := RunMap(Decl.Name, Params[0].Text, Params[1].Text);

'THEAP':
if (Length(Params) = 1) then
Parser := RunHeap(Decl.Name, Params[0].Text);

'TARRAYBUFFER':
if (Length(Params) = 1) then
Parser := RunArrayBuffer(Decl.Name, Params[0].Text);
end;
end;
end;

Expand Down
59 changes: 48 additions & 11 deletions Source/ide/codetools/simba.ide_codetools_parser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ TDeclaration_Type = class(TDeclaration)
function GetHeader: String; override;
end;

TDeclaration_GenericSpecialize = class(TDeclaration);
TDeclaration_GenericParam = class(TDeclaration);
TDeclaration_TypeGeneric = class(TDeclaration_Type)
protected
function GetTyp: TDeclaration;
function GetParams: TDeclarationArray;
public
property Typ: TDeclaration read GetTyp;
property Params: TDeclarationArray read GetParams;
end;

TDeclaration_TypeRecord = class(TDeclaration_Type)
protected
FFields: TDeclarationCache;
Expand Down Expand Up @@ -247,7 +258,6 @@ TDeclaration_TypeMethod = class(TDeclaration_Type)
property Method: TDeclaration_Method read GetMethod;
end;

TDeclaration_TypeFakeGeneric = class(TDeclaration_Type);
TDeclaration_TypeNativeMethod = class(TDeclaration_Type);

TDeclaration_TypeRange = class(TDeclaration_Type);
Expand Down Expand Up @@ -473,6 +483,11 @@ TCodeParser = class(TPasParser)
procedure TypeDeclaration; override;
procedure TypeName; override;

// types - generics
procedure GenericType; override;
procedure GenericSpecialize; override;
procedure GenericParam; override;

// types - alias
procedure TypeAlias; override;

Expand All @@ -492,8 +507,6 @@ TCodeParser = class(TPasParser)
// types - native
procedure NativeType; override;

procedure FakeGenericType; override;

// types = record
procedure UnionType; override;
procedure RecordType; override;
Expand Down Expand Up @@ -1010,6 +1023,16 @@ function TDeclaration_Type.GetHeader: String;
Result := FHeader;
end;

function TDeclaration_TypeGeneric.GetTyp: TDeclaration;
begin
Result := FItems.GetByClassFirst(TDeclaration_GenericSpecialize);
end;

function TDeclaration_TypeGeneric.GetParams: TDeclarationArray;
begin
Result := FItems.GetByClass(TDeclaration_GenericParam);
end;

function TDeclaration_EnumElement.GetName: string;
begin
if FName.IsNull then
Expand Down Expand Up @@ -1713,6 +1736,27 @@ procedure TCodeParser.TypeName;
inherited;
end;

procedure TCodeParser.GenericType;
begin
PushStack(TDeclaration_TypeGeneric);
inherited;
PopStack();
end;

procedure TCodeParser.GenericSpecialize;
begin
PushStack(TDeclaration_GenericSpecialize);
inherited;
PopStack();
end;

procedure TCodeParser.GenericParam;
begin
PushStack(TDeclaration_GenericParam);
inherited;
PopStack();
end;

procedure TCodeParser.TypeCopy;
begin
PushStack(TDeclaration_TypeCopy);
Expand All @@ -1726,7 +1770,7 @@ procedure TCodeParser.PointerType;
begin
PushStack(TDeclaration_TypePointer);
PushStack(TDeclaration_VarType);
inherited PointerType();
inherited;
PopStack();
PopStack();
end;
Expand Down Expand Up @@ -1897,13 +1941,6 @@ procedure TCodeParser.NativeType;
PopStack();
end;

procedure TCodeParser.FakeGenericType;
begin
PushStack(TDeclaration_TypeFakeGeneric);
inherited;
PopStack();
end;

procedure TCodeParser.RecordType;
begin
PushStack(TDeclaration_TypeRecord);
Expand Down
Loading

0 comments on commit 74c2fe5

Please sign in to comment.