Move the analysis of the class annotation `noautoinit` after the inheritance of initializers so the warning is correct, thus fixes #1350
The main commit is mainly moving the code in the same method.
Pull-Request: #1408
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
# FIXME : This huge `if` block is only necessary to copy primitive arrays as long as there's no better way to do it
if comment == "#" then
- temp.add(" in \"Java\" `\{\n{comment}\t\trecv.{jmethod_id}({java_params});\n{comment}\t`\}\n")
+ temp.add(" in \"Java\" `\{\n{comment}\t\tself.{jmethod_id}({java_params});\n{comment}\t`\}\n")
# Methods with return type
else if return_type != null then
- temp.add(" in \"Java\" `\{\n{comment}\t\treturn {jreturn_type.return_cast}recv.{jmethod_id}({java_params});\n{comment}\t`\}\n")
+ temp.add(" in \"Java\" `\{\n{comment}\t\treturn {jreturn_type.return_cast}self.{jmethod_id}({java_params});\n{comment}\t`\}\n")
# Methods without return type
else if jreturn_type.is_void then
- temp.add(" in \"Java\" `\{\n{comment}\t\trecv.{jmethod_id}({java_params});\n{comment}\t`\}\n")
+ temp.add(" in \"Java\" `\{\n{comment}\t\tself.{jmethod_id}({java_params});\n{comment}\t`\}\n")
# No copy
else
- temp.add(" in \"Java\" `\{\n{comment}\t\trecv.{jmethod_id}({java_params});\n{comment}\t`\}\n")
+ temp.add(" in \"Java\" `\{\n{comment}\t\tself.{jmethod_id}({java_params});\n{comment}\t`\}\n")
end
return temp.join("")
# The current values assigned to each variable
var vars = new HashMap[String, Int]
- redef fun visit(n) do n.accept_calculator(self)
+ redef fun visit(n) do n.accept_minilang(self)
end
redef class Node
# Execution of the node by the interpreter `v`
- fun accept_calculator(v: Interpretor) do visit_children(v)
+ fun accept_minilang(v: Interpretor) do visit_children(v)
end
redef class Nint
- redef fun accept_calculator(v) do v.stack.push(text.to_i)
+ redef fun accept_minilang(v) do v.stack.push(text.to_i)
end
redef class Ns_assign
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.vars[n_id.text] = v.stack.pop
end
end
redef class Ns_print
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
printn v.stack.pop
end
end
redef class Ns_print_str
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
var text = n_str.text
text = text.substring(1, text.length-2)
printn text
end
end
redef class Ns_println
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
print ""
end
end
redef class Ns_if
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
v.enter_visit(n_c)
if v.bstack.pop then
v.enter_visit(n_then)
end
end
redef class Ns_while
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
loop
v.enter_visit(n_c)
if not v.bstack.pop then break
redef class Nc_and
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
var b1 = v.bstack.pop
var b2 = v.bstack.pop
end
redef class Nc_or
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
var b1 = v.bstack.pop
var b2 = v.bstack.pop
end
redef class Nc_not
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.bstack.push(not v.bstack.pop)
end
end
redef class Nc_eq
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.bstack.push(v.stack.pop == v.stack.pop)
end
end
redef class Nc_ne
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.bstack.push(v.stack.pop != v.stack.pop)
end
end
redef class Nc_lt
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.bstack.push(v.stack.pop > v.stack.pop)
end
end
redef class Nc_le
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.bstack.push(v.stack.pop >= v.stack.pop)
end
end
redef class Nc_gt
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.bstack.push(v.stack.pop < v.stack.pop)
end
end
redef class Nc_ge
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.bstack.push(v.stack.pop <= v.stack.pop)
end
end
redef class Ne_add
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.stack.push(v.stack.pop+v.stack.pop)
end
end
redef class Ne_sub
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
var n1 = v.stack.pop
v.stack.push(v.stack.pop-n1)
end
end
redef class Ne_neg
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.stack.push(-v.stack.pop)
end
end
redef class Ne_mul
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
v.stack.push(v.stack.pop*v.stack.pop)
end
end
redef class Ne_div
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
super
var n1 = v.stack.pop
v.stack.push(v.stack.pop/n1)
end
end
redef class Ne_var
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
v.stack.push v.vars[n_id.text]
end
end
redef class Ne_read
- redef fun accept_calculator(v) do
+ redef fun accept_minilang(v) do
var t = gets
v.stack.push(t.to_i)
end
# Returns null on success
fun file_rename_to(dest: String): nullable String import String.to_cstring,
NativeString.to_s, String.as nullable `{
- int res = rename(String_to_cstring(recv), String_to_cstring(dest));
+ int res = rename(String_to_cstring(self), String_to_cstring(dest));
if (res == 0) return null_String();
return String_as_nullable(NativeString_to_s(strerror(errno)));
`}
`}
# The pin `id` depends on wiringPi setup used
- fun id: Int `{ return recv->id; `}
+ fun id: Int `{ return self->id; `}
# Sets the mode of the pin
- fun mode(mode: RPiPinMode) `{ pinMode(recv->id, mode); `}
+ fun mode(mode: RPiPinMode) `{ pinMode(self->id, mode); `}
# This sets the pull-up or pull-down resistor mode on the given pin,
# which should be set as an input.
- fun pullup_dncontrol(pud: PUDControl) `{ pullUpDnControl(recv->id, pud); `}
+ fun pullup_dncontrol(pud: PUDControl) `{ pullUpDnControl(self->id, pud); `}
# Writes the value HIGH or LOW (true or false) to the given pin which must
# have been previously set as an output.
- fun write(high: Bool) `{ digitalWrite(recv->id, high? HIGH: LOW); `}
+ fun write(high: Bool) `{ digitalWrite(self->id, high? HIGH: LOW); `}
# Writes the value to the PWM register for the given pin.
# The Raspberry Pi has one on-board PWM pin, pin 1 (BMC_GPIO 18, Phys 12)
# and the range is 0-1024.
# Other PWM devices may have other PWM ranges.
- fun pwm_write(value: Int) `{ pwmWrite(recv->id, value); `}
+ fun pwm_write(value: Int) `{ pwmWrite(self->id, value); `}
# This function returns the value read at the given pin.
# It will be HIGH or LOW (true or false) depending on the logic level at the pin.
- fun read: Bool `{ return digitalRead(recv->id) == HIGH? true: false; `}
+ fun read: Bool `{ return digitalRead(self->id) == HIGH? true: false; `}
end
# RPI Pin modes
# See the License for the specific language governing permissions and
# limitations under the License.
-# This sample has been implemented to show you how simple is it to play
-# with native callbacks (C) through an high level with NIT program.
-
+# This sample has been implemented to show you how simple is it to relay
+# native callbacks from C to a Nit program.
module callback_chimpanze
+
import callback_monkey
class Chimpanze
do
var monkey = new Monkey
print "Hum, I'm sleeping ..."
- # Invoking method which will take some time to compute, and
- # will be back in wokeUp method with information.
+
+ # Invoking method which will take some time to compute, and
+ # will be back in woke_up method with information.
# - Callback method defined in MonkeyActionCallable Interface
- monkey.wokeUpAction(self, "Hey, I'm awake.")
+ monkey.woke_up_action(self, "Hey, I'm awake.")
end
# Inherit callback method, defined by MonkeyActionCallable interface
- # - Back of wokeUpAction method
- redef fun wokeUp( sender:Monkey, message:Object )
+ # - Back of woke_up_action method
+ redef fun woke_up(sender:Monkey, message:Object)
do
print message
end
# See the License for the specific language governing permissions and
# limitations under the License.
-# This sample has been implemented to show you how simple is it to play
-# with native callbacks (C) through an high level with NIT program.
-
+# This sample has been implemented to show you how simple is it to relay
+# native callbacks from C to a Nit program.
module callback_monkey
in "C header" `{
#include <stdio.h>
#include <stdlib.h>
- typedef struct {
+ typedef struct {
int id;
int age;
} CMonkey;
void cbMonkey(CMonkey *mkey, void callbackFunc(CMonkey*, MonkeyAction*), MonkeyAction *data)
{
sleep(2);
- callbackFunc( mkey, data );
+ callbackFunc(mkey, data);
}
// Back of background treatment, will be redirected to callback function
- void nit_monkey_callback_func( CMonkey *mkey, MonkeyAction *data )
+ void nit_monkey_callback_func(CMonkey *mkey, MonkeyAction *data)
{
- // To call a your method, the signature must be written like this :
+ // To call a your method, the signature must be written like this:
// <Interface Name>_<Method>...
- MonkeyActionCallable_wokeUp( data->toCall, mkey, data->message );
+ MonkeyActionCallable_woke_up(data->toCall, mkey, data->message);
}
`}
# Implementable interface to get callback in defined methods
interface MonkeyActionCallable
- fun wokeUp( sender:Monkey, message: Object) is abstract
+ fun woke_up(sender:Monkey, message: Object) is abstract
end
# Defining my object type Monkey, which is, in a low level, a pointer to a C struct (CMonkey)
extern class Monkey `{ CMonkey * `}
-
+
new `{
- CMonkey *monkey = malloc( sizeof(CMonkey) );
+ CMonkey *monkey = malloc(sizeof(CMonkey));
monkey->age = 10;
monkey->id = 1;
return monkey;
`}
-
- # Object method which will get a callback in wokeUp method, defined in MonkeyActionCallable interface
+
+ # Object method which will get a callback in woke_up method, defined in MonkeyActionCallable interface
# Must be defined as Nit/C method because of C call inside
- fun wokeUpAction( toCall: MonkeyActionCallable, message: Object ) is extern import MonkeyActionCallable.wokeUp `{
+ fun woke_up_action(toCall: MonkeyActionCallable, message: Object) is extern import MonkeyActionCallable.woke_up `{
- // Allocating memory to keep reference of received parameters :
+ // Allocating memory to keep reference of received parameters:
// - Object receiver
- // - Message
- MonkeyAction *data = malloc( sizeof(MonkeyAction) );
+ // - Message
+ MonkeyAction *data = malloc(sizeof(MonkeyAction));
// Incrementing reference counter to prevent from releasing
- MonkeyActionCallable_incr_ref( toCall );
- Object_incr_ref( message );
-
+ MonkeyActionCallable_incr_ref(toCall);
+ Object_incr_ref(message);
+
data->toCall = toCall;
data->message = message;
-
- // Calling method which reproduce a callback by passing :
+
+ // Calling method which reproduce a callback by passing:
// - Receiver
// - Function pointer to object return method
// - Datas
- cbMonkey( recv, &nit_monkey_callback_func, data );
+ cbMonkey(self, &nit_monkey_callback_func, data);
`}
end
redef enum Int
fun n_chars: Int `{
int c;
- if ( abs(recv) >= 10 )
- c = 1+(int)log10f( (float)abs(recv) );
+ if ( abs(self) >= 10 )
+ c = 1+(int)log10f( (float)abs(self) );
else
c = 1;
- if ( recv < 0 ) c ++;
+ if ( self < 0 ) c ++;
return c;
`}
end
redef enum Int
# Returns self'th fibonnaci number
# implemented here in C for optimization purposes
- fun fib : Int import fib `{
- if ( recv < 2 )
- return recv;
+ fun fib: Int import fib `{
+ if (self < 2)
+ return self;
else
- return Int_fib( recv-1 ) + Int_fib( recv-2 );
+ return Int_fib(self-1) + Int_fib(self-2);
`}
# System call to sleep for "self" seconds
fun sleep `{
- sleep( recv );
+ sleep(self);
`}
- # Return atan2l( self, x ) from libmath
- fun atan_with( x : Int ) : Float `{
- return atan2( recv, x );
+ # Return atan2l(self, x) from libmath
+ fun atan_with(x: Int): Float `{
+ return atan2(self, x);
`}
# This method callback to Nit methods from C code
# * to_s, a method of all objects
# * String.to_cstring, a method of String to return an equivalent char*
fun foo import fib, +, to_s, String.to_cstring `{
- long recv_fib = Int_fib( recv );
- long recv_plus_fib = Int__plus( recv, recv_fib );
+ long self_fib = Int_fib(self);
+ long self_plus_fib = Int__plus(self, self_fib);
- String nit_string = Int_to_s( recv_plus_fib );
- char *c_string = String_to_cstring( nit_string );
+ String nit_string = Int_to_s(self_plus_fib);
+ char *c_string = String_to_cstring(nit_string);
- printf( "from C: self + fib(self) = %s\n", c_string );
+ printf("from C: self + fib(self) = %s\n", c_string);
`}
# Equivalent to foo but written in pure Nit
print "sleeping 1 second..."
1.sleep
-print 100.atan_with( 200 )
+print 100.atan_with(200)
8.foo
8.bar
android.util.Log.d("mnit_simple", "Java within NIT!!!");
// - Context needed from now on
- final android.app.Activity context = App_native_activity(recv);
+ final android.app.Activity context = App_native_activity(self);
// Vibration
android.os.Vibrator v = (android.os.Vibrator)
# HACK for bug #845
redef fun new_global_ref: SELF import sys, Sys.jni_env `{
- Sys sys = NativeActivity_sys(recv);
+ Sys sys = NativeActivity_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
extern class NativeAssetManager in "Java" `{ android.content.res.AssetManager `}
super JavaObject
- fun close in "Java" `{ recv.close(); `}
+ fun close in "Java" `{ self.close(); `}
fun get_locales: Array[JavaString] import Array[JavaString], Array[JavaString].add in "Java" `{
int arr = new_Array_of_JavaString();
- for (String s : recv.getLocales()) {
+ for (String s : self.getLocales()) {
Array_of_JavaString_add(arr, s);
}
return arr;
fun list(path: JavaString): Array[JavaString] import Array[JavaString], Array[JavaString].add in "Java" `{
int arr = new_Array_of_JavaString();
try {
- for (String s : recv.list(path)) {
+ for (String s : self.list(path)) {
Array_of_JavaString_add(arr, s);
}
}catch (IOException e) {
fun open(file_name: JavaString): NativeInputStream in "Java" `{
InputStream stream = null;
try {
- stream = recv.open(file_name);
+ stream = self.open(file_name);
}catch (IOException e) {
Log.e("Error while opening " + file_name, e.getMessage());
e.printStackTrace();
fun open_fd(file_name: JavaString): NativeAssetFileDescriptor in "Java" `{
AssetFileDescriptor afd = null;
try {
- afd = recv.openFd(file_name);
+ afd = self.openFd(file_name);
}catch(IOException e){
Log.e("Error while opening " + file_name, e.getMessage());
e.printStackTrace();
fun open_non_asset_fd(file_name: JavaString): NativeAssetFileDescriptor in "Java" `{
AssetFileDescriptor afd = null;
try {
- afd = recv.openNonAssetFd(file_name);
+ afd = self.openNonAssetFd(file_name);
}catch(IOException e){
Log.e("Error while opening " + file_name, e.getMessage());
e.printStackTrace();
# HACK for bug #845
redef fun new_global_ref import sys, Sys.jni_env `{
- Sys sys = NativeResources_sys(recv);
+ Sys sys = NativeResources_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
extern class NativeResources in "Java" `{ android.content.res.Resources `}
super JavaObject
- fun get_assets:NativeAssetManager in "Java" `{ return recv.getAssets(); `}
- fun get_color(id: Int): Int in "Java" `{ return recv.getColor((int)id); `}
- fun get_boolean(id: Int): Bool in "Java" `{ return recv.getBoolean((int)id); `}
- fun get_dimension(id: Int): Int in "Java" `{ return (int)recv.getDimension((int)id); `}
- fun get_drawable(id: Int): NativeDrawable in "Java" `{ return recv.getDrawable((int)id); `}
- fun get_identifier(name, def_type, def_package: JavaString): Int in "Java" `{ return recv.getIdentifier(name, def_type, def_package); `}
- fun get_integer(id: Int): Int in "Java" `{ return recv.getInteger((int)id); `}
- fun get_string(id: Int): JavaString in "Java" `{ return recv.getString((int)id); `}
- fun get_resource_entry_name(resid: Int): JavaString in "Java" `{ return recv.getResourceEntryName((int)resid); `}
- fun get_resource_name(resid: Int): JavaString in "Java" `{ return recv.getResourceName((int)resid); `}
- fun get_resource_pakage_name(resid: Int): JavaString in "Java" `{ return recv.getResourcePackageName((int)resid); `}
- fun get_resource_type_name(resid: Int): JavaString in "Java" `{ return recv.getResourceTypeName((int)resid); `}
+ fun get_assets:NativeAssetManager in "Java" `{ return self.getAssets(); `}
+ fun get_color(id: Int): Int in "Java" `{ return self.getColor((int)id); `}
+ fun get_boolean(id: Int): Bool in "Java" `{ return self.getBoolean((int)id); `}
+ fun get_dimension(id: Int): Int in "Java" `{ return (int)self.getDimension((int)id); `}
+ fun get_drawable(id: Int): NativeDrawable in "Java" `{ return self.getDrawable((int)id); `}
+ fun get_identifier(name, def_type, def_package: JavaString): Int in "Java" `{ return self.getIdentifier(name, def_type, def_package); `}
+ fun get_integer(id: Int): Int in "Java" `{ return self.getInteger((int)id); `}
+ fun get_string(id: Int): JavaString in "Java" `{ return self.getString((int)id); `}
+ fun get_resource_entry_name(resid: Int): JavaString in "Java" `{ return self.getResourceEntryName((int)resid); `}
+ fun get_resource_name(resid: Int): JavaString in "Java" `{ return self.getResourceName((int)resid); `}
+ fun get_resource_pakage_name(resid: Int): JavaString in "Java" `{ return self.getResourcePackageName((int)resid); `}
+ fun get_resource_type_name(resid: Int): JavaString in "Java" `{ return self.getResourceTypeName((int)resid); `}
# HACK for bug #845
redef fun new_global_ref import sys, Sys.jni_env `{
- Sys sys = NativeResources_sys(recv);
+ Sys sys = NativeResources_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
# Create a NativeBitmap using a resource ID and the NativeResources
# Called by the ResourceManager
new from_resources(res: NativeResources, id: Int) in "Java" `{ return BitmapFactory.decodeResource(res, (int)id); `}
- fun width: Int in "Java" `{ return recv.getWidth(); `}
- fun height: Int in "Java" `{ return recv.getHeight(); `}
+ fun width: Int in "Java" `{ return self.getWidth(); `}
+ fun height: Int in "Java" `{ return self.getHeight(); `}
# HACK for bug #845
redef fun new_global_ref import sys, Sys.jni_env `{
- Sys sys = NativeResources_sys(recv);
+ Sys sys = NativeResources_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
fun close in "Java" `{
try {
- recv.close();
+ self.close();
}catch(IOException e){
e.printStackTrace();
}
`}
fun create_input_stream: NativeFileInputStream in "Java" `{
try {
- return recv.createInputStream();
+ return self.createInputStream();
}catch(IOException e){
Log.e("Error creating input_stream", e.getMessage());
e.printStackTrace();
`}
fun create_output_stream: NativeFileOutputStream in "Java" `{
try {
- return recv.createOutputStream();
+ return self.createOutputStream();
}catch(IOException e){
Log.e("Error creating output stream", e.getMessage());
e.printStackTrace();
return null;
}
`}
- fun describe_contents: Int in "Java" `{ return (int)recv.describeContents(); `}
- fun declared_length: Int in "Java" `{ return (int)recv.getDeclaredLength(); `}
- # fun extras: Bundle in "Java" `{ return recv.getExtras(); `}
+ fun describe_contents: Int in "Java" `{ return (int)self.describeContents(); `}
+ fun declared_length: Int in "Java" `{ return (int)self.getDeclaredLength(); `}
+ # fun extras: Bundle in "Java" `{ return self.getExtras(); `}
fun file_descriptor: NativeFileDescriptor in "Java" `{
- FileDescriptor fd = recv.getFileDescriptor();
+ FileDescriptor fd = self.getFileDescriptor();
if (fd == null) {
Log.e("AssetFileDesciptorError", "Can't retrieve the FileDescriptor of this AssetFileDescriptor");
}
return fd;
`}
- fun length: Int in "Java" `{ return (int)recv.getLength(); `}
- fun start_offset: Int in "Java" `{ return (int)recv.getStartOffset(); `}
- redef fun to_s: String import JavaString.to_s in "Java" `{ return JavaString_to_s(recv.toString()); `}
+ fun length: Int in "Java" `{ return (int)self.getLength(); `}
+ fun start_offset: Int in "Java" `{ return (int)self.getStartOffset(); `}
+ redef fun to_s: String import JavaString.to_s in "Java" `{ return JavaString_to_s(self.toString()); `}
# HACK for bug #845
redef fun new_global_ref import sys, Sys.jni_env `{
- Sys sys = NativeResources_sys(recv);
+ Sys sys = NativeResources_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
var asset_manager: AssetManager is lazy do return new AssetManager(self)
# Get the native AssetsManager of the application, used to initialize the nit's AssetManager
- private fun assets: NativeAssetManager import native_activity in "Java" `{ return App_native_activity(recv).getAssets(); `}
+ private fun assets: NativeAssetManager import native_activity in "Java" `{ return App_native_activity(self).getAssets(); `}
# Get the package name of the application
- private fun package_name: JavaString import native_activity in "Java" `{ return App_native_activity(recv).getPackageName(); `}
+ private fun package_name: JavaString import native_activity in "Java" `{ return App_native_activity(self).getPackageName(); `}
# Get the native ResourceManager of the application, used to initialize the nit's ResourceManager
- private fun resources: NativeResources import native_activity in "Java" `{ return App_native_activity(recv).getResources(); `}
+ private fun resources: NativeResources import native_activity in "Java" `{ return App_native_activity(self).getResources(); `}
end
# Current audio mode.
# ( MODE_NORMAL = 0, MODE_RINGTONE = 1, MODE_IN_CALL = 2 or MODE_IN_COMMUNICATION = 3 )
- fun mode: Int in "Java" `{ return recv.getMode(); `}
+ fun mode: Int in "Java" `{ return self.getMode(); `}
# Sets the audio mode.
# ( MODE_NORMAL = 0, MODE_RINGTONE = 1, MODE_IN_CALL = 2 or MODE_IN_COMMUNICATION = 3 )
- fun mode=(i: Int) in "Java" `{ recv.setMode((int)i); `}
+ fun mode=(i: Int) in "Java" `{ self.setMode((int)i); `}
# Sends a request to obtain audio focus
fun request_audio_focus: Int in "Java" `{
- return recv.requestAudioFocus(afChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
+ return self.requestAudioFocus(afChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
`}
# Gives up audio focus
- fun abandon_audio_focus: Int in "Java" `{ return recv.abandonAudioFocus(afChangeListener); `}
+ fun abandon_audio_focus: Int in "Java" `{ return self.abandonAudioFocus(afChangeListener); `}
end
# Media Player from Java, used to play long sounds or musics, not simultaneously
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
return mp;
`}
- fun start in "Java" `{ recv.start(); `}
+ fun start in "Java" `{ self.start(); `}
fun prepare in "Java" `{
try {
- recv.prepare();
+ self.prepare();
}catch(IOException e) {
Log.e("Error preparing the Media Player", e.getMessage());
e.printStackTrace();
}
`}
- fun create(context: NativeActivity, id: Int): NativeMediaPlayer in "Java" `{ return recv.create(context, (int)id); `}
- fun pause in "Java" `{ recv.pause(); `}
- fun stop in "Java" `{ recv.stop(); `}
- fun playing: Bool in "Java" `{ return recv.isPlaying(); `}
- fun release in "Java" `{ recv.release(); `}
- fun duration: Int in "Java" `{ return recv.getDuration(); `}
- fun looping: Bool in "Java" `{ return recv.isLooping(); `}
- fun looping=(b: Bool) in "Java" `{ recv.setLooping(b); `}
- fun volume=(vol: Float) in "Java" `{ recv.setVolume((float)vol, (float)vol); `}
- fun both_volume(left_volume, right_volume: Float) in "Java" `{ recv.setVolume((float)left_volume, (float)right_volume); `}
- fun stream_type=(stream_type: Int) in "Java" `{ recv.setAudioStreamType((int)stream_type); `}
+ fun create(context: NativeActivity, id: Int): NativeMediaPlayer in "Java" `{ return self.create(context, (int)id); `}
+ fun pause in "Java" `{ self.pause(); `}
+ fun stop in "Java" `{ self.stop(); `}
+ fun playing: Bool in "Java" `{ return self.isPlaying(); `}
+ fun release in "Java" `{ self.release(); `}
+ fun duration: Int in "Java" `{ return self.getDuration(); `}
+ fun looping: Bool in "Java" `{ return self.isLooping(); `}
+ fun looping=(b: Bool) in "Java" `{ self.setLooping(b); `}
+ fun volume=(vol: Float) in "Java" `{ self.setVolume((float)vol, (float)vol); `}
+ fun both_volume(left_volume, right_volume: Float) in "Java" `{ self.setVolume((float)left_volume, (float)right_volume); `}
+ fun stream_type=(stream_type: Int) in "Java" `{ self.setAudioStreamType((int)stream_type); `}
fun data_source_fd(fd: NativeFileDescriptor, start_offset, length: Int) in "Java" `{
try {
- recv.setDataSource(fd, start_offset, length);
+ self.setDataSource(fd, start_offset, length);
}catch(IOException e) {
Log.e("Error loading the Media Player with a file descriptor", e.getMessage());
e.printStackTrace();
`}
fun data_source_path(path: JavaString) in "Java" `{
try {
- recv.setDataSource(path);
+ self.setDataSource(path);
}catch(IOException e) {
Log.e("Error loading the Media Player", e.getMessage());
e.printStackTrace();
}
`}
- fun reset in "Java" `{ recv.reset(); `}
+ fun reset in "Java" `{ self.reset(); `}
end
# Sound Pool from Java, used to play sounds simultaneously
new(max_streams, stream_type, src_quality: Int) in "Java" `{
return new SoundPool((int)max_streams, (int)stream_type, (int)src_quality);
`}
- fun load_asset_fd(afd: NativeAssetFileDescriptor, priority: Int): Int in "Java" `{ return recv.load(afd, (int)priority); `}
- fun load_id(context: NativeActivity, resid, priority: Int): Int in "Java" `{ return recv.load(context, (int)resid, (int)priority); `}
- fun load_path(path: JavaString, priority: Int): Int in "Java" `{ return recv.load(path, (int)priority); `}
+ fun load_asset_fd(afd: NativeAssetFileDescriptor, priority: Int): Int in "Java" `{ return self.load(afd, (int)priority); `}
+ fun load_id(context: NativeActivity, resid, priority: Int): Int in "Java" `{ return self.load(context, (int)resid, (int)priority); `}
+ fun load_path(path: JavaString, priority: Int): Int in "Java" `{ return self.load(path, (int)priority); `}
fun play(sound_id: Int, left_volume, right_volume: Float, priority, l: Int, rate: Float): Int in "Java" `{
- return recv.play((int)sound_id, (float)left_volume, (float)right_volume, (int)priority, (int)l, (float)rate);
+ return self.play((int)sound_id, (float)left_volume, (float)right_volume, (int)priority, (int)l, (float)rate);
`}
- fun pause(stream_id: Int) in "Java" `{ recv.pause((int)stream_id); `}
- fun auto_pause in "Java" `{ recv.autoPause(); `}
- fun auto_resume in "Java" `{ recv.autoResume(); `}
- fun resume(stream_id: Int) in "Java" `{ recv.resume((int)stream_id); `}
- fun set_loop(stream_id, l: Int) in "Java" `{ recv.setLoop((int)stream_id, (int)l); `}
- fun set_priority(stream_id, priority: Int) in "Java" `{ recv.setPriority((int)stream_id, (int)priority); `}
- fun set_rate(stream_id: Int, rate: Float) in "Java" `{ recv.setRate((int)stream_id, (float)rate); `}
- fun set_volume(stream_id: Int, left_volume, right_volume: Float) in "Java" `{ recv.setVolume((int)stream_id, (float)left_volume, (float)right_volume); `}
- fun stop(stream_id: Int) in "Java" `{ recv.stop((int)stream_id); `}
- fun unload(sound_id: Int): Bool in "Java" `{ return recv.unload((int)sound_id); `}
- fun release in "Java" `{ recv.release(); `}
+ fun pause(stream_id: Int) in "Java" `{ self.pause((int)stream_id); `}
+ fun auto_pause in "Java" `{ self.autoPause(); `}
+ fun auto_resume in "Java" `{ self.autoResume(); `}
+ fun resume(stream_id: Int) in "Java" `{ self.resume((int)stream_id); `}
+ fun set_loop(stream_id, l: Int) in "Java" `{ self.setLoop((int)stream_id, (int)l); `}
+ fun set_priority(stream_id, priority: Int) in "Java" `{ self.setPriority((int)stream_id, (int)priority); `}
+ fun set_rate(stream_id: Int, rate: Float) in "Java" `{ self.setRate((int)stream_id, (float)rate); `}
+ fun set_volume(stream_id: Int, left_volume, right_volume: Float) in "Java" `{ self.setVolume((int)stream_id, (float)left_volume, (float)right_volume); `}
+ fun stop(stream_id: Int) in "Java" `{ self.stop((int)stream_id); `}
+ fun unload(sound_id: Int): Bool in "Java" `{ return self.unload((int)sound_id); `}
+ fun release in "Java" `{ self.release(); `}
end
# Get the native audio manager
fun audio_manager: NativeAudioManager import native_activity in "Java" `{
- return (AudioManager)App_native_activity(recv).getSystemService(Context.AUDIO_SERVICE);
+ return (AudioManager)App_native_activity(self).getSystemService(Context.AUDIO_SERVICE);
`}
# Sets the stream of the app to STREAM_MUSIC.
# STREAM_MUSIC is the default stream used by android apps.
private fun manage_audio_stream import native_activity, native_app_glue in "Java" `{
- App_native_activity(recv).setVolumeControlStream(AudioManager.STREAM_MUSIC);
+ App_native_activity(self).setVolumeControlStream(AudioManager.STREAM_MUSIC);
`}
# Retrieves a sound with a soundpool in the `assets` folder using its name.
# See the License for the specific language governing permissions and
# limitations under the License.
-# A mapping class of `String` to various value types used by the
+# A mapping class of `String` to various value types used by the
# Android API for various data exchange purposes
module bundle
new in "Java" `{ return new Bundle(); `}
- fun clone: JavaObject in "Java" `{ return recv.clone(); `}
- fun size: Int in "Java" `{ return recv.size(); `}
- fun is_empty: Bool in "Java" `{ return recv.isEmpty(); `}
- fun clear in "Java" `{ recv.clear(); `}
- fun contains_key(key: JavaString): Bool in "Java" `{ return recv.containsKey(key); `}
- fun get(key: JavaString): JavaObject in "Java" `{ return recv.get(key); `}
- fun remove(key: JavaString) in "Java" `{ recv.remove(key); `}
- fun put_all(bundle: NativeBundle) in "Java" `{ recv.putAll(bundle); `}
+ fun clone: JavaObject in "Java" `{ return self.clone(); `}
+ fun size: Int in "Java" `{ return self.size(); `}
+ fun is_empty: Bool in "Java" `{ return self.isEmpty(); `}
+ fun clear in "Java" `{ self.clear(); `}
+ fun contains_key(key: JavaString): Bool in "Java" `{ return self.containsKey(key); `}
+ fun get(key: JavaString): JavaObject in "Java" `{ return self.get(key); `}
+ fun remove(key: JavaString) in "Java" `{ self.remove(key); `}
+ fun put_all(bundle: NativeBundle) in "Java" `{ self.putAll(bundle); `}
fun key_set: HashSet[JavaString] import HashSet[JavaString],
HashSet[JavaString].add in "Java" `{
- Set<String> java_set = recv.keySet();
+ Set<String> java_set = self.keySet();
int nit_hashset = new_HashSet_of_JavaString();
for (String element: java_set)
return nit_hashset;
`}
- fun has_file_descriptors: Bool in "Java" `{ return recv.hasFileDescriptors(); `}
- fun put_boolean(key: JavaString, value: Bool) in "Java" `{
- recv.putBoolean(key, value);
+ fun has_file_descriptors: Bool in "Java" `{ return self.hasFileDescriptors(); `}
+ fun put_boolean(key: JavaString, value: Bool) in "Java" `{
+ self.putBoolean(key, value);
`}
- fun put_byte(key: JavaString, value: Int) in "Java" `{
- recv.putByte(key, (byte) value);
+ fun put_byte(key: JavaString, value: Int) in "Java" `{
+ self.putByte(key, (byte) value);
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
- fun put_char(key: JavaString, value: Char) in "Java" `{
- recv.putChar(key, value);
+ fun put_char(key: JavaString, value: Char) in "Java" `{
+ self.putChar(key, value);
`}
- fun put_short(key: JavaString, value: Int) in "Java" `{
- recv.putShort(key, (short) value);
+ fun put_short(key: JavaString, value: Int) in "Java" `{
+ self.putShort(key, (short) value);
`}
- fun put_int(key: JavaString, value: Int) in "Java" `{
- recv.putInt(key, (int) value);
+ fun put_int(key: JavaString, value: Int) in "Java" `{
+ self.putInt(key, (int) value);
`}
- fun put_long(key: JavaString, value: Int) in "Java" `{
- recv.putLong(key, value);
+ fun put_long(key: JavaString, value: Int) in "Java" `{
+ self.putLong(key, value);
`}
- fun put_float(key: JavaString, value: Float) in "Java" `{
- recv.putFloat(key, (float) value);
+ fun put_float(key: JavaString, value: Float) in "Java" `{
+ self.putFloat(key, (float) value);
`}
- fun put_double(key: JavaString, value: Float) in "Java" `{
- recv.putDouble(key, value);
+ fun put_double(key: JavaString, value: Float) in "Java" `{
+ self.putDouble(key, value);
`}
- fun put_string(key: JavaString, value: JavaString) in "Java" `{
- recv.putString(key, value);
+ fun put_string(key: JavaString, value: JavaString) in "Java" `{
+ self.putString(key, value);
`}
- fun put_char_sequence(key: JavaString, value: JavaString) in "Java" `{
- recv.putCharSequence(key, value);
+ fun put_char_sequence(key: JavaString, value: JavaString) in "Java" `{
+ self.putCharSequence(key, value);
`}
- fun put_integer_array_list(key: JavaString, value: Array[Int])
+ fun put_integer_array_list(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
- ArrayList<Integer> java_array =
+ ArrayList<Integer> java_array =
new ArrayList<Integer>((int) Array_of_Int_length(value));
-
+
for(int i=0; i < java_array.size(); ++i)
java_array.add((int) Array_of_Int__index(value, i));
- recv.putIntegerArrayList(key, java_array);
+ self.putIntegerArrayList(key, java_array);
`}
fun put_string_array_list(key: JavaString, value: Array[JavaString])
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
ArrayList<String> java_array = new ArrayList<String>((int)Array_of_JavaString_length(value));
-
+
for(int i=0; i < java_array.size(); ++i)
java_array.add(Array_of_JavaString__index(value, i));
- recv.putStringArrayList(key, java_array);
+ self.putStringArrayList(key, java_array);
`}
fun put_char_sequence_array_list(key: JavaString, value: Array[JavaString])
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
- ArrayList<CharSequence> java_array =
+ ArrayList<CharSequence> java_array =
new ArrayList<CharSequence>((int)Array_of_JavaString_length(value));
-
+
for(int i=0; i < java_array.size(); ++i)
java_array.add(Array_of_JavaString__index(value, i));
- recv.putCharSequenceArrayList(key, java_array);
+ self.putCharSequenceArrayList(key, java_array);
`}
fun put_boolean_array(key: JavaString, value: Array[Bool])
import Array[Bool].length, Array[Bool].[] in "Java" `{
boolean[] java_array = new boolean[(int)Array_of_Bool_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Bool__index(value, i);
- recv.putBooleanArray(key, java_array);
+ self.putBooleanArray(key, java_array);
`}
fun put_byte_array(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
byte[] java_array = new byte[(int)Array_of_Int_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = (byte) Array_of_Int__index(value, i);
- recv.putByteArray(key, java_array);
+ self.putByteArray(key, java_array);
`}
fun put_short_array(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
short[] java_array = new short[(int)Array_of_Int_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = (short) Array_of_Int__index(value, i);
- recv.putShortArray(key, java_array);
+ self.putShortArray(key, java_array);
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun put_char_array(key: JavaString, value: Array[Char])
import Array[Char].length, Array[Char].[] in "Java" `{
char[] java_array = new char[(int)Array_of_Char_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Char__index(value, i);
- recv.putCharArray(key, java_array);
+ self.putCharArray(key, java_array);
`}
fun put_int_array(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
int[] java_array = new int[(int)Array_of_Int_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = (int) Array_of_Int__index(value, i);
- recv.putIntArray(key, java_array);
+ self.putIntArray(key, java_array);
`}
fun put_long_array(key: JavaString, value: Array[Int])
import Array[Int].length, Array[Int].[] in "Java" `{
long[] java_array = new long[(int)Array_of_Int_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Int__index(value, i);
- recv.putLongArray(key, java_array);
+ self.putLongArray(key, java_array);
`}
fun put_float_array(key: JavaString, value: Array[Float])
import Array[Float].length, Array[Float].[] in "Java" `{
float[] java_array = new float[(int)Array_of_Float_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = (float) Array_of_Float__index(value, i);
- recv.putFloatArray(key, java_array);
+ self.putFloatArray(key, java_array);
`}
fun put_double_array(key: JavaString, value: Array[Float])
import Array[Float].length, Array[Float].[] in "Java" `{
double[] java_array = new double[(int)Array_of_Float_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Float__index(value, i);
- recv.putDoubleArray(key, java_array);
+ self.putDoubleArray(key, java_array);
`}
fun put_string_array(key: JavaString, value: Array[JavaString])
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
String[] java_array = new String[(int)Array_of_JavaString_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_JavaString__index(value, i);
- recv.putStringArray(key, java_array);
+ self.putStringArray(key, java_array);
`}
fun put_char_sequence_array(key: JavaString, value: Array[JavaString])
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
CharSequence[] java_array = new CharSequence[(int)Array_of_JavaString_length(value)];
-
+
for(int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_JavaString__index(value, i);
- recv.putCharSequenceArray(key, java_array);
+ self.putCharSequenceArray(key, java_array);
`}
- fun put_bundle(key: JavaString, value: NativeBundle) in "Java" `{
- recv.putBundle(key, value);
+ fun put_bundle(key: JavaString, value: NativeBundle) in "Java" `{
+ self.putBundle(key, value);
`}
- fun get_boolean(key: JavaString): Bool in "Java" `{ return recv.getBoolean(key); `}
+ fun get_boolean(key: JavaString): Bool in "Java" `{ return self.getBoolean(key); `}
fun get_boolean_with_def_value(key: JavaString, def_value: Bool): Bool in "Java" `{
- return recv.getBoolean(key, def_value);
+ return self.getBoolean(key, def_value);
`}
- fun get_byte(key: JavaString): Int in "Java" `{ return recv.getByte(key); `}
- fun get_byte_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
- return recv.getByte(key, (byte) def_value);
+ fun get_byte(key: JavaString): Int in "Java" `{ return self.getByte(key); `}
+ fun get_byte_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
+ return self.getByte(key, (byte) def_value);
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
- fun get_char(key: JavaString): Char in "Java" `{ return recv.getChar(key); `}
+ fun get_char(key: JavaString): Char in "Java" `{ return self.getChar(key); `}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun get_char_with_def_value(key: JavaString, def_value: Char): Char in "Java" `{
- return recv.getChar(key, def_value);
+ return self.getChar(key, def_value);
`}
- fun get_short(key: JavaString): Int in "Java" `{ return (short) recv.getShort(key); `}
+ fun get_short(key: JavaString): Int in "Java" `{ return (short) self.getShort(key); `}
fun get_short_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
- return (short) recv.getShort(key, (short) def_value);
+ return (short) self.getShort(key, (short) def_value);
`}
- fun get_int(key: JavaString): Int in "Java" `{ return recv.getInt(key); `}
+ fun get_int(key: JavaString): Int in "Java" `{ return self.getInt(key); `}
fun get_int_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
- return recv.getInt(key, (int) def_value);
+ return self.getInt(key, (int) def_value);
`}
- fun get_long(key: JavaString): Int in "Java" `{ return recv.getLong(key); `}
+ fun get_long(key: JavaString): Int in "Java" `{ return self.getLong(key); `}
fun get_long_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
- return recv.getLong(key);
+ return self.getLong(key);
`}
fun get_float(key: JavaString): Float in "Java" `{
- return (float) recv.getFloat(key);
+ return (float) self.getFloat(key);
`}
fun get_float_with_def_value(key: JavaString, def_value: Float): Float in "Java" `{
- return (float) recv.getFloat(key, (float) def_value);
+ return (float) self.getFloat(key, (float) def_value);
`}
- fun get_double(key: JavaString): Float in "Java" `{ return recv.getDouble(key); `}
- fun get_double_with_def_value(key: JavaString, def_value: Float): Float in "Java" `{
- return recv.getDouble(key, def_value);
+ fun get_double(key: JavaString): Float in "Java" `{ return self.getDouble(key); `}
+ fun get_double_with_def_value(key: JavaString, def_value: Float): Float in "Java" `{
+ return self.getDouble(key, def_value);
`}
fun get_string(key: JavaString): JavaString in "Java" `{
- return recv.getString(key);
+ return self.getString(key);
`}
fun get_char_sequence(key: JavaString): JavaString in "Java" `{
- return (String) recv.getCharSequence(key);
+ return (String) self.getCharSequence(key);
`}
fun get_bundle(key: JavaString): NativeBundle in "Java" `{
- return recv.getBundle(key);
+ return self.getBundle(key);
`}
fun get_integer_array_list(key: JavaString): Array[Int]
import Array[Int], Array[Int].add in "Java" `{
- ArrayList<Integer> java_array = recv.getIntegerArrayList(key);
+ ArrayList<Integer> java_array = self.getIntegerArrayList(key);
int nit_array = new_Array_of_Int();
if (java_array == null) return nit_array;
`}
fun get_string_array_list(key: JavaString): Array[String]
import StringCopyArray, StringCopyArray.add, StringCopyArray.collection in "Java" `{
- ArrayList<String> java_array = recv.getStringArrayList(key);
+ ArrayList<String> java_array = self.getStringArrayList(key);
int nit_array = new_StringCopyArray();
if (java_array == null) return nit_array;
`}
fun get_char_sequence_array_list(key: JavaString): Array[String]
import StringCopyArray, StringCopyArray.add, StringCopyArray.collection in "Java" `{
- ArrayList<CharSequence> java_array = recv.getCharSequenceArrayList(key);
+ ArrayList<CharSequence> java_array = self.getCharSequenceArrayList(key);
int nit_array = new_StringCopyArray();
if (java_array == null) return nit_array;
return StringCopyArray_collection(nit_array);
`}
fun get_boolean_array(key: JavaString): Array[Bool]
- import Array[Bool], Array[Bool].add in "Java" `{
- boolean[] java_array = recv.getBooleanArray(key);
+ import Array[Bool], Array[Bool].add in "Java" `{
+ boolean[] java_array = self.getBooleanArray(key);
int nit_array = new_Array_of_Bool();
if (java_array == null) return nit_array;
return nit_array;
`}
fun get_byte_array(key: JavaString): Array[Int]
- import Array[Int], Array[Int].add in "Java" `{
- byte[] java_array = recv.getByteArray(key);
+ import Array[Int], Array[Int].add in "Java" `{
+ byte[] java_array = self.getByteArray(key);
int nit_array = new_Array_of_Int();
-
+
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
Array_of_Int_add(nit_array, java_array[i]);
-
+
return nit_array;
`}
fun get_short_array(key: JavaString): Array[Int]
- import Array[Int], Array[Int].add in "Java" `{
- short[] java_array = recv.getShortArray(key);
+ import Array[Int], Array[Int].add in "Java" `{
+ short[] java_array = self.getShortArray(key);
int nit_array = new_Array_of_Int();
-
+
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
Array_of_Int_add(nit_array, java_array[i]);
-
+
return nit_array;
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun get_char_array(key: JavaString): Array[Char]
- import Array[Char], Array[Char].add in "Java" `{
- char[] java_array = recv.getCharArray(key);
+ import Array[Char], Array[Char].add in "Java" `{
+ char[] java_array = self.getCharArray(key);
int nit_array = new_Array_of_Char();
-
+
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
Array_of_Char_add(nit_array, java_array[i]);
-
+
return nit_array;
`}
fun get_int_array(key: JavaString): Array[Int]
- import Array[Int], Array[Int].add in "Java" `{
- int[] java_array = recv.getIntArray(key);
+ import Array[Int], Array[Int].add in "Java" `{
+ int[] java_array = self.getIntArray(key);
int nit_array = new_Array_of_Int();
-
+
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
Array_of_Int_add(nit_array, java_array[i]);
-
+
return nit_array;
`}
# FIXME: Get rid of the int cast as soon as the ffi is fixed
fun get_long_array(key: JavaString): Array[Int]
- import Array[Int], Array[Int].add in "Java" `{
- long[] java_array = recv.getLongArray(key);
+ import Array[Int], Array[Int].add in "Java" `{
+ long[] java_array = self.getLongArray(key);
int nit_array = new_Array_of_Int();
-
+
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
Array_of_Int_add(nit_array, java_array[i]);
-
+
return nit_array;
`}
fun get_float_array(key: JavaString): Array[Float]
- import Array[Float], Array[Float].add in "Java" `{
- float[] java_array = recv.getFloatArray(key);
+ import Array[Float], Array[Float].add in "Java" `{
+ float[] java_array = self.getFloatArray(key);
int nit_array = new_Array_of_Float();
-
+
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
Array_of_Float_add(nit_array, (double) java_array[i]);
-
+
return nit_array;
`}
fun get_double_array(key: JavaString): Array[Float]
- import Array[Float], Array[Float].add in "Java" `{
- double[] java_array = recv.getDoubleArray(key);
+ import Array[Float], Array[Float].add in "Java" `{
+ double[] java_array = self.getDoubleArray(key);
int nit_array = new_Array_of_Float();
-
+
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
Array_of_Float_add(nit_array, java_array[i]);
-
+
return nit_array;
`}
fun get_string_array(key: JavaString): Array[String]
import StringCopyArray, StringCopyArray.add, StringCopyArray.collection in "Java" `{
- String[] java_array = recv.getStringArray(key);
+ String[] java_array = self.getStringArray(key);
int nit_array = new_StringCopyArray();
-
+
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
StringCopyArray_add(nit_array, java_array[i]);
-
+
return StringCopyArray_collection(nit_array);
`}
fun get_char_sequence_array(key: JavaString): Array[String]
import StringCopyArray, StringCopyArray.add, StringCopyArray.collection in "Java" `{
- CharSequence[] java_array = recv.getCharSequenceArray(key);
+ CharSequence[] java_array = self.getCharSequenceArray(key);
int nit_array = new_StringCopyArray();
-
+
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
StringCopyArray_add(nit_array, (String)java_array[i]);
-
+
return StringCopyArray_collection(nit_array);
`}
- fun describe_contents: Int in "Java" `{ return recv.describeContents(); `}
- fun to_string: JavaString in "Java" `{ return recv.toString(); `}
+ fun describe_contents: Int in "Java" `{ return self.describeContents(); `}
+ fun to_string: JavaString in "Java" `{ return self.toString(); `}
# HACK for bug #845
redef fun new_global_ref import sys, Sys.jni_env `{
- Sys sys = NativeBundle_sys(recv);
+ Sys sys = NativeBundle_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
sys.jni_env.pop_local_frame
return return_value
end
-
+
# Returns the number of entries in the current `Bundle`
fun size: Int do return native_bundle.size
return string_set
end
- # Add key-value information by dynamically choosing the appropriate
+ # Add key-value information by dynamically choosing the appropriate
# java method according to value type
- # If there's already a value associated with this key, the new value
+ # If there's already a value associated with this key, the new value
# overwrites it
#
# To retrieve entries, you'll have to call the type corresponding method
- # conforming to these rules :
+ # conforming to these rules:
#
# | Nit type | corresponding getter |
# |:----------------------|:--------------------------------|
- # ! `Int` | `long` |
+ # | `Int` | `long` |
# | `Float` | `double` |
# | `Bool` | `bool` |
# | `Char` | `char` |
- # ! `String` | `string` |
- # ! `Serializable` | `deserialize` |
- # ! `Array[Int]` | `array_of_long` |
- # ! `Array[Float]` | `array_of_double` |
- # ! `Array[Bool]` | `array_of_bool` |
- # ! `Array[Char]` | `array_of_char` |
- # ! `Array[String]` | `array_of_string` |
+ # | `String` | `string` |
+ # | `Serializable` | `deserialize` |
+ # | `Array[Int]` | `array_of_long` |
+ # | `Array[Float]` | `array_of_double` |
+ # | `Array[Bool]` | `array_of_bool` |
+ # | `Array[Char]` | `array_of_char` |
+ # | `Array[String]` | `array_of_string` |
# | `Array[Serializable]` | `deserialize_array` |
fun []=(key: String, value: Serializable): Bundle
do
# Retrieve an `Object` serialized via `[]=` function
# Returns `null` if there's no serialized object corresponding to the given key
# or if it's the wrong value type
- # Make sure that the serialized object is `auto_serializable` or that it
+ # Make sure that the serialized object is `auto_serializable` or that it
# redefines the appropriate methods. Refer to `Serializable` documentation
# for further details
fun deserialize(key: String): nullable Object
# Retrieve an `Array` of `Object` serialized via `[]=` function
# Returns `null` if there's no serialized `Array` corresponding to the given key
# or if it's the wrong value type
- # Make sure that the serialized objects are `auto_serializable` or that they
+ # Make sure that the serialized objects are `auto_serializable` or that they
# redefine the appropriate methods. Refer to `Serializable` documentation
# for further details
fun deserialize_array(key: String): nullable Array[nullable Object]
fun bool(key: String, def_value: Bool): Bool
do
sys.jni_env.push_local_frame(1)
- var return_value =
+ var return_value =
native_bundle.get_boolean_with_def_value(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
return return_value
fun char(key: String, def_value: Char): Char
do
sys.jni_env.push_local_frame(1)
- var return_value =
+ var return_value =
native_bundle.get_char_with_def_value(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
return return_value
fun int(key: String, def_value: Int): Int
do
sys.jni_env.push_local_frame(1)
- var return_value =
+ var return_value =
native_bundle.get_long_with_def_value(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
return return_value
end
-
+
# Retrieves the `Float` value corresponding to the given key
# Returns the `def_value` if none or if it's the wrong value type
fun float(key: String, def_value: Float): Float
do
sys.jni_env.push_local_frame(1)
- var return_value =
+ var return_value =
native_bundle.get_double_with_def_value(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
return return_value
var return_value = native_bundle.get_string_array(key.to_java_string)
sys.jni_env.pop_local_frame
-
+
if return_value.is_empty then return null
return return_value
bundle.put_char_array(key, self)
else if self isa Array[String] then
sys.jni_env.push_local_frame(self.length)
- var java_string_array = new Array[JavaString]
+ var java_string_array = new Array[JavaString]
for element in self do
java_string_array.push(element.to_s.to_java_string)
`}
# Start tracking head movement
- fun start_tracking in "Java" `{ recv.startTracking(); `}
+ fun start_tracking in "Java" `{ self.startTracking(); `}
# Stop tracking head movement
- fun stop_tracking in "Java" `{ recv.stopTracking(); `}
+ fun stop_tracking in "Java" `{ self.stopTracking(); `}
# Apply correction to the gyroscope values
fun gyro_bias=(matrix: JavaFloatArray) in "Java" `{
- recv.setGyroBias(matrix);
+ self.setGyroBias(matrix);
`}
# Enable finer analysis using the neck as center of movement
fun neck_model_enabled=(value: Bool) in "Java" `{
- recv.setNeckModelEnabled(value);
+ self.setNeckModelEnabled(value);
`}
# Fill `matrix` with the last rotation matrix calculated from head movements
#
# Require: matrix.length >= offset + 16
fun last_head_view(matrix: JavaFloatArray, offset: Int) in "Java" `{
- recv.getLastHeadView(matrix, (int)offset);
+ self.getLastHeadView(matrix, (int)offset);
`}
end
end
private fun find_class_loader(native_activity: NativeActivity) import jni_env, class_loader=, JavaObject.as nullable, class_loader_method=, JMethodID.as nullable `{
- JNIEnv *env = Sys_jni_env(recv);
+ JNIEnv *env = Sys_jni_env(self);
// Retrieve main activity
jclass class_activity = (*env)->GetObjectClass(env, native_activity);
}
// Return the values to Nit
- Sys_class_loader__assign(recv, JavaObject_as_nullable((*env)->NewGlobalRef(env, instance_class_loader)));
- Sys_class_loader_method__assign(recv, JMethodID_as_nullable(class_class_loader_findClass));
+ Sys_class_loader__assign(self, JavaObject_as_nullable((*env)->NewGlobalRef(env, instance_class_loader)));
+ Sys_class_loader_method__assign(self, JMethodID_as_nullable(class_class_loader_findClass));
// Clean up
(*env)->DeleteLocalRef(env, class_activity);
`}
private fun load_jclass_intern(instance_class_loader: JavaObject, class_loader_findClass: JMethodID, name: NativeString): JClass import jni_env `{
- JNIEnv *env = Sys_jni_env(recv);
+ JNIEnv *env = Sys_jni_env(self);
jobject class_name = (*env)->NewStringUTF(env, name);
jclass java_class = (*env)->CallObjectMethod(env, instance_class_loader, class_loader_findClass, class_name);
private extern class NativeAndroidMotionEvent `{AInputEvent *`}
fun pointers_count: Int `{
- return AMotionEvent_getPointerCount(recv);
+ return AMotionEvent_getPointerCount(self);
`}
# Did this motion event just started?
fun just_went_down: Bool `{
- return (AMotionEvent_getAction(recv) & AMOTION_EVENT_ACTION_MASK) == AMOTION_EVENT_ACTION_DOWN;
+ return (AMotionEvent_getAction(self) & AMOTION_EVENT_ACTION_MASK) == AMOTION_EVENT_ACTION_DOWN;
`}
fun edge: Int `{
- return AMotionEvent_getEdgeFlags(recv);
+ return AMotionEvent_getEdgeFlags(self);
`}
# Get the non-primary pointer id that just went down (returns -1 or > 0)
fun index_down_pointer: Int `{
- int a = AMotionEvent_getAction(recv);
+ int a = AMotionEvent_getAction(self);
if ((a & AMOTION_EVENT_ACTION_MASK) == AMOTION_EVENT_ACTION_POINTER_DOWN)
return (a & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
else return -1;
`}
- fun action: AMotionEventAction `{ return AMotionEvent_getAction(recv); `}
+ fun action: AMotionEventAction `{ return AMotionEvent_getAction(self); `}
end
private extern class AMotionEventAction `{ int32_t `}
- fun action: Int `{ return recv & AMOTION_EVENT_ACTION_MASK; `}
+ fun action: Int `{ return self & AMOTION_EVENT_ACTION_MASK; `}
fun is_down: Bool do return action == 0
fun is_up: Bool do return action == 1
super KeyEvent
super AndroidInputEvent
- private fun action: Int `{ return AKeyEvent_getAction(recv); `}
+ private fun action: Int `{ return AKeyEvent_getAction(self); `}
redef fun is_down: Bool do return action == 0
redef fun is_up: Bool do return action == 1
# Hardware code of the key raising this event
- fun key_code: Int `{ return AKeyEvent_getKeyCode(recv); `}
+ fun key_code: Int `{ return AKeyEvent_getKeyCode(self); `}
redef fun to_c `{
- int code = AKeyEvent_getKeyCode(recv);
+ int code = AKeyEvent_getKeyCode(self);
if (code >= AKEYCODE_0 && code <= AKEYCODE_9)
return '0'+code-AKEYCODE_0;
if (code >= AKEYCODE_A && code <= AKEYCODE_Z)
new in "Java" `{ return new Intent(); `}
- fun add_category(category: JavaString) in "Java" `{ recv.addCategory(category); `}
- fun add_flags(flags: Int) in "Java" `{ recv.addFlags((int)flags); `}
+ fun add_category(category: JavaString) in "Java" `{ self.addCategory(category); `}
+ fun add_flags(flags: Int) in "Java" `{ self.addFlags((int)flags); `}
fun filter_equals(other: NativeIntent): Bool in "Java" `{
- return recv.filterEquals(other);
+ return self.filterEquals(other);
`}
- fun action: JavaString in "Java" `{ return recv.getAction(); `}
+ fun action: JavaString in "Java" `{ return self.getAction(); `}
fun boolean_array_extra(name: JavaString): Array[Bool] import Array[Bool],
Array[Bool].push in "Java" `{
- boolean[] java_array = recv.getBooleanArrayExtra(name);
+ boolean[] java_array = self.getBooleanArrayExtra(name);
int nit_array = new_Array_of_Bool();
for(int i=0; i < java_array.length; ++i)
return nit_array;
`}
fun boolean_extra(name: JavaString, def_value: Bool): Bool in "Java" `{
- return recv.getBooleanExtra(name, def_value);
+ return self.getBooleanExtra(name, def_value);
`}
fun byte_array_extra(name: JavaString): Array[Int] import Array[Int],
Array[Int].add in "Java" `{
- byte[] java_array = recv.getByteArrayExtra(name);
+ byte[] java_array = self.getByteArrayExtra(name);
int nit_array = new_Array_of_Int();
for (int i=0; i < java_array.length; ++i)
return nit_array;
`}
fun byte_extra(name: JavaString, def_value: Int): Int in "Java" `{
- return (int) recv.getByteExtra(name, (byte) def_value);
+ return (int) self.getByteExtra(name, (byte) def_value);
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun char_array_extra(name: JavaString): Array[Char] import Array[Char],
Array[Char].add in "Java" `{
- char[] java_array = recv.getCharArrayExtra(name);
+ char[] java_array = self.getCharArrayExtra(name);
int nit_array = new_Array_of_Char();
for (int i = 0; i < java_array.length; ++i)
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun char_extra(name: JavaString, def_value: Char): Char in "Java" `{
- return recv.getCharExtra(name, def_value);
+ return self.getCharExtra(name, def_value);
`}
fun char_sequence_array_extra(name: JavaString): Array[String]
import StringCopyArray, StringCopyArray.add, StringCopyArray.collection in "Java" `{
- CharSequence[] java_array = recv.getCharSequenceArrayExtra(name);
+ CharSequence[] java_array = self.getCharSequenceArrayExtra(name);
int nit_array = new_StringCopyArray();
for (int i = 0; i < java_array.length; ++i)
`}
fun char_sequence_array_list_extra(name: JavaString): Array[String]
import StringCopyArray, StringCopyArray.add, StringCopyArray.collection in "Java" `{
- ArrayList<CharSequence> java_array = recv.getCharSequenceArrayListExtra(name);
+ ArrayList<CharSequence> java_array = self.getCharSequenceArrayListExtra(name);
int nit_array = new_StringCopyArray();
if (java_array == null) return nit_array;
return StringCopyArray_collection(nit_array);
`}
fun char_sequence_extra(name: JavaString): JavaString in "Java" `{
- return (String) recv.getCharSequenceExtra(name);
+ return (String) self.getCharSequenceExtra(name);
`}
fun categories: HashSet[String] import StringCopyHashSet,
StringCopyHashSet.add, StringCopyHashSet.collection in "Java" `{
- Set<String> java_set = recv.getCategories();
+ Set<String> java_set = self.getCategories();
int nit_hashset = new_StringCopyHashSet();
if (java_set == null) return nit_hashset;
return StringCopyHashSet_collection(nit_hashset);
`}
# Returns the Uri as an encoded String
- fun data: JavaString in "Java" `{ return recv.getDataString(); `}
+ fun data: JavaString in "Java" `{ return self.getDataString(); `}
fun double_array_extra(name: JavaString): Array[Float] import Array[Float],
Array[Float].push in "Java" `{
- double[] java_array = recv.getDoubleArrayExtra(name);
+ double[] java_array = self.getDoubleArrayExtra(name);
int nit_array = new_Array_of_Float();
for(int i=0; i < java_array.length; ++i)
return nit_array;
`}
fun double_extra(name: JavaString, def_value: Float): Float in "Java" `{
- return recv.getDoubleExtra(name, def_value);
+ return self.getDoubleExtra(name, def_value);
`}
- fun flags: Int in "Java" `{ return recv.getFlags(); `}
+ fun flags: Int in "Java" `{ return self.getFlags(); `}
fun float_array_extra(name: JavaString): Array[Float] import Array[Float],
Array[Float].push in "Java" `{
- float[] java_array = recv.getFloatArrayExtra(name);
+ float[] java_array = self.getFloatArrayExtra(name);
int nit_array = new_Array_of_Float();
for(int i=0; i < java_array.length; ++i)
return nit_array;
`}
fun float_extra(name: JavaString, def_value: Float): Float in "Java" `{
- return recv.getFloatExtra(name, (float) def_value);
+ return self.getFloatExtra(name, (float) def_value);
`}
fun int_array_extra(name: JavaString): Array[Int] import Array[Int],
Array[Int].push in "Java" `{
- int[] java_array = recv.getIntArrayExtra(name);
+ int[] java_array = self.getIntArrayExtra(name);
int nit_array = new_Array_of_Int();
for(int i=0; i < java_array.length; ++i)
return nit_array;
`}
fun int_extra(name: JavaString, def_value: Int): Int in "Java" `{
- return recv.getIntExtra(name, (int)def_value);
+ return self.getIntExtra(name, (int)def_value);
`}
fun long_array_extra(name: JavaString): Array[Int] import Array[Int],
Array[Int].push in "Java" `{
- long[] java_array = recv.getLongArrayExtra(name);
+ long[] java_array = self.getLongArrayExtra(name);
int nit_array = new_Array_of_Int();
for(int i=0; i < java_array.length; ++i)
return nit_array;
`}
fun long_extra(name: JavaString, def_value: Int): Int in "Java" `{
- return (int) recv.getLongExtra(name, def_value);
+ return (int) self.getLongExtra(name, def_value);
`}
- fun get_package: JavaString in "Java" `{ return recv.getPackage(); `}
- fun scheme: JavaString in "Java" `{ return recv.getScheme(); `}
+ fun get_package: JavaString in "Java" `{ return self.getPackage(); `}
+ fun scheme: JavaString in "Java" `{ return self.getScheme(); `}
fun short_array_extra(name: JavaString): Array[Int] import Array[Int],
Array[Int].push in "Java" `{
- short[] java_array = recv.getShortArrayExtra(name);
+ short[] java_array = self.getShortArrayExtra(name);
int nit_array = new_Array_of_Int();
for(int i=0; i < java_array.length; ++i)
return nit_array;
`}
fun short_extra(name: JavaString, def_value: Int): Int in "Java" `{
- return recv.getShortExtra(name, (short) def_value);
+ return self.getShortExtra(name, (short) def_value);
`}
fun string_array_extra(name: JavaString): Array[String]
import StringCopyArray, StringCopyArray.add, StringCopyArray.collection in "Java" `{
- String[] java_array = recv.getStringArrayExtra(name);
+ String[] java_array = self.getStringArrayExtra(name);
int nit_array = new_StringCopyArray();
for(int i=0; i < java_array.length; ++i)
`}
fun string_array_list_extra(name: JavaString): Array[String]
import StringCopyArray, StringCopyArray.add, StringCopyArray.collection in "Java" `{
- ArrayList<String> java_array = recv.getStringArrayListExtra(name);
+ ArrayList<String> java_array = self.getStringArrayListExtra(name);
int nit_array = new_StringCopyArray();
for (String element: java_array)
return StringCopyArray_collection(nit_array);
`}
fun string_extra(name: JavaString): JavaString in "Java" `{
- String return_value = recv.getStringExtra(name);
+ String return_value = self.getStringExtra(name);
if (return_value == null) return "";
return return_value;
`}
- fun get_type: JavaString in "Java" `{ return recv.getType(); `}
+ fun get_type: JavaString in "Java" `{ return self.getType(); `}
fun has_category(category: JavaString): Bool in "Java" `{
- return recv.hasCategory(category);
+ return self.hasCategory(category);
`}
- fun has_extra(extra: JavaString): Bool in "Java" `{ return recv.hasExtra(extra); `}
- fun has_file_descriptors: Bool in "Java" `{ return recv.hasFileDescriptors(); `}
+ fun has_extra(extra: JavaString): Bool in "Java" `{ return self.hasExtra(extra); `}
+ fun has_file_descriptors: Bool in "Java" `{ return self.hasFileDescriptors(); `}
fun add_extra_double(name: JavaString, value: Float): NativeIntent in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
fun add_extra_array_of_double(name: JavaString, value: Array[Float]): NativeIntent
import Array[Float].length, Array[Float].[] in "Java" `{
for (int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Float__index(value, i);
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun add_extra_char(name: JavaString, value: Char): NativeIntent in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun add_extra_array_of_char(name: JavaString, value: Array[Char]): NativeIntent
for (int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Char__index(value, i);
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
fun add_extra_char_sequence(name: JavaString, value: JavaString): NativeIntent
in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
fun add_extra_array_of_char_sequence(name: JavaString, value: Array[JavaString]):
NativeIntent import Array[JavaString].length, Array[JavaString].[] in "Java" `{
for (int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_JavaString__index(value, i);
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
fun add_extra_bundle(name: JavaString, value: NativeBundle): NativeIntent
in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
fun add_extra_int(name: JavaString, value: Int): NativeIntent in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
fun add_extra_array_of_int(name: JavaString, value: Array[Int]): NativeIntent
import Array[Int].length, Array[Int].[] in "Java" `{
for (int i=0; i < java_array.length; ++i)
java_array[i] = (int)Array_of_Int__index(value, i);
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
fun add_extra_array_list_of_int(name: JavaString, value: Array[Int]): NativeIntent
import Array[Int].length, Array[Int].[] in "Java" `{
for (int i=0; i < length; ++i)
java_array.add((int)Array_of_Int__index(value, i));
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
fun add_extra_byte(name: JavaString, value: Int): NativeIntent in "Java" `{
- return recv.putExtra(name, (byte) value);
+ return self.putExtra(name, (byte) value);
`}
fun add_extra_array_of_byte(name: JavaString, value: Int): NativeIntent in "Java" `{
- return recv.putExtra(name, (byte) value);
+ return self.putExtra(name, (byte) value);
`}
fun add_extra_long(name: JavaString, value: Int): NativeIntent in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
fun add_extra_array_of_long(name: JavaString, value: Array[Int]): NativeIntent
import Array[Int].length, Array[Int].[] in "Java" `{
for (int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Int__index(value, i);
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
fun add_extra_float(name: JavaString, value: Float): NativeIntent in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
fun add_extra_array_of_float(name: JavaString, value: Array[Float]): NativeIntent
import Array[Float].length, Array[Float].[] in "Java" `{
for (int i=0; i < java_array.length; ++i)
java_array[i] = (float) Array_of_Float__index(value, i);
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
fun add_extra_string(name: JavaString, value: JavaString): NativeIntent in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
fun add_extra_array_of_string(name: JavaString, value: Array[JavaString]): NativeIntent
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
for (int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_JavaString__index(value, i);
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
fun add_extra_array_list_of_string(name: JavaString, value: Array[JavaString]): NativeIntent
import Array[JavaString].length, Array[JavaString].[] in "Java" `{
java_array.add(Array_of_JavaString__index(value, i));
}
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
fun add_extra_bool(name: JavaString, value: Bool): NativeIntent in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
fun add_extra_array_of_bool(name: JavaString, value: Array[Bool]): NativeIntent
import Array[Bool].length, Array[Bool].[] in "Java" `{
for (int i=0; i < java_array.length; ++i)
java_array[i] = Array_of_Bool__index(value, i);
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
fun add_extra_short(name: JavaString, value: Int): NativeIntent in "Java" `{
- return recv.putExtra(name, value);
+ return self.putExtra(name, value);
`}
fun add_extra_array_of_short(name: JavaString, value: Array[Int]): NativeIntent
import Array[Int].length, Array[Int].[] in "Java" `{
for (int i=0; i < java_array.length; ++i)
java_array[i] = (short) Array_of_Int__index(value, i);
- return recv.putExtra(name, java_array);
+ return self.putExtra(name, java_array);
`}
- fun copy_extras(src: NativeIntent): NativeIntent in "Java" `{ return recv.putExtras(src); `}
- fun add_extras(src: NativeBundle): NativeIntent in "Java" `{ return recv.putExtras(src); `}
- fun remove_category(category: JavaString) in "Java" `{ recv.removeCategory(category); `}
- fun remove_extra(name: JavaString) in "Java" `{ recv.removeExtra(name); `}
+ fun copy_extras(src: NativeIntent): NativeIntent in "Java" `{ return self.putExtras(src); `}
+ fun add_extras(src: NativeBundle): NativeIntent in "Java" `{ return self.putExtras(src); `}
+ fun remove_category(category: JavaString) in "Java" `{ self.removeCategory(category); `}
+ fun remove_extra(name: JavaString) in "Java" `{ self.removeExtra(name); `}
fun replace_extras(src: NativeIntent): NativeIntent in "Java" `{
- return recv.replaceExtras(src);
+ return self.replaceExtras(src);
`}
fun resolve_activity(pm: NativePackageManager): NativeComponentName in "Java" `{
- return recv.resolveActivity(pm);
+ return self.resolveActivity(pm);
`}
fun resolve_type(context: NativeActivity): JavaString in "Java" `{
- return recv.resolveType(context);
+ return self.resolveType(context);
`}
- fun action=(action: JavaString): NativeIntent in "Java" `{ return recv.setAction(action); `}
+ fun action=(action: JavaString): NativeIntent in "Java" `{ return self.setAction(action); `}
fun class_=(package_context: NativeActivity, class_name: JavaString): NativeIntent
in "Java" `{
Class<?> java_class = null;
} catch (Exception e) {
e.getStackTrace();
}
- return recv.setClass(package_context, java_class);
+ return self.setClass(package_context, java_class);
`}
fun class_name=(package_context: NativeActivity, class_name: JavaString): NativeIntent
in "Java" `{
- return recv.setClassName(package_context, class_name);
+ return self.setClassName(package_context, class_name);
`}
fun set_class_name(package_name: JavaString, class_name: JavaString): NativeIntent
in "Java" `{
- return recv.setClassName(package_name, class_name);
+ return self.setClassName(package_name, class_name);
`}
fun data=(data_uri: JavaString): NativeIntent in "Java" `{
- return recv.setData(Uri.parse(data_uri));
+ return self.setData(Uri.parse(data_uri));
`}
fun data_and_type=(data_uri: JavaString, type_: JavaString): NativeIntent in "Java" `{
- return recv.setDataAndType(Uri.parse(data_uri), type_);
+ return self.setDataAndType(Uri.parse(data_uri), type_);
`}
- fun flags=(flags: Int): NativeIntent in "Java" `{ return recv.setFlags((int)flags); `}
+ fun flags=(flags: Int): NativeIntent in "Java" `{ return self.setFlags((int)flags); `}
fun package_name=(package_name: JavaString): NativeIntent in "Java" `{
- return recv.setPackage(package_name);
+ return self.setPackage(package_name);
`}
fun source_bounds=(left, top, right, bottom: Int) in "Java" `{
- recv.setSourceBounds(new Rect((int)left, (int)top, (int)right, (int)bottom));
+ self.setSourceBounds(new Rect((int)left, (int)top, (int)right, (int)bottom));
`}
fun mime_type=(mime_type: JavaString): NativeIntent in "Java" `{
- return recv.setType(mime_type);
+ return self.setType(mime_type);
`}
- fun to_native_s: JavaString in "Java" `{ return recv.toString(); `}
- fun to_uri(flags: Int): JavaString in "Java" `{ return recv.toUri((int)flags); `}
+ fun to_native_s: JavaString in "Java" `{ return self.toString(); `}
+ fun to_uri(flags: Int): JavaString in "Java" `{ return self.toUri((int)flags); `}
# HACK for bug #845
redef fun new_global_ref import sys, Sys.jni_env `{
- Sys sys = NativeIntent_sys(recv);
+ Sys sys = NativeIntent_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
end
redef extern class NativeActivity
- private fun start_activity(intent: NativeIntent) in "Java" `{ recv.startActivity(intent); `}
- private fun start_service(intent: NativeIntent) in "Java" `{ recv.startService(intent); `}
- private fun stop_service(intent: NativeIntent) in "Java" `{ recv.stopService(intent); `}
+ private fun start_activity(intent: NativeIntent) in "Java" `{ self.startActivity(intent); `}
+ private fun start_service(intent: NativeIntent) in "Java" `{ self.startService(intent); `}
+ private fun stop_service(intent: NativeIntent) in "Java" `{ self.stopService(intent); `}
end
# Allows user to get values with enum-like syntax : `intent_action.main`
`}
redef extern class NativeIntent
- fun selector=(selector: NativeIntent) in "Java" `{ recv.setSelector(selector); `}
+ fun selector=(selector: NativeIntent) in "Java" `{ self.setSelector(selector); `}
end
redef class Category
`}
redef extern class NativeIntent
- fun set_data_and_normalize(data_uri: JavaString): NativeIntent in "Java" `{ return recv.setDataAndNormalize(Uri.parse(data_uri)); `}
- fun set_data_and_type_and_normalize(data_uri: JavaString, type_: JavaString): NativeIntent in "Java" `{ return recv.setDataAndTypeAndNormalize(Uri.parse(data_uri), type_); `}
- fun set_mime_type_and_normalize(mime_type: JavaString): NativeIntent in "Java" `{ return recv.setTypeAndNormalize(mime_type); `}
+ fun set_data_and_normalize(data_uri: JavaString): NativeIntent in "Java" `{ return self.setDataAndNormalize(Uri.parse(data_uri)); `}
+ fun set_data_and_type_and_normalize(data_uri: JavaString, type_: JavaString): NativeIntent in "Java" `{ return self.setDataAndTypeAndNormalize(Uri.parse(data_uri), type_); `}
+ fun set_mime_type_and_normalize(mime_type: JavaString): NativeIntent in "Java" `{ return self.setTypeAndNormalize(mime_type); `}
end
redef class Extra
int event;
void* source;
while ((ident=ALooper_pollAll(timeout_ms, NULL, &event, &source)) >= 0) {
- App_handle_looper_event(recv, ident, event, source);
+ App_handle_looper_event(self, ident, event, source);
}
`}
destroy, start, resume, low_memory, config_changed, input_changed,
window_resized, window_redraw_needed, content_rect_changed `{
- struct android_app *app_glue = App_native_app_glue(recv);
+ struct android_app *app_glue = App_native_app_glue(self);
struct android_poll_source* source = (struct android_poll_source*)data;
// Process this event.
#fun set_callbacks_handler(handler: App) or callbacks= ...
# Java VM associated to `self`
- fun vm: JavaVM `{ return recv->vm; `}
+ fun vm: JavaVM `{ return self->vm; `}
# JNI environmnet associated to `self`
- fun env: JniEnv `{ return recv->env; `}
+ fun env: JniEnv `{ return self->env; `}
# The `NativeActivity`, as in the Java object, associated to `self`
- fun java_native_activity: NativeActivity `{ return recv->clazz; `}
+ fun java_native_activity: NativeActivity `{ return self->clazz; `}
# Path to this application's internal data directory.
- fun internal_data_path: NativeString `{ return (char*)recv->internalDataPath; `}
+ fun internal_data_path: NativeString `{ return (char*)self->internalDataPath; `}
# Path to this application's external (removable/mountable) data directory.
- fun external_data_path: NativeString `{ return (char*)recv->externalDataPath; `}
+ fun external_data_path: NativeString `{ return (char*)self->externalDataPath; `}
# The platform's SDK version code.
- fun sdk_version: Int `{ return recv->sdkVersion; `}
+ fun sdk_version: Int `{ return self->sdkVersion; `}
# This is the native instance of the application. It is not used by
# the framework, but can be set by the application to its own instance
# state.
- fun instance: Pointer `{ return recv->instance; `}
+ fun instance: Pointer `{ return self->instance; `}
# Pointer to the Asset Manager instance for the application. The application
# uses this to access binary assets bundled inside its own .apk file.
#
# TODO activate in a future `asset_manager` module if it cannot be done in Java
- #fun asset_manager: AssetManager `{ return recv->assetManager; `}
+ #fun asset_manager: AssetManager `{ return self->assetManager; `}
# Available starting with Honeycomb: path to the directory containing
# the application's OBB files (if any). If the app doesn't have any
# api?
#
# TODO activate in a future module at API 11
- #fun obb_path: NativeString `{ return (char*)recv->obbPath; `}
+ #fun obb_path: NativeString `{ return (char*)self->obbPath; `}
end
# This is the interface for the standard glue code of a threaded
extern class NativeAppGlue `{ struct android_app* `}
# We use the `userData` field of the C structure to store an handle to
# the associated App
- private fun user_data: App `{ return recv->userData; `}
+ private fun user_data: App `{ return self->userData; `}
private fun user_data=(val: App) `{
App_incr_ref(val);
- recv->userData = val;
+ self->userData = val;
`}
# Fill this in with the function to process input events. At this point
#fun set_input_event_handler(handler: App) `{ `}
# The ANativeActivity object instance that this app is running in.
- fun ndk_native_activity: NdkNativeActivity `{ return recv->activity; `}
+ fun ndk_native_activity: NdkNativeActivity `{ return self->activity; `}
# The current configuration the app is running in.
- fun config: AConfiguration `{ return recv->config; `}
+ fun config: AConfiguration `{ return self->config; `}
# This is the last instance's saved state, as provided at creation time.
# It is NULL if there was no state. You can use this as you need; the
# at which point they will be initialized to NULL and you can malloc your
# state and place the information here. In that case the memory will be
# freed for you later.
- fun saved_state: Pointer `{ return recv->savedState; `}
- fun saved_state_size: Int `{ return recv->savedStateSize; `}
+ fun saved_state: Pointer `{ return self->savedState; `}
+ fun saved_state_size: Int `{ return self->savedStateSize; `}
# The ALooper associated with the app's thread.
- fun looper: ALooper `{ return recv->looper; `}
+ fun looper: ALooper `{ return self->looper; `}
# When non-NULL, this is the input queue from which the app will
# receive user input events.
- fun input_queue: AInputQueue `{ return recv->inputQueue; `}
+ fun input_queue: AInputQueue `{ return self->inputQueue; `}
# When non-NULL, this is the window surface that the app can draw in.
- fun window: ANativeWindow `{ return recv->window; `}
+ fun window: ANativeWindow `{ return self->window; `}
# Current content rectangle of the window; this is the area where the
# window's content should be placed to be seen by the user.
#
# TODO activate when we know what to return (returns a struct not a pointer)
- #fun content_recv: ARect `{ return recv->contentRect; `}
+ #fun content_self: ARect `{ return self->contentRect; `}
# Current state of the app's activity. May be either APP_CMD_START,
# APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below.
- fun activity_state: Int `{ return recv->activityState; `}
+ fun activity_state: Int `{ return self->activityState; `}
# This is non-zero when the application's NativeActivity is being
# destroyed and waiting for the app thread to complete.
- fun detroy_request: Bool `{ return recv->destroyRequested; `}
+ fun detroy_request: Bool `{ return self->destroyRequested; `}
end
# Android NDK's struture holding configurations of the native app
Activity.on_start, Activity.on_restart, Activity.on_stop,
Activity.on_pause, Activity.on_resume,
Activity.on_save_instance_state, Activity.on_restore_instance_state `{
- App_incr_ref(recv);
- global_app = recv;
+ App_incr_ref(self);
+ global_app = self;
`}
# Create the Nit side to this new `native` Java activity, and return it to Java
redef class NativeActivity
fun notification_manager: NativeNotificationManager in "Java" `{
- return (NotificationManager)recv.getSystemService(Context.NOTIFICATION_SERVICE);
+ return (NotificationManager)self.getSystemService(Context.NOTIFICATION_SERVICE);
`}
end
extern class NativeNotificationManager in "Java" `{ android.app.NotificationManager `}
fun notify(tag: JavaString, id: Int, notif: NativeNotification) in "Java" `{
- recv.notify(tag, (int)id, notif);
+ self.notify(tag, (int)id, notif);
`}
- fun cancel(tag: JavaString, id: Int) in "Java" `{ recv.cancel(tag, (int)id); `}
+ fun cancel(tag: JavaString, id: Int) in "Java" `{ self.cancel(tag, (int)id); `}
- fun cancel_all in "Java" `{ recv.cancelAll(); `}
+ fun cancel_all in "Java" `{ self.cancelAll(); `}
end
extern class NativeNotification in "Java" `{ android.app.Notification `}
fun create: NativeNotification in "Java" `{
// Deprecated since API 16, which introduces `build`,
// refinement and global compilation should prevent warnings.
- return recv.getNotification();
+ return self.getNotification();
`}
- fun title=(value: JavaString) in "Java" `{ recv.setContentTitle(value); `}
+ fun title=(value: JavaString) in "Java" `{ self.setContentTitle(value); `}
- fun text=(value: JavaString) in "Java" `{ recv.setContentText(value); `}
+ fun text=(value: JavaString) in "Java" `{ self.setContentText(value); `}
- fun ticker=(value: JavaString) in "Java" `{ recv.setTicker(value); `}
+ fun ticker=(value: JavaString) in "Java" `{ self.setTicker(value); `}
- fun small_icon=(value: Int) in "Java" `{ recv.setSmallIcon((int)value); `}
+ fun small_icon=(value: Int) in "Java" `{ self.setSmallIcon((int)value); `}
- fun auto_cancel=(value: Bool) in "Java" `{ recv.setAutoCancel(value); `}
+ fun auto_cancel=(value: Bool) in "Java" `{ self.setAutoCancel(value); `}
- fun number=(value: Int) in "Java" `{ recv.setNumber((int)value); `}
+ fun number=(value: Int) in "Java" `{ self.setNumber((int)value); `}
- fun ongoing=(value: Bool) in "Java" `{ recv.setOngoing(value); `}
+ fun ongoing=(value: Bool) in "Java" `{ self.setOngoing(value); `}
end
extern class ASensorType `{int`}
new accelerometer: ASensorType `{return ASENSOR_TYPE_ACCELEROMETER;`}
- fun is_accelerometer: Bool `{return recv == ASENSOR_TYPE_ACCELEROMETER;`}
+ fun is_accelerometer: Bool `{return self == ASENSOR_TYPE_ACCELEROMETER;`}
new magnetic_field: ASensorType `{return ASENSOR_TYPE_MAGNETIC_FIELD;`}
- fun is_magnetic_field: Bool `{return recv == ASENSOR_TYPE_MAGNETIC_FIELD;`}
+ fun is_magnetic_field: Bool `{return self == ASENSOR_TYPE_MAGNETIC_FIELD;`}
new gyroscope:ASensorType `{return ASENSOR_TYPE_GYROSCOPE;`}
- fun is_gyroscope: Bool `{ return recv == ASENSOR_TYPE_GYROSCOPE;`}
+ fun is_gyroscope: Bool `{ return self == ASENSOR_TYPE_GYROSCOPE;`}
new light: ASensorType `{return ASENSOR_TYPE_LIGHT;`}
- fun is_light: Bool `{return recv == ASENSOR_TYPE_LIGHT;`}
+ fun is_light: Bool `{return self == ASENSOR_TYPE_LIGHT;`}
new proximity: ASensorType `{return ASENSOR_TYPE_PROXIMITY;`}
- fun is_proximity:Bool `{return recv == ASENSOR_TYPE_PROXIMITY;`}
+ fun is_proximity:Bool `{return self == ASENSOR_TYPE_PROXIMITY;`}
end
# Manages the sensors
# Returns the list of available sensors
fun get_sensor_list: Pointer `{
ASensorList *list;
- ASensorManager_getSensorList(recv, list);
+ ASensorManager_getSensorList(self, list);
return list;
`}
# Create a new sensor event queue and associate it with a looper
fun create_event_queue(app: NativeAppGlue): ASensorEventQueue `{
- return ASensorManager_createEventQueue(recv, app->looper, LOOPER_ID_USER, NULL, NULL);
+ return ASensorManager_createEventQueue(self, app->looper, LOOPER_ID_USER, NULL, NULL);
`}
# Returns the default sensor of the given type
fun get_default_sensor(sensortype: ASensorType): ASensor `{
- return ASensorManager_getDefaultSensor(recv, sensortype);
+ return ASensorManager_getDefaultSensor(self, sensortype);
`}
# Destroys the event queue and free all resources associated to it
fun destroy_event_queue(queue: ASensorEventQueue) `{
- ASensorManager_destroyEventQueue(recv, queue);
+ ASensorManager_destroyEventQueue(self, queue);
`}
end
# Enable the selected sensor, returns a negative value on error
fun enable_sensor(sensor: ASensor): Int `{
- return ASensorEventQueue_enableSensor(recv, sensor);
+ return ASensorEventQueue_enableSensor(self, sensor);
`}
# Disable the selected sensor, returns a negative value on error
fun disable_sensor(sensor: ASensor): Int `{
- return ASensorEventQueue_disableSensor(recv, sensor);
+ return ASensorEventQueue_disableSensor(self, sensor);
`}
# Set the delivery rate of events in microseconds for the given sensor
fun set_event_rate(sensor: ASensor, usec: Int): Int `{
- return ASensorEventQueue_setEventRate(recv, sensor, usec);
+ return ASensorEventQueue_setEventRate(self, sensor, usec);
`}
# Returns 1 if the queue has events, 0 if it does not have events,
# and a negative value if there is an error
fun has_events: Int `{
- return ASensorEventQueue_hasEvents(recv);
+ return ASensorEventQueue_hasEvents(self);
`}
# Returns the next available events from the queue.
# Returns a negative value if no events are available or an error has occured
# otherwise the number of events returned
fun get_events(events: ASensorEvents, count: Int): Int `{
- return ASensorEventQueue_getEvents(recv, events, (size_t)count);
+ return ASensorEventQueue_getEvents(self, events, (size_t)count);
`}
end
extern class ASensor `{ASensorRef`}
new `{return malloc(sizeof(ASensorRef));`}
- fun name: NativeString `{return (char*)ASensor_getName(recv);`}
- fun vendor: NativeString `{return (char*)ASensor_getVendor(recv);`}
- fun sensor_type: ASensorType `{return ASensor_getType(recv);`}
- fun resolution: Float `{return ASensor_getResolution(recv);`}
- fun min_delay: Int `{return ASensor_getMinDelay(recv);`}
+ fun name: NativeString `{return (char*)ASensor_getName(self);`}
+ fun vendor: NativeString `{return (char*)ASensor_getVendor(self);`}
+ fun sensor_type: ASensorType `{return ASensor_getType(self);`}
+ fun resolution: Float `{return ASensor_getResolution(self);`}
+ fun min_delay: Int `{return ASensor_getMinDelay(self);`}
end
# NIT representation of an Android Sensor used in android_app to initialize sensors
extern class ASensorEvent `{ASensorEvent*`}
super SensorEvent
- fun version: Int `{return recv->version;`}
- fun sensor: ASensor `{return (ASensorRef)recv->sensor;`}
- fun sensor_type: ASensorType `{return recv->type;`}
- fun timestamp: Int `{return recv->timestamp;`}
+ fun version: Int `{return self->version;`}
+ fun sensor: ASensor `{return (ASensorRef)self->sensor;`}
+ fun sensor_type: ASensorType `{return self->type;`}
+ fun timestamp: Int `{return self->timestamp;`}
end
extern class FullSensor `{ASensorEvent*`}
super ASensorLight
super ASensorProximity
- fun temperature: Float `{return recv->temperature;`}
- fun pressure: Float `{return recv->pressure;`}
- fun data: Pointer `{return recv->data;`}
- fun vector: ASensorVector `{return &(recv->vector);`}
- fun acceleration: ASensorVector `{return &(recv->acceleration);`}
- fun magnetic: ASensorVector `{return &(recv->magnetic);`}
+ fun temperature: Float `{return self->temperature;`}
+ fun pressure: Float `{return self->pressure;`}
+ fun data: Pointer `{return self->data;`}
+ fun vector: ASensorVector `{return &(self->vector);`}
+ fun acceleration: ASensorVector `{return &(self->acceleration);`}
+ fun magnetic: ASensorVector `{return &(self->magnetic);`}
end
# Extern class referencing a ASensorVector, attribute of ASensorRef
extern class ASensorVector `{ASensorVector*`}
- fun v: Pointer `{return recv->v;`}
- fun x: Float `{ return recv->x;`}
- fun y: Float `{return recv->y;`}
- fun z: Float `{return recv->z;`}
- fun azimuth: Float `{return recv->azimuth;`}
- fun pitch: Float `{return recv->pitch;`}
- fun roll: Float `{return recv->roll;`}
- fun status: Int `{return recv->status;`}
- fun reserved: Pointer `{return recv->reserved;`}
+ fun v: Pointer `{return self->v;`}
+ fun x: Float `{ return self->x;`}
+ fun y: Float `{return self->y;`}
+ fun z: Float `{return self->z;`}
+ fun azimuth: Float `{return self->azimuth;`}
+ fun pitch: Float `{return self->pitch;`}
+ fun roll: Float `{return self->roll;`}
+ fun status: Int `{return self->status;`}
+ fun reserved: Pointer `{return self->reserved;`}
end
# Sensor event returned by the Accelerometer sensor
extern class ASensorAccelerometer `{ASensorEvent*`}
super ASensorEvent
- fun x: Float `{return recv->acceleration.x;`}
- fun y: Float `{return recv->acceleration.y;`}
- fun z: Float `{return recv->acceleration.z;`}
+ fun x: Float `{return self->acceleration.x;`}
+ fun y: Float `{return self->acceleration.y;`}
+ fun z: Float `{return self->acceleration.z;`}
end
# Sensor event returned by the Magnetic Field sensor
extern class ASensorMagneticField `{ASensorEvent*`}
super ASensorEvent
- fun x: Float `{return recv->magnetic.x;`}
- fun y: Float `{return recv->magnetic.y;`}
- fun z: Float `{ return recv->magnetic.z;`}
+ fun x: Float `{return self->magnetic.x;`}
+ fun y: Float `{return self->magnetic.y;`}
+ fun z: Float `{ return self->magnetic.z;`}
end
# Sensor event returned by the gyroscope sensor
extern class ASensorGyroscope `{ASensorEvent*`}
super ASensorEvent
- fun x: Float `{return recv->vector.x;`}
- fun y: Float `{return recv->vector.y;`}
- fun z: Float `{return recv->vector.y;`}
+ fun x: Float `{return self->vector.x;`}
+ fun y: Float `{return self->vector.y;`}
+ fun z: Float `{return self->vector.y;`}
end
# Sensor event returned by the Light sensor
extern class ASensorLight `{ASensorEvent*`}
super ASensorEvent
- fun light: Float `{return recv->light;`}
+ fun light: Float `{return self->light;`}
end
# sensor event returned by the Proximity Sensor
extern class ASensorProximity `{ASensorEvent*`}
super ASensorEvent
- fun distance: Float `{return recv->distance;`}
+ fun distance: Float `{return self->distance;`}
end
# Array of SensorEvents
new (length: Int) `{return malloc(sizeof(ASensorEvent)*length);`}
fun [](index: Int): ASensorEvent `{
- return recv+index;
+ return self+index;
`}
end
//maybe add a boolean to the app to know if we want to use Sensor API or ASensorEvent directly ...
ASensorEvent* events = malloc(sizeof(ASensorEvent)*10);
int nbevents;
- ASensorEventQueue* queue = App_eventqueue(recv);
+ ASensorEventQueue* queue = App_eventqueue(self);
while((nbevents = ASensorEventQueue_getEvents(queue, events, 10)) > 0) {
int i;
for(i = 0; i < nbevents; i++){
ASensorEvent event = events[i];
switch (event.type) {
case ASENSOR_TYPE_ACCELEROMETER:
- App_extern_input_sensor_accelerometer(recv, &event);
+ App_extern_input_sensor_accelerometer(self, &event);
break;
case ASENSOR_TYPE_MAGNETIC_FIELD:
- App_extern_input_sensor_magnetic_field(recv, &event);
+ App_extern_input_sensor_magnetic_field(self, &event);
break;
case ASENSOR_TYPE_GYROSCOPE:
- App_extern_input_sensor_gyroscope(recv, &event);
+ App_extern_input_sensor_gyroscope(self, &event);
break;
case ASENSOR_TYPE_LIGHT:
- App_extern_input_sensor_light(recv, &event);
+ App_extern_input_sensor_light(self, &event);
break;
case ASENSOR_TYPE_PROXIMITY:
- App_extern_input_sensor_proximity(recv, &event);
+ App_extern_input_sensor_proximity(self, &event);
break;
}
}
extern class NativeSharedPreferences in "Java" `{ android.content.SharedPreferences `}
super JavaObject
-
- fun contains(key: JavaString): Bool in "Java" `{ return recv.contains(key); `}
+
+ fun contains(key: JavaString): Bool in "Java" `{ return self.contains(key); `}
fun get_all: HashMap[JavaString, JavaObject] import HashMap[JavaString, JavaObject],
- HashMap[JavaString, JavaObject].[]= in "Java" `{
+ HashMap[JavaString, JavaObject].[]= in "Java" `{
Map<String, ?> java_map = null;
int nit_hashmap = new_HashMap_of_JavaString_JavaObject();
try {
- java_map = recv.getAll();
+ java_map = self.getAll();
} catch (NullPointerException e) {
return nit_hashmap;
}
for (Map.Entry<String, ?> entry: java_map.entrySet())
- HashMap_of_JavaString_JavaObject__index_assign(nit_hashmap,
+ HashMap_of_JavaString_JavaObject__index_assign(nit_hashmap,
entry.getKey(), entry.getValue());
return nit_hashmap;
`}
- fun get_boolean(key: JavaString, def_value: Bool): Bool in "Java" `{
+ fun get_boolean(key: JavaString, def_value: Bool): Bool in "Java" `{
boolean return_value;
try {
- return_value = recv.getBoolean(key, def_value);
+ return_value = self.getBoolean(key, def_value);
} catch (ClassCastException e) {
return def_value;
}
return return_value;
`}
- fun get_float(key: JavaString, def_value: Float): Float in "Java" `{
+ fun get_float(key: JavaString, def_value: Float): Float in "Java" `{
float return_value;
try {
- return_value = recv.getFloat(key, (float) def_value);
+ return_value = self.getFloat(key, (float) def_value);
} catch (ClassCastException e) {
return def_value;
}
fun get_int(key: JavaString, def_value: Int): Int in "Java" `{
int return_value;
try {
- return_value = recv.getInt(key, (int)def_value);
+ return_value = self.getInt(key, (int)def_value);
} catch (ClassCastException e) {
return def_value;
}
fun get_long(key: JavaString, def_value: Int): Int in "Java" `{
long return_value;
try {
- return_value = recv.getLong(key, def_value);
+ return_value = self.getLong(key, def_value);
} catch (ClassCastException e) {
return def_value;
}
fun get_string(key: JavaString, def_value: JavaString): JavaString in "Java" `{
String return_value = null;
try {
- return_value = recv.getString(key, def_value);
+ return_value = self.getString(key, def_value);
} catch (ClassCastException e) {
return def_value;
}
# HACK for bug #845
redef fun new_global_ref import sys, Sys.jni_env `{
- Sys sys = NativeSharedPreferences_sys(recv);
+ Sys sys = NativeSharedPreferences_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
extern class NativeSharedPreferencesEditor in "Java" `{ android.content.SharedPreferences$Editor `}
super JavaObject
- fun clear: NativeSharedPreferencesEditor in "Java" `{ return recv.clear(); `}
- fun commit: Bool in "Java" `{ return recv.commit(); `}
- fun put_boolean(key: JavaString, value: Bool ): NativeSharedPreferencesEditor in "Java" `{
- return recv.putBoolean (key, value);
+ fun clear: NativeSharedPreferencesEditor in "Java" `{ return self.clear(); `}
+ fun commit: Bool in "Java" `{ return self.commit(); `}
+ fun put_boolean(key: JavaString, value: Bool): NativeSharedPreferencesEditor in "Java" `{
+ return self.putBoolean (key, value);
`}
fun put_float(key: JavaString, value: Float): NativeSharedPreferencesEditor in "Java" `{
- return recv.putFloat(key, (float) value);
+ return self.putFloat(key, (float) value);
`}
fun put_int(key: JavaString, value: Int): NativeSharedPreferencesEditor in "Java" `{
- return recv.putInt(key, (int)value);
+ return self.putInt(key, (int)value);
`}
fun put_long(key: JavaString, value: Int): NativeSharedPreferencesEditor in "Java" `{
- return recv.putLong(key, value);
+ return self.putLong(key, value);
`}
fun put_string(key: JavaString, value: JavaString): NativeSharedPreferencesEditor in "Java" `{
- return recv.putString(key, value);
+ return self.putString(key, value);
`}
- fun remove(key: JavaString): NativeSharedPreferencesEditor in "Java" `{
- return recv.remove(key);
+ fun remove(key: JavaString): NativeSharedPreferencesEditor in "Java" `{
+ return self.remove(key);
`}
# HACK for bug #845
redef fun new_global_ref import sys, Sys.jni_env `{
- Sys sys = NativeSharedPreferencesEditor_sys(recv);
+ Sys sys = NativeSharedPreferencesEditor_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
# Automatically commits every saving/removing instructions (`true` by default)
var auto_commit = true
-
- protected init(app: App, file_name: String, mode: Int)
+
+ protected init(app: App, file_name: String, mode: Int)
do
self.context = app.native_activity
sys.jni_env.push_local_frame(1)
end
# Restricts file access to the current application
- init privately(app: App, file_name: String)
+ init privately(app: App, file_name: String)
do
self.init(app, file_name, private_mode)
end
end
private fun setup(file_name: JavaString, mode: Int) import context, set_vars in "Java" `{
- Activity context = (Activity) SharedPreferences_context(recv);
+ Activity context = (Activity) SharedPreferences_context(self);
SharedPreferences sp;
// Uses default SharedPreferences if file_name is an empty String
if (file_name.equals("")) {
sp = context.getPreferences((int)mode);
- } else {
+ } else {
sp = context.getSharedPreferences(file_name, (int)mode);
}
SharedPreferences.Editor editor = sp.edit();
-
- SharedPreferences_set_vars(recv, sp, editor);
+
+ SharedPreferences_set_vars(self, sp, editor);
`}
private fun commit_if_auto do if auto_commit then self.commit
# Returns true if there's an entry corresponding the given key
- fun has(key: String): Bool
+ fun has(key: String): Bool
do
sys.jni_env.push_local_frame(2)
- var return_value = shared_preferences.contains(key.to_java_string)
+ var return_value = shared_preferences.contains(key.to_java_string)
sys.jni_env.pop_local_frame
return return_value
end
# var foo = new HashMap[JavaString, JavaObject]
# # ...
# for key, value in foo do
- # key.delete_local_ref
- # value.delete_local_ref
+ # key.delete_local_ref
+ # value.delete_local_ref
# end
# ~~~
- # *You should use Nit getters instead and get each value one by one*
+ # *You should use Nit getters instead and get each value one by one*
fun all: nullable HashMap[JavaString, JavaObject]
- do
+ do
var hashmap = shared_preferences.get_all
if hashmap.is_empty then return null
return hashmap
# Returns the `Bool` value corresponding the given key or `def_value` if none
# or if the value isn't of correct type
- fun bool(key: String, def_value: Bool): Bool
- do
+ fun bool(key: String, def_value: Bool): Bool
+ do
sys.jni_env.push_local_frame(2)
var return_value = shared_preferences.get_boolean(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
# Returns the `Float` value corresponding the given key or `def_value` if none
# or if the value isn't of correct type
- fun float(key: String, def_value: Float): Float
- do
+ fun float(key: String, def_value: Float): Float
+ do
sys.jni_env.push_local_frame(2)
var return_value = shared_preferences.get_float(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
# Returns the `Int` value corresponding the given key or `def_value` if none
# or if the value isn't of correct type
- # Be aware of possible `def_value` integer overflow as the Nit `Int` corresponds
+ # Be aware of possible `def_value` integer overflow as the Nit `Int` corresponds
# to Java `long`
- fun int(key: String, def_value: Int): Int
- do
+ fun int(key: String, def_value: Int): Int
+ do
sys.jni_env.push_local_frame(2)
var return_value = shared_preferences.get_int(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
# or if the value isn't of correct type
# Calls `getLong(key, value)` java method
# Nit `Int` is equivalent to Java `long` so that no integer overflow will occur
- fun long(key: String, def_value: Int): Int
- do
+ fun long(key: String, def_value: Int): Int
+ do
sys.jni_env.push_local_frame(2)
var return_value = shared_preferences.get_long(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
# Returns the `String` value corresponding the given key or `def_value` if none
# or if the value isn't of correct type
- fun string(key: String, def_value: String): String
- do
+ fun string(key: String, def_value: String): String
+ do
sys.jni_env.push_local_frame(3)
- var java_return_value = shared_preferences.get_string(key.to_java_string,
+ var java_return_value = shared_preferences.get_string(key.to_java_string,
def_value.to_java_string)
var nit_return_value = java_return_value.to_s
sys.jni_env.pop_local_frame
return nit_return_value
end
- # Clears all the dictionnary entries in the specified file or the default file
+ # Clears all the dictionnary entries in the specified file or the default file
# if none specified at instanciation
# Returns `self` allowing fluent programming
- fun clear: SharedPreferences
- do
+ fun clear: SharedPreferences
+ do
editor.clear
commit_if_auto
return self
end
-
+
# If auto_commit is `false`, has to be called to save the data to persistant memory
- fun commit: Bool
- do
+ fun commit: Bool
+ do
sys.jni_env.push_local_frame(1)
var return_value = editor.commit
sys.jni_env.pop_local_frame
# Set a key-value pair using a `Bool` value
# Returns `self` allowing fluent programming
- fun add_bool(key: String, value: Bool ): SharedPreferences
- do
+ fun add_bool(key: String, value: Bool): SharedPreferences
+ do
sys.jni_env.push_local_frame(1)
editor.put_boolean(key.to_java_string, value)
sys.jni_env.pop_local_frame
#
# Be aware of possible loss of precision as Nit `Float` corresponds to Java `double`
# and the methods stores a Java `float`
- fun add_float(key: String, value: Float): SharedPreferences
- do
+ fun add_float(key: String, value: Float): SharedPreferences
+ do
sys.jni_env.push_local_frame(1)
editor.put_float(key.to_java_string, value)
sys.jni_env.pop_local_frame
# Be aware of possible integer overflow as the Nit `Int` corresponds to Java `long`
# and the methods stores a Java `int`
# *You might want to use add_long instead*
- fun add_int(key: String, value: Int): SharedPreferences
- do
+ fun add_int(key: String, value: Int): SharedPreferences
+ do
sys.jni_env.push_local_frame(1)
editor.put_int(key.to_java_string, value)
sys.jni_env.pop_local_frame
# Set a key-value pair using a `Int` type value
# Returns `self` allowing fluent programming
- fun add_long(key: String, value: Int): SharedPreferences
- do
+ fun add_long(key: String, value: Int): SharedPreferences
+ do
sys.jni_env.push_local_frame(1)
editor.put_long(key.to_java_string, value)
sys.jni_env.pop_local_frame
# Set a key-value pair using a `String` type value
# Returns `self` allowing fluent programming
- fun add_string(key: String, value: String): SharedPreferences
- do
+ fun add_string(key: String, value: String): SharedPreferences
+ do
sys.jni_env.push_local_frame(2)
editor.put_string(key.to_java_string, value.to_java_string)
sys.jni_env.pop_local_frame
# Removes the corresponding entry in the file
# Returns `self` allowing fluent programming
- fun remove(key: String): SharedPreferences
- do
+ fun remove(key: String): SharedPreferences
+ do
sys.jni_env.push_local_frame(1)
editor.remove(key.to_java_string)
sys.jni_env.pop_local_frame
end
# Deallocate global references allocated by the SharedPreferences instance
- fun destroy
+ fun destroy
do
self.shared_preferences.delete_global_ref
self.editor.delete_global_ref
import shared_preferences
-in "Java" `{
+in "Java" `{
import java.util.HashSet;
- import java.util.Set;
- import android.content.Context;
+ import java.util.Set;
+ import android.content.Context;
`}
redef extern class NativeSharedPreferences
-
+
# Default value to null instead of Set<String>
- fun get_string_set(key: JavaString): HashSet[JavaString] import HashSet[JavaString],
- HashSet[JavaString].add in "Java" `{
+ fun get_string_set(key: JavaString): HashSet[JavaString] import HashSet[JavaString],
+ HashSet[JavaString].add in "Java" `{
Set<String> def_value = new HashSet<String>();
- Set<String> java_set = recv.getStringSet(key, def_value);
+ Set<String> java_set = self.getStringSet(key, def_value);
int nit_hashset = new_HashSet_of_JavaString();
for (String element: java_set)
`}
end
-redef extern class NativeSharedPreferencesEditor
-
- fun put_string_set(key: JavaString, value: HashSet[JavaString]): NativeSharedPreferencesEditor
- import HashSet[JavaString], HashSet[JavaString].iterator, Iterator[JavaString].is_ok,
- Iterator[JavaString].item, Iterator[JavaString].next in "Java" `{
+redef extern class NativeSharedPreferencesEditor
+
+ fun put_string_set(key: JavaString, value: HashSet[JavaString]): NativeSharedPreferencesEditor
+ import HashSet[JavaString], HashSet[JavaString].iterator, Iterator[JavaString].is_ok,
+ Iterator[JavaString].item, Iterator[JavaString].next in "Java" `{
Set<String> java_set = new HashSet<String>();
int itr = HashSet_of_JavaString_iterator(value);
-
+
while (Iterator_of_JavaString_is_ok(itr)) {
java_set.add(Iterator_of_JavaString_item(itr));
Iterator_of_JavaString_next(itr);
}
- return recv.putStringSet(key, java_set);
+ return self.putStringSet(key, java_set);
`}
end
-
+
redef class SharedPreferences
# Allows multiple processes to write into the same `SharedPreferences` file
# # ...
# for element in a_hash_set do element.delete_local_ref
# ~~~
- fun string_set(key: String): HashSet[JavaString]
- do
+ fun string_set(key: String): HashSet[JavaString]
+ do
sys.jni_env.push_local_frame(3)
var return_value = shared_preferences.get_string_set(key.to_java_string)
sys.jni_env.pop_local_frame
# for element in foo do element.delete_local_ref
# ~~~
fun add_string_set(key: String, value: HashSet[JavaString]): SharedPreferences
- do
+ do
editor.put_string_set(key.to_java_string, value)
return self
end
private fun native_toast(message: JavaString, is_long: Bool)
import native_activity in "Java" `{
- final android.app.Activity context = App_native_activity(recv);
+ final android.app.Activity context = App_native_activity(self);
final CharSequence final_message = message;
final int duration = is_long? Toast.LENGTH_LONG: Toast.LENGTH_SHORT;
# Set the main layout of this activity
fun content_view=(layout: NativeViewGroup) in "Java" `{
final ViewGroup final_layout = layout;
- final Activity final_recv = recv;
+ final Activity final_self = self;
- recv.runOnUiThread(new Runnable() {
+ self.runOnUiThread(new Runnable() {
@Override
public void run() {
- final_recv.setContentView(final_layout);
+ final_self.setContentView(final_layout);
final_layout.requestFocus();
}
extern class NativeView in "Java" `{ android.view.View `}
super JavaObject
- fun minimum_width=(val: Int) in "Java" `{ recv.setMinimumWidth((int)val); `}
- fun minimum_height=(val: Int) in "Java" `{ recv.setMinimumHeight((int)val); `}
+ fun minimum_width=(val: Int) in "Java" `{ self.setMinimumWidth((int)val); `}
+ fun minimum_height=(val: Int) in "Java" `{ self.setMinimumHeight((int)val); `}
- fun enabled: Bool in "Java" `{ return recv.isEnabled(); `}
+ fun enabled: Bool in "Java" `{ return self.isEnabled(); `}
fun enabled=(value: Bool) in "Java" `{
- final View final_recv = recv;
+ final View final_self = self;
final boolean final_value = value;
- ((Activity)recv.getContext()).runOnUiThread(new Runnable() {
+ ((Activity)self.getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
- final_recv.setEnabled(final_value);
+ final_self.setEnabled(final_value);
}
});
`}
extern class NativeViewGroup in "Java" `{ android.view.ViewGroup `}
super NativeView
- fun add_view(view: NativeView) in "Java" `{ recv.addView(view); `}
+ fun add_view(view: NativeView) in "Java" `{ self.addView(view); `}
fun add_view_with_weight(view: NativeView, weight: Float)
in "Java" `{
- recv.addView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, (float)weight));
+ self.addView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, (float)weight));
`}
end
new(context: NativeActivity) in "Java" `{ return new LinearLayout(context); `}
- fun set_vertical in "Java" `{ recv.setOrientation(LinearLayout.VERTICAL); `}
- fun set_horizontal in "Java" `{ recv.setOrientation(LinearLayout.HORIZONTAL); `}
+ fun set_vertical in "Java" `{ self.setOrientation(LinearLayout.VERTICAL); `}
+ fun set_horizontal in "Java" `{ self.setOrientation(LinearLayout.HORIZONTAL); `}
redef fun add_view(view) in "Java"
`{
MarginLayoutParams params = new MarginLayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
- recv.addView(view, params);
+ self.addView(view, params);
`}
end
new(context: NativeActivity) in "Java" `{ return new android.widget.GridLayout(context); `}
- fun row_count=(val: Int) in "Java" `{ recv.setRowCount((int)val); `}
+ fun row_count=(val: Int) in "Java" `{ self.setRowCount((int)val); `}
- fun column_count=(val: Int) in "Java" `{ recv.setColumnCount((int)val); `}
+ fun column_count=(val: Int) in "Java" `{ self.setColumnCount((int)val); `}
- redef fun add_view(view) in "Java" `{ recv.addView(view); `}
+ redef fun add_view(view) in "Java" `{ self.addView(view); `}
end
extern class NativePopupWindow in "Java" `{ android.widget.PopupWindow `}
super NativeView
new (context: NativeActivity) in "Java" `{
- PopupWindow recv = new PopupWindow(context);
- recv.setWindowLayoutMode(LinearLayout.LayoutParams.MATCH_PARENT,
+ PopupWindow self = new PopupWindow(context);
+ self.setWindowLayoutMode(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
- recv.setClippingEnabled(false);
- return recv;
+ self.setClippingEnabled(false);
+ return self;
`}
- fun content_view=(layout: NativeViewGroup) in "Java" `{ recv.setContentView(layout); `}
+ fun content_view=(layout: NativeViewGroup) in "Java" `{ self.setContentView(layout); `}
end
extern class NativeTextView in "Java" `{ android.widget.TextView `}
new (context: NativeActivity) in "Java" `{ return new TextView(context); `}
- fun text: JavaString in "Java" `{ return recv.getText().toString(); `}
+ fun text: JavaString in "Java" `{ return self.getText().toString(); `}
fun text=(value: JavaString) in "Java" `{
- final TextView final_recv = recv;
+ final TextView final_self = self;
final String final_value = value;
- ((Activity)recv.getContext()).runOnUiThread(new Runnable() {
+ ((Activity)self.getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
- final_recv.setText(final_value);
+ final_self.setText(final_value);
}
});
`}
fun gravity_center in "Java" `{
- recv.setGravity(Gravity.CENTER);
+ self.setGravity(Gravity.CENTER);
`}
fun text_size: Float in "Java" `{
- return recv.getTextSize();
+ return self.getTextSize();
`}
fun text_size=(dpi: Float) in "Java" `{
- recv.setTextSize(android.util.TypedValue.COMPLEX_UNIT_DIP, (float)dpi);
+ self.setTextSize(android.util.TypedValue.COMPLEX_UNIT_DIP, (float)dpi);
`}
end
new (context: NativeActivity) in "Java" `{ return new android.widget.EditText(context); `}
- fun width=(val: Int) in "Java" `{ recv.setWidth((int)val); `}
+ fun width=(val: Int) in "Java" `{ self.setWidth((int)val); `}
- fun input_type_text in "Java" `{ recv.setInputType(android.text.InputType.TYPE_CLASS_TEXT); `}
+ fun input_type_text in "Java" `{ self.setInputType(android.text.InputType.TYPE_CLASS_TEXT); `}
redef fun new_global_ref: SELF import sys, Sys.jni_env `{
- Sys sys = NativeEditText_sys(recv);
+ Sys sys = NativeEditText_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
redef type SELF: NativeButton
redef fun new_global_ref: SELF import sys, Sys.jni_env `{
- Sys sys = NativeButton_sys(recv);
+ Sys sys = NativeButton_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
super JavaObject
# Vibrate for `n` miliseconds
- fun vibrate(n: Int) in "Java" `{ recv.vibrate(n); `}
+ fun vibrate(n: Int) in "Java" `{ self.vibrate(n); `}
# Does this devices has a vibrator
#
# TODO activate in API 11
- #fun exists: Bool in "Java" `{ return recv.hasVibrator(); `}
+ #fun exists: Bool in "Java" `{ return self.hasVibrator(); `}
# Turn off the vibration
- fun cancel in "Java" `{ recv.cancel(); `}
+ fun cancel in "Java" `{ self.cancel(); `}
# HACK for bug #845
redef fun new_global_ref import sys, Sys.jni_env `{
- Sys sys = Vibrator_sys(recv);
+ Sys sys = Vibrator_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
end
new p1_26 `{ return RPI_GPIO_P1_26; `}
# Select mode: input, output or alts
- fun fsel=(mode: FunctionSelect) `{ bcm2835_gpio_fsel(recv, mode); `}
+ fun fsel=(mode: FunctionSelect) `{ bcm2835_gpio_fsel(self, mode); `}
# Set output
- redef fun write(high) `{ bcm2835_gpio_write(recv, high? HIGH: LOW); `}
+ redef fun write(high) `{ bcm2835_gpio_write(self, high? HIGH: LOW); `}
# Set pull up mode
- fun pud=(pud: PUDControl) `{ bcm2835_gpio_set_pud(recv, pud); `}
+ fun pud=(pud: PUDControl) `{ bcm2835_gpio_set_pud(self, pud); `}
# Falling edge detect
# Do not use on raspbian, it is bugged!
- fun fen `{ bcm2835_gpio_fen(recv); `}
- fun clr_fen `{ bcm2835_gpio_clr_fen(recv); `}
+ fun fen `{ bcm2835_gpio_fen(self); `}
+ fun clr_fen `{ bcm2835_gpio_clr_fen(self); `}
# Raising edge detect
# Do not use on raspbian, it is bugged!
- fun ren `{ bcm2835_gpio_ren(recv); `}
- fun clr_ren `{ bcm2835_gpio_clr_ren(recv); `}
+ fun ren `{ bcm2835_gpio_ren(self); `}
+ fun clr_ren `{ bcm2835_gpio_clr_ren(self); `}
# High edge detect
# Do not use on raspbian, it is bugged!
- fun hen `{ bcm2835_gpio_hen(recv); `}
- fun clr_hen `{ bcm2835_gpio_clr_hen(recv); `}
+ fun hen `{ bcm2835_gpio_hen(self); `}
+ fun clr_hen `{ bcm2835_gpio_clr_hen(self); `}
# Low edge detect
# Do not use on raspbian, it is bugged!
- fun len `{ bcm2835_gpio_len(recv); `}
- fun clr_len `{ bcm2835_gpio_clr_len(recv); `}
+ fun len `{ bcm2835_gpio_len(self); `}
+ fun clr_len `{ bcm2835_gpio_clr_len(self); `}
- fun set_eds `{ bcm2835_gpio_set_eds(recv); `}
- fun eds: Bool `{ return bcm2835_gpio_eds(recv); `}
+ fun set_eds `{ bcm2835_gpio_set_eds(self); `}
+ fun eds: Bool `{ return bcm2835_gpio_eds(self); `}
# Return input on pin, true for high and false for low
- fun lev: Bool `{ return bcm2835_gpio_lev(recv); `}
+ fun lev: Bool `{ return bcm2835_gpio_lev(self); `}
end
extern class FunctionSelect `{ bcm2835FunctionSelect `}
end
redef universal Int
- fun bcm2835_delay `{ bcm2835_delay(recv); `}
- fun bcm2835_delay_micros `{ bcm2835_delayMicroseconds(recv); `}
+ fun bcm2835_delay `{ bcm2835_delay(self); `}
+ fun bcm2835_delay_micros `{ bcm2835_delayMicroseconds(self); `}
end
class RotaryEncoder
uint64_t conv;
} u;
- u.val = recv;
+ u.val = self;
if (big_endian)
u.conv = htobe64(u.conv);
uint32_t conv;
} u;
- u.val = recv;
+ u.val = self;
if (big_endian)
u.conv = htobe32(u.conv);
uint64_t conv;
} u;
- u.val = recv;
+ u.val = self;
if (big_endian)
u.conv = htobe64(u.conv);
# Initialize a new NativeCIntArray of `size` elements.
new(size: Int) `{ return calloc(size, sizeof(int)); `}
- redef fun [](index) `{ return recv[index]; `}
- redef fun []=(index, val) `{ recv[index] = val; `}
+ redef fun [](index) `{ return self[index]; `}
+ redef fun []=(index, val) `{ self[index] = val; `}
- redef fun +(offset) `{ return recv + offset; `}
+ redef fun +(offset) `{ return self + offset; `}
end
# Wrapper around an array of `unsigned char` in C (`unsigned char*`) with length and destroy state
# Allocate a new array of `size`
new(size: Int) `{ return calloc(size, sizeof(unsigned char)); `}
- redef fun [](index) `{ return recv[index]; `}
- redef fun []=(index, val) `{ recv[index] = val; `}
+ redef fun [](index) `{ return self[index]; `}
+ redef fun []=(index, val) `{ self[index] = val; `}
- redef fun +(offset) `{ return recv + offset; `}
+ redef fun +(offset) `{ return self + offset; `}
end
# Wrapper around an array of `NativeString` in C (`char**`) with length and destroy state.
# Initialize a new NativeCStringArray of `size` elements.
new(size: Int) `{ return calloc(size, sizeof(char*)); `}
- redef fun [](index) `{ return recv[index]; `}
- redef fun []=(index, val) `{ recv[index] = val; `}
- redef fun +(offset) `{ return recv + offset; `}
+ redef fun [](index) `{ return self[index]; `}
+ redef fun []=(index, val) `{ self[index] = val; `}
+ redef fun +(offset) `{ return self + offset; `}
end
redef class NativeString
super NativeCArray
redef type E: Char
- redef fun +(offset) `{ return recv + offset; `}
+ redef fun +(offset) `{ return self + offset; `}
end
new in "ObjC" `{ return [[NSAlert alloc] init]; `}
# Set the content of this message box
- fun message_text=(text: NSString) in "ObjC" `{ [recv setMessageText:text]; `}
+ fun message_text=(text: NSString) in "ObjC" `{ [self setMessageText:text]; `}
# Show this message box
- fun run_modal in "ObjC" `{ [recv runModal]; `}
+ fun run_modal in "ObjC" `{ [self runModal]; `}
end
redef class NativeString
# Get a `NSString` from `self` with the specified `length`
fun to_nsstring(length: Int): NSString in "ObjC" `{
- return [[NSString alloc] initWithBytes:recv
+ return [[NSString alloc] initWithBytes:self
length:length
encoding:NSASCIIStringEncoding];
`}
redef class NativeString
# Get `self` as a `CppString`
fun to_cpp_string(length: Int): CppString in "C++" `{
- return new std::string(recv, length);
+ return new std::string(self, length);
`}
end
# Constructor, CURL low level initializer
new easy_init `{ return curl_easy_init(); `}
# Check for correct initialization
- fun is_init:Bool `{ return (recv != NULL); `}
+ fun is_init:Bool `{ return (self != NULL); `}
# Easy Clean / Release CURL instance
- fun easy_clean `{ curl_easy_cleanup( recv ); `}
+ fun easy_clean `{ curl_easy_cleanup( self ); `}
# Perform the transfer described by setted options
- fun easy_perform:CURLCode `{ return curl_easy_perform( recv ); `}
+ fun easy_perform:CURLCode `{ return curl_easy_perform( self ); `}
# Set options to tell CURL how to behave. Obj parameter type can be Int, Bool, String, OFile, CURLSList.
fun easy_setopt(opt: CURLOption, obj: Object):CURLCode
do
return once new CURLCode.unknown_option
end
# Internal method to set options to CURL using OFile parameter.
- private fun i_setopt_file(opt: CURLOption, fl: OFile):CURLCode `{ return curl_easy_setopt( recv, opt, fl); `}
+ private fun i_setopt_file(opt: CURLOption, fl: OFile):CURLCode `{ return curl_easy_setopt( self, opt, fl); `}
# Internal method to set options to CURL using Int parameter.
- private fun i_setopt_int(opt: CURLOption, num: Int):CURLCode `{ return curl_easy_setopt( recv, opt, num); `}
+ private fun i_setopt_int(opt: CURLOption, num: Int):CURLCode `{ return curl_easy_setopt( self, opt, num); `}
# Internal method to set options to CURL using CURLSList parameter.
- private fun i_setopt_slist(opt: CURLOption, list: CURLSList):CURLCode `{ return curl_easy_setopt( recv, opt, list); `}
+ private fun i_setopt_slist(opt: CURLOption, list: CURLSList):CURLCode `{ return curl_easy_setopt( self, opt, list); `}
# Internal method to set options to CURL using String parameter.
private fun i_setopt_string(opt: CURLOption, str: String):CURLCode import String.to_cstring `{
char *rStr = String_to_cstring(str);
- return curl_easy_setopt( recv, opt, rStr);
+ return curl_easy_setopt( self, opt, rStr);
`}
# Request Chars internal information from the CURL session
fun easy_getinfo_chars(opt: CURLInfoChars):nullable CURLInfoResponseString
# Internal method used to get String object information initially knowns as C Chars type
private fun i_getinfo_chars(opt: CURLInfoChars, res: CURLInfoResponseString):CURLCode import CURLInfoResponseString.response=, NativeString.to_s_with_copy `{
char *r = NULL;
- CURLcode c = curl_easy_getinfo( recv, opt, &r);
+ CURLcode c = curl_easy_getinfo( self, opt, &r);
if((c == CURLE_OK) && r != NULL){
String ro = NativeString_to_s_with_copy(r);
CURLInfoResponseString_response__assign( res, ro);
private fun i_getinfo_long(opt: CURLInfoLong, res: CURLInfoResponseLong):CURLCode import CURLInfoResponseLong.response= `{
long *r = NULL;
r = malloc(sizeof(long));
- CURLcode c = curl_easy_getinfo( recv, opt, r);
+ CURLcode c = curl_easy_getinfo( self, opt, r);
if((c == CURLE_OK) && r != NULL) CURLInfoResponseLong_response__assign( res, *r);
free(r);
return c;
private fun i_getinfo_double(opt: CURLInfoDouble, res: CURLInfoResponseDouble):CURLCode import CURLInfoResponseDouble.response= `{
double *r = NULL;
r = malloc(sizeof(double));
- CURLcode c = curl_easy_getinfo( recv, opt, r);
+ CURLcode c = curl_easy_getinfo( self, opt, r);
if((c == CURLE_OK) && r != NULL) CURLInfoResponseDouble_response__assign( res, *r);
free(r);
return c;
# Internal method used to get Array[String] object information initially knowns as C SList type
private fun i_getinfo_slist(opt: CURLInfoSList, res: CURLInfoResponseArray):CURLCode import CURLInfoResponseArray.prim_response=`{
struct curl_slist* csl = NULL;
- CURLcode ce = curl_easy_getinfo( recv, opt, &csl);
+ CURLcode ce = curl_easy_getinfo( self, opt, &csl);
CURLInfoResponseArray_prim_response__assign(res, csl);
return ce;
`}
d->data = (char*)String_to_cstring(datas);
d->len = size;
d->pos = 0;
- return curl_easy_setopt( recv, CURLOPT_READDATA, d);
+ return curl_easy_setopt( self, CURLOPT_READDATA, d);
`}
# Internal method used to configure callbacks in terms of given type
private fun i_register_callback(delegate: CCurlCallbacks, cbtype: CURLCallbackType):CURLCode is extern import CCurlCallbacks.header_callback, CCurlCallbacks.body_callback, CCurlCallbacks.stream_callback, NativeString.to_s_with_copy, NativeString.to_s `{
CURLcode e;
switch(cbtype){
case CURLcallbackTypeHeader:
- e = curl_easy_setopt( recv, CURLOPT_HEADERFUNCTION, (curl_write_callback)&nit_curl_callback_func);
+ e = curl_easy_setopt( self, CURLOPT_HEADERFUNCTION, (curl_write_callback)&nit_curl_callback_func);
if(e != CURLE_OK) return e;
- e = curl_easy_setopt( recv, CURLOPT_WRITEHEADER, d);
+ e = curl_easy_setopt( self, CURLOPT_WRITEHEADER, d);
break;
case CURLcallbackTypeBody:
case CURLcallbackTypeStream:
- e = curl_easy_setopt( recv, CURLOPT_WRITEFUNCTION, (curl_write_callback)&nit_curl_callback_func);
+ e = curl_easy_setopt( self, CURLOPT_WRITEFUNCTION, (curl_write_callback)&nit_curl_callback_func);
if(e != CURLE_OK) return e;
- e = curl_easy_setopt( recv, CURLOPT_WRITEDATA, d);
+ e = curl_easy_setopt( self, CURLOPT_WRITEDATA, d);
break;
case CURLcallbackTypeRead:
- e = curl_easy_setopt( recv, CURLOPT_READFUNCTION, (curl_write_callback)&nit_curl_callback_read_func);
+ e = curl_easy_setopt( self, CURLOPT_READFUNCTION, (curl_write_callback)&nit_curl_callback_read_func);
default:
break;
}
fun escape(url: String):String import String.to_cstring, NativeString.to_s_with_copy `{
char *orig_url, *encoded_url = NULL;
orig_url = String_to_cstring(url);
- encoded_url = curl_easy_escape( recv, orig_url, strlen(orig_url));
+ encoded_url = curl_easy_escape( self, orig_url, strlen(orig_url));
String b_url = NativeString_to_s_with_copy(encoded_url);
curl_free(encoded_url);
return b_url;
# Open / Create a file from given name
new open(str: NativeString) `{ return fopen(str, "wb"); `}
# Check for File validity
- fun is_valid:Bool `{ return recv != NULL; `}
+ fun is_valid:Bool `{ return self != NULL; `}
# Internal method to write to the current file
- private fun n_write(buffer: NativeString, size: Int, count: Int):Int `{ return fwrite(buffer, size, count, recv); `}
+ private fun n_write(buffer: NativeString, size: Int, count: Int):Int `{ return fwrite(buffer, size, count, self); `}
# Write datas to the current file
fun write(buffer: String, size: Int, count: Int):Int
do
return 0
end
# Internal method to close the current file
- private fun n_close:Int `{ return fclose(recv); `}
+ private fun n_close:Int `{ return fclose(self); `}
# Close the current file
fun close:Bool
do
new body `{ return CURLcallbackTypeBody; `}
new stream `{ return CURLcallbackTypeStream; `}
new read `{ return CURLcallbackTypeRead; `}
- fun to_i:Int `{ return recv; `}
+ fun to_i:Int `{ return self; `}
end
# CURL Code binding and helpers
new unsupported_protocol `{ return CURLE_UNSUPPORTED_PROTOCOL; `}
new ok `{ return CURLE_OK; `}
new failed_init `{ return CURLE_FAILED_INIT; `}
- fun code:Int `{ return recv; `}
- fun is_ok:Bool `{ return recv == CURLE_OK; `}
- fun is_valid_protocol:Bool `{ return recv == CURLE_UNSUPPORTED_PROTOCOL; `}
- fun is_valid_init:Bool `{ return recv == CURLE_FAILED_INIT; `}
+ fun code:Int `{ return self; `}
+ fun is_ok:Bool `{ return self == CURLE_OK; `}
+ fun is_valid_protocol:Bool `{ return self == CURLE_UNSUPPORTED_PROTOCOL; `}
+ fun is_valid_init:Bool `{ return self == CURLE_FAILED_INIT; `}
fun to_i:Int do return code end
redef fun to_s import NativeString.to_s_with_copy `{
- char *c = (char*)curl_easy_strerror(recv);
+ char *c = (char*)curl_easy_strerror(self);
return NativeString_to_s_with_copy(c);
`}
end
return l;
`}
# Check for initialization
- fun is_init:Bool `{ return (recv != NULL); `}
+ fun is_init:Bool `{ return (self != NULL); `}
# Append an element in the linked list
fun append(key: String) import String.to_cstring `{
char *k = String_to_cstring(key);
- curl_slist_append(recv, (char*)k);
+ curl_slist_append(self, (char*)k);
`}
# Internal method to check for reachability of current data
private fun i_data_reachable(c: CURLSList):Bool `{ return (c != NULL && c->data != NULL); `}
return r
end
# Release allocated memory
- fun destroy `{ curl_slist_free_all(recv); `}
+ fun destroy `{ curl_slist_free_all(self); `}
end
redef class Collection[E]
new condition_unmet `{ return CURLINFO_CONDITION_UNMET; `}
new rtsp_client_cseq `{ return CURLINFO_RTSP_CLIENT_CSEQ; `}
new rtsp_server_cseq `{ return CURLINFO_RTSP_SERVER_CSEQ; `}
- new rtsp_cseq_recv `{ return CURLINFO_RTSP_CSEQ_RECV; `}
+ new rtsp_cseq_self `{ return CURLINFO_RTSP_CSEQ_RECV; `}
end
# Reproduce Enum of available CURL Double information, used for CCurl.easy_getinfo
new service_unavailable `{ return 503; `}
new gateway_timeout `{ return 504; `}
new http_version_not_supported `{ return 505; `}
- fun to_i:Int `{ return recv; `}
+ fun to_i:Int `{ return self; `}
end
# Reproduce Enum of CURL Options usable, used for CCurl.easy_setopt
# Clear the entire window so it can be repainted from scratch with a refresh
fun wclear `{
- wclear(recv);
+ wclear(self);
`}
# Delete the window
fun delwin `{
- delwin(recv);
+ delwin(self);
`}
# Suspend the curses session and restore the previous terminal
new current `{ return eglGetCurrentDisplay(); `}
new(handle: Pointer) `{ return eglGetDisplay(handle); `}
- fun is_valid: Bool `{ return recv != EGL_NO_DISPLAY; `}
+ fun is_valid: Bool `{ return self != EGL_NO_DISPLAY; `}
fun initialize: Bool `{
- EGLBoolean r = eglInitialize(recv, NULL, NULL);
+ EGLBoolean r = eglInitialize(self, NULL, NULL);
if (r == EGL_FALSE) {
fprintf(stderr, "Unable to eglInitialize");
return 0;
fun major_version: Int `{
EGLint val;
- eglInitialize(recv, &val, NULL);
+ eglInitialize(self, &val, NULL);
return val;
`}
fun minor_version: Int `{
EGLint val;
- eglInitialize(recv, NULL, &val);
+ eglInitialize(self, NULL, &val);
return val;
`}
}
// get number of configs
- EGLBoolean r = eglChooseConfig(recv, c_attribs, NULL, 0, &n_configs);
+ EGLBoolean r = eglChooseConfig(self, c_attribs, NULL, 0, &n_configs);
if (r == EGL_FALSE) {
- EGLDisplay_report_egl_error(recv, "failed to get number of available configs.");
+ EGLDisplay_report_egl_error(self, "failed to get number of available configs.");
return null_Array_of_EGLConfig();
} else if (n_configs == 0) {
- EGLDisplay_report_egl_error(recv, "no config available.");
+ EGLDisplay_report_egl_error(self, "no config available.");
return null_Array_of_EGLConfig();
}
configs = (EGLConfig*)malloc(sizeof(EGLConfig)*n_configs);
- r = eglChooseConfig(recv, c_attribs, configs, n_configs, &n_configs);
+ r = eglChooseConfig(self, c_attribs, configs, n_configs, &n_configs);
if (r == EGL_FALSE) {
- EGLDisplay_report_egl_error(recv, "failed to load config.");
+ EGLDisplay_report_egl_error(self, "failed to load config.");
return null_Array_of_EGLConfig();
} else {
Array_of_EGLConfig array = new_Array_of_EGLConfig();
# Can be used directly, but it is preferable to use a `EGLConfigAttribs`
fun config_attrib(config: EGLConfig, attribute: Int): Int `{
EGLint val;
- EGLBoolean r = eglGetConfigAttrib(recv, config, attribute, &val);
+ EGLBoolean r = eglGetConfigAttrib(self, config, attribute, &val);
if (r == EGL_FALSE)
return -1;
else
`}
fun terminate: Bool `{
- return eglTerminate(recv) == EGL_TRUE;
+ return eglTerminate(self) == EGL_TRUE;
`}
fun create_window_surface(config: EGLConfig, native_window: Pointer, attribs: Array[Int]): EGLSurface `{
- EGLSurface surface = eglCreateWindowSurface(recv, config, (EGLNativeWindowType)native_window, NULL);
+ EGLSurface surface = eglCreateWindowSurface(self, config, (EGLNativeWindowType)native_window, NULL);
return surface;
`}
# TODO add share_context
fun create_context(config: EGLConfig): EGLContext `{
EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE}; // TODO move out!
- EGLContext context = eglCreateContext(recv, config, EGL_NO_CONTEXT, context_attribs);
+ EGLContext context = eglCreateContext(self, config, EGL_NO_CONTEXT, context_attribs);
return context;
`}
fun make_current(draw, read: EGLSurface, context: EGLContext): Bool `{
- if (eglMakeCurrent(recv, draw, read, context) == EGL_FALSE) {
+ if (eglMakeCurrent(self, draw, read, context) == EGL_FALSE) {
fprintf(stderr, "Unable to eglMakeCurrent");
return 0;
}
# Can be used directly, but it is preferable to use a `EGLSurfaceAttribs`
fun query_surface(surface: EGLSurface, attribute: Int): Int `{
int val;
- EGLBoolean r = eglQuerySurface(recv, surface, attribute, &val);
+ EGLBoolean r = eglQuerySurface(self, surface, attribute, &val);
if (r == EGL_FALSE)
return -1;
else
`}
fun destroy_context(context: EGLContext): Bool `{
- return eglDestroyContext(recv, context);
+ return eglDestroyContext(self, context);
`}
fun destroy_surface(surface: EGLSurface): Bool `{
- return eglDestroySurface(recv, surface);
+ return eglDestroySurface(self, surface);
`}
fun error: EGLError `{ return eglGetError(); `}
end
private fun query_string(name: Int): String import NativeString.to_s `{
- return NativeString_to_s((char *)eglQueryString(recv, name));
+ return NativeString_to_s((char *)eglQueryString(self, name));
`}
fun vendor: String do return query_string(0x3053)
fun client_apis: Array[String] do return query_string(0x308D).split_with(" ")
- fun swap_buffers(surface: EGLSurface) `{ eglSwapBuffers(recv, surface); `}
+ fun swap_buffers(surface: EGLSurface) `{ eglSwapBuffers(self, surface); `}
end
extern class EGLConfig `{ EGLConfig `}
new current_read `{ return eglGetCurrentSurface(EGL_READ); `}
new none `{ return EGL_NO_SURFACE; `}
- fun is_ok: Bool `{ return recv != EGL_NO_SURFACE; `}
+ fun is_ok: Bool `{ return self != EGL_NO_SURFACE; `}
fun attribs(display: EGLDisplay): EGLSurfaceAttribs do
return new EGLSurfaceAttribs(display, self)
new current `{ return eglGetCurrentContext(); `}
new none `{ return EGL_NO_CONTEXT; `}
- fun is_ok: Bool `{ return recv != EGL_NO_CONTEXT; `}
+ fun is_ok: Bool `{ return self != EGL_NO_CONTEXT; `}
end
# Attributes of a config for a given EGL display
extern class EGLConfigCaveat `{ EGLint `}
new from_i(val: Int) `{ return (EGLint)val; `}
- fun to_i: Int `{ return recv; `}
+ fun to_i: Int `{ return self; `}
new none `{ return EGL_NONE; `}
- fun is_none: Bool `{ return recv == EGL_NONE; `}
+ fun is_none: Bool `{ return self == EGL_NONE; `}
new dont_care `{ return EGL_DONT_CARE; `}
- fun is_dont_care: Bool `{ return recv == EGL_DONT_CARE; `}
+ fun is_dont_care: Bool `{ return self == EGL_DONT_CARE; `}
new slow `{ return EGL_SLOW_CONFIG; `}
- fun is_slow: Bool `{ return recv == EGL_SLOW_CONFIG; `}
+ fun is_slow: Bool `{ return self == EGL_SLOW_CONFIG; `}
# Obselete since EGL 1.3, use EGL_CONFORMANT instead
new non_conformant `{ return EGL_NON_CONFORMANT_CONFIG; `}
- fun is_non_conformant: Bool `{ return recv == EGL_NON_CONFORMANT_CONFIG; `}
+ fun is_non_conformant: Bool `{ return self == EGL_NON_CONFORMANT_CONFIG; `}
redef fun to_s
do
extern class EGLConformant `{ EGLint `}
new `{ return (EGLint)0; `}
new from_i(val: Int) `{ return (EGLint)val; `}
- fun to_i: Int `{ return recv; `}
+ fun to_i: Int `{ return self; `}
- fun opengl: Bool `{ return recv & EGL_OPENGL_BIT; `}
- fun with_opengl: EGLConformant `{ return recv | EGL_OPENGL_BIT; `}
+ fun opengl: Bool `{ return self & EGL_OPENGL_BIT; `}
+ fun with_opengl: EGLConformant `{ return self | EGL_OPENGL_BIT; `}
- fun opengl_es: Bool `{ return recv & EGL_OPENGL_ES_BIT; `}
- fun with_opengl_es: EGLConformant `{ return recv | EGL_OPENGL_ES_BIT; `}
+ fun opengl_es: Bool `{ return self & EGL_OPENGL_ES_BIT; `}
+ fun with_opengl_es: EGLConformant `{ return self | EGL_OPENGL_ES_BIT; `}
- fun opengl_es2: Bool `{ return recv & EGL_OPENGL_ES2_BIT; `}
- fun with_opengl_es2: EGLConformant `{ return recv | EGL_OPENGL_ES2_BIT; `}
+ fun opengl_es2: Bool `{ return self & EGL_OPENGL_ES2_BIT; `}
+ fun with_opengl_es2: EGLConformant `{ return self | EGL_OPENGL_ES2_BIT; `}
- fun openvg: Bool `{ return recv & EGL_OPENVG_BIT; `}
- fun with_openvg: EGLConformant `{ return recv | EGL_OPENVG_BIT; `}
+ fun openvg: Bool `{ return self & EGL_OPENVG_BIT; `}
+ fun with_openvg: EGLConformant `{ return self | EGL_OPENVG_BIT; `}
fun to_a: Array[String]
do
end
extern class EGLError `{ EGLint `}
- fun is_success: Bool `{ return recv == EGL_SUCCESS; `}
-
- fun is_not_initialized: Bool `{ return recv == EGL_NOT_INITIALIZED; `}
- fun is_bad_access: Bool `{ return recv == EGL_BAD_ACCESS; `}
- fun is_bad_alloc: Bool `{ return recv == EGL_BAD_ALLOC; `}
- fun is_bad_attribute: Bool `{ return recv == EGL_BAD_ATTRIBUTE; `}
- fun is_bad_config: Bool `{ return recv == EGL_BAD_CONFIG; `}
- fun is_bad_context: Bool `{ return recv == EGL_BAD_CONTEXT; `}
- fun is_bad_current_surface: Bool `{ return recv == EGL_BAD_CURRENT_SURFACE; `}
- fun is_bad_display: Bool `{ return recv == EGL_BAD_DISPLAY; `}
- fun is_bad_match: Bool `{ return recv == EGL_BAD_MATCH; `}
- fun is_bad_native_pixmap: Bool `{ return recv == EGL_BAD_NATIVE_PIXMAP; `}
- fun is_bad_native_window: Bool `{ return recv == EGL_BAD_NATIVE_WINDOW; `}
- fun is_bad_parameter: Bool `{ return recv == EGL_BAD_PARAMETER; `}
- fun is_bad_surface: Bool `{ return recv == EGL_BAD_SURFACE; `}
- fun is_context_lost: Bool `{ return recv == EGL_CONTEXT_LOST; `}
+ fun is_success: Bool `{ return self == EGL_SUCCESS; `}
+
+ fun is_not_initialized: Bool `{ return self == EGL_NOT_INITIALIZED; `}
+ fun is_bad_access: Bool `{ return self == EGL_BAD_ACCESS; `}
+ fun is_bad_alloc: Bool `{ return self == EGL_BAD_ALLOC; `}
+ fun is_bad_attribute: Bool `{ return self == EGL_BAD_ATTRIBUTE; `}
+ fun is_bad_config: Bool `{ return self == EGL_BAD_CONFIG; `}
+ fun is_bad_context: Bool `{ return self == EGL_BAD_CONTEXT; `}
+ fun is_bad_current_surface: Bool `{ return self == EGL_BAD_CURRENT_SURFACE; `}
+ fun is_bad_display: Bool `{ return self == EGL_BAD_DISPLAY; `}
+ fun is_bad_match: Bool `{ return self == EGL_BAD_MATCH; `}
+ fun is_bad_native_pixmap: Bool `{ return self == EGL_BAD_NATIVE_PIXMAP; `}
+ fun is_bad_native_window: Bool `{ return self == EGL_BAD_NATIVE_WINDOW; `}
+ fun is_bad_parameter: Bool `{ return self == EGL_BAD_PARAMETER; `}
+ fun is_bad_surface: Bool `{ return self == EGL_BAD_SURFACE; `}
+ fun is_context_lost: Bool `{ return self == EGL_CONTEXT_LOST; `}
redef fun to_s
do
#
# For more info, SEE setlocale manual
fun set_locale `{
- setlocale(LC_ALL, recv);
+ setlocale(LC_ALL, self);
`}
end
# Gettext `gettext`, SEE gettext manual for further info
fun gettext: String
import String.to_cstring, NativeString.to_s `{
- return NativeString_to_s(gettext(String_to_cstring(recv)));
+ return NativeString_to_s(gettext(String_to_cstring(self)));
`}
# Gettext `dgettext`, SEE gettext manual for further info
fun dgettext(domain: String): String
import String.to_cstring, NativeString.to_s `{
- return NativeString_to_s(dgettext(String_to_cstring(domain), String_to_cstring(recv)));
+ return NativeString_to_s(dgettext(String_to_cstring(domain), String_to_cstring(self)));
`}
end
var config = configs.first
# TODO android part
-# Opengles1Display_midway_init(recv, format);
+# Opengles1Display_midway_init(self, format);
var surface = egl_display.create_window_surface(config, x11_window_handle, [0])
assert surface.is_ok else print egl_display.error
new `{ return glCreateProgram(); `}
# Is this a valid program?
- fun is_ok: Bool `{ return glIsProgram(recv); `}
+ fun is_ok: Bool `{ return glIsProgram(self); `}
# Attach a `shader` to this program
- fun attach_shader(shader: GLShader) `{ glAttachShader(recv, shader); `}
+ fun attach_shader(shader: GLShader) `{ glAttachShader(self, shader); `}
# Set the location for the attribute by `name`
fun bind_attrib_location(index: Int, name: String) import String.to_cstring `{
GLchar *c_name = String_to_cstring(name);
- glBindAttribLocation(recv, index, c_name);
+ glBindAttribLocation(self, index, c_name);
`}
# Get the location of the attribute by `name`
# Returns `-1` if there is no active attribute named `name`.
fun attrib_location(name: String): Int import String.to_cstring `{
GLchar *c_name = String_to_cstring(name);
- return glGetAttribLocation(recv, c_name);
+ return glGetAttribLocation(self, c_name);
`}
# Get the location of the uniform by `name`
# Returns `-1` if there is no active uniform named `name`.
fun uniform_location(name: String): Int import String.to_cstring `{
GLchar *c_name = String_to_cstring(name);
- return glGetUniformLocation(recv, c_name);
+ return glGetUniformLocation(self, c_name);
`}
# Query information on this program
fun query(pname: Int): Int `{
int val;
- glGetProgramiv(recv, pname, &val);
+ glGetProgramiv(self, pname, &val);
return val;
`}
# Try to link this program
#
# Check result using `in_linked` and `info_log`.
- fun link `{ glLinkProgram(recv); `}
+ fun link `{ glLinkProgram(self); `}
# Is this program linked?
fun is_linked: Bool do return query(0x8B82) != 0
# Use this program for the following operations
- fun use `{ glUseProgram(recv); `}
+ fun use `{ glUseProgram(self); `}
# Delete this program
- fun delete `{ glDeleteProgram(recv); `}
+ fun delete `{ glDeleteProgram(self); `}
# Has this program been deleted?
fun is_deleted: Bool do return query(0x8B80) != 0
# Validate whether this program can be executed in the current OpenGL state
#
# Check results using `is_validated` and `info_log`.
- fun validate `{ glValidateProgram(recv); `}
+ fun validate `{ glValidateProgram(self); `}
# Boolean result of `validate`, must be called after `validate`
fun is_validated: Bool do return query(0x8B83) != 0
# Useful with `link` and `validate`
fun info_log: String import NativeString.to_s `{
int size;
- glGetProgramiv(recv, GL_INFO_LOG_LENGTH, &size);
+ glGetProgramiv(self, GL_INFO_LOG_LENGTH, &size);
GLchar *msg = malloc(size);
- glGetProgramInfoLog(recv, size, NULL, msg);
+ glGetProgramInfoLog(self, size, NULL, msg);
return NativeString_to_s(msg);
`}
char *name = malloc(max_size);
int size;
GLenum type;
- glGetActiveAttrib(recv, index, max_size, NULL, &size, &type, name);
+ glGetActiveAttrib(self, index, max_size, NULL, &size, &type, name);
return name;
`}
fun active_attrib_size(index: Int): Int `{
int size;
GLenum type;
- glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
+ glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
return size;
`}
fun active_attrib_type(index: Int): GLFloatDataType `{
int size;
GLenum type;
- glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
+ glGetActiveAttrib(self, index, 0, NULL, &size, &type, NULL);
return type;
`}
char *name = malloc(max_size);
int size;
GLenum type;
- glGetActiveUniform(recv, index, max_size, NULL, &size, &type, name);
+ glGetActiveUniform(self, index, max_size, NULL, &size, &type, name);
return name;
`}
fun active_uniform_size(index: Int): Int `{
int size;
GLenum type;
- glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
+ glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
return size;
`}
fun active_uniform_type(index: Int): GLDataType `{
int size;
GLenum type = 0;
- glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
+ glGetActiveUniform(self, index, 0, NULL, &size, &type, NULL);
return type;
`}
end
extern class GLShader `{GLuint`}
# Set the source of the shader
fun source=(code: NativeString) `{
- glShaderSource(recv, 1, (GLchar const **)&code, NULL);
+ glShaderSource(self, 1, (GLchar const **)&code, NULL);
`}
# Source of the shader, if available
private fun source_native(size: Int): NativeString `{
GLchar *code = malloc(size);
- glGetShaderSource(recv, size, NULL, code);
+ glGetShaderSource(self, size, NULL, code);
return code;
`}
# Query information on this shader
protected fun query(pname: Int): Int `{
int val;
- glGetShaderiv(recv, pname, &val);
+ glGetShaderiv(self, pname, &val);
return val;
`}
# Try to compile `source` into a binary GPU program
#
# Check the result using `is_compiled` and `info_log`
- fun compile `{ glCompileShader(recv); `}
+ fun compile `{ glCompileShader(self); `}
# Has this shader been compiled?
fun is_compiled: Bool do return query(0x8B81) != 0
# Delete this shader
- fun delete `{ glDeleteShader(recv); `}
+ fun delete `{ glDeleteShader(self); `}
# Has this shader been deleted?
fun is_deleted: Bool do return query(0x8B80) != 0
# Is this a valid shader?
- fun is_ok: Bool `{ return glIsShader(recv); `}
+ fun is_ok: Bool `{ return glIsShader(self); `}
# Retrieve the information log of this shader
#
# Useful with `link` and `validate`
fun info_log: String import NativeString.to_s `{
int size;
- glGetShaderiv(recv, GL_INFO_LOG_LENGTH, &size);
+ glGetShaderiv(self, GL_INFO_LOG_LENGTH, &size);
GLchar *msg = malloc(size);
- glGetShaderInfoLog(recv, size, NULL, msg);
+ glGetShaderInfoLog(self, size, NULL, msg);
return NativeString_to_s(msg);
`}
end
# General type for OpenGL enumerations
extern class GLEnum `{ GLenum `}
- redef fun hash `{ return recv; `}
+ redef fun hash `{ return self; `}
redef fun ==(o) do return o != null and is_same_type(o) and o.hash == self.hash
end
fun is_ok: Bool do return is_no_error
# Is this not an error?
- fun is_no_error: Bool `{ return recv == GL_NO_ERROR; `}
+ fun is_no_error: Bool `{ return self == GL_NO_ERROR; `}
- fun is_invalid_enum: Bool `{ return recv == GL_INVALID_ENUM; `}
- fun is_invalid_value: Bool `{ return recv == GL_INVALID_VALUE; `}
- fun is_invalid_operation: Bool `{ return recv == GL_INVALID_OPERATION; `}
- fun is_invalid_framebuffer_operation: Bool `{ return recv == GL_INVALID_FRAMEBUFFER_OPERATION; `}
- fun is_out_of_memory: Bool `{ return recv == GL_OUT_OF_MEMORY; `}
+ fun is_invalid_enum: Bool `{ return self == GL_INVALID_ENUM; `}
+ fun is_invalid_value: Bool `{ return self == GL_INVALID_VALUE; `}
+ fun is_invalid_operation: Bool `{ return self == GL_INVALID_OPERATION; `}
+ fun is_invalid_framebuffer_operation: Bool `{ return self == GL_INVALID_FRAMEBUFFER_OPERATION; `}
+ fun is_out_of_memory: Bool `{ return self == GL_OUT_OF_MEMORY; `}
redef fun to_s
do
extern class GLFloatDataType
super GLEnum
- fun is_float: Bool `{ return recv == GL_FLOAT; `}
- fun is_float_vec2: Bool `{ return recv == GL_FLOAT_VEC2; `}
- fun is_float_vec3: Bool `{ return recv == GL_FLOAT_VEC3; `}
- fun is_float_vec4: Bool `{ return recv == GL_FLOAT_VEC4; `}
- fun is_float_mat2: Bool `{ return recv == GL_FLOAT_MAT2; `}
- fun is_float_mat3: Bool `{ return recv == GL_FLOAT_MAT3; `}
- fun is_float_mat4: Bool `{ return recv == GL_FLOAT_MAT4; `}
+ fun is_float: Bool `{ return self == GL_FLOAT; `}
+ fun is_float_vec2: Bool `{ return self == GL_FLOAT_VEC2; `}
+ fun is_float_vec3: Bool `{ return self == GL_FLOAT_VEC3; `}
+ fun is_float_vec4: Bool `{ return self == GL_FLOAT_VEC4; `}
+ fun is_float_mat2: Bool `{ return self == GL_FLOAT_MAT2; `}
+ fun is_float_mat3: Bool `{ return self == GL_FLOAT_MAT3; `}
+ fun is_float_mat4: Bool `{ return self == GL_FLOAT_MAT4; `}
# Instances of `GLFloatDataType` can be equal to instances of `GLDataType`
redef fun ==(o)
extern class GLDataType
super GLFloatDataType
- fun is_int: Bool `{ return recv == GL_INT; `}
- fun is_int_vec2: Bool `{ return recv == GL_INT_VEC2; `}
- fun is_int_vec3: Bool `{ return recv == GL_INT_VEC3; `}
- fun is_int_vec4: Bool `{ return recv == GL_INT_VEC4; `}
- fun is_bool: Bool `{ return recv == GL_BOOL; `}
- fun is_bool_vec2: Bool `{ return recv == GL_BOOL_VEC2; `}
- fun is_bool_vec3: Bool `{ return recv == GL_BOOL_VEC3; `}
- fun is_bool_vec4: Bool `{ return recv == GL_BOOL_VEC4; `}
- fun is_sampler_2d: Bool `{ return recv == GL_SAMPLER_2D; `}
- fun is_sampler_cube: Bool `{ return recv == GL_SAMPLER_CUBE; `}
+ fun is_int: Bool `{ return self == GL_INT; `}
+ fun is_int_vec2: Bool `{ return self == GL_INT_VEC2; `}
+ fun is_int_vec3: Bool `{ return self == GL_INT_VEC3; `}
+ fun is_int_vec4: Bool `{ return self == GL_INT_VEC4; `}
+ fun is_bool: Bool `{ return self == GL_BOOL; `}
+ fun is_bool_vec2: Bool `{ return self == GL_BOOL_VEC2; `}
+ fun is_bool_vec3: Bool `{ return self == GL_BOOL_VEC3; `}
+ fun is_bool_vec4: Bool `{ return self == GL_BOOL_VEC4; `}
+ fun is_sampler_2d: Bool `{ return self == GL_SAMPLER_2D; `}
+ fun is_sampler_cube: Bool `{ return self == GL_SAMPLER_CUBE; `}
end
# Kind of primitives to render with `GLES::draw_arrays`
new `{ return 0; `}
# Add the color buffer to the returned buffer set
- fun color: GLBuffer `{ return recv | GL_COLOR_BUFFER_BIT; `}
+ fun color: GLBuffer `{ return self | GL_COLOR_BUFFER_BIT; `}
# Add the depth buffer to the returned buffer set
- fun depth: GLBuffer `{ return recv | GL_DEPTH_BUFFER_BIT; `}
+ fun depth: GLBuffer `{ return self | GL_DEPTH_BUFFER_BIT; `}
# Add the stencil buffer to the returned buffer set
- fun stencil: GLBuffer `{ return recv | GL_STENCIL_BUFFER_BIT; `}
+ fun stencil: GLBuffer `{ return self | GL_STENCIL_BUFFER_BIT; `}
end
`}
fun current_page: Int `{
- return gtk_assistant_get_current_page (recv);
+ return gtk_assistant_get_current_page (self);
`}
fun current_page=(page_num: Int) `{
- gtk_assistant_set_current_page(recv, page_num);
+ gtk_assistant_set_current_page(self, page_num);
`}
fun number_pages: Int `{
- return gtk_assistant_get_n_pages(recv);
+ return gtk_assistant_get_n_pages(self);
`}
fun get_page(page_num: Int): GtkWidget `{
- return gtk_assistant_get_nth_page(recv, page_num);
+ return gtk_assistant_get_nth_page(self, page_num);
`}
fun prepend(page: GtkWidget): Int `{
- return gtk_assistant_prepend_page(recv, page);
+ return gtk_assistant_prepend_page(self, page);
`}
fun append(page: GtkWidget): Int `{
- return gtk_assistant_append_page(recv, page);
+ return gtk_assistant_append_page(self, page);
`}
fun insert(page: GtkWidget, position: Int): Int `{
- return gtk_assistant_insert_page(recv, page, position);
+ return gtk_assistant_insert_page(self, page, position);
`}
fun remove(page_num: Int) `{
- gtk_assistant_remove_page(recv, page_num);
+ gtk_assistant_remove_page(self, page_num);
`}
fun get_page_type(page: GtkWidget): GtkAssistantPageType `{
- return gtk_assistant_get_page_type(recv, page);
+ return gtk_assistant_get_page_type(self, page);
`}
fun set_page_type(page: GtkWidget, t: GtkAssistantPageType) `{
- gtk_assistant_set_page_type(recv, page, t);
+ gtk_assistant_set_page_type(self, page, t);
`}
fun get_page_title(page: GtkWidget): String import NativeString.to_s `{
- return NativeString_to_s((char *)gtk_assistant_get_page_title(recv, page));
+ return NativeString_to_s((char *)gtk_assistant_get_page_title(self, page));
`}
fun set_page_title(page: GtkWidget, title: String) import String.to_cstring `{
- gtk_assistant_set_page_title(recv, page, String_to_cstring(title));
+ gtk_assistant_set_page_title(self, page, String_to_cstring(title));
`}
fun set_page_complete(page: GtkWidget, is_complete: Bool) `{
- gtk_assistant_set_page_complete(recv, page, is_complete);
+ gtk_assistant_set_page_complete(self, page, is_complete);
`}
fun get_page_complete(page: GtkWidget): Bool `{
- return gtk_assistant_get_page_complete(recv, page);
+ return gtk_assistant_get_page_complete(self, page);
`}
fun remove_action_widget(child: GtkWidget) `{
- gtk_assistant_remove_action_widget(recv, child);
+ gtk_assistant_remove_action_widget(self, child);
`}
fun add_action_widget(child: GtkWidget) `{
- gtk_assistant_add_action_widget(recv, child);
+ gtk_assistant_add_action_widget(self, child);
`}
fun update_buttons_state `{
- gtk_assistant_update_buttons_state(recv);
+ gtk_assistant_update_buttons_state(self);
`}
fun commit `{
- gtk_assistant_commit(recv);
+ gtk_assistant_commit(self);
`}
fun next_page `{
- gtk_assistant_next_page(recv);
+ gtk_assistant_next_page(self);
`}
fun previous_page `{
- gtk_assistant_previous_page(recv);
+ gtk_assistant_previous_page(self);
`}
end
# Base class for all widgets
# See: https://developer.gnome.org/gtk3/stable/GtkWidget.html
extern class GtkWidget `{GtkWidget *`}
- fun show_all `{ gtk_widget_show_all(recv); `}
+ fun show_all `{ gtk_widget_show_all(self); `}
fun signal_connect(signal_name: String, to_call: GtkCallable, user_data: nullable Object) import String.to_cstring, GtkCallable.signal, Object.as not nullable `{
NitGtkSignal *data = malloc(sizeof(NitGtkSignal));
data->user_data = user_data;
/*Use G_CALLBACK() to cast the callback function to a GCallback*/
- g_signal_connect(recv,
+ g_signal_connect(self,
String_to_cstring(signal_name),
G_CALLBACK(nit_gtk_callback_func),
data);
redef fun ==(o) do return o isa GtkWidget and equal_to_gtk_widget(o)
private fun equal_to_gtk_widget(o: GtkWidget): Bool `{
- return recv == o;
+ return self == o;
`}
fun request_size(width, height: Int) `{
- gtk_widget_set_size_request(recv, width, height);
+ gtk_widget_set_size_request(self, width, height);
`}
fun bg_color=(state: GtkStateType, color: GdkRGBA) `{
- gtk_widget_override_background_color(recv, state, color);
+ gtk_widget_override_background_color(self, state, color);
`}
# with gtk it's possible to set fg_color to all widget: is it correct? is fg color inherited?
# GdkColor color;
fun fg_color=(state: GtkStateType, color: GdkRGBA) `{
- gtk_widget_override_color(recv, state, color);
+ gtk_widget_override_color(self, state, color);
`}
# Sets the sensitivity of a widget. sensitive -> the user can interact with it.
# Insensitive -> widget "grayed out" and the user can"t interact with them
fun sensitive=(sensitive: Bool) `{
- gtk_widget_set_sensitive(recv, sensitive);
+ gtk_widget_set_sensitive(self, sensitive);
`}
# return the sensitivity of the widget
fun sensitive: Bool `{
- return gtk_widget_get_sensitive(recv);
+ return gtk_widget_get_sensitive(self);
`}
# Set the visibility of the widget
fun visible=(visible: Bool) `{
- gtk_widget_set_visible(recv, visible);
+ gtk_widget_set_visible(self, visible);
`}
# Get the visibility of the widget only
fun visible_self: Bool `{
- return gtk_widget_get_visible(recv);
+ return gtk_widget_get_visible(self);
`}
# Destroy the widget
- fun destroy `{ gtk_widget_destroy(recv); `}
+ fun destroy `{ gtk_widget_destroy(self); `}
# Show the widget on screen
#
# See: `show_all` to recursively show this widget and contained widgets.
- fun show `{ gtk_widget_show(recv); `}
+ fun show `{ gtk_widget_show(self); `}
# Hide the widget (reverse the effects of `show`)
- fun hide `{ gtk_widget_hide(recv); `}
+ fun hide `{ gtk_widget_hide(self); `}
end
# Base class for widgets which contain other widgets
# Add a widget to the container
fun add(widget: GtkWidget) `{
- gtk_container_add(recv, widget);
+ gtk_container_add(self, widget);
`}
# Remove the widget from the container
fun remove_widget(widget: GtkWidget) `{
- gtk_container_remove(recv, widget);
+ gtk_container_remove(self, widget);
`}
# Get the resize mode of the container
fun resize_mode: GtkResizeMode `{
- return gtk_container_get_resize_mode(recv);
+ return gtk_container_get_resize_mode(self);
`}
# Set the resize mode of the container
fun resize_mode=(resize_mode: GtkResizeMode) `{
- gtk_container_set_resize_mode(recv, resize_mode);
+ gtk_container_set_resize_mode(self, resize_mode);
`}
end
super GtkContainer
fun child: GtkWidget `{
- return gtk_bin_get_child(recv);
+ return gtk_bin_get_child(self);
`}
end
# Connect the "destroy" signal to `quit_gtk`
fun connect_destroy_signal_to_quit `{
- g_signal_connect(recv, "destroy", G_CALLBACK(gtk_main_quit), NULL);
+ g_signal_connect(self, "destroy", G_CALLBACK(gtk_main_quit), NULL);
`}
fun title=(title: String) import String.to_cstring `{
- gtk_window_set_title(recv, String_to_cstring(title));
+ gtk_window_set_title(self, String_to_cstring(title));
`}
# The "destroy" signal is emitted when a widget is destroyed, either by explicitly calling gtk_widget_destroy() or when the widget is unparented. Top-level GtkWindows are also destroyed when the Close window control button is clicked.
end
fun resizable: Bool `{
- return gtk_window_get_resizable(recv);
+ return gtk_window_get_resizable(self);
`}
fun resizable=(is_resizable: Bool) `{
- return gtk_window_set_resizable(recv, is_resizable);
+ return gtk_window_set_resizable(self, is_resizable);
`}
# Activates the current focused widget within the window.
# returns TRUE if a widget got activated.
fun activate_focus: Bool `{
- return gtk_window_activate_focus(recv);
+ return gtk_window_activate_focus(self);
`}
# Sets a window modal or non-modal. Modal windows prevent interaction with other windows in the same application.
fun modal=(is_modal: Bool) `{
- gtk_window_set_modal(recv, is_modal);
+ gtk_window_set_modal(self, is_modal);
`}
# Windows can't actually be 0x0 in size, they must be at least 1x1
# params width in pixels, or -1 to unset the default width
# params height in pixels, or -1 to unset the default height
fun default_size(width: Int, height: Int) `{
- gtk_window_set_default_size(recv, width, height);
+ gtk_window_set_default_size(self, width, height);
`}
# Activates the default widget for the window
# unless the current focused widget has been configured to receive the default action (see gtk_widget_set_receives_default()), in which case the focused widget is activated.
fun activate_default: Bool `{
- return gtk_window_activate_default(recv);
+ return gtk_window_activate_default(self);
`}
fun gravity: GdkGravity `{
- return gtk_window_get_gravity(recv);
+ return gtk_window_get_gravity(self);
`}
fun gravity=(window_grav: GdkGravity) `{
- gtk_window_set_gravity(recv, window_grav);
+ gtk_window_set_gravity(self, window_grav);
`}
# fun position: GtkWindowPosition `{
-# return gtk_window_get_position(recv);
+# return gtk_window_get_position(self);
# `}
#
# fun position=(window_pos: GtkWindowPosition) `{
-# gtk_window_set_position(recv, window_pos);
+# gtk_window_set_position(self, window_pos);
# `}
fun active: Bool `{
- return gtk_window_is_active(recv);
+ return gtk_window_is_active(self);
`}
# Returns whether the input focus is within this GtkWindow. For real toplevel windows, this is identical to gtk_window_is_active(), but for embedded windows, like GtkPlug, the results will differ.
fun has_toplevel_focus: Bool `{
- return gtk_window_has_toplevel_focus(recv);
+ return gtk_window_has_toplevel_focus(self);
`}
fun get_focus: GtkWidget `{
- return gtk_window_get_focus(recv);
+ return gtk_window_get_focus(self);
`}
fun set_focus(widget: GtkWidget) `{
- return gtk_window_set_focus(recv, widget);
+ return gtk_window_set_focus(self, widget);
`}
fun get_default_widget: GtkWidget `{
- return gtk_window_get_default_widget(recv);
+ return gtk_window_get_default_widget(self);
`}
fun set_default_widget(widget: GtkWidget) `{
- return gtk_window_set_default(recv, widget);
+ return gtk_window_set_default(self, widget);
`}
fun maximize `{
- return gtk_window_maximize(recv);
+ return gtk_window_maximize(self);
`}
fun unmaximize `{
- return gtk_window_unmaximize(recv);
+ return gtk_window_unmaximize(self);
`}
fun fullscreen `{
- return gtk_window_fullscreen(recv);
+ return gtk_window_fullscreen(self);
`}
fun unfullscreen `{
- return gtk_window_unfullscreen(recv);
+ return gtk_window_unfullscreen(self);
`}
fun keep_above=(setting: Bool) `{
- gtk_window_set_keep_above(recv, setting);
+ gtk_window_set_keep_above(self, setting);
`}
fun keep_below=(setting: Bool) `{
- gtk_window_set_keep_below(recv, setting);
+ gtk_window_set_keep_below(self, setting);
`}
end
`}
fun frame_label: String `{
- return NativeString_to_s((char *)gtk_frame_get_label(recv));
+ return NativeString_to_s((char *)gtk_frame_get_label(self));
`}
fun frame_label=(lbl: String) import String.to_cstring `{
- gtk_frame_set_label(recv, String_to_cstring(lbl));
+ gtk_frame_set_label(self, String_to_cstring(lbl));
`}
fun label_widget: GtkWidget `{
- return gtk_frame_get_label_widget(recv);
+ return gtk_frame_get_label_widget(self);
`}
fun label_widget=(widget: GtkWidget) `{
- gtk_frame_set_label_widget(recv, widget);
+ gtk_frame_set_label_widget(self, widget);
`}
fun shadow_type: GtkShadowType `{
- return gtk_frame_get_shadow_type(recv);
+ return gtk_frame_get_shadow_type(self);
`}
fun shadow_type=(stype: GtkShadowType) `{
- gtk_frame_set_shadow_type(recv, stype);
+ gtk_frame_set_shadow_type(self, stype);
`}
fun label_align=(xalign: Float, yalign: Float) `{
- gtk_frame_set_label_align(recv, xalign, yalign);
+ gtk_frame_set_label_align(self, xalign, yalign);
`}
end
# Set a widget child inside the grid at a given position
fun attach(child: GtkWidget, left, top, width, height: Int) `{
- gtk_grid_attach(recv, child, left, top, width, height);
+ gtk_grid_attach(self, child, left, top, width, height);
`}
# Get the child of the Grid at the given position
fun get_child_at(left: Int, top: Int): GtkWidget `{
- return gtk_grid_get_child_at(recv, left, top);
+ return gtk_grid_get_child_at(self, left, top);
`}
# Insert a row at the specified position
fun insert_row(position:Int) `{
- gtk_grid_insert_row(recv, position);
+ gtk_grid_insert_row(self, position);
`}
# Insert a column at the specified position
fun insert_column(position: Int) `{
- gtk_grid_insert_column(recv, position);
+ gtk_grid_insert_column(self, position);
`}
end
# Get the orientation of this widget
fun orientation: GtkOrientation `{
- return gtk_orientable_get_orientation(recv);
+ return gtk_orientable_get_orientation(self);
`}
# Set the orientation of this widget
fun orientation=(orientation: GtkOrientation) `{
- gtk_orientable_set_orientation(recv, orientation);
+ gtk_orientable_set_orientation(self, orientation);
`}
end
`}
# Give the children of `self` equal space in the box?
- fun homogeneous: Bool `{ return gtk_box_get_homogeneous(recv); `}
+ fun homogeneous: Bool `{ return gtk_box_get_homogeneous(self); `}
# Give the children of `self` equal space in the box?
fun homogeneous=(homogeneous: Bool) `{
- gtk_box_set_homogeneous(recv, homogeneous);
+ gtk_box_set_homogeneous(self, homogeneous);
`}
# Add `child` and pack it at the start of the box
fun pack_start(child: GtkWidget, expand, fill: Bool, padding: Int) `{
- gtk_box_pack_start(recv, child, expand, fill, padding);
+ gtk_box_pack_start(self, child, expand, fill, padding);
`}
# Add `child` and pack it at the end of the box
fun pack_end(child: GtkWidget, expand, fill: Bool, padding: Int) `{
- gtk_box_pack_end(recv, child, expand, fill, padding);
+ gtk_box_pack_end(self, child, expand, fill, padding);
`}
# Set the way `child` is packed in `self`
fun set_child_packing(child: GtkWidget, expand, fill: Bool, padding: Int, packing: GtkPackType) `{
- gtk_box_set_child_packing(recv, child, expand, fill, padding, packing);
+ gtk_box_set_child_packing(self, child, expand, fill, padding, packing);
`}
end
fun alignment: GtkAlignment is abstract
fun alignment=(x: Float, y: Float) `{
- gtk_misc_set_alignment(recv, x, y);
+ gtk_misc_set_alignment(self, x, y);
`}
fun padding: GtkAlignment is abstract
fun padding=(x: Float, y: Float) `{
- gtk_misc_set_padding(recv, x, y);
+ gtk_misc_set_padding(self, x, y);
`}
end
`}
fun text: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy((char *)gtk_entry_get_text(recv));
+ return NativeString_to_s_with_copy((char *)gtk_entry_get_text(self));
`}
fun text=(value: String) import String.to_cstring `{
- gtk_entry_set_text(recv, String_to_cstring(value));
+ gtk_entry_set_text(self, String_to_cstring(value));
`}
# Is the text visible or is it the invisible char (such as '*')?
fun visiblility: Bool `{
- return gtk_entry_get_visibility(recv);
+ return gtk_entry_get_visibility(self);
`}
# Set the text visiblility
# If false, will use the invisible char (such as '*')
fun visibility=(is_visible: Bool) `{
- gtk_entry_set_visibility(recv, is_visible);
+ gtk_entry_set_visibility(self, is_visible);
`}
fun max_length: Int `{
- return gtk_entry_get_max_length(recv);
+ return gtk_entry_get_max_length(self);
`}
fun max_length=(max: Int) `{
- gtk_entry_set_max_length(recv, max);
+ gtk_entry_set_max_length(self, max);
`}
end
# Gets the current position of the fill level indicator.
fun fill_level: Float `{
- return gtk_range_get_fill_level(recv);
+ return gtk_range_get_fill_level(self);
`}
fun fill_level=(level: Float) `{
- gtk_range_set_fill_level(recv, level);
+ gtk_range_set_fill_level(self, level);
`}
# Gets whether the range is restricted to the fill level.
fun restricted_to_fill_level: Bool `{
- return gtk_range_get_restrict_to_fill_level(recv);
+ return gtk_range_get_restrict_to_fill_level(self);
`}
fun restricted_to_fill_level=(restricted: Bool) `{
- gtk_range_set_restrict_to_fill_level(recv, restricted);
+ gtk_range_set_restrict_to_fill_level(self, restricted);
`}
# Gets whether the range displays the fill level graphically.
fun show_fill_level: Bool `{
- return gtk_range_get_show_fill_level(recv);
+ return gtk_range_get_show_fill_level(self);
`}
fun show_fill_level=(is_displayed: Bool) `{
- gtk_range_set_show_fill_level(recv, is_displayed);
+ gtk_range_set_show_fill_level(self, is_displayed);
`}
fun adjustment: GtkAdjustment `{
- return gtk_range_get_adjustment(recv);
+ return gtk_range_get_adjustment(self);
`}
fun adjustment=(value: GtkAdjustment) `{
- gtk_range_set_adjustment(recv, value);
+ gtk_range_set_adjustment(self, value);
`}
fun inverted: Bool `{
- return gtk_range_get_inverted(recv);
+ return gtk_range_get_inverted(self);
`}
fun inverted=(setting: Bool) `{
- gtk_range_set_inverted(recv, setting);
+ gtk_range_set_inverted(self, setting);
`}
fun value: Float `{
- return gtk_range_get_value(recv);
+ return gtk_range_get_value(self);
`}
fun value=(val: Float) `{
- gtk_range_set_value(recv, val);
+ gtk_range_set_value(self, val);
`}
fun set_increments(step: Float, page: Float) `{
- gtk_range_set_increments(recv, step, page);
+ gtk_range_set_increments(self, step, page);
`}
fun set_range(min: Float, max: Float) `{
- gtk_range_set_range(recv, min, max);
+ gtk_range_set_range(self, min, max);
`}
fun round_digits: Int `{
- return gtk_range_get_round_digits(recv);
+ return gtk_range_get_round_digits(self);
`}
fun round_digits=(nb: Int) `{
- gtk_range_set_round_digits(recv, nb);
+ gtk_range_set_round_digits(self, nb);
`}
fun size_fixed: Bool `{
- return gtk_range_get_slider_size_fixed(recv);
+ return gtk_range_get_slider_size_fixed(self);
`}
fun size_fixed=(is_fixed: Bool) `{
- return gtk_range_set_slider_size_fixed(recv, is_fixed);
+ return gtk_range_set_slider_size_fixed(self, is_fixed);
`}
fun flippable: Bool `{
- return gtk_range_get_flippable(recv);
+ return gtk_range_get_flippable(self);
`}
fun min_size=(is_flippable: Bool) `{
- return gtk_range_set_flippable(recv, is_flippable);
+ return gtk_range_set_flippable(self, is_flippable);
`}
fun min_slider_size: Int `{
- return gtk_range_get_min_slider_size(recv);
+ return gtk_range_get_min_slider_size(self);
`}
fun min_slider_size=(size: Int) `{
- return gtk_range_set_min_slider_size(recv, size);
+ return gtk_range_set_min_slider_size(self, size);
`}
end
`}
fun digits: Int `{
- return gtk_scale_get_digits(recv);
+ return gtk_scale_get_digits(self);
`}
fun digits=(nb_digits: Int) `{
- gtk_scale_set_digits(recv, nb_digits);
+ gtk_scale_set_digits(self, nb_digits);
`}
fun draw_value: Bool `{
- return gtk_scale_get_draw_value(recv);
+ return gtk_scale_get_draw_value(self);
`}
fun draw_value=(is_displayed: Bool) `{
- gtk_scale_set_draw_value(recv, is_displayed);
+ gtk_scale_set_draw_value(self, is_displayed);
`}
fun value_position: GtkPositionType `{
- return gtk_scale_get_value_pos(recv);
+ return gtk_scale_get_value_pos(self);
`}
fun value_position=(pos: GtkPositionType) `{
- gtk_scale_set_value_pos(recv, pos);
+ gtk_scale_set_value_pos(self, pos);
`}
fun has_origin: Bool `{
- return gtk_scale_get_has_origin(recv);
+ return gtk_scale_get_has_origin(self);
`}
fun has_origin=(orig: Bool) `{
- gtk_scale_set_has_origin(recv, orig);
+ gtk_scale_set_has_origin(self, orig);
`}
fun add_mark(value: Float, position: GtkPositionType, markup: String)
import String.to_cstring `{
- gtk_scale_add_mark(recv, value, position, String_to_cstring(markup));
+ gtk_scale_add_mark(self, value, position, String_to_cstring(markup));
`}
# Removes any marks that have been added with gtk_scale_add_mark().
fun clear_marks `{
- gtk_scale_clear_marks(recv);
+ gtk_scale_clear_marks(self);
`}
end
# Set the text of the label
fun text=(text: String) import String.to_cstring `{
- gtk_label_set_text(recv, String_to_cstring(text));
+ gtk_label_set_text(self, String_to_cstring(text));
`}
# Returns the text of the label
fun text: String import NativeString.to_s `{
- return NativeString_to_s((char*)gtk_label_get_text(recv));
+ return NativeString_to_s((char*)gtk_label_get_text(self));
`}
# Sets the angle of rotation for the label.
# An angle of 90 reads from from bottom to top, an angle of 270, from top to bottom.
fun angle=(degre: Float) `{
- gtk_label_set_angle(recv, degre);
+ gtk_label_set_angle(self, degre);
`}
# Returns the angle of rotation for the label.
fun angle: Float `{
- return gtk_label_get_angle(recv);
+ return gtk_label_get_angle(self);
`}
end
`}
fun pixel_size: Int `{
- return gtk_image_get_pixel_size(recv);
+ return gtk_image_get_pixel_size(self);
`}
fun pixel_size=(size: Int) `{
- gtk_image_set_pixel_size(recv, size);
+ gtk_image_set_pixel_size(self, size);
`}
fun clear `{
- gtk_image_clear(recv);
+ gtk_image_clear(self);
`}
end
`}
fun set(arrow_type: GtkArrowType, shadow_type: GtkShadowType) `{
- gtk_arrow_set(recv, arrow_type, shadow_type);
+ gtk_arrow_set(self, arrow_type, shadow_type);
`}
end
`}
fun text: String `{
- return NativeString_to_s((char *)gtk_button_get_label(recv));
+ return NativeString_to_s((char *)gtk_button_get_label(self));
`}
fun text=(value: String) import String.to_cstring `{
- gtk_button_set_label(recv, String_to_cstring(value));
+ gtk_button_set_label(self, String_to_cstring(value));
`}
fun on_click(to_call: GtkCallable, user_data: nullable Object) do
`}
fun expanded: Bool `{
- return gtk_expander_get_expanded(recv);
+ return gtk_expander_get_expanded(self);
`}
fun expanded=(is_expanded: Bool) `{
- gtk_expander_set_expanded(recv, is_expanded);
+ gtk_expander_set_expanded(self, is_expanded);
`}
fun spacing: Int `{
- return gtk_expander_get_spacing(recv);
+ return gtk_expander_get_spacing(self);
`}
fun spacing=(pixels: Int) `{
- gtk_expander_set_spacing(recv, pixels);
+ gtk_expander_set_spacing(self, pixels);
`}
fun label_text: String `{
- return NativeString_to_s((char *)gtk_expander_get_label(recv));
+ return NativeString_to_s((char *)gtk_expander_get_label(self));
`}
fun label_text=(lbl: String) import String.to_cstring `{
- gtk_expander_set_label(recv, String_to_cstring(lbl));
+ gtk_expander_set_label(self, String_to_cstring(lbl));
`}
fun use_underline: Bool `{
- return gtk_expander_get_use_underline(recv);
+ return gtk_expander_get_use_underline(self);
`}
fun use_underline=(used: Bool) `{
- gtk_expander_set_use_underline(recv, used);
+ gtk_expander_set_use_underline(self, used);
`}
fun use_markup: Bool `{
- return gtk_expander_get_use_markup(recv);
+ return gtk_expander_get_use_markup(self);
`}
fun use_markup=(used: Bool) `{
- gtk_expander_set_use_markup(recv, used);
+ gtk_expander_set_use_markup(self, used);
`}
fun label_widget: GtkWidget `{
- return gtk_expander_get_label_widget(recv);
+ return gtk_expander_get_label_widget(self);
`}
fun label_widget=(widget: GtkWidget) `{
- gtk_expander_set_label_widget(recv, widget);
+ gtk_expander_set_label_widget(self, widget);
`}
fun label_fill: Bool `{
- return gtk_expander_get_label_fill(recv);
+ return gtk_expander_get_label_fill(self);
`}
fun label_fill=(fill: Bool) `{
- gtk_expander_set_label_fill(recv, fill);
+ gtk_expander_set_label_fill(self, fill);
`}
fun resize_toplevel: Bool `{
- return gtk_expander_get_resize_toplevel(recv);
+ return gtk_expander_get_resize_toplevel(self);
`}
fun resize_toplevel=(resize: Bool) `{
- gtk_expander_set_resize_toplevel(recv, resize);
+ gtk_expander_set_resize_toplevel(self, resize);
`}
end
`}
fun wrap_width: Int `{
- return gtk_combo_box_get_wrap_width(recv);
+ return gtk_combo_box_get_wrap_width(self);
`}
fun wrap_width=(width: Int) `{
- gtk_combo_box_set_wrap_width(recv, width);
+ gtk_combo_box_set_wrap_width(self, width);
`}
fun row_span_col: Int `{
- return gtk_combo_box_get_row_span_column(recv);
+ return gtk_combo_box_get_row_span_column(self);
`}
fun row_span_col=(row_span: Int) `{
- gtk_combo_box_set_row_span_column(recv, row_span);
+ gtk_combo_box_set_row_span_column(self, row_span);
`}
fun col_span_col: Int `{
- return gtk_combo_box_get_column_span_column(recv);
+ return gtk_combo_box_get_column_span_column(self);
`}
fun col_span_col=(col_span: Int) `{
- gtk_combo_box_set_column_span_column(recv, col_span);
+ gtk_combo_box_set_column_span_column(self, col_span);
`}
fun active_item: Int `{
- return gtk_combo_box_get_active(recv);
+ return gtk_combo_box_get_active(self);
`}
fun active_item=(active: Int) `{
- gtk_combo_box_set_active(recv, active);
+ gtk_combo_box_set_active(self, active);
`}
fun column_id: Int `{
- return gtk_combo_box_get_id_column(recv);
+ return gtk_combo_box_get_id_column(self);
`}
fun column_id=(id_column: Int) `{
- gtk_combo_box_set_id_column(recv, id_column);
+ gtk_combo_box_set_id_column(self, id_column);
`}
fun active_id: String `{
- return NativeString_to_s((char *)gtk_combo_box_get_active_id(recv));
+ return NativeString_to_s((char *)gtk_combo_box_get_active_id(self));
`}
fun active_id=(id_active: String) import String.to_cstring `{
- gtk_combo_box_set_active_id(recv, String_to_cstring(id_active));
+ gtk_combo_box_set_active_id(self, String_to_cstring(id_active));
`}
fun model: GtkTreeModel `{
- return gtk_combo_box_get_model(recv);
+ return gtk_combo_box_get_model(self);
`}
fun model=(model: GtkTreeModel) `{
- gtk_combo_box_set_model(recv, model);
+ gtk_combo_box_set_model(self, model);
`}
fun popup `{
- gtk_combo_box_popup(recv);
+ gtk_combo_box_popup(self);
`}
fun popdown `{
- gtk_combo_box_popdown(recv);
+ gtk_combo_box_popdown(self);
`}
fun title: String `{
- return NativeString_to_s((char *)gtk_combo_box_get_title(recv));
+ return NativeString_to_s((char *)gtk_combo_box_get_title(self));
`}
fun title=(t: String) import String.to_cstring `{
- gtk_combo_box_set_title(recv, String_to_cstring(t));
+ gtk_combo_box_set_title(self, String_to_cstring(t));
`}
fun has_entry: Bool `{
- return gtk_combo_box_get_has_entry(recv);
+ return gtk_combo_box_get_has_entry(self);
`}
fun with_fixed: Bool `{
- return gtk_combo_box_get_popup_fixed_width(recv);
+ return gtk_combo_box_get_popup_fixed_width(self);
`}
fun with_fixed=(fixed: Bool) `{
- gtk_combo_box_set_popup_fixed_width(recv, fixed);
+ gtk_combo_box_set_popup_fixed_width(self, fixed);
`}
end
`}
fun start `{
- return gtk_spinner_start(recv);
+ return gtk_spinner_start(self);
`}
fun stop `{
- return gtk_spinner_stop(recv);
+ return gtk_spinner_stop(self);
`}
end
`}
fun active: Bool `{
- return gtk_switch_get_active(recv);
+ return gtk_switch_get_active(self);
`}
fun active=(is_active: Bool) `{
- return gtk_switch_set_active(recv, is_active);
+ return gtk_switch_set_active(self, is_active);
`}
end
`}
fun set (xalign: Float, yalign: Float, xscale: Float, yscale: Float) `{
- gtk_alignment_set(recv, xalign, yalign, xscale, yscale);
+ gtk_alignment_set(self, xalign, yalign, xscale, yscale);
`}
end
`}
fun run `{
- gtk_dialog_run(recv);
+ gtk_dialog_run(self);
`}
end
`}
fun program_name: String import NativeString.to_s `{
- return NativeString_to_s((char *)gtk_about_dialog_get_program_name(recv));
+ return NativeString_to_s((char *)gtk_about_dialog_get_program_name(self));
`}
fun program_name=(name: String) import String.to_cstring `{
- gtk_about_dialog_set_program_name(recv, String_to_cstring(name));
+ gtk_about_dialog_set_program_name(self, String_to_cstring(name));
`}
fun version: String import NativeString.to_s `{
- return NativeString_to_s((char *)gtk_about_dialog_get_version(recv));
+ return NativeString_to_s((char *)gtk_about_dialog_get_version(self));
`}
fun version=(v: String) import String.to_cstring `{
- gtk_about_dialog_set_version(recv, String_to_cstring(v));
+ gtk_about_dialog_set_version(self, String_to_cstring(v));
`}
fun copyright: String import NativeString.to_s `{
- return NativeString_to_s((char *)gtk_about_dialog_get_copyright(recv));
+ return NativeString_to_s((char *)gtk_about_dialog_get_copyright(self));
`}
fun copyright=(c: String) import String.to_cstring `{
- gtk_about_dialog_set_copyright(recv, String_to_cstring(c));
+ gtk_about_dialog_set_copyright(self, String_to_cstring(c));
`}
fun comments: String import NativeString.to_s `{
- return NativeString_to_s((char *)gtk_about_dialog_get_comments(recv));
+ return NativeString_to_s((char *)gtk_about_dialog_get_comments(self));
`}
fun comments=(com: String) import String.to_cstring `{
- gtk_about_dialog_set_comments(recv, String_to_cstring(com));
+ gtk_about_dialog_set_comments(self, String_to_cstring(com));
`}
fun license: String import NativeString.to_s `{
- return NativeString_to_s((char *)gtk_about_dialog_get_license(recv));
+ return NativeString_to_s((char *)gtk_about_dialog_get_license(self));
`}
fun license=(li: String) import String.to_cstring `{
- gtk_about_dialog_set_license(recv, String_to_cstring(li));
+ gtk_about_dialog_set_license(self, String_to_cstring(li));
`}
# license_type
fun website: String import NativeString.to_s `{
- return NativeString_to_s((char *)gtk_about_dialog_get_website(recv));
+ return NativeString_to_s((char *)gtk_about_dialog_get_website(self));
`}
fun website=(link: String) import String.to_cstring `{
- gtk_about_dialog_set_website(recv, String_to_cstring(link));
+ gtk_about_dialog_set_website(self, String_to_cstring(link));
`}
fun website_label: String import NativeString.to_s `{
- return NativeString_to_s((char *) gtk_about_dialog_get_website_label(recv));
+ return NativeString_to_s((char *) gtk_about_dialog_get_website_label(self));
`}
fun website_label=(link_label: String) import String.to_cstring `{
- gtk_about_dialog_set_website_label(recv, String_to_cstring(link_label));
+ gtk_about_dialog_set_website_label(self, String_to_cstring(link_label));
`}
# TODO
# fun authors: String`{
- # return NativeString_to_s(gtk_about_dialog_get_authors(recv));
+ # return NativeString_to_s(gtk_about_dialog_get_authors(self));
# `}
# TODO
# fun authors=(authors_list: String) import String.to_cstring`{
- # gtk_about_dialog_set_authors(recv, String_to_cstring(authors_list));
+ # gtk_about_dialog_set_authors(self, String_to_cstring(authors_list));
# `}
fun show_about_dialog(parent: GtkWindow, params: String)
parent, flags, String_to_cstring(content_type));
`}
- fun widget: GtkWidget `{ return gtk_app_chooser_dialog_get_widget(recv); `}
+ fun widget: GtkWidget `{ return gtk_app_chooser_dialog_get_widget(self); `}
fun heading: String import NativeString.to_s `{
- return NativeString_to_s((char *)gtk_app_chooser_dialog_get_heading(recv));
+ return NativeString_to_s((char *)gtk_app_chooser_dialog_get_heading(self));
`}
fun heading=(text: String) import String.to_cstring `{
- gtk_app_chooser_dialog_set_heading(recv, String_to_cstring(text));
+ gtk_app_chooser_dialog_set_heading(self, String_to_cstring(text));
`}
end
`}
fun month=(month: Int, year: Int) `{
- gtk_calendar_select_month(recv, month, year);
+ gtk_calendar_select_month(self, month, year);
`}
fun day=(day: Int) `{
- gtk_calendar_select_day(recv, day);
+ gtk_calendar_select_day(self, day);
`}
fun mark_day(day: Int) `{
- gtk_calendar_mark_day(recv, day);
+ gtk_calendar_mark_day(self, day);
`}
fun unmark_day(day: Int) `{
- gtk_calendar_unmark_day(recv, day);
+ gtk_calendar_unmark_day(self, day);
`}
fun is_marked(day: Int): Bool `{
- return gtk_calendar_get_day_is_marked(recv, day);
+ return gtk_calendar_get_day_is_marked(self, day);
`}
fun clear_marks `{
- gtk_calendar_clear_marks(recv);
+ gtk_calendar_clear_marks(self);
`}
fun display_options: GtkCalendarDisplayOptions `{
- return gtk_calendar_get_display_options(recv);
+ return gtk_calendar_get_display_options(self);
`}
fun display_options=(options: GtkCalendarDisplayOptions) `{
- gtk_calendar_set_display_options(recv, options);
+ gtk_calendar_set_display_options(self, options);
`}
# date en nit...
`}
fun pulse `{
- gtk_progress_bar_pulse(recv);
+ gtk_progress_bar_pulse(self);
`}
fun pulse_step: Float `{
- return gtk_progress_bar_get_pulse_step(recv);
+ return gtk_progress_bar_get_pulse_step(self);
`}
fun pulse_step=(step: Float) `{
- gtk_progress_bar_set_pulse_step(recv, step);
+ gtk_progress_bar_set_pulse_step(self, step);
`}
fun fraction: Float `{
- return gtk_progress_bar_get_fraction(recv);
+ return gtk_progress_bar_get_fraction(self);
`}
fun fraction=(fraction: Float) `{
- gtk_progress_bar_set_fraction(recv, fraction);
+ gtk_progress_bar_set_fraction(self, fraction);
`}
fun inverted: Bool `{
- return gtk_progress_bar_get_inverted(recv);
+ return gtk_progress_bar_get_inverted(self);
`}
fun inverted=(is_inverted: Bool) `{
- gtk_progress_bar_set_inverted(recv, is_inverted);
+ gtk_progress_bar_set_inverted(self, is_inverted);
`}
fun show_text: Bool `{
- return gtk_progress_bar_get_show_text(recv);
+ return gtk_progress_bar_get_show_text(self);
`}
fun show_text=(show: Bool) `{
- gtk_progress_bar_set_show_text(recv, show);
+ gtk_progress_bar_set_show_text(self, show);
`}
fun text: String import NativeString.to_s `{
- return NativeString_to_s((char *)gtk_progress_bar_get_text(recv));
+ return NativeString_to_s((char *)gtk_progress_bar_get_text(self));
`}
fun text=(value: String) import String.to_cstring `{
- gtk_progress_bar_set_text(recv, String_to_cstring(value));
+ gtk_progress_bar_set_text(self, String_to_cstring(value));
`}
fun ellipsize is abstract
`}
# fun color_selection: `{
- # return gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(recv));
+ # return gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(self));
# `}
# fun color: Float `{
- # return gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(recv));
+ # return gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(self));
# `}
end
`}
fun configure (adjustment: GtkAdjustment, climb_rate: Float, digits: Int) `{
- gtk_spin_button_configure(recv, adjustment, climb_rate, digits);
+ gtk_spin_button_configure(self, adjustment, climb_rate, digits);
`}
fun adjustment: GtkAdjustment `{
- return gtk_spin_button_get_adjustment(recv);
+ return gtk_spin_button_get_adjustment(self);
`}
fun adjustment=(value: GtkAdjustment) `{
- gtk_spin_button_set_adjustment(recv, value);
+ gtk_spin_button_set_adjustment(self, value);
`}
fun digits: Int `{
- return gtk_spin_button_get_digits(recv);
+ return gtk_spin_button_get_digits(self);
`}
fun digits=(nb_digits: Int) `{
- gtk_spin_button_set_digits(recv, nb_digits);
+ gtk_spin_button_set_digits(self, nb_digits);
`}
fun value: Float `{
- return gtk_spin_button_get_value(recv);
+ return gtk_spin_button_get_value(self);
`}
fun val=(val: Float) `{
- gtk_spin_button_set_value(recv, val);
+ gtk_spin_button_set_value(self, val);
`}
fun spin(direction: GtkSpinType, increment: Float)`{
- gtk_spin_button_spin(recv, direction, increment);
+ gtk_spin_button_spin(self, direction, increment);
`}
end
#
# Can be used by on-screen keyboards and other input methods to adjust their behaviour.
fun input_purpose: GtkInputPurpose `{
- return gtk_entry_get_input_purpose(recv);
+ return gtk_entry_get_input_purpose(self);
`}
# Input purpose, tweaks the behavior of this widget
#
# Can be used by on-screen keyboards and other input methods to adjust their behaviour.
fun input_purpose=(purpose: GtkInputPurpose) `{
- gtk_entry_set_input_purpose(recv, purpose);
+ gtk_entry_set_input_purpose(self, purpose);
`}
end
redef class GtkWidget
# Get the visibility of the widget, check if it's parents are visible too
fun visible: Bool `{
- return gtk_widget_is_visible(recv);
+ return gtk_widget_is_visible(self);
`}
end
# Register `self` globally in C so it can be retrieved from iOS callbacks
private fun register_globally in "ObjC" `{
- App_incr_ref(recv);
- app_nit_ios_app = recv;
+ App_incr_ref(self);
+ app_nit_ios_app = self;
`}
# Entry point to the iOS framework
NSLog(@"Hello World!");
// Display "Hello world!" on the screen
- recv.window = [[UIWindow alloc] initWithFrame:
+ self.window = [[UIWindow alloc] initWithFrame:
[[UIScreen mainScreen] bounds]];
- recv.window.backgroundColor = [UIColor whiteColor];
+ self.window.backgroundColor = [UIColor whiteColor];
UILabel *label = [[UILabel alloc] init];
label.text = @"Hello World!";
label.center = CGPointMake(100, 100);
[label sizeToFit];
- [recv.window addSubview: label];
- [recv.window makeKeyAndVisible];
+ [self.window addSubview: label];
+ [self.window makeKeyAndVisible];
return YES;
`}
# Get a new array of the given `size`
new(size: Int) in "Java" `{ return new float[(int)size]; `}
- redef fun [](i) in "Java" `{ return (double)recv[(int)i]; `}
+ redef fun [](i) in "Java" `{ return (double)self[(int)i]; `}
- redef fun []=(i, e) in "Java" `{ recv[(int)i] = (float)e; `}
+ redef fun []=(i, e) in "Java" `{ self[(int)i] = (float)e; `}
- redef fun length in "Java" `{ return recv.length; `}
+ redef fun length in "Java" `{ return self.length; `}
end
# Java primitive array `double[]`
# Get a new array of the given `size`
new(size: Int) in "Java" `{ return new double[(int)size]; `}
- redef fun [](i) in "Java" `{ return recv[(int)i]; `}
+ redef fun [](i) in "Java" `{ return self[(int)i]; `}
- redef fun []=(i, e) in "Java" `{ recv[(int)i] = (float)e; `}
+ redef fun []=(i, e) in "Java" `{ self[(int)i] = (float)e; `}
- redef fun length in "Java" `{ return recv.length; `}
+ redef fun length in "Java" `{ return self.length; `}
end
# Java primitive array `Object[]`
# Get a new array of the given `size`
new(size: Int) in "Java" `{ return new Object[(int)size]; `}
- redef fun [](i) in "Java" `{ return recv[(int)i]; `}
+ redef fun [](i) in "Java" `{ return self[(int)i]; `}
- redef fun []=(i, e) in "Java" `{ recv[(int)i] = e; `}
+ redef fun []=(i, e) in "Java" `{ self[(int)i] = e; `}
- redef fun length in "Java" `{ return recv.length; `}
+ redef fun length in "Java" `{ return self.length; `}
end
# TODO other primitive arrays:
extern class NativeFile in "Java" `{ java.io.File `}
super JavaObject
- fun can_execute: Bool in "Java" `{ return recv.canExecute(); `}
- fun can_read: Bool in "Java" `{ return recv.canRead(); `}
- fun can_write: Bool in "Java" `{ return recv.canWrite(); `}
+ fun can_execute: Bool in "Java" `{ return self.canExecute(); `}
+ fun can_read: Bool in "Java" `{ return self.canRead(); `}
+ fun can_write: Bool in "Java" `{ return self.canWrite(); `}
fun create_file: Bool in "Java" `{
try {
- return recv.createNewFile();
+ return self.createNewFile();
}catch(IOException e){
e.printStackTrace();
return false;
}
`}
- fun delete: Bool in "Java" `{ return recv.delete(); `}
- fun delete_on_exit in "Java" `{ recv.deleteOnExit(); `}
- fun exists: Bool in "Java" `{ return recv.exists(); `}
- fun absolute_file: NativeFile in "Java" `{ return recv.getAbsoluteFile(); `}
- fun absolute_path: JavaString in "Java" `{ return recv.getAbsolutePath(); `}
+ fun delete: Bool in "Java" `{ return self.delete(); `}
+ fun delete_on_exit in "Java" `{ self.deleteOnExit(); `}
+ fun exists: Bool in "Java" `{ return self.exists(); `}
+ fun absolute_file: NativeFile in "Java" `{ return self.getAbsoluteFile(); `}
+ fun absolute_path: JavaString in "Java" `{ return self.getAbsolutePath(); `}
fun canonical_file: NativeFile in "Java" `{
try {
- return recv.getCanonicalFile();
+ return self.getCanonicalFile();
}catch(IOException e){
e.printStackTrace();
return null;
}
`}
- fun free_space: Int in "Java" `{ return (int)recv.getFreeSpace(); `}
- fun name: JavaString in "Java" `{ return recv.getName(); `}
- fun parent: JavaString in "Java" `{ return recv.getParent(); `}
- fun parent_file: NativeFile in "Java" `{ return recv.getParentFile(); `}
- fun path: JavaString in "Java" `{ return recv.getPath(); `}
- fun total_space: Int in "Java" `{ return (int)recv.getTotalSpace(); `}
- fun usable_space: Int in "Java" `{ return (int)recv.getUsableSpace(); `}
- fun absolute: Bool in "Java" `{ return recv.isAbsolute(); `}
- fun is_directory: Bool in "Java" `{ return recv.isDirectory(); `}
- fun is_file: Bool in "Java" `{ return recv.isFile(); `}
- fun is_hidden: Bool in "Java" `{ return recv.isHidden(); `}
- fun last_modified: Int in "Java" `{ return (int)recv.lastModified(); `}
- fun length: Int in "Java" `{ return (int)recv.length(); `}
- fun set_readable(r: Bool, owner_only: Bool): Bool in "Java" `{ return recv.setReadable(r, owner_only); `}
- fun set_writable(w: Bool, owner_only: Bool): Bool in "Java" `{ return recv.setWritable(w, owner_only); `}
+ fun free_space: Int in "Java" `{ return (int)self.getFreeSpace(); `}
+ fun name: JavaString in "Java" `{ return self.getName(); `}
+ fun parent: JavaString in "Java" `{ return self.getParent(); `}
+ fun parent_file: NativeFile in "Java" `{ return self.getParentFile(); `}
+ fun path: JavaString in "Java" `{ return self.getPath(); `}
+ fun total_space: Int in "Java" `{ return (int)self.getTotalSpace(); `}
+ fun usable_space: Int in "Java" `{ return (int)self.getUsableSpace(); `}
+ fun absolute: Bool in "Java" `{ return self.isAbsolute(); `}
+ fun is_directory: Bool in "Java" `{ return self.isDirectory(); `}
+ fun is_file: Bool in "Java" `{ return self.isFile(); `}
+ fun is_hidden: Bool in "Java" `{ return self.isHidden(); `}
+ fun last_modified: Int in "Java" `{ return (int)self.lastModified(); `}
+ fun length: Int in "Java" `{ return (int)self.length(); `}
+ fun set_readable(r: Bool, owner_only: Bool): Bool in "Java" `{ return self.setReadable(r, owner_only); `}
+ fun set_writable(w: Bool, owner_only: Bool): Bool in "Java" `{ return self.setWritable(w, owner_only); `}
end
extern class NativeFileInputStream in "Java" `{ java.io.FileInputStream `}
fun available: Int in "Java" `{
try {
- return recv.available();
+ return self.available();
}catch(IOException e){
e.printStackTrace();
return -1;
`}
fun close in "Java" `{
try {
- recv.close();
+ self.close();
}catch(IOException e){
e.printStackTrace();
}
`}
fun read: Int in "Java" `{
try {
- return recv.read();
+ return self.read();
}catch(IOException e){
e.printStackTrace();
return -1;
`}
fun skip(byte_count: Int): Int in "Java" `{
try {
- return (int)recv.skip(byte_count);
+ return (int)self.skip(byte_count);
}catch(IOException e){
e.printStackTrace();
return -1;
fun close in "Java" `{
try {
- recv.close();
+ self.close();
}catch(IOException e){
e.printStackTrace();
}
`}
fun write(one_byte: Int) in "Java" `{
try {
- recv.write((byte)one_byte);
+ self.write((byte)one_byte);
}catch(IOException e){
e.printStackTrace();
}
`}
fun flush in "Java" `{
try {
- recv.flush();
+ self.flush();
}catch(IOException e){
e.printStackTrace();
}
fun sync in "Java" `{
try{
- recv.sync();
+ self.sync();
}catch(SyncFailedException e){
e.printStackTrace();
}
`}
- fun valid: Bool in "Java" `{ return recv.valid(); `}
+ fun valid: Bool in "Java" `{ return self.valid(); `}
end
extern class NativeInputStream in "Java" `{ java.io.InputStream `}
fun available: Int in "Java" `{
try {
- return recv.available();
+ return self.available();
}catch(IOException e){
e.printStackTrace();
return -1;
fun close in "Java" `{
try {
- recv.close();
+ self.close();
}catch(IOException e){
e.printStackTrace();
}
# Get a Java class by its name from the current `jni_env`
fun load_jclass(name: NativeString): JClass import jni_env `{
- JNIEnv *nit_ffi_jni_env = Sys_jni_env(recv);
+ JNIEnv *nit_ffi_jni_env = Sys_jni_env(self);
// retrieve the implementation Java class
jclass java_class = (*nit_ffi_jni_env)->FindClass(nit_ffi_jni_env, name);
# Get the string from Java and copy it to Nit memory
fun to_cstring: NativeString import sys, Sys.jni_env `{
- Sys sys = JavaString_sys(recv);
+ Sys sys = JavaString_sys(self);
JNIEnv *env = Sys_jni_env(sys);
// Get the data from Java
- const jbyte *java_cstr = (char*)(*env)->GetStringUTFChars(env, recv, NULL);
- jsize len = (*env)->GetStringUTFLength(env, recv);
+ const jbyte *java_cstr = (char*)(*env)->GetStringUTFChars(env, self, NULL);
+ jsize len = (*env)->GetStringUTFLength(env, self);
// Copy it in control of Nit
char *nit_cstr = (char*)malloc(len+1);
nit_cstr[len] = '\0';
// Free JNI ref and return
- (*env)->ReleaseStringUTFChars(env, recv, java_cstr);
+ (*env)->ReleaseStringUTFChars(env, self, java_cstr);
return nit_cstr;
`}
# This instance is only valid until the next execution of Java code.
# You can use `new_local_ref` to keep it longer.
fun to_java_string: JavaString import sys, Sys.jni_env `{
- Sys sys = JavaString_sys(recv);
+ Sys sys = JavaString_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewStringUTF(env, recv);
+ return (*env)->NewStringUTF(env, self);
`}
end
# You must use a global reference when keeping a Java object
# across execution of Java code, per JNI specification.
fun new_global_ref: SELF import sys, Sys.jni_env `{
- Sys sys = JavaObject_sys(recv);
+ Sys sys = JavaObject_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- return (*env)->NewGlobalRef(env, recv);
+ return (*env)->NewGlobalRef(env, self);
`}
# Delete this global reference
fun delete_global_ref import sys, Sys.jni_env `{
- Sys sys = JavaObject_sys(recv);
+ Sys sys = JavaObject_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- (*env)->DeleteGlobalRef(env, recv);
+ (*env)->DeleteGlobalRef(env, self);
`}
# Delete this local reference
fun delete_local_ref import sys, Sys.jni_env `{
- Sys sys = JavaObject_sys(recv);
+ Sys sys = JavaObject_sys(self);
JNIEnv *env = Sys_jni_env(sys);
- (*env)->DeleteLocalRef(env, recv);
+ (*env)->DeleteLocalRef(env, self);
`}
# Pops the current local reference frame and return a valid reference to self
end
private fun pop_from_local_frame_with_env(jni_env: JniEnv): SELF `{
- return (*jni_env)->PopLocalFrame(jni_env, recv);
+ return (*jni_env)->PopLocalFrame(jni_env, self);
`}
# Is `self` null in Java?
# the return of all extern methods implemented in Java to ensure the value
# is not a Java null. In case it is, you should replace it by a normal Nit
# `null`.
- fun is_java_null: Bool in "Java" `{ return recv == null; `}
+ fun is_java_null: Bool in "Java" `{ return self == null; `}
# `JavaString` representation of `self` using Java's `toString`
- fun to_java_string: JavaString in "Java" `{ return recv.toString(); `}
+ fun to_java_string: JavaString in "Java" `{ return self.toString(); `}
# Use Java's `toString` for any `JavaObject`
redef fun to_s
# ~~~
module serialization
-import ::serialization
+import ::serialization::caching
private import ::serialization::engine_tools
private import static
# Serializer of Nit objects to Json string.
class JsonSerializer
- super Serializer
+ super CachingSerializer
# Target writing stream
var stream: Writer
redef fun serialize_reference(object)
do
- if not plain_json and refs_map.has_key(object) then
+ if not plain_json and cache.has_object(object) then
# if already serialized, add local reference
- var id = ref_id_for(object)
+ var id = cache.id_for(object)
stream.write "\{\"__kind\": \"ref\", \"__id\": "
stream.write id.to_s
stream.write "\}"
serialize object
end
end
-
- # Map of references to already serialized objects.
- private var refs_map = new StrictHashMap[Serializable,Int]
-
- # Get the internal serialized reference for this `object`.
- private fun ref_id_for(object: Serializable): Int
- do
- if refs_map.has_key(object) then
- return refs_map[object]
- else
- var id = refs_map.length
- refs_map[object] = id
- return id
- end
- end
end
# Deserializer from a Json string.
class JsonDeserializer
- super Deserializer
+ super CachingDeserializer
# Json text to deserialize from.
private var text: Text
# Depth-first path in the serialized object tree.
private var path = new Array[JsonObject]
- # Map of references to already deserialized objects.
- private var id_to_object = new StrictHashMap[Int, Object]
-
# Last encountered object reference id.
#
# See `id_to_object`.
do
var id = just_opened_id
if id == null then return # Register `new_object` only once
- id_to_object[id] = new_object
+ cache[id] = new_object
end
# Convert from simple Json object to Nit object
var id = object["__id"]
assert id isa Int
- assert id_to_object.has_key(id)
- return id_to_object[id]
+ assert cache.has_id(id)
+ return cache.object_for(id)
end
# obj?
var class_name = object["__class"]
assert class_name isa String
- assert not id_to_object.has_key(id) else print "Error: Object with id '{id}' of {class_name} is deserialized twice."
+ assert not cache.has_id(id) else print "Error: Object with id '{id}' of {class_name} is deserialized twice."
# advance on path
path.push object
redef class Serializable
private fun serialize_to_json(v: JsonSerializer)
do
- var id = v.ref_id_for(self)
+ var id = v.cache.new_id_for(self)
v.stream.write "\{"
if not v.plain_json then
v.stream.write "\"__kind\": \"obj\", \"__id\": "
do
# Register as pseudo object
if not v.plain_json then
- var id = v.ref_id_for(self)
+ var id = v.cache.new_id_for(self)
v.stream.write """{"__kind": "obj", "__id": """
v.stream.write id.to_s
v.stream.write """, "__class": """"
redef init from_deserializer(v: Deserializer)
do
+ super
if v isa JsonDeserializer then
v.notify_of_creation self
init
redef fun serialize_to_json(v)
do
# Register as pseudo object
- var id = v.ref_id_for(self)
+ var id = v.cache.new_id_for(self)
if v.plain_json then
v.stream.write "\{"
# Instantiate a new `Array` from its serialized representation.
redef init from_deserializer(v: Deserializer)
do
- init
+ super
if v isa JsonDeserializer then
v.notify_of_creation self
+ init
var length = v.deserialize_attribute("__length").as(Int)
var keys = v.path.last["__keys"].as(SequenceRead[nullable Object])
# Unavailable on Android, where you cannot instanciate a new JVM.
fun set_default `{
#ifndef ANDROID
- JNI_GetDefaultJavaVMInitArgs(recv);
+ JNI_GetDefaultJavaVMInitArgs(self);
#endif
`}
- fun version: Int `{ return recv->version; `}
- fun version=(v: Int) `{ recv->version = v; `}
+ fun version: Int `{ return self->version; `}
+ fun version=(v: Int) `{ self->version = v; `}
- fun options: JavaVMOptionArray `{ return recv->options; `}
- fun options=(v: JavaVMOptionArray) `{ recv->options = v; `}
+ fun options: JavaVMOptionArray `{ return self->options; `}
+ fun options=(v: JavaVMOptionArray) `{ self->options = v; `}
- fun n_options: Int `{ return recv->nOptions; `}
- fun n_options=(v: Int) `{ recv->nOptions = v; `}
+ fun n_options: Int `{ return self->nOptions; `}
+ fun n_options=(v: Int) `{ self->nOptions = v; `}
end
private extern class JavaVMOption `{ JavaVMOption* `}
fun string: String import NativeString.to_s `{
- return NativeString_to_s((char*)recv->optionString);
+ return NativeString_to_s((char*)self->optionString);
`}
fun string=(v: String) import String.to_cstring `{
- recv->optionString = String_to_cstring(v);
+ self->optionString = String_to_cstring(v);
`}
fun extra_info: String import NativeString.to_s `{
- return NativeString_to_s((char*)recv->extraInfo);
+ return NativeString_to_s((char*)self->extraInfo);
`}
fun extra_info=(v: String) import String.to_cstring `{
- recv->extraInfo = String_to_cstring(v);
+ self->extraInfo = String_to_cstring(v);
`}
end
private extern class JavaVMOptionArray `{ JavaVMOption* `}
new(size: Int) `{ return (JavaVMOption*)malloc(sizeof(JavaVMOption)*size); `}
- fun [](i: Int): JavaVMOption `{ return recv+i; `}
+ fun [](i: Int): JavaVMOption `{ return self+i; `}
end
# Represents a jni JavaVM
end
fun destroy `{
- (*recv)->DestroyJavaVM(recv);
+ (*self)->DestroyJavaVM(self);
`}
fun env: JniEnv import jni_error `{
JNIEnv *env;
- int res = (*recv)->GetEnv(recv, (void **)&env, JNI_VERSION_1_6);
+ int res = (*self)->GetEnv(self, (void **)&env, JNI_VERSION_1_6);
if (res != JNI_OK) {
JavaVM_jni_error(NULL, "Could not get JNIEnv from Java VM", res);
return NULL;
JNIEnv *env;
#ifdef ANDROID
// the signature is different (better actually) on Android
- int res = (*recv)->AttachCurrentThread(recv, &env, NULL);
+ int res = (*self)->AttachCurrentThread(self, &env, NULL);
#else
- int res = (*recv)->AttachCurrentThread(recv, (void**)&env, NULL);
+ int res = (*self)->AttachCurrentThread(self, (void**)&env, NULL);
#endif
if (res != JNI_OK) {
JavaVM_jni_error(NULL, "Could not attach current thread to Java VM", res);
# Get a class object from its fully-qualified name or null if the class cannot be found
fun find_class(class_name : String): JClass import String.to_cstring `{
- return (*recv)->FindClass(recv,String_to_cstring(class_name));
+ return (*self)->FindClass(self,String_to_cstring(class_name));
`}
# Return the method id for an instance of a class or interface
# The method is determined by its name and signature
# To obtain the method ID of a constructor, supply "<init>" as the method name and "void(V)" as the return type
fun get_method_id(clazz : JClass, name : String, signature : String): JMethodID import String.to_cstring `{
- return (*recv)->GetMethodID(recv, clazz, String_to_cstring(name), String_to_cstring(signature));
+ return (*self)->GetMethodID(self, clazz, String_to_cstring(name), String_to_cstring(signature));
`}
# Construct a new Java object from the `clazz`, using the constructor ̀ method_id`
fun new_object(clazz: JClass, method_id: JMethodID): JavaObject `{
- return (*recv)->NewObject(recv, clazz, method_id);
+ return (*self)->NewObject(self, clazz, method_id);
`}
# Return the JClass of `obj`
fun get_object_class(obj: JavaObject): JClass `{
- return (*recv)->GetObjectClass(recv, obj);
+ return (*self)->GetObjectClass(self, obj);
`}
# Registers native methods with the class specified by the `clazz` argument
fun register_natives(clazz: JClass, method: JNINativeMethod, n_method : Int): Int `{
- return (*recv)->RegisterNatives(recv, clazz, method, n_method);
+ return (*self)->RegisterNatives(self, clazz, method, n_method);
`}
# Call a method on `obj` designed by `method_id` with an array `args` of arguments
fun call_void_method(obj: JavaObject, method_id: JMethodID, args: nullable Array[nullable Object]) import convert_args_to_jni `{
- jvalue * args_tab = JniEnv_convert_args_to_jni(recv, args);
- (*recv)->CallVoidMethodA(recv, obj, method_id, args_tab);
+ jvalue * args_tab = JniEnv_convert_args_to_jni(self, args);
+ (*self)->CallVoidMethodA(self, obj, method_id, args_tab);
free(args_tab);
`}
# Call a method on `obj` designed by `method_id` with an array `args` of argument returning a JavaObject
fun call_object_method(obj: JavaObject, method_id: JMethodID, args: nullable Array[nullable Object]): JavaObject import convert_args_to_jni `{
- jvalue * args_tab = JniEnv_convert_args_to_jni(recv, args);
- jobject res = (*recv)->CallObjectMethod(recv, obj, method_id, args_tab);
+ jvalue * args_tab = JniEnv_convert_args_to_jni(self, args);
+ jobject res = (*self)->CallObjectMethod(self, obj, method_id, args_tab);
free(args_tab);
return res;
`}
# Call a method on `obj` designed by `method_id` with an array `args` of arguments returning a Bool
fun call_boolean_method(obj: JavaObject, method_id: JMethodID, args: nullable Array[nullable Object]): Bool import convert_args_to_jni `{
- jvalue * args_tab = JniEnv_convert_args_to_jni(recv, args);
- jboolean res = (*recv)->CallBooleanMethod(recv, obj, method_id, args_tab);
+ jvalue * args_tab = JniEnv_convert_args_to_jni(self, args);
+ jboolean res = (*self)->CallBooleanMethod(self, obj, method_id, args_tab);
free(args_tab);
return res;
`}
# Call a method on `obj` designed by `method_id` with an array `args` of arguments returning a Char
fun call_char_method(obj: JavaObject, method_id: JMethodID, args: nullable Array[nullable Object]): Char import convert_args_to_jni `{
- jvalue * args_tab = JniEnv_convert_args_to_jni(recv, args);
- jchar res = (*recv)->CallCharMethod(recv, obj, method_id, args_tab);
+ jvalue * args_tab = JniEnv_convert_args_to_jni(self, args);
+ jchar res = (*self)->CallCharMethod(self, obj, method_id, args_tab);
free(args_tab);
return res;
`}
# Call a method on `obj` designed by `method_id` with an array `args` of arguments returning an Int
fun call_int_method(obj: JavaObject, method_id: JMethodID, args: nullable Array[nullable Object]): Int import convert_args_to_jni `{
- jvalue * args_tab = JniEnv_convert_args_to_jni(recv, args);
- jint res = (*recv)->CallIntMethod(recv, obj, method_id, args_tab);
+ jvalue * args_tab = JniEnv_convert_args_to_jni(self, args);
+ jint res = (*self)->CallIntMethod(self, obj, method_id, args_tab);
free(args_tab);
return res;
`}
# Call a method on `obj` designed by `method_id` with an array `args` of arguments returning a Float
fun call_float_method(obj: JavaObject, method_id: JMethodID, args: nullable Array[nullable Object]): Float import convert_args_to_jni `{
- jvalue * args_tab = JniEnv_convert_args_to_jni(recv, args);
- jfloat res = (*recv)->CallFloatMethod(recv, obj, method_id, args_tab);
+ jvalue * args_tab = JniEnv_convert_args_to_jni(self, args);
+ jfloat res = (*self)->CallFloatMethod(self, obj, method_id, args_tab);
free(args_tab);
return res;
`}
# Call a method on `obj` designed by `method_id` with an array `args` of arguments returning a NativeString
fun call_string_method(obj: JavaObject, method_id: JMethodID, args: nullable Array[nullable Object]): NativeString import convert_args_to_jni `{
- jvalue * args_tab = JniEnv_convert_args_to_jni(recv, args);
- jobject jobj = (*recv)->CallObjectMethod(recv, obj, method_id, args_tab);
+ jvalue * args_tab = JniEnv_convert_args_to_jni(self, args);
+ jobject jobj = (*self)->CallObjectMethod(self, obj, method_id, args_tab);
free(args_tab);
- return (char*)(*recv)->GetStringUTFChars(recv, (jstring)jobj, NULL);
+ return (char*)(*self)->GetStringUTFChars(self, (jstring)jobj, NULL);
`}
private fun convert_args_to_jni(args: nullable Array[nullable Object]): Pointer import Array[nullable Object].as not nullable, Array[nullable Object].[], Array[nullable Object].length, nullable Object.as(Int), nullable Object.as(Char), nullable Object.as(Bool), nullable Object.as(Float), nullable Object.as(JavaObject), nullable Object.as(String), String.to_cstring, String.length `{
} else if(nullable_Object_is_a_String(nullable_obj)){
String val = nullable_Object_as_String(nullable_obj);
char* c = String_to_cstring(val);
- jstring js = (*recv)->NewStringUTF(recv, c);
+ jstring js = (*self)->NewStringUTF(self, c);
c_array[i].l = js;
} else {
fprintf(stderr, "NOT YET SUPPORTED: nit objects are not supported\n");
# Returns the field ID for an instance field of a class. The field is specified by its name and signature
fun get_field_id(clazz: JClass, name: String, sign: String): JFieldID import String.to_cstring `{
- return (*recv)->GetFieldID(recv, clazz, String_to_cstring(name), String_to_cstring(sign));
+ return (*self)->GetFieldID(self, clazz, String_to_cstring(name), String_to_cstring(sign));
`}
# returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling get_field_id()
fun get_object_field(obj: JavaObject, fieldID: JFieldID): JavaObject `{
- return (*recv)->GetObjectField(recv, obj, fieldID);
+ return (*self)->GetObjectField(self, obj, fieldID);
`}
fun get_boolean_field(obj: JavaObject, fieldID: JFieldID): Bool `{
- return (*recv)->GetBooleanField(recv, obj, fieldID);
+ return (*self)->GetBooleanField(self, obj, fieldID);
`}
fun get_char_field(obj: JavaObject, fieldID: JFieldID): Char `{
- return (*recv)->GetCharField(recv, obj, fieldID);
+ return (*self)->GetCharField(self, obj, fieldID);
`}
fun get_int_field(obj: JavaObject, fieldID: JFieldID): Int `{
- return (*recv)->GetIntField(recv, obj, fieldID);
+ return (*self)->GetIntField(self, obj, fieldID);
`}
fun get_float_field(obj: JavaObject, fieldID: JFieldID): Float `{
- return (*recv)->GetFloatField(recv, obj, fieldID);
+ return (*self)->GetFloatField(self, obj, fieldID);
`}
fun set_object_field(obj: JavaObject, fieldID: JFieldID, value: JavaObject) `{
- (*recv)->SetObjectField(recv, obj, fieldID, value);
+ (*self)->SetObjectField(self, obj, fieldID, value);
`}
fun set_boolean_field(obj: JavaObject, fieldID: JFieldID, value: Bool) `{
- (*recv)->SetBooleanField(recv, obj, fieldID, value);
+ (*self)->SetBooleanField(self, obj, fieldID, value);
`}
fun set_char_field(obj: JavaObject, fieldID: JFieldID, value: Char) `{
- (*recv)->SetCharField(recv, obj, fieldID, value);
+ (*self)->SetCharField(self, obj, fieldID, value);
`}
fun set_int_field(obj: JavaObject, fieldID: JFieldID, value: Int) `{
- (*recv)->SetIntField(recv, obj, fieldID, value);
+ (*self)->SetIntField(self, obj, fieldID, value);
`}
fun set_float_field(obj: JavaObject, fieldID: JFieldID, value: Float) `{
- (*recv)->SetFloatField(recv, obj, fieldID, value);
+ (*self)->SetFloatField(self, obj, fieldID, value);
`}
# Check for pending exception without creating a local reference to the exception object
fun exception_check: Bool `{
- return (*recv)->ExceptionCheck(recv);
+ return (*self)->ExceptionCheck(self);
`}
# Construct an exception object from the specified class with the message specified by `message` and causes that exception to be thrown
fun throw_new(clazz: JClass, message: String): Int import String.to_cstring `{
- return (*recv)->ThrowNew(recv, clazz, String_to_cstring(message));
+ return (*self)->ThrowNew(self, clazz, String_to_cstring(message));
`}
# return the exception if there is one in the process of being thrown, or NULL if no exception is currently being thrown
fun exception_occurred: JavaObject `{
- return (*recv)->ExceptionOccurred(recv);
+ return (*self)->ExceptionOccurred(self);
`}
# prints an exception and backtrace to error channel
fun exception_describe `{
- return (*recv)->ExceptionDescribe(recv);
+ return (*self)->ExceptionDescribe(self);
`}
# clears any exception currently being thrown, has no effect if there is no exception
fun exception_clear `{
- return (*recv)->ExceptionClear(recv);
+ return (*self)->ExceptionClear(self);
`}
# Raise a fatal error
fun fatal_error(msg: String) import String.to_cstring `{
- (*recv)->FatalError(recv, String_to_cstring(msg));
+ (*self)->FatalError(self, String_to_cstring(msg));
`}
# Transform a NIT String into a JavaObject
fun string_to_jobject(string: String): JavaObject `{
- return (*recv)->NewStringUTF(recv, String_to_cstring(string));
+ return (*self)->NewStringUTF(self, String_to_cstring(string));
`}
# Pushes a local reference frame on the JNI stack
fun push_local_frame(capacity: Int): Bool `{
- return (*recv)->PushLocalFrame(recv, capacity);
+ return (*self)->PushLocalFrame(self, capacity);
`}
# Pops the current local reference frame on the JNI stack
#
# Similiar to `JavaObject::pop_from_local_frame` which returns a value.
fun pop_local_frame `{
- (*recv)->PopLocalFrame(recv, NULL);
+ (*self)->PopLocalFrame(self, NULL);
`}
end
# Represents a jni JNINNativeMethod
extern class JNINativeMethod `{ JNINativeMethod* `}
fun name: String import NativeString.to_s `{
- return NativeString_to_s((void*)recv->name);
+ return NativeString_to_s((void*)self->name);
`}
fun name=(name: String) import String.to_cstring `{
- recv->name = String_to_cstring(name);
+ self->name = String_to_cstring(name);
`}
fun signature: String import NativeString.to_s `{
- return NativeString_to_s((void*)recv->signature);
+ return NativeString_to_s((void*)self->signature);
`}
fun signature=(signature: String) import String.to_cstring `{
- recv->signature = String_to_cstring(signature);
+ self->signature = String_to_cstring(signature);
`}
end
extern class JValue `{jvalue`}
fun set_boolean(b: Bool) `{
- recv.z = b;
+ self.z = b;
`}
fun get_boolean:Bool `{
- return recv.z;
+ return self.z;
`}
fun set_char(c: Char)`{
- recv.c = c;
+ self.c = c;
`}
fun get_char: Char `{
- return recv.c;
+ return self.c;
`}
fun set_int(i: Int) `{
- recv.i = i;
+ self.i = i;
`}
fun get_int: Int `{
- return recv.i;
+ return self.i;
`}
fun set_float(f: Float) `{
- recv.f = f;
+ self.f = f;
`}
fun get_float: Float `{
- return recv.f;
+ return self.f;
`}
fun set_jobject(obj: JavaObject) `{
- recv.l = obj;
+ self.l = obj;
`}
fun get_jobject: JavaObject `{
- return recv.l;
+ return self.l;
`}
end
redef class Int
redef fun to_jvalue(env): JValue `{
jvalue value;
- value.i = recv;
+ value.i = self;
return value;
`}
end
redef class Float
redef fun to_jvalue(env): JValue `{
jvalue value;
- value.f = recv;
+ value.f = self;
return value;
`}
end
redef class Bool
redef fun to_jvalue(env): JValue `{
jvalue value;
- value.z = recv;
+ value.z = self;
return value;
`}
end
redef class NativeString
redef fun to_jvalue(env)`{
jvalue value;
- value.l = (*env)->NewStringUTF(env, recv);
+ value.l = (*env)->NewStringUTF(env, self);
return value;
`}
end
#
# This loop will run the event base until either there are no more added
# events, or until something calls `exit_loop`.
- fun dispatch `{ event_base_dispatch(recv); `}
+ fun dispatch `{ event_base_dispatch(self); `}
# Exit the event loop
#
# TODO support timer
- fun exit_loop `{ event_base_loopexit(recv, NULL); `}
+ fun exit_loop `{ event_base_loopexit(self, NULL); `}
# Destroy this instance
- fun destroy `{ event_base_free(recv); `}
+ fun destroy `{ event_base_free(self); `}
end
# Spawned to manage a specific connection
extern class NativeBufferEvent `{ struct bufferevent * `}
# Write `length` bytes of `line`
fun write(line: NativeString, length: Int): Int `{
- return bufferevent_write(recv, line, length);
+ return bufferevent_write(self, line, length);
`}
# Write the byte `value`
fun write_byte(value: Int): Int `{
unsigned char byt = (unsigned char)value;
- return bufferevent_write(recv, &byt, 1);
+ return bufferevent_write(self, &byt, 1);
`}
# Check if we have anything left in our buffers. If so, we set our connection to be closed
# on a callback. Otherwise we close it and free it right away.
fun destroy: Bool `{
- struct evbuffer* out = bufferevent_get_output(recv);
- struct evbuffer* in = bufferevent_get_input(recv);
+ struct evbuffer* out = bufferevent_get_output(self);
+ struct evbuffer* in = bufferevent_get_input(self);
if(evbuffer_get_length(in) > 0 || evbuffer_get_length(out) > 0) {
return 0;
} else {
- bufferevent_free(recv);
+ bufferevent_free(self);
return 1;
}
`}
# The output buffer associated to `self`
- fun output_buffer: OutputNativeEvBuffer `{ return bufferevent_get_output(recv); `}
+ fun output_buffer: OutputNativeEvBuffer `{ return bufferevent_get_output(self); `}
# The input buffer associated to `self`
- fun input_buffer: InputNativeEvBuffer `{ return bufferevent_get_input(recv); `}
+ fun input_buffer: InputNativeEvBuffer `{ return bufferevent_get_input(self); `}
end
# A single buffer
extern class NativeEvBuffer `{ struct evbuffer * `}
# Length of data in this buffer
- fun length: Int `{ return evbuffer_get_length(recv); `}
+ fun length: Int `{ return evbuffer_get_length(self); `}
end
# An input buffer
super NativeEvBuffer
# Empty/clear `length` data from buffer
- fun drain(length: Int) `{ evbuffer_drain(recv, length); `}
+ fun drain(length: Int) `{ evbuffer_drain(self, length); `}
end
# An output buffer
# Add file to buffer
fun add_file(fd, offset, length: Int): Bool `{
- return evbuffer_add_file(recv, fd, offset, length);
+ return evbuffer_add_file(self, fd, offset, length);
`}
end
`}
# Get the `NativeEventBase` associated to `self`
- fun base: NativeEventBase `{ return evconnlistener_get_base(recv); `}
+ fun base: NativeEventBase `{ return evconnlistener_get_base(self); `}
# Callback method on listening error
fun error_callback do
# Split `input` string into `MDLines` and create a parent `MDBlock` with it.
private fun read_lines(input: String): MDBlock do
- var block = new MDBlock
+ var block = new MDBlock(new MDLocation(1, 1, 1, 1))
var value = new FlatBuffer
var i = 0
+
+ var line_pos = 0
+ var col_pos = 0
+
while i < input.length do
value.clear
var pos = 0
var eol = false
while not eol and i < input.length do
+ col_pos += 1
var c = input[i]
if c == '\n' then
- i += 1
eol = true
else if c == '\t' then
var np = pos + (4 - (pos.bin_and(3)))
value.add ' '
pos += 1
end
- i += 1
else
pos += 1
value.add c
- i += 1
end
+ i += 1
end
+ line_pos += 1
- var line = new MDLine(value.write_to_string)
+ var loc = new MDLocation(line_pos, 1, line_pos, col_pos)
+ var line = new MDLine(loc, value.write_to_string)
var is_link_ref = check_link_ref(line)
# Skip link refs
if not is_link_ref then block.add_line line
+ col_pos = 0
end
return block
end
c2 = ' '
end
+ var loc = text.pos_to_loc(pos)
+
if c == '*' then
if c1 == '*' then
if c0 != ' ' or c2 != ' ' then
- return new TokenStrongStar(pos, c)
+ return new TokenStrongStar(loc, pos, c)
else
- return new TokenEmStar(pos, c)
+ return new TokenEmStar(loc, pos, c)
end
end
if c0 != ' ' or c1 != ' ' then
- return new TokenEmStar(pos, c)
+ return new TokenEmStar(loc, pos, c)
else
- return new TokenNone(pos, c)
+ return new TokenNone(loc, pos, c)
end
else if c == '_' then
if c1 == '_' then
if c0 != ' ' or c2 != ' 'then
- return new TokenStrongUnderscore(pos, c)
+ return new TokenStrongUnderscore(loc, pos, c)
else
- return new TokenEmUnderscore(pos, c)
+ return new TokenEmUnderscore(loc, pos, c)
end
end
if ext_mode then
if (c0.is_letter or c0.is_digit) and c0 != '_' and
(c1.is_letter or c1.is_digit) then
- return new TokenNone(pos, c)
+ return new TokenNone(loc, pos, c)
else
- return new TokenEmUnderscore(pos, c)
+ return new TokenEmUnderscore(loc, pos, c)
end
end
if c0 != ' ' or c1 != ' ' then
- return new TokenEmUnderscore(pos, c)
+ return new TokenEmUnderscore(loc, pos, c)
else
- return new TokenNone(pos, c)
+ return new TokenNone(loc, pos, c)
end
else if c == '!' then
- if c1 == '[' then return new TokenImage(pos, c)
- return new TokenNone(pos, c)
+ if c1 == '[' then return new TokenImage(loc, pos, c)
+ return new TokenNone(loc, pos, c)
else if c == '[' then
- return new TokenLink(pos, c)
+ return new TokenLink(loc, pos, c)
else if c == ']' then
- return new TokenNone(pos, c)
+ return new TokenNone(loc, pos, c)
else if c == '`' then
if c1 == '`' then
- return new TokenCodeDouble(pos, c)
+ return new TokenCodeDouble(loc, pos, c)
else
- return new TokenCodeSingle(pos, c)
+ return new TokenCodeSingle(loc, pos, c)
end
else if c == '\\' then
if c1 == '\\' or c1 == '[' or c1 == ']' or c1 == '(' or c1 == ')' or c1 == '{' or c1 == '}' or c1 == '#' or c1 == '"' or c1 == '\'' or c1 == '.' or c1 == '<' or c1 == '>' or c1 == '*' or c1 == '+' or c1 == '-' or c1 == '_' or c1 == '!' or c1 == '`' or c1 == '~' or c1 == '^' then
- return new TokenEscape(pos, c)
+ return new TokenEscape(loc, pos, c)
else
- return new TokenNone(pos, c)
+ return new TokenNone(loc, pos, c)
end
else if c == '<' then
- return new TokenHTML(pos, c)
+ return new TokenHTML(loc, pos, c)
else if c == '&' then
- return new TokenEntity(pos, c)
+ return new TokenEntity(loc, pos, c)
else
if ext_mode then
if c == '~' and c1 == '~' then
- return new TokenStrike(pos, c)
+ return new TokenStrike(loc, pos, c)
end
end
- return new TokenNone(pos, c)
+ return new TokenNone(loc, pos, c)
end
end
private var allowed_id_chars: Array[Char] = ['-', '_', ':', '.']
end
+# Location in a Markdown input.
+class MDLocation
+
+ # Starting line number (starting from 1).
+ var line_start: Int
+
+ # Starting column number (starting from 1).
+ var column_start: Int
+
+ # Stopping line number (starting from 1).
+ var line_end: Int
+
+ # Stopping column number (starting from 1).
+ var column_end: Int
+
+ redef fun to_s do return "{line_start},{column_start}--{line_end},{column_end}"
+end
+
# A block of markdown lines.
# A `MDBlock` can contains lines and/or sub-blocks.
class MDBlock
+
+ # Position of `self` in the input.
+ var location: MDLocation
+
# Kind of block.
# See `Block`.
var kind: Block = new BlockNone(self) is writable
# Split `self` creating a new sub-block having `line` has `last_line`.
fun split(line: MDLine): MDBlock do
- var block = new MDBlock
+ # location for new block
+ var new_loc = new MDLocation(
+ first_line.location.line_start,
+ first_line.location.column_start,
+ line.location.line_end,
+ line.location.column_end)
+ # create block
+ var block = new MDBlock(new_loc)
block.first_line = first_line
block.last_line = line
first_line = line.next
last_line = null
else
first_line.prev = null
+ # update current block loc
+ location.line_start = first_line.location.line_start
+ location.column_start = first_line.location.column_start
end
if first_block == null then
first_block = block
# A markdown line.
class MDLine
+ # Location of `self` in the original input.
+ var location: MDLocation
+
# Text contained in this line.
var value: String is writable
# Some tokens have a specific markup behaviour that is handled here.
abstract class Token
- # Position of `self` in markdown input.
+ # Location of `self` in the original input.
+ var location: MDLocation
+
+ # Position of `self` in input independant from lines.
var pos: Int
# Character found at `pos` in the markdown input.
return null
end
+ # Init a `MDLocation` instance at `pos` in `self`.
+ private fun pos_to_loc(pos: Int): MDLocation do
+ assert pos <= length
+ var line = 1
+ var col = 0
+ var i = 0
+ while i <= pos do
+ col += 1
+ var c = self[i]
+ if c == '\n' then
+ line +=1
+ col = 0
+ end
+ i +=1
+ end
+ return new MDLocation(line, col, line, col)
+ end
+
# Is `self` an unsafe HTML element?
private fun is_html_unsafe: Bool do return html_unsafe_tags.has(self.write_to_string)
class TestBlock
super TestSuite
+ # A dummy location for testing purposes.
+ var loc = new MDLocation(0, 0, 0, 0)
+
fun test_has_blocks do
- var subject = new MDBlock
+ var subject = new MDBlock(loc)
assert not subject.has_blocks
- subject.first_block = new MDBlock
+ subject.first_block = new MDBlock(loc)
assert subject.has_blocks
end
fun test_count_blocks do
- var subject = new MDBlock
+ var subject = new MDBlock(loc)
assert subject.count_blocks == 0
- subject.first_block = new MDBlock
+ subject.first_block = new MDBlock(loc)
assert subject.count_blocks == 1
- subject.first_block.next = new MDBlock
+ subject.first_block.next = new MDBlock(loc)
assert subject.count_blocks == 2
end
fun test_has_lines do
- var subject = new MDBlock
+ var subject = new MDBlock(loc)
assert not subject.has_lines
- subject.first_line = new MDLine("")
+ subject.first_line = new MDLine(loc, "")
assert subject.has_lines
end
fun test_count_lines do
- var subject = new MDBlock
+ var subject = new MDBlock(loc)
assert subject.count_lines == 0
- subject.first_line = new MDLine("")
+ subject.first_line = new MDLine(loc, "")
assert subject.count_lines == 1
- subject.first_line.next = new MDLine("")
+ subject.first_line.next = new MDLine(loc, "")
assert subject.count_lines == 2
end
fun test_split do
- var line1 = new MDLine("line1")
- var line2 = new MDLine("line2")
- var line3 = new MDLine("line3")
- var subject = new MDBlock
+ var line1 = new MDLine(loc, "line1")
+ var line2 = new MDLine(loc, "line2")
+ var line3 = new MDLine(loc, "line3")
+ var subject = new MDBlock(loc)
subject.add_line line1
subject.add_line line2
subject.add_line line3
end
fun test_add_line do
- var subject = new MDBlock
+ var subject = new MDBlock(loc)
assert subject.count_lines == 0
- subject.add_line new MDLine("")
+ subject.add_line new MDLine(loc, "")
assert subject.count_lines == 1
- subject.add_line new MDLine("")
+ subject.add_line new MDLine(loc, "")
assert subject.count_lines == 2
end
fun test_remove_line do
- var line1 = new MDLine("line1")
- var line2 = new MDLine("line2")
- var line3 = new MDLine("line3")
- var subject = new MDBlock
+ var line1 = new MDLine(loc, "line1")
+ var line2 = new MDLine(loc, "line2")
+ var line3 = new MDLine(loc, "line3")
+ var subject = new MDBlock(loc)
subject.add_line line1
subject.add_line line2
subject.add_line line3
end
fun test_transform_headline1 do
- var subject = new MDBlock
+ var subject = new MDBlock(loc)
var kind = new BlockHeadline(subject)
- subject.add_line new MDLine(" # Title 1 ")
+ subject.add_line new MDLine(loc, " # Title 1 ")
kind.transform_headline(subject)
assert kind.depth == 1
assert subject.first_line.value == "Title 1"
end
fun test_transform_headline2 do
- var subject = new MDBlock
+ var subject = new MDBlock(loc)
var kind = new BlockHeadline(subject)
- subject.add_line new MDLine(" #####Title 5 ")
+ subject.add_line new MDLine(loc, " #####Title 5 ")
kind.transform_headline(subject)
assert kind.depth == 5
assert subject.first_line.value == "Title 5"
end
fun test_remove_quote_prefix do
- var subject = new MDBlock
+ var subject = new MDBlock(loc)
var kind = new BlockQuote(subject)
- subject.add_line new MDLine(" > line 1")
- subject.add_line new MDLine(" > line 2")
- subject.add_line new MDLine(" > line 3")
+ subject.add_line new MDLine(loc, " > line 1")
+ subject.add_line new MDLine(loc, " > line 2")
+ subject.add_line new MDLine(loc, " > line 3")
kind.remove_block_quote_prefix(subject)
assert subject.first_line.value == "line 1"
assert subject.first_line.next.value == "line 2"
end
fun test_remove_leading_empty_lines_1 do
- var block = new MDBlock
- block.add_line new MDLine("")
- block.add_line new MDLine("")
- block.add_line new MDLine("")
- block.add_line new MDLine("")
- block.add_line new MDLine(" text")
- block.add_line new MDLine("")
+ var block = new MDBlock(loc)
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, " text")
+ block.add_line new MDLine(loc, "")
assert block.remove_leading_empty_lines
assert block.first_line.value == " text"
end
fun test_remove_leading_empty_lines_2 do
- var block = new MDBlock
- block.add_line new MDLine(" text")
+ var block = new MDBlock(loc)
+ block.add_line new MDLine(loc, " text")
block.remove_leading_empty_lines
assert block.first_line.value == " text"
end
fun test_remove_trailing_empty_lines_1 do
- var block = new MDBlock
- block.add_line new MDLine("")
- block.add_line new MDLine("text")
- block.add_line new MDLine("")
- block.add_line new MDLine("")
- block.add_line new MDLine("")
- block.add_line new MDLine("")
+ var block = new MDBlock(loc)
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "text")
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "")
assert block.remove_trailing_empty_lines
assert block.last_line.value == "text"
end
fun test_remove_trailing_empty_lines_2 do
- var block = new MDBlock
- block.add_line new MDLine("text ")
+ var block = new MDBlock(loc)
+ block.add_line new MDLine(loc, "text ")
assert not block.remove_trailing_empty_lines
assert block.last_line.value == "text "
end
fun test_remove_surrounding_empty_lines do
- var block = new MDBlock
- block.add_line new MDLine("")
- block.add_line new MDLine("text")
- block.add_line new MDLine("")
- block.add_line new MDLine("")
- block.add_line new MDLine("")
- block.add_line new MDLine("")
+ var block = new MDBlock(loc)
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "text")
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "")
+ block.add_line new MDLine(loc, "")
assert block.remove_surrounding_empty_lines
assert block.first_line.value == "text"
assert block.last_line.value == "text"
class TestLine
super TestSuite
+ # A dummy location for testing purposes.
+ var loc = new MDLocation(0, 0, 0, 0)
+
var subject: MDLine
fun test_is_empty do
- subject = new MDLine("")
+ subject = new MDLine(loc, "")
assert subject.is_empty
- subject = new MDLine(" ")
+ subject = new MDLine(loc, " ")
assert subject.is_empty
- subject = new MDLine("test")
+ subject = new MDLine(loc, "test")
assert not subject.is_empty
- subject = new MDLine(" test")
+ subject = new MDLine(loc, " test")
assert not subject.is_empty
end
fun test_leading do
- subject = new MDLine("")
+ subject = new MDLine(loc, "")
assert subject.leading == 0
- subject = new MDLine(" ")
+ subject = new MDLine(loc, " ")
assert subject.leading == 4
- subject = new MDLine("test")
+ subject = new MDLine(loc, "test")
assert subject.leading == 0
- subject = new MDLine(" test")
+ subject = new MDLine(loc, " test")
assert subject.leading == 4
end
fun test_trailing do
- subject = new MDLine("")
+ subject = new MDLine(loc, "")
assert subject.trailing == 0
- subject = new MDLine(" ")
+ subject = new MDLine(loc, " ")
assert subject.trailing == 0
- subject = new MDLine("test ")
+ subject = new MDLine(loc, "test ")
assert subject.trailing == 3
- subject = new MDLine(" test ")
+ subject = new MDLine(loc, " test ")
assert subject.trailing == 1
end
fun test_line_type do
var v = new MarkdownProcessor
- subject = new MDLine("")
+ subject = new MDLine(loc, "")
assert v.line_kind(subject) isa LineEmpty
- subject = new MDLine(" ")
+ subject = new MDLine(loc, " ")
assert v.line_kind(subject) isa LineEmpty
- subject = new MDLine("text ")
+ subject = new MDLine(loc, "text ")
assert v.line_kind(subject) isa LineOther
- subject = new MDLine(" # Title")
+ subject = new MDLine(loc, " # Title")
assert v.line_kind(subject) isa LineHeadline
- subject = new MDLine(" ### Title")
+ subject = new MDLine(loc, " ### Title")
assert v.line_kind(subject) isa LineHeadline
- subject = new MDLine(" code")
+ subject = new MDLine(loc, " code")
assert v.line_kind(subject) isa LineCode
- subject = new MDLine(" Title ")
- subject.next = new MDLine("== ")
+ subject = new MDLine(loc, " Title ")
+ subject.next = new MDLine(loc, "== ")
assert v.line_kind(subject) isa LineHeadline1
- subject = new MDLine(" Title ")
- subject.next = new MDLine("-- ")
+ subject = new MDLine(loc, " Title ")
+ subject.next = new MDLine(loc, "-- ")
assert v.line_kind(subject) isa LineHeadline2
- subject = new MDLine(" * * * ")
+ subject = new MDLine(loc, " * * * ")
assert v.line_kind(subject) isa LineHR
- subject = new MDLine(" *** ")
+ subject = new MDLine(loc, " *** ")
assert v.line_kind(subject) isa LineHR
- subject = new MDLine("- -- ")
+ subject = new MDLine(loc, "- -- ")
assert v.line_kind(subject) isa LineHR
- subject = new MDLine("--------- ")
+ subject = new MDLine(loc, "--------- ")
assert v.line_kind(subject) isa LineHR
- subject = new MDLine(" >")
+ subject = new MDLine(loc, " >")
assert v.line_kind(subject) isa LineBlockquote
- subject = new MDLine("<p></p>")
+ subject = new MDLine(loc, "<p></p>")
assert v.line_kind(subject) isa LineXML
- subject = new MDLine("<p>")
+ subject = new MDLine(loc, "<p>")
assert v.line_kind(subject) isa LineOther
- subject = new MDLine(" * foo")
+ subject = new MDLine(loc, " * foo")
assert v.line_kind(subject) isa LineUList
- subject = new MDLine("- foo")
+ subject = new MDLine(loc, "- foo")
assert v.line_kind(subject) isa LineUList
- subject = new MDLine("+ foo")
+ subject = new MDLine(loc, "+ foo")
assert v.line_kind(subject) isa LineUList
- subject = new MDLine("1. foo")
+ subject = new MDLine(loc, "1. foo")
assert v.line_kind(subject) isa LineOList
- subject = new MDLine(" 11111. foo")
+ subject = new MDLine(loc, " 11111. foo")
assert v.line_kind(subject) isa LineOList
end
fun test_line_type_ext do
var v = new MarkdownProcessor
- subject = new MDLine(" ~~~")
+ subject = new MDLine(loc, " ~~~")
assert v.line_kind(subject) isa LineFence
- subject = new MDLine(" ```")
+ subject = new MDLine(loc, " ```")
assert v.line_kind(subject) isa LineFence
end
fun test_count_chars do
- subject = new MDLine("")
+ subject = new MDLine(loc, "")
assert subject.count_chars('*') == 0
- subject = new MDLine("* ")
+ subject = new MDLine(loc, "* ")
assert subject.count_chars('*') == 1
- subject = new MDLine(" * text")
+ subject = new MDLine(loc, " * text")
assert subject.count_chars('*') == 0
- subject = new MDLine(" * * *")
+ subject = new MDLine(loc, " * * *")
assert subject.count_chars('*') == 3
- subject = new MDLine("text ** ")
+ subject = new MDLine(loc, "text ** ")
assert subject.count_chars('*') == 0
end
fun test_count_chars_start do
- subject = new MDLine("")
+ subject = new MDLine(loc, "")
assert subject.count_chars_start('*') == 0
- subject = new MDLine("* ")
+ subject = new MDLine(loc, "* ")
assert subject.count_chars_start('*') == 1
- subject = new MDLine(" * text")
+ subject = new MDLine(loc, " * text")
assert subject.count_chars_start('*') == 1
- subject = new MDLine(" * * * text")
+ subject = new MDLine(loc, " * * * text")
assert subject.count_chars_start('*') == 3
- subject = new MDLine("text ** ")
+ subject = new MDLine(loc, "text ** ")
assert subject.count_chars_start('*') == 0
end
end
assert res == exp
end
end
+
+class TestTokenLocation
+ super TestSuite
+
+ fun test_token_location1 do
+ var string = "**Hello** `World`"
+ var stack = [
+ "TokenStrongStar at 1,1--1,1",
+ "TokenStrongStar at 1,8--1,8",
+ "TokenCodeSingle at 1,11--1,11",
+ "TokenCodeSingle at 1,17--1,17"]
+ (new TestTokenProcessor(stack)).process(string)
+ end
+
+ fun test_token_location2 do
+ var string = "**Hello**\n`World`\n*Bonjour*\n[le monde]()"
+ var stack = [
+ "TokenStrongStar at 1,1--1,1",
+ "TokenStrongStar at 1,8--1,8",
+ "TokenCodeSingle at 2,1--2,1",
+ "TokenCodeSingle at 2,7--2,7",
+ "TokenEmStar at 3,1--3,1",
+ "TokenEmStar at 3,9--3,9",
+ "TokenLink at 4,1--4,1"]
+ (new TestTokenProcessor(stack)).process(string)
+ end
+
+ fun test_token_location3 do
+ var string = """**Hello**
+ `World`
+ *Bonjour*
+ [le monde]()"""
+ var stack = [
+ "TokenStrongStar at 1,1--1,1",
+ "TokenStrongStar at 1,8--1,8",
+ "TokenCodeSingle at 2,1--2,1",
+ "TokenCodeSingle at 2,7--2,7",
+ "TokenEmStar at 3,1--3,1",
+ "TokenEmStar at 3,9--3,9",
+ "TokenLink at 4,1--4,1"]
+ (new TestTokenProcessor(stack)).process(string)
+ end
+end
+
+class TestTokenProcessor
+ super MarkdownProcessor
+
+ var test_stack: Array[String]
+
+ redef fun token_at(input, pos) do
+ var token = super
+ if token isa TokenNone then return token
+ var res = "{token.class_name} at {token.location}"
+ print res
+ var exp = test_stack.shift
+ assert exp == res
+ return token
+ end
+end
+
+class TestBlockLocation
+ super TestSuite
+
+ var proc = new MarkdownProcessor
+
+ fun test_block_location1 do
+ var stack = [
+ "BlockHeadline: 1,1--1,8",
+ "BlockListItem: 2,1--2,6",
+ "BlockListItem: 3,1--3,5"
+ ]
+ var string =
+ "# Title\n* li1\n* li2"
+ proc.emitter.decorator = new TestBlockDecorator(stack)
+ proc.process(string)
+ end
+
+ fun test_block_location2 do
+ var stack = [
+ "BlockHeadline: 1,1--1,11",
+ "BlockFence: 3,1--5,4",
+ "BlockListItem: 7,1--7,7",
+ "BlockListItem: 8,1--8,6"]
+ var string ="""#### Title
+
+~~~fence
+some code
+~~~
+
+1. li1
+1. li2"""
+ proc.emitter.decorator = new TestBlockDecorator(stack)
+ proc.process(string)
+ end
+end
+
+class TestBlockDecorator
+ super HTMLDecorator
+
+ var stack: Array[String]
+
+ redef fun add_headline(v, block) do
+ super
+ check_res(block)
+ end
+
+ redef fun add_listitem(v, block) do
+ super
+ check_res(block)
+ end
+
+ redef fun add_blockquote(v, block) do
+ super
+ check_res(block)
+ end
+
+ redef fun add_code(v, block) do
+ super
+ check_res(block)
+ end
+
+ fun check_res(block: Block) do
+ var res = "{block.class_name}: {block.block.location}"
+ var exp = stack.shift
+ assert res == exp
+ end
+end
if not token isa TokenLink then return token
if pos + 1 < text.length then
var c = text[pos + 1]
- if c == '[' then return new TokenWikiLink(pos, c)
+ if c == '[' then return new TokenWikiLink(token.location, pos, c)
end
return token
end
int di;
char *in_text;
- in_text = String_to_cstring(recv);
+ in_text = String_to_cstring(self);
md5_init(&state);
md5_append(&state, (const md5_byte_t *)in_text, strlen(in_text));
}
/* Used by Android to set buffer geometry */
- Opengles1Display_midway_init(recv, format);
+ Opengles1Display_midway_init(self, format);
surface = eglCreateWindowSurface(display, config, mnit_window, NULL);
context = eglCreateContext(display, config, NULL, NULL);
extern class Opengles1Image in "C" `{struct mnit_opengles_Texture *`}
super Image
- redef fun destroy is extern `{ free( recv ); `}
+ redef fun destroy is extern `{ free( self ); `}
- redef fun width: Int is extern `{ return recv->width; `}
- redef fun height: Int is extern `{ return recv->height; `}
+ redef fun width: Int is extern `{ return self->width; `}
+ redef fun height: Int is extern `{ return self->height; `}
- fun center_x: Int `{ return recv->center_x; `}
- fun center_y: Int `{ return recv->center_y; `}
+ fun center_x: Int `{ return self->center_x; `}
+ fun center_y: Int `{ return self->center_y; `}
redef fun scale=( v: Float ) is extern `{
- recv->scale = v;
- recv->center_x = v*recv->width/2;
- recv->center_y = v*recv->height/2;
+ self->scale = v;
+ self->center_x = v*self->width/2;
+ self->center_y = v*self->height/2;
`}
- redef fun scale: Float is extern `{ return recv->scale; `}
+ redef fun scale: Float is extern `{ return self->scale; `}
- redef fun blended=( v: Bool ) is extern `{ recv->blended = v; `}
- redef fun blended: Bool is extern `{ return recv->blended; `}
+ redef fun blended=( v: Bool ) is extern `{ self->blended = v; `}
+ redef fun blended: Bool is extern `{ return self->blended; `}
# inherits scale and blend from source
redef fun subimage( x, y, w, h: Int ): Image is extern import Opengles1Image.as( Image ) `{
struct mnit_opengles_Texture* image =
malloc( sizeof( struct mnit_opengles_Texture ) );
- image->texture = recv->texture;
+ image->texture = self->texture;
image->width = w;
image->height = h;
- image->center_x = recv->scale*w/2;
- image->center_y = recv->scale*h/2;
- image->scale = recv->scale;
- image->blended = recv->blended;
-
- float r_dx = recv->src_xi - recv->src_xo;
- float r_dy = recv->src_yi - recv->src_yo;
- image->src_xo = recv->src_xo + ((float)x)/recv->width*r_dx;
- image->src_yo = recv->src_yo + ((float)y)/recv->height*r_dy;
- image->src_xi = recv->src_xo + ((float)x+w)/recv->width*r_dx;
- image->src_yi = recv->src_yo + ((float)y+h)/recv->height*r_dy;
+ image->center_x = self->scale*w/2;
+ image->center_y = self->scale*h/2;
+ image->scale = self->scale;
+ image->blended = self->blended;
+
+ float r_dx = self->src_xi - self->src_xo;
+ float r_dy = self->src_yi - self->src_yo;
+ image->src_xo = self->src_xo + ((float)x)/self->width*r_dx;
+ image->src_yo = self->src_yo + ((float)y)/self->height*r_dy;
+ image->src_xi = self->src_xo + ((float)x+w)/self->width*r_dx;
+ image->src_yi = self->src_yo + ((float)y+h)/self->height*r_dy;
return Opengles1Image_as_Image( image );
`}
void mnit_android_png_read_data(png_structp png_ptr,
png_bytep data, png_size_t length)
{
- struct AAsset *recv = png_get_io_ptr(png_ptr);
- int read = AAsset_read(recv, data, length);
+ struct AAsset *self = png_get_io_ptr(png_ptr);
+ int read = AAsset_read(self, data, length);
}
void mnit_android_png_error_fn(png_structp png_ptr,
png_const_charp error_msg)
fun read(count: Int): nullable String is extern import String.as nullable, NativeString.to_s `{
char *buffer = malloc(sizeof(char) * (count+1));
- int read = AAsset_read(recv, buffer, count);
+ int read = AAsset_read(self, buffer, count);
if (read != count)
return null_String();
else
`}
fun length: Int is extern `{
- return AAsset_getLength(recv);
+ return AAsset_getLength(self);
`}
fun to_fd: Int is extern `{
off_t start;
off_t length;
- int fd = AAsset_openFileDescriptor(recv, &start, &length);
+ int fd = AAsset_openFileDescriptor(self, &start, &length);
return fd;
`}
fun close is extern `{
- AAsset_close(recv);
+ AAsset_close(self);
`}
end
end
protected fun load_asset_from_apk(path: String): nullable AndroidAsset is extern import String.to_cstring, AndroidAsset.as nullable, native_app_glue `{
- struct android_app *native_app_glue = App_native_app_glue(recv);
+ struct android_app *native_app_glue = App_native_app_glue(self);
struct AAsset* a = AAssetManager_open(native_app_glue->activity->assetManager, String_to_cstring(path), AASSET_MODE_BUFFER);
if (a == NULL)
{
redef class Opengles1Image
# Read a png from a zipped stream
new from_android_asset(asset: AndroidAsset) import Int.next_pow `{
- struct mnit_opengles_Texture *recv = NULL;
+ struct mnit_opengles_Texture *self = NULL;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
for (i = 0; i < height; i++)
memcpy(pixels + (row_bytes_pow2*i), row_pointers[i], row_bytes);
- recv = mnit_opengles_load_image((const uint_least32_t *)pixels,
+ self = mnit_opengles_load_image((const uint_least32_t *)pixels,
width, height, width_pow2, height_pow2, has_alpha);
// Calculate the size of the client-side memory allocated and freed
}
close_stream:
- return recv;
+ return self;
`}
end
redef class Opengles1Display
redef fun midway_init(format) import app_native_window `{
- mnit_window = Opengles1Display_app_native_window(recv);
+ mnit_window = Opengles1Display_app_native_window(self);
if (ANativeWindow_setBuffersGeometry(mnit_window, 0, 0, (EGLint)format) != 0) {
LOGW("Unable to ANativeWindow_setBuffersGeometry");
}
bson_t *bson;
bson = bson_new_from_json(data, -1, &error);
if(!bson) {
- NativeBSON_set_mongoc_error(recv, &error);
+ NativeBSON_set_mongoc_error(bson, &error);
return NULL;
}
return bson;
# The `bson_as_json()` function shall encode bson as a JSON encoded UTF-8 string.
# The caller is responsible for freeing the resulting UTF-8 encoded string
# by calling `bson_free()` with the result.
- fun to_native_string: NativeString `{ return bson_as_json(recv, NULL); `}
+ fun to_native_string: NativeString `{ return bson_as_json(self, NULL); `}
# Wrapper for `bson_destroy()`.
#
# unless otherwise specified.
#
# This instance should not be used beyond this point!
- fun destroy `{ bson_destroy(recv); `}
+ fun destroy `{ bson_destroy(self); `}
# Utility method to set `Sys.last_mongoc_error`.
fun set_mongoc_error(err: BSONError) do sys.last_mongoc_error = err
#
# The `error.domain` field contains the logical domain within a library that
# created the error.
- fun domain: Int `{ return recv->domain; `}
+ fun domain: Int `{ return self->domain; `}
# Wrapper for `error.code`.
#
# The `error.code` field contains the domain specific error code.
- fun code: Int `{ return recv->code; `}
+ fun code: Int `{ return self->code; `}
# Wrapper for `error.message`.
#
# The `error.message` field contains a human printable error message.
- fun message: NativeString `{ return recv->message; `}
+ fun message: NativeString `{ return self->message; `}
end
redef class Sys
# Frees `self`.
#
# This instance should not be used beyond this point!
- fun destroy `{ free(recv); `}
+ fun destroy `{ free(self); `}
end
# Wrapper for `mongoc_client_t`.
fun server_status: nullable NativeBSON import set_mongoc_error, NativeBSON.as nullable `{
bson_error_t error;
bson_t *reply = bson_new();
- if(!mongoc_client_get_server_status(recv, NULL, reply, &error)){
- NativeMongoClient_set_mongoc_error(recv, &error);
+ if(!mongoc_client_get_server_status(self, NULL, reply, &error)){
+ NativeMongoClient_set_mongoc_error(self, &error);
return null_NativeBSON();
}
return NativeBSON_as_nullable(reply);
import set_mongoc_error, NativeCStringArray, NativeCStringArray.as nullable `{
bson_error_t error;
char **strv;
- if(strv = mongoc_client_get_database_names(recv, &error)) {
+ if(strv = mongoc_client_get_database_names(self, &error)) {
return NativeCStringArray_as_nullable(strv);
}
- NativeMongoClient_set_mongoc_error(recv, &error);
+ NativeMongoClient_set_mongoc_error(self, &error);
return null_NativeCStringArray();
`}
#
# This instance should not be used beyond this point!
fun destroy `{
- mongoc_client_destroy(recv);
+ mongoc_client_destroy(self);
mongoc_cleanup();
`}
import set_mongoc_error, NativeCStringArray, NativeCStringArray.as nullable `{
bson_error_t error;
char **strv;
- if(strv = mongoc_database_get_collection_names(recv, &error)) {
+ if(strv = mongoc_database_get_collection_names(self, &error)) {
return NativeCStringArray_as_nullable(strv);
}
- NativeMongoDb_set_mongoc_error(recv, &error);
+ NativeMongoDb_set_mongoc_error(self, &error);
return null_NativeCStringArray();
`}
# Allocates a new `mongoc_collection_t` structure for the collection named
# `name` in database.
fun collection(name: NativeString): NativeMongoCollection `{
- return mongoc_database_get_collection(recv, name);
+ return mongoc_database_get_collection(self, name);
`}
# Wrapper for `mongoc_database_has_collection()`.
# within database.
fun has_collection(name: NativeString): Bool import set_mongoc_error `{
bson_error_t error;
- if(!mongoc_database_has_collection(recv, name, &error)) {
- NativeMongoDb_set_mongoc_error(recv, &error);
+ if(!mongoc_database_has_collection(self, name, &error)) {
+ NativeMongoDb_set_mongoc_error(self, &error);
return false;
}
return true;
# This function attempts to drop a database on the MongoDB server.
fun drop: Bool import set_mongoc_error `{
bson_error_t error;
- if(!mongoc_database_drop(recv, &error)) {
- NativeMongoDb_set_mongoc_error(recv, &error);
+ if(!mongoc_database_drop(self, &error)) {
+ NativeMongoDb_set_mongoc_error(self, &error);
return false;
}
return true;
# Wrapper for `mongoc_database_destroy()`.
#
# This instance should not be used beyond this point!
- fun destroy `{ mongoc_database_destroy(recv); `}
+ fun destroy `{ mongoc_database_destroy(self); `}
# Utility method to set `Sys.last_mongoc_error`.
fun set_mongoc_error(err: BSONError) do sys.last_mongoc_error = err
# You can retrieve a generated `_id` from `mongoc_collection_get_last_error()`.
fun insert(doc: NativeBSON): Bool import set_mongoc_error `{
bson_error_t error;
- if(!mongoc_collection_insert(recv, MONGOC_INSERT_NONE, doc, NULL, &error)) {
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ if(!mongoc_collection_insert(self, MONGOC_INSERT_NONE, doc, NULL, &error)) {
+ NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
# Otherwise it will be inserted.
fun save(document: NativeBSON): Bool import set_mongoc_error `{
bson_error_t error;
- if(!mongoc_collection_save(recv, document, NULL, &error)) {
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ if(!mongoc_collection_save(self, document, NULL, &error)) {
+ NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
# The bson selector is not validated, simply passed along as appropriate to the server.
fun remove(selector: NativeBSON): Bool import set_mongoc_error `{
bson_error_t error;
- if(!mongoc_collection_remove(recv, MONGOC_REMOVE_SINGLE_REMOVE, selector, NULL, &error)) {
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ if(!mongoc_collection_remove(self, MONGOC_REMOVE_SINGLE_REMOVE, selector, NULL, &error)) {
+ NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
# This function shall remove documents in the collection that match `selector`.
fun remove_all(selector: NativeBSON): Bool import set_mongoc_error `{
bson_error_t error;
- if(!mongoc_collection_remove(recv, MONGOC_REMOVE_NONE, selector, NULL, &error)) {
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ if(!mongoc_collection_remove(self, MONGOC_REMOVE_NONE, selector, NULL, &error)) {
+ NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
# matches `selector`.
fun update(selector, update: NativeBSON): Bool import set_mongoc_error `{
bson_error_t error;
- if(!mongoc_collection_update(recv, MONGOC_UPDATE_NONE, selector, update, NULL, &error)) {
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ if(!mongoc_collection_update(self, MONGOC_UPDATE_NONE, selector, update, NULL, &error)) {
+ NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
# This function shall update documents in the collection that match `selector`.
fun update_all(selector, update: NativeBSON): Bool import set_mongoc_error `{
bson_error_t error;
- if(!mongoc_collection_update(recv, MONGOC_UPDATE_MULTI_UPDATE, selector, update, NULL, &error)) {
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ if(!mongoc_collection_update(self, MONGOC_UPDATE_MULTI_UPDATE, selector, update, NULL, &error)) {
+ NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
# This function shall execute a count `query` on the underlying collection.
fun count(query: NativeBSON): Int import set_mongoc_error `{
bson_error_t error;
- int64_t count = mongoc_collection_count(recv, MONGOC_QUERY_NONE, query, 0, 0, NULL, &error);
+ int64_t count = mongoc_collection_count(self, MONGOC_QUERY_NONE, query, 0, 0, NULL, &error);
if(count < 0) {
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ NativeMongoCollection_set_mongoc_error(self, &error);
return -1;
}
return count;
NativeMongoCursor.as nullable, set_mongoc_error `{
bson_error_t error;
mongoc_cursor_t *cursor;
- cursor = mongoc_collection_find(recv, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
+ cursor = mongoc_collection_find(self, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
if (mongoc_cursor_error(cursor, &error)) {
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ NativeMongoCollection_set_mongoc_error(self, &error);
return null_NativeMongoCursor();
}
fun stats: nullable NativeBSON import set_mongoc_error, NativeBSON.as nullable `{
bson_error_t error;
bson_t *reply = bson_new();
- if(!mongoc_collection_stats(recv, NULL, reply, &error)){
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ if(!mongoc_collection_stats(self, NULL, reply, &error)){
+ NativeMongoCollection_set_mongoc_error(self, &error);
return null_NativeBSON();
}
return NativeBSON_as_nullable(reply);
# including all indexes associated with the collection.
fun drop: Bool import set_mongoc_error `{
bson_error_t error;
- if(!mongoc_collection_drop(recv, &error)) {
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ if(!mongoc_collection_drop(self, &error)) {
+ NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
# Additional operations will occur on renamed collection.
fun rename(new_database, new_name: NativeString): Bool `{
bson_error_t error;
- if(!mongoc_collection_rename(recv, new_database, new_name, false, &error)){
- NativeMongoCollection_set_mongoc_error(recv, &error);
+ if(!mongoc_collection_rename(self, new_database, new_name, false, &error)){
+ NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
# Wrapper for `mongoc_collection_destroy()`.
#
# This instance should not be used beyond this point!
- fun destroy `{ mongoc_collection_destroy(recv); `}
+ fun destroy `{ mongoc_collection_destroy(self); `}
# Utility method to set `Sys.last_mongoc_error`.
fun set_mongoc_error(err: BSONError) do sys.last_mongoc_error = err
# Wrapper for `mongoc_cursor_current()`.
#
# Fetches the cursors current document or NULL if there has been an error.
- fun current: NativeBSON `{ return (bson_t*) mongoc_cursor_current(recv); `}
+ fun current: NativeBSON `{ return (bson_t*) mongoc_cursor_current(self); `}
# Wrapper for `mongoc_cursor_next()`.
#
# This function is a blocking function.
fun next: Bool `{
const bson_t *doc;
- return mongoc_cursor_next(recv, &doc);
+ return mongoc_cursor_next(self, &doc);
`}
# Wrapper for `mongoc_cursor_more()`.
#
# This function shall indicate if there is more data to be read from the cursor.
- fun more: Bool `{ return mongoc_cursor_more(recv); `}
+ fun more: Bool `{ return mongoc_cursor_more(self); `}
# Wrapper for `mongoc_cursor_destroy()`.
#
# This instance should not be used beyond this point!
- fun destroy `{ mongoc_cursor_destroy(recv); `}
+ fun destroy `{ mongoc_cursor_destroy(self); `}
end
# Number of processors in this communicator
fun size: Int `{
int size;
- MPI_Comm_size(recv, &size);
+ MPI_Comm_size(self, &size);
return size;
`}
# Rank on this processor in this communicator
fun rank: Rank `{
int rank;
- MPI_Comm_rank(recv, &rank);
+ MPI_Comm_rank(self, &rank);
return rank;
`}
end
new `{ return malloc(sizeof(MPI_Status)); `}
# Source of this communication
- fun source: Rank `{ return recv->MPI_SOURCE; `}
+ fun source: Rank `{ return self->MPI_SOURCE; `}
# Tag of this communication
- fun tag: Tag `{ return recv->MPI_TAG; `}
+ fun tag: Tag `{ return self->MPI_TAG; `}
# Success or error on this communication
- fun error: SuccessOrError `{ return recv->MPI_ERROR; `}
+ fun error: SuccessOrError `{ return self->MPI_ERROR; `}
# Count of the given `data_type` in this communication
fun count(data_type: DataType): Int
`{
int count;
- MPI_Get_count(recv, data_type, &count);
+ MPI_Get_count(self, data_type, &count);
return count;
`}
end
# An MPI return code to report success or errors
extern class SuccessOrError `{ int `}
# Is this a success?
- fun is_success: Bool `{ return recv == MPI_SUCCESS; `}
+ fun is_success: Bool `{ return self == MPI_SUCCESS; `}
# Is this an error?
fun is_error: Bool do return not is_success
fun error_class: ErrorClass
`{
int class;
- MPI_Error_class(recv, &class);
+ MPI_Error_class(self, &class);
return class;
`}
redef fun to_s do return native_to_s.to_s
private fun native_to_s: NativeString `{
char *err = malloc(MPI_MAX_ERROR_STRING);
- MPI_Error_string(recv, err, NULL);
+ MPI_Error_string(self, err, NULL);
return err;
`}
end
redef fun to_s do return native_to_s.to_s
private fun native_to_s: NativeString `{
char *err = malloc(MPI_MAX_ERROR_STRING);
- MPI_Error_string(recv, err, NULL);
+ MPI_Error_string(self, err, NULL);
return err;
`}
end
new any `{ return MPI_ANY_SOURCE; `}
# This Rank as an `Int`
- fun to_i: Int `{ return recv; `}
+ fun to_i: Int `{ return self; `}
redef fun to_s do return to_i.to_s
end
new any `{ return MPI_ANY_TAG; `}
# This tag as an `Int`
- fun to_i: Int `{ return recv; `}
+ fun to_i: Int `{ return self; `}
redef fun to_s do return to_i.to_s
end
redef universal Int
# `self`th MPI rank
- fun rank: Rank `{ return recv; `}
+ fun rank: Rank `{ return self; `}
# Tag identified by `self`
- fun tag: Tag `{ return recv; `}
+ fun tag: Tag `{ return self; `}
# Is this value undefined according to MPI? (may be returned by `Status::count`)
- fun is_undefined: Bool `{ return recv == MPI_UNDEFINED; `}
+ fun is_undefined: Bool `{ return self == MPI_UNDEFINED; `}
end
# Something sendable directly and efficiently over MPI
extern class PepperDictionary `{ struct PP_Var* `}
new `{
- struct PP_Var* recv = malloc( sizeof( struct PP_Var ) );
- *recv = g_varDictionaryInterface->Create();
- return recv;
+ struct PP_Var* self = malloc( sizeof( struct PP_Var ) );
+ *self = g_varDictionaryInterface->Create();
+ return self;
`}
# Get fonction using PepperVars.
# If 'key' is not a String typed PepperVar, or doesn't exist in the Dictionary, an undefined PepperVar is returned.
fun native_get(key: PepperVar): PepperVar `{
struct PP_Var* value = malloc( sizeof ( struct PP_Var ) );
- *value = g_varDictionaryInterface->Get(*recv, *key);
+ *value = g_varDictionaryInterface->Get(*self, *key);
return value;
`}
# Returns a Boolean indicating whether the operation succeeds.
fun native_set(key: PepperVar, value: PepperVar): Bool `{
PP_Bool b;
- b = g_varDictionaryInterface->Set(*recv, *key, *value);
+ b = g_varDictionaryInterface->Set(*self, *key, *value);
return b;
`}
#
# Takes a String typed PepperVar.
fun native_delete(key: PepperVar) `{
- g_varDictionaryInterface->Delete(*recv, *key);
+ g_varDictionaryInterface->Delete(*self, *key);
`}
# Deletes the specified key and its associated value, if the key exists.
# Takes a String typed PepperVar.
fun native_has_key(key: PepperVar): Bool `{
PP_Bool b;
- b = g_varDictionaryInterface->HasKey(*recv, *key);
+ b = g_varDictionaryInterface->HasKey(*self, *key);
return b;
`}
# Returns a PepperArray which contains all the keys of the Dictionary. The elements are string vars.
fun get_keys: PepperArray `{
struct PP_Var* array = malloc( sizeof( struct PP_Var ) );
- *array = g_varDictionaryInterface->GetKeys(*recv);
+ *array = g_varDictionaryInterface->GetKeys(*self);
return array;
`}
fun copy: PepperDictionary `{
struct PP_Var* varDictionary = malloc( sizeof( struct PP_Var ) );
*varDictionary = g_varDictionaryInterface->Create();
- *varDictionary = *recv;
+ *varDictionary = *self;
return varDictionary;
`}
end
extern class PepperArray `{ struct PP_Var* `}
new `{
- struct PP_Var* recv = malloc( sizeof( struct PP_Var ) );
- *recv = g_varArrayInterface->Create();
- return recv;
+ struct PP_Var* self = malloc( sizeof( struct PP_Var ) );
+ *self = g_varArrayInterface->Create();
+ return self;
`}
# Returns the element at the specified position as a PepperVar.
# If 'index' is larger than or equal to the array length, an undefined PepperVar is returned.
fun native_get(index: Int): PepperVar `{
struct PP_Var* value = malloc( sizeof( struct PP_Var ) );
- *value = g_varArrayInterface->Get(*recv, index);
+ *value = g_varArrayInterface->Get(*self, index);
return value;
`}
# Returns an int containing the length of the PepperArray.
fun length: Int `{
- int length = g_varArrayInterface->GetLength(*recv);
+ int length = g_varArrayInterface->GetLength(*self);
return length;
`}
# Returns a Boolean indicating whether the operation succeeds.
fun native_set(index: Int, value: PepperVar): Bool `{
PP_Bool b;
- b = g_varArrayInterface->Set(*recv, index, *value);
+ b = g_varArrayInterface->Set(*self, index, *value);
return b;
`}
# Returns a Boolean indicating whether the operation succeeds.
fun length=(length: Int): Bool `{
PP_Bool b;
- b = g_varArrayInterface->SetLength(*recv, length);
+ b = g_varArrayInterface->SetLength(*self, length);
return b;
`}
end
return null
end
- private fun isa_null: Bool `{ return recv->type == PP_VARTYPE_NULL; `}
- private fun isa_bool: Bool `{ return recv->type == PP_VARTYPE_BOOL; `}
- private fun isa_int: Bool `{ return recv->type == PP_VARTYPE_INT32; `}
- private fun isa_float: Bool `{ return recv->type == PP_VARTYPE_DOUBLE; `}
- private fun isa_string: Bool `{ return recv->type == PP_VARTYPE_STRING; `}
- private fun is_undefined: Bool `{ return recv->type == PP_VARTYPE_UNDEFINED; `}
+ private fun isa_null: Bool `{ return self->type == PP_VARTYPE_NULL; `}
+ private fun isa_bool: Bool `{ return self->type == PP_VARTYPE_BOOL; `}
+ private fun isa_int: Bool `{ return self->type == PP_VARTYPE_INT32; `}
+ private fun isa_float: Bool `{ return self->type == PP_VARTYPE_DOUBLE; `}
+ private fun isa_string: Bool `{ return self->type == PP_VARTYPE_STRING; `}
+ private fun is_undefined: Bool `{ return self->type == PP_VARTYPE_UNDEFINED; `}
- private fun as_bool: Bool `{ return recv->value.as_bool; `}
- private fun as_int: Int `{ return recv->value.as_int; `}
- private fun as_float: Float `{ return recv->value.as_double; `}
+ private fun as_bool: Bool `{ return self->value.as_bool; `}
+ private fun as_int: Int `{ return self->value.as_int; `}
+ private fun as_float: Float `{ return self->value.as_double; `}
private fun as_string: String import NativeString.to_s_with_length `{
uint32_t len;
- char* str = (char*)g_varInterface->VarToUtf8(*recv, &len);
+ char* str = (char*)g_varInterface->VarToUtf8(*self, &len);
return NativeString_to_s_with_length(str, len);
`}
end
# Converts a Int into a PepperVar with Int type.
redef fun to_pepper `{
struct PP_Var* var = malloc( sizeof( struct PP_Var ) );
- *var = PP_MakeInt32(recv);
+ *var = PP_MakeInt32(self);
return var;
`}
end
# Converts a Float into a PepperVar with Float type.
redef fun to_pepper `{
struct PP_Var* var = malloc( sizeof( struct PP_Var ) );
- *var = PP_MakeDouble(recv);
+ *var = PP_MakeDouble(self);
return var;
`}
end
# Converts a Bool into a PepperVar with Bool type.
redef fun to_pepper `{
struct PP_Var* var = malloc( sizeof( struct PP_Var ) );
- *var = PP_MakeBool(recv);
+ *var = PP_MakeBool(self);
return var;
`}
end
# Converts a String into a PepperVar with String type.
redef fun to_pepper: PepperVar import String.to_cstring, String.length `{
- char *str = String_to_cstring(recv);
+ char *str = String_to_cstring(self);
struct PP_Var* var = malloc( sizeof( struct PP_Var ) );
- *var = g_varInterface->VarFromUtf8(str, String_length(recv));
+ *var = g_varInterface->VarFromUtf8(str, String_length(self));
return var;
`}
end
# Sets everything up to work, need to be called at first.
fun initialize import PnaclApp.handle_message, PnaclApp.handle_dictionary, NativeString.to_s_with_length `{
- app = recv;
+ app = self;
`}
# Posts a message to JS.
redef extern class Passwd
# User information
- fun gecos: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_gecos); `}
+ fun gecos: String import NativeString.to_s `{ return NativeString_to_s(self->pw_gecos); `}
end
redef extern class NativePthread
fun cancel: Bool `{
- return pthread_cancel(*recv);
+ return pthread_cancel(*self);
`}
end
return barrier;
`}
- fun destroy `{ pthread_barrier_destroy(recv); `}
+ fun destroy `{ pthread_barrier_destroy(self); `}
- fun wait `{ pthread_barrier_wait(recv); `}
+ fun wait `{ pthread_barrier_wait(self); `}
end
fun join: nullable Object `{
void *thread_return;
- pthread_join(*recv, &thread_return);
+ pthread_join(*self, &thread_return);
if(thread_return == NULL) thread_return = null_Object();
return (nullable_Object)thread_return;
`}
- fun equal(other: NativePthread): Bool `{ return pthread_equal(*recv, *other); `}
+ fun equal(other: NativePthread): Bool `{ return pthread_equal(*self, *other); `}
- fun kill(signal: Int) `{ pthread_kill(*recv, signal); `}
+ fun kill(signal: Int) `{ pthread_kill(*self, signal); `}
end
private extern class NativePthreadAttr in "C" `{ pthread_attr_t * `}
`}
fun destroy `{
- pthread_attr_destroy(recv);
+ pthread_attr_destroy(self);
`}
# Most features of this class are still TODO
return mutex;
`}
- fun destroy `{ pthread_mutex_destroy(recv); `}
+ fun destroy `{ pthread_mutex_destroy(self); `}
- fun lock `{ pthread_mutex_lock(recv); `}
- fun try_lock: Bool `{ return pthread_mutex_trylock(recv); `}
- fun unlock `{ pthread_mutex_unlock(recv); `}
+ fun lock `{ pthread_mutex_lock(self); `}
+ fun try_lock: Bool `{ return pthread_mutex_trylock(self); `}
+ fun unlock `{ pthread_mutex_unlock(self); `}
end
private extern class NativePthreadMutexAttr in "C" `{ pthread_mutexattr_t * `}
return attr;
`}
- fun destroy `{ pthread_mutexattr_destroy(recv); `}
+ fun destroy `{ pthread_mutexattr_destroy(self); `}
- fun set_type_normal `{ pthread_mutexattr_settype(recv, PTHREAD_MUTEX_NORMAL); `}
- fun set_type_recursive `{ pthread_mutexattr_settype(recv, PTHREAD_MUTEX_RECURSIVE); `}
- fun set_type_errorcheck `{ pthread_mutexattr_settype(recv, PTHREAD_MUTEX_ERRORCHECK); `}
+ fun set_type_normal `{ pthread_mutexattr_settype(self, PTHREAD_MUTEX_NORMAL); `}
+ fun set_type_recursive `{ pthread_mutexattr_settype(self, PTHREAD_MUTEX_RECURSIVE); `}
+ fun set_type_errorcheck `{ pthread_mutexattr_settype(self, PTHREAD_MUTEX_ERRORCHECK); `}
# pthread_mutexattr_setpshared
# pthread_mutexattr_setprotocol
`}
fun get: nullable Object `{
- void *val = pthread_getspecific(*recv);
+ void *val = pthread_getspecific(*self);
if (val == NULL) val = null_Object();
return val;
`}
fun set(val: nullable Object) `{
- pthread_setspecific(*recv, val);
+ pthread_setspecific(*self, val);
`}
end
return NULL;
`}
- fun destroy `{ pthread_cond_destroy(recv); `}
+ fun destroy `{ pthread_cond_destroy(self); `}
- fun signal `{ pthread_cond_signal(recv); `}
+ fun signal `{ pthread_cond_signal(self); `}
- fun broadcast `{ pthread_cond_broadcast(recv); `}
+ fun broadcast `{ pthread_cond_broadcast(self); `}
- fun wait(mutex: NativePthreadMutex) `{ pthread_cond_wait(recv, mutex); `}
+ fun wait(mutex: NativePthreadMutex) `{ pthread_cond_wait(self, mutex); `}
end
#
# Update `self` clock.
fun update `{
- clock_gettime( CLOCK_MONOTONIC, recv );
+ clock_gettime(CLOCK_MONOTONIC, self);
`}
# Substract a Timespec from `self`.
# Number of whole seconds of elapsed time.
fun sec : Int `{
- return recv->tv_sec;
+ return self->tv_sec;
`}
# Rest of the elapsed time (a fraction of a second).
#
# Number of nanoseconds.
fun nanosec : Int `{
- return recv->tv_nsec;
+ return self->tv_nsec;
`}
# Seconds in Float
TTF_Quit();
`}
- redef fun finish `{ SDL_Flip(recv); `}
+ redef fun finish `{ SDL_Flip(self); `}
# Clear the entire window with given RGB color (integer values)
fun clear_int(r, g, b: Int) `{
- SDL_FillRect(recv, NULL, SDL_MapRGB(recv->format,r,g,b));
+ SDL_FillRect(self, NULL, SDL_MapRGB(self->format,r,g,b));
`}
- redef fun width: Int `{ return recv->w; `}
- redef fun height: Int `{ return recv->h; `}
+ redef fun width: Int `{ return self->w; `}
+ redef fun height: Int `{ return self->h; `}
# Fill a rectangle with given color
fun fill_rect(rect: SDLRectangle, r, g, b: Int) `{
- SDL_FillRect(recv, rect, SDL_MapRGB(recv->format,r,g,b));
+ SDL_FillRect(self, rect, SDL_MapRGB(self->format,r,g,b));
`}
redef fun clear(r, g, b: Float) `{
ri = (Uint8)r*255;
gi = (Uint8)g*255;
bi = (Uint8)b*255;
- SDL_FillRect(recv, NULL, SDL_MapRGB(recv->format,ri,gi,bi));
+ SDL_FillRect(self, NULL, SDL_MapRGB(self->format,ri,gi,bi));
`}
# SDL events since the last call to this method
dst.w = 0;
dst.h = 0;
- SDL_BlitSurface(img, NULL, recv, &dst);
+ SDL_BlitSurface(img, NULL, self, &dst);
`}
redef fun blit_centered(img, x, y)
fun save_to_file(path: String) import String.to_cstring `{ `}
# Destroy the image and free the memory
- redef fun destroy `{ SDL_FreeSurface(recv); `}
+ redef fun destroy `{ SDL_FreeSurface(self); `}
- redef fun width: Int `{ return recv->w; `}
- redef fun height: Int `{ return recv->h; `}
+ redef fun width: Int `{ return self->w; `}
+ redef fun height: Int `{ return self->h; `}
fun is_ok: Bool do return not address_is_null
# Returns a reference to the pixels of the texture
- fun pixels: NativeCByteArray `{ return recv->pixels; `}
+ fun pixels: NativeCByteArray `{ return self->pixels; `}
# Does this texture has an alpha mask?
- fun amask: Bool `{ return recv->format->Amask; `}
+ fun amask: Bool `{ return self->format->Amask; `}
end
# A simple rectangle
return rect;
`}
- fun x=(v: Int) `{ recv->x = (Sint16)v; `}
- fun x: Int `{ return recv->x; `}
+ fun x=(v: Int) `{ self->x = (Sint16)v; `}
+ fun x: Int `{ return self->x; `}
- fun y=(v: Int) `{ recv->y = (Sint16)v; `}
- fun y: Int `{ return recv->y; `}
+ fun y=(v: Int) `{ self->y = (Sint16)v; `}
+ fun y: Int `{ return self->y; `}
- fun w=(v: Int) `{ recv->w = (Uint16)v; `}
- fun w: Int `{ return recv->w; `}
+ fun w=(v: Int) `{ self->w = (Uint16)v; `}
+ fun w: Int `{ return self->w; `}
- fun h=(v: Int) `{ recv->h = (Uint16)v; `}
- fun h: Int `{ return recv->h; `}
+ fun h=(v: Int) `{ self->h = (Uint16)v; `}
+ fun h: Int `{ return self->h; `}
end
interface SDLInputEvent
end
redef class Int
- fun delay `{ SDL_Delay(recv); `}
+ fun delay `{ SDL_Delay(self); `}
end
# Class to load and use TTF_Font
return font;
`}
- fun destroy `{ TTF_CloseFont(recv); `}
+ fun destroy `{ TTF_CloseFont(self); `}
# Create a String with the specified color, return an SDLImage
fun render(text: String, r, g, b: Int): SDLImage import String.to_cstring `{
color.b = b;
ctext = String_to_cstring(text);
- if(!(text_surface=TTF_RenderText_Blended(recv, ctext, color)))
+ if(!(text_surface=TTF_RenderText_Blended(self, ctext, color)))
{
fprintf(stderr, "SDL TFF error: %s\n", TTF_GetError());
exit(1);
# Maximum pixel height of all glyphs of this font.
fun height: Int `{
- return TTF_FontHeight(recv);
+ return TTF_FontHeight(self);
`}
fun ascent: Int `{
- return TTF_FontAscent(recv);
+ return TTF_FontAscent(self);
`}
fun descent: Int `{
- return TTF_FontDescent(recv);
+ return TTF_FontDescent(self);
`}
# Get the recommended pixel height of a rendered line of text of the loaded font. This is usually larger than the Font.height.
fun line_skip: Int `{
- return TTF_FontLineSkip(recv);
+ return TTF_FontLineSkip(self);
`}
# Return true is the font used fixed width for each char
fun is_fixed_width: Bool `{
- return TTF_FontFaceIsFixedWidth(recv);
+ return TTF_FontFaceIsFixedWidth(self);
`}
# Return the family name of the font
fun family_name: nullable String import String.to_cstring, String.as nullable `{
- char *fn = TTF_FontFaceFamilyName(recv);
+ char *fn = TTF_FontFaceFamilyName(self);
if (fn == NULL)
return null_String();
# Return the style name of the font
fun style_name: nullable String import String.to_cstring, String.as nullable `{
- char *sn = TTF_FontFaceStyleName(recv);
+ char *sn = TTF_FontFaceStyleName(self);
if (sn == NULL)
return null_String();
fun width_of(text: String): Int import NativeString.to_s `{
char *ctext = String_to_cstring(text);
int w;
- if (TTF_SizeText(recv, ctext, &w, NULL))
+ if (TTF_SizeText(self, ctext, &w, NULL))
{
fprintf(stderr, "SDL TFF error: %s\n", TTF_GetError());
exit(1);
# Returns the handle of this window on a X11 window system
fun x11_window_handle: Pointer `{
- return (void*)recv->info.x11.window;
+ return (void*)self->info.x11.window;
`}
end
# Poll and event into `self`
#
# Returns `true` if an event was available.
- fun poll_event: Bool `{ return SDL_PollEvent(recv); `}
+ fun poll_event: Bool `{ return SDL_PollEvent(self); `}
# Get a reference to the data at `self` as a precise `SDLEvent`
#
end
# Is this a quit event?
- fun is_quit: Bool `{ return recv->type == SDL_QUIT; `}
+ fun is_quit: Bool `{ return self->type == SDL_QUIT; `}
# Get a reference to data at `self` as a `SDLQuitEvent`
- fun to_quit: SDLQuitEvent `{ return recv; `}
+ fun to_quit: SDLQuitEvent `{ return self; `}
# Is this a mouse motion event?
- fun is_mouse_motion: Bool `{ return recv->type == SDL_MOUSEMOTION; `}
+ fun is_mouse_motion: Bool `{ return self->type == SDL_MOUSEMOTION; `}
# Get a reference to data at `self` as a `SDLMouseMotionEvent`
- fun to_mouse_motion: SDLMouseMotionEvent `{ return recv; `}
+ fun to_mouse_motion: SDLMouseMotionEvent `{ return self; `}
# Is this a mouse button down event?
- fun is_mouse_button_down: Bool `{ return recv->type == SDL_MOUSEBUTTONDOWN; `}
+ fun is_mouse_button_down: Bool `{ return self->type == SDL_MOUSEBUTTONDOWN; `}
# Get a reference to data at `self` as a `SDLMouseButtonDownEvent`
- fun to_mouse_button_down: SDLMouseButtonDownEvent `{ return recv; `}
+ fun to_mouse_button_down: SDLMouseButtonDownEvent `{ return self; `}
# Is this a mouse button up event?
- fun is_mouse_button_up: Bool `{ return recv->type == SDL_MOUSEBUTTONUP; `}
+ fun is_mouse_button_up: Bool `{ return self->type == SDL_MOUSEBUTTONUP; `}
# Get a reference to data at `self` as a `SDLMouseButtonUpEvent`
- fun to_mouse_button_up: SDLMouseButtonUpEvent `{ return recv; `}
+ fun to_mouse_button_up: SDLMouseButtonUpEvent `{ return self; `}
# TODO other SDL events:
#
# four fields of each events are common to all of them.
# Which mouse, pointer or finger raised this event
- fun which: Int `{ return recv->motion.which; `}
+ fun which: Int `{ return self->motion.which; `}
end
# A mouse motion event
super SDLMouseEvent
# X coordinate on screen of this event
- fun x: Int `{ return recv->motion.x; `}
+ fun x: Int `{ return self->motion.x; `}
# Y coordinate on screen of this event
- fun y: Int `{ return recv->motion.y; `}
+ fun y: Int `{ return self->motion.y; `}
# Difference on the X axis between this event and the previous one
- fun xrel: Int `{ return recv->motion.xrel; `}
+ fun xrel: Int `{ return self->motion.xrel; `}
# Difference on the Y axis between this event and the previous one
- fun yrel: Int `{ return recv->motion.yrel; `}
+ fun yrel: Int `{ return self->motion.yrel; `}
end
# A mouse button event
super SDLMouseEvent
# X coordinate on screen of this event
- fun x: Int `{ return recv->button.x; `}
+ fun x: Int `{ return self->button.x; `}
# Y coordinate on screen of this event
- fun y: Int `{ return recv->button.y; `}
+ fun y: Int `{ return self->button.y; `}
end
# A mouse button release event
new `{ return 0; `}
# Add the JPG support to this flag set
- fun jpg: SDLImgInitFlags `{ return recv | IMG_INIT_JPG; `}
+ fun jpg: SDLImgInitFlags `{ return self | IMG_INIT_JPG; `}
# Add the PNG support to this flag set
- fun png: SDLImgInitFlags `{ return recv | IMG_INIT_PNG; `}
+ fun png: SDLImgInitFlags `{ return self | IMG_INIT_PNG; `}
# Add the TIF support to this flag set
- fun tif: SDLImgInitFlags `{ return recv | IMG_INIT_TIF; `}
+ fun tif: SDLImgInitFlags `{ return self | IMG_INIT_TIF; `}
# Add the WEBP support to this flag set
- fun webp: SDLImgInitFlags `{ return recv | IMG_INIT_WEBP; `}
+ fun webp: SDLImgInitFlags `{ return self | IMG_INIT_WEBP; `}
end
new `{ return 0; `}
# Add the timer subsystem
- fun timer: SDLInitFlags `{ return recv | SDL_INIT_TIMER; `}
+ fun timer: SDLInitFlags `{ return self | SDL_INIT_TIMER; `}
# Add the audio subsystem
- fun audio: SDLInitFlags `{ return recv | SDL_INIT_AUDIO; `}
+ fun audio: SDLInitFlags `{ return self | SDL_INIT_AUDIO; `}
# Add the video subsystem
- fun video: SDLInitFlags `{ return recv | SDL_INIT_VIDEO; `}
+ fun video: SDLInitFlags `{ return self | SDL_INIT_VIDEO; `}
# Add the joystick subsystem
#
# Implied by `gamecontroller`
- fun joystick: SDLInitFlags `{ return recv | SDL_INIT_JOYSTICK; `}
+ fun joystick: SDLInitFlags `{ return self | SDL_INIT_JOYSTICK; `}
# Add the haptic subsystem
- fun haptic: SDLInitFlags `{ return recv | SDL_INIT_HAPTIC; `}
+ fun haptic: SDLInitFlags `{ return self | SDL_INIT_HAPTIC; `}
# Add the gamecontroller subsystem
- fun gamecontroller: SDLInitFlags `{ return recv | SDL_INIT_GAMECONTROLLER; `}
+ fun gamecontroller: SDLInitFlags `{ return self | SDL_INIT_GAMECONTROLLER; `}
# Add the events subsystem
#
# Implied by `video` and `joystick`
- fun events: SDLInitFlags `{ return recv | SDL_INIT_EVENTS; `}
+ fun events: SDLInitFlags `{ return self | SDL_INIT_EVENTS; `}
# Add all subsystems
- fun everything: SDLInitFlags `{ return recv | SDL_INIT_EVERYTHING; `}
+ fun everything: SDLInitFlags `{ return self | SDL_INIT_EVERYTHING; `}
# Is this flag set empty?
- fun is_empty: Bool `{ return recv == 0; `}
+ fun is_empty: Bool `{ return self == 0; `}
# TODO add all other is_
end
fun initialized: Bool do return not address_is_null
# Destroy this window
- fun destroy `{ SDL_DestroyWindow(recv); `}
+ fun destroy `{ SDL_DestroyWindow(self); `}
# Get the `SDLWindowFlags` describing the status of the window
- fun flags: SDLWindowFlags `{ return SDL_GetWindowFlags(recv); `}
+ fun flags: SDLWindowFlags `{ return SDL_GetWindowFlags(self); `}
# Show a simple message box
#
# Similar to `sys.sdl.show_simple_message_box` but attached to this window
fun show_simple_message_box(level: SDLMessageBoxFlags, title, content: NativeString) `{
- SDL_ShowSimpleMessageBox(level, title, content, recv);
+ SDL_ShowSimpleMessageBox(level, title, content, self);
`}
# Set the icon of this window
- fun icon=(icon: SDLSurface) `{ SDL_SetWindowIcon(recv, icon); `}
+ fun icon=(icon: SDLSurface) `{ SDL_SetWindowIcon(self, icon); `}
end
# Flags for `SDLWindow::new` and returned by `SDLWindow::flags`
new `{ return 0; `}
# Add the flag requesting a fullscreen window
- fun fullscreen: SDLWindowFlags `{ return recv | SDL_WINDOW_FULLSCREEN; `}
+ fun fullscreen: SDLWindowFlags `{ return self | SDL_WINDOW_FULLSCREEN; `}
# Add the flag requesting a fullscreen window for the current desktop
- fun fullscreen_desktop: SDLWindowFlags `{ return recv | SDL_WINDOW_FULLSCREEN_DESKTOP; `}
+ fun fullscreen_desktop: SDLWindowFlags `{ return self | SDL_WINDOW_FULLSCREEN_DESKTOP; `}
# Add the flag requesting a window usable with an OpenGL context
- fun opengl: SDLWindowFlags `{ return recv | SDL_WINDOW_OPENGL; `}
+ fun opengl: SDLWindowFlags `{ return self | SDL_WINDOW_OPENGL; `}
# Add the flag requesting a hidden window
- fun hidden: SDLWindowFlags `{ return recv | SDL_WINDOW_HIDDEN; `}
+ fun hidden: SDLWindowFlags `{ return self | SDL_WINDOW_HIDDEN; `}
# Add the flag requesting a borderless window
- fun borderless: SDLWindowFlags `{ return recv | SDL_WINDOW_BORDERLESS; `}
+ fun borderless: SDLWindowFlags `{ return self | SDL_WINDOW_BORDERLESS; `}
# Add the flag requesting a resizable window
- fun resizable: SDLWindowFlags `{ return recv | SDL_WINDOW_RESIZABLE; `}
+ fun resizable: SDLWindowFlags `{ return self | SDL_WINDOW_RESIZABLE; `}
# Add the flag requesting a minimized window
- fun minimized: SDLWindowFlags `{ return recv | SDL_WINDOW_MINIMIZED; `}
+ fun minimized: SDLWindowFlags `{ return self | SDL_WINDOW_MINIMIZED; `}
# Add the flag requesting a maximimez window
- fun maximized: SDLWindowFlags `{ return recv | SDL_WINDOW_MAXIMIZED; `}
+ fun maximized: SDLWindowFlags `{ return self | SDL_WINDOW_MAXIMIZED; `}
# Add the flag to grab the input focus
- fun input_grabbed: SDLWindowFlags `{ return recv | SDL_WINDOW_INPUT_GRABBED; `}
+ fun input_grabbed: SDLWindowFlags `{ return self | SDL_WINDOW_INPUT_GRABBED; `}
# Add the flag to request a window using the system High-DPI mode
fun allow_highdpi: SDLWindowFlags `{
#if SDL_VERSION_ATLEAST(2, 0, 2)
- return recv | SDL_WINDOW_ALLOW_HIGHDPI;
+ return self | SDL_WINDOW_ALLOW_HIGHDPI;
#else
- return recv;
+ return self;
#endif
`}
# Is the window shown?
#
# Can only be queried because it is ignored by `SDLWindow::new`
- fun is_shown: Bool `{ return recv & SDL_WINDOW_SHOWN; `}
+ fun is_shown: Bool `{ return self & SDL_WINDOW_SHOWN; `}
# Does the window has the input focus?
#
# Can only be queried because it is ignored by `SDLWindow::new`
- fun has_input_focus: Bool `{ return recv & SDL_WINDOW_INPUT_FOCUS; `}
+ fun has_input_focus: Bool `{ return self & SDL_WINDOW_INPUT_FOCUS; `}
# Does the window has the mouse focus?
#
# Can only be queried because it is ignored by `SDLWindow::new`
- fun has_mouse_focus: Bool `{ return recv & SDL_WINDOW_MOUSE_FOCUS; `}
+ fun has_mouse_focus: Bool `{ return self & SDL_WINDOW_MOUSE_FOCUS; `}
# TODO add all other `is_` methods, as needed
end
redef universal Int
- # Suspend execution for `recv` milliseconds
- fun delay `{ SDL_Delay(recv); `}
+ # Suspend execution for `self` milliseconds
+ fun delay `{ SDL_Delay(self); `}
end
# A renderer, maybe software or hardware
`}
# Destroy this renderer
- fun destroy `{ SDL_DestroyRenderer(recv); `}
+ fun destroy `{ SDL_DestroyRenderer(self); `}
# Clear the rendering target with the current `draw_color`
- fun clear `{ SDL_RenderClear(recv); `}
+ fun clear `{ SDL_RenderClear(self); `}
# Copy the rectangle at `src` from `texture` to fill the `dst` at the rendering `target`
#
end
private fun native_copy(texture: SDLTexture, src, dst: SDLRect) `{
- SDL_RenderCopy(recv, texture, src, dst);
+ SDL_RenderCopy(self, texture, src, dst);
`}
# Update the screen with all rendering since the previous call
- fun present `{ SDL_RenderPresent(recv); `}
+ fun present `{ SDL_RenderPresent(self); `}
# Get the `SDLRendererInfo` for this renderer
- fun info_copy(out: SDLRendererInfo) `{ SDL_GetRendererInfo(recv, out); `}
+ fun info_copy(out: SDLRendererInfo) `{ SDL_GetRendererInfo(self, out); `}
# Set the drawing color
fun draw_color=(val: SDLColor) `{
- SDL_SetRenderDrawColor(recv, val->r, val->g, val->b, val->a);
+ SDL_SetRenderDrawColor(self, val->r, val->g, val->b, val->a);
`}
# Get the drawing color of this renderer
# Copy the drawing color of this renderer in `color`
fun draw_color_copy(color: SDLColor) `{
- SDL_GetRenderDrawColor(recv, &color->r, &color->g, &color->b, &color->a);
+ SDL_GetRenderDrawColor(self, &color->r, &color->g, &color->b, &color->a);
`}
# Fill a rectangle with the current `draw_color`
#
# If `rect.address_is_null` then fills the entire screen.
- fun fill_rect(rect: SDLRect) `{ SDL_RenderFillRect(recv, rect); `}
+ fun fill_rect(rect: SDLRect) `{ SDL_RenderFillRect(self, rect); `}
# Draw a rectangle with the current `draw_color`
- fun draw_rect(rect: SDLRect) `{ SDL_RenderDrawRect(recv, rect); `}
+ fun draw_rect(rect: SDLRect) `{ SDL_RenderDrawRect(self, rect); `}
# Draw a point with the current `draw_color`
- fun draw_point(x, y: Int) `{ SDL_RenderDrawPoint(recv, x, y); `}
+ fun draw_point(x, y: Int) `{ SDL_RenderDrawPoint(self, x, y); `}
# Draw a line with the current `draw_color`
- fun draw_line(x1, y1, x2, y2: Int) `{ SDL_RenderDrawLine(recv, x1, y1, x2, y2); `}
+ fun draw_line(x1, y1, x2, y2: Int) `{ SDL_RenderDrawLine(self, x1, y1, x2, y2); `}
# Set the viewport of this renderer
- fun viewport=(rect: SDLRect) `{ SDL_RenderSetViewport(recv, rect); `}
+ fun viewport=(rect: SDLRect) `{ SDL_RenderSetViewport(self, rect); `}
# Get the rendering target of this renderer
- fun target: SDLTexture `{ return SDL_GetRenderTarget(recv); `}
+ fun target: SDLTexture `{ return SDL_GetRenderTarget(self); `}
# Set the rendering target of this renderer
- fun target=(val: SDLTexture) `{ SDL_SetRenderTarget(recv, val); `}
+ fun target=(val: SDLTexture) `{ SDL_SetRenderTarget(self, val); `}
# TODO add other renderer related methods:
#
end
# The red component of this color `[0..255]`
- fun r: Int `{ return recv->r; `}
+ fun r: Int `{ return self->r; `}
# Set the red component of this color `[0..255]`
- fun r=(val: Int) `{ recv->r = val; `}
+ fun r=(val: Int) `{ self->r = val; `}
# The green component of this color `[0..255]`
- fun g: Int `{ return recv->g; `}
+ fun g: Int `{ return self->g; `}
# Set the green component of this color `[0..255]`
- fun g=(val: Int) `{ recv->g = val; `}
+ fun g=(val: Int) `{ self->g = val; `}
# The blue component of this color `[0..255]`
- fun b: Int `{ return recv->b; `}
+ fun b: Int `{ return self->b; `}
# Set the blue component of this color `[0..255]`
- fun b=(val: Int) `{ recv->b = val; `}
+ fun b=(val: Int) `{ self->b = val; `}
# The alpha component of this color `[0..255]`
- fun a: Int `{ return recv->a; `}
+ fun a: Int `{ return self->a; `}
# Set the ralpha component of this color `[0..255]`
- fun a=(val: Int) `{ recv->a = val; `}
+ fun a=(val: Int) `{ self->a = val; `}
# TODO implement the related `SDL_Palette` and related methods
end
new `{ return 0; `}
# Add the flag to request a software renderer
- fun software: SDLRendererFlags `{ return recv | SDL_RENDERER_SOFTWARE; `}
+ fun software: SDLRendererFlags `{ return self | SDL_RENDERER_SOFTWARE; `}
# Add the flag to request an accelerated renderer
#
# This is the default option.
- fun accelerated: SDLRendererFlags `{ return recv | SDL_RENDERER_ACCELERATED; `}
+ fun accelerated: SDLRendererFlags `{ return self | SDL_RENDERER_ACCELERATED; `}
# Add the flag to request a renderer where `SDLRenderer::present` is synchronized with the refresh rate
- fun presentvsync: SDLRendererFlags `{ return recv | SDL_RENDERER_PRESENTVSYNC; `}
+ fun presentvsync: SDLRendererFlags `{ return self | SDL_RENDERER_PRESENTVSYNC; `}
# Add the flag to request a renderer able to render to a texture
- fun targettexture: SDLRendererFlags `{ return recv | SDL_RENDERER_TARGETTEXTURE; `}
+ fun targettexture: SDLRendererFlags `{ return self | SDL_RENDERER_TARGETTEXTURE; `}
end
# A bitmap surface
# Load the BMP file at `path`
new load_bmp(path: NativeString) `{ return SDL_LoadBMP(path); `}
- redef fun free `{ SDL_FreeSurface(recv); `}
+ redef fun free `{ SDL_FreeSurface(self); `}
# Save this texture to a BMP file
- fun save_bmp(path: NativeString) `{ SDL_SaveBMP(recv, path); `}
+ fun save_bmp(path: NativeString) `{ SDL_SaveBMP(self, path); `}
end
# A loaded bitmap texture
`}
# Destroy this texture
- fun destroy `{ SDL_DestroyTexture(recv); `}
+ fun destroy `{ SDL_DestroyTexture(self); `}
# Width of this texture
fun width: Int `{
int val;
- SDL_QueryTexture(recv, NULL, NULL, &val, NULL);
+ SDL_QueryTexture(self, NULL, NULL, &val, NULL);
return val;
`}
# Height of this texture
fun height: Int `{
int val;
- SDL_QueryTexture(recv, NULL, NULL, NULL, &val);
+ SDL_QueryTexture(self, NULL, NULL, NULL, &val);
return val;
`}
end
# X coordinate of the top left corner
- fun x: Int `{ return recv->x; `}
+ fun x: Int `{ return self->x; `}
# Set the X coordinate of the top left corner
- fun x=(val: Int) `{ recv->x = val; `}
+ fun x=(val: Int) `{ self->x = val; `}
# Y coordinate of the top left corner
- fun y: Int `{ return recv->y; `}
+ fun y: Int `{ return self->y; `}
# Set the Y coordinate of the top left corner
- fun y=(val: Int) `{ recv->y = val; `}
+ fun y=(val: Int) `{ self->y = val; `}
# Width of this rectangle
- fun w: Int `{ return recv->w; `}
+ fun w: Int `{ return self->w; `}
# Set the width of this rectangle
- fun w=(val: Int) `{ recv->w = val; `}
+ fun w=(val: Int) `{ self->w = val; `}
# Height of this rectangle
- fun h: Int `{ return recv->h; `}
+ fun h: Int `{ return self->h; `}
# Set the height of this rectangle
- fun h=(val: Int) `{ recv->h = val; `}
+ fun h=(val: Int) `{ self->h = val; `}
# TODO implement other `SDLRect` related methods:
#
end
# X coordinate of this point
- fun x: Int `{ return recv->x; `}
+ fun x: Int `{ return self->x; `}
# Set the X coordinate of this point
- fun x=(val: Int) `{ recv->x = val; `}
+ fun x=(val: Int) `{ self->x = val; `}
# Y coordinate of this point
- fun y: Int `{ return recv->y; `}
+ fun y: Int `{ return self->y; `}
# Set the Y coordinate of this point
- fun y=(val: Int) `{ recv->y = val; `}
+ fun y=(val: Int) `{ self->y = val; `}
end
# Flag to set the icon in `sys.sdl.show_simple_message_box` and `SDLWindow::show_simple_message_box`
new malloc `{ return malloc(sizeof(SDL_RendererInfo)); `}
# Name of the renderer's driver
- fun name: NativeString `{ return (char*)recv->name; `}
+ fun name: NativeString `{ return (char*)self->name; `}
# Maximum texture width supported by the renderer
- fun max_texture_width: Int `{ return recv->max_texture_width; `}
+ fun max_texture_width: Int `{ return self->max_texture_width; `}
# Maximum texture height supported by the renderer
- fun max_texture_height: Int `{ return recv->max_texture_height; `}
+ fun max_texture_height: Int `{ return self->max_texture_height; `}
end
SDL_VERSION(&val->version);
- if(SDL_GetWindowWMInfo(recv, val) <= 0) {
+ if(SDL_GetWindowWMInfo(self, val) <= 0) {
free(val);
return NULL;
}
# Created using `SDLWindow::vm_info`
extern class SDLSysWMInfo `{ SDL_SysWMinfo * `}
# Is this an unknown window manager?
- fun is_unknown: Bool `{ return recv->subsystem == SDL_SYSWM_UNKNOWN; `}
+ fun is_unknown: Bool `{ return self->subsystem == SDL_SYSWM_UNKNOWN; `}
# Is this a Windows system?
- fun is_windows: Bool `{ return recv->subsystem == SDL_SYSWM_WINDOWS; `}
+ fun is_windows: Bool `{ return self->subsystem == SDL_SYSWM_WINDOWS; `}
# Is this the X11 window manager?
- fun is_x11: Bool `{ return recv->subsystem == SDL_SYSWM_X11; `}
+ fun is_x11: Bool `{ return self->subsystem == SDL_SYSWM_X11; `}
# Is this a direct DirectFB?
- fun is_direcfb: Bool `{ return recv->subsystem == SDL_SYSWM_DIRECTFB; `}
+ fun is_direcfb: Bool `{ return self->subsystem == SDL_SYSWM_DIRECTFB; `}
# Is this system an OS X?
- fun is_cocoa: Bool `{ return recv->subsystem == SDL_SYSWM_COCOA; `}
+ fun is_cocoa: Bool `{ return self->subsystem == SDL_SYSWM_COCOA; `}
# Is this system an iOS?
- fun is_uikit: Bool `{ return recv->subsystem == SDL_SYSWM_UIKIT; `}
+ fun is_uikit: Bool `{ return self->subsystem == SDL_SYSWM_UIKIT; `}
# It this window manager Wayland?
fun is_wayland: Bool `{
#if SDL_VERSION_ATLEAST(2, 0, 2)
- return recv->subsystem == SDL_SYSWM_WAYLAND;
+ return self->subsystem == SDL_SYSWM_WAYLAND;
#else
return 0;
#endif
# It this window manager Mir?
fun is_mir: Bool `{
#if SDL_VERSION_ATLEAST(2, 0, 3)
- return recv->subsystem == SDL_SYSWM_MIR;
+ return self->subsystem == SDL_SYSWM_MIR;
#else
return 0;
#endif
# Is this system a Windows RT?
fun is_winrt: Bool `{
#if SDL_VERSION_ATLEAST(2, 0, 3)
- return recv->subsystem == SDL_SYSWM_WINRT;
+ return self->subsystem == SDL_SYSWM_WINRT;
#else
return 0;
#endif
# Is this system an Android?
fun is_android: Bool `{
#if SDL_VERSION_ATLEAST(2, 0, 4)
- return recv->subsystem == SDL_SYSWM_ANDROID;
+ return self->subsystem == SDL_SYSWM_ANDROID;
#else
return 0;
#endif
#
# Require: `is_x11`
fun x11_window_handle: Pointer `{
- return (void*)recv->info.x11.window;
+ return (void*)self->info.x11.window;
`}
end
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Services for caching serialization engines
+module caching
+
+import serialization
+private import engine_tools
+
+# A `Serializer` with a `cache`
+abstract class CachingSerializer
+ super Serializer
+
+ # Cache of known objects
+ var cache = new SerializerCache is lazy, writable
+
+ # Link the cache of `self` with `deserializer`
+ #
+ # This allows reference objects by id when they are known by the other side
+ # of the stream.
+ #
+ # Use `cache` if it is a `DuplexCache`, otherwise create a new one.
+ fun link(deserializer: CachingDeserializer)
+ do
+ var mem = self.cache
+ if not mem isa DuplexCache then mem = new DuplexCache
+
+ self.cache = mem
+ deserializer.cache = mem
+ end
+end
+
+# A `Deserializer` with a `cache`
+abstract class CachingDeserializer
+ super Deserializer
+
+ # Cache of known objects
+ var cache = new DeserializerCache is lazy, writable
+end
+
+# Cache of sent objects
+#
+# Used by `Serializer` to avoid duplicating objects, by serializing them once,
+# then using a reference.
+class SerializerCache
+ # Map of already serialized objects to the reference id
+ private var sent: Map[Serializable, Int] = new StrictHashMap[Serializable, Int]
+
+ # Is `object` known?
+ fun has_object(object: Serializable): Bool do return sent.keys.has(object)
+
+ # Get the id for `object`
+ #
+ # Require: `has_object(object)`
+ fun id_for(object: Serializable): Int
+ do
+ assert sent.keys.has(object)
+ return sent[object]
+ end
+
+ # Get a new id for `object` and store it
+ #
+ # Require: `not has_object(object)`
+ fun new_id_for(object: Serializable): Int
+ do
+ var id = sent.length
+ sent[object] = id
+ return id
+ end
+end
+
+# Cache of received objects sorted by there reference id
+#
+# Used by `Deserializer` to find already deserialized objects by their reference.
+class DeserializerCache
+ # Map of references to already deserialized objects.
+ private var received: Map[Int, Object] = new StrictHashMap[Int, Object]
+
+ # Is there an object associated to `id`?
+ fun has_id(id: Int): Bool do return received.keys.has(id)
+
+ # Get the object associated to `id`
+ fun object_for(id: Int): nullable Object do return received[id]
+
+ # Associate `object` to `id`
+ fun []=(id: Int, object: Object) do received[id] = object
+end
+
+# A shared cache for serialization and deserialization
+class DuplexCache
+ super SerializerCache
+ super DeserializerCache
+
+ redef fun new_id_for(object)
+ do
+ var id = super
+ received[id] = object
+ return id
+ end
+
+ redef fun []=(id, object)
+ do
+ super
+ assert object isa Serializable
+ sent[object] = id
+ end
+end
module engine_tools
import serialization
+intrude import standard::collection::hash_collection
-# Maps instances to a value, uses `is_same_instance`
-#
-# Warning: This class does not implement all the services from `Map`.
+# Maps instances to a value, uses `is_same_serialized` and `serialization_hash`.
class StrictHashMap[K, V]
- super Map[K, V]
-
- # private
- var map = new HashMap[K, Array[Couple[K, V]]]
-
- redef var length = 0
-
- redef fun is_empty do return length == 0
+ super HashMap[K, V]
- # private
- fun node_at(key: K): nullable Couple[K, V]
+ redef fun index_at(k)
do
- if not map.keys.has(key) then return null
-
- var arr = map[key]
- for couple in arr do
- if couple.first.is_same_serialized(key) then
- return couple
- end
- end
+ if k == null then return 0
- return null
+ var i = k.serialization_hash % _capacity
+ if i < 0 then i = - i
+ return i
end
- redef fun [](key)
+ redef fun node_at_idx(i, k)
do
- var node = node_at(key)
- assert node != null
- return node.second
- end
-
- redef fun []=(key, value)
- do
- var node = node_at(key)
- if node != null then
- node.second = value
- return
+ var c = _array[i]
+ while c != null do
+ var ck = c._key
+ if ck.is_same_serialized(k) then
+ break
+ end
+ c = c._next_in_bucklet
end
-
- var arr
- if not map.keys.has(key) then
- arr = new Array[Couple[K, V]]
- map[key] = arr
- else arr = map[key]
-
- arr.add new Couple[K, V](key, value)
- self.length += 1
+ return c
end
-
- redef fun has_key(key) do return node_at(key) != null
end
#
# Used to determine if an object has already been serialized.
fun is_same_serialized(other: nullable Object): Bool do return is_same_instance(other)
+
+ # Hash value use for serialization
+ #
+ # Used in combination with `is_same_serialized`. If two objects are the same
+ # in a serialization context, they must have the same `serialization_hash`.
+ fun serialization_hash: Int do return object_id
end
# Instances of this class are not delayed and instead serialized immediately
sha1nfo s;
sha1_init(&s);
- sha1_write(&s, String_to_cstring(recv), String_length(recv));
+ sha1_write(&s, String_to_cstring(self), String_length(self));
uint8_t* digest = sha1_result(&s);
char* digested = malloc(21);
sha1nfo s;
sha1_init(&s);
- sha1_write(&s, String_to_cstring(recv), String_length(recv));
+ sha1_write(&s, String_to_cstring(self), String_length(self));
uint8_t* digest = sha1_result(&s);
char* ret_str = malloc(41);
if (last_handler != NULL)
SignalHandler_decr_ref(last_handler);
- nit_signals_list[signal].handler = recv;
- SignalHandler_incr_ref(recv);
+ nit_signals_list[signal].handler = self;
+ SignalHandler_incr_ref(self);
nit_signals_list[signal].safely = safely;
}
private extern class NativeSocketPollFD `{ struct pollfd * `}
# File descriptor
- fun fd: Int `{ return recv->fd; `}
+ fun fd: Int `{ return self->fd; `}
# List of events to be watched
- fun events: Int `{ return recv->events; `}
+ fun events: Int `{ return self->events; `}
# List of events received by the last poll function
- fun revents: Int `{ return recv->revents; `}
+ fun revents: Int `{ return self->revents; `}
new (pid: Int, events: NativeSocketPollValues) `{
struct pollfd *poll = malloc(sizeof(struct pollfd));
return d;
`}
- fun destroy `{ free(recv); `}
+ fun destroy `{ free(self); `}
- fun close: Int `{ return close(*recv); `}
+ fun close: Int `{ return close(*self); `}
- fun descriptor: Int `{ return *recv; `}
+ fun descriptor: Int `{ return *self; `}
fun gethostbyname(n: String): NativeSocketHostent import String.to_cstring `{ return gethostbyname(String_to_cstring(n)); `}
fun connect(addrIn: NativeSocketAddrIn): Int `{
- return connect(*recv, (struct sockaddr*)addrIn, sizeof(*addrIn));
+ return connect(*self, (struct sockaddr*)addrIn, sizeof(*addrIn));
`}
fun write(buffer: String): Int
import String.to_cstring, String.length `{
- return write(*recv, (char*)String_to_cstring(buffer), String_length(buffer));
+ return write(*self, (char*)String_to_cstring(buffer), String_length(buffer));
`}
# Write `value` as a single byte
fun write_byte(value: Int): Int `{
unsigned char byt = (unsigned char)value;
- return write(*recv, &byt, 1);
+ return write(*self, &byt, 1);
`}
fun read: String import NativeString.to_s_with_length, NativeString.to_s_with_copy `{
static char c[1024];
- int n = read(*recv, c, 1023);
+ int n = read(*self, c, 1023);
if(n < 0) {
return NativeString_to_s_with_length("",0);
}
#
# Returns `true` on success.
fun setsockopt(level: NativeSocketOptLevels, option_name: NativeSocketOptNames, option_value: Int): Bool `{
- int err = setsockopt(*recv, level, option_name, &option_value, sizeof(int));
+ int err = setsockopt(*self, level, option_name, &option_value, sizeof(int));
if(err != 0){
return 0;
}
return 1;
`}
- fun bind(addrIn: NativeSocketAddrIn): Int `{ return bind(*recv, (struct sockaddr*)addrIn, sizeof(*addrIn)); `}
+ fun bind(addrIn: NativeSocketAddrIn): Int `{ return bind(*self, (struct sockaddr*)addrIn, sizeof(*addrIn)); `}
- fun listen(size: Int): Int `{ return listen(*recv, size); `}
+ fun listen(size: Int): Int `{ return listen(*self, size); `}
# Checks if the buffer is ready for any event specified when creating the pollfd structure
fun socket_poll(filedesc: PollFD, timeout: Int): Array[NativeSocketPollValues]
private fun native_accept(addr_in: NativeSocketAddrIn): NativeSocket `{
socklen_t s = sizeof(struct sockaddr);
- int socket = accept(*recv, (struct sockaddr*)addr_in, &s);
+ int socket = accept(*self, (struct sockaddr*)addr_in, &s);
if (socket == -1) return NULL;
int *ptr = malloc(sizeof(int));
# Set wether this socket is non blocking
fun non_blocking=(value: Bool) `{
- int flags = fcntl(*recv, F_GETFL, 0);
+ int flags = fcntl(*self, F_GETFL, 0);
if (flags == -1) flags = 0;
if (value) {
} else {
return;
}
- fcntl(*recv, F_SETFL, flags);
+ fcntl(*self, F_SETFL, flags);
`}
end
return sai;
`}
- fun address: String import NativeString.to_s `{ return NativeString_to_s((char*)inet_ntoa(recv->sin_addr)); `}
+ fun address: String import NativeString.to_s `{ return NativeString_to_s((char*)inet_ntoa(self->sin_addr)); `}
- fun family: NativeSocketAddressFamilies `{ return recv->sin_family; `}
+ fun family: NativeSocketAddressFamilies `{ return self->sin_family; `}
- fun port: Int `{ return ntohs(recv->sin_port); `}
+ fun port: Int `{ return ntohs(self->sin_port); `}
- fun destroy `{ free(recv); `}
+ fun destroy `{ free(self); `}
end
extern class NativeSocketHostent `{ struct hostent* `}
- private fun native_h_aliases(i: Int): String import NativeString.to_s `{ return NativeString_to_s(recv->h_aliases[i]); `}
+ private fun native_h_aliases(i: Int): String import NativeString.to_s `{ return NativeString_to_s(self->h_aliases[i]); `}
- private fun native_h_aliases_reachable(i: Int): Bool `{ return (recv->h_aliases[i] != NULL); `}
+ private fun native_h_aliases_reachable(i: Int): Bool `{ return (self->h_aliases[i] != NULL); `}
fun h_aliases: Array[String]
do
return d
end
- fun h_addr: String import NativeString.to_s `{ return NativeString_to_s((char*)inet_ntoa(*(struct in_addr*)recv->h_addr)); `}
+ fun h_addr: String import NativeString.to_s `{ return NativeString_to_s((char*)inet_ntoa(*(struct in_addr*)self->h_addr)); `}
- fun h_addrtype: Int `{ return recv->h_addrtype; `}
+ fun h_addrtype: Int `{ return self->h_addrtype; `}
- fun h_length: Int `{ return recv->h_length; `}
+ fun h_length: Int `{ return self->h_length; `}
- fun h_name: String import NativeString.to_s `{ return NativeString_to_s(recv->h_name); `}
+ fun h_name: String import NativeString.to_s `{ return NativeString_to_s(self->h_name); `}
end
extern class NativeTimeval `{ struct timeval* `}
return tv;
`}
- fun seconds: Int `{ return recv->tv_sec; `}
+ fun seconds: Int `{ return self->tv_sec; `}
- fun microseconds: Int `{ return recv->tv_usec; `}
+ fun microseconds: Int `{ return self->tv_usec; `}
- fun destroy `{ free(recv); `}
+ fun destroy `{ free(self); `}
end
extern class NativeSocketSet `{ fd_set* `}
return f;
`}
- fun set(s: NativeSocket) `{ FD_SET(*s, recv); `}
+ fun set(s: NativeSocket) `{ FD_SET(*s, self); `}
- fun is_set(s: NativeSocket): Bool `{ return FD_ISSET(*s, recv); `}
+ fun is_set(s: NativeSocket): Bool `{ return FD_ISSET(*s, self); `}
- fun zero `{ FD_ZERO(recv); `}
+ fun zero `{ FD_ZERO(self); `}
- fun clear(s: NativeSocket) `{ FD_CLR(*s, recv); `}
+ fun clear(s: NativeSocket) `{ FD_CLR(*s, self); `}
- fun destroy `{ free(recv); `}
+ fun destroy `{ free(self); `}
end
class NativeSocketObserver
# Combines two NativeSocketPollValues
private fun +(other: NativeSocketPollValues): NativeSocketPollValues `{
- return recv | other;
+ return self | other;
`}
end
extern class Sqlite3Code `{int`}
new ok `{ return SQLITE_OK; `} # 0 /* Successful result */
- fun is_ok: Bool `{ return recv == SQLITE_OK; `}
+ fun is_ok: Bool `{ return self == SQLITE_OK; `}
# new `{ return SQLITE_ERROR; `} # 1 /* SQL error or missing database */
# new `{ return SQLITE_INTERNAL; `} # 2 /* Internal logic error in SQLite */
# new `{ return SQLITE_WARNING; `} # 28 /* Warnings from sqlite3_log() */
new row `{ return SQLITE_ROW; `} # 100 /* sqlite3_step() has another row ready */
- fun is_row: Bool `{ return recv == SQLITE_ROW; `}
+ fun is_row: Bool `{ return self == SQLITE_ROW; `}
new done `{ return SQLITE_DONE; `} # 101 /* sqlite3_step() has finished executing */
- fun is_done: Bool `{ return recv == SQLITE_DONE; `}
+ fun is_done: Bool `{ return self == SQLITE_DONE; `}
redef fun to_s: String import NativeString.to_s `{
#if SQLITE_VERSION_NUMBER >= 3007015
- char *err = (char *)sqlite3_errstr(recv);
+ char *err = (char *)sqlite3_errstr(self);
#else
char *err = "sqlite3_errstr supported only by version >= 3.7.15";
#endif
# Evaluate the statement
fun step: Sqlite3Code `{
- return sqlite3_step(recv);
+ return sqlite3_step(self);
`}
fun column_name(i: Int) : String import NativeString.to_s `{
- const char * name = (sqlite3_column_name(recv, i));
+ const char * name = (sqlite3_column_name(self, i));
if(name == NULL){
name = "";
}
# Number of bytes in the blob or string at row `i`
fun column_bytes(i: Int) : Int `{
- return sqlite3_column_bytes(recv, i);
+ return sqlite3_column_bytes(self, i);
`}
fun column_double(i: Int) : Float `{
- return sqlite3_column_double(recv, i);
+ return sqlite3_column_double(self, i);
`}
fun column_int(i: Int) : Int `{
- return sqlite3_column_int(recv, i);
+ return sqlite3_column_int(self, i);
`}
fun column_text(i: Int): NativeString `{
- return (char *)sqlite3_column_text(recv, i);
+ return (char *)sqlite3_column_text(self, i);
`}
# Type of the entry at row `i`
fun column_type(i: Int): DataType `{
- return sqlite3_column_type(recv, i);
+ return sqlite3_column_type(self, i);
`}
- fun column_blob(i: Int): Pointer `{ return (void*)sqlite3_column_blob(recv, i); `}
+ fun column_blob(i: Int): Pointer `{ return (void*)sqlite3_column_blob(self, i); `}
fun column_count: Int `{
- return sqlite3_column_count(recv);
+ return sqlite3_column_count(self);
`}
# Reset this statement to its original state, to be reexecuted
- fun reset: Sqlite3Code `{ return sqlite3_reset(recv); `}
+ fun reset: Sqlite3Code `{ return sqlite3_reset(self); `}
# Delete this statement
- fun finalize: Sqlite3Code `{ return sqlite3_finalize(recv); `}
+ fun finalize: Sqlite3Code `{ return sqlite3_finalize(self); `}
end
# A database connection
# Close this connection
fun close `{
#if SQLITE_VERSION_NUMBER >= 3007014
- sqlite3_close_v2(recv);
+ sqlite3_close_v2(self);
#else
// A program using the older version should not rely on the garbage-collector
// to close its connections. They must be closed manually after the associated
// prepare statements have been finalized.
- sqlite3_close(recv);
+ sqlite3_close(self);
#endif
`}
# Execute a SQL statement
fun exec(sql: String): Sqlite3Code import String.to_cstring `{
- return sqlite3_exec(recv, String_to_cstring(sql), 0, 0, 0);
+ return sqlite3_exec(self, String_to_cstring(sql), 0, 0, 0);
`}
# Prepare a SQL statement
fun prepare(sql: String): nullable NativeStatement import String.to_cstring, NativeStatement.as nullable `{
sqlite3_stmt *stmt;
- int res = sqlite3_prepare_v2(recv, String_to_cstring(sql), -1, &stmt, 0);
+ int res = sqlite3_prepare_v2(self, String_to_cstring(sql), -1, &stmt, 0);
if (res == SQLITE_OK)
return NativeStatement_as_nullable(stmt);
else
`}
fun last_insert_rowid: Int `{
- return sqlite3_last_insert_rowid(recv);
+ return sqlite3_last_insert_rowid(self);
`}
fun error: Sqlite3Code `{
- return sqlite3_errcode(recv);
+ return sqlite3_errcode(self);
`}
end
# Sqlite data types
extern class DataType `{ int `}
- fun is_integer: Bool `{ return recv == SQLITE_INTEGER; `}
- fun is_float: Bool `{ return recv == SQLITE_FLOAT; `}
- fun is_blob: Bool `{ return recv == SQLITE_BLOB; `}
- fun is_null: Bool `{ return recv == SQLITE_NULL; `}
- fun is_text: Bool `{ return recv == SQLITE_TEXT; `}
+ fun is_integer: Bool `{ return self == SQLITE_INTEGER; `}
+ fun is_float: Bool `{ return self == SQLITE_FLOAT; `}
+ fun is_blob: Bool `{ return self == SQLITE_BLOB; `}
+ fun is_null: Bool `{ return self == SQLITE_NULL; `}
+ fun is_text: Bool `{ return self == SQLITE_TEXT; `}
- fun to_i: Int `{ return recv; `}
+ fun to_i: Int `{ return self; `}
end
-# This file is part of NIT ( http://www.nitlanguage.org ).
+# This file is part of NIT (http://www.nitlanguage.org).
#
# Copyright 2014 Julien Pagès <julien.pages@lirmm.fr>
#
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
#include <assert.h>
`}
-# Add support of binary operations related
-# to binary level of Integer
-# For compatibility reasons, xor, and, or methods
-# are still in the math.nit module
+# Add support of binary operations related to binary level of Integer
+# For compatibility reasons, xor, and, or methods are still in the `math` module.
redef class Int
- # Sets the i-bit of self to the given value
- # assert 11.setbit(0, 0) == 10
- # assert 10.setbit(0, 1) == 11
+ # Sets the i-bit of self to the given `value`
+ #
+ # assert 11.setbit(0, 0) == 10
+ # assert 10.setbit(0, 1) == 11
fun setbit(index: Int, value: Int): Int `{
assert(index >= 0 && index < 32);
if(value == 1)
- return recv | (1 << index);
+ return self | (1 << index);
else
- return recv & ~(1 << index);
+ return self & ~(1 << index);
`}
- # Returns the i-bit value of self Integer
- # assert 10.getbit(0) == 0
- # assert 10.getbit(3) == 1
+ # Returns the i-bit value of `self`
+ #
+ # assert 10.getbit(0) == 0
+ # assert 10.getbit(3) == 1
fun getbit(index: Int): Int `{
assert(index >= 0 && index < 32);
int op = 1 << index;
-
- if((recv & op) == 0)
+
+ if((self & op) == 0)
return 0;
else
return 1;
`}
# Give a binary representation of self Integer
- fun bits : Array[Int]
+ fun bits: Array[Int]
do
- var bits = new Array[Int].with_capacity(32)
-
+ var bits = new Array[Int].with_capacity(32)
+
for i in [0..32[
do
bits[i] = getbit(i)
return bits
end
- # Returns the number of bits of specified value (0 or 1)
- # in self
- # assert 10.number_bits(1) == 2
- # assert 10.number_bits(0) == 30
+ # Returns the number of bits of specified value (0 or 1) in `self`
+ #
+ # assert 10.number_bits(1) == 2
+ # assert 10.number_bits(0) == 30
fun number_bits(value: Int): Int `{
assert(value == 0 || value == 1);
{
for(i=bound; i>0; i/=2)
{
- if(recv & i)
+ if(self & i)
count++;
}
}
{
for(i=bound; i>0; i/=2)
{
- if(!(recv & i))
+ if(!(self & i))
count++;
}
}
return count;
`}
- # Returns the position of the highest bit
- # set to 1 in self (the rightest bit is at position 0)
- # assert 10.highest_bit == 3
- # assert 1.highest_bit == 0
- fun highest_bit: Int `{
+ # Returns the position of the highest bit set to 1 in `self`
+ #
+ # The rightmost bit is at position 0.
+ #
+ # assert 10.highest_bit == 3
+ # assert 1.highest_bit == 0
+ fun highest_bit: Int `{
long int msb = 1L << 31;
int pos = 31;
-
- while(msb > 0 && !(recv & msb))
+
+ while(msb > 0 && !(self & msb))
{
msb /= 2;
pos--;
}
-
+
return pos;
`}
end
struct stat* stat_element;
int res;
stat_element = malloc(sizeof(struct stat));
- res = lstat(recv, stat_element);
+ res = lstat(self, stat_element);
if (res == -1) return NULL;
return stat_element;
`}
private fun file_mkdir: Bool is extern "string_NativeString_NativeString_file_mkdir_0"
- private fun rmdir: Bool `{ return !rmdir(recv); `}
+ private fun rmdir: Bool `{ return !rmdir(self); `}
private fun file_delete: Bool is extern "string_NativeString_NativeString_file_delete_0"
private fun file_chdir: Bool is extern "string_NativeString_NativeString_file_chdir_0"
private fun file_realpath: NativeString is extern "file_NativeString_realpath"
fun size: Int is extern "file_FileStat_FileStat_size_0"
# Returns true if it is a regular file (not a device file, pipe, sockect, ...)
- fun is_reg: Bool `{ return S_ISREG(recv->st_mode); `}
+ fun is_reg: Bool `{ return S_ISREG(self->st_mode); `}
# Returns true if it is a directory
- fun is_dir: Bool `{ return S_ISDIR(recv->st_mode); `}
+ fun is_dir: Bool `{ return S_ISDIR(self->st_mode); `}
# Returns true if it is a character device
- fun is_chr: Bool `{ return S_ISCHR(recv->st_mode); `}
+ fun is_chr: Bool `{ return S_ISCHR(self->st_mode); `}
# Returns true if it is a block device
- fun is_blk: Bool `{ return S_ISBLK(recv->st_mode); `}
+ fun is_blk: Bool `{ return S_ISBLK(self->st_mode); `}
# Returns true if the type is fifo
- fun is_fifo: Bool `{ return S_ISFIFO(recv->st_mode); `}
+ fun is_fifo: Bool `{ return S_ISFIFO(self->st_mode); `}
# Returns true if the type is a link
- fun is_lnk: Bool `{ return S_ISLNK(recv->st_mode); `}
+ fun is_lnk: Bool `{ return S_ISLNK(self->st_mode); `}
# Returns true if the type is a socket
- fun is_sock: Bool `{ return S_ISSOCK(recv->st_mode); `}
+ fun is_sock: Bool `{ return S_ISSOCK(self->st_mode); `}
end
# Instance of this class are standard FILE * pointers
fun io_write(buf: NativeString, len: Int): Int is extern "file_NativeFile_NativeFile_io_write_2"
fun write_byte(value: Int): Int `{
unsigned char b = (unsigned char)value;
- return fwrite(&b, 1, 1, recv);
+ return fwrite(&b, 1, 1, self);
`}
fun io_close: Int is extern "file_NativeFile_NativeFile_io_close_0"
fun file_stat: NativeFileStat is extern "file_NativeFile_NativeFile_file_stat_0"
- fun fileno: Int `{ return fileno(recv); `}
+ fun fileno: Int `{ return fileno(self); `}
# Flushes the buffer, forcing the write operation
fun flush: Int is extern "fflush"
# Used to specify how the buffering will be handled for the current stream.
new opendir(path: NativeString) `{ return opendir(path); `}
# Close a directory
- fun closedir `{ closedir(recv); `}
+ fun closedir `{ closedir(self); `}
# Read the next directory entry
fun readdir: NativeString `{
struct dirent *de;
- de = readdir(recv);
+ de = readdir(self);
if (!de) return NULL;
return de->d_name;
`}
# Returns the square root of `self`
#
# assert 16.sqrt == 4
- fun sqrt: Int `{ return sqrt(recv); `}
+ fun sqrt: Int `{ return sqrt(self); `}
# Returns the greatest common divisor of `self` and `o`
#
# assert 12.0.abs == 12.0
# assert (-34.56).abs == 34.56
# assert -34.56.abs == -34.56
- fun abs: Float `{ return fabs(recv); `}
+ fun abs: Float `{ return fabs(self); `}
# Returns `self` raised at `e` power.
#
# assert 1.9.ceil == 2.0
# assert 2.0.ceil == 2.0
# assert (-1.5).ceil == -1.0
- fun ceil: Float `{ return ceil(recv); `}
+ fun ceil: Float `{ return ceil(self); `}
# assert 1.1.floor == 1.0
# assert 1.9.floor == 1.0
# assert 2.0.floor == 2.0
# assert (-1.5).floor == -2.0
- fun floor: Float `{ return floor(recv); `}
+ fun floor: Float `{ return floor(self); `}
# Rounds the value of a float to its nearest integer value
#
new from_name(name: String) import String.to_cstring `{ return getpwnam( String_to_cstring(name) ); `}
# Username
- fun name: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_name); `}
+ fun name: String import NativeString.to_s `{ return NativeString_to_s(self->pw_name); `}
# User password
- fun passwd: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_passwd); `}
+ fun passwd: String import NativeString.to_s `{ return NativeString_to_s(self->pw_passwd); `}
# User ID
- fun uid: Int `{ return recv->pw_uid; `}
+ fun uid: Int `{ return self->pw_uid; `}
# Group ID
- fun gid: Int `{ return recv->pw_gid; `}
+ fun gid: Int `{ return self->pw_gid; `}
# Home directory
- fun dir: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_dir); `}
+ fun dir: String import NativeString.to_s `{ return NativeString_to_s(self->pw_dir); `}
# Shell program
- fun shell: String import NativeString.to_s `{ return NativeString_to_s(recv->pw_shell); `}
+ fun shell: String import NativeString.to_s `{ return NativeString_to_s(self->pw_shell); `}
end
# Information on a user group
new from_name(name: String) import String.to_cstring `{ return getgrnam( String_to_cstring(name) ); `}
# Name of this ground
- fun name: String import NativeString.to_s `{ return NativeString_to_s(recv->gr_name); `}
+ fun name: String import NativeString.to_s `{ return NativeString_to_s(self->gr_name); `}
# Encrypted password of this group
- fun passwd: String import NativeString.to_s `{ return NativeString_to_s(recv->gr_passwd); `}
+ fun passwd: String import NativeString.to_s `{ return NativeString_to_s(self->gr_passwd); `}
# Id of this group
- fun gid: Int `{ return recv->gr_gid; `}
+ fun gid: Int `{ return self->gr_gid; `}
# List of the members of the group
fun mem: Array[String] import Array[String], Array[String].add, NativeString.to_s `{
int m;
Array_of_String ret;
- mem = recv->gr_mem;
+ mem = self->gr_mem;
ret = new_Array_of_String();
for (m = 0; mem[m] != NULL; m++)
# Compile the regular expression `regex` into a form that is suitable for subsequent `regexec` searches
fun regcomp(regex: NativeString, cflags: Int): Int `{
- return regcomp(recv, regex, cflags);
+ return regcomp(self, regex, cflags);
`}
# Match `string` against the precompiled pattern buffer of `self`, locating matches
# `nmatch` and `pmatch` are used to provide information regarding the location of any matches.
# `eflags` may be the bitwise-or of one or both of `flag_notbol` and `flag_noteol`.
fun regexec(string: NativeString, nmatch: Int, pmatch: NativeMatchArray, eflags: Int): Int `{
- return regexec(recv, string, nmatch, pmatch, eflags);
+ return regexec(self, string, nmatch, pmatch, eflags);
`}
# Match `string` against the precompiled pattern buffer of `self`, do not locate matches
#
# `eflags` may be the bitwise-or of one or both of `flag_notbol` and `flag_noteol`.
fun regexec_match_only(string: NativeString, eflags: Int): Int `{
- return regexec(recv, string, 0, NULL, eflags);
+ return regexec(self, string, 0, NULL, eflags);
`}
# Free the memory allocated to the pattern buffer by the compiling process
#
# Does not free the memory holding `self`, use `free` for this purpose.
- fun regfree `{ regfree(recv); `}
+ fun regfree `{ regfree(self); `}
# Turn the error codes that can be returned by both `regcomp` and `regexec` into error message strings
fun regerror(errcode: Int): NativeString `{
- size_t len = regerror(errcode, recv, NULL, 0);
+ size_t len = regerror(errcode, self, NULL, 0);
char *message = malloc(len);
- regerror(errcode, recv, message, len);
+ regerror(errcode, self, message, len);
return message;
`}
# Number of parenthetical subexpressions in this compiled regular expression
- fun re_nsub: Int `{ return recv->re_nsub; `}
+ fun re_nsub: Int `{ return self->re_nsub; `}
end
# Flags for `NativeRegex::regcomp`
private fun error_espace: Int `{ return REG_ESPACE; `}
redef universal Int
- private fun is_nomatch: Bool `{ return recv == REG_NOMATCH; `}
+ private fun is_nomatch: Bool `{ return self == REG_NOMATCH; `}
end
# An array of `regmatch_t` or a pointer to one
new malloc(length: Int) `{ return malloc(length * sizeof(regmatch_t)); `}
# The offset in string of the beginning of a substring
- fun rm_so: Int `{ return recv->rm_so; `}
+ fun rm_so: Int `{ return self->rm_so; `}
# The offset in string of the end of the substring
- fun rm_eo: Int `{ return recv->rm_eo; `}
+ fun rm_eo: Int `{ return self->rm_eo; `}
# Get a pointer to the element at `index`, can also be used as a subarray
- fun [](index: Int): NativeMatchArray `{ return recv + index; `}
+ fun [](index: Int): NativeMatchArray `{ return self + index; `}
end
redef extern class NativeString
- private fun substring_from(index: Int): NativeString `{ return recv + index; `}
+ private fun substring_from(index: Int): NativeString `{ return self + index; `}
end
redef class Text
new from_i(i: Int) `{ return i; `}
# Update current time.
- fun update `{ time(&recv); `}
+ fun update `{ time(&self); `}
# Convert `self` to a human readable String.
fun ctime: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy( ctime(&recv) );
+ return NativeString_to_s_with_copy( ctime(&self) );
`}
# Difference in secondes from start (self if the end time)
- fun difftime(start: TimeT): Float `{ return difftime(recv, start); `}
+ fun difftime(start: TimeT): Float `{ return difftime(self, start); `}
redef fun to_s do return ctime.replace("\n", "")
# Convert self to Int (expressed as seconds since epoch).
- fun to_i: Int `{ return (int)recv; `}
+ fun to_i: Int `{ return (int)self; `}
end
# Time structure
`}
# Convert `self` as a TimeT.
- fun to_timet: TimeT `{ return mktime(recv); `}
+ fun to_timet: TimeT `{ return mktime(self); `}
# Seconds after the minute.
- fun sec: Int `{ return recv->tm_sec; `}
+ fun sec: Int `{ return self->tm_sec; `}
# Minutes after the hour.
- fun min: Int `{ return recv->tm_min; `}
+ fun min: Int `{ return self->tm_min; `}
# hours since midnight.
- fun hour: Int `{ return recv->tm_hour; `}
+ fun hour: Int `{ return self->tm_hour; `}
# Day of the month.
- fun mday: Int `{ return recv->tm_mday; `}
+ fun mday: Int `{ return self->tm_mday; `}
# Months since January.
- fun mon: Int `{ return recv->tm_mon; `}
+ fun mon: Int `{ return self->tm_mon; `}
# Years since 1900.
- fun year: Int `{ return recv->tm_year; `}
+ fun year: Int `{ return self->tm_year; `}
# Days since Sunday.
- fun wday: Int `{ return recv->tm_wday; `}
+ fun wday: Int `{ return self->tm_wday; `}
# Days since January 1st.
- fun yday: Int `{ return recv->tm_yday; `}
+ fun yday: Int `{ return self->tm_yday; `}
# Is `self` in Daylight Saving Time.
- fun is_dst: Bool `{ return recv->tm_isdst; `}
+ fun is_dst: Bool `{ return self->tm_isdst; `}
# Convert `self` to a human readable String.
fun asctime: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy( asctime(recv) );
+ return NativeString_to_s_with_copy( asctime(self) );
`}
# Convert `self` to a human readable String corresponding to `format`.
buf = (char*)malloc(100);
c_format = String_to_cstring(format);
- res = strftime(buf, 100, c_format, recv);
+ res = strftime(buf, 100, c_format, self);
String s = NativeString_to_s_with_copy(buf);
free(buf);
return s;
# 4 | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
# ~~~
private fun len: Int `{
- char* ns = recv->ns;
- int pos = recv->pos;
+ char* ns = self->ns;
+ int pos = self->pos;
char nspos = ns[pos];
if((nspos & 0x80) == 0x00){ return 1;}
if((nspos & 0xE0) == 0xC0){ return 2;}
# Position in containing NativeString
private fun pos: Int `{
- return recv->pos;
+ return self->pos;
`}
- private fun pos=(p: Int) `{recv->pos = p;`}
+ private fun pos=(p: Int) `{self->pos = p;`}
# C char* wrapping the char
fun ns: NativeString `{
- return recv->ns;
+ return self->ns;
`}
# Returns the Unicode code point representing the character
#
# Note : A unicode character might not be a visible glyph, but it will be used to determine canonical equivalence
fun code_point: Int import UTF8Char.len `{
- switch(UTF8Char_len(recv)){
+ switch(UTF8Char_len(self)){
case 1:
- return (long)(0x7F & (unsigned char)recv->ns[recv->pos]);
+ return (long)(0x7F & (unsigned char)self->ns[self->pos]);
case 2:
- return 0 | ((0x1F & (unsigned char)recv->ns[recv->pos]) << 6) | (0x3F & (unsigned char)recv->ns[recv->pos+1]);
+ return 0 | ((0x1F & (unsigned char)self->ns[self->pos]) << 6) | (0x3F & (unsigned char)self->ns[self->pos+1]);
case 3:
- return 0 | ((0x0F & (unsigned char)recv->ns[recv->pos]) << 12) |
- ((0x3F & (unsigned char)recv->ns[recv->pos+1]) << 6) |
- (0x3F & (unsigned char)recv->ns[recv->pos+2]);
+ return 0 | ((0x0F & (unsigned char)self->ns[self->pos]) << 12) |
+ ((0x3F & (unsigned char)self->ns[self->pos+1]) << 6) |
+ (0x3F & (unsigned char)self->ns[self->pos+2]);
case 4:
- return 0 | ((0x07 & (unsigned char)recv->ns[recv->pos]) << 18) |
- ((0x3F & (unsigned char)recv->ns[recv->pos+1]) << 12) |
- ((0x3F & (unsigned char)recv->ns[recv->pos+2]) << 6) |
- (0x3F & (unsigned char)recv->ns[recv->pos+3]);
+ return 0 | ((0x07 & (unsigned char)self->ns[self->pos]) << 18) |
+ ((0x3F & (unsigned char)self->ns[self->pos+1]) << 12) |
+ ((0x3F & (unsigned char)self->ns[self->pos+2]) << 6) |
+ (0x3F & (unsigned char)self->ns[self->pos+3]);
}
`}
# NOTE : Works only on ASCII chars
# TODO : Support unicode for to_upper
fun to_upper: UTF8Char import UTF8Char.code_point `{
- int cp = UTF8Char_code_point(recv);
- if(cp < 97 || cp > 122){ return recv; }
+ int cp = UTF8Char_code_point(self);
+ if(cp < 97 || cp > 122){ return self; }
char* ns = malloc(2);
ns[1] = '\0';
- char c = recv->ns[recv->pos];
+ char c = self->ns[self->pos];
ns[0] = c - 32;
UTF8Char* ret = malloc(sizeof(UTF8Char));
ret->ns = ns;
# NOTE : Works only on ASCII chars
# TODO : Support unicode for to_upper
fun to_lower: UTF8Char import UTF8Char.code_point `{
- int cp = UTF8Char_code_point(recv);
- if(cp < 65 || cp > 90){ return recv; }
+ int cp = UTF8Char_code_point(self);
+ if(cp < 65 || cp > 90){ return self; }
char* ns = malloc(2);
ns[1] = '\0';
- char c = recv->ns[recv->pos];
+ char c = self->ns[self->pos];
ns[0] = c + 32;
UTF8Char* ret = malloc(sizeof(UTF8Char));
ret->ns = ns;
end
redef fun output import UTF8Char.code_point `{
- switch(UTF8Char_len(recv)){
+ switch(UTF8Char_len(self)){
case 1:
- printf("%c", recv->ns[recv->pos]);
+ printf("%c", self->ns[self->pos]);
break;
case 2:
- printf("%c%c", recv->ns[recv->pos], recv->ns[recv->pos + 1]);
+ printf("%c%c", self->ns[self->pos], self->ns[self->pos + 1]);
break;
case 3:
- printf("%c%c%c", recv->ns[recv->pos], recv->ns[recv->pos + 1], recv->ns[recv->pos + 2]);
+ printf("%c%c%c", self->ns[self->pos], self->ns[self->pos + 1], self->ns[self->pos + 2]);
break;
case 4:
- printf("%c%c%c%c", recv->ns[recv->pos], recv->ns[recv->pos + 1], recv->ns[recv->pos + 2], recv->ns[recv->pos + 3]);
+ printf("%c%c%c%c", self->ns[self->pos], self->ns[self->pos + 1], self->ns[self->pos + 2], self->ns[self->pos + 3]);
break;
}
`}
redef fun to_s import NativeString.to_s_with_length `{
- int len = utf8___UTF8Char_len___impl(recv);
+ int len = utf8___UTF8Char_len___impl(self);
char* r = malloc(len + 1);
r[len] = '\0';
- char* src = (recv->ns + recv->pos);
+ char* src = (self->ns + self->pos);
memcpy(r, src, len);
return NativeString_to_s_with_length(r, len);
`}
new(size: Int) `{ return malloc(size*sizeof(UTF8Char)); `}
# Sets the character at `index` as `item`
- fun []=(index: Int, item: UTF8Char) `{ recv[index] = *item; `}
+ fun []=(index: Int, item: UTF8Char) `{ self[index] = *item; `}
# Gets the character at position `id`
- fun [](id: Int): UTF8Char `{ return &recv[id]; `}
+ fun [](id: Int): UTF8Char `{ return &self[id]; `}
# Copies a part of self starting at index `my_from` of length `length` into `other`, starting at `its_from`
fun copy_to(other: StringIndex, my_from: Int, its_from: Int, length: Int)`{
- UTF8Char* myfrom = recv + my_from*(sizeof(UTF8Char));
+ UTF8Char* myfrom = self + my_from*(sizeof(UTF8Char));
UTF8Char* itsfrom = other + its_from*(sizeof(UTF8Char));
memcpy(itsfrom, myfrom, length);
`}
while(pos < length){
UTF8Char* curr = &index[index_pos];
curr->pos = pos;
- curr->ns = recv;
+ curr->ns = self;
pos += UTF8Char_len(curr);
index_pos ++;
}
# 4 | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
# ~~~
fun len: Int `{
- uint32_t s = *recv;
+ uint32_t s = *self;
if(s <= 127) {return 1;}
if(s >= 49280 && s <= 57279) {return 2;}
if(s >= 14712960 && s <= 15712191) {return 3;}
#
# Note : A unicode character might not be a visible glyph, but it will be used to determine canonical equivalence
fun code_point: Int import UnicodeChar.len `{
- uint32_t val = *recv;
+ uint32_t val = *self;
uint32_t ret = 0;
- switch(UnicodeChar_len(recv)){
+ switch(UnicodeChar_len(self)){
case 1:
- ret = *recv;
+ ret = *self;
break;
case 2:
ret = 0 | ((val & 0x00001F00) >> 2) | (val & 0x0000003F);
# NOTE : Works only on ASCII chars
# TODO : Support unicode for to_upper
fun to_upper: UnicodeChar import UnicodeChar.code_point `{
- if(*recv < 97 || *recv > 122){ return recv; }
+ if(*self < 97 || *self > 122){ return self; }
uint32_t* ret = calloc(1,4);
- *ret = *recv - 32;
+ *ret = *self - 32;
return ret;
`}
# NOTE : Works only on ASCII chars
# TODO : Support unicode for to_upper
fun to_lower: UnicodeChar import UnicodeChar.code_point `{
- if(*recv < 65 || *recv > 90){ return recv; }
+ if(*self < 65 || *self > 90){ return self; }
uint32_t* ret = calloc(1,4);
- *ret = *recv + 32;
+ *ret = *self + 32;
return ret;
`}
end
redef fun output import UnicodeChar.len `{
- uint32_t self = *recv;
+ uint32_t self0 = *self;
if(!IS_BIG_ENDIAN){
- uint32_t tmp = ntohl(self);
- memcpy(&self, &tmp, 4);
+ uint32_t tmp = ntohl(self0);
+ memcpy(&self0, &tmp, 4);
}
- unsigned char* s = (unsigned char*) &self;
- switch(UnicodeChar_len(recv)){
+ unsigned char* s = (unsigned char*) &self0;
+ switch(UnicodeChar_len(self0)){
case 1:
printf("%c", s[3]);
break;
`}
redef fun to_s: FlatString import FlatString.full, UnicodeChar.len `{
- int len = UnicodeChar_len(recv);
+ int len = UnicodeChar_len(self);
char* r = malloc(len + 1);
r[len] = '\0';
- uint32_t src = *recv;
+ uint32_t src = *self;
if(!IS_BIG_ENDIAN){
uint32_t tmp = htonl(src);
memcpy(&src, &tmp, 4);
# Length implementation
private fun length_l: Int import FlatString.items, FlatString.index_to, FlatString.index_from `{
- char* ns = FlatString_items(recv);
- int i = FlatString_index_from(recv);
- int max = FlatString_index_to(recv);
+ char* ns = FlatString_items(self);
+ int i = FlatString_index_from(self);
+ int max = FlatString_index_to(self);
int length = 0;
while(i <= max){
char c = ns[i];
# Shifts the content of the buffer by `len` bytes to the right, starting at byte `from`
fun rshift_bytes(from: Int, len: Int) import FlatBuffer.bytelen, FlatBuffer.bytelen=, FlatBuffer.items `{
- long bt = FlatBuffer_bytelen(recv);
- char* ns = FlatBuffer_items(recv);
+ long bt = FlatBuffer_bytelen(self);
+ char* ns = FlatBuffer_items(self);
int off = from + len;
memmove(ns + off, ns + from, bt - from);
- FlatBuffer_bytelen__assign(recv, bt + len);
+ FlatBuffer_bytelen__assign(self, bt + len);
`}
# Shifts the content of the buffer by `len` bytes to the left, starting at `from`
fun lshift_bytes(from: Int, len: Int) import FlatBuffer.bytelen, FlatBuffer.bytelen=, FlatBuffer.items `{
- long bt = FlatBuffer_bytelen(recv);
- char* ns = FlatBuffer_items(recv);
+ long bt = FlatBuffer_bytelen(self);
+ char* ns = FlatBuffer_items(self);
int off = from - len;
memmove(ns + off, ns + from, bt - from);
- FlatBuffer_bytelen__assign(recv, bt - len);
+ FlatBuffer_bytelen__assign(self, bt - len);
`}
# Get the Unicode char stored at `index` in `self`
fun is_valid: Bool do return not address_is_null
# Wipe handle of XDG data cache.
- fun destroy `{ xdgWipeHandle(recv); `}
+ fun destroy `{ xdgWipeHandle(self); `}
# Update the data cache.
#
# be used to access XDG data as it was before `update` was called.
#
# Returns `true` if the update was successful.
- fun update: Bool `{ return xdgUpdateData(recv); `}
+ fun update: Bool `{ return xdgUpdateData(self); `}
# Base directory for user specific data files.
fun data_home: String import NativeString.to_s `{
- return NativeString_to_s((char*)xdgDataHome(recv));
+ return NativeString_to_s((char*)xdgDataHome(self));
`}
# Base directory for user specific configuration files.
fun config_home: String import NativeString.to_s `{
- return NativeString_to_s((char*)xdgConfigHome(recv));
+ return NativeString_to_s((char*)xdgConfigHome(self));
`}
# Base directory for user specific non-essential data files.
fun cache_home: String import NativeString.to_s `{
- return NativeString_to_s((char*)xdgCacheHome(recv));
+ return NativeString_to_s((char*)xdgCacheHome(self));
`}
# Preference-ordered set of base directories to search for data files
fun data_dirs: Array[String] do return native_data_dirs.to_string_array
private fun native_data_dirs: ConstPointer `{
- return xdgDataDirectories(recv);
+ return xdgDataDirectories(self);
`}
# Preference-ordered set of base directories to search for data files
end
private fun native_searchable_data_dirs: ConstPointer `{
- return xdgSearchableDataDirectories(recv);
+ return xdgSearchableDataDirectories(self);
`}
# Preference-ordered set of base directories to search for configuration
fun config_dirs: Array[String] do return native_config_dirs.to_string_array
private fun native_config_dirs: ConstPointer `{
- return xdgConfigDirectories(recv);
+ return xdgConfigDirectories(self);
`}
# Preference-ordered set of base directories to search for configuration
end
private fun native_searchable_config_dirs: ConstPointer `{
- return xdgSearchableConfigDirectories(recv);
+ return xdgSearchableConfigDirectories(self);
`}
end
# Convert a C `char **` to a Nit `Array[String]`
fun to_string_array: Array[String]
import Array[String], Array[String].add, NativeString.to_s `{
- char **strings = (char**)recv;
+ char **strings = (char**)self;
Array_of_String aos = new_Array_of_String();
int p = 0;
if mproperty.is_init then
var recv_mtype = recv_mtype
recv_var = nitni_visitor.init_instance_or_extern(recv_mtype)
- nitni_visitor.add("{mtype.ctype} recv /* var self: {mtype} */;")
- nitni_visitor.add("recv = {recv_var};")
+ nitni_visitor.add("{mtype.ctype} self /* var self: {mtype} */;")
+ nitni_visitor.add("self = {recv_var};")
else
mtype = mtype.anchor_to(v.compiler.mainmodule, recv_mtype)
- recv_var = nitni_visitor.var_from_c("recv", mtype)
+ recv_var = nitni_visitor.var_from_c("self", mtype)
recv_var = nitni_visitor.box_extern(recv_var, mtype)
end
var vars = new Array[RuntimeVariable]
- var recv_var = nitni_visitor.var_from_c("recv", mclass_type)
+ var recv_var = nitni_visitor.var_from_c("self", mclass_type)
recv_var = nitni_visitor.box_extern(recv_var, mclass_type)
vars.add(recv_var)
# Will convert C arguments to C++ and call the C++ implementation function.
fc = new CFunction(indirection_sig)
if not mproperty.is_init then
- var param_name = "recv"
+ var param_name = "self"
var type_name = to_cpp_call_context.name_mtype(mclass_type)
if mclass_type.mclass.ftype isa ForeignCppType then
fc.exprs.add("{type_name} {param_name}_for_cpp = static_cast<{type_name}>({param_name});\n")
jni_signature_alt = mclass_type.jni_signature_alt
return_type = mclass_type
else
- params.add "recv"
+ params.add "self"
if signature.return_mtype != null then
var ret_mtype = signature.return_mtype
ret_mtype = ret_mtype.resolve_for(mclass_type, mclass_type, mmodule, true)
cparams.add "jclass clazz"
if not self.is_init then
- cparams.add "{call_context.name_mtype(recv_mtype)} recv"
+ cparams.add "{call_context.name_mtype(recv_mtype)} self"
end
for p in signature.mparameters do
var param_mtype = p.mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
var cparams = new List[String]
if not self.is_init then
- cparams.add( "{call_context.name_mtype(recv_mtype)} recv" )
+ cparams.add( "{call_context.name_mtype(recv_mtype)} self" )
end
for p in signature.mparameters do
var param_mtype = p.mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
var cparams = new List[String]
if not self.is_init then
- cparams.add(call_context.cast_to(recv_mtype, "recv{param_suffix}"))
+ cparams.add(call_context.cast_to(recv_mtype, "self{param_suffix}"))
end
for p in signature.mparameters do
assert sup isa MClassType
- # `sub` and `sup` can be discovered inside a Generic type during the subtyping test
- if not sup.mclass.loaded then create_class(sup.mclass)
- if not sub.mclass.loaded then create_class(sub.mclass)
+ # and `sup` can be discovered inside a Generic type during the subtyping test
+ if not sub.mclass.loaded then load_class(sub.mclass)
+
+ # If the target of the test is not-loaded yet, the subtyping-test will be false
+ if not sup.mclass.abstract_loaded then return false
# For now, always use perfect hashing for subtyping test
var super_id = sup.mclass.vtable.id
# Redef init_instance to simulate the loading of a class
redef fun init_instance(recv: Instance)
do
- if not recv.mtype.as(MClassType).mclass.loaded then create_class(recv.mtype.as(MClassType).mclass)
+ if not recv.mtype.as(MClassType).mclass.loaded then load_class(recv.mtype.as(MClassType).mclass)
recv.vtable = recv.mtype.as(MClassType).mclass.vtable
# Associate a `PrimitiveInstance` to its `VTable`
redef fun init_instance_primitive(recv: Instance)
do
- if not recv.mtype.as(MClassType).mclass.loaded then create_class(recv.mtype.as(MClassType).mclass)
+ if not recv.mtype.as(MClassType).mclass.loaded then load_class(recv.mtype.as(MClassType).mclass)
recv.vtable = recv.mtype.as(MClassType).mclass.vtable
end
return attributes;
`}
- # Creates the runtime structures for this class
- fun create_class(mclass: MClass) do mclass.make_vt(self)
+ # Load the class and create its runtime structures, this loading is explicit
+ fun load_class(mclass: MClass)
+ do
+ if mclass.loaded then return
+
+ # Recursively load superclasses
+ for parent in mclass.in_hierarchy(mainmodule).direct_greaters do load_class_indirect(parent)
+
+ if mclass.abstract_loaded then
+ mclass.allocate_vtable(self)
+ else
+ mclass.make_vt(self, true)
+ end
+ end
+
+ # This method is called to handle an implicitly loaded class,
+ # i.e. a superclass of an explicitly loaded class
+ # A class loaded implicitly will not be fully allocated
+ fun load_class_indirect(mclass: MClass)
+ do
+ # It the class was already implicitly loaded
+ if mclass.abstract_loaded then return
+
+ for parent in mclass.in_hierarchy(mainmodule).direct_greaters do load_class_indirect(parent)
+
+ mclass.make_vt(self, false)
+ end
# Execute `mproperty` for a `args` (where `args[0]` is the receiver).
redef fun send(mproperty: MMethod, args: Array[Instance]): nullable Instance
# returns the most specific local method in the class corresponding to `vtable`
private fun method_dispatch(mproperty: MMethod, vtable: VTable, recv: Instance): MMethodDef
do
- if mproperty.intro_mclassdef.mclass.positions_methods[recv.mtype.as(MClassType).mclass] != -1 then
- return method_dispatch_sst(vtable.internal_vtable, mproperty.absolute_offset)
+ var position = recv.mtype.as(MClassType).mclass.get_position_methods(mproperty.intro_mclassdef.mclass)
+ if position > 0 then
+ return method_dispatch_sst(vtable.internal_vtable, mproperty.offset + position)
else
return method_dispatch_ph(vtable.internal_vtable, vtable.mask,
mproperty.intro_mclassdef.mclass.vtable.id, mproperty.offset)
assert recv isa MutableInstance
var i: Instance
-
- if mproperty.intro_mclassdef.mclass.positions_attributes[recv.mtype.as(MClassType).mclass] != -1 then
+ var position = recv.mtype.as(MClassType).mclass.get_position_attributes(mproperty.intro_mclassdef.mclass)
+ if position > 0 then
# if this attribute class has an unique position for this receiver, then use direct access
- i = read_attribute_sst(recv.internal_attributes, mproperty.absolute_offset)
+ i = read_attribute_sst(recv.internal_attributes, position + mproperty.offset)
else
# Otherwise, read the attribute value with perfect hashing
var id = mproperty.intro_mclassdef.mclass.vtable.id
assert recv isa MutableInstance
# Replace the old value of mproperty in recv
- if mproperty.intro_mclassdef.mclass.positions_attributes[recv.mtype.as(MClassType).mclass] != -1 then
+ var position = recv.mtype.as(MClassType).mclass.get_position_attributes(mproperty.intro_mclassdef.mclass)
+ if position > -1 then
# if this attribute class has an unique position for this receiver, then use direct access
- write_attribute_sst(recv.internal_attributes, mproperty.absolute_offset, value)
+ write_attribute_sst(recv.internal_attributes, position + mproperty.offset, value)
else
# Otherwise, use perfect hashing to replace the old value
var id = mproperty.intro_mclassdef.mclass.vtable.id
# True when the class is effectively loaded by the vm, false otherwise
var loaded: Bool = false
+ # Indicate this class was partially loaded (it only has its identifier allocated)
+ var abstract_loaded: Bool = false
+
# Color for Cohen subtyping test : the absolute position of the id
# of this class in virtual tables
var color: Int
- # For each loaded subclass, keep the position of the group of attributes
- # introduced by self class in the object
+ # For superclasses which have a non-invariant position, keep their position in attribute table
var positions_attributes: HashMap[MClass, Int] = new HashMap[MClass, Int]
- # For each loaded subclass, keep the position of the group of methods
- # introduced by self class in the vtable
+ # For superclasses which have a non-invariant position, keep their position in virtual table
var positions_methods: HashMap[MClass, Int] = new HashMap[MClass, Int]
+ # The position of the class' block in virtual table,
+ # the position is set to -1 when the invariant position is no longer satisfied
+ var position_attributes: Int
+
+ # The position of the class' block in attribute table
+ # the position is set to -1 when the invariant position is no longer satisfied
+ var position_methods: Int
+
+ # The chosen prefix for this class.
+ # The prefix is the direct superclass which has the most properties,
+ # this class will stay at its usual position in virtual table and attribute table
+ var prefix: nullable MClass
+
+ # The linear extension of all superclasses with the prefix rule
+ var ordering: Array[MClass]
+
# The `MAttribute` this class introduced
var intro_mattributes = new Array[MAttribute]
var mmethods = new Array[MMethod]
# Allocates a VTable for this class and gives it an id
- private fun make_vt(v: VirtualMachine)
+ # * `vm` The currently executed VirtualMachine
+ # * `explicit` Indicate if this class was directly instantiated (i.e. not indirectly loaded)
+ private fun make_vt(vm: VirtualMachine, explicit: Bool)
do
- if loaded then return
+ # `ordering` contains the order of superclasses for virtual tables
+ ordering = superclasses_ordering(vm)
+ ordering.remove(self)
- # `superclasses` contains the order of superclasses for virtual tables
- var superclasses = superclasses_ordering(v)
- superclasses.remove(self)
-
- # Make_vt for super-classes
var ids = new Array[Int]
var nb_methods = new Array[Int]
var nb_attributes = new Array[Int]
# and the second and third are respectively class id and delta
var offset_methods = 3
- # The previous element in `superclasses`
- var previous_parent: nullable MClass = null
- if superclasses.length > 0 then previous_parent = superclasses[0]
- for parent in superclasses do
- if not parent.loaded then parent.make_vt(v)
+ var parent
+ var prefix_index = ordering.index_of(prefix.as(not null))
+ for i in [0..ordering.length[ do
+ parent = ordering[i]
# Get the number of introduced methods and attributes for this class
var methods = parent.intro_mmethods.length
nb_methods.push(methods)
nb_attributes.push(attributes)
- # Update `positions_attributes` and `positions_methods` in `parent`.
- # If the position is invariant for this parent, store this position
- # else store a special value (-1)
- var pos_attr = -1
- var pos_meth = -1
-
- if previous_parent.as(not null).positions_attributes[parent] == offset_attributes then pos_attr = offset_attributes
- if previous_parent.as(not null).positions_methods[parent] == offset_methods then pos_meth = offset_methods
-
- parent.update_positions(pos_attr, pos_meth, self)
+ # If the class is in the suffix part of the order
+ if i > prefix_index then
+ moved_class_attributes(vm, ordering[i], offset_attributes)
+ moved_class_methods(vm, ordering[i], offset_methods)
+ end
offset_attributes += attributes
offset_methods += methods
offset_methods += 2 # Because each block starts with an id and the delta
end
- # When all super-classes have their identifiers and vtables, allocate current one
- allocate_vtable(v, ids, nb_methods, nb_attributes, offset_attributes, offset_methods)
- loaded = true
+ # Update the positions of the class
+ update_positions(offset_attributes, offset_methods)
- # Set the absolute position of the identifier of this class in the virtual table
- color = offset_methods - 2
+ ordering.add(self)
- # The virtual table now needs to be filled with pointer to methods
- superclasses.add(self)
- for cl in superclasses do
- fill_vtable(v, vtable.as(not null), cl)
+ # Compute the identifier with Perfect Hashing
+ compute_identifier(vm, ids, offset_methods)
+
+ # Update caches and offsets of methods and attributes for this class
+ # If the loading was explicit, the virtual table will be allocated and filled
+ set_offsets(vm, explicit)
+
+ if not explicit then
+ # Just init the C-pointer to NULL to avoid errors
+ vtable.internal_vtable = vm.memory_manager.null_ptr
end
end
- # Allocate a single vtable
- # * `ids : Array of superclasses identifiers
- # * `nb_methods : Array which contain the number of introduced methods for each class in ids
- # * `nb_attributes : Array which contain the number of introduced attributes for each class in ids
- # * `offset_attributes : Offset from the beginning of the table of the group of attributes
+ # Allocate a unique identifier to the class with perfect hashing
+ # * `vm` The currently executed VirtualMachine
+ # * `ids` Array of superclasses identifiers
# * `offset_methods : Offset from the beginning of the table of the group of methods
- private fun allocate_vtable(v: VirtualMachine, ids: Array[Int], nb_methods: Array[Int], nb_attributes: Array[Int],
- offset_attributes: Int, offset_methods: Int)
+ private fun compute_identifier(vm: VirtualMachine, ids: Array[Int], offset_methods: Int)
do
vtable = new VTable
var idc = new Array[Int]
- vtable.mask = v.ph.pnand(ids, 1, idc) - 1
+ # Give an identifier to the class and put it inside the virtual table
+ vtable.mask = vm.ph.pnand(ids, 1, idc) - 1
vtable.id = idc[0]
vtable.classname = name
- # Add current id to Array of super-ids
- var ids_total = new Array[Int]
- ids_total.add_all(ids)
- ids_total.push(vtable.id)
+ # Set the color for subtyping tests in SST of this class
+ color = offset_methods - 2
- var nb_methods_total = new Array[Int]
- var nb_attributes_total = new Array[Int]
+ # Indicate the class has its identifier computed
+ abstract_loaded = true
+ end
- var self_methods = 0
- var nb_introduced_attributes = 0
+ # Update the positions of this class
+ # * `offset_attributes` The offset of the block of attributes of this class
+ # * `offset_methods` The offset of the block of methods of this class
+ private fun update_positions(offset_attributes: Int, offset_methods: Int)
+ do
+ # Recopy the position tables of the prefix in `self`
+ for key, value in prefix.positions_methods do
+ positions_methods[key] = value
+ end
+ for key, value in prefix.positions_attributes do
+ positions_attributes[key] = value
+ end
+
+ # Save the offsets of self class
+ position_attributes = offset_attributes
+ position_methods = offset_methods
+ end
+
+ # Set the offsets for the properties introduced by `self` class
+ # * `vm` The currently executed VirtualMachine
+ # * `explicit` Indicate if this class was explicitly loaded
+ private fun set_offsets(vm: VirtualMachine, explicit: Bool)
+ do
# Fixing offsets for self attributes and methods
var relative_offset_attr = 0
var relative_offset_meth = 0
for p in classdef.intro_mproperties do
# Collect properties and fixing offsets
if p isa MMethod then
- self_methods += 1
p.offset = relative_offset_meth
- p.absolute_offset = offset_methods + relative_offset_meth
relative_offset_meth += 1
intro_mmethods.add(p)
end
if p isa MAttribute then
- nb_introduced_attributes += 1
p.offset = relative_offset_attr
- p.absolute_offset = offset_attributes + relative_offset_attr
relative_offset_attr += 1
intro_mattributes.add(p)
mattributes.add_all(intro_mattributes)
mmethods.add_all(intro_mmethods)
- nb_methods_total.add_all(nb_methods)
- nb_methods_total.push(self_methods)
+ if explicit then allocate_vtable(vm)
+ end
- nb_attributes_total.add_all(nb_attributes)
- nb_attributes_total.push(nb_introduced_attributes)
+ # Allocate a single vtable
+ # * `vm` The currently executed VirtualMachine
+ private fun allocate_vtable(vm: VirtualMachine)
+ do
+ var ids = new Array[Int]
+ var nb_methods_total = new Array[Int]
+ var nb_attributes_total = new Array[Int]
- # Save the offsets of self class
- update_positions(offset_attributes, offset_methods, self)
+ for cl in ordering do
+ ids.add(cl.vtable.id)
+ nb_methods_total.add(cl.intro_mmethods.length)
+ nb_attributes_total.add(cl.intro_mattributes.length)
+ end
- # Since we have the number of attributes for each class, calculate the delta
+ # Calculate the delta to prepare object structure
var deltas = calculate_delta(nb_attributes_total)
- vtable.internal_vtable = v.memory_manager.init_vtable(ids_total, nb_methods_total, deltas, vtable.mask)
+ vtable.internal_vtable = vm.memory_manager.init_vtable(ids, nb_methods_total, deltas, vtable.mask)
+
+ # The virtual table now needs to be filled with pointer to methods
+ for cl in ordering do
+ fill_vtable(vm, vtable.as(not null), cl)
+ end
+
+ loaded = true
end
- # Fill the vtable with methods of `self` class
- # * `v` : Current instance of the VirtualMachine
- # * `table` : the table of self class, will be filled with its methods
- private fun fill_vtable(v:VirtualMachine, table: VTable, cl: MClass)
+ # Fill the vtable with local methods for `self` class
+ # * `vm` Current instance of the VirtualMachine
+ # * `table` the table of self class, will be filled with its methods
+ # * `cl` The class which introduced the methods
+ private fun fill_vtable(vm: VirtualMachine, table: VTable, cl: MClass)
do
var methods = new Array[MMethodDef]
for m in cl.intro_mmethods do
# `propdef` is the most specific implementation for this MMethod
- var propdef = m.lookup_first_definition(v.mainmodule, self.intro.bound_mtype)
+ var propdef = m.lookup_first_definition(vm.mainmodule, self.intro.bound_mtype)
methods.push(propdef)
end
# Call a method in C to put propdefs of self methods in the vtables
- v.memory_manager.put_methods(vtable.internal_vtable, vtable.mask, cl.vtable.id, methods)
+ vm.memory_manager.put_methods(vtable.internal_vtable, vtable.mask, cl.vtable.id, methods)
end
# Computes delta for each class
return ordering
else
# There is no super-class, self is Object
+ prefix = self
return superclasses
end
end
end
if prefix != null then
+ if self.prefix == null then self.prefix = prefix
+
# Add the prefix class ordering at the beginning of our sequence
var prefix_res = new Array[MClass]
prefix_res = prefix.dfs(v, prefix_res)
res.push(self)
else
if direct_parents.length > 0 then
+ if prefix == null then prefix = direct_parents.first
+
res = direct_parents.first.dfs(v, res)
end
end
return res
end
- # Update positions of the class `cl`
- # * `attributes_offset`: absolute offset of introduced attributes
- # * `methods_offset`: absolute offset of introduced methods
- private fun update_positions(attributes_offsets: Int, methods_offset:Int, cl: MClass)
+ # This method is called when `current_class` class is moved in virtual table of `self`
+ # *`vm` Running instance of the virtual machine
+ # *`current_class` The class which was moved in `self` structures
+ # *`offset` The offset of block of methods of `current_class` in `self`
+ fun moved_class_methods(vm: VirtualMachine, current_class: MClass, offset: Int)
do
- positions_attributes[cl] = attributes_offsets
- positions_methods[cl] = methods_offset
+ # `current_class` was moved in `self` method table
+ if current_class.position_methods > 0 then
+ # The invariant position is no longer satisfied
+ current_class.positions_methods[current_class] = current_class.position_methods
+ current_class.position_methods = - current_class.position_methods
+ else
+ # The class has already several positions and an update is needed
+ current_class.positions_methods[current_class] = -current_class.positions_methods[current_class]
+
+ for sub in ordering do
+ if sub == current_class then continue
+
+ var super_id = current_class.vtable.id
+ var mask = sub.vtable.mask
+ vm.load_class(sub)
+
+ if vm.inter_is_subtype_ph(super_id, mask, sub.vtable.internal_vtable) then
+ if not sub.positions_methods.has_key(current_class) then
+ sub.positions_methods[current_class] = current_class.position_methods
+ else
+ var old_position = sub.positions_methods[current_class]
+ if old_position > 0 then
+ # Indicate this class can not used anymore single inheritance implementation
+ sub.positions_methods[current_class] = - old_position
+ end
+ end
+ end
+ end
+ end
+
+ # Save the position of `current_class` in `self`
+ positions_methods[current_class] = offset
end
+
+ # This method is called when `current_class` class is moved in attribute table of `self`
+ # *`vm` Running instance of the virtual machine
+ # *`current_class` The class which was moved in `self` structures
+ # *`offset` The offset of block of attributes of `current_class` in `self`
+ fun moved_class_attributes(vm: VirtualMachine, current_class: MClass, offset: Int)
+ do
+ # `current_class` was moved in `self` attribute table
+ if not current_class.positions_attributes.has_key(current_class) then
+ # The invariant position is no longer satisfied
+ current_class.positions_attributes[current_class] = current_class.position_attributes
+ current_class.position_attributes = - current_class.position_attributes
+ else
+ # The class has already several positions and an update is needed
+ current_class.positions_attributes[current_class] = - current_class.positions_attributes[current_class]
+
+ for sub in ordering do
+ if sub == current_class then continue
+
+ var super_id = current_class.vtable.id
+ var mask = sub.vtable.mask
+ vm.load_class(sub)
+
+ if vm.inter_is_subtype_ph(super_id, mask, sub.vtable.internal_vtable) then
+ if not sub.positions_methods.has_key(current_class) then
+ sub.positions_attributes[current_class] = current_class.position_attributes
+ else
+ var old_position = sub.positions_attributes[current_class]
+ if old_position > 0 then
+ # Indicate this class can not used anymore single inheritance implementation
+ sub.positions_attributes[current_class] = - old_position
+ end
+ end
+ end
+ end
+ end
+
+ # Save the position of `current_class` in `self`
+ positions_attributes[current_class] = offset
+ end
+
+ # Return the position of the method's block of class `cl` in `self` if `cl` has an invariant position in self,
+ # Otherwise return a negative position
+ fun get_position_methods(cl: MClass): Int
+ do
+ # The class has an invariant position in all subclasses
+ if cl.position_methods > 0 then return cl.position_methods
+
+ # The position has an invariant position for this class and its subclasses only
+ if positions_methods.has_key(cl) then
+ var pos = positions_methods[cl]
+ if pos > 0 then return pos
+ return -1
+ end
+
+ # No invariant position at all, the caller must use a multiple inheritance implementation
+ return -1
+ end
+
+ # Return the position of the attribute's block of class `cl` in `self` if `cl` has an invariant position in self,
+ # Otherwise return a negative position
+ fun get_position_attributes(cl: MClass): Int
+ do
+ # The class has an invariant position in all subclasses
+ if cl.position_attributes > 0 then return cl.position_attributes
+
+ # The position has an invariant position for this class and its subclasses only
+ if positions_attributes.has_key(cl) then
+ var pos = positions_attributes[cl]
+ if pos > 0 then return pos
+ return -1
+ end
+
+ # No invariant position at all, the caller must use a multiple inheritance implementation
+ return -1
+ end
+end
+
+redef class MProperty
+ # Relative offset of this in the runtime instance
+ # (beginning of the block of its introducing class for attributes or methods)
+ var offset: Int
end
redef class MAttribute
# Relative offset of this attribute in the runtime instance
# (beginning of the block of its introducing class)
- var offset: Int
-
- # Absolute offset of this attribute in the runtime instance (beginning of the attribute table)
- var absolute_offset: Int
+ redef var offset: Int
end
redef class MMethod
# Relative offset of this method in the virtual table (from the beginning of the block)
- var offset: Int
-
- # Absolute offset of this method in the virtual table (from the beginning of the vtable)
- var absolute_offset: Int
+ redef var offset: Int
end
# Redef MutableInstance to improve implementation of attributes in objects
MMethodDef_incr_ref(method);
}
`}
+
+ # Return a NULL pointer, used to initialize virtual tables
+ private fun null_ptr: Pointer `{
+ return NULL;
+ `}
end
callsite.id, callsite.offset)
end
+ #TODO : we need recompilations here
+ callsite.status = 0
return self.call(propdef, args)
end
end
# * `recv` The receiver (The object) of the access
protected fun optimize(mproperty: MAttribute, recv: MutableInstance)
do
- if mproperty.intro_mclassdef.mclass.positions_attributes[recv.mtype.as(MClassType).mclass] != -1 then
+ var position = recv.mtype.as(MClassType).mclass.get_position_attributes(mproperty.intro_mclassdef.mclass)
+ if position > 0 then
# if this attribute class has an unique position for this receiver, then use direct access
- offset = mproperty.absolute_offset
+ offset = position + mproperty.offset
status = 1
else
# Otherwise, perfect hashing must be used
abort
end
+ #TODO : we need recompilations here
+ status = 0
+
return i
end
end
v.write_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable,
recv.vtable.mask, id, offset, i)
end
+
+ #TODO : we need recompilations here
+ status = 0
end
end
# Otherwise we must use perfect hashing
fun optimize(recv: Instance)
do
- if mproperty.intro_mclassdef.mclass.positions_methods[recv.mtype.as(MClassType).mclass] != -1 then
- offset = mproperty.absolute_offset
+ var position = recv.mtype.as(MClassType).mclass.get_position_methods(mproperty.intro_mclassdef.mclass)
+ if position > 0 then
+ offset = position + mproperty.offset
status = 1
else
offset = mproperty.offset
var recv = v.expr(self.n_expr)
if recv == null then return null
- if status == 0 then optimize(v, recv.mtype, self.cast_type.as(not null))
+ optimize(v, recv.mtype, self.cast_type.as(not null))
var mtype = v.unanchor_type(self.cast_type.as(not null))
# If this test can be optimized, directly call appropriate subtyping methods
return
end
- if not target.mclass.loaded then return
+ if not target.mclass.abstract_loaded then return
- # Try to get the position of the target type in source's structures
- var value = source.mclass.positions_methods.get_or_null(target.mclass)
-
- if value != null then
- if value != -1 then
- # Store informations for Cohen test
- position = target.mclass.color
- status = 1
- else
- # We use perfect hashing
- status = 2
- end
+ # If the value is positive, the target class has an invariant position in source's structures
+ var value = source.mclass.get_position_methods(target.mclass)
+
+ if value > 0 then
+ # `value - 2` is the position of the target identifier in source vtable
+ position = value - 2
+ status = 1
+ else
+ # We use perfect hashing
+ status = 2
end
id = target.mclass.vtable.id
end
var recv = v.expr(self.n_expr)
if recv == null then return null
- if status == 0 then optimize(v, recv.mtype, self.mtype.as(not null))
+ optimize(v, recv.mtype, self.mtype.as(not null))
var mtype = self.mtype.as(not null)
var amtype = v.unanchor_type(mtype)
if not target.mclass.loaded then return
- # Try to get the position of the target type in source's structures
- var value = source.mclass.positions_methods.get_or_null(target.mclass)
-
- if value != null then
- if value != -1 then
- # Store informations for Cohen test
- position = target.mclass.color
- status = 1
- else
- # We use perfect hashing
- status = 2
- end
+ # If the value is positive, the target class has an invariant position in source's structures
+ var value = source.mclass.get_position_methods(target.mclass)
+
+ if value > 0 then
+ # `value - 2` is the position of the target identifier in source vtable
+ position = value - 2
+ status = 1
+ else
+ # We use perfect hashing
+ status = 2
end
id = target.mclass.vtable.id
end
printf( "received msg: %s, of length = %d\n", c_msg, msg_len );
/* A_my_attr is a callback to the getter of self.my_attr */
- printf( "old attr %d\n", A_my_attr(recv) );
+ printf( "old attr %d\n", A_my_attr(self) );
if(chose)
truc;
chose;
/* A_my_attr is a callback to the setter of self.my_attr= */
- A_my_attr__assign( recv, msg_len );
+ A_my_attr__assign( self, msg_len );
`}
end
extern class TimeT `{time_t`}
new `{ return time(NULL); `}
new from_i(i: Int) `{ return i; `}
- fun update `{ time(&recv); `}
+ fun update `{ time(&self); `}
fun ctime: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy( ctime(&recv) );
+ return NativeString_to_s_with_copy( ctime(&self) );
`}
# Difference in secondes from start (self if the end time)
- fun difftime(start: TimeT): Float `{ return difftime(recv, start); `}
+ fun difftime(start: TimeT): Float `{ return difftime(self, start); `}
private fun intern_poll(in_fds: Array[Int], out_fds: Array[Int]): nullable Int is
extern import Array[Int].length, Array[Int].[], Int.as(nullable Int) `{`}
fun address_is_null: Bool is extern "address_is_null"
-fun free `{ free(recv); `}
+fun free `{ free(self); `}
printf( "received msg: %s, of length = %d\n", c_msg, msg_len );
/* A_my_attr is a callback to the getter of self.my_attr */
- printf( "old attr %d\n", A_my_attr(recv) );
+ printf( "old attr %d\n", A_my_attr(self) );
if(chose)
truc;
chose;
/* A_my_attr is a callback to the setter of self.my_attr= */
- A_my_attr__assign( recv, msg_len );
+ A_my_attr__assign( self, msg_len );
`}
end
new `{ return time(NULL); `}
new from_i(i: Int) `{ return i; `}
- fun update `{ time(&recv); `}
+ fun update `{ time(&self); `}
fun ctime: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy( ctime(&recv) );
+ return NativeString_to_s_with_copy( ctime(&self) );
`}
# Difference in secondes from start (self if the end time)
- fun difftime(start: TimeT): Float `{ return difftime(recv, start); `}
+ fun difftime(start: TimeT): Float `{ return difftime(self, start); `}
private fun intern_poll(in_fds: Array[Int], out_fds: Array[Int]): nullable Int is
extern import Array[Int].length, Array[Int].[], Int.as(nullable Int) `{`}
fun address_is_null: Bool is extern "address_is_null"
-fun free `{ free(recv); `}
+fun free `{ free(self); `}
if name == "Array[nullable Object]" then return new Array[nullable Object].from_deserializer(self)
if name == "Array[Serializable]" then return new Array[Serializable].from_deserializer(self)
if name == "Array[String]" then return new Array[String].from_deserializer(self)
- if name == "HashMap[Serializable, Array[Couple[Serializable, Int]]]" then return new HashMap[Serializable, Array[Couple[Serializable, Int]]].from_deserializer(self)
- if name == "Array[Couple[Serializable, Int]]" then return new Array[Couple[Serializable, Int]].from_deserializer(self)
- if name == "Couple[Serializable, Int]" then return new Couple[Serializable, Int].from_deserializer(self)
return super
end
end
+++ /dev/null
-28
-ハaロЖー𐍃a世界 ᓀ . ᓂ A,𐍆 a日本A語aです
-ハaロЖー𐍃a世界 ᓀ . ᓂ A,𐍆 a日本A語aです
-すでa語A本日a 𐍆,A ᓂ . ᓀ 界世a𐍃ーЖロaハ
-ー𐍃a世
-世a𐍃ー
-世a𐍃ー
-ー𐍃a世
-すでa語A本日a 𐍆,A ᓂ . ᓀ 界世a𐍃ーЖロaハ
-ハaロЖー𐍃a世界 ᓀ . ᓂ A,𐍆 a日本A語aです
-ハAロЖー𐍃A世界 ᓀ . ᓂ A,𐍆 A日本A語Aです
-ハaロЖー𐍃a世界 ᓀ . ᓂ a,𐍆 a日本a語aです
-aハロЖー𐍃a世界 ᓀ . ᓂ A,𐍆 a日本A語aです
-aハロЖー𐍃a世界 ᓀ . ᓂ a,𐍆 a日本a語aです
-AハロЖー𐍃A世界 ᓀ . ᓂ A,𐍆 A日本A語Aです
-すでA語A本日A 𐍆,A ᓂ . ᓀ 界世A𐍃ーЖロハA
char* string = "This is a test string";
FlatString ref_string = NativeString_to_s(string);
- StringTest_ref_test(recv, ref_string);
+ StringTest_ref_test(self, ref_string);
FlatString copy_string = NativeString_to_s_with_copy(string);
- StringTest_copy_test(recv, copy_string);
+ StringTest_copy_test(self, copy_string);
int same_refs = FlatString_items(copy_string) == FlatString_items(ref_string);
info = curl.easy_getinfo_long(new CURLInfoLong.rtsp_server_cseq)
assert infoResp:info != null
-info = curl.easy_getinfo_long(new CURLInfoLong.rtsp_cseq_recv)
+info = curl.easy_getinfo_long(new CURLInfoLong.rtsp_cseq_self)
assert infoResp:info != null
# Double
fun print_all import String.to_cstring, r, rw `{
printf( "%s %s\n",
- String_to_cstring( A_r( recv ) ),
- String_to_cstring( A_rw( recv ) ) );
+ String_to_cstring( A_r( self ) ),
+ String_to_cstring( A_rw( self ) ) );
`}
fun modify import NativeString.to_s, w=, rw= `{
- A_w__assign( recv, NativeString_to_s( "w set from native" ) );
- A_rw__assign( recv, NativeString_to_s( "rw set from native" ) );
+ A_w__assign( self, NativeString_to_s( "w set from native" ) );
+ A_rw__assign( self, NativeString_to_s( "rw set from native" ) );
`}
end
int i;
for(i = 0; i < 2000; ++i) {
printf("%d\n", i);
- Test_foo(recv, NativeString_to_s("asdf"));
+ Test_foo(self, NativeString_to_s("asdf"));
}
`}
fun foo do print "foo"
fun call_a_fun import foo `{
- Sys_foo(recv);
+ Sys_foo(self);
`}
fun call_a_constructor import A, A.bar `{
if ( n == 1 )
return 1;
else
- return FibonacciEngine_fibonacci( recv, n-1 ) + FibonacciEngine_fibonacci( recv, n-2 );
+ return FibonacciEngine_fibonacci( self, n-1 ) + FibonacciEngine_fibonacci( self, n-2 );
`}
end
redef class Int
fun fibonacci : Int import fibonacci `{
- if ( recv == 0 )
+ if ( self == 0 )
return 0;
- else if ( recv == 1 )
+ else if ( self == 1 )
return 1;
else
- return Int_fibonacci( recv-1 ) + Int_fibonacci( recv-2 );
+ return Int_fibonacci( self-1 ) + Int_fibonacci( self-2 );
`}
end
`}
fun []=(i: Int, v: A) `{
- recv[i] = v;
+ self[i] = v;
A_incr_ref(v);
`}
fun [](i: Int): A `{
- return recv[i];
+ return self[i];
`}
end
`}
fun p : Int import m `{
- return A_m( recv ) + 5;
+ return A_m( self ) + 5;
`}
fun in_language : Int is extern in "C" `{
fun out(i: Int, f: Float): Int import in1, in2, A, A.alt, A.to_i `{
printf("From C, beginning out: %ld\n", i);
- Sys_in1(recv, i);
+ Sys_in1(self, i);
A a = new_A();
A b = new_A_alt(10);
printf("From C, a=%ld\n", A_to_i(a));
fun a do print "a"
fun p `{
- printf( "allo from %i\n", *recv );
+ printf( "allo from %i\n", *self );
`}
fun d : A import d, A `{
return new_A();
`}
redef fun to_s import NativeString, NativeString.to_s `{
- int len = snprintf(NULL, 0, "%d", *recv) + 1;
+ int len = snprintf(NULL, 0, "%d", *self) + 1;
char *c = new_NativeString(len);
- sprintf(c, "%d", *recv);
+ sprintf(c, "%d", *self);
return NativeString_to_s(c);
`}
end
init(value: Int) do self.value = value
fun +(other: A): A import value, A `{
- int s = A_value( recv );
+ int s = A_value( self );
int o = A_value( other );
return new_A( s + o );
`}
fun +: A import value, A `{
- int s = A_value(recv);
+ int s = A_value(self);
return new_A(+s);
`}
fun -(other: A): A import value, A `{
- int s = A_value( recv );
+ int s = A_value( self );
int o = A_value( other );
return new_A( s - o );
`}
fun -: A import value, A `{
- int s = A_value(recv);
+ int s = A_value(self);
return new_A(-s);
`}
fun *(by: Int): A import value, A `{
- int s = A_value( recv );
+ int s = A_value( self );
return new_A( s * by );
`}
fun /(by: Int): A import value, A `{
- int s = A_value( recv );
+ int s = A_value( self );
return new_A( s / by );
`}
redef fun ==(other) import value, nullable Object.as(A) `{
if ( nullable_Object_is_a_A( other ) &&
- A_value( nullable_Object_as_A(other) ) == A_value( recv ) )
+ A_value( nullable_Object_as_A(other) ) == A_value( self ) )
return 1;
else
return 0;
`}
fun %(other: A): A import value, A `{
- return new_A( A_value( recv ) % A_value( other ) );
+ return new_A( A_value( self ) % A_value( other ) );
`}
fun <=>(other: A): A import value, A `{
- return new_A( A_value( recv )* 1024 );
+ return new_A( A_value( self )* 1024 );
`}
fun >(other: A): Bool import value `{
- return A_value( recv ) > A_value( other );
+ return A_value( self ) > A_value( other );
`}
fun <(other: A): Bool import value `{
- return A_value( recv ) < A_value( other );
+ return A_value( self ) < A_value( other );
`}
fun >=(other: A): Bool import value `{
- return A_value( recv ) >= A_value( other );
+ return A_value( self ) >= A_value( other );
`}
fun <=(other: A): Bool import value `{
- return A_value( recv ) <= A_value( other );
+ return A_value( self ) <= A_value( other );
`}
fun >>(other: A): A import value, value=, A `{
- int new_val = A_value( recv ) >> A_value( other );
+ int new_val = A_value( self ) >> A_value( other );
return new_A(new_val);
`}
fun <<(other: A): A import value, A `{
- int new_val = A_value( recv ) << A_value( other );
+ int new_val = A_value( self ) << A_value( other );
return new_A(new_val);
`}
fun |(other: A): A import value, A `{
- int new_val = A_value( recv ) | A_value( other );
+ int new_val = A_value( self ) | A_value( other );
return new_A(new_val);
`}
fun ^(other: A): A import value, A `{
- int new_val = A_value( recv ) ^ A_value( other );
+ int new_val = A_value( self ) ^ A_value( other );
return new_A(new_val);
`}
fun ~: A import value, A `{
- int new_val = ~A_value( recv );
+ int new_val = ~A_value( self );
return new_A(new_val);
`}
fun &(other: A): A import value, A `{
- int new_val = A_value( recv ) & A_value( other );
+ int new_val = A_value( self ) & A_value( other );
return new_A(new_val);
`}
redef fun id : String import super, NativeString.to_s, String.to_cstring `{
char *new_name;
char *prefix = "B special ";
- char *super_name = String_to_cstring( B_id___super( recv ) );
+ char *super_name = String_to_cstring( B_id___super( self ) );
new_name = calloc( strlen( prefix )+strlen( super_name )+1, sizeof(char) );
strcpy( new_name, prefix );
return v;
`}
fun p `{
- printf( "A< %d %d >\n", recv->x, recv->y );
+ printf( "A< %d %d >\n", self->x, self->y );
`}
end
`}
redef fun p import super `{
printf( "B< " );
- B_p___super(recv);
- printf( " %d %d >\n", recv->w, recv->h );
+ B_p___super(self);
+ printf( " %d %d >\n", self->w, self->h );
`}
end
return v;
`}
redef fun p `{
- printf( "C< %d %d >\n", recv->x, recv->y );
+ printf( "C< %d %d >\n", self->x, self->y );
`}
end
# Adds an element to the end of the vector
fun push(v: Int) in "C++" `{
- recv->push_back(v);
+ self->push_back(v);
`}
# Pops an element from the end of the vector
fun pop: Int in "C++" `{
- long val = recv->back();
- recv->pop_back();
+ long val = self->back();
+ self->pop_back();
return val;
`}
fun safe_pop_with_default(default_return: Int): Int import report_error in "C++" `{
- if (recv->empty()) {
- CppVector_report_error(recv);
+ if (self->empty()) {
+ CppVector_report_error(self);
return default_return;
} else {
- long val = recv->back();
- recv->pop_back();
+ long val = self->back();
+ self->pop_back();
return val;
}
`}
# Adds an element to the end of the vector
fun push(v: Int) in "C++" `{
- recv->push_back(v);
+ self->push_back(v);
`}
# Pops an element from the end of the vector
fun pop: Int in "C++" `{
- long val = recv->back();
- recv->pop_back();
+ long val = self->back();
+ self->pop_back();
return val;
`}
# Uses a callback to report when receiver is empty
fun safe_pop_with_default(default_return: Int): Int import report_error in "C++" `{
- if (recv->empty()) {
- CppVector_report_error(recv);
+ if (self->empty()) {
+ CppVector_report_error(self);
return default_return;
} else {
- long val = recv->back();
- recv->pop_back();
+ long val = self->back();
+ self->pop_back();
return val;
}
`}
# Prints the given string when receiver is empty
fun safe_pop_with_custom_error(default_return: Int, error_msg: String): Int import String.to_cpp_string in "C++" `{
- if (recv->empty()) {
+ if (self->empty()) {
string *cpp_error_msg = String_to_cpp_string(error_msg);
cout << *cpp_error_msg << "\n";
return default_return;
} else {
- long val = recv->back();
- recv->pop_back();
+ long val = self->back();
+ self->pop_back();
return val;
}
`}
# Adds an element to the end of the vector
fun push(v: Int) in "C++" `{
- recv->push_back(v);
+ self->push_back(v);
`}
# Pops an element from the end of the vector
fun pop: Int in "C++" `{
- long val = recv->back();
- recv->pop_back();
+ long val = self->back();
+ self->pop_back();
return val;
`}
end
fun i: Int do return 777
fun foo import bar, i in "Java" `{
- A_bar(recv);
- long i = A_i(recv);
+ A_bar(self);
+ long i = A_i(self);
System.out.println(i);
`}
return new LinkedBlockingQueue<String>();
`}
- fun offer(o: JavaString) in "Java" `{ recv.offer(o); `}
+ fun offer(o: JavaString) in "Java" `{ self.offer(o); `}
- fun remove: JavaString in "Java" `{ return recv.remove(); `}
+ fun remove: JavaString in "Java" `{ return self.remove(); `}
redef fun output in "Java" `{
- for (String s: recv) {
+ for (String s: self) {
System.out.println(s);
}
`}
System.out.println(input);
// Callback Nit with string
- String str = A_bar(recv, "Created in Java");
+ String str = A_bar(self, "Created in Java");
System.out.println(str);
// Send back a string
return new ArrayList();
`}
- fun add(o: JavaString) in "Java" `{ recv.add(o); `}
+ fun add(o: JavaString) in "Java" `{ self.add(o); `}
redef fun output in "Java" `{
- for (Object i: recv) {
+ for (Object i: self) {
System.out.println((String)i);
}
`}
fun sort in "Java" `{
- Collections.sort(recv);
+ Collections.sort(self);
`}
end
printf("From Objective-C: %ld %f %s\n", ii, f, cstr);
- Sys_bar(recv, ii, f, s);
+ Sys_bar(self, ii, f, s);
`}
fun bar(i: Int, f: Float, s: String)
printf( "received msg: %s, of length = %d\n", c_msg, msg_len );
/* A_my_attr is a callback to the getter of self.my_attr */
- printf( "old attr %d\n", A_my_attr(recv) );
+ printf( "old attr %d\n", A_my_attr(self) );
if(chose)
truc;
chose;
/* A_my_attr is a callback to the setter of self.my_attr= */
- A_my_attr__assign( recv, msg_len );
+ A_my_attr__assign( self, msg_len );
`}
end
new `{ return time(NULL); `}
new from_i(i: Int) `{ return i; `}
- fun update `{ time(&recv); `}
+ fun update `{ time(&self); `}
fun ctime: String import NativeString.to_s_with_copy `{
- return NativeString_to_s_with_copy( ctime(&recv) );
+ return NativeString_to_s_with_copy( ctime(&self) );
`}
# Difference in secondes from start (self if the end time)
- fun difftime(start: TimeT): Float `{ return difftime(recv, start); `}
+ fun difftime(start: TimeT): Float `{ return difftime(self, start); `}
private fun intern_poll(in_fds: Array[Int], out_fds: Array[Int]) : nullable Int is extern import Array[Int].length, Array[Int].[], Int.as(nullable Int) `{`}
end
fun address_is_null: Bool is extern "address_is_null"
-fun free `{ free(recv); `}
+fun free `{ free(self); `}
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# This file is free software, which comes along with NIT. This software is
-# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE. You can modify it is you want, provided this header
-# is kept unaltered, and a notification of the changes is added.
-# You are allowed to redistribute it and sell it, alone or is a part of
-# another product.
-
-import standard
-intrude import string_experimentations::utf8_noindex
-
-var s = "aàハ𐍆".as(FlatString)
-assert s.char_at(0).code_point == 97
-assert s.char_at(1).code_point == 224
-assert s.char_at(2).code_point == 12495
-assert s.char_at(3).code_point == 66374
-
-var str = "ハaロЖー𐍃a世界 ᓀ . ᓂ A,𐍆 a日本A語aです".as(FlatString)
-
-print str.length
-print str
-
-for i in [0 .. str.length[ do
- str.char_at(i).output
-end
-
-'\n'.output
-
-var ss = str.reversed.as(FlatString)
-
-for i in [0 .. ss.length[ do ss.char_at(i).output
-
-'\n'.output
-
-var x = str.substring(4,4).as(FlatString)
-
-for i in [0 .. x.length[ do x.char_at(i).output
-
-'\n'.output
-
-var xx = x.reversed.as(FlatString)
-
-for i in [0 .. xx.length[ do xx.char_at(i).output
-
-'\n'.output
-
-var it = new FlatStringReviter(x)
-for i in it do
- i.output
-end
-
-'\n'.output
-
-var it2 = new FlatStringIter(x)
-for i in it2 do
- i.output
-end
-
-'\n'.output
-
-it = new FlatStringReviter(str)
-for i in it do
- i.output
-end
-
-'\n'.output
-
-it2 = new FlatStringIter(str)
-for i in it2 do
- i.output
-end
-
-'\n'.output
-
-assert str * 2 == str + str
-
-assert x * 2 == x + x
-
-print str.to_upper
-
-print str.to_lower
-
-var buf = new FlatBuffer.from(str)
-
-buf.append str
-
-var bf = new FlatBuffer.from(str)
-
-bf.times(2)
-
-assert bf == buf
-
-var bf2 = new FlatBuffer.from(str)
-
-bf2.char_at(0) = str.char_at(1)
-bf2.char_at(1) = str.char_at(0)
-
-for i in [0 .. bf2.length[ do bf2.char_at(i).output
-
-'\n'.output
-
-bf2.lower
-
-for i in [0 .. bf2.length[ do bf2.char_at(i).output
-
-'\n'.output
-
-bf2.upper
-
-for i in [0 .. bf2.length[ do bf2.char_at(i).output
-
-'\n'.output
-
-bf2.reverse
-
-for i in [0 .. bf2.length[ do bf2.char_at(i).output
-
-'\n'.output