fa/examples/all_features.fa
Ari Archer 4ba152cedc
Start work on type checking, add generic type and add more tests for to
Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
2022-07-28 13:08:36 +03:00

204 lines
3.1 KiB
Text

-- Include
include 'std/std.fa'
include 'std/mem/gmem.fa'
-- Macro and end
macro hi 0 end
fun some_function_hello [ int ] eo
-- Nested Functions
fun ex [ int ] eo %exit end
#ex
end
-- Ret
fun i_will_return eo ret end
macro main
-- Strings
"String\n" %STDERR %fputs
-- Sys, numbers and drop
"Sys, numbers and drop\n" %STDOUT %SYS_write sys 4 1 drop
-- Swap
"\n" swap drop
-- Expand macro
%hi pop
-- This assumes that 2 is stderr --
-- Add
"1 + 1 = 2\n" 1 1 add %fputs
-- Sub
"3 - 1 = 2\n" 1 3 sub %fputs
-- Mul
"1 * 2 = 2\n" 2 1 mul %fputs
-- Bor
"2 | 2 = 2\n" 2 2 bor %fputs
-- Ban
"2 & 2 = 2\n" 2 2 ban %fputs
-- Xor
"0 ^ 2 = 2\n" 2 0 xor %fputs
-- Shr
"10 >> 2 = 2" 2 10 shr %fputs
"\{10}" %STDERR %fputs
-- Shl
"1 << 1 = 2" 1 1 shl %fputs
"\n" %STDERR %fputs
-- Grt
"77 > 0 = true" 0 77 grt 1 add %fputs
"\n" %STDERR %fputs
-- Lst
"0 < 6 = true" 6 0 lst 1 add %fputs
"\n" %STDERR %fputs
-- Bot
"4 + ~1 = 2" 1 bot 4 add %fputs
"\n" %STDERR %fputs
-- Eql
"0 == 0 = true" 0 0 eql 1 add %fputs
"\n" %STDERR %fputs
-- Dvm
"2 /% 10 = (5, 0); 5 + 0 = 5; 5 - 3 = 2"
3 2 10 dvm add sub %fputs
"\n" %STDERR %fputs
-- Lse
"0 <= 0 = true" 0 0 lse 1 add %fputs
"\n" %STDERR %fputs
-- Gre
"0 >= 0 = true" 0 0 gre 1 add %fputs
"\n" %STDERR %fputs
------------------------------------
-- Copy
1 copy drop
-- Undefine
undefine hi
-- Nop
nop
--< Block comments >--
-- Line comments
-- Nested macros
macro a 0 end
macro b %a end
macro c %b end
macro d
macro f
macro e %c end
%e
end
%f
end
-- Names
10 as hello
-- Dereferencing
@hello deref as bye
-- Point
@bye 1 point
-- Unname
unname hello
-- Some math and variables
1 %d sub @bye deref add --< Macro expansion with math >-- 1 add copy drop
-- If
1 if
"One is true" %puts
%EXIT_SUCCESS
else
"One is not false!\n" %STDERR %fputs
%EXIT_FAILURE
end
-- Set
8 #malloc as somemem
@somemem deref 0 set
8 @somemem deref #mfree pop
-- Ret
#i_will_return
-- Elipsis
...
-- Booleans
true false 2 drop
-- Null
null pop
-- Argc
argc pop
-- Argv
argv pop
-- Negative numbers
-1 1 add
-- Turn
1 1 turn turn turn
2 drop
-- Hop
1 swap hop 2 drop
-- Char
'\0'
-- To
to int
add
-- Unsized string
4 u"Ustr" %puts
4 u"Ustr" %puts
-- Pop
69 pop
-- While loop
0 while copy 10 grt do
"I am looping" %puts
1 add
end 2 drop
-- To
1 to int copy drop
-- Functions
#some_function_hello
end
%main --<
XXX: Macro main is an old convension,
it's only shown as an exampkle here
>--