Implemented const keyword

This commit is contained in:
2025-02-15 14:38:01 +01:00
parent be028a52d1
commit 0a1a8f741d
21 changed files with 164 additions and 26 deletions

View File

@ -1,15 +1,21 @@
import sys
const std {
in 0
out 1
err 2
}
in(buffer []Int8) -> Int {
return sys.read(0, buffer, len(buffer))
return sys.read(std.in, buffer, len(buffer))
}
out(buffer []Int8) -> Int {
return sys.write(1, buffer, len(buffer))
return sys.write(std.out, buffer, len(buffer))
}
error(buffer []Int8) -> Int {
return sys.write(2, buffer, len(buffer))
return sys.write(std.err, buffer, len(buffer))
}
read(fd Int, buffer []Int8) -> Int {

View File

@ -1,7 +1,17 @@
import sys
const prot {
read 0x1
write 0x2
}
const map {
private 0x02
anonymous 0x20
}
alloc(length Int) -> []Int8 {
x := sys.mmap(0, length+8, 0x1|0x2, 0x02|0x20)
x := sys.mmap(0, length+8, prot.read|prot.write, map.private|map.anonymous)
if x < 0x1000 {
return x

View File

@ -1,7 +1,17 @@
import sys
const prot {
read 0x1
write 0x2
}
const map {
private 0x02
anonymous 0x1000
}
alloc(length Int) -> []Int8 {
x := sys.mmap(0, length+8, 0x1|0x2, 0x02|0x1000)
x := sys.mmap(0, length+8, prot.read|prot.write, map.private|map.anonymous)
if x < 0x1000 {
return x

View File

@ -1,7 +1,16 @@
import sys
const page {
readwrite 0x0004
}
const mem {
commit 0x1000
reserve 0x2000
}
alloc(length Int) -> []Int8 {
x := sys.mmap(0, length+8, 0x0004, 0x3000)
x := sys.mmap(0, length+8, page.readwrite, mem.commit|mem.reserve)
if x < 0x1000 {
return x

View File

@ -3,10 +3,14 @@ extern kernel32 {
VirtualFree(address *Any, length Int, type Int) -> Bool
}
const mem {
decommit 0x4000
}
mmap(address Int, length Int, protection Int, flags Int) -> *Any {
return kernel32.VirtualAlloc(address, length, flags, protection)
}
munmap(address *Any, length Int) -> Int {
return kernel32.VirtualFree(address, length, 0x4000)
return kernel32.VirtualFree(address, length, mem.decommit)
}