vala r1952 - in trunk: . gobject
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1952 - in trunk: . gobject
- Date: Sun, 2 Nov 2008 15:15:43 +0000 (UTC)
Author: juergbi
Date: Sun Nov 2 15:15:42 2008
New Revision: 1952
URL: http://svn.gnome.org/viewvc/vala?rev=1952&view=rev
Log:
2008-11-02 JÃrg Billeter <j bitron ch>
* gobject/valaccodegenerator.vala:
* gobject/valaccodeinvocationexpressionmodule.vala:
* gobject/valaccodemethodmodule.vala:
Add partial support for calling coroutines from other coroutines
Modified:
trunk/ChangeLog
trunk/gobject/valaccodegenerator.vala
trunk/gobject/valaccodeinvocationexpressionmodule.vala
trunk/gobject/valaccodemethodmodule.vala
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Sun Nov 2 15:15:42 2008
@@ -1900,6 +1900,25 @@
stmt.ccodenode = new CCodeExpressionStatement ((CCodeExpression) stmt.expression.ccodenode);
+ var invoc = stmt.expression as InvocationExpression;
+ if (invoc != null) {
+ var m = invoc.call.symbol_reference as Method;
+ var ma = invoc.call as MemberAccess;
+ if (m != null && m.coroutine && (ma == null || ma.member_name != "begin"
+ || ma.inner.symbol_reference != ma.symbol_reference)) {
+ var cfrag = new CCodeFragment ();
+
+ int state = next_coroutine_state++;
+
+ cfrag.append (stmt.ccodenode);
+ cfrag.append (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "state"), new CCodeConstant (state.to_string ()))));
+ cfrag.append (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
+ cfrag.append (new CCodeCaseStatement (new CCodeConstant (state.to_string ())));
+
+ stmt.ccodenode = cfrag;
+ }
+ }
+
if (stmt.tree_can_fail && stmt.expression.tree_can_fail) {
// simple case, no node breakdown necessary
Modified: trunk/gobject/valaccodeinvocationexpressionmodule.vala
==============================================================================
--- trunk/gobject/valaccodeinvocationexpressionmodule.vala (original)
+++ trunk/gobject/valaccodeinvocationexpressionmodule.vala Sun Nov 2 15:15:42 2008
@@ -349,8 +349,14 @@
}
if (m != null && m.coroutine) {
- carg_map.set (codegen.get_param_pos (-1), new CCodeConstant ("NULL"));
- carg_map.set (codegen.get_param_pos (-0.9), new CCodeConstant ("NULL"));
+ if (ma.member_name == "begin" && ma.inner.symbol_reference == ma.symbol_reference) {
+ // asynchronous begin call
+ carg_map.set (codegen.get_param_pos (-1), new CCodeConstant ("NULL"));
+ carg_map.set (codegen.get_param_pos (-0.9), new CCodeConstant ("NULL"));
+ } else {
+ carg_map.set (codegen.get_param_pos (-1), new CCodeIdentifier (codegen.current_method.get_cname () + "_ready"));
+ carg_map.set (codegen.get_param_pos (-0.9), new CCodeIdentifier ("data"));
+ }
}
if (expr.tree_can_fail) {
Modified: trunk/gobject/valaccodemethodmodule.vala
==============================================================================
--- trunk/gobject/valaccodemethodmodule.vala (original)
+++ trunk/gobject/valaccodemethodmodule.vala Sun Nov 2 15:15:42 2008
@@ -257,8 +257,29 @@
if (m.coroutine) {
var cswitch = new CCodeSwitchStatement (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "state"));
+
+ // initial coroutine state
cswitch.add_statement (new CCodeCaseStatement (new CCodeConstant ("0")));
+
+ // coroutine body
cswitch.add_statement (codegen.function.block);
+
+ // complete async call by invoking callback
+ var object_creation = new CCodeFunctionCall (new CCodeIdentifier ("g_object_newv"));
+ object_creation.add_argument (new CCodeConstant ("G_TYPE_OBJECT"));
+ object_creation.add_argument (new CCodeConstant ("0"));
+ object_creation.add_argument (new CCodeConstant ("NULL"));
+
+ var async_result_creation = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_new"));
+ async_result_creation.add_argument (object_creation);
+ async_result_creation.add_argument (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "callback"));
+ async_result_creation.add_argument (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "user_data"));
+ async_result_creation.add_argument (new CCodeIdentifier ("data"));
+
+ var completecall = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_complete"));
+ completecall.add_argument (async_result_creation);
+ cswitch.add_statement (new CCodeExpressionStatement (completecall));
+
cswitch.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
codegen.function.block = new CCodeBlock ();
@@ -546,6 +567,7 @@
datastruct.add_field ("int", "state");
datastruct.add_field ("GAsyncReadyCallback", "callback");
datastruct.add_field ("gpointer", "user_data");
+ datastruct.add_field ("GAsyncResult*", "res");
foreach (FormalParameter param in m.get_parameters ()) {
datastruct.add_field (param.parameter_type.get_cname (), param.name);
@@ -623,6 +645,33 @@
finishfunc.block = finishblock;
codegen.source_type_member_definition.append (finishfunc);
+
+ // generate ready callback handler
+ var readyfunc = new CCodeFunction (m.get_cname () + "_ready", "void");
+ readyfunc.line = codegen.function.line;
+
+ readyfunc.add_parameter (new CCodeFormalParameter ("source_object", "GObject*"));
+ readyfunc.add_parameter (new CCodeFormalParameter ("res", "GAsyncResult*"));
+ readyfunc.add_parameter (new CCodeFormalParameter ("user_data", "gpointer"));
+
+ var readyblock = new CCodeBlock ();
+
+ datadecl = new CCodeDeclaration (dataname + "*");
+ datadecl.add_declarator (new CCodeVariableDeclarator ("data"));
+ readyblock.add_statement (datadecl);
+ readyblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("data"), new CCodeIdentifier ("user_data"))));
+ readyblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "res"), new CCodeIdentifier ("res"))));
+
+ ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
+ ccall.add_argument (new CCodeIdentifier ("data"));
+ readyblock.add_statement (new CCodeExpressionStatement (ccall));
+
+ readyfunc.modifiers |= CCodeModifiers.STATIC;
+ codegen.source_type_member_declaration.append (readyfunc.copy ());
+
+ readyfunc.block = readyblock;
+
+ codegen.source_type_member_definition.append (readyfunc);
}
if (m is CreationMethod) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]