Skip to content

Commit

Permalink
Fix parser bug. Add isnan(x) macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Nov 12, 2023
1 parent 19d3f29 commit 62f8b97
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 1 addition & 3 deletions ncc/examples/mini_bbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ void post_message(user_t* p_user)
assert(num_messages <= MAX_MESSAGES);
message_t* p_message = &messages[msg_idx];

// Initialize the message struct
p_message->timestamp = time_current_ms();

memcpy(p_message->username, p_user->name, MAX_NAME_LEN);

//p_user->msg_buf[MAX_MSG_LEN - 1] = '\0';
memcpy(p_message->text, p_user->msg_buf, sizeof(p_user->msg_buf));
}

Expand Down
3 changes: 3 additions & 0 deletions ncc/include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#define M_PI_F 3.14159266f
#define INFINITY_F (1.0f / 0.0f)

// Test if a floating-point value is NaN
#define isnan(x) (x != x)

// Here we use macros for performance because
// ncc doesn't yet support inline functions
#define sinf(f) (asm (f) -> float { sin_f32; })
Expand Down
8 changes: 8 additions & 0 deletions ncc/include/uvm/3dmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ void vec3_normalize(vec3 v)
}
}

// Scalar multiplication
void vec3_mul(vec3 a, float f, vec3 result)
{
result[0] = a[1] * f;
result[1] = a[2] * f;
result[2] = a[0] * f;
}

// Compute the dot product of two vectors
float vec3_dot(vec3 a, vec3 b)
{
Expand Down
8 changes: 8 additions & 0 deletions ncc/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ fn parse_postfix(input: &mut Input) -> Result<Expr, ParseError>
base: Box::new(base_expr),
field: field_name
};

continue;
}

// Postfix increment expression
Expand Down Expand Up @@ -1373,4 +1375,10 @@ mod tests
parse_ok("void main() { if (1) { foo(); } }");
parse_ok("void main() { if (1) { foo(); } else { bar(); } }");
}

#[test]
fn regress_ptr_buf_idx()
{
parse_ok("void main(user_t* p_user) { p_user->msg_buf[0]; }");
}
}

0 comments on commit 62f8b97

Please sign in to comment.