-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraft.fun
More file actions
155 lines (129 loc) · 5.23 KB
/
draft.fun
File metadata and controls
155 lines (129 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// For scripting fun should be callable by a standard shebang line.
#!/usr/bin/env fun
/*
This file is the creative are of an idea. Here will be fun defined before any
implementation or programming. Just a compiled version of many ideas... ;)
Copyright 2025 Johannes Findeisen <you@hanez.org>
License: Apache-2.0 License, https://opensource.org/license/apache-2-0
Birthdate: 2025-09-10
*/
// This line MUST work as a comment.
// This is a comment! /* in combination with */ are a multiline comments.
/*
- No ";" for line termination. New commands must be processed in a new line,
not like in bash where you can do df; df; But you can do df; df;. :)
- Something like printf and date formatation must exist.
- Can be used inside ''; Like echo 'x "y" z'. ' has higher priority.
- Intendation would be nice if would be fixed on 2 whitespaces. No tabs!
- Internals like range() must not be redefined!
- Functions and variables can not have the same name! If a function with name
foo() exists, you can not asign a avlue to foo = value.
- Strings must be initialized with the type they are and can not be missused.
If a string is 1 you need to cast it to num to become a new type.
- Strings are always qouted wit "" but can be qouted with '' too, but then you
can use "" inside the string. ' can be used in the string too, but it than
must be escaped with \.
- Not Git based includes like in Go! No way! All dependencies MUST be managed
inside the fun projects code base.
- Global variables can not be redefined somwhere in the code. So defining a
variable in a function that exist globally would overwrite the memory of the
global variable. Local variables SHOULD be prefixed with _ or some other
prefix and named to be unique. If you have a global variable i in a file you
can not use i in that file anymore. If you try to define a global variable
in your code, that is defined already in a library as a global var,
execution will fail. So, keep the use of globals vars very very limited!
*/
// Includes from a system installed file. Included libs should support the
// extension .so and the .fun extension for core libraries implemented in fun,
// but can be included without the extension. This directory must support
// subdirectories. The root for this diretory is e.g. /var/lib/fun/. A file
// named fun.so and fun.fun can reside here, but the .fun file will be included
// here; The .fun file can then include a .so file with the same name, but then
// extension .so is required.
// Some examples:
#include crypt/md5
#include crypt/sha256
#include date
#include math
// Files can be included with or without the extension.
#include native/lib.fun
#include std.so
#include network
#include process
#include socket
#include thread
#include time
// Includes from current working directory. The prefixed / makes the difference.
// Files here are written in fun and have the .fun extension, but can be
// included with or without the extension. This directory must support
// subdirectories.
#include some_fun_file
#include includes/some_include_file.fun
// But it should be possible for .fun like system includes. Files here are
// written in fun and have the .fun extension, but can be included without the
// extension. This directory must support subdirectories.
#include /home/hanez/fun/file.fun
// Keywords (e.g., if, for, while, f)
// Operators (+, -, *, /, =, ==)
// Comparisons (==, !=, >, <)
// Variable names can contain chars and numbers from a_z, A_Z and 0_9, but can
// not start with a number.
// Boolean variables should be true/false and 1/0
boolean funny = true
// fun has a byte variable where raw bytes can bes stored.
byte mario = 0x23
// Strings need '.
byte luigi = "Jehaa!"
// Numbers don't use ' here.
byte todd = 42
float new_float = 0.12345
// Global variables can be used everywhere in the code. Even in included files.
// It should be possible to use ' and ", but ' has higher priority so " can be
// used inside '.
global string a_string = "Hello"
global string b_string = 'World!'
// This produces: Hello World!
string x_string = a_string + " " + b_string
// This produces: Hello World!
string y_string = a_string + ' ' + b_string
// This produces: Hello " " World!
string z_string = a_string + '" "' + b_string
// This produces an error.
string z_string = a_string + "' '" + b_string
// 64 bit number
number foo = 23
// Private variables can only be used here in this file.
private number bar = 42
for i in range(1, 1000)
print i
print add(i, 1)
for i in range(1, foo)
print "i"
// This must not work since range() is an internal function.
string range = "f987458n73v03258"
if(x != y)
print x
else if(a == b || h != i)
print [a + b + h + i]
else
if(k < 1 && l > 1)
print "Buh!"
fi
fi
// Internal functions.
add(a, b)
return [a + b]
sub(a, b)
return [a - b]
// a can be "df -h", "df -h; df -h" or "cat /etc/resolv.conf | grep nameserver".
system(a)
// Execute a system command here and then return the return code.
return [a]
// Some kind of cast function for converting data types.
cast(a)
// Not implemented.
return CASTED_variable_from_one_to_another_existing_type(a)
// External functions need f as a prefix to define the function.
fun get_string(a_string, b_string)
return a_string + " " + b_string
eof