The Lambda Lab
/
projects
/
scheme.forth.jl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
eatspaces now eats comments
[scheme.forth.jl.git]
/
scheme.4th
diff --git
a/scheme.4th
b/scheme.4th
index
52ce346
..
72897be
100644
(file)
--- a/
scheme.4th
+++ b/
scheme.4th
@@
-277,41
+277,37
@@
global-env setobj
global-env fetchobj define-var
;
global-env fetchobj define-var
;
-( = Arithmeic = )
+: arg-count-error
+ bold fg red ." Incorrect argument count." reset-term cr
+ abort
+;
-: add-prim ( args -- )
- 2dup nil objeq? if
- 2drop
- 0 fixnum-type
+: ensure-arg-count ( args n -- )
+ dup 0= if
+ drop nil objeq? false = if
+ arg-count-error
+ then
else
else
- 2dup car drop
- -rot cdr recurse drop
- + fixnum-type
+ -rot 2dup nil objeq? if
+ arg-count-error
+ then
+
+ cdr rot 1- recurse
then
;
then
;
-' add-prim make-primitive +
-:noname ( args -- )
- 2dup nil objeq? if
- 2drop
- 0 fixnum-type
- else
- 2dup car drop
- -rot cdr add-prim drop
- - fixnum-type
- then
-; make-primitive -
+: arg-type-error
+ bold fg red ." Incorrect argument type." reset-term cr
+ abort
+;
-:noname ( args -- )
- 2dup nil objeq? if
- 2drop
- 1 fixnum-type
- else
- 2dup car drop
- -rot cdr recurse drop
- * fixnum-type
+: ensure-arg-type ( arg type -- arg )
+ istype? false = if
+ arg-type-error
then
then
-; make-primitive *
+;
+
+include scheme-primitives.4th
\ }}}
\ }}}
@@
-381,12
+377,27
@@
parse-idx-stack parse-idx-sp !
nextchar [char] ) = or
;
nextchar [char] ) = or
;
+: commentstart? ( -- bool )
+ nextchar [char] ; = ;
+
: eatspaces
: eatspaces
+
+ false \ Indicates whether or not we're eating a comment
+
begin
begin
- whitespace?
+ dup whitespace? or commentstart? or
while
while
+ dup nextchar '\n' = and if
+ invert \ Stop eating comment
+ else
+ dup false = commentstart? and if
+ invert \ Begin eating comment
+ then
+ then
+
inc-parse-idx
repeat
inc-parse-idx
repeat
+ drop
;
: digit? ( -- bool )
;
: digit? ( -- bool )
@@
-397,8
+408,11
@@
parse-idx-stack parse-idx-sp !
: minus? ( -- bool )
nextchar [char] - = ;
: minus? ( -- bool )
nextchar [char] - = ;
+: plus? ( -- bool )
+ nextchar [char] + = ;
+
: fixnum? ( -- bool )
: fixnum? ( -- bool )
- minus? if
+ minus?
plus? or
if
inc-parse-idx
delim? if
inc-parse-idx
delim? if
@@
-497,8
+511,11
@@
parse-idx-stack parse-idx-sp !
nextchar [char] " = ;
: readnum ( -- num-atom )
nextchar [char] " = ;
: readnum ( -- num-atom )
- minus? dup if
+ plus? minus? or if
+ minus?
inc-parse-idx
inc-parse-idx
+ else
+ false
then
0
then
0