AIR-Lang@Wiki

言語ハッキング方法 ( Hack AIR-Engine! )

最終更新:

air-lang

- view
だれでも歓迎! 編集



How to hack the Reserved Keyword. (予約語)


  • Open "parser/flex.l" and seek definition statement which includes the Reserved Keyord or its Alias Name you want to hack, in the function named chk_rsvdkeywd().
  • ファイル "parser/flex.l" を開き、ハックしたい予約語、又は、その別名を含む定義文を、関数 chk_rsvdkeywd() の中から検索します。

Example: "elif"

 extern int chk_rsvdkeywd(char *str){
   ...
   if( strcmp(str,"elif")==0 ){ _f("[ELIF]",0); return(ELIF); }
   ...
 }

Each token in AIR-Script Program is extracted and passed to this function, chk_rsvdkeywd(), to check whether it is a Reserved Keyword or not. 1st parameter, str, is a string to be checked.

Function _f() is a debug function in flex scanner. It displays debug message with line number if "-f" option is given to AIR-Engine. So you can just ignore it.

ELIF is a termnal symbol defined in bison parser. It will be reduced to if_stmt non terminal symbol, if correct 'if' statement comes in.

Example: Change Keyword from "elif" to "elseif"

 extern int chk_rsvdkeywd(char *str){
   ...
 //if( strcmp(str,"elif")==0 ){ _f("[ELIF]",0); return(ELIF); }
   if( strcmp(str,"elseif")==0 ){ _f("[ELIF]",0); return(ELIF); }
   ...
 }

Example: Define "elseif" as Alias Name for "elif"

 extern int chk_rsvdkeywd(char *str){
   ...
   if( strcmp(str,"elif")==0 ){ _f("[ELIF]",0); return(ELIF); }
   if( strcmp(str,"elseif")==0 ){ _f("[ELIF]",0); return(ELIF); }
   ...
 }

Example: Remove Keyword of "elif"

 extern int chk_rsvdkeywd(char *str){
   ...
   if( strcmp(str,"(N/A)")==0 ){ _f("[ELIF]",0); return(ELIF); }
   ...
 }

Identifier of "(N/A)" cannot be a valid token in AIR-Lang, so it will never passed to this function. Or you can just remove this line completely.



How to hack the Built-In Constants. (組み込み定数)


  • Open "admin/inst_syscnst.c" and seek definition statement for Built-In Constant you want to hack, in the function named inst_syscnst(void).
  • ファイル "admin/inst_syscnst.c" を開き、ハックしたい組み込み定数の定義文を、関数 inst_syscnst() の中から検索します。

Example: "M_PI"

 void inst_syscnst(int s_argc,char *s_argv[]){
     ...
     wr_dtab(GL_DTAB,"M_PI",'D',M_PI);
     ....
 }

Each system built-in constat is installed into AIR-Engine by inst_syscnst(), by using wr_dtab() function. Parameters to this function is as follows.

   # GL_DTAB = This identifier "M_PI" has global scope.
   # "M_PI"  = Name of Identifier, which can be seen from AIR-Script Program.
   # 'D'     = Value type of this identifier. ( 'D'  = Double     )
   # M_PI    = Initial Value to be installed. ( M_PI = 3.1415 ... )

Example: Change Name from "M_PI" to "PI"

 void inst_syscnst(int s_argc,char *s_argv[]){
     ...
     wr_dtab(GL_DTAB,"PI",'D',M_PI);
     ....
 }

Example: Remove Name of "M_PI" completely

 void inst_syscnst(int s_argc,char *s_argv[]){
     ...
     ....
 }

Example: Define *NEW* Name of "ONE","TWO", and "THREE" in double

 void inst_syscnst(int s_argc,char *s_argv[]){
     ...
     wr_dtab(GL_DTAB,"ONE"  ,'D',1.0);
     wr_dtab(GL_DTAB,"TWO"  ,'D',2.0);
     wr_dtab(GL_DTAB,"THREE",'D',3.0);
     ....
 }

Example: Define *NEW* Name of "ONE","TWO", and "THREE" in integer

 void inst_syscnst(int s_argc,char *s_argv[]){
     ...
     wr_dtab(GL_DTAB,"ONE"  ,'I',1);
     wr_dtab(GL_DTAB,"TWO"  ,'I',2);
     wr_dtab(GL_DTAB,"THREE",'I',3);
     ....
 }



How to hack the Built-In Functions. (組み込み関数)


  • Open "admin/inst_sysfunc.c" and seek definition statement for Built-In Function you want to hack, in the function named inst_sysfunc(void).
  • ファイル "admin/inst_sysfunc.c" を開き、ハックしたい組み込み関数の定義文を、関数 inst_sysfunc() の中から検索します。

Example: "cos()"

 void inst_sysfunc(void){
     ...
     wr_dtab(GL_DTAB,"cos",'X',i_cos,1);
     ....
 }

