Граф коммитов

105 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
ec50db729d
compiler: implement slicing slices 2018-09-13 20:49:35 +02:00
Ayke van Laethem
5b3ef2c02f
compiler: fix unreachable type assert
The unreachable instruction is actually a block terminator so may only
be inserted at the end of a basic block. This is not always the case for
type asserts, so don't insert this instruction.

LLVM will hopefully optimize it anyway when it realizes anything after
the panic() call is unreachable.
2018-09-13 20:48:23 +02:00
Ayke van Laethem
9cd7c7f0ba
compiler: fix phi nodes for type asserts
Type asserts insert more basic block, causing phi node values to be
invalid. Fix this by remembering the outgoing LLVM basic block.
2018-09-13 20:42:04 +02:00
Ayke van Laethem
57661a3c76
compiler: fix typeassert without comma-ok for unused types 2018-09-13 16:58:44 +02:00
Ayke van Laethem
8ce139284a
all: remove last traces of the C runtime
This increases code size on the nrf, but it is a fixed increase and can
hopefully be reduced in the future.
The Makefile gets a lot smaller with this which is a huge advantage
(less build time complexity).
2018-09-12 23:26:30 +02:00
Ayke van Laethem
2788ab0172
all: rename __reg to __volatile
It is less magical now: it only marks loads and stores as volatile. So
the name '__reg' is a bit wrong now.
2018-09-12 22:05:41 +02:00
Ayke van Laethem
865520b571
compiler: act as a compiler driver (on unix systems)
As a final step, link the object file with the system compiler/linker.
TODO: cross compiling.
2018-09-12 19:59:13 +02:00
Ayke van Laethem
6ab2b30984
compiler: move output file type selection to main.go 2018-09-12 19:11:50 +02:00
Ayke van Laethem
20c2552f8a
compiler: add 'run' command for bytecode interpretation 2018-09-12 17:26:56 +02:00
Ayke van Laethem
81b9edbe65
compiler: print() doesn't print spaces between arguments 2018-09-11 20:01:49 +02:00
Ayke van Laethem
8675025fc8
compiler: implement type assert without comma-ok 2018-09-11 19:51:31 +02:00
Ayke van Laethem
4ad6df3227
all: complete the implementation of interface asserts
Because a few things were left unimplemented it only happened to kind-of
work before in my test cases.
This commit should complete interface-to-interface type asserts.
2018-09-11 19:39:25 +02:00
Ayke van Laethem
61e6f7cf5b
compiler: add debug information for function parameters
Add 'optimized-out' parameters to functions. This might make debugging
slightly easier by showing parameter names.

Sadly I din't get setting variables to work. It might be a bug in
CreateExpression.
2018-09-11 17:00:24 +02:00
Ayke van Laethem
43b8c24226
compiler: implement interface assertions
This is a lot harder than 'regular' type assertions as the actual
methods need to be checked.
2018-09-06 20:18:18 +02:00
Ayke van Laethem
30ac6ec281
compiler: don't try to get pointer methods
I don't know why this was ever needed, but it seems to be incorrect and
unnecessary.
2018-09-06 20:04:41 +02:00
Ayke van Laethem
0f83c3b3c6
compiler: allow copying a string to a slice
Now that strings and slices are similar, this just works.
2018-09-06 10:53:18 +02:00
Ayke van Laethem
41a50ec336
compiler: simplify code for builtin len()
Strings and slices now have the len element at the same location.
2018-09-06 10:52:36 +02:00
Ayke van Laethem
31f494e611
all: swap string from {len, ptr} to {ptr, len} for slice compatibility
Having slices and strings be similar makes other code simpler.
2018-09-06 10:50:13 +02:00
Ayke van Laethem
5aa8b71ae1
compiler: implement builtin copy(dst, src []T)
Not implemented: copying a string into a []byte slice.
2018-09-06 10:37:44 +02:00
Ayke van Laethem
fd9fa038a9
compiler: fix make([]T, ...) type 2018-09-06 10:37:00 +02:00
Ayke van Laethem
094c5561b6
compiler: implement make([]T, ...) 2018-09-06 09:46:58 +02:00
Ayke van Laethem
ef2c406127
compiler: implement comparing a pointer against nil 2018-09-05 20:35:16 +02:00
Ayke van Laethem
f44d2f718f
compiler: rewrite defer support to better support them
This costs a bit in code size, but should be more flexible for the
future to implement recover() and running deferred functions while
panicking.
2018-09-05 20:34:17 +02:00
Ayke van Laethem
87dd1a1fe5
compiler: fix debug metadata
Not setting the correct debug location at function entry leads to
instructions getting the address of the previously emitted function,
which is of course wrong. LLVM complains about it when validating a
module.
2018-09-05 16:41:34 +02:00
Ayke van Laethem
17b5b6ec5b
all: use less magic in memory-mapped IO
Don't store addresses in the values of registers, this leads to problems
with char arrays (among others). Instead, do it like it's done in C with
raw addresses cast to struct pointers.

