forked from idris-lang/Idris-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Edwin Brady
committed
Aug 31, 2012
1 parent
b70780f
commit 79e6bf7
Showing
4 changed files
with
52 additions
and
3 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,5 @@ | ||
int main(int argc, char* argv[]) { | ||
VM* vm = init_vm(1024000, 1024000); | ||
|
||
_idris_main(vm, NULL); | ||
} |
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,34 @@ | ||
module IRTS.CodegenC where | ||
|
||
import IRTS.Bytecode | ||
import IRTS.Lang | ||
import Core.TT | ||
import Paths_idris | ||
|
||
import Data.Char | ||
|
||
cname :: Name -> String | ||
cname n = "_idris_" ++ concatMap cchar (show n) | ||
where cchar x | isAlpha x || isDigit x = [x] | ||
| otherwise = "_" ++ show (fromEnum x) ++ "_" | ||
|
||
indent i = take (i * 4) (repeat ' ') | ||
|
||
creg RVal = "RVAL" | ||
creg (L i) = "LOC(" ++ show i ++ ")" | ||
creg (T i) = "TOP(" ++ show i ++ ")" | ||
|
||
toDecl :: Name -> String | ||
toDecl f = "void " ++ cname f ++ "(VM*, VAL*);\n" | ||
|
||
toC :: Name -> [BC] -> String | ||
toC f code | ||
= -- "/* " ++ show code ++ "*/\n\n" ++ | ||
"void " ++ cname f ++ "(VM* vm, VAL* oldbase) {" ++ | ||
concatMap (bcc 1) code ++ "}\n\n" | ||
|
||
bcc :: Int -> BC -> String | ||
bcc i (ASSIGN l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n" | ||
|
||
bcc i _ = indent i ++ "// not done yet\n" | ||
|
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