Trans Extension
Monkey Targets Forums/Desktop/Trans Extension
| ||
| Hi ALL, here is version 0.3 of monkey Ext. included source code. http://bcxdx.spoilerspace.com/Monkey/TransExt0.3.zip Enjoy it. |
| ||
| What's this? |
| ||
| A clone of Monkey Ext? https://code.google.com/p/monkey-ext/ [edit] I guess not... |
| ||
| It's transcc with an extendend preprocessor. |
| ||
| What I can see is that you can do "inline" C... but I don't really see any benefit over the extern system... is there anything else it does? |
| ||
| Hi all, actually TRANS EXTENSION is the original transcc with some added new features. 1- adding Cpp code with Monkey code by using inlineC-endC keyword or by ! symbol Example
!DWORD put( String a ) {
! bbPrint( a );
!}
inlineC
// Inline c in declration area
endC
Extern
Function put:Int(a:String)
Public
Function Main:Int()
Local kiro:Int = 20
Print kiro
inlineC
// Inline c source code
t_kiro=200;
endC
! /* Inline Sym C */
! bbPrint(String(t_kiro));
put("Monkey Ext is very good")
Return 0
End
BTW , inline , is a reserved word and i do not know it will be for. 2-added Enum keyword to monkey Example
Enum
ONE,TWO,THREE
EndEnum
Enum
AA,BB=10+4,CC,PP=60,ZZ
ENUM_1 = 1 ' restart at 1
ENUM_2 = CC ' 15
ENUM_3 ' Err should print 16
End
Enum 20
ENUM_4 ' will start at 20
ENUM_5 ' will be 21
End Enum
Enum 50*10 Step 5*10
ENUM_6 ' will start at 500
ENUM_7 ' will be 550
ENUM_8 ' will be 600
EndEnum
Enum
ENUM_10 = 1 Shl 0
ENUM_11 = 1 Shl 1
ENUM_12 = 1 Shl 2
ENUM_13 = 1 Shl 3
EndEnum
Class ABC ' enum in class
Enum 50 Step 5
ENUM_14 ' will start at 50
ENUM_15 ' will be 55
ENUM_16 ' will be 60
End
Enum DEF
ENUM_17
ENUM_18
ENUM_19
End
End
Enum POINT
TA,TB,TC
EndEnum
Enum Option
INVALID = -1
NONE = 0
A = 1
B = 2
C = 4
D = 8
End Enum
Function Main:Int()
Print ONE
Print TWO
Print THREE
Print AA
Print BB
Print CC
Print PP
Print ZZ
Print ENUM_1
Print ENUM_2
Print ENUM_3
Print ENUM_4
Print ENUM_5
Print ENUM_6
Print ENUM_7
Print ENUM_8
Print ENUM_10
Print ENUM_11
Print ENUM_12
Print ENUM_13
Print POINT.TA
Print POINT.TB
Print POINT.TC
Print ( Option.A | Option.B ) 'Prints 3
Local everything:Int = Option.A | Option.B | Option.C | Option.D
Print ( everything ) 'Prints 15
If HasFlag(everything, Option.D) Then Print "True" Else Print "False" 'Prints True
Print ABC.ENUM_14 ' Enum in class
Print ABC.ENUM_19 ' Err must be ABC.DEF.ENUM_19
Local currentOption:Option 'Declares as an Enum type
' currentOption = Option.C ' Err connot convert from Int to Option
' Print currentOption 'Prints 4
Return 0
End
Function HasFlag?(value:Int, flag:Int)
Return (value & flag = flag)
End Function
3- extend import keyword to accept a library that to be linked with ore code Example
Import -lcomdlg32
inlineC
//' Returns an empty String If dialog is cancelled
static String openfilename() {
const char *filter = "All Files (*.*)\0*.*\0";
HWND owner = NULL;
OPENFILENAME ofn;
char fileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = owner;
ofn.lpstrFilter = filter;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "";
String fileNameStr;
if ( GetOpenFileName(&ofn) )
fileNameStr = fileName;
return fileNameStr;
}
endC
Extern
Function OpenFileName:String() = "openfilename"
Public
Function Main:Int()
Print OpenFileName()
Return 0
End
BTW , for MSVC using #LIBS will make it. 4- allow using #CC_OPTS with desktop target to accept g++ option that will pass while building monkey code. 5- allow import keyword to accept header files .h and c files , with c file it will automatically enclosed it with Extren "C"{} trem. those are what i have done till now , more will be coming. thanks |
| ||
| Hi all, this time i bring to you my new features that added to Trans_ext. extend "Import" keyword so that it accept header files [zlib.h] to main.cpp file, also accept's c files [Myfile.c]. add keyword "PrjImport" that accepts many file format to the project , not well , the file that import with PrjImport will not insert into mai.cpp but will compile with it's compiler then linked with the main obj file. here is the file formats and it's corresponding compiler. 1- c/c++ -----------> compile with g++. 2-o(obj file) ----------> added to the link obj files table. 3-asm -----------> compile with Fasm assembler. 4- S(gas asm)--------> compile as gas assembler. 5 zir(High Level asm) -----> compile with Ziron assembler. her is an example that demonstrate the new features
// this is the main file
Import Archive
Function Main:Int()
Print MySquare(10) 'test fasm routin
Local dststr:String="welcome"
Local srcstr:String="1234567"
H_strcpy(STRPTR(dststr),STRPTR(srcstr))
Print dststr
Return 0
End
// this is Archive.monkey file
Import os
#CC_OPTS+="-ID:\MonkeyX\MagicPro\zlib"
#CC_OPTS+="-ID:\MonkeyX\MagicPro\Encrpt"
Import -lwininet
PrjImport "zlib/adler32.c"
PrjImport "zlib/compress.c"
PrjImport "zlib/crc32.c"
PrjImport "zlib/deflate.c"
PrjImport "zlib/infback.c"
PrjImport "zlib/inffast.c"
PrjImport "zlib/inflate.c"
PrjImport "zlib/inftrees.c"
PrjImport "zlib/ioapi.c"
PrjImport "zlib/trees.c"
PrjImport "zlib/uncompr.c"
PrjImport "zlib/unzip.c"
PrjImport "zlib/zip.c"
PrjImport "zlib/zutil.c"
PrjImport "Resource/resource.cpp"
PrjImport "Encrpt/Encryptor.cpp"
PrjImport "asm/test.asm"
PrjImport "S/as_test.s"
PrjImport "zir/z_test.zir"
Import "zlib/zlib.h"
Import "Encrpt/Encryptor.h"
! CEncryptor Encrpt(0xFFDDCCAA);
! Extern "C" Int MySquare ( Int val);
! Extern "C" Void __stdcall H_strcpy (DWORD dst,DWORD src);
Extern
Function MySquare:Int(Val:Int) = "MySquare"
Function H_strcpy:Void(dest:CHARPtr,source:CHARPtr) = "H_strcpy"
Public
// here is z_test.zir file
program MSCOFF 'test';
#define APPTYPE_LIB;
#include 'win_def.zir';
#Include 'console.zir';
function H_strcpy(Dword dst, src)
{
uses edx ebx;
Eax = dst;
Edx = src;
push Eax;
BX = word[Edx];
while ( BX != 0)
{
word[Eax] = BX;
Eax++; Edx++;
BX = word[Edx];
}
word[Eax] = 0;
pop Eax;
}
exports H_strcpy;
// this is test.asm file
format COFF
public _MySquare
section "code" code
_MySquare:
push ebp
mov ebp,esp
mov eax, dword [ebp+8]
imul eax,eax
mov esp, ebp
pop ebp
ret
//this is as_test.s file
.text
LC0:
.ascii "Hello, world!\12\0"
.globl s_test
s_test:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl $LC0, (%esp)
call _printf
movl $0, %eax
leave
ret
.intel_syntax noprefix
.globl inteltest
inteltest:
push ebp
mov ebp, esp
mov eax, dword [ebp+8]
imul eax,2
leave
ret
.att_syntax noprefix
i have add fasm.exe and ziron.exe and it's stuff with the mingw folder for easy access of those compilers and assemblers. i will post then new trans with it's depended sooner. this will work only with gcc. Enjoy with extended monkey. |
| ||
| Sounds like an awesome extension and very handful for some here. |
| ||
| thanks Mike for your nice word. |
| ||
| Nice, could be very useful in the future, well done Emil! |