MX2 bugs (github master 2016-03-27)
Community Forums/Monkey2 Talk/MX2 bugs (github master 2016-03-27)
| ||
Just installed current github master and found some problems with comments. Error on Line 1 of ' hello-world.monkey2 ‚ —> Unexpected token ‚#‘ #Rem #End Function Main() Print "Hello World!" End The workaround is to insert a comment line: ' #Rem #End Function Main() Print "Hello World!" End Another problem with comments: I paste sometimes C++ comments in MX2, but MX2 is scanning the comments (instead ignoring it): Error on Line 3 of ' hello-world.monkey2 ‚ —> Unexpected token ‘/‘ ' #Rem // C++ comment #End Function Main() Print "Hello World!" End The workaround is to insert a comment in front of // within #Rem/#End sections: ' #Rem '// C++ comment #End Function Main() Print "Hello World!" End EDIT: #Rem / #End doesn’t work at all: Unexpected token 'my': ' #Rem my comment #End Function Main() Print "Hello World!" End EDIT 2: Okay, #Rem is now lowercase and case-sensitive. This works: ’ #rem my comment // C++ comment #end Function Main() Print "Hello World!" End |
| ||
Is it correct that Public / Private / Protected are now blocks and require 'End‘? This wasn’t the case with MX2 Xmas demo v3: ' #rem my comment // C++ comment #end Extern #rem #end Class XYZ = "cpp::xyz" Public Method New() End ' end required for Public Protected Method xyz() End ' end required for Protected Private Method abc() End ' end required for Private End Public Function Main() Print("Hello World!") End Can’t get anything compiled that I wrote using Xmas demo v3. EDIT: The 'End' is now required for Extern method declarations! This compiles: ' #rem my comment // C++ comment #end Extern #rem #end Class XYZ = "cpp::xyz" public Method New() End protected Method xyz() End private Method abc() End Method def() End End Public Function Main() Print("Hello World!") End Do I need to add 'End‘ to all Extern method declarations now, or is it a bug? |
| ||
Extern declarations need parameter names now? This gives now Error: "Missing parameter identifier" Extern Function a:Int(Void) Function b:Int(Int) Now we need to add parameter names: Extern Function a:Int(a:Void) Function b:Int(b:Int) (Void could be omitted, of course) Is it correct that Extern function/method parameters require a name now? |
| ||
> Okay, #Rem is now lowercase and case-sensitive. This works: Will fix. Also, # on the first line is broken. > Is it correct that Extern function/method parameters require a name now? Yes, but this could be relaxed. However, externs are auto-docced when you makedocs so it's nice if params have names... Not sure what's up with your other extern problems though. Can you run tests/monkey/externs.monkey2? |
| ||
Ok, I am having some issues with using public/protected etc inside extern classes. Will fix! |
| ||
Yes, when using Public / Private / Protected within Extern class declarations, the methods need ‚End‘. Without Public/Private/Protected it works: ' Extern #rem #end Class X 'Public Method New() 'End 'Protected Method xyz() 'End 'Private Method abc() 'End Method def() 'End End Public Function Main() Print("Hello World!") End Thanks! |
| ||
public/private/protected were 'turning off' extern the way they do at file scope! |
| ||
Ok, just committed some parser fixes for everything except '#' on first line. After git fetch/merge, you should be able to just ./updatemods.sh followed by ./updatemx2cc.sh to rebuild the compiler. |
| ||
Thanks, MX2 can compile my stuff now. I’m getting C++ errors now because it can’t find namespaces.Parsing... Semanting... Translating... Compiling.... Build error: System command 'g++ -std=c++11 -g -std=c++11 -Wno-deprecated-declarations -Wno-tautological-pointer-compare -Wno-undefined-bool-conversion -Wno-int-to-void-pointer-cast -Wno-inconsistent-missing-override -Wno-logical-op-parentheses -O0 -Wno-int-to-pointer-cast -Wno-parentheses-equality -Wno-comment -I"/Users/danilo/Monkey/monkey2/modules/monkey/native" -c -o "/Users/danilo/Monkey/SOURCES/Irrlicht/examples/test3.buildv002/build_cache/desktop_debug_macos/test3_0test3.cpp.o" "/Users/danilo/Monkey/SOURCES/Irrlicht/examples/test3.buildv002/build_cache/desktop_debug_macos/test3_test3.cpp"' failed. g++ -std=c++11 -g -std=c++11 -Wno-deprecated-declarations -Wno-tautological-pointer-compare -Wno-undefined-bool-conversion -Wno-int-to-void-pointer-cast -Wno-inconsistent-missing-override -Wno-logical-op-parentheses -O0 -Wno-int-to-pointer-cast -Wno-parentheses-equality -Wno-comment -I"/Users/danilo/Monkey/monkey2/modules/monkey/native" -c -o "/Users/danilo/Monkey/SOURCES/Irrlicht/examples/test3.buildv002/build_cache/desktop_debug_macos/test3_0test3.cpp.o" "/Users/danilo/Monkey/SOURCES/Irrlicht/examples/test3.buildv002/build_cache/desktop_debug_macos/test3_test3.cpp" /Users/danilo/Monkey/SOURCES/Irrlicht/examples/test3.buildv002/build_cache/desktop_debug_macos/test3_test3.cpp:31:5: error: use of undeclared identifier 'irr' irr::IrrlichtDevice* l_device{}; ^ /Users/danilo/Monkey/SOURCES/Irrlicht/examples/test3.buildv002/build_cache/desktop_debug_macos/test3_test3.cpp:32:5: error: use of undeclared identifier 'irr' irr::video::IVideoDriver* l_driver{}; ^ /Users/danilo/Monkey/SOURCES/Irrlicht/examples/test3.buildv002/build_cache/desktop_debug_macos/test3_test3.cpp:33:5: error: use of undeclared identifier 'irr' irr::scene::IAnimatedMesh* l_mesh{}; ^ […snip...] I use: #Import "includes/irrlicht.h“ …but somehow MX2 does not include it anymore. It is not included in test3_test3.h nor test3_test3.cpp! A separate file is generated: test3__1Irrlicht.h: #ifndef MX2_TEST3__1IRRLICHT_H #define MX2_TEST3__1IRRLICHT_H #include <bbmonkey.h> #include <OpenGL/gl.h> #include "../../../../includes/irrlicht.h" // ***** External ***** // ***** Internal ***** #endif This file is not included anywhere in the app headers. EDIT: Okay, if I #Import a .h file within the main source, it works. If the .h file is included in another irrlicht.monkey2 file, it is not included correctly and I get C++ errors. |
| ||
BTW: What is the replacement for CChar Ptr, WChar Ptr, and string.ToWString() etc? :) |
| ||
If you use 'End‘ with Extern method declarations, it crashes the compiler:Parsing... Semanting... ***** Uncaught Monkey 2 Exception: Memory access violation ***** Test code: ' Extern Class X Method New() End ' put here by accident (or by IDE method completion) Method xyz() Method abc() Method def() End Public Function Main() Print("Hello World!") End The 'End‘ is taken for the ‘Class‘, and the following method declarations crash the compiler - probably because there is no current class/context. Maybe you want to catch that and harden/stabilize the compiler. |
| ||
> …but somehow MX2 does not include it anymore. It is not included in test3_test3.h nor test3_test3.cpp! I'd have to see more code to work out what's happening here. > BTW: What is the replacement for CChar Ptr, WChar Ptr, and string.ToWString() etc? :) CChar, WChar, Utf8Char have gone, as not all c libs use the same 'c' char types to represent chars (eg: some use 'char*' to represent utf8, some use 'unsigned char *', some even apparently use 'signed char*' to represent plain c strings) so they were sort of meaningless/misleading. To pass strings to extern functions, use CString, WString or Utf8String param types and that should be it. Returning strings is a bit more complex - you need return a pointer of appropriate type and use String.FromBlahString() with the returned pointer. I eventually want to wrap this so functions can just return CString etc. I've added some 'C' char types to libc such char_t for 'char', uchar_t for 'unsigned char' etc. so functions should return these, eg: Method GetString:libc.char_t( ... ) See externs.monkey2 test for a demo of passing/returning strings. |
| ||
>> …but somehow MX2 does not include it anymore. It is not included in test3_test3.h nor test3_test3.cpp! > > I'd have to see more code to work out what's happening here. Tried to write a small test-code that shows the issue, but it always works. :) Will see later if I can isolate it. Thanks for the information about external string stuff. Should help. |
| ||
@Mark: > I'd have to see more code to work out what's happening here. Have a working example now: incTest.zip - Please start the main file: main/main.monkey2 You will get a C++ error about namespace not found: /Users/danilo/Monkey/SOURCES/incTest/main/main.buildv002/build_cache/desktop_debug_macos/main_main.cpp:16:3: error: use of undeclared identifier 'theNamespace' theNamespace::Xyz* l_obj=new theNamespace::Xyz(); ^ /Users/danilo/Monkey/SOURCES/incTest/main/main.buildv002/build_cache/desktop_debug_macos/main_main.cpp:16:32: error: use of undeclared identifier 'theNamespace' theNamespace::Xyz* l_obj=new theNamespace::Xyz(); ^ 2 errors generated. ***** Fatal mx2cc error ***** Build error. native.monkey2 contains: #Import "theFramework/native.h" Nonetheless, theFramework.monkey2 must include it again. Otherwise above C++ error. theFramework.monkey2 requires: #Import "native.h“ …even if it’s already included in native.monkey2 This wasn’t the case in Xmas v3 demo. Looks like I have to #Import the same .h file many times now. |
| ||
Ok, thanks for that! The problem is to do with a change I made to prevent monkey2 including everything all the time. In the xmas demo, once you imported a module, any .h #imports it contained were ultimately #included by ALL translated monkey2 code. Which can be a big deal for things like SDL, litehtml etc, so you now need to place the #import "blah.h" in the monkey2 file that declares the externs that "blah.h" contains. This way, only code that uses those externs will end up #including "blah.h" In other words, change 'theFramework.monkey2' to... #Import "native.cpp" 'Doesn't have to be here - could be in a 'makefile.monkey2' etc. #Import "native.h" 'HAS to be here: contains the extern stuff declared below. Extern Class Xyz Extends Void = "theNamespace::Xyz" Method doIt:Int() End ..and that should be it. You shouldn't need #import "native.h" anywhere else, ie: you can remove it from native.monkey2. You can #import "blah.h" from multiple monkey2 files, so you can still split externs up into multiple files, but each file must #Import "blah.h". Not as nice as having every 'just work', but it should ultimately reduce build times significantly, esp. once we get 1001 modules in there. |
| ||
Thanks, that explains it! :) |