Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add libuv to provide some asynchronous functionality #432

Merged
merged 25 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
195258b
feat: implement delay async using libuv
Chronostasys Aug 12, 2024
4d7cf61
feat: support async closure
Chronostasys Aug 15, 2024
fb5e289
fix: wrong generator parameter logic
Chronostasys Aug 16, 2024
ca59e15
fix: missing libuv symbol sometimes
Chronostasys Aug 21, 2024
45032c7
fix: support await statement
Chronostasys Aug 21, 2024
dec2a67
try: build uv myself
Chronostasys Aug 28, 2024
8c2588f
try fix link issue
Chronostasys Aug 28, 2024
f1e97be
fix: cannot lgcc on linux
Chronostasys Aug 28, 2024
d5f0fd6
fix: use cmake to compile libuv && add jit load libuv logic
Chronostasys Aug 29, 2024
9665e49
fix: fuck Rust build script cfg
Chronostasys Aug 29, 2024
4db94da
fix: dylib load on macos & jit crash bug
Chronostasys Aug 30, 2024
0cf138b
fix: a macro panic issue && add beter diag msg for macro related err
Chronostasys Sep 2, 2024
6234a15
fix: global inference
Chronostasys Sep 3, 2024
8448b48
fix: use generic caches correctly in LSP
Chronostasys Sep 6, 2024
fa11c27
feat: add basic tcp listen
Chronostasys Sep 9, 2024
c858f5b
feat: add auto accept
Chronostasys Sep 9, 2024
ac1bec4
feat: make conn callback into async fn
Chronostasys Sep 10, 2024
b4e0a3e
feat: tcp read
Chronostasys Sep 12, 2024
cc556f3
feat: add stream write req
Chronostasys Sep 17, 2024
7e194b7
feat: echo server
Chronostasys Sep 17, 2024
83c0695
chore: update salsa
Chronostasys Sep 23, 2024
2e96cf2
feat: add stop ev & fix a win bug
Chronostasys Sep 27, 2024
bb08b19
feat: allow async main directly
Chronostasys Oct 9, 2024
5a4666c
fix: make ci happy
Chronostasys Oct 9, 2024
4561aed
try fix: orc jit exit error
Chronostasys Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
RUSTFLAGS: ""
libvm: "libvm.a"
libvm_dylib: "libvm.dylib"
libuv_dylib: "libuv.dylib"
- os: "ubuntu-latest"
dir: linux64
debdir: pivot-lang_0.1.0-1_amd64
Expand All @@ -40,12 +41,14 @@ jobs:
RUSTFLAGS: ""
libvm: "libvm.a"
libvm_dylib: "libvm.so"
libuv_dylib: "libuv.so"
- os: "windows-latest"
dir: win64
artifacts: "plc.exe"
RUSTFLAGS: "-Dwarnings -Ctarget-feature=+crt-static"
libvm: "vm.lib"
libvm_dylib: "vm.dll"
libuv_dylib: "uv.dll"
arch: windows-amd64
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -127,6 +130,20 @@ jobs:
dst = os.environ['OUT_DIR'] + "/" + artifact
shutil.copy(src, dst)
shell: python
- name: Move libuv dylib
env:
ARTIFACTS: ${{ matrix.config.libuv_dylib }}
OUT_DIR: ${{ matrix.config.dir }}
OS: ${{ matrix.config.os }}
run: |
import os
import shutil
artifacts = os.environ['ARTIFACTS'].split()
for artifact in artifacts:
src = "target/release/%s" % artifact
dst = os.environ['OUT_DIR'] + "/" + artifact
shutil.copy(src, dst)
shell: python
- name: Move pllib
env:
ARTIFACTS: planglib
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"lldb.showDisassembly": "auto",
"lldb.dereferencePointers": true,
"lldb.consoleMode": "commands",
"makefile.configureOnOpen": true,
// "rust-analyzer.check.targets": [
// "wasm32-unknown-unknown",
// ],
Expand Down
9 changes: 6 additions & 3 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ vmdebug:
@cp target/debug/libvm.a target/release/libvm.a
@touch target/debug/libvm.so && cp target/debug/libvm.so target/release/libvm.so
@touch target/debug/libvm.dylib && cp target/debug/libvm.dylib target/release/libvm.dylib
@touch target/debug/libuv.so && cp target/debug/libvm.so target/release/libuv.so
@touch target/debug/libuv.dylib && cp target/debug/libuv.dylib target/release/libuv.dylib

install:
@cargo install --path=.
@cargo install --path=. --locked

fmt:
@cargo +stable fmt
Expand Down
2 changes: 1 addition & 1 deletion immix
Submodule immix updated 5 files
+46 −24 llvm/pljit.cpp
+18 −2 src/block.rs
+20 −0 src/c_api.rs
+7 −2 src/collector.rs
+23 −0 src/lib.rs
35 changes: 34 additions & 1 deletion pl_linker/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ fn get_linux_lib_paths() -> Vec<String> {
paths
}

// fn get_libgcc_path() -> Result<String, String> {
// let base_path = "/usr/lib/gcc/x86_64-linux-gnu";
// let entries = std::fs::read_dir(base_path).map_err(|e| format!("Failed to read directory {}: {}", base_path, e))?;

// for entry in entries {
// let entry = entry.map_err(|e| format!("Failed to read directory entry: {}", e))?;
// if entry.path().is_dir() {
// let version = entry.file_name().into_string().map_err(|e| format!("Failed to convert OsString to String: {:?}", e))?;
// return Ok(format!("{}/{}", base_path, version));
// }
// }

