add cangjie binding (#117)
This commit is contained in:
parent
28ff8bb8f7
commit
501b6b0d75
46
README.md
46
README.md
@ -495,6 +495,52 @@ class Example {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
### ruapu with cangjie
|
||||||
|
|
||||||
|
<table>
|
||||||
|
|
||||||
|
<tr><td>
|
||||||
|
|
||||||
|
Compile ruapu library
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd cangjie
|
||||||
|
cd c-src
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
```
|
||||||
|
run example
|
||||||
|
```bash
|
||||||
|
cd cangjie
|
||||||
|
cjpm run
|
||||||
|
```
|
||||||
|
or compile example
|
||||||
|
```bash
|
||||||
|
cd cangjie
|
||||||
|
cjpm build
|
||||||
|
./target/release/bin/main
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
Use ruapu in cangjie
|
||||||
|
|
||||||
|
```swift
|
||||||
|
import ruapu.*
|
||||||
|
main(): Int64 {
|
||||||
|
ruapu_init()
|
||||||
|
let neon_supported = ruapu_supports("neon")
|
||||||
|
println("supports neon: ${neon_supported}")
|
||||||
|
let d = ruapu_rua()
|
||||||
|
for (i in d) {
|
||||||
|
println(i)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
```
|
||||||
</td></tr>
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
14
cangjie/README.md
Normal file
14
cangjie/README.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
## ruapu cangjie
|
||||||
|
|
||||||
|
当前代码仓颉版本: `0.51.4`
|
||||||
|
|
||||||
|
> 仓颉目前处于内测阶段,不保证该代码在更新的仓颉编译器版本中可用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd cangjie
|
||||||
|
cd c-src
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
cd ..
|
||||||
|
cjpm run
|
||||||
|
```
|
10
cangjie/c-src/CMakeLists.txt
Normal file
10
cangjie/c-src/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
project(ruapu)
|
||||||
|
|
||||||
|
include_directories(../../)
|
||||||
|
|
||||||
|
|
||||||
|
add_library(ruapu
|
||||||
|
ruapu-binding.c
|
||||||
|
)
|
14
cangjie/c-src/ruapu-binding.c
Normal file
14
cangjie/c-src/ruapu-binding.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#define RUAPU_IMPLEMENTATION
|
||||||
|
#include "ruapu.h"
|
||||||
|
|
||||||
|
void ruapu_init_c() {
|
||||||
|
ruapu_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ruapu_supports_c(const char* isa) {
|
||||||
|
return ruapu_supports(isa);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* const* ruapu_rua_c() {
|
||||||
|
return ruapu_rua();
|
||||||
|
}
|
16
cangjie/cjpm.toml
Normal file
16
cangjie/cjpm.toml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
cjc-version = "0.51.4"
|
||||||
|
compile-option = ""
|
||||||
|
description = "ruapu"
|
||||||
|
link-option = ""
|
||||||
|
name = "ruapu_cangjie"
|
||||||
|
output-type = "executable"
|
||||||
|
src-dir = ""
|
||||||
|
target-dir = ""
|
||||||
|
version = "1.0.0"
|
||||||
|
package-configuration = {}
|
||||||
|
|
||||||
|
[ffi.c]
|
||||||
|
ruapu = { path = "./c-src/" }
|
11
cangjie/src/main.cj
Normal file
11
cangjie/src/main.cj
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import ruapu.*
|
||||||
|
main(): Int64 {
|
||||||
|
ruapu_init()
|
||||||
|
let neon_supported = ruapu_supports("neon")
|
||||||
|
println("supports neon: ${neon_supported}")
|
||||||
|
let d = ruapu_rua()
|
||||||
|
for (i in d) {
|
||||||
|
println(i)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
30
cangjie/src/ruapu/ruapu.cj
Normal file
30
cangjie/src/ruapu/ruapu.cj
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package ruapu
|
||||||
|
|
||||||
|
from std import collection.ArrayList
|
||||||
|
|
||||||
|
foreign func ruapu_init_c(): Unit
|
||||||
|
|
||||||
|
foreign func ruapu_supports_c(s: CString): Int32
|
||||||
|
|
||||||
|
foreign func ruapu_rua_c(): CPointer<CString>
|
||||||
|
|
||||||
|
public func ruapu_init(): Unit {
|
||||||
|
unsafe{ ruapu_init_c() }
|
||||||
|
}
|
||||||
|
|
||||||
|
public func ruapu_supports(isa: String): Bool {
|
||||||
|
var isa_c = unsafe { LibC.mallocCString(isa) }
|
||||||
|
let result_c = unsafe { ruapu_supports_c(isa_c) }
|
||||||
|
return result_c == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
public func ruapu_rua(): Array<String> {
|
||||||
|
var ruaList = ArrayList<String>()
|
||||||
|
var sp = unsafe { ruapu_rua_c() }
|
||||||
|
while(!unsafe { sp.read().isNull() }) {
|
||||||
|
let temp = unsafe { sp.read() }
|
||||||
|
ruaList.append(temp.toString())
|
||||||
|
sp = unsafe { sp + 1 }
|
||||||
|
}
|
||||||
|
return Array<String>(ruaList)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user