diff --git a/src/ast.rs b/src/ast.rs index d6be321..7a9b35a 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -197,6 +197,19 @@ pub enum Tag { body: Node, else_expr: Node, }, + // TODO: implement this: + // /// if expression whose body consists of a single expression + // SimpleIfExpr { + // condition: Node, + // body: Node, + // }, + // /// if expression whose body consists of a single expression, + // /// and whose else-expr is one of: SimpleIfExpr, SimpleIfElseExpr, Expr + // SimpleIfElseExpr { + // condition: Node, + // body: Node, + // else_expr: Node, + // }, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/src/intern_pool.rs b/src/intern_pool.rs new file mode 100644 index 0000000..6176aaf --- /dev/null +++ b/src/intern_pool.rs @@ -0,0 +1,78 @@ +struct Symbol { + name: Index, +} + +struct Pools { + bytes: Vec, + symbols: Vec, +} + +type Data = u32; + +struct InternPool { + tags: Vec, + data: Vec, +} + +enum Tag { + TypeSInt, + TypeUInt, +} + +// #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +// #[allow(non_camel_case_types)] +// #[repr(u32)] +// #[non_exhaustive] +// enum Index { +// u0_type, +// i0_type, +// u1_type, +// i1_type, +// u8_type, +// i8_type, +// u16_type, +// i16_type, +// u32_type, +// i32_type, +// u64_type, +// i64_type, +// usize_type, +// isize_type, +// bool_type, +// void_type, +// f32_type, +// f64_type, + +// zero_u8, +// zero_u32, +// zero_usize, +// one_u8, +// one_u32, +// one_usize, +// false_value, +// true_value, + +// None = u32::MAX, +// } + +// const static_keys: [Key; 14] = [ +// Key::UInt { bits: 0 }, +// Key::SInt { bits: 0 }, +// Key::UInt { bits: 1 }, +// Key::SInt { bits: 1 }, +// Key::UInt { bits: 8 }, +// Key::SInt { bits: 8 }, +// Key::UInt { bits: 16 }, +// Key::SInt { bits: 16 }, +// Key::UInt { bits: 32 }, +// Key::SInt { bits: 32 }, +// Key::UInt { bits: 64 }, +// Key::SInt { bits: 64 }, +// Key::UInt { bits: 64 }, +// Key::SInt { bits: 64 }, +// ]; + +// enum Key { +// SInt { bits: u16 }, +// UInt { bits: u16 }, +// } diff --git a/src/mangle.rs b/src/mangle.rs new file mode 100644 index 0000000..e69de29 diff --git a/test.c b/test.c new file mode 100644 index 0000000..187be27 --- /dev/null +++ b/test.c @@ -0,0 +1,33 @@ +#include +#include + +extern float inverse_sqrt(float); +extern float inverse_sqrt(float); +extern int square_of_greater(int, int); + +float Q_rsqrt(float number) +{ + long i; + float x2, y; + const float threehalfs = 1.5F; + + x2 = number * 0.5F; + y = number; + i = * ( long * ) &y; // evil floating point bit level hacking + i = 0x5f3759df - ( i >> 1 ); // what the fuck? + y = * ( float * ) &i; + y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration + // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed + + return y; +} + +int main() { + printf("hello, world!\n"); + float n = 4.0; + float i = inverse_sqrt(n); + printf("%f = inverse_sqrt(%f)\n", i, n); + printf("%f = Q_rsqrt(%f)\n", Q_rsqrt(4.0), 4.0); + printf("%d = square_of_greater(4,5)\n", square_of_greater(4, 5)); + return 0; +}