API Remake
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "FasmOnDelphi"]
|
||||
path = FasmOnDelphi
|
||||
url = git@git.teamfnd.ru:artem3213212/FasmOnDelphi.git
|
||||
[submodule "lib/pLua-XE"]
|
||||
path = lib/pLua-XE
|
||||
url = https://github.com/felipedaragon/pLua-XE.git
|
||||
|
||||
Submodule FasmOnDelphi deleted from 62a5d170ba
@@ -2,6 +2,8 @@ unit RuntimeBuilder.Fasm;
|
||||
|
||||
interface
|
||||
|
||||
//{$INLINE auto}
|
||||
|
||||
uses
|
||||
System.Classes,System.TypInfo,System.IOUtils,System.Rtti,Winapi.Windows,
|
||||
RuntimeBuilder,FasmOnDelphi;
|
||||
@@ -35,23 +37,23 @@ type
|
||||
constructor Create(Name:string);
|
||||
destructor Destroy;override;
|
||||
end;
|
||||
protected
|
||||
libs:TStringList;
|
||||
function GetIncLibs():string;
|
||||
protected
|
||||
FText:string;
|
||||
function GetText:string;override;
|
||||
procedure SetText(S:string);override;
|
||||
public
|
||||
function LoadLib(Name:string):TRTBLib;override;
|
||||
constructor Create(Compiler:TRTBFasmCompiler);
|
||||
function CompilateAsFunc:TRTBFunc;override;
|
||||
function CompilateAsLib:TRTBLib;override;
|
||||
end;
|
||||
protected
|
||||
function GetIncLibs():string;
|
||||
public
|
||||
CompilerMem:NativeUInt;
|
||||
MaxSteps:word;
|
||||
libs:TStringList;
|
||||
constructor Create(FasmPath:String=FasmPath;AsDll:boolean=false);
|
||||
function LoadLib(Name:string):TRTBLib;
|
||||
function GenNewSrc():TRTBSource;override;
|
||||
end;
|
||||
|
||||
@@ -68,9 +70,6 @@ FreeMem(p);
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.TRTBFasmSource.TRTBFasmFunc.Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;
|
||||
{$IFDEF CPUX64}
|
||||
//function()
|
||||
{$ENDIF}
|
||||
begin
|
||||
{$IFDEF CPUX64}
|
||||
Result:=Invoke(p,args,ccReg,OutType);
|
||||
@@ -127,10 +126,25 @@ begin
|
||||
FText:=S;
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.TRTBFasmSource.GetIncLibs():string;
|
||||
var
|
||||
i:integer;
|
||||
begin
|
||||
Result:='';
|
||||
for i:=0 to libs.count-1 do
|
||||
Result:=Result+sLineBreak+'include '+#39+libs.Strings[i]+#39;
|
||||
end;
|
||||
|
||||
constructor TRTBFasmCompiler.TRTBFasmSource.Create(Compiler:TRTBFasmCompiler);
|
||||
begin
|
||||
inherited Create(Compiler);
|
||||
FText:='';
|
||||
libs:=TStringList.Create;
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.TRTBFasmSource.LoadLib(Name:string):TRTBLib;
|
||||
begin
|
||||
libs.Add(Name);
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.TRTBFasmSource.CompilateAsFunc:TRTBFunc;
|
||||
@@ -162,21 +176,6 @@ begin
|
||||
CompilerMem:=1024*1024*16;
|
||||
MaxSteps:=65535;
|
||||
OpenFASM(FasmPath,AsDll);
|
||||
libs:=TStringList.Create;
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.LoadLib(Name:string):TRTBLib;
|
||||
begin
|
||||
libs.Add(Name);
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.GetIncLibs():string;
|
||||
var
|
||||
i:integer;
|
||||
begin
|
||||
Result:='';
|
||||
for i:=0 to libs.count-1 do
|
||||
Result:=Result+sLineBreak+'include '+#39+libs.Strings[i]+#39;
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.GenNewSrc():TRTBSource;
|
||||
|
||||
166
Source/RuntimeBuilder.Lua.pas
Normal file
166
Source/RuntimeBuilder.Lua.pas
Normal file
@@ -0,0 +1,166 @@
|
||||
unit RuntimeBuilder.Lua;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
System.Classes,System.TypInfo,System.IOUtils,System.Rtti,Winapi.Windows,
|
||||
pLuaObject,pLuaRecord,pLuaTable,uWordList,Lua,LuaObject,LuaWrapper,pLua,RuntimeBuilder;
|
||||
|
||||
type
|
||||
TRTBLuaCompiler=class(TRTBCompiler)
|
||||
protected type
|
||||
TRTBLuaSource=class(TRTBSource)
|
||||
protected type
|
||||
{TRTBLuaFunc=class(TRTBFunc)
|
||||
protected
|
||||
p:Pointer;
|
||||
sb:NativeUInt;
|
||||
public
|
||||
constructor Create(p:Pointer;sb:NativeUInt);
|
||||
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;override;
|
||||
destructor Destroy;override;
|
||||
end;
|
||||
TRTBLuaLib=class(TRTBLib)
|
||||
private type
|
||||
TRTBLuaLibFunc=class(TRTBLuaFunc)
|
||||
public
|
||||
constructor Create(p:Pointer);
|
||||
destructor Destroy;override;
|
||||
end;
|
||||
private
|
||||
filename:string;
|
||||
Lib:NativeUInt;
|
||||
function GetFuntion(Name:string):TRTBFunc;override;
|
||||
public
|
||||
constructor Create(Name:string);
|
||||
destructor Destroy;override;
|
||||
end;}
|
||||
protected
|
||||
FText:string;
|
||||
function GetText:string;override;
|
||||
procedure SetText(S:string);override;
|
||||
public
|
||||
constructor Create(Compiler:TRTBLuaCompiler);
|
||||
function CompilateAsFunc:TRTBFunc;override;
|
||||
//function CompilateAsLib:TRTBLib;override;
|
||||
end;
|
||||
protected
|
||||
Lua:Plua_state;
|
||||
//function GetIncLibs():string;
|
||||
public
|
||||
libs:TStringList;
|
||||
constructor Create();
|
||||
//function LoadLib(Name:string):TRTBLib;
|
||||
function GenNewSrc():TRTBSource;override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses System.SysUtils;
|
||||
|
||||
{constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaFunc.Create(p:Pointer;sb:NativeUInt);
|
||||
begin
|
||||
Self.p:=VirtualAlloc(nil,sb,MEM_COMMIT ,PAGE_EXECUTE_READWRITE);
|
||||
CopyMemory(Self.p,p,sb);
|
||||
Self.sb:=sb;
|
||||
FreeMem(p);
|
||||
end;
|
||||
|
||||
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaFunc.Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;
|
||||
begin
|
||||
end;
|
||||
|
||||
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaFunc.Destroy;
|
||||
begin
|
||||
VirtualFree(p,sb,MEM_RELEASE);
|
||||
p:=nil;
|
||||
end;
|
||||
|
||||
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.TRTBLuaLibFunc.Create(p:Pointer);
|
||||
begin
|
||||
Self.p:=p;
|
||||
end;
|
||||
|
||||
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.TRTBLuaLibFunc.Destroy;
|
||||
begin
|
||||
p:=nil;
|
||||
end;
|
||||
|
||||
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.GetFuntion(Name:string):TRTBFunc;
|
||||
begin
|
||||
Result:=TRTBLuaLibFunc.Create(GetProcAddress(Lib,pwidechar(Name)));
|
||||
end;
|
||||
|
||||
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.Create(Name:string);
|
||||
begin
|
||||
filename:=Name;
|
||||
Lib:=LoadLibrary(pwidechar(Name));
|
||||
end;
|
||||
|
||||
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.Destroy;
|
||||
begin
|
||||
FreeLibrary(Lib);
|
||||
end;}
|
||||
|
||||
function TRTBLuaCompiler.TRTBLuaSource.GetText:string;
|
||||
begin
|
||||
Result:=FText;
|
||||
end;
|
||||
|
||||
procedure TRTBLuaCompiler.TRTBLuaSource.SetText(S:string);
|
||||
begin
|
||||
FText:=S;
|
||||
end;
|
||||
|
||||
constructor TRTBLuaCompiler.TRTBLuaSource.Create(Compiler:TRTBLuaCompiler);
|
||||
begin
|
||||
inherited Create(Compiler);
|
||||
FText:='';
|
||||
end;
|
||||
|
||||
function TRTBLuaCompiler.TRTBLuaSource.CompilateAsFunc:TRTBFunc;
|
||||
begin
|
||||
//lua_(lua_tocfunction());
|
||||
//(Compiler as TRTBLuaCompiler).Lua.RegisterFunction();
|
||||
end;
|
||||
|
||||
(*function TRTBLuaCompiler.TRTBLuaSource.CompilateAsLib:TRTBLib;
|
||||
var
|
||||
templib:string;
|
||||
Res:TLuaResult;
|
||||
begin
|
||||
templib:=TPath.GetTempFileName;
|
||||
Res:=LuaAssembleToFile({$IFDEF CPUX64}'format PE64 DLL'{$ELSE}'format PE DLL'{$ENDIF}+
|
||||
(Compiler as TRTBLuaCompiler).GetIncLibs+sLineBreak+Text,templib,
|
||||
(Compiler as TRTBLuaCompiler).CompilerMem,(Compiler as TRTBLuaCompiler).MaxSteps);
|
||||
if Res.Error<>Lua_OK then
|
||||
raise Exception.Create(Res.OutStr);
|
||||
Result:=TRTBLuaLib.Create(templib);
|
||||
end;*)
|
||||
|
||||
{function TRTBLuaCompiler.GetIncLibs():string;
|
||||
var
|
||||
i:integer;
|
||||
begin
|
||||
Result:='';
|
||||
for i:=0 to libs.count-1 do
|
||||
Result:=Result+sLineBreak+'include '+#39+libs.Strings[i]+#39;
|
||||
end;}
|
||||
|
||||
constructor TRTBLuaCompiler.Create();
|
||||
begin
|
||||
Lua:=luaL_newstate;
|
||||
libs:=TStringList.Create;
|
||||
end;
|
||||
|
||||
{function TRTBLuaCompiler.LoadLib(Name:string):TRTBLib;
|
||||
begin
|
||||
libs.Add(Name);
|
||||
end;}
|
||||
|
||||
function TRTBLuaCompiler.GenNewSrc():TRTBSource;
|
||||
begin
|
||||
Result:=TRTBLuaSource.Create(Self);
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -2,26 +2,38 @@ unit RuntimeBuilder;
|
||||
|
||||
interface
|
||||
|
||||
uses System.TypInfo,System.Rtti;
|
||||
uses
|
||||
System.TypInfo,System.Rtti;
|
||||
|
||||
const
|
||||
CRTBCallTypeNil=$0;
|
||||
CRTBCallTypeRegister=$1;
|
||||
CRTBCallTypeStdCall=$2;
|
||||
CRTBCallTypeCdecl=$3;
|
||||
CRTBCallTypePascal=$4;
|
||||
CRTBCallTypeSafeCall=$5;
|
||||
CRTBCallType64Call=$40;
|
||||
CRTBCallTypeDefault=$80;
|
||||
CRTBCallTypeNil=ccReg;
|
||||
CRTBCallTypeRegister=ccReg;
|
||||
CRTBCallTypeStdCall=ccStdCall;
|
||||
CRTBCallTypeCdecl=ccCdecl;
|
||||
CRTBCallTypePascal=ccPascal;
|
||||
CRTBCallTypeSafeCall=ccSafeCall;
|
||||
CRTBCallType64Call=CRTBCallTypeNil;
|
||||
CRTBCallTypeScript=CRTBCallTypeNil;
|
||||
CRTBCallTypeDefault=CRTBCallTypeNil;
|
||||
|
||||
type
|
||||
TRTBCompiler=class;
|
||||
|
||||
TRTBCallType=CRTBCallTypeNil..CRTBCallTypeDefault;
|
||||
TRTBCallType=TCallConv;
|
||||
|
||||
TRTBType=PTypeInfo;
|
||||
|
||||
TRTBFunc=class abstract
|
||||
public
|
||||
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;virtual;abstract;
|
||||
function Call(Name:string;OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;virtual;abstract;
|
||||
end;
|
||||
|
||||
TRTBVar=class abstract
|
||||
protected
|
||||
function SetVal(TValue);virtual;abstract;
|
||||
function GetVal:TValue;virtual;abstract;
|
||||
public
|
||||
property Val:TValue read GetVal write SetVal;
|
||||
end;
|
||||
|
||||
TRTBLib=class abstract
|
||||
@@ -29,6 +41,7 @@ type
|
||||
function GetFuntion(Name:string):TRTBFunc;virtual;abstract;
|
||||
public
|
||||
property Funtion[Name:string]:TRTBFunc read GetFuntion;
|
||||
property &Var[Name:string]:TRTBVar read GetFuntion;
|
||||
end;
|
||||
|
||||
TRTBSource=class abstract
|
||||
@@ -38,8 +51,29 @@ type
|
||||
procedure SetText(S:string);virtual;abstract;
|
||||
public
|
||||
constructor Create(Compiler:TRTBCompiler);
|
||||
function CompilateAsFunc:TRTBFunc;virtual;abstract;
|
||||
function CompilateAsLib:TRTBLib;virtual;abstract;
|
||||
|
||||
procedure LoadLib(Name:string);virtual;abstract;
|
||||
procedure UnLoadLib(Name:string);virtual;abstract;
|
||||
|
||||
procedure AddNameSpace(Name:string);virtual;abstract;
|
||||
procedure DelNameSpace(Name:string);virtual;abstract;
|
||||
|
||||
procedure AddType(NameSpace:string;Name:string;&Type:TRTBType);virtual;abstract;
|
||||
procedure ExportType(NameSpace:string;Name:string;&Type:TRTBType);virtual;abstract;
|
||||
procedure DelType(NameSpace:string;Name:string);virtual;abstract;
|
||||
|
||||
procedure AddConst(NameSpace:string;Name:string;Val:TValue);virtual;abstract;
|
||||
procedure ExportConst(NameSpace:string;Name:string;Val:TValue);virtual;abstract;
|
||||
procedure DelConst(NameSpace:string;Name:string);virtual;abstract;
|
||||
|
||||
procedure AddVariable(NameSpace:string;Name:string;var Data);virtual;abstract;
|
||||
procedure ExportVariable(NameSpace:string;Name:string;var Data);virtual;abstract;
|
||||
procedure DelVariable(NameSpace:string;Name:string);virtual;abstract;
|
||||
|
||||
procedure &Register(NameSpace:string;Name:string;&Type:TRTBType);virtual;abstract;
|
||||
procedure &RegisterFunction(NameSpace:string;Name:string);virtual;abstract;
|
||||
|
||||
function Compilate:TRTBLib;virtual;abstract;
|
||||
procedure LoadFromFile(&File:string);
|
||||
procedure SaveToFile(&File:string);
|
||||
property Text:string read GetText write SetText;
|
||||
@@ -47,7 +81,6 @@ type
|
||||
|
||||
TRTBCompiler=class abstract
|
||||
public
|
||||
function LoadLib(Name:string):TRTBLib;virtual;abstract;
|
||||
function GenNewSrc():TRTBSource;virtual;abstract;
|
||||
end;
|
||||
|
||||
|
||||
@@ -14,8 +14,17 @@ uses
|
||||
Unit1 in 'Unit1.pas',
|
||||
RuntimeBuilder in '..\Source\RuntimeBuilder.pas',
|
||||
RuntimeBuilder.Fasm in '..\Source\RuntimeBuilder.Fasm.pas',
|
||||
FasmOnDelphi in '..\FasmOnDelphi\Source\FasmOnDelphi.pas',
|
||||
Fasm4Delphi in '..\FasmOnDelphi\Fasm4Delphi\Source\Fasm4Delphi.pas';
|
||||
FasmOnDelphi in '..\lib\FasmOnDelphi\Source\FasmOnDelphi.pas',
|
||||
Fasm4Delphi in '..\lib\FasmOnDelphi\Fasm4Delphi\Source\Fasm4Delphi.pas'{,
|
||||
RuntimeBuilder.Lua in '..\Source\RuntimeBuilder.Lua.pas',
|
||||
pLuaObject in '..\lib\pLua-XE\src\pLuaObject.pas',
|
||||
pLuaRecord in '..\lib\pLua-XE\src\pLuaRecord.pas',
|
||||
pLuaTable in '..\lib\pLua-XE\src\pLuaTable.pas',
|
||||
uWordList in '..\lib\pLua-XE\src\uWordList.pas',
|
||||
Lua in '..\lib\pLua-XE\src\Lua.pas',
|
||||
LuaObject in '..\lib\pLua-XE\src\LuaObject.pas',
|
||||
LuaWrapper in '..\lib\pLua-XE\src\LuaWrapper.pas',
|
||||
pLua in '..\lib\pLua-XE\src\pLua.pas'{};
|
||||
|
||||
var
|
||||
runner : ITestRunner;
|
||||
|
||||
@@ -98,8 +98,19 @@
|
||||
<DCCReference Include="Unit1.pas"/>
|
||||
<DCCReference Include="..\Source\RuntimeBuilder.pas"/>
|
||||
<DCCReference Include="..\Source\RuntimeBuilder.Fasm.pas"/>
|
||||
<DCCReference Include="..\FasmOnDelphi\Source\FasmOnDelphi.pas"/>
|
||||
<DCCReference Include="..\FasmOnDelphi\Fasm4Delphi\Source\Fasm4Delphi.pas"/>
|
||||
<DCCReference Include="..\lib\FasmOnDelphi\Source\FasmOnDelphi.pas"/>
|
||||
<DCCReference Include="..\lib\FasmOnDelphi\Fasm4Delphi\Source\Fasm4Delphi.pas">
|
||||
<Form>,
|
||||
RuntimeBuilder.Lua in '..\Source\RuntimeBuilder.Lua.pas',
|
||||
pLuaObject in '..\lib\pLua-XE\src\pLuaObject.pas',
|
||||
pLuaRecord in '..\lib\pLua-XE\src\pLuaRecord.pas',
|
||||
pLuaTable in '..\lib\pLua-XE\src\pLuaTable.pas',
|
||||
uWordList in '..\lib\pLua-XE\src\uWordList.pas',
|
||||
Lua in '..\lib\pLua-XE\src\Lua.pas',
|
||||
LuaObject in '..\lib\pLua-XE\src\LuaObject.pas',
|
||||
LuaWrapper in '..\lib\pLua-XE\src\LuaWrapper.pas',
|
||||
pLua in '..\lib\pLua-XE\src\pLua.pas'{</Form>
|
||||
</DCCReference>
|
||||
<BuildConfiguration Include="Release">
|
||||
<Key>Cfg_2</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
@@ -456,13 +467,13 @@
|
||||
<Operation>1</Operation>
|
||||
</Platform>
|
||||
</DeployClass>
|
||||
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME)"/>
|
||||
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
|
||||
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
|
||||
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
|
||||
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
|
||||
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
|
||||
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME)"/>
|
||||
<ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
|
||||
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
|
||||
</Deployment>
|
||||
<Platforms>
|
||||
<Platform value="OSX32">False</Platform>
|
||||
|
||||
@@ -23,7 +23,7 @@ var
|
||||
Src:TRTBSource;
|
||||
Func1:TRTBFunc;
|
||||
begin
|
||||
Fasm:=TRTBFasmCompiler.Create('..\..\..\FasmOnDelphi\fasmw172\fasm');
|
||||
{Fasm:=TRTBFasmCompiler.Create('..\..\..\FasmOnDelphi\fasmw172\fasm');
|
||||
Src:=Fasm.GenNewSrc;
|
||||
Src.Text:='use32'+sLineBreak+'pop ecx'+sLineBreak+'pop eax'+sLineBreak+'jmp ecx';
|
||||
Func1:=src.CompilateAsFunc;
|
||||
@@ -33,7 +33,7 @@ begin
|
||||
end;
|
||||
FreeAndNil(Func1);
|
||||
FreeAndNil(Src);
|
||||
FreeAndNil(Fasm);
|
||||
FreeAndNil(Fasm);}
|
||||
end;
|
||||
|
||||
procedure TRuntimeBuilderTestObject.Test2();
|
||||
@@ -43,7 +43,7 @@ var
|
||||
lib:TRTBLib;
|
||||
Func1:TRTBFunc;
|
||||
begin
|
||||
Fasm:=TRTBFasmCompiler.Create('..\..\..\FasmOnDelphi\fasmw172\fasm');
|
||||
{Fasm:=TRTBFasmCompiler.Create('..\..\..\FasmOnDelphi\fasmw172\fasm');
|
||||
Src:=Fasm.GenNewSrc;
|
||||
Src.LoadFromFile('..\..\testlib.fasm');
|
||||
Fasm.LoadLib('W:\RuntimeBuilder\FasmOnDelphi\fasmw172\INCLUDE\win32a.inc');
|
||||
@@ -55,7 +55,7 @@ begin
|
||||
end;
|
||||
FreeAndNil(Func1);
|
||||
FreeAndNil(Src);
|
||||
FreeAndNil(Fasm);
|
||||
FreeAndNil(Fasm);}
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
1
lib/FasmOnDelphi
Submodule
1
lib/FasmOnDelphi
Submodule
Submodule lib/FasmOnDelphi added at dd1e5ff80a
1
lib/pLua-XE
Submodule
1
lib/pLua-XE
Submodule
Submodule lib/pLua-XE added at 79883e7f4e
Reference in New Issue
Block a user