<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Hiroshi Tsubokawa</title>
    <description>The latest articles on Forem by Hiroshi Tsubokawa (@tsubo164).</description>
    <link>https://forem.com/tsubo164</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3071296%2F3fcf052e-f939-484b-a178-7e7512de7bcc.png</url>
      <title>Forem: Hiroshi Tsubokawa</title>
      <link>https://forem.com/tsubo164</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tsubo164"/>
    <language>en</language>
    <item>
      <title>The out Parameter in Turbine: A Markdown-like Scripting Language</title>
      <dc:creator>Hiroshi Tsubokawa</dc:creator>
      <pubDate>Thu, 23 Oct 2025 12:26:21 +0000</pubDate>
      <link>https://forem.com/tsubo164/the-out-parameter-in-turbine-a-markdown-like-scripting-language-53ab</link>
      <guid>https://forem.com/tsubo164/the-out-parameter-in-turbine-a-markdown-like-scripting-language-53ab</guid>
      <description>&lt;p&gt;In previous posts, I’ve introduced some of the key syntax and features of &lt;strong&gt;Turbine&lt;/strong&gt;, a Markdown-inspired scripting language.&lt;br&gt;
This time, let’s look at one of its practical features, the &lt;strong&gt;out parameter&lt;/strong&gt;, a mechanism for returning multiple values from a function, similar to how C and C++ handle it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Do We Need an Out Parameter?
&lt;/h2&gt;

&lt;p&gt;In Turbine, a function can only have &lt;strong&gt;one return value&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But sometimes, you want to return &lt;strong&gt;a main result&lt;/strong&gt; and an additional &lt;strong&gt;status flag&lt;/strong&gt;, for example, when you want to detect division by zero in a &lt;code&gt;divide()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Many scripting languages, such as Python, can easily return multiple values using tuples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s convenient and expressive.&lt;br&gt;
However, in C or C++, a function can only return a single value, so developers typically use &lt;strong&gt;references or pointers&lt;/strong&gt; to return additional results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Turbine follows this &lt;strong&gt;C/C++ style approach&lt;/strong&gt;, but with a much simpler, &lt;strong&gt;Markdown-like syntax&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing an Out Parameter in Turbine
&lt;/h2&gt;

&lt;p&gt;In Turbine, you declare an out parameter by prefixing it with &lt;code&gt;&amp;amp;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;# divide(a int, b int, &amp;amp;ok bool) int
&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function above performs integer division and sets &lt;code&gt;ok&lt;/code&gt; to indicate success.&lt;/p&gt;

&lt;p&gt;On the caller side, it looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;# main(args vec{string}) int
&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;
    &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"result ="&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"divide by zero"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;&amp;amp;ok&lt;/code&gt; means the variable &lt;code&gt;ok&lt;/code&gt; is &lt;strong&gt;passed by reference&lt;/strong&gt;, and the function writes its result back to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design Philosophy
&lt;/h2&gt;

&lt;p&gt;Turbine’s out parameter system is not just nostalgic imitation of C —&lt;br&gt;
it’s designed to clearly separate the “main result” from auxiliary information.&lt;/p&gt;

&lt;p&gt;Take the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;# parse_int(s string, &amp;amp;ok bool) int
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Turbine used tuple-style multiple returns (like &lt;code&gt;(int, bool)&lt;/code&gt;), the caller would need to unpack both values every time, even if they only cared about one.&lt;br&gt;
Instead, Turbine encourages a clear distinction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Return value → the primary result&lt;/li&gt;
&lt;li&gt;Out parameter → state, flag, or secondary information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes the code both &lt;strong&gt;cleaner and semantically clearer&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Explicitly Ignoring Outputs with &lt;code&gt;discard&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Out parameters cannot simply be omitted.&lt;br&gt;
If you call a function with an out parameter but never use the variable afterward, &lt;strong&gt;Turbine will raise an error&lt;/strong&gt;, it assumes you forgot to handle the result.&lt;/p&gt;

&lt;p&gt;To intentionally ignore the output, you can use the special keyword discard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;# main(args vec{string}) int
&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parse_int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;discard&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;discard&lt;/code&gt; keyword lets you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Skip creating an unnecessary variable&lt;/li&gt;
&lt;li&gt;Avoid “unused output” errors&lt;/li&gt;
&lt;li&gt;Clearly express that the result is &lt;strong&gt;intentionally ignored&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is especially convenient in lightweight scripts where you don’t need every auxiliary output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rules and Limitations
&lt;/h2&gt;

