Skip to content

Commit

Permalink
Rename tailcall to tailstrict as strict argument evaluation changes s…
Browse files Browse the repository at this point in the history
…emantics and should be more obvious
  • Loading branch information
sparkprime committed May 22, 2015
1 parent d024ea3 commit a3fa910
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ struct AST {
struct Apply : public AST {
AST *target;
std::vector<AST*> arguments;
bool tailcall;
Apply(const LocationRange &lr, AST *target, const std::vector<AST*> &arguments, bool tailcall)
: AST(lr, AST_APPLY), target(target), arguments(arguments), tailcall(tailcall)
bool tailstrict;
Apply(const LocationRange &lr, AST *target, const std::vector<AST*> &arguments, bool tailstrict)
: AST(lr, AST_APPLY), target(target), arguments(arguments), tailstrict(tailstrict)
{ }
};

Expand Down
2 changes: 1 addition & 1 deletion editors/atom/language-jsonnet/grammars/jsonnet.cson
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

{
'name': 'keyword.other.jsonnet'
'match': '\\b(local|tailcall)\\b'
'match': '\\b(local|tailstrict)\\b'
},

{
Expand Down
2 changes: 1 addition & 1 deletion editors/vim/syntax/jsonnet.vim
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ syn match Keyword "\<[a-zA-Z_][a-z0-9A-Z_]*\s*\(([^)]*)\)\?\s*+\?::\?:\?"
syntax keyword Include import importstr
syntax keyword Type function self super
syntax keyword Statement if then else for in
syntax keyword Special local tailcall
syntax keyword Special local tailstrict
syntax keyword Constant true false null
syntax keyword Underlined error

Expand Down
4 changes: 2 additions & 2 deletions lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ std::list<Token> jsonnet_lex(const std::string &filename, const char *input)
kind = Token::SELF;
} else if (id == "super") {
kind = Token::SUPER;
} else if (id == "tailcall") {
kind = Token::TAILCALL;
} else if (id == "tailstrict") {
kind = Token::TAILSTRICT;
} else if (id == "then") {
kind = Token::THEN;
} else if (id == "true") {
Expand Down
4 changes: 2 additions & 2 deletions lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Token {
IN,
LOCAL,
NULL_LIT,
TAILCALL,
TAILSTRICT,
THEN,
SELF,
SUPER,
Expand Down Expand Up @@ -112,7 +112,7 @@ struct Token {
case NULL_LIT: return "null";
case SELF: return "self";
case SUPER: return "super";
case TAILCALL: return "tailcall";
case TAILSTRICT: return "tailstrict";
case THEN: return "then";
case TRUE: return "true";

Expand Down
10 changes: 5 additions & 5 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ namespace {
case Token::OPERATOR:
case Token::PAREN_R:
case Token::SEMICOLON:
case Token::TAILCALL:
case Token::TAILSTRICT:
case Token::THEN:
throw unexpected(tok, "parsing terminal");

Expand Down Expand Up @@ -731,12 +731,12 @@ namespace {
std::vector<AST*> args;
Token end = parseCommaList(args, Token::PAREN_R,
"function argument", obj_level);
bool tailcall = false;
if (peek().kind == Token::TAILCALL) {
bool tailstrict = false;
if (peek().kind == Token::TAILSTRICT) {
pop();
tailcall = true;
tailstrict = true;
}
lhs = alloc->make<Apply>(span(begin, end), lhs, args, tailcall);
lhs = alloc->make<Apply>(span(begin, end), lhs, args, tailstrict);

} else if (op.kind == Token::BRACE_L) {
AST *obj;
Expand Down
22 changes: 11 additions & 11 deletions std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ limitations under the License.
if i >= std.length(str) then
arr + [v]
else if c == delim then
aux(str, delim, i2, arr + [v], "") tailcall
aux(str, delim, i2, arr + [v], "") tailstrict
else
aux(str, delim, i2, arr, v + c) tailcall;
aux(str, delim, i2, arr, v + c) tailstrict;
aux(str, c, 0, [], ""),

range(from, to)::
Expand All @@ -85,11 +85,11 @@ limitations under the License.
if i >= std.length(arr) then
running
else if arr[i] == null then
aux(arr, i + 1, first, running) tailcall
aux(arr, i + 1, first, running) tailstrict
else if first then
aux(arr, i + 1, false, running + arr[i]) tailcall
aux(arr, i + 1, false, running + arr[i]) tailstrict
else
aux(arr, i + 1, false, running + sep + arr[i]) tailcall;
aux(arr, i + 1, false, running + sep + arr[i]) tailstrict;
if std.type(arr) != "array" then
error "join second parameter should be array, got " + std.type(arr)
else if std.type(sep) == "string" then
Expand Down Expand Up @@ -545,15 +545,15 @@ limitations under the License.
if idx < 0 then
running
else
aux(func, arr, func(arr[idx], running), idx - 1) tailcall;
aux(func, arr, func(arr[idx], running), idx - 1) tailstrict;
aux(func, arr, init, std.length(arr) - 1),

foldl(func, arr, init)::
local aux(func, arr, running, idx) =
if idx >= std.length(arr) then
running
else
aux(func, arr, func(running, arr[idx]), idx + 1) tailcall;
aux(func, arr, func(running, arr[idx]), idx + 1) tailstrict;
aux(func, arr, init, 0),


Expand Down Expand Up @@ -698,7 +698,7 @@ limitations under the License.
// 2 LSB of i
base64_table[(arr[i] & 3) << 4] +
"==";
aux(arr, i + 3, r + str) tailcall
aux(arr, i + 3, r + str) tailstrict
else if i + 2 >= std.length(arr) then
local str =
// 6 MSB of i
Expand All @@ -708,7 +708,7 @@ limitations under the License.
// 4 LSB of i+1
base64_table[(arr[i+1] & 15) << 2] +
"=";
aux(arr, i + 3, r + str) tailcall
aux(arr, i + 3, r + str) tailstrict
else
local str =
// 6 MSB of i
Expand All @@ -719,7 +719,7 @@ limitations under the License.
base64_table[(arr[i+1] & 15) << 2 | (arr[i+2] & 192) >> 6] +
// 6 LSB of i+2
base64_table[(arr[i+2] & 63)];
aux(arr, i + 3, r + str) tailcall;
aux(arr, i + 3, r + str) tailstrict;

local sanity = std.foldl(function(r, a) r && (a < 256), bytes, true);
if !sanity then
Expand All @@ -746,7 +746,7 @@ limitations under the License.
local n3 =
if str[i+3] == "=" then []
else [(base64_inv[str[i+2]] & 3) << 6 | base64_inv[str[i+3]]];
aux(str, i+4, r + n1 + n2 + n3) tailcall;
aux(str, i+4, r + n1 + n2 + n3) tailstrict;
aux(str, 0, []),

base64Decode(str)::
Expand Down
2 changes: 1 addition & 1 deletion test_suite/recursive_function.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local sum(x, v) =
if x <= 0 then
v
else
sum(x - 1, x + v) tailcall;
sum(x - 1, x + v) tailstrict;

local sz = 10000;
std.assertEqual(sum(sz, 0), sz * (sz+1)/2) &&
Expand Down
6 changes: 3 additions & 3 deletions vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ namespace {
stack.emplace_back(args...);
}

/** If there is a tailcall annotated frame followed by some locals, pop them all. */
/** If there is a tailstrict annotated frame followed by some locals, pop them all. */
void tailCallTrimStack (void)
{
for (int i=stack.size()-1 ; i>=0 ; --i) {
Expand Down Expand Up @@ -1181,7 +1181,7 @@ namespace {
for (unsigned i=0 ; i<func->params.size() ; ++i)
bindings[func->params[i]] = args[i];
stack.newCall(ast.location, func, func->self, func->offset, bindings);
if (ast.tailcall) {
if (ast.tailstrict) {
stack.top().thunks = args;
stack.top().val = scratch;
stack.top().tailCall = true;
Expand Down Expand Up @@ -1744,7 +1744,7 @@ namespace {
thunk->fill(scratch);
} else if (auto *closure = dynamic_cast<HeapClosure*>(f.context)) {
if (f.elementId < f.thunks.size()) {
// If tailcall, force thunks
// If tailstrict, force thunks
HeapThunk *th = f.thunks[f.elementId++];
if (!th->filled) {
stack.newCall(f.location, th,
Expand Down

0 comments on commit a3fa910

Please sign in to comment.