Skip to main content

RUBY_RUNTIME

Constant RUBY_RUNTIME 

Source
pub const RUBY_RUNTIME: &str = r#"# frozen_string_literal: true
# OxiLean Ruby Runtime — auto-generated

module OxiLeanRuntime
  module_function

  # Natural-number addition (Ruby Integer is arbitrary-precision)
  def nat_add(a, b) = a + b

  # Natural-number saturating subtraction
  def nat_sub(a, b) = [0, a - b].max

  # Natural-number multiplication
  def nat_mul(a, b) = a * b

  # Natural-number division (truncating, div-by-zero → 0)
  def nat_div(a, b) = b.zero? ? 0 : a / b

  # Natural-number modulo (div-by-zero → a)
  def nat_mod(a, b) = b.zero? ? a : a % b

  # Decidable boolean → 0/1 as Integer
  def decide(b) = b ? 1 : 0

  # Natural number to string
  def nat_to_string(n) = n.to_s

  # String append
  def str_append(a, b) = a + b

  # String length
  def str_length(s) = s.length

  # List cons: prepend element
  def cons(head, tail) = [head, *tail]

  # List nil: empty list
  def nil_list = []

  # Pair constructor
  def mk_pair(a, b) = [a, b]

  # Unreachable branch
  def unreachable! = raise(RuntimeError, "OxiLean: unreachable code reached")
end
"#;
Expand description

Minimal Ruby runtime module emitted before the generated code.