diff --git a/.idea/shelf/Uncommitted_changes_before_Update_at_27_07_2024,_23_06_[Changes]/shelved.patch b/.idea/shelf/Uncommitted_changes_before_Update_at_27_07_2024,_23_06_[Changes]/shelved.patch
new file mode 100644
index 0000000..63fe313
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Update_at_27_07_2024,_23_06_[Changes]/shelved.patch
@@ -0,0 +1,77 @@
+Index: .idea/workspace.xml
+IDEA additional info:
+Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
+<+>\n\n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n \n \n \n \n \n \n \n \n \n \n {\n "lastFilter": {\n "state": "OPEN",\n "assignee": "Robert-M-Lucas"\n }\n}\n \n \n \n {\n "selectedUrlAndAccountId": {\n "url": "https://github.com/Robert-M-Lucas/whython-8.git",\n "accountId": "dcb8df19-0b39-47e1-9073-4a54f7034be8"\n }\n}\n \n \n \n \n \n \n {\n "customColor": "",\n "associatedIndex": 4\n}\n \n \n \n \n \n {\n "keyToString": {\n "Cargo.Build `Run whython-8`.executor": "Run",\n "Cargo.Run whython-8.executor": "Run",\n "Cargo.Test whython-8.executor": "Run",\n "RunOnceActivity.OpenProjectViewOnStart": "true",\n "RunOnceActivity.ShowReadmeOnStart": "true",\n "RunOnceActivity.rust.reset.selective.auto.import": "true",\n "Shell Script.Test Asm.executor": "Run",\n "git-widget-placeholder": "master",\n "ignore.virus.scanning.warn.message": "true",\n "last_opened_file_path": "/home/robertlucas/RustroverProjects/trace",\n "node.js.detected.package.eslint": "true",\n "node.js.detected.package.tslint": "true",\n "node.js.selected.package.eslint": "(autodetect)",\n "node.js.selected.package.tslint": "(autodetect)",\n "nodejs_package_manager_path": "npm",\n "org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",\n "org.rust.cargo.project.model.impl.CargoExternalSystemProjectAware.subscribe.first.balloon": "",\n "org.rust.first.attach.projects": "true",\n "settings.editor.selected.configurable": "preferences.pluginManager",\n "vue.rearranger.settings.migration": "true"\n },\n "keyToStringList": {\n "com.intellij.ide.scratch.ScratchImplUtil$2/New Scratch File": [\n "Rust"\n ]\n }\n}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n \n \n \n \n \n \n \n 1714088144106\n \n \n 1714088144106\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n 1717469659146\n \n \n \n 1717469659146\n \n \n \n 1717473113692\n \n \n \n 1717473113692\n \n \n \n 1717473365560\n \n \n \n 1717473365560\n \n \n \n 1717562697947\n \n \n \n 1717562697947\n \n \n \n 1717570846946\n \n \n \n 1717570846946\n \n \n \n 1717572031837\n \n \n \n 1717572031837\n \n \n \n 1717578308406\n \n \n \n 1717578308406\n \n \n \n 1717598684770\n \n \n \n 1717598684770\n \n \n \n 1717599815108\n \n \n \n 1717599815108\n \n \n \n 1717614243407\n \n \n \n 1717614243407\n \n \n \n 1717614696137\n \n \n \n 1717614696137\n \n \n \n 1717677552390\n \n \n \n 1717677552390\n \n \n \n 1717684897421\n \n \n \n 1717684897422\n \n \n \n 1717705529640\n \n \n \n 1717705529640\n \n \n \n 1717769943602\n \n \n \n 1717769943602\n \n \n \n 1717794101530\n \n \n \n 1717794101530\n \n \n \n 1717794233364\n \n \n \n 1717794233364\n \n \n \n 1717794747334\n \n \n \n 1717794747334\n \n \n \n 1717819316020\n \n \n \n 1717819316020\n \n \n \n 1717826853448\n \n \n \n 1717826853448\n \n \n \n 1718558711741\n \n \n \n 1718558711741\n \n \n \n 1718558898901\n \n \n \n 1718558898901\n \n \n \n 1718636633009\n \n \n \n 1718636633009\n \n \n \n 1718798005819\n \n \n \n 1718798005819\n \n \n \n 1718798188305\n \n \n \n 1718798188305\n \n \n \n 1718799244388\n \n \n \n 1718799244388\n \n \n \n 1718803787262\n \n \n \n 1718803787262\n \n \n \n 1718805301324\n \n \n \n 1718805301324\n \n \n \n 1718888868217\n \n \n \n 1718888868217\n \n \n \n 1718889832262\n \n \n \n 1718889832262\n \n \n \n 1718895358320\n \n \n \n 1718895358320\n \n \n \n 1718928037028\n \n \n \n 1718928037028\n \n \n \n 1718928163157\n \n \n \n 1718928163157\n \n \n \n 1718963722966\n \n \n \n 1718963722967\n \n \n \n 1718964303334\n \n \n \n 1718964303334\n \n \n \n 1718968546046\n \n \n \n 1718968546046\n \n \n \n 1719323220161\n \n \n \n 1719323220162\n \n \n \n 1719323378191\n \n \n \n 1719323378191\n \n \n \n 1719324580280\n \n \n \n 1719324580280\n \n \n \n 1719324945974\n \n \n \n 1719324945974\n \n \n \n 1719325143424\n \n \n \n 1719325143424\n \n \n \n 1721950132807\n \n \n \n 1721950132807\n \n \n \n 1721951605297\n \n \n \n 1721951605297\n \n \n \n 1721954057479\n \n \n \n 1721954057480\n \n \n \n 1721990519536\n \n \n \n 1721990519536\n \n \n \n 1721996703318\n \n \n \n 1721996703318\n \n \n \n 1721997307152\n \n \n \n 1721997307152\n \n \n \n 1721997775708\n \n \n \n 1721997775708\n \n \n \n 1722095029520\n \n \n \n 1722095029521\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
+Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+<+>UTF-8
+===================================================================
+diff --git a/.idea/workspace.xml b/.idea/workspace.xml
+--- a/.idea/workspace.xml (revision f39ebc39f3c1966f09766fcb00b4c79886954a55)
++++ b/.idea/workspace.xml (date 1722117982574)
+@@ -7,11 +7,8 @@
+
+
+
+-
+-
+-
+-
+-
++
++
+
+
+
+@@ -228,15 +225,8 @@
+
+
+
+-
+-
+-
+-
+- 1717469659146
+-
+-
+-
+- 1717469659146
++
++
+
+
+
+@@ -622,7 +612,15 @@
+
+ 1722095029521
+
+-
++
++
++ 1722095789946
++
++
++
++ 1722095789946
++
++
+
+
+
+@@ -640,7 +638,6 @@
+
+
+
+-
+
+
+
+@@ -665,7 +662,8 @@
+
+
+
+-
++
++
+
+
+
diff --git a/Cargo.lock b/Cargo.lock
index a1bca4e..c437d25 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -381,6 +381,16 @@ dependencies = [
"unicode-ident",
]
+[[package]]
+name = "termsize"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6f11ff5c25c172608d5b85e2fb43ee9a6d683a7f4ab7f96ae07b3d8b590368fd"
+dependencies = [
+ "libc",
+ "winapi",
+]
+
[[package]]
name = "thiserror"
version = "1.0.63"
@@ -462,6 +472,7 @@ dependencies = [
"strum",
"strum_macros",
"substring",
+ "termsize",
"thiserror",
"unique-type-id",
"walkdir",
diff --git a/Cargo.toml b/Cargo.toml
index 98635be..63a0262 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,6 +23,7 @@ nom-supreme = "0.8.0"
substring = "1.4.5"
derive-getters = "0.4.0"
derive_more = "0.99.18"
+termsize = "0.1.9"
[profile.release]
opt-level = 3
diff --git a/build/out.asm b/build/out.asm
index 1d2bac3..6396549 100644
--- a/build/out.asm
+++ b/build/out.asm
@@ -5,98 +5,52 @@ section .text
main:
push rbp
mov rbp, rsp
- mov qword [rbp-16], 3
- mov qword [rbp-8], 4
- mov rax, rbp
- add rax, -16
- mov qword [rbp-24], rax
- mov rax, rbp
- add rax, -16
+ ; Heap Alloc
+ mov qword [rbp-24], 3
+ mov qword [rbp-16], 4
+ mov rdi, 16
+ sub rsp, 24
+ extern malloc
+ call malloc
+ sub rsp, 24
mov qword [rbp-32], rax
+ mov rdx, qword [rbp-32]
+ mov rax, qword [rbp-24]
+ mov qword [rdx+0], rax
+ mov rax, qword [rbp-16]
+ mov qword [rdx+8], rax
mov rax, qword [rbp-32]
- mov qword [rbp-40], rax
- sub rsp, 40
- call _3
- add rsp, 40
- mov rax, rbp
- add rax, -16
- mov qword [rbp-40], rax
- mov rax, qword [rbp-40]
+ mov qword [rbp-8], rax
+ ; Unheap
+ mov rdx, qword [rbp-8]
+ mov rax, qword [rdx+0]
mov qword [rbp-48], rax
- sub rsp, 48
- call _4
- add rsp, 48
- mov qword [rbp-48], 2
- mov rax, qword [rbp-24]
- mov rdx, qword [rbp-48]
- add qword [rax], rdx
+ mov rax, qword [rdx+8]
+ mov qword [rbp-40], rax
+ ; Get member
mov rax, rbp
- add rax, -16
+ add rax, -48
mov qword [rbp-56], rax
- mov rax, qword [rbp-56]
+ ; Deref member
+ mov rdx, qword [rbp-56]
+ mov rax, qword [rdx+0]
mov qword [rbp-64], rax
- sub rsp, 64
- call _3
- add rsp, 64
- mov qword [rbp-64], 7
+ ; Print
mov rax, qword [rbp-64]
- leave
- ret
-
-
-_3:
- push rbp
- mov rbp, rsp
- mov rax, [rbp+16]
- add rax, 0
- mov qword [rbp-16], rax
- mov rdx, qword [rbp-16]
- mov rax, qword [rdx+0]
- mov qword [rbp-8], rax
- mov rdi, __8_fstr
- mov rsi, [rbp-8]
- mov al, 0
- sub rsp, 16
- extern printf
- call printf
- add rsp, 16
- mov rax, [rbp+16]
- add rax, 8
- mov qword [rbp-32], rax
- mov rdx, qword [rbp-32]
- mov rax, qword [rdx+0]
- mov qword [rbp-24], rax
+ mov qword [rbp-72], rax
mov rdi, __8_fstr
- mov rsi, [rbp-24]
+ mov rsi, [rbp-72]
mov al, 0
- sub rsp, 32
+ sub rsp, 72
extern printf
call printf
- add rsp, 32
-
-leave
-ret
-
-_4:
- push rbp
- mov rbp, rsp
- mov rax, [rbp+16]
- add rax, 0
- mov qword [rbp-8], rax
- mov qword [rbp-16], 1
- mov rax, qword [rbp-8]
- mov rdx, qword [rbp-16]
- add qword [rax], rdx
- mov rax, [rbp+16]
- add rax, 8
- mov qword [rbp-24], rax
- mov qword [rbp-32], 1
- mov rax, qword [rbp-24]
- mov rdx, qword [rbp-32]
- add qword [rax], rdx
+ add rsp, 72
+ ; Return
+ mov qword [rbp-80], 7
+ mov rax, qword [rbp-80]
+ leave
+ ret
-leave
-ret
section .data_readonly
__8_fstr db `Integer: %ld\n`,0
\ No newline at end of file
diff --git a/build/out.o b/build/out.o
index 84087e4..2e0f615 100644
Binary files a/build/out.o and b/build/out.o differ
diff --git a/build/out.out b/build/out.out
index 372c7b3..9a8a964 100755
Binary files a/build/out.out and b/build/out.out differ
diff --git a/main.why b/main.why
index 331545a..d5cbfc8 100644
--- a/main.why
+++ b/main.why
@@ -1,31 +1,15 @@
-struct MyStruct {
- a: int,
- b: int
+struct LL {
+ has_node: bool,
+ first: &Node
}
-impl MyStruct {
- fn print(&self) {
- printi(*self.a);
- printi(*self.b);
- }
- fn increment(&self) {
- self.a += 1;
- self.b += 1;
- }
+struct Node {
+ val: int,
+ has_next: bool,
+ next: &Node
}
fn main() -> int {
- let x: MyStruct = MyStruct {
- a: 3,
- b: 4
- };
- let y: &int = x.a;
-
- x.print();
- x.increment();
- y += 2;
- x.print();
-
- return 7;
+ let r: LL = LL { has_node: false, first: Node::null() };
}
\ No newline at end of file
diff --git a/src/root.rs b/src/root.rs
index d1d345b..765d838 100644
--- a/src/root.rs
+++ b/src/root.rs
@@ -107,7 +107,18 @@ pub fn main_args(args: Args) -> Result<(), WErr> {
if args.build {
println!("Skipping execution")
} else {
- println!("Executing...");
+ let termsize::Size {rows, cols} = termsize::get().unwrap();
+ const EXECUTING: &str = "Executing";
+ if cols < EXECUTING.len() as u16 || cols > 300 {
+ cprintln!("Executing...>");
+ }
+ else {
+ let padl = (cols - EXECUTING.len() as u16) / 2;
+ let padr = if ((cols - EXECUTING.len() as u16) % 2) == 1 {
+ padl + 1
+ } else { padl };
+ cprintln!("{}{}{}>", "-".repeat(padl as usize), EXECUTING, "-".repeat(padr as usize));
+ }
run(&args.output);
}
}
diff --git a/src/root/compiler/assembly/heap.rs b/src/root/compiler/assembly/heap.rs
new file mode 100644
index 0000000..234ca15
--- /dev/null
+++ b/src/root/compiler/assembly/heap.rs
@@ -0,0 +1,18 @@
+use crate::root::assembler::assembly_builder::AssemblyBuilder;
+use crate::root::compiler::local_variable_table::LocalVariableTable;
+use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable;
+use crate::root::shared::common::{AddressedTypeRef, TypeRef};
+
+pub fn heap_alloc(t: TypeRef, global_table: &mut GlobalDefinitionTable, local_variable_table: &mut LocalVariableTable) -> (String, AddressedTypeRef) {
+ let size = global_table.get_size(&t).0;
+ let sz = local_variable_table.stack_size().0;
+ let output = global_table.add_local_variable_unnamed_base(t.plus_one_indirect(), local_variable_table);
+
+ (format!(" mov rdi, {size}
+ sub rsp, {sz}
+ extern malloc
+ call malloc
+ sub rsp, {sz}
+ mov qword {}, rax\n", output.local_address()), output)
+
+}
\ No newline at end of file
diff --git a/src/root/compiler/assembly/mod.rs b/src/root/compiler/assembly/mod.rs
index b5614dd..ecd745f 100644
--- a/src/root/compiler/assembly/mod.rs
+++ b/src/root/compiler/assembly/mod.rs
@@ -1 +1,2 @@
pub mod utils;
+pub mod heap;
\ No newline at end of file
diff --git a/src/root/compiler/compile_function.rs b/src/root/compiler/compile_function.rs
index d877f7d..3568ae5 100644
--- a/src/root/compiler/compile_function.rs
+++ b/src/root/compiler/compile_function.rs
@@ -1,3 +1,4 @@
+use color_print::cprintln;
use crate::root::assembler::assembly_builder::AssemblyBuilder;
use crate::root::builtin::types::bool::BoolType;
use crate::root::builtin::types::int::IntType;
@@ -329,7 +330,7 @@ fn recursively_compile_lines(
}
#[cfg(debug_assertions)]
LineTokens::Marker(value) => {
- println!("\nCompiling marker [{}]", value.value());
+ cprintln!("\nAt Compilation Marker:> '{}'", value.value());
contents.line(&format!(";{}", value.value()));
}
}
diff --git a/src/root/compiler/evaluation/into.rs b/src/root/compiler/evaluation/into.rs
index b700b81..14423d1 100644
--- a/src/root/compiler/evaluation/into.rs
+++ b/src/root/compiler/evaluation/into.rs
@@ -22,6 +22,7 @@ use crate::root::shared::types::Type;
use either::{Left, Right};
use itertools::Itertools;
use std::any::Any;
+use crate::root::compiler::evaluation::new::compile_evaluable_new;
use crate::root::parser::parse::Location;
/// Evaluates `et` putting the result into `target`
@@ -383,10 +384,27 @@ pub fn compile_evaluable_into(
}
EvaluableTokens::StructInitialiser(struct_init) => {
let t = global_table.resolve_to_type_ref(struct_init.name())?;
+
+ if *struct_init.heap_alloc() {
+ if target.type_ref() != &t.plus_one_indirect() {
+ todo!()
+ }
+ let mut ab = AssemblyBuilder::new();
+ let (c, sr) = compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?;
+ ab.other(&c);
+ let sr = sr.unwrap();
+ ab.other(©(*sr.local_address(), *target.local_address(), global_table.get_size(target.type_ref())));
+ return Ok(ab.finish());
+ }
debug_assert!(!t.indirection().has_indirection());
- if &t != target.type_ref() {
+
+ if *struct_init.heap_alloc() && &t.plus_one_indirect() != target.type_ref() {
+ todo!()
+ }
+ if !struct_init.heap_alloc() && &t != target.type_ref() {
todo!();
}
+
let tt = global_table.get_type(t.type_id().clone());
let attributes = tt.get_attributes()?.iter().map(|x| x.clone()).collect_vec();
let give_attrs = struct_init.contents();
diff --git a/src/root/compiler/evaluation/new.rs b/src/root/compiler/evaluation/new.rs
index 10fae40..276418f 100644
--- a/src/root/compiler/evaluation/new.rs
+++ b/src/root/compiler/evaluation/new.rs
@@ -1,12 +1,15 @@
+use either::{Left, Right};
+use itertools::Itertools;
+
use crate::root::assembler::assembly_builder::AssemblyBuilder;
use crate::root::builtin::core::referencing::{set_deref, set_reference};
+use crate::root::compiler::assembly::heap::heap_alloc;
use crate::root::compiler::assembly::utils::{
- copy, copy_from_indirect_fixed_offset, copy_to_indirect,
+ copy, copy_to_indirect,
};
use crate::root::compiler::compile_function_call::call_function;
-use crate::root::compiler::evaluation::coerce_self::coerce_self;
-use crate::root::compiler::evaluation::reference::compile_evaluable_reference;
use crate::root::compiler::evaluation::{function_only, into, reference, type_only};
+use crate::root::compiler::evaluation::reference::compile_evaluable_reference;
use crate::root::compiler::global_tracker::GlobalTracker;
use crate::root::compiler::local_variable_table::LocalVariableTable;
use crate::root::errors::evaluable_errors::EvalErrs;
@@ -14,16 +17,13 @@ use crate::root::errors::evaluable_errors::EvalErrs::{ExpectedNotNone, ExpectedR
use crate::root::errors::name_resolver_errors::NRErrs;
use crate::root::errors::WErr;
use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, NameResult};
+use crate::root::parser::parse::Location;
use crate::root::parser::parse_function::parse_evaluable::{EvaluableToken, EvaluableTokens};
use crate::root::parser::parse_function::parse_operator::{OperatorTokens, PrefixOrInfixEx};
-use crate::root::parser::parse_parameters::SelfType;
use crate::root::shared::common::{
AddressedTypeRef, FunctionID, Indirection, LocalAddress, TypeRef,
};
use crate::root::shared::types::Type;
-use either::{Left, Right};
-use itertools::Itertools;
-use crate::root::parser::parse::Location;
/// Evaluates `et` into a new address
pub fn compile_evaluable_new(
@@ -409,8 +409,17 @@ pub fn compile_evaluable_new(
}
EvaluableTokens::StructInitialiser(struct_init) => {
let t = global_table.resolve_to_type_ref(struct_init.name())?;
- debug_assert!(!t.indirection().has_indirection());
- let target = global_table.add_local_variable_unnamed_base(t.clone(), local_variables);
+ let size = global_table.get_size(&t);
+
+ let mut code = AssemblyBuilder::new();
+
+ let target = // if struct_init.heap_alloc() {
+ // let (c, ref_target) = heap_alloc(t.clone(), global_table, local_variables);
+ // code.other(&c);
+ // ref_target
+ // } else {
+ global_table.add_local_variable_unnamed_base(t.clone(), local_variables)
+ /* } */;
let tt = global_table.get_type(t.type_id().clone());
let attributes = tt.get_attributes()?.iter().map(|x| x.clone()).collect_vec();
@@ -420,9 +429,6 @@ pub fn compile_evaluable_new(
todo!()
}
- let mut code = AssemblyBuilder::new();
-
- // TODO: Doable without clone?
for ((offset, t_name, t_type), (name, val)) in attributes.iter().zip(give_attrs.iter())
{
if t_name.name() != name.name() {
@@ -443,7 +449,15 @@ pub fn compile_evaluable_new(
)?);
}
- (code.finish(), Some(target))
+ if *struct_init.heap_alloc() {
+ let (c, ref_target) = heap_alloc(t, global_table, local_variables);
+ code.other(&c);
+ code.other(©_to_indirect(*target.local_address(), *ref_target.local_address(), size));
+ (code.finish(), Some(ref_target))
+ }
+ else {
+ (code.finish(), Some(target))
+ }
}
EvaluableTokens::None => (String::new(), None),
})
diff --git a/src/root/compiler/evaluation/reference.rs b/src/root/compiler/evaluation/reference.rs
index 20b807e..9f78a1b 100644
--- a/src/root/compiler/evaluation/reference.rs
+++ b/src/root/compiler/evaluation/reference.rs
@@ -41,13 +41,13 @@ pub fn compile_evaluable_reference(
}
}
EvaluableTokens::Literal(_) => {
- new::compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
+ compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
}
EvaluableTokens::InfixOperator(_, _, _) => {
compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
}
EvaluableTokens::PrefixOperator(_, _) => {
- new::compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
+ compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
}
EvaluableTokens::DynamicAccess(_, _) => {
compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
@@ -59,10 +59,10 @@ pub fn compile_evaluable_reference(
)
} // Accessed methods must be called
EvaluableTokens::FunctionCall(_, _) => {
- new::compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
+ compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
}
EvaluableTokens::StructInitialiser(struct_init) => {
- new::compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
+ compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)?
}
EvaluableTokens::None => (String::new(), None),
})
diff --git a/src/root/compiler/evaluation/type_only.rs b/src/root/compiler/evaluation/type_only.rs
index b468731..d972b39 100644
--- a/src/root/compiler/evaluation/type_only.rs
+++ b/src/root/compiler/evaluation/type_only.rs
@@ -148,8 +148,10 @@ pub fn compile_evaluable_type_only(
return_type
}
EvaluableTokens::StructInitialiser(struct_init) => {
- let t = global_table.resolve_to_type_ref(struct_init.name())?;
- debug_assert!(!t.indirection().has_indirection());
+ let mut t = global_table.resolve_to_type_ref(struct_init.name())?;
+ if *struct_init.heap_alloc() {
+ t = t.plus_one_indirect();
+ }
t
}
EvaluableTokens::None => {
diff --git a/src/root/parser/parse_function/parse_evaluable.rs b/src/root/parser/parse_function/parse_evaluable.rs
index b90a16e..808349f 100644
--- a/src/root/parser/parse_function/parse_evaluable.rs
+++ b/src/root/parser/parse_function/parse_evaluable.rs
@@ -223,6 +223,7 @@ pub fn parse_evaluable<'a, 'b>(
semicolon_terminated: bool,
) -> ParseResult<'a, Span<'a>, EvaluableToken> {
let mut s = s;
+ println!("{s}");
let mut evaluables = Vec::new();
diff --git a/src/root/parser/parse_function/parse_struct_init.rs b/src/root/parser/parse_function/parse_struct_init.rs
index d670b7e..d243e52 100644
--- a/src/root/parser/parse_function/parse_struct_init.rs
+++ b/src/root/parser/parse_function/parse_struct_init.rs
@@ -1,4 +1,4 @@
-use crate::root::parser::parse::{Location, ParseResult, Span};
+use crate::root::parser::parse::{ErrorTree, Location, ParseResult, Span};
use crate::root::parser::parse_blocks::{
parse_terminator_default_set, take_until_or_end_discard_smart, BRACE_TERMINATOR,
};
@@ -21,6 +21,7 @@ use nom::character::streaming::char;
pub struct StructInitToken {
location: Location,
name: FullNameWithIndirectionToken,
+ heap_alloc: bool,
contents: Vec<(SimpleNameToken, EvaluableToken)>,
}
@@ -30,6 +31,8 @@ pub fn parse_struct_init<'a, 'b>(
) -> ParseResult<'a, Span<'a>, StructInitToken> {
let (s, _) = discard_ignored(s)?;
+ let (s, heap_alloc) = tag::<&str, Span, ErrorTree>("new")(s).map(|(ns, _)| (ns, true)).unwrap_or((s, false));
+
let (s, struct_name) = parse_full_name(s, containing_class.clone())?;
debug_assert!(*struct_name.indirection() == Indirection(0)); // TODO
@@ -59,6 +62,7 @@ pub fn parse_struct_init<'a, 'b>(
StructInitToken {
location: struct_name.inner().location().clone(),
name: struct_name,
+ heap_alloc,
contents,
},
))
diff --git a/src/root/runner.rs b/src/root/runner.rs
index a62699b..38ab1af 100644
--- a/src/root/runner.rs
+++ b/src/root/runner.rs
@@ -66,7 +66,16 @@ pub fn run(output: &str) {
};
);
- // ? Here to circumvent some timing issues
+ let termsize::Size {rows, cols} = termsize::get().unwrap();
+ const EXITED: &str = "Exited";
+ if cols > EXITED.len() as u16 && cols < 300 {
+ let padl = (cols - EXITED.len() as u16) / 2;
+ let padr = if ((cols - EXITED.len() as u16) % 2) == 1 {
+ padl + 1
+ } else { padl };
+ cprintln!("\n{}{}{}>", "-".repeat(padl as usize), EXITED, "-".repeat(padr as usize));
+ }
+
println!("\nExited with return code {}", code);
cprintln!("Completed [{:?}]>", time);
}
diff --git a/todo.md b/todo.md
index 4fd3a28..40ff591 100644
--- a/todo.md
+++ b/todo.md
@@ -1,7 +1,7 @@
-- Add support for struct.function()
-- Add support for struct::staticFunction()
+
+- Add support for heap stuff
+- Add support for x.a where x is a ref
- Add array support
- Add rich parser errors
- Add support for multiple files
-- Add support for heap stuff