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

285 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
8402e84b6d
runtime: implement a simple mark/sweep garbage collector 2018-11-18 19:18:39 +01:00
Ayke van Laethem
27fc397e21
arm: implement arm.ReadRegister
This pseudo-function reads the contents of the specified register, for
example "sp".
2018-11-18 18:40:36 +01:00
Ayke van Laethem
9181f2d4ce
runtime: add "end of heap" to detect out of memory
This can be used in the future to trigger garbage collection. For now,
it provides a more useful error message in case the heap is completely
filled up.
2018-11-17 15:33:32 +01:00
Ayke van Laethem
ef93001ab8
runtime: add "none" garbage collector
This collector does not implement runtime.alloc, so it is a
quick-and-dirty way to check where in a program memory is allocated.
2018-11-17 15:14:29 +01:00
Ayke van Laethem
c220c140ef
all: make garbage collector configurable 2018-11-17 15:14:05 +01:00
Ayke van Laethem
15a4afb22a
runtime: unify GC interface
Make sure every to-be-implemented GC can use the same interface. As a
result, a 1MB chunk of RAM is allocated on Unix systems on init instead
of allocating on demand.
2018-11-17 14:11:58 +01:00
Ayke van Laethem
1ba463c7ee
machine: redesign I2C interface 2018-11-16 23:08:41 +01:00
Ayke van Laethem
9bddaae04a
compiler: support any int type in slice indexes
Make sure the compiler will correctly compile indexes of type uint64,
for example.
2018-11-14 14:41:40 +01:00
Ayke van Laethem
ee7c276493
compiler: update integer type sizes
* Use 64-bit integers on 64-bit platforms, just like gc and gccgo:
  https://golang.org/doc/go1.1#int
* Do not use a separate length type. Instead, use uintptr everywhere a
  length is expected.
2018-11-14 14:01:04 +01:00
Ayke van Laethem
c4ef2908ee
microbit: fix pin numbers for ADC and I2C 2018-11-11 19:23:09 +01:00
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