Browse Source

Add basic skeleton of Rust version

Getty Ritter 3 years ago
parent
commit
da0fd8f85b
3 changed files with 63 additions and 0 deletions
  1. 3 0
      .gitignore
  2. 10 0
      Cargo.toml
  3. 50 0
      src/lib.rs

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+/target
+**/*.rs.bk
+Cargo.lock

+ 10 - 0
Cargo.toml

@@ -0,0 +1,10 @@
+[package]
+name = "rakonteto"
+version = "0.1.0"
+authors = ["Getty Ritter <samothes@infinitenegativeutility.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+z3 = "*"

+ 50 - 0
src/lib.rs

@@ -0,0 +1,50 @@
+use std::collections::HashMap;
+
+struct Context {
+    variables: Vec<String>,
+    var_lookup: HashMap<String, Var>,
+}
+
+#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
+struct Var {
+    idx: usize,
+}
+
+impl Context {
+    fn var(&mut self, name: &str) -> Var {
+        if let Some(v) = self.var_lookup.get(name) {
+            return *v;
+        }
+        let idx = self.variables.len();
+        let var = Var { idx };
+        self.variables.push(name.to_string());
+        self.var_lookup.insert(name.to_string(), var);
+        var
+    }
+}
+
+impl Var {
+    fn show<'r>(&self, ctx: &'r Context) -> &'r str {
+        &ctx.variables[self.idx]
+    }
+}
+
+struct StoryState {
+    variables: HashMap<Var, Vec<Var>>,
+}
+
+struct Story {
+    state: StoryState,
+    storylets: Vec<Storylet>,
+}
+
+struct Storylet {
+}
+
+#[cfg(test)]
+mod tests {
+    #[test]
+    fn it_works() {
+        assert_eq!(2 + 2, 4);
+    }
+}