Commit Graph

524 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 30e41242ec doc/internal/gc.md: add practical tuning examples
add workload-specific GC tuning advice based on benchmark data:
- allocation-heavy: interval_ratio 400 for ~12% improvement
- real-time: step_limit for bounded pause times
- large buffers: malloc_threshold
- diagnosing GC overhead with GC.stat

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:27 +09:00
Yukihiro "Matz" Matsumoto 309f450bab gc.c: use actual work done for debt repayment in incremental step
Decrement gc_debt by the actual number of objects processed
instead of the fixed GC_STEP_SIZE. This makes step_ratio
directly affect debt repayment: larger steps repay more debt,
naturally reducing GC invocation frequency.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:24 +09:00
Yukihiro "Matz" Matsumoto 851da984b4 gc.c: use :debt instead of :threshold in GC.stat
Expose gc_debt directly as :debt in GC.stat without sign negation.
The debt model has no threshold ceiling, so :threshold was a
misleading name. Negative debt means credit, positive means GC
is behind on collection work.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:24 +09:00
Yukihiro "Matz" Matsumoto 4d03f40204 doc/internal/gc.md: update for debt model and new tuning parameters
Document the debt-based GC trigger model, malloc threshold,
step limit, GC.stat, and tuning guide.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:23 +09:00
mimaki 831da26b90 Update version and release date. (mruby 4.0.0 (2026-04-20)) 2026-04-20 17:43:06 +09:00
HASUMI Hitoshi 5e9eed2d0c Fix KHASH_DEFAULT_SIZE to KHASH_INITIAL_SIZE rename inconsistencies
Commit 250bf6edd renamed KHASH_DEFAULT_SIZE to KHASH_INITIAL_SIZE but
missed updating build_config files and documentation. Also restore the
default value in khash.h to 32, consistent with the documented default
and the profile hierarchy (MRB_CONSTRAINED_BASELINE_PROFILE reduces it
to 16).
2026-03-19 09:38:36 +09:00
Yukihiro "Matz" Matsumoto 143959b94b doc: fix prettier formatting in markdown files
Co-authored-by: Claude <noreply@anthropic.com>
2026-03-12 14:33:37 +09:00
Yukihiro "Matz" Matsumoto 9239a9e0ef pre-commit: fix prettier formatting in doc/guides/capi.md
Co-authored-by: Claude <noreply@anthropic.com>
2026-03-12 14:05:48 +09:00
Yukihiro "Matz" Matsumoto 46e8101c03 Merge pull request #6733 from mruby/fix/presym-include 2026-03-10 16:59:51 +09:00
Yukihiro "Matz" Matsumoto 8956c5abb5 mruby.h: include mruby/presym.h for all source files
Since presym is now mandatory, mruby.h includes presym.h so that
MRB_SYM() macros are available everywhere without explicit include.
Remove redundant #include <mruby/presym.h> from all source files.

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-09 16:50:58 +09:00
Yukihiro "Matz" Matsumoto 8f3917f361 language.md: remove unnecessary bold markup from "operator"
Co-authored-by: Claude <noreply@anthropic.com>
2026-03-09 16:50:54 +09:00
leviongit 87f88a1ce8 fix grammar
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-03-03 13:58:23 +01:00
leviongit ab06ed825a change wording of the "overloading" section
the previous wording may have been taken as mruby not permitting the
overloading of operators on any class
2026-03-03 13:49:03 +01:00
Yukihiro "Matz" Matsumoto 02877f043a amalgamation.md: document platform dependency of HAL gems
Amalgamated files include HAL gem source code selected at build time,
making them platform-specific. Document this as expected behavior.

Ref #6726.

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-02 10:34:55 +09:00
Yukihiro "Matz" Matsumoto 98bc495fd2 getting-started.md: add links to language and C API guides
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-28 11:35:28 +09:00
Yukihiro "Matz" Matsumoto 0313800b10 doc: add README.md as documentation index
Organizes 22 doc files by audience (getting started, embedders,
contributors) so visitors can find the right document quickly.
Rendered automatically by GitHub when browsing the doc/ directory.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-28 10:42:54 +09:00
Yukihiro "Matz" Matsumoto 438a3bdffc docs: fix version labels, add navigation aids
limitations.md: use consistent CRuby/mruby labels for remaining
entries that still had specific version strings.

language.md: add upfront summary of major CRuby differences so
porting developers see the key gotchas before reading the full doc.

capi.md: add table of contents for navigating the 800+ line
reference.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 22:03:39 +09:00
Yukihiro "Matz" Matsumoto 3ce3453e9c docs: improve usability of new documentation
language.md: reorganize stdlib tables by class name instead of gem
name so users can quickly find "does mruby have Time/File/Set?"