&lt;p&gt;There are a few simple rules for out parameters in Turbine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only &lt;strong&gt;primitive types&lt;/strong&gt; (&lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;) can be used with &lt;code&gt;&amp;amp;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Reference types such as strings, containers (&lt;code&gt;vec&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, etc.), and structs &lt;strong&gt;cannot&lt;/strong&gt; be out parameters&lt;/li&gt;
&lt;li&gt;At call time, you must pass either an existing variable or &lt;code&gt;&amp;amp;discard&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because reference types are already passed by reference, you can modify them directly inside functions without &lt;code&gt;&amp;amp;&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Turbine’s out parameter design is all about &lt;strong&gt;clarity and intent&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;&amp;amp;&lt;/code&gt; to return extra results from a function&lt;/li&gt;
&lt;li&gt;Callers must explicitly mark out arguments with &lt;code&gt;&amp;amp;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Keeps the main return value semantically distinct&lt;/li&gt;
&lt;li&gt;Detects unused out arguments at compile time&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;discard&lt;/code&gt; makes intentional ignoring explicit&lt;/li&gt;
&lt;li&gt;Limited to primitive types for simplicity and safety&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you need to return just one extra piece of information, such as a success flag or minor result, Turbine’s out parameter is a clean and practical solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn More
&lt;/h2&gt;

&lt;p&gt;Turbine is still in active development, and its syntax and semantics are evolving gradually.&lt;br&gt;
You can check the progress and documentation here:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/tsubo164/turbine" rel="noopener noreferrer"&gt;GitHub (source)&lt;/a&gt;&lt;br&gt;
👉 &lt;a href="https://tsubo164.github.io/turbine-docs/" rel="noopener noreferrer"&gt;Project Docs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  For Those Interested
&lt;/h2&gt;

&lt;p&gt;If you’re into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Language design and compiler implementation&lt;/li&gt;
&lt;li&gt;Embeddable scripting languages that pair well with C/C++&lt;/li&gt;
&lt;li&gt;Minimal, Markdown-inspired syntax&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’d love to hear your thoughts and feedback!&lt;br&gt;
I’ll continue sharing updates and implementation notes as Turbine evolves.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>tooling</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Memory Management in Turbine: A Markdown-Inspired Scripting Language</title>
      <dc:creator>Hiroshi Tsubokawa</dc:creator>
      <pubDate>Mon, 28 Jul 2025 16:36:12 +0000</pubDate>
      <link>https://forem.com/tsubo164/memory-management-in-turbine-a-markdown-inspired-scripting-language-5ih</link>
      <guid>https://forem.com/tsubo164/memory-management-in-turbine-a-markdown-inspired-scripting-language-5ih</guid>
      <description>&lt;h2&gt;
  
  
  Understanding Memory Management in Turbine
&lt;/h2&gt;

&lt;p&gt;In previous posts, I introduced &lt;em&gt;Turbine&lt;/em&gt;, a scripting language with Markdown-like syntax and some interesting features, like its enum system. Today, I’ll dive a bit deeper and walk through how memory is managed under the hood.&lt;/p&gt;

&lt;p&gt;Turbine uses automatic memory management powered by garbage collection (GC). That means you don’t need to manually call &lt;code&gt;free()&lt;/code&gt; like in C — memory cleanup is handled behind the scenes.&lt;/p&gt;

&lt;p&gt;Still, if you’re interested in virtual machine (VM) internals or building your own language runtime, this post will give you an overview of how memory works in Turbine.&lt;/p&gt;




&lt;h2&gt;
  
  
  Primitive vs Reference Types
&lt;/h2&gt;

&lt;p&gt;Turbine distinguishes between two kinds of values when it comes to memory management:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Primitive types&lt;/strong&gt; (&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, etc.) are &lt;em&gt;not&lt;/em&gt; managed by the GC.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reference types&lt;/strong&gt; (arrays, strings, user-defined structs, etc.) &lt;em&gt;are&lt;/em&gt; managed by the GC.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reference values are allocated on the heap, and what gets stored in VM registers or local variables is a reference (i.e. pointer) to those heap objects.&lt;br&gt;&lt;br&gt;
The garbage collector follows these references to determine which objects are still reachable and should stay alive.&lt;/p&gt;




