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

Implements the OP_MUL opcode (numeric multiplication) in the VM. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 if ((a.type==VAL_INT||a.type==VAL_FLOAT) &&(b.type==VAL_INT||b.type==VAL_FLOAT))
 exit (1)

Variables

case OP_MUL
Value a = pop_value(vm)
 else
 break

Detailed Description

Implements the OP_MUL opcode (numeric multiplication) in the VM.

Handles the OP_MUL instruction, multiplying two numeric operands and pushing the result. If either operand is a float, multiplication is performed in double precision; otherwise it is 64-bit integer multiplication.

Behavior:

  • Pops two values from the stack.
  • If any operand is VAL_FLOAT, computes (double)a * (double)b and pushes a VAL_FLOAT.
  • Else computes a.i * b.i and pushes a VAL_INT.

Error Handling:

  • Raises a runtime error and aborts execution if operands are not numeric.

Example: // Bytecode: OP_MUL // Stack before: [3, 4] // Stack after: [12] // Stack before: [2.5, 4] // Stack after: [10.0]

Definition in file mul.c.

Function Documentation

◆ exit()

exit(1)

◆ if()

if((a.type==VAL_INT||a.type==VAL_FLOAT) &&(b.type==VAL_INT||b.type==VAL_FLOAT))

Definition at line 38 of file mul.c.

Here is the call graph for this function:

Variable Documentation

◆ a

Value a = pop_value(vm)

Definition at line 37 of file mul.c.

◆ break

break

Definition at line 57 of file mul.c.

◆ else

else
Initial value:
{
fprintf(stderr, "Runtime type error: MUL expects numbers, got %s and %s\n",
value_type_name(a.type), value_type_name(b.type))
Value a
Definition add.c:37
uint32_t b
Definition band.c:32
#define fprintf
Definition vm.c:200

Definition at line 52 of file mul.c.

◆ OP_MUL

case OP_MUL

Definition at line 35 of file mul.c.