mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-14 17:35:03 +01:00
more function things
This commit is contained in:
parent
e15967e24c
commit
ff6b4703ab
11 changed files with 77 additions and 55 deletions
40
Cargo.lock
generated
40
Cargo.lock
generated
|
|
@ -10,19 +10,19 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
|||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.8.0"
|
||||
version = "3.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c"
|
||||
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.14.1"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45"
|
||||
checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31"
|
||||
dependencies = [
|
||||
"encode_unicode",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"terminal_size",
|
||||
"winapi",
|
||||
]
|
||||
|
|
@ -72,9 +72,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
|||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.7.0"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
|
||||
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
|
|
@ -82,9 +82,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "insta"
|
||||
version = "1.9.0"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86c4e56d571b4cc829f0ce71506bd865a90369eeab5f3d3657ba96230beb8012"
|
||||
checksum = "b3cb858fc306825b542b1311d5fd536e4483680528f303a17a1d6803b0f6ce17"
|
||||
dependencies = [
|
||||
"console",
|
||||
"lazy_static",
|
||||
|
|
@ -119,6 +119,12 @@ version = "0.5.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.36"
|
||||
|
|
@ -151,18 +157,18 @@ checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.132"
|
||||
version = "1.0.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008"
|
||||
checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.132"
|
||||
version = "1.0.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276"
|
||||
checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -171,9 +177,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.73"
|
||||
version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5"
|
||||
checksum = "c059c05b48c5c0067d4b4b2b4f0732dd65feb52daf7e0ea09cd87e7dadc1af79"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
|
@ -200,9 +206,9 @@ checksum = "2e24979f63a11545f5f2c60141afe249d4f19f84581ea2138065e400941d83d3"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.84"
|
||||
version = "1.0.85"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b"
|
||||
checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
bumpalo = { version = "3.8.0", features = ["collections"] }
|
||||
debug2 = { version = "0.1.0", optional = true }
|
||||
rustc-hash = { version = "1.1.0", optional = true }
|
||||
|
||||
debug2 = { version = "0.1.0", optional = true }
|
||||
|
||||
|
||||
[features]
|
||||
fxhash = ["rustc-hash"]
|
||||
pretty = ["debug2"]
|
||||
_debug = ["debug2"]
|
||||
|
||||
# todo: we don't actually want this as a default feature
|
||||
default = ["pretty"]
|
||||
default = ["_debug"]
|
||||
|
||||
[dev-dependencies]
|
||||
insta = "1.9.0"
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ pub struct Ident {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Program<'ast>(pub Vec<'ast, Stmt<'ast>>);
|
||||
pub type Program<'ast> = Block<'ast>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Block<'ast> {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ pub struct FnBlock<'bc> {
|
|||
pub arity: u8,
|
||||
}
|
||||
|
||||
#[cfg(feature = "pretty")]
|
||||
#[cfg(feature = "_debug")]
|
||||
impl debug2::Debug for FnBlock<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("FnBlock")
|
||||
|
|
@ -94,7 +94,7 @@ pub type Function = usize;
|
|||
|
||||
/// A bytecode instruction. For more details on the structure of the bytecode, read the module level docs [`bytecode`](`self`)
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[cfg_attr(feature = "pretty", derive(debug2::Debug))]
|
||||
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
|
||||
pub enum Instr {
|
||||
/// An operation that does nothing.
|
||||
Nop,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use crate::vm::Value;
|
|||
use crate::{HashMap, RtAlloc};
|
||||
use bumpalo::collections::Vec;
|
||||
use bumpalo::Bump;
|
||||
use std::borrow::BorrowMut;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
|
@ -95,13 +94,17 @@ impl<'bc, 'gc> Compiler<'bc, 'gc> {
|
|||
self.blocks.push(global_block);
|
||||
self.current_block = self.blocks.len() - 1;
|
||||
|
||||
// padding for backwards jumps
|
||||
self.push_instr(Instr::Nop, StackChange::None, Span::dummy());
|
||||
|
||||
self.compile_stmts(&ast.0)?;
|
||||
self.compile_fn(ast)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compile_fn(&mut self, block: &Block) -> CResult {
|
||||
// padding for backwards jumps
|
||||
self.push_instr(Instr::Nop, StackChange::None, block.span);
|
||||
|
||||
self.compile_stmts(&block.stmts)
|
||||
}
|
||||
|
||||
fn compile_stmts(&mut self, stmts: &[Stmt]) -> CResult {
|
||||
for stmt in stmts {
|
||||
match stmt {
|
||||
|
|
@ -168,8 +171,27 @@ impl<'bc, 'gc> Compiler<'bc, 'gc> {
|
|||
})?,
|
||||
};
|
||||
|
||||
let new_block_idx = self.blocks.len();
|
||||
self.blocks.push(block);
|
||||
self.current_block = self.blocks.len() - 1;
|
||||
let old_block = self.current_block;
|
||||
self.current_block = new_block_idx;
|
||||
|
||||
self.compile_fn(&decl.body)?;
|
||||
|
||||
self.current_block = old_block;
|
||||
|
||||
self.push_instr(
|
||||
Instr::PushVal(Value::Function(new_block_idx)),
|
||||
StackChange::Grow,
|
||||
decl.span,
|
||||
);
|
||||
|
||||
let stack_pos = self.current_stack_top();
|
||||
|
||||
self.env
|
||||
.borrow_mut()
|
||||
.locals
|
||||
.insert(decl.name.sym, stack_pos);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub use span::Span;
|
|||
mod span {
|
||||
|
||||
#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
|
||||
#[cfg_attr(feature = "pretty", derive(debug2::Debug))]
|
||||
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
|
||||
pub struct Span {
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
|
|
|
|||
12
src/gc.rs
12
src/gc.rs
|
|
@ -30,14 +30,14 @@ impl<T: ?Sized> Deref for Gc<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pretty")]
|
||||
#[cfg(feature = "_debug")]
|
||||
impl<T: debug2::Debug> debug2::Debug for Gc<T> {
|
||||
fn fmt(&self, f: &mut debug2::Formatter<'_>) -> std::fmt::Result {
|
||||
T::fmt(&*self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pretty")]
|
||||
#[cfg(feature = "_debug")]
|
||||
impl debug2::Debug for Gc<str> {
|
||||
fn fmt(&self, f: &mut debug2::Formatter<'_>) -> std::fmt::Result {
|
||||
let str = self.deref();
|
||||
|
|
@ -61,7 +61,7 @@ impl<T: ?Sized> Copy for Gc<T> {}
|
|||
|
||||
/// An reference to an interned String. Hashing and Equality are O(1) and just look at the pointer address
|
||||
#[derive(Clone, Copy)]
|
||||
#[cfg_attr(feature = "pretty", derive(debug2::Debug))]
|
||||
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
|
||||
pub struct Symbol {
|
||||
gc: Gc<str>,
|
||||
}
|
||||
|
|
@ -74,20 +74,20 @@ type ObjectMap = HashMap<Symbol, Value>;
|
|||
/// ```
|
||||
/// This is inside the local x now.
|
||||
#[derive(Clone, Copy)]
|
||||
#[cfg_attr(feature = "pretty", derive(debug2::Debug))]
|
||||
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
|
||||
pub struct Object {
|
||||
gc: Gc<HeapObject>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
#[cfg_attr(feature = "pretty", derive(debug2::Debug))]
|
||||
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
|
||||
struct HeapObject {
|
||||
kind: HeapObjectKind,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "pretty", derive(debug2::Debug))]
|
||||
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
|
||||
enum HeapObjectKind {
|
||||
String(Gc<str>),
|
||||
Object(ObjectMap),
|
||||
|
|
|
|||
|
|
@ -68,11 +68,11 @@ fn process_ast(program: &str, ast: &Program, mut runtime: RtAlloc, cfg: &mut Con
|
|||
match bytecode {
|
||||
Ok(code) => {
|
||||
if cfg.debug {
|
||||
#[cfg(feature = "pretty")]
|
||||
#[cfg(feature = "_debug")]
|
||||
{
|
||||
println!("Bytecode:\n{}\n", debug2::pprint(code));
|
||||
}
|
||||
#[cfg(not(feature = "pretty"))]
|
||||
#[cfg(not(feature = "_debug"))]
|
||||
{
|
||||
println!("Bytecode:\n{:#?}\n", code);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,10 @@ where
|
|||
const MAX_DEPTH: usize = 100;
|
||||
|
||||
fn program(&mut self) -> ParseResult<Program<'ast>> {
|
||||
Ok(Program(self.statement_list()?))
|
||||
Ok(Block {
|
||||
stmts: self.statement_list()?,
|
||||
span: Span::dummy(),
|
||||
})
|
||||
}
|
||||
|
||||
fn too_nested_error(&mut self) -> ParseResult<()> {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ pub fn execute<'bc>(
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[cfg_attr(feature = "pretty", derive(debug2::Debug))]
|
||||
#[cfg_attr(feature = "_debug", derive(debug2::Debug))]
|
||||
pub enum Value {
|
||||
/// `null`
|
||||
Null,
|
||||
|
|
@ -278,7 +278,7 @@ impl Display for Value {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pretty")]
|
||||
#[cfg(feature = "_debug")]
|
||||
impl debug2::Debug for Ptr {
|
||||
fn fmt(&self, f: &mut debug2::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Ptr").finish()
|
||||
|
|
|
|||
17
test.dil
17
test.dil
|
|
@ -1,14 +1,5 @@
|
|||
let x = 5;
|
||||
fn hello(uwu) {
|
||||
3 + 1;
|
||||
}
|
||||
|
||||
x(5, 6, 7);
|
||||
|
||||
fn hi(a, b,c,ds,gds,fdsa,fds,fd,sf,ds,fd,fd,fd,d,fd,fd,f,df,df,d,fd
|
||||
,fd,f,fd,fd,fd,fd,fd,f,a, b,c,ds,gds,fdsa,fds,fd,sf,ds,fd,fd,fd,d,fd,
|
||||
fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,fd,f,a, b,c,ds,gds,fdsa,fds,fd,sf,ds,
|
||||
fd,fd,fd,d,fd,fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,fd,f,a, b,c,ds,gds,fdsa,
|
||||
fds,fd,sf,ds,fd,fd,fd,d,fd,fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,fd,f,a, b,c,ds,
|
||||
gds,fdsa,fds,fd,sf,ds,fd,fd,fd,d,fd,fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,fd,f,df,
|
||||
df,d,fd,fd,f,fd,fd,fd,fd,fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,f,df,df,d,fd,fd,f,
|
||||
fd,fd,fd,fd,fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,
|
||||
fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,fd,f,df,df,d,
|
||||
fd,fd,f,fd,fd,fd,fd,f,df,df,d,fd,fd,f,fd,fd,fd,fd,fd,f,df,df,d,fd,fd,f,fd,fd,fd) {}
|
||||
let yeah = hello;
|
||||
Loading…
Add table
Add a link
Reference in a new issue