Commit Graph

253 Commits

Author SHA1 Message Date
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
Ayke van Laethem 74bd378c29 Replace _llvm_* workaround in the scheduler with //go:linkname
This also removes the need for the _llvm_ special case in the compiler.
And it makes the scheduler code a whole lot nicer!
2018-08-30 22:30:16 +02:00
Ayke van Laethem 771f23e320 Implement //go:linkname pragma 2018-08-30 22:27:19 +02:00
Ayke van Laethem 906e061e37 Replace own dummy syscall with standard library syscall
This makes it easier to support other standard library packages.
2018-08-30 05:58:54 +02:00
Ayke van Laethem e01259ba77 interpreter: string concatenation
Sometimes strings are concatenated in a way that isn't const-propagated
by the SSA transformation (e.g. the result of a function call).
Concatenate them during init() interpretation.
2018-08-30 05:54:40 +02:00
Ayke van Laethem 16cdffc367 Try to interpret simple function calls in init() functions
This is useful for example for globals like these:

    import "errors"

    var MyError = errors.New("mymodule: something went wrong!")
2018-08-30 05:53:22 +02:00
Ayke van Laethem 15f62b29cf Add runtime.GOOS 2018-08-30 05:48:16 +02:00
Ayke van Laethem 82d0d70ba2 Add (hardcoded) runtime.GOROOT()
Necessary for the time package.
2018-08-30 05:41:48 +02:00
Ayke van Laethem cfd20c7a12 Add a number for the "error" type by default 2018-08-30 05:40:11 +02:00