Announcing RNP: the friendly compile-to-RPN language

Hey fellow SDK users. I’m super excited to announce the 1.0 release of RNP, a language I’ve been working on which compiles to RPN. You can download it from @flybywiresim/rnp - npm and try it out online at RNP.

My motivations for making RNP are roughly as follows:

  • RPN is a pain to write
  • RPN is a pain to read
  • RPN’s fail-quiet behaviour makes it difficult to debug

So what is supported by RNP? Pretty much everything! Here are some of my favorite features:

Named Variables!

let a = (L:XYZ, meters);
if a > 2 {
  # ...
}

Static Typing! (and great error messages :smile:)

 --> demo.rnp:1:4
  |
1 | if (L:XYZ, string) {}
  |    ^^^^^^^^^^^^^^^ Expected boolean but got string
  |

Hygienic Macros!

macro mapf($n, $in_min, $in_max, $out_min, $out_max) {
  ($n - $in_min) * ($out_max - $out_min) / ($in_max - $in_min) + $out_min
}

let x = mapf(y, -100, 100, -1, 1);
let z = mapf(n, 0, 1, 10, 15);

Method Operations!

let foo = 8.log(10);
let bar = 'hello, world!'.toUpperCase();

So Much More!

See the full list of syntax at the link above. Feel free to use this in your projects, and please remember to report bugs! We are working on integrating RNP into the FlyByWire A32NX mod, so don’t fret, it will be supported for a long time.

4 Likes

Thank you for sharing!

This is interesting and while perusing the source code I was wondering about a few things:

  • Is there any link between this and the recent announcement FS2020 will be supporting the FSX XML gauges in a near future?

  • Is it parsing a RNP file and converts this to XML file, or is it directly translated to XML in memory so that FS2020 is using the translated RNP directly?

  • What was the main driver for creating another script language instead of for example using the ubiquitous LUA?

  • And actually while at it, instead of supporting XML natively in FS2020, why not having a XML to JS translator and just code in JS natively?

Thank you in advance for clarifying this!

Is there any link between this and the recent announcement FS2020 will be supporting the FSX XML gauges in a near future?

Nope, I don’t do FSX conversions. If this helps them in some way though, that’s great!

Is it parsing a RNP file and converts this to XML file, or is it directly translated to XML in memory so that FS2020 is using the translated RNP directly?

The package itself is just RNP to RPN. It is intended to be used in conjunction with a tool which parses and modifies the XML source files. I’m not sure there would be any way to modify the files in memory (And I’m not sure you’d want to do that anyway, since you can do it ahead of time). You can see a (work in progress) example of a script which converts XML files containing RNP here: https://github.com/flybywiresim/a32nx/blob/rnp/src/behavior/build.js

What was the main driver for creating another script language instead of for example using the ubiquitous LUA?

Lua is a great language, but it can’t be (trivially) compiled to RPN. The runtime object model would likely require more than the 50 heap slots that RPN provides.

And actually while at it, instead of supporting XML natively in FS2020, why not having a XML to JS translator and just code in JS natively?

I’m not sure I understand the question here, but this is generally intended to be used in model behaviors more than instruments.

Ok this most likely what I’ve missed initially :crazy_face:

If I understand correctly, the FS2020 SDK supports scripting the model behavior using the legacy FSX XML scripts isn’t it? So the workflow is you use your translator against your RNP script files, and this produces the XML equivalent script files you then copy/paste into the model behavior file (either manually or programmatically) is this correct?

More or less. You can see an example input and output file here, basically the same thing just with RNP scripts converted into RPN scripts.

1 Like

What’s the added overhead in moving away from the very stack efficient RPN ?

I seem to remember, back in the Dark ages of FSX, there were quick & easy RPN evaluators (encoders / decoders) that you could use if you were having a brain freeze in reading the RPN, but you always ending up using the RPN, because it was efficient.

At the moment only named variables use registers, everything else uses the stack. A planned feature for the future is a peephole optimizer pass, which should be able to lower some named variable usage to the stack as well (for example, that screenshot I posted above would just be 1 (>L:XYZ,meters) instead of using a register).

All that being said, I haven’t noticed any slowdown from register usage (tested on i5-8400H and GTX1050Ti Max-Q at 1080p).

very cool… will watch with interest …

We’ve merged the first bit of RNP into A32NX :tada: a32nx/A32NX_Interior_Misc.xml at dfc40f0bd2326c3fb0ef5007cdc753ac409d0cb9 · flybywiresim/a32nx · GitHub

Also for who want to play around with it, I’ve added a website which shows real-time compilation output: RNP

3 Likes

I don’t know how to express my gratitude with enough emphasis. This is a GEM! I recently bought Axis and Ohs and have been struggling with making a RNP script for my throttles. I’ve never come in contact with RNP before and after a while I seriously thought I was going to throw the darn thing out the window. But then came you and your absolutely awesome little thing and saved the day!:slightly_smiling_face: You even have the algorithm I’m trying to use to remap a value from one range to another.

1 Like