Skip to content

Commit 6b1a8f0

Browse files
authored
Add FFI (#54)
* Add FFI * Normalize all the line endings
1 parent 38b46bd commit 6b1a8f0

File tree

19 files changed

+896
-562
lines changed

19 files changed

+896
-562
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/target
1+
/target

Cargo.toml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
[package]
2-
name = "rocklang"
3-
version = "0.2.8"
4-
edition = "2021"
5-
authors = ["Jaroslaw Konik"]
6-
license = "MIT"
7-
description = "JIT-compiled functional programming language."
8-
documentation = "https://jarkonik.github.io/rocklang/"
9-
homepage = "https://jarkonik.github.io/rocklang/"
10-
repository = "https://github.com/jarkonik/rocklang"
11-
12-
# See more keys and their definitions at
13-
# https://doc.rust-lang.org/cargo/reference/manifest.html
14-
15-
[workspace]
16-
members = [
17-
"stdlib"
18-
]
19-
20-
[dependencies]
21-
serde = { version = "1.0.130", features = ["derive"] }
22-
serde_json = "1.0.59"
23-
assert-json-diff = "2.0.1"
24-
stdlib = { path = "./stdlib" }
25-
llvm-sys = "130"
26-
backtrace = "0.3"
27-
28-
[dev-dependencies]
29-
assert_cmd = "0.10"
30-
predicates = "2.1.0"
31-
32-
# [profile.release]
33-
# debug = true
1+
[package]
2+
name = "rocklang"
3+
version = "0.2.8"
4+
edition = "2021"
5+
authors = ["Jaroslaw Konik"]
6+
license = "MIT"
7+
description = "JIT-compiled functional programming language."
8+
documentation = "https://jarkonik.github.io/rocklang/"
9+
homepage = "https://jarkonik.github.io/rocklang/"
10+
repository = "https://github.com/jarkonik/rocklang"
11+
12+
# See more keys and their definitions at
13+
# https://doc.rust-lang.org/cargo/reference/manifest.html
14+
15+
[workspace]
16+
members = [
17+
"stdlib"
18+
]
19+
20+
[dependencies]
21+
serde = { version = "1.0.130", features = ["derive"] }
22+
serde_json = "1.0.59"
23+
assert-json-diff = "2.0.1"
24+
stdlib = { path = "./stdlib" }
25+
llvm-sys = "130"
26+
backtrace = "0.3"
27+
28+
[dev-dependencies]
29+
assert_cmd = "0.10"
30+
predicates = "2.1.0"
31+
32+
# [profile.release]
33+
# debug = true

MIT-LICENSE.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
Copyright (c) 2021 Jaroslaw Konik
2-
3-
Permission is hereby granted, free of charge, to any person obtaining
4-
a copy of this software and associated documentation files (the
5-
"Software"), to deal in the Software without restriction, including
6-
without limitation the rights to use, copy, modify, merge, publish,
7-
distribute, sublicense, and/or sell copies of the Software, and to
8-
permit persons to whom the Software is furnished to do so, subject to
9-
the following conditions:
10-
11-
The above copyright notice and this permission notice shall be
12-
included in all copies or substantial portions of the Software.
13-
14-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1+
Copyright (c) 2021 Jaroslaw Konik
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
1-
# Rock
2-
3-
⚠️The project is at a very early stage, lots of things will not work.
4-
5-
[![Github all releases](https://img.shields.io/github/downloads/jarkonik/rocklang/total.svg)](https://GitHub.com/jarkonik/rocklang/releases/)
6-
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate?hosted_button_id=Y25KDXY4LJYQ2)
7-
[![Continuous integration](https://github.com/jarkonik/rocklang/actions/workflows/main.yml/badge.svg)](https://github.com/jarkonik/rocklang/actions/workflows/main.yml)
8-
[![codecov](https://codecov.io/gh/jarkonik/rocklang/branch/main/graph/badge.svg?token=DW07IRWGG0)](https://codecov.io/gh/jarkonik/rocklang)
9-
[![Rocklang
10-
Discord](https://badgen.net/discord/members/NK3baHRTve)](https://discord.gg/NK3baHRTve)
11-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
12-
13-
<img src="./rock.svg" width="100" height="100">
14-
15-
JIT-compiled functional programming language.
16-
17-
## Getting started
18-
19-
### Windows
20-
21-
1. [Download and run the installer.](https://github.com/jarkonik/rocklang/releases/latest/download/rocklang-windows-latest.msi)
22-
2. At this point, if you haven't changed the default installer options,
23-
`rocklang.exe` should be installed and added to your `PATH`.
24-
3. Create a file named `main.rc` in a directory of your choice, with following
25-
content:
26-
```
27-
print("Hello from rocklang")
28-
```
29-
4. While being in the same directory, that you've created the source file in, run `rocklang main.rc` from PowerShell or
30-
Command Prompt.
31-
5. You should see text `Hello from rocklang` printed in your terminal.
32-
33-
## Example
34-
35-
Sample implementation of Sieve of Eratosthenes written in Rock
36-
37-
```c
38-
memset = (vec: vec, val: number, n: number): vec => {
39-
i = 0
40-
while i < n {
41-
vec = vecset(vec, i, val)
42-
i = i + 1
43-
}
44-
vec
45-
}
46-
47-
sieve = (n: number): void => {
48-
v = vecnew()
49-
prime = memset(v, 1, n + 1)
50-
51-
p = 2
52-
53-
while p * p <= n {
54-
if vecget(prime, p) == 1 {
55-
i = p * p
56-
while i <= n {
57-
prime = vecset(prime, i, 0)
58-
i = i + p
59-
}
60-
}
61-
62-
p = p + 1
63-
}
64-
65-
p = 2
66-
67-
while p <= n {
68-
if vecget(prime, p) == 1 {
69-
print(string(p))
70-
print("\n")
71-
}
72-
73-
p = p + 1
74-
}
75-
}
76-
77-
sieve(100)
78-
```
79-
80-
## Building from source
81-
1. Install Rust compiler that supports Rust Edition 2021, along with `cargo` tool, in your favorite fashion.
82-
2. Install llvm 13
83-
3. Run `cargo build` to build binaries or `cargo run examples/sieve.rc` to run a sample program.
84-
85-
## License
86-
87-
This project is licensed under the terms of the MIT license.
1+
# Rock
2+
3+
⚠️The project is at a very early stage, lots of things will not work.
4+
5+
[![Github all releases](https://img.shields.io/github/downloads/jarkonik/rocklang/total.svg)](https://GitHub.com/jarkonik/rocklang/releases/)
6+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate?hosted_button_id=Y25KDXY4LJYQ2)
7+
[![Continuous integration](https://github.com/jarkonik/rocklang/actions/workflows/main.yml/badge.svg)](https://github.com/jarkonik/rocklang/actions/workflows/main.yml)
8+
[![codecov](https://codecov.io/gh/jarkonik/rocklang/branch/main/graph/badge.svg?token=DW07IRWGG0)](https://codecov.io/gh/jarkonik/rocklang)
9+
[![Rocklang
10+
Discord](https://badgen.net/discord/members/NK3baHRTve)](https://discord.gg/NK3baHRTve)
11+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
12+
13+
<img src="./rock.svg" width="100" height="100">
14+
15+
JIT-compiled functional programming language.
16+
17+
## Getting started
18+
19+
### Windows
20+
21+
1. [Download and run the installer.](https://github.com/jarkonik/rocklang/releases/latest/download/rocklang-windows-latest.msi)
22+
2. At this point, if you haven't changed the default installer options,
23+
`rocklang.exe` should be installed and added to your `PATH`.
24+
3. Create a file named `main.rc` in a directory of your choice, with following
25+
content:
26+
```
27+
print("Hello from rocklang")
28+
```
29+
4. While being in the same directory, that you've created the source file in, run `rocklang main.rc` from PowerShell or
30+
Command Prompt.
31+
5. You should see text `Hello from rocklang` printed in your terminal.
32+
33+
## Example
34+
35+
Sample implementation of Sieve of Eratosthenes written in Rock
36+
37+
```c
38+
memset = (vec: vec, val: number, n: number): vec => {
39+
i = 0
40+
while i < n {
41+
vec = vecset(vec, i, val)
42+
i = i + 1
43+
}
44+
vec
45+
}
46+
47+
sieve = (n: number): void => {
48+
v = vecnew()
49+
prime = memset(v, 1, n + 1)
50+
51+
p = 2
52+
53+
while p * p <= n {
54+
if vecget(prime, p) == 1 {
55+
i = p * p
56+
while i <= n {
57+
prime = vecset(prime, i, 0)
58+
i = i + p
59+
}
60+
}
61+
62+
p = p + 1
63+
}
64+
65+
p = 2
66+
67+
while p <= n {
68+
if vecget(prime, p) == 1 {
69+
print(string(p))
70+
print("\n")
71+
}
72+
73+
p = p + 1
74+
}
75+
}
76+
77+
sieve(100)
78+
```
79+
80+
## Building from source
81+
1. Install Rust compiler that supports Rust Edition 2021, along with `cargo` tool, in your favorite fashion.
82+
2. Install llvm 13
83+
3. Run `cargo build` to build binaries or `cargo run examples/sieve.rc` to run a sample program.
84+
85+
## License
86+
87+
This project is licensed under the terms of the MIT license.

examples/ffi.rc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
load("./tests/rockffitestlib.so")
2+
rockffitestlib = extern<number, number, number>("rockffitest")
3+
4+
print("2 + 3 is ")
5+
print(string(rockffitestlib(2, 3)))
6+
print("\n")

0 commit comments

Comments
 (0)