&lt;h2&gt;
  
  
  Register-Based VM
&lt;/h2&gt;

&lt;p&gt;Turbine’s virtual machine is &lt;strong&gt;register-based&lt;/strong&gt;. Unlike stack-based VMs that use &lt;code&gt;push&lt;/code&gt; and &lt;code&gt;pop&lt;/code&gt; operations, Turbine instructions directly operate on register indices.&lt;/p&gt;

&lt;p&gt;At compile time, the number of registers needed for a function is calculated — including all temporaries. This enables the VM to allocate just enough register space per function call, reducing overhead and avoiding unnecessary overlap between register lifetimes.&lt;/p&gt;

&lt;p&gt;Each register can hold either a primitive value or a reference.&lt;br&gt;&lt;br&gt;
The GC inspects the registers and traces any reference-type values they contain, ensuring that only live heap objects stay around.&lt;/p&gt;




&lt;h2&gt;
  
  
  Precise Garbage Collection
&lt;/h2&gt;

&lt;p&gt;Turbine implements a &lt;strong&gt;precise, tracing garbage collector&lt;/strong&gt;, based on the classic mark-and-sweep algorithm.&lt;/p&gt;

&lt;p&gt;Key characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The GC knows exactly which values are references and which are primitives.&lt;/li&gt;
&lt;li&gt;It starts from roots (like global variables and VM registers), marks reachable objects, and sweeps the rest.&lt;/li&gt;
&lt;li&gt;Fields within heap objects are recursively traced.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since Turbine is statically typed, the compiler can &lt;strong&gt;simulate register types during code generation&lt;/strong&gt; and record which registers hold references at each instruction. This allows the GC to consult a &lt;em&gt;stack map-like table&lt;/em&gt; at runtime — no guessing needed.&lt;/p&gt;

&lt;p&gt;Unlike conservative GCs (common in C-based runtimes), Turbine’s collector doesn’t need to keep ambiguous data "just in case it’s a pointer". Instead, it uses static type information to precisely identify which values to trace.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example: GC in Action
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;gc&lt;/span&gt;

&lt;span class="cp"&gt;# main(args vec{string}) int
&lt;/span&gt;  &lt;span class="c1"&gt;// Create a temporary vec&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// The register holding the vec gets overwritten&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="mf"&gt;0..10&lt;/span&gt;
    &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"before ==============================="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;gc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="c1"&gt;// Temporary vec is now unreachable and should be collected&lt;/span&gt;
  &lt;span class="n"&gt;gc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"after  ==============================="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;gc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, a temporary &lt;code&gt;vec&lt;/code&gt; is used in the first loop, and then its register is reused in the second loop, making the original reference unreachable.&lt;/p&gt;

&lt;p&gt;Calling &lt;code&gt;gc.collect()&lt;/code&gt; doesn’t immediately run the GC. Instead, it sets a flag in the VM, and garbage collection is triggered at the next safe point.&lt;br&gt;
However, in most cases, it feels like GC runs instantly, so it behaves much like manual collection from the programmer’s perspective.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Turbine runs on a &lt;strong&gt;register-based virtual machine&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reference types&lt;/strong&gt; are managed by a &lt;strong&gt;precise mark-and-sweep GC&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Static type information enables &lt;strong&gt;accurate tracing without ambiguity&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a developer, you don’t need to manually manage memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;Turbine is still under active development. Syntax and features are evolving, and I'm documenting the process as I go.&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/tsubo164/turbine" rel="noopener noreferrer"&gt;GitHub (source)&lt;/a&gt;&lt;br&gt;
👉 &lt;a href="https://tsubo164.github.io/turbine-docs/" rel="noopener noreferrer"&gt;Project Docs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interested?
&lt;/h2&gt;

&lt;p&gt;If you're:&lt;/p&gt;

&lt;p&gt;curious about designing a new language from scratch&lt;/p&gt;

&lt;p&gt;looking for a small, embeddable scripting language that plays well with C/C++&lt;/p&gt;

&lt;p&gt;into clean, Markdown-inspired syntax&lt;/p&gt;

