Move core.wren to be next to wren_core.wren.inc.

This commit is contained in:
Bob Nystrom
2015-10-17 22:17:10 -07:00
parent e5176607d9
commit 30e7d9e508
7 changed files with 22 additions and 25 deletions
+17 -12
View File
@@ -1,19 +1,24 @@
This contains the Wren source code. It is organized like so:
* `cli`: the source code for the command line interface. This is a custom
exectuable that embeds the VM in itself. Code here handles reading
command-line, running the REPL, loading modules from disc, etc.
* `aux`: the Wren and C source code for the auxiliary modules. These are built
in to the VM and can be used even when you embed the VM in your own
application. But they are also optional and can be compiled out by setting
defines.
* `include`: the public header directory for the VM. If you are embedding the
VM in your own application, you will add this to your include path.
* `cli`: the source code for the command line interface. This is a custom
exectuable that embeds the VM in itself. Code here handles reading
command-line, running the REPL, loading modules from disc, etc.
* `module`: the source code for the built-in modules that come with the CLI.
These modules are written in a mixture of C and Wren and generally use
[libuv][] to implement their underlying functionality.
* `include`: the public header directory for the VM. If you are embedding the
VM in your own application, you will add this to your include path.
* `vm`: the source code for the Wren VM itself. Unlike code in `cli` and
`module`, this has no dependencies on libuv. If you are embedding the VM in
your own application from source, you will compile the files here into your
app.
* `module`: the source code for the built-in modules that come with the CLI.
These modules are written in a mixture of C and Wren and generally use
[libuv][] to implement their underlying functionality.
* `vm`: the source code for the Wren VM itself. Unlike code in `cli` and
`module`, this has no dependencies on libuv. If you are embedding the VM in
your own application from source, you will compile the files here into your
app.
[libuv]: http://libuv.org/
+1 -1
View File
@@ -1,4 +1,4 @@
// Generated automatically from src/module/random.wren. Do not edit.
// Generated automatically from src/aux/wren_aux_random.wren. Do not edit.
static const char* randomModuleSource =
"foreign class Random {\n"
" construct new() {\n"
+250
View File
@@ -0,0 +1,250 @@
class Bool {}
class Fiber {}
class Fn {}
class Null {}
class Num {}
class Sequence {
all(f) {
var result = true
for (element in this) {
result = f.call(element)
if (!result) return result
}
return result
}
any(f) {
var result = false
for (element in this) {
result = f.call(element)
if (result) return result
}
return result
}
contains(element) {
for (item in this) {
if (element == item) return true
}
return false
}
count {
var result = 0
for (element in this) {
result = result + 1
}
return result
}
count(f) {
var result = 0
for (element in this) {
if (f.call(element)) result = result + 1
}
return result
}
each(f) {
for (element in this) {
f.call(element)
}
}
isEmpty { iterate(null) ? false : true }
map(transformation) { MapSequence.new(this, transformation) }
where(predicate) { WhereSequence.new(this, predicate) }
reduce(acc, f) {
for (element in this) {
acc = f.call(acc, element)
}
return acc
}
reduce(f) {
var iter = iterate(null)
if (!iter) Fiber.abort("Can't reduce an empty sequence.")
// Seed with the first element.
var result = iteratorValue(iter)
while (iter = iterate(iter)) {
result = f.call(result, iteratorValue(iter))
}
return result
}
join() { join("") }
join(sep) {
var first = true
var result = ""
for (element in this) {
if (!first) result = result + sep
first = false
result = result + element.toString
}
return result
}
toList {
var result = List.new()
for (element in this) {
result.add(element)
}
return result
}
}
class MapSequence is Sequence {
construct new(sequence, fn) {
_sequence = sequence
_fn = fn
}
iterate(iterator) { _sequence.iterate(iterator) }
iteratorValue(iterator) { _fn.call(_sequence.iteratorValue(iterator)) }
}
class WhereSequence is Sequence {
construct new(sequence, fn) {
_sequence = sequence
_fn = fn
}
iterate(iterator) {
while (iterator = _sequence.iterate(iterator)) {
if (_fn.call(_sequence.iteratorValue(iterator))) break
}
return iterator
}
iteratorValue(iterator) { _sequence.iteratorValue(iterator) }
}
class String is Sequence {
bytes { StringByteSequence.new(this) }
codePoints { StringCodePointSequence.new(this) }
}
class StringByteSequence is Sequence {
construct new(string) {
_string = string
}
[index] { _string.byteAt_(index) }
iterate(iterator) { _string.iterateByte_(iterator) }
iteratorValue(iterator) { _string.byteAt_(iterator) }
count { _string.byteCount_ }
}
class StringCodePointSequence is Sequence {
construct new(string) {
_string = string
}
[index] { _string.codePointAt_(index) }
iterate(iterator) { _string.iterate(iterator) }
iteratorValue(iterator) { _string.codePointAt_(iterator) }
count { _string.count }
}
class List is Sequence {
addAll(other) {
for (element in other) {
add(element)
}
return other
}
toString { "[" + join(", ") + "]" }
+(other) {
var result = this[0..-1]
for (element in other) {
result.add(element)
}
return result
}
}
class Map {
keys { MapKeySequence.new(this) }
values { MapValueSequence.new(this) }
toString {
var first = true
var result = "{"
for (key in keys) {
if (!first) result = result + ", "
first = false
result = result + key.toString + ": " + this[key].toString
}
return result + "}"
}
}
class MapKeySequence is Sequence {
construct new(map) {
_map = map
}
iterate(n) { _map.iterate_(n) }
iteratorValue(iterator) { _map.keyIteratorValue_(iterator) }
}
class MapValueSequence is Sequence {
construct new(map) {
_map = map
}
iterate(n) { _map.iterate_(n) }
iteratorValue(iterator) { _map.valueIteratorValue_(iterator) }
}
class Range is Sequence {}
class System {
static print() {
writeString_("\n")
}
static print(obj) {
writeObject_(obj)
writeString_("\n")
return obj
}
static printAll(sequence) {
for (object in sequence) writeObject_(object)
writeString_("\n")
}
static write(obj) {
writeObject_(obj)
return obj
}
static writeAll(sequence) {
for (object in sequence) writeObject_(object)
}
static writeObject_(obj) {
var string = obj.toString
if (string is String) {
writeString_(string)
} else {
writeString_("[invalid toString]")
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Generated automatically from builtin/core.wren. Do not edit.
// Generated automatically from src/vm/wren_core.wren. Do not edit.
static const char* coreModuleSource =
"class Bool {}\n"
"class Fiber {}\n"