Skip to content

Commit

Permalink
make more clear when a definition of interface function should be
Browse files Browse the repository at this point in the history
provided (ie internal_provided=True), small fixes for generated stubs
  • Loading branch information
ipelupessy committed Aug 21, 2022
1 parent 0a59fda commit 7532055
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 43 deletions.
10 changes: 0 additions & 10 deletions src/amuse/community/asterisk/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,5 @@ public int get_z_far(double[] z_far) {
return 0;
}

@Override
public int get_working_directory(String[] dir) {
return -2; // not implemented
}

@Override
public int set_working_directory(String dir) {
return -2; // not implemented
}


}
10 changes: 0 additions & 10 deletions src/amuse/community/distributed/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,14 +656,4 @@ public void end() {
}
}

@Override
public int get_working_directory(String[] dir) {
return -2; // not implemented
}

@Override
public int set_working_directory(String dir) {
return -2; // not implemented
}

}
10 changes: 9 additions & 1 deletion src/amuse/rfi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,20 +865,23 @@ def internal__get_message_polling_interval():
function = LegacyFunctionSpecification()
function.addParameter('polling_interval', dtype='int32', direction=function.OUT)
function.result_type = 'int32'
function.internal_provided=True
return function

@legacy_function
def internal__set_message_polling_interval():
function = LegacyFunctionSpecification()
function.addParameter('polling_interval', dtype='int32', direction=function.IN)
function.result_type = 'int32'
function.internal_provided=True
return function

@legacy_function
def internal__open_port():
function = LegacyFunctionSpecification()
function.addParameter('port_identifier', dtype='string', direction=function.OUT)
function.result_type = 'int32'
function.internal_provided=True
return function

@legacy_function
Expand All @@ -887,6 +890,7 @@ def internal__accept_on_port():
function.addParameter('port_identifier', dtype='string', direction=function.IN)
function.addParameter('comm_identifier', dtype='int32', direction=function.OUT)
function.result_type = 'int32'
function.internal_provided=True
return function

@legacy_function
Expand All @@ -895,13 +899,15 @@ def internal__connect_to_port():
function.addParameter('port_identifier', dtype='string', direction=function.IN)
function.addParameter('comm_identifier', dtype='int32', direction=function.OUT)
function.result_type = 'int32'
function.internal_provided=True
return function

@legacy_function
def internal__activate_communicator():
function = LegacyFunctionSpecification()
function.addParameter('comm_identifier', dtype='int32', direction=function.IN)
function.result_type = 'int32'
function.internal_provided=True
return function


Expand Down Expand Up @@ -1026,6 +1032,7 @@ def internal__become_code():
function.addParameter('modulename', dtype='string', direction=function.IN)
function.addParameter('classname', dtype='string', direction=function.IN)
function.result_type = 'int32'
function.internal_provided=True
return function

def get_code_module_directory(self):
Expand All @@ -1040,16 +1047,17 @@ def set_working_directory():
function = LegacyFunctionSpecification()
function.addParameter('working_directory', dtype='string', direction=function.IN)
function.result_type = 'int32'
function.internal_provided=True
return function

@legacy_function
def get_working_directory():
function = LegacyFunctionSpecification()
function.addParameter('working_directory', dtype='string', direction=function.OUT)
function.result_type = 'int32'
function.internal_provided=True
return function


class CodeWithDataDirectories(object):


Expand Down
4 changes: 2 additions & 2 deletions src/amuse/rfi/python_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def handle_message(self, input_message, output_message):
dtype_to_count = self.get_dtype_to_count(specification)


if specification.name.startswith('internal__'):
if hasattr(specification, "internal_provided"):
method = getattr(self, specification.name)
else:
method = getattr(self.implementation, specification.name)
Expand Down Expand Up @@ -543,7 +543,7 @@ def handle_message(self, input_message, output_message):

if specification.name == '_stop_worker':
method = lambda : None
elif specification.name.startswith('internal__'):
elif hasattr(specification,"internal_provided"):
method = getattr(self, specification.name)
else:
method = getattr(self.implementation, specification.name)
Expand Down
6 changes: 3 additions & 3 deletions src/amuse/rfi/tools/create_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,8 +1380,8 @@ def make_extern_c(self):
return True

def must_include_interface_function_in_output(self, x):
if x.specification.name.startswith("internal__"):
return False
if hasattr(x.specification,"internal_provided"):
return False

for cls in self.ignore_functions_from_specification_classes:
if hasattr(cls, x.specification.name):
Expand Down Expand Up @@ -1430,7 +1430,7 @@ def output_sourcecode_for_function(self):
return create_definition.CreateCStub()

def must_include_interface_function_in_output(self, x):
return not x.specification.name.startswith("internal__")
return not hasattr(x.specification,"internal_provided")

def start(self):

