Commit Graph

175 Commits

Author SHA1 Message Date
Ayke van Laethem d1c0d6120a compiler: simplify runtime.interfaceMethod signature slightly
Code size is not affected, as dead arguments are eliminated anyway.
It makes future interface optimizations hopefully easier to implement.
2018-11-09 15:20:38 +01:00
Ayke van Laethem 611bca39ab all: rename 'arm' to 'tinygo.arm' for Cortex-M
Let the standard library think that it is compiling for js/wasm.

The most correct way of supporting bare metal Cortex-M targets would be
using the 'arm' build tag and specifying no OS or an 'undefined' OS
(perhaps GOOS=noos?). However, there is no build tag for specifying no
OS at all, the closest possible is GOOS=js which makes very few
assumptions.

Sadly GOOS=js also makes some assumptions: it assumes to be running with
GOARCH=wasm. This would not be such a problem, just add js, wasm and arm
as build tags. However, having two GOARCH build tags leads to an error
in internal/cpu: it defines variables for both architectures which then
conflict.

To work around these problems, the 'arm' target has been renamed to
'tinygo.arm', which should work around these problems. In the future, a
GOOS=noos (or similar) should be added which can work with any
architecture and doesn't implement OS-specific stuff.
2018-11-09 11:50:38 +01:00
Marc-Antoine Ruel b1cf69a523 compiler: implement binop string: <, <=, >, >=
Include unit tests.
2018-11-08 20:48:29 -05:00
Ayke van Laethem 76d04990f4 runtime: stub out some more syscall/js calls
These produce link errors when trying to import the "os" package.
2018-11-05 13:52:56 +01:00
Ayke van Laethem b4be9e033a runtime: add syscall/js stubs for microcontrollers 2018-11-05 13:11:15 +01:00
Ayke van Laethem 22914165cc reflect: add more stubs for encoding/binary
Package encoding/binary uses reflect and is needed by image/png, but
image/png doesn't actually need the reflect-using parts of
encoding/binary. So stub them out for now to get it to compile.

Thanks to Stephen Solka who wrote the patch.
2018-11-03 16:06:44 +01:00
Ayke van Laethem d7844ce124 compiler, runtime: move defer notes to the runtime file
This seems like the more appropriate place to describe the
implementation of defer.
2018-11-01 11:42:04 +01:00
Ayke van Laethem a459570d94 wasm: execute an 'unreachable' trap inst on panic
This already happened when directly calling panic() but not with some
runtime panics like accessing a slice out of bounds.
2018-10-30 15:59:29 +01:00
Ayke van Laethem 0314a487ff compiler: check slice cap instead of len during slicing
When doing a slice operation on a slice, use the capacity value instead
of the length. Of course, for strings and arrays, the slice operation
checks the length because there is no capacity. But according to the
spec, this check should be based on cap for slice instead of len:

> For slices, the upper index bound is the slice capacity cap(a) rather
> than the length.

https://golang.org/ref/spec#Slice_expressions

Fixes: https://github.com/aykevl/tinygo/issues/65
2018-10-30 15:58:50 +01:00
Ayke van Laethem 772c6486ab runtime: correctly copy a zero-length buffer backwards
Fixes:
https://github.com/aykevl/tinygo/issues/64
2018-10-29 14:02:47 +01:00
Ayke van Laethem d90d7be8a8 runtime: implement syscall.runtime_envs
It is stubbed out currently, but may be useful in the future.

Note that this function is implemented for a future change to the init
system, it is not yet useful.
2018-10-28 19:25:55 +01:00
Ayke van Laethem 436901dc49 compiler: implement operations on nil hashmaps
* comparing a map against nil
  * getting the length of a nil map
2018-10-27 00:57:37 +02:00
Ayke van Laethem 0b8beb77c1 reflect: add stub reflect package
This is necessary to compile fmt. However, it cannot link yet.
2018-10-23 15:39:53 +02:00
Ayke van Laethem 96f74ec153 compiler: support 64-bit numbers in bounds check 2018-10-23 14:07:27 +02:00
Ayke van Laethem 9b9b66a09d compiler: add complex manipulation
* builtins: real, imag, complex
* printing of complex numbers

