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

595 коммитов

Автор SHA1 Сообщение Дата
Darren Rush
cea0a5977a
docs: enable tinygo/docker to resolve go dependencies
Example for mapping the GOPATH into the tinygo docker image so that go
dependencies installed on the host can be found by the image.
2018-12-01 13:40:42 +01:00
Ayke van Laethem
b4c90f3677
compiler: lower interfaces in a separate pass
This commit changes many things:

  * Most interface-related operations are moved into an optimization
    pass for more modularity. IR construction creates pseudo-calls which
    are lowered in this pass.
  * Type codes are assigned in this interface lowering pass, after DCE.
  * Type codes are sorted by usage: types more often used in type
    asserts are assigned lower numbers to ease jump table construction
    during machine code generation.
  * Interface assertions are optimized: they are replaced by constant
    false, comparison against a constant, or a typeswitch with only
    concrete types in the general case.
  * Interface calls are replaced with unreachable, direct calls, or a
    concrete type switch with direct calls depending on the number of
    implementing types. This hopefully makes some interface patterns
    zero-cost.

These changes lead to a ~0.5K reduction in code size on Cortex-M for
testdata/interface.go. It appears that a major cause for this is the
replacement of function pointers with direct calls, which are far more
susceptible to optimization. Also, not having a fixed global array of
function pointers greatly helps dead code elimination.

This change also makes future optimizations easier, like optimizations
on interface value comparisons.
2018-12-01 13:26:06 +01:00
Ayke van Laethem
e45c4ac182
arm: set default GC to marksweep 2018-11-28 17:34:59 +01:00
Ayke van Laethem
e817bd38ec
main: configure default GC in target JSON file 2018-11-28 17:34:57 +01:00
Ayke van Laethem
05d70d288d
wasm: fix printing from Go code 2018-11-25 18:07:24 +01:00
Ayke van Laethem
f0fb1bd41a
compiler: fix binops on named types in struct fields 2018-11-24 22:13:01 +01:00
Ayke van Laethem
dbb3211485
wasm: add glue JS code
The file wasm_glue.js was copied from the Go wasm port and was modified,
most importantly to match the TinyGo calling convention.
2018-11-24 19:03:58 +01:00
Ayke van Laethem
242a1843d1
wasm: fix heap end address 2018-11-24 19:00:42 +01:00
Ayke van Laethem
e101937589
wasm: fix .json file after compiler updates 2018-11-24 18:36:44 +01:00
Ayke van Laethem
5c08eaf777
Dockerfile: remove arm-none-eabi-gcc dependency 2018-11-22 16:20:15 +01:00
Ayke van Laethem
44068ef396
travis: remove gcc dependency 2018-11-22 16:20:15 +01:00
Ayke van Laethem
62d74d8329
all: compile and link using clang, where possible 2018-11-22 16:20:10 +01:00
Ayke van Laethem
4a8ced590b
tools/gen-device-svd: generate .s files compatible with lld
The llvm linker expects some flags to line up in input sections mapped
to a particular output section, which the GNU linker ignored. Make sure
this flag is set in the input section, see:
https://svnweb.freebsd.org/base/stable/11/sys/arm/arm/locore-v4.S?r1=321049&r2=321048&pathrev=321049
2018-11-22 12:35:17 +01:00
Ayke van Laethem
d887d645f7
arm: implement SVCall
The SVCall function call is lowered to an inline "svc" instruction. The
first parameter *must* be a constant number.
2018-11-21 17:06:56 +01:00
Ron Evans
ce0ad1daa2
pca10031: add support for PCA10031 nrf51 wireless dongle
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-11-21 10:36:36 +01:00
Ayke van Laethem
bf4a43ef04
machine/avr: implement raw GPIO access for bitbanged drivers 2018-11-20 21:04:43 +01:00
Ayke van Laethem
9392ef900d
avr: add support for the digispark
Blinking the on-board LED works. Nothing else has been tested yet.
2018-11-20 18:50:24 +01:00
Ayke van Laethem
a96e2879b2
avr: make stack size configurable 2018-11-20 18:20:24 +01:00
Ayke van Laethem
760bc5d0a4
targets: let specific targets inherit more general targets
This avoids a ton of duplication and makes it easier to change a generic
target (for example, the "cortex-m" target) for all boards that use it.

