Initial commit

This commit is contained in:
Lucia Ceionia
2023-05-12 16:54:29 -05:00
commit 1f6da72364
14 changed files with 1783 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View 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
View 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
View 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

BIN
a.out Executable file

Binary file not shown.

12
ack.src Normal file
View 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
View 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

3
extra.c Normal file
View File

@@ -0,0 +1,3 @@
void printfd(int v) {
printf("%d\n", v);
}

BIN
extra.o Normal file

Binary file not shown.

1464
src/main.rs Normal file

File diff suppressed because it is too large Load Diff

160
test.S Normal file
View 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

BIN
test.o Normal file

Binary file not shown.

43
test.src Normal file
View 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

21
test2.src Normal file
View File

@@ -0,0 +1,21 @@
extern printfd;
extern puts;
fn main(argc i32 argv ppi8)
a b i32;
endvar
a 20:=;
5 b=:;
a 10 a=: b+1+ call printvalue;
a 20:=;
5 b=:;
a 0+ 10 a=: b+1+ call printvalue;
endfn
fn printvalue(a i32)
endvar
a call printfd;
endfn