Skip to content

Commit

Permalink
vine: traits (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi authored Feb 12, 2025
1 parent efea658 commit ae82004
Show file tree
Hide file tree
Showing 193 changed files with 14,180 additions and 12,382 deletions.
17 changes: 14 additions & 3 deletions cli/src/vine_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use ivm::{heap::Heap, IVM};
use ivy::{ast::Nets, host::Host};
use rustyline::DefaultEditor;
use vine::{
compiler::Compiler,
core::{Core, CoreArenas},
repl::Repl,
};
Expand Down Expand Up @@ -50,8 +51,6 @@ pub struct CompileArgs {
main: Option<PathBuf>,
#[arg(long = "lib")]
libs: Vec<PathBuf>,
#[arg(long = "item")]
items: Vec<String>,
#[arg(long)]
no_std: bool,
}
Expand All @@ -61,7 +60,19 @@ impl CompileArgs {
if !self.no_std {
self.libs.push(std_path())
}
match vine::compile(vine::Config { main: self.main, libs: self.libs, items: self.items }) {

let arenas = CoreArenas::default();
let core = &Core::new(&arenas);
let mut compiler = Compiler::new(core);

if let Some(main) = self.main {
compiler.loader.load_main_mod(main);
}
for lib in self.libs {
compiler.loader.load_mod(lib);
}

match compiler.compile(()) {
Ok(nets) => nets,
Err(err) => {
eprintln!("{}", err);
Expand Down
4 changes: 4 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"indexmap",
"interner",
"interstage",
"impls",
"miri",
"nilary",
"nohash",
Expand All @@ -34,15 +35,18 @@
"primality",
"readback",
"readline",
"rels",
"repr",
"rotr",
"rustyline",
"sequentializing",
"scrutinee",
"sixel",
"specializer",
"strs",
"structs",
"subexpressions",
"subimpls",
"subpatterns",
"unpark",
"vecs",
Expand Down
15 changes: 7 additions & 8 deletions lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use futures::{stream::FuturesUnordered, StreamExt};
use tower_lsp::{jsonrpc::Result, lsp_types::*, Client, LanguageServer, LspService, Server};

use vine::{
checker::Checker,
chart::Chart,
charter::Charter,
checker::{ChartTypes, Checker},
core::{Core, CoreArenas},
diag::Diag,
loader::Loader,
Expand Down Expand Up @@ -36,13 +38,10 @@ impl Backend {

let root = loader.finish();

let mut resolver = Resolver::new(core);
resolver.build_graph(root);
resolver.resolve_imports();
resolver.resolve_defs();

let mut checker = Checker::new(core, &mut resolver);
checker.check_defs();
let chart = &mut Chart::default();
Charter { core, chart }.chart_root(root);
Resolver { core, chart }.resolve_all();
Checker::new(core, chart, &mut ChartTypes::default()).check_all();

self.report(core, core.take_diags())
}
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_04.vi
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ pub fn main(&io: &IO) {
struct Channel[M](M, ~M);

mod Channel {
pub fn send[M](Channel[M](got, ~out), value: M) -> M {
pub fn .send[M](Channel[M](got, ~out), value: M) -> M {
out = value;
got
}

pub fn get[M](&Channel[M](i, _)) -> M {
pub fn .get[M](&Channel[M](i, _)) -> M {
i
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/programs/aoc_2024/day_08.vi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

use std::{data::Map::{Map, Cmp, Ord}, tuple::Pair};
use std::data::Map;

pub fn main(&io: &IO) {
let input = io.full_input();

let antennas = Map::new[_, List[(N32, N32)]](Char::cmp);
let antinodes1 = Map::new(Pair::cmp(N32::cmp, N32::cmp));
let antinodes2 = Map::new(Pair::cmp(N32::cmp, N32::cmp));
let antennas = Map::empty[Char, List[(N32, N32)]];
let antinodes1 = Map::empty[(N32, N32), _];
let antinodes2 = Map::empty[(N32, N32), _];

let grid = input.split_trim("\n");

Expand Down
2 changes: 1 addition & 1 deletion tests/programs/aoc_2024/day_09.vi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

use std::{numeric::N64, tuple::Pair};
use std::numeric::N64;

pub fn main(&io: &IO) {
let input = io.read_line().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/aoc_2024/day_10.vi
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn count(s: Set) -> N32 {
struct Channel[M](M, ~M);

mod Channel {
pub fn send[M](Channel[M](got, ~out), value: M) -> M {
pub fn .send[M](Channel[M](got, ~out), value: M) -> M {
out = value;
got
}
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_11.vi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const max: N32 = 75;
pub fn main(&io: &IO) {
let input = io.read_line().unwrap();

let stones = Map::new(N64::cmp);
let stones = Map::empty[N64, _];
let input = input.split(" ");
while input.pop_front() is Some(stone) {
let stone = N64::from_n32(N32::parse(stone).unwrap());
Expand All @@ -22,7 +22,7 @@ pub fn main(&io: &IO) {
}

fn blink(&io: &IO, old: Map[N64, N64]) -> Map[N64, N64] {
let new = Map::new(N64::cmp);
let new = Map::empty[N64, _];
let iter = old.into_iter();
dyn fn add_stones(number: N64, count: N64) {
let &c = new.get_or_insert(number, N64::zero);
Expand Down
25 changes: 15 additions & 10 deletions tests/programs/aoc_2024/day_12.vi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

use std::data::Array;
use std::unicode::ToString;

pub fn main(&io: &IO) {
let regions = Regions(Array::empty);
Expand Down Expand Up @@ -87,26 +88,30 @@ enum Region {
}

mod Region {
pub fn to_string(self: Region) -> String {
match self {
Region::Root(a, p) { "Root(" ++ a.to_string() ++ ", " ++ p.to_string() ++ ")" }
Region::Child(n) { "Child(" ++ n.to_string() ++ ")" }
pub impl to_string: ToString[Region] {
fn to_string(self: Region) -> String {
match self {
Region::Root(a, p) { "Root(" ++ a.to_string() ++ ", " ++ p.to_string() ++ ")" }
Region::Child(n) { "Child(" ++ n.to_string() ++ ")" }
}
}
}
}

mod Regions {
pub fn to_string(Regions(array)) -> String {
array.to_list().to_string(Region::to_string)
pub impl to_string: ToString[Regions] {
fn to_string(Regions(array)) -> String {
array.to_list().to_string()
}
}

pub fn new(&Regions(array)) -> N32 {
pub fn .new(&Regions(array)) -> N32 {
let i = array.len();
array.push_back(Region::Root(1, 0));
i
}

pub fn find(&Regions(array), i: N32) -> N32 {
pub fn .find(&Regions(array), i: N32) -> N32 {
let ~root;
while array.get(i) is &Region::Child(p) {
i = p;
Expand All @@ -116,15 +121,15 @@ mod Regions {
i
}

pub fn get_area(&self: &Regions, i: N32) -> N32 {
pub fn .get_area(&self: &Regions, i: N32) -> N32 {
let i = self.find(i);
let &Regions(array) = &self;
match *array.get(i) {
Region::Root(a, _) { a }
}
}

pub fn union_found(&Regions(array), i: N32, j: N32) -> N32 {
pub fn .union_found(&Regions(array), i: N32, j: N32) -> N32 {
if i == j {
match array.get(i) {
&Region::Root(_, p) {
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/aoc_2024/day_15.vi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

use std::{data::Array, tuple::Pair};
use std::data::Array;

pub fn main(&io: &IO) {
let grid = Array::empty;
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/aoc_2024/day_16.vi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn main(&io: &IO) {
}
let grid = Array::from_list(grid);

let pq = Map::new(N32::cmp);
let pq = Map::empty[N32, _];
pq.insert(0, [(start, 0)]);

dyn fn try_insert(dist: N32, pos: (N32, N32), dir) {
Expand Down
2 changes: 1 addition & 1 deletion tests/programs/aoc_2024/day_17.vi
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ pub fn main(&io: &IO) {
ip += 2;
}

io.println("Part 1: " ++ output.map(N32::to_string).join(","));
io.println("Part 1: " ++ output.map(fn(x: N32) { x.to_string() }).join(","));
}
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_18.vi
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ mod DisjointSet {
DisjointSet(Array::new(len, Node::Root(1)))
}

pub fn find(&DisjointSet(array), i: N32) -> N32 {
pub fn .find(&DisjointSet(array), i: N32) -> N32 {
let ~root;
while array.get(i) is &Node::Child(parent) {
i = parent;
Expand All @@ -117,7 +117,7 @@ mod DisjointSet {
i
}

pub fn union(&self: &DisjointSet, a: N32, b: N32) -> N32 {
pub fn .union(&self: &DisjointSet, a: N32, b: N32) -> N32 {
let a = self.find(a);
let b = self.find(b);
if a == b {
Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_22.vi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

use std::{data::Map, numeric::N64, tuple::Pair};
use std::{data::Map, numeric::N64};

pub fn main(&io: &IO) {
let map = Map::new(N32::cmp);
let map = Map::empty[N32, _];

let part1 = N64::zero;

Expand Down
4 changes: 2 additions & 2 deletions tests/programs/aoc_2024/day_23.vi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::data::Map;

pub fn main(&io: &IO) {
let graph = Map::new(N32::cmp);
let graph = Map::empty[N32, Map[N32, _]];

while io.read_line() is Some(line) {
let String({ chars }) = line;
Expand All @@ -12,7 +12,7 @@ pub fn main(&io: &IO) {
if a > b {
(b, a) = (a, b)
}
(*graph.get_or_insert(a, Map::new(N32::cmp))).insert(b, ());
(*graph.get_or_insert(a, Map::empty)).insert(b, ());
}

do {
Expand Down
8 changes: 4 additions & 4 deletions tests/programs/aoc_2024/day_24.vi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{data::{Array, Map}, numeric::N64};

pub fn main(&io: &IO) {
let map = Map::new(String::cmp);
let map = Map::empty[String, _];

while io.read_line() is Some(line) && line.len() != 0 {
let (name, value) = line.split_once(": ");
Expand Down Expand Up @@ -61,15 +61,15 @@ mod Wire {
Wire(move ~x, x)
}

pub fn input(value: Bool) -> Wire {
pub fn .input(value: Bool) -> Wire {
Wire(~_, value)
}

pub fn get(&Wire(_, value)) -> Bool {
pub fn .get(&Wire(_, value)) -> Bool {
value
}

pub fn set(&Wire(~out, _), value: Bool) {
pub fn .set(&Wire(~out, _), value: Bool) {
out = value;
}
}
2 changes: 1 addition & 1 deletion tests/programs/cyclist.vi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn main(&io: &IO) {

while list.pop_front() is Some(val) {
cycle(&list, val);
io.println(val.to_string() ++ ";\t" ++ list.to_string(N32::to_string));
io.println(val.to_string() ++ ";\t" ++ list.to_string());
}
}

Expand Down
Loading

0 comments on commit ae82004

Please sign in to comment.