Mercurial > octave
view test/compile/cdef_bar.m @ 32309:822314643f50
VM Add support for nested functions
Nested functions and functions with nested functions can be evaluated by the VM.
* libinterp/corefcn/call-stack.cc: Push bytecode frame for nested functions
* libinterp/corefcn/call-stack.h
* libinterp/corefcn/stack-frame.cc: Support saving bytecode frames, frameoffset ...
* libinterp/corefcn/stack-frame.h
* libinterp/octave-value/ov-fcn-handle.cc: Compile nested function handles
Refactor VM call and is compiled check.
* libinterp/octave-value/ov-fcn.cc: Refactor compiled check and VM call
* libinterp/octave-value/ov-ref.cc: New ref octave_value_ref_ptr for nested frames
* libinterp/octave-value/ov-ref.h
* libinterp/octave-value/ov-usr-fcn.cc: Refactor vm call and compiled check
* libinterp/octave-value/ov.h: octave_value_ref_ptr friend to call is_ref() and ref_rep ()
* libinterp/parse-tree/pt-bytecode-vm.cc: Function caches might be written to refs
New vm::call () and vm::maybe_compiled_or_compile ()
Call bytecode for command functions.
* libinterp/parse-tree/pt-bytecode-vm.h
* libinterp/parse-tree/pt-bytecode-walk.cc: Compile nested functions, set up variables
* libinterp/parse-tree/pt-bytecode-walk.h
* libinterp/parse-tree/pt-bytecode.h: New opcode ENTER_NESTED
* libinterp/parse-tree/pt-eval.cc: Push nested frame, refactor how VM is called
* libinterp/parse-tree/pt-eval.h
* test/compile/bytecode.tst: Tests added
* test/compile/module.mk
* test/compile/bytecode_nested.m
* test/compile/cdef_bar.m: Self-counting test class
author | Petter T. |
---|---|
date | Mon, 04 Sep 2023 16:52:22 +0200 |
parents | |
children | 8e4f14837db2 |
line wrap: on
line source
% classdef that keeps track of alive objects of itself too be able % to ensure all are destroyed. % % Inspect cdef_bar_alive_objs to see which object with what message % that is alive during debugging. classdef cdef_bar < handle properties msg = ""; end methods function f = cdef_bar(msg = "") global cdef_bar_cnt = 0; global cdef_bar_alive_objs = struct; f.msg = msg; cdef_bar_cnt++; if isfield (cdef_bar_alive_objs, msg) entry = cdef_bar_alive_objs.(msg); entry.cnt++; cdef_bar_alive_objs.(msg) = entry; else entry = struct; entry.cnt = 1; cdef_bar_alive_objs.(msg) = entry; end %printf ("ctored %s cnt=%d\n", msg, cdef_bar_cnt); end function delete (self) global cdef_bar_cnt = 0; global cdef_bar_alive_objs = struct; cdef_bar_cnt--; if isfield (cdef_bar_alive_objs, self.msg) entry = cdef_bar_alive_objs.(self.msg); entry.cnt--; if entry.cnt cdef_bar_alive_objs.(self.msg) = entry; else cdef_bar_alive_objs = rmfield (cdef_bar_alive_objs, self.msg); end else printf ("Unexpected missing alive objects entry for cdef_bar in cdef_bar.m") end %printf ("dtored %s cnt=%d\n", self.msg, cdef_bar_cnt); endfunction endmethods end