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

283 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
18b3e8d156
gen-device: move to new tools directory 2018-09-13 00:55:18 +02:00
Ayke van Laethem
a46ed465c5
README: defer has been fully implemented 2018-09-13 00:31:43 +02:00
Ayke van Laethem
422c848163
README: fix nrf example and add arduino example 2018-09-13 00:23:53 +02:00
Ayke van Laethem
7e7502a990
README: update build instructions 2018-09-13 00:23:45 +02:00
Ayke van Laethem
5e9e3bd1a0
Makefile: use the compiler driver directly 2018-09-12 23:55:13 +02:00
Ayke van Laethem
76a513802f
targets/pca10040: support linking from within the compiler
This is kind of dirty with that huge list of linker params, but it works
and it produces smaller object files (probably because GCC is better
optimized for size).
2018-09-12 23:40:21 +02:00
Ayke van Laethem
8ce139284a
all: remove last traces of the C runtime
This increases code size on the nrf, but it is a fixed increase and can
hopefully be reduced in the future.
The Makefile gets a lot smaller with this which is a huge advantage
(less build time complexity).
2018-09-12 23:26:30 +02:00
Ayke van Laethem
f7f7d4cbbc
runtime/nrf: translate nrf sleep function from C to Go
This is the last critical part of the C runtime.

Code size is reduced by 4 bytes for examples/blinky2 (probably due to
inlining) and is unchanged for examples/test.
2018-09-12 22:24:17 +02:00
Ayke van Laethem
67e33ac30e
gen-device-svd: add _Pos and _Msk fields
Without these extra fields, it is impossible to read/write some register
bits correctly.
2018-09-12 22:06:42 +02:00
Ayke van Laethem
2788ab0172
all: rename __reg to __volatile
It is less magical now: it only marks loads and stores as volatile. So
the name '__reg' is a bit wrong now.
2018-09-12 22:05:41 +02:00
Ayke van Laethem
914cd56ca5
all: support Arduino in the compiler driver
This makes sure the compiler itself can build/link an ELF file that
works on an Arduino.
2018-09-12 20:55:50 +02:00
Ayke van Laethem
865520b571
compiler: act as a compiler driver (on unix systems)
As a final step, link the object file with the system compiler/linker.
TODO: cross compiling.
2018-09-12 19:59:13 +02:00
Ayke van Laethem
6ab2b30984
compiler: move output file type selection to main.go 2018-09-12 19:11:50 +02:00
Ayke van Laethem
9bec479041
all: make targets configurable with a JSON file
This is intentionally similar to the target specifications in Rust:
https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.TargetOptions.html
2018-09-12 18:28:39 +02:00
Ayke van Laethem
20c2552f8a
compiler: add 'run' command for bytecode interpretation 2018-09-12 17:26:56 +02:00
Ayke van Laethem
8362751590
compiler: use runtime.GOOS/GOARCH instead of hardcoding build tags 2018-09-12 17:25:43 +02:00
Ayke van Laethem
e9b0a7d2ae
compiler: improve command line errors 2018-09-12 17:25:14 +02:00
Ayke van Laethem
0779ee6088
compiler: improve command line argument parsing
To get more compatibility with the go command, implement a similar
command line interface (with "tinygo build <package>" etc.).
Other than that, an all-round cleanup of command parsing.
2018-09-12 17:23:36 +02:00
Ayke van Laethem
81b9edbe65
compiler: print() doesn't print spaces between arguments 2018-09-11 20:01:49 +02:00
Ayke van Laethem
8675025fc8
compiler: implement type assert without comma-ok 2018-09-11 19:51:31 +02:00
Ayke van Laethem
31e0662856
runtime: use a specialized runtime panic function
This specifically fixes unix alloc(): previously when allocation fails
it would (recursively) call alloc() again to create an interface due to
lacking escape analysis.
Also, all other cases shouldn't try to allocate just because something
bad happens at runtime.

TODO: implement escape analysis.
2018-09-11 19:50:49 +02:00
Ayke van Laethem
4ad6df3227
all: complete the implementation of interface asserts
Because a few things were left unimplemented it only happened to kind-of
work before in my test cases.
This commit should complete interface-to-interface type asserts.
2018-09-11 19:39:25 +02:00
Ayke van Laethem
61e6f7cf5b
compiler: add debug information for function parameters
Add 'optimized-out' parameters to functions. This might make debugging
slightly easier by showing parameter names.

