tco
This commit is contained in:
43
parse.cm
43
parse.cm
@@ -1425,7 +1425,9 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
vars: [],
|
||||
in_loop: opts.in_loop == true,
|
||||
function_nr: fn_nr,
|
||||
is_function_scope: opts.is_func == true
|
||||
is_function_scope: opts.is_func == true,
|
||||
func_node: null,
|
||||
has_inner_func: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1478,6 +1480,15 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
return false
|
||||
}
|
||||
|
||||
var sem_find_func_scope = function(scope) {
|
||||
var s = scope
|
||||
while (s != null) {
|
||||
if (s.is_function_scope) return s
|
||||
s = s.parent
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
var sem_add_intrinsic = function(name) {
|
||||
if (find(intrinsics, name) == null) push(intrinsics, name)
|
||||
}
|
||||
@@ -1635,6 +1646,7 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
var pname = null
|
||||
var def_val = null
|
||||
var sr = null
|
||||
var enclosing = null
|
||||
|
||||
if (_assign_kinds[kind] == true) {
|
||||
sem_check_assign_target(scope, expr.left)
|
||||
@@ -1736,9 +1748,12 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
}
|
||||
|
||||
if (kind == "function") {
|
||||
enclosing = sem_find_func_scope(scope)
|
||||
if (enclosing != null) enclosing.has_inner_func = true
|
||||
fn_nr_val = expr.function_nr
|
||||
if (fn_nr_val == null) fn_nr_val = scope.function_nr
|
||||
fn_scope = make_scope(scope, fn_nr_val, {is_func: true})
|
||||
fn_scope.func_node = expr
|
||||
expr.outer = scope.function_nr
|
||||
i = 0
|
||||
while (i < length(expr.list)) {
|
||||
@@ -1819,6 +1834,8 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
var pname = null
|
||||
var def_val = null
|
||||
var sr = null
|
||||
var enclosing = null
|
||||
var func_scope = null
|
||||
var tt = null
|
||||
|
||||
if (kind == "var_list") {
|
||||
@@ -1941,7 +1958,26 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (kind == "return" || kind == "go") {
|
||||
if (kind == "go") {
|
||||
sem_check_expr(scope, stmt.expression)
|
||||
if (stmt.expression == null || stmt.expression.kind != "(") {
|
||||
sem_error(stmt, "'go' must be followed by a function call")
|
||||
} else {
|
||||
func_scope = sem_find_func_scope(scope)
|
||||
if (func_scope != null && func_scope.func_node != null) {
|
||||
if (func_scope.func_node.disruption != null) {
|
||||
sem_error(stmt, "cannot use 'go' in a function with a disruption clause")
|
||||
}
|
||||
if (func_scope.has_inner_func) {
|
||||
sem_error(stmt, "cannot use 'go' in a function that defines inner functions")
|
||||
}
|
||||
}
|
||||
stmt.tail = true
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
if (kind == "return") {
|
||||
sem_check_expr(scope, stmt.expression)
|
||||
if (stmt.expression != null && stmt.expression.kind == "(") {
|
||||
stmt.tail = true
|
||||
@@ -1982,11 +2018,14 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
}
|
||||
|
||||
if (kind == "function") {
|
||||
enclosing = sem_find_func_scope(scope)
|
||||
if (enclosing != null) enclosing.has_inner_func = true
|
||||
name = stmt.name
|
||||
if (name != null) sem_add_var(scope, name, {make: "function", fn_nr: scope.function_nr})
|
||||
fn_nr_val = stmt.function_nr
|
||||
if (fn_nr_val == null) fn_nr_val = scope.function_nr
|
||||
fn_scope = make_scope(scope, fn_nr_val, {is_func: true})
|
||||
fn_scope.func_node = stmt
|
||||
stmt.outer = scope.function_nr
|
||||
i = 0
|
||||
while (i < length(stmt.list)) {
|
||||
|
||||
Reference in New Issue
Block a user