fix some issues in sasm, add more sasm example code
This commit is contained in:
parent
de7044cda5
commit
22a2efe211
2 changed files with 31 additions and 1 deletions
|
@ -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()))),
|
||||||
|
|
29
test.sasm
29
test.sasm
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue