Skip to content

Commit

Permalink
Add some more operators while I'm here
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-y committed Sep 24, 2024
1 parent 1e9b04a commit 81e7cb3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/parser/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ export const infixOps: OpMap = new Map([
["*", 2],
["/", 2],
["^", 3],
["and", 0],
["or", 0],
["xor", 0],
["as", 0],
["is", 0],
["in", 0],
["%", 2],
["==", 0],
["!=", 0],
["<", 0],
Expand All @@ -80,6 +75,15 @@ export const infixOps: OpMap = new Map([
["::", 0],
[";", 4],
["??", 3],
["not", 0],
["and", 0],
["or", 0],
["xor", 0],
["as", 0],
["is", 0],
["is_subtype_of", 0],
["in", 0],
["has_trait", 0],
]);

export const isInfixOp = (op?: Expr): op is Identifier =>
Expand Down
22 changes: 22 additions & 0 deletions std/operators.voyd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub def_wasm_operator('+', add, i32, i32)
pub def_wasm_operator('-', sub, i32, i32)
pub def_wasm_operator('*', mul, i32, i32)
pub def_wasm_operator('/', div_s, i32, i32)
pub def_wasm_operator('%', rem_s, i32, i32)
pub def_wasm_operator('rem_u', rem_u, i32, i32)

pub def_wasm_operator('<', lt_s, i64, bool)
pub def_wasm_operator('>', gt_s, i64, bool)
Expand All @@ -36,7 +38,10 @@ pub def_wasm_operator('+', add, i64, i64)
pub def_wasm_operator('-', sub, i64, i64)
pub def_wasm_operator('*', mul, i64, i64)
pub def_wasm_operator('/', div_s, i64, i64)
pub def_wasm_operator('%', rem_s, i64, i64)
pub def_wasm_operator('rem_u', rem_u, i64, i64)

// Floating-point operators for f32
pub def_wasm_operator('<', lt, f32, bool)
pub def_wasm_operator('>', gt, f32, bool)
pub def_wasm_operator('<=', le, f32, bool)
Expand All @@ -47,7 +52,16 @@ pub def_wasm_operator('+', add, f32, f32)
pub def_wasm_operator('-', sub, f32, f32)
pub def_wasm_operator('*', mul, f32, f32)
pub def_wasm_operator('/', div, f32, f32)
pub def_wasm_operator(sqrt, sqrt, f32, f32)
pub def_wasm_operator(trunc, trunc, f32, f32)
pub def_wasm_operator(floor, floor, f32, f32)
pub def_wasm_operator(ceil, ceil, f32, f32)
pub def_wasm_operator(nearest, nearest, f32, f32)
pub def_wasm_operator(min, min, f32, f32)
pub def_wasm_operator(max, max, f32, f32)
pub def_wasm_operator(copysign, copysign, f32, f32)

// Floating-point operators for f64
pub def_wasm_operator('<', lt, f64, bool)
pub def_wasm_operator('>', gt, f64, bool)
pub def_wasm_operator('<=', le, f64, bool)
Expand All @@ -58,6 +72,14 @@ pub def_wasm_operator('+', add, f64, f64)
pub def_wasm_operator('-', sub, f64, f64)
pub def_wasm_operator('*', mul, f64, f64)
pub def_wasm_operator('/', div, f64, f64)
pub def_wasm_operator(sqrt, sqrt, f64, f64)
pub def_wasm_operator(trunc, trunc, f64, f64)
pub def_wasm_operator(floor, floor, f64, f64)
pub def_wasm_operator(ceil, ceil, f64, f64)
pub def_wasm_operator(nearest, nearest, f64, f64)
pub def_wasm_operator(min, min, f64, f64)
pub def_wasm_operator(max, max, f64, f64)
pub def_wasm_operator(copysign, copysign, f64, f64)

// Bitwise operators
// i32 bitwise operators
Expand Down

0 comments on commit 81e7cb3

Please sign in to comment.