diff options
| author | Chouser <chouser@n01se.net> | 2015-02-15 16:46:34 -0500 |
|---|---|---|
| committer | Chouser <chouser@n01se.net> | 2015-02-21 13:22:44 -0500 |
| commit | c4403c179e732a50e2b21a01469f0a38ea2d0187 (patch) | |
| tree | 71cb962c6f9dafafae6e31a17072e14b1e52b381 /forth/core.fs | |
| parent | 136ce7c9afb5e103133fe6e423e6dad3d23db38d (diff) | |
| download | mal-c4403c179e732a50e2b21a01469f0a38ea2d0187.tar.gz mal-c4403c179e732a50e2b21a01469f0a38ea2d0187.zip | |
forth: Add support for & var-args
Diffstat (limited to 'forth/core.fs')
| -rw-r--r-- | forth/core.fs | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/forth/core.fs b/forth/core.fs index 16105ad..6dd4ec4 100644 --- a/forth/core.fs +++ b/forth/core.fs @@ -7,30 +7,61 @@ require env.fs argv i cells + @ as-native loop ; -: defcore ( xt ) - parse-allot-name MalSymbol. ( xt sym ) - swap MalNativeFn. core env/set ; - -:noname args-as-native + MalInt. ; defcore + -:noname args-as-native - MalInt. ; defcore - -:noname args-as-native * MalInt. ; defcore * -:noname args-as-native / MalInt. ; defcore / -:noname args-as-native < mal-bool ; defcore < -:noname args-as-native > mal-bool ; defcore > -:noname args-as-native <= mal-bool ; defcore <= -:noname args-as-native >= mal-bool ; defcore >= - -:noname { argv argc } +: defcore* ( sym xt ) + MalNativeFn. core env/set ; + +: defcore + parse-allot-name MalSymbol. ( xt ) + ['] defcore* :noname ; + +defcore + args-as-native + MalInt. ;; +defcore - args-as-native - MalInt. ;; +defcore * args-as-native * MalInt. ;; +defcore / args-as-native / MalInt. ;; +defcore < args-as-native < mal-bool ;; +defcore > args-as-native > mal-bool ;; +defcore <= args-as-native <= mal-bool ;; +defcore >= args-as-native >= mal-bool ;; + +defcore list { argv argc } MalList new { list } argc cells allocate throw { start } argv start argc cells cmove argc list MalList/count ! start list MalList/start ! - list -; defcore list + list ;; + +defcore list? drop @ mal-type @ MalList = mal-bool ;; +defcore empty? drop @ empty? ;; +defcore count drop @ mal-count ;; + +defcore = drop dup @ swap cell+ @ swap m= mal-bool ;; +defcore not + drop @ + dup mal-nil = if + drop mal-true + else + mal-false = if + mal-true + else + mal-false + endif + endif ;; + +: pr-str-multi ( argv argc ) + ?dup 0= if drop s" " + else + { argv argc } + new-str + argv @ pr-buf + argc 1 ?do + a-space + argv i cells + @ pr-buf + loop + endif ; -:noname drop @ mal-type @ MalList = mal-bool ; defcore list? -:noname drop @ empty? ; defcore empty? -:noname drop @ mal-count ; defcore count +defcore prn pr-str-multi type cr mal-nil ;; +defcore pr-str pr-str-multi MalString. ;; -:noname drop dup @ swap cell+ @ swap m= mal-bool ; defcore = +defcore str drop @ pr-str MalString. ;; +defcore println pr-str-multi 10 str-append-char MalString. ;; |
