Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
add.cpp File Reference

Fun VM C++ opcode snippet: add two 64-bit integers (cpp_add). More...

#include <cstdint>
#include "vm.h"
Include dependency graph for add.cpp:

Go to the source code of this file.

Functions

int fun_op_cpp_add (VM *vm)
 Add two 64-bit integers from the VM stack and push the sum.

Detailed Description

Fun VM C++ opcode snippet: add two 64-bit integers (cpp_add).

This opcode is compiled and linked only when the CMake option -DFUN_WITH_CPP=ON is enabled. It demonstrates how to implement a VM opcode in C++ while exposing a C ABI symbol for the VM dispatcher.

Stack behavior:

  • Pops: b:int64, a:int64
  • Pushes: (a + b):int64

Error handling and type conversions (e.g., from other numeric types to int64) are delegated to the VM helpers vm_pop_i64 and vm_push_i64.

Definition in file add.cpp.

Function Documentation

◆ fun_op_cpp_add()

int fun_op_cpp_add(VM *vm)

Add two 64-bit integers from the VM stack and push the sum.

Pops two values from the VM stack using vm_pop_i64, adds them as 64-bit signed integers, and pushes the result via vm_push_i64.

Stack effect:

  • Input: [..., a:int64, b:int64]
  • Output: [..., (a+b):int64]
Parameters
vmPointer to the VM instance. Must not be NULL.
Returns
0 on success. Any stack underflow or conversion errors are handled by the VM helpers; non-zero may be used by future implementations to indicate a runtime error.

Definition at line 47 of file add.cpp.

Here is the call graph for this function: