Target Platform Overview

Target Platform Overview

VSCXML generates state machine code for multiple target platforms. This guide compares the targets and helps you choose the right one for your project.

Table of Contents

  1. Target Comparison
  2. Quick Start
  3. Architecture
  4. Datamodel Support
  5. Event Processing
  6. Target Guides

Target Comparison

Target Status Datamodels Timer System Use Case
Java Production ECMAScript, XPath, Null, Native Executor thread JVM applications
JavaScript Production ECMAScript, Null, Native Native setTimeout Web, Node.js
C# Production ECMAScript, Null, Native Task.Delay .NET applications, Unity
C Production ECMAScript, Null, Native Platform-adaptive Embedded, desktop
Python Production ECMAScript, Null, Native Threading Data science, scripting
Go Production ECMAScript, Null, Native Goroutine Cloud, microservices

Feature Matrix

Feature Java JavaScript C# C Python Go
W3C ECMAScript 100% 100% 100% 100% 100% 100%
Delayed events Executor setTimeout Task.Delay Platform Threading Goroutine
Thread safety Built-in N/A Built-in Optional Built-in Built-in
Memory management GC GC GC Manual/static GC GC
Native-image GraalJS N/A AOT Full N/A Native
Invoke bundling Runtime --bundle --bundle --bundle --bundle --bundle
MISRA support N/A N/A N/A MISRA-aware N/A N/A

Quick Start

Code Generation

bash
# Java
scxml-gen traffic.scxml -o TrafficLight.java --package com.example

# JavaScript
scxml-gen traffic.scxml -t js -o TrafficLight.js

# C#
scxml-gen traffic.scxml -t csharp -o TrafficLight.cs --namespace Example

# C
scxml-gen traffic.scxml -t c -o traffic_light.c

# Python
scxml-gen traffic.scxml -t python -o TrafficLight.py

# Go
scxml-gen traffic.scxml -t go -o TrafficLight.go

Basic Usage

Java:

java
TrafficLight machine = new TrafficLight();
ContinuousStateMachineExecutor executor =
    new ContinuousStateMachineExecutor(machine);
executor.start();
executor.send(EVT_TIMER);
executor.close();

JavaScript:

javascript
const machine = new TrafficLight();
machine.start();
machine.send('timer');

C#:

csharp
var machine = new TrafficLight();
machine.Start();
machine.Send("timer");

C:

c
TrafficLight sm;
TrafficLight_init(&sm);
TrafficLight_start(&sm);
TrafficLight_send(&sm, EVT_TIMER, NULL);
TrafficLight_destroy(&sm);

Python:

python
from traffic_light import TrafficLight

machine = TrafficLight()
machine.start()
machine.send("timer")

Go:

go
import "./scxmlgen"

machine := NewTrafficLight()
machine.Start()
machine.Send(scxmlgen.NewEvent("timer"))

Architecture

┌───────────────────────────────────────────────────────────────────────────────────┐
│                               SCXML Source                                          │
│                           (state-machine.scxml)                                     │
└───────────────────────────────────┬───────────────────────────────────────────────┘
                                    │
       ┌────────────┬───────────────┼───────────────┬────────────┬────────────┐
       │            │               │               │            │            │
       ▼            ▼               ▼               ▼            ▼            ▼
  ┌─────────┐  ┌─────────┐    ┌─────────┐    ┌─────────┐  ┌─────────┐  ┌─────────┐
  │ Java    │  │ JS      │    │ C#      │    │ C       │  │ Python  │  │ Go      │
  │Generator│  │Generator│    │Generator│    │Generator│  │Generator│  │Generator│
  └────┬────┘  └────┬────┘    └────┬────┘    └────┬────┘  └────┬────┘  └────┬────┘
       │            │               │               │            │            │
       ▼            ▼               ▼               ▼            ▼            ▼
  ┌─────────┐  ┌─────────┐    ┌─────────┐    ┌─────────┐  ┌─────────┐  ┌─────────┐
  │.java    │  │.js      │    │.cs      │    │.c/.h    │  │.py      │  │.go      │
  │(JVM 11+)│  │(ES6+)   │    │(.NET 6+)│    │(C11)    │  │(3.10+)  │  │(1.21+)  │
  └────┬────┘  └────┬────┘    └────┬────┘    └────┬────┘  └────┬────┘  └────┬────┘
       │            │               │               │            │            │
       ▼            ▼               ▼               ▼            ▼            ▼
  ┌─────────┐  ┌─────────┐    ┌─────────┐    ┌─────────┐  ┌─────────┐  ┌─────────┐
  │scxml-   │  │@scxml-  │    │ScxmlGen.│    │scxml-   │  │scxmlgen │  │scxmlgen │
  │core     │  │gen/     │    │Runtime  │    │runtime  │  │(pip)    │  │(go mod) │
  │runtime  │  │runtime  │    │(NuGet)  │    │(header) │  │         │  │         │
  └─────────┘  └─────────┘    └─────────┘    └─────────┘  └─────────┘  └─────────┘

Generated Code Characteristics

Aspect Java JavaScript C# C Python Go
Output Single .java Single .js ES module Single .cs .c + .h Single .py Single .go
Base class TranspiledStateMachine ScxmlStateMachine TranspiledStateMachine Struct + functions TranspiledStateMachine TranspiledStateMachine
State lookup O(1) BitSet O(1) Set O(1) BitSet O(1) bitfield O(1) Set O(1) map
Event dispatch Integer constants Integer constants String constants Integer constants Integer constants Integer constants

