|
@@ -20,7 +20,8 @@ class Compiler {
|
|
|
PK_ALWAYS_PASS_BY_POINTER(Compiler)
|
|
PK_ALWAYS_PASS_BY_POINTER(Compiler)
|
|
|
|
|
|
|
|
inline static PrattRule rules[kTokenCount];
|
|
inline static PrattRule rules[kTokenCount];
|
|
|
- std::unique_ptr<Lexer> lexer;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Lexer lexer;
|
|
|
stack<CodeEmitContext> contexts;
|
|
stack<CodeEmitContext> contexts;
|
|
|
VM* vm;
|
|
VM* vm;
|
|
|
bool unknown_global_scope; // for eval/exec() call
|
|
bool unknown_global_scope; // for eval/exec() call
|
|
@@ -39,7 +40,7 @@ class Compiler {
|
|
|
void advance(int delta=1) { i += delta; }
|
|
void advance(int delta=1) { i += delta; }
|
|
|
|
|
|
|
|
CodeEmitContext* ctx() { return &contexts.top(); }
|
|
CodeEmitContext* ctx() { return &contexts.top(); }
|
|
|
- CompileMode mode() const{ return lexer->src->mode; }
|
|
|
|
|
|
|
+ CompileMode mode() const{ return lexer.src->mode; }
|
|
|
NameScope name_scope() const;
|
|
NameScope name_scope() const;
|
|
|
CodeObject_ push_global_context();
|
|
CodeObject_ push_global_context();
|
|
|
FuncDecl_ push_f_context(Str name);
|
|
FuncDecl_ push_f_context(Str name);
|
|
@@ -61,8 +62,9 @@ class Compiler {
|
|
|
Expr_ EXPR_VARS(); // special case for `for loop` and `comp`
|
|
Expr_ EXPR_VARS(); // special case for `for loop` and `comp`
|
|
|
|
|
|
|
|
template <typename T, typename... Args>
|
|
template <typename T, typename... Args>
|
|
|
- std::unique_ptr<T> make_expr(Args&&... args) {
|
|
|
|
|
- std::unique_ptr<T> expr = std::make_unique<T>(std::forward<Args>(args)...);
|
|
|
|
|
|
|
+ unique_ptr_64<T> make_expr(Args&&... args) {
|
|
|
|
|
+ void* p = pool64_alloc(sizeof(T));
|
|
|
|
|
+ unique_ptr_64<T> expr(new (p) T(std::forward<Args>(args)...));
|
|
|
expr->line = prev().line;
|
|
expr->line = prev().line;
|
|
|
return expr;
|
|
return expr;
|
|
|
}
|
|
}
|
|
@@ -70,7 +72,7 @@ class Compiler {
|
|
|
template<typename T>
|
|
template<typename T>
|
|
|
void _consume_comp(Expr_ expr){
|
|
void _consume_comp(Expr_ expr){
|
|
|
static_assert(std::is_base_of<CompExpr, T>::value);
|
|
static_assert(std::is_base_of<CompExpr, T>::value);
|
|
|
- std::unique_ptr<CompExpr> ce = make_expr<T>();
|
|
|
|
|
|
|
+ unique_ptr_64<CompExpr> ce = make_expr<T>();
|
|
|
ce->expr = std::move(expr);
|
|
ce->expr = std::move(expr);
|
|
|
ce->vars = EXPR_VARS();
|
|
ce->vars = EXPR_VARS();
|
|
|
consume(TK("in"));
|
|
consume(TK("in"));
|
|
@@ -130,9 +132,9 @@ class Compiler {
|
|
|
PyObject* to_object(const TokenValue& value);
|
|
PyObject* to_object(const TokenValue& value);
|
|
|
PyObject* read_literal();
|
|
PyObject* read_literal();
|
|
|
|
|
|
|
|
- void SyntaxError(Str msg){ lexer->throw_err("SyntaxError", msg, err().line, err().start); }
|
|
|
|
|
- void SyntaxError(){ lexer->throw_err("SyntaxError", "invalid syntax", err().line, err().start); }
|
|
|
|
|
- void IndentationError(Str msg){ lexer->throw_err("IndentationError", msg, err().line, err().start); }
|
|
|
|
|
|
|
+ void SyntaxError(Str msg){ lexer.throw_err("SyntaxError", msg, err().line, err().start); }
|
|
|
|
|
+ void SyntaxError(){ lexer.throw_err("SyntaxError", "invalid syntax", err().line, err().start); }
|
|
|
|
|
+ void IndentationError(Str msg){ lexer.throw_err("IndentationError", msg, err().line, err().start); }
|
|
|
|
|
|
|
|
public:
|
|
public:
|
|
|
Compiler(VM* vm, std::string_view source, const Str& filename, CompileMode mode, bool unknown_global_scope=false);
|
|
Compiler(VM* vm, std::string_view source, const Str& filename, CompileMode mode, bool unknown_global_scope=false);
|