Compare commits

..

5 Commits

Author SHA1 Message Date
8f8f8ffe80 Update README.md 2025-04-07 17:50:32 +02:00
6ed7838a53 [Compiler-Rust]: Vec.get(0) -> Vec.first() 2024-01-02 17:22:36 +01:00
6085eb0d6e Add solution to project euler's problem 3 2023-12-23 22:10:07 +01:00
01c062ce8f Add increment function to the standard library 2023-12-23 22:05:32 +01:00
90d67867cc Fix fasm error when enqueueing ints > 2^32
On x64 the only instruction supporting imm64 is mov rXX,
imm64 so there has to be a special case for those numbers
2023-12-23 22:01:06 +01:00
4 changed files with 73 additions and 3 deletions

View File

@ -1,3 +1,5 @@
**Moved to [Codeberg](https://codeberg.org/0x4261756D/kurz)**
# kurz # kurz
Queue based language Queue based language

View File

@ -0,0 +1,56 @@
//valid,6857
//:END:
import "../std.qbl"
600851475143 2 divHasLargerPF 3
while
{
// n p
req dup 2 req req +
// p n p+2
swp req
// n p p+2
divHasLargerPF
// p+2 hasLPF newN
req
}
deq 2 - intToStr println
function int int => bool int divHasLargerPF
{
req dup req divIfDivisible
// n newN
1 req dup
// newN 1 n newN
== req req
// is1 n newN
if
{
false req deq
}
else
{
true deq req
}
}
function int int => int divIfDivisible
{
// p n
dup req dup swp
// p n p n
divmod 0
// p n p/n p%n 0
req req req ==
// p n p/n isDiv
req req req
if
{
deq req divIfDivisible
}
else
{
req deq deq
}
}

View File

@ -501,7 +501,15 @@ fn generate_assembly_linux_x64_block(operations: &Vec<Operation>, functions: &Ve
{ {
Datatype::Int => Datatype::Int =>
{ {
data.code += format!("\tmov qword [queue+8*r13], {}\n", value).as_str(); if value.parse::<i64>().unwrap() > u32::MAX as i64
{
data.code += format!("\tmov rax, {}\n", value).as_str();
data.code += "\tmov qword [queue+8*r13], rax\n";
}
else
{
data.code += format!("\tmov qword [queue+8*r13], {}\n", value).as_str();
}
} }
Datatype::Bool => Datatype::Bool =>
{ {
@ -946,7 +954,7 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
} }
Operation::Dup(_, _) => Operation::Dup(_, _) =>
{ {
let val = queue.get(0).unwrap(); let val = queue.first().unwrap();
queue.push(val.clone()); queue.push(val.clone());
} }
Operation::Swap(_, _) => Operation::Swap(_, _) =>
@ -1241,7 +1249,7 @@ fn get_return_type(operations: &Vec<Operation>, ins: &[Datatype], functions: &Ve
} }
Operation::Dup(line, col) => Operation::Dup(line, col) =>
{ {
if let Some(typ) = type_queue.get(0) if let Some(typ) = type_queue.first()
{ {
type_queue.push(*typ); type_queue.push(*typ);
} }

View File

@ -24,3 +24,7 @@ function int => int decrement
{ {
1 - 1 -
} }
function int => int increment
{
1 +
}