Improved type system
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
extern kernel32 {
|
||||
SetConsoleCP(cp UInt)
|
||||
SetConsoleOutputCP(cp UInt)
|
||||
ExitProcess(code UInt)
|
||||
SetConsoleCP(cp uint)
|
||||
SetConsoleOutputCP(cp uint)
|
||||
ExitProcess(code uint)
|
||||
}
|
||||
|
||||
const cp {
|
||||
|
10
lib/io/io.q
10
lib/io/io.q
@ -6,22 +6,22 @@ const std {
|
||||
err 2
|
||||
}
|
||||
|
||||
in(buffer []Int8) -> Int {
|
||||
in(buffer []int8) -> int {
|
||||
return sys.read(std.in, buffer, len(buffer))
|
||||
}
|
||||
|
||||
out(buffer []Int8) -> Int {
|
||||
out(buffer []int8) -> int {
|
||||
return sys.write(std.out, buffer, len(buffer))
|
||||
}
|
||||
|
||||
error(buffer []Int8) -> Int {
|
||||
error(buffer []int8) -> int {
|
||||
return sys.write(std.err, buffer, len(buffer))
|
||||
}
|
||||
|
||||
read(fd Int, buffer []Int8) -> Int {
|
||||
read(fd int, buffer []int8) -> int {
|
||||
return sys.read(fd, buffer, len(buffer))
|
||||
}
|
||||
|
||||
write(fd Int, buffer []Int8) -> Int {
|
||||
write(fd int, buffer []int8) -> int {
|
||||
return sys.write(fd, buffer, len(buffer))
|
||||
}
|
@ -1,16 +1,15 @@
|
||||
import mem
|
||||
import sys
|
||||
|
||||
number(x Int) {
|
||||
length := 20
|
||||
buffer := mem.alloc(length)
|
||||
address, count := itoa(x, buffer, length)
|
||||
number(x int) {
|
||||
buffer := mem.alloc(20)
|
||||
address, count := itoa(x, buffer)
|
||||
sys.write(1, address, count)
|
||||
mem.free(buffer)
|
||||
}
|
||||
|
||||
itoa(x Int, buffer *Any, length Int) -> (*Any, Int) {
|
||||
end := buffer + length
|
||||
itoa(x int, buffer []int8) -> (*any, int) {
|
||||
end := buffer + len(buffer)
|
||||
tmp := end
|
||||
digit := 0
|
||||
|
||||
|
@ -10,7 +10,7 @@ const map {
|
||||
anonymous 0x20
|
||||
}
|
||||
|
||||
alloc(length Int) -> []Int8 {
|
||||
alloc(length int) -> []int8 {
|
||||
x := sys.mmap(0, length+8, prot.read|prot.write, map.private|map.anonymous)
|
||||
|
||||
if x < 0x1000 {
|
||||
|
@ -10,7 +10,7 @@ const map {
|
||||
anonymous 0x1000
|
||||
}
|
||||
|
||||
alloc(length Int) -> []Int8 {
|
||||
alloc(length int) -> []int8 {
|
||||
x := sys.mmap(0, length+8, prot.read|prot.write, map.private|map.anonymous)
|
||||
|
||||
if x < 0x1000 {
|
||||
|
@ -9,7 +9,7 @@ const mem {
|
||||
reserve 0x2000
|
||||
}
|
||||
|
||||
alloc(length Int) -> []Int8 {
|
||||
alloc(length int) -> []int8 {
|
||||
x := sys.mmap(0, length+8, page.readwrite, mem.commit|mem.reserve)
|
||||
|
||||
if x < 0x1000 {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import sys
|
||||
|
||||
free(address []Any) -> Int {
|
||||
free(address []any) -> int {
|
||||
return sys.munmap(address-8, len(address)+8)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
htons(num Int) -> Int {
|
||||
htons(num int) -> int {
|
||||
return ((num & 0xFF) << 8) | (num >> 8)
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import sys
|
||||
|
||||
bind(socket Int, port Int) -> Int {
|
||||
bind(socket int, port int) -> int {
|
||||
addr := new(sys.sockaddr_in)
|
||||
addr.sin_family = 2
|
||||
addr.sin_port = htons(port)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import sys
|
||||
|
||||
bind(socket Int, port Int) -> Int {
|
||||
bind(socket int, port int) -> int {
|
||||
addr := new(sys.sockaddr_in_bsd)
|
||||
addr.sin_family = 2
|
||||
addr.sin_port = htons(port)
|
||||
|
@ -1,23 +1,23 @@
|
||||
getcwd(buffer *Any, length Int) -> Int {
|
||||
getcwd(buffer *any, length int) -> int {
|
||||
return syscall(79, buffer, length)
|
||||
}
|
||||
|
||||
chdir(path *Any) -> Int {
|
||||
chdir(path *any) -> int {
|
||||
return syscall(80, path)
|
||||
}
|
||||
|
||||
rename(old *Any, new *Any) -> Int {
|
||||
rename(old *any, new *any) -> int {
|
||||
return syscall(82, old, new)
|
||||
}
|
||||
|
||||
mkdir(path *Any, mode Int) -> Int {
|
||||
mkdir(path *any, mode int) -> int {
|
||||
return syscall(83, path, mode)
|
||||
}
|
||||
|
||||
rmdir(path *Any) -> Int {
|
||||
rmdir(path *any) -> int {
|
||||
return syscall(84, path)
|
||||
}
|
||||
|
||||
unlink(file *Any) -> Int {
|
||||
unlink(file *any) -> int {
|
||||
return syscall(87, file)
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
read(fd Int, buffer *Any, length Int) -> Int {
|
||||
read(fd int, buffer *any, length int) -> int {
|
||||
return syscall(0, fd, buffer, length)
|
||||
}
|
||||
|
||||
write(fd Int, buffer *Any, length Int) -> Int {
|
||||
write(fd int, buffer *any, length int) -> int {
|
||||
return syscall(1, fd, buffer, length)
|
||||
}
|
||||
|
||||
open(path *Any, flags Int, mode Int) -> Int {
|
||||
open(path *any, flags int, mode int) -> int {
|
||||
return syscall(2, path, flags, mode)
|
||||
}
|
||||
|
||||
close(fd Int) -> Int {
|
||||
close(fd int) -> int {
|
||||
return syscall(3, fd)
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
read(fd Int, buffer *Any, length Int) -> Int {
|
||||
read(fd int, buffer *any, length int) -> int {
|
||||
return syscall(0x2000003, fd, buffer, length)
|
||||
}
|
||||
|
||||
write(fd Int, buffer *Any, length Int) -> Int {
|
||||
write(fd int, buffer *any, length int) -> int {
|
||||
return syscall(0x2000004, fd, buffer, length)
|
||||
}
|
||||
|
||||
open(path *Any, flags Int, mode Int) -> Int {
|
||||
open(path *any, flags int, mode int) -> int {
|
||||
return syscall(0x2000005, path, flags, mode)
|
||||
}
|
||||
|
||||
close(fd Int) -> Int {
|
||||
close(fd int) -> int {
|
||||
return syscall(0x2000006, fd)
|
||||
}
|
@ -1,15 +1,16 @@
|
||||
extern kernel32 {
|
||||
GetStdHandle(handle Int) -> Int
|
||||
WriteConsoleA(fd Int, buffer *Any, length Int, written *Int) -> Bool
|
||||
ReadFile(fd Int, buffer *Any, length Int) -> Bool
|
||||
GetStdHandle(handle int64) -> int64
|
||||
WriteConsoleA(fd int64, buffer *any, length uint32, written *uint32) -> bool
|
||||
ReadConsole(fd int64, buffer *any, length uint32, written *uint32) -> bool
|
||||
}
|
||||
|
||||
read(fd Int, buffer *Any, length Int) -> Int {
|
||||
kernel32.ReadFile(fd, buffer, length)
|
||||
read(fd int64, buffer *any, length int64) -> int64 {
|
||||
fd = kernel32.GetStdHandle(-10 - fd)
|
||||
kernel32.ReadConsole(fd, buffer, length, 0)
|
||||
return length
|
||||
}
|
||||
|
||||
write(fd Int, buffer *Any, length Int) -> Int {
|
||||
write(fd int64, buffer *any, length int64) -> int64 {
|
||||
fd = kernel32.GetStdHandle(-10 - fd)
|
||||
kernel32.WriteConsoleA(fd, buffer, length, 0)
|
||||
return length
|
||||
|
@ -1,7 +1,7 @@
|
||||
mmap(address Int, length Int, protection Int, flags Int) -> *Any {
|
||||
mmap(address int, length int, protection int, flags int) -> *any {
|
||||
return syscall(9, address, length, protection, flags)
|
||||
}
|
||||
|
||||
munmap(address *Any, length Int) -> Int {
|
||||
munmap(address *any, length int) -> int {
|
||||
return syscall(11, address, length)
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
mmap(address Int, length Int, protection Int, flags Int) -> *Any {
|
||||
mmap(address int, length int, protection int, flags int) -> *any {
|
||||
return syscall(0x20000C5, address, length, protection, flags)
|
||||
}
|
||||
|
||||
munmap(address *Any, length Int) -> Int {
|
||||
munmap(address *any, length int) -> int {
|
||||
return syscall(0x2000049, address, length)
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
extern kernel32 {
|
||||
VirtualAlloc(address Int, length Int, flags Int, protection Int)
|
||||
VirtualFree(address *Any, length Int, type Int) -> Bool
|
||||
VirtualAlloc(address int, length int, flags int, protection int)
|
||||
VirtualFree(address *any, length int, type int) -> bool
|
||||
}
|
||||
|
||||
const mem {
|
||||
decommit 0x4000
|
||||
}
|
||||
|
||||
mmap(address Int, length Int, protection Int, flags Int) -> *Any {
|
||||
mmap(address int, length int, protection int, flags int) -> *any {
|
||||
return kernel32.VirtualAlloc(address, length, flags, protection)
|
||||
}
|
||||
|
||||
munmap(address *Any, length Int) -> Int {
|
||||
munmap(address *any, length int) -> int {
|
||||
return kernel32.VirtualFree(address, length, mem.decommit)
|
||||
}
|
@ -1,26 +1,26 @@
|
||||
struct sockaddr_in {
|
||||
sin_family Int16
|
||||
sin_port Int16
|
||||
sin_addr Int64
|
||||
sin_zero Int64
|
||||
sin_family int16
|
||||
sin_port int16
|
||||
sin_addr int64
|
||||
sin_zero int64
|
||||
}
|
||||
|
||||
socket(family Int, type Int, protocol Int) -> Int {
|
||||
socket(family int, type int, protocol int) -> int {
|
||||
return syscall(41, family, type, protocol)
|
||||
}
|
||||
|
||||
accept(fd Int, address *Any, length Int) -> Int {
|
||||
accept(fd int, address *any, length int) -> int {
|
||||
return syscall(43, fd, address, length)
|
||||
}
|
||||
|
||||
bind(fd Int, address *sockaddr_in, length Int) -> Int {
|
||||
bind(fd int, address *sockaddr_in, length int) -> int {
|
||||
return syscall(49, fd, address, length)
|
||||
}
|
||||
|
||||
listen(fd Int, backlog Int) -> Int {
|
||||
listen(fd int, backlog int) -> int {
|
||||
return syscall(50, fd, backlog)
|
||||
}
|
||||
|
||||
setsockopt(fd Int, level Int, optname Int, optval *Any, optlen Int) -> Int {
|
||||
setsockopt(fd int, level int, optname int, optval *any, optlen int) -> int {
|
||||
return syscall(54, fd, level, optname, optval, optlen)
|
||||
}
|
@ -1,23 +1,23 @@
|
||||
struct sockaddr_in_bsd {
|
||||
sin_len Int8
|
||||
sin_family Int8
|
||||
sin_port Int16
|
||||
sin_addr Int64
|
||||
sin_zero Int64
|
||||
sin_len int8
|
||||
sin_family int8
|
||||
sin_port int16
|
||||
sin_addr int64
|
||||
sin_zero int64
|
||||
}
|
||||
|
||||
socket(family Int, type Int, protocol Int) -> Int {
|
||||
socket(family int, type int, protocol int) -> int {
|
||||
return syscall(0x2000061, family, type, protocol)
|
||||
}
|
||||
|
||||
accept(fd Int, address *Any, length Int) -> Int {
|
||||
accept(fd int, address *any, length int) -> int {
|
||||
return syscall(0x200001E, fd, address, length)
|
||||
}
|
||||
|
||||
bind(fd Int, address *sockaddr_in_bsd, length Int) -> Int {
|
||||
bind(fd int, address *sockaddr_in_bsd, length int) -> int {
|
||||
return syscall(0x2000068, fd, address, length)
|
||||
}
|
||||
|
||||
listen(fd Int, backlog Int) -> Int {
|
||||
listen(fd int, backlog int) -> int {
|
||||
return syscall(0x200006A, fd, backlog)
|
||||
}
|
@ -1,19 +1,19 @@
|
||||
clone(flags Int, stack *Any) -> Int {
|
||||
clone(flags int, stack *any) -> int {
|
||||
return syscall(56, flags, stack)
|
||||
}
|
||||
|
||||
fork() -> Int {
|
||||
fork() -> int {
|
||||
return syscall(57)
|
||||
}
|
||||
|
||||
execve(path *Any, argv *Any, envp *Any) -> Int {
|
||||
execve(path *any, argv *any, envp *any) -> int {
|
||||
return syscall(59, path, argv, envp)
|
||||
}
|
||||
|
||||
exit(status Int) {
|
||||
exit(status int) {
|
||||
syscall(60, status)
|
||||
}
|
||||
|
||||
waitid(type Int, id Int, info *Any, options Int) -> Int {
|
||||
waitid(type int, id int, info *any, options int) -> int {
|
||||
return syscall(247, type, id, info, options)
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
exit(status Int) {
|
||||
exit(status int) {
|
||||
syscall(0x2000001, status)
|
||||
}
|
||||
|
||||
fork() -> Int {
|
||||
fork() -> int {
|
||||
return syscall(0x2000002)
|
||||
}
|
||||
|
||||
execve(path *Any, argv *Any, envp *Any) -> Int {
|
||||
execve(path *any, argv *any, envp *any) -> int {
|
||||
return syscall(0x200003B, path, argv, envp)
|
||||
}
|
||||
|
||||
waitid(type Int, id Int, info *Any, options Int) -> Int {
|
||||
waitid(type int, id int, info *any, options int) -> int {
|
||||
return syscall(0x20000AD, type, id, info, options)
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
extern kernel32 {
|
||||
ExitProcess(code UInt)
|
||||
ExitProcess(code uint)
|
||||
}
|
||||
|
||||
exit(code Int) {
|
||||
exit(code int) {
|
||||
kernel32.ExitProcess(code)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
struct timespec {
|
||||
seconds Int
|
||||
nanoseconds Int
|
||||
seconds int64
|
||||
nanoseconds int64
|
||||
}
|
||||
|
||||
nanosleep(duration *timespec) -> Int {
|
||||
nanosleep(duration *timespec) -> int {
|
||||
return syscall(35, duration, 0)
|
||||
}
|
@ -11,7 +11,7 @@ const clone {
|
||||
io 0x80000000
|
||||
}
|
||||
|
||||
create(func *Any) -> Int {
|
||||
create(func *any) -> int {
|
||||
size := 4096
|
||||
stack := sys.mmap(0, size, 0x1|0x2, 0x02|0x20|0x100|0x20000)
|
||||
stack += size
|
||||
|
@ -1,7 +1,7 @@
|
||||
extern kernel32 {
|
||||
CreateThread(attributes Int, stackSize Int, address *Any, parameter Int) -> Int
|
||||
CreateThread(attributes int, stackSize int, address *any, parameter int) -> int
|
||||
}
|
||||
|
||||
create(func *Any) -> Int {
|
||||
create(func *any) -> int {
|
||||
return kernel32.CreateThread(0, 4096, func, 0)
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import sys
|
||||
|
||||
sleep(nanoseconds Int) {
|
||||
sleep(nanoseconds int) {
|
||||
seconds := 0
|
||||
|
||||
if nanoseconds >= 1000000000 {
|
||||
|
Reference in New Issue
Block a user