capi.md: fix mrb_protect example (mrb->exc is cleared after protect,
so mrb_print_error does not work; show mrb_inspect instead); fix
fiber yield example to show correct usage as return value.

gc.md, compiler.md, vm.md: add "read this if" guidance paragraphs
to help developers decide whether they need each document.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 19:03:29 +09:00
Yukihiro "Matz" Matsumoto 1c7b9b1f26 architecture.md: add cross-references to standalone internal docs
Replace duplicated GC, compiler, and VM details with concise
summaries linking to gc.md, compiler.md, and vm.md.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 18:36:09 +09:00
Yukihiro "Matz" Matsumoto c561b21d43 vm.md: add VM internals documentation
Covers execution context, call frames, stack layout, argument
encoding, dispatch loop, method lookup with cache, exception
handling, closure environments, and fiber switching.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 18:36:04 +09:00
Yukihiro "Matz" Matsumoto 95954d3905 compiler.md: add compiler pipeline documentation
Covers parser/lexer, code generator, IRep structure, operand
encoding with OP_EXT1/2/3, OP_ENTER aspec format, presym system,
and RITE binary format.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 18:35:58 +09:00
Yukihiro "Matz" Matsumoto 985b5108d5 gc.md: add GC internals documentation
Covers heap structure, tri-color marking, incremental phases, gray
stack, write barriers, arena management, generational mode, and
tuning parameters.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 18:35:52 +09:00
Yukihiro "Matz" Matsumoto 366d9be721 limitations.md: update version references and add missing limitations
Update CRuby/mruby version labels to generic names. Add sections for
refinements, Encoding, integer precision by boxing mode, and
ObjectSpace limitations.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 18:35:47 +09:00
Yukihiro "Matz" Matsumoto 0a5a305a01 capi.md: add error handling, fibers, procs, and compilation context sections
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 18:35:42 +09:00
Yukihiro "Matz" Matsumoto aa7556acdb language.md: add Ruby language subset guide
Covers supported syntax, numeric types by boxing mode, core classes,
standard library gemboxes, and key differences from CRuby.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 18:35:37 +09:00
Yukihiro "Matz" Matsumoto 449627d085 gc-arena-howto.md: update Array#inspect example to current code
The old inspect_ary() function no longer exists. Replace with the
current mrb_ary_to_s() implementation from src/array.c.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 18:04:35 +09:00
Yukihiro "Matz" Matsumoto 301436d400 mrbconf.md: update macro documentation for mruby 4.0
- add MRB_NO_BOXING, MRB_WORDBOX_NO_INLINE_FLOAT documentation
- update MRB_WORD_BOXING description (inline floats on 64-bit)
- add MRB_INT64 restriction note for 32-bit platforms
- fix MRB_MALLOC_TRIM -> MRB_USE_MALLOC_TRIM (renamed)
- fix MRB_ARY_LENGTH_MAX default (131072, not 1MB)
- remove stale MRB_USE_LINK_TIME_RO_DATA_P reference
- add MRB_SYMBOL_LINEAR_THRESHOLD and tuning profiles section
- remove outdated heap page size calculation (referenced mruby 3.1.0)

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 18:03:32 +09:00
Yukihiro "Matz" Matsumoto 5c1aaa0259 boxing.md: add inline float details and comparison table
Add sections on 64-bit inline float rotation encoding and 32-bit
RFloat heap allocation with char[] buffer for alignment safety.
Add comparison table of all three boxing modes and ABI note.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 17:19:08 +09:00
Yukihiro "Matz" Matsumoto 55348ce0da opcode.md: update instruction table to match current ops.h
Add 13 new opcodes (OP_GETIDX0, OP_MATCHERR, OP_SSEND0,
OP_SEND0, OP_BLKCALL, OP_RETSELF, OP_RETNIL, OP_RETTRUE,
OP_RETFALSE, OP_ADDILV, OP_SUBILV, OP_TDEF, OP_SDEF).
Fix renamed instructions (OP_LOADT -> OP_LOADTRUE, etc.).
Update title and introduction to reflect current state.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 17:05:47 +09:00
Yukihiro "Matz" Matsumoto 59e1fe29d6 mrbconf.h: rename MRB_WORDBOX_NO_FLOAT_TRUNCATE to MRB_WORDBOX_NO_INLINE_FLOAT
The old name referred to "truncation" of float precision, which no
longer happens with rotation encoding. The new name describes the
actual behavior: disabling inline float encoding in word boxing.
The old name is kept as an obsolete alias for backward compatibility.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 10:30:01 +09:00
Yukihiro "Matz" Matsumoto 4ed338bdb9 doc: add getting-started guide, C API reference, and architecture overview
Three new documents:
- doc/guides/getting-started.md: building, running, and embedding mruby
- doc/guides/capi.md: C API reference for values, classes, methods, etc.
- doc/internal/architecture.md: internal architecture for developers

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 09:18:17 +09:00
Yukihiro "Matz" Matsumoto bf376a6160 memory.md: document mrb_gc_add_region() heap region API
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-26 08:56:23 +09:00
Yukihiro "Matz" Matsumoto 3c2922a361 rom-method-table.md: fix prettier table formatting
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-25 15:20:03 +09:00
Yukihiro "Matz" Matsumoto 71cb3c2e3a class.c: allocate ROM table wrappers per mrb_state
ROM method tables used static mrb_mt_tbl variables shared
across the process. The next pointer in each wrapper was
mutated by mrb_mt_init_rom(), causing cross-state
contamination when multiple mrb_state instances existed.

