diff --git a/README.md b/README.md index 2510d43..2329498 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Cosmo -Cosmo is a portable scripting language loosely based off of Lua. Cosmo easily allows the user to extend the language through the use of Proto objects, which describe the behavior of Objects. For example the following is a simple Vector class which describes behavior for a Vector-like object. +Cosmo is a portable scripting language loosely based off of Lua. Cosmo easily allows the user to extend the language through the use of Proto objects, which describe the behavior of Objects. For example the following is a simple Vector Proto which describes behavior for a Vector-like object. ``` -class Vector +proto Vector function __init(self) self.vector = {} self.x = 0 diff --git a/examples/increment.cosmo b/examples/increment.cosmo index 59f9841..1e2f8eb 100644 --- a/examples/increment.cosmo +++ b/examples/increment.cosmo @@ -1,4 +1,4 @@ -class Vector +proto Vector function __init(self) self.vector = {} self.x = 0 diff --git a/examples/newtest.cosmo b/examples/newtest.cosmo index 792dd80..76eb3dc 100644 --- a/examples/newtest.cosmo +++ b/examples/newtest.cosmo @@ -1,4 +1,4 @@ -class test +proto test function __init(self, x) self.setArg(x) end diff --git a/examples/stress.cosmo b/examples/stress.cosmo index 3cb6782..d869e05 100644 --- a/examples/stress.cosmo +++ b/examples/stress.cosmo @@ -1,4 +1,4 @@ -class Test +proto Test function __init(self, x) self.x = x end diff --git a/examples/test.cosmo b/examples/test.cosmo index fdc0a6c..cd84bf6 100644 --- a/examples/test.cosmo +++ b/examples/test.cosmo @@ -1,5 +1,5 @@ -// crafts a dummy class -class test end +// crafts a dummy proto +proto test end // instance of test var obj = test() diff --git a/src/clex.c b/src/clex.c index a6fe6f2..7cca720 100644 --- a/src/clex.c +++ b/src/clex.c @@ -5,7 +5,6 @@ CReservedWord reservedWords[] = { {TOKEN_AND, "and", 3}, - {TOKEN_CLASS, "class", 5}, {TOKEN_DO, "do", 2}, {TOKEN_ELSE, "else", 4}, {TOKEN_ELSEIF, "elseif", 6}, @@ -18,6 +17,7 @@ CReservedWord reservedWords[] = { {TOKEN_NIL, "nil", 3}, {TOKEN_NOT, "not", 3}, {TOKEN_OR, "or", 2}, + {TOKEN_PROTO, "proto", 5}, {TOKEN_RETURN, "return", 6}, {TOKEN_THEN, "then", 4}, {TOKEN_TRUE, "true", 4}, diff --git a/src/clex.h b/src/clex.h index aac2d65..f3b6547 100644 --- a/src/clex.h +++ b/src/clex.h @@ -49,7 +49,7 @@ typedef enum { TOKEN_END, TOKEN_FOR, TOKEN_FUNCTION, - TOKEN_CLASS, + TOKEN_PROTO, TOKEN_IF, TOKEN_LOCAL, TOKEN_NOT, diff --git a/src/cparse.c b/src/cparse.c index 4d97a1e..a8c271a 100644 --- a/src/cparse.c +++ b/src/cparse.c @@ -742,7 +742,7 @@ ParseRule ruleTable[] = { [TOKEN_END] = {NULL, NULL, PREC_NONE}, [TOKEN_FOR] = {NULL, NULL, PREC_NONE}, [TOKEN_FUNCTION] = {anonFunction, NULL, PREC_NONE}, - [TOKEN_CLASS] = {NULL, NULL, PREC_NONE}, + [TOKEN_PROTO] = {NULL, NULL, PREC_NONE}, [TOKEN_IF] = {NULL, NULL, PREC_NONE}, [TOKEN_LOCAL] = {NULL, NULL, PREC_NONE}, [TOKEN_NOT] = {NULL, NULL, PREC_NONE}, @@ -828,7 +828,7 @@ static void defineVariable(CParseState *pstate, uint16_t global, bool forceLocal valuePopped(pstate, 1); } -static void _class(CParseState *pstate) { +static void _proto(CParseState *pstate) { uint16_t var = parseVariable(pstate, "Expected identifer!", false); int entries = 0; @@ -1156,8 +1156,8 @@ static void expressionStatement(CParseState *pstate) { forLoop(pstate); } else if (match(pstate, TOKEN_FUNCTION)) { functionDeclaration(pstate); - } else if (match(pstate, TOKEN_CLASS)) { - _class(pstate); + } else if (match(pstate, TOKEN_PROTO)) { + _proto(pstate); } else if (match(pstate, TOKEN_RETURN)) { returnStatement(pstate); } else {