Compare commits
6 Commits
3440226658
...
main
Author | SHA1 | Date | |
---|---|---|---|
8f8f8ffe80 | |||
6ed7838a53 | |||
6085eb0d6e | |||
01c062ce8f | |||
90d67867cc | |||
1f78ad0a7f |
@ -1,3 +1,5 @@
|
||||
**Moved to [Codeberg](https://codeberg.org/0x4261756D/kurz)**
|
||||
|
||||
# kurz
|
||||
|
||||
Queue based language
|
||||
|
55
project_euler/problem2.qbl
Normal file
55
project_euler/problem2.qbl
Normal file
@ -0,0 +1,55 @@
|
||||
//valid,4613732
|
||||
//:END:
|
||||
import "../std.qbl"
|
||||
|
||||
true 1 2 0 0 0
|
||||
|
||||
while
|
||||
{
|
||||
// a b even_count 0 sum
|
||||
fib
|
||||
// even_count 0 sum b a+b
|
||||
dup ==
|
||||
// sum b a+b even_count even?
|
||||
req req req req
|
||||
if
|
||||
// sum b a+b even_count
|
||||
{
|
||||
req dup
|
||||
// b a+b even_count sum b
|
||||
req req deq 3 +
|
||||
// b a+b even_count sum+b
|
||||
req req
|
||||
}
|
||||
else
|
||||
{
|
||||
req req req
|
||||
}
|
||||
// even_count sum+b b a+b
|
||||
decrement 0 req req
|
||||
// a+b even_count-1 0 sum+b b
|
||||
check
|
||||
// even_count-1 0 sum+b b a+b big?
|
||||
req req req req swp
|
||||
// even_count-1 0 sum+b b big? a+b
|
||||
req req req swp
|
||||
// a+b even_count-1 0 sum+b big? b
|
||||
req req req req
|
||||
// big? b a+b even_count-1 0 sum+b
|
||||
}
|
||||
deq deq deq deq intToStr println
|
||||
|
||||
function int int => int int fib
|
||||
{
|
||||
req dup +
|
||||
}
|
||||
|
||||
function int => int nPrint
|
||||
{
|
||||
dup intToStr req print
|
||||
}
|
||||
|
||||
function int => int bool check
|
||||
{
|
||||
4000000 dup <
|
||||
}
|
56
project_euler/problem3.qbl
Normal file
56
project_euler/problem3.qbl
Normal 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
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
//valid,233168
|
||||
//:END:
|
||||
import "../std.qbl"
|
||||
|
||||
true 3 0
|
||||
|
14
src/main.rs
14
src/main.rs
@ -501,7 +501,15 @@ fn generate_assembly_linux_x64_block(operations: &Vec<Operation>, functions: &Ve
|
||||
{
|
||||
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 =>
|
||||
{
|
||||
@ -946,7 +954,7 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
||||
}
|
||||
Operation::Dup(_, _) =>
|
||||
{
|
||||
let val = queue.get(0).unwrap();
|
||||
let val = queue.first().unwrap();
|
||||
queue.push(val.clone());
|
||||
}
|
||||
Operation::Swap(_, _) =>
|
||||
@ -1241,7 +1249,7 @@ fn get_return_type(operations: &Vec<Operation>, ins: &[Datatype], functions: &Ve
|
||||
}
|
||||
Operation::Dup(line, col) =>
|
||||
{
|
||||
if let Some(typ) = type_queue.get(0)
|
||||
if let Some(typ) = type_queue.first()
|
||||
{
|
||||
type_queue.push(*typ);
|
||||
}
|
||||
|
Reference in New Issue
Block a user