diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ast.c | 1 | ||||
| -rw-r--r-- | src/ast.h | 5 | ||||
| -rw-r--r-- | src/compile.c | 25 | ||||
| -rw-r--r-- | src/parse.c | 46 | ||||
| -rw-r--r-- | src/typecheck.c | 2 |
5 files changed, 4 insertions, 75 deletions
@@ -177,7 +177,6 @@ CORD ast_to_xml(ast_t *ast) optional_tagged("iterable", data.iter)) T(Skip, "<Skip>%r</Skip>", data.target) T(Stop, "<Stop>%r</Stop>", data.target) - T(PrintStatement, "<PrintStatement>%r</PrintStatement>", ast_list_to_xml(data.to_print)) T(Pass, "<Pass/>") T(Defer, "<Defer>%r<Defer/>", ast_to_xml(data.body)) T(Return, "<Return>%r</Return>", ast_to_xml(data.value)) @@ -123,7 +123,7 @@ typedef enum { Unknown = 0, None, Bool, Var, Int, Num, - TextLiteral, TextJoin, PrintStatement, + TextLiteral, TextJoin, Path, Declare, Assign, Power, Multiply, Divide, Mod, Mod1, Plus, Minus, Concat, LeftShift, UnsignedLeftShift, @@ -183,9 +183,6 @@ struct ast_s { const char *path; } Path; struct { - ast_list_t *to_print; - } PrintStatement; - struct { ast_t *var; type_ast_t *type; ast_t *value; diff --git a/src/compile.c b/src/compile.c index ad3097a7..a4f5b3ec 100644 --- a/src/compile.c +++ b/src/compile.c @@ -213,11 +213,6 @@ static void add_closed_vars(Table_t *closed_vars, env_t *enclosing_scope, env_t add_closed_vars(closed_vars, enclosing_scope, env, child->ast); break; } - case PrintStatement: { - for (ast_list_t *child = Match(ast, PrintStatement)->to_print; child; child = child->next) - add_closed_vars(closed_vars, enclosing_scope, env, child->ast); - break; - } case Declare: { add_closed_vars(closed_vars, enclosing_scope, env, Match(ast, Declare)->value); bind_statement(env, ast); @@ -1406,24 +1401,6 @@ static CORD _compile_statement(env_t *env, ast_t *ast) env->deferred = new(deferral_t, .defer_env=defer_env, .block=body, .next=env->deferred); return code; } - case PrintStatement: { - ast_list_t *to_print = Match(ast, PrintStatement)->to_print; - if (!to_print) - return CORD_EMPTY; - - CORD code = "say("; - if (to_print->next) code = CORD_all(code, "Texts("); - for (ast_list_t *chunk = to_print; chunk; chunk = chunk->next) { - if (chunk->ast->tag == TextLiteral) { - code = CORD_cat(code, compile(env, chunk->ast)); - } else { - code = CORD_cat(code, compile_string(env, chunk->ast, "USE_COLOR")); - } - if (chunk->next) code = CORD_cat(code, ", "); - } - if (to_print->next) code = CORD_all(code, ")"); - return CORD_cat(code, ", yes);"); - } case Return: { if (!env->fn_ret) code_err(ast, "This return statement is not inside any function"); auto ret = Match(ast, Return)->value; @@ -3738,7 +3715,7 @@ CORD compile(env_t *env, ast_t *ast) case Extern: code_err(ast, "Externs are not supported as expressions"); case TableEntry: code_err(ast, "Table entries should not be compiled directly"); case Declare: case Assign: case UPDATE_CASES: case For: case While: case Repeat: case StructDef: case LangDef: case Extend: - case EnumDef: case FunctionDef: case ConvertDef: case Skip: case Stop: case Pass: case Return: case DocTest: case PrintStatement: + case EnumDef: case FunctionDef: case ConvertDef: case Skip: case Stop: case Pass: case Return: case DocTest: code_err(ast, "This is not a valid expression"); default: case Unknown: code_err(ast, "Unknown AST: ", ast_to_xml_str(ast)); } diff --git a/src/parse.c b/src/parse.c index 9d4d35ee..fa021e28 100644 --- a/src/parse.c +++ b/src/parse.c @@ -131,7 +131,6 @@ static PARSER(parse_path); static PARSER(parse_reduction); static PARSER(parse_repeat); static PARSER(parse_return); -static PARSER(parse_say); static PARSER(parse_set); static PARSER(parse_skip); static PARSER(parse_stack_reference); @@ -1740,8 +1739,7 @@ PARSER(parse_assignment) { PARSER(parse_statement) { ast_t *stmt = NULL; if ((stmt=parse_declaration(ctx, pos)) - || (stmt=parse_doctest(ctx, pos)) - || (stmt=parse_say(ctx, pos))) + || (stmt=parse_doctest(ctx, pos))) return stmt; if (!(false @@ -2287,48 +2285,6 @@ PARSER(parse_doctest) { return NewAST(ctx->file, start, pos, DocTest, .expr=expr, .expected=expected); } -PARSER(parse_say) { - const char *start = pos; - if (!match(&pos, "!!")) return NULL; - spaces(&pos); - - ast_list_t *chunks = NULL; - CORD chunk = CORD_EMPTY; - const char *chunk_start = pos; - const char open_interp = '$'; - while (pos < ctx->file->text + ctx->file->len) { - if (*pos == open_interp) { // Interpolation - const char *interp_start = pos; - if (chunk) { - ast_t *literal = NewAST(ctx->file, chunk_start, pos, TextLiteral, .cord=chunk); - chunks = new(ast_list_t, .ast=literal, .next=chunks); - chunk = NULL; - } - ++pos; - ast_t *interp; - if (*pos == ' ' || *pos == '\t') - parser_err(ctx, pos, pos+1, "Whitespace is not allowed before an interpolation here"); - interp = expect(ctx, interp_start, &pos, parse_term, "I expected an interpolation term here"); - chunks = new(ast_list_t, .ast=interp, .next=chunks); - chunk_start = pos; - } else if (*pos == '\r' || *pos == '\n') { // Newline - break; - } else { // Plain character - chunk = CORD_cat_char(chunk, *pos); - ++pos; - } - } - - if (chunk) { - ast_t *literal = NewAST(ctx->file, chunk_start, pos, TextLiteral, .cord=chunk); - chunks = new(ast_list_t, .ast=literal, .next=chunks); - chunk = NULL; - } - - REVERSE_LIST(chunks); - return NewAST(ctx->file, start, pos, PrintStatement, .to_print=chunks); -} - PARSER(parse_use) { const char *start = pos; diff --git a/src/typecheck.c b/src/typecheck.c index c6f8b10f..c5243195 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -1020,7 +1020,7 @@ type_t *get_type(env_t *env, ast_t *ast) case Stop: case Skip: { return Type(AbortType); } - case Pass: case Defer: case PrintStatement: return Type(VoidType); + case Pass: case Defer: return Type(VoidType); case Negative: { ast_t *value = Match(ast, Negative)->value; type_t *t = get_type(env, value); |
