-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f713d5
commit 8a13beb
Showing
121 changed files
with
7,972 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.