No support for complex arithmetic yet.
2018-10-22 13:49:03 +02:00
Ayke van Laethem e5e09747f0 all: add WebAssembly backend 2018-10-21 19:47:47 +02:00
Ayke van Laethem ad06ed46cd runtime: fix linker error: os.sigpipe 2018-10-20 18:37:58 +02:00
Ayke van Laethem 0a06c6014d compiler: special slice bounds check for 64-bit numbers
It is allowed to index with an int64 even on a 32-bit platform, so we
have to handle that case. But make sure the normal case isn't penalized
by using 32-bit numbers when possible.
2018-10-20 18:28:00 +02:00
Ayke van Laethem 239504d9f4 compiler: implement recover()
Doesn't do anything useful yet as running deferred calls are not
executed during panic. Only implemented to get code to compile.
2018-10-20 18:00:12 +02:00
Ayke van Laethem 7c2a6169b0 compiler: support comma-ok in map lookup 2018-10-20 17:54:16 +02:00
Ayke van Laethem c0c1ccb381 compiler, runtime: implement delete builtin 2018-10-20 16:18:55 +02:00
Ayke van Laethem 7f60dd79ee sync: implement dummy sync.Pool for fmt 2018-10-20 15:52:41 +02:00
Ayke van Laethem 963ba16d7b compiler: add support for the append builtin 2018-10-19 14:40:19 +02:00
Ayke van Laethem fd45410c24 runtime: add proper arm arch 2018-10-18 15:23:52 +02:00
Ayke van Laethem daf92226d8 nrf: add nrf52840-mdk board
With the help of Chillance on GitHub.
2018-10-18 15:07:06 +02:00
Ayke van Laethem a613d0484e runtime: add support for time.Now()
TODO: On unix systems, this does not return an accurate value.
2018-10-15 20:20:37 +02:00
Ayke van Laethem ccee42ec7a machine: add helpers for bit-banged driver support
The returned pointer and value can be used to set or clear a specific
pin.
2018-10-15 19:56:27 +02:00
Ayke van Laethem 392bba8394 compiler: add support for parameters to inline assembly 2018-10-15 19:37:09 +02:00
Ayke van Laethem 0ce5347409 runtime: fix hashmap lookup of entries at position > 8
Bigger hashmaps (size > 8) use multiple buckets in a chain. The lookup
code looked at multiple buckets for a lookup, but kept checking the
first bucket for key equality.
2018-10-10 14:09:17 +02:00
Ron Evans ca13bfd992 microbit: add SetEntireLEDMatrixOn() function
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-10-08 20:38:21 +02:00
Ayke van Laethem a63af97e86 all: add emulation support for Cortex-M3 with QEMU 2018-10-08 17:07:19 +02:00
Ayke van Laethem 8982b8df83 runtime: refactor initialization code
Let each target handle its own initialization/finalization sequence
instead of providing one in the runtime with hooks for memory
initialization etc. This is much more flexible although it causes a
little bit of code duplication.
2018-10-08 14:49:33 +02:00
Ayke van Laethem 1bbdab41d2 all: improve compiler-rt compilation
A few changes to make sure compiler-rt is correctly compiled (and
doesn't include host headers, for example).

This improves support for AVR, but it still doesn't work. Compiler-rt
itself doesn't really work for AVR either.
2018-10-07 21:29:45 +02:00
Ron Evans c516a11004 microbit: add functions for LED matrix and correct button pin mapping
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-10-07 19:40:16 +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
Ron Evans ef2ac09561 nrf: implement UART interface
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-10-02 17:08:31 +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
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 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 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 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
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 c9ae72a105 all: allow -O0 optimization level 2018-09-24 16:17:42 +02:00
Ayke van Laethem 473e71b573 compiler: implement range over a string 2018-09-22 19:19:53 +02:00
Ayke van Laethem 4d5b5241ec all: avoid _Msk fields when not necessary 2018-09-22 17:42:44 +02:00
Ayke van Laethem 3bba26ce5b machine/bluepill: create definitions for all pins 2018-09-22 15:47:16 +02:00