-
Notifications
You must be signed in to change notification settings - Fork 0
rpopic2/allang
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
# allang: alvin's assembly like language
by rpopic2
why allang?
- if you know how modern computer works, then you know how to code in allang. stop learning languages.
- compiles fast, runs fast. write optimized code without optimizers.
- explicit but not verbose.
other features:
- compatibility with c
- safety features are opt-out, footguns are opt-in
- metaprogramming in the same syntax
hello.al
```
std:print "Hello World!"\n =>
```
ex) dead simple todo list interoperrating with c standard library
```
#import stdio.h
#import stdlib.h
#import string.h
main: (i32 Argc, addr addr c8 Argv =>Error?)
@inline NO_ARGS = Argc is 1
NO_ARGS ->
File :: 'filemode' "r" @flie.open
~ fclose=>
File Length :: *File @file.len
Buffer :: File Length @buffer.new
~ free=>
*Buffer, #sizeof c8, File Length, *File
fread=>
:: print_file
Buffer =[#va_arg]
"todo: \n%s" printf=>
Ok ret
Argc isnt 3 ->
usage=> Error ret
Command ::
Arg_1 :: [Argv, 1 addr c8]
Arg_1 strlen=> isnt 2 -> usage=> Error ret
[Arg_1, 1 c8]
Command is
'c' create->
'd' delete->
create:
File :: 'filemode' "a" @file.open
~ fclose=>
File, [Argv, 2 addr c8], fwrite=>
#allow_loop
@inline read_until_newline: (code, iter c8 *Iter =>code)
@loop
[*Iter++, 0 c8] isnt '\n' continue->
delete:
Buffer ::
File :: 'filemode' "r" @flie.open
~ fclose=>
File Length :: *File @file.len
File Length @buffer.new
Self, #sizeof c8, File Length *File
fread=>
~ free=>
Index To Delete :: [Argv, 2 addr] atoi=>
File :: 'filemode' "w" @file.open
~ fclose=>
Iter :: Buffer as iter c8
Line Index :: i32 0
@loop
Line Index is Index To Delete break->
@read_until_newline
Line Index++
Iter++
Buffer, #sizeof c8, Iter - Buffer, *File
fwrite=>
*Iter @read_untile_newline
*Iter++
Write_Length ::
Iter - Buffer =$
File_Length - $
Iter, 1, Write_Length, *File
fwrite=>
usage: (=>)
"" EOF
usage:
create entry test: -c test
delete entry at 0: -d 0
EOF
printf=>
file:
@inline open: (cstr 'filemode' Mode =>File~)
"todo.txt", Mode fopen=> =Self
Self isnt pointing -> "File does not exist", Error panic
Self
@inline len: (addr FILE *File =>i32)
*File 1 fseek=>
File ftell=> =Self
*File 0 fseek=>
Self
buffer:
@inline new: (usize Size)
Size malloc=> =Self
Self isnt pointing -> "malloc failed", Error panic
```
About
alvin's programming language
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published