Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Source Help

Pascal plugIn

A community discussion post from the original code:zIRON forum.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

Pascal plugIn

hi

i am start a new Pascal plugin that will understand this function prototype.

// this is dummy function used for testing purpose
function* SetCursorProperties(XHotSpot, YHotSpot: LongWord; pCursorBitmap: IDirect3DSurface9): HResult; stdcall;         

and here is my first step , it is only find out is that a pascal function or not

//******************************************************//
//                                                      //
//               Pascal Plugin                          //
//                                                      //
//               By Emil Halim                          //
//               8 / 11 / 2011                          //
//                                                      //
//******************************************************//

plugins off;

program WIN32DLL 'Pas PLUGIN';

#include 'zirplug/framework.zir';
#include 'strings.zir';

//////////////////////////////

const strLoaded = 'Pas plugin has loaded!';

//////////////////////////////
function H_strlen(char* str) {
  Eax = str;
  while(char[eax] != 0) {
    Eax++;
  }
  sub eax, str
}

function  H_strcpy(Dword dst,src)
{ 
  Eax = dst; 
  Edx = src; 
  push Eax;
  BL =  [Edx]; 
  while ( BL != 0)  
   { 
      [Eax] = BL; 
      Eax++; Edx++; 
      BL =  [Edx]; 
   }  
  [Eax] = 0;
  pop Eax;
} 

function H_strcat(Dword dst,src) 
{ 
  Eax = dst; 
  Edx = src;
  push Eax;
  while (byte [Eax] != 0) { Eax++; } 
  while (byte [Edx] != 0)  
   { 
      BL =  [Edx]; 
      [Eax] = BL;  
      Edx++; Eax++; 
   } 
  [Eax] = 0;
  pop Eax;
} 

inline procedure  H_strjoin(;)
{
  $temp = 1;
  $to = $argc - 1;  
  $repeat $to:	
     H_strcat($arg[0],$arg[$temp]);  
  $temp++;
  $end
}

inline procedure Ziron_ExecuteF(m_st)
{
   Ziron_Execute($m_st,H_strlen($m_st));
}

//
// event_Pas()
//
function event_Pas()
{
  uses edi;
  char buf[2048];
  char line[2048];
  char val[255];
  Dword Len;
  boolean ParesFlg;  
        
  len = Ziron_ExtractLine(@line, 2048);  
  //Ziron_ShowMessage(@line);                // show our entire line for debug purpose
  Eax = @line;
  Cl  = char[Eax];
  Edx  = false;
  ParesFlg = false;  
  while( cl != 0)
   {
       if(cl == '(')
        {
          Edx = true;
        }
       if(cl == ')')
        {
          Edx = false;
        } 
       if( Edx == true and cl == ":")
        {
           ParesFlg = true;
        }
       Cl  = char[Eax];
       Eax++;
   }
  
 
  // see if the line have to pares with this plugin
  if(ParesFlg)
   { 
      Ziron_ShowMessage(@line);                // show our entire line for debug purpose
    
      return true;
   }
  else
   {   
      return false;                           // let Ziron handle the line  
   }   
}


function InitPlugin(pointer pGetF) {
	Ziron_LoadAll(pGetF); //use framework utility function to load all
	
	//add some variable type
	const MyType = 'type HResult = DWord;';
        Ziron_Execute(@MyType,H_strlen(@MyType));

	//register our keyword
	Ziron_RegisterKeyword('function', @event_Pas);
	
	return strLoaded;
}

entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
  if (iReason == DLL_PROCESS_ATTACH) {
    return true;
  }

  return false;
}

exports InitPlugin;

any suggestion ?

http://www.freewebs.com/ogremagic/index.htm

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

I don't believe i understand the purpose of this one...

Colin admin
Posts
928
Threads
49
Location
Bulgaria

btw.. i also think that consts and types should not be hardcoded in, since they may interfere with inbuilt or users file and types - a better alternative is to supply an additional zir file with the types inside, this allows for flexibility - such as removing or changing some of them..

ps. I began adding some compatibility files such as pascal_compat.zir which contains some of the pascal variable types.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

the main purpose of this plugIn is , if you have a pascal header file that contains functions

declaration , you do not have to convert it manually to work with ziron , instead you use

this plugin that make Zrion will understand this header file.

i agree with you , i will remove type from plugin and supply ziron header that contains

the types needed by plugin.

hope you got my point , so what do you think?

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

It is an interesting idea, to do this via a plugin, however what would be much better and more efficient is if the plugin converts the header file then outputs/writes the conversion to a ziron header file.

I plan to write a software to convert pascal/c includes to ziron includes at some point :)

but still will be interesting to see this from a plugin aswell, allowing people to more quickly port their pascal programs.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

i think , creating converter that will convert pascal/c headers to Ziron header is better if you have a big file.

but plugin is a quick and simple way that let ziron handle the pascal syntax.

the problem i have faced now , i was using ':' in parameter to peek a pascal function , so

suppose that pascal function has no parameter at all. how to peek it ?

one solution is to use #Pas #EndPas directives and put pascal stuff inside them.

so what is your opinion?

   

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

of course the directives will be processed by plugin in FileEntry.

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

a custom directive would be a good option, else for params you check for token ( - zirOpenParen