Each system built-in function is installed into AIR-Engine by inst_sysfunc(), by using wr_dtab() function. Parameters to this function is as follows.

   # GL_DTAB = This identifier "cos" has global scope.
   # "cos"   = Name of Identifier, which can be seen from AIR-Script Program.
   # 'X'     = This identifier is Built-In Function.
   # i_cos   = Internal function name for this identifier. ( Exist in icode/ )
   # 1       = Parameter Count of this function.

Example: Change Keyword from "cos()" to "cosine()"

 void inst_sysfunc(void){
     ...
     wr_dtab(GL_DTAB,"cosine",'X',i_cos,1);
     ....
 }

Example: Define "cosine()" as Alias Name for "cos()"

 void inst_sysfunc(void){
     ...
     wr_dtab(GL_DTAB,"cos",'X',i_cos,1);
     wr_dtab(GL_DTAB,"cosine",'X',i_cos,1);
     ....
 }

Example: Remove "cos()"

 void inst_sysfunc(void){
     ...
     wr_dtab(GL_DTAB,"(N/A)",'X',i_cos,1);
     ....
 }

Identifier of "(N/A)" cannot be a valid function name in AIR-Lang, so it will disable this function. Or you can just remove this line completely.

FYI (参考)

  • If you want to change its internal behavior, seek "i_cos.c" in "icode/" and modify it for your purpose.
  • もし、その関数の内部動作を変更したい場合は、"icode/*" 中から "i_cos.c" を探し、その内容を変更してください。

Define *NEW* Built-In Function: "log3()"

  • The best way to define *NEW* built-in function is to utilize pre-existing functions. In this case "log2()" would be a good sample.
  • 新しい組込み関数を定義する最良の方法は、既にある関数を利用することです。この場合は、関数 "log2()" を利用するのがベストとなります。
  1. Seek source code file for log2() in icode/*. In most cases file name for built-in function is "i_" + name + ".c". ( In this case, its "i_log2.c". )
  2. Copy i_log2.c to i_log3.c in the same directory layer.
  3. Edit i_log3.c so that it will return log3().
  4. Here is the source.
/****************************************************************************/
// i_log2.c
/****************************************************************************/

#include    "air.h"

void i_log2(void){      /*** AIR-Lang: a=log2(x) ***/

char    *fx="log2()";               /* Function Name                        */
dtab    *a,*x;                      /* Pointer to AIR-Script Variables      */

/* Set Parameters */
    if(set_iparam1(fx,&a,&x,"ID")!=TRUE)
        pterm(EXIT_FAILURE);

/*--------------------------------------------------------------------------*/
// Do log2()!!
/*--------------------------------------------------------------------------*/
    a->type='D';
    a->dval=log2(cdbl(x));

}

*a is a return value from log2(). ( struct dtab is defined in air.h )

*x is a parameter value to log2().

set_iparam1() sets parameter of log2() to *x, but it only accepts if it is 'I'nt or 'D'ouble.

*a->type='D'; sets return type as 'D'ouble.

*a->dval=...; sets return value in a storage area for 'D'ouble.

cdbl(x) casts numerical value into 'D'ouble. ( cdbl = cast-double )

  1. In this case, substitude /log2()/log3()/ at first, then replace "*a->dval=log3(cdbl(x))" line like this.
        a->dval=log10(cdbl(x))/log10(3.0);
    
  2. After preparing i_log3.c, you need to declare this function correctrly to supress compiling waring message from GCC.
  3. Open "admin/ifunc.h" and seek declaration line for i_log2() then insert i_log3() declaration like this. (before)
     extern void     i_log(void),i_log2(void),i_log10(void);
    
    (after)
     extern void     i_log(void),i_log2(void),i_log3(void),i_log10(void);
    
  4. Then install it AIR-Engine as built-in function.
  5. Open "admin/inst_sysfunc.c and seek definition line for log2() then insert log3() definition like this. (before)
     wr_dtab(GL_DTAB,"log"  ,'X',i_log  ,1);
     wr_dtab(GL_DTAB,"log2" ,'X',i_log2 ,1);
     wr_dtab(GL_DTAB,"log10",'X',i_log10,1);
    
    (after)
     wr_dtab(GL_DTAB,"log"  ,'X',i_log  ,1);
     wr_dtab(GL_DTAB,"log2" ,'X',i_log2 ,1);
     wr_dtab(GL_DTAB,"log3" ,'X',i_log3 ,1);
     wr_dtab(GL_DTAB,"log10",'X',i_log10,1);
    



How to hack Colon Command. (コロンコマンド)


  • Open file "parser/flex.l" and seek Regular Expression Pattern for Colon Command you want to hack. Then change its pattern or action according to your need. Refere to flex(1) manual in detail.
  • ファイル parser/flex.l を開き、ハック対象とするコロンコマンドの正規表現パターンを検索します。そしてそのパターン又はアクションをお好みに応じて変更して下さい。詳細については flex(1) マニュアルを参照して下さい。

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

記事メニュー
目安箱バナー