Skip to content

Commit

Permalink
Light Touchups
Browse files Browse the repository at this point in the history
created the typetable lib.

did some touchups in other areas
  • Loading branch information
coffeebe4code committed Jul 3, 2024
1 parent bd0929b commit 72a285e
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ members = [
"linter",
"codelocation",
"types",
"cachectx"]
"cachectx", "typetable"]
resolver = "2"

1 change: 1 addition & 0 deletions cachectx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lexer = { path = "../lexer" }
parser = { path = "../parser" }
ast = { path = "../ast" }
symtable = { path = "../symtable" }
typetable = { path = "../typetable" }
types = { path = "../types" }
linter = { path = "../linter" }
ir = { path = "../ir" }
1 change: 1 addition & 0 deletions cachectx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use parser::*;
use std::{fs::File, io::Read, path::PathBuf, rc::Rc};
use symtable::*;
use types::*;
use typetable::*;

struct InternalContext {
source: PathBuf,
Expand Down
2 changes: 1 addition & 1 deletion e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
ast = { path = "../ast" }
linker = { path = "../linker" }
symtable = { path = "../symtable" }
typetable = { path = "../typetable" }
lexer = { path = "../lexer" }
token = { path = "../token" }
parser = { path = "../parser" }
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use linter::LintSource;
use parser::Parser;
use std::fs::File;
use std::io::Read;
use symtable::TypeTable;
use typetable::TypeTable;

use std::path::Path;
use std::process::Command;
Expand Down
1 change: 1 addition & 0 deletions ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
ast = { path="../ast" }
symtable = { path="../symtable" }
typetable = { path="../typetable" }
token = { path="../token" }
perror = { path="../perror" }
lexer = { path="../lexer" }
Expand Down
1 change: 1 addition & 0 deletions ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use perror::*;
use std::rc::Rc;
use symtable::*;
use types::*;
use typetable::*;

pub struct IRSource<'tt> {
package: u32,
Expand Down
2 changes: 1 addition & 1 deletion linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
ast = { path = "../ast" }
types = { path = "../types" }
symtable = { path = "../symtable" }
typetable = { path = "../typetable" }
parser = { path = "../parser" }
token = { path = "../token" }
lexer = { path = "../lexer" }
Expand Down
38 changes: 18 additions & 20 deletions linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use lexer::*;
use perror::LinterError;
use perror::LinterErrorPoint;
use std::rc::Rc;
use symtable::*;
use token::Token;
use types::*;
use typetable::*;

type ResultTreeType = Result<(Rc<Box<TypeTree>>, Ty), usize>;

Expand Down Expand Up @@ -115,7 +115,7 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = init.block_curried.clone();
let full = tree!(FuncInit, init);

self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));
Ok((full, curried))
}

Expand Down Expand Up @@ -193,7 +193,7 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let full = tree!(SymbolInit, sym);
self.ttbl
.table
.insert(symbol.val.slice.clone(), (Rc::clone(&full), 0));
.insert(symbol.val.slice.clone(), Rc::clone(&full));
return Ok((full, curried));
}

Expand All @@ -205,7 +205,6 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
.table
.get(&symbol.val.slice)
.unwrap()
.0
.get_curried()
.clone(),
};
Expand Down Expand Up @@ -246,7 +245,7 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = err_info.curried.clone();
let full = tree!(ErrorInfo, err_info);

self.ttbl.table.insert(slice.clone(), (Rc::clone(&full), 0));
self.ttbl.table.insert(slice.clone(), Rc::clone(&full));
return Ok((full, curried));
}

Expand Down Expand Up @@ -343,7 +342,7 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = obj_info.curried.clone();
let full = tree!(StructInfo, obj_info);

self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));
return Ok((full, curried));
}
Err(self.set_error(
Expand All @@ -364,7 +363,7 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = init.curried.clone();
let full = tree!(PropInit, init);

self.ttbl.table.insert(slice.clone(), (Rc::clone(&full), 0));
self.ttbl.table.insert(slice.clone(), Rc::clone(&full));
return Ok((full, curried));
}

Expand Down Expand Up @@ -394,10 +393,9 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = struct_init.curried.clone();
let full = tree!(StructInit, struct_init);

self.ttbl.table.insert(
prev.0.into_symbol_access().ident.clone(),
(Rc::clone(&full), 0),
);
self.ttbl
.table
.insert(prev.0.into_symbol_access().ident.clone(), Rc::clone(&full));
return Ok((full, curried));
}
Err(self.set_error(
Expand Down Expand Up @@ -434,7 +432,7 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = tag_info.curried.clone();
let full = tree!(TagInfo, tag_info);

self.ttbl.table.insert(copy, (Rc::clone(&full), 0));
self.ttbl.table.insert(copy, Rc::clone(&full));
return Ok((full, curried));
}

Expand Down Expand Up @@ -467,7 +465,7 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = init.block_curried.clone();
let full = tree!(FuncInit, init);

self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));
Ok((full, curried))
}

