refactor(tvix/compiler): use rnix's typed AST for literal values
Change-Id: Ic56ab64ad82343c7cdf8168ef41ee0a97f7e1dd9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6077 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
parent
18fe188c3e
commit
28f57abac1
1 changed files with 5 additions and 7 deletions
|
@ -22,8 +22,8 @@ impl Compiler {
|
||||||
// Literals contain a single token comprising of the
|
// Literals contain a single token comprising of the
|
||||||
// literal itself.
|
// literal itself.
|
||||||
rnix::SyntaxKind::NODE_LITERAL => {
|
rnix::SyntaxKind::NODE_LITERAL => {
|
||||||
let token = node.first_token().expect("TODO");
|
let value = rnix::types::Value::cast(node).unwrap();
|
||||||
self.compile_literal(token)
|
self.compile_literal(value.to_value().expect("TODO"))
|
||||||
}
|
}
|
||||||
|
|
||||||
rnix::SyntaxKind::NODE_BIN_OP => {
|
rnix::SyntaxKind::NODE_BIN_OP => {
|
||||||
|
@ -37,8 +37,8 @@ impl Compiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
rnix::SyntaxKind::NODE_PAREN => {
|
rnix::SyntaxKind::NODE_PAREN => {
|
||||||
let op = rnix::types::Paren::cast(node).unwrap();
|
let node = rnix::types::Paren::cast(node).unwrap();
|
||||||
self.compile(op.inner().unwrap())
|
self.compile(node.inner().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
kind => {
|
kind => {
|
||||||
|
@ -48,9 +48,7 @@ impl Compiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_literal(&mut self, token: rnix::SyntaxToken) -> EvalResult<()> {
|
fn compile_literal(&mut self, value: rnix::value::Value) -> EvalResult<()> {
|
||||||
let value = rnix::value::Value::from_token(token.kind(), token.text()).expect("TODO");
|
|
||||||
|
|
||||||
match value {
|
match value {
|
||||||
rnix::NixValue::Float(f) => {
|
rnix::NixValue::Float(f) => {
|
||||||
let idx = self.chunk.add_constant(Value::Float(f));
|
let idx = self.chunk.add_constant(Value::Float(f));
|
||||||
|
|
Loading…
Reference in a new issue