aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
AgeCommit message (Collapse)Author
2021-04-21runtime: implement command line arguments in hosted environmentsAyke van Laethem
Implement command line arguments for Linux, MacOS and WASI.
2021-04-21runtime: implement environment variables for LinuxAyke van Laethem
2021-04-21interp: remove map supportAyke van Laethem
The interp package is in many cases able to execute map functions in the runtime directly. This is probably slower than adding special support for them in the interp package and also doesn't cover all cases (most importantly, map keys that contain pointers) but removing this code also removes a large amount of code that needs to be maintained and is susceptible to hard-to-find bugs. As a side effect, this resulted in different output of the testdata/map.go test because the test relied on the existing iteration order of TinyGo maps. I've updated the test to not rely on this test, making the output compatible with what the Go toolchain would output.
2021-04-15wasm: use WASI ABI for exit functionAyke van Laethem
This improves compatibility between the regular browser target (-target=wasm) and the WASI target (-target=wasi). Specifically, it allows running WASI tests like this: tinygo test -target=wasi encoding/base32
2021-04-12reflect: implement New functionAyke van Laethem
This is very important for some use cases, for example for Vecty.
2021-04-09main: implement -ldflags="-X ..."Ayke van Laethem
This commit implements replacing some global variables with a different value, if the global variable has no initializer. For example, if you have: package main var version string you can replace the value with -ldflags="-X main.version=0.2". Right now it only works for uninitialized globals. The Go tooling also supports initialized globals (var version = "<undefined>") but that is a bit hard to combine with how initialized globals are currently implemented. The current implementation still allows caching package IR files while making sure the values don't end up in the build cache. This means compiling a program multiple times with different values will use the cached package each time, inserting the string value only late in the build process. Fixes #1045
2021-04-09main: clean up testsAyke van Laethem
- Explicitly list all test cases. This makes it possible to store tests in testdata/ that aren't tested on all platforms. - Clean up filesystem and env test, by running them in a subtest and deduplicating some code and removing the additionalArgs parameter.
2021-04-06cgo: add support for CFLAGS in .c filesAyke van Laethem
This patch adds support for passing CFLAGS added in #cgo lines of the CGo preprocessing phase to the compiler when compiling C files inside packages. This is expected and convenient but didn't work before.
2021-03-29compiler: fix "fragment covers entire variable" bugAyke van Laethem
This bug could sometimes be triggered by syscall/js code it seems. But it's a generic bug, not specific to WebAssembly.
2021-03-29reflect: implement Sizeof and Alignof for func valuesAyke van Laethem
This is a small change that appears to be necessary for encoding/json support. It's simple enough to implement.
2021-03-28reflect: implement Value.CanAddrAyke van Laethem
It is used in the crypto/sha512 test, for example. And it is very simple to implement.
2021-03-28transform: optimize reflect.Type Implements() methodAyke van Laethem
This commit adds a new transform that converts reflect Implements() calls to runtime.interfaceImplements. At the moment, the Implements() method is not yet implemented (how ironic) but if the value passed to Implements is known at compile time the method call can be optimized to runtime.interfaceImplements to make it a regular interface assert. This commit is the last change necessary to add basic support for the encoding/json package. The json package is certainly not yet fully supported, but some trivial objects can be converted to JSON.
2021-03-28WASI & darwin: support basic file io based on libcTakeshi Yoneda
Signed-off-by: Takeshi Yoneda <[email protected]>
2021-03-23compiler: merge runtime.typecodeID and runtime.typeInInterfaceAyke van Laethem
This distinction was useful before when reflect wasn't properly supported. Back then it made sense to only include method sets that were actually used in an interface. But now that it is possible to get to other values (for example, by extracting fields from structs) and it is possible to turn them back into interfaces, it is necessary to preserve all method sets that can possibly be used in the program in a type assert, interface assert or interface method call. In the future, this logic will need to be revisited again when reflect.New or reflect.Zero gets implemented. Code size increases a bit in some cases, but usually in a very limited way (except for one outlier in the drivers smoke tests). The next commit will improve the situation significantly.
2021-02-24WASI & darwin: support env variables based on libcTakeshi Yoneda
Signed-off-by: Takeshi Yoneda <[email protected]>
2021-02-11cgo: add support for variadic functionsAyke van Laethem
This doesn't yet add support for actually making use of variadic functions, but at least allows (unintended) variadic functions like the following to work: void foo();
2021-01-24compiler: support all kinds of deferred builtinsAyke van Laethem
This change extends defer support to all supported builitin functions. Not all of them make sense (such as len, cap, real, imag, etc) but this change for example adds support for `defer(delete(m, key))` which is used in the Go 1.15 encoding/json package.
2021-01-23reflect: implement PtrToAyke van Laethem
2021-01-19compiler: test float to int conversions and fix upper-bound calculationNia Weiss
2021-01-16compiler: saturate float-to-int conversionsNia Weiss
This works around some UB in LLVM, where an out-of-bounds conversion would produce a poison value. The selected behavior is saturating, except that NaN is mapped to the minimum value.
2020-12-27compiler: fix non-int integer constantsAyke van Laethem
Before this change, the compiler could panic with the following message: panic: 20 not an Int That of course doesn't make much sense. But it apparently is expected behavior, see https://github.com/golang/go/issues/43165 for details. This commit fixes this issue by converting the constant to an integer if needed.
2020-10-29runtime: allow ranging over a nil mapAyke van Laethem
This appears to be allowed by the specification, at least it is allowed by the main Go implementation: https://play.golang.org/p/S8jxAMytKDB Allow it in TinyGo too, for consistency. Found because it is triggered with `tinygo test flags`. This doesn't make the flags package pass all tests, but is a step closer.
2020-10-28compiler: implement negate for complex numbersAyke van Laethem
2020-10-23implement reflect.SwapperTakeshi Yoneda
Signed-off-by: mathetake <[email protected]>
2020-10-14runtime: add cheap atomic condition variableNia Weiss
2020-10-02runtime: use dedicated printfloat32Ayke van Laethem
It can be unexpected that printing a float32 involves 64-bit floating point routines, see for example: https://github.com/tinygo-org/tinygo/issues/1415 This commit adds a dedicated printfloat32 instead just for printing float32 values. It comes with a possible code size increase, but only if both float32 and float64 values are printed. Therefore, this should be an improvement in almost all cases. I also tried using printfloat32 for everything (and casting a float64 to float32 to print) but the printed values are slightly different, breaking the testdata/math.go test for example.
2020-07-31compiler: implement func value and builtin deferswaj334
Co-authored-by: Justin A. Wilson <[email protected]>
2020-07-29compiler: fix named string to []byte slice conversionAyke van Laethem
This was missing a `.Underlying()` call to avoid testing the named type (but instead test for the underlying type).
2020-06-23extend stdlib to allow import of more packages (#1099)Cornel
* stdlib: extend stdlib to allow import of more packages
2020-05-28compiler: add support for atomic operationsAyke van Laethem
This also implements DisableInterrupts/EnableInterrupts for RISC-V, as those operations were needed to implement a few libcalls.
2020-05-27compiler: fix a few crashes due to named typesAyke van Laethem
There were a few cases left where a named type would cause a crash in the compiler. While going through enough code would have found them eventually, I specifically looked for the `Type().(` pattern: a Type() call that is then used in a type assert. Most of those were indeed bugs, although for some I couldn't come up with a reproducer so I left them as-is.
2020-05-13os: implement virtual filesystem supportAyke van Laethem
This allows applications to mount filesystems in the os package. This is useful for mounting external flash filesystems, for example.
2020-05-12runtime: add cap and len support for chanscornelk
2020-05-12testdata: fix formattingcornelk
2020-05-09testdata, sync: add sync.Mutex test to testdata/coroutines.goJaden Weiss
2020-05-09testdata: replace fake waitgroup in channel.go with sync.WaitGroupJaden Weiss
2020-04-13runtime (chan): fix blocking select on a nil channelJaden Weiss
Previously, a blocking select on a nil channel would result in a nil panic inside the channel runtime code. This change fixes the nil checks so that the select works as intended.
2020-04-09compiler: pass interface typecode through defer framesJaden Weiss
Previously, the typecode was passed via a direct reference, which results in invalid IR when the defer is not reached in all return paths. It also results in incorrect behavior if the defer is in a loop, causing all defers to use the typecode of the last iteration.
2020-04-07builder: make sure -fshort-enums is used consistentlyAyke van Laethem
The main change is in building the libraries, where -fshort-enums was passed on RISC-V while other C files weren't compiled with this setting. Note: the test already passed before this change, but it seems like a good idea to explicitly test for enum size consistency. There is also not a particular reason not to pass -fshort-enums on RISC-V. Perhaps it's better to do it there too (on baremetal targets that don't have to worry about binary compatibility).
2020-04-05all: change //go:export to //exportAyke van Laethem
This is the kind that is used in Go (actually CGo) for exporting functions. I think it's best to use //export instead of our custom //go:export pragma, for consistency (they are equivalent in TinyGo). Therefore I've updated all instances to the standard format (except for two that are updated in https://github.com/tinygo-org/tinygo/pull/1024). No smoke tests changed (when comparing the output hash), except for some wasm tests that include DWARF debug info and tend to be flaky anyway.
2020-03-29compiler: add support for anonymous type assertsAyke van Laethem
This is used for example by the errors package, which contains: if x, ok := err.(interface{ As(interface{}) bool }); ok && x.As(target) { return true } The interface here is not a named type.
2020-03-28compiler: implement spec-compliant shiftsJaden Weiss
Previously, the compiler used LLVM's shift instructions directly, which have UB whenever the shifts are large or negative. This commit adds runtime checks for negative shifts, and handles oversized shifts.
2020-03-22all: include picolibc for bare metal targetsAyke van Laethem
This is necessary for better CGo support on bare metal. Existing libraries expect to be able to include parts of libc and expect to be able to link to those symbols. Because with this all targets have a working libc, it is now possible to add tests to check that a libc in fact works basically. Not all parts of picolibc are included, such as the math or stdio parts. These should be added later, when needed. This commit also avoids the need for the custom memcpy/memset/memcmp symbols that are sometimes emitted by LLVM. The C library will take care of that.
2020-03-20interp: add support for constant type assertsAyke van Laethem
Non-constant type asserts are not yet implemented, but should be relatively easy to add at a later time. They should result in a clear error message for now.
2020-03-17refactor coroutine lowering and tasksJaden Weiss
2020-03-13compiler,runtime: check for channel size limitsAyke van Laethem
This patch is a combination of two related changes: 1. The compiler now allows other types than `int` when specifying the size of a channel in a make(chan ..., size) call. 2. The compiler now checks for maximum allowed channel sizes. Such checks are trivially optimized out in the vast majority of cases as channel sizes are usually constant. I discovered this issue when trying out channels on AVR.
2020-02-27compiler: fix deferred calls to exported functionsJaden Weiss
Previously using defer with an exported function generated an invalid function call due to differences between TinyGo's calling convention and the C calling convention.
2020-02-26compiler,runtime: support operations on nil mapAyke van Laethem
The index expression and delete keyword are valid on nil maps, so the runtime must be modified to support this.
2020-01-27avr: use a garbage collectorAyke van Laethem
This might sound crazy, but I think it's better to enable the GC by default to avoid surprises. It costs 1130 bytes of flash and 16 bytes of RAM (plus heap overhead) so it's not exactly free, but if needed it can easily be disabled with `-gc=leaking`. On the Uno (32kB flash, 2kB RAM) that's not massive, on the DigiSpark (8kB flash, 0.5kB RAM) that may be too much depending on the application.
2020-01-27compiler,runtime: implement maps for arbitrary keysAyke van Laethem
This implementation simply casts types without special support to an interface, to make the implementation simpler and possibly reducing the code size too. It will likely be slower than the canonical Go implementation though (which builds special compare and hash functions at compile time).