This commit also splits gen-device.py, as AVR and ARM have very
different ideas of what a register is. It's easier to just keep them
separate.
2018-09-05 12:18:21 +02:00
Ayke van Laethem
7258553528
compiler: implement const pointers from integers
These raw pointers are used for memory-mapped IO.
2018-09-05 11:15:33 +02:00
Ayke van Laethem
83ad0b6137
all: move bootstrapping IR to Go runtime
This has the benefit of not requiring a 'runtime' IR file, so that
complete relocatable files can be built without requiring input IR.
This makes the compiler a lot easier to use without the Makefile.

Code size is not affected.
2018-09-04 21:18:26 +02:00
Ayke van Laethem
0746d61639
compiler: move optimizer into the binary 2018-09-04 19:20:49 +02:00
Ayke van Laethem
c109ec0955
compiler: let a failed typeassert return the nil value
See the comment in the source for details.

The underlying type would be casted to the final one even before the
type is checked. This apparently led LLVM to think the type cast was OK,
so it speculatively dereferenced a pointer (while the underlying type
was an int). Speculatively dereferencing a pointer is fine when it is a
valid pointer, but when it is not it leads to a segfault (or worse).
This is what I saw, and it took me a while to figure out where it went
wrong.
2018-09-03 19:18:10 +02:00
Ayke van Laethem
efdc2b8672
compiler: add basic debug info
Only implements debugging with source lines and stacktraces (without
parameters), which already is a huge improvement over no debug
information at all. This should be extended to arguments and local
variables (of the correct DWARF type), but this is more work.
2018-09-03 19:17:44 +02:00
Ayke van Laethem
a7fcef62e0
compiler: implement comparing interfaces to nil
Comparing an interface to nil is easy, as the dynamic type is also nil.
Comparing the dynamic values (when the dynamic types match) is much
harder and depends on reflection capabilities, so is not yet implemented.
2018-09-03 01:13:07 +02:00
Ayke van Laethem
c100e4d67f
compiler: fix nil constant interface
A nil interface has no dynamic type (or: nil dynamic type). Don't try to
use the static type as the dynamic type, because these are different.
2018-09-03 01:01:24 +02:00
Ayke van Laethem
4ed04309a3
compiler: truncate shift amount when needed 2018-09-03 00:22:55 +02:00
Ayke van Laethem
ebd87ce4cd
compiler: implement []byte(str) 2018-09-03 00:21:33 +02:00
Ayke van Laethem
a080ce26ef
compiler: implement string slicing 2018-09-02 23:46:31 +02:00
Ayke van Laethem
1170cdc21f
compiler: implement Field expression
This expression is used when calling a method on an embedded type in a
struct.
2018-09-02 21:14:33 +02:00
Ayke van Laethem
9519f989bc
runtime/scheduler: make debugging easier + rename some functions
This shouldn't affect functionality but makes debugging a whole lot
easier. A scheduler is difficult so make it easy to debug.
2018-09-02 19:30:13 +02:00
Ayke van Laethem
1e90858145
Fix blocking functions
Don't think they're blocking when the scheduler has been disabled.
2018-09-02 18:39:39 +02:00
Ayke van Laethem
bfff0c33e4
Fix external globals
This broke the allocator on ARM, and with that the blinky example.
2018-09-02 18:37:28 +02:00
Ayke van Laethem
88b6b2e7f5
Optimize/eliminate bounds checking
TODO: do better at it by tracking min/max values of integers. The
following straightforward code doesn't have its bounds checks removed:

    for _, n := range slice {
        println(n)
    }
2018-09-02 16:28:46 +02:00
Ayke van Laethem
42cddd3260
Move runtime.TargetBits out of the compiler 2018-09-02 16:00:31 +02:00
Ayke van Laethem
9fca0e99b5
compiler: use InternalLinkage where appropriate
Internal linkage means that symbols show up in tools like objdump, which
is very useful for debugging.
2018-09-02 15:58:49 +02:00
Ayke van Laethem
58c87329d4
Implement closures and bound methods 2018-09-02 03:39:37 +02:00
Ayke van Laethem
58b853bbef
Defer for trivial cases 2018-09-01 17:14:38 +02:00
Ayke van Laethem
887814a69d
Be able to handle complex64 and complex128 types
No support for complex types yet, but at least be able to handle their
types.
2018-08-31 21:30:21 +02:00
Ayke van Laethem
94ce893ab4
Copy printfloat() from original runtime
I've tried writing my own, but I couldn't make it correct in all cases.
So just copy the one from upstream for now, hopefully to be replaced at
some point.

TODO: add a printfloat32() implementation, now it just casts to float64.
This will be useful for embedded systems that sometimes have float32 but
not float64.
2018-08-31 21:29:34 +02:00
Ayke van Laethem
46d2d2e777
Add support for floats
I'm not sure all operations are supported but the vast majority should
be supported now.

This commit also refactors binop translation.
2018-08-31 21:29:13 +02:00
Ayke van Laethem
f057d612fc
Add support for indexing in an array by a non-constant 2018-08-31 21:20:10 +02:00
Ayke van Laethem
674b506bb2
Replace compiler hack for sync package with //go:linkname 2018-08-30 22:38:45 +02:00
Ayke van Laethem
771f23e320
Implement //go:linkname pragma 2018-08-30 22:27:19 +02:00