Commit Graph

21 Commits

Author SHA1 Message Date
Ayke van Laethem 4957db89f4 compiler: fix interface calls for big underlying values
When the underlying value of an interface does not fit in a pointer, a
pointer to the value was correctly inserted in the heap. However, the
receiving method still assumed it got the underlying value instead of a
pointer to it leading to a crash.

This commit inserts wrapper functions for method calls on interfaces.

The bug wasn't obvious as on a 64-bit system, the underlying value was
almost always put directly in the interface. However, it led to a crash
on the AVR platform where pointer are (usually) just 16 bits making it
far more likely that underlying values cannot be directly stored in an
interface.
2018-10-07 02:06:48 +02:00
Ayke van Laethem 482c5633dd compiler: put debug information on package initializer functions
Make sure package initializers show up in backtraces, as they should. In
practice, it doesn't actually break backtraces as these functions are
usually inlined anyway, but it may help to debug an error in
initialization code.
2018-10-06 23:50:35 +02:00
Ayke van Laethem 5db43e8d04 compiler: move Optimize() function to a separate file
In the future, there will be more optimizations. Let's keep them in a
separate file for separation of concerns.
2018-10-06 19:57:41 +02:00
Ayke van Laethem 5d2ffa79e5 compiler: improve debug info to cover initialization 2018-10-03 19:24:29 +02:00
Ayke van Laethem f107a24b72 all: use LLVM library provided by the system 2018-09-30 15:10:04 +02:00
Ayke van Laethem b6db84e916 main: use GOPATH from the environment
Be more compatible with the Go toolchain by setting GOPATH in the same
way. This makes it possible to flash and run examples from the standard
GOPATH instead of only from the source tree.
2018-09-29 22:30:45 +02:00
Ayke van Laethem 8d170d3bd2 all: change special type __volatile to pragma //go:volatile
This is one step towards removing unnecessary special casts in most
cases. It is also part of removing as much magic as possible from the
compiler (the pragma is explicit, the special name is not).
2018-09-28 13:17:03 +02:00
Ayke van Laethem 13cb7d6503 avr: add interrupt support
Interrupts are supported using a special //go:interrupt pragma.
For example:

//go:interrupt INT0_vect
func handleINT0() {
    // do something here
}
2018-09-25 13:47:20 +02:00
Ayke van Laethem 174b6333f8 compiler: fix expanding zero-length structs 2018-09-25 13:45:04 +02:00
Ayke van Laethem ed227b8fd3 all: fix errors reported by go vet 2018-09-24 17:22:59 +02:00
Ayke van Laethem c9ae72a105 all: allow -O0 optimization level 2018-09-24 16:17:42 +02:00
Ayke van Laethem 6191d4e1ac compiler: rename .Parse() to .Compiler()
The fact it was called Parse() is more of a historical accident, as the
compiler started out using the Go AST directly instead of Go SSA.
2018-09-24 15:55:38 +02:00
Ayke van Laethem 1b229a8f8b compiler: support compiling individual .go files
For example:

    tinygo run ./src/examples/test/test.go
2018-09-24 15:46:30 +02:00
Ayke van Laethem a561e9a9ac ir: move adding packages from the compiler 2018-09-24 15:46:30 +02:00
Ayke van Laethem 9df04a2170 compiler: fix panic on import errors
I think this is a problem in the loader package - it doesn't seem to
return errors for missing packages.
2018-09-24 15:46:30 +02:00
Ayke van Laethem 8a468786df compiler: use config struct for options 2018-09-24 15:46:05 +02:00
Ayke van Laethem fd6dda5e4f main: run the compiler from any path 2018-09-24 12:25:33 +02:00
Ayke van Laethem 2938437efc compiler: make string data unnamed addresses
This ensures LLVM can merge identical strings, and thus reduces code
size in some cases.
2018-09-23 03:03:40 +02:00
Ayke van Laethem 7cea40bcb5 compiler: small cleanup in call handling code 2018-09-23 03:01:10 +02:00
Ayke van Laethem fdfa810060 compiler: expand small structs
Use fields of small structs (3 or less fields when flattened
recursively) directly as parameter values.

Advantages:
  * Code size is slightly reduced, both on unix and nrf.
  * AVR can finally deal with struct parameters - at least the small
    ones. examples/test now compiles. A real fix for struct parameters
    should go into upstream LLVM, but this is a nice win.

fixes #20
2018-09-23 02:39:05 +02:00
Ayke van Laethem b2cbfa78ca compiler: refactor compiler into separate package 2018-09-22 20:32:28 +02:00