How to Add New Targets?
Monkey Forums/Monkey Programming/How to Add New Targets?
| ||
So how does one do it? I guess the source code of Trans needs to be altered: * In the modules/trans folder create the new translator file * In the modules/trans folder alter trans.monkey to add the import to the new translator * In the src/trans/targets folder create the new target file * In the src/trans/targets folder alter targets.monkey by adding the new target * In the src/trans folder alter target.monkey by adding the new target paths etc When I did this and tried to compile trans it can not see the new translator!? How does it see the current translators (eg _trans=New JavaTranslator)? Anything else? Are the targets template files needed? |
| ||
Okay making progress... Looks like I forgot to save a file when I was compiling... Also you must always do a clean when building trans!!! Now in the new translator file you have a method called IsValid: Function IsValid() If FileType( "android" )<>FILETYPE_DIR Return False ... End So this checks the file type "android" with FILETYPE_DIR... FILETYPE_DIR is a constant with the value 2, hows does FileType("new") work, mine is always returning 0 (zero)?? |
| ||
Hi, You also need to add a 'newtarget' dir to the top level 'targets' dir that contains the target template stuff. This is what the FileType code is checking for. A lot of this will eventually be cleaned up (it's all getting a bit hacky), but it should be easy to reuse whatever you come up with. Also, you should only have to modify 'targets/targets.monkey' and add your new targets/newtarget.monkey file. You shouldn't have to touch trans.monkey itself. I think. |
| ||
??? I don't get it! |
| ||
Hi, Ok, step by step: 1) Create a '/targets/mytarget' dir. This is where your target 'project template' code goes. 2) Save the following as '/src/trans/targets/mytarget.monkey': 3) Change '/src/trans/targets/targets.monkey' to: Untested, but should do the trick. It wont actually do anything of course, but should show up in the IDE. |
| ||
Thanks Marks, I was missing the 'newtarget' dir to the top level 'targets' dir stuff. Also I had to alter trans.monkey: Function LoadConfig() .... Select lhs Case "ANDROID_PATH" .... Case "NEW_TARGET_PATH" If Not NEW_TARGET_PATH And FileType( path )=FILETYPE_FILE NEW_TARGET_PATH=path Endif |
| ||
Ahh, ok. I got that now. Thanks for the explanation. |
| ||
Hi, > Also I had to alter trans.monkey: Yes, if you need something from config, then you'll have to hack trans.monkey. Perhaps I should move LoadConfig to targets.monkey? That way, you'd still only have to modify one file. |
| ||
Sounds good to me :) |
| ||
Hi, Just curious, but what target are you adding? |
| ||
BlitzMax ;) |
| ||
Hmmmm For loops seems to be an issue... It looks like it has already been partly processed in the format (c=0;c<10;c++) in parser.monkey and I dont want to be changing that file!! Any clues please? |
| ||
OOOOooKay, I've hacked together the TransForStmt:Method TransForStmt$( stmt:ForStmt ) Local nbroken=broken Local init$=stmt.init.Trans() Local expr$=stmt.expr.Trans() Local incr$=stmt.incr.Trans() Local splitExpr:= expr.Split(" ") Local splitIncr:= incr.Split(" ") Local bmaxExpr$ = splitExpr[1] Local bmaxIncr$ = splitIncr[2] if bmaxExpr="<=" or bmaxExpr=">=" bmaxExpr = "To" Else if bmaxExpr="<" or bmaxExpr=">" bmaxExpr = "Until" End Emit "for "+init+" "+bmaxExpr +" "+splitExpr[2]+ " Step "+ bmaxIncr Local unr=EmitBlock( stmt.block ) Emit "next" If broken=nbroken And ConstExpr( stmt.expr ) And ConstExpr( stmt.expr ).value unreachable=True broken=nbroken End It works... but I hope there is a better way... :/ |
| ||
OOOOooKay, I've hacked together the TransForStmt:Method TransForStmt$( stmt:ForStmt ) Local nbroken=broken Local init$=stmt.init.Trans() Local expr$=stmt.expr.Trans() Local incr$=stmt.incr.Trans() Local splitExpr:= expr.Split(" ") Local splitIncr:= incr.Split(" ") Local bmaxExpr$ = splitExpr[1] Local bmaxIncr$ = splitIncr[2] if bmaxExpr="<=" or bmaxExpr=">=" bmaxExpr = "To" Else if bmaxExpr="<" or bmaxExpr=">" bmaxExpr = "Until" End Emit "for "+init+" "+bmaxExpr +" "+splitExpr[2]+ " Step "+ bmaxIncr Local unr=EmitBlock( stmt.block ) Emit "next" If broken=nbroken And ConstExpr( stmt.expr ) And ConstExpr( stmt.expr ).value unreachable=True broken=nbroken End It works... but I hope there is a better way... :/ |
| ||
Ahh heres a new little problem when creating a new target: Monkey is case-sensitive (Yay!)... but your new target isnt (Boo!): Monkey code: Local x:Float = 2.4 Local X:Int = 2 Print "Local x="+x Print "local X="+X Guess what happens in the new target language ;) |
| ||
Interesting idea. Just one question how are you intending to translate overloaded methods? |
| ||
translate overloaded methods? Basically this: Class Foo Method Bar:Int(a:Int) End Method Bar:Int(a:String) End End Becomes: Type Foo Method Bar1:Int(a:Int) End Method Method Bar2:Int(a:String) End Method End Type Monkey already does this for Flash anyway ;) |
| ||
I've got a simple class now working:Class Sprite Field x:Float, y:Float Function Test:Void() Print "Sprite Test" End Method New() Print "New Sprite" x = 100 y = 100 End Method Draw:Void() Print "Draw" End Method Draw:Void(x:Int, y:Int) Print "Draw2" End End Translates to: Type bb_Sprite Field bb_x:float=.0; Field bb_y:float=.0; Method bb_Sprite_new:bb_Sprite() print("New Sprite"); self.bb_x=100.0; self.bb_y=100.0; return self; EndMethod Method bbm_Draw:int() print("Draw"); EndMethod Method bbm_Draw2:int(bbt_x:int,bbt_y:int) print("Draw2"); EndMethod Function bb_Test:int() print("Sprite Test"); EndFunction EndType Anyone want to help with interfaces? :P |
| ||
Cool project :) |
| ||
Ta... its going pretty well, I'm currently just working on the Monkey Language to BlitzMax at the moment... Also I am working on a test file, which covers all the basic Monkey stuff: * If statements * Loops (For, While, Repeat) * Maths (+ / * - += -= Mod Shr Shl, Cos, Sin, Tan etc) * Objects (extends, abstract) - Havent done interfaces yet (not sure how!) * Functions * Arrays * Basic types (ints, floats, strings etc) Have I missed anything? Once this is working well, I'll move onto Mojo to BlitzMax, where the real fun is ;) |
| ||
If you manage to get this working Therevills, I will be very happy :D |
| ||
Me too! |
| ||
Hmmmmm to translation from ~n to \n is in config.monkey :( [edit] Which is called in translator.monkey Enquotes$... cool! Back on track! [/edit] |
| ||
does this help with mojo? http://www.blitzbasic.com/codearcs/codearcs.php?code=2612 you can use glmatrix to set the matrix (the main command needed by mojo) BTW would it be possible to make a blitzmax=>Monkey convertor? |
| ||
I haven't even started looking into the Mojo stuff yet... but I wouldn't want to use a 3rd party add on, it needs to be pure BlitzMax. Thanks anyway. You "could" I guess do a pure BlitzMax to Monkey, but you would lose stuff in the process eg doubles would turn into floats etc. |
| ||
the thingy that i linked to is pure blitzmax, its just code a blitzmax-monkey convertor would be amazing |
| ||
is pure blitzmax, its just code Yeah I know it just code :P (it does import bah.libxml) But its not "pure" BlitzMax graphics, also its just OpenGL (I want to be able to use DX and OpenGL). I also want my MojoMax (just thought of that... patent pending :P) to just call BlitzMax commands where possible. a blitzmax-monkey convertor would be amazing Off you go then ;) |
| ||
This sounds brilliant! :) Dabz |
| ||
Well hopefully it will be... if I get it all to work ;) Going to charge the cheap, cheap price of one million dollars, buy now save later :P Just been fighting new line characters, as Monkey uses ~n and BlitzMax uses ~n, but if you dont change ~n it will add a new line character into the actually source code not ~n!!! Found out if you replace ~n with ~~n it works! That only took about an hour to find out!!! :/ |
| ||
Going to charge the cheap, cheap price of one million dollars, buy now save later :P Hopefully, that'll be interest-free with no deposit... If so, I'll buy 15 of them thank you please that'll do nicely! Dabz |
| ||
Thankfully I haven't started to use Interfaces yet - and I guess I'd better stick to not using them if they turn out to be a requirement for the Blitzmax Target! Since I don't want to miss that ;) |
| ||
I do want to add interfaces somehow... when I get around to it, I'll have a look at the HTML5 and C++ trans stuff as I think that there are the current targets which doesn't support interfaces natively. I was fighting Arrays yesterday, its nearly there... but at the moment the code only support 2 levels of Array of Arrays eg Local array[][]. |
| ||
Last night I tried adding TList (well a StringList)... BlitzMax has an Object class... but to instaniate it you need to do it using an array!?! bb_Node.bb__sentinal=(new Object[0]); So I'm not sure if this is the correct approach... Later the StringList spits out this code: Type bb_StringList extends bb_List Method bb_StringList_new:bb_StringList() super.bb_List_new(); return self; EndMethod Method bbm_Equals:Int(bbt_lhs:Object,bbt_rhs:Object) Local bbt_lhs2:bb_StringObject=(bb_StringObject)bbt_lhs Local bbt_rhs2:bb_StringObject=(bb_StringObject)bbt_rhs return bbt_lhs2.bb_value = bbt_rhs2.bb_value; EndMethod EndType And BlitzMax gives me this error: Compile Error: Unable to convert from 'Type' to 'bb_StringObject' Fun fun fun! :/ [edit] D'oh!! When you use Java during the day and casting works like this: (Int)x It is sometimes hard to go back to BlitzMax/Monkey where casting works like this: Int(x) So the above method should be: Method bbm_Equals:Int(bbt_lhs:Object,bbt_rhs:Object) Local bbt_lhs2:bb_StringObject=bb_StringObject(bbt_lhs) Local bbt_rhs2:bb_StringObject=bb_StringObject(bbt_rhs) return bbt_lhs2.bb_value = bbt_rhs2.bb_value; EndMethod [/edit] |
| ||
Yep that was the issue - Lists now work \o/ Monkey Code: Local spriteList:List<Sprite> = New List<Sprite> For Local i% = 0 To 10 spriteList.AddLast(New Sprite(Rnd(0,100), Rnd(0,10))) Next Print spriteList.Count() spriteList.Clear() Print spriteList.Count() If spriteList.IsEmpty() Print "EMPTY!!" End Generated BlitzMax Code: Local bbt_spriteList:bb_List=(New bb_List).bb_List_new(); For Local bbt_i:Int=0 To 10 Step 1 bbt_spriteList.bbm_AddLast((New bb_Sprite).bb_Sprite_new(bb_Rnd2(0.0,100.0),bb_Rnd2(0.0,10.0))); Next Print((bbt_spriteList.bbm_Count())); bbt_spriteList.bbm_Clear(); Print((bbt_spriteList.bbm_Count())); If(bbt_spriteList.bbm_IsEmpty()) Then Print("EMPTY!!"); EndIf |
| ||
how you have set the blitzmax compiler path? I get an error in my "target-project" : TRANS Failed to execute '"D:\Dev\AmiDevCpp"\usr\local\amiga\bin\m68k-amigaos-g++ -o main_winnt main.cpp', return code=1 i wonder about the quotes around the config string "D:\Dev\AmiDevCpp" |
| ||
The compiler path is set in the config.winnt.txt:'-------------------- ' BlitzMax path ' 'BMAX_PATH="C:\BlitzMax\1.42\bin\bmk.exe" |
| ||
this should get a sticky. and the OP should be cleaned up. if the peeps involved have the time to do it. |
| ||
Could somebody post step by step instructions how to add an own target to the newest version of Monkey? I tried to figure it out myself by reading through the sources, but it seems that I missed something (couldn't get the IDE to recognize my target). |
| ||
This changes once in a while as Monkey matures... Let me push that I have created a Custom Target target to allay these problems somewhat. I feel that to embrace new targets, people don't want any overhead other than copying and pasting files and adding a few lines of code. I sure don't and I make targets all the time! http://monkeycoder.co.nz/Community/posts.php?topic=4932 So currently (V67+), to add a new target: 1. Create a new builder in the src/transcc/builders folder (copy & edit one) 2. add the builder's class to the "builders.monkey" file in that same folder 3. rebuild transcc using the cpp_tool 4. copy trans_cc to the bin 5. create new target folder (copy an existing one) in targets folder 6. fill in the TARGET.MONKEY file appropriately 7. the templates and modules folders should be filled in appropriately. this differs for each target. |
| ||
3. rebuild transcc using the cpp_tool 4. copy trans_cc to the bin For these steps I created a batch file which automatically backs up the original trans, rebuilds trans and copies it over to the bin folder. Feel free to use it, its in the MonkeyMax repo. |
| ||
Thank you! That helped me to figure out what my mistake was. BTW the Custom Target is a good approach, I hope BRL will include it (or something similar) in future versions of the official monkey distribution. |
| ||
Stupid question alert! (I found Monkey not too long ago...I know nothing of blitzmax and brethren.) Why would you want to translate from monkey into blitzmax as a target? What would you get there that you don't already having with glfw? -Ken |
| ||
blitzmax is the predecessor to monkey and is aging, but more mature. What would you get there that you don't already having with glfw? - embed files into the exe - multithreading - directx7 - easier full screen/windowed switching ...i may have missed a couple, but to me it's all preference. |
| ||
Along with Adam's comments, BlitzMax has proven itself for the commercial world... I've yet to see a Monkey GLFW game in the wild making big money. |