&lt;p&gt;…I’d love your thoughts and feedback!&lt;br&gt;
More dev logs, code examples, and internals coming soon.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>c</category>
      <category>cpp</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Enums in Turbine: More Than Just Constants</title>
      <dc:creator>Hiroshi Tsubokawa</dc:creator>
      <pubDate>Mon, 05 May 2025 11:18:37 +0000</pubDate>
      <link>https://forem.com/tsubo164/enums-in-turbine-more-than-just-constants-434p</link>
      <guid>https://forem.com/tsubo164/enums-in-turbine-more-than-just-constants-434p</guid>
      <description>&lt;p&gt;In &lt;a href="https://dev.to/tsubo164/introducing-turbine-a-scripting-language-for-c-and-c-projects-5cj4"&gt;my previous post&lt;/a&gt;, I introduced &lt;strong&gt;Turbine&lt;/strong&gt;, a lightweight scripting language with a Markdown-like syntax. This time, I’d like to dive into a feature that stands out from conventional programming languages: &lt;strong&gt;Enums&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Moving Beyond Integer-Based Enums
&lt;/h2&gt;

&lt;p&gt;In many languages, enums are used to represent states or flags by assigning consecutive integers or bit values (using things like &lt;code&gt;iota()&lt;/code&gt; or &lt;code&gt;auto()&lt;/code&gt;). A typical usage would be something like this in C++:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Color&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;green&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;blue&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="n"&gt;Color&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;red&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"red&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;green&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"green&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;blue&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"blue&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bit-shifting (like &lt;code&gt;1 &amp;lt;&amp;lt; 0&lt;/code&gt;, &lt;code&gt;1 &amp;lt;&amp;lt; 1&lt;/code&gt;, etc.) is often used for flag enums too, especially when working with combinations.&lt;/p&gt;

&lt;p&gt;Turbine, however, takes a different approach: &lt;strong&gt;it removes the need to think about assigning specific numeric values altogether&lt;/strong&gt;. Instead, you can directly associate &lt;strong&gt;meaningful data fields&lt;/strong&gt; with each enum entry. That makes your enums more expressive and structured.&lt;/p&gt;

&lt;p&gt;Here’s what it looks like in Turbine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;## Color enum
&lt;/span&gt;  &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;symbol&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rgba_index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bgra_index&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;R&lt;/span&gt;      &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"red"&lt;/span&gt;   &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;         &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;G&lt;/span&gt;      &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"green"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;         &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;B&lt;/span&gt;      &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"blue"&lt;/span&gt;  &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;         &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;A&lt;/span&gt;      &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"alpha"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;         &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="cp"&gt;# main() int
&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;
  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bgra_index&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This format allows you to work with richer data—like color channels for different formats—without writing extra logic or &lt;code&gt;switch&lt;/code&gt; statements. In essence, &lt;strong&gt;Turbine enums act like 2D tables where each row is a named data record&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Not Just Call It a Table?
&lt;/h2&gt;

&lt;p&gt;Early in development, I originally called this feature a "table" instead of an "enum". The syntax even resembled Markdown tables. But several issues came up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;|&lt;/code&gt; character conflicted with bitwise OR when writing constant expressions.&lt;/li&gt;
&lt;li&gt;Explaining the feature took more effort than just calling it an "enum".&lt;/li&gt;
&lt;li&gt;The term "&lt;strong&gt;table&lt;/strong&gt;" was easily confused with "&lt;strong&gt;table types&lt;/strong&gt;" in other languages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Eventually, I chose to stick with the more familiar term: &lt;strong&gt;Enum&lt;/strong&gt;. Describing it as a “2D enum” turns out to be surprisingly intuitive for most developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Looping Over Enum Entries
&lt;/h2&gt;

&lt;p&gt;Sometimes, you need to loop over all enum values—like when building dropdown menus or defining configurable options. Turbine makes this very straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;## Month enum
&lt;/span&gt;  &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;symbol&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;         &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Jan&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"January"&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Feb&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"February"&lt;/span&gt;   &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Mar&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"March"&lt;/span&gt;      &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Apr&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"April"&lt;/span&gt;      &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;May&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"May"&lt;/span&gt;        &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Jun&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"June"&lt;/span&gt;       &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Jul&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"July"&lt;/span&gt;       &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Aug&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"August"&lt;/span&gt;     &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Sep&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"September"&lt;/span&gt;  &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Oct&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"October"&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Nov&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"November"&lt;/span&gt;   &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Dec&lt;/span&gt;    &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"December"&lt;/span&gt;   &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;

