Skip to content

Commit

Permalink
merge of grin compiler into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
atzedijkstra committed Mar 14, 2006
1 parent 7f713d5 commit 8a13beb
Show file tree
Hide file tree
Showing 121 changed files with 7,972 additions and 61 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/make -f
TOP_PREFIX :=

default: explanation
Expand Down Expand Up @@ -27,6 +28,7 @@ include ehc/variant.mk
include uhc/files.mk
include ehc/files.mk
include grini/files.mk
include grinc/files.mk
include agprimer/files.mk
-include infer2pass/files.mk
-include figs/files.mk
Expand Down Expand Up @@ -54,13 +56,15 @@ WWW_DOC_PDF := www/current-ehc-doc.pdf
explanation:
@echo "make bin/<n>/ehc : make compiler version <n> (where <n> in {$(EHC_PUB_VARIANTS)})" ; \
echo "make bin/<n>/grini : make grin interpreter version <n> (where <n> in {$(GRIN_PUB_VARIANTS)})" ; \
echo "make bin/<n>/grinc : make grin compiler version <n> (where <n> in {$(GRIN_PUB_VARIANTS)})" ; \
echo "make $(RULER2) : make ruler tool" ; \
echo "make $(SHUFFLE) : make shuffle tool" ; \
echo "make doc/<d>.pdf : make (public) documentation <d> (where <d> in {$(TEXT_PUB_VARIANTS)})," ; \
echo " or (non-public): <d> in {$(TEXT_PRIV_VARIANTS)}" ; \
echo " only if text src available, otherwise already generated" ; \
echo "make ehcs : make all compiler ($(EHC_EXEC_NAME)) versions" ; \
echo "make grinis : make all grin interpreter ($(GRINI_EXEC_NAME)) versions" ; \
echo "make grincs : make all grin compiler ($(GRINC_EXEC_NAME)) versions" ; \
echo "make test-regress : run regression test," ; \
echo " restrict to versions <v> by specifying 'VERSIONS=<v>'," ; \
echo " requires corresponding $(EHC_EXEC_NAME)/$(GRINI_EXEC_NAME) already built" ; \
Expand Down Expand Up @@ -112,6 +116,8 @@ ehcs: $(EHC_ALL_PUB_EXECS)

grinis: $(GRINI_ALL_PUB_EXECS)

grincs: $(GRINC_ALL_PUB_EXECS)

docs: $(TEXT_DIST_DOC_FILES)

edit-s:
Expand Down
15 changes: 15 additions & 0 deletions cmm/compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# compile via grin.lua script
# grin.lua expect to compile grin files via ../8/grc

#qc--.opt or just qc--
cmmc=qc--.opt
which "${cmmc}" >& /dev/null || cmmc=qc--

in="../${1}"
out="../${1%.*}"
shift

cd cmm
${cmmc} eh.lua grin.lua peephole.lua -globals startup.cmm "${in}" -o "${out}" -lgc "$@"
24 changes: 24 additions & 0 deletions cmm/eh.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Frontends.EH = Frontends.EH or { } -- initialize table
Frontends.EH.dir = "../bin/8/"

function Frontends.EH.file(name)
return Frontends.EH.dir .. '/' .. name -- does not port to windows!
end

-- Make the linker pass EH runtime and standard libraries
-- Ld.libs = Ld.libs .. " " .. Frontends.EH.file("stdlib.eh")

-- Tell the driver how to convert a .eh fle into a .grin file
function CMD.compilertab[".eh"](file)
local out = CMD.outfilename(file, ".grin") -- compiler generate output to this path
local ehc = Frontends.GRIN.file("ehc")
local options = "-v1 -cgrin"
CMD.outfilename(file, ".core") -- ehc also generates a .core file
--if Frontends.GRINC.aOption then options = "..." end -- allow options
CMD.exec(ehc .. " " .. options .. " \"" .. file .. "\"")
return out
end

-- Allow Interpretting and pretty printing the generated C-- code from a .eh file
CMD.interptab[".eh"] = CMD.compilertab[".eh"]
CMD.prettytab[".eh"] = CMD.compilertab[".eh"]
24 changes: 24 additions & 0 deletions cmm/grin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Frontends.GRIN = Frontends.GRIN or { } -- initialize table
Frontends.GRIN.dir = "../bin/10/"

function Frontends.GRIN.file(name)
return Frontends.GRIN.dir .. '/' .. name -- does not port to windows!
end

-- Make the linker pass GRIN runtime and standard libraries
-- Ld.libs = Ld.libs .. " " .. Frontends.GRIN.file("runtime.o")
-- .. " " .. Frontends.GRIN.file("stdlib.a")

-- Tell the driver how to convert a .grin fle into a .cmm file
function CMD.compilertab[".grin"](file)
local out = CMD.outfilename(file, ".cmm") -- compiler generate output to this path
local grinc = Frontends.GRIN.file("grinc")
local options = "-v0"
--if Frontends.GRINC.aOption then options = "..." end -- allow options
CMD.exec(grinc .. " " .. options .. " \"" .. file .. "\"")
return out
end

