Spin1/Ruby polyglot

So for some reason I wondered: "Can you make a file that's both a Spin program and a Ruby program"
Then I passed out and an hour later I woke up with this in my editor (hey forum admins, why is there still no button for the code block?):
''# The amazing Ruby/Spin polyglot!
''; puts "Henlo World!"
''; text = %{
CON

_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

OBJ
pst : "parallax serial terminal"

PUB main
  pst.start(115_200)
  repeat
    pst.str(string("Henlo world!",13))

''}

'';p text
she/her
My projects: JET Engine - Ventilator Computer (site coming soon™) and relatedly, VentilatorOS and software archive - Turbulence NTSC - The game(no not that one) (also coming soon™)
Other cool links: Propeller Discord - Retronitus
Wow, I too finally have an overly long signature!

Comments

  • Wuerfel_21Wuerfel_21 Posts: 491
    edited 2019-03-15 - 22:45:09
    I also managed to find a way to include more than just oneliners of ruby:
    ''# The amazing Ruby/Spin polyglot!
    ''; puts "Henlo World!"
    {{ } => 0
    }
    10.times { |x|
      p x
    }
    ''; { 0 => {
    }}
    ''; text = %{
    CON
    
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    
    OBJ
    pst : "parallax serial terminal"
    
    PUB main
      pst.start(115_200)
      repeat
        pst.str(string("Henlo world!",13))
    
    ''}
    
    '';p text
    
    she/her
    My projects: JET Engine - Ventilator Computer (site coming soon™) and relatedly, VentilatorOS and software archive - Turbulence NTSC - The game(no not that one) (also coming soon™)
    Other cool links: Propeller Discord - Retronitus
    Wow, I too finally have an overly long signature!
  • :cool:
    Stockholm, Sweden
    I am only an egg -- Stranger in a Strange land, Robert A. Heinlein
  • What is Ruby?
    Sarcasm for English build 2019.12.30 released two days before New Year's! Ports to other languages are in progress and are expected to be finished by January 5, 2020.
  • So, @Wuerfel_21, how on earth did you do this? Are you compiling Ruby with Spin in the Propeller Tool???
    Sarcasm for English build 2019.12.30 released two days before New Year's! Ports to other languages are in progress and are expected to be finished by January 5, 2020.
  • nah, the trick is quite simple - abusing the syntax of both languages so that they read the other language code either as comments/strings or ineffective statements. It makes more sense when you actually paste it into an editor with syntax highlighting.
    I don't think there is really anything useful one can do with this, but it's cool, still.
    she/her
    My projects: JET Engine - Ventilator Computer (site coming soon™) and relatedly, VentilatorOS and software archive - Turbulence NTSC - The game(no not that one) (also coming soon™)
    Other cool links: Propeller Discord - Retronitus
    Wow, I too finally have an overly long signature!
  • So, it doesn’t compile?
    Sarcasm for English build 2019.12.30 released two days before New Year's! Ports to other languages are in progress and are expected to be finished by January 5, 2020.
  • It does, but it doesn't do anything cool. The cool part is that the same file compiles succesfully in Ruby and Spin and does the same thing (print out "Henlo World!").
    she/her
    My projects: JET Engine - Ventilator Computer (site coming soon™) and relatedly, VentilatorOS and software archive - Turbulence NTSC - The game(no not that one) (also coming soon™)
    Other cool links: Propeller Discord - Retronitus
    Wow, I too finally have an overly long signature!
  • The trick is that the Spin code is a comment in Ruby, and the Ruby code is a comment in Spin.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • 🤯
    Sarcasm for English build 2019.12.30 released two days before New Year's! Ports to other languages are in progress and are expected to be finished by January 5, 2020.
Sign In or Register to comment.