3

can I invoke Java functions from Rascal. I want to write RASCAL analyser, but want access CFG nodes by calling a java function. Is this possible in Rascal. To put it simply, can I wrap the existing java application and invoke it from RASCAL

  • Could you accept the answer if it is satisfactory? – Jurgen Vinju Nov 12 '13 at 13:53
  • Are there any new libraries developed to support this? Is pdb.values be replaced by valLang library now? – user2940768 Jun 30 '18 at 05:20
  • yes, pdb.values was renamed to vallang. Otherwise there is no new API for the interpreter. For compiled Rascal programs the RVM.asInterface() method was added, which exposes a Rascal module to its Java counterpart as a POJO (with vallang interfaces to the parameters). – Jurgen Vinju Jul 09 '18 at 15:05

1 Answers1

4

Sure. It works as follows.

  1. Treat your Rascal project in Eclipse as a Java project as well.
  2. Add source code and libraries and make the stuff compile.
  3. Learn about the pdb.values API (in particular IValueFactory)
  4. In Rascal write something like this:
    @javaClass{com.mypackage.MyClass}
    java int myFunction(str arg);
  1. Then in Java:
     package com.mypackage;    
     public class MyClass {
        private final IValueFactor vf;
        public MyClass(IValueFactory vf) { 
          this.vf = vf;
        }
        IValue myFunction(IString x) {
           return vf.integer(-1);
        }
     }  
Jurgen Vinju
  • 6,393
  • 1
  • 15
  • 26