Skip to content
/ jariko Public

a JAva virtual machine Rpg Interpreter written in KOtlin

License

Notifications You must be signed in to change notification settings

smeup/jariko

Repository files navigation

JaRIKo: a JAva virtual machine Rpg Interpreter written in KOtlin

jariko Logo

License codebeat badge GitHub commit activity

⚡️ Cross-platform RPG Code in a polyglot environment ⚡️

Introduction

JaRIKo is an interpreter for the RPG programming language. It runs on the JVM since it's written in Kotlin.

It is part of a bigger project named Sme.UP Open Architecture, by the italian software company Sme.UP.

Sme.UP Open Architecture aims to build a software platform for business applications (also mistakenly known as ERP systems) and it is the core of Sme.UP Data Platform.

How might this work in the real world

JaRIKo can be used as a library: you push RPG code in, it is executed, you get the results out. And it works, as you can see in this animated gif of a simple on-the-fly online rpg-running application.

rpgweb

This application is running completely on Linux

  • receives the RPG code via HTTP
  • uses Jariko as a jar
  • overwrites the DSPLY opcode, redirecting the output to the http-response. Pretty slick!

rpgweb

But, for an enterprise-grade application, there will be a runtime environment running both RPG and JVM languages, with the following architecture:

smeup_data_platform

Once a request comes into the system, it's recognized as a "program" (a unit of execution) and redirected towards the right program handler: RPG is handled by JaRIKo (interpreter), the others by different executors. So JaRIKo is one (important) part of the whole architecture

Why are we doing this?

Why build something that executes RPG, such an old and niche programming language? RPG is widely used in the business enterprise and financial industry to this day. Big companies still rely on stable, battle-tested, mission critical RPG codebases to run their business.

This is for at least a couple of reasons.

First, RPG was designed for enterprise, it is very simple, powerful for data manipulation, but extremely inadequate at solving technology issues (like threads, async, http calls, cryptography, and so forth). The developer doesn't need to be aware of the technical details. The system provides all this technology, making code run on top of a platform that solves those issues.

This helped to create a generation of RPG programmers that are closer to business consultants than to developers, and this is very good for business applications development.

The second is that RPG only runs on IBMi, best known as AS/400, that was also designed for business, is very reliable, fast, well-supported, and stable. RPG leverages AS/400 architecture, they are the perfect couple.

Focus on:

1- Doping your code

One of the core features of Jariko is the doping mechanism: once the code is taken over by the interpreter, every single program can be replaced at runtime. This allows to write a very flexible and polyglot software, choosing the right tool for the right job and having all the java (and jvm) power and ecosystem available.

doping

Through doping, it's also much simpler to make the architectural design needed to deal with things like SPOOLS, DATAQUEUES, JOBS, DATAAREA, etc, typical of the OS/400 operating system, where the RPG code used to run.

2- DSL

If you know how programming languages work, you also know that once you have a syntax three in your hands, you can do almost whatever you want. So, since RPG is best used for business applications, why don't add new high-level features to make the life of the RPG programmer easier? This is a step towards a Domain Specific Language

 C                   PARM                    §§METO
 C                   PARM                    §§SVAR
 C                   EVAL      PRICE=§§SVAR
 C                   CALC_VAT(PRICE)    

In this example CALC_VAT, standing for "calculate vat" does not exist in RPG, but the interpreter can handle it as a language keyword, with type check, syntax highlighting, code suggenstions, intellisense, errors an so on.

Some questions

1.So it sounds like you are developing an interpreter to run an application on multiple other platforms.

Right

2.What language is the interpreter being developed in?

Mostly Kotlin, but the overall resulting system will be µ-service-based and we're going to use jvm languages.

3.How do you transfer the database to another platform? SQL scripts?

We have ETLs. We've already been doing that since years. SQL must not have dialect-specific statements, or it has to be re-arranged, but we're thinking about that.

4.Do you handle multiple member files, DDM files, multiple physical logical files

No. We're also not implementing DDS, SUBFILE, CLP. And absolutely none of the os/400 system apis.

5.Data areas and user spaces?

Yes. Also QTEMP, RLA (read, write, chain, setll, etc...), SQLRPGLE (maybe...), /COPY

Development

All information for developers is to be found in the Development guide.

Features

The following list shows all the implemented features:

Logging

Jariko supports configurable logging, described in a separate document.

RPG Unit tests: the MUTE mechanism

Special annotations can be used to write unit tests in RPG. For more details, see this document.

MUTEs and Visual Studio Code

You can run MUTE tests in Visual Studio Code: see the documentation

How the repository is organized

  • generated-src contains the code generated from the grammar
  • gradle, gradlew, and gradlew.bat contain the gradle wrapper
  • src contains the source code for the project and the tests
  • out, and build contain temporary files
  • misc contains utilities for downloading sources from AS400 (for example this ruby script)
  • misc/docker: support for Docker, see instructions
  • docs contains documentation

Are there any presentations about your work?

Yes, of course: see the presentation list

How to use this code in your project

At the moment, we use Maven Central to publish the project.

Maven

To use Jariko in a Maven application, add the following dependencies for the core library:

<dependency>
    <groupId>io.github.smeup.jariko</groupId>
    <artifactId>rpgJavaInterpreter-core</artifactId>
    <version>vx.y.z</version>
</dependency>

If you also want to include the examples, add:

<dependency>
    <groupId>io.github.smeup.jariko</groupId>
    <artifactId>examples</artifactId>
    <version>vx.y.z</version>
</dependency>

Gradle

To use Jariko in a Gradle application, add the following lines to your build.gradle file:

dependencies {
    ...
    implementation 'io.github.smeup.jariko:rpgJavaInterpreter-core:vx.y.z'
}

Samples

Here is a sample project that uses the interpreter as a library, and here is another one.

Contributing

Every kind of contribution to this project is welcome. See our contributing guide for more details.

Credits

The grammar used in this project is based on the work from Ryan Eberly. It is derived from his project rpgleparser.

Some RPG Examples are from Claudio Neroni

Another source for good examples is go4as400