Skip to content

V4 Virtual Machine v0.9.0

Choose a tag to compare

@kirisaki kirisaki released this 03 Nov 03:27
· 45 commits to main since this release

V4 Virtual Machine v0.9.0 πŸš€

Major release adding preemptive multitasking system for embedded microcontrollers.

🎯 Highlights

Preemptive Multitasking System

  • Priority-based scheduler supporting up to 8 concurrent tasks
  • Inter-task messaging with 16-message ring buffer queue
  • Platform abstraction for timer interrupts (ESP32-C6, CH32V203, etc.)
  • Lightweight footprint: 42KB static library with LTO optimization

New VM Opcodes (0x90-0x9A)

11 new instructions for task control and messaging:

  • TASK_SPAWN, TASK_EXIT, TASK_SLEEP, TASK_YIELD
  • CRITICAL_ENTER, CRITICAL_EXIT
  • TASK_SEND, TASK_RECEIVE, TASK_RECEIVE_BLOCKING
  • TASK_SELF, TASK_COUNT

πŸ“Š Performance

Metric Value
Context switch <100ΞΌs
Message passing <50ΞΌs
Default time slice 10ms (configurable)

πŸ’Ύ Memory Footprint

Component Size
Static library (Release) 42KB
Task scheduler ~400 bytes
Per-task TCB 32 bytes
Message queue 132 bytes (16 messages)

πŸ”§ Build Optimizations

  • LTO (Link Time Optimization) now enabled by default
  • Function/data section splitting for better dead code elimination
  • Linker garbage collection (-Wl,--gc-sections)
  • Unused features automatically removed in final applications

πŸ“ API Example

#include "v4/task.h"

// Initialize task system (10ms time slice)
vm_task_init(vm, 10);

// Spawn a task with priority 128
int task_id = vm_task_spawn(vm, word_idx, 128, 256, 64);

// Task control
vm_task_sleep(vm, 100);  // Sleep 100ms
vm_task_yield(vm);       // Yield to other tasks

// Inter-task messaging
vm_task_send(vm, target_task, msg_type, data);
vm_task_receive(vm, msg_type, &data, &src_task);

πŸ§ͺ Testing

  • 10 test suites with comprehensive coverage
  • 119 assertions for task system functionality
  • All tests passing βœ…

πŸ“š Documentation

See updated:

πŸ”— Platform Support

Task system requires platform-specific timer interrupt implementation:

  • Mock platform included for testing
  • Platform implementations available in V4-ports repository

πŸŽ“ Credits

Implemented with assistance from Claude Code (Anthropic).


Full Changelog

Added:

  • Preemptive multitasking system with priority-based scheduler
  • Task management API: vm_task_init(), vm_task_spawn(), vm_task_exit()
  • Task control: vm_task_sleep(), vm_task_yield(), vm_task_critical_enter/exit()
  • Inter-task messaging with type filtering and broadcast support
  • Platform abstraction layer (v4_task_platform.h)
  • 11 new VM opcodes (0x90-0x9A)
  • Comprehensive test suite (119 assertions)

Changed:

  • LTO enabled by default (V4_ENABLE_LTO=ON)
  • Enhanced size optimization with function/data section splitting
  • Binary size increase: +28KB (14KB β†’ 42KB static library)

Performance:

  • Context switch: <100ΞΌs
  • Message passing: <50ΞΌs
  • Default time slice: 10ms (configurable)

See CHANGELOG.md for complete details.