├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── clojit-0.1.0-SNAPSHOT-standalone.jar ├── clojitvm ├── resources └── programs │ ├── builtin1.clj │ ├── builtin_int.clj │ ├── builtin_int.cson │ ├── closure_test.clj │ ├── complex_closure.clj │ ├── complex_closure2.clj │ ├── complex_closure3.clj │ ├── function-ret-trunc.clj │ ├── let_test.clj │ ├── let_test.cson │ ├── multi_protocol_type.clj │ ├── multi_protocol_type.cson │ ├── multiarty_same_name.clj │ ├── multiarty_same_name.cson │ ├── output_test.clj │ ├── simple_float_test.clj │ ├── simple_fn_call.clj │ ├── simple_fn_call_2.clj │ ├── simple_fn_call_2.cson │ ├── simple_if_test.clj │ ├── simple_if_test.cson │ ├── simple_loop.clj │ ├── simple_ns_and_add.clj │ ├── simple_ns_and_add.cson │ ├── simple_protocol_type.clj │ ├── simple_protocol_type_prn.clj │ ├── simple_type.clj │ ├── simpler_fn_call.clj │ ├── stack-growing-test.clj │ ├── typeprotocol.clj │ ├── typeprotocol.cson │ └── typeprotocol2.clj └── src ├── bin └── main.rs ├── fetch.rs ├── lib.rs └── vm.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | 12 | /target/ 13 | **/*.rs.bk 14 | Cargo.lock 15 | 16 | .idea 17 | **/*.cson 18 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "clojit_vm" 3 | version = "0.0.1" 4 | authors = ["Niklaus Zbinden ", "Sebastian Wicki "] 5 | 6 | [workspace] 7 | 8 | [dependencies] 9 | 10 | serde_json = "1.0.8" 11 | serde = "1.0.26" 12 | serde_derive = "1.0.26" 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 clojit 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Clojit-VM 2 | ====================== 3 | 4 | ## What 5 | 6 | Clojure Virtual Maschine written in Rust 7 | 8 | ## Why 9 | 10 | Explore how to write a VM and JIT in Rust 11 | 12 | ## How 13 | 14 | 15 | chmod +x clojitvm 16 | ./clojitvm resources/programs/let_test.clj 17 | 18 | 19 | This first runs the Clojure->Clojit Bytecode comipler (written in Clojure). 20 | 21 | Then runs 'cargo run' to pass in the Bytecode file to VM. -------------------------------------------------------------------------------- /clojit-0.1.0-SNAPSHOT-standalone.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojit/clojit-vm/6027a0c0eeb971051053e91bb09161fb9a5b128d/clojit-0.1.0-SNAPSHOT-standalone.jar -------------------------------------------------------------------------------- /clojitvm: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | 4 | x=$1 5 | y=${x%.clj} 6 | z=.cson 7 | 8 | file=$y$z 9 | 10 | if [ ! -f "$file" ]; then 11 | java -jar clojit-0.1.0-SNAPSHOT-standalone.jar $1 12 | fi 13 | 14 | cargo run $y$z 15 | -------------------------------------------------------------------------------- /resources/programs/builtin1.clj: -------------------------------------------------------------------------------- 1 | (println "test") 2 | -------------------------------------------------------------------------------- /resources/programs/builtin_int.clj: -------------------------------------------------------------------------------- 1 | (println 1) 2 | -------------------------------------------------------------------------------- /resources/programs/builtin_int.cson: -------------------------------------------------------------------------------- 1 | {"CSTR":["println"],"CFLOAT":[],"CKEY":[],"CINT":[],"types":[],"vtable":{},"bytecode":[{"op":"NSGET","a":1,"d":0},{"op":"CSHORT","a":2,"d":1},{"op":"CALL","a":0,"d":2},{"op":"EXIT","a":0,"d":null}]} -------------------------------------------------------------------------------- /resources/programs/closure_test.clj: -------------------------------------------------------------------------------- 1 | (do (defn testfn [a] 2 | (fn [b] 3 | (+ a b))) 4 | (println ((testfn 10) 5))) 5 | -------------------------------------------------------------------------------- /resources/programs/complex_closure.clj: -------------------------------------------------------------------------------- 1 | (println (((fn [a] 2 | (fn [b] 3 | (let [fnc (fn [c] (+ c a)) 4 | fnd (fn [d] (+ d a)) 5 | fne (fn [e] (+ e a))] 6 | (fnc (fnd (fne (+ a b))))))) 5) 5)) 7 | 8 | ;; 25 9 | 10 | -------------------------------------------------------------------------------- /resources/programs/complex_closure2.clj: -------------------------------------------------------------------------------- 1 | (println ((((fn foo [a b] 2 | (let [x 9] 3 | (fn [c d] 4 | (fn [e f] 5 | (+ a b x))))) 6 | 1 2) 3 4) 5 6)) 7 | 8 | ;; 12 9 | -------------------------------------------------------------------------------- /resources/programs/complex_closure3.clj: -------------------------------------------------------------------------------- 1 | (println (((((fn [a] (fn [b] (fn [c] (fn [d] (+ a b c d))))) 1) 2) 3) 4)) 2 | -------------------------------------------------------------------------------- /resources/programs/function-ret-trunc.clj: -------------------------------------------------------------------------------- 1 | 2 | ;; 13 3 | 4 | ((fn [b] (- b 2)) ((fn [a] (+ a 5)) 10)) 5 | 6 | -------------------------------------------------------------------------------- /resources/programs/let_test.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (defprotocol REST 3 | (GET [self])) 4 | 5 | (deftype API [a] 6 | REST 7 | (GET [self] a)) 8 | 9 | (let [a "jdfkldafjölkdafjöakjfdaölkdfjaölfjda" 10 | b :random-key-test-key 11 | c 34398283492 12 | d 1921.3432] 13 | (GET (->API 5)))) 14 | 15 | 16 | -------------------------------------------------------------------------------- /resources/programs/let_test.cson: -------------------------------------------------------------------------------- 1 | {"CSTR":["a","->API","jdfkldafj\u00f6lkdafj\u00f6akjfda\u00f6lkdfja\u00f6lfjda"],"CFLOAT":[1921.3432],"CKEY":["random-key-test-key"],"CINT":[34398283492],"types":[{"type-id":0,"size":1}],"vtable":{"30":{"0":14}},"bytecode":[{"op":"FNEW","a":0,"d":17},{"op":"NSSET","a":0,"d":1},{"op":"CTYPE","a":0,"d":0},{"op":"CSTR","a":0,"d":2},{"op":"CKEY","a":1,"d":0},{"op":"CINT","a":2,"d":0},{"op":"CFLOAT","a":3,"d":0},{"op":"VFNEW","a":5,"d":30},{"op":"NSGET","a":7,"d":1},{"op":"CSHORT","a":8,"d":5},{"op":"CALL","a":6,"d":2},{"op":"CALL","a":4,"d":1},{"op":"MOV","a":0,"d":4},{"op":"EXIT","a":0,"d":null},{"op":"FUNCF","a":0,"d":null},{"op":"GETFIELD","a":3,"b":2,"c":0},{"op":"RET","a":3,"d":null},{"op":"FUNCF","a":1,"d":null},{"op":"CTYPE","a":3,"d":0},{"op":"ALLOC","a":3,"d":3},{"op":"MOV","a":4,"d":2},{"op":"SETFIELD","a":3,"b":0,"c":4},{"op":"RET","a":3,"d":null}]} -------------------------------------------------------------------------------- /resources/programs/multi_protocol_type.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (defprotocol REST 3 | (GET [self]) 4 | (POST [self a b]) 5 | (PUT [self a b c])) 6 | 7 | (defprotocol REST2 8 | (PATCH [self])) 9 | 10 | (deftype API [x] 11 | REST 12 | (GET [self] x) 13 | (POST [self a b] (+ a b)) 14 | (PUT [self a b c] (+ a b c)) 15 | REST2 16 | (PATCH [self] 101)) 17 | 18 | (deftype API2 [a b] 19 | REST2 20 | (PATCH [self] 101)) 21 | 22 | (println (+ 23 | (PATCH (->API2 5 5)) ;; 101 24 | (GET (->API 99)) ;; 99 25 | (PUT (->API 100) 10 20 20))) ;; 50 26 | 27 | ) 28 | 29 | ;;Result 250 30 | -------------------------------------------------------------------------------- /resources/programs/multi_protocol_type.cson: -------------------------------------------------------------------------------- 1 | {"CSTR":["x","->API","a","b","->API2","println"],"CFLOAT":[],"CKEY":[],"CINT":[],"types":[{"type-id":0,"size":1},{"type-id":1,"size":2}],"vtable":{"30":{"0":30},"31":{"0":33},"32":{"0":38},"34":{"0":45,"1":54}},"bytecode":[{"op":"FNEW","a":0,"d":48},{"op":"NSSET","a":0,"d":1},{"op":"CTYPE","a":0,"d":0},{"op":"FNEW","a":0,"d":57},{"op":"NSSET","a":0,"d":4},{"op":"CTYPE","a":0,"d":1},{"op":"NSGET","a":1,"d":5},{"op":"VFNEW","a":3,"d":34},{"op":"NSGET","a":5,"d":4},{"op":"CSHORT","a":6,"d":5},{"op":"CSHORT","a":7,"d":5},{"op":"CALL","a":4,"d":3},{"op":"CALL","a":2,"d":1},{"op":"VFNEW","a":4,"d":30},{"op":"NSGET","a":6,"d":1},{"op":"CSHORT","a":7,"d":99},{"op":"CALL","a":5,"d":2},{"op":"CALL","a":3,"d":1},{"op":"ADDVV","a":2,"b":2,"c":3},{"op":"VFNEW","a":4,"d":32},{"op":"NSGET","a":6,"d":1},{"op":"CSHORT","a":7,"d":100},{"op":"CALL","a":5,"d":2},{"op":"CSHORT","a":6,"d":10},{"op":"CSHORT","a":7,"d":20},{"op":"CSHORT","a":8,"d":20},{"op":"CALL","a":3,"d":4},{"op":"ADDVV","a":2,"b":2,"c":3},{"op":"CALL","a":0,"d":2},{"op":"EXIT","a":0,"d":null},{"op":"FUNCF","a":0,"d":null},{"op":"GETFIELD","a":3,"b":2,"c":0},{"op":"RET","a":3,"d":null},{"op":"FUNCF","a":2,"d":null},{"op":"MOV","a":5,"d":3},{"op":"MOV","a":6,"d":4},{"op":"ADDVV","a":5,"b":5,"c":6},{"op":"RET","a":5,"d":null},{"op":"FUNCF","a":3,"d":null},{"op":"MOV","a":6,"d":3},{"op":"MOV","a":7,"d":4},{"op":"ADDVV","a":6,"b":6,"c":7},{"op":"MOV","a":7,"d":5},{"op":"ADDVV","a":6,"b":6,"c":7},{"op":"RET","a":6,"d":null},{"op":"FUNCF","a":0,"d":null},{"op":"CSHORT","a":3,"d":101},{"op":"RET","a":3,"d":null},{"op":"FUNCF","a":1,"d":null},{"op":"CTYPE","a":3,"d":0},{"op":"ALLOC","a":3,"d":3},{"op":"MOV","a":4,"d":2},{"op":"SETFIELD","a":3,"b":0,"c":4},{"op":"RET","a":3,"d":null},{"op":"FUNCF","a":0,"d":null},{"op":"CSHORT","a":3,"d":101},{"op":"RET","a":3,"d":null},{"op":"FUNCF","a":2,"d":null},{"op":"CTYPE","a":4,"d":1},{"op":"ALLOC","a":4,"d":4},{"op":"MOV","a":5,"d":2},{"op":"SETFIELD","a":4,"b":0,"c":5},{"op":"MOV","a":6,"d":3},{"op":"SETFIELD","a":4,"b":1,"c":6},{"op":"RET","a":4,"d":null}]} -------------------------------------------------------------------------------- /resources/programs/multiarty_same_name.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (defprotocol IBar 3 | (total [self] [self a])) 4 | (deftype Bar [a] 5 | IBar 6 | (total [self] 5) 7 | (total [self a] (+ 9 a))) 8 | (println (total (->Bar 3)))) 9 | -------------------------------------------------------------------------------- /resources/programs/multiarty_same_name.cson: -------------------------------------------------------------------------------- 1 | {"CSTR":["a","->Bar","println"],"CFLOAT":[],"CKEY":[],"CINT":[],"types":[{"type-id":0,"size":1}],"vtable":{"30":{"0":14}},"bytecode":[{"op":"FNEW","a":0,"d":19},{"op":"NSSET","a":0,"d":1},{"op":"CTYPE","a":0,"d":0},{"op":"NSGET","a":1,"d":2},{"op":"VFNEW","a":3,"d":30},{"op":"NSGET","a":5,"d":1},{"op":"CSHORT","a":6,"d":3},{"op":"CALL","a":4,"d":2},{"op":"CALL","a":2,"d":1},{"op":"CALL","a":0,"d":2},{"op":"EXIT","a":0,"d":null},{"op":"FUNCF","a":0,"d":null},{"op":"CSHORT","a":3,"d":5},{"op":"RET","a":3,"d":null},{"op":"FUNCF","a":1,"d":null},{"op":"CSHORT","a":4,"d":9},{"op":"MOV","a":5,"d":3},{"op":"ADDVV","a":4,"b":4,"c":5},{"op":"RET","a":4,"d":null},{"op":"FUNCF","a":1,"d":null},{"op":"CTYPE","a":3,"d":0},{"op":"ALLOC","a":3,"d":3},{"op":"MOV","a":4,"d":2},{"op":"SETFIELD","a":3,"b":0,"c":4},{"op":"RET","a":3,"d":null}]} -------------------------------------------------------------------------------- /resources/programs/output_test.clj: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/programs/simple_float_test.clj: -------------------------------------------------------------------------------- 1 | (- 4.5 2.2) 2 | -------------------------------------------------------------------------------- /resources/programs/simple_fn_call.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (def a "abc") 3 | 4 | ((fn [a] 5 | (+ a 10)) 5)) 6 | -------------------------------------------------------------------------------- /resources/programs/simple_fn_call_2.clj: -------------------------------------------------------------------------------- 1 | ( 2 | (fn [c] (+ 8 c)) 3 | ((fn [a] 4 | (+ a 10)) 5 | 5)) 6 | -------------------------------------------------------------------------------- /resources/programs/simple_fn_call_2.cson: -------------------------------------------------------------------------------- 1 | {"CSTR":[],"CFLOAT":[],"CKEY":[],"CINT":[],"types":[],"vtable":{},"bytecode":[{"op":"FNEW","a":1,"d":11},{"op":"FNEW","a":3,"d":6},{"op":"CSHORT","a":4,"d":5},{"op":"CALL","a":2,"d":2},{"op":"CALL","a":0,"d":2},{"op":"EXIT","a":0,"d":null},{"op":"FUNCF","a":1,"d":null},{"op":"MOV","a":3,"d":2},{"op":"CSHORT","a":4,"d":10},{"op":"ADDVV","a":3,"b":3,"c":4},{"op":"RET","a":3,"d":null},{"op":"FUNCF","a":1,"d":null},{"op":"CSHORT","a":3,"d":8},{"op":"MOV","a":4,"d":2},{"op":"ADDVV","a":3,"b":3,"c":4},{"op":"RET","a":3,"d":null}]} -------------------------------------------------------------------------------- /resources/programs/simple_if_test.clj: -------------------------------------------------------------------------------- 1 | (if 2 1 0) 2 | -------------------------------------------------------------------------------- /resources/programs/simple_if_test.cson: -------------------------------------------------------------------------------- 1 | {"CSTR":[],"CFLOAT":[],"CKEY":[],"CINT":[],"types":[],"vtable":{},"bytecode":[{"op":"CSHORT","a":0,"d":2},{"op":"JUMPF","a":0,"d":3},{"op":"CSHORT","a":0,"d":1},{"op":"JUMP","a":null,"d":2},{"op":"CSHORT","a":0,"d":0},{"op":"EXIT","a":0,"d":null}]} -------------------------------------------------------------------------------- /resources/programs/simple_loop.clj: -------------------------------------------------------------------------------- 1 | (loop [x 0 y 1 z 2] 2 | (if (== x 10) 3 | x 4 | (recur (+ x 1) (+ 19 10 10 1 (+ y 1)) (+ y (+ z 1))))) 5 | 6 | ;; Result 10 7 | -------------------------------------------------------------------------------- /resources/programs/simple_ns_and_add.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (def global2 5) 3 | (def global 84) 4 | (+ global2 global)) 5 | -------------------------------------------------------------------------------- /resources/programs/simple_ns_and_add.cson: -------------------------------------------------------------------------------- 1 | {"CSTR":["global2","global"],"CFLOAT":[],"CKEY":[],"CINT":[],"types":[],"vtable":{},"bytecode":[{"op":"CSHORT","a":0,"d":5},{"op":"NSSET","a":0,"d":0},{"op":"CSHORT","a":0,"d":84},{"op":"NSSET","a":0,"d":1},{"op":"NSGET","a":0,"d":0},{"op":"NSGET","a":1,"d":1},{"op":"ADDVV","a":0,"b":0,"c":1},{"op":"EXIT","a":0,"d":null}]} -------------------------------------------------------------------------------- /resources/programs/simple_protocol_type.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (defprotocol REST 3 | (GET [self])) 4 | (deftype API [a] 5 | REST 6 | (GET [self] a)) 7 | (GET (->API 1001))) -------------------------------------------------------------------------------- /resources/programs/simple_protocol_type_prn.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (defprotocol REST 3 | (GET [self])) 4 | (deftype API [a] 5 | REST 6 | (GET [self] a)) 7 | (println (GET (->API 1001)))) -------------------------------------------------------------------------------- /resources/programs/simple_type.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (deftype TestT [a b c]) 3 | (. (->TestT 6) b)) -------------------------------------------------------------------------------- /resources/programs/simpler_fn_call.clj: -------------------------------------------------------------------------------- 1 | ((fn [c] (+ 8 c)) 5) 2 | -------------------------------------------------------------------------------- /resources/programs/stack-growing-test.clj: -------------------------------------------------------------------------------- 1 | (let [ z 1 2 | y (fn [] (let [a 1 3 | b 2 4 | c 3 5 | d 4 6 | e 5] 7 | ((fn [a b c d e] (+ a (+ b (+ c (+ d e))))) a b c d e)))] 8 | (y 81) 9 | ((fn [y] (+ y 1)) 47)) 10 | -------------------------------------------------------------------------------- /resources/programs/typeprotocol.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (defprotocol IBar 3 | (total [self] 4 | [self a])) 5 | (deftype Bar [a b c] 6 | IBar 7 | (total [self] 993) ; 12820 8 | (total [self a] (+ 993 a))) ; 12821 9 | 10 | (total (->Bar 1))) 11 | -------------------------------------------------------------------------------- /resources/programs/typeprotocol.cson: -------------------------------------------------------------------------------- 1 | {"CSTR":["a","b","c","->Bar"],"CFLOAT":[],"CKEY":[],"CINT":[],"types":[{"type-id":0,"size":3}],"vtable":{"30":{"0":12}},"bytecode":[{"op":"FNEW","a":0,"d":17},{"op":"NSSET","a":0,"d":3},{"op":"CTYPE","a":0,"d":0},{"op":"VFNEW","a":1,"d":30},{"op":"NSGET","a":3,"d":3},{"op":"CSHORT","a":4,"d":1},{"op":"CALL","a":2,"d":2},{"op":"CALL","a":0,"d":1},{"op":"EXIT","a":0,"d":null},{"op":"FUNCF","a":0,"d":null},{"op":"CSHORT","a":3,"d":993},{"op":"RET","a":3,"d":null},{"op":"FUNCF","a":1,"d":null},{"op":"CSHORT","a":4,"d":993},{"op":"MOV","a":5,"d":3},{"op":"ADDVV","a":4,"b":4,"c":5},{"op":"RET","a":4,"d":null},{"op":"FUNCF","a":3,"d":null},{"op":"CTYPE","a":5,"d":0},{"op":"ALLOC","a":5,"d":5},{"op":"MOV","a":6,"d":2},{"op":"SETFIELD","a":5,"b":0,"c":6},{"op":"MOV","a":7,"d":3},{"op":"SETFIELD","a":5,"b":1,"c":7},{"op":"MOV","a":8,"d":4},{"op":"SETFIELD","a":5,"b":2,"c":8},{"op":"RET","a":5,"d":null}]} -------------------------------------------------------------------------------- /resources/programs/typeprotocol2.clj: -------------------------------------------------------------------------------- 1 | (do 2 | (defprotocol IBar 3 | (total [self] 4 | [self b])) 5 | 6 | (defprotocol INoArg 7 | (stuff [self])) 8 | 9 | (deftype Bar [a] 10 | IBar 11 | (total [self] "Bar total 1 arg") ; 12820 12 | (total [self b] :Bar-total-2-arg) 13 | INoArg 14 | (stuff [self] 5556464)) 15 | 16 | (deftype Foo [c] 17 | IBar 18 | (total [self] "Foo total 1 arg") 19 | (total [self b] :Foo-total-2-arg) 20 | INoArg 21 | (stuff [self] 888.88)) 22 | 23 | (total (->Bar 1))) -------------------------------------------------------------------------------- /src/bin/main.rs: -------------------------------------------------------------------------------- 1 | extern crate clojit_vm; 2 | 3 | #[macro_use] 4 | extern crate serde_derive; 5 | 6 | extern crate serde; 7 | extern crate serde_json; 8 | 9 | use std::env; 10 | 11 | use std::fs::File; 12 | use std::io::prelude::*; 13 | 14 | use std::collections::BTreeMap; 15 | 16 | #[derive(Serialize, Deserialize, Debug)] 17 | struct CljType { 18 | #[serde(rename = "type-id")] 19 | typeid: u64, 20 | size: u64 21 | } 22 | 23 | #[derive(Serialize, Deserialize, Debug)] 24 | #[serde(untagged)] 25 | enum Inst { 26 | ABC { 27 | op : String, 28 | a : u8, 29 | b : u8, 30 | c : u8 31 | }, 32 | AD { 33 | op : String, 34 | a : u8, 35 | d : Option 36 | } 37 | } 38 | 39 | #[derive(Serialize, Deserialize, Debug)] 40 | struct CsonInput { 41 | #[serde(rename = "CFLOAT")] 42 | cfloat : Vec, 43 | #[serde(rename = "CINT")] 44 | cint: Vec, 45 | #[serde(rename = "CSTR")] 46 | cstr: Vec, 47 | #[serde(rename = "CKEY")] 48 | ckey: Vec, 49 | vtable: BTreeMap>, 50 | types: Vec, 51 | bytecode : Vec 52 | } 53 | 54 | fn main() { 55 | println!("Start clojit-vm"); 56 | 57 | let args: Vec = env::args().collect(); 58 | 59 | let filename = &args[1]; 60 | 61 | let mut f = File::open(filename).expect("file not found"); 62 | 63 | let mut contents = String::new(); 64 | f.read_to_string(&mut contents) 65 | .expect("something went wrong reading the file"); 66 | 67 | let parsed_cson: CsonInput = serde_json::from_str(&contents).unwrap(); 68 | 69 | 70 | println!("Parsed Bytecode: "); 71 | 72 | println!("{:?}", parsed_cson); 73 | 74 | println!("Result: "); 75 | 76 | 77 | 78 | } -------------------------------------------------------------------------------- /src/fetch.rs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojit/clojit-vm/6027a0c0eeb971051053e91bb09161fb9a5b128d/src/fetch.rs -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | pub mod vm; 4 | pub mod fetch; 5 | -------------------------------------------------------------------------------- /src/vm.rs: -------------------------------------------------------------------------------- 1 | 2 | 3 | #[derive(Debug, Clone, PartialEq, Eq)] 4 | pub enum OpCode { 5 | CSTR, CKEY, CINT, CSHORT, CFLOAT, CBOOL, CNIL,CTYPE, 6 | NSSETS, NSGETS, 7 | ADDVV, SUBVV, MULVV, DIVVV, MODVV, POWVV, 8 | ISLT, ISGE, ISLE, ISGT, ISEQ, ISNEQ, 9 | MOV, NOT, NEG, 10 | JUMP, JUMPF, JUMPT, 11 | CALL, RET, 12 | APPLY, 13 | FNEW, VFNEW, 14 | DROP, TRANC, UCLO, 15 | GETFREEVAR, 16 | LOOP, BULKMOV, 17 | NEWARRAY, GETARRAY, SETARRAY, 18 | ALLOC, SETFIELD, GETFIELD, 19 | FUNCF, FUNCV, 20 | EXIT 21 | } 22 | 23 | pub enum InstrType { 24 | TyABC, 25 | TyAD 26 | } 27 | 28 | pub type Keyword = String; 29 | --------------------------------------------------------------------------------