Also, by making it possible to inherit properties from a parent target
specification, it is easier to support out-of-tree boards that don't
have to be updated so often. A target specification for a
special-purpose board can simply inherit the specification of a
supported chip and override the properites it needs to override (like
the programming interface).
2018-11-19 21:08:12 +01:00
Ayke van Laethem
f02766265c
targets: make compiler runtime selection more configurable 2018-11-19 20:17:42 +01:00
Ayke van Laethem
74b5e28a38
docs: add documentation for the -gc compiler flag 2018-11-18 19:32:57 +01:00
Ayke van Laethem
8402e84b6d
runtime: implement a simple mark/sweep garbage collector 2018-11-18 19:18:39 +01:00
Ayke van Laethem
dbf581b56d
interp: do not try to interpret functions with an inttoptr instruction 2018-11-18 18:41:59 +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
8cb7b583d8
compiler: support creating slices with uncommon initial len/cap types 2018-11-18 18:35:29 +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
ecb4742316
main: do not run legacy init interpreter with run subcommand
Do not run the new init interpreter either. Just run the code.
2018-11-17 14:48:48 +01:00
Ayke van Laethem
21db7e6099
main: move "tinygo" build tag to compiler
Replace "tgo" with "tinygo" and set it always (even with `tinygo run`).
2018-11-17 14:36:41 +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
4fdffdf8b2
interp: support non-const ptrtoint instruction 2018-11-17 14:09:18 +01:00
Ayke van Laethem
c3c4a33b42
main: enable -initinterp by default
It can still be disabled using -initinterp=false.
2018-11-16 23:12:32 +01:00
Ayke van Laethem
1ba463c7ee
machine: redesign I2C interface 2018-11-16 23:08:41 +01:00
Ayke van Laethem
100901574b
compiler: let escape analysis look across bitcasts
This is necessary to avoid memory allocation in the math packages in
some functions.
2018-11-16 23:03:38 +01:00
Denys Smirnov
46755b774e
compiler: fix another usage of the named type 2018-11-16 11:34:22 +01:00
Ayke van Laethem
1ed019771d
compiler: set debug info when defining a function
Move attaching debug info to where the function is defined. As LLVM does
not allow setting debug info on declarations, this makes more sense and
is less error-prone.

This commit fixes debug info when using CGo.
2018-11-15 20:00:00 +01:00
Ron Evans
ae3535945c
all: add support to Dockerfile for AVR and ARM targets
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2018-11-15 12:53:10 +01:00
Ayke van Laethem
668c1741c3
compiler: implement array equality
Implement binops == and != on array types.
2018-11-15 11:51:16 +01:00
Ayke van Laethem
6292a0fd2e
compiler: fix bug in for range loop over a named map type 2018-11-14 15:43:50 +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
101d41dc58
compiler: pass i64 return value in an extra pointer param
To support the WebAssembly<->JS barrier, return values also have to be
passed in memory. i64 return values are used by syscall/js, so must be
supported across this ABI barrier.
2018-11-14 12:35:43 +01:00
Ayke van Laethem
7d8b269f2e
interp: fix several bugs related to constant vs dirty values
* Loading from a dirty global must be done at runtime (!). For some
  reason this wasn't already the case.
* Global variables somehow had IsConstant() the wrong way round,
  returning the inverse from what they should.
* Do binary and logical operations at runtime if necessary, relying on
  const propagation in the IR builder.
* Don't try to interpret functions that take a dirty parameter. Call
  them at runtime.
2018-11-14 12:25:27 +01:00
Ayke van Laethem
eccbd572eb
interp: do cast operations at runtime if needed
Cast operations will still be evaluated at compile time in all cases
they did before because of the built-in constant propagation of the
IRBuilder, but when one of the parameters is not a constant it will
transparently be evaluated at runtime.

This avoids some errors in the partial evaluator. It is not yet complete
as all binops will need a similar treatment.
2018-11-14 11:43:25 +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
26acc89f9c
compiler: avoid load/store on zero-length data
These loads/stores probably would get optimized away anyway, but not
emitting them helps the init interpreter.
2018-11-09 15:48:47 +01:00
Ayke van Laethem
2ddb6f788a
compiler: move interface-related stuff to a separate file
This makes it easier to get an overview of everything interface related,
because interfaces are quite complicated and were scattered through the
(huge!) compiler.go file.
2018-11-09 15:20:38 +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