Skip to content

Commit

Permalink
Revert "#74 Fixes to how setjmp/longjmp are used, plus beginning of a…
Browse files Browse the repository at this point in the history
… C__new keyword"

This reverts commit 24e1fac
  • Loading branch information
dibyendumajumdar committed Oct 13, 2021
1 parent db52f54 commit 772897e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 34 deletions.
1 change: 0 additions & 1 deletion include/ravi_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ enum TokenType {
TOK_defer,
TOK_C__decl,
TOK_C__unsafe,
TOK_C__new,
TOK_nil,
TOK_not,
TOK_or,
Expand Down
8 changes: 4 additions & 4 deletions src/chibicc/chibicc_tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void C_error(C_Parser *parser, char *fmt, ...) {
va_start(ap, fmt);
error_vsprintf(parser, fmt, ap);
error_sprintf(parser, "\n");
longjmp(parser->env, 1);
longjmp(&parser->env, 1);
}

// Reports an error message in the following format.
Expand Down Expand Up @@ -117,14 +117,14 @@ void C_error_at(C_Parser *tokenizer, char *loc, char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
verror_at(tokenizer, tokenizer->current_file->name, tokenizer->current_file->contents, line_no, loc, fmt, ap);
longjmp(tokenizer->env, 1);
longjmp(&tokenizer->env, 1);
}

void C_error_tok(C_Parser *tokenizer, C_Token *tok, char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
verror_at(tokenizer, tok->file->name, tok->file->contents, tok->line_no, tok->loc, fmt, ap);
longjmp(tokenizer->env, 1);
longjmp(&tokenizer->env, 1);
}

void C_warn_tok(C_Parser *tokenizer, C_Token *tok, char *fmt, ...) {
Expand Down Expand Up @@ -849,7 +849,7 @@ C_Token *C_tokenize_buffer(C_Parser *tokenizer, char *p) {
if (!p)
return NULL;

if (setjmp(tokenizer->env) != 0)
if (setjmp(&tokenizer->env) != 0)
return NULL;

// UTF-8 texts may start with a 3-byte "BOM" marker sequence.
Expand Down
3 changes: 0 additions & 3 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ static inline char lua_getlocaledecpoint(void) { return localeconv()->decimal_po
#define ARRAY_SIZE(array) ((int)(sizeof(array) / sizeof(array[0])))
/*Note: Following array was generated using utils/tokenstr.h */
static const char *const luaX_tokens[] = {

"and",
"break",
"do",
Expand All @@ -64,7 +63,6 @@ static const char *const luaX_tokens[] = {
"defer",
"C__decl",
"C__unsafe",
"C__new",
"nil",
"not",
"or",
Expand Down Expand Up @@ -98,7 +96,6 @@ static const char *const luaX_tokens[] = {
"<name>",
"<string>",
};

/* Says whether the given string represents a Lua/Ravi keyword i.e. reserved word */
static inline int is_reserved(const StringObject *s) { return s->reserved; }

Expand Down
2 changes: 1 addition & 1 deletion src/linearizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2310,7 +2310,7 @@ static void linearize_embedded_C_decl(Proc *proc, AstNode *node)

static void linearize_embedded_C(Proc *proc, AstNode *node)
{
if (node->embedded_C_stmt.c_statement_type == C__DECL) {
if (node->embedded_C_stmt.is_decl) {
linearize_embedded_C_decl(proc, node);
return;
}
Expand Down
12 changes: 1 addition & 11 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,19 +1188,13 @@ static AstNode *parse_goto_statment(ParserState *parser)
return goto_stmt;
}

static AstNode *parse_embedded_C_alloc(ParserState *parser) {
LexerState *ls = parser->ls;
raviX_syntaxerror(ls, "C__new not yet implemented");
return NULL;
}

static AstNode *parse_embedded_C(ParserState *parser, bool is_decl) {
LexerState *ls = parser->ls;
/* stat -> C (NAME {',' NAME}) string */
AstNode *node = raviX_allocate_ast_node(parser, STMT_EMBEDDED_C);
node->embedded_C_stmt.c_statement_type = is_decl ? C__DECL : C__UNSAFE;
node->embedded_C_stmt.C_src_snippet = NULL;
node->embedded_C_stmt.symbols = NULL;
node->embedded_C_stmt.is_decl = is_decl;
raviX_next(ls);
if (!is_decl && testnext(ls, '(')) {
switch (ls->t.token) {
Expand Down Expand Up @@ -1677,10 +1671,6 @@ static AstNode *parse_statement(ParserState *parser)
stmt = parse_goto_statment(parser);
break;
}
case TOK_C__new: {
stmt = parse_embedded_C_alloc(parser);
break;
}
case TOK_C__unsafe:
case TOK_C__decl: {
stmt = parse_embedded_C(parser, ls->t.token == TOK_C__decl);
Expand Down
15 changes: 2 additions & 13 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,10 @@ struct ForStatement {
AstNodeList *for_statement_list; /* statements in this block */
};
/* for embedded C */
enum EmbeddedCStatementType {
C__DECL,
C__UNSAFE,
C__NEW
};
struct EmbeddedCStatement {
enum EmbeddedCStatementType c_statement_type;
LuaSymbolList *symbols;
const StringObject *C_src_snippet; // C source snippet
union {
LuaSymbolList *symbols;
struct {
const StringObject *lua_namespace; // Userdata namespace
AstNode *size_expr;
} new_expr;
};
bool is_decl; // true if the snippet is only supposed to be declarations
};

/* To access the type field common to all expr objects */
Expand Down
2 changes: 1 addition & 1 deletion utils/tokenmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define TKDEF(_, __, ___) \
_(and) _(break) _(do) _(else) _(elseif) _(end) \
_(false) _(for) _(function) _(goto) _(if) _(in) _(local) \
_(defer) _(C__decl) _(C__unsafe) _(C__new) /* Ravi extensions */ \
_(defer) _(C__decl) _(C__unsafe) /* Ravi extensions */ \
_(nil) _(not) _(or) \
_(repeat) _(return) _(then) _(true) _(until) _(while) \
/* other terminal symbols */ \
Expand Down

0 comments on commit 772897e

Please sign in to comment.