From 2da3720c0f3b4ceb62f6ffabc3e2bdf3b57a5b02 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 28 Feb 2026 13:20:11 +1100 Subject: [PATCH] xo-interpreter2 stack: support 0-argument function calls --- .../interpreter2/VirtualSchematikaMachine.cpp | 21 +++++++++++++++---- .../include/xo/procedure2/DPrimitive.hpp | 1 - 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp index c258cdd6..c2221aed 100644 --- a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp +++ b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp @@ -699,11 +699,24 @@ namespace xo { // now i_arg is 0 -> evaluate that argument - this->expr_ = apply_expr->arg(i_arg); - this->pc_ = VsmInstr::c_eval; - this->cont_ = VsmInstr::c_evalargs; + if (i_arg >= static_cast(apply_expr->n_args())) { + // corner case: function with 0 arguments - return; + this->fn_ = apply_frame->fn(); // = value; + this->args_ = apply_frame->args(); // empty + + this->stack_ = apply_frame->parent(); + this->pc_ = VsmInstr::c_apply; + this->cont_ = apply_frame->cont(); + + return; + } else { + this->expr_ = apply_expr->arg(i_arg); + this->pc_ = VsmInstr::c_eval; + this->cont_ = VsmInstr::c_evalargs; + + return; + } } else { // error - function position must deliver something with AProcedure? // or DClosure, but we'll get to that. diff --git a/xo-procedure2/include/xo/procedure2/DPrimitive.hpp b/xo-procedure2/include/xo/procedure2/DPrimitive.hpp index abec46cc..e458ce3a 100644 --- a/xo-procedure2/include/xo/procedure2/DPrimitive.hpp +++ b/xo-procedure2/include/xo/procedure2/DPrimitive.hpp @@ -110,7 +110,6 @@ namespace xo { using R = typename Traits::return_type; assert(args); - assert(args->size() > 0); obj mm = rcx.allocator();