1
0
forked from Mirror/wren
Commit Graph

50 Commits

Author SHA1 Message Date
58e4d26648 "IO" -> "System".
Get rid of the separate opt-in IO class and replace it with a core
System class.

- Remove wren_io.c, wren_io.h, and io.wren.
- Remove the flags that disable it.
- Remove the overloads for print() with different arity. (It was an
  experiment, but I don't think it's that useful.)
- Remove IO.read(). That will reappear using libuv in the CLI at some
  point.
- Remove IO.time. Doesn't seem to have been used.
- Update all of the tests, docs, etc.

I'm sorry for all the breakage this causes, but I think "System" is a
better name for this class (it makes it natural to add things like
"System.gc()") and frees up "IO" for referring to the CLI's IO module.
2015-09-15 07:46:09 -07:00
c0b5ec9f15 Move codePointAt() to separate CodePointSequence class. 2015-09-11 07:56:01 -07:00
bda9ad880a Flesh out string byte handling a bit:
- Get rid of public byteAt(_) method on strings. It's redundant and
  longer than .bytes[_].
- Implement bytes.count natively so it's O(1).
2015-09-10 23:52:18 -07:00
71ab3ca887 Use "construct" instead of "this" to define constructors. 2015-07-21 07:24:53 -07:00
5fb6186d7d Make constructors just methods.
* Eliminate "new" reserved word.
* Allow "this" before a method definition to define a constructor.
* Only create a default constructor for classes that don't define one.
2015-07-10 09:18:22 -07:00
4a15653c66 Add isEmpty to Sequence.
Thanks, Michel and Thorbjørn!
2015-06-30 06:52:29 -07:00
e861b86563 Revert 40897f3348.
It leaks memory in the case of runtime errors.
2015-05-19 06:50:17 -07:00
40897f3348 Don't stackoverflow on recursive lists and maps. Fix #3. 2015-05-03 11:13:05 -07:00
75a3051fae .list -> .toList
Fix #248.
2015-04-03 11:22:34 -07:00
563a090865 Push more core class creation into the core library itself. 2015-04-03 08:00:55 -07:00
b46828e93e Update docs for map(_) and where(_). 2015-04-01 07:31:15 -07:00
f4a836c66e Merge branch 'deferred_execution' of git://github.com/bjorn/wren into bjorn-deferred_execution
Conflicts:
	builtin/core.wren
	src/vm/wren_core.c
2015-04-01 07:22:02 -07:00
561d46ef1d Merge pull request #241 from bjorn/sequence_each
Added Sequence.each
2015-04-01 07:10:21 -07:00
a8ea2a91a6 Use deferred execution for Sequence.map and Sequence.where
The methods Sequence.map and Sequence.where are now implemented using
deferred execution. They return an instance of a new Sequence-derived
class that performs the operation while iterating. This has three main
advantages:

* It can be computationally cheaper when not the whole sequence is
  iterated.

* It consumes less memory since it does not store the result in a newly
  allocated list.

* They can work on infinite sequences.

Some disadvantages are:

* Iterating the returned iterator will be slightly slower due to
  the added indirection.

* You should be aware that modifications made to the original sequence
  will affect the returned sequence.

* If you need the result in a list, you now need to call Sequence.list
  on the result.
2015-03-31 22:25:07 +02:00
c00d6ad694 Added Sequence.each
This is a bit of a style preference since of course you can always write
the same thing with a for loop. However, I think sometimes the code
looks better when using this method.

It also provides an alternative to Sequence.map for cases where you
don't need the resulting list, and one that becomes especially necessary
when Sequence.map is changed to return a new sequence. The example in
the README.md file was using Sequence.map in a way that required this
alternative in that case.
2015-03-31 21:53:29 +02:00
07f9d4d2be Tweak Sequence.all() and Sequence.any().
When possible, they return the actual value from the predicate
instead of always just "true" and "false". This matches && and ||
which evaluate to the RHS or LHS when appropriate.
2015-03-28 10:18:45 -07:00
53ee453f0f Merge pull request #239 from bjorn/sequence_list
Added Sequence.list
2015-03-28 09:06:49 -07:00
72c38a59ce More stuff for working with strings and bytes!
- "\x" escape sequence to put byte values in strings: "\x34"
- String.byteAt(index) gets value of byte in string.
- String.bytes returns a raw sequence of bytes for a string.
- String.codePointAt(index) gets the code point at an offset as a raw number.
2015-03-27 20:44:07 -07:00
b409569b6f Added Sequence.list
This helper method turns any sequence into a List.
2015-03-27 22:59:58 +01:00
94804fe1a0 Added Sequence.count(predicate)
Returns the number of elements in the sequence that pass the
`predicate`.

