Skip to content

Operators

Munos follows familiar C/JavaScript operator conventions. One emphasis worth noting: bitwise operators are first-class and expected — flag packing, tile decoding, and memory-layout work are everyday tasks for retro modders.

A rule that applies throughout: binary operators require both operands to have the same type. There are no implicit conversions, so mixing a u8 and an i32 is an error — cast first.

Arithmetic

+ - * / %

Same integer type in, same type out. Integer division truncates toward zero. Overflow wraps.

munos
var a = 7 / 2     // 3
var b = -7 / 2    // -3 (toward zero)
var c = 7 % 2     // 1

Comparison

== != < > <= >=

Return bool. Operands must share a type. Strings compare by byte sequence.

Logical

&& || !

Boolean operators with short-circuit evaluation. Operands must be bool — numbers and strings are not coerced.

munos
if occupied[i] && x > 0 { … }

Bitwise

& | ^ ~ << >>

AND, OR, XOR, complement, left shift, right shift. Operands must be the same integer type. Right shift is arithmetic (sign-extending) on signed types and logical (zero-filling) on unsigned types.

munos
var key = (hi << 8) | lo          // pack two bytes
var facing_right = (flags & 0x40) != 0

Assignment

= assigns. Compound forms apply an operator in place:

+=  -=  *=  /=  %=  &=  |=  ^=  <<=  >>=

x op= y is exactly x = x op y.

munos
score += 100
flags &= ~0x40

Precedence

Highest to lowest:

#Operators
1unary ! ~ -
2* / %
3+ -
4<< >>
5< > <= >=
6== !=
7&
8^
9|
10&&
11||

Use parentheses whenever precedence isn't obvious — bitwise-and-shift mixes in particular read better parenthesized.

Part of the MultiNostalgia project.