-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1295 from andrew-johnson-4/ansi-c-frontend-rqre
Ansi c frontend rqre
- Loading branch information
Showing
11 changed files
with
26,013 additions
and
25,142 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
let std-c-chain(f1: Fragment, f2: Fragment): Fragment = ( | ||
f2 = f2.set( c"expression", f1.get(c"expression") + f2.get(c"expression") ); | ||
f2 | ||
); |
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,86 @@ | ||
|
||
|
||
let std-c-compile-args(callee-ctx: FContext, caller-ctx: FContext, lhs: AST, rhs: AST): Tuple<FContext,FContext> = ( | ||
match lhs { | ||
App{lhs-rst=left, right:App{ left:Lit{key:c":"}, right:App{left:Var{k=key}, right:AType{kt=tt}} }} => ( | ||
if typeof(rhs).is-t(c"Cons") { | ||
match rhs { | ||
App{le=left, re=right} => ( | ||
if kt.is-t(c"...") { | ||
kt = kt.slot(c"...").r1; | ||
if can-unify(kt, typeof(re)) { | ||
if kt.is-open { callee-ctx = union(callee-ctx, unify(kt, typeof(re))); }; | ||
let c1 = std-c-compile-expr(caller-ctx, re); | ||
caller-ctx = open(c1.context); | ||
callee-ctx = bind-vararg(callee-ctx, k, kt, c1); | ||
(callee-ctx, caller-ctx) = std-c-compile-args(callee-ctx, caller-ctx, lhs, le); | ||
} else { | ||
(callee-ctx, caller-ctx) = std-c-compile-args(callee-ctx, caller-ctx, lhs-rst, rhs); | ||
} | ||
} else { | ||
if kt.is-open { callee-ctx = union(callee-ctx, unify(kt, typeof(re))); }; | ||
let c1 = std-c-compile-expr(caller-ctx, re); | ||
caller-ctx = open(c1.context); | ||
callee-ctx = callee-ctx.bind(k, kt, c1); | ||
(callee-ctx, caller-ctx) = std-c-compile-args(callee-ctx, caller-ctx, lhs-rst, le); | ||
} | ||
); | ||
} | ||
} else { | ||
if kt.is-t(c"...") { | ||
kt = kt.slot(c"...").r1; | ||
if can-unify(kt, typeof(rhs)) { | ||
if kt.is-open { callee-ctx = union(callee-ctx, unify(kt, typeof(rhs))); }; | ||
let c1 = std-c-compile-expr(caller-ctx, rhs); | ||
caller-ctx = open(c1.context); | ||
callee-ctx = bind-vararg(callee-ctx, k, kt, c1); | ||
} else { | ||
(callee-ctx, caller-ctx) = std-c-compile-args(callee-ctx, caller-ctx, lhs-rst, rhs); | ||
} | ||
} else { | ||
if kt.is-open { callee-ctx = union(callee-ctx, unify(kt, typeof(rhs))); }; | ||
let c1 = std-c-compile-expr(caller-ctx, rhs); | ||
caller-ctx = open(c1.context); | ||
callee-ctx = callee-ctx.bind(k, kt, c1); | ||
} | ||
}; | ||
(callee-ctx, caller-ctx) | ||
); | ||
App{ left:Lit{key:c":"}, right:App{left:Var{k=key}, right:AType{kt=tt}} } => ( | ||
if typeof(rhs).is-t(c"Cons") { | ||
match rhs { | ||
App{le=left, re=right} => ( | ||
if kt.is-t(c"...") { | ||
kt = kt.slot(c"...").r1; | ||
if kt.is-open { callee-ctx = union(callee-ctx, unify(kt, typeof(re))); }; | ||
let c1 = std-c-compile-expr(caller-ctx, re); | ||
caller-ctx = open(c1.context); | ||
callee-ctx = bind-vararg(callee-ctx, k, kt, c1); | ||
(callee-ctx, caller-ctx) = std-c-compile-args(callee-ctx, caller-ctx, lhs, le); | ||
} else { | ||
fail("std-c-compile-args unexpected RHS, vararg mismatch"); | ||
} | ||
); | ||
} | ||
} else { | ||
if kt.is-t(c"...") { | ||
kt = kt.slot(c"...").r1; | ||
if can-unify(kt, typeof(rhs)) { | ||
if kt.is-open { callee-ctx = union(callee-ctx, unify(kt, typeof(rhs))); }; | ||
let c1 = std-c-compile-expr(caller-ctx, rhs); | ||
caller-ctx = open(c1.context); | ||
callee-ctx = bind-vararg(callee-ctx, k, kt, c1); | ||
} else { | ||
(callee-ctx, caller-ctx) = std-c-compile-args(callee-ctx, caller-ctx, lhs, rhs); | ||
} | ||
} else { | ||
if kt.is-open { callee-ctx = union(callee-ctx, unify(kt, typeof(rhs))); }; | ||
let c1 = std-c-compile-expr(caller-ctx, rhs); | ||
caller-ctx = open(c1.context); | ||
callee-ctx = callee-ctx.bind(k, kt, c1); | ||
} | ||
}; | ||
(callee-ctx, caller-ctx) | ||
); | ||
} | ||
); |
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,17 @@ | ||
|
||
let std-c-compile-call(ctx: FContext, fname: CString, fterm: AST, args: AST): Fragment = ( | ||
if typeof(fterm).is-t(c"Blob") { | ||
let f = ctx.lookup(fname, typeof(args), args); | ||
let r = mk-fragment(); | ||
match f.term { | ||
Abs{lhs=lhs, rhs=rhs} => ( | ||
(let callee-ctx, let caller-ctx) = std-c-compile-args(global-ctx, ctx, lhs, args); | ||
r = blob-render(callee-ctx, rhs, r, 0); | ||
r.context = close(caller-ctx); | ||
); | ||
}; | ||
r | ||
} else { | ||
fail("TODO std-c-compile-call Function"); mk-fragment(); | ||
} | ||
); |
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,4 @@ | ||
|
||
let std-c-compile-constructor(ctx: FContext, fname: CString, fterm: AST, args: AST): Fragment = ( | ||
mk-fragment(); | ||
); |
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,4 @@ | ||
|
||
int main() { | ||
return 0; | ||
} |
Empty file.