Datamodel Support

By Target

Datamodel Java JavaScript C# C Python Go
ecmascript Rhino/GraalJS Native Jint JerryScript dukpy Goja
xpath Saxon-HE - - - - -
null Built-in Built-in Built-in Built-in Built-in Built-in
native-java Compile-time - - - - -
native-js - Compile-time - - - -
native-csharp - - Compile-time - - -
native-c - - - Compile-time - -
native-python - - - - Compile-time -
native-go - - - - - Compile-time

Choosing a Datamodel

Need scripting?
├── Yes → ecmascript (full W3C compliance)
│         └── Java: Use Rhino or GraalJS
│         └── JS: Uses native JavaScript
│         └── C#: Jint (~2MB)
│         └── C: JerryScript (~200KB)
│         └── Python: dukpy (~2MB)
│         └── Go: Goja (~5MB)
│
└── No → Which target?
         ├── Java → native-java or null
         ├── JavaScript → native-js or null
         ├── C# → native-csharp or null
         ├── C → native-c or null (smallest footprint)
         ├── Python → native-python or null
         └── Go → native-go or null

ECMAScript Engine Comparison

Engine Platform Size Native-Image/AOT Notes
Rhino Java ~2MB No Default, mature
GraalJS Java ~30MB Yes Faster, GraalVM
Native JavaScript 0 N/A Uses JS engine
Jint C# ~2MB Yes Cross-platform .NET
JerryScript C ~200KB Yes Embedded-friendly
dukpy Python ~2MB N/A pip install, ES5
Goja Go ~5MB Yes Pure Go, ES5.1+

Event Processing

Timer Mechanisms

┌─────────────────────────────────────────────────────────────────────┐
│                   <send event="timeout" delay="3s"/>                 │
└─────────────────────────────────────────────────────────────────────┘
     │              │              │              │              │
     ▼              ▼              ▼              ▼              ▼
┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐
│  Java   │  │   JS    │  │   C#    │  │    C    │  │ Python  │
├─────────┤  ├─────────┤  ├─────────┤  ├─────────┤  ├─────────┤
│Executor │  │setTimeout│  │Task.    │  │Platform │  │Threading│
│thread   │  │(event   │  │Delay    │  │specific │  │Timer    │
│         │  │loop)    │  │         │  │         │  │         │
└─────────┘  └─────────┘  └─────────┘  └─────────┘  └─────────┘

Event Processing Patterns

Java - Executor required:

java
// Background thread handles delayed events
ContinuousStateMachineExecutor executor =
    new ContinuousStateMachineExecutor(machine);
executor.start();
executor.send(EVT_GO);  // Async processing
executor.close();

JavaScript - Native event loop:

javascript
// setTimeout handles delayed events automatically
const machine = new TrafficLight();
machine.start();
machine.send('go');  // Processed via event loop

C - Platform-dependent:

c
// Arduino/bare-metal: Manual tick required
while (running) {
    scxml_executor_tick(sm.executor, elapsed_ms);
    // Process inputs...
}

// Desktop: Timers fire automatically
MyMachine_send(&sm, EVT_GO, NULL);

Target Guides

Java Target

Full guide: JAVA.md

Key features:

  • Executor patterns (Continuous, RunToCompletion)
  • ECMAScript engine switching (Rhino/GraalJS)
  • GraalVM native-image support
  • Java object binding in scripts

Dependencies:

gradle
implementation 'com.scxmlgen:scxml-core:1.0.0'
implementation 'org.mozilla:rhino:1.7.15'

JavaScript Target

Full guide: JAVASCRIPT.md

Key features:

  • ES6+ class generation
  • React/Vue/Svelte integration
  • Runtime interpreter for dynamic SCXML
  • Native setTimeout for delays

Dependencies:

bash
npm install @scxml-gen/runtime  # Optional

C# Target

Full guide: CSHARP.md

Key features:

  • .NET 6+ and .NET Framework 4.7.2+ support
  • Jint ECMAScript engine integration
  • Unity game engine support
  • Full W3C compliance (200/200 tests)

Dependencies:

xml
<PackageReference Include="ScxmlGen.Runtime" Version="1.0.0" />
<PackageReference Include="Jint" Version="3.1.6" />  <!-- For ECMAScript -->

C Target

Full guide: C.md

Key features:

  • Embedded-friendly (Arduino, ESP32, bare-metal)
  • Platform-adaptive timer system
  • Static memory allocation (MISRA-aware mode)
  • JerryScript for ECMAScript

Dependencies:

bash
# None required - copy generated files
# Optional: JerryScript for ECMAScript

Python Target

Full guide: PYTHON.md

Key features:

  • Python 3.10+ with match/case syntax
  • dukpy ECMAScript engine integration
  • Thread-safe ContinuousExecutor
  • Self-contained bundled distribution

Dependencies:

bash
pip install scxmlgen           # Runtime library
pip install dukpy>=0.3.0       # For ECMAScript datamodel

Go Target

Full guide: GO.md

Key features:

  • Go 1.21+ with goroutine-based executor
  • Goja ECMAScript engine (pure Go, ES5.1+)
  • Thread-safe ContinuousExecutor
  • Zero dependencies for null/native-go datamodels

Dependencies:

bash
go get github.com/scxmlgen/scxmlgen           # Runtime library
go get github.com/dop251/goja                 # For ECMAScript datamodel

See Also