Moved const and extern identifiers to the left
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
const idtype {
|
idtype const {
|
||||||
pid 1
|
pid 1
|
||||||
}
|
}
|
||||||
|
|
||||||
const state {
|
state const {
|
||||||
exited 0x4
|
exited 0x4
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
extern user32 {
|
user32 extern {
|
||||||
MessageBoxA(window *any, text *byte, title *byte, flags uint) -> int
|
MessageBoxA(window *any, text *byte, title *byte, flags uint) -> int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
|
cp const {
|
||||||
|
utf8 65001
|
||||||
|
}
|
||||||
|
|
||||||
|
kernel32 extern {
|
||||||
|
SetConsoleCP(cp uint)
|
||||||
|
SetConsoleOutputCP(cp uint)
|
||||||
|
ExitProcess(code uint)
|
||||||
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
kernel32.SetConsoleCP(cp.utf8)
|
kernel32.SetConsoleCP(cp.utf8)
|
||||||
kernel32.SetConsoleOutputCP(cp.utf8)
|
kernel32.SetConsoleOutputCP(cp.utf8)
|
||||||
@ -11,14 +21,4 @@ exit() {
|
|||||||
|
|
||||||
crash() {
|
crash() {
|
||||||
kernel32.ExitProcess(1)
|
kernel32.ExitProcess(1)
|
||||||
}
|
|
||||||
|
|
||||||
const cp {
|
|
||||||
utf8 65001
|
|
||||||
}
|
|
||||||
|
|
||||||
extern kernel32 {
|
|
||||||
SetConsoleCP(cp uint)
|
|
||||||
SetConsoleOutputCP(cp uint)
|
|
||||||
ExitProcess(code uint)
|
|
||||||
}
|
}
|
18
lib/io/io.q
18
lib/io/io.q
@ -1,5 +1,23 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
std const {
|
||||||
|
in 0
|
||||||
|
out 1
|
||||||
|
err 2
|
||||||
|
}
|
||||||
|
|
||||||
|
in(buffer []byte) -> int {
|
||||||
|
return sys.read(std.in, buffer, len(buffer))
|
||||||
|
}
|
||||||
|
|
||||||
|
out(buffer []byte) -> int {
|
||||||
|
return sys.write(std.out, buffer, len(buffer))
|
||||||
|
}
|
||||||
|
|
||||||
|
error(buffer []byte) -> int {
|
||||||
|
return sys.write(std.err, buffer, len(buffer))
|
||||||
|
}
|
||||||
|
|
||||||
read(fd int, buffer []byte) -> int {
|
read(fd int, buffer []byte) -> int {
|
||||||
return sys.read(fd, buffer, len(buffer))
|
return sys.read(fd, buffer, len(buffer))
|
||||||
}
|
}
|
||||||
|
19
lib/io/std.q
19
lib/io/std.q
@ -1,19 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
in(buffer []byte) -> int {
|
|
||||||
return sys.read(std.in, buffer, len(buffer))
|
|
||||||
}
|
|
||||||
|
|
||||||
out(buffer []byte) -> int {
|
|
||||||
return sys.write(std.out, buffer, len(buffer))
|
|
||||||
}
|
|
||||||
|
|
||||||
error(buffer []byte) -> int {
|
|
||||||
return sys.write(std.err, buffer, len(buffer))
|
|
||||||
}
|
|
||||||
|
|
||||||
const std {
|
|
||||||
in 0
|
|
||||||
out 1
|
|
||||||
err 2
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
extern kernel32 {
|
kernel32 extern {
|
||||||
VirtualAlloc(address int, size uint, flags uint32, protection uint32) -> *any
|
VirtualAlloc(address int, size uint, flags uint32, protection uint32) -> *any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
const prot {
|
prot const {
|
||||||
read 0x1
|
read 0x1
|
||||||
write 0x2
|
write 0x2
|
||||||
}
|
}
|
||||||
|
|
||||||
const map {
|
map const {
|
||||||
private 0x02
|
private 0x02
|
||||||
anonymous 0x20
|
anonymous 0x20
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
const prot {
|
prot const {
|
||||||
read 0x1
|
read 0x1
|
||||||
write 0x2
|
write 0x2
|
||||||
}
|
}
|
||||||
|
|
||||||
const map {
|
map const {
|
||||||
private 0x02
|
private 0x02
|
||||||
anonymous 0x1000
|
anonymous 0x1000
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
const page {
|
page const {
|
||||||
readwrite 0x0004
|
readwrite 0x0004
|
||||||
}
|
}
|
||||||
|
|
||||||
const mem {
|
mem const {
|
||||||
commit 0x1000
|
commit 0x1000
|
||||||
reserve 0x2000
|
reserve 0x2000
|
||||||
decommit 0x4000
|
decommit 0x4000
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
extern kernel32 {
|
kernel32 extern {
|
||||||
VirtualFree(address *any, size uint, type uint32) -> bool
|
VirtualFree(address *any, size uint, type uint32) -> bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ write(fd int, buffer *byte, length int) -> int {
|
|||||||
return length
|
return length
|
||||||
}
|
}
|
||||||
|
|
||||||
extern kernel32 {
|
kernel32 extern {
|
||||||
GetStdHandle(handle int64) -> int64
|
GetStdHandle(handle int64) -> int64
|
||||||
ReadConsole(fd int64, buffer *byte, length uint32, written *uint32) -> bool
|
ReadConsole(fd int64, buffer *byte, length uint32, written *uint32) -> bool
|
||||||
WriteConsoleA(fd int64, buffer *byte, length uint32, written *uint32) -> bool
|
WriteConsoleA(fd int64, buffer *byte, length uint32, written *uint32) -> bool
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
import core
|
import core
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
clone const {
|
||||||
|
vm 0x100
|
||||||
|
fs 0x200
|
||||||
|
files 0x400
|
||||||
|
sighand 0x800
|
||||||
|
parent 0x8000
|
||||||
|
thread 0x10000
|
||||||
|
io 0x80000000
|
||||||
|
}
|
||||||
|
|
||||||
create(func *any) -> int {
|
create(func *any) -> int {
|
||||||
stack := sys.mmap(0, 4096, 0x1|0x2, 0x02|0x20|0x100)
|
stack := sys.mmap(0, 4096, 0x1|0x2, 0x02|0x20|0x100)
|
||||||
stack += 4096 - 8
|
stack += 4096 - 8
|
||||||
@ -8,14 +18,4 @@ create(func *any) -> int {
|
|||||||
stack -= 8
|
stack -= 8
|
||||||
store(stack, 8, func)
|
store(stack, 8, func)
|
||||||
return sys.clone(clone.vm|clone.fs|clone.files|clone.sighand|clone.parent|clone.thread|clone.io, stack, 0, 0, 0)
|
return sys.clone(clone.vm|clone.fs|clone.files|clone.sighand|clone.parent|clone.thread|clone.io, stack, 0, 0, 0)
|
||||||
}
|
|
||||||
|
|
||||||
const clone {
|
|
||||||
vm 0x100
|
|
||||||
fs 0x200
|
|
||||||
files 0x400
|
|
||||||
sighand 0x800
|
|
||||||
parent 0x8000
|
|
||||||
thread 0x10000
|
|
||||||
io 0x80000000
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
create(func *any) -> int {
|
kernel32 extern {
|
||||||
return kernel32.CreateThread(0, 4096, func, 0)
|
CreateThread(attributes int, stackSize int, address *any, parameter int) -> int
|
||||||
}
|
}
|
||||||
|
|
||||||
extern kernel32 {
|
create(func *any) -> int {
|
||||||
CreateThread(attributes int, stackSize int, address *any, parameter int) -> int
|
return kernel32.CreateThread(0, 4096, func, 0)
|
||||||
}
|
}
|
@ -2,12 +2,10 @@ package errors
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
EmptySwitch = &Base{"Empty switch"}
|
EmptySwitch = &Base{"Empty switch"}
|
||||||
ExpectedConstName = &Base{"Expected a name for the const group"}
|
|
||||||
InvalidDefinition = &Base{"Invalid definition"}
|
InvalidDefinition = &Base{"Invalid definition"}
|
||||||
ExpectedFunctionDefinition = &Base{"Expected function definition"}
|
ExpectedFunctionDefinition = &Base{"Expected function definition"}
|
||||||
ExpectedIfBeforeElse = &Base{"Expected an 'if' block before 'else'"}
|
ExpectedIfBeforeElse = &Base{"Expected an 'if' block before 'else'"}
|
||||||
ExpectedPackageName = &Base{"Expected package name"}
|
ExpectedPackageName = &Base{"Expected package name"}
|
||||||
ExpectedDLLName = &Base{"Expected DLL name"}
|
|
||||||
InvalidNumber = &Base{"Invalid number"}
|
InvalidNumber = &Base{"Invalid number"}
|
||||||
InvalidCondition = &Base{"Invalid condition"}
|
InvalidCondition = &Base{"Invalid condition"}
|
||||||
InvalidExpression = &Base{"Invalid expression"}
|
InvalidExpression = &Base{"Invalid expression"}
|
||||||
|
@ -9,14 +9,8 @@ import (
|
|||||||
|
|
||||||
// scanConst scans a block of constants.
|
// scanConst scans a block of constants.
|
||||||
func (s *Scanner) scanConst(file *fs.File, tokens token.List, i int) (int, error) {
|
func (s *Scanner) scanConst(file *fs.File, tokens token.List, i int) (int, error) {
|
||||||
i++
|
|
||||||
|
|
||||||
if tokens[i].Kind != token.Identifier {
|
|
||||||
return i, errors.New(errors.ExpectedConstName, file, tokens[i].Position)
|
|
||||||
}
|
|
||||||
|
|
||||||
groupName := tokens[i].Text(file.Bytes)
|
groupName := tokens[i].Text(file.Bytes)
|
||||||
i++
|
i += 2
|
||||||
|
|
||||||
if tokens[i].Kind != token.BlockStart {
|
if tokens[i].Kind != token.BlockStart {
|
||||||
return i, errors.New(errors.MissingBlockStart, file, tokens[i].Position)
|
return i, errors.New(errors.MissingBlockStart, file, tokens[i].Position)
|
||||||
|
@ -8,14 +8,8 @@ import (
|
|||||||
|
|
||||||
// scanExtern scans a block of external function declarations.
|
// scanExtern scans a block of external function declarations.
|
||||||
func (s *Scanner) scanExtern(file *fs.File, tokens token.List, i int) (int, error) {
|
func (s *Scanner) scanExtern(file *fs.File, tokens token.List, i int) (int, error) {
|
||||||
i++
|
|
||||||
|
|
||||||
if tokens[i].Kind != token.Identifier {
|
|
||||||
return i, errors.New(errors.ExpectedDLLName, file, tokens[i].Position)
|
|
||||||
}
|
|
||||||
|
|
||||||
dllName := tokens[i].Text(file.Bytes)
|
dllName := tokens[i].Text(file.Bytes)
|
||||||
i++
|
i += 2
|
||||||
|
|
||||||
if tokens[i].Kind != token.BlockStart {
|
if tokens[i].Kind != token.BlockStart {
|
||||||
return i, errors.New(errors.MissingBlockStart, file, tokens[i].Position)
|
return i, errors.New(errors.MissingBlockStart, file, tokens[i].Position)
|
||||||
|
@ -43,6 +43,10 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
|||||||
i, err = s.scanFunction(file, tokens, i)
|
i, err = s.scanFunction(file, tokens, i)
|
||||||
case token.BlockStart:
|
case token.BlockStart:
|
||||||
i, err = s.scanStruct(file, tokens, i)
|
i, err = s.scanStruct(file, tokens, i)
|
||||||
|
case token.Extern:
|
||||||
|
i, err = s.scanExtern(file, tokens, i)
|
||||||
|
case token.Const:
|
||||||
|
i, err = s.scanConst(file, tokens, i)
|
||||||
case token.GroupEnd:
|
case token.GroupEnd:
|
||||||
return errors.New(errors.MissingGroupStart, file, next.Position)
|
return errors.New(errors.MissingGroupStart, file, next.Position)
|
||||||
case token.BlockEnd:
|
case token.BlockEnd:
|
||||||
@ -54,10 +58,6 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
|||||||
}
|
}
|
||||||
case token.Import:
|
case token.Import:
|
||||||
i, err = s.scanImport(file, tokens, i)
|
i, err = s.scanImport(file, tokens, i)
|
||||||
case token.Extern:
|
|
||||||
i, err = s.scanExtern(file, tokens, i)
|
|
||||||
case token.Const:
|
|
||||||
i, err = s.scanConst(file, tokens, i)
|
|
||||||
case token.EOF:
|
case token.EOF:
|
||||||
return nil
|
return nil
|
||||||
case token.Invalid:
|
case token.Invalid:
|
||||||
|
@ -1 +0,0 @@
|
|||||||
extern {}
|
|
@ -15,7 +15,6 @@ var errs = []struct {
|
|||||||
ExpectedError error
|
ExpectedError error
|
||||||
}{
|
}{
|
||||||
{"EmptySwitch.q", errors.EmptySwitch},
|
{"EmptySwitch.q", errors.EmptySwitch},
|
||||||
{"ExpectedDLLName.q", errors.ExpectedDLLName},
|
|
||||||
{"ExpectedFunctionDefinition.q", errors.ExpectedFunctionDefinition},
|
{"ExpectedFunctionDefinition.q", errors.ExpectedFunctionDefinition},
|
||||||
{"ExpectedIfBeforeElse.q", errors.ExpectedIfBeforeElse},
|
{"ExpectedIfBeforeElse.q", errors.ExpectedIfBeforeElse},
|
||||||
{"ExpectedIfBeforeElse2.q", errors.ExpectedIfBeforeElse},
|
{"ExpectedIfBeforeElse2.q", errors.ExpectedIfBeforeElse},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const num {
|
num const {
|
||||||
one 1
|
one 1
|
||||||
two 2
|
two 2
|
||||||
three 3
|
three 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user