From cfdddbb00236770e7f621deffb2f63ed40573df1 Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Wed, 18 Mar 2026 17:28:58 -0700 Subject: [PATCH] cons/nil for pair/unit in scheme backend --- Makefile | 2 +- prim.ss | 5 ++--- src/Lib/CompileExp.newt | 6 ------ src/Lib/ProcessDecl.newt | 13 ++++++++----- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 458431f..5e75b82 100644 --- a/Makefile +++ b/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 diff --git a/prim.ss b/prim.ss index 7386c4c..e4a780e 100644 --- a/prim.ss +++ b/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) diff --git a/src/Lib/CompileExp.newt b/src/Lib/CompileExp.newt index 979671e..ef22d84 100644 --- a/src/Lib/CompileExp.newt +++ b/src/Lib/CompileExp.newt @@ -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 diff --git a/src/Lib/ProcessDecl.newt b/src/Lib/ProcessDecl.newt index 40fa641..3c98095 100644 --- a/src/Lib/ProcessDecl.newt +++ b/src/Lib/ProcessDecl.newt @@ -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