Expand All @@ -483,11 +481,11 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = init.curried.clone();
if import.mutability.token == Token::Const {
let full: Rc<Box<TypeTree>> = tree!(ConstInit, init);
self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));
return Ok((full, Ty::Const(Box::new(curried))));
}
let full: Rc<Box<TypeTree>> = tree!(MutInit, init);
self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));
return Ok((full, Ty::Mut(Box::new(curried))));
}

Expand All @@ -504,12 +502,12 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
if inner.mutability.token == Token::Const {
init.curried = Ty::Const(Box::new(init.curried));
let full: Rc<Box<TypeTree>> = tree!(ConstInit, init);
self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));
return Ok((full, Ty::Const(Box::new(curried))));
}
init.curried = Ty::Mut(Box::new(init.curried));
let full: Rc<Box<TypeTree>> = tree!(MutInit, init);
self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));
return Ok((full, Ty::Mut(Box::new(curried))));
}

Expand All @@ -525,11 +523,11 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = init.curried.clone();
if td.mutability.token == Token::Const {
let full: Rc<Box<TypeTree>> = tree!(ConstInit, init);
self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));
return Ok((full, Ty::Const(Box::new(curried))));
}
let full: Rc<Box<TypeTree>> = tree!(MutInit, init);
self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));
return Ok((full, Ty::Mut(Box::new(curried))));
}

Expand Down Expand Up @@ -617,7 +615,7 @@ impl<'buf, 'sym> LintSource<'buf, 'sym> {
let curried = a.curried.clone();
self.curr_self = Some(a.curried.clone());
let full: Rc<Box<TypeTree>> = tree!(ArgInit, a);
self.ttbl.table.insert(slice, (Rc::clone(&full), 0));
self.ttbl.table.insert(slice, Rc::clone(&full));

return Ok((full, curried));
}
Expand Down
1 change: 1 addition & 0 deletions objmaker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
ast = { path = "../ast" }
symtable = { path = "../symtable" }
typetable = { path = "../typetable" }
lexer = { path = "../lexer" }
linter = { path = "../linter" }
token = { path = "../token" }
Expand Down
5 changes: 4 additions & 1 deletion objmaker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::io::Read;
use std::path::Path;
use std::path::PathBuf;
use symtable::SymTable;
use symtable::TypeTable;
use typetable::TypeTable;

pub fn from_buffer(contents: &str, path: &Path) -> () {
let lex = TLexer::new(&contents);
Expand All @@ -23,6 +23,9 @@ pub fn from_buffer(contents: &str, path: &Path) -> () {
let lint_res = linter.lint_check(&ast_parsed);
let mut ir = IRSource::new(0, SymTable::new(), linter.ttbl);
if linter.issues.len() > 0 {
for x in linter.issues {
println!("{}", x);
}
panic!("linter issues exist");
}
let rc_thing = lint_res.first().unwrap().to_owned();
Expand Down
1 change: 0 additions & 1 deletion symtable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
types = { path = "../types" }
15 changes: 0 additions & 15 deletions symtable/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
use std::collections::BTreeMap;
use std::rc::Rc;
use types::*;

//todo:: this is for when we are using the TypeTree
pub struct TypeTable {
pub table: BTreeMap<String, (Rc<Box<TypeTree>>, u32)>,
}

impl TypeTable {
pub fn new() -> Self {
TypeTable {
table: BTreeMap::new(),
}
}
}

pub struct SymTable {
pub table: BTreeMap<String, u32>,
Expand Down
8 changes: 2 additions & 6 deletions todos.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
- readup on all conversations in zulip chat to refamiliarlize myself
- figure out data layout and how modules build in cranelift
- look up linters and how to do so
- mark down linter todos as far as what is not allowed: ie valid syntax, but incorrect context
- type work in Lexers + IR for signatures
- formalize SLT and IRSource job and how that works.
- data layout
- scopes
7 changes: 7 additions & 0 deletions typetable/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "typetable"
version = "0.1.0"
edition = "2021"

[dependencies]
types = { path = "../types" }
15 changes: 15 additions & 0 deletions typetable/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::collections::BTreeMap;
use std::rc::Rc;
use types::*;

pub struct TypeTable {
pub table: BTreeMap<String, Rc<Box<TypeTree>>>,
}

impl TypeTable {
pub fn new() -> Self {
TypeTable {
table: BTreeMap::new(),
}
}
}

0 comments on commit 72a285e

Please sign in to comment.