Skip to content

Commit

Permalink
Switched to rust
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeaster30 committed Jun 5, 2022
1 parent 34db107 commit 762c034
Show file tree
Hide file tree
Showing 33 changed files with 685 additions and 4,005 deletions.
Empty file modified .gitattributes
100644 → 100755
Empty file.
15 changes: 4 additions & 11 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
.vscode/*
CMakeFiles/*
*/CMakeFiles/*
*.cmake
*/Makefile
Makefile
CMakeCache.txt

ocean
src/ocean.tab.cpp
src/ocean.tab.hpp
src/lex.yy.cpp
scratch/*

*/*.output
# Added by cargo

/target
12 changes: 0 additions & 12 deletions CMakeLists.txt

This file was deleted.

7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "ocean"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Empty file modified LICENSE
100644 → 100755
Empty file.
15 changes: 0 additions & 15 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
# ocean
A C-like programming language (get it like sea-like like an ocean lol)

### Building
This project uses flex and bison so install them. _add some instructions about this_

Then in the root folder of this repo run:

```cmake .```

to build the makefile then:

```make```

to build the project then

```{install???}```

to install.
31 changes: 31 additions & 0 deletions examples/collatz.sea
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
isEven: func = (x: i64) -> (result: bool = x % 2 == 0)

isEmpty: func = (x: string) -> (result: bool = x == "")

collatz: func = (input: i64) -> (path: i64[]) {
loop input != 1 {
path.append(input)
if !input.isEven() {
input = input / 2
} else {
input = 3 * input + 1
}
}
}

while true {
print("Input a number: ")
userinput: string = input()
if !userinput.isEmpty() {
parsed: auto = userInput.parsei64 # the type here is optional i64
if parsed.has_value() {
result: auto = parsed.collatz()
println(result.size())
println(result)
break
}
println(`{userinput} is not an integer`)
} else {
println("not a number")
}
}
10 changes: 10 additions & 0 deletions examples/fibonacci.sea
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fib: func = (input: i64) -> (result: i64) {
if input == 0 {
result = 0
} else {
result = input + fib(input - 1)
}
}

println(9.fib)
println(fib(10))
3 changes: 3 additions & 0 deletions examples/hello_world.sea
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use io

println("Hello, World!")
46 changes: 46 additions & 0 deletions examples/rational.sea
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
gcd: func = (a: i64, b: i64) -> (result: i64) {
# If A=0 then GCD(A, B)=B since the Greatest Common Divisor of 0 and B is B.
# If B=0 then GCD(a,b)=a since the Greatest Common Divisor of 0 and a is a.
# Let R be the remainder of dividing A by B assuming A > B. (R = A % B)
# Find GCD( B, R ) because GCD( A, B ) = GCD( B, R ). Use the above steps again.

loop a != 0 || b != 0 {
new_a: i64 = b
new_b: i64 = a % b
}

if a == 0 {
result = b
} else if b == 0 {
result = a
}
}

abs: func = (a: i64) -> (result: i64) {
if a < 0 {
result = -a
} else {
result = a
}
}

lcm: func = (a: i64, b: i64) -> (result: i64 = abs(a) * abs(b) / gcd(a, b))

op _+_ left = (x: auto T, y: T) -> (result: T = add(x, y))

op _-_ left = (x: auto T, y: T) -> (result: T = subtract(x, y))

pack rational {
numerator: i64
denominator: i64
}

add: func = (a: rational, b: rational) -> (result: rational) {
mul: i64 = lcm(a.denominator, b.denominator)
res = { a.numerator * mul + b.numerator * mul, mul };
}

subtract: func = (a: rational, b: rational) -> (res: rational) {
mul: i64 = lcm(a.denominator, b.denominator)
res = { a.numerator * mul - b.numerator * mul, mul };
}
39 changes: 0 additions & 39 deletions src/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 762c034

Please sign in to comment.