Expand Down
42 changes: 32 additions & 10 deletions src/amuse/rfi/tools/create_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class {0.name_of_the_community_interface_class}({0.name_of_the_superclass_for_the_community_code_interface_class}):
include_headers = ['worker_code.h']
{0.include_headers_or_modules}
def __init__(self, **keyword_arguments):
{0.name_of_the_superclass_for_the_community_code_interface_class}.__init__(self, name_of_the_worker="{0.name_of_the_community_code}_worker", **keyword_arguments)
Expand Down Expand Up @@ -241,6 +241,10 @@ def name_of_the_superclass_for_the_code_interface_class(self):
def amuse_root_dir(self):
return get_amuse_root_dir()

@late
def include_headers_or_modules(self):
return "include_headers = ['worker_code.h']"

def start(self):

self.make_directories()
Expand Down Expand Up @@ -320,6 +324,9 @@ def make_example_files(self):
CODELIB = src/lib{0.name_of_the_community_code}.a
# needed if code functions are accessed through a module
FCFLAGS+= -I$(realpath ./src)
all: {0.name_of_the_community_code}_worker
clean:
Expand Down Expand Up @@ -383,13 +390,20 @@ def make_example_files(self):
"""

interface_examplefile_template_fortran = """\
FUNCTION echo_int(input, output)
INTEGER echo
INTEGER echo_int
INTEGER input, output
output = echo(input)
echo_int = 0
END FUNCTION
module {0.name_of_the_interface_module}
contains
function echo_int(input, output)
integer :: echo
integer :: echo_int
integer :: input, output
output = echo(input)
echo_int = 0
end function
end module
"""
class CreateADirectoryAndPopulateItWithFilesForAFortranCode(CreateADirectoryAndPopulateItWithFiles):
Expand All @@ -401,7 +415,15 @@ def path_of_the_code_examplefile(self):
@late
def path_of_the_interface_examplefile(self):
return os.path.join(self.path_of_the_community_code, self.name_of_the_interface_code + '.f90')


@late
def include_headers_or_modules(self):
return 'use_modules=["{0}"]'.format(self.name_of_the_interface_module)

@late
def name_of_the_interface_module(self):
return '{0}Interface'.format(self.name_of_the_community_code)

def make_makefile(self):

with open(self.path_of_the_makefile, "w") as f:
Expand All @@ -418,6 +440,6 @@ def make_example_files(self):
f.write(string)

with open(self.path_of_the_interface_examplefile, "w") as f:
string = interface_examplefile_template_fortran
string = interface_examplefile_template_fortran.format(self)
f.write(string)

23 changes: 18 additions & 5 deletions src/amuse/rfi/tools/create_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ def output_modules(self):
self.out.n() + 'use ' + x

def must_include_declaration_of_function(self, x):
if x.specification.name.startswith("internal__"):
if hasattr(x.specification,"internal_provided"):
return False

return True
Expand Down Expand Up @@ -1627,20 +1627,33 @@ def output_sourcecode_for_function(self):
return result

def start(self):

if hasattr(self.specification_class, 'use_modules'):
self.out.lf() + 'module {0}'.format(self.specification_class.use_modules[0])

self.output_modules()
self.out.indent()

self.output_modules(1)

if hasattr(self.specification_class, 'use_modules'):
self.out.lf() + "contains"

self.out.lf()

self.output_sourcecode_for_functions()

self.out.lf()

if hasattr(self.specification_class, 'use_modules'):
self.out.dedent()
self.out.lf() + "end module"
self.out.lf()

self._result = self.out.string


def must_include_interface_function_in_output(self, x):
if x.specification.name.startswith("internal__"):
if hasattr(x.specification,"internal_provided"):
return False

for cls in self.ignore_functions_from_specification_classes:
Expand All @@ -1649,10 +1662,10 @@ def must_include_interface_function_in_output(self, x):

return True

def output_modules(self):
def output_modules(self,skip):
self.out.n()
if hasattr(self.specification_class, 'use_modules'):
for x in self.specification_class.use_modules:
for x in self.specification_class.use_modules[skip:]:
self.out.n() + 'use ' + x


Expand Down
4 changes: 2 additions & 2 deletions src/amuse/rfi/tools/create_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ def start(self):
self.output_lines_with_number_of_outputs()


if self.specification.name.startswith("internal__"):
if hasattr(self.specification,"internal_provided"):
self.out.lf() + "//" + self.specification.name + " ignored"
else:
self.output_declare_variables()
Expand Down Expand Up @@ -1439,7 +1439,7 @@ def dtype_to_spec(self):


def must_include_interface_function_in_output(self, x):
if x.specification.name.startswith("internal__"):
if hasattr(x.specification,"internal_provided"):
return False

for cls in self.ignore_functions_from_specification_classes:
Expand Down

0 comments on commit 7532055

Please sign in to comment.