Browse Source

Remove `let`

Ginger Bill 8 years ago
parent
commit
a0d8dcd974
14 changed files with 30 additions and 35 deletions
  1. 1 1
      core/fmt.odin
  2. 2 2
      core/hash.odin
  3. 3 3
      core/opengl.odin
  4. 1 1
      core/os_linux.odin
  5. 1 1
      core/os_windows.odin
  6. 1 1
      core/strconv.odin
  7. 1 1
      core/utf8.odin
  8. 6 0
      src/check_expr.cpp
  9. 2 4
      src/check_stmt.cpp
  10. 2 3
      src/checker.cpp
  11. 0 1
      src/docs.cpp
  12. 1 2
      src/ir.cpp
  13. 9 14
      src/parser.cpp
  14. 0 1
      src/tokenizer.cpp

+ 1 - 1
core/fmt.odin

@@ -559,7 +559,7 @@ proc _fmt_int(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: int,
 	_pad(fi, s);
 	_pad(fi, s);
 }
 }
 
 
-let (
+var (
 	__DIGITS_LOWER = "0123456789abcdefx";
 	__DIGITS_LOWER = "0123456789abcdefx";
 	__DIGITS_UPPER = "0123456789ABCDEFX";
 	__DIGITS_UPPER = "0123456789ABCDEFX";
 )
 )

+ 2 - 2
core/hash.odin

@@ -210,7 +210,7 @@ proc murmur64(data: []u8) -> u64 {
 }
 }
 
 
 
 
