Skip to content

Commit

Permalink
fidle
Browse files Browse the repository at this point in the history
  • Loading branch information
sthiele committed Oct 14, 2023
1 parent c14e1a1 commit 3f5246f
Showing 1 changed file with 62 additions and 31 deletions.
93 changes: 62 additions & 31 deletions examples/test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use clingo::ast::{guard, symbolic_term, ComparisonOperator, Location};
use clingo::ast::{symbolic_term, ComparisonOperator, Guard, Location, SymbolicTerm, Term, AST};
use clingo::Symbol;
use clingo_sys::*;
use core::marker::PhantomData;
use core::ptr::NonNull;
use std::ffi::{CStr, CString};

fn raw() {
use std::ffi::{CStr, CString};

let file = CString::new("").unwrap();
let location = clingo_location {
begin_line: 0,
Expand Down Expand Up @@ -68,12 +69,38 @@ fn raw() {
assert_eq!(res, " > \"test\"".to_string());
}

fn wrapped() {
use clingo::ast::{Guard, Term, AST};
use core::marker::PhantomData;
use core::ptr::NonNull;
use std::ffi::{CStr, CString};
fn xguard<'a, T>(gt: ComparisonOperator, symbolic_term: T) -> Result<Guard<'a>, ()>
where
T: Into<Term<'a>>,
{
let term: Term = symbolic_term.into();
let mut guard = std::ptr::null_mut();
if !unsafe {
clingo_ast_build(
clingo_ast_type_e_clingo_ast_type_guard as i32,
&mut guard,
gt,
term.ast,
)
} {
panic!("clingo_ast_build() guard failed.");
}
let _ = gt;
let _ = term;
let _ = symbolic_term;

match NonNull::new(guard) {
Some(ast) => Ok(Guard {
ast: AST {
ptr: ast,
_lifetime: PhantomData,
},
}),
None => Err(()),
}
}

fn wrapped() {
let loc = Location::default();
let mut symbol = 0;
let c_str = CString::new("test").unwrap();
Expand Down Expand Up @@ -108,30 +135,34 @@ fn wrapped() {

let gt = ComparisonOperator::GreaterThan;

let term : Term = symbolic_term.into();
let mut guard = std::ptr::null_mut();
if !unsafe {
clingo_ast_build(
clingo_ast_type_e_clingo_ast_type_guard as i32,
&mut guard,
gt as isize,
term,
)
} {
panic!("clingo_ast_build() guard failed.");
}
// let term: Term = symbolic_term.into();
// let mut guard = std::ptr::null_mut();
// if !unsafe {
// clingo_ast_build(
// clingo_ast_type_e_clingo_ast_type_guard as i32,
// &mut guard,
// gt as isize,
// term.ast,
// )
// } {
// panic!("clingo_ast_build() guard failed.");
// }
// let _ = gt;
// let _ = term;
// let _ = symbolic_term;

let guard = match NonNull::new(guard) {
Some(ast) => Ok(Guard {
ast: AST {
ptr: ast,
_lifetime: PhantomData,
},
}),
None => Err(()),
};
let guard = guard.unwrap();
// let guard = guard(gt, symbolic_term).unwrap();
// let guard = match NonNull::new(guard) {
// Some(ast) => Ok(Guard {
// ast: AST {
// ptr: ast,
// _lifetime: PhantomData,
// },
// }),
// None => Err(()),
// };
// let guard = guard.unwrap();
let guard = xguard(gt, symbolic_term).unwrap();
// let guard = clingo::ast::guard(gt, symbolic_term).unwrap();

let mut size: usize = 0;
if !unsafe { clingo_ast_to_string_size(guard.ast.ptr.as_ptr(), &mut size) } {
Expand Down

0 comments on commit 3f5246f

Please sign in to comment.