Allocate mrb_mt_tbl wrappers per-state via mrb_malloc().
The const mrb_mt_entry[] arrays remain static and shared.
Wrappers are tracked in mrb->rom_mt and freed at mrb_close().

Remove MRB_MT_ROM_TAB macro; add MRB_MT_INIT_ROM macro that
auto-computes size and calls the new mrb_mt_init_rom().

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 22:24:31 +09:00
Yukihiro "Matz" Matsumoto 4a097525df proc.h: unify method flag layout; eliminate aspec shifting
Move MRB_METHOD_FUNC_FL to bit 24 and visibility flags to
bits 25-26 so that MRB_ARGS_*() values (bits 0-23) can be
stored directly without shifting. This makes MRB_MT_PRIVATE
and MRB_METHOD_PRIVATE_FL the same value, eliminating the
dual-constant confusion and simplifying the MRB_MT_ENTRY()
macro to a single OR operation.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 13:49:17 +09:00
Yukihiro "Matz" Matsumoto ada229d2b0 proc.h: remove MRB_METHOD_NOARG flag; derive from aspec
The NOARG flag (bit 2) is now redundant since the full aspec is
stored in bits 4+ of the flags field. Replace the dedicated bit
check with aspec==0 check. Store aspec in define_method_id() for
dynamically defined methods too.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 11:51:59 +09:00
Yukihiro "Matz" Matsumoto 483c155a41 class.c: store aspec in ROM method table entries
Restore MRB_ARGS_* argument specs and ISO section comments to all
709 ROM method table entries. The aspec is encoded in bits 4-27 of
the flags field; MRB_MT_NOARG is now auto-derived from aspec==0.

Add MRB_MT_ENTRY_PRIVATE() macro for private methods (53 entries)
and MRB_MT_ASPEC() accessor for extracting aspec from flags.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 11:44:28 +09:00
Yukihiro "Matz" Matsumoto 20b9002214 class.c: merge conditional methods into ROM tables
Move conditional mrb_define_method_id() calls into ROM entry
arrays using #ifdef guards. With linear search, sizeof in
MRB_MT_ROM_TAB() adjusts automatically after preprocessing.

Cross-class ROM tables (methods a gem defines on a class it does
not own) are reverted to mrb_define_method_id(). Multiple gems
should not add ROM table layers to the same class; each layer
costs a 16-byte mrb_mt_tbl struct in RAM and deepens the lookup
chain. Use mrb_define_method_id() for cross-class methods.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 11:05:03 +09:00
Yukihiro "Matz" Matsumoto 8adba34bd9 class.c: auto-set MRB_MT_FUNC in MRB_MT_ENTRY macro
Since ROM table entries are always C functions, have the
MRB_MT_ENTRY() macro set MRB_MT_FUNC automatically. This
simplifies entry definitions across all 32 source files.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 10:37:06 +09:00
Yukihiro "Matz" Matsumoto 0fab703028 class.c: use linear search for method tables; make ROM entries const
Replace binary search with linear scan in mt_get(), mt_put(),
mt_del(), mt_chain_has(), and mrb_mt_foreach(). The method cache
makes repeated lookups O(1), so linear scan on cache misses is
acceptable.

This removes the sorting requirement, allowing ROM entry arrays
to be declared const. On embedded systems, const static data
resides in flash/ROM instead of RAM, saving ~8.4KB for ~700
method entries on 32-bit MCUs.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 08:26:05 +09:00
Yukihiro "Matz" Matsumoto ce8ce3f96d class.c: separate flags from symbol key in mrb_mt_entry
Add a dedicated uint32_t flags field to mrb_mt_entry instead of
packing flags into the lower bits of mrb_sym via MRB_MT_KEY().
The key field now stores the pure symbol ID with no shift.

