2010-01-25 08:59:44 -05:00
|
|
|
{
|
|
|
|
This file is part of the Mufasa Macro Library (MML)
|
|
|
|
Copyright (c) 2009 by Raymond van Venetië and Merlijn Wajer
|
|
|
|
|
|
|
|
MML is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
MML is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with MML. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
See the file COPYING, included in this distribution,
|
|
|
|
for details about the copyright.
|
|
|
|
|
|
|
|
MMLPSThread for the Mufasa Macro Library
|
|
|
|
}
|
|
|
|
|
|
|
|
unit mmlpsthread;
|
|
|
|
|
|
|
|
{$Define PS_USESSUPPORT}
|
2010-01-26 11:51:36 -05:00
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, client, uPSComponent,uPSCompiler,
|
|
|
|
uPSRuntime,stdCtrls, uPSPreProcessor,MufasaTypes, web,
|
2010-02-13 11:56:46 -05:00
|
|
|
bitmaps, plugins, libloader, dynlibs,internets;
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
{ TMMLPSThread }
|
|
|
|
TSyncInfo = record
|
|
|
|
V : MufasaTypes.TVariantArray;
|
|
|
|
MethodName : string;
|
|
|
|
Res : Variant;
|
|
|
|
SyncMethod : procedure of object;
|
|
|
|
OldThread : TThread;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TWritelnProc = procedure(s: string);
|
|
|
|
TDbgImgInfo = record
|
|
|
|
DispSize : ^TPoint;
|
|
|
|
ShowForm : procedure of object;
|
|
|
|
ToDrawBitmap : ^TMufasaBitmap;
|
|
|
|
DrawBitmap : procedure of object;
|
|
|
|
GetDebugBitmap : ^TMufasaBitmap;
|
|
|
|
GetBitmap : procedure of object;
|
|
|
|
end;
|
|
|
|
PSyncInfo = ^TSyncInfo;
|
|
|
|
TErrorType = (errRuntime,errCompile);
|
|
|
|
TOnError = procedure of object;
|
|
|
|
TErrorData = record
|
2010-02-26 11:59:05 -05:00
|
|
|
Row,Col,Position : integer;
|
2010-01-25 08:59:44 -05:00
|
|
|
Error : string;
|
|
|
|
ErrType : TErrorType;
|
|
|
|
Module : string;
|
|
|
|
IncludePath : string;
|
|
|
|
end;
|
|
|
|
PErrorData = ^TErrorData;
|
|
|
|
TExpMethod = record
|
|
|
|
Section : string;
|
|
|
|
FuncDecl : string;
|
|
|
|
FuncPtr : Pointer;
|
|
|
|
end;
|
|
|
|
TExpMethodArr = array of TExpMethod;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
TMThread = class(TThread)
|
|
|
|
protected
|
|
|
|
ScriptPath, AppPath, IncludePath, PluginPath, FontPath: string;
|
|
|
|
DebugTo: TWritelnProc;
|
|
|
|
DebugImg : TDbgImgInfo;
|
|
|
|
ExportedMethods : TExpMethodArr;
|
2010-02-26 11:59:05 -05:00
|
|
|
Includes : TStringList;
|
2010-02-07 03:42:06 -05:00
|
|
|
procedure LoadPlugin(plugidx: integer); virtual; abstract;
|
2010-01-25 12:38:43 -05:00
|
|
|
|
|
|
|
public
|
|
|
|
Client : TClient;
|
2010-02-13 11:56:46 -05:00
|
|
|
MInternet : TMInternet;
|
2010-01-25 12:38:43 -05:00
|
|
|
StartTime : LongWord;
|
|
|
|
DebugMemo : TMemo;
|
|
|
|
|
|
|
|
SyncInfo : PSyncInfo; //We need this for callthreadsafe
|
|
|
|
ErrorData : PErrorData; //We need this for thread-safety etc
|
|
|
|
OnError : TOnError; //Error handeler
|
|
|
|
|
2010-01-31 07:29:33 -05:00
|
|
|
CompileOnly : boolean;
|
2010-02-26 11:59:05 -05:00
|
|
|
procedure HandleError(ErrorRow,ErrorCol,ErrorPosition : integer; ErrorStr : string; ErrorType : TErrorType; ErrorModule : string);
|
2010-01-26 17:58:41 -05:00
|
|
|
function ProcessDirective(DirectiveName, DirectiveArgs: string): boolean;
|
2010-02-26 11:59:05 -05:00
|
|
|
function LoadFile(ParentFile : string; var filename, contents: string): boolean;
|
2010-01-26 17:58:41 -05:00
|
|
|
procedure AddMethod(meth: TExpMethod); virtual;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure SetScript(Script : string);
|
|
|
|
procedure SetDebug( writelnProc : TWritelnProc );
|
|
|
|
procedure SetDbgImg( DebugImageInfo : TDbgImgInfo);
|
|
|
|
procedure SetPaths(ScriptP,AppP,IncludeP,PluginP,FontP : string);
|
|
|
|
procedure OnThreadTerminate(Sender: TObject);
|
|
|
|
procedure SetScript(script: string); virtual; abstract;
|
|
|
|
procedure Execute; override; abstract;
|
|
|
|
procedure Terminate; virtual; abstract;
|
|
|
|
|
2010-01-26 17:58:41 -05:00
|
|
|
constructor Create(CreateSuspended: boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
2010-01-25 12:38:43 -05:00
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
class function GetExportedMethods : TExpMethodArr;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TPSThread = class(TMThread)
|
2010-01-26 17:58:41 -05:00
|
|
|
public
|
|
|
|
procedure OnProcessDirective(Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
|
|
|
const DirectiveName, DirectiveParam: string; var Continue: Boolean);
|
|
|
|
function PSScriptFindUnknownFile(Sender: TObject;
|
|
|
|
const OrginFileName: string; var FileName, Output: string): Boolean;
|
|
|
|
procedure PSScriptProcessUnknowDirective(Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
|
|
|
const DirectiveName, DirectiveParam: string; var Continue: Boolean);
|
|
|
|
protected
|
2010-02-07 03:42:06 -05:00
|
|
|
PluginsToload : array of integer;
|
|
|
|
procedure LoadPlugin(plugidx: integer); override;
|
2010-01-26 17:58:41 -05:00
|
|
|
procedure OnCompile(Sender: TPSScript);
|
|
|
|
function RequireFile(Sender: TObject; const OriginFileName: String;
|
|
|
|
var FileName, OutPut: string): Boolean;
|
|
|
|
procedure OnCompImport(Sender: TObject; x: TPSPascalCompiler);
|
|
|
|
procedure OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
|
|
|
|
procedure OutputMessages;
|
|
|
|
public
|
|
|
|
PSScript : TPSScript;
|
|
|
|
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure SetScript(script: string); override;
|
|
|
|
procedure Execute; override;
|
|
|
|
procedure Terminate; override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TPrecompiler_Callback = function(name, args: PChar): boolean; stdcall;
|
2010-01-27 10:52:58 -05:00
|
|
|
TErrorHandeler_Callback = procedure(line, pos: integer; err: PChar; runtime: boolean); stdcall;
|
2010-01-26 17:58:41 -05:00
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
TCPThread = class(TMThread)
|
2010-01-26 17:58:41 -05:00
|
|
|
protected
|
|
|
|
instance: pointer;
|
2010-01-27 10:52:58 -05:00
|
|
|
added_methods: array of TExpMethod;
|
2010-02-07 03:42:06 -05:00
|
|
|
procedure LoadPlugin(plugidx: integer); override;
|
2010-01-26 17:58:41 -05:00
|
|
|
public
|
2010-01-28 01:01:07 -05:00
|
|
|
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
2010-01-26 17:58:41 -05:00
|
|
|
destructor Destroy; override;
|
|
|
|
procedure SetScript(script: string); override;
|
|
|
|
procedure Execute; override;
|
|
|
|
procedure Terminate; override;
|
|
|
|
procedure AddMethod(meth: TExpMethod); override;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
2010-01-25 12:38:43 -05:00
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
threadvar
|
2010-01-25 12:38:43 -05:00
|
|
|
CurrThread : TMThread;
|
2010-01-26 17:58:41 -05:00
|
|
|
var
|
|
|
|
PluginsGlob: TMPlugins;
|
2010-01-25 12:38:43 -05:00
|
|
|
|
2010-01-28 01:01:07 -05:00
|
|
|
libcpascal: integer;
|
|
|
|
interp_init: function(precomp: TPrecompiler_Callback; err: TErrorHandeler_Callback): Pointer; cdecl;
|
|
|
|
interp_meth: procedure(interp: Pointer; addr: Pointer; def: PChar); cdecl;
|
2010-02-05 14:24:27 -05:00
|
|
|
interp_type: procedure(interp: Pointer; def: PChar); cdecl;
|
2010-01-28 01:01:07 -05:00
|
|
|
interp_set: procedure(interp: Pointer; ppg: PChar); cdecl;
|
|
|
|
interp_comp: function(interp: Pointer): boolean; cdecl;
|
|
|
|
interp_run: function(interp: Pointer): boolean; cdecl;
|
|
|
|
interp_free: procedure(interp: Pointer); cdecl;
|
2010-01-25 12:38:43 -05:00
|
|
|
|
2010-01-28 01:01:07 -05:00
|
|
|
implementation
|
2010-01-27 00:44:43 -05:00
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
uses
|
|
|
|
colour_conv,dtmutil,
|
2010-02-26 11:59:05 -05:00
|
|
|
{$ifdef mswindows}windows, MMSystem,{$endif}//MMSystem -> Sounds
|
2010-01-25 08:59:44 -05:00
|
|
|
uPSC_std, uPSC_controls,uPSC_classes,uPSC_graphics,uPSC_stdctrls,uPSC_forms,
|
|
|
|
uPSC_extctrls, //Compile-libs
|
|
|
|
uPSUtils,
|
|
|
|
fontloader,
|
2010-02-05 14:20:35 -05:00
|
|
|
IOmanager,//TTarget_Exported
|
2010-01-28 18:34:03 -05:00
|
|
|
IniFiles,//Silly INI files
|
2010-02-25 20:02:41 -05:00
|
|
|
stringutil, //String st00f
|
2010-01-25 08:59:44 -05:00
|
|
|
uPSR_std, uPSR_controls,uPSR_classes,uPSR_graphics,uPSR_stdctrls,uPSR_forms,
|
|
|
|
uPSR_extctrls, //Runtime-libs
|
|
|
|
Graphics, //For Graphics types
|
|
|
|
math, //Maths!
|
|
|
|
strutils,
|
|
|
|
tpa, //Tpa stuff
|
|
|
|
forms,//Forms
|
2010-01-27 08:01:37 -05:00
|
|
|
lclintf // for GetTickCount and others.
|
|
|
|
;
|
2010-01-28 18:34:03 -05:00
|
|
|
{$ifdef Linux}
|
2010-01-27 00:44:43 -05:00
|
|
|
{$define PS_StdCall}
|
2010-01-28 18:34:03 -05:00
|
|
|
{$else}
|
|
|
|
//{$define PS_StdCall}
|
|
|
|
{$endif}
|
2010-01-26 11:51:36 -05:00
|
|
|
{$MACRO ON}
|
|
|
|
{$ifdef PS_StdCall}
|
2010-01-28 18:34:03 -05:00
|
|
|
{$define extdecl := stdcall}
|
2010-01-26 11:51:36 -05:00
|
|
|
{$else}
|
2010-01-28 18:34:03 -05:00
|
|
|
{$define extdecl := REGISTER}
|
2010-01-26 11:51:36 -05:00
|
|
|
{$endif}
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
{Some General PS Functions here}
|
2010-01-28 18:34:03 -05:00
|
|
|
procedure psWriteln(str : string); extdecl;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
if Assigned(CurrThread.DebugTo) then
|
|
|
|
CurrThread.DebugTo(str)
|
|
|
|
else
|
|
|
|
writeln(str);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function MakeString(data : TPSVariantIFC) : string;
|
|
|
|
begin;
|
2010-02-26 13:25:42 -05:00
|
|
|
if data.Dta = nil then
|
|
|
|
result := 'Nil'
|
|
|
|
else
|
2010-01-25 08:59:44 -05:00
|
|
|
if data.aType.basetype in [btString,btChar] then
|
|
|
|
result := PSGetAnsiString(Data.Dta,data.aType)
|
|
|
|
else if data.aType.ExportName = 'BOOLEAN' then
|
|
|
|
result := BoolToStr(PSGetInt(Data.Dta,data.aType) <> 0,true)
|
|
|
|
else
|
|
|
|
result := PSVariantToString(data,'');
|
|
|
|
end;
|
|
|
|
|
|
|
|
function writeln_(Caller: TPSExec; p: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
|
|
|
|
var
|
|
|
|
arr: TPSVariantIFC;
|
|
|
|
begin
|
|
|
|
Result:=true;
|
|
|
|
psWriteln(makeString(NewTPSVariantIFC(Stack[Stack.Count-1],false)));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function swap_(Caller: TPSExec; p: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
|
|
|
|
var
|
|
|
|
Param1,Param2: TPSVariantIFC;
|
|
|
|
tempCopy : pointer;
|
|
|
|
begin
|
|
|
|
Result:=true;
|
|
|
|
Param1 := NewTPSVariantIFC(Stack[Stack.count-1],true);
|
|
|
|
Param2 := NewTPSVariantIFC(Stack[Stack.count-2],true);
|
|
|
|
if Param1.aType.BaseType <> Param2.aType.BaseType then
|
|
|
|
exit(false)
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Param1.aType.CalcSize;
|
|
|
|
param2.aType.CalcSize;
|
|
|
|
if Param1.aType.RealSize <> Param2.aType.RealSize then
|
|
|
|
exit(false);
|
|
|
|
GetMem(tempcopy,Param1.aType.RealSize);
|
|
|
|
Move(Param1.Dta^,tempCopy^,param1.atype.realsize);
|
|
|
|
Move(Param2.Dta^,Param1.Dta^,param1.atype.realsize);
|
|
|
|
Move(tempCopy^,Param2.Dta^,param1.atype.realsize);
|
|
|
|
Freemem(tempcopy);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function ToStr_(Caller: TPSExec; p: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
|
|
|
|
var
|
|
|
|
data: TPSVariantIFC;
|
|
|
|
begin
|
|
|
|
result := true;
|
|
|
|
Stack.SetAnsiString(-1, MakeString(NewTPSVariantIFC(Stack[Stack.Count-2],false)));
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
{***implementation TMThread***}
|
2010-01-26 17:58:41 -05:00
|
|
|
constructor TMThread.Create(CreateSuspended: boolean; TheSyncInfo: PSyncInfo; plugin_dir: string);
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
|
|
|
Client := TClient.Create(plugin_dir);
|
2010-02-13 11:56:46 -05:00
|
|
|
MInternet := TMInternet.Create(Client);
|
2010-01-26 17:58:41 -05:00
|
|
|
SyncInfo:= TheSyncInfo;
|
2010-01-25 12:38:43 -05:00
|
|
|
ExportedMethods:= GetExportedMethods;
|
|
|
|
FreeOnTerminate := True;
|
2010-01-31 07:29:33 -05:00
|
|
|
CompileOnly := false;
|
2010-01-25 12:38:43 -05:00
|
|
|
OnTerminate := @OnThreadTerminate;
|
2010-01-26 20:50:17 -05:00
|
|
|
OnError:= nil;
|
2010-02-26 11:59:05 -05:00
|
|
|
Includes := TStringList.Create;
|
|
|
|
Includes.CaseSensitive:= {$ifdef linux}true{$else}false{$endif};
|
2010-01-25 12:38:43 -05:00
|
|
|
inherited Create(CreateSuspended);
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TMThread.Destroy;
|
|
|
|
begin
|
2010-02-13 11:56:46 -05:00
|
|
|
MInternet.Free;
|
2010-01-25 12:38:43 -05:00
|
|
|
Client.Free;
|
2010-02-26 11:59:05 -05:00
|
|
|
Includes.free;
|
2010-01-25 12:38:43 -05:00
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2010-02-26 11:59:05 -05:00
|
|
|
procedure TMThread.HandleError(ErrorRow,ErrorCol, ErrorPosition: integer; ErrorStr: string; ErrorType: TErrorType; ErrorModule : string);
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
|
|
|
if OnError = nil then
|
|
|
|
exit;
|
2010-02-26 11:59:05 -05:00
|
|
|
ErrorData^.Row:= ErrorRow;
|
|
|
|
ErrorData^.Col := ErrorCol;
|
2010-01-25 12:38:43 -05:00
|
|
|
ErrorData^.Position:= ErrorPosition;
|
|
|
|
ErrorData^.Error:= ErrorStr;
|
|
|
|
ErrorData^.ErrType:= ErrorType;
|
|
|
|
ErrorData^.Module:= ErrorModule;
|
|
|
|
ErrorData^.IncludePath:= IncludePath;
|
2010-01-25 16:37:33 -05:00
|
|
|
CurrThread.Synchronize(OnError);
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMThread.OnThreadTerminate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2010-01-26 17:58:41 -05:00
|
|
|
procedure TMThread.AddMethod(meth: TExpMethod);
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
2010-02-26 11:59:05 -05:00
|
|
|
function FindFile(filename : string; Dirs : array of string) : string; //Results '' if not found
|
2010-01-25 12:38:43 -05:00
|
|
|
var
|
2010-02-26 11:59:05 -05:00
|
|
|
i : integer;
|
|
|
|
begin;
|
|
|
|
if fileexists(filename) then
|
|
|
|
result := filename
|
|
|
|
else
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
2010-02-26 11:59:05 -05:00
|
|
|
for i := 0 to high(Dirs) do
|
|
|
|
if DirectoryExists(dirs[i]) then
|
|
|
|
if fileexists(dirs[i] + filename) then
|
|
|
|
begin
|
|
|
|
result := dirs[i] + filename;
|
|
|
|
exit;
|
|
|
|
end;
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-02-26 11:59:05 -05:00
|
|
|
function TMThread.LoadFile(ParentFile : string; var filename, contents: string): boolean;
|
2010-01-25 12:38:43 -05:00
|
|
|
var
|
|
|
|
path: string;
|
|
|
|
f: TFileStream;
|
|
|
|
begin
|
2010-02-26 11:59:05 -05:00
|
|
|
path := FindFile(filename,[includepath,ScriptPath,IncludeTrailingPathDelimiter(ExtractFileDir(parentfile))]);
|
|
|
|
if path = '' then
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
|
|
|
psWriteln(Path + ' doesn''t exist');
|
|
|
|
Result := false;
|
|
|
|
Exit;
|
|
|
|
end;
|
2010-02-26 11:59:05 -05:00
|
|
|
filename := path;//Yeah!
|
|
|
|
Includes.Add(path);
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
try
|
|
|
|
f:= TFileStream.Create(Path, fmOpenRead or fmShareDenyWrite);
|
2010-02-26 11:59:05 -05:00
|
|
|
SetLength(contents, f.Size);
|
|
|
|
f.Read(contents[1], Length(contents));
|
|
|
|
result:= true;
|
|
|
|
f.free;
|
2010-01-25 12:38:43 -05:00
|
|
|
except
|
|
|
|
Result := false;
|
2010-02-26 11:59:05 -05:00
|
|
|
psWriteln('ERROR in TMThread.LoadFile');
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
2010-02-26 11:59:05 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TMThread.ProcessDirective(DirectiveName, DirectiveArgs: string): boolean;
|
|
|
|
var
|
|
|
|
plugin_idx, i: integer;
|
|
|
|
path : string;
|
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
if CompareText(DirectiveName,'LOADDLL') = 0 then
|
|
|
|
begin
|
|
|
|
if DirectiveArgs <> '' then
|
|
|
|
begin;
|
|
|
|
plugin_idx:= PluginsGlob.LoadPlugin(DirectiveArgs);
|
|
|
|
if plugin_idx < 0 then
|
|
|
|
psWriteln(Format('Your DLL %s has not been found',[DirectiveArgs]))
|
|
|
|
else begin
|
|
|
|
LoadPlugin(plugin_idx);
|
|
|
|
result:= True;
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
psWriteln('Your LoadDLL directive has no params, thus cannot find the plugin');
|
|
|
|
end else
|
|
|
|
if CompareText(DirectiveName,'INCLUDE_ONCE') = 0 then
|
|
|
|
begin
|
|
|
|
result := true; //Lets to the actual file checking later on in the preprocessor ;-)
|
|
|
|
if DirectiveArgs <> '' then
|
|
|
|
begin
|
|
|
|
path := FindFile(DirectiveArgs,[ScriptPath,IncludePath]);
|
|
|
|
if path <> '' then
|
|
|
|
if Includes.Find(path,i) then
|
|
|
|
begin
|
|
|
|
psWriteln('Include_Once file already included');
|
|
|
|
result := false;
|
|
|
|
end;
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
2010-02-26 11:59:05 -05:00
|
|
|
end else
|
|
|
|
result := true;
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMThread.SetDebug(writelnProc: TWritelnProc);
|
|
|
|
begin
|
|
|
|
DebugTo := writelnProc;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMThread.SetDbgImg(DebugImageInfo: TDbgImgInfo);
|
|
|
|
begin
|
|
|
|
DebugImg := DebugImageInfo;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMThread.SetPaths(ScriptP, AppP,IncludeP,PluginP,FontP: string);
|
|
|
|
begin
|
|
|
|
AppPath:= AppP;
|
|
|
|
ScriptPath:= ScriptP;
|
|
|
|
IncludePath:= IncludeP;
|
|
|
|
PluginPath:= PluginP;
|
|
|
|
FontPath:= FontP;
|
|
|
|
end;
|
|
|
|
|
2010-02-26 11:59:05 -05:00
|
|
|
function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant; extdecl;
|
2010-01-25 16:37:33 -05:00
|
|
|
begin
|
|
|
|
CurrThread.SyncInfo^.MethodName:= ProcName;
|
|
|
|
CurrThread.SyncInfo^.V:= V;
|
|
|
|
CurrThread.SyncInfo^.OldThread := CurrThread;
|
|
|
|
CurrThread.Synchronize(CurrThread.SyncInfo^.SyncMethod);
|
|
|
|
Result := CurrThread.SyncInfo^.Res;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
{$I PSInc/Wrappers/other.inc}
|
|
|
|
{$I PSInc/Wrappers/bitmap.inc}
|
|
|
|
{$I PSInc/Wrappers/window.inc}
|
2010-02-06 16:01:35 -05:00
|
|
|
{$I PSInc/Wrappers/tpa.inc}
|
2010-01-25 12:38:43 -05:00
|
|
|
{$I PSInc/Wrappers/strings.inc}
|
|
|
|
{$I PSInc/Wrappers/colour.inc}
|
|
|
|
{$I PSInc/Wrappers/math.inc}
|
|
|
|
{$I PSInc/Wrappers/mouse.inc}
|
|
|
|
{$I PSInc/Wrappers/file.inc}
|
|
|
|
{$I PSInc/Wrappers/keyboard.inc}
|
|
|
|
{$I PSInc/Wrappers/dtm.inc}
|
|
|
|
{$I PSInc/Wrappers/ocr.inc}
|
|
|
|
{$I PSInc/Wrappers/internets.inc}
|
|
|
|
|
|
|
|
class function TMThread.GetExportedMethods: TExpMethodArr;
|
|
|
|
var
|
|
|
|
c : integer;
|
|
|
|
CurrSection : string;
|
|
|
|
|
|
|
|
procedure SetCurrSection(str : string);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin;
|
2010-01-25 12:38:43 -05:00
|
|
|
CurrSection := Str;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure AddFunction( Ptr : Pointer; DeclStr : String);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin;
|
2010-01-25 12:38:43 -05:00
|
|
|
if c >= 300 then
|
|
|
|
raise exception.create('PSThread.LoadMethods: Exported more than 300 functions');
|
|
|
|
Result[c].FuncDecl:= DeclStr;
|
|
|
|
Result[c].FuncPtr:= Ptr;
|
|
|
|
Result[c].Section:= CurrSection;
|
|
|
|
inc(c);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
|
|
|
c := 0;
|
|
|
|
CurrSection := 'Other';
|
|
|
|
SetLength(Result,300);
|
|
|
|
|
|
|
|
{$i PSInc/psexportedmethods.inc}
|
|
|
|
|
|
|
|
SetLength(Result,c);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{***implementation TPSThread***}
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
Note to Raymond: For PascalScript, Create it on the .Create,
|
|
|
|
Execute it on the .Execute, and don't forget to Destroy it on .Destroy.
|
|
|
|
|
|
|
|
Furthermore, all the wrappers can be in the unit "implementation" section.
|
|
|
|
Better still to create an .inc for it, otherwise this unit will become huge.
|
|
|
|
(You can even split up the .inc's in stuff like color, bitmap, etc. )
|
|
|
|
|
|
|
|
Also, don't add PS to this unit, but make a seperate unit for it.
|
|
|
|
Unit "MMLPSThread", perhaps?
|
|
|
|
|
|
|
|
See the TestUnit for use of this thread, it's pretty straightforward.
|
|
|
|
|
|
|
|
It may also be wise to turn the "Importing of wrappers" into an include as
|
|
|
|
well, it will really make the unit more straightforward to use and read.
|
|
|
|
}
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
constructor TPSThread.Create(CreateSuspended : boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
2010-02-05 11:30:42 -05:00
|
|
|
var
|
|
|
|
I : integer;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
PSScript := TPSScript.Create(nil);
|
|
|
|
PSScript.UsePreProcessor:= True;
|
|
|
|
PSScript.OnNeedFile := @RequireFile;
|
|
|
|
PSScript.OnProcessDirective:=@OnProcessDirective;
|
|
|
|
PSScript.OnProcessUnknowDirective:=@PSScriptProcessUnknowDirective;
|
|
|
|
PSScript.OnCompile:= @OnCompile;
|
|
|
|
PSScript.OnCompImport:= @OnCompImport;
|
|
|
|
PSScript.OnExecImport:= @OnExecImport;
|
|
|
|
PSScript.OnFindUnknownFile:=@PSScriptFindUnknownFile;
|
|
|
|
// Set some defines
|
|
|
|
{$I PSInc/psdefines.inc}
|
2010-01-26 17:58:41 -05:00
|
|
|
inherited Create(CreateSuspended, TheSyncInfo, plugin_dir);
|
2010-02-05 11:30:42 -05:00
|
|
|
for i := 0 to high(ExportedMethods) do
|
|
|
|
if pos('Writeln',exportedmethods[i].FuncDecl) > 0 then
|
|
|
|
begin
|
|
|
|
ExportedMethods[i].FuncPtr := nil;
|
|
|
|
break;
|
|
|
|
end;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
destructor TPSThread.Destroy;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
PSScript.Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OnProcessDirective(Sender: TPSPreProcessor;
|
2010-01-25 08:59:44 -05:00
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
|
|
|
const DirectiveName, DirectiveParam: string; var Continue: Boolean);
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
function TPSThread.PSScriptFindUnknownFile(Sender: TObject;
|
2010-01-25 08:59:44 -05:00
|
|
|
const OrginFileName: string; var FileName, Output: string): Boolean;
|
|
|
|
begin
|
|
|
|
Writeln(OrginFileName + '-' + Output + '-' + FileName);
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.PSScriptProcessUnknowDirective(Sender: TPSPreProcessor;
|
2010-01-25 08:59:44 -05:00
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
|
|
|
const DirectiveName, DirectiveParam: string; var Continue: Boolean);
|
|
|
|
begin
|
2010-01-25 12:38:43 -05:00
|
|
|
Continue:= ProcessDirective(DirectiveName, DirectiveParam);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-02-04 18:32:24 -05:00
|
|
|
function Muf_Conv_to_PS_Conv( conv : integer) : TDelphiCallingConvention;
|
|
|
|
begin
|
|
|
|
case conv of
|
|
|
|
cv_StdCall : result := cdStdCall;
|
|
|
|
cv_Register: result := cdRegister;
|
|
|
|
else
|
|
|
|
raise exception.createfmt('Unknown Calling Convention[%d]',[conv]);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-02-07 03:42:06 -05:00
|
|
|
|
|
|
|
procedure TPSThread.LoadPlugin(plugidx: integer);
|
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
for i := High(PluginsToLoad) downto 0 do
|
|
|
|
if PluginsToLoad[i] = plugidx then
|
|
|
|
Exit;
|
|
|
|
SetLength(PluginsToLoad,Length(PluginsToLoad)+1);
|
|
|
|
PluginsToLoad[High(PluginsToLoad)]:= plugidx;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OnCompile(Sender: TPSScript);
|
2010-01-25 08:59:44 -05:00
|
|
|
var
|
|
|
|
i,ii : integer;
|
|
|
|
Fonts : TMFonts;
|
|
|
|
begin
|
|
|
|
{$I PSInc/pscompile.inc}
|
|
|
|
Fonts := Client.MOCR.GetFonts;
|
|
|
|
for i := fonts.count - 1 downto 0 do
|
|
|
|
PSScript.Comp.AddConstantN(Fonts[i].Name,'string').SetString(Fonts[i].Name);
|
|
|
|
|
|
|
|
for i := high(PluginsToLoad) downto 0 do
|
|
|
|
for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].MethodLen - 1 do
|
|
|
|
PSScript.AddFunctionEx(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncPtr,
|
2010-02-04 18:32:24 -05:00
|
|
|
PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncStr,
|
|
|
|
Muf_Conv_to_PS_Conv(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncConv));
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
for i := 0 to high(VirtualKeys) do
|
|
|
|
PSScript.Comp.AddConstantN(Format('VK_%S',[VirtualKeys[i].Str]),'Byte').SetInt(VirtualKeys[i].Key);
|
|
|
|
// Here we add all the Consts/Types to the engine.
|
|
|
|
|
|
|
|
//Export all the methods
|
|
|
|
for i := 0 to high(ExportedMethods) do
|
|
|
|
if ExportedMethods[i].FuncPtr <> nil then
|
2010-01-26 11:51:36 -05:00
|
|
|
PSScript.AddFunctionEx(ExportedMethods[i].FuncPtr,ExportedMethods[i].FuncDecl,
|
|
|
|
{$ifdef PS_StdCall}cdStdCall{$else}cdRegister {$endif});
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
function TPSThread.RequireFile(Sender: TObject;
|
2010-01-25 08:59:44 -05:00
|
|
|
const OriginFileName: String; var FileName, OutPut: string): Boolean;
|
|
|
|
begin
|
2010-02-26 11:59:05 -05:00
|
|
|
result:= LoadFile(OriginFileName,FileName,OutPut);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure SIRegister_Mufasa(cl: TPSPascalCompiler);
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
2010-01-25 08:59:44 -05:00
|
|
|
with cl.AddClassN(cl.FindClass('TObject'),'TMufasaBitmap') do
|
|
|
|
begin;
|
|
|
|
RegisterMethod('constructor create');
|
|
|
|
RegisterMethod('procedure Free');
|
|
|
|
RegisterMethod('function SaveToFile(const FileName : string) :boolean;');
|
|
|
|
RegisterMethod('procedure LoadFromFile(const FileName : string);');
|
|
|
|
RegisterProperty('Index','Integer',iptR);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CreateMufasaBitmap : TMufasaBitmap;
|
|
|
|
begin;
|
|
|
|
result := TMufasaBitmap.Create;
|
|
|
|
CurrThread.Client.MBitmaps.AddBMP(result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure FreeMufasaBitmap(Self : TMufasaBitmap);
|
|
|
|
begin;
|
|
|
|
CurrThread.Client.MBitmaps.FreeBMP(Self.Index);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure MufasaBitmapIndex(self : TMufasaBitmap; var Index : integer);
|
|
|
|
begin;
|
|
|
|
Index := self.Index;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure RIRegister_Mufasa(cl: TPSRuntimeClassImporter);
|
|
|
|
begin;
|
|
|
|
with cl.Add(TMufasaBitmap) do
|
|
|
|
begin
|
|
|
|
RegisterConstructor(@CreateMufasaBitmap,'CREATE');
|
|
|
|
RegisterMethod(@FreeMufasaBitmap,'FREE');
|
|
|
|
RegisterMethod(@TMufasaBitmap.SaveToFile, 'SAVETOFILE');
|
|
|
|
RegisterMethod(@TMufasaBitmap.LoadFromFile, 'LOADFROMFILE');
|
|
|
|
RegisterPropertyHelper(@MufasaBitmapIndex,nil,'INDEX');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OnCompImport(Sender: TObject; x: TPSPascalCompiler);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
SIRegister_Std(x);
|
|
|
|
SIRegister_Controls(x);
|
|
|
|
SIRegister_Classes(x, true);
|
|
|
|
SIRegister_Graphics(x, true);
|
|
|
|
SIRegister_stdctrls(x);
|
|
|
|
SIRegister_Forms(x);
|
|
|
|
SIRegister_ExtCtrls(x);
|
|
|
|
SIRegister_Mufasa(x);
|
|
|
|
with x.AddFunction('procedure writeln;').decl do
|
|
|
|
with AddParam do
|
|
|
|
begin
|
|
|
|
OrgName:= 'x';
|
|
|
|
Mode:= pmIn;
|
|
|
|
end;
|
|
|
|
with x.AddFunction('function ToStr:string').decl do
|
|
|
|
with addparam do
|
|
|
|
begin
|
|
|
|
OrgName:= 'x';
|
|
|
|
Mode:= pmIn;
|
|
|
|
end;
|
|
|
|
with x.AddFunction('procedure swap;').decl do
|
|
|
|
begin
|
|
|
|
with addparam do
|
|
|
|
begin
|
|
|
|
OrgName:= 'x';
|
|
|
|
Mode:= pmInOut;
|
|
|
|
end;
|
|
|
|
with addparam do
|
|
|
|
begin
|
|
|
|
OrgName:= 'y';
|
|
|
|
Mode:= pmInOut;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OnExecImport(Sender: TObject; se: TPSExec;
|
2010-01-25 08:59:44 -05:00
|
|
|
x: TPSRuntimeClassImporter);
|
|
|
|
begin
|
|
|
|
RIRegister_Std(x);
|
|
|
|
RIRegister_Classes(x, True);
|
|
|
|
RIRegister_Controls(x);
|
|
|
|
RIRegister_Graphics(x, True);
|
|
|
|
RIRegister_stdctrls(x);
|
|
|
|
RIRegister_Forms(x);
|
|
|
|
RIRegister_ExtCtrls(x);
|
|
|
|
RIRegister_Mufasa(x);
|
|
|
|
se.RegisterFunctionName('WRITELN',@Writeln_,nil,nil);
|
|
|
|
se.RegisterFunctionName('TOSTR',@ToStr_,nil,nil);
|
|
|
|
se.RegisterFunctionName('SWAP',@swap_,nil,nil);
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OutputMessages;
|
2010-01-25 08:59:44 -05:00
|
|
|
var
|
|
|
|
l: Longint;
|
|
|
|
b: Boolean;
|
|
|
|
begin
|
|
|
|
b := False;
|
|
|
|
for l := 0 to PSScript.CompilerMessageCount - 1 do
|
|
|
|
begin
|
|
|
|
if (not b) and (PSScript.CompilerMessages[l] is TIFPSPascalCompilerError) then
|
|
|
|
begin
|
|
|
|
b := True;
|
|
|
|
if OnError <> nil then
|
|
|
|
with PSScript.CompilerMessages[l] do
|
2010-02-26 11:59:05 -05:00
|
|
|
HandleError(Row, Col, Pos, MessageToString,errCompile, ModuleName)
|
2010-01-25 08:59:44 -05:00
|
|
|
else
|
|
|
|
psWriteln(PSScript.CompilerErrorToStr(l) + ' at line ' + inttostr(PSScript.CompilerMessages[l].Row));
|
|
|
|
end else
|
|
|
|
psWriteln(PSScript.CompilerErrorToStr(l) + ' at line ' + inttostr(PSScript.CompilerMessages[l].Row));
|
|
|
|
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.Execute;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
CurrThread := Self;
|
|
|
|
Starttime := lclintf.GetTickCount;
|
|
|
|
|
|
|
|
try
|
|
|
|
if PSScript.Compile then
|
|
|
|
begin
|
|
|
|
OutputMessages;
|
|
|
|
psWriteln('Compiled succesfully in ' + IntToStr(GetTickCount - Starttime) + ' ms.');
|
2010-01-31 07:29:33 -05:00
|
|
|
if CompileOnly then
|
|
|
|
exit;
|
2010-01-25 08:59:44 -05:00
|
|
|
// if not (ScriptState = SCompiling) then
|
|
|
|
if not PSScript.Execute then
|
2010-02-26 11:59:05 -05:00
|
|
|
HandleError(PSScript.ExecErrorRow,PSScript.ExecErrorCol,PSScript.ExecErrorPosition,PSScript.ExecErrorToString,
|
2010-01-25 08:59:44 -05:00
|
|
|
errRuntime, PSScript.ExecErrorFileName)
|
|
|
|
else
|
2010-02-27 10:55:31 -05:00
|
|
|
psWriteln('Successfully executed.');
|
2010-01-25 08:59:44 -05:00
|
|
|
end else
|
|
|
|
begin
|
|
|
|
OutputMessages;
|
2010-02-27 10:55:31 -05:00
|
|
|
psWriteln('Compiling failed.');
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
except
|
|
|
|
on E : Exception do
|
|
|
|
psWriteln('ERROR IN PSSCRIPT: ' + e.message);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.Terminate;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
2010-01-25 12:38:43 -05:00
|
|
|
PSScript.Stop;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.SetScript(script: string);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
PSScript.Script.Text:= Script;
|
|
|
|
end;
|
|
|
|
|
2010-01-26 17:58:41 -05:00
|
|
|
{***implementation TCPThread***}
|
|
|
|
|
2010-01-28 01:01:07 -05:00
|
|
|
procedure LoadCPascal(plugin_dir: string);
|
|
|
|
begin
|
|
|
|
libcpascal:= LoadLibrary(PChar(plugin_dir + 'libcpascal' + {$ifdef LINUX} '.so' {$else} '.dll' {$endif}));
|
|
|
|
if libcpascal = 0 then
|
|
|
|
raise Exception.Create('CPascal library not found');
|
|
|
|
Pointer(interp_init):= GetProcAddress(libcpascal, PChar('interp_init'));
|
|
|
|
Pointer(interp_meth):= GetProcAddress(libcpascal, PChar('interp_meth'));
|
2010-02-05 14:24:27 -05:00
|
|
|
Pointer(interp_type):= GetProcAddress(libcpascal, PChar('interp_type'));
|
2010-01-28 01:01:07 -05:00
|
|
|
Pointer(interp_set):= GetProcAddress(libcpascal, PChar('interp_set'));
|
|
|
|
Pointer(interp_comp):= GetProcAddress(libcpascal, PChar('interp_comp'));
|
|
|
|
Pointer(interp_run):= GetProcAddress(libcpascal, PChar('interp_run'));
|
|
|
|
Pointer(interp_free):= GetProcAddress(libcpascal, PChar('interp_free'));
|
|
|
|
end;
|
|
|
|
|
2010-01-27 10:52:58 -05:00
|
|
|
function Interpreter_Precompiler(name, args: PChar): boolean; stdcall;
|
2010-01-26 17:58:41 -05:00
|
|
|
var
|
2010-01-27 10:52:58 -05:00
|
|
|
local_name, local_args: string;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 10:52:58 -05:00
|
|
|
result:= CurrThread.ProcessDirective(name, args);
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-27 10:52:58 -05:00
|
|
|
procedure Interpreter_ErrorHandler(line, pos: integer; err: PChar; runtime: boolean); stdcall;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 10:52:58 -05:00
|
|
|
if runtime then
|
2010-02-26 11:59:05 -05:00
|
|
|
CurrThread.HandleError(line,-1,pos,err,errRuntime,'')
|
2010-01-27 10:52:58 -05:00
|
|
|
else
|
2010-02-26 11:59:05 -05:00
|
|
|
CurrThread.HandleError(line,-1,pos,err,errCompile,'')
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-28 01:01:07 -05:00
|
|
|
constructor TCPThread.Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
2010-01-27 00:44:43 -05:00
|
|
|
var
|
2010-01-27 10:52:58 -05:00
|
|
|
plugin_idx: integer;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-28 01:01:07 -05:00
|
|
|
if libcpascal = 0 then
|
|
|
|
LoadCPascal(plugin_dir);
|
2010-01-27 10:52:58 -05:00
|
|
|
instance:= interp_init(@Interpreter_Precompiler, @Interpreter_ErrorHandler);
|
|
|
|
inherited Create(CreateSuspended, TheSyncInfo, plugin_dir);
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-27 10:52:58 -05:00
|
|
|
destructor TCPThread.Destroy;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 10:52:58 -05:00
|
|
|
interp_free(instance);
|
|
|
|
inherited Destroy;
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
procedure TCPThread.SetScript(script: string);
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 10:52:58 -05:00
|
|
|
interp_set(instance,PChar(script));
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
procedure TCPThread.AddMethod(meth: TExpMethod);
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 00:44:43 -05:00
|
|
|
interp_meth(instance,meth.FuncPtr,PChar(meth.FuncDecl));
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-02-07 03:42:06 -05:00
|
|
|
procedure TCPThread.LoadPlugin(plugidx: integer);
|
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
with PluginsGlob.MPlugins[plugidx] do
|
|
|
|
for i := 0 to MethodLen - 1 do
|
|
|
|
with Methods[i] do
|
|
|
|
begin
|
|
|
|
pswriteln(FuncStr);
|
|
|
|
interp_meth(self.instance,FuncPtr,PChar(FuncStr));
|
|
|
|
end;
|
|
|
|
pswriteln('done')
|
|
|
|
end;
|
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
procedure TCPThread.Execute;
|
2010-01-27 10:52:58 -05:00
|
|
|
var
|
|
|
|
i,ii: integer;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 00:44:43 -05:00
|
|
|
CurrThread := Self;
|
2010-01-27 10:52:58 -05:00
|
|
|
Starttime := GetTickCount;
|
2010-01-27 00:44:43 -05:00
|
|
|
psWriteln('Invoking CPascal Interpreter');
|
2010-02-07 03:42:06 -05:00
|
|
|
interp_type(self.instance,'type longword = integer;');
|
|
|
|
interp_type(self.instance,'type word = integer;');
|
|
|
|
interp_type(self.instance,'type longint = integer;');
|
|
|
|
interp_type(self.instance,'type pointer = integer;');
|
|
|
|
interp_type(self.instance,'type byte = integer;');
|
2010-02-05 14:24:27 -05:00
|
|
|
interp_type(self.instance,'type extended = real;');
|
2010-02-07 03:42:06 -05:00
|
|
|
interp_type(self.instance,'type tcolor = integer;');
|
|
|
|
|
|
|
|
interp_type(self.instance,'type TExtendedArray = array of extended;');
|
|
|
|
interp_type(self.instance,'type T2DExtendedArray = array of array of extended;');
|
|
|
|
interp_type(self.instance,'type TIntegerArray = array of integer;');
|
|
|
|
|
|
|
|
interp_type(self.instance,'type TBox = record X1,Y1,X2,Y2: integer; end;');
|
|
|
|
interp_type(self.instance,'type TPoint = record x,y: integer; end;');
|
|
|
|
interp_type(self.instance,'type TPointArray = array of TPoint;'); ;
|
|
|
|
interp_type(self.instance,'type T2DPointArray = array of array of TPoint;'); ;
|
|
|
|
interp_type(self.instance,'type TPointArrayArray = T2DPointArray;');
|
|
|
|
|
|
|
|
interp_type(self.instance,'type TTarget_Exported = record int1,int2,int3,int4,int5,int6,int7,int8,int9,int10,int11,int12,int13,int14:integer; end;');
|
|
|
|
interp_type(self.instance,'type TMask = record White, Black : TPointArray; WhiteHi,BlackHi : integer; W,H : integer;end;');
|
|
|
|
interp_type(self.instance,'type TDTMPointDef = record x, y, Color, Tolerance, AreaSize, AreaShape: integer; end;');
|
|
|
|
interp_type(self.instance,'type TDTMPointDefArray = Array Of TDTMPointDef;');
|
|
|
|
interp_type(self.instance,'type TDTM = record MainPoint: TDTMPointDef; SubPoints: TDTMPointDefArray; end;');
|
|
|
|
interp_type(self.instance,'type pDTM = record l: Integer;p: TPointArray;c, t, asz, ash: TIntegerArray; bp: Array Of Boolean; n: String; end;');
|
|
|
|
|
2010-02-05 14:24:27 -05:00
|
|
|
|
|
|
|
for i := 0 to high(ExportedMethods) do
|
|
|
|
if ExportedMethods[i].FuncPtr <> nil then
|
|
|
|
with ExportedMethods[i] do
|
|
|
|
interp_meth(self.instance,FuncPtr,PChar(FuncDecl));
|
2010-01-27 10:52:58 -05:00
|
|
|
if interp_comp(instance) then
|
|
|
|
begin
|
|
|
|
psWriteln('Compiled Successfully in ' + IntToStr(GetTickCount - Starttime) + 'ms');
|
2010-01-31 07:29:33 -05:00
|
|
|
if CompileOnly then
|
|
|
|
exit;
|
2010-01-27 10:52:58 -05:00
|
|
|
if interp_run(instance) then
|
|
|
|
psWriteln('Executed Successfully')
|
|
|
|
else
|
|
|
|
psWriteln('Execution Failed');
|
|
|
|
end else
|
|
|
|
psWriteln('Compile Failed');
|
2010-01-26 17:58:41 -05:00
|
|
|
|
|
|
|
end;
|
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
procedure TCPThread.Terminate;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 00:44:43 -05:00
|
|
|
raise Exception.Create('Stopping Interpreter not yet implemented');
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
initialization
|
|
|
|
PluginsGlob := TMPlugins.Create;
|
2010-01-28 01:01:07 -05:00
|
|
|
libcpascal:= 0;
|
2010-01-25 08:59:44 -05:00
|
|
|
finalization
|
|
|
|
//PluginsGlob.Free;
|
|
|
|
//Its a nice idea, but it will segfault... the program is closing anyway.
|
|
|
|
end.
|
|
|
|
|