cons/nil for pair/unit in scheme backend
This commit is contained in:
2
Makefile
2
Makefile
@@ -25,7 +25,7 @@ newt3.js: newt2.js
|
||||
newt.ss: newt.js
|
||||
$(RUNJS) newt.js src/Main.newt -o newt.ss
|
||||
|
||||
newt.so: newt.ss
|
||||
newt.so: newt.ss prim.ss
|
||||
chez --script scripts/compile-chez.ss
|
||||
|
||||
test: newt.js
|
||||
|
||||
5
prim.ss
5
prim.ss
@@ -1,9 +1,8 @@
|
||||
;; REVIEW all of this - some of it is IO and needs the IO dance
|
||||
;; maybe we make a helper? A macro?
|
||||
|
||||
(define $Nil (lambda (nm-0) (vector 0 nm-0)))
|
||||
(define $Cons (lambda (nm-0 nm-1 nm-2) (vector 1 nm-0 nm-1 nm-2)))
|
||||
(define $IORes (lambda (nm-1 nm-2) (vector 0 #f nm-1 nm-2)))
|
||||
; (define $IORes (lambda (nm-1 nm-2) (vector 0 #f nm-1 nm-2)))
|
||||
(define $IORes (lambda (nm-1 nm-2) (cons nm-1 nm-2)))
|
||||
(define ($Left x) (vector 0 #f #f x))
|
||||
(define ($Right x) (vector 1 #f #f x))
|
||||
(define $LT 0)
|
||||
|
||||
@@ -146,12 +146,6 @@ compileTerm tm@(App _ _ _) = case funArgs tm of
|
||||
if length' qs == length' args
|
||||
then pure $ CConstr tag nm.baseName args' qs NilCon
|
||||
else apply nm args' arity
|
||||
-- REVIEW Slower for JS, faster for scheme. (2.88 vs 3.01)
|
||||
-- but all of the "JS" diff is code gen?
|
||||
-- Just (DCon tag info qs _) =>
|
||||
-- if length' qs == length' args
|
||||
-- then pure $ CConstr tag nm.baseName args' qs info
|
||||
-- else apply nm args' arity
|
||||
_ => apply nm args' arity
|
||||
-- REVIEW maybe we want a different constructor for non-Ref applications?
|
||||
(t, args) => do
|
||||
|
||||
@@ -415,11 +415,14 @@ populateConInfo entries =
|
||||
-- Boolean
|
||||
| Just (a :: b :: Nil) => (setInfo a FalseCon :: setInfo b TrueCon :: Nil)
|
||||
| Just entries => entries in
|
||||
let (a :: b :: Nil) = entries | _ => entries in
|
||||
fromMaybe entries $ checkNat entries <|> checkCons entries
|
||||
-- let (Nothing) = checkNat entries | Just entries => entries in
|
||||
-- let (Nothing) = checkNat entries | Just entries => entries in
|
||||
-- entries
|
||||
case entries of
|
||||
a :: Nil => case countFields a of
|
||||
0 => setInfo a NilCon :: Nil
|
||||
2 => setInfo a ConsCon :: Nil
|
||||
_ => entries
|
||||
a :: b :: Nil =>
|
||||
fromMaybe entries $ checkNat entries <|> checkCons entries
|
||||
_ => entries
|
||||
where
|
||||
countFields : TopEntry → Int
|
||||
countFields (MkEntry fc name type def eflags) = go type
|
||||
|
||||
Reference in New Issue
Block a user