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

137 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
923a6f5873 interp: add testing for scanning for side effects 2019-11-01 17:00:32 +01:00
Ayke van Laethem
7369a0e7f2 all: add support for Windows 2019-10-17 00:14:59 +02:00
Ayke van Laethem
582457b81e interp: implement runtime.sliceCopy
This implements the copy() built-in function. It may not work in all
cases, but should work in most cases.

This commit gets the following 3 packages to compile, according to
tinygo-site/imports/main.go:

  * encoding/base32
  * encoding/base64
  * encoding/pem (was blocked by encoding/base64)
2019-09-24 18:16:43 +02:00
Ayke van Laethem
4ea1559d46 interp: add basic test to interp package
More tests should be added in the future, but this is a start.
2019-09-24 18:16:43 +02:00
Ayke van Laethem
da7f7eef00 interp: avoid an extra TargetData argument
This can be easily calculated from the module datalayout string.
2019-09-24 18:16:43 +02:00
Jaden Weiss
17ef7a5c32
all: add support for go 1.13 2019-09-24 16:13:26 +02:00
Ayke van Laethem
10ed3decb0 compiler: rename getZeroValue to llvm.ConstNull
It does the same thing but should be more complete, and it probably is
faster as well (just one CGo call instead of several).
2019-09-15 19:09:10 +02:00
Ayke van Laethem
385d1d0a5d
compiler,runtime: implement a portable conservative GC 2019-07-01 16:30:33 +02:00
Ayke van Laethem
7156afca9e interp: support some more expressions in const icmp 2019-05-24 14:00:23 +02:00
Ayke van Laethem
3bf4c06c99 interp: work around limitation of constfolding in IR builder
The IR builder does not appear to fold comparisons of constant inttoptr
instructions to const null pointer. So do it manually during
interpretatin, as a somewhat ugly hack.

This fixes https://github.com/tinygo-org/tinygo/issues/363
2019-05-21 19:33:19 +02:00
Ayke van Laethem
f1d9e7b75e interp: make errors during branches more reliable
Previously, there was a suble error in that .IsConstant() is not always
allowed to be called, resulting in a i1 that was not 0 or 1. Fix this by
checking for the constants directly and adding some more diagnostics to
catch more cases.
2019-05-21 19:33:19 +02:00
Ayke van Laethem
5342d392aa interp: improve scan for loads
During a scan, consider loads from dirty globals to be dirty and check
whether they have any local side effects.

This fixes a problem with the new volatile operations that are now in
methods on registers instead of being emitted inline as volatile
instructions.
2019-05-18 18:30:22 +02:00
Ayke van Laethem
371c468e8e compiler: add debug info for function arguments
This commit adds debug info to function arguments, so that in many cases
you can see them when compiling with less optimizations enabled.
Unfortunately, due to the way Go SSA works, it is hard to preserve them
in many cases.
Local variables are not yet saved.

Also, change the language type to C, to make sure lldb shows function
arguments. The previous language was Modula 3, apparently due to a
off-by-one error somewhere.
2019-05-14 11:18:38 +02:00
Ayke van Laethem
7de3d4be2b all: support interface asserts in interp
This adds support for the math/rand package.
2019-04-13 20:55:56 +02:00
Ayke van Laethem
f967c6919a interp: fix segmentation fault in some builds
A call to .IsConstant() also returns true for constant globals, not just
constant expressions. Do an extra check that we're really operating on a
constant expression.
2019-04-10 18:29:22 +02:00
Ayke van Laethem
4d82f42d61 runtime: add runtime.nanotime
This function returns the current timestamp, or 0 at compile time.

runtime.nanotime is used at package initialization by the time package
starting with Go 1.12.
2019-03-23 16:16:19 +01:00
Ayke van Laethem
b7cdf8cd0c interp: refactor to eliminate lots of code
This may cause a small performance penalty, but the code is easier to
maange as a result.
2019-03-08 17:36:53 +01:00
Ayke van Laethem
cfc1a66e8d interp: use correct initialization order on panic() calls
Whenever interp hits an unreachable instruction, it bails out at that
point. However, it used to insert new instructions at the bottom with
the old init calls still at the top. So when a panic() happened in a
non-main package, the last packages to init would actually be called
first.

This commit fixes this by setting the insert point at the top of
runtime.initAll before starting interpretation, so the initialization
order is still correct when a panic() happens during init.
2019-03-07 16:22:06 +01:00
Ayke van Laethem
6ae4b43eb2 interp: fix recursive scanning
There were a few issues that made interp not perform as it should:

  * The scan was non-recursive due to a bug.
  * Recursive scanning would always return the severity level, which is
    not always the best strategy.
2019-02-05 17:37:55 +01:00
Ayke van Laethem
bece6b9648 interp: remove init call when hitting 'unreachable'
The interp package interprets calls in runtime.initAll and replaces
these calls with non-interpretable instructions if needed.
When hitting an unreachable instruction, this call should be removed,
but it wasn't. This commit makes sure the call is removed even before
trying to interpret the package init function.
2019-02-05 17:37:55 +01:00
Ayke van Laethem
553f00bdb8 interp: fix uintptr type context in interface
This bug led to a non-obvious validation error after interp had run.
2019-02-05 17:37:55 +01:00
Konstantin Yegupov
504c82a0e7
compiler: support for byte arrays as keys in maps 2019-01-31 16:35:22 +01:00
Konstantin Yegupov
f8a1e5f449
interp: support map literals with integer keys 2019-01-31 16:34:59 +01:00
Ayke van Laethem
9092dbcc53
all: rename go-llvm to new import path
the new import path is:

    tinygo.org/x/go-llvm
2019-01-27 19:26:16 +01:00
Ayke van Laethem
602c264749
all: rewrite goroutine lowering
Before this commit, goroutine support was spread through the compiler.
This commit changes this support, so that the compiler itself only
generates simple intrinsics and leaves the real support to a compiler
pass that runs as one of the TinyGo-specific optimization passes.

The biggest change, that was done together with the rewrite, was support
for goroutines in WebAssembly for JavaScript. The challenge in
JavaScript is that in general no blocking operations are allowed, which
means that programs that call time.Sleep() but do not start goroutines
also have to be scheduled by the scheduler.
2019-01-21 22:09:33 +01:00
Ayke van Laethem
c0ab91a263
interp: extra safety check in string emulation 2019-01-21 22:08:12 +01:00
Ron Evans
b4dd2dbf60
docs: change links in README and remove old ReadTheDocs pages to point to TinyGo.org site
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2019-01-13 20:29:45 +01:00
Ayke van Laethem
564b1b3312
compiler: always use fat function pointers with context
This reduces complexity in the compiler without affecting binary sizes
too much.

Cortex-M0:   no changes
Linux x64:   no changes
WebAssembly: some testcases (calls, coroutines, map) are slightly bigger
2018-12-09 18:47:39 +01:00
Ayke van Laethem
469193735a
interp: report 'unreachable' instruction as an error
This instruction should never be hit in real programs, but the
interpreter may hit it after a call to panic(). This would always be a
runtime error.
2018-12-01 16:16:59 +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
dbf581b56d
interp: do not try to interpret functions with an inttoptr instruction 2018-11-18 18:41:59 +01:00
Ayke van Laethem
4fdffdf8b2
interp: support non-const ptrtoint instruction 2018-11-17 14:09:18 +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
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
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