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:
@@ -33,14 +33,14 @@ public func format(objects ...) -> Any
|
||||
{
|
||||
if objects.length() < 1
|
||||
{
|
||||
throw FormatError{"Require format string"};
|
||||
throw new FormatError{"Require format string"};
|
||||
}
|
||||
|
||||
var fmt := objects[0];
|
||||
var fmtType := value.type(fmt);
|
||||
if fmtType != "String"
|
||||
{
|
||||
throw FormatError{"arg 0 (fmt) must be String type, got " + fmtType};
|
||||
throw new FormatError{"arg 0 (fmt) must be String type, got " + fmtType};
|
||||
}
|
||||
|
||||
var result := "";
|
||||
@@ -56,7 +56,7 @@ public func format(objects ...) -> Any
|
||||
{
|
||||
if (i + 1 >= length)
|
||||
{
|
||||
throw FormatError{"unclosed brace"};
|
||||
throw new FormatError{"unclosed brace"};
|
||||
}
|
||||
|
||||
var nextChar = fmt[i + 1];
|
||||
@@ -80,12 +80,12 @@ public func format(objects ...) -> Any
|
||||
|
||||
if endIndex == -1
|
||||
{
|
||||
throw FormatError{"unclosed brace"};
|
||||
throw new FormatError{"unclosed brace"};
|
||||
}
|
||||
|
||||
if argIndex >= objects.length()
|
||||
{
|
||||
throw FormatError{"require enough format expression"};
|
||||
throw new FormatError{"require enough format expression"};
|
||||
}
|
||||
|
||||
result += value.string_from(objects[argIndex]);
|
||||
@@ -102,7 +102,7 @@ public func format(objects ...) -> Any
|
||||
continue;
|
||||
}
|
||||
|
||||
throw FormatError{"invalid format syntax"};
|
||||
throw new FormatError{"invalid format syntax"};
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -122,14 +122,14 @@ public func formatByListArgs(objects) -> Any
|
||||
}
|
||||
if objects.length() < 1
|
||||
{
|
||||
throw FormatError{"Require format string"};
|
||||
throw new FormatError{"Require format string"};
|
||||
}
|
||||
|
||||
var fmt := objects[0];
|
||||
var fmtType := value.type(fmt);
|
||||
if fmtType != "String"
|
||||
{
|
||||
throw FormatError{"arg 0 (fmt) must be String type, got " + fmtType};
|
||||
throw new FormatError{"arg 0 (fmt) must be String type, got " + fmtType};
|
||||
}
|
||||
|
||||
var result := "";
|
||||
@@ -145,7 +145,7 @@ if objects.length() < 1
|
||||
{
|
||||
if (i + 1 >= length)
|
||||
{
|
||||
throw FormatError{"unclosed brace"};
|
||||
throw new FormatError{"unclosed brace"};
|
||||
}
|
||||
|
||||
var nextChar = fmt[i + 1];
|
||||
@@ -169,12 +169,12 @@ if objects.length() < 1
|
||||
|
||||
if endIndex == -1
|
||||
{
|
||||
throw FormatError{"unclosed brace"};
|
||||
throw new FormatError{"unclosed brace"};
|
||||
}
|
||||
|
||||
if argIndex >= objects.length()
|
||||
{
|
||||
throw FormatError{"require enough format expression"};
|
||||
throw new FormatError{"require enough format expression"};
|
||||
}
|
||||
|
||||
result += value.string_from(objects[argIndex]);
|
||||
@@ -191,7 +191,7 @@ if objects.length() < 1
|
||||
continue;
|
||||
}
|
||||
|
||||
throw FormatError{"invalid format syntax"};
|
||||
throw new FormatError{"invalid format syntax"};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -47,5 +47,5 @@ public struct Time
|
||||
|
||||
public func now() -> Time
|
||||
{
|
||||
return Time{__ftime_now_ns()};
|
||||
return new Time{__ftime_now_ns()};
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Ast/Expressions/VarExpr.hpp"
|
||||
#include "Ast/Statements/VarDef.hpp"
|
||||
#include "Ast/astBase.hpp"
|
||||
#include <Ast/Statements/InterfaceDefSt.hpp>
|
||||
#include <Ast/functionParameters.hpp>
|
||||
#include <Core/fig_string.hpp>
|
||||
@@ -35,11 +38,19 @@ namespace Fig
|
||||
{u8"true", Object::getTrueInstance()},
|
||||
{u8"false", Object::getFalseInstance()},
|
||||
{u8"Error",
|
||||
std::make_shared<Object>(InterfaceType(
|
||||
ErrorInterfaceTypeInfo,
|
||||
{Ast::InterfaceMethod(u8"toString", Ast::FunctionParameters({}, {}), u8"String", nullptr),
|
||||
Ast::InterfaceMethod(u8"getErrorClass", Ast::FunctionParameters({}, {}), u8"String", nullptr),
|
||||
Ast::InterfaceMethod(u8"getErrorMessage", Ast::FunctionParameters({}, {}), u8"String", nullptr)}))},
|
||||
std::make_shared<Object>(InterfaceType(ErrorInterfaceTypeInfo,
|
||||
{Ast::InterfaceMethod(u8"toString",
|
||||
Ast::FunctionParameters({}, {}),
|
||||
std::make_shared<Ast::VarExprAst>(u8"String"),
|
||||
nullptr),
|
||||
Ast::InterfaceMethod(u8"getErrorClass",
|
||||
Ast::FunctionParameters({}, {}),
|
||||
std::make_shared<Ast::VarExprAst>(u8"String"),
|
||||
nullptr),
|
||||
Ast::InterfaceMethod(u8"getErrorMessage",
|
||||
Ast::FunctionParameters({}, {}),
|
||||
std::make_shared<Ast::VarExprAst>(u8"String"),
|
||||
nullptr)}))},
|
||||
|
||||
{u8"Any", std::make_shared<Object>(StructType(ValueType::Any, nullptr, {}, true))},
|
||||
{u8"Int", std::make_shared<Object>(StructType(ValueType::Int, nullptr, {}, true))},
|
||||
|
||||
Reference in New Issue
Block a user