-let _crc32_table = [256]u32{
+var _crc32_table = [256]u32{
 	0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
 	0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
 	0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
 	0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
 	0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
 	0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@@ -276,7 +276,7 @@ let _crc32_table = [256]u32{
 	0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
 	0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
 	0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
 	0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
 };
 };
-let _crc64_table = [256]u64{
+var _crc64_table = [256]u64{
 	0x0000000000000000, 0x42f0e1eba9ea3693, 0x85e1c3d753d46d26, 0xc711223cfa3e5bb5,
 	0x0000000000000000, 0x42f0e1eba9ea3693, 0x85e1c3d753d46d26, 0xc711223cfa3e5bb5,
 	0x493366450e42ecdf, 0x0bc387aea7a8da4c, 0xccd2a5925d9681f9, 0x8e224479f47cb76a,
 	0x493366450e42ecdf, 0x0bc387aea7a8da4c, 0xccd2a5925d9681f9, 0x8e224479f47cb76a,
 	0x9266cc8a1c85d9be, 0xd0962d61b56fef2d, 0x17870f5d4f51b498, 0x5577eeb6e6bb820b,
 	0x9266cc8a1c85d9be, 0xd0962d61b56fef2d, 0x17870f5d4f51b498, 0x5577eeb6e6bb820b,

+ 3 - 3
core/opengl.odin

@@ -41,7 +41,7 @@ proc _string_data(s: string) -> ^u8 #inline { return &s[0]; }
 
 
 var _libgl = win32.load_library_a(_string_data("opengl32.dll\x00"));
 var _libgl = win32.load_library_a(_string_data("opengl32.dll\x00"));
 
 
-proc get_proc_address(name: string) -> proc() #cc_c {
+proc get_proc_address(name: string) -> rawptr {
 	if name[len(name)-1] == 0 {
 	if name[len(name)-1] == 0 {
 		name = name[0..<len(name)-1];
 		name = name[0..<len(name)-1];
 	}
 	}
@@ -51,7 +51,7 @@ proc get_proc_address(name: string) -> proc() #cc_c {
 	if res == nil {
 	if res == nil {
 		res = win32.get_proc_address(_libgl, &name[0]);
 		res = win32.get_proc_address(_libgl, &name[0]);
 	}
 	}
-	return res;
+	return rawptr(res);
 }
 }
 
 
 var (
 var (
@@ -118,7 +118,7 @@ var (
 
 
 proc init() {
 proc init() {
 	proc set_proc_address(p: rawptr, name: string) #inline {
 	proc set_proc_address(p: rawptr, name: string) #inline {
-		var x = ^(proc() #cc_c)(p);
+		var x = ^rawptr(p);
 		x^ = get_proc_address(name);
 		x^ = get_proc_address(name);
 	}
 	}
 
 

+ 1 - 1
core/os_linux.odin

@@ -43,7 +43,7 @@ const (
 )
 )
 
 
 // "Argv" arguments converted to Odin strings
 // "Argv" arguments converted to Odin strings
-let args = _alloc_command_line_arguments();
+var args = _alloc_command_line_arguments();
 
 
 type _FileTime struct #ordered {
 type _FileTime struct #ordered {
 	seconds:     i64,
 	seconds:     i64,

+ 1 - 1
core/os_windows.odin

@@ -54,7 +54,7 @@ const (
 )
 )
 
 
 // "Argv" arguments converted to Odin strings
 // "Argv" arguments converted to Odin strings
-let args = _alloc_command_line_arguments();
+var args = _alloc_command_line_arguments();
 
 
 
 
 proc open(path: string, mode: int = O_RDONLY, perm: u32 = 0) -> (Handle, Errno) {
 proc open(path: string, mode: int = O_RDONLY, perm: u32 = 0) -> (Handle, Errno) {

+ 1 - 1
core/strconv.odin

@@ -416,7 +416,7 @@ proc round_shortest(d: ^Decimal, mant: u64, exp: int, flt: ^Float_Info) {
 }
 }
 
 
 const MAX_BASE = 32;
 const MAX_BASE = 32;
-let digits = "0123456789abcdefghijklmnopqrstuvwxyz";
+var digits = "0123456789abcdefghijklmnopqrstuvwxyz";
 
 
 
 
 proc is_integer_negative(u: u128, is_signed: bool, bit_size: int) -> (unsigned: u128, neg: bool) {
 proc is_integer_negative(u: u128, is_signed: bool, bit_size: int) -> (unsigned: u128, neg: bool) {

+ 1 - 1
core/utf8.odin

@@ -32,7 +32,7 @@ const (
 
 
 type AcceptRange struct { lo, hi: u8 }
 type AcceptRange struct { lo, hi: u8 }
 
 
-let (
+var (
 	accept_ranges = [5]AcceptRange{
 	accept_ranges = [5]AcceptRange{
 		{0x80, 0xbf},
 		{0x80, 0xbf},
 		{0xa0, 0xbf},
 		{0xa0, 0xbf},

+ 6 - 0
src/check_expr.cpp

@@ -5865,6 +5865,12 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
 				check_close_scope(c);
 				check_close_scope(c);
 				return kind;
 				return kind;
 			}
 			}
+
+			if (pl->body == NULL) {
+				error(node, "A procedure literal must have a body");
+				return kind;
+			}
+
 			check_procedure_later(c, c->curr_ast_file, empty_token, decl, type, pl->body, pl->tags);
 			check_procedure_later(c, c->curr_ast_file, empty_token, decl, type, pl->body, pl->tags);
 		}
 		}
 		check_close_scope(c);
 		check_close_scope(c);

+ 2 - 4
src/check_stmt.cpp

@@ -1657,7 +1657,6 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
 			if (decl->kind == AstNode_GenDecl) {
 			if (decl->kind == AstNode_GenDecl) {
 				switch (decl->GenDecl.token.kind) {
 				switch (decl->GenDecl.token.kind) {
 				case Token_var:
 				case Token_var:
-				case Token_let:
 					check_stmt(c, decl, flags);
 					check_stmt(c, decl, flags);
 					break;
 					break;
 				}
 				}
@@ -1673,8 +1672,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
 		for_array(i, gd->specs) {
 		for_array(i, gd->specs) {
 			AstNode *spec = gd->specs[i];
 			AstNode *spec = gd->specs[i];
 			switch (gd->token.kind) {
 			switch (gd->token.kind) {
-			case Token_var:
-			case Token_let: {
+			case Token_var: {
 				ast_node(vd, ValueSpec, spec);
 				ast_node(vd, ValueSpec, spec);
 
 
 				Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count);
 				Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count);
@@ -1699,7 +1697,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
 							found = current_scope_lookup_entity(c->context.scope, str);
 							found = current_scope_lookup_entity(c->context.scope, str);
 						}
 						}
 						if (found == NULL) {
 						if (found == NULL) {
-							entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, gd->token.kind == Token_let);
+							entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, false);
 							entity->identifier = name;
 							entity->identifier = name;
 
 
 							AstNode *fl = c->context.curr_foreign_library;
 							AstNode *fl = c->context.curr_foreign_library;

+ 2 - 3
src/checker.cpp

@@ -1635,8 +1635,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_sco
 					check_arity_match(c, vs);
 					check_arity_match(c, vs);
 				} break;
 				} break;
 
 
-				case Token_var:
-				case Token_let: {
+				case Token_var: {
 					if (!c->context.scope->is_file) {
 					if (!c->context.scope->is_file) {
 						// NOTE(bill): local scope -> handle later and in order
 						// NOTE(bill): local scope -> handle later and in order
 						break;
 						break;
@@ -1671,7 +1670,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_sco
 							error(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
 							error(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
 							continue;
 							continue;
 						}
 						}
-						Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident, NULL, gd->token.kind == Token_let);
+						Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident, NULL, false);
 						e->Variable.is_thread_local = (gd->flags & VarDeclFlag_thread_local) != 0;
 						e->Variable.is_thread_local = (gd->flags & VarDeclFlag_thread_local) != 0;
 						e->identifier = name;
 						e->identifier = name;
 
 

+ 0 - 1
src/docs.cpp

@@ -95,7 +95,6 @@ void print_declaration(AstNode *decl) {
 			AstNode *spec = gd->specs[spec_index];
 			AstNode *spec = gd->specs[spec_index];
 			switch(gd->token.kind) {
 			switch(gd->token.kind) {
 			case Token_var:
 			case Token_var:
-			case Token_let:
 				break;
 				break;
 			case Token_const:
 			case Token_const:
 				break;
 				break;

+ 1 - 2
src/ir.cpp

@@ -5947,8 +5947,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
 		for_array(i, gd->specs) {
 		for_array(i, gd->specs) {
 			AstNode *spec = gd->specs[i];
 			AstNode *spec = gd->specs[i];
 			switch (gd->token.kind) {
 			switch (gd->token.kind) {
-			case Token_var:
-			case Token_let: {
+			case Token_var: {
 				ast_node(vd, ValueSpec, spec);
 				ast_node(vd, ValueSpec, spec);
 
 
 				irModule *m = proc->module;
 				irModule *m = proc->module;

+ 9 - 14
src/parser.cpp

@@ -1760,7 +1760,6 @@ void fix_advance_to_next_stmt(AstFile *f) {
 
 
 		case Token_var:
 		case Token_var:
 		case Token_const:
 		case Token_const:
-		case Token_let:
 		case Token_type:
 		case Token_type:
 		case Token_proc:
 		case Token_proc:
 		case Token_foreign:
 		case Token_foreign:
@@ -1902,7 +1901,6 @@ void expect_semicolon(AstFile *f, AstNode *s) {
 		if (s->kind == AstNode_GenDecl) {
 		if (s->kind == AstNode_GenDecl) {
 			switch (s->GenDecl.token.kind) {
 			switch (s->GenDecl.token.kind) {
 			case Token_var:
 			case Token_var:
-			case Token_let:
 				node_string = str_lit("variable declaration");
 				node_string = str_lit("variable declaration");
 				break;
 				break;
 			case Token_const:
 			case Token_const:
@@ -2292,7 +2290,9 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
 		AstNode *type = parse_proc_type(f, token, &link_name);
 		AstNode *type = parse_proc_type(f, token, &link_name);
 		u64 tags = type->ProcType.tags;
 		u64 tags = type->ProcType.tags;
 
 
-		if (f->curr_token.kind == Token_OpenBrace) {
+		if (allow_token(f, Token_Undef)) {
+			return ast_proc_lit(f, type, NULL, tags, link_name);
+		} else if (f->curr_token.kind == Token_OpenBrace) {
 			if ((tags & ProcTag_foreign) != 0) {
 			if ((tags & ProcTag_foreign) != 0) {
 				syntax_error(token, "A procedure tagged as `#foreign` cannot have a body");
 				syntax_error(token, "A procedure tagged as `#foreign` cannot have a body");
 			}
 			}
@@ -2749,7 +2749,9 @@ AstNode *parse_proc_decl(AstFile *f) {
 	f->allow_gen_proc_type = prev_allow_gen_proc_type;
 	f->allow_gen_proc_type = prev_allow_gen_proc_type;
 
 
 
 
-	if (f->curr_token.kind == Token_OpenBrace) {
+	if (allow_token(f, Token_Undef)) {
+		body = NULL;
+	} else if (f->curr_token.kind == Token_OpenBrace) {
 		if ((tags & ProcTag_foreign) != 0) {
 		if ((tags & ProcTag_foreign) != 0) {
 			syntax_error(token, "A procedure tagged as `#foreign` cannot have a body");
 			syntax_error(token, "A procedure tagged as `#foreign` cannot have a body");
 		}
 		}
@@ -3002,7 +3004,6 @@ void parse_foreign_block_decl(AstFile *f, Array<AstNode *> *decls) {
 	case AstNode_GenDecl:
 	case AstNode_GenDecl:
 		switch (decl->GenDecl.token.kind) {
 		switch (decl->GenDecl.token.kind) {
 		case Token_var:
 		case Token_var:
-		case Token_let:
 			array_add(decls, decl);
 			array_add(decls, decl);
 			return;
 			return;
 		}
 		}
@@ -3019,7 +3020,6 @@ AstNode *parse_decl(AstFile *f) {
 	switch (f->curr_token.kind) {
 	switch (f->curr_token.kind) {
 	case Token_var:
 	case Token_var:
 	case Token_const:
 	case Token_const:
-	case Token_let:
 		func = parse_value_spec;
 		func = parse_value_spec;
 		break;
 		break;
 
 
@@ -3088,7 +3088,6 @@ AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) {
 	switch (f->curr_token.kind) {
 	switch (f->curr_token.kind) {
 	case Token_var:
 	case Token_var:
 	case Token_const:
 	case Token_const:
-	case Token_let:
 		return parse_decl(f);
 		return parse_decl(f);
 	}
 	}
 
 
@@ -4247,7 +4246,6 @@ AstNode *parse_stmt(AstFile *f) {
 
 
 	case Token_var:
 	case Token_var:
 	case Token_const:
 	case Token_const:
-	case Token_let:
 	case Token_proc:
 	case Token_proc:
 	case Token_type:
 	case Token_type:
 	case Token_import:
 	case Token_import:
@@ -4287,8 +4285,7 @@ AstNode *parse_stmt(AstFile *f) {
 		// TODO(bill): Make using statements better
 		// TODO(bill): Make using statements better
 		Token token = expect_token(f, Token_using);
 		Token token = expect_token(f, Token_using);
 		AstNode *decl = NULL;
 		AstNode *decl = NULL;
-		if (f->curr_token.kind == Token_var ||
-		    f->curr_token.kind == Token_let) {
+		if (f->curr_token.kind == Token_var) {
 			decl = parse_decl(f);
 			decl = parse_decl(f);
 			expect_semicolon(f, decl);
 			expect_semicolon(f, decl);
 		} else {
 		} else {
@@ -4307,8 +4304,7 @@ AstNode *parse_stmt(AstFile *f) {
 
 
 
 
 		if (decl != NULL && decl->kind == AstNode_GenDecl) {
 		if (decl != NULL && decl->kind == AstNode_GenDecl) {
-			if (decl->GenDecl.token.kind != Token_var &&
-			    decl->GenDecl.token.kind != Token_let) {
+			if (decl->GenDecl.token.kind != Token_var) {
 				syntax_error(token, "`using` may only be applied to variable declarations");
 				syntax_error(token, "`using` may only be applied to variable declarations");
 				return decl;
 				return decl;
 			}
 			}
@@ -4384,8 +4380,7 @@ AstNode *parse_stmt(AstFile *f) {
 			AstNode *s = parse_stmt(f);
 			AstNode *s = parse_stmt(f);
 
 
 			if (s->kind == AstNode_GenDecl) {
 			if (s->kind == AstNode_GenDecl) {
-				if (s->GenDecl.token.kind != Token_var &&
-				    s->GenDecl.token.kind != Token_let) {
+				if (s->GenDecl.token.kind != Token_var) {
 					syntax_error(token, "`thread_local` may only be applied to variable declarations");
 					syntax_error(token, "`thread_local` may only be applied to variable declarations");
 				}
 				}
 				if (f->curr_proc != NULL) {
 				if (f->curr_proc != NULL) {

+ 0 - 1
src/tokenizer.cpp

@@ -84,7 +84,6 @@ TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \
 \
 \
 TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
 TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
 	TOKEN_KIND(Token_var,                    "var"),                    \
 	TOKEN_KIND(Token_var,                    "var"),                    \
-	TOKEN_KIND(Token_let,                    "let"),                    \
 	TOKEN_KIND(Token_const,                  "const"),                  \
 	TOKEN_KIND(Token_const,                  "const"),                  \
 	TOKEN_KIND(Token_type,                   "type"),                   \
 	TOKEN_KIND(Token_type,                   "type"),                   \
 	TOKEN_KIND(Token_import,                 "import"),                 \
 	TOKEN_KIND(Token_import,                 "import"),                 \