include new files
This commit is contained in:
12
sample/nothing.pl.xml
Normal file
12
sample/nothing.pl.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<program name="nothing">
|
||||||
|
<main>
|
||||||
|
<real>
|
||||||
|
<integer value="5"/>
|
||||||
|
</real>
|
||||||
|
<return>
|
||||||
|
<integer>
|
||||||
|
<real value="3.0"/>
|
||||||
|
</integer>
|
||||||
|
</return>
|
||||||
|
</main>
|
||||||
|
</program>
|
||||||
21
src/compiler/context.rs
Normal file
21
src/compiler/context.rs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
pub struct Context {
|
||||||
|
variables: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Context {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Context {
|
||||||
|
variables: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn variable_offset(&mut self, var: &String) -> usize {
|
||||||
|
self.variables
|
||||||
|
.iter()
|
||||||
|
.position(|p| p == var)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
self.variables.push(var.clone());
|
||||||
|
self.variables.len() - 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/compiler/value_type.rs
Normal file
8
src/compiler/value_type.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
pub enum ValueType {
|
||||||
|
Integer,
|
||||||
|
Real,
|
||||||
|
String,
|
||||||
|
Array,
|
||||||
|
Function,
|
||||||
|
None
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user