interpreter: BuiltIn overhaul!
- Allowed builtins to self-describe
- Broke builtins into their own module
- Created a macro to work with BuiltIns easier
- Uses macro 2.0 syntax, so it requires passing in ALL externally referenced identifiers
- Luckily, this is already a requirement of good, readable macro definitions!
- As a temporary hack, turn overloadable operators into function calls
- This is kind of pointless at the moment, since there can only be one definition of a function per name (no ADL/function overloading/traits/type namespaces yet!)
- This is also pretty slow, but benchmarking shows it's not as slow as I thought (~400x slower in release mode than a native Rust implementation when running `fib.cl`/`fib.rs`. Totally unacceptable for most work, but this is a tree walk interpreter.)
- TODO: Remove this when desugaring from operators to function calls is implemented
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
// Calculate Fibonacci numbers
|
||||
|
||||
fn main() -> i128 {
|
||||
let num = 10;
|
||||
print("fib(", num, "): ", fib(num));
|
||||
fn main() {
|
||||
for num in 0..=30 {
|
||||
print("fib(", num, ") = ", fib(num))
|
||||
}
|
||||
}
|
||||
|
||||
/// Implements the classic recursive definition of fib()
|
||||
fn fib(a: i128) -> i128 {
|
||||
fn fib(a: i64) -> i64 {
|
||||
if a > 1 {
|
||||
fib(a - 1) + fib(a - 2)
|
||||
} else {
|
||||
Reference in New Issue
Block a user