&lt;span class="cp"&gt;# main(args vec{string}) int
&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;month_menu&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Select Month"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;Month&lt;/span&gt;
    &lt;span class="n"&gt;vecpush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;month_menu&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Use month_menu as the dropdown options&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By treating enums as iterable collections, you can keep your UI and logic in sync without redundancy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enum Loops: A Syntax Exception
&lt;/h2&gt;

&lt;p&gt;In Turbine, &lt;code&gt;for&lt;/code&gt; loops normally expect an &lt;strong&gt;expression&lt;/strong&gt; after &lt;code&gt;in&lt;/code&gt;, like a range or a collection. But there's a special exception: &lt;strong&gt;Enums&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of writing something like &lt;code&gt;in Enum.all()&lt;/code&gt; or a built-in &lt;code&gt;.values&lt;/code&gt;, Turbine allows you to simply write &lt;code&gt;for val in Month&lt;/code&gt;. This improves readability and matches real-world use cases like UI building.&lt;/p&gt;

&lt;p&gt;Yes, it bends the consistency of the syntax a bit, but the trade-off is worthwhile. In all other contexts, using just an enum type like &lt;code&gt;Month&lt;/code&gt; without a field (e.g., &lt;code&gt;Month.Jan&lt;/code&gt;) would result in a syntax error—so the parser treats this for loop form as a special case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Turbine enums are more than just symbolic constants. They’re essentially &lt;strong&gt;collections of named records&lt;/strong&gt;, shaped by their origin in table-based syntax. If you ever wanted to manage small tables of structured data inside a script, Turbine enums might be just what you’re looking for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn More
&lt;/h2&gt;

&lt;p&gt;Turbine is still under active development, and the syntax and features are evolving. You can follow along here:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/tsubo164/turbine" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
👉 &lt;a href="https://tsubo164.github.io/turbine-docs/" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interested in Turbine?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Curious about language design?&lt;/li&gt;
&lt;li&gt;Looking for a lightweight scripting language that pairs well with C/C++?&lt;/li&gt;
&lt;li&gt;Love the idea of Markdown-style syntax?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any of that sounds interesting, I'd love to hear from you!&lt;br&gt;
Come join the discussion, share feedback, or just hang out with fellow language enthusiasts:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://discord.gg/CntCY5Mz" rel="noopener noreferrer"&gt;Join the Turbine Discord&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>✨ Introducing Turbine – A Scripting Language for C and C++ Projects</title>
      <dc:creator>Hiroshi Tsubokawa</dc:creator>
      <pubDate>Tue, 22 Apr 2025 12:49:44 +0000</pubDate>
      <link>https://forem.com/tsubo164/introducing-turbine-a-scripting-language-for-c-and-c-projects-5cj4</link>
      <guid>https://forem.com/tsubo164/introducing-turbine-a-scripting-language-for-c-and-c-projects-5cj4</guid>
      <description>&lt;p&gt;Hello everyone! 👋&lt;/p&gt;

&lt;p&gt;I'm excited to introduce &lt;strong&gt;Turbine&lt;/strong&gt;, a small and focused scripting language designed to be embedded into &lt;strong&gt;C and C++&lt;/strong&gt; applications with minimal overhead.&lt;br&gt;
It features a clean, &lt;strong&gt;Markdown-inspired syntax&lt;/strong&gt; that keeps scripts easy to read and write—for both engineers and non-engineers alike.&lt;/p&gt;

&lt;p&gt;Turbine is built around a single idea:  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Keep things simple, explicit, and practical.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Turbine is designed for developers who want &lt;strong&gt;a lightweight, embeddable scripting tool&lt;/strong&gt; that behaves predictably and integrates seamlessly with C or C++ codebases.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚡️ Why Turbine?
&lt;/h2&gt;

