diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 5a58bfb..3433c62 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -8,8 +8,18 @@
+
-
+
+
+
+
+
+
+
+
+
+
@@ -56,27 +66,27 @@
- {
- "keyToString": {
- "Cargo.Run whython-8.executor": "Run",
- "RunOnceActivity.OpenProjectViewOnStart": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "RunOnceActivity.rust.reset.selective.auto.import": "true",
- "git-widget-placeholder": "master",
- "ignore.virus.scanning.warn.message": "true",
- "last_opened_file_path": "/home/robertlucas/RustroverProjects/whython-8/src/root/builtin/int",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
- "org.rust.cargo.project.model.impl.CargoExternalSystemProjectAware.subscribe.first.balloon": "",
- "org.rust.first.attach.projects": "true",
- "settings.editor.selected.configurable": "preferences.pluginManager",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -169,6 +179,7 @@
+
@@ -432,4 +443,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/build/out.asm b/build/out.asm
index c6df377..2740025 100644
--- a/build/out.asm
+++ b/build/out.asm
@@ -6,14 +6,17 @@ main:
push rbp
mov rbp, rsp
- mov qword [rbp-8], 1
+ mov qword [rbp-8], 0
+ mov qword [rbp-16], 1
+ mov rax, qword [rbp-16]
+ mov qword [rbp-40], rax
mov rax, qword [rbp-8]
- mov qword [rbp-16], rax
- sub rsp, 16
+ mov qword [rbp-48], rax
+ sub rsp, 48
call _1
- add rsp, 16
- mov qword [rbp-16], 255
- mov rax, qword [rbp-16]
+ add rsp, 48
+ mov qword [rbp-40], 255
+ mov rax, qword [rbp-40]
leave
ret
@@ -34,15 +37,30 @@ _1:
mov rax, qword [rbp+16]
mov qword [rbp-24], rax
- mov qword [rbp-32], 1
+ mov rax, qword [rbp+24]
+ mov qword [rbp-32], rax
mov rax, qword [rbp-24]
add rax, qword [rbp-32]
mov qword [rbp-16], rax
- mov rax, qword [rbp-16]
+ mov rax, qword [rbp+24]
mov qword [rbp-40], rax
- sub rsp, 40
+ mov qword [rbp-48], 12
+ mov rax, 60
+ mov rdi, [rbp-48]
+ syscall
+ mov rax, qword [rbp-40]
+ mov qword [rbp-56], rax
+ mov rax, qword [rbp-16]
+ mov qword [rbp-64], rax
+ mov rax, qword [rbp-64]
+ mov qword [rbp-88], rax
+ mov rax, qword [rbp-56]
+ mov qword [rbp-96], rax
+ sub rsp, 96
call _1
- add rsp, 40
+ add rsp, 96
+ leave
+ ret
section .data
__10_fstr db `Integer: %d\n`,0
\ No newline at end of file
diff --git a/build/out.o b/build/out.o
index 77c790b..120e41f 100644
Binary files a/build/out.o and b/build/out.o differ
diff --git a/build/out.out b/build/out.out
index fc791b0..2bcb0cf 100755
Binary files a/build/out.out and b/build/out.out differ
diff --git a/main.why b/main.why
index dd34695..770974e 100644
--- a/main.why
+++ b/main.why
@@ -1,9 +1,12 @@
-fn r(a: int) {
+fn fib(a: int, b: int) {
printi(a);
- r(a + 1);
+ let d: int = a + b;
+ let c: int = b;
+ exit(12);
+ fib(c, d);
}
fn main() -> int {
- r(1);
+ fib(0, 1);
return 255;
}
diff --git a/src/root/builtin/functions/exit.rs b/src/root/builtin/functions/exit.rs
new file mode 100644
index 0000000..a0ceae5
--- /dev/null
+++ b/src/root/builtin/functions/exit.rs
@@ -0,0 +1,51 @@
+use unique_type_id::UniqueTypeId;
+use crate::root::builtin::{BuiltinInlineFunction, f_id, InlineFunctionGenerator};
+use crate::root::builtin::types::int::IntType;
+use crate::root::errors::WErr;
+use crate::root::name_resolver::name_resolvers::NameResult::Function;
+use crate::root::name_resolver::resolve_function_signatures::FunctionSignature;
+
+use crate::root::shared::common::{FunctionID, Indirection, LocalAddress, TypeID, TypeRef};
+
+#[derive(UniqueTypeId)]
+#[UniqueTypeIdType = "u16"]
+pub struct ExitFunction;
+
+impl ExitFunction {
+ pub const fn id() -> FunctionID {
+ f_id(ExitFunction::unique_type_id().0)
+ }
+}
+
+impl BuiltinInlineFunction for ExitFunction {
+ fn id(&self) -> FunctionID {
+ Self::id()
+ }
+
+ fn name(&self) -> &'static str {
+ "exit"
+ }
+
+ fn signature(&self) -> FunctionSignature {
+ FunctionSignature::new_inline_builtin(
+ false,
+ &[("lhs", IntType::id().immediate())],
+ None
+ )
+ }
+
+ fn inline(&self) -> InlineFunctionGenerator {
+ |args: &[LocalAddress], _, gt, sz| -> String {
+ let lhs = &args[0];
+
+ // 0 us exit syscall
+ format!(" mov rax, 60
+ mov rdi, {lhs}
+ syscall")
+ }
+ }
+
+ fn parent_type(&self) -> Option {
+ None
+ }
+}
diff --git a/src/root/builtin/functions/mod.rs b/src/root/builtin/functions/mod.rs
index e69de29..cd3646e 100644
--- a/src/root/builtin/functions/mod.rs
+++ b/src/root/builtin/functions/mod.rs
@@ -0,0 +1,9 @@
+mod exit;
+
+use b_box::b;
+use crate::root::builtin::functions::exit::ExitFunction;
+use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable;
+
+pub fn register_functions(global_table: &mut GlobalDefinitionTable) {
+ global_table.register_inline_function(&ExitFunction);
+}
\ No newline at end of file
diff --git a/src/root/builtin/mod.rs b/src/root/builtin/mod.rs
index 85566dc..d278c39 100644
--- a/src/root/builtin/mod.rs
+++ b/src/root/builtin/mod.rs
@@ -1,6 +1,7 @@
pub mod types;
pub mod functions;
+use crate::root::builtin::functions::register_functions;
use crate::root::builtin::types::int::register_int;
use crate::root::compiler::global_tracker::GlobalTracker;
use crate::root::errors::WErr;
@@ -10,6 +11,7 @@ use crate::root::shared::common::{ByteSize, FunctionID, LocalAddress, TypeID};
use crate::root::shared::types::Type;
pub fn register_builtin(global_table: &mut GlobalDefinitionTable) {
+ register_functions(global_table);
register_int(global_table);
}
diff --git a/src/root/builtin/types/int/printi.rs b/src/root/builtin/types/int/printi.rs
index da2d331..3b6b02d 100644
--- a/src/root/builtin/types/int/printi.rs
+++ b/src/root/builtin/types/int/printi.rs
@@ -28,7 +28,7 @@ impl BuiltinInlineFunction for PrintI {
fn signature(&self) -> FunctionSignature {
FunctionSignature::new_inline_builtin(
- true,
+ false,
&[("lhs", IntType::id().immediate())],
None
)
diff --git a/src/root/compiler/compile_function.rs b/src/root/compiler/compile_function.rs
index 2e20c96..79e3ad3 100644
--- a/src/root/compiler/compile_function.rs
+++ b/src/root/compiler/compile_function.rs
@@ -56,9 +56,9 @@ pub fn compile_function(fid: FunctionID, function: FunctionToken, global_table:
full_contents
);
- if fid.is_main() {
- final_contents += "\n\tleave\n\tret"
- }
+ // if fid.is_main() {
+ final_contents += "\n\tleave\n\tret";
+ // }
Ok(final_contents)
}
diff --git a/src/root/compiler/compile_function_call.rs b/src/root/compiler/compile_function_call.rs
index 56f2180..682b5b7 100644
--- a/src/root/compiler/compile_function_call.rs
+++ b/src/root/compiler/compile_function_call.rs
@@ -129,7 +129,7 @@ pub fn call_function(
local_variables.enter_block();
// ? Arguments
- for arg in args {
+ for arg in args.iter().rev() {
let into = global_table.add_local_variable_unnamed_base(arg.type_ref().clone(), local_variables);
code += "\n";
code += ©(*arg.local_address(), *into.local_address(), global_table.get_size(into.type_ref()));
diff --git a/types.toml b/types.toml
index 38b4c7c..684024f 100644
--- a/types.toml
+++ b/types.toml
@@ -8,3 +8,13 @@ Pri=6
Prin=7
Print=8
PrintI=9
+E=10
+Ex=11
+Exi=12
+Exit=13
+ExitF=14
+ExitFu=15
+ExitFun=16
+ExitFunctio=17
+ExitFunction=18
+ExitFunctions=19