Add Bool builtin type, branches, and some more stuff

* obj::Bool builtin type is used for truthiness and decision-making
* Branches are compiled and seem to be working for basic integer
  comparison
* Updated version of Shredder to what is current as of writing
* CheckTruth VM instruction that will explicitly set the condition flag
* Probably some other stuff

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-11-06 16:57:25 -08:00
parent 692bb521ec
commit be9a659159
17 changed files with 435 additions and 78 deletions

View File

@@ -104,7 +104,7 @@ AccessExpr -> Result<Expr>:
;
FunExpr -> Result<Expr>:
AtomExpr { $1 }
IfExpr { $1 }
| 'fn' '(' FunParams ')' '{' Body '}' { Ok(FunExpr::new_expr($3?, $6?)) }
;
@@ -118,6 +118,31 @@ FunParamsTail -> Result<Vec<String>>:
| Ident { Ok(vec![$1?]) }
;
IfExpr -> Result<Expr>:
AtomExpr { $1 }
| 'if' Expr '{' Body '}' Elif El {
Ok(IfExpr::new_expr(
CondBody { cond: $2?, body: $4?, },
$6?,
$7?,
))
}
;
Elif -> Result<Vec<CondBody>>:
Elif 'elif' Expr '{' Body '}' {
let mut head = $1?;
head.push(CondBody { cond: $3?, body: $5? });
Ok(head)
}
| { Ok(Vec::new()) }
;
El -> Result<Option<Body>>:
'el' '{' Body '}' { $3.map(Some) }
| { Ok(None) }
;
AtomExpr -> Result<Expr>:
Atom { $1.map(Expr::Atom) }
| '(' Expr ')' { $2 }