&lt;p&gt;If you’ve ever wanted to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;define behavior in plain-text config files&lt;/li&gt;
&lt;li&gt;script parts of your application logic&lt;/li&gt;
&lt;li&gt;allow lightweight user-defined automation&lt;/li&gt;
&lt;li&gt;do all that &lt;strong&gt;without pulling in a heavyweight scripting runtime&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;…then Turbine might be just what you’re looking for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Minimal and readable syntax&lt;/strong&gt;, loosely inspired by Markdown&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No magic&lt;/strong&gt;: no generics, no polymorphism, no complex runtime semantics&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C99-compatible core&lt;/strong&gt;, easily embeddable in both C and C++ projects&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Familiar built-in containers&lt;/strong&gt;: &lt;code&gt;vec&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt;, &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;queue&lt;/code&gt;, &lt;code&gt;stack&lt;/code&gt; — inspired by C++ STL concepts, but much simpler&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scoped blocks&lt;/strong&gt; for managing variable lifetime and organization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Turbine gives you just enough power — no more, no less.&lt;/p&gt;
&lt;h2&gt;
  
  
  What Does the Syntax Look Like?
&lt;/h2&gt;

&lt;p&gt;Turbine is inspired by many ideas and feelings from Markdown.&lt;br&gt;
However, its grammar is not fully compatible, and it follows its own style.&lt;/p&gt;
&lt;h3&gt;
  
  
  Hello World
&lt;/h3&gt;

&lt;p&gt;The classic "Hello World" looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Prints "Hello, World!" to the console.&lt;/span&gt;
&lt;span class="cp"&gt;# main(args vec{string}) int
&lt;/span&gt;  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;main&lt;/code&gt; is the function called first by the virtual machine.&lt;/li&gt;
&lt;li&gt;Function definitions are in the format: &lt;code&gt;# function_name(parameter_name type, ...) return_type&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C++ style comments&lt;/strong&gt; are used (// or /* ... */).&lt;/li&gt;
&lt;li&gt;print() is a built-in function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summing Even Numbers
&lt;/h3&gt;

&lt;p&gt;This example demonstrates working with vectors, loops, and basic conditional logic.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Define a simple function&lt;/strong&gt; to process a vector.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loop through a vector&lt;/strong&gt; of integers and apply logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use an if-statement&lt;/strong&gt; to filter out even values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calculate the total sum&lt;/strong&gt; of the filtered values.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;# sum_even(numbers vec{int}) int
&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
      &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;

&lt;span class="cp"&gt;# main() int
&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sum_even&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sum of even numbers:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🛠️ Project Status
&lt;/h2&gt;

&lt;p&gt;Turbine is currently in early development.&lt;br&gt;&lt;br&gt;
It’s capable of running real scripts, comes with a test suite, and is already being embedded into native applications.&lt;/p&gt;

&lt;p&gt;I'm now looking for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;early users to try things out&lt;/li&gt;
&lt;li&gt;feedback from C/C++ developers&lt;/li&gt;
&lt;li&gt;contributors who are excited to help shape the language&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚀 Getting Started
&lt;/h2&gt;

&lt;p&gt;GitHub repository:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://github.com/tsubo164/turbine" rel="noopener noreferrer"&gt;https://github.com/tsubo164/turbine&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Documentation:&lt;br&gt;
👉 &lt;a href="https://tsubo164.github.io/turbine-docs" rel="noopener noreferrer"&gt;Turbine Programming Language&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To build it, all you need is a &lt;strong&gt;C99-compatible compiler&lt;/strong&gt; (e.g. &lt;code&gt;gcc&lt;/code&gt;, &lt;code&gt;clang&lt;/code&gt;, &lt;code&gt;tcc&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;No external dependencies. No build system hell.&lt;/p&gt;




&lt;h2&gt;
  
  
  💬 Join the Community
&lt;/h2&gt;

&lt;p&gt;I’d love to hear from you!&lt;/p&gt;

&lt;p&gt;Join our Discord to chat, give feedback, or follow development:&lt;br&gt;&lt;br&gt;
👉 &lt;em&gt;[&lt;a href="https://discord.gg/Q6pABVW3" rel="noopener noreferrer"&gt;https://discord.gg/Q6pABVW3&lt;/a&gt;]&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Thanks for reading!&lt;br&gt;&lt;br&gt;
I hope Turbine becomes a useful tool in your C or C++ toolkit.&lt;/p&gt;

&lt;p&gt;Let’s build something simple, together. ⚙️&lt;/p&gt;




&lt;h3&gt;
  
  
  🧠 P.S.
&lt;/h3&gt;

&lt;p&gt;If you’ve ever wished for a scripting language that feels like a natural extension of C or C++ — with familiar containers and no surprises — give Turbine a try.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>c</category>
      <category>opensource</category>
      <category>cpp</category>
    </item>
  </channel>
</rss>
