Skip to content

Commit

Permalink
Merge pull request #196 from KainAlive/main
Browse files Browse the repository at this point in the history
Add implementations in the Hare language
  • Loading branch information
bddicken authored Jan 10, 2025
2 parents e946d1a + e7a784a commit 655d7e7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rm -rf fsharp/obj
rm -rf fsharp/code-aot
rm -rf fsharp/code
rm haskell/code haskell/*.hi haskell/*.o
rm hare/code
rm v/code
rm emojicode/code emojicode/code.o
rm -f chez/code.so
Expand Down
1 change: 1 addition & 0 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ compile 'c' 'gcc -O3 c/code.c -o c/code'
compile 'cpp' 'g++ -std=c++23 -march=native -O3 -Ofast -o cpp/code cpp/code.cpp'
#compile 'go' 'go build -ldflags "-s -w" -o go/code go/code.go'
go build -ldflags "-s -w" -o go/code go/code.go
hare build -R -o hare/code hare/code.ha
compile 'jvm' 'javac jvm/code.java'
compile 'js' 'bun build --bytecode --compile js/code.js --outfile js/bun'
# The compile function can't cope with the java-native-image compile
Expand Down
18 changes: 18 additions & 0 deletions fibonacci/hare/code.ha
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use fmt;
use os;
use strconv;

fn fibonacci(n: uint) uint = {
if (n == 0) return 0;
if (n == 1) return 1;
return fibonacci(n-1) + fibonacci(n-1);
};

export fn main() void = {
let u = strconv::stou(os::args[1])!;
let r: uint = 0;
for (let i: uint = 1; i < u; i+=1) {
r += fibonacci(i);
};
fmt::printfln("{}", r)!;
};
19 changes: 19 additions & 0 deletions loops/hare/code.ha
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use fmt;
use os;
use strconv;
use math::random;
use time;

export fn main() void = {
let u = strconv::stoi(os::args[1])!;
let rng = random::init(time::unix(time::now(time::clock::REALTIME)): u64);
let r = random::next(&rng) % 1000;
let a: [10000]int = [0...];
for(let i = 0; i < 10000; i+=1) {
for(let j = 0; j < 100000; j+=1) {
a[i] = a[i] + j%u;
};
a[i] += r: int;
};
fmt::printfln("{}", a[r])!;
};
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function run {
fi
}

run "Hare" "./hare/code 40"
# run "Language" "Executable" "Command" "Arguments"
#run "Ada" "./ada/code" "./ada/code" "${input}"
#run "AWK" "./awk/code.awk" "awk -f ./awk/code.awk" "${input}"
Expand Down

0 comments on commit 655d7e7

Please sign in to comment.