fix some issues in sasm, add more sasm example code

This commit is contained in:
Daniella 2023-04-08 20:19:37 +02:00
parent de7044cda5
commit 22a2efe211
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
2 changed files with 31 additions and 1 deletions

View file

@ -11,6 +11,7 @@ pub fn sasm_read(s: String) -> Words {
pub fn sasm_read_func<'a>(lines: &mut impl Iterator<Item = &'a str>) -> Words { pub fn sasm_read_func<'a>(lines: &mut impl Iterator<Item = &'a str>) -> Words {
let mut words = Vec::new(); let mut words = Vec::new();
while let Some(line) = lines.next() { while let Some(line) = lines.next() {
let line = line.trim_start();
if line == "end" { if line == "end" {
break; break;
} }
@ -20,7 +21,7 @@ pub fn sasm_read_func<'a>(lines: &mut impl Iterator<Item = &'a str>) -> Words {
} }
fn sasm_parse<'a>(line: &str, words: &mut Vec<Word>, lines: &mut impl Iterator<Item = &'a str>) { fn sasm_parse<'a>(line: &str, words: &mut Vec<Word>, lines: &mut impl Iterator<Item = &'a str>) {
let line: Vec<_> = line.trim_start().split(" ").collect(); let line: Vec<_> = line.split(" ").collect();
match line[0] { match line[0] {
"dump" => words.push(Word::Key(Keyword::Dump)), "dump" => words.push(Word::Key(Keyword::Dump)),
"def" => words.push(Word::Key(Keyword::Def(line[1].to_owned()))), "def" => words.push(Word::Key(Keyword::Def(line[1].to_owned()))),

View file

@ -4,5 +4,34 @@ func main 1
Hello, world! Hello, world!
end HW end HW
call println call println
call test
const mega 3 const mega 3
end end
func test 0
call [
const func 5
const mega 0
const mega 1
const mega 2
const mega 3
const mega 4
end
call call
call ]
objcall iter
objpush
const func 1
const mega 5
call *
end
objpop
objcall map
objpush
const func 0
call _str
call println
end
objpop
objcall foreach
end