Summary
Support method calls on struct/enum instances with automatic self injection, including the special equals and toString methods.
Strategy: bound method value
Rather than a dedicated call_method opcode, use a .bound_method value variant. get_field resolves the method and bundles the receiver + function into a single typed value; call dispatches on it like any other callable. Keeps opcodes orthogonal, and bound methods become first-class values for free.
Checklist
VM — value
VM — execution
Compiler
Special methods
Tests
Depends on #43 (call frames), #49 (struct instances), and #51 (builtins).
Summary
Support method calls on struct/enum instances with automatic
selfinjection, including the specialequalsandtoStringmethods.Strategy: bound method value
Rather than a dedicated
call_methodopcode, use a.bound_methodvalue variant.get_fieldresolves the method and bundles the receiver + function into a single typed value;calldispatches on it like any other callable. Keeps opcodes orthogonal, and bound methods become first-class values for free.Checklist
VM — value
.bound_method = { fn_idx, receiver }variant tovm/value.zigVM — execution
get_fieldfallback: if field not found as data, look upTypeName.fieldNamein globals → push.bound_methodcallnew arm:.bound_method→ inject receiver as first arg, build frameCompiler
struct.methodsasTypeName.methodNamein globalsSpecial methods
equals: whenop_equalencounters two struct instances, look up and callTypeName.equalsif definedtoString: coerce struct instances viaTypeName.toStringbefore passing to builtins (overlaps with Add builtin function call convention to bytecode VM #51)Tests
selfcorrectly refers to the receiver inside the method bodyequalsmethod used by==operatortoStringmethod used byprintDepends on #43 (call frames), #49 (struct instances), and #51 (builtins).