summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-05-23 18:32:55 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-05-23 18:32:55 -0400
commit72e2940d78fc923f3d9af4ef333a40a0b397b065 (patch)
treee80b0dbd0c1ff9b59ea18ff0c5fd2741336a3a1f
parentdc6a7e198d2001086dd2245dd223bab3eda5670b (diff)
some cleanup involving blocks no longer having ret_exprs
-rw-r--r--main.c5
-rw-r--r--parse.c4
-rw-r--r--test.toc2
-rw-r--r--types.c4
-rw-r--r--types.h21
5 files changed, 11 insertions, 25 deletions
diff --git a/main.c b/main.c
index a092fce..94c0379 100644
--- a/main.c
+++ b/main.c
@@ -8,9 +8,6 @@
/*
@TODO:
-fix expr_find_end
-see if you can get rid of Expression.cgen.id--would mean that kind doesn't have to be a bitfield anymore
-check return #C("3");
initialization statements (maybe #init(-50), where -50 is the priority and <0 is reserved for standard library)
if we do #include "foo.toc", bar; and foo.toc fails, bar should be declared as TYPE_UNKNOWN (right now it's undeclared)
improve type_to_str:
@@ -28,6 +25,7 @@ don't bother generating ret_ if nothing's deferred
X ::= newtype(int); or something
any odd number of "s for a string
give each warning a number; #no_warn(warning), #no_warn_throughout_this_file(warning)
+test various parse errors; see if they can be improved, e.g. if else { 3; }
use point #except x;
optional -Wshadow
format errors so that vim/emacs can jump to them
@@ -43,7 +41,6 @@ once you have a bunch of test code:
- try making Value.slice a pointer
- should val_stack be on the allocator? what about temporary arrays?
-->on the contrary, should in_decls be off the allocator?
-error on x ::= {return; 3}
struct param inference
maybe macros are just inline functions
passing untyped expressions to macros
diff --git a/parse.c b/parse.c
index 7b8c76a..ce2a9eb 100644
--- a/parse.c
+++ b/parse.c
@@ -398,9 +398,7 @@ static Token *expr_find_end(Parser *p, ExprEndFlags flags) {
case KW_RBRACE:
--brace_level;
if (paren_level == 0 && brace_level == 0 && square_level == 0) {
- /* if there's an else/elif, the expr must continue */
- if (!(token_is_kw(token + 1, KW_ELSE) || token_is_kw(token + 1, KW_ELIF)))
- return token + 1; /* token afer } is end */
+ return token + 1; /* token afer } is end */
}
if (brace_level < 0)
return token;
diff --git a/test.toc b/test.toc
index d596c68..00b42d1 100644
--- a/test.toc
+++ b/test.toc
@@ -8,7 +8,7 @@ foo ::= fn(x: int) int {
if x == 3 {
return 7;
} else {
- return 3*x;
+ return #C("3*x");
}
}
diff --git a/types.c b/types.c
index 8815ddb..d8928e5 100644
--- a/types.c
+++ b/types.c
@@ -3715,6 +3715,10 @@ top:
err_print(s->where, "Returning type %s in function which returns %s.", got, expected);
return false;
}
+ /* e.g. return #C("3+6"); */
+ if (r->expr.type.kind == TYPE_UNKNOWN) {
+ r->expr.type = tr->fn->ret_type;
+ }
} else {
if (!type_is_void(&tr->fn->ret_type) || tr->fn->ret_decls) {
err_print(s->where, "No return value in non-void function.");
diff --git a/types.h b/types.h
index ceedcea..035543c 100644
--- a/types.h
+++ b/types.h
@@ -104,22 +104,10 @@ typedef double F64;
#define F64_MANT_DIG DBL_MANT_DIG
#define F64_DIG DBL_DIG
-#define F32_FMT "%.16f"
-#define F64_FMT "%.16f"
-
-typedef U32 IdentID; /* identifier ID for cgen (anonymous variables). not to be confused with IdentTree.id */
-
-/* for keeping track of whence something came */
-#ifdef TOC_DEBUG
-#define SOURCE_LOCATION char *src_file; int src_line;
-#define SOURCE_LOCATION_PARAMS char *src_file, int src_line,
-#define DEBUG_UNDERSCORE(x) x##_
-#else
-#define SOURCE_LOCATION
-#define SOURCE_LOCATION_PARAMS
-#define DEBUG_UNDERSCORE(x) x
-#endif
+#define F32_FMT "%.10f"
+#define F64_FMT "%.18f"
+typedef U32 IdentID; /* identifier ID for cgen (anonymous variables). */
typedef struct ErrCtx {
bool enabled;
@@ -764,13 +752,12 @@ enum {
EXPR_FOUND_TYPE = 0x01
};
-
typedef U8 ExprFlags;
typedef struct Expression {
Type type;
Location where;
- ExprKind kind : 8;
+ ExprKind kind;
ExprFlags flags;
struct {
IdentID id; /* cgen ID used for this expression */