Skip to content

Commit a2cc015

Browse files
committed
fix(*): adjust sfn
1. adjust sfn 2. fix a fatal bug in astrunner please refer to the work log for details BREAKING CHANGE: the old version of the stamon-standard-library is incompatible
1 parent e01d696 commit a2cc015

File tree

10 files changed

+198
-200
lines changed

10 files changed

+198
-200
lines changed

demos/demo.stvc

1 Byte
Binary file not shown.

demos/demo1.stvc

1 Byte
Binary file not shown.

demos/demo2.stvc

1 Byte
Binary file not shown.

doc/工作日志/20250322.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 2025/03/22 工作日志
2+
3+
本次更新发行2.4.40。
4+
本次更新调整了依赖库和SFN机制,修复了一个致命的漏洞。
5+
6+
### 调整了依赖库和SFN机制
7+
8+
将依赖库接口的``printf````scanf``改为实现起来更为简单的``print````input``。现在开发者不实现格式字符串,也能移植Stamon了。
9+
除此之外,删除了早期测试用的,现在已经废弃的``printNum``SFN端口,并且将一些分支判断语句改为更简单明了的switch语句。
10+
11+
### 修复了一个漏洞
12+
13+
Stamon在初始化一个继承类时会崩溃,经调查发现是因为传参时直接将``Variable*``指针转换成``ClassType*``指针。目前该漏洞以修复。

include/stdc_implemented/stmlib.hpp

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "String.hpp"
1515
#include "stdlib.h"
16+
#include "ctype.h"
1617

1718
/*由于代码经常涉及到基类转派生类,所以我编写了这个可以直接转换的宏*/
1819
/*
@@ -47,7 +48,52 @@ String toString(T&& t){
4748
} \
4849
while (0)
4950

50-
#define platform_exit exit
51-
#define platform_system system
52-
#define platform_scanf scanf
53-
#define platform_printf printf
51+
void platform_exit(int code) {
52+
exit(code);
53+
}
54+
55+
int platform_system(String cmd) {
56+
return system(cmd.getstr());
57+
}
58+
59+
#define _PLATFORM_INPUT_BUFFER_SIZE 1024
60+
61+
String platform_input() {
62+
63+
String rst;
64+
65+
char buffer[_PLATFORM_INPUT_BUFFER_SIZE]; //缓冲区
66+
int pos = 0; //当前缓冲区所处位置
67+
68+
memset(buffer, 0, sizeof(buffer)); //清空buffer
69+
70+
char ch = getchar();
71+
72+
//先过滤先前的空格
73+
while(isspace(ch)) {
74+
ch = getchar();
75+
}
76+
77+
while(isspace(ch)==false) {
78+
if(pos == _PLATFORM_INPUT_BUFFER_SIZE-2) {
79+
//缓冲区已满
80+
rst += String(buffer);
81+
pos = 0;
82+
memset(buffer, 0, sizeof(buffer));
83+
}
84+
buffer[pos] = ch;
85+
pos++;
86+
ch = getchar();
87+
}
88+
89+
if(pos!=0) {
90+
//输入完成后,把缓冲区剩余的内容全部加入到rst当中
91+
rst += String(buffer);
92+
}
93+
94+
return rst;
95+
}
96+
97+
int platform_print(String s) {
98+
return printf("%s",s.getstr());
99+
}

include/template/stmlib.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
Description: 一些杂糅的库定义
77
*/
88

9-
//这个库原本叫做clib.h
10-
//由于需要引入c++代码,所以后缀改为hpp,顺便把文件名改为stmlib
11-
129
#pragma once
1310

1411
#include"String.hpp"
@@ -49,9 +46,9 @@ String toString(bool x);
4946
} \
5047
while (0)
5148

52-
//以下宏需要手动填写
49+
//以下函数需要自行实现
5350

54-
#define platform_exit
55-
#define platform_system
56-
#define platform_scanf
57-
#define platform_printf
51+
void platform_exit(int code);
52+
int platform_system(String cmd);
53+
String platform_input();
54+
int platform_print(String s);

src/bin-include/stdio.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import math;
55
import string;
66

77
func puts(s) {
8-
native("puts", s);
8+
native("print", s);
99
}
1010

1111
func print(n) {

src/config/StamonConfig.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace stamon {
1313
constexpr int STAMON_VER_X = 2;
1414
constexpr int STAMON_VER_Y = 4;
15-
constexpr int STAMON_VER_Z = 38;
15+
constexpr int STAMON_VER_Z = 40;
1616
} // namespace stamon
1717

1818
namespace stamon::config {

0 commit comments

Comments
 (0)