Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.

Commit 00135b3

Browse files
author
Shady Khalifa
authored
Merge pull request #1 from AhmedKorim/master
integrate allo_isolate
2 parents eb6755a + 932d9b7 commit 00135b3

File tree

5 files changed

+156
-365
lines changed

5 files changed

+156
-365
lines changed

src/dart_source_writer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ impl DartSourceWriter {
5050
let mut map = HashMap::new();
5151
map.insert("void *", DartType::new("Pointer", "Pointer"));
5252
map.insert("void", DartType::new("Void", "void"));
53-
53+
map.insert(
54+
"Dart_CObject",
55+
DartType::new("Dart_CObject", "Dart_CObject"),
56+
);
5457
map.insert(
5558
"char *",
5659
DartType::new("Pointer<ffi.Utf8>", "Pointer<ffi.Utf8>"),

src/lib.rs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,32 @@
3838
//! // and start using it to write your own high level abstraction.
3939
//! bindings.write_to_file("simple/lib/ffi.dart")?;
4040
//! ```
41-
use clang::{Clang, Entity, EntityKind, Index, Type, TypeKind};
42-
use log::debug;
4341
use std::{
4442
collections::HashMap,
4543
fmt, fs,
4644
io::{self, Write},
4745
path::PathBuf,
4846
};
47+
48+
use clang::{Clang, Entity, EntityKind, Index, Type, TypeKind};
49+
use log::debug;
50+
51+
use config::DynamicLibraryConfig;
52+
use dart_source_writer::{DartSourceWriter, ImportedUri};
53+
use errors::CodegenError;
54+
use func::{Func, Param};
55+
use structure::{Field, Struct};
56+
4957
/// Bindgens config for loading `DynamicLibrary` on each Platform.
5058
pub mod config;
51-
use config::DynamicLibraryConfig;
5259

5360
mod dart_source_writer;
54-
use dart_source_writer::{DartSourceWriter, ImportedUri};
5561

5662
mod errors;
57-
use errors::CodegenError;
5863

5964
mod structure;
60-
use structure::{Field, Struct};
6165

6266
mod func;
63-
use func::{Func, Param};
6467

6568
/// Abstract over Func, Struct and Global.
6669
trait Element {
@@ -73,10 +76,12 @@ trait Element {
7376
/// Used to Write the Current Element to the Final Source File
7477
fn generate_source(&self, w: &mut DartSourceWriter) -> io::Result<()>;
7578
}
79+
7680
/// Dart Code Generator
7781
pub struct Codegen {
7882
src_header: PathBuf,
7983
lib_name: String,
84+
allo_isolate: bool,
8085
config: DynamicLibraryConfig,
8186
elements: HashMap<String, Box<dyn Element>>,
8287
}
@@ -118,6 +123,23 @@ impl Codegen {
118123
self.elements.insert(s.name().to_owned(), Box::new(s));
119124
}
120125
}
126+
if self.allo_isolate {
127+
// push new element
128+
let params = vec![Param::new(
129+
Some("ptr".to_string()),
130+
"Pointer<NativeFunction<Int8 \
131+
Function(Int64, Pointer<Dart_CObject>)>>"
132+
.to_string(),
133+
)];
134+
let func = Func::new(
135+
"store_dart_post_cobject".to_string(),
136+
None,
137+
params,
138+
"void".to_string(),
139+
);
140+
self.elements
141+
.insert("store_dart_post_cobject".to_string(), Box::new(func));
142+
}
121143
debug!("Generating Dart Source...");
122144
for el in self.elements.values() {
123145
el.generate_source(&mut dsw)?;
@@ -299,13 +321,15 @@ impl fmt::Debug for Codegen {
299321
.finish()
300322
}
301323
}
324+
302325
/// The [`Codegen`] Builder
303326
///
304327
/// start by calling [`Codegen::builder()`]
305328
#[derive(Clone, Debug, Default)]
306329
pub struct CodegenBuilder {
307330
src_header: PathBuf,
308331
lib_name: String,
332+
allo_isolate: bool,
309333
config: Option<DynamicLibraryConfig>,
310334
}
311335

@@ -336,7 +360,10 @@ impl CodegenBuilder {
336360
///
337361
/// This allow dart-bindgen to add the code required by allo-isolate
338362
/// i.e `store_dart_post_cobject` fn
339-
pub const fn with_allo_isoate(mut self) -> Self { self }
363+
pub const fn with_allo_isolate(mut self) -> Self {
364+
self.allo_isolate = true;
365+
self
366+
}
340367

341368
/// Consumes the builder and validate everyting, then create the [`Codegen`]
342369
pub fn build(self) -> Result<Codegen, CodegenError> {
@@ -353,6 +380,7 @@ impl CodegenBuilder {
353380
Ok(Codegen {
354381
src_header: self.src_header,
355382
lib_name: self.lib_name,
383+
allo_isolate: self.allo_isolate,
356384
config,
357385
elements: HashMap::new(),
358386
})

0 commit comments

Comments
 (0)