Commit Graph

433 Commits

Author SHA1 Message Date
Ayke van Laethem 4957db89f4 compiler: fix interface calls for big underlying values
When the underlying value of an interface does not fit in a pointer, a
pointer to the value was correctly inserted in the heap. However, the
receiving method still assumed it got the underlying value instead of a
pointer to it leading to a crash.

This commit inserts wrapper functions for method calls on interfaces.

The bug wasn't obvious as on a 64-bit system, the underlying value was
almost always put directly in the interface. However, it led to a crash
on the AVR platform where pointer are (usually) just 16 bits making it
far more likely that underlying values cannot be directly stored in an
interface.
2018-10-07 02:06:48 +02:00
Ayke van Laethem 482c5633dd compiler: put debug information on package initializer functions
Make sure package initializers show up in backtraces, as they should. In
practice, it doesn't actually break backtraces as these functions are
usually inlined anyway, but it may help to debug an error in
initialization code.
2018-10-06 23:50:35 +02:00
Ayke van Laethem 5db43e8d04 compiler: move Optimize() function to a separate file
In the future, there will be more optimizations. Let's keep them in a
separate file for separation of concerns.
2018-10-06 19:57:41 +02:00
Ayke van Laethem c9c9935b9c travis: add micro:bit 2018-10-06 13:51:40 +02:00
Ayke van Laethem bc9210b674 nrf: add micro:bit board 2018-10-06 13:04:14 +02:00
Ron Evans e4fa1a8288 nrf: I2C interface
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-10-05 12:50:43 +02:00
Ron Evans 8f7b7e6ee3 nrf52: implement ADC and PWM interfaces
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-10-04 13:56:44 +02:00
Ayke van Laethem 3e98fbcdc8 avr: use machine.UART0 as stdout 2018-10-04 13:38:12 +02:00
Ayke van Laethem f37d409855 nrf: use machine.UART0 as stdout 2018-10-04 13:36:15 +02:00
Ayke van Laethem b36b9c24a2 tools/gen-device-svd: fix interrupts for derived peripherals 2018-10-03 20:06:13 +02:00
Ayke van Laethem 9d408b7cbc main: hide OCD output by default in gdb subcommand
In most cases, it's useless. But in some cases it may be critical if the
OCD server (like openocd) has a problem.

It would be nice if openocd would differentiate between stdout and
stderr, and only write errors to stderr. But sadly it doesn't.
2018-10-03 19:33:36 +02:00
Ayke van Laethem 5d2ffa79e5 compiler: improve debug info to cover initialization 2018-10-03 19:24:29 +02:00
Ayke van Laethem f2768bee17 nrf: better formatting of pca10040.json 2018-10-03 19:03:27 +02:00
Ayke van Laethem b08c8a0cf0 all: implement gdb sub-command for easy debugging 2018-10-03 19:03:22 +02:00
Ron Evans ef2ac09561 nrf: implement UART interface
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-10-02 17:08:31 +02:00
Ayke van Laethem 3540fd9638 travis: try to build blinky2 for the host 2018-10-02 16:00:52 +02:00
Ayke van Laethem afecd28859 travis: test running a few builds for MCUs
Just a sanity check nothing gets horribly broken in the "runtime" or
"machine" packages.
2018-10-02 15:42:13 +02:00
Ayke van Laethem 2ca4540f2a tools/gen-device-svd: support old Python version
Travis-CI runs Ubuntu Trusty with Python 3.4, so we have to support
that.
2018-10-02 14:22:28 +02:00
Ayke van Laethem bdcac9ae42 Makefile: add gen-device-stm32 to gen-device target 2018-10-02 13:30:49 +02:00
Ayke van Laethem ffa6d562a9 tools/gen-device-svd: fix bug in previous commit
There was a bug in the generated Go code: padding member numbers would
not increase their count leading to multiple struct members with the
same name.
2018-10-01 21:21:09 +02:00
Ayke van Laethem a72d0b7959 tools/gen-device-svd: make sure all clusters are included
This is important for nrf52840, which has UART pin selection in a
cluster that wasn't exposed.
2018-10-01 17:14:33 +02:00
Ron Evans 4c8a725d78 avr: implement UART interface
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-10-01 12:02:59 +02:00
Ayke van Laethem bcf441ccba docs: add another way in which a llvm-7-dev installation can fail 2018-09-30 18:02:15 +02:00
Ayke van Laethem eac81e5232 Makefile: run verbose 'make test' 2018-09-30 18:01:14 +02:00
Ayke van Laethem 02936042b8 travis: add Travis CI build script 2018-09-30 17:32:40 +02:00
Ayke van Laethem a2e57b40f9 docs: update installation instructions
* Update to system-installed LLVM.
  * Avoid the use of make.
