Initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "lang-lucia"
|
||||
version = "0.1.0"
|
||||
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "lang-lucia"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
21
Makefile
Normal file
21
Makefile
Normal file
@@ -0,0 +1,21 @@
|
||||
objects = test.o extra.o
|
||||
|
||||
all: $(objects)
|
||||
gcc -g -m32 -no-pie -o a.out $^
|
||||
|
||||
.PRECIOUS: %.S
|
||||
|
||||
%.S: %.src
|
||||
cat $< | ./target/debug/lang-lucia -q > $@
|
||||
|
||||
%.o: %.S
|
||||
nasm -Ox -g -F dwarf -felf -o $@ $<
|
||||
|
||||
%.o: %.c
|
||||
gcc -m32 -g -c -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f test.o test.S
|
||||
|
||||
compiler:
|
||||
cargo build
|
||||
12
ack.src
Normal file
12
ack.src
Normal file
@@ -0,0 +1,12 @@
|
||||
fn ack(m i32 n i32)
|
||||
endvar
|
||||
if m then
|
||||
if n then
|
||||
m 1- : m n 1- call ack call ack ret;
|
||||
else
|
||||
m 1- 1 call ack ret;
|
||||
end
|
||||
else
|
||||
n 1+ ret
|
||||
end
|
||||
endfn
|
||||
43
ex.src
Normal file
43
ex.src
Normal file
@@ -0,0 +1,43 @@
|
||||
extern printfd;
|
||||
extern puts;
|
||||
|
||||
fn ack(m i32 n i32) endvar
|
||||
if m 0 eq then
|
||||
n 1+ ret;
|
||||
elif n 0 eq then
|
||||
(m 1- 1)ack ret;
|
||||
else
|
||||
(m 1- (m n 1-)ack)ack ret;
|
||||
end
|
||||
endfn
|
||||
|
||||
fn foo(ptr pi32) endvar
|
||||
ptr* ptr* 1+:=
|
||||
endfn
|
||||
|
||||
fn main(argc i32 argv ppi8)
|
||||
x y u32;
|
||||
ptr ppi8;
|
||||
endvar
|
||||
|
||||
0 y=:;
|
||||
loop
|
||||
y 4 eq breakif;
|
||||
0 x=:;
|
||||
loop
|
||||
x 4 eq breakif;
|
||||
((y x)ack)printfd;
|
||||
(x&)foo
|
||||
end
|
||||
y 1 + y=:;
|
||||
end
|
||||
|
||||
x argc :=;
|
||||
ptr argv :=;
|
||||
loop
|
||||
x 0 eq ptr* 0 eq or breakif;
|
||||
(ptr*)puts;
|
||||
x 1 - x=:;
|
||||
ptr 4+ ptr=:;
|
||||
end
|
||||
endfn
|
||||
1464
src/main.rs
Normal file
1464
src/main.rs
Normal file
File diff suppressed because it is too large
Load Diff
160
test.S
Normal file
160
test.S
Normal file
@@ -0,0 +1,160 @@
|
||||
extern printfd
|
||||
extern puts
|
||||
global ack
|
||||
ack:
|
||||
push ebp
|
||||
push edi
|
||||
push esi
|
||||
push ebx
|
||||
mov ebp, esp
|
||||
mov ebx, [ebp + 20]
|
||||
cmp ebx, 0
|
||||
sete bl
|
||||
test bl, bl
|
||||
jz .le0
|
||||
mov ebx, [ebp + 24]
|
||||
add ebx, 1
|
||||
mov eax, ebx
|
||||
mov esp, ebp
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
jmp .lE0
|
||||
.le0:
|
||||
mov ebx, [ebp + 24]
|
||||
cmp ebx, 0
|
||||
sete bl
|
||||
test bl, bl
|
||||
jz .l0e0
|
||||
mov ebx, [ebp + 20]
|
||||
sub ebx, 1
|
||||
push 1
|
||||
push ebx
|
||||
call ack
|
||||
add esp, 8
|
||||
mov esp, ebp
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
jmp .lE0
|
||||
.l0e0:
|
||||
mov ebx, [ebp + 20]
|
||||
sub ebx, 1
|
||||
mov eax, [ebp + 24]
|
||||
sub eax, 1
|
||||
push eax
|
||||
push dword [ebp + 20]
|
||||
call ack
|
||||
add esp, 8
|
||||
push eax
|
||||
push ebx
|
||||
call ack
|
||||
add esp, 8
|
||||
mov esp, ebp
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
.lE0:
|
||||
mov esp, ebp
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
global foo
|
||||
foo:
|
||||
push ebp
|
||||
push edi
|
||||
push esi
|
||||
push ebx
|
||||
mov ebp, esp
|
||||
mov ebx, dword [ebp + 20]
|
||||
mov eax, dword [ebp + 20]
|
||||
mov eax, [eax]
|
||||
add eax, 1
|
||||
mov dword [ebx], eax
|
||||
mov esp, ebp
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
global main
|
||||
main:
|
||||
push ebp
|
||||
push edi
|
||||
push esi
|
||||
push ebx
|
||||
mov ebp, esp
|
||||
sub esp, 12
|
||||
mov dword [ebp - 4], 0
|
||||
.l0:
|
||||
mov ebx, [ebp - 4]
|
||||
cmp ebx, 4
|
||||
sete bl
|
||||
test bl, bl
|
||||
jnz .le0
|
||||
mov dword [ebp - 8], 0
|
||||
.l1:
|
||||
mov ebx, [ebp - 8]
|
||||
cmp ebx, 4
|
||||
sete bl
|
||||
test bl, bl
|
||||
jnz .le1
|
||||
push dword [ebp - 8]
|
||||
push dword [ebp - 4]
|
||||
call ack
|
||||
add esp, 8
|
||||
push eax
|
||||
call printfd
|
||||
add esp, 4
|
||||
lea ebx, dword [ebp - 8]
|
||||
push ebx
|
||||
call foo
|
||||
add esp, 4
|
||||
jmp .l1
|
||||
.le1:
|
||||
mov ebx, [ebp - 4]
|
||||
add ebx, 1
|
||||
mov dword [ebp - 4], ebx
|
||||
jmp .l0
|
||||
.le0:
|
||||
mov ebx, [ebp + 20]
|
||||
mov dword [ebp - 8], ebx
|
||||
mov ebx, [ebp + 24]
|
||||
mov dword [ebp - 12], ebx
|
||||
.l2:
|
||||
mov ebx, [ebp - 8]
|
||||
cmp ebx, 0
|
||||
sete bl
|
||||
mov eax, dword [ebp - 12]
|
||||
mov eax, [eax]
|
||||
cmp eax, 0
|
||||
sete al
|
||||
or bl, al
|
||||
test bl, bl
|
||||
jnz .le2
|
||||
mov ebx, dword [ebp - 12]
|
||||
push dword [ebx]
|
||||
call puts
|
||||
add esp, 4
|
||||
mov ebx, [ebp - 8]
|
||||
sub ebx, 1
|
||||
mov dword [ebp - 8], ebx
|
||||
mov ebx, [ebp - 12]
|
||||
add ebx, 4
|
||||
mov dword [ebp - 12], ebx
|
||||
jmp .l2
|
||||
.le2:
|
||||
mov esp, ebp
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
43
test.src
Normal file
43
test.src
Normal file
@@ -0,0 +1,43 @@
|
||||
extern printfd;
|
||||
extern puts;
|
||||
|
||||
fn ack(m i32 n i32) endvar
|
||||
if m 0 eq then
|
||||
n 1+ ret;
|
||||
elif n 0 eq then
|
||||
(m 1- 1)ack ret;
|
||||
else
|
||||
(m 1- (m n 1-)ack)ack ret;
|
||||
end
|
||||
endfn
|
||||
|
||||
fn foo(ptr pi32) endvar
|
||||
ptr* ptr* 1+:=
|
||||
endfn
|
||||
|
||||
fn main(argc i32 argv ppi8)
|
||||
x y u32;
|
||||
ptr ppi8;
|
||||
endvar
|
||||
|
||||
0 y=:;
|
||||
loop
|
||||
y 4 eq breakif;
|
||||
0 x=:;
|
||||
loop
|
||||
x 4 eq breakif;
|
||||
((y x)ack)printfd;
|
||||
(x&)foo
|
||||
end
|
||||
y 1 + y=:;
|
||||
end
|
||||
|
||||
x argc :=;
|
||||
ptr argv :=;
|
||||
loop
|
||||
x 0 eq ptr* 0 eq or breakif;
|
||||
(ptr*)puts;
|
||||
x 1 - x=:;
|
||||
ptr 4+ ptr=:;
|
||||
end
|
||||
endfn
|
||||
Reference in New Issue
Block a user