Track spans for the variable_manager::Error enum
This commit is contained in:
@@ -97,12 +97,7 @@ impl From<Error> for lsp_types::Diagnostic {
|
|||||||
severity: Some(DiagnosticSeverity::ERROR),
|
severity: Some(DiagnosticSeverity::ERROR),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
ScopeError(e) => Diagnostic {
|
ScopeError(e) => e.into(),
|
||||||
message: e.to_string(),
|
|
||||||
range: Range::default(),
|
|
||||||
severity: Some(DiagnosticSeverity::ERROR),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
DuplicateIdentifier(_, span)
|
DuplicateIdentifier(_, span)
|
||||||
| UnknownIdentifier(_, span)
|
| UnknownIdentifier(_, span)
|
||||||
| InvalidDevice(_, span)
|
| InvalidDevice(_, span)
|
||||||
@@ -284,7 +279,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
Expression::DeviceDeclaration(expr_dev) => {
|
Expression::DeviceDeclaration(expr_dev) => {
|
||||||
self.expression_device(expr_dev.node, expr_dev.span)?;
|
self.expression_device(expr_dev.node)?;
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
Expression::Declaration(var_name, decl_expr) => {
|
Expression::Declaration(var_name, decl_expr) => {
|
||||||
@@ -304,7 +299,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
// Invocation returns result in r15 (RETURN_REGISTER).
|
// Invocation returns result in r15 (RETURN_REGISTER).
|
||||||
// If used as an expression, we must move it to a temp to avoid overwrite.
|
// If used as an expression, we must move it to a temp to avoid overwrite.
|
||||||
let temp_name = self.next_temp_name();
|
let temp_name = self.next_temp_name();
|
||||||
let temp_loc = scope.add_variable(&temp_name, LocationRequest::Temp)?;
|
let temp_loc = scope.add_variable(&temp_name, LocationRequest::Temp, None)?;
|
||||||
self.emit_variable_assignment(
|
self.emit_variable_assignment(
|
||||||
&temp_name,
|
&temp_name,
|
||||||
&temp_loc,
|
&temp_loc,
|
||||||
@@ -326,7 +321,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
Expression::Literal(spanned_lit) => match spanned_lit.node {
|
Expression::Literal(spanned_lit) => match spanned_lit.node {
|
||||||
Literal::Number(num) => {
|
Literal::Number(num) => {
|
||||||
let temp_name = self.next_temp_name();
|
let temp_name = self.next_temp_name();
|
||||||
let loc = scope.add_variable(&temp_name, LocationRequest::Temp)?;
|
let loc = scope.add_variable(&temp_name, LocationRequest::Temp, None)?;
|
||||||
self.emit_variable_assignment(&temp_name, &loc, num.to_string())?;
|
self.emit_variable_assignment(&temp_name, &loc, num.to_string())?;
|
||||||
Ok(Some(CompilationResult {
|
Ok(Some(CompilationResult {
|
||||||
location: loc,
|
location: loc,
|
||||||
@@ -336,7 +331,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
Literal::Boolean(b) => {
|
Literal::Boolean(b) => {
|
||||||
let val = if b { "1" } else { "0" };
|
let val = if b { "1" } else { "0" };
|
||||||
let temp_name = self.next_temp_name();
|
let temp_name = self.next_temp_name();
|
||||||
let loc = scope.add_variable(&temp_name, LocationRequest::Temp)?;
|
let loc = scope.add_variable(&temp_name, LocationRequest::Temp, None)?;
|
||||||
self.emit_variable_assignment(&temp_name, &loc, val)?;
|
self.emit_variable_assignment(&temp_name, &loc, val)?;
|
||||||
Ok(Some(CompilationResult {
|
Ok(Some(CompilationResult {
|
||||||
location: loc,
|
location: loc,
|
||||||
@@ -346,7 +341,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
_ => Ok(None), // String literals don't return values in this context typically
|
_ => Ok(None), // String literals don't return values in this context typically
|
||||||
},
|
},
|
||||||
Expression::Variable(name) => {
|
Expression::Variable(name) => {
|
||||||
match scope.get_location_of(&name.node) {
|
match scope.get_location_of(&name.node, Some(name.span)) {
|
||||||
Ok(loc) => Ok(Some(CompilationResult {
|
Ok(loc) => Ok(Some(CompilationResult {
|
||||||
location: loc,
|
location: loc,
|
||||||
temp_name: None, // User variable, do not free
|
temp_name: None, // User variable, do not free
|
||||||
@@ -378,7 +373,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
// 2. Allocate a temp register for the result
|
// 2. Allocate a temp register for the result
|
||||||
let result_name = self.next_temp_name();
|
let result_name = self.next_temp_name();
|
||||||
let loc = scope.add_variable(&result_name, LocationRequest::Temp)?;
|
let loc = scope.add_variable(&result_name, LocationRequest::Temp, None)?;
|
||||||
let reg = self.resolve_register(&loc)?;
|
let reg = self.resolve_register(&loc)?;
|
||||||
|
|
||||||
// 3. Emit load instruction: l rX device member
|
// 3. Emit load instruction: l rX device member
|
||||||
@@ -386,7 +381,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
// 4. Cleanup
|
// 4. Cleanup
|
||||||
if let Some(c) = cleanup {
|
if let Some(c) = cleanup {
|
||||||
scope.free_temp(c)?;
|
scope.free_temp(c, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(CompilationResult {
|
Ok(Some(CompilationResult {
|
||||||
@@ -410,13 +405,13 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
// Compile negation as 0 - inner
|
// Compile negation as 0 - inner
|
||||||
let (inner_str, cleanup) = self.compile_operand(*inner_expr, scope)?;
|
let (inner_str, cleanup) = self.compile_operand(*inner_expr, scope)?;
|
||||||
let result_name = self.next_temp_name();
|
let result_name = self.next_temp_name();
|
||||||
let result_loc = scope.add_variable(&result_name, LocationRequest::Temp)?;
|
let result_loc = scope.add_variable(&result_name, LocationRequest::Temp, None)?;
|
||||||
let result_reg = self.resolve_register(&result_loc)?;
|
let result_reg = self.resolve_register(&result_loc)?;
|
||||||
|
|
||||||
self.write_output(format!("sub {result_reg} 0 {inner_str}"))?;
|
self.write_output(format!("sub {result_reg} 0 {inner_str}"))?;
|
||||||
|
|
||||||
if let Some(name) = cleanup {
|
if let Some(name) = cleanup {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(CompilationResult {
|
Ok(Some(CompilationResult {
|
||||||
@@ -506,7 +501,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
&& let Expression::Literal(spanned_lit) = &box_expr.node
|
&& let Expression::Literal(spanned_lit) = &box_expr.node
|
||||||
&& let Literal::Number(neg_num) = &spanned_lit.node
|
&& let Literal::Number(neg_num) = &spanned_lit.node
|
||||||
{
|
{
|
||||||
let loc = scope.add_variable(&name_str, LocationRequest::Persist)?;
|
let loc = scope.add_variable(&name_str, LocationRequest::Persist, Some(name_span))?;
|
||||||
self.emit_variable_assignment(&name_str, &loc, format!("-{neg_num}"))?;
|
self.emit_variable_assignment(&name_str, &loc, format!("-{neg_num}"))?;
|
||||||
return Ok(Some(CompilationResult {
|
return Ok(Some(CompilationResult {
|
||||||
location: loc,
|
location: loc,
|
||||||
@@ -517,16 +512,22 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
let (loc, temp_name) = match expr.node {
|
let (loc, temp_name) = match expr.node {
|
||||||
Expression::Literal(spanned_lit) => match spanned_lit.node {
|
Expression::Literal(spanned_lit) => match spanned_lit.node {
|
||||||
Literal::Number(num) => {
|
Literal::Number(num) => {
|
||||||
let var_location =
|
let var_location = scope.add_variable(
|
||||||
scope.add_variable(name_str.clone(), LocationRequest::Persist)?;
|
name_str.clone(),
|
||||||
|
LocationRequest::Persist,
|
||||||
|
Some(name_span),
|
||||||
|
)?;
|
||||||
|
|
||||||
self.emit_variable_assignment(&name_str, &var_location, num)?;
|
self.emit_variable_assignment(&name_str, &var_location, num)?;
|
||||||
(var_location, None)
|
(var_location, None)
|
||||||
}
|
}
|
||||||
Literal::Boolean(b) => {
|
Literal::Boolean(b) => {
|
||||||
let val = if b { "1" } else { "0" };
|
let val = if b { "1" } else { "0" };
|
||||||
let var_location =
|
let var_location = scope.add_variable(
|
||||||
scope.add_variable(name_str.clone(), LocationRequest::Persist)?;
|
name_str.clone(),
|
||||||
|
LocationRequest::Persist,
|
||||||
|
Some(name_span),
|
||||||
|
)?;
|
||||||
|
|
||||||
self.emit_variable_assignment(&name_str, &var_location, val)?;
|
self.emit_variable_assignment(&name_str, &var_location, val)?;
|
||||||
(var_location, None)
|
(var_location, None)
|
||||||
@@ -536,7 +537,8 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
Expression::Invocation(invoke_expr) => {
|
Expression::Invocation(invoke_expr) => {
|
||||||
self.expression_function_invocation(invoke_expr, scope)?;
|
self.expression_function_invocation(invoke_expr, scope)?;
|
||||||
|
|
||||||
let loc = scope.add_variable(&name_str, LocationRequest::Persist)?;
|
let loc =
|
||||||
|
scope.add_variable(&name_str, LocationRequest::Persist, Some(name_span))?;
|
||||||
self.emit_variable_assignment(
|
self.emit_variable_assignment(
|
||||||
&name_str,
|
&name_str,
|
||||||
&loc,
|
&loc,
|
||||||
@@ -565,7 +567,8 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
let loc = scope.add_variable(&name_str, LocationRequest::Persist)?;
|
let loc =
|
||||||
|
scope.add_variable(&name_str, LocationRequest::Persist, Some(name_span))?;
|
||||||
self.emit_variable_assignment(
|
self.emit_variable_assignment(
|
||||||
&name_str,
|
&name_str,
|
||||||
&loc,
|
&loc,
|
||||||
@@ -577,7 +580,8 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
// Support assigning binary expressions to variables directly
|
// Support assigning binary expressions to variables directly
|
||||||
Expression::Binary(bin_expr) => {
|
Expression::Binary(bin_expr) => {
|
||||||
let result = self.expression_binary(bin_expr, scope)?;
|
let result = self.expression_binary(bin_expr, scope)?;
|
||||||
let var_loc = scope.add_variable(&name_str, LocationRequest::Persist)?;
|
let var_loc =
|
||||||
|
scope.add_variable(&name_str, LocationRequest::Persist, Some(name_span))?;
|
||||||
|
|
||||||
if let CompilationResult {
|
if let CompilationResult {
|
||||||
location: VariableLocation::Constant(Literal::Number(num)),
|
location: VariableLocation::Constant(Literal::Number(num)),
|
||||||
@@ -593,14 +597,15 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
// Free the temp result
|
// Free the temp result
|
||||||
if let Some(name) = result.temp_name {
|
if let Some(name) = result.temp_name {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
(var_loc, None)
|
(var_loc, None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::Logical(log_expr) => {
|
Expression::Logical(log_expr) => {
|
||||||
let result = self.expression_logical(log_expr, scope)?;
|
let result = self.expression_logical(log_expr, scope)?;
|
||||||
let var_loc = scope.add_variable(&name_str, LocationRequest::Persist)?;
|
let var_loc =
|
||||||
|
scope.add_variable(&name_str, LocationRequest::Persist, Some(name_span))?;
|
||||||
|
|
||||||
// Move result from temp to new persistent variable
|
// Move result from temp to new persistent variable
|
||||||
let result_reg = self.resolve_register(&result.location)?;
|
let result_reg = self.resolve_register(&result.location)?;
|
||||||
@@ -608,12 +613,12 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
// Free the temp result
|
// Free the temp result
|
||||||
if let Some(name) = result.temp_name {
|
if let Some(name) = result.temp_name {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
(var_loc, None)
|
(var_loc, None)
|
||||||
}
|
}
|
||||||
Expression::Variable(name) => {
|
Expression::Variable(name) => {
|
||||||
let src_loc_res = scope.get_location_of(&name.node);
|
let src_loc_res = scope.get_location_of(&name.node, Some(name.span));
|
||||||
|
|
||||||
let src_loc = match src_loc_res {
|
let src_loc = match src_loc_res {
|
||||||
Ok(l) => l,
|
Ok(l) => l,
|
||||||
@@ -624,7 +629,8 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let var_loc = scope.add_variable(&name_str, LocationRequest::Persist)?;
|
let var_loc =
|
||||||
|
scope.add_variable(&name_str, LocationRequest::Persist, Some(name_span))?;
|
||||||
|
|
||||||
// Handle loading from stack if necessary
|
// Handle loading from stack if necessary
|
||||||
let src_str = match src_loc {
|
let src_str = match src_loc {
|
||||||
@@ -675,13 +681,14 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
let var_loc = scope.add_variable(&name_str, LocationRequest::Persist)?;
|
let var_loc =
|
||||||
|
scope.add_variable(&name_str, LocationRequest::Persist, Some(name_span))?;
|
||||||
let result_reg = self.resolve_register(&comp_res.location)?;
|
let result_reg = self.resolve_register(&comp_res.location)?;
|
||||||
|
|
||||||
self.emit_variable_assignment(&name_str, &var_loc, result_reg)?;
|
self.emit_variable_assignment(&name_str, &var_loc, result_reg)?;
|
||||||
|
|
||||||
if let Some(temp) = comp_res.temp_name {
|
if let Some(temp) = comp_res.temp_name {
|
||||||
scope.free_temp(temp)?;
|
scope.free_temp(temp, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
(var_loc, None)
|
(var_loc, None)
|
||||||
@@ -730,7 +737,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(CompilationResult {
|
Ok(CompilationResult {
|
||||||
location: scope.define_const(const_name.node, value)?,
|
location: scope.define_const(const_name.node, value, Some(const_name.span))?,
|
||||||
temp_name: None,
|
temp_name: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -747,7 +754,8 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
match assignee.node {
|
match assignee.node {
|
||||||
Expression::Variable(identifier) => {
|
Expression::Variable(identifier) => {
|
||||||
let location = match scope.get_location_of(&identifier.node) {
|
let location = match scope.get_location_of(&identifier.node, Some(identifier.span))
|
||||||
|
{
|
||||||
Ok(l) => l,
|
Ok(l) => l,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.errors.push(Error::UnknownIdentifier(
|
self.errors.push(Error::UnknownIdentifier(
|
||||||
@@ -791,7 +799,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(name) = cleanup {
|
if let Some(name) = cleanup {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::MemberAccess(access) => {
|
Expression::MemberAccess(access) => {
|
||||||
@@ -804,10 +812,10 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
self.write_output(format!("s {} {} {}", device_str, member.node, val_str))?;
|
self.write_output(format!("s {} {} {}", device_str, member.node, val_str))?;
|
||||||
|
|
||||||
if let Some(c) = dev_cleanup {
|
if let Some(c) = dev_cleanup {
|
||||||
scope.free_temp(c)?;
|
scope.free_temp(c, None)?;
|
||||||
}
|
}
|
||||||
if let Some(c) = val_cleanup {
|
if let Some(c) = val_cleanup {
|
||||||
scope.free_temp(c)?;
|
scope.free_temp(c, None)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@@ -855,7 +863,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
// backup all used registers to the stack
|
// backup all used registers to the stack
|
||||||
let active_registers = stack.registers().cloned().collect::<Vec<_>>();
|
let active_registers = stack.registers().cloned().collect::<Vec<_>>();
|
||||||
for register in &active_registers {
|
for register in &active_registers {
|
||||||
stack.add_variable(format!("temp_{register}"), LocationRequest::Stack)?;
|
stack.add_variable(format!("temp_{register}"), LocationRequest::Stack, None)?;
|
||||||
self.write_output(format!("push r{register}"))?;
|
self.write_output(format!("push r{register}"))?;
|
||||||
}
|
}
|
||||||
for arg in arguments {
|
for arg in arguments {
|
||||||
@@ -872,14 +880,15 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
Expression::Variable(var_name) => {
|
Expression::Variable(var_name) => {
|
||||||
let loc = match stack.get_location_of(var_name.node.clone()) {
|
let loc =
|
||||||
Ok(l) => l,
|
match stack.get_location_of(var_name.node.clone(), Some(var_name.span)) {
|
||||||
Err(_) => {
|
Ok(l) => l,
|
||||||
self.errors
|
Err(_) => {
|
||||||
.push(Error::UnknownIdentifier(var_name.node, var_name.span));
|
self.errors
|
||||||
VariableLocation::Temporary(0)
|
.push(Error::UnknownIdentifier(var_name.node, var_name.span));
|
||||||
}
|
VariableLocation::Temporary(0)
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
match loc {
|
match loc {
|
||||||
VariableLocation::Persistant(reg) | VariableLocation::Temporary(reg) => {
|
VariableLocation::Persistant(reg) | VariableLocation::Temporary(reg) => {
|
||||||
@@ -916,7 +925,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
let reg_str = self.resolve_register(&result.location)?;
|
let reg_str = self.resolve_register(&result.location)?;
|
||||||
self.write_output(format!("push {reg_str}"))?;
|
self.write_output(format!("push {reg_str}"))?;
|
||||||
if let Some(name) = result.temp_name {
|
if let Some(name) = result.temp_name {
|
||||||
stack.free_temp(name)?;
|
stack.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::Logical(log_expr) => {
|
Expression::Logical(log_expr) => {
|
||||||
@@ -925,7 +934,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
let reg_str = self.resolve_register(&result.location)?;
|
let reg_str = self.resolve_register(&result.location)?;
|
||||||
self.write_output(format!("push {reg_str}"))?;
|
self.write_output(format!("push {reg_str}"))?;
|
||||||
if let Some(name) = result.temp_name {
|
if let Some(name) = result.temp_name {
|
||||||
stack.free_temp(name)?;
|
stack.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::MemberAccess(access) => {
|
Expression::MemberAccess(access) => {
|
||||||
@@ -947,7 +956,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
let reg_str = self.resolve_register(&result.location)?;
|
let reg_str = self.resolve_register(&result.location)?;
|
||||||
self.write_output(format!("push {reg_str}"))?;
|
self.write_output(format!("push {reg_str}"))?;
|
||||||
if let Some(name) = result.temp_name {
|
if let Some(name) = result.temp_name {
|
||||||
stack.free_temp(name)?;
|
stack.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.write_output("push 0")?; // Should fail ideally
|
self.write_output("push 0")?; // Should fail ideally
|
||||||
@@ -970,7 +979,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
for register in active_registers {
|
for register in active_registers {
|
||||||
let VariableLocation::Stack(stack_offset) = stack
|
let VariableLocation::Stack(stack_offset) = stack
|
||||||
.get_location_of(format!("temp_{register}"))
|
.get_location_of(format!("temp_{register}"), None)
|
||||||
.map_err(Error::ScopeError)?
|
.map_err(Error::ScopeError)?
|
||||||
else {
|
else {
|
||||||
// This shouldn't happen if we just added it
|
// This shouldn't happen if we just added it
|
||||||
@@ -996,14 +1005,12 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expression_device(
|
fn expression_device(&mut self, expr: DeviceDeclarationExpression) -> Result<(), Error> {
|
||||||
&mut self,
|
|
||||||
expr: DeviceDeclarationExpression,
|
|
||||||
span: Span,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
if self.devices.contains_key(&expr.name.node) {
|
if self.devices.contains_key(&expr.name.node) {
|
||||||
self.errors
|
self.errors.push(Error::DuplicateIdentifier(
|
||||||
.push(Error::DuplicateIdentifier(expr.name.node.clone(), span));
|
expr.name.node.clone(),
|
||||||
|
expr.name.span,
|
||||||
|
));
|
||||||
// We can overwrite or ignore. Let's ignore new declaration to avoid cascading errors?
|
// We can overwrite or ignore. Let's ignore new declaration to avoid cascading errors?
|
||||||
// Actually, for recovery, maybe we want to allow it so subsequent uses work?
|
// Actually, for recovery, maybe we want to allow it so subsequent uses work?
|
||||||
// But we already have it.
|
// But we already have it.
|
||||||
@@ -1033,7 +1040,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
self.write_output(format!("beq {cond_str} 0 {else_label}"))?;
|
self.write_output(format!("beq {cond_str} 0 {else_label}"))?;
|
||||||
|
|
||||||
if let Some(name) = cleanup {
|
if let Some(name) = cleanup {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile Body
|
// Compile Body
|
||||||
@@ -1108,7 +1115,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
self.write_output(format!("beq {cond_str} 0 {end_label}"))?;
|
self.write_output(format!("beq {cond_str} 0 {end_label}"))?;
|
||||||
|
|
||||||
if let Some(name) = cleanup {
|
if let Some(name) = cleanup {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile Body
|
// Compile Body
|
||||||
@@ -1221,7 +1228,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
VariableLocation::Stack(offset) => {
|
VariableLocation::Stack(offset) => {
|
||||||
// If it's on the stack, we must load it into a temp to use it as an operand
|
// If it's on the stack, we must load it into a temp to use it as an operand
|
||||||
let temp_name = self.next_temp_name();
|
let temp_name = self.next_temp_name();
|
||||||
let temp_loc = scope.add_variable(&temp_name, LocationRequest::Temp)?;
|
let temp_loc = scope.add_variable(&temp_name, LocationRequest::Temp, None)?;
|
||||||
let temp_reg = self.resolve_register(&temp_loc)?;
|
let temp_reg = self.resolve_register(&temp_loc)?;
|
||||||
|
|
||||||
self.write_output(format!(
|
self.write_output(format!(
|
||||||
@@ -1343,7 +1350,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
// Allocate result register
|
// Allocate result register
|
||||||
let result_name = self.next_temp_name();
|
let result_name = self.next_temp_name();
|
||||||
let result_loc = scope.add_variable(&result_name, LocationRequest::Temp)?;
|
let result_loc = scope.add_variable(&result_name, LocationRequest::Temp, None)?;
|
||||||
let result_reg = self.resolve_register(&result_loc)?;
|
let result_reg = self.resolve_register(&result_loc)?;
|
||||||
|
|
||||||
// Emit instruction: op result lhs rhs
|
// Emit instruction: op result lhs rhs
|
||||||
@@ -1351,10 +1358,10 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
// Clean up operand temps
|
// Clean up operand temps
|
||||||
if let Some(name) = lhs_cleanup {
|
if let Some(name) = lhs_cleanup {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
if let Some(name) = rhs_cleanup {
|
if let Some(name) = rhs_cleanup {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(CompilationResult {
|
Ok(CompilationResult {
|
||||||
@@ -1373,14 +1380,14 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
let (inner_str, cleanup) = self.compile_operand(*inner, scope)?;
|
let (inner_str, cleanup) = self.compile_operand(*inner, scope)?;
|
||||||
|
|
||||||
let result_name = self.next_temp_name();
|
let result_name = self.next_temp_name();
|
||||||
let result_loc = scope.add_variable(&result_name, LocationRequest::Temp)?;
|
let result_loc = scope.add_variable(&result_name, LocationRequest::Temp, None)?;
|
||||||
let result_reg = self.resolve_register(&result_loc)?;
|
let result_reg = self.resolve_register(&result_loc)?;
|
||||||
|
|
||||||
// seq rX rY 0 => if rY == 0 set rX = 1 else rX = 0
|
// seq rX rY 0 => if rY == 0 set rX = 1 else rX = 0
|
||||||
self.write_output(format!("seq {result_reg} {inner_str} 0"))?;
|
self.write_output(format!("seq {result_reg} {inner_str} 0"))?;
|
||||||
|
|
||||||
if let Some(name) = cleanup {
|
if let Some(name) = cleanup {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(CompilationResult {
|
Ok(CompilationResult {
|
||||||
@@ -1408,7 +1415,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
// Allocate result register
|
// Allocate result register
|
||||||
let result_name = self.next_temp_name();
|
let result_name = self.next_temp_name();
|
||||||
let result_loc = scope.add_variable(&result_name, LocationRequest::Temp)?;
|
let result_loc = scope.add_variable(&result_name, LocationRequest::Temp, None)?;
|
||||||
let result_reg = self.resolve_register(&result_loc)?;
|
let result_reg = self.resolve_register(&result_loc)?;
|
||||||
|
|
||||||
// Emit instruction: op result lhs rhs
|
// Emit instruction: op result lhs rhs
|
||||||
@@ -1416,10 +1423,10 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
|
|
||||||
// Clean up operand temps
|
// Clean up operand temps
|
||||||
if let Some(name) = lhs_cleanup {
|
if let Some(name) = lhs_cleanup {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
if let Some(name) = rhs_cleanup {
|
if let Some(name) = rhs_cleanup {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(CompilationResult {
|
Ok(CompilationResult {
|
||||||
@@ -1478,7 +1485,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
if let Some(comp_res) = result
|
if let Some(comp_res) = result
|
||||||
&& let Some(name) = comp_res.temp_name
|
&& let Some(name) = comp_res.temp_name
|
||||||
{
|
{
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}) {
|
}) {
|
||||||
@@ -1511,49 +1518,51 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match expr.node {
|
match expr.node {
|
||||||
Expression::Variable(var_name) => match scope.get_location_of(&var_name.node) {
|
Expression::Variable(var_name) => {
|
||||||
Ok(loc) => match loc {
|
match scope.get_location_of(&var_name.node, Some(var_name.span)) {
|
||||||
VariableLocation::Temporary(reg) | VariableLocation::Persistant(reg) => {
|
Ok(loc) => match loc {
|
||||||
self.write_output(format!(
|
VariableLocation::Temporary(reg) | VariableLocation::Persistant(reg) => {
|
||||||
"move r{} r{reg} {}",
|
self.write_output(format!(
|
||||||
VariableScope::RETURN_REGISTER,
|
"move r{} r{reg} {}",
|
||||||
debug!(self, "#returnValue")
|
VariableScope::RETURN_REGISTER,
|
||||||
))?;
|
debug!(self, "#returnValue")
|
||||||
}
|
))?;
|
||||||
VariableLocation::Constant(lit) => {
|
}
|
||||||
let str = extract_literal(lit, false)?;
|
VariableLocation::Constant(lit) => {
|
||||||
self.write_output(format!(
|
let str = extract_literal(lit, false)?;
|
||||||
"move r{} {str} {}",
|
self.write_output(format!(
|
||||||
VariableScope::RETURN_REGISTER,
|
"move r{} {str} {}",
|
||||||
debug!(self, "#returnValue")
|
VariableScope::RETURN_REGISTER,
|
||||||
))?
|
debug!(self, "#returnValue")
|
||||||
}
|
))?
|
||||||
VariableLocation::Stack(offset) => {
|
}
|
||||||
self.write_output(format!(
|
VariableLocation::Stack(offset) => {
|
||||||
"sub r{} sp {offset}",
|
self.write_output(format!(
|
||||||
VariableScope::TEMP_STACK_REGISTER
|
"sub r{} sp {offset}",
|
||||||
))?;
|
VariableScope::TEMP_STACK_REGISTER
|
||||||
self.write_output(format!(
|
))?;
|
||||||
"get r{} db r{}",
|
self.write_output(format!(
|
||||||
VariableScope::RETURN_REGISTER,
|
"get r{} db r{}",
|
||||||
VariableScope::TEMP_STACK_REGISTER
|
VariableScope::RETURN_REGISTER,
|
||||||
))?;
|
VariableScope::TEMP_STACK_REGISTER
|
||||||
}
|
))?;
|
||||||
VariableLocation::Device(_) => {
|
}
|
||||||
return Err(Error::Unknown(
|
VariableLocation::Device(_) => {
|
||||||
"You can not return a device from a function.".into(),
|
return Err(Error::Unknown(
|
||||||
Some(var_name.span),
|
"You can not return a device from a function.".into(),
|
||||||
|
Some(var_name.span),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
self.errors.push(Error::UnknownIdentifier(
|
||||||
|
var_name.node.clone(),
|
||||||
|
var_name.span,
|
||||||
));
|
));
|
||||||
|
// Proceed with dummy
|
||||||
}
|
}
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
self.errors.push(Error::UnknownIdentifier(
|
|
||||||
var_name.node.clone(),
|
|
||||||
var_name.span,
|
|
||||||
));
|
|
||||||
// Proceed with dummy
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Expression::Literal(spanned_lit) => match spanned_lit.node {
|
Expression::Literal(spanned_lit) => match spanned_lit.node {
|
||||||
Literal::Number(num) => {
|
Literal::Number(num) => {
|
||||||
self.emit_variable_assignment(
|
self.emit_variable_assignment(
|
||||||
@@ -1581,7 +1590,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
result_reg
|
result_reg
|
||||||
))?;
|
))?;
|
||||||
if let Some(name) = result.temp_name {
|
if let Some(name) = result.temp_name {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::Logical(log_expr) => {
|
Expression::Logical(log_expr) => {
|
||||||
@@ -1593,7 +1602,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
result_reg
|
result_reg
|
||||||
))?;
|
))?;
|
||||||
if let Some(name) = result.temp_name {
|
if let Some(name) = result.temp_name {
|
||||||
scope.free_temp(name)?;
|
scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::MemberAccess(access) => {
|
Expression::MemberAccess(access) => {
|
||||||
@@ -1609,7 +1618,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
let reg = self.resolve_register(&res.location)?;
|
let reg = self.resolve_register(&res.location)?;
|
||||||
self.write_output(format!("move r{} {}", VariableScope::RETURN_REGISTER, reg))?;
|
self.write_output(format!("move r{} {}", VariableScope::RETURN_REGISTER, reg))?;
|
||||||
if let Some(temp) = res.temp_name {
|
if let Some(temp) = res.temp_name {
|
||||||
scope.free_temp(temp)?;
|
scope.free_temp(temp, None)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1636,7 +1645,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
($($to_clean:expr),*) => {
|
($($to_clean:expr),*) => {
|
||||||
$(
|
$(
|
||||||
if let Some(to_clean) = $to_clean {
|
if let Some(to_clean) = $to_clean {
|
||||||
scope.free_temp(to_clean)?;
|
scope.free_temp(to_clean, None)?;
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
};
|
};
|
||||||
@@ -1926,7 +1935,11 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
.rev()
|
.rev()
|
||||||
.take(VariableScope::PERSIST_REGISTER_COUNT as usize)
|
.take(VariableScope::PERSIST_REGISTER_COUNT as usize)
|
||||||
{
|
{
|
||||||
let loc = block_scope.add_variable(var_name.node.clone(), LocationRequest::Persist)?;
|
let loc = block_scope.add_variable(
|
||||||
|
var_name.node.clone(),
|
||||||
|
LocationRequest::Persist,
|
||||||
|
Some(var_name.span),
|
||||||
|
)?;
|
||||||
// we don't need to imcrement the stack offset as it's already on the stack from the
|
// we don't need to imcrement the stack offset as it's already on the stack from the
|
||||||
// previous scope
|
// previous scope
|
||||||
|
|
||||||
@@ -1959,11 +1972,19 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
// anything as they already exist on the stack, but we DO need to let our block_scope be
|
// anything as they already exist on the stack, but we DO need to let our block_scope be
|
||||||
// aware that the variables exist on the stack (left to right)
|
// aware that the variables exist on the stack (left to right)
|
||||||
for var_name in arguments.iter().take(arguments.len() - saved_variables) {
|
for var_name in arguments.iter().take(arguments.len() - saved_variables) {
|
||||||
block_scope.add_variable(var_name.node.clone(), LocationRequest::Stack)?;
|
block_scope.add_variable(
|
||||||
|
var_name.node.clone(),
|
||||||
|
LocationRequest::Stack,
|
||||||
|
Some(var_name.span),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.write_output("push ra")?;
|
self.write_output("push ra")?;
|
||||||
block_scope.add_variable(format!("{}_ra", name.node), LocationRequest::Stack)?;
|
block_scope.add_variable(
|
||||||
|
format!("{}_ra", name.node),
|
||||||
|
LocationRequest::Stack,
|
||||||
|
Some(name.span),
|
||||||
|
)?;
|
||||||
|
|
||||||
for expr in body.0 {
|
for expr in body.0 {
|
||||||
match expr.node {
|
match expr.node {
|
||||||
@@ -1976,7 +1997,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
if let Some(comp_res) = result
|
if let Some(comp_res) = result
|
||||||
&& let Some(name) = comp_res.temp_name
|
&& let Some(name) = comp_res.temp_name
|
||||||
{
|
{
|
||||||
block_scope.free_temp(name)?;
|
block_scope.free_temp(name, None)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}) {
|
}) {
|
||||||
@@ -1987,7 +2008,8 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the saved return address and save it back into `ra`
|
// Get the saved return address and save it back into `ra`
|
||||||
let ra_res = block_scope.get_location_of(format!("{}_ra", name.node));
|
let ra_res = block_scope.get_location_of(format!("{}_ra", name.node), Some(name.span));
|
||||||
|
|
||||||
let ra_stack_offset = match ra_res {
|
let ra_stack_offset = match ra_res {
|
||||||
Ok(VariableLocation::Stack(offset)) => offset,
|
Ok(VariableLocation::Stack(offset)) => offset,
|
||||||
_ => {
|
_ => {
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
// r1 - r7 : Temporary Variables
|
// r1 - r7 : Temporary Variables
|
||||||
// r8 - r14 : Persistant Variables
|
// r8 - r14 : Persistant Variables
|
||||||
|
|
||||||
use parser::tree_node::Literal;
|
use lsp_types::{Diagnostic, DiagnosticSeverity};
|
||||||
|
use parser::tree_node::{Literal, Span};
|
||||||
use quick_error::quick_error;
|
use quick_error::quick_error;
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
|
|
||||||
@@ -13,18 +14,33 @@ const PERSIST: [u8; 7] = [8, 9, 10, 11, 12, 13, 14];
|
|||||||
quick_error! {
|
quick_error! {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
DuplicateVariable(var: String) {
|
DuplicateVariable(var: String, span: Option<Span>) {
|
||||||
display("{var} already exists.")
|
display("{var} already exists.")
|
||||||
}
|
}
|
||||||
UnknownVariable(var: String) {
|
UnknownVariable(var: String, span: Option<Span>) {
|
||||||
display("{var} does not exist.")
|
display("{var} does not exist.")
|
||||||
}
|
}
|
||||||
Unknown(reason: String) {
|
Unknown(reason: String, span: Option<Span>) {
|
||||||
display("{reason}")
|
display("{reason}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Error> for lsp_types::Diagnostic {
|
||||||
|
fn from(value: Error) -> Self {
|
||||||
|
match value {
|
||||||
|
Error::DuplicateVariable(_, span)
|
||||||
|
| Error::UnknownVariable(_, span)
|
||||||
|
| Error::Unknown(_, span) => Diagnostic {
|
||||||
|
range: span.map(lsp_types::Range::from).unwrap_or_default(),
|
||||||
|
severity: Some(DiagnosticSeverity::ERROR),
|
||||||
|
message: value.to_string(),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A request to store a variable at a specific register type
|
/// A request to store a variable at a specific register type
|
||||||
pub enum LocationRequest {
|
pub enum LocationRequest {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -112,10 +128,11 @@ impl<'a> VariableScope<'a> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
var_name: impl Into<String>,
|
var_name: impl Into<String>,
|
||||||
location: LocationRequest,
|
location: LocationRequest,
|
||||||
|
span: Option<Span>,
|
||||||
) -> Result<VariableLocation, Error> {
|
) -> Result<VariableLocation, Error> {
|
||||||
let var_name = var_name.into();
|
let var_name = var_name.into();
|
||||||
if self.var_lookup_table.contains_key(var_name.as_str()) {
|
if self.var_lookup_table.contains_key(var_name.as_str()) {
|
||||||
return Err(Error::DuplicateVariable(var_name));
|
return Err(Error::DuplicateVariable(var_name, span));
|
||||||
}
|
}
|
||||||
let var_location = match location {
|
let var_location = match location {
|
||||||
LocationRequest::Temp => {
|
LocationRequest::Temp => {
|
||||||
@@ -151,10 +168,11 @@ impl<'a> VariableScope<'a> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
var_name: impl Into<String>,
|
var_name: impl Into<String>,
|
||||||
value: Literal,
|
value: Literal,
|
||||||
|
span: Option<Span>,
|
||||||
) -> Result<VariableLocation, Error> {
|
) -> Result<VariableLocation, Error> {
|
||||||
let var_name = var_name.into();
|
let var_name = var_name.into();
|
||||||
if self.var_lookup_table.contains_key(&var_name) {
|
if self.var_lookup_table.contains_key(&var_name) {
|
||||||
return Err(Error::DuplicateVariable(var_name));
|
return Err(Error::DuplicateVariable(var_name, span));
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_value = VariableLocation::Constant(value);
|
let new_value = VariableLocation::Constant(value);
|
||||||
@@ -163,7 +181,11 @@ impl<'a> VariableScope<'a> {
|
|||||||
Ok(new_value)
|
Ok(new_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_location_of(&self, var_name: impl Into<String>) -> Result<VariableLocation, Error> {
|
pub fn get_location_of(
|
||||||
|
&self,
|
||||||
|
var_name: impl Into<String>,
|
||||||
|
span: Option<Span>,
|
||||||
|
) -> Result<VariableLocation, Error> {
|
||||||
let var_name = var_name.into();
|
let var_name = var_name.into();
|
||||||
|
|
||||||
// 1. Check this scope
|
// 1. Check this scope
|
||||||
@@ -180,7 +202,7 @@ impl<'a> VariableScope<'a> {
|
|||||||
|
|
||||||
// 2. Recursively check parent
|
// 2. Recursively check parent
|
||||||
if let Some(parent) = self.parent {
|
if let Some(parent) = self.parent {
|
||||||
let loc = parent.get_location_of(var_name)?;
|
let loc = parent.get_location_of(var_name, span)?;
|
||||||
|
|
||||||
if let VariableLocation::Stack(parent_offset) = loc {
|
if let VariableLocation::Stack(parent_offset) = loc {
|
||||||
return Ok(VariableLocation::Stack(parent_offset + self.stack_offset));
|
return Ok(VariableLocation::Stack(parent_offset + self.stack_offset));
|
||||||
@@ -188,7 +210,7 @@ impl<'a> VariableScope<'a> {
|
|||||||
return Ok(loc);
|
return Ok(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Error::UnknownVariable(var_name))
|
Err(Error::UnknownVariable(var_name, span))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_parent(&self) -> bool {
|
pub fn has_parent(&self) -> bool {
|
||||||
@@ -196,10 +218,14 @@ impl<'a> VariableScope<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn free_temp(&mut self, var_name: impl Into<String>) -> Result<(), Error> {
|
pub fn free_temp(
|
||||||
|
&mut self,
|
||||||
|
var_name: impl Into<String>,
|
||||||
|
span: Option<Span>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
let var_name = var_name.into();
|
let var_name = var_name.into();
|
||||||
let Some(location) = self.var_lookup_table.remove(var_name.as_str()) else {
|
let Some(location) = self.var_lookup_table.remove(var_name.as_str()) else {
|
||||||
return Err(Error::UnknownVariable(var_name));
|
return Err(Error::UnknownVariable(var_name, span));
|
||||||
};
|
};
|
||||||
|
|
||||||
match location {
|
match location {
|
||||||
@@ -207,9 +233,10 @@ impl<'a> VariableScope<'a> {
|
|||||||
self.temporary_vars.push_back(t);
|
self.temporary_vars.push_back(t);
|
||||||
}
|
}
|
||||||
VariableLocation::Persistant(_) => {
|
VariableLocation::Persistant(_) => {
|
||||||
return Err(Error::UnknownVariable(String::from(
|
return Err(Error::UnknownVariable(
|
||||||
"Attempted to free a `let` variable.",
|
String::from("Attempted to free a `let` variable."),
|
||||||
)));
|
span,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user