Working variables
This commit is contained in:
+10
-2
@@ -38,6 +38,10 @@ impl Scope {
|
|||||||
Scope::Local(l) => l.parent.next_var_idx(),
|
Scope::Local(l) => l.parent.next_var_idx(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_name(&self, export: bool) -> String {
|
||||||
|
format!("{}{}", if export { 'V' } else { 'v' }, self.next_var_idx())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -89,11 +93,15 @@ impl LocalScope {
|
|||||||
if let Some(init) = init {
|
if let Some(init) = init {
|
||||||
let var_type = self.get_type_from_expr(init).unwrap();
|
let var_type = self.get_type_from_expr(init).unwrap();
|
||||||
|
|
||||||
|
let var_name = name.clone();
|
||||||
|
|
||||||
|
*name = self.parent.get_name(false);
|
||||||
|
|
||||||
self.variables.lock().unwrap().insert(
|
self.variables.lock().unwrap().insert(
|
||||||
name.clone(),
|
var_name,
|
||||||
Arc::new(VarRef {
|
Arc::new(VarRef {
|
||||||
export: false,
|
export: false,
|
||||||
name: name.to_string(),
|
name: name.clone(),
|
||||||
var_type,
|
var_type,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
+2
-5
@@ -3,9 +3,6 @@ package main;
|
|||||||
import "fmt";
|
import "fmt";
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test(67);
|
let a = 0;
|
||||||
}
|
let b = a + 10;
|
||||||
|
|
||||||
void test(int x) {
|
|
||||||
fmt.println("Hello" + x);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user