Skip to content

Commit

Permalink
fix(*): release 2.4.25
Browse files Browse the repository at this point in the history
1. fix some bugs
please refer to the work log for details
  • Loading branch information
CLimber-Rong committed Sep 8, 2024
1 parent 15f29fb commit 6b30505
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 28 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ include_directories(${PROJECT_SOURCE_DIR}/src/tac)
set(CMAKE_C_FLAGS_DEBUG "-g -Og -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-g -Og -DDEBUG")

set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS_RELEASE "-O2 -static")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -static")

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_C_FLAGS "-std=c17")
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright [2024] [CLimber-Rong]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
29 changes: 26 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ COMPILER = g++
STRIP = strip
UPX = upx
REMOVE = del
LINK = -static
# -static选项让编译的程序更通用,但是程序体积更大,删去可以缩小程序体积

# 以下指令用于兼容先前调试时的编译指令

Expand Down Expand Up @@ -45,7 +47,7 @@ release:
xcopy src\bin-include bin\include /s /e /y /i
$(COMPILER) src/Main.cpp \
-o bin/stamon.exe \
-O2 \
-O2 $(LINK) \
-std=c++17 \
-I include/stdc_implemented \
-I src/ast \
Expand All @@ -66,7 +68,7 @@ release_win:
xcopy src\bin-include bin\include /s /e /y /i
$(COMPILER) src/Main.cpp \
-o bin/stamon.exe \
-O2 \
-O2 $(LINK) \
-std=c++17 \
-I include/stdc_implemented \
-I src/ast \
Expand All @@ -86,7 +88,28 @@ release_linux:
cp -r -T src/bin-include bin/include
$(COMPILER) src/Main.cpp \
-o bin/stamon \
-O2 \
-O2 $(LINK) \
-std=c++17 \
-I include/stdc_implemented \
-I src/ast \
-I src/data_type \
-I src/vm \
-I src/ir \
-I src/compiler \
-I src/sfn \
-I src/tac \
-I src \
-lm

$(STRIP) -s bin/stamon

release_macos:
# 编译MacOS版本
mkdir "bin/include"
cp -r "src/bin-include/" "bin/include"
$(COMPILER) src/Main.cpp \
-o bin/stamon \
-O2 $(LINK) \
-std=c++17 \
-I include/stdc_implemented \
-I src/ast \
Expand Down
Binary file modified demos/demo.stvc
Binary file not shown.
Binary file modified demos/demo1.stvc
Binary file not shown.
Binary file modified demos/demo2.stvc
Binary file not shown.
4 changes: 2 additions & 2 deletions doc/发行版使用指南.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Stamon目前支持以下指令:
|参数用法|功能|默认值|支持此参数的最低版本|
|-|-|-|-|
|--import=<boolean>|是否支持引用源码|true|2.4.4|
|--strip=<boolean>|设置虚拟机的对象内存限制(按字节计)|false|2.4.4|
|-I<path>|设置内存池缓存大小(按字节计)||2.4.4|
|--strip=<boolean>|是否剥削字节码调试信息|false|2.4.4|
|-I<path>|待引用源码所在的路径||2.4.4|

<br>

Expand Down
30 changes: 30 additions & 0 deletions doc/工作日志/20240908.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 2024/09/08 工作日志

本次修复了项目的许多漏洞,正式发行了2.4.25。

### 修复了大量漏洞

本次修复的漏洞有:

* 修复了运行时报错不显示报错文件和行号的漏洞
* 将String的初始化参数设为常量
* 修改LICENSE中的年份和版权所有者
* 修复了新建长度为负数的数列会内存泄漏的漏洞
* 修复了0为除数无法报错的漏洞


### 接下来要做的事

1. 支持文件处理库
2. 支持编译为平面字节码
3. 编写词法分析的保存功能
4. 编写AST的O1优化器
5. 完善标准库
6. 编写AST的解释器

### 后记

随着项目的发展,Stamon的流言蜚语越来越多,甚至还有人企图控制Stamon。
我认为这是正常的,我只想做我想要做的。

我将会发布各种规范,以此限制住一些素质低下的人的行径。
3 changes: 2 additions & 1 deletion doc/编译发行版指南.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 编译发行版指南