-- Allow Interpret and pretty printing the generated C-- code from a .grin file
CMD.interptab[".grin"] = CMD.compilertab[".grin"]
CMD.prettytab[".grin"] = CMD.compilertab[".grin"]
124 changes: 124 additions & 0 deletions cmm/startup.cmm
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
target byteorder little;

import grin_main;
import printf;
import getenv;
import atoi;

//GC
//import malloc;
import GC_init;

export main;
export printInt;

const HEAP_SIZE = 1024;

//bits32 @hp;
bits32 @eh;

section "data" {
heapsize_var : bits8[] "GRIN_HEAPSIZE\0";
heapsize_msg : bits8[] "heapsize %d KB\naddress space ranges from %p upto %p\n\0";
int_msg : bits8[] "int: %d\n\0";
error_msg : bits8[] "error: exception at %p with tag %d\n\0";
}

section "data" {
align 4;
argument_count: bits32;
argument_array: bits32;
}

printInt (bits32 n) {
foreign "C" printf("address" int_msg, n);
return;
}

foreign "C" main(bits32 argc, "address" bits32 argv) {
bits32 result;
bits32 heapsize;
bits32 env_var;

/*
//init heap (load from environment var GRIN_HEAPSIZE)
env_var = foreign "C" getenv("address" heapsize_var);
if (env_var == 0) {
heapsize = HEAP_SIZE;
} else {
heapsize = foreign "C" atoi("address" env_var);
}


//no GC yet - just allocate the memory and hope we will not allocate to much
//@hp = foreign "C" malloc(heapsize * 1024);
foreign "C" printf("address" heapsize_msg, heapsize, @hp, @hp + (heapsize * 1024));
//@hp = foreign "C" gc_init(heapsize * 1024);
*/
foreign "C" GC_init();
//save argument positions
bits32[argument_count] = argc;
bits32[argument_array] = argv;

//install default exception handler
@eh = defaultHandler;

//call main function
result = grin_main() also cuts to defaultHandler;
printInt(result);

foreign "C" return (0);

bits32 e;
continuation defaultHandler("address" e):
foreign "C" printf("address" error_msg, e, bits32[e]);
foreign "C" return (1);
}

//GRIN generic update function which is here as an example, the code generate
//might produce an inlined variant of this function for the unspecialized
//update operation. An optimization is to factor out the bigPartPointer.

import GRIN_TAG_InfoTable;

export update_field as "GRIN_generic_update_field";

update_field (bits32 p, bits32 tag, bits32 fieldNr, bits32 field) {
//nodes are at least a tag and 4 fields in memory. The last known field
//(4th) might be a pointer to the rest of the fields.
const bigPartPointerOffset = 4;

if fieldNr == 0 {
bits32[p] = tag;
return;
}

bits32 arity;
arity = bits32[GRIN_TAG_InfoTable + tag];

if fieldNr <= arity {
switch fieldNr {
case 1 .. (bigPartPointerOffset-1): {
bits32[p+fieldNr] = field;
}
case bigPartPointerOffset: {
if arity == (bigPartPointerOffset+1) {
bits32[p+fieldNr] = field;
} else {
bits32[bits32[p+bigPartPointerOffset]] = field;
}
}
case (bigPartPointerOffset+1) .. 0xffff: {
bits32[bits32[p+bigPartPointerOffset]] = field;
}
}
}
return;
}




/*
vim:ts=4
*/
2 changes: 1 addition & 1 deletion ehc/EHCnstr.chs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id$
% $Id: EHCnstr.chs 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
4 changes: 2 additions & 2 deletions ehc/EHCommon.chs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHCommon.chs 273 2005-08-24 08:58:20Z atze $
% $Id: EHCommon.chs 270 2005-08-14 18:38:07Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down Expand Up @@ -763,7 +763,7 @@ groupSortByOn :: (b -> b -> Ordering) -> (a -> b) -> [a] -> [[a]]
groupSortByOn cmp sel = groupByOn (\e1 e2 -> cmp e1 e2 == EQ) sel . sortByOn cmp sel
%%]

