Skip to main content

How to add a new native function?

2 replies [Last post]
Joined: 2009-06-18
Points: 0

Dear all,
If I want to add a new native function in the cldc project, what I should do?

I try to add a native function in as following:

1. Add this code into after executeGC(boolean forceFullGC)

private native static void executeGC(boolean forceFullGC);
/*****the new code*****/
private native static void executeSchedule();

2.Add this code into

public final static int ENTRY_COUNT = 162;
/*****the new code*****/
public final static int com_sun_squawk_VM$executeSchedule = 163;

3. New code in bytecodes.c.spp

case Native_com_sun_squawk_VM_executeGC: {
boolean forceFullGC = popInt();
com_sun_squawk_ServiceOperation_i1 = forceFullGC;
if (TRACE) {
printStackTracePrim(-1, ip, fp, "GARBAGE_COLLECT", null);
/*****the new code******/
case Native_com_sun_squawk_VM_executeSchedule: {
printf("schedule tests!!!!\n");

But when I build squawk, it has the problems as followling:

root@nqq-desktop:/home/nqq/squawk/trunk# -prod -mac -o2 rom cldc
Launcher: Found tools.jar in /home/java/jdk1.5.0_19/lib/tools.jar, by popping up a level from jre.
Builder.JDK: Looking for JDK in /home/java/jdk1.5.0_19, popped up a level from jre
Launcher: Found tools.jar in /home/java/jdk1.5.0_19/lib/tools.jar, by popping up a level from jre.
For vm2c tools.jar=/home/java/jdk1.5.0_19/lib/tools.jar
[running rom...]
[running romize...]
Loaded suite stripping settings from
excluding: com.sun.squawk.compiler.*
excluding: com.sun.squawk.os.*
excluding: com.sun.squawk.BytecodeTracer
excluding: com.sun.squawk.CheneyCollector*
excluding: com.sun.squawk.Lisp2Collector*
excluding: com.sun.squawk.ClassTunnel
[translating suite squawk [closed: false, parent: null] ...]
/home/nqq/squawk/trunk/vmcore/src/vm/rom.h is already up to date
Romizer processed 379 classes and generated these files:
[running runvm2c...]
build failed: Could not parse macro at line 4669 in vmcore/src/vm/bytecodes.c.spp.preprocessed: Cannot use C++ style comments inside a macro

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-09-08
Points: 0

It looks like there are two issues here:

1) The right way to add a native method is not to edit, but run the native builder tool.

See builder/ for the correct steps. Probably need to do a clean first.

2) The error message "Cannot use C++ style comments inside a macro" is usually due to using the "//" style of comment instead of "/* */". I didn't see any "//" in your example code, but look out for that.

Joined: 2009-06-18
Points: 0

Thank you, Derek!

Now, my project works well! I delete all the new codes, and add them again, when I build the squawk, the codes work well. It's really strang, but, it's OK. Thank you for your help!