Skip to content

Commit

Permalink
Var enum (#27)
Browse files Browse the repository at this point in the history
* fix passing vecnew

* add bug tests

* comp test

* rename

* sep files

* refactor

* impl all types

* fix

* fix

* fix

* fix

* fix

* fix

* fix func
  • Loading branch information
jarkonik authored Nov 9, 2021
1 parent 631f110 commit bdec4ee
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 195 deletions.
3 changes: 1 addition & 2 deletions examples/mandelbrot.rc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ while y < HEIGHT {
isstable = 1

while i < 50 {
mulres = complexmul(acc, acc)
acc = complexadd(mulres, c)
acc = complexadd(complexmul(acc, acc), c)
if sqrt(vecget(acc, 0) * vecget(acc, 0) + vecget(acc, 1) * vecget(acc, 1)) > 2 {
isstable = 0
}
Expand Down
30 changes: 30 additions & 0 deletions src/compiler/frame.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::compiler::var::Var;
use crate::llvm;
use std::collections::HashMap;

pub struct Frame {
env: HashMap<String, Var>,
pub fun: llvm::Value,
}

impl Frame {
pub fn new(fun: llvm::Value) -> Self {
Frame {
env: HashMap::new(),
fun,
}
}

pub fn get(&self, literal: &str) -> Option<&Var> {
self.env.get(literal)
}

pub fn set(&mut self, literal: &str, val: Var) {
self.env.insert(literal.to_string(), val);
}

#[allow(dead_code)]
pub fn remove(&mut self, literal: &str) {
self.env.remove(&literal.to_string());
}
}
Loading

0 comments on commit bdec4ee

Please sign in to comment.