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

775 коммитов

Автор SHA1 Сообщение Дата
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
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
bf9d62fe98
interp: fix GEP with const value in a local variable 2018-11-05 13:33:01 +01:00
Ayke van Laethem
2cd9846cc9
interp: fix compile-time alloc linkage
This makes sure compile-time allocations (globals with the $alloc
suffix) can be eliminated when unused.
2018-11-05 13:11:15 +01:00
Ayke van Laethem
b4be9e033a
runtime: add syscall/js stubs for microcontrollers 2018-11-05 13:11:15 +01:00
Ayke van Laethem
3d0ccb81c6
main: fix -initinterp flag
It got accidentally replaced by -interp just before finalizing the
previous commit.
2018-11-05 13:11:15 +01:00
Ayke van Laethem
bb3d05169d
interp: add new compile-time package initialization interpreter
This interpreter currently complements the Go SSA level interpreter. It
may stay complementary or may be the only interpreter in the future.

This interpreter is experimental and not yet finished (there are known
bugs!) so it is disabled by default. It can be enabled by passing the
-initinterp flag.

The goal is to be able to run all initializations at compile time except
for the ones having side effects. This mostly works except perhaps for a
few edge cases.

In the future, this interpeter may be used to actually run regular Go
code, perhaps in a shell.
2018-11-04 18:40:51 +01:00
Ayke van Laethem
f900d3f9d5
travis: remove Go master testing
There is a problem with this version, but fixing it requires some
changes to ir/interpreter.go which will be replaced soon anyway.

Remove master from the tests. It probably wasn't such a great idea
anyway during the development cycle of Go.
2018-11-04 18:29:17 +01:00
Ayke van Laethem
e930a1ead5
compiler: allow multiple basic blocks in package initializers
I don't know why they sometimes have them, but apparently some packages
do. Don't panic in that case, the interpreter will stop anyway on the
first branch.
2018-11-03 20:22:00 +01:00
Ayke van Laethem
a531caa2e9
compiler: implement deferring of interface calls 2018-11-03 20:21:43 +01:00
Ayke van Laethem
8f8942d763
compiler: make all functions unnamed_addr
In Go, function pointers are not comparable. This means that the address
itself is not significant and functions can therefore be merged.

Add the unnamed_addr attribute to all functions to learn LLVM about this
fact. At the moment the mergefunc pass hasn't been enabled, but it
should be in the future to reduce code size.
2018-11-03 18:47:49 +01:00
Ayke van Laethem
3823870d07
main: print IR even when verification failed 2018-11-03 18:26:46 +01:00
Ayke van Laethem
60eefe1568
compiler: do not abort on verification failure 2018-11-03 18:24:57 +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
e66d457c42
compiler: fix float <-> int conversions 2018-11-03 12:20:55 +01:00
Ayke van Laethem
8da1a5bc17
compiler: add comment to interface call signatures 2018-11-03 12:04:33 +01:00
Ayke van Laethem
2e22d53e5d
compiler: work around i64 limitation in JavaScript
JavaScript does not support i64 directly, so make sure we pass a pointer
instead which can be read from JavaScript.

This is a temporary workaround which should be removed once JavaScript
supports some form of i64 (probably in the form of BigInt).
2018-11-03 12:03:49 +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
c7cf6f0e82
docs: move calling convention documentation here 2018-11-01 11:41:24 +01:00
Ayke van Laethem
85d5fe7643
docs: add description of internal datatypes 2018-10-31 20:47:12 +01:00