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

673 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
1b283c11c1
ir: do not throw an error on unknown conversions 2018-10-31 10:19:25 +01:00
Ayke van Laethem
4e4f91bea7
main: cleanup printing of IR
Panics don't usually happen nowadays, instead the compiler package
returns errors while compiling. If it still panics, this is usually from
within LLVM from where deferred functions are not run.
2018-10-31 10:10:49 +01:00
Ayke van Laethem
8a211d36aa
compiler: only produce one bitcast from an alloca
This makes passes simpler, by being able to look at the (only) bitcast
from an alloca to know the expected type.
2018-10-30 20:10:29 +01:00
Ayke van Laethem
b09b07a52d
wasm: allow all undefined symbols
Undefined symbols will be shown by the embedder, for example when
running generated wasm files in a browser.

In the future, this should probably become a fixed list again. But for
experimenting it's easier now to just ignore undefined symbols and
expect the JS to provide them.
2018-10-30 15:59:29 +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
317b12b8c0
compiler: remove println statement
I forgot to remove this debug print after I wrote the code...
2018-10-29 18:18:23 +01:00
Ayke van Laethem
2a5c331516
compiler: assume external functions don't let pointers escape
Assume any external function won't let pointers live longer than the
call itself. This is true in the vast majority of cases (apparently
everywhere currently) but might not always be true.

TODO: add a //go:noescape (or maybe //go:escape) to handle this, instead
of this assumption.
2018-10-29 14:04:55 +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
Marc-Antoine Ruel
a3d87456cd tinygo: add 'tinygo' build tag
This enables project to conditionally skip code that can't compile on tinygo.
2018-10-27 16:44:10 -04: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
c84fc6a670
main: gofmt 2018-10-26 23:31:27 +02:00
Ayke van Laethem
e751e4afe9
compiler: avoid accidentally emitting debug info 2018-10-26 23:30:46 +02:00
Justin Clift
bce697bcc1
docs: rename readme extension to .md
.md is the generally accepted extension meaning Markdown, at least
on GitHub.
2018-10-25 20:45:51 +02:00
Christian Muehlhaeuser
db636da207
README: typo fix
"becauses" => "because"
2018-10-25 20:43:46 +02:00
Marc-Antoine Ruel
63b0b4b90c
compiler: fix compiler.go import order
go/parser is part of the standard library.

No functional change.
2018-10-25 20:41:45 +02:00
Justin Clift
586d3b33b1
README: add Getting Help section
Includes information about the new #TinyGo Slack channel.

Fixes #54.
2018-10-25 20:40:00 +02:00
Marc-Antoine Ruel
7f30ef7e4d
testdata: add more test cases in testdata
Specifically test for one or multiple init functions.
2018-10-25 20:37:35 +02:00
Ayke van Laethem
97d4558d81
main: update help text with new subcommands 2018-10-25 20:36:11 +02:00
Ayke van Laethem
980dceb192
main: refactor build option passing
The list of options passed to build/run/gdb/etc commands was getting
unwieldly and hard to add extra options to. Put all common build options
in a single build config struct so that these options are more
centralized.
2018-10-24 23:53:44 +02:00
Ayke van Laethem
fcd44c02cd
compiler: fix const complex numbers
This led to an assertion failure with a debug build of LLVM, but
apparently worked with a release build of LLVM.
2018-10-24 23:24:11 +02:00
Ayke van Laethem
cb0a148cd7
compiler: fix map optimization
Not all uses of a map are call instructions. Don't assume they are.
TODO: investigate these uses and see whether they might be eliminated?
2018-10-24 12:37:47 +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
6c6a43310a
compiler: fix invalid incoming block in complex typeassert flow
A single *ssa.BasicBlock may be split in multiple LLVM basic blocks due
to typeassert instructions. This means the incoming block and outgoing
block are different. PHI nodes need to get the result from the outgoing
block, which was fixed before, but incoming branches need to branch to
the incoming block, not the outgoing block.

Branching to the outgoing block led to a LLVM verification error when
compiling the fmt package.

Originally found in (*fmt.pp).handleMethods.
2018-10-23 15:00:37 +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
17e8c850f6
compiler: fix invalid use of extractvalue on vector types 2018-10-23 14:05:55 +02:00
Ayke van Laethem
893c115f31
travis: remove WebAssembly test
It fails (hangs) roughly half of the time and I don't know why. Perhaps
a problem in the linker?

Remove it now for green checkmarks.
2018-10-23 13:29:24 +02:00
Ayke van Laethem
e2f6aedd9d
compiler: implement comparing structs directly 2018-10-23 13:27:18 +02:00
Ayke van Laethem
cbd7d401fe
testdata: go fmt 2018-10-23 13:24:18 +02:00
Ayke van Laethem
82be43f4e6
compiler: implement deferring of immediately-applied closures
This is a common operation:

    freevar := ...
    defer func() {
        println("I am deferred:", freevar)
    }()

The function is thus an immediately applied closure. Only this form is
currently supported, support for regular (fat) function pointers should
be trivial to add but is not currently implemented as it wasn't
necessary to get fmt to compile.
2018-10-22 14:06:51 +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
9393cdd5ed
README: add WebAssembly as a supported target 2018-10-22 12:40:06 +02:00
Ayke van Laethem
c88d2d10a7
docs: give a working Docker example 2018-10-21 22:42:38 +02:00
Ayke van Laethem
58ce5d9bf2
docs: add WebAssembly to targets and improve formatting 2018-10-21 20:22:21 +02:00
Ayke van Laethem
e5e09747f0
all: add WebAssembly backend 2018-10-21 19:47:47 +02:00
Johan Brandhorst
a51e04c550
Dockerfile: include necessary build subfolders
When building, tinygo needs access to files relative to
the directory it was built from. Include src and targets
directories.
2018-10-21 17:52:12 +01:00
Johan Brandhorst
f1b3ec4be8 Dockerfile: add vendor step
The Dockerfile was missing the part where we download
the dependencies into the vendor folder. It was of course
working locally because I had a vendor folder already.
2018-10-21 16:21:04 +01:00
Ayke van Laethem
dda9c1cc6e
ir: fix interface call edge case
A function on a type that is put in an interface must not be assumed to
not need a context pointer when it isn't directly put in a function
pointer, because the interface call side won't know this and pass an
extra parameter with that extra function pointer.

This is usually not a problem but WebAssembly has strict checks on
function signatures so this resulted in an error when running
src/examples/test/test.go.
2018-10-21 01:33:40 +02:00
Johan Brandhorst
97caabb8c2 Add Dockerfile 2018-10-21 00:28:18 +01:00
Johan Brandhorst
3d644e6ea8 Add dep files 2018-10-20 23:29:32 +01: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
da89464a63
compiler: compare slice against nil 2018-10-20 17:22:51 +02:00
Ayke van Laethem
3f05490846
compiler: fix odd bounds check failure with impossible typeassert 2018-10-20 17:21:47 +02:00
Ayke van Laethem
77d6d6c417
compiler: allow structs in map keys 2018-10-20 17:21:13 +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