Skip to content

Commit

Permalink
Merge pull request #27 from hotg-ai/parsing-gesture-runefile
Browse files Browse the repository at this point in the history
Parse the Gesture runefile
  • Loading branch information
Michael-F-Bryan committed Feb 28, 2021
2 parents 200c344 + 3a1b3ef commit 7e5241b
Show file tree
Hide file tree
Showing 9 changed files with 931 additions and 465 deletions.
35 changes: 31 additions & 4 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use anyhow::{Context, Error};
use handlebars::Handlebars;
use rune_syntax::hir::{Rune, Sink, SourceKind};
use rune_syntax::{
ast::{ArgumentValue, Literal, LiteralKind},
hir::{Rune, Sink, SourceKind},
};
use serde::Serialize;
use serde_json::{json, Value};
use std::{
collections::HashMap,
fs::File,
path::{Path, PathBuf},
process::Command,
Expand Down Expand Up @@ -171,14 +175,17 @@ impl Generator {
for (&id, source) in &self.rune.sources {
if let Some(name) = self.rune.names.get_name(id) {
let kind = match &source.kind {
SourceKind::Rand => "RAND",
SourceKind::Random => "RAND",
SourceKind::Accelerometer => "ACCEL",
SourceKind::Other(name) => name.as_str(),
};

capabilities.push(json!({
"name": name,
"kind": kind,
"parameters": source.parameters,
"parameters": source.parameters.iter()
.map(|p| (&p.name.value, jsonify_arg_value(&p.value)))
.collect::<HashMap<_, _>>(),
}));
}
}
Expand Down Expand Up @@ -255,7 +262,7 @@ fn _dependency_info(
let git_repo = if is_builtin {
String::from(RUNE_GIT_REPO)
} else {
format!("https://github.com/{}.git", proc.path)
format!("https://github.com/{}.git", proc.path.body)
};

json!({ "name": name, "git": git_repo })
Expand All @@ -266,3 +273,23 @@ fn create_dir(path: impl AsRef<Path>) -> Result<(), Error> {
std::fs::create_dir_all(path)
.with_context(|| format!("Unable to create \"{}\"", path.display()))
}

fn jsonify_arg_value(arg: &ArgumentValue) -> Value {
match arg {
ArgumentValue::Literal(Literal {
kind: LiteralKind::Integer(i),
..
}) => Value::from(*i),
ArgumentValue::Literal(Literal {
kind: LiteralKind::Float(f),
..
}) => Value::from(*f),
ArgumentValue::Literal(Literal {
kind: LiteralKind::String(s),
..
}) => Value::from(s.as_str()),
ArgumentValue::List(list) => {
Value::Array(list.iter().map(|s| Value::from(s.as_str())).collect())
},
}
}
8 changes: 4 additions & 4 deletions examples/gesture/Runefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM runicos/base

CAPABILITY<_,f32[384]> accelerometer ACCEL -n 128
CAPABILITY<F32[384]> accelerometer ACCEL -n 128

# Dependency is { git = "https://github.com/hotg-ai/rune", path="proc_blocks/normalize" }
PROC_BLOCK<f32[384],f32[384]> normalize hotg-ai/rune#proc_blocks/normalize
PROC_BLOCK<F32[384],F32[384]> normalize hotg-ai/rune#proc_blocks/normalize

MODEL<f32[384],f32[4]> gesture ./model.tflite
MODEL<F32[384],F32[4]> gesture ./model.tflite


# Dependency is { git = "https://github.com/hotg-ai/rune", path="proc_blocks/ohv_label" }
PROC_BLOCK<f32[4], UTF8> label hotg-ai/rune#proc_blocks/ohv_label --labels=Wing,Ring,Slope,Unknown
PROC_BLOCK<F32[4], UTF8> label hotg-ai/rune#proc_blocks/ohv_label --labels=Wing,Ring,Slope,Unknown

RUN accelerometer normalize gesture label

Expand Down
8 changes: 4 additions & 4 deletions examples/sine/Runefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

FROM runicos/base
FROM runicos/base

CAPABILITY<_,I32> RAND rand --n 1
CAPABILITY<I32> rand RAND --n 1

PROC_BLOCK<_,_> hotg-ai/pb-mod mod360 --modulo 100
PROC_BLOCK<_,_> mod360 hotg-ai/pb-mod --modulo 100

MODEL<_,_> ./sinemodel.tflite sine --input [1,1] --output [1,1]
MODEL<I32, F32> sine ./sinemodel.tflite

RUN rand mod360 sine

Expand Down

0 comments on commit 7e5241b

Please sign in to comment.