summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/overview
blob: 5f7904edfd43785f2f089bad3488e829d303f274 (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
CS course work project

zippy - a high level functional programing language

zippy will be an interpreted language designed to replace C in higher level use
C is used largely to write most of the unix desktop, however c can be difficult
when writing larger programs, and is missing moddern features like oop or
functional patterns (higher order functions)

requirents:
	- must be human readable, even a non programmer should be able to figure
	out what a program is doing
	- faster than competion, other languages that have tried to slot into
	this position like python are far to slow, and thus it must be faster
	- low runtime overhead, the interpreter should be small, it shouldn't 
	force the developer to think about how the interpreter works to use it
	efficently
	- have moddern tools, a pkg manager and enviroment manager, making it
	easy to develop for
	- needs to support c libarys

language info

zippy will use function programming as a primary solution, however also support
simple oop, with classes (no inheritence)
its syntax will be comparable to lisp, with prolific use of "()"
it will need a stdlib, which can be taken from C's stdlib

types:

	char - just like a c char
	i32 - 32 bit signed int
	f32 - 32 bit signed float
	u32 - unsigned 32 bit int
	i16- 16 bit signed int
	u16 - 16 bit unsigned int
	bool - TRUE/FALSE


	arrays:
	
		arrays can be created like so
		(let arr[]:char "hello there")
		(let arr[]:i32 1 2 3)

		all arrays are linked lists of there data type
		their size is not fixed

		you can get, or set the value of an array at a specific index using
		arr[index]

	strings:
	
		strings are arrays of chars
		a string can be defined by a litteral like so
		"hello world" - this is the same as 'h' 'e' 'l'....
		because this is represented as a linked list there is no need to have a
		NULL terminator like in c, the end of the string is jus the point where the 
		linked list has no more nodes

comments:

	comments can be writen like so
	! this is a comment

indentation and spacing:
	
	indentation and new lines arent at all necesary
	any new lines will be converted to spaces, and tabs will be removed
	the only place that needs spaces is when calling a function and giving its args

scopes:

	() can be placed anywhere, and anything that is in them is in there own scope
	as soon as the bracket is closed, any variables defined in the scope
	will be deleted 
	any scope inherets all variables and functions from the scope that contains it
	code writen in the main body of the file can be imagined like so
	(
		...
		...
		...
		your code
		...
		...
		...
	)
	however that level of indentation is not needed
	
	this can be helpful if you want to have two scopes with different imports
	(
		(import z)
		(
			(import x) 
			! anything writen here has access to libary x and z
		)
		(
			(import y)
			! anything writen here has access to libary y and z
		)
		! anything writen here has access to libary z	
	)
	
libarys:

	libarys are similar to header files in c
	when imported the user can use any function contained within the file
	
	it would be good practice to put your libary in a struct to avoid functions with the
	same names coming from 2 libarys, however its not needed

errors:

	errors would be 

keywords:

	(defun arg1:type arg2:type returnType
		...
		...
		...
	)
	defines a function, can be done anywhere in the program, all functions 
	must return a value, return type and arguments must be known at runtime

	returns the function that can be asigned with let
	
	(return VALUE)
	returns VALUE from a function, VALUE must be of the same tupe as returnType
	in defun

	(for x a b function)

	runs the function inside the loop, x will be increment by 1 each iteration and
	it will have a starting value of a running until it reaches b (inclusive)
	x cant be changed in any way other than the for loop
	x, a, b are all of type i32

	(while condtion function)

	runs all code inside the loop until the condion is not TRUE
	condition must be a bool (TRUE/FALSE)
	
	(let name:type value)

	assign value to variable name, this will create the variable if it doesn't already
	exist, and overwrite it if it does
	names type must be defined by type

	(const name:type value)

	same as let but creates an imutable variable

	(import libary)

	searches the libary dir and imports the libary to the current project
	libary can also be a specific path if it starts with / or ./ or ../

	(struct name
		...
		...
		...
		(defun init arg1:type type
			...
			...
			...
		)
		(defun deinit arg1:type type
			...
			...
			...
		)
	)

	structs can be used as a custom data type
	creates a struct/class called name, functions called init will be ran when an
	object is created
	when deinit is called the code init will be ran, then the object will be deleted
	if deinit is not defined it can still be called to delete the instace of the class

	you can create a struct like so:
		(let mystruct:name (name.init arg1 arg2))

	you can call a method attached to an instace of a struct like this:
		(mystruct.method arg1 arg2)

	and to destroy it you can just use this:
		(mystruct.deinit arg1 arg2)
	
	structs can be recursive
	eg:
		(struct node
			(defun init next:node
				(let next:node next)
			)
		)

	a struct can have default values
	eg:
		(struct person
			(let age:i32 50)
			(let name[]:char "john doe")
			...
			...
			...
		)

	this will make the struct have default values

	overall in simple terms structs are just like c structs but they can contain
	functions

	(symbol arg1:type arg2:type returntype location)

	returns a function that can be called. the function is retrieved from a .o file
	which can be writen in C, the args, should be the args that the function takes in
	and there types
	the interpreter will try to convert data to the equal type in C, however this may need
	to be done manually
	the location should be a string which is is the file path to the .o file

	(if condition
		...
		...
		...
	)(elif condition
		...
		...
		...
	)(else
		...
		...
		...
	)
		
	simple if statment, if condition is TRUE run the code inside, elif runs if the condition in it
	is TRUE and if the previous has not been TRUE
	else will run if nothing else is TRUE

	(cast TYPE variable)

	returns a variable casted to type TYPE, if type is function, will return a function with no args
	that returns the variable value in its starting type

	conditions:
		(= a b) returns TRUE if a is equal to be (works with arrays)
		(!= a b) returns TRUE if a is not equal to be (works with arrays)
		(> a b) returns TRUE if a > b (does not work with arrays)
		(< a b) returns TRUE if a < b (does not work with arrays)
		(>= a b) returns TRUE if a >= b (does not work with arrays)
		(<= a b) returns TRUE if a <= b (does not work with arrays)
		(! a) returns TRUE if a is FALSE (only works on bools)
		(| a b) returns TRUE if a or b are TRUE (only works on bools)
		(& a b) returns TRUE if a and b are TRUE (only works on bools)
		(^ a b) returns TRUE if a xor b is true (only works on bools)

		all these are just functions that can be used to assign values
		eg:
			(let mybool:bool (= a b))
			! mybool will be TRUE if a = b
	
	mathmatical operations:
		zippy uses reverse polish notation
		(+ a b) returns a + b
		(- a b)	returns a - b
		(* a b) returns a * b
		(/ a b) returns a / b, whole number eg: (/ 7 3) = 2
		(/. a b) returns a / b, floating point number eg: (/. 7 3) = 2.5
		(% a b) returns the remander of (/ a b)
		(** a b) returns a ^ b


sample code
	(let fib:function (defun num:i32 i32
			(if (< num 2)
				(return num)
			)
			(else
				(return (+ (fib (- num 1)) (fib (- num 2)) ))
			)
		)
	)
	(let a:i32 (fib 5))
	! returns the 5th fib number

stdlib:
	(import io)
	io contains a few types
	they are:
		(io.file)
	io contains many io related functions
	they are:

	(io.write "hello %s\n" name) ! this is very similar to printf in C
	(let input:char[] (io.read))
	
	(let file:io.file (io.open path[]:char "method"))
	
	(io.fwrite file:io.file "hello %s" name)
	(let file[]:char (io.fread file:io.file))
	(let line[]:char (io.freadline file:io.file lineno:i32))