Author Topic: small universal language  (Read 2452 times)

0 Members and 1 Guest are viewing this topic.

Emil_halim

  • Guest
small universal language
« on: February 07, 2015, 07:40:43 AM »
hi all ,

my main goal is to make a compiler that will understand small basic of many programming languages syntax, such as C,pascal,basic,powerbasic, sphinx c--,asm,Amiga BlitzBasic2 , Oxygen basic ,and so on.

at the same time i want it to be simple and easy , so i have pick up the small C and tried to extend it.

i have made some progress in that , if any one interested and want to contribute me , i will go ahead
and post the project here .

  Charles , i think you kindly well help me , you have a good experiences in this way.       

Edited ,
   till now i did not diced the name of this language , any suggestion will be welcom.
   so any user , what ever his language will start using it with no difficult and learn another language
syntax.   

thanks
« Last Edit: February 07, 2015, 07:47:58 AM by Emil_halim »

Charles Pegge

  • Guest
Re: small universal language
« Reply #1 on: February 07, 2015, 01:47:07 PM »
Emil,

You have got yourself a lifetime's project. Good luck! I was going to suggest NILE, though it has been used already in some phD project (2010-2012).

Emil_halim

  • Guest
Re: small universal language
« Reply #2 on: February 17, 2015, 11:32:08 AM »
Hi Charles,

I think that, because of using Fasm as a backend  of Small c , i will name it something related to Fasm. may be universalFasm.....

here is a small Example ,

Code: [Select]
//
//  test program
//

$ format PE GUI  //this is inline asm

$ entry main   

       
$ include 'MACRO/PROC32.inc'

extern  stdcall MessageBoxA();



/*  Fasm Proc syntax */

proc itoa  value,buf,base

  local table db '0123456789ABCDEF' ;Table used in conversion

  cmp  [base],16      ;Nothing over base 16(Hex) is supported. You could add support for them by just modifying this line and the table above
  ja   .base_error
  cmp  [base],2       ;Nothing below base 2 is supported
  jb   .base_error

  pushad              ;Save the registers. No one likes a procedure that thrashes everything

  mov  eax,[value]    ;Load up the registers
  mov  ebx,[base]
  mov  edi,[buf]
  mov  edx,0          ;Important note if you didn't know this, division by a dword is a 64-bit divide, edx will interfere if it's not cleared
                      ;Division by a dword does edx:eax div r/m32      where edx:eax is treated as one 64-bit number

  push 0xFFFF         ;This push is used later in the reversing part, it tells it that it's done.

  @@:
    or   eax,eax      ;Is the value to convert zero?
    jz   .reverse     ;If so, we're done here, lets reverse it.
    div  ebx          ;Else, divide it by the base.  Result stored in eax, remainder in edx
    lea  edx,[edx+table] ;Point edx to the byte in the table holding the value we need
    movzx edx,byte[edx]  ;Put that byte in edx
    push edx             ;Push it
    mov  edx,0           ;and as I explained earlier, edx MUST be zero before the next divide, or it will interfere with the divide
    jmp @b               ;Lather, rinse, and repeat



;The routine above gets the numbers backwards, so we must reverse them.
  .reverse:
    pop  eax          ;Pop a converted value off the stack
    cmp  eax,0xFFFF   ;Are we done reversing(was the popped value the 0xFFFF we pushed before we started)?
    je   @f
    stosb             ;If not, store the byte in the buffer
    jmp  .reverse

  @@:
    mov  eax,0        ;The string needs to be zero terminated, so this just places a 0x0 at the end
    stosb

  popad
  mov  eax,0          ;Out: eax = 0, everything went fine
  ret

  .base_error:
    mov  eax,-1       ;Out: eax = -1, Bad base
    ret
endp

/*   c function Sytax */
print(x)
 int x;
{
    char buf[255];
    itoa(x,buf,10);
    MessageBoxA(0,buf,"the Value Is",0);
}



main()
{
   
   int k,m,c;
 
   k = 10;
   m = 20;
   c = m + k;
   
   print(c);
}


#asm

section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dd RVA _ExitProcess
    dd 0
  user_table:
    MessageBoxA dd RVA _MessageBoxA
    dd 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0

section '.reloc' fixups data readable discardable       ; needed for Win32s
           
#endasm           

 
i will post that in Fasm forum also.