diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ast.c | 5 | ||||
| -rw-r--r-- | src/ast.h | 3 | ||||
| -rw-r--r-- | src/compile/expressions.c | 1 | ||||
| -rw-r--r-- | src/compile/functions.c | 4 | ||||
| -rw-r--r-- | src/compile/optionals.c | 7 | ||||
| -rw-r--r-- | src/compile/optionals.h | 1 | ||||
| -rw-r--r-- | src/formatter/formatter.c | 9 | ||||
| -rw-r--r-- | src/parse/binops.c | 3 | ||||
| -rw-r--r-- | src/parse/expressions.c | 15 | ||||
| -rw-r--r-- | src/parse/suffixes.c | 7 | ||||
| -rw-r--r-- | src/parse/suffixes.h | 1 | ||||
| -rw-r--r-- | src/typecheck.c | 6 |
12 files changed, 8 insertions, 54 deletions
@@ -269,7 +269,6 @@ Text_t ast_to_sexp(ast_t *ast) { T(LangDef, "(LangDef \"", data.name, "\" ", ast_to_sexp(data.namespace), ")"); T(Index, "(Index ", ast_to_sexp(data.indexed), " ", ast_to_sexp(data.index), ")"); T(FieldAccess, "(FieldAccess ", ast_to_sexp(data.fielded), " \"", data.field, "\")"); - T(Optional, "(Optional ", ast_to_sexp(data.value), ")"); T(NonOptional, "(NonOptional ", ast_to_sexp(data.value), ")"); T(DocTest, "(DocTest ", ast_to_sexp(data.expr), optional_sexp("expected", data.expected), ")"); T(Assert, "(Assert ", ast_to_sexp(data.expr), " ", optional_sexp("message", data.message), ")"); @@ -655,10 +654,6 @@ void ast_visit(ast_t *ast, void (*visitor)(ast_t *, void *), void *userdata) { ast_visit(Match(ast, FieldAccess)->fielded, visitor, userdata); return; } - case Optional: { - ast_visit(Match(ast, Optional)->value, visitor, userdata); - return; - } case NonOptional: { ast_visit(Match(ast, NonOptional)->value, visitor, userdata); return; @@ -269,7 +269,6 @@ typedef enum { LangDef, Index, FieldAccess, - Optional, NonOptional, DocTest, Assert, @@ -438,7 +437,7 @@ struct ast_s { } FieldAccess; struct { ast_t *value; - } Optional, NonOptional; + } NonOptional; struct { ast_t *expr, *expected; bool skip_source : 1; diff --git a/src/compile/expressions.c b/src/compile/expressions.c index cd244fec..f4326b00 100644 --- a/src/compile/expressions.c +++ b/src/compile/expressions.c @@ -113,7 +113,6 @@ Text_t compile(env_t *env, ast_t *ast) { } case HeapAllocate: case StackReference: return compile_typed_allocation(env, ast, get_type(env, ast)); - case Optional: return compile_optional(env, ast); case NonOptional: return compile_non_optional(env, ast); case Power: case Multiply: diff --git a/src/compile/functions.c b/src/compile/functions.c index e2fa8a11..5f6f7e91 100644 --- a/src/compile/functions.c +++ b/src/compile/functions.c @@ -552,10 +552,6 @@ static void add_closed_vars(Table_t *closed_vars, env_t *enclosing_scope, env_t add_closed_vars(closed_vars, enclosing_scope, env, Match(ast, FieldAccess)->fielded); break; } - case Optional: { - add_closed_vars(closed_vars, enclosing_scope, env, Match(ast, Optional)->value); - break; - } case NonOptional: { add_closed_vars(closed_vars, enclosing_scope, env, Match(ast, NonOptional)->value); break; diff --git a/src/compile/optionals.c b/src/compile/optionals.c index 86b4f771..d74f0f31 100644 --- a/src/compile/optionals.c +++ b/src/compile/optionals.c @@ -113,13 +113,6 @@ Text_t check_none(type_t *t, Text_t value) { } public -Text_t compile_optional(env_t *env, ast_t *ast) { - ast_t *value = Match(ast, Optional)->value; - Text_t value_code = compile(env, value); - return promote_to_optional(get_type(env, value), value_code); -} - -public Text_t compile_non_optional(env_t *env, ast_t *ast) { ast_t *value = Match(ast, NonOptional)->value; if (value->tag == Index && Match(value, Index)->index != NULL) return compile_indexing(env, value, true); diff --git a/src/compile/optionals.h b/src/compile/optionals.h index d30aaefb..28ee25b9 100644 --- a/src/compile/optionals.h +++ b/src/compile/optionals.h @@ -11,5 +11,4 @@ Text_t optional_into_nonnone(type_t *t, Text_t value); Text_t promote_to_optional(type_t *t, Text_t code); Text_t compile_none(type_t *t); Text_t check_none(type_t *t, Text_t value); -Text_t compile_optional(env_t *env, ast_t *ast); Text_t compile_non_optional(env_t *env, ast_t *ast); diff --git a/src/formatter/formatter.c b/src/formatter/formatter.c index a07b903d..69c1a213 100644 --- a/src/formatter/formatter.c +++ b/src/formatter/formatter.c @@ -269,10 +269,6 @@ OptionalText_t format_inline_code(ast_t *ast, Table_t comments) { ast_t *val = Match(ast, StackReference)->value; return Texts("&", must(termify_inline(val, comments))); } - /*inline*/ case Optional: { - ast_t *val = Match(ast, Optional)->value; - return Texts(must(termify_inline(val, comments)), "?"); - } /*inline*/ case NonOptional: { ast_t *val = Match(ast, NonOptional)->value; return Texts(must(termify_inline(val, comments)), "!"); @@ -698,11 +694,6 @@ Text_t format_code(ast_t *ast, Table_t comments, Text_t indent) { ast_t *val = Match(ast, StackReference)->value; return Texts("&(", termify(val, comments, indent), ")"); } - /*multiline*/ case Optional: { - if (inlined_fits) return inlined; - ast_t *val = Match(ast, Optional)->value; - return Texts(termify(val, comments, indent), "?"); - } /*multiline*/ case NonOptional: { if (inlined_fits) return inlined; ast_t *val = Match(ast, NonOptional)->value; diff --git a/src/parse/binops.c b/src/parse/binops.c index 4676b249..dd1ac3c2 100644 --- a/src/parse/binops.c +++ b/src/parse/binops.c @@ -73,8 +73,7 @@ ast_t *parse_infix_expr(parse_ctx_t *ctx, const char *pos, int min_tightness) { progress = (false || (new_term = parse_index_suffix(ctx, key)) || (new_term = parse_method_call_suffix(ctx, key)) || (new_term = parse_field_suffix(ctx, key)) - || (new_term = parse_fncall_suffix(ctx, key)) || (new_term = parse_optional_suffix(ctx, key)) - || (new_term = parse_non_optional_suffix(ctx, key))); + || (new_term = parse_fncall_suffix(ctx, key)) || (new_term = parse_non_optional_suffix(ctx, key))); if (progress) key = new_term; } if (key && key->tag == Var) key = NULL; diff --git a/src/parse/expressions.c b/src/parse/expressions.c index 7410f678..3cb47669 100644 --- a/src/parse/expressions.c +++ b/src/parse/expressions.c @@ -54,10 +54,9 @@ ast_t *parse_reduction(parse_ctx_t *ctx, const char *pos) { ast_t *key = NewAST(ctx->file, pos, pos, Var, .name = op_str); for (bool progress = true; progress;) { ast_t *new_term; - progress = - (false || (new_term = parse_index_suffix(ctx, key)) || (new_term = parse_method_call_suffix(ctx, key)) - || (new_term = parse_field_suffix(ctx, key)) || (new_term = parse_fncall_suffix(ctx, key)) - || (new_term = parse_optional_suffix(ctx, key)) || (new_term = parse_non_optional_suffix(ctx, key))); + progress = (false || (new_term = parse_index_suffix(ctx, key)) + || (new_term = parse_method_call_suffix(ctx, key)) || (new_term = parse_field_suffix(ctx, key)) + || (new_term = parse_fncall_suffix(ctx, key)) || (new_term = parse_non_optional_suffix(ctx, key))); if (progress) key = new_term; } if (key && key->tag == Var) key = NULL; @@ -98,8 +97,7 @@ ast_t *parse_heap_alloc(parse_ctx_t *ctx, const char *pos) { ast_t *ast = NewAST(ctx->file, start, pos, HeapAllocate, .value = val); for (;;) { - ast_t *next = parse_optional_suffix(ctx, ast); - if (!next) next = parse_non_optional_suffix(ctx, ast); + ast_t *next = parse_non_optional_suffix(ctx, ast); if (!next) break; ast = next; } @@ -123,8 +121,7 @@ ast_t *parse_stack_reference(parse_ctx_t *ctx, const char *pos) { ast_t *ast = NewAST(ctx->file, start, pos, StackReference, .value = val); for (;;) { - ast_t *next = parse_optional_suffix(ctx, ast); - if (!next) next = parse_non_optional_suffix(ctx, ast); + ast_t *next = parse_non_optional_suffix(ctx, ast); if (!next) break; ast = next; } @@ -212,7 +209,7 @@ ast_t *parse_term(parse_ctx_t *ctx, const char *pos) { progress = (false || (new_term = parse_index_suffix(ctx, term)) || (new_term = parse_method_call_suffix(ctx, term)) || (new_term = parse_field_suffix(ctx, term)) || (new_term = parse_fncall_suffix(ctx, term)) - || (new_term = parse_optional_suffix(ctx, term)) || (new_term = parse_non_optional_suffix(ctx, term))); + || (new_term = parse_non_optional_suffix(ctx, term))); if (progress) term = new_term; } return term; diff --git a/src/parse/suffixes.c b/src/parse/suffixes.c index 312f958f..7493a65d 100644 --- a/src/parse/suffixes.c +++ b/src/parse/suffixes.c @@ -25,13 +25,6 @@ ast_t *parse_field_suffix(parse_ctx_t *ctx, ast_t *lhs) { return NewAST(ctx->file, lhs->start, pos, FieldAccess, .fielded = lhs, .field = field); } -ast_t *parse_optional_suffix(parse_ctx_t *ctx, ast_t *lhs) { - if (!lhs) return NULL; - const char *pos = lhs->end; - if (match(&pos, "?")) return NewAST(ctx->file, lhs->start, pos, Optional, .value = lhs); - else return NULL; -} - ast_t *parse_non_optional_suffix(parse_ctx_t *ctx, ast_t *lhs) { if (!lhs) return NULL; const char *pos = lhs->end; diff --git a/src/parse/suffixes.h b/src/parse/suffixes.h index da2f23a2..23ca7182 100644 --- a/src/parse/suffixes.h +++ b/src/parse/suffixes.h @@ -11,4 +11,3 @@ ast_t *parse_index_suffix(parse_ctx_t *ctx, ast_t *lhs); ast_t *parse_method_call_suffix(parse_ctx_t *ctx, ast_t *self); ast_t *parse_non_optional_suffix(parse_ctx_t *ctx, ast_t *lhs); ast_t *parse_optional_conditional_suffix(parse_ctx_t *ctx, ast_t *stmt); -ast_t *parse_optional_suffix(parse_ctx_t *ctx, ast_t *lhs); diff --git a/src/typecheck.c b/src/typecheck.c index 64bf0fd8..b4798768 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -798,12 +798,6 @@ type_t *get_type(env_t *env, ast_t *ast) { default: return Type(PointerType, .pointed = get_type(env, value), .is_stack = true); } } - case Optional: { - ast_t *value = Match(ast, Optional)->value; - type_t *t = get_type(env, value); - if (t->tag == OptionalType) code_err(ast, "This value is already optional, it can't be converted to optional"); - return Type(OptionalType, .type = t); - } case NonOptional: { ast_t *value = Match(ast, NonOptional)->value; type_t *t = get_type(env, value); |
