Skip to content

Commit

Permalink
#50: in lack of a better solution, synchronizing csharp and python as…
Browse files Browse the repository at this point in the history
… well
  • Loading branch information
Tomer Filiba committed Apr 1, 2012
1 parent d01e8f0 commit f33408a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion compiler/src/agnos_compiler/targets/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .base import TargetBase, NOOP
from contextlib import contextmanager
from .. import compiler
from ..compiler import is_complex_type, is_complicated_type
from ..compiler import is_complex_type, is_complicated_type, IDLError
from ..compat import icount


Expand Down
45 changes: 23 additions & 22 deletions compiler/src/agnos_compiler/targets/csharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from .base import TargetBase, NOOP
from .. import compiler
from ..compiler import is_complex_type
from ..compiler import is_complex_type, IDLError
from ..compat import icount


Expand Down Expand Up @@ -1200,27 +1200,28 @@ def generate_client_internal_funcs(self, module, service):
for arg in func.args)
with BLOCK("public {0} sync_{1}({2})", type_to_cs(func.type, proxy = True),
func.id, args):
if is_complex_type(func.type) or func.type == compiler.t_heteromap:
STMT("int seq = client._utils.BeginCall({0}, client.{1})",
func.id, type_to_packer(func.type))
else:
STMT("int seq = client._utils.BeginCall({0}, {1})", func.id,
type_to_packer(func.type))
if func.args:
with BLOCK("try"):
for arg in func.args:
if is_complex_type(arg.type) or arg.type is compiler.t_heteromap:
STMT("client.{0}.pack({1}, client._utils.transport)", type_to_packer(arg.type), arg.name)
else:
STMT("{0}.pack({1}, client._utils.transport)", type_to_packer(arg.type), arg.name)
with BLOCK("catch (Exception ex)"):
STMT("client._utils.CancelCall()")
STMT("throw ex")
STMT("client._utils.EndCall()")
if func.type == compiler.t_void:
STMT("client._utils.GetReply(seq)")
else:
STMT("return ({0})client._utils.GetReply(seq)", type_to_cs(func.type, proxy = True))
with BLOCK("lock(this)"):
if is_complex_type(func.type) or func.type == compiler.t_heteromap:
STMT("int seq = client._utils.BeginCall({0}, client.{1})",
func.id, type_to_packer(func.type))
else:
STMT("int seq = client._utils.BeginCall({0}, {1})", func.id,
type_to_packer(func.type))
if func.args:
with BLOCK("try"):
for arg in func.args:
if is_complex_type(arg.type) or arg.type is compiler.t_heteromap:
STMT("client.{0}.pack({1}, client._utils.transport)", type_to_packer(arg.type), arg.name)
else:
STMT("{0}.pack({1}, client._utils.transport)", type_to_packer(arg.type), arg.name)
with BLOCK("catch (Exception ex)"):
STMT("client._utils.CancelCall()")
STMT("throw ex")
STMT("client._utils.EndCall()")
if func.type == compiler.t_void:
STMT("client._utils.GetReply(seq)")
else:
STMT("return ({0})client._utils.GetReply(seq)", type_to_cs(func.type, proxy = True))
SEP()
SEP()
STMT("internal readonly _Functions _funcs")
Expand Down
23 changes: 13 additions & 10 deletions compiler/src/agnos_compiler/targets/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
from .base import TargetBase
from .. import compiler
from ..compiler import is_complex_type
from ..compiler import is_complex_type, IDLError


def type_to_packer(t):
Expand Down Expand Up @@ -97,6 +97,7 @@ def generate(self, service):
STMT("from agnos import packers")
STMT("from agnos import utils")
STMT("from functools import partial")
STMT("import threading")
SEP()

STMT("AGNOS_TOOLCHAIN_VERSION = '{0}'", compiler.AGNOS_TOOLCHAIN_VERSION)
Expand Down Expand Up @@ -576,18 +577,20 @@ def generate_client_ctor(self, module, service):
with BLOCK("class Functions(object)"):
with BLOCK("def __init__(self, utils)"):
STMT("self.utils = utils")
STMT("self.lock = threading.Lock()")
for func in service.funcs.values():
args = ", ".join(arg.name for arg in func.args)
with BLOCK("def sync_{0}(_self, {1})", func.id, args):
with BLOCK("with _self.utils.invocation({0}, {1}) as seq",
func.id, type_to_packer(func.type)):
if not func.args:
STMT("pass")
else:
for arg in func.args:
STMT("{0}.pack({1}, _self.utils.transport)",
type_to_packer(arg.type), arg.name)
STMT("return _self.utils.get_reply(seq)")
with BLOCK("with self.lock"):
with BLOCK("with _self.utils.invocation({0}, {1}) as seq",
func.id, type_to_packer(func.type)):
if not func.args:
STMT("pass")
else:
for arg in func.args:
STMT("{0}.pack({1}, _self.utils.transport)",
type_to_packer(arg.type), arg.name)
STMT("return _self.utils.get_reply(seq)")
SEP()
STMT("self._funcs = Functions(self._utils)")
SEP()
Expand Down

0 comments on commit f33408a

Please sign in to comment.