remove native function and replace it with an enhanced ceylon implementation

113 views
Skip to first unread message

Loïc Rouchon

unread,
Feb 25, 2013, 2:47:40 PM2/25/13
to ceylo...@googlegroups.com
Hello,

I'm working on https://github.com/ceylon/ceylon.language/issues/196 and I'm trying to replace the Java/JS implementation of:
  shared native Integer? parseInteger(String string);
by a ceylon implementation:
  shared Integer? parseInteger(String string, Integer radix = 10) {...}

But when I do so, it looks like my function is not correctly taken into account, because I ends with the following message when compiling the unit tests of parseInteger (ant clean followed by ant test)
[ceylon-compile] .../ceylon.language/test/numbers.ceylon:309: error: no matching parameter declared by parseInteger: parseInteger has 1 parameters
[ceylon-compile]     check((parseInteger("-123",10) else 0)==-123, "parse integer");


I think I miss some native mapping declaration and that it's still using the native implementation.

Any ideas about what I forgot to do?

Thanks,

Tako Schotanus

unread,
Feb 25, 2013, 2:55:24 PM2/25/13
to ceylon-dev
Hi Loïc,

the thing is that the ant build file for the language module specifically includes a Java implementation in the build process. You'd have to disable that (search for "parseInteger" in the build file).

See if that helps,
-Tako



-Tako



--
You received this message because you are subscribed to the Google Groups "ceylon-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-dev+...@googlegroups.com.
To post to this group, send email to ceylo...@googlegroups.com.
Visit this group at http://groups.google.com/group/ceylon-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Loïc Rouchon

unread,
Feb 25, 2013, 4:22:40 PM2/25/13
to ceylo...@googlegroups.com, ta...@codejive.org

Le lundi 25 février 2013 20:55:24 UTC+1, Tako Schotanus a écrit :
Hi Loïc,

the thing is that the ant build file for the language module specifically includes a Java implementation in the build process. You'd have to disable that (search for "parseInteger" in the build file).

Thanks, it helps :)

After removing the include for parseInteger_.java, I was stuck with this:
[ceylon-compile] .../ceylon.language/test/numbers.ceylon:309: error: function or value does not exist: parseInteger

[ceylon-compile]     check((parseInteger("-123",10) else 0)==-123, "parse integer");


But this was, because of the exclude rule in the build.xml for Integer.ceylon, so I had to create a new file (parseInteger.ceylon) that don't match that exclude rule and now it's working perfectly.

I will now continue with the unit test for that function and work on the "format" to hex/binary method this week

 

Loïc Rouchon

unread,
Mar 2, 2013, 12:37:40 PM3/2/13
to ceylo...@googlegroups.com, ta...@codejive.org
I add the following platform depends attributes in Integer.ceylon

shared native Integer maxIntegerValue;
shared native Integer minIntegerValue;


I did the java implementation of it and it seems to work fine. But I don't know how to implement those native attributes in javascript.

I did the following in numbers.js (I took infinity as example)
//-(2^53)+1
var $minIntegerValue = Integer(-9007199254740991);
function getMinIntegerValue() { return $minIntegerValue; }
//(2^53)-3
var $maxIntegerValue = Integer(9007199254740989);
function getMaxIntegerValue() { return $maxIntegerValue; }


With:
exports.getMinIntegerValue=getMinIntegerValue;
exports.getMaxIntegerValue=getMaxIntegerValue;

or:
exports.minIntegerValue=$minIntegerValue;
exports.maxIntegerValue=$maxIntegerValue;


But when I launch ant ceylon.language.js it ends with the following error:
ceylon.language.js:
     [java] Generating language module metamodel in JSON...
     [java] 2 errors, 0 warningserror encountered [toplevel value must be specified: maxIntegerValue] at 14:0-14:37 of ceylon/language/Integer.ceylon
     [java]
     [java] Compiling language module sources
     [java] error encountered [toplevel value must be specified: minIntegerValue] at 15:0-15:37 of ceylon/language/Integer.ceylon
     [java] Compiling language module from Ceylon source
     [java] error encountered [toplevel value must be specified: maxIntegerValue] at 14:0-14:37 of ceylon/language/Integer.ceylon
     [java] error encountered [toplevel value must be specified: minIntegerValue] at 15:0-15:37 of ceylon/language/Integer.ceylon2 errors, 0 warnings
     [java]
     [java] Java Result: 1


I take a look at build.xml to see if the where some specific include declarations to be done (like I did for the java implementation of those package attributes) but I didn't found anything.

Right now, I have no ideas about what I forgot to do.
Any Ideas?

Thanks,

Enrique

unread,
Mar 22, 2013, 7:02:23 PM3/22/13
to ceylo...@googlegroups.com, ta...@codejive.org
The problem is that the js compiler doesn't treat `native` stuff in any special way, so you get that error. But since neither jvm nor js are really compiling that code, you can initialize the attributes to zero in Integer.ceylon, the backends will ignore that.

And you have to export the getters:

exports.getMaxIntegerValue=getMaxIntegerValue;

Loïc Rouchon

unread,
Mar 23, 2013, 5:32:47 AM3/23/13
to ceylo...@googlegroups.com, ta...@codejive.org
Thanks, I will try that

Loïc Rouchon

unread,
Mar 24, 2013, 2:57:42 PM3/24/13
to ceylo...@googlegroups.com, ta...@codejive.org
I had some time to test this this afternoon, but after a full update, I didn't have the issue anymore (maybe the js compiler had been improved in the meantime)

Now, it's compiling fine, but when I launch the test, I have a runtime error but I think it's due to a limitation of the current js build process of ceylon.language

I open a new Thread about that issue here: https://groups.google.com/d/msg/ceylon-dev/oRA2qx0drxI/FxNpyXwMElQJ
Reply all
Reply to author
Forward
0 new messages