Home / Docs / Python Progress

Historical engineering note, with a current-status update below, corrected. Everything from "Completed Work" onward is a point-in-time snapshot from January 2026, capturing early libc prerequisite work for a planned MicroPython port. An earlier version of this page's "Current status" section claimed MayteraOS had moved past MicroPython entirely to ship real CPython instead; that claim did not match the source tree (there is no CPython port anywhere in userland/) and has been corrected below.

Python Support Implementation Progress

Current status, corrected

MayteraOS ships a MicroPython port as /APPS/PYTHON.ELF (userland/python/micropython/, MIT-licensed port glue over MicroPython's own MIT-licensed source), with MayteraOS-specific os, socket and maytera modules for file, network and window access from Python code. This is what the Start menu's Python entry and Files' "Open With" launch.

A separate, much smaller hand-written Python-subset interpreter also exists in the tree (userland/python/ examples plus an original minimal interpreter, binary name python), predates the MicroPython work, and implements a limited subset: variables, expressions, print(), basic control flow, no classes or real standard library. It is original MayteraOS code, not a third-party component, and is a separate binary from the MicroPython-based PYTHON.ELF.

There is no CPython port in the current public repository or release. See the Python Support plan page for the original MicroPython recommendation this shipped from, and Licenses for the MicroPython license.

Historical: Phase 1 prerequisite work (January 2026)

Date: January 27, 2026 Status: Phase 1 Prerequisites Complete

Completed Work

P1 Priority Functions (Essential for MicroPython)

1. setjmp/longjmp Implementation

Files:

  • userland/libc/setjmp.h - Header with jmp_buf structure
  • userland/libc/setjmp.asm - x86_64 assembly implementation

Features:

  • Saves/restores callee-saved registers (RBX, RBP, R12-R15)
  • Saves stack pointer and return address
  • Returns 0 on first call, specified value on longjmp
  • Correctly handles x86_64 calling convention

2. snprintf/vsnprintf Implementation

Files:

  • userland/libc/stdio.c - Updated with new functions
  • userland/libc/stdio.h - Updated declarations

Features:

  • Buffer size limiting with null termination
  • Support for %d, %i, %u, %x, %X, %p, %c, %s, %%
  • Width and zero-padding support
  • Left/right justification with '-' flag
  • Length modifiers: l, ll, z

3. strtol/strtoul Functions

Files:

  • userland/libc/stdlib.c - Implementation
  • userland/libc/stdlib.h - Declarations

Functions implemented:

  • strtol() - Convert string to long
  • strtoul() - Convert string to unsigned long
  • strtoll() - Convert string to long long
  • strtoull() - Convert string to unsigned long long

Features:

  • Automatic base detection (0x for hex, 0b for binary, 0 for octal)
  • Support for bases 2-36
  • Whitespace skipping
  • Sign handling
  • End pointer support

Build System

  • Updated userland/libc/Makefile to include setjmp.asm
  • Updated userland/libc/maytera.h to include setjmp.h
  • All files compile successfully

Next Steps for MicroPython Port

Phase 1 Remaining Work

  1. Download MicroPython Source
   git clone https://github.com/micropython/micropython.git
   cd micropython
   git checkout v1.22.0  # or latest stable
  1. Create Directory Structure
   kernel/python/
   ├── mpconfigport.h      # MayteraOS configuration
   ├── mphalport.h         # HAL function declarations
   ├── mphalport.c         # HAL function implementations
   ├── qstrdefsport.h      # QSTR definitions
   └── Makefile            # Build integration
  1. Implement HAL Functions
  • mp_hal_stdin_rx_chr() - Read character from keyboard
  • mp_hal_stdout_tx_strn() - Write string to console/serial
  • mp_hal_ticks_ms() - Get milliseconds since boot
  • mp_hal_delay_ms() - Delay function
  1. Configure Memory
  • Allocate GC heap (256KB-1MB)
  • Implement memory wrappers if needed
  1. Test Basic REPL
  • Verify VM initialization
  • Test basic Python operations

Files Modified This Session

FileChanges
userland/libc/setjmp.hCreated - jmp_buf structure
userland/libc/setjmp.asmCreated - x86_64 setjmp/longjmp
userland/libc/stdio.cAdded snprintf, vsnprintf, sprintf
userland/libc/stdio.hAdded function declarations
userland/libc/stdlib.cAdded strtol, strtoul, strtoll, strtoull
userland/libc/stdlib.hAdded function declarations
userland/libc/maytera.hAdded setjmp.h include
userland/libc/MakefileAdded setjmp.asm to build

Test Verification

The libc builds successfully:

$ cd userland/libc && make
gcc ... -c string.c -o string.o
gcc ... -c stdio.c -o stdio.o
gcc ... -c stdlib.c -o stdlib.o
nasm -f elf64 -g syscall.asm -o syscall.o
nasm -f elf64 -g setjmp.asm -o setjmp.o
ar rcs libc.a string.o stdio.o stdlib.o syscall.o setjmp.o
Built libc.a

References

  • Original plan: docs/python-support-plan.md
  • MicroPython porting guide: https://docs.micropython.org/en/latest/develop/porting.html
  • MicroPython minimal port example: micropython/ports/minimal/