%%[8
%%[8 export(strBlankPad)
strBlankPad :: Int -> String -> String
strBlankPad n s = s ++ replicate (n - length s) ' '
%%]
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHCore.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHCore.cag 260 2005-07-23 12:18:44Z atze $
% $Id: EHCore.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHCoreAbsSyn.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHCoreAbsSyn.cag 260 2005-07-23 12:18:44Z atze $
% $Id: EHCoreAbsSyn.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
11 changes: 6 additions & 5 deletions ehc/EHCoreGrin.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHCoreGrin.cag 262 2005-07-24 11:36:39Z atze $
% $Id: EHCoreGrin.cag 277 2005-09-01 14:00:21Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down Expand Up @@ -218,7 +218,7 @@ SEM CModule
= GrAlt_Alt
(mkGrPatTagNode GrTagFun 0 n argL)
(GrExpr_Seq (GrExpr_Call n (map GrVal_Var argL)) (GrPat_Var n4)
(GrExpr_Seq (GrExpr_Update n1 (GrVal_Var n4)) GrPat_Empty
(GrExpr_Seq (GrExpr_Update n1 (GrVal_Var n4) Nothing) GrPat_Empty
(GrExpr_Unit (GrVal_Var n4))))
where (n4:argL) = take (arity+1) (hsnUniqSupplyL u)
mkPAlt n nL arity
Expand All @@ -231,7 +231,7 @@ SEM CModule
++ (zipWith mkFAlt (mkInfNewLevUIDL @lUniq4) . Map.toList $ Map.insert hsnGrApply 2 @expr.lamNmMp)
++ (zipWith mkFAlt (mkInfNewLevUIDL @lUniq5) . Map.toList $ @expr.cafNmMp)
,\alts -> GrBind_Bind hsnGrEval [n1]
(GrExpr_Seq (GrExpr_Fetch n1 Nothing) (GrPat_Var n2)
(GrExpr_Seq (GrExpr_Fetch n1 Nothing Nothing) (GrPat_Var n2)
(GrExpr_Case (GrVal_Var n2) alts))
)
. evalBind = @mkEvalBind @evalAltL
Expand All @@ -242,6 +242,7 @@ SEM CModule
)
@evalAltL
lhs . grMod = GrModule_Mod (HNm @baseName)
[] -- TODO: this should contain all the caf variables
(@expr.grBindL ++ [@applyBind,@evalBind])
@allCTags @evalTagMp @applyTagMp
%%]
Expand Down Expand Up @@ -347,8 +348,8 @@ SEM CExpr
mkSt nmL e = foldr (\n e -> GrExpr_Seq (GrExpr_Store h) (GrPat_Var n) e) e nmL
mkV b n n' n'' e
= GrExpr_Seq b (GrPat_Var n')
(GrExpr_Seq (GrExpr_Fetch n' Nothing) (GrPat_Var n'')
(GrExpr_Seq (GrExpr_Update n (GrVal_Var n'')) GrPat_Empty e))
(GrExpr_Seq (GrExpr_Fetch n' Nothing Nothing) (GrPat_Var n'')
(GrExpr_Seq (GrExpr_Update n (GrVal_Var n'') Nothing) GrPat_Empty e))
mkVs bs e = foldr (\(GrBind_Bind n _ v) e -> mkV v n (hsnPrefix "_" n) (hsnPrefix "__" n) e) e bs
_ -> foldr (\(GrBind_Bind n _ v) e -> GrExpr_Seq v (GrPat_Var n) e)
@body.grExpr @binds.grBindL
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHCoreJava.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHCoreJava.cag 262 2005-07-24 11:36:39Z atze $
% $Id: EHCoreJava.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHCorePretty.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHCorePretty.cag 260 2005-07-23 12:18:44Z atze $
% $Id: EHCorePretty.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHCoreTrfCommonFv.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHCoreTrfCommonFv.cag 260 2005-07-23 12:18:44Z atze $
% $Id: EHCoreTrfCommonFv.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHCoreTrfLamLift.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHCoreTrfLamLift.cag 260 2005-07-23 12:18:44Z atze $
% $Id: EHCoreTrfLamLift.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHCoreUtils.chs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHCoreUtils.chs 264 2005-07-28 12:57:52Z atze $
% $Id: EHCoreUtils.chs 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHGam.chs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHGam.chs 267 2005-08-07 20:16:41Z atze $
% $Id: EHGam.chs 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHGamUtils.chs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id$
% $Id: EHGamUtils.chs 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHGatherError.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHGatherError.cag 273 2005-08-24 08:58:20Z atze $
% $Id: EHGatherError.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHGenCore.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHGenCore.cag 273 2005-08-24 08:58:20Z atze $
% $Id: EHGenCore.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHInfer.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHInfer.cag 276 2005-08-31 11:54:35Z atze $
% $Id: EHInfer.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHInferCaseExpr.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id$
% $Id: EHInferCaseExpr.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHInferData.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHInferData.cag 266 2005-08-02 20:47:40Z atze $
% $Id: EHInferData.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHInferExpr.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id: EHInferExpr.cag 275 2005-08-28 13:39:57Z atze $
% $Id: EHInferExpr.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHInferPatExpr.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id$
% $Id: EHInferPatExpr.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
2 changes: 1 addition & 1 deletion ehc/EHInferTyExpr.cag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% $Id$
% $Id: EHInferTyExpr.cag 269 2005-08-14 12:49:00Z cddouma $

%%[0
%include lhs2TeX.fmt
Expand Down
Loading

0 comments on commit 8a13beb

Please sign in to comment.