-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from EpitechPromo2026/develop
Develop
- Loading branch information
Showing
15 changed files
with
315 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "funkylib.fk" | ||
|
||
var str: u8[] = "Very Strong string really difficult to break and very long as you can see"; | ||
|
||
putnbr(strlen(str)); | ||
write 10; | ||
putstr(str); | ||
write 10; | ||
putstrrev(str); | ||
write 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
73 | ||
Very Strong string really difficult to break and very long as you can see | ||
ees nac uoy sa gnol yrev dna kaerb ot tluciffid yllaer gnirts gnortS yreV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "funkylib.fk" | ||
|
||
#define OP_END 0 | ||
#define OP_INC_DP 1 | ||
#define OP_DEC_DP 2 | ||
#define OP_INC_VAL 3 | ||
#define OP_DEC_VAL 4 | ||
#define OP_OUT 5 | ||
#define OP_INS 6 | ||
#define OP_JMP_FWD 7 | ||
#define OP_JMP_BCK 8 | ||
|
||
#define SUCCESS 0 | ||
#define FAILURE 1 | ||
|
||
#define PROGRAM_SIZE 4096 | ||
#define STACK_SIZE 512 | ||
#define DATA_SIZE 4096 | ||
|
||
allocate PROGRAM: u16 = PROGRAM_SIZE * 2; | ||
allocate STACK: u16 = STACK_SIZE; | ||
var SP: u32 = 0; | ||
|
||
|
||
|
||
var data1: u64 = _argv[1]; | ||
var pc: u16 = 0; | ||
var jmp_pc: u16 = 0; | ||
var i: i32 = 0; | ||
while (data1[i] != 0) { | ||
if (data1[i] == 62) { | ||
PROGRAM[pc * 2] = OP_INC_DP; | ||
} | ||
if (data1[i] == 60) { | ||
PROGRAM[pc * 2] = OP_DEC_DP; | ||
} | ||
if (data1[i] == 43) { | ||
PROGRAM[pc * 2] = OP_INC_VAL; | ||
} | ||
if (data1[i] == 45) { | ||
PROGRAM[pc * 2] = OP_DEC_VAL; | ||
} | ||
if (data1[i] == 46) { | ||
PROGRAM[pc * 2] = OP_OUT; | ||
} | ||
if (data1[i] == 44) { | ||
PROGRAM[pc * 2] = OP_INS; | ||
} | ||
if (data1[i] == 91) { | ||
PROGRAM[pc * 2] = OP_JMP_FWD; | ||
STACK[SP] = pc; | ||
SP = SP + 1; | ||
} | ||
if (data1[i] == 93) { | ||
SP = SP - 1; | ||
jmp_pc = STACK[SP]; | ||
PROGRAM[pc * 2] = OP_JMP_BCK; | ||
PROGRAM[pc * 2 + 1] = jmp_pc; | ||
PROGRAM[jmp_pc * 2 + 1] = pc; | ||
} | ||
i = i + 1; | ||
pc = pc + 1; | ||
} | ||
|
||
PROGRAM[pc * 2] = OP_END; | ||
|
||
pc = 0; | ||
allocate data2: u64 = DATA_SIZE; | ||
var ptr: u32 = DATA_SIZE; | ||
while (ptr != 0) { | ||
data2[ptr] = 0; | ||
ptr = ptr - 1; | ||
} | ||
while (PROGRAM[pc * 2] != OP_END) { | ||
if (PROGRAM[pc * 2] == OP_INC_DP) { | ||
ptr = ptr + 1; | ||
} | ||
if (PROGRAM[pc * 2] == OP_DEC_DP) { | ||
ptr = ptr - 1; | ||
} | ||
if (PROGRAM[pc * 2] == OP_INC_VAL) { | ||
data2[ptr] = data2[ptr] + 1; | ||
} | ||
if (PROGRAM[pc * 2] == OP_DEC_VAL) { | ||
data2[ptr] = data2[ptr] - 1; | ||
} | ||
if (PROGRAM[pc * 2] == OP_OUT) { | ||
write data2[ptr]; | ||
} | ||
if (PROGRAM[pc * 2] == OP_INS) { | ||
data2[ptr] = 0; | ||
} | ||
if (PROGRAM[pc * 2] == OP_JMP_FWD) { | ||
if (data2[ptr] == 0) { | ||
pc = PROGRAM[pc * 2 + 1]; | ||
} | ||
} | ||
if (PROGRAM[pc * 2] == OP_JMP_BCK) { | ||
if (data2[ptr] != 0) { | ||
pc = PROGRAM[pc * 2 + 1]; | ||
} | ||
} | ||
pc = pc + 1; | ||
} | ||
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
funk strlen(str: u64): i32 { | ||
var i: i32 = 0; | ||
while (str[i] != 0) { | ||
i = i + 1; | ||
} | ||
return i; | ||
} | ||
|
||
funk putstr(str: u64): i32 { | ||
var size: i32 = strlen(str); | ||
var i: i32 = 0; | ||
while (i < size) { | ||
write str[i]; | ||
i = i + 1; | ||
} | ||
return 0; | ||
} | ||
|
||
funk putnbr(nb: i32): i32 { | ||
var pow: i32 = 1; | ||
var save: i32 = nb; | ||
|
||
if (nb == 0) { | ||
write 48; | ||
return 0; | ||
} | ||
|
||
if (nb < 0) { | ||
write 45; | ||
nb = nb * -1; | ||
} | ||
|
||
while (save > 0) { | ||
pow = pow * 10; | ||
save = save / 10; | ||
} | ||
pow = pow / 10; | ||
|
||
while (pow > 0) { | ||
write ((nb / pow) + 48); | ||
nb = nb % pow; | ||
pow = pow / 10; | ||
} | ||
return 0; | ||
} | ||
|
||
funk putstrrev(str: u64): i32 { | ||
var size: i32 = strlen(str); | ||
var i: i32 = size - 1; | ||
while (i >= 0) { | ||
write str[i]; | ||
i = i - 1; | ||
} | ||
return 0; | ||
} | ||
|
||
funk strcmp(str1: u64, str2: u64): i32 { | ||
var i: i32 = 0; | ||
while (str1[i] != 0 && str2[i] != 0) { | ||
if (str1[i] != str2[i]) { | ||
return 1; | ||
} | ||
i = i + 1; | ||
} | ||
if (str1[i] != str2[i]) { | ||
return 1; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
documentation/docs/User Documentation/Funk_Introduction_cn.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
## The Funk编程语言 | ||
|
||
欢迎来到 *The Funk Programming Language*,这是有关Funk的介绍。Funk是一种受Rust和C传统启发的高级和低级控制语言。Funk注重现代语言的优雅语法,同时提供对代码的控制。 | ||
|
||
## Funk适用于谁? | ||
|
||
Funk适用于那些程序员,用一个词来形容就是“时髦的”。 | ||
在Funk基金会,我们希望有一种语言,能让来自各行各业和背景的人都能拥抱他们的真我。成为Funk程序员不仅仅是简历上的一项技能,更是一种精神 | ||
|
||
## 法律事项 | ||
|
||
Funk是一种开源语言,欢迎新的贡献者。写Funk代码的唯一要求是要时髦。 | ||
|
||
## 入门指南 | ||
|
||
让我们开始你的Funk之旅吧!有很多东西要学,但每个旅程都要从某个地方开始。我们将讨论在Funk中编写*Hello World!*程序以及如何使用语法。 | ||
|
||
## Hello World | ||
|
||
Hello World!这是经典的、每次学习新东西时都会写的第一个程序。在Funk中我们也会做同样的事情! | ||
|
||
首先,创建一个新的项目文件夹和一个名为 `hello.fk` 的文件。Funk使用 `.fk` 扩展名来表示其源文件。 | ||
|
||
通过使用 `var` 关键字创建一个变量。给它一个名字,然后使用 `:` 符号指定类型。Funk有多种原始类型,我们将在后面的章节中介绍,现在我们想要存储一个字符串。我们将使用 `u8[]` 来存储我们的字符串。然后使用 = 符号添加一个值。在这里指定我们的消息。用必需的 `;` 分号结束你的指令,这样你就创建了你的第一个变量! | ||
|
||
```ts | ||
var hello: u8[] = "Hello World!"; | ||
``` | ||
|
||
现在,为了打印它,我们将使用Funk的标准库:`funkystd`。 | ||
|
||
在你的文件顶部添加以下内容 `"#include "funkystd"`。这将为你的程序提供比以往更多的功能实用性!现在我们可以使用库中的 `putstr` 函数来打印我们的消息。 | ||
|
||
```ts | ||
#include "funkystd" | ||
|
||
var hello: u8[] = "Hello World!"; | ||
|
||
putstrln(hello); | ||
``` | ||
|
||
恭喜!你刚刚在Funk中编写了你的第一个程序!但等一下,我们还没有运行它!不要担心,我们将看到如何在下一章中运行Funk程序。 | ||
|
||
## 运行Funk程序 | ||
|
||
你刚刚完成了你的第一个Funk *Hello World!*,但你仍然不知道如何运行它?在本章中,我们将介绍Funk的执行方式。 | ||
|
||
Funk是一种**编译**语言,这意味着它需要被放入另一个程序中才能执行。但别担心,我们已经为你准备好了,你不必自己编写。使用命令行界面,输入以下命令: | ||
|
||
```console | ||
$ funkc hello.fk | ||
Created: out.bin | ||
``` | ||
|
||
你得到了一个新文件:`out.bin`。这个文件代表我们的程序的`字节码`。与其他编译语言一样,Funk首先被编译成包含程序所需指令集的字节码。 | ||
|
||
这个文件不是一个可执行二进制文件,而是字节码。现在我们可以使用`FVM`(Funk虚拟机)来执行字节码指令。想象一下Java的执行方式。你将项目编译成一个包含字节码的 `.jar` 文件,然后将其传递给`JVM`(Java虚拟机)。这不是剽窃,这是灵感来源。 | ||
|
||
```console | ||
$ fvm out.bin | ||
Hello World! | ||
``` | ||
|
||
现在它正在运行!你的第一个程序,现在在终端上显示输出。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,4 @@ funk strcmp(str1: u64, str2: u64): i32 { | |
} | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
var test: i32 = 125 + 5; | ||
var str1: u8 = 0; | ||
read str1; | ||
write str1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.