Merge branch 'mach' into mcode2
This commit is contained in:
46
parse.cm
46
parse.cm
@@ -1493,6 +1493,22 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
return functino_names[name] == true
|
||||
}
|
||||
|
||||
var derive_type_tag = function(expr) {
|
||||
if (expr == null) return null
|
||||
var k = expr.kind
|
||||
if (k == "array") return "array"
|
||||
if (k == "record") return "record"
|
||||
if (k == "function") return "function"
|
||||
if (k == "text" || k == "text literal") return "text"
|
||||
if (k == "number") {
|
||||
if (is_integer(expr.number)) return "integer"
|
||||
return "number"
|
||||
}
|
||||
if (k == "true" || k == "false") return "logical"
|
||||
if (k == "null") return "null"
|
||||
return null
|
||||
}
|
||||
|
||||
var _assign_kinds = {
|
||||
assign: true, "+=": true, "-=": true, "*=": true, "/=": true, "%=": true,
|
||||
"<<=": true, ">>=": true, ">>>=": true,
|
||||
@@ -1517,7 +1533,8 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
function_nr: v.function_nr,
|
||||
nr_uses: v.nr_uses,
|
||||
closure: v.closure == 1,
|
||||
level: 0
|
||||
level: 0,
|
||||
type_tag: v.type_tag
|
||||
}
|
||||
slots = slots + 1
|
||||
if (v.closure) close_slots = close_slots + 1
|
||||
@@ -1650,13 +1667,26 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (kind == "[") {
|
||||
sem_check_expr(scope, expr.left)
|
||||
sem_check_expr(scope, expr.right)
|
||||
if (expr.right != null) {
|
||||
if (expr.right.kind == "number" && is_integer(expr.right.number)) {
|
||||
expr.access_kind = "index"
|
||||
} else if (expr.right.kind == "text") {
|
||||
expr.access_kind = "field"
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
if (kind == "," || kind == "+" || kind == "-" || kind == "*" ||
|
||||
kind == "/" || kind == "%" || kind == "==" || kind == "!=" ||
|
||||
kind == "<" || kind == ">" || kind == "<=" || kind == ">=" ||
|
||||
kind == "&&" || kind == "||" || kind == "&" ||
|
||||
kind == "|" || kind == "^" || kind == "<<" || kind == ">>" ||
|
||||
kind == ">>>" || kind == "**" || kind == "in" ||
|
||||
kind == "." || kind == "[") {
|
||||
kind == ".") {
|
||||
sem_check_expr(scope, expr.left)
|
||||
sem_check_expr(scope, expr.right)
|
||||
return null
|
||||
@@ -1765,6 +1795,7 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
if (r.level > 0) r.v.closure = 1
|
||||
} else {
|
||||
expr.level = -1
|
||||
expr.intrinsic = true
|
||||
sem_add_intrinsic(name)
|
||||
}
|
||||
}
|
||||
@@ -1788,6 +1819,7 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
var pname = null
|
||||
var def_val = null
|
||||
var sr = null
|
||||
var tt = null
|
||||
|
||||
if (kind == "var_list") {
|
||||
i = 0
|
||||
@@ -1827,6 +1859,13 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
}
|
||||
}
|
||||
sem_check_expr(scope, stmt.right)
|
||||
if (name != null) {
|
||||
tt = derive_type_tag(stmt.right)
|
||||
if (tt != null) {
|
||||
existing = sem_find_var(scope, name)
|
||||
if (existing != null) existing.type_tag = tt
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -1904,6 +1943,9 @@ var parse = function(tokens, src, filename, tokenizer) {
|
||||
|
||||
if (kind == "return" || kind == "go") {
|
||||
sem_check_expr(scope, stmt.expression)
|
||||
if (stmt.expression != null && stmt.expression.kind == "(") {
|
||||
stmt.tail = true
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user