diff --git a/examples/collatz/collatz.q b/examples/collatz/collatz.q index 5f71d2c..dab2869 100644 --- a/examples/collatz/collatz.q +++ b/examples/collatz/collatz.q @@ -5,7 +5,7 @@ main() { collatz(12) } -collatz(x Int) { +collatz(x int) { loop { if x & 1 == 0 { x /= 2 diff --git a/examples/factorial/factorial.q b/examples/factorial/factorial.q index 885fc2f..e34436f 100644 --- a/examples/factorial/factorial.q +++ b/examples/factorial/factorial.q @@ -4,7 +4,7 @@ main() { log.number(factorial(5)) } -factorial(x Int) -> Int { +factorial(x int) -> int { if x <= 1 { return 1 } diff --git a/examples/fibonacci/fibonacci.q b/examples/fibonacci/fibonacci.q index a071002..4d0f940 100644 --- a/examples/fibonacci/fibonacci.q +++ b/examples/fibonacci/fibonacci.q @@ -4,7 +4,7 @@ main() { log.number(fibonacci(10)) } -fibonacci(x Int) -> Int { +fibonacci(x int) -> int { if x <= 1 { return x } diff --git a/examples/fizzbuzz/fizzbuzz.q b/examples/fizzbuzz/fizzbuzz.q index 7823731..e626e7f 100644 --- a/examples/fizzbuzz/fizzbuzz.q +++ b/examples/fizzbuzz/fizzbuzz.q @@ -5,7 +5,7 @@ main() { fizzbuzz(15) } -fizzbuzz(n Int) { +fizzbuzz(n int) { x := 1 loop { diff --git a/examples/gcd/gcd.q b/examples/gcd/gcd.q index d952825..c9382b2 100644 --- a/examples/gcd/gcd.q +++ b/examples/gcd/gcd.q @@ -4,7 +4,7 @@ main() { log.number(gcd(1071, 462)) } -gcd(a Int, b Int) -> Int { +gcd(a int, b int) -> int { loop { switch { a == b { return a } diff --git a/examples/point/point.q b/examples/point/point.q index 4026af6..c2a7d5f 100644 --- a/examples/point/point.q +++ b/examples/point/point.q @@ -2,8 +2,8 @@ import mem import sys struct Point { - x Int - y Int + x int + y int } main() { @@ -12,7 +12,7 @@ main() { delete(p) } -construct(x Int, y Int) -> *Point { +construct(x int, y int) -> *Point { p := new(Point) p.x = x p.y = y diff --git a/examples/prime/prime.q b/examples/prime/prime.q index 76e3d77..e417cd8 100644 --- a/examples/prime/prime.q +++ b/examples/prime/prime.q @@ -22,7 +22,7 @@ main() { } } -isPrime(x Int) -> Int { +isPrime(x int) -> int { if x == 2 { return 1 } diff --git a/examples/winapi/winapi.q b/examples/winapi/winapi.q index a3f1dd7..c7a9c8e 100644 --- a/examples/winapi/winapi.q +++ b/examples/winapi/winapi.q @@ -1,5 +1,5 @@ extern user32 { - MessageBoxA(window *Any, text *Int8, title *Int8, type UInt) + MessageBoxA(window *any, text *int8, title *int8, flags uint) } main() { diff --git a/lib/core/core_windows.q b/lib/core/core_windows.q index 2b50ec1..b0acd58 100644 --- a/lib/core/core_windows.q +++ b/lib/core/core_windows.q @@ -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 { diff --git a/lib/io/io.q b/lib/io/io.q index 4b34566..c741271 100644 --- a/lib/io/io.q +++ b/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)) } \ No newline at end of file diff --git a/lib/log/number.q b/lib/log/number.q index 0dc6e55..c292167 100644 --- a/lib/log/number.q +++ b/lib/log/number.q @@ -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 diff --git a/lib/mem/alloc_linux.q b/lib/mem/alloc_linux.q index 8ade3e6..78e403c 100644 --- a/lib/mem/alloc_linux.q +++ b/lib/mem/alloc_linux.q @@ -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 { diff --git a/lib/mem/alloc_mac.q b/lib/mem/alloc_mac.q index cdfbe86..e45eaf4 100644 --- a/lib/mem/alloc_mac.q +++ b/lib/mem/alloc_mac.q @@ -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 { diff --git a/lib/mem/alloc_windows.q b/lib/mem/alloc_windows.q index 3167a43..3a4b0a4 100644 --- a/lib/mem/alloc_windows.q +++ b/lib/mem/alloc_windows.q @@ -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 { diff --git a/lib/mem/free.q b/lib/mem/free.q index 2568b2b..2c61b78 100644 --- a/lib/mem/free.q +++ b/lib/mem/free.q @@ -1,5 +1,5 @@ import sys -free(address []Any) -> Int { +free(address []any) -> int { return sys.munmap(address-8, len(address)+8) } \ No newline at end of file diff --git a/lib/net/htons.q b/lib/net/htons.q index c491d9b..8e414c6 100644 --- a/lib/net/htons.q +++ b/lib/net/htons.q @@ -1,3 +1,3 @@ -htons(num Int) -> Int { +htons(num int) -> int { return ((num & 0xFF) << 8) | (num >> 8) } \ No newline at end of file diff --git a/lib/net/net_linux.q b/lib/net/net_linux.q index 4f226aa..4a025e3 100644 --- a/lib/net/net_linux.q +++ b/lib/net/net_linux.q @@ -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) diff --git a/lib/net/net_mac.q b/lib/net/net_mac.q index 5a6cb00..ce2de78 100644 --- a/lib/net/net_mac.q +++ b/lib/net/net_mac.q @@ -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) diff --git a/lib/sys/fs_linux.q b/lib/sys/fs_linux.q index 11b7503..2eda9ff 100644 --- a/lib/sys/fs_linux.q +++ b/lib/sys/fs_linux.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/io_linux.q b/lib/sys/io_linux.q index d204bb4..d70e220 100644 --- a/lib/sys/io_linux.q +++ b/lib/sys/io_linux.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/io_mac.q b/lib/sys/io_mac.q index 8fc3dbd..87f7adc 100644 --- a/lib/sys/io_mac.q +++ b/lib/sys/io_mac.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/io_windows.q b/lib/sys/io_windows.q index 81351c3..29fc51a 100644 --- a/lib/sys/io_windows.q +++ b/lib/sys/io_windows.q @@ -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 diff --git a/lib/sys/mem_linux.q b/lib/sys/mem_linux.q index 5821426..14dca51 100644 --- a/lib/sys/mem_linux.q +++ b/lib/sys/mem_linux.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/mem_mac.q b/lib/sys/mem_mac.q index 6bf509d..2b0d33b 100644 --- a/lib/sys/mem_mac.q +++ b/lib/sys/mem_mac.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/mem_windows.q b/lib/sys/mem_windows.q index 97772e9..cdcc65e 100644 --- a/lib/sys/mem_windows.q +++ b/lib/sys/mem_windows.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/net_linux.q b/lib/sys/net_linux.q index 6e2e53c..d4977bc 100644 --- a/lib/sys/net_linux.q +++ b/lib/sys/net_linux.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/net_mac.q b/lib/sys/net_mac.q index ca0a735..f143b1e 100644 --- a/lib/sys/net_mac.q +++ b/lib/sys/net_mac.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/proc_linux.q b/lib/sys/proc_linux.q index 3540b0c..6a6491b 100644 --- a/lib/sys/proc_linux.q +++ b/lib/sys/proc_linux.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/proc_mac.q b/lib/sys/proc_mac.q index aa3454a..a3dc367 100644 --- a/lib/sys/proc_mac.q +++ b/lib/sys/proc_mac.q @@ -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) } \ No newline at end of file diff --git a/lib/sys/proc_windows.q b/lib/sys/proc_windows.q index c5c4cdc..b846e5c 100644 --- a/lib/sys/proc_windows.q +++ b/lib/sys/proc_windows.q @@ -1,7 +1,7 @@ extern kernel32 { - ExitProcess(code UInt) + ExitProcess(code uint) } -exit(code Int) { +exit(code int) { kernel32.ExitProcess(code) } \ No newline at end of file diff --git a/lib/sys/time_linux.q b/lib/sys/time_linux.q index f2957d3..3099f60 100644 --- a/lib/sys/time_linux.q +++ b/lib/sys/time_linux.q @@ -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) } \ No newline at end of file diff --git a/lib/thread/thread_linux.q b/lib/thread/thread_linux.q index 98b4d6f..e57fa17 100644 --- a/lib/thread/thread_linux.q +++ b/lib/thread/thread_linux.q @@ -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 diff --git a/lib/thread/thread_windows.q b/lib/thread/thread_windows.q index 0faef0d..0885bd1 100644 --- a/lib/thread/thread_windows.q +++ b/lib/thread/thread_windows.q @@ -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) } \ No newline at end of file diff --git a/lib/time/time.q b/lib/time/time.q index b39dbe8..9d459d8 100644 --- a/lib/time/time.q +++ b/lib/time/time.q @@ -1,6 +1,6 @@ import sys -sleep(nanoseconds Int) { +sleep(nanoseconds int) { seconds := 0 if nanoseconds >= 1000000000 { diff --git a/src/core/ExpressionToRegister.go b/src/core/ExpressionToRegister.go index d2b0cae..56ce93e 100644 --- a/src/core/ExpressionToRegister.go +++ b/src/core/ExpressionToRegister.go @@ -144,10 +144,6 @@ func (f *Function) ExpressionToRegister(node *expression.Expression, register cp return nil, err } - if typ == types.AnyPointer && right.Token.Kind == token.Identifier && f.VariableByName(right.Token.Text(f.File.Bytes)).Type == types.AnyPointer { - typ = types.Int - } - err = f.Execute(node.Token, register, right) if register != final { @@ -155,5 +151,17 @@ func (f *Function) ExpressionToRegister(node *expression.Expression, register cp f.FreeRegister(register) } + _, isArray := typ.(*types.Array) + + if isArray { + typ = types.AnyPointer + } else if right.Token.Kind == token.Identifier { + rightVariable := f.VariableByName(right.Token.Text(f.File.Bytes)) + + if typ == types.AnyPointer && rightVariable.Type == types.AnyPointer { + typ = types.Int + } + } + return typ, err } diff --git a/src/types/Array.go b/src/types/Array.go index d46b216..fd6add2 100644 --- a/src/types/Array.go +++ b/src/types/Array.go @@ -9,10 +9,6 @@ type Array struct { // Name returns the type name. func (a *Array) Name() string { - if a.Of == Any { - return "[]Any" - } - return "[]" + a.Of.Name() } diff --git a/src/types/ByName.go b/src/types/ByName.go index 27ac5fc..bba1c17 100644 --- a/src/types/ByName.go +++ b/src/types/ByName.go @@ -29,28 +29,36 @@ func ByName(name string, pkg string, structs map[string]*Struct) Type { } switch name { - case "Any": - return Any - case "Bool": - return Bool - case "Int": + case "int": return Int - case "Int64": + case "int64": return Int64 - case "Int32": + case "int32": return Int32 - case "Int16": + case "int16": return Int16 - case "Int8": + case "int8": return Int8 - case "Float": - return Float - case "Float64": - return Float64 - case "Float32": - return Float32 - case "UInt": + case "uint": return UInt + case "uint64": + return UInt64 + case "uint32": + return UInt32 + case "uint16": + return UInt16 + case "uint8": + return UInt8 + case "float": + return Float + case "float64": + return Float64 + case "float32": + return Float32 + case "bool": + return Bool + case "any": + return Any } typ, exists := structs[pkg+"."+name] diff --git a/src/types/Common.go b/src/types/Common.go index aab4a96..a846b61 100644 --- a/src/types/Common.go +++ b/src/types/Common.go @@ -1,20 +1,24 @@ package types var ( - Any = &Base{name: "Any", size: 0} + Any = &Base{name: "any", size: 0} AnyArray = &Array{Of: Any} AnyPointer = &Pointer{To: Any} - Int64 = &Base{name: "Int64", size: 8} - Int32 = &Base{name: "Int32", size: 4} - Int16 = &Base{name: "Int16", size: 2} - Int8 = &Base{name: "Int8", size: 1} - Float64 = &Base{name: "Float64", size: 8} - Float32 = &Base{name: "Float32", size: 4} + Int64 = &Base{name: "int64", size: 8} + Int32 = &Base{name: "int32", size: 4} + Int16 = &Base{name: "int16", size: 2} + Int8 = &Base{name: "int8", size: 1} + Float64 = &Base{name: "float64", size: 8} + Float32 = &Base{name: "float32", size: 4} ) var ( - Bool = Int - Int = Int64 - Float = Float64 - UInt = Int + Bool = Int + Int = Int64 + Float = Float64 + UInt = Int + UInt64 = Int64 + UInt32 = Int32 + UInt16 = Int16 + UInt8 = Int8 ) diff --git a/src/types/Is.go b/src/types/Is.go index 438b917..4134701 100644 --- a/src/types/Is.go +++ b/src/types/Is.go @@ -25,5 +25,10 @@ func Is(a Type, b Type) bool { return true } + // Temporary hack for implicit casts + if a.Size() > b.Size() { + return true + } + return false } diff --git a/src/types/Pointer.go b/src/types/Pointer.go index 1cf180b..1037776 100644 --- a/src/types/Pointer.go +++ b/src/types/Pointer.go @@ -7,10 +7,6 @@ type Pointer struct { // Name returns the type name. func (p *Pointer) Name() string { - if p.To == nil { - return "*Any" - } - return "*" + p.To.Name() } diff --git a/src/types/types_test.go b/src/types/types_test.go index e19602c..e3cb03e 100644 --- a/src/types/types_test.go +++ b/src/types/types_test.go @@ -8,12 +8,12 @@ import ( ) func TestName(t *testing.T) { - assert.Equal(t, types.Int.Name(), "Int64") - assert.Equal(t, types.AnyArray.Name(), "[]Any") - assert.Equal(t, types.AnyPointer.Name(), "*Any") - assert.Equal(t, (&types.Pointer{To: types.Int}).Name(), "*Int64") - assert.Equal(t, (&types.Array{Of: types.Int}).Name(), "[]Int64") - assert.Equal(t, types.String.Name(), "[]Int8") + assert.Equal(t, types.Int.Name(), "int64") + assert.Equal(t, types.AnyArray.Name(), "[]any") + assert.Equal(t, types.AnyPointer.Name(), "*any") + assert.Equal(t, (&types.Pointer{To: types.Int}).Name(), "*int64") + assert.Equal(t, (&types.Array{Of: types.Int}).Name(), "[]int64") + assert.Equal(t, types.String.Name(), "[]int8") } func TestSize(t *testing.T) { @@ -32,7 +32,7 @@ func TestStruct(t *testing.T) { s := types.NewStruct("main", "Test") assert.Equal(t, s.Name(), "Test") assert.Equal(t, s.Size(), 0) - field := &types.Field{Name: "TestField", TypeName: "Int8"} + field := &types.Field{Name: "TestField", TypeName: "int8"} s.AddField(field) s.Update(nil) assert.Equal(t, s.Size(), 1) diff --git a/tests/errors/MissingParameter2.q b/tests/errors/MissingParameter2.q index fd8af14..827b8d8 100644 --- a/tests/errors/MissingParameter2.q +++ b/tests/errors/MissingParameter2.q @@ -1 +1 @@ -f(a Int,) -> Int { return a } \ No newline at end of file +f(a int,) -> int { return a } \ No newline at end of file diff --git a/tests/errors/MissingParameter3.q b/tests/errors/MissingParameter3.q index 6b4650b..839bf40 100644 --- a/tests/errors/MissingParameter3.q +++ b/tests/errors/MissingParameter3.q @@ -1 +1 @@ -f(,a Int) {} \ No newline at end of file +f(,a int) {} \ No newline at end of file diff --git a/tests/errors/TypeMismatch.q b/tests/errors/TypeMismatch.q index 57bdd6b..09d6221 100644 --- a/tests/errors/TypeMismatch.q +++ b/tests/errors/TypeMismatch.q @@ -2,6 +2,6 @@ main() { writeToMemory(42) } -writeToMemory(p *Any) { +writeToMemory(p *any) { p[0] = 'A' } \ No newline at end of file diff --git a/tests/errors/UnknownIdentifier3.q b/tests/errors/UnknownIdentifier3.q index 4cc4927..4295081 100644 --- a/tests/errors/UnknownIdentifier3.q +++ b/tests/errors/UnknownIdentifier3.q @@ -2,6 +2,6 @@ main() { x := 1 + f(x) } -f(x Int) -> Int { +f(x int) -> int { return x } \ No newline at end of file diff --git a/tests/errors_test.go b/tests/errors_test.go index 7b3812e..781b662 100644 --- a/tests/errors_test.go +++ b/tests/errors_test.go @@ -49,8 +49,8 @@ var errs = []struct { {"MissingParameter3.q", errors.MissingParameter}, {"MissingType.q", errors.MissingType}, {"ReturnCountMismatch.q", &errors.ReturnCountMismatch{Count: 1, ExpectedCount: 0}}, - {"TypeMismatch.q", &errors.TypeMismatch{Expected: "*Any", Encountered: "Int64", ParameterName: "p"}}, - {"TypeMismatch2.q", &errors.TypeMismatch{Expected: "[]Any", Encountered: "Int64", ParameterName: "array"}}, + {"TypeMismatch.q", &errors.TypeMismatch{Expected: "*any", Encountered: "int64", ParameterName: "p"}}, + {"TypeMismatch2.q", &errors.TypeMismatch{Expected: "[]any", Encountered: "int64", ParameterName: "array"}}, {"UnknownFunction.q", &errors.UnknownFunction{Name: "unknown"}}, {"UnknownFunction2.q", &errors.UnknownFunction{Name: "f"}}, {"UnknownIdentifier.q", &errors.UnknownIdentifier{Name: "x"}}, diff --git a/tests/programs/branch-save.q b/tests/programs/branch-save.q index 75ad7bf..325880a 100644 --- a/tests/programs/branch-save.q +++ b/tests/programs/branch-save.q @@ -12,7 +12,7 @@ main() { assert b == 5 } -f(b Int) -> (Int, Int) { +f(b int) -> (int, int) { a := 0 if b >= 10 { diff --git a/tests/programs/branch.q b/tests/programs/branch.q index 171002b..92b6669 100644 --- a/tests/programs/branch.q +++ b/tests/programs/branch.q @@ -74,10 +74,10 @@ main() { sys.exit(1) } -inc(x Int) -> Int { +inc(x int) -> int { return x + 1 } -dec(x Int) -> Int { +dec(x int) -> int { return x - 1 } \ No newline at end of file diff --git a/tests/programs/chained-calls.q b/tests/programs/chained-calls.q index cd3c519..b9068c4 100644 --- a/tests/programs/chained-calls.q +++ b/tests/programs/chained-calls.q @@ -2,6 +2,6 @@ main() { assert f(1) + f(2) + f(3) == 9 } -f(x Int) -> Int { +f(x int) -> int { return x + 1 } \ No newline at end of file diff --git a/tests/programs/loop-lifetime.q b/tests/programs/loop-lifetime.q index d30489e..59f4164 100644 --- a/tests/programs/loop-lifetime.q +++ b/tests/programs/loop-lifetime.q @@ -12,6 +12,6 @@ main() { } } -f(x Int) -> Int { +f(x int) -> int { return x } \ No newline at end of file diff --git a/tests/programs/math.q b/tests/programs/math.q index 2de1b1b..cb79331 100644 --- a/tests/programs/math.q +++ b/tests/programs/math.q @@ -4,10 +4,10 @@ main() { assert result == 10 } -div(x Int, y Int) -> Int { +div(x int, y int) -> int { return x / y } -div10(x Int) -> Int { +div10(x int) -> int { return x / 10 } \ No newline at end of file diff --git a/tests/programs/negation.q b/tests/programs/negation.q index 089d4d7..07cf8ac 100644 --- a/tests/programs/negation.q +++ b/tests/programs/negation.q @@ -5,6 +5,6 @@ main() { assert neg(256) == -256 } -neg(x Int) -> Int { +neg(x int) -> int { return -x } \ No newline at end of file diff --git a/tests/programs/nested-calls.q b/tests/programs/nested-calls.q index e555b99..515a8d3 100644 --- a/tests/programs/nested-calls.q +++ b/tests/programs/nested-calls.q @@ -2,6 +2,6 @@ main() { assert f(f(f(1))) == 4 } -f(x Int) -> Int { +f(x int) -> int { return x + 1 } \ No newline at end of file diff --git a/tests/programs/op-assign.q b/tests/programs/op-assign.q index 257b6ac..85dd9c4 100644 --- a/tests/programs/op-assign.q +++ b/tests/programs/op-assign.q @@ -2,7 +2,7 @@ main() { f(10) } -f(new Int) { +f(new int) { old := new new -= 1 assert new != old diff --git a/tests/programs/param-multi.q b/tests/programs/param-multi.q index 0e19661..040ed48 100644 --- a/tests/programs/param-multi.q +++ b/tests/programs/param-multi.q @@ -2,11 +2,11 @@ main() { assert f(1, 2, 3) == 21 } -f(x Int, y Int, z Int) -> Int { +f(x int, y int, z int) -> int { w := g(4, 5, 6) return x + y + z + w } -g(x Int, y Int, z Int) -> Int { +g(x int, y int, z int) -> int { return x + y + z } \ No newline at end of file diff --git a/tests/programs/param-order.q b/tests/programs/param-order.q index 3e299b1..25ffd6d 100644 --- a/tests/programs/param-order.q +++ b/tests/programs/param-order.q @@ -2,11 +2,11 @@ main() { f1(1, 2, 3, 4, 5, 6) } -f1(a Int, b Int, c Int, d Int, e Int, f Int) { +f1(a int, b int, c int, d int, e int, f int) { f2(f, e, d, c, b, a) } -f2(a Int, b Int, c Int, d Int, e Int, f Int) { +f2(a int, b int, c int, d int, e int, f int) { assert a == 6 assert b == 5 assert c == 4 diff --git a/tests/programs/param.q b/tests/programs/param.q index 5e1628d..5efd3c1 100644 --- a/tests/programs/param.q +++ b/tests/programs/param.q @@ -2,11 +2,11 @@ main() { assert f(1) == 3 } -f(x Int) -> Int { +f(x int) -> int { y := g() return x + y } -g() -> Int { +g() -> int { return 2 } \ No newline at end of file diff --git a/tests/programs/return-multi.q b/tests/programs/return-multi.q index be81c42..1b5bd1a 100644 --- a/tests/programs/return-multi.q +++ b/tests/programs/return-multi.q @@ -15,14 +15,14 @@ main() { assert i == 1 + 4 } -reverse2(a Int, b Int) -> (Int, Int) { +reverse2(a int, b int) -> (int, int) { return b, a } -reverse3(a Int, b Int, c Int) -> (Int, Int, Int) { +reverse3(a int, b int, c int) -> (int, int, int) { return c, b, a } -mix4(a Int, b Int, c Int, d Int) -> (Int, Int, Int, Int) { +mix4(a int, b int, c int, d int) -> (int, int, int, int) { return d + a, c + b, b + c, a + d } \ No newline at end of file diff --git a/tests/programs/return.q b/tests/programs/return.q index 36095bc..abee37c 100644 --- a/tests/programs/return.q +++ b/tests/programs/return.q @@ -2,10 +2,10 @@ main() { assert f(2) == 6 } -f(x Int) -> Int { +f(x int) -> int { return x + 1 + g(x) } -g(x Int) -> Int { +g(x int) -> int { return x + 1 } \ No newline at end of file diff --git a/tests/programs/reuse.q b/tests/programs/reuse.q index 4658edb..109071e 100644 --- a/tests/programs/reuse.q +++ b/tests/programs/reuse.q @@ -2,6 +2,6 @@ main() { assert f(1) == 3 } -f(x Int) -> Int { +f(x int) -> int { return x + 1 + x } \ No newline at end of file diff --git a/tests/programs/square-sum.q b/tests/programs/square-sum.q index a9c0850..d97ba73 100644 --- a/tests/programs/square-sum.q +++ b/tests/programs/square-sum.q @@ -2,6 +2,6 @@ main() { assert f(2, 3) == 25 } -f(x Int, y Int) -> Int { +f(x int, y int) -> int { return (x + y) * (x + y) } \ No newline at end of file diff --git a/tests/programs/struct.q b/tests/programs/struct.q index 514a863..ad438c4 100644 --- a/tests/programs/struct.q +++ b/tests/programs/struct.q @@ -1,6 +1,6 @@ struct Point { - x Int - y Int + x int + y int } main() {