On 64-bit, the flags field fills the alignment gap after mrb_sym,
so entry size remains 16 bytes (zero overhead). On 32-bit, entry
size grows from 8 to 12 bytes.

This eliminates the risk of symbol ID overflow from the 4-bit
shift, and the flags field can later store aspec (MRB_ARGS_*)
information that was previously discarded.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 07:57:02 +09:00
Yukihiro "Matz" Matsumoto bde2202100 class.c: refactor ROM method tables to array-of-structs layout
Replace the parallel-arrays (struct-of-arrays) ROM method table
layout with an array-of-structs layout where each mrb_mt_entry
bundles its function pointer and symbol key together.

New MRB_MT_ENTRY() and MRB_MT_ROM_TAB() macros simplify ROM table
definitions from a 3-part pattern (SIZE define + anonymous struct +
mrb_mt_tbl) to a 2-part pattern (entries array + mrb_mt_tbl).

Internal mt_* functions in class.c are simplified: single memmove/
memcpy operations replace paired key+value operations.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 23:59:30 +09:00
Yukihiro "Matz" Matsumoto 0ed26f8352 class.c: rename mt_/MT_ to mrb_mt_/MRB_MT_ for non-static identifiers
Follow mruby's naming convention: non-static types, macros, and
functions use the mrb_/MRB_ prefix. Renamed:
- union mt_ptr -> union mrb_mt_ptr
- mt_tbl -> mrb_mt_tbl
- MT_KEY(), MT_FUNC, MT_NOARG, MT_PUBLIC, MT_PRIVATE -> MRB_MT_*
- MT_KEY_SHIFT, MT_READONLY_BIT, MT_REMOVED_P -> MRB_MT_*
- mt_init_rom() -> mrb_mt_init_rom()
File-local static functions and macros in class.c are unchanged.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 15:22:55 +09:00
Yukihiro "Matz" Matsumoto 494d55c9f7 class.c: use tombstone for remove_method with ROM method tables
Previously, removing a ROM method required flattening all chain layers
into a single mutable table. This was O(n) and allocated RAM for all
previously-ROM methods.

Use a tombstone marker (MT_FUNC flag with func=NULL) instead. The
mt_get() lookup treats this as "not found" and stops the chain walk,
hiding the ROM entry while allowing superclass lookup.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 14:57:50 +09:00
Yukihiro "Matz" Matsumoto 16fb8a6b08 doc: add ROM method table guide
Comprehensive documentation covering architecture, definition
format, flags, extension gem usage, conditional methods, runtime
behavior (COW, method removal, GC), and conversion guide.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 14:38:29 +09:00
Yukihiro "Matz" Matsumoto dcd77f1efd mruby-compiler: replace MRB_SYM_2() with MRB_SYM() macros
The _2 suffix variants accept an mrb_state* parameter that is
always ignored with presym enabled. Replace all uses in codegen.c,
parse.y, and y.tab.c with the standard macros. The _2 macro
definitions are kept in presym headers for backward compatibility.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 14:14:40 +09:00
Yukihiro "Matz" Matsumoto 5829ca60b6 doc: update presym documentation
Remove references to conf.disable_presym and MRB_NO_PRESYM.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 12:18:00 +09:00
Yukihiro "Matz" Matsumoto f7988c9339 vm.c: use 1.5x stack growth instead of linear
Change default stack growth from linear (+128) to exponential (1.5x).
This reduces reallocation frequency while maintaining reasonable memory
usage. The minimum growth is still MRB_STACK_GROWTH (128) to ensure
small programs don't over-allocate.

MRB_STACK_EXTEND_DOUBLING (2x growth) remains available for maximum
performance when memory is not a concern.

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-27 14:57:27 +09:00
Yukihiro "Matz" Matsumoto 64f1436323 amalgamation.md: add mruby-rational/complex, clarify gem defines
Co-authored-by: Claude <noreply@anthropic.com>
2026-01-02 18:04:39 +09:00
Yukihiro "Matz" Matsumoto f78ac530c8 amalgam.rb: support gems with core-affecting defines
Gems like mruby-task add preprocessor defines (MRB_USE_TASK_SCHEDULER)
that affect mrb_state structure. The amalgamation generator now detects
these defines from the build configuration and adds them at the top of
mruby.h before struct definitions are encountered.

Supported define patterns: MRB_USE_*, MRB_UTF8_*, HAVE_MRUBY_*

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-02 17:35:31 +09:00