Skip to content

Commit

Permalink
heap
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Aug 29, 2024
1 parent 2425c9f commit e3b4161
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 41 deletions.
10 changes: 7 additions & 3 deletions Source/ide/codetools/simba.ide_codetools_generics.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ interface
'property <MapName>.CaseSens(Value: Boolean); external;' + LineEnding;

HEAP_METHODS =
'procedure <HeapName>.Push(Value: <ValueType>; Index: SizeInt; LoHi: Boolean); external;' + LineEnding +
'procedure <HeapName>.Pop(LoHi: Boolean); external;' + LineEnding +
'function <HeapName>.Peek(LoHi: Boolean): record Value: <ValueType>; Index: SizeInt; end; external;';
'procedure <HeapName>.Push(Value: <ValueType>; Index: Integer); external;' + LineEnding +
'property <HeapName>.Pop: record Value: <ValueType>; Index: Integer; end; external;' + LineEnding +
'property <HeapName>.Peek: record Value: <ValueType>; Index: Integer; end; external;' + LineEnding +
'property <HeapName>.Items: array of record Value: <ValueType>; Index: Integer; end; external;' + LineEnding +
'property <HeapName>.Count: Integer; external;' + LineEnding +
'procedure <HeapName>.Clear; external;' + LineEnding +
'function <HeapName>.ToString: String; external;' + LineEnding;

function GetGeneric(Decl: TDeclaration): TDeclarationArray;