It could also have been implemented as:

  count(f) { reduce(0) {|a, b| f.call(b) ? a + 1 : a } }

But I considered the simple version more readable.

Also documented Sequence.count.
2015-03-19 21:10:05 +01:00
fc1dc4c54b Moved List.contains to Sequence.contains, added tests and docs 2015-03-15 15:59:42 +01:00
d35e3c917c Add count to Sequence. 2015-03-06 07:01:02 -08:00
8f985847d4 Added Sequence.any as complement to Sequence.all 2015-03-01 23:14:32 +01:00
c2c576b27c Get rid of builtin function for importing. 2015-02-16 10:21:29 -08:00
5b1447882b Move running the module fiber into C. 2015-02-16 10:16:42 -08:00
36d100b8e4 Move module load failure into C. 2015-02-16 10:12:41 -08:00
bb647d4247 Start getting module loading working.
Right now, it uses a weird "import_" method on String which
should either be replaced or at least hidden behind some syntax.

But it does roughly the right thing. Still lots of corner cases to
clean up and stuff to fix. In particular:

- Need to handle compilation errors in imported modules.
- Need to implicitly import all core and IO types into imported module.
- Need to handle circular imports.
  (Just need to give entry module the right name for this to work.)
2015-02-06 07:01:15 -08:00
ed8e595f54 Get rid of bytecodes for list literals.
Just compile them to:

new List
.add(...)
.add(...)
...

Gets rid of some code in the interpreter loop, which is always good.
Also addresses the old limitation where a list literal could only have
255 elements.
2015-01-25 22:49:30 -08:00
492c730e6f Key and value iteration for maps. Also toString. 2015-01-25 10:27:38 -08:00
abe80e6d4b Initial map implementation.
Still lots of methods missing and clean up and tests to do.
Also still no literal syntax.

But the core hash table code is there and working. The supported
key types are all, uh, supported.
2015-01-24 22:27:35 -08:00
4977083904 Abstract List's toString method to a more general join method on Sequence. 2015-01-24 14:01:16 -08:00
eb424f5c1a Make strings iterable over their code points.
I'm not sure why, but this also regresses perf:

binary_trees - wren            ..........  3290  0.30s   96.68% relative to baseline
delta_blue - wren              ..........  7948  0.13s   99.06% relative to baseline
fib - wren                     ..........  3165  0.32s   95.90% relative to baseline
for - wren                     ..........  8242  0.12s   96.00% relative to baseline
method_call - wren             ..........  5417  0.18s   78.74% relative to baseline

Need to investigate.
2015-01-22 20:58:22 -08:00
5cfb638fd1 Use @munificent's single-argument reduce 2015-01-16 09:26:19 +01:00
4c6b819ed1 Add reduce function on Sequence 2015-01-16 09:24:59 +01:00
b829ce67af Rename forall to all. 2015-01-14 23:19:31 -08:00
f2b334d7d2 Add more forall test cases. 2015-01-14 22:51:34 -08:00
7716ad6263 Adds forall method on Sequences. 2015-01-13 23:47:01 -08:00
c0b0920d67 Update set example to new Syntax. Replaces #30 2015-01-09 16:02:40 -06:00
dca58ff747 Require parentheses around operator and setter arguments. 2014-04-08 17:54:37 -07:00
9a8f2edda4 List.addAll(). 2014-04-06 08:37:37 -07:00
9792581292 Style choice: I had been writing methods with spaces before the arguments, but that doesn't seem to be the case in the documentation. This is just to keep things consistent 2014-02-18 11:55:55 -06:00
f8a9d7f321 Make Sequence base class.
This lets us share functionality between List and Range (and
other user-defined sequence types).
2014-02-16 09:20:31 -08:00
4728687ca5 Merge branch 'feature/list-where' of git://github.com/zeckalpha/wren into zeckalpha-feature/list-where
Conflicts:
	builtin/core.wren
	src/wren_core.c
2014-02-15 11:21:24 -08:00
3409d588e5 Added List.where method and tests. 2014-02-15 00:42:14 -06:00
83ea5aaf45 Add List.map method and test 2014-02-14 23:06:29 -06:00
ea3cfa05bd Allow [0..-1] and [0...0] to work on empty lists. 2014-02-14 20:10:41 -08:00
ca7ff222fe Fix iterating over an empty list. 2014-02-14 17:24:06 -08:00
e519ecbc49 Third try. ;) Concat operator, tests. Now [1,2,3] + (4..6) works! Inlined helper functions to keep core lib small. 2014-02-14 11:16:57 -06:00
756fe0d920 Make "this" the implicit receiver! 2014-02-12 17:33:35 -08:00
36df70dba1 Move IO into a separate module. 2014-02-04 08:44:59 -08:00