fix(c,octave): C div-by-zero error code, Octave struct init

C: Added division-by-zero check (-8 error) before calling eval_prim
Octave: Fixed struct field assignment (dimension mismatch in struct())
This commit is contained in:
allaun 2026-06-30 18:23:58 -05:00
parent d4a7f954c4
commit bd4fc304df
3 changed files with 7 additions and 1 deletions

View file

@ -177,6 +177,8 @@ int step(State *s, const Instr *prog, int prog_len) {
if (s->sp < arity) return -4;
AnyVal b = (arity >= 2) ? s->stack[--s->sp] : (AnyVal){0};
AnyVal a = s->stack[--s->sp];
/* Check division by zero before calling eval_prim */
if (p == PRIM_DIV_Q16 && b.val.i == 0) return -8;
s->stack[s->sp++] = eval_prim(p, a, b);
} else if (instr.op == OP_HALT) {
s->halted = true;

View file

@ -41,6 +41,7 @@ lean_lib «SilverSightFormal» where
`CoreFormalism.HachimojiBridging,
`CoreFormalism.HachimojiManifoldAxiom,
`CoreFormalism.ChentsovFinite,
`CoreFormalism.HopfFibration,
`SilverSight.WireFormat,
`SilverSight.ProductSchema,
`SilverSight.ProductWireFormat,

View file

@ -62,7 +62,10 @@ classdef AVM
function s = init_state(n_locals)
if nargin < 1; n_locals = 0; end
s = struct('pc', int32(0), 'stack', {}, 'locals', cell(n_locals, 1), 'halted', false);
s.pc = int32(0);
s.stack = {};
s.locals = cell(n_locals, 1);
s.halted = false;
end
function r = exec_prim(p, a, b)