2018-09-30 15:40:58 +02:00
Ayke van Laethem f107a24b72 all: use LLVM library provided by the system 2018-09-30 15:10:04 +02:00
Ayke van Laethem 5c79a93c85 tools/gen-device-svd: generate code for cluster arrays
This should make it possible to add support for PWM on nrf devices.
2018-09-30 14:57:06 +02:00
Ayke van Laethem 9b4a6dcc14 tools/gen-device-svd: move peripheral list to beginning
It's much easier to scan the source when the peripheral list is at the
front. Go doesn't care about the order of declaration anyway.
2018-09-30 14:56:19 +02:00
Ayke van Laethem e77a5af5d2 tools/gen-device-svd: rewrite with ElementTree
xml.etree.ElementTree is much easier to work with. This also fixes a few
small bugs in the parser. And as an added bonus, device generation got a
lot faster: apprently etree is a lot faster than minidom.
2018-09-30 14:55:38 +02:00
Ron Evans ee5d562050 examples: add color mood lamp that shows using GPIO, PWM, ADC, and I2C all at the same time on an Arduino
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-09-29 23:18:31 +02:00
Ayke van Laethem 802350f8da main: helpful error message for flash cmd without -target 2018-09-29 22:39:44 +02:00
Ayke van Laethem b6db84e916 main: use GOPATH from the environment
Be more compatible with the Go toolchain by setting GOPATH in the same
way. This makes it possible to flash and run examples from the standard
GOPATH instead of only from the source tree.
2018-09-29 22:30:45 +02:00
Ayke van Laethem 5bf058a0a6 nrf: fix off-by-one in modulo of runtime.ticks
This code:
    foo & 0xffffff
Is equivalent to this code:
    foo % 0x1000000
However, to drop the high 8 bits, this calculation was used:
    foo % 0xffffff
This is far more expensive (and incorrect), as it needs an actual modulo
operation which increases code size and probably reduces speed on a
Cortex-M4 and needs library functions for a Cortex-M0 increasing code
size by a much bigger amount.
2018-09-29 16:21:17 +02:00
Ayke van Laethem c1a833c7cc main: add basic float tests 2018-09-29 00:12:23 +02:00
Ayke van Laethem 717262c0a6 main: add coroutine/sleep tests 2018-09-29 00:11:58 +02:00
Ayke van Laethem 318567f398 ir: fix nil pointer dereference in IsVolatile 2018-09-29 00:11:05 +02:00
Ayke van Laethem 8d170d3bd2 all: change special type __volatile to pragma //go:volatile
This is one step towards removing unnecessary special casts in most
cases. It is also part of removing as much magic as possible from the
compiler (the pragma is explicit, the special name is not).
2018-09-28 13:17:03 +02:00
Ayke van Laethem 0e813c4cb7 main: add -no-debug flag to avoid DWARF debug info 2018-09-25 20:17:46 +02:00
Ayke van Laethem 69f2cec045 avr: fix build for Arduino
I'm afraid I broke this while merging the I2S changes...
2018-09-25 14:32:02 +02:00
Ayke van Laethem 8f661d25a9 main_test: fix error logging of test 2018-09-25 14:25:38 +02:00
Ayke van Laethem 4731f2f787 testdata: add better tests for struct expanding 2018-09-25 14:24:44 +02:00
Ron Evans 12fb4f3f91 avr: i2c implementation with BlinkM example
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-09-25 14:00:01 +02:00
Ayke van Laethem d190bfccf6 Makefile: add 'make test' that runs go test 2018-09-25 13:49:03 +02:00
Ayke van Laethem 13cb7d6503 avr: add interrupt support
Interrupts are supported using a special //go:interrupt pragma.
For example:

//go:interrupt INT0_vect
func handleINT0() {
    // do something here
}
2018-09-25 13:47:20 +02:00
Ayke van Laethem dc88948f55 Makefile: go fmt testdata/*.go 2018-09-25 13:45:50 +02:00
Ayke van Laethem 174b6333f8 compiler: fix expanding zero-length structs 2018-09-25 13:45:04 +02:00
Ayke van Laethem d8f0ddf3fa main: add tests
Add testing infrastructure and one initial test (for
src/runtime/print.go). More tests to be added later.
2018-09-24 17:24:58 +02:00
Ayke van Laethem ed227b8fd3 all: fix errors reported by go vet 2018-09-24 17:22:59 +02:00
Ayke van Laethem a2eaaa42a0 main: optimize 'tinygo run'
Apparently -Oz without inliner is the fastest, probably because it
removes code that would otherwise need to be emitted.

TODO: does this mean that the ExecutionEngine compiles the module before
running it? Can we control this?
2018-09-24 16:22:09 +02:00