From e55fee86cb81cb609205815258d1b2ed40927d47 Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Wed, 26 Jan 2022 12:33:27 +0700 Subject: [PATCH] fix: updated makefile to be in parent dir --- Makefile | 11 +++++++++++ blspc/example/if.bbb | 32 +++++++++++++++++++------------- blvm/src/main.rs | 3 +++ blvm/src/parser.rs | 18 +++++++++++++++++- 4 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..18aba22 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +all: build-blspc build-blvm + +build-blspc: + cd ./blspc; cargo build + rm ~/bin/blspc -f + mv ./target/debug/blspc ~/bin/blspc + +build-blvm: + cd ./blvm; cargo build + rm ~/bin/blvm -f + mv ./target/debug/blvm ~/bin/blvm diff --git a/blspc/example/if.bbb b/blspc/example/if.bbb index 1c3b8c5..af8719a 100644 --- a/blspc/example/if.bbb +++ b/blspc/example/if.bbb @@ -1,13 +1,19 @@ -1: STORE r1 $true -2: JUMP_IF_FALSE r1 9 -3: STORE r2 $34 -4: STORE r3 $35 -5: IADD r2 r3 r4 -6: STORE r5 $1 -7: CALL r5 r4 -8: JUMP 12 -9: STORE r6 $"False" -10: STORE r7 $1 -11: CALL r7 r6 -12: STORE r8 $0 -13: RETURN r8 +; ------------------------------ +; (if true (print (+ 34 35)) (print "False")) +; ------- Condition block ------ +1: STORE r1 $true ; r1 = True +2: JUMP_IF_FALSE r1 9 ; if +; --------- True block --------- +3: STORE r2 $34 ; r2 = 34 +4: STORE r3 $35 ; r3 = 35 +5: IADD r2 r3 r4 ; r2 + r3 -> r4 +6: STORE r5 $1 ; r5 = 1 (function calling) +7: CALL r5 r4 ; call 1 (print) 34 (r4) +8: JUMP 12 +; -------- False block --------- +9: STORE r6 $"False" ; r6 = "False" +10: STORE r7 $1 ; r7 = 1 (function calling) +11: CALL r7 r6 ; call 1 (print) "False" (r6) +12: STORE r8 $0 ; r8 = 0 (return value) +13: RETURN r8 ; return 0 (exit code) +; ------------ End ------------- \ No newline at end of file diff --git a/blvm/src/main.rs b/blvm/src/main.rs index b309ec7..52bd6d0 100644 --- a/blvm/src/main.rs +++ b/blvm/src/main.rs @@ -5,10 +5,13 @@ mod args; use args::Args; mod parser; +use parser::tokenize; fn main() { let args = Args::from_args(); let src = read_to_string(&args.file).unwrap(); let _file_name = Path::new(&args.file).file_stem().unwrap().to_str().unwrap(); + + let tokens = tokenize(&src); } diff --git a/blvm/src/parser.rs b/blvm/src/parser.rs index cdea64d..739e827 100644 --- a/blvm/src/parser.rs +++ b/blvm/src/parser.rs @@ -1 +1,17 @@ -use middle::*; \ No newline at end of file +use middle::*; + +pub fn tokenize(src: &str) -> Vec { + let mut result = Vec::new(); + + for line in src.lines() { + //