Sadly I din't get setting variables to work. It might be a bug in
CreateExpression.
2018-09-11 17:00:24 +02:00
Ayke van Laethem
43b8c24226
compiler: implement interface assertions
This is a lot harder than 'regular' type assertions as the actual
methods need to be checked.
2018-09-06 20:18:18 +02:00
Ayke van Laethem
30ac6ec281
compiler: don't try to get pointer methods
I don't know why this was ever needed, but it seems to be incorrect and
unnecessary.
2018-09-06 20:04:41 +02:00
Ayke van Laethem
0f83c3b3c6
compiler: allow copying a string to a slice
Now that strings and slices are similar, this just works.
2018-09-06 10:53:18 +02:00
Ayke van Laethem
41a50ec336
compiler: simplify code for builtin len()
Strings and slices now have the len element at the same location.
2018-09-06 10:52:36 +02:00
Ayke van Laethem
31f494e611
all: swap string from {len, ptr} to {ptr, len} for slice compatibility
Having slices and strings be similar makes other code simpler.
2018-09-06 10:50:13 +02:00
Ayke van Laethem
5aa8b71ae1
compiler: implement builtin copy(dst, src []T)
Not implemented: copying a string into a []byte slice.
2018-09-06 10:37:44 +02:00
Ayke van Laethem
fd9fa038a9
compiler: fix make([]T, ...) type 2018-09-06 10:37:00 +02:00
Ayke van Laethem
01635b5efd
runtime: move panic functions to a separate file 2018-09-06 09:59:32 +02:00
Ayke van Laethem
65358ed3c9
interpreter: don't panic on a nil (*ssa.Call).Object() 2018-09-06 09:47:39 +02:00
Ayke van Laethem
094c5561b6
compiler: implement make([]T, ...) 2018-09-06 09:46:58 +02:00
Ayke van Laethem
ef2c406127
compiler: implement comparing a pointer against nil 2018-09-05 20:35:16 +02:00
Ayke van Laethem
f44d2f718f
compiler: rewrite defer support to better support them
This costs a bit in code size, but should be more flexible for the
future to implement recover() and running deferred functions while
panicking.
2018-09-05 20:34:17 +02:00
Ayke van Laethem
87dd1a1fe5
compiler: fix debug metadata
Not setting the correct debug location at function entry leads to
instructions getting the address of the previously emitted function,
which is of course wrong. LLVM complains about it when validating a
module.
2018-09-05 16:41:34 +02:00
Ayke van Laethem
9101ea11bf
examples: clean up examples and add blinky1 for Arduino
Arduino has trouble supporting anything that's not extremely simple, so
add a simple blinky example for it. Also, it may be useful anyway.
2018-09-05 16:40:46 +02:00
Ayke van Laethem
17b5b6ec5b
all: use less magic in memory-mapped IO
Don't store addresses in the values of registers, this leads to problems
with char arrays (among others). Instead, do it like it's done in C with
raw addresses cast to struct pointers.

This commit also splits gen-device.py, as AVR and ARM have very
different ideas of what a register is. It's easier to just keep them
separate.
2018-09-05 12:18:21 +02:00
Ayke van Laethem
93248c93ed
avr: remove device files, use them from a subrepository
These files don't really belong in this repository. It's better to
generate them automatically from a source, like the one provided by the
avr-rust project. So a new command `make gen-device-avr` has been
provided for this purpose.
2018-09-05 12:13:33 +02:00
Ayke van Laethem
7258553528
compiler: implement const pointers from integers
These raw pointers are used for memory-mapped IO.
2018-09-05 11:15:33 +02:00
Ayke van Laethem
ce71d18450
runtime/nrf: remove AEABI functions
Apparently these functions were not actually used.
2018-09-05 07:09:24 +02:00
Ayke van Laethem
92877f8371
Makefile: some cleanups
Remove $(GCC) and $(LLC) which were not used anymore, and display binary
size even when building for the host.
2018-09-04 21:32:56 +02:00
Ayke van Laethem
83ad0b6137
all: move bootstrapping IR to Go runtime
This has the benefit of not requiring a 'runtime' IR file, so that
complete relocatable files can be built without requiring input IR.
This makes the compiler a lot easier to use without the Makefile.

Code size is not affected.
2018-09-04 21:18:26 +02:00
Ayke van Laethem
0746d61639
compiler: move optimizer into the binary 2018-09-04 19:20:49 +02:00
Ayke van Laethem
c109ec0955
compiler: let a failed typeassert return the nil value
See the comment in the source for details.

The underlying type would be casted to the final one even before the
type is checked. This apparently led LLVM to think the type cast was OK,
so it speculatively dereferenced a pointer (while the underlying type
was an int). Speculatively dereferencing a pointer is fine when it is a
valid pointer, but when it is not it leads to a segfault (or worse).
This is what I saw, and it took me a while to figure out where it went
wrong.
2018-09-03 19:18:10 +02:00
Ayke van Laethem
efdc2b8672
compiler: add basic debug info
Only implements debugging with source lines and stacktraces (without
parameters), which already is a huge improvement over no debug
information at all. This should be extended to arguments and local
variables (of the correct DWARF type), but this is more work.
2018-09-03 19:17:44 +02:00
Ayke van Laethem
a7fcef62e0
compiler: implement comparing interfaces to nil
Comparing an interface to nil is easy, as the dynamic type is also nil.
Comparing the dynamic values (when the dynamic types match) is much
harder and depends on reflection capabilities, so is not yet implemented.
2018-09-03 01:13:07 +02:00
Ayke van Laethem
c100e4d67f
compiler: fix nil constant interface
A nil interface has no dynamic type (or: nil dynamic type). Don't try to
use the static type as the dynamic type, because these are different.
2018-09-03 01:01:24 +02:00
Ayke van Laethem
4ed04309a3
compiler: truncate shift amount when needed 2018-09-03 00:22:55 +02:00
Ayke van Laethem
ebd87ce4cd
compiler: implement []byte(str) 2018-09-03 00:21:33 +02:00