Changeset 13440


Ignore:
Timestamp:
Sep 10, 2019 2:47:16 PM (3 months ago)
Author:
Christian Andersson
Message:

Updated the evaluator. Related to ticket:5837

Location:
branches/dev-cw-evaluator
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-cw-evaluator/Compiler/ModelicaCBackEnd/src/jastadd/CCodeGen/CCodeGenExternalCeval.jrag

    r13437 r13440  
    294294        if (arg.isReal()) {
    295295            input = input.concat("d");
    296         } else if (arg.isInteger() || arg.isEnum()) {
     296        } else if (arg.isInteger() || arg.isEnum() || arg.isBoolean()) {
    297297            input = input.concat("i");
    298298        } else if (arg.isString()) {
  • branches/dev-cw-evaluator/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalProcessCacheImpl.java

    r13437 r13440  
    117117                if (canUseEvaluator(ext)) {
    118118                    String jmHome = System.getenv("JMODELICA_HOME");
    119                     executable = jmHome + File.separator + "bin" + File.separator + CCompilerDelegator.reduceBits(EnvironmentUtils.getJavaPlatform(),mc.getCCompiler().getTargetPlatforms()) + File.separator + "jmi_evaluator" + SystemUtil.executableExtension();
     119                    String platform = CCompilerDelegator.reduceBits(EnvironmentUtils.getJavaPlatform(),mc.getCCompiler().getTargetPlatforms());
     120                    String bits = platform.contains("64") && SystemUtil.isWindows() ? "64" : "";
     121                    executable = jmHome + File.separator + "bin" + bits + File.separator + "jmi_evaluator" + SystemUtil.executableExtension();
    120122                   
    121123                    String sharedLibrary = getSharedLibrary(ext);
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/files/Modelica/ExtFunctionTests.mo

    r11759 r13440  
    11package ExtFunctionTests
     2
     3model Substring
     4    constant String full="Yy00";
     5    constant String sub=Modelica.Utilities.Strings.substring(full,1,1);
     6    constant String string1 = "This is line 111";
     7    constant String string2 = Modelica.Utilities.Strings.substring(string1,9,12); // string2 = \"line\"
     8    constant Integer len = Modelica.Utilities.Strings.length(string1);
     9    constant Integer start = Modelica.Utilities.Strings.Advanced.skipWhiteSpace("   Hello", 1);
     10end Substring;
    211
    312model ExtFunctionTest1
  • branches/dev-cw-evaluator/Python/src/tests_jmodelica/general/test_extfunctions.py

    r11759 r13440  
    3333path_to_mofiles = os.path.join(get_files_path(), 'Modelica')
    3434
     35class TestEvaluator:
     36    @classmethod
     37    def setUpClass(cls):
     38        """
     39        Sets up the test class.
     40        """
     41        cls.fpath = path(path_to_mofiles, "ExtFunctionTests.mo")
     42   
     43    @testattr(stddist_base = True)
     44    def test_builtin_substring(self):
     45        """
     46        Test compiling a model with external functions in a static library.
     47        """
     48        cpath = "ExtFunctionTests.Substring"
     49        fmu_name = compile_fmu(cpath, self.fpath)
     50        model = load_fmu(fmu_name)
     51       
     52        assert model.get("sub") == "Y"
     53        assert model.get("string2") == "line"
     54        assert model.get("len") == 16
     55        assert model.get("start") == 4
     56
    3557class TestExternalStatic:
    3658
  • branches/dev-cw-evaluator/RuntimeLibrary/src/evaluator/CMakeLists.txt

    r13436 r13440  
    3838if(NOT MSVC)
    3939    set_target_properties(jmi_evaluator PROPERTIES COMPILE_FLAGS "-Wall -g -std=c89 -pedantic -O2")
    40     set (EVALUATOR_LIBS ${EVALUATOR_LIBS} dl)
     40    IF (NOT WIN32)
     41        set (EVALUATOR_LIBS ${EVALUATOR_LIBS} dl)
     42    endif()
    4143endif()
    4244target_link_libraries (jmi_evaluator  ${EVALUATOR_LIBS})
  • branches/dev-cw-evaluator/RuntimeLibrary/src/evaluator/jmi_evaluator.c

    r13436 r13440  
    2323/* Builtins */
    2424extern const char* ModelicaStrings_substring(const char*, int, int);
     25extern const char* ModelicaStrings_length(const char*);
     26extern const char* ModelicaStrings_skipWhiteSpace(const char*, int);
    2527
    2628#define ERROR_LOAD_DLL 3
     
    182184typedef double(__stdcall *f_d_idd)(int, double, double);
    183185typedef int (__stdcall *f_i_ii)(int, int);
     186typedef int (__stdcall *f_i_s)(const char*);
     187typedef int (__stdcall *f_i_si)(const char*, int);
    184188typedef void(__stdcall *f___iddpR_ddddddddddd_)(int, double, double, R_ddddddddddd**);
    185189typedef void (*generic_funcptr)(void);
     
    304308}
    305309
    306 void jmi_call_string_fcn_sii(generic_funcptr fcn, const char *out) {
     310void jmi_call_integer_fcn_s(generic_funcptr fcn, double *out) {
     311    JMI_DEF(STR, arg_0)
     312
     313    JMCEVAL_parse(String, arg_0);
     314
     315    JMCEVAL_check("CALC");
     316    if (JMCEVAL_try()) {
     317        /* Calc phase */
     318        *out = ((f_i_s)fcn)(arg_0);
     319    }
     320    else {
     321        JMCEVAL_failed();
     322    }
     323}
     324
     325void jmi_call_integer_fcn_si(generic_funcptr fcn, double *out) {
     326    JMI_DEF(STR, arg_0)
     327    JMI_DEF(INT, arg_1)
     328    JMI_DEF(INT_EXT, tmp_1)
     329
     330    JMCEVAL_parse(String, arg_0);
     331    JMCEVAL_parse(Integer, arg_1);
     332
     333    JMCEVAL_check("CALC");
     334    if (JMCEVAL_try()) {
     335        /* Calc phase */
     336        tmp_1 = (int)arg_1;
     337        *out = ((f_i_si)fcn)(arg_0, tmp_1);
     338    }
     339    else {
     340        JMCEVAL_failed();
     341    }
     342}
     343
     344void jmi_call_integer_fcn(generic_funcptr fcn, const char* inputs) {
     345    JMI_DEF(INT, i_output)
     346    JMCEVAL_parse(Integer, i_output);
     347
     348    if (strcmp(inputs, "s,") == 0) {
     349        jmi_call_integer_fcn_s(fcn, &i_output);
     350    } else if (strcmp(inputs, "s,i,") == 0) {
     351        jmi_call_integer_fcn_si(fcn, &i_output);
     352    } else {
     353        printf(ERROR_NOT_SUPPORTED_INPUT_ARGS_MSG);
     354        exit(ERROR_NOT_SUPPORTED_INPUT_ARGS);
     355    }
     356
     357    JMCEVAL_check("DONE");
     358    JMCEVAL_print(Integer, i_output);
     359}
     360
     361void jmi_call_string_fcn_sii(generic_funcptr fcn, char **out) {
    307362    JMI_DEF(STR, arg_0)
    308363    JMI_DEF(INT, arg_1)
     
    320375        tmp_1 = (int)arg_1;
    321376        tmp_2 = (int)arg_2;
    322         out = ((f_s_sii)fcn)(arg_0, tmp_1, tmp_2);
     377        *out = ((f_s_sii)fcn)(arg_0, tmp_1, tmp_2);
    323378    } else {
    324379        JMCEVAL_failed();
     
    331386
    332387    if (strcmp(inputs, "s,i,i,") == 0) {
    333         jmi_call_string_fcn_sii(fcn, s_output);
     388        jmi_call_string_fcn_sii(fcn, &s_output);
    334389    } else {
    335390        printf(ERROR_NOT_SUPPORTED_INPUT_ARGS_MSG);
     
    369424    if (strcmp(argv[2], "ModelicaStrings_substring") == 0) {
    370425        funci = (generic_funcptr)ModelicaStrings_substring;
     426    } else if (strcmp(argv[2], "ModelicaStrings_length") == 0) {
     427        funci = (generic_funcptr)ModelicaStrings_length;
     428    } else if (strcmp(argv[2], "ModelicaStrings_skipWhiteSpace") == 0) {
     429        funci = (generic_funcptr)ModelicaStrings_skipWhiteSpace;
    371430    }
    372431
     
    433492        if (strcmp(output_args, "d") == 0) {
    434493            jmi_call_double_fcn(funci, input_args);
    435         } else if(strcmp(output_args, "s") == 0) {
     494        } else if (strcmp(output_args, "s") == 0) {
    436495            jmi_call_string_fcn(funci, input_args);
     496        } else if (strcmp(output_args, "i") == 0) {
     497            jmi_call_integer_fcn(funci, input_args);
    437498        } else if (strcmp(output_args, "void") == 0) {
    438499            jmi_call_void_fcn(funci, input_args);
Note: See TracChangeset for help on using the changeset viewer.