Skip to content

Commit

Permalink
Multiple fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor committed Jul 31, 2024
1 parent 8bf3447 commit d21a33e
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 239 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC=rustc
CCARGS=-Ctarget-feature=+crt-static -Copt-level=3 -Cstrip=symbols -v
CCARGS=-Copt-level=3 -Cstrip=symbols -v
SRC=src/maeel.rs
TESTS=tests.maeel
EXE=maeel
Expand All @@ -10,6 +10,9 @@ all: build
fmt:
rustfmt $(SRC)

fast:
$(CC) $(SRC) -o $(EXE)

build:
$(CC) $(CCARGS) $(SRC) -o $(EXE)

Expand Down
19 changes: 4 additions & 15 deletions examples.maeel
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
include "maeel"

fun inline fact (
dup 1=
(drop 1)
(dup 1- fact *)
ifelse
dup 1 = (drop 1) (dup 1- fact*) ifelse
)

fun map xs fn (
List
xs (fn!) for
end
fun inline fib (
dup 1 < (drop 1) (dup 1- fib swap 2- fib+) ifelse
)

fun range a b (
List
a (dup 1+) (dup b<) while
end
)


1 10 range (fib) map putsln
1 10 range (fact) map putsln
4 changes: 2 additions & 2 deletions examples/01_variables.maeel
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include "maeel"

"Hello, world" ~ hello_variable
"Hello, world" : hello_variable

"number 1" "number 2" ~ n2 ~ n1 # chained assignment
"number 1" "number 2" : n2 : n1 # chained assignment

hello_variable putsln
n1 putsln
Expand Down
5 changes: 1 addition & 4 deletions examples/04_functions.maeel
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ fun inline calling_itself (calling_itself)



("hello from code block" putsln) ~ hello_fun
("hello from code block" putsln) : hello_fun

hello_fun # will push a code block
drop () # ignore me
! # use "!" to execute the code block

hello_fun! # will print "hello from codeblock"

&proc # will push the code block assiociated with the "hello" function (l3)
! # will print "hello from function"
9 changes: 1 addition & 8 deletions examples/05_conds.maeel
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
include "maeel"

1 1+ 2= ? ("Yep!" putsln)

2 20 pow 3 15 pow <
("2^20 is lower than 3^15" putsln)
("2^20 is greater than 3^15" putsln)
ifelse
# TODO
2 changes: 1 addition & 1 deletion examples/06_loops.maeel
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ List 1 2 3 4 end (putsln) for
(
n putsln
n 2 *~ n
) (n 65536 <) while
) (n 65536 <) while
19 changes: 1 addition & 18 deletions examples/07_arrays.maeel
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
include "maeel"

List 1 2 3 4 5 end ~ this_is_a_list

this_is_a_list (1+) map ~ added_one
added_one (2*) map ~ mul_by_two
mul_by_two (+) 0 reduce ~ this_is_the_sum

1 20 range ~ from_1_to_19
from_1_to_19 (2%0=) filter ~ only_evens


"This is a list: " puts this_is_a_list putsln
"Added one two every element: " puts added_one putsln
"Multiplied every element by two: " puts mul_by_two putsln
"This is the sum of the new list: " puts this_is_the_sum putsln
"Here are the numbers from 1 to 19: " puts from_1_to_19 putsln
"Here are the even numbers only: " puts only_evens putsln
# TODO
30 changes: 30 additions & 0 deletions src/maeel.maeel
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ fun inline bool_to_string (("true") ("false") ifelse)

fun inline bool_to_int ((1) (0) ifelse)

fun inline neg (0 swap -)

fun inline not ((false) (true) ifelse)

fun mod a b (
a 0 < ((a b +: a) (a 0 <) while) then
(a b -: a) (a b > a b = or) while
a
)

fun and p q (
1 0 p! 1=
(1 0 q! 1= (true) (false) ifelse)
Expand Down Expand Up @@ -64,3 +72,25 @@ fun inline reverse (List swap () for end2)

fun inline end (list (+) (over List= not) while swap drop reverse)

fun map xs fn (
List
xs (fn!) for
end
)

fun range a b (
List
a (dup 1+) (dup b<) while
end
)

fun inline unpack (
fun inline unpack_aux (
dup 0= (get) (
over over get rot 1- unpack_aux
) ifelse
)

dup len 1- unpack_aux
)

Loading

0 comments on commit d21a33e

Please sign in to comment.