User loginNavigation |
cicada-nymph -- a forth-like language for to teachthe little nymph is for teaching purpose only. it reuses the code and idea to teach my friends I will use assembly language (FASM for x86-64) the programming language to be implemented the following shows how to define "if" & "else" & "then" by "define-macro"
: if
<< string[address, length] --
address, string[address, length] >>
*false?branch* save-into,jo-heap
*current-free-address,jo-heap* xx|swap|x
0 save-into,jo-heap
end
; define-macro
: else
<< address, string[address, length] --
address, string[address, length] >>
*branch* save-into,jo-heap
x|swap|xx
*current-free-address,jo-heap* xxx|swap|x
0 save-into,jo-heap
<< address, string[address, length], address >>
*current-free-address,jo-heap*
over sub *jo-size* div
swap save
end
; define-macro
: then
<< address, string[address, length] --
string[address, length] >>
x|swap|xx
*current-free-address,jo-heap*
over sub *jo-size* div
swap save
end
; define-macro
the following shows how to define factorial
: factorial
<< number -- number >>
dup one? if
end
then
dup sub1 factorial
mul
end
; define-function
for the code and more info :: code on github the cicada nymph is for teaching purpose at first and By xieyuheng at 2015-03-12 18:56 | LtU Forum | previous forum topic | next forum topic | other blogs | 5205 reads
|
Browse archives
Active forum topics |
Recent comments
1 day 5 hours ago
2 days 1 hour ago
3 days 6 hours ago
3 days 6 hours ago
1 week 1 day ago
1 week 1 day ago
1 week 1 day ago
4 weeks 2 days ago
5 weeks 8 hours ago
5 weeks 14 hours ago