mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-16 20:28:04 +01:00
Clean up definition syntax:
- Don't use "def" on constructors. - Put "foreign" and "static" before "def".
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
class Cthulu {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def message { "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn" }
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import "cthulu" for Cthulu
|
||||
|
||||
class Lovecraft {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def say() { Cthulu.new().message }
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
// Class definition with a toplevel name.
|
||||
class SyntaxExample {
|
||||
// Constructor
|
||||
def construct new() {
|
||||
construct new() {
|
||||
// Top-level name `IO`
|
||||
System.print("I am a constructor!")
|
||||
|
||||
@ -26,7 +26,7 @@ class SyntaxExample {
|
||||
}
|
||||
|
||||
// Constructor with arguments
|
||||
def construct constructor(a, b) {
|
||||
construct constructor(a, b) {
|
||||
print(a, b)
|
||||
field = a
|
||||
}
|
||||
@ -49,7 +49,7 @@ class SyntaxExample {
|
||||
}
|
||||
|
||||
// Static method with single argument
|
||||
def static fields(a) {
|
||||
static def fields(a) {
|
||||
// Static field
|
||||
__a = a
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import "scheduler" for Scheduler
|
||||
|
||||
foreign class File {
|
||||
def static open(path) {
|
||||
static def open(path) {
|
||||
if (!(path is String)) Fiber.abort("Path must be a string.")
|
||||
|
||||
open_(path, Fiber.current)
|
||||
@ -9,7 +9,7 @@ foreign class File {
|
||||
return new_(fd)
|
||||
}
|
||||
|
||||
def static open(path, fn) {
|
||||
static def open(path, fn) {
|
||||
var file = open(path)
|
||||
var fiber = Fiber.new { fn.call(file) }
|
||||
|
||||
@ -22,18 +22,18 @@ foreign class File {
|
||||
return result
|
||||
}
|
||||
|
||||
def static read(path) {
|
||||
static def read(path) {
|
||||
return File.open(path) {|file| file.readBytes(file.size) }
|
||||
}
|
||||
|
||||
def static size(path) {
|
||||
static def size(path) {
|
||||
if (!(path is String)) Fiber.abort("Path must be a string.")
|
||||
|
||||
sizePath_(path, Fiber.current)
|
||||
return Scheduler.runNextScheduled_()
|
||||
}
|
||||
|
||||
def construct new_(fd) {}
|
||||
construct new_(fd) {}
|
||||
|
||||
def close() {
|
||||
if (close_(Fiber.current)) return
|
||||
@ -59,17 +59,17 @@ foreign class File {
|
||||
return Scheduler.runNextScheduled_()
|
||||
}
|
||||
|
||||
def foreign static open_(path, fiber)
|
||||
def foreign static sizePath_(path, fiber)
|
||||
foreign static def open_(path, fiber)
|
||||
foreign static def sizePath_(path, fiber)
|
||||
|
||||
def foreign close_(fiber)
|
||||
def foreign descriptor
|
||||
def foreign readBytes_(count, fiber)
|
||||
def foreign size_(fiber)
|
||||
foreign def close_(fiber)
|
||||
foreign def descriptor
|
||||
foreign def readBytes_(count, fiber)
|
||||
foreign def size_(fiber)
|
||||
}
|
||||
|
||||
class Stdin {
|
||||
def static readLine() {
|
||||
static def readLine() {
|
||||
if (__isClosed == true) {
|
||||
Fiber.abort("Stdin was closed.")
|
||||
}
|
||||
@ -84,7 +84,7 @@ class Stdin {
|
||||
return line
|
||||
}
|
||||
|
||||
def static onData_(data) {
|
||||
static def onData_(data) {
|
||||
if (data == null) {
|
||||
__isClosed = true
|
||||
readStop_()
|
||||
@ -119,6 +119,6 @@ class Stdin {
|
||||
}
|
||||
}
|
||||
|
||||
def foreign static readStart_()
|
||||
def foreign static readStop_()
|
||||
foreign static def readStart_()
|
||||
foreign static def readStop_()
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ static const char* ioModuleSource =
|
||||
"import \"scheduler\" for Scheduler\n"
|
||||
"\n"
|
||||
"foreign class File {\n"
|
||||
" def static open(path) {\n"
|
||||
" static def open(path) {\n"
|
||||
" if (!(path is String)) Fiber.abort(\"Path must be a string.\")\n"
|
||||
"\n"
|
||||
" open_(path, Fiber.current)\n"
|
||||
@ -11,7 +11,7 @@ static const char* ioModuleSource =
|
||||
" return new_(fd)\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def static open(path, fn) {\n"
|
||||
" static def open(path, fn) {\n"
|
||||
" var file = open(path)\n"
|
||||
" var fiber = Fiber.new { fn.call(file) }\n"
|
||||
"\n"
|
||||
@ -24,18 +24,18 @@ static const char* ioModuleSource =
|
||||
" return result\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def static read(path) {\n"
|
||||
" static def read(path) {\n"
|
||||
" return File.open(path) {|file| file.readBytes(file.size) }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def static size(path) {\n"
|
||||
" static def size(path) {\n"
|
||||
" if (!(path is String)) Fiber.abort(\"Path must be a string.\")\n"
|
||||
"\n"
|
||||
" sizePath_(path, Fiber.current)\n"
|
||||
" return Scheduler.runNextScheduled_()\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def construct new_(fd) {}\n"
|
||||
" construct new_(fd) {}\n"
|
||||
"\n"
|
||||
" def close() {\n"
|
||||
" if (close_(Fiber.current)) return\n"
|
||||
@ -61,17 +61,17 @@ static const char* ioModuleSource =
|
||||
" return Scheduler.runNextScheduled_()\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def foreign static open_(path, fiber)\n"
|
||||
" def foreign static sizePath_(path, fiber)\n"
|
||||
" foreign static def open_(path, fiber)\n"
|
||||
" foreign static def sizePath_(path, fiber)\n"
|
||||
"\n"
|
||||
" def foreign close_(fiber)\n"
|
||||
" def foreign descriptor\n"
|
||||
" def foreign readBytes_(count, fiber)\n"
|
||||
" def foreign size_(fiber)\n"
|
||||
" foreign def close_(fiber)\n"
|
||||
" foreign def descriptor\n"
|
||||
" foreign def readBytes_(count, fiber)\n"
|
||||
" foreign def size_(fiber)\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"class Stdin {\n"
|
||||
" def static readLine() {\n"
|
||||
" static def readLine() {\n"
|
||||
" if (__isClosed == true) {\n"
|
||||
" Fiber.abort(\"Stdin was closed.\")\n"
|
||||
" }\n"
|
||||
@ -86,7 +86,7 @@ static const char* ioModuleSource =
|
||||
" return line\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def static onData_(data) {\n"
|
||||
" static def onData_(data) {\n"
|
||||
" if (data == null) {\n"
|
||||
" __isClosed = true\n"
|
||||
" readStop_()\n"
|
||||
@ -121,6 +121,6 @@ static const char* ioModuleSource =
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def foreign static readStart_()\n"
|
||||
" def foreign static readStop_()\n"
|
||||
" foreign static def readStart_()\n"
|
||||
" foreign static def readStop_()\n"
|
||||
"}\n";
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Scheduler {
|
||||
def static add(callable) {
|
||||
static def add(callable) {
|
||||
if (__scheduled == null) __scheduled = []
|
||||
|
||||
__scheduled.add(Fiber.new {
|
||||
@ -9,11 +9,11 @@ class Scheduler {
|
||||
}
|
||||
|
||||
// Called by native code.
|
||||
def static resume_(fiber) { fiber.transfer() }
|
||||
def static resume_(fiber, arg) { fiber.transfer(arg) }
|
||||
def static resumeError_(fiber, error) { fiber.transferError(error) }
|
||||
static def resume_(fiber) { fiber.transfer() }
|
||||
static def resume_(fiber, arg) { fiber.transfer(arg) }
|
||||
static def resumeError_(fiber, error) { fiber.transferError(error) }
|
||||
|
||||
def static runNextScheduled_() {
|
||||
static def runNextScheduled_() {
|
||||
if (__scheduled == null || __scheduled.isEmpty) {
|
||||
return Fiber.suspend()
|
||||
} else {
|
||||
@ -21,7 +21,7 @@ class Scheduler {
|
||||
}
|
||||
}
|
||||
|
||||
def foreign static captureMethods_()
|
||||
foreign static def captureMethods_()
|
||||
}
|
||||
|
||||
Scheduler.captureMethods_()
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Generated automatically from src/module/scheduler.wren. Do not edit.
|
||||
static const char* schedulerModuleSource =
|
||||
"class Scheduler {\n"
|
||||
" def static add(callable) {\n"
|
||||
" static def add(callable) {\n"
|
||||
" if (__scheduled == null) __scheduled = []\n"
|
||||
"\n"
|
||||
" __scheduled.add(Fiber.new {\n"
|
||||
@ -11,11 +11,11 @@ static const char* schedulerModuleSource =
|
||||
" }\n"
|
||||
"\n"
|
||||
" // Called by native code.\n"
|
||||
" def static resume_(fiber) { fiber.transfer() }\n"
|
||||
" def static resume_(fiber, arg) { fiber.transfer(arg) }\n"
|
||||
" def static resumeError_(fiber, error) { fiber.transferError(error) }\n"
|
||||
" static def resume_(fiber) { fiber.transfer() }\n"
|
||||
" static def resume_(fiber, arg) { fiber.transfer(arg) }\n"
|
||||
" static def resumeError_(fiber, error) { fiber.transferError(error) }\n"
|
||||
"\n"
|
||||
" def static runNextScheduled_() {\n"
|
||||
" static def runNextScheduled_() {\n"
|
||||
" if (__scheduled == null || __scheduled.isEmpty) {\n"
|
||||
" return Fiber.suspend()\n"
|
||||
" } else {\n"
|
||||
@ -23,7 +23,7 @@ static const char* schedulerModuleSource =
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def foreign static captureMethods_()\n"
|
||||
" foreign static def captureMethods_()\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"Scheduler.captureMethods_()\n";
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import "scheduler" for Scheduler
|
||||
|
||||
class Timer {
|
||||
def static sleep(milliseconds) {
|
||||
static def sleep(milliseconds) {
|
||||
if (!(milliseconds is Num)) Fiber.abort("Milliseconds must be a number.")
|
||||
if (milliseconds < 0) Fiber.abort("Milliseconds cannot be negative.")
|
||||
|
||||
@ -9,5 +9,5 @@ class Timer {
|
||||
Scheduler.runNextScheduled_()
|
||||
}
|
||||
|
||||
def foreign static startTimer_(milliseconds, fiber)
|
||||
foreign static def startTimer_(milliseconds, fiber)
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ static const char* timerModuleSource =
|
||||
"import \"scheduler\" for Scheduler\n"
|
||||
"\n"
|
||||
"class Timer {\n"
|
||||
" def static sleep(milliseconds) {\n"
|
||||
" static def sleep(milliseconds) {\n"
|
||||
" if (!(milliseconds is Num)) Fiber.abort(\"Milliseconds must be a number.\")\n"
|
||||
" if (milliseconds < 0) Fiber.abort(\"Milliseconds cannot be negative.\")\n"
|
||||
"\n"
|
||||
@ -11,5 +11,5 @@ static const char* timerModuleSource =
|
||||
" Scheduler.runNextScheduled_()\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def foreign static startTimer_(milliseconds, fiber)\n"
|
||||
" foreign static def startTimer_(milliseconds, fiber)\n"
|
||||
"}\n";
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Meta {
|
||||
def static eval(source) {
|
||||
static def eval(source) {
|
||||
if (!(source is String)) Fiber.abort("Source code must be a string.")
|
||||
|
||||
var fn = compile_(source)
|
||||
@ -9,5 +9,5 @@ class Meta {
|
||||
Fiber.new(fn).call()
|
||||
}
|
||||
|
||||
def foreign static compile_(source)
|
||||
foreign static def compile_(source)
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Generated automatically from src/optional/wren_opt_meta.wren. Do not edit.
|
||||
static const char* metaModuleSource =
|
||||
"class Meta {\n"
|
||||
" def static eval(source) {\n"
|
||||
" static def eval(source) {\n"
|
||||
" if (!(source is String)) Fiber.abort(\"Source code must be a string.\")\n"
|
||||
"\n"
|
||||
" var fn = compile_(source)\n"
|
||||
@ -11,5 +11,5 @@ static const char* metaModuleSource =
|
||||
" Fiber.new(fn).call()\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def foreign static compile_(source)\n"
|
||||
" foreign static def compile_(source)\n"
|
||||
"}\n";
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
foreign class Random {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
seed_()
|
||||
}
|
||||
|
||||
def construct new(seed) {
|
||||
construct new(seed) {
|
||||
if (seed is Num) {
|
||||
seed_(seed)
|
||||
} else if (seed is Sequence) {
|
||||
@ -35,15 +35,15 @@ foreign class Random {
|
||||
}
|
||||
}
|
||||
|
||||
def foreign seed_()
|
||||
def foreign seed_(seed)
|
||||
def foreign seed_(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16)
|
||||
foreign def seed_()
|
||||
foreign def seed_(seed)
|
||||
foreign def seed_(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16)
|
||||
|
||||
def foreign float()
|
||||
foreign def float()
|
||||
def float(end) { float() * end }
|
||||
def float(start, end) { float() * (end - start) + start }
|
||||
|
||||
def foreign int()
|
||||
foreign def int()
|
||||
def int(end) { (float() * end).floor }
|
||||
def int(start, end) { (float() * (end - start)).floor + start }
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
// Generated automatically from src/optional/wren_opt_random.wren. Do not edit.
|
||||
static const char* randomModuleSource =
|
||||
"foreign class Random {\n"
|
||||
" def construct new() {\n"
|
||||
" construct new() {\n"
|
||||
" seed_()\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def construct new(seed) {\n"
|
||||
" construct new(seed) {\n"
|
||||
" if (seed is Num) {\n"
|
||||
" seed_(seed)\n"
|
||||
" } else if (seed is Sequence) {\n"
|
||||
@ -37,15 +37,15 @@ static const char* randomModuleSource =
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def foreign seed_()\n"
|
||||
" def foreign seed_(seed)\n"
|
||||
" def foreign seed_(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16)\n"
|
||||
" foreign def seed_()\n"
|
||||
" foreign def seed_(seed)\n"
|
||||
" foreign def seed_(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16)\n"
|
||||
"\n"
|
||||
" def foreign float()\n"
|
||||
" foreign def float()\n"
|
||||
" def float(end) { float() * end }\n"
|
||||
" def float(start, end) { float() * (end - start) + start }\n"
|
||||
"\n"
|
||||
" def foreign int()\n"
|
||||
" foreign def int()\n"
|
||||
" def int(end) { (float() * end).floor }\n"
|
||||
" def int(start, end) { (float() * (end - start)).floor + start }\n"
|
||||
"}\n";
|
||||
|
||||
@ -2614,7 +2614,7 @@ GrammarRule rules[] =
|
||||
/* TOKEN_BANGEQ */ INFIX_OPERATOR(PREC_EQUALITY, "!="),
|
||||
/* TOKEN_BREAK */ UNUSED,
|
||||
/* TOKEN_CLASS */ UNUSED,
|
||||
/* TOKEN_CONSTRUCT */ { NULL, NULL, constructorSignature, PREC_NONE, NULL },
|
||||
/* TOKEN_CONSTRUCT */ UNUSED,
|
||||
/* TOKEN_DEF */ UNUSED,
|
||||
/* TOKEN_ELSE */ UNUSED,
|
||||
/* TOKEN_FALSE */ PREFIX(boolean),
|
||||
@ -3130,15 +3130,24 @@ static void defineMethod(Compiler* compiler, int classSlot, bool isStatic,
|
||||
// be parsed.
|
||||
static bool method(Compiler* compiler, int classSlot)
|
||||
{
|
||||
// TODO: Don't require 'def' for constructors.
|
||||
consume(compiler, TOKEN_DEF, "Expect 'def' for method definition.");
|
||||
|
||||
// TODO: What about foreign constructors?
|
||||
bool isForeign = match(compiler, TOKEN_FOREIGN);
|
||||
compiler->enclosingClass->inStatic = match(compiler, TOKEN_STATIC);
|
||||
|
||||
SignatureFn signatureFn = rules[compiler->parser->current.type].method;
|
||||
nextToken(compiler->parser);
|
||||
SignatureFn signatureFn;
|
||||
|
||||
// Methods are declared using "construct" for constructors or "def" for
|
||||
// everything else.
|
||||
if (match(compiler, TOKEN_CONSTRUCT))
|
||||
{
|
||||
signatureFn = constructorSignature;
|
||||
}
|
||||
else
|
||||
{
|
||||
consume(compiler, TOKEN_DEF, "Expect 'def' before method definition.");
|
||||
signatureFn = rules[compiler->parser->current.type].method;
|
||||
nextToken(compiler->parser);
|
||||
}
|
||||
|
||||
if (signatureFn == NULL)
|
||||
{
|
||||
|
||||
@ -103,7 +103,7 @@ class Sequence {
|
||||
}
|
||||
|
||||
class MapSequence is Sequence {
|
||||
def construct new(sequence, fn) {
|
||||
construct new(sequence, fn) {
|
||||
_sequence = sequence
|
||||
_fn = fn
|
||||
}
|
||||
@ -113,7 +113,7 @@ class MapSequence is Sequence {
|
||||
}
|
||||
|
||||
class WhereSequence is Sequence {
|
||||
def construct new(sequence, fn) {
|
||||
construct new(sequence, fn) {
|
||||
_sequence = sequence
|
||||
_fn = fn
|
||||
}
|
||||
@ -134,7 +134,7 @@ class String is Sequence {
|
||||
}
|
||||
|
||||
class StringByteSequence is Sequence {
|
||||
def construct new(string) {
|
||||
construct new(string) {
|
||||
_string = string
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ class StringByteSequence is Sequence {
|
||||
}
|
||||
|
||||
class StringCodePointSequence is Sequence {
|
||||
def construct new(string) {
|
||||
construct new(string) {
|
||||
_string = string
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ class Map {
|
||||
}
|
||||
|
||||
class MapKeySequence is Sequence {
|
||||
def construct new(map) {
|
||||
construct new(map) {
|
||||
_map = map
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ class MapKeySequence is Sequence {
|
||||
}
|
||||
|
||||
class MapValueSequence is Sequence {
|
||||
def construct new(map) {
|
||||
construct new(map) {
|
||||
_map = map
|
||||
}
|
||||
|
||||
@ -215,31 +215,31 @@ class MapValueSequence is Sequence {
|
||||
class Range is Sequence {}
|
||||
|
||||
class System {
|
||||
def static print() {
|
||||
static def print() {
|
||||
writeString_("\n")
|
||||
}
|
||||
|
||||
def static print(obj) {
|
||||
static def print(obj) {
|
||||
writeObject_(obj)
|
||||
writeString_("\n")
|
||||
return obj
|
||||
}
|
||||
|
||||
def static printAll(sequence) {
|
||||
static def printAll(sequence) {
|
||||
for (object in sequence) writeObject_(object)
|
||||
writeString_("\n")
|
||||
}
|
||||
|
||||
def static write(obj) {
|
||||
static def write(obj) {
|
||||
writeObject_(obj)
|
||||
return obj
|
||||
}
|
||||
|
||||
def static writeAll(sequence) {
|
||||
static def writeAll(sequence) {
|
||||
for (object in sequence) writeObject_(object)
|
||||
}
|
||||
|
||||
def static writeObject_(obj) {
|
||||
static def writeObject_(obj) {
|
||||
var string = obj.toString
|
||||
if (string is String) {
|
||||
writeString_(string)
|
||||
|
||||
@ -105,7 +105,7 @@ static const char* coreModuleSource =
|
||||
"}\n"
|
||||
"\n"
|
||||
"class MapSequence is Sequence {\n"
|
||||
" def construct new(sequence, fn) {\n"
|
||||
" construct new(sequence, fn) {\n"
|
||||
" _sequence = sequence\n"
|
||||
" _fn = fn\n"
|
||||
" }\n"
|
||||
@ -115,7 +115,7 @@ static const char* coreModuleSource =
|
||||
"}\n"
|
||||
"\n"
|
||||
"class WhereSequence is Sequence {\n"
|
||||
" def construct new(sequence, fn) {\n"
|
||||
" construct new(sequence, fn) {\n"
|
||||
" _sequence = sequence\n"
|
||||
" _fn = fn\n"
|
||||
" }\n"
|
||||
@ -136,7 +136,7 @@ static const char* coreModuleSource =
|
||||
"}\n"
|
||||
"\n"
|
||||
"class StringByteSequence is Sequence {\n"
|
||||
" def construct new(string) {\n"
|
||||
" construct new(string) {\n"
|
||||
" _string = string\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
@ -148,7 +148,7 @@ static const char* coreModuleSource =
|
||||
"}\n"
|
||||
"\n"
|
||||
"class StringCodePointSequence is Sequence {\n"
|
||||
" def construct new(string) {\n"
|
||||
" construct new(string) {\n"
|
||||
" _string = string\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
@ -197,7 +197,7 @@ static const char* coreModuleSource =
|
||||
"}\n"
|
||||
"\n"
|
||||
"class MapKeySequence is Sequence {\n"
|
||||
" def construct new(map) {\n"
|
||||
" construct new(map) {\n"
|
||||
" _map = map\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
@ -206,7 +206,7 @@ static const char* coreModuleSource =
|
||||
"}\n"
|
||||
"\n"
|
||||
"class MapValueSequence is Sequence {\n"
|
||||
" def construct new(map) {\n"
|
||||
" construct new(map) {\n"
|
||||
" _map = map\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
@ -217,31 +217,31 @@ static const char* coreModuleSource =
|
||||
"class Range is Sequence {}\n"
|
||||
"\n"
|
||||
"class System {\n"
|
||||
" def static print() {\n"
|
||||
" static def print() {\n"
|
||||
" writeString_(\"\n\")\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def static print(obj) {\n"
|
||||
" static def print(obj) {\n"
|
||||
" writeObject_(obj)\n"
|
||||
" writeString_(\"\n\")\n"
|
||||
" return obj\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def static printAll(sequence) {\n"
|
||||
" static def printAll(sequence) {\n"
|
||||
" for (object in sequence) writeObject_(object)\n"
|
||||
" writeString_(\"\n\")\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def static write(obj) {\n"
|
||||
" static def write(obj) {\n"
|
||||
" writeObject_(obj)\n"
|
||||
" return obj\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def static writeAll(sequence) {\n"
|
||||
" static def writeAll(sequence) {\n"
|
||||
" for (object in sequence) writeObject_(object)\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" def static writeObject_(obj) {\n"
|
||||
" static def writeObject_(obj) {\n"
|
||||
" var string = obj.toString\n"
|
||||
" if (string is String) {\n"
|
||||
" writeString_(string)\n"
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
class Call {
|
||||
def static noParams {
|
||||
static def noParams {
|
||||
System.print("noParams")
|
||||
}
|
||||
|
||||
def static zero() {
|
||||
static def zero() {
|
||||
System.print("zero")
|
||||
}
|
||||
|
||||
def static one(one) {
|
||||
static def one(one) {
|
||||
System.print("one %(one)")
|
||||
}
|
||||
|
||||
def static two(one, two) {
|
||||
static def two(one, two) {
|
||||
// Don't print null bytes.
|
||||
if (two is String && two.bytes.contains(0)) {
|
||||
two = two.bytes.toList
|
||||
@ -20,7 +20,7 @@ class Call {
|
||||
System.print("two %(one) %(two)")
|
||||
}
|
||||
|
||||
def static getValue(value) {
|
||||
static def getValue(value) {
|
||||
// Return a new value if we aren't given one.
|
||||
if (value == null) return ["a", "b"]
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
class ForeignClass {
|
||||
def foreign static finalized
|
||||
foreign static def finalized
|
||||
}
|
||||
|
||||
// Class with a default constructor.
|
||||
foreign class Counter {
|
||||
def construct new() {}
|
||||
def foreign increment(amount)
|
||||
def foreign value
|
||||
construct new() {}
|
||||
foreign def increment(amount)
|
||||
foreign def value
|
||||
}
|
||||
|
||||
var counter = Counter.new()
|
||||
@ -25,16 +25,16 @@ class PointBase {
|
||||
|
||||
// Class with non-default constructor.
|
||||
foreign class Point is PointBase {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
System.print("default")
|
||||
}
|
||||
|
||||
def construct new(x, y, z) {
|
||||
construct new(x, y, z) {
|
||||
System.print("%(x), %(y), %(z)")
|
||||
}
|
||||
|
||||
def foreign translate(x, y, z)
|
||||
def foreign toString
|
||||
foreign def translate(x, y, z)
|
||||
foreign def toString
|
||||
}
|
||||
|
||||
var p = Point.new(1, 2, 3) // expect: 1, 2, 3
|
||||
@ -54,7 +54,7 @@ System.print(error) // expect: Class 'Subclass' cannot inherit from foreign clas
|
||||
|
||||
// Class with a finalizer.
|
||||
foreign class Resource {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
var resources = [
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
class Returns {
|
||||
def foreign static implicitNull
|
||||
foreign static def implicitNull
|
||||
|
||||
def foreign static returnInt
|
||||
def foreign static returnFloat
|
||||
foreign static def returnInt
|
||||
foreign static def returnFloat
|
||||
|
||||
def foreign static returnTrue
|
||||
def foreign static returnFalse
|
||||
foreign static def returnTrue
|
||||
foreign static def returnFalse
|
||||
|
||||
def foreign static returnString
|
||||
def foreign static returnBytes
|
||||
foreign static def returnString
|
||||
foreign static def returnBytes
|
||||
}
|
||||
|
||||
System.print(Returns.implicitNull == null) // expect: true
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
class Value {
|
||||
def foreign static value=(value)
|
||||
def foreign static value
|
||||
foreign static def value=(value)
|
||||
foreign static def value
|
||||
}
|
||||
|
||||
Value.value = ["list", "of", "strings"]
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Benchmark {
|
||||
def foreign static arguments(a, b, c, d)
|
||||
foreign static def arguments(a, b, c, d)
|
||||
}
|
||||
|
||||
var start = System.clock
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Ported from the Python version.
|
||||
|
||||
class Tree {
|
||||
def construct new(item, depth) {
|
||||
construct new(item, depth) {
|
||||
_item = item
|
||||
if (depth > 0) {
|
||||
var item2 = item + item
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Ported from the Python version.
|
||||
|
||||
class Tree {
|
||||
def construct new(item, depth) {
|
||||
construct new(item, depth) {
|
||||
_item = item
|
||||
if (depth > 0) {
|
||||
var item2 = item + item
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
// disrupting current constraints. Strengths cannot be created outside
|
||||
// this class, so == can be used for value comparison.
|
||||
class Strength {
|
||||
def construct new(value, name) {
|
||||
construct new(value, name) {
|
||||
_value = value
|
||||
_name = name
|
||||
}
|
||||
@ -49,10 +49,10 @@ class Strength {
|
||||
|
||||
def nextWeaker { ORDERED[_value] }
|
||||
|
||||
def static stronger(s1, s2) { s1.value < s2.value }
|
||||
def static weaker(s1, s2) { s1.value > s2.value }
|
||||
def static weakest(s1, s2) { Strength.weaker(s1, s2) ? s1 : s2 }
|
||||
def static strongest(s1, s2) { Strength.stronger(s1, s2) ? s1 : s2 }
|
||||
static def stronger(s1, s2) { s1.value < s2.value }
|
||||
static def weaker(s1, s2) { s1.value > s2.value }
|
||||
static def weakest(s1, s2) { Strength.weaker(s1, s2) ? s1 : s2 }
|
||||
static def strongest(s1, s2) { Strength.stronger(s1, s2) ? s1 : s2 }
|
||||
}
|
||||
|
||||
// Compile time computed constants.
|
||||
@ -71,7 +71,7 @@ var ORDERED = [
|
||||
var ThePlanner
|
||||
|
||||
class Constraint {
|
||||
def construct new(strength) {
|
||||
construct new(strength) {
|
||||
_strength = strength
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ class Constraint {
|
||||
|
||||
// Abstract superclass for constraints having a single possible output variable.
|
||||
class UnaryConstraint is Constraint {
|
||||
def construct new(myOutput, strength) {
|
||||
construct new(myOutput, strength) {
|
||||
super(strength)
|
||||
_satisfied = false
|
||||
_myOutput = myOutput
|
||||
@ -176,7 +176,7 @@ class UnaryConstraint is Constraint {
|
||||
// change their output during plan execution. This is called "stay
|
||||
// optimization".
|
||||
class StayConstraint is UnaryConstraint {
|
||||
def construct new(variable, strength) {
|
||||
construct new(variable, strength) {
|
||||
super(variable, strength)
|
||||
}
|
||||
|
||||
@ -188,7 +188,7 @@ class StayConstraint is UnaryConstraint {
|
||||
// A unary input constraint used to mark a variable that the client
|
||||
// wishes to change.
|
||||
class EditConstraint is UnaryConstraint {
|
||||
def construct new(variable, strength) {
|
||||
construct new(variable, strength) {
|
||||
super(variable, strength)
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ var BACKWARD = 0
|
||||
// Abstract superclass for constraints having two possible output
|
||||
// variables.
|
||||
class BinaryConstraint is Constraint {
|
||||
def construct new(v1, v2, strength) {
|
||||
construct new(v1, v2, strength) {
|
||||
super(strength)
|
||||
_v1 = v1
|
||||
_v2 = v2
|
||||
@ -311,7 +311,7 @@ class BinaryConstraint is Constraint {
|
||||
// this relationship but the scale factor and offset are considered
|
||||
// read-only.
|
||||
class ScaleConstraint is BinaryConstraint {
|
||||
def construct new(src, scale, offset, dest, strength) {
|
||||
construct new(src, scale, offset, dest, strength) {
|
||||
_scale = scale
|
||||
_offset = offset
|
||||
super(src, dest, strength)
|
||||
@ -359,7 +359,7 @@ class ScaleConstraint is BinaryConstraint {
|
||||
|
||||
// Constrains two variables to have the same value.
|
||||
class EqualityConstraint is BinaryConstraint {
|
||||
def construct new(v1, v2, strength) {
|
||||
construct new(v1, v2, strength) {
|
||||
super(v1, v2, strength)
|
||||
}
|
||||
|
||||
@ -374,7 +374,7 @@ class EqualityConstraint is BinaryConstraint {
|
||||
// various parameters of interest to the DeltaBlue incremental
|
||||
// constraint solver.
|
||||
class Variable {
|
||||
def construct new(name, value) {
|
||||
construct new(name, value) {
|
||||
_constraints = []
|
||||
_determinedBy = null
|
||||
_mark = 0
|
||||
@ -413,7 +413,7 @@ class Variable {
|
||||
// to resatisfy all currently satisfiable constraints in the face of
|
||||
// one or more changing inputs.
|
||||
class Plan {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
_list = []
|
||||
}
|
||||
|
||||
@ -431,7 +431,7 @@ class Plan {
|
||||
}
|
||||
|
||||
class Planner {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
_currentMark = 0
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Fib {
|
||||
def static get(n) {
|
||||
static def get(n) {
|
||||
if (n < 2) return n
|
||||
return get(n - 1) + get(n - 2)
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Toggle {
|
||||
def construct new(startState) {
|
||||
construct new(startState) {
|
||||
_state = startState
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ class Toggle {
|
||||
}
|
||||
|
||||
class NthToggle is Toggle {
|
||||
def construct new(startState, maxCounter) {
|
||||
construct new(startState, maxCounter) {
|
||||
super(startState)
|
||||
_countMax = maxCounter
|
||||
_count = 0
|
||||
|
||||
@ -15,7 +15,7 @@ System.print([1, [2, [3], 4], 5].join(",")) // expect: 1,[2, [3], 4],5
|
||||
|
||||
// Calls toString on elements.
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def toString { "Foo.toString" }
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ System.print([1, [2, [3], 4], 5]) // expect: [1, [2, [3], 4], 5]
|
||||
|
||||
// Calls toString on elements.
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def toString { "Foo.toString" }
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ System.print({1: {2: {}}}) // expect: {1: {2: {}}}
|
||||
|
||||
// Calls toString on elements.
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def toString { "Foo.toString" }
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
System.print(!Foo.new()) // expect: false
|
||||
|
||||
@ -25,7 +25,7 @@ System.print(Object.same(Bool, Bool)) // expect: true
|
||||
|
||||
// Other types compare by identity.
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
var foo = Foo.new()
|
||||
@ -34,7 +34,7 @@ System.print(Object.same(foo, Foo.new())) // expect: false
|
||||
|
||||
// Ignores == operators.
|
||||
class Bar {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def ==(other) { true }
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
System.print(Foo.new().toString == "instance of Foo") // expect: true
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class TestSequence is Sequence {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def iterate(iterator) {
|
||||
if (iterator == null) return 1
|
||||
|
||||
@ -2,7 +2,7 @@ System.print([].isEmpty) // expect: true
|
||||
System.print([1].isEmpty) // expect: false
|
||||
|
||||
class InfiniteSequence is Sequence {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def iterate(iterator) { true }
|
||||
def iteratorValue(iterator) { iterator }
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Infinite iterator demonstrating that Sequence.map is not eager
|
||||
class FibIterator {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
_current = 0
|
||||
_next = 1
|
||||
}
|
||||
@ -15,7 +15,7 @@ class FibIterator {
|
||||
}
|
||||
|
||||
class Fib is Sequence {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def iterate(iterator) {
|
||||
if (iterator == null) return FibIterator.new()
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class TestSequence is Sequence {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def iterate(iterator) {
|
||||
if (iterator == null) return 1
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Infinite iterator demonstrating that Sequence.where is not eager
|
||||
class FibIterator {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
_current = 0
|
||||
_next = 1
|
||||
}
|
||||
@ -15,7 +15,7 @@ class FibIterator {
|
||||
}
|
||||
|
||||
class Fib is Sequence {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def iterate(iterator) {
|
||||
if (iterator == null) return FibIterator.new()
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def toString { "Foo.toString" }
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def toString { "Foo" }
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class BadToString {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def toString { 3 }
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def toString { "Foo" }
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class BadToString {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def toString { 3 }
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
class foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def static callFoo {
|
||||
static def callFoo {
|
||||
System.print(foo)
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ class foo {
|
||||
}
|
||||
|
||||
def foo { "instance foo method" }
|
||||
def static foo { "static foo method" }
|
||||
static def foo { "static foo method" }
|
||||
}
|
||||
|
||||
foo.callFoo // expect: static foo method
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def static sayName {
|
||||
static def sayName {
|
||||
System.print(Foo)
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ class Foo {
|
||||
System.print(Foo)
|
||||
}
|
||||
|
||||
def static toString { "Foo!" }
|
||||
static def toString { "Foo!" }
|
||||
}
|
||||
|
||||
Foo.sayName // expect: Foo!
|
||||
|
||||
6
test/language/class/newline_after_def.wren
Normal file
6
test/language/class/newline_after_def.wren
Normal file
@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
def // expect error
|
||||
method {} // expect error
|
||||
}
|
||||
|
||||
// The second error is cascaded.
|
||||
@ -1,6 +1,4 @@
|
||||
class Foo {
|
||||
static // expect error
|
||||
method {} // expect error
|
||||
def method {}
|
||||
}
|
||||
|
||||
// The second error is cascaded.
|
||||
@ -1,7 +1,7 @@
|
||||
var F = null
|
||||
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def method(param) {
|
||||
F = Fn.new {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
def static bar { true }
|
||||
def static baz { 1 }
|
||||
construct new() {}
|
||||
static def bar { true }
|
||||
static def baz { 1 }
|
||||
}
|
||||
|
||||
// Condition precedence.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct +(value) { // expect error
|
||||
construct +(value) { // expect error
|
||||
System.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct -(value) { // expect error
|
||||
construct -(value) { // expect error
|
||||
System.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct name=(value) { // expect error
|
||||
construct name=(value) { // expect error
|
||||
System.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
class Foo {
|
||||
def static construct new() {} // expect error
|
||||
def construct static new() {} // expect error
|
||||
static construct new() {} // expect error
|
||||
construct static new() {} // expect error
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct [value] { // expect error
|
||||
construct [value] { // expect error
|
||||
System.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct ! { // expect error
|
||||
construct ! { // expect error
|
||||
System.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
System.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
class Foo {
|
||||
def construct named() { _field = "named" }
|
||||
def construct other() { _field = "other" }
|
||||
construct named() { _field = "named" }
|
||||
construct other() { _field = "other" }
|
||||
|
||||
def toString { _field }
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new { // expect error
|
||||
construct new { // expect error
|
||||
System.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct base() {}
|
||||
construct base() {}
|
||||
}
|
||||
|
||||
class Bar is Foo {}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
class A {}
|
||||
|
||||
class B is A {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
super // expect error
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class A {
|
||||
def construct new(arg) {
|
||||
construct new(arg) {
|
||||
System.print("new A %(arg)")
|
||||
_field = arg
|
||||
}
|
||||
@ -8,7 +8,7 @@ class A {
|
||||
}
|
||||
|
||||
class B is A {
|
||||
def construct new(arg1, arg2) {
|
||||
construct new(arg1, arg2) {
|
||||
super(arg2)
|
||||
System.print("new B %(arg1)")
|
||||
_field = arg1
|
||||
@ -18,7 +18,7 @@ class B is A {
|
||||
}
|
||||
|
||||
class C is B {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
super("one", "two")
|
||||
System.print("new C")
|
||||
_field = "c"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() { _field = "Foo field" }
|
||||
construct new() { _field = "Foo field" }
|
||||
|
||||
def closeOverGet {
|
||||
return Fn.new { _field }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def write { System.print(_field) }
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def static bar {
|
||||
static def bar {
|
||||
Fn.new { _field = "wat" } // expect error
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def static bar {
|
||||
static def bar {
|
||||
_field = "wat" // expect error
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
class Outer {
|
||||
def foo {
|
||||
class Inner {
|
||||
def static bar {
|
||||
static def bar {
|
||||
_field = "nope" // expect error
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def set(a, b, c, d, e) {
|
||||
_a = a
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
class Outer {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def method {
|
||||
_field = "outer"
|
||||
System.print(_field) // expect: outer
|
||||
|
||||
class Inner {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def method {
|
||||
_field = "inner"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// This test exists mainly to make sure the GC traces instance fields.
|
||||
class Node {
|
||||
def construct new(left, value, right) {
|
||||
construct new(left, value, right) {
|
||||
_left = left
|
||||
_value = value
|
||||
_right = right
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def write { System.print(_field) } // Compile a use of the field...
|
||||
def init { _field = "value" } // ...before an assignment to it.
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Iter {
|
||||
def construct new(value) { _value = value }
|
||||
construct new(value) { _value = value }
|
||||
def iterate(iterator) { _value }
|
||||
def iteratorValue(iterator) { "value" }
|
||||
}
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
class Foo {
|
||||
def static foreign method // expect error
|
||||
static def foreign method // expect error
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
class Foo {
|
||||
def foreign method { "body" } // expect error
|
||||
}
|
||||
foreign def method { "body" } // expect error
|
||||
} // expect error
|
||||
|
||||
// The second error is cascaded.
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
class Foo {
|
||||
def foreign someUnknownMethod // expect runtime error: Could not find foreign method 'someUnknownMethod' for class Foo in module 'main'.
|
||||
foreign def someUnknownMethod // expect runtime error: Could not find foreign method 'someUnknownMethod' for class Foo in module 'main'.
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def getter {
|
||||
System.print("getter")
|
||||
@ -15,7 +15,7 @@ class Foo {
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def test {
|
||||
getter // expect: getter
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def getter {
|
||||
System.print("getter")
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def bar { "getter" }
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def bar=(value) {
|
||||
System.print("setter")
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Outer {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def getter {
|
||||
System.print("outer getter")
|
||||
@ -19,7 +19,7 @@ class Outer {
|
||||
method("arg") // expect: outer method
|
||||
|
||||
class Inner {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def getter {
|
||||
System.print("inner getter")
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
class Foo {
|
||||
def static getter {
|
||||
static def getter {
|
||||
System.print("getter")
|
||||
}
|
||||
|
||||
def static setter=(value) {
|
||||
static def setter=(value) {
|
||||
System.print("setter")
|
||||
}
|
||||
|
||||
def static method(a) {
|
||||
static def method(a) {
|
||||
System.print("method")
|
||||
}
|
||||
|
||||
def static test {
|
||||
static def test {
|
||||
getter // expect: getter
|
||||
setter = "value" // expect: setter
|
||||
method("arg") // expect: method
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def static methodOnFoo { System.print("foo") }
|
||||
static def methodOnFoo { System.print("foo") }
|
||||
}
|
||||
|
||||
class Bar is Foo {}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def foo(a, b) {
|
||||
_field1 = a
|
||||
@ -13,7 +13,7 @@ class Foo {
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def bar(a, b) {
|
||||
_field1 = a
|
||||
|
||||
@ -6,7 +6,7 @@ class Foo {
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def methodOnBar { System.print("bar") }
|
||||
def method(a, b) { System.print("bar") }
|
||||
def method(a, b, c, d) { System.print("bar") }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() { _field = "Foo field" }
|
||||
construct new() { _field = "Foo field" }
|
||||
|
||||
def closeOverFooGet {
|
||||
return Fn.new { Fn.new { _field } }
|
||||
@ -11,7 +11,7 @@ class Foo {
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
def construct new() {
|
||||
construct new() {
|
||||
super()
|
||||
_field = "Bar field"
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
class A {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
class B is A {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
class C is B {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
var a = A.new()
|
||||
var b = B.new()
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def method { "getter" }
|
||||
def method() { "no args" }
|
||||
def method(a) { a }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def bar {}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def thisHasAMethodNameThatIsExactly64CharactersLongWhichIsTheMaximum {
|
||||
return "result"
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def method000 { 1 }
|
||||
def method001 { 1 }
|
||||
def method002 { 1 }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def method(a, b) { "method %(a) %(b)" }
|
||||
def [a, b] { "subscript %(a) %(b)" }
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
Foo.new().someUnknownMethod // expect runtime error: Foo does not implement 'someUnknownMethod'.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
Foo.new().someUnknownMethod(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) // expect runtime error: Foo does not implement 'someUnknownMethod(_,_,_,_,_,_,_,_,_,_,_)'.
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
Foo.new().someUnknownMethod(1, 2) // expect runtime error: Foo does not implement 'someUnknownMethod(_,_)'.
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
Foo.new().someUnknownMethod(1) // expect runtime error: Foo does not implement 'someUnknownMethod(_)'.
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def +(other) { "infix + %(other)" }
|
||||
def -(other) { "infix - %(other)" }
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def bar { "on instance" }
|
||||
def static bar { "on metaclass" }
|
||||
static def bar { "on metaclass" }
|
||||
|
||||
def bar(arg) { "on instance %(arg)" }
|
||||
def static bar(arg) { "on metaclass %(arg)" }
|
||||
static def bar(arg) { "on metaclass %(arg)" }
|
||||
}
|
||||
|
||||
System.print(Foo.new().bar) // expect: on instance
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
def [a] { "1-subscript %(a)" }
|
||||
def [a, b] { "2-subscript %(a) %(b)" }
|
||||
def [a, b, c] { "3-subscript %(a) %(b) %(c)" }
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
var Module = "before"
|
||||
|
||||
class Other {
|
||||
def static change {
|
||||
static def change {
|
||||
Module = "after"
|
||||
}
|
||||
|
||||
def static show {
|
||||
static def show {
|
||||
System.print(Module)
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ Nonlocal = "after"
|
||||
System.print(Nonlocal) // expect: after
|
||||
|
||||
class Foo {
|
||||
def static method {
|
||||
static def method {
|
||||
Nonlocal = "method"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
def static bar { Bar.new() }
|
||||
construct new() {}
|
||||
static def bar { Bar.new() }
|
||||
}
|
||||
|
||||
class Bar {
|
||||
def construct new() {}
|
||||
def static foo { Foo.new() }
|
||||
construct new() {}
|
||||
static def foo { Foo.new() }
|
||||
}
|
||||
|
||||
System.print(Foo.bar) // expect: instance of Bar
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
var Global = "global"
|
||||
|
||||
class Foo {
|
||||
def construct new() {}
|
||||
construct new() {}
|
||||
|
||||
def method {
|
||||
System.print(Global)
|
||||
}
|
||||
|
||||
def static classMethod {
|
||||
static def classMethod {
|
||||
System.print(Global)
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user