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 generator #319

Merged
merged 14 commits into from
Aug 4, 2023
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ cmake-clean:

lsp-wasm:
@wasm-pack build --target bundler --no-default-features --scope pivot-lang

renew-expect:
@UPDATE_EXPECT=1 cargo test --all

mdbook-install:
@cargo install mdbook
@cargo install mdbook-mermaid
@cargo install mdbook-admonish
@cargo install mdbook-linkcheck
@cargo install mdbook-toc

5 changes: 5 additions & 0 deletions immix/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ impl Collector {
/// precise mark a pointer
unsafe extern "C" fn mark_ptr(&self, ptr: *mut u8) {
let father = ptr;
// check pointer is valid (divided by 8)
if (ptr as usize) % 8 != 0 {
return;
}

let mut ptr = *(ptr as *mut *mut u8);
// println!("mark ptr {:p} -> {:p}", father, ptr);
// mark it if it is in heap
Expand Down
6 changes: 3 additions & 3 deletions immix/src/llvm_stackmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ pub fn build_root_maps(
for _ in 0..num_functions {
let (function, next_ptr) = Function::new(ptr);
function.safe_points.iter().for_each(|&safe_point| {
roots
.insert(safe_point, function.clone())
.and_then(|_| -> Option<()> { panic!("duplicate safe point: {:p}", safe_point) });
if roots.insert(safe_point, function.clone()).is_some() {
panic!("duplicate safe point: {:p}", safe_point)
}
});
// roots.insert(function.addr, function);
ptr = next_ptr;
Expand Down
1 change: 1 addition & 0 deletions pl_linker/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ impl Linker for MsvcLinker {
self.push_args("bcrypt.lib");
self.push_args("userenv.lib");
self.push_args("advapi32.lib");
self.push_args("ntdll.lib");

// use linker directly, since lld may report
// lld-link: error: The CodeView record is corrupted.
Expand Down
2 changes: 2 additions & 0 deletions planglib/core/builtin.pi
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ impl <T> Option<T> {
return f(v);
}
}

pub use core::gc::string;
7 changes: 6 additions & 1 deletion planglib/core/gc.pi
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
pub fn DioGC__malloc(size: i64, obj_type: u8) *u8;
fn DioGC__malloc(size: i64, obj_type: u8) *u8;

pub fn DioGC__collect() void;

pub fn DioGC__malloc_no_collect(size: i64, obj_type: u8) *u8;


pub fn malloc<T>() *u8 {
return DioGC__malloc(sizeof<T>(), gc_type<T>());
}

pub struct string {
pub len: i64;
pub byte_len: i64;
Expand Down
3 changes: 2 additions & 1 deletion planglib/std/__private.pi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io;
use std::stdbuiltin;
use std::iter;
use std::iter;
use std::cols::arr;
72 changes: 72 additions & 0 deletions planglib/std/cols/arr.pi
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::iter::*;
use core::panic::*;
use std::io;

pub struct Array<T> {
data:[T];
len:u32;
}

pub fn new<T>() Array<T> {
let arr_raw = [T*4;];
let arr = Array<T> {
len:0 as u32
};
arr.data = arr_raw;
return arr;
}

impl <T> Array<T> {
pub fn push(t:T) void {
if self.len as i64 + 1 > arr_len(self.data) {
let new_data = [T*(arr_len(self.data) * 2);];
arr_copy(self.data, new_data, arr_len(self.data));
self.data = new_data;
self.data[self.len as i64] = t;
self.len = self.len + 1;
}else {
self.data[self.len as i64] = t;
self.len = self.len + 1;
}
return;
}
pub fn pop() T {
self.len = self.len - 1;
return self.data[self.len as i64];
}
pub fn len() u32 {
return self.len;
}
pub fn get(i:i64) T {
self.check_idx(i);
return self.data[i];
}
fn check_idx(i:i64) void {
if i >= arr_len(self.data) {
io::print_s("Array index out of bounds");
pl_panic();
}
return;
}
pub fn set(i:i64, t:T) void {
self.check_idx(i);
self.data[i] = t;
return;
}

gen pub fn iter() Iterator<T> {
for let i = 0; i < self.len as i64; i = i + 1 {
yield return self.data[i];
}
}
}


pub fn from_slice<T>(slice:[T]) Array<T> {
let arr = Array<T> {
len:arr_len(slice) as u32
};
arr.data = slice;
return arr;
}

12 changes: 0 additions & 12 deletions planglib/std/iter.pi
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
use core::builtin::*;

pub trait Iterator<T> {
fn next() Option<T>;
}

struct name<T> {
t:T;
}

impl <T> Iterator<T> for name<T> {
fn next() Option<T> {
return self.t;
}
}

2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.69.0
1.71.0
Loading