// Err("No valid gcc version directory found".to_string())
// }

impl Linker for LdLinker {
fn add_object(&mut self, path: &Path) -> Result<(), LinkerError> {
let path_str = path
Expand All @@ -115,9 +130,21 @@ impl Linker for LdLinker {
paths.iter().for_each(|lib| {
self.push_args(&format!("-L{}", lib.as_str()));
});
// // Add the path to the libgcc library
// match get_libgcc_path() {
// Ok(libgcc_dir) => {
// self.push_args(&format!("-L{}", libgcc_dir));
// }
// Err(e) => {
// return Err(LinkerError::LinkError(format!(
// "Failed to get libgcc path: {}",
// e
// )));
// }
// }
// libs and link args
[
"-pie",
"-no-pie",
"-zrelro",
"--hash-style=gnu",
"--build-id",
Expand All @@ -133,6 +160,7 @@ impl Linker for LdLinker {
"-lunwind",
"--no-as-needed",
"-ldl",
// "-lgcc",
// "/usr/lib/gcc/x86_64-linux-gnu/<version>/crtendS.o",
"/lib/x86_64-linux-gnu/crtn.o",
]
Expand Down Expand Up @@ -318,6 +346,11 @@ impl Linker for MsvcLinker {
self.push_args("ntdll.lib");
self.push_args("psapi.lib");
self.push_args("PowrProf.lib");
self.push_args("user32.lib"); // Add user32.lib
self.push_args("dbghelp.lib"); // Add dbghelp.lib
self.push_args("ole32.lib"); // Add ole32.lib
self.push_args("shell32.lib"); // Add shell32.lib
self.push_args("iphlpapi.lib"); // Add iphlpapi.lib

self.args.insert(0, "lld-link".to_owned());
lld_rs::link(lld_rs::LldFlavor::Coff, &self.args)
Expand Down
66 changes: 61 additions & 5 deletions planglib/core/gc.pi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn DioGC__malloc(size: i64, obj_type: u8, rsp:i64) *u8;
fn DioGC__malloc(size: i64, obj_type: u8, rsp:i64) *();

pub fn DioGC__collect() void;

Expand All @@ -10,9 +10,31 @@ pub fn DioGC__enable_auto_collect() void;

pub fn DioGC__get_stw_num() i64;

fn DioGC__stuck_begin(sp:i64) void;
pub fn DioGC__stuck_begin(sp:i64) void;

fn DioGC__stuck_end() void;
pub fn DioGC__pin(ptr: * u8) void;

fn DioGC__keep_live_pinned(ptr: *u8) void;

fn DioGC__rm_live_pinned(ptr: *u8) void;

fn DioGC__is_pinned(ptr: *u8) i32;

pub fn is_pinned<T>(ptr: *T) bool {
return DioGC__is_pinned(unsafe_cast<u8>(ptr)) == 1;
}

pub fn keep_alive_pinned<T>(ptr: *T) void {
DioGC__keep_live_pinned(unsafe_cast<u8>(ptr));
return;
}

pub fn rm_alive_pinned<T>(ptr: *T) void {
DioGC__rm_live_pinned(unsafe_cast<u8>(ptr));
return;
}

pub fn DioGC__stuck_end() void;
fn DioGC__add_coro_stack(sp:i64, stack:* u8) void;
fn DioGC__remove_coro_stack(stack:i64) void;

Expand All @@ -32,6 +54,11 @@ pub fn remove_coro_stack(stack:i64) void {
return;
}

pub fn pin<T>(ptr: *T) void {
DioGC__pin(unsafe_cast<u8>(ptr));
return;
}

/// # string
///
/// Built-in string type
Expand Down Expand Up @@ -72,8 +99,6 @@ pub fn ptr_to_int(ptr: *u8) i64;

pub fn utf8_count(ptr: *u8, len:i64) i64;

fn printi64ln(i:i64) void;

impl string {
pub fn append(str: string) void {
let old = self.data;
Expand Down Expand Up @@ -113,6 +138,13 @@ impl string {
return arr_from_raw(self.data, self._byte_len);
}

pub fn cstr() *u8 {
let arr = [u8*self._byte_len + 1;];
memcpy(&arr[0], self.data, self._byte_len);
arr[self._byte_len] = 0 as u8;
return &arr[0];
}

pub fn chars() [char] {
let bytes = arr_from_raw(self.data, self._byte_len);
let chars = [char*self._len;];
Expand Down Expand Up @@ -169,3 +201,27 @@ pub fn string_eq(l:string, r:string) bool {
}
return true;
}


/// # malloc
///
/// Allocate memory using GC
///
/// The allocated memory is treated as atomic, which means the memory
/// shall not contain any gc pointer.
pub fn malloc(size: i64) * () {
return DioGC__malloc(size, 0 as u8, asm_sp());
}


/// # malloc_pinned
///
/// Allocate memory using GC
///
/// The allocated memory is treated as pinned-atomic, which means the memory
/// shall not contain any gc pointer, and it will not be moved by gc.
pub fn malloc_pinned(size: i64) * () {
let mem = DioGC__malloc(size, 0 as u8, asm_sp());
pin(mem);
return mem;
}
6 changes: 6 additions & 0 deletions planglib/std/__private.pi
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ use std::time;
use std::string;
use std::slice;
use std::task;
use std::libuv;
use std::task::reactor;
use std::task::executor;
use std::task::helper;
use std::task::delay;
use std::task::tcp;
Loading
Loading