Expand Down
23 changes: 13 additions & 10 deletions Source/ide/codetools/simba.ide_codetools_parser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ TDeclaration = class({$IFDEF PARSER_LEAK_CHECKS}TLeakChecker{$ELSE}TObject{$EN
public
procedure Add(const Decl: TDeclaration); overload;
procedure Add(const Decls: TDeclarationArray); overload;
procedure Remove(const Decl: TDeclaration);

function GetByName(Name: String): TDeclarationArray;
function GetByClassAndName(Name: String; DeclClass: TDeclarationClass; ExactClass: Boolean = False): TDeclarationArray;
Expand Down Expand Up @@ -456,7 +457,6 @@ TCodeParser = class(TPasParser)
procedure MethodDirective; override;
procedure Method; override;
procedure MethodOfType; override;
procedure MethodBlock; override;
procedure MethodName; override;
procedure MethodTypeName; override;
procedure MethodResultType; override;
Expand Down Expand Up @@ -911,6 +911,18 @@ procedure TDeclarationArrayHelper.Add(const Decls: TDeclarationArray);
Self += Decls;
end;

procedure TDeclarationArrayHelper.Remove(const Decl: TDeclaration);
var
I: Integer;
begin
for I := 0 to High(Self) do
if (Self[I] = Decl) then
begin
Delete(Self, I, 1);
Exit;
end;
end;

function TDeclarationArrayHelper.GetByName(Name: String): TDeclarationArray;
var
I, Count: Integer;
Expand Down Expand Up @@ -1804,15 +1816,6 @@ procedure TCodeParser.ConstantName;
VarName();
end;

procedure TCodeParser.MethodBlock;
begin
//if (FStack.Top is TDeclaration_Method) then
// if (fLastNoJunkTok <> tokSemiColon) then
// TDeclaration_Method(FStack.Top).isNotFullyDeclared := True;

inherited;
end;

procedure TCodeParser.Method;
var
Decl: TDeclaration_Method;
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');
Result := (S = 'STRINGMAP') or (S = 'MAP') or (S = 'HEAP');
end;

begin
Expand Down
33 changes: 7 additions & 26 deletions Source/ide/simba.ide_editor_paramhint.pas
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,6 @@ procedure TSimbaParamHint.DoEditorCommand(Sender: TObject; AfterProcessing: Bool
end;
end;

function FilterProperties(Decls: TDeclarationArray; IsIndexing: Boolean): TDeclarationArray;
var
I: Integer;
begin
if IsIndexing then
Result := RemoveDuplicateProperties(Decls)
else
begin
// for `obj.Prop(` to be valid syntax it must return a method
Result := [];
for I := 0 to High(Decls) do
if FCodeinsight.ResolveVarType(TDeclaration_Property(Decls[I]).ResultType) is TDeclaration_TypeMethod then
Result.Add(Decls[I]);
Result := RemoveDuplicateProperties(Result);
end;
end;

var
Decl: TDeclaration;
Members, Decls: TDeclarationArray;
Expand Down Expand Up @@ -491,14 +474,13 @@ procedure TSimbaParamHint.DoEditorCommand(Sender: TObject; AfterProcessing: Bool

if (Decl <> nil) then
begin
// properties
// property indexing
if IsIndexing then
begin
if (Decl is TDeclaration_Property) then
begin
Decls := Members.GetByClassAndName(Decl.Name, TDeclaration_Property);
Decls := FilterProperties(Decls, IsIndexing);
Decls := IndexableProperties(Decls);
Decls := RemoveDuplicateProperties(Decls);
end;
end else
begin
Expand All @@ -509,12 +491,6 @@ procedure TSimbaParamHint.DoEditorCommand(Sender: TObject; AfterProcessing: Bool
if (Decl is TDeclaration_TypeMethod) then
Decls := [TDeclaration_TypeMethod(Decl).Method];
end else
// properties
if (Decl is TDeclaration_Property) then
begin
Decls := Members.GetByClassAndName(Decl.Name, TDeclaration_Property);
//Decls := FilterProperties(Decls, IsIndexing);
end else
// method of type
if (Decl is TDeclaration_MethodOfType) then
begin
Expand All @@ -529,6 +505,11 @@ procedure TSimbaParamHint.DoEditorCommand(Sender: TObject; AfterProcessing: Bool

// remove overrides
Decls := RemoveOverridenMethods(Decls);

// if declarating a new method such as "procedure foo(hello," remove it.
Decl := FCodeinsight.ScriptParser.Items.GetByPosition(FCodeinsight.ScriptParser.CaretPos);
if (Decl is TDeclaration_ParamList) and (Decl.Parent is TDeclaration_Method) then
Decls.Remove(Decl.Parent);
end;

if (Length(Decls) > 0) then
Expand Down
4 changes: 4 additions & 0 deletions Source/script/simba.compiler_dump.pas
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ procedure TSimbaCompilerDump.InitBaseDefinitions;
Add('Base', 'function GetScriptMethodName(Address: Pointer): String; external;');
Add('Base', 'function DumpCallStack(Start: Integer = 0): String; external;');

Add('Base', 'function Map(KeyType: T; ValueType: V): Map; external;');
Add('Base', 'function StringMap(ValueType: V): StringMap; external;');
Add('Base', 'function Heap(ValueType: V): Heap; external;');

ImportingSection := '';
end;

Expand Down
4 changes: 3 additions & 1 deletion Source/script/simba.script_compiler.pas
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ implementation
simba.script_compiler_rtti,
simba.script_compiler_imagefromstring,
simba.script_genericmap,
simba.script_genericstringmap;
simba.script_genericstringmap,
simba.script_genericheap;

procedure TSimbaScript_Compiler.addProperty(Obj, Name, Typ: String; ReadFunc: Pointer; WriteFunc: Pointer);
begin
Expand Down Expand Up @@ -148,6 +149,7 @@ procedure TSimbaScript_Compiler.Import;
InitializeRTTI(Self);
InitializeMap(Self);
InitializeStringMap(Self);
InitializeHeap(Self);

AddSimbaImports(Self);
finally
Expand Down
3 changes: 3 additions & 0 deletions Source/script/simba.script_genericbase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
--------------------------------------------------------------------------
Base class for generating generic methods.
}
unit simba.script_genericbase;

Expand Down
Loading

0 comments on commit e3b4161

Please sign in to comment.