Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
mul.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
34
35case OP_MUL: {
36 Value b = pop_value(vm);
37 Value a = pop_value(vm);
38 if ((a.type == VAL_INT || a.type == VAL_FLOAT) && (b.type == VAL_INT || b.type == VAL_FLOAT)) {
39 if (a.type == VAL_FLOAT || b.type == VAL_FLOAT) {
40 double da = (a.type == VAL_FLOAT) ? a.d : (double)a.i;
41 double db = (b.type == VAL_FLOAT) ? b.d : (double)b.i;
45 push_value(vm, res);
46 } else {
47 Value res = make_int(a.i * b.i);
50 push_value(vm, res);
51 }
52 } else {
53 fprintf(stderr, "Runtime type error: MUL expects numbers, got %s and %s\n",
54 value_type_name(a.type), value_type_name(b.type));
55 exit(1);
56 }
57 break;
58}
Value a
Definition add.c:37
int res
Definition and.c:34
uint32_t b
Definition band.c:32
@ OP_MUL
Definition bytecode.h:46
double da
Definition fmax.c:26
double db
Definition fmax.c:27
Tagged union representing a Fun value.
Definition value.h:68
void free_value(Value v)
Free dynamic storage owned by a Value.
Definition value.c:517
Value make_float(double v)
Construct a Value representing a double-precision float.
Definition value.c:64
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
@ VAL_INT
Definition value.h:51
@ VAL_FLOAT
Definition value.h:58
#define fprintf
Definition vm.c:200
#define exit(code)
Definition vm.c:230