目前支持编译Windows、Linux系统
目前支持编译Windows、Linux、Macos系统

我们提供了两种编译方法:使用Makefile或CMake

Expand Down Expand Up @@ -55,4 +55,5 @@ ninja
* ``make release``:编译Windows发行版(旧指令,但仍然兼容)
* ``make release_win``:编译Windows发行版,在``bin``目录下生成``stamon.exe``
* ``make release_linux``:编译Linux发行版,在``bin``目录下生成``stamon``
* ``make release_macos``:编译MacOS发行版,在``bin``目录下生成``stamon``

4 changes: 2 additions & 2 deletions include/stdc_implemented/MemoryPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MemoryPool {
}

template<typename T, typename... Types> T *NewObject(Types &&...args) {
if (PoolCacheSize == 0) {
if (PoolCacheSize <= 0) {
// 无缓存,直接使用new
return new T(args...);
} else {
Expand Down Expand Up @@ -94,7 +94,7 @@ class MemoryPool {
}

template<typename T> void DeleteObject(T *object) {
if (PoolCacheSize == 0) {
if (PoolCacheSize <= 0) {
// 无缓存,直接使用delete
delete object;
return;
Expand Down
4 changes: 2 additions & 2 deletions include/stdc_implemented/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class String {
str = (char_type*)StrCalloc(1);
} //初始化为空字符串

String(char_type *s) {
String(const char_type *s) {
str = (char_type*)StrCalloc(strlen(s)+1);
strcpy(str, s);
} //初始化,将s复制到this

String(char_type* s, size_type len) {
String(const char_type* s, size_type len) {
str = (char_type*)StrCalloc(len+1);
strncpy(str, s, len);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Date: 24/02/24 11:59
Description:
* 命令行工具
* 该文件并不属于编译器或虚拟机的范畴,所以使用了平台库
* 该文件并不属于编译器或虚拟机的范畴,所以使用了C标准库
* 开发者可以自行更改或者建立属于自己的命令行工具
* 在使用stamon之前,你需要配置环境变量
* 即:将可执行文件所在目录设为STAMON
Expand Down
2 changes: 1 addition & 1 deletion src/Stamon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace stamon {
constexpr int STAMON_VER_X = 2;
constexpr int STAMON_VER_Y = 4;
constexpr int STAMON_VER_Z = 20;
constexpr int STAMON_VER_Z = 25;
}

#include"ArrayList.hpp"
Expand Down
93 changes: 80 additions & 13 deletions src/vm/AstRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
//利用t1、t2拷贝了一份left和right,使其原值不受影响

#define DIV_ERRCHECK \
if(r->getType()==0) {\
if(r->getVal()==0) {\
ThrowDivZeroError();\
}
//用于ASMD_OPERATE中的ErrCheck
Expand Down Expand Up @@ -282,6 +282,7 @@ namespace stamon::vm {
*/

String getDataTypeName(int type);
String getExcutePosition();
void ThrowTypeError(int type);
void ThrowPostfixError();
void ThrowIndexError();
Expand All @@ -293,6 +294,7 @@ namespace stamon::vm {
void ThrowReturnError();
void ThrowUnknownOperatorError();
void ThrowUnknownMemberError(int id);
void ThrowLengthError();

RetStatus excute(
ast::AstNode* main_node, bool isGC, int vm_mem_limit,
Expand Down Expand Up @@ -857,6 +859,7 @@ namespace stamon::vm {
CHECK_ASS(Sub, -,)
CHECK_ASS(Mul, *,)
CHECK_ASS(Div, /, DIV_ERRCHECK)
CE
CHECK_INT_ASS(Mod, %)
CHECK_INT_ASS(And, &)
CHECK_INT_ASS(XOr, ^)
Expand Down Expand Up @@ -1320,6 +1323,12 @@ namespace stamon::vm {
datatype::DataType* length = st.retval->data;
CDT(length, datatype::IntegerType)

if(((datatype::IntegerType*)length)->getVal()<0) {
//错误的数列长度
ThrowLengthError();
CE;
}

OPND_PUSH(length)

Variable* rst_var = new Variable(
Expand Down Expand Up @@ -1477,45 +1486,85 @@ inline String stamon::vm::AstRunner::getDataTypeName(int type) {
}
}

inline String stamon::vm::AstRunner::getExcutePosition() {
if(RunningFileName.equals("") && RunningLineNo==-1) {
//字节码中被没有调试信息,即被字节码被strip过
return String((char*)"");
} else {
return String((char*)"at \"")
+ RunningFileName
+ String((char*)"\": ")
+ toString(RunningLineNo)
+ String((char*)": ");
}
}


inline void stamon::vm::AstRunner::ThrowTypeError(int type) {
THROW_S(
String((char*)"Type Error: "
"an error of data type \'")
String((char*)"Type Error: ")
+ getExcutePosition()
+ String((char*)"an error of data type \'")
+ getDataTypeName(type)
+ String((char*)"\' occurred in the calculation")
)
}

inline void stamon::vm::AstRunner::ThrowPostfixError() {
THROW("ast::Postfix Error: unknown type of postfix")
THROW_S(
String((char*)"ast::Postfix Error: ")
+ getExcutePosition()
+ String((char*)"unknown type of postfix")
)
}

inline void stamon::vm::AstRunner::ThrowIndexError() {
THROW("Index Error: list index out of range")
THROW_S(
String((char*)"Index Error: ")
+ getExcutePosition()
+ String((char*)"list index out of range")
)
}

inline void stamon::vm::AstRunner::ThrowConstantsError() {
THROW("Constants Error: wrong index of constants")
THROW_S(
String((char*)"Constants Error: ")
+ getExcutePosition()
+ String((char*)"wrong index of constants")
)
}

inline void stamon::vm::AstRunner::ThrowDivZeroError() {
THROW("Zero Division Error: division by zero")
THROW_S(
String((char*)"Zero Division Error: ")
+ getExcutePosition()
+ String((char*)"division by zero")
)
}

inline void stamon::vm::AstRunner::ThrowBreakError() {
THROW("Break Error: \'break\' outside loop")
THROW_S(
String((char*)"Break Error: ")
+ getExcutePosition()
+ String((char*)"\'break\' outside loop")
)
}

inline void stamon::vm::AstRunner::ThrowContinueError() {
THROW("Continue Error: \'continue\' outside loop")
THROW_S(
String((char*)"Continue Error: ")
+ getExcutePosition()
+ String((char*)"\'continue\' outside loop")
)
}

inline void stamon::vm::AstRunner::ThrowArgumentsError(
int form_args, int actual_args
) {
THROW_S(
String((char*)"Arguments Error: takes ")
String((char*)"Arguments Error: ")
+ getExcutePosition()
+ String((char*)"takes ")
+ toString(form_args)
+ String((char*)" form arguments but ")
+ toString(actual_args)
Expand All @@ -1524,22 +1573,40 @@ inline void stamon::vm::AstRunner::ThrowArgumentsError(
}

inline void stamon::vm::AstRunner::ThrowReturnError() {
THROW("Return Error: \'return\' outside function")
THROW_S(
String((char*)"Return Error: ")
+ getExcutePosition()
+ String((char*)"\'return\' outside function")
)
}

inline void stamon::vm::AstRunner::ThrowUnknownOperatorError() {
THROW("Operator Error: unknown operator")
THROW_S(
String((char*)"Operator Error: ")
+ getExcutePosition()
+ String((char*)"unknown operator")
)
}

inline void stamon::vm::AstRunner::ThrowUnknownMemberError(int id) {
String iden = ((ir::IdenConstType*)tabconst[id])->getVal();
THROW_S(
String((char*)"Unknown Member Error: object has no member \'")
String((char*)"Unknown Member Error: ")
+ getExcutePosition()
+ String((char*)"object has no member \'")
+ iden
+ String((char*)"\'")
)
}

inline void stamon::vm::AstRunner::ThrowLengthError() {
THROW_S(
String((char*)"Length Error: ")
+ getExcutePosition()
+ String((char*)"the length must be non-negative")
)
}

inline void stamon::vm::AstRunner::BinaryOperatorConvert(
datatype::DataType*& left, datatype::DataType*& t1,
datatype::DataType*&right, datatype::DataType*& t2
Expand Down

0 comments on commit 6b30505

Please sign in to comment.