v0.4.2-alpha

[Fix][Impl] 为了消除类构造带来的语法歧义,同时保持实现简洁和括号省略的语法,自此版本,引入了 `new` 操作符
            造成歧义的原方法:
                if a == A{}
            条件是 a == A,还是 a == A{} ?

            因此,现在使用 new a_struct{}来构造类
[Opti] 相较于 Fig v0.4.1-alpha版本,release O3同编译条件下
       Fib普通递归法性能提升 ~50%
       具体方式:
            增加了小整数优化,-128~127的整数现在会直接从IntPool获取而不是新构造
            ...忘了
[Fix] 类构造 shorthand模式忘写了,现在补上了
[Feat][Impl] 类型声明现在接受一个表达式,原为Identifier。实现 var start: time.Time = time.now() 的效果
             这是符合语法和语言特性的支持,类型为一等公民。类似Python的 <class 'type'>

[Impl] 修改了部分错误输出的细节
This commit is contained in:
2026-01-22 08:24:14 +08:00
parent 21641f888e
commit ca4ae143b4
27 changed files with 947 additions and 670 deletions

View File

@@ -1,13 +1,12 @@
#pragma once
#include "Ast/astBase.hpp"
#include <Ast/astBase.hpp>
#include <Ast/ast.hpp>
#include <Lexer/lexer.hpp>
#include <Core/fig_string.hpp>
#include <Error/error.hpp>
#include <memory>
#include <print>
#include <source_location>
#include <unordered_map>
@@ -248,7 +247,7 @@ namespace Fig
[[nodiscard]] SemicolonDisabler disableSemicolon() { return SemicolonDisabler(this); }
void expectSemicolon()
void expectSemicolon(std::source_location loc = std::source_location::current())
{
// if need semicolon and stream has `;`, consume it. if not need semicolon, do nothing
@@ -263,18 +262,18 @@ namespace Fig
}
// normal semicolon check
expectConsume(TokenType::Semicolon);
expectConsume(TokenType::Semicolon, loc);
}
void expectConsume(TokenType type, FString expected)
void expectConsume(TokenType type, FString expected, std::source_location loc = std::source_location::current())
{
expect(type, expected);
expect(type, expected, loc);
next();
}
void expectConsume(TokenType type)
void expectConsume(TokenType type, std::source_location loc = std::source_location::current())
{
expect(type);
expect(type, loc);
next();
}
@@ -314,6 +313,8 @@ namespace Fig
Ast::MapExpr __parseMapExpr(); // entry: current is `{`
Ast::InitExpr __parseInitExpr(Ast::Expression); // entry: current is `{`, ahead is struct type exp.
Ast::Expression __parseTupleOrParenExpr(); // entry: current is `(`
Ast::FunctionLiteralExpr __parseFunctionLiteralExpr(); // entry: current is Token::LParen after Token::Function