Commit Graph

38 Commits

Author SHA1 Message Date
Justin Clift 4442b1304e Trivial typo fix 2019-05-28 09:55:35 +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 8aed8d8c56 Makefile: rename tgo to tinygo 2019-02-01 13:26:32 +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 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
Ayke van Laethem ad06ed46cd runtime: fix linker error: os.sigpipe 2018-10-20 18:37:58 +02:00
Ayke van Laethem 963ba16d7b compiler: add support for the append builtin 2018-10-19 14:40:19 +02:00
Ayke van Laethem a613d0484e runtime: add support for time.Now()
TODO: On unix systems, this does not return an accurate value.
2018-10-15 20:20:37 +02:00
Ayke van Laethem 8982b8df83 runtime: refactor initialization code
Let each target handle its own initialization/finalization sequence
instead of providing one in the runtime with hooks for memory
initialization etc. This is much more flexible although it causes a
little bit of code duplication.
2018-10-08 14:49:33 +02:00
Ayke van Laethem c9ae72a105 all: allow -O0 optimization level 2018-09-24 16:17:42 +02:00
Ayke van Laethem 7517ac86e4 runtime: merge common sleep() functions 2018-09-22 01:40:04 +02:00
Ayke van Laethem 39e3fe28db avr: convert initialization from asm to Go
This increases code size by 1 instruction (2 bytes) because LLVM isn't
yet smart enough to recognize that it doesn't need to clear a register
to use 0: it can just use r1 which is always 0 according to the
convention. It makes initialization a lot easier to read, however.
2018-09-16 15:03:48 +02:00
Ayke van Laethem 1484bb5c2c all: basic support for the os package
The resulting binary is pretty big due to lacking optimizations
(probably because of interfaces), so that should be fixed.
2018-09-16 13:01:03 +02:00
Ayke van Laethem 2a20c0c7f0 all: rewrite sleep function
time.Sleep now compiles on all systems, so lets use that.
Additionally, do a few improvements in time unit handling for the
scheduler. This should lead to somewhat longer sleep durations without
wrapping (on some platforms).

Some examples got smaller, some got bigger. In particular, code using
the scheduler got bigger and the blinky1 example got smaller (especially
on Arduino: 380 -> 314 bytes).
2018-09-15 01:58:54 +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 01635b5efd runtime: move panic functions to a separate file 2018-09-06 09:59:32 +02:00
Ayke van Laethem 094c5561b6 compiler: implement make([]T, ...) 2018-09-06 09:46:58 +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 88b6b2e7f5 Optimize/eliminate bounds checking
TODO: do better at it by tracking min/max values of integers. The
following straightforward code doesn't have its bounds checks removed:

    for _, n := range slice {
        println(n)
    }
2018-09-02 16:28:46 +02:00
Ayke van Laethem 42cddd3260 Move runtime.TargetBits out of the compiler 2018-09-02 16:00:31 +02:00
Ayke van Laethem 82d0d70ba2 Add (hardcoded) runtime.GOROOT()
Necessary for the time package.
2018-08-30 05:41:48 +02:00
Ayke van Laethem c912091f8b Add integer key support to hashmap 2018-08-29 21:50:43 +02:00
Ayke van Laethem 8f7db8661b Move string type to runtime in separate file 2018-08-29 20:55:09 +02:00
Ayke van Laethem 2b78b6d7e8 Fix bug in runtime.memzero
Not the memory itself, but the byte after the memory was zeroed.
2018-08-23 23:45:39 +02:00
Ayke van Laethem 3a6ef38041 Preliminary implementation of a hashmap, unfinished
Missing features:
  * keys other than strings
  * more than 8 values in the hashmap
  * growing a map when needed
  * initial size hint
  * delete(m, key)
  * iterators (for range)
  * initializing global maps
  * ...more?
2018-08-22 04:50:24 +02:00
Ayke van Laethem c3cb22030f Implement == and != for strings 2018-08-22 00:56:11 +02:00
Ayke van Laethem 29d601883b Implement dummy GOMAXPROCS
This compiler targets single-core machines, GOMAXPROCS is thus fixed to
1.
2018-08-18 20:06:59 +02:00
Ayke van Laethem 8b6cb204cd Basic support for slices 2018-08-18 20:06:35 +02:00
Ayke van Laethem 62c4c5e90b go fmt 2018-08-17 23:23:20 +02:00
Ayke van Laethem 0168bf7797 Add goroutines and function pointers 2018-06-07 14:48:24 +02:00
Ayke van Laethem 320c583221 Implement printing of int8/uint8/pointers 2018-06-03 16:39:24 +02:00
Ayke van Laethem 04fef19753 Add runtime support for the nRF52 2018-04-25 20:06:08 +02:00
Ayke van Laethem 75fce0f949 runtime: Move print functions to separate file 2018-04-22 15:26:07 +02:00
Ayke van Laethem cf9cea7a0d Implement array bounds check 2018-04-21 01:03:05 +02:00
Ayke van Laethem 1f0651c84c Implement string out of bounds checks 2018-04-21 00:40:21 +02:00
Ayke van Laethem db66039dfe Implement panic() 2018-04-21 00:26:14 +02:00
Ayke van Laethem 45e7376f39 Implement print() and println() in Go 2018-04-20 16:32:40 +02:00