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

2011 коммитов

Автор SHA1 Сообщение Дата
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
01635b5efd
runtime: move panic functions to a separate file 2018-09-06 09:59:32 +02:00
Ayke van Laethem
65358ed3c9
interpreter: don't panic on a nil (*ssa.Call).Object() 2018-09-06 09:47:39 +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
9101ea11bf
examples: clean up examples and add blinky1 for Arduino
Arduino has trouble supporting anything that's not extremely simple, so
add a simple blinky example for it. Also, it may be useful anyway.
2018-09-05 16:40:46 +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
93248c93ed
avr: remove device files, use them from a subrepository
These files don't really belong in this repository. It's better to
generate them automatically from a source, like the one provided by the
avr-rust project. So a new command `make gen-device-avr` has been
provided for this purpose.
2018-09-05 12:13:33 +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
ce71d18450
runtime/nrf: remove AEABI functions
Apparently these functions were not actually used.
2018-09-05 07:09:24 +02:00
Ayke van Laethem
92877f8371
Makefile: some cleanups
Remove $(GCC) and $(LLC) which were not used anymore, and display binary
size even when building for the host.
2018-09-04 21:32:56 +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
8ba3fef7d7
runtime/scheduler: always update task state
Not updating it only saves 4 bytes and makes debugging harder.
2018-09-02 19:28:41 +02:00
Ayke van Laethem
d183f12395
nrf: fix sleep
For some reason, the old behavior stopped working at some point (maybe
at the nrfx update?). Change sleep behavior to be more correct.
2018-09-02 19:20:05 +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
cd2a9d99a1
Add dummy runtime.SetFinalizer()
Requirement for the os package. The os package can't be compiled yet,
though.
2018-08-31 21:56:46 +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
3cdf606183
Improve runtime.printuint32: avoid recursion
This reduces size slightly at least on the PCA10040, and is probably
faster and probably uses less stack as well.
2018-08-31 21:29:06 +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
a1359d7f64
passes: small code cleanup 2018-08-30 22:54:44 +02:00
Ayke van Laethem
734b0cb6bc
Implement runtime functions for reflect
The reflect package isn't supported yet. But at least the Go
parser/typechecker can now deal with it.
2018-08-30 22:53:34 +02:00
Ayke van Laethem
b13cfc5255
Be able to deal with anonymous functions 2018-08-30 22:52:00 +02:00
Ayke van Laethem
674b506bb2
Replace compiler hack for sync package with //go:linkname 2018-08-30 22:38:45 +02:00