Class VariableStruct

java.lang.Object
org.cloudburstmc.mojava.runtime.struct.VariableStruct
All Implemented Interfaces:
MoStruct, MoValue
Direct Known Subclasses:
ArrayStruct, ContextStruct

public class VariableStruct extends Object implements MoStruct
Two-segment variable/temp values (v.x, t.y) are the hot read path. The compiler resolves each name to a stable int slot (via slotFor(java.lang.String)) at compile time and reads it with an array load instead of a HashMap.get.

The map stays the canonical store, so getMap(), for_each, dynamic keys and nested structs behave exactly as before. slots is a write-through fast cache: every mutation funnels through slotSet(int, java.lang.String, org.cloudburstmc.mojava.runtime.value.MoValue), so a slot read never goes stale. (External callers that mutate the map directly via getMap().put(...) would bypass it — use setDirectly(java.lang.String, org.cloudburstmc.mojava.runtime.value.MoValue) instead.)

  • Field Details

  • Constructor Details

    • VariableStruct

      public VariableStruct()
  • Method Details

    • slotFor

      public static int slotFor(String name)
      Stable slot for a variable name, assigned once and shared across all structs/runtimes.
    • slotGet

      public MoValue slotGet(int slot)
      Fast read of a compile-time slot; null when unset (caller maps that to 0.0).
    • slotSet

      public void slotSet(int slot, String name, MoValue value)
      Write-through: updates both the slot cache and the canonical map.
    • set

      public void set(Iterator<String> names, MoValue value)
      Specified by:
      set in interface MoStruct
    • setDirectly

      public void setDirectly(String name, MoValue value)
    • get

      public MoValue get(Iterator<String> names, MoParams params)
      Specified by:
      get in interface MoStruct
    • getRaw

      public MoValue getRaw(Iterator<String> names, MoParams params)
      Specified by:
      getRaw in interface MoStruct
    • clear

      public void clear()
      Specified by:
      clear in interface MoStruct