-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tvm
crate stage 3 of Rust refactor (#5769)
* Adapt to new macro * Add tvm crate * Fix out of tree pass with new bindings * Super slick API working * Add examples * Delay egg example and add ASF headers * Move array.rs around * Remove outdated tests will restore in CI PR * Fix some memory issues * Fix ref counting issue * Formatting and cleanup * Remove out-of-tree for now * Remove out-of-tree
- Loading branch information
Showing
25 changed files
with
1,114 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
use std::convert::{TryFrom, TryInto}; | ||
use std::marker::PhantomData; | ||
|
||
use crate::errors::Error; | ||
use crate::object::{IsObjectRef, Object, ObjectPtr, ObjectRef}; | ||
use crate::{ | ||
external, | ||
function::{Function, Result}, | ||
RetValue, | ||
}; | ||
|
||
#[repr(C)] | ||
#[derive(Clone)] | ||
pub struct Array<T: IsObjectRef> { | ||
object: ObjectRef, | ||
_data: PhantomData<T>, | ||
} | ||
|
||
// TODO(@jroesch): convert to use generics instead of casting inside | ||
// the implementation. | ||
external! { | ||
#[name("node.ArrayGetItem")] | ||
fn array_get_item(array: ObjectRef, index: isize) -> ObjectRef; | ||
} | ||
|
||
impl<T: IsObjectRef> Array<T> { | ||
pub fn from_vec(data: Vec<T>) -> Result<Array<T>> { | ||
let iter = data | ||
.iter() | ||
.map(|element| element.to_object_ref().into()) | ||
.collect(); | ||
|
||
let func = Function::get("node.Array").expect( | ||
"node.Array function is not registered, this is most likely a build or linking error", | ||
); | ||
|
||
// let array_data = func.invoke(iter)?; | ||
// let array_data: ObjectRef = func.invoke(iter)?.try_into()?; | ||
let array_data: ObjectPtr<Object> = func.invoke(iter)?.try_into()?; | ||
|
||
debug_assert!( | ||
array_data.count() >= 1, | ||
"array reference count is {}", | ||
array_data.count() | ||
); | ||
|
||
Ok(Array { | ||
object: ObjectRef(Some(array_data)), | ||
_data: PhantomData, | ||
}) | ||
} | ||
|
||
pub fn get(&self, index: isize) -> Result<T> | ||
where | ||
T: TryFrom<RetValue, Error = Error>, | ||
{ | ||
let oref: ObjectRef = array_get_item(self.object.clone(), index)?; | ||
oref.downcast() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.