Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions LM23COMMON/typecheck-infer-type-definition.lsts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

let type-ast-inserts = mk-vector(type(AST));
let complex-type-index = {} : Hashtable<(CString,U64),U64>;
let complex-type-index = {} : Hashtable<(CString,U64),Bool>;

let visit-field-template(field-name: CString, base-type: Type, field-type: Type, blame: AST, field-ordinal: U64, case-number: U64): Nil = (
let mangled-field-name = case-number.into(type(CString)) + c"_" + field-name;
Expand Down Expand Up @@ -83,7 +83,7 @@ let infer-type-definition(term: AST): Nil = (

let case-number = 0_u64;
for vector Tuple{ case-tag2=first, case-fields=second } in cases {
complex-type-index = complex-type-index.bind( lhs-type.ground-tag-and-arity, 1_u64 );
complex-type-index = complex-type-index.bind( lhs-type.ground-tag-and-arity, true );
datatype-index = datatype-index.bind( lhs-type.ground-tag-and-arity, true );
let field-ordinal = 0_u64;
for vector Tuple{ field-name3=first, field-type=second } in case-fields {
Expand Down
4 changes: 2 additions & 2 deletions PLUGINS/BACKEND/C/escape-string.lsts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

let escape-string(s: CString): CString = (
let e = SNil;
while head(s) {
while head(s) != 0 {
if head(s) == 92 {
s = tail(s);
match head(s) {
Expand All @@ -27,7 +27,7 @@ let escape-string(s: CString): CString = (

let escape-string(s: S): S = (
match s {
SAtom{atom=atom} => SAtom(escape-string(atom));
SAtom{atom=atom} => SAtom(escape-string(atom.into(type(CString))));
SCons{left=left, right=right} => escape-string(left) + escape-string(right);
_ => SNil;
}
Expand Down
2 changes: 1 addition & 1 deletion PLUGINS/BACKEND/C/std-c-compile-expr.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
let def = var-to-def(t);
let e = std-c-fragment-context.lookup(def, mk-fragment());
if not(non-zero(e)) {
exit-error( untern("Unable to Find Variable Fragment in Context: \{key}"), t );
exit-error("Unable to Find Variable Fragment in Context: \{key}", t );
}; e
}
);
Expand Down
14 changes: 7 additions & 7 deletions PLUGINS/BACKEND/C/std-c-compile-type-typedef.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let std-c-compile-type-typedef-concrete(tctx: Maybe<TypeContext>, concrete-type:
continue-compile-c-typedefs-concrete = cons( (tctx, concrete-type), continue-compile-c-typedefs-concrete );
} else {
concrete-typedef-compiled-index = concrete-typedef-compiled-index.bind(concrete-type, true);
is-cstruct-hard-compiled-index = is-cstruct-hard-compiled-index.bind(concrete-type, 1_u64);
is-cstruct-hard-compiled-index = is-cstruct-hard-compiled-index.bind(concrete-type, true);

assemble-header-section = assemble-header-section + SAtom(c"typedef struct ") + std-c-mangle-type(concrete-type, td)
+ SAtom(c" ") + std-c-mangle-type(concrete-type, td) + SAtom(c";\n");
Expand Down Expand Up @@ -120,26 +120,26 @@ let std-c-compile-type-typedef-concrete(tctx: Maybe<TypeContext>, concrete-type:
};
);

let is-incomplete-typedef(tt: Type): U64 = is-incomplete-typedef(tt, tt.is-t(c"FlexibleArrayMember",0));
let is-incomplete-typedef(tt: Type, is-flexible-array-member: U64): U64 = (
let is-incomplete-typedef(tt: Type): Bool = is-incomplete-typedef(tt, tt.is-t(c"FlexibleArrayMember",0));
let is-incomplete-typedef(tt: Type, is-flexible-array-member: Bool): Bool = (
match tt {
TAnd{conjugate=conjugate} => (
let r = 0_u64;
let r = false;
for vector c in conjugate { r = r or is-incomplete-typedef(c, is-flexible-array-member) };
r
);
TAny{} => false;
TVar{} => false;
TGround{tag:"Sized",parameters:[st..]} => is-incomplete-typedef(st);
TGround{tag:"Array",parameters:[_..base-type..]} => if is-flexible-array-member then is-incomplete-typedef(base-type) else false;
TGround{tag:c"Sized",parameters:[st..]} => is-incomplete-typedef(st);
TGround{tag:c"Array",parameters:[_..base-type..]} => if is-flexible-array-member then is-incomplete-typedef(base-type) else false;
TGround{} => complex-type-index.lookup(tt.ground-tag-and-arity,false)
and not(is-cstruct-hard-compiled-index.lookup(tt, false));
}
);

let continue-compile-c-typedefs-concrete = [] : List<(TypeContext?,Type)>;
let continue-compile-c-typedefs-count = 0_u64;
let is-cstruct-hard-compiled-index = {} : Hashtable<Type,U64>;
let is-cstruct-hard-compiled-index = {} : Hashtable<Type,Bool>;

let try-continue-compile-c-typedefs(): Nil = (
let continue = continue-compile-c-typedefs-concrete;
Expand Down
4 changes: 2 additions & 2 deletions PLUGINS/BACKEND/C/std-c-is-ctype.lsts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

let std-c-is-ctype(tt: Type): U64 = (
let std-c-is-ctype(tt: Type): Bool = (
match tt {
TGround{tag:c"C"} => true;
TGround{tag:c"Array", parameters:[_.. base-type..]} => std-c-is-ctype(base-type);
TAnd{ conjugate=conjugate } => (
let result = false as U64;
let result = false;
for vector c in conjugate { result = result or std-c-is-ctype(c) };
result
);
Expand Down
2 changes: 1 addition & 1 deletion PLUGINS/BACKEND/C/std-c-mangle-declaration.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let std-c-mangle-declaration(tt: Type, blame: AST): Tuple<S,S> = (

let std-c-mangle-declaration-internal(tt: Type, blame: AST): Tuple<S,S> = std-c-mangle-declaration-internal(tt, false, blame);

let std-c-mangle-declaration-internal(tt: Type, is-flexible-array-member: U64, blame: AST): Tuple<S,S> = (
let std-c-mangle-declaration-internal(tt: Type, is-flexible-array-member: Bool, blame: AST): Tuple<S,S> = (
match tt {
TGround{tag:c"Array", parameters:[ TGround{tag:c"CONST"}.. array-base.. ]} => (
let rest = std-c-mangle-declaration-internal(array-base, false, blame);
Expand Down
18 changes: 9 additions & 9 deletions PLUGINS/FRONTEND/C/c-frontend.lsts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

let c-frontend(fp: CString): Nil = (
let tmp = intern(mktemp(untern("/tmp/lm.tmp.XXXXXX") as U8[]) as CString);
let cmd = "cpp /dev/null -o " + tmp;
cmd = cmd + " -U__USE_MISC";
cmd = cmd + " -D__STRICT_ANSI__";
cmd = cmd + " -D__LM__";
cmd = cmd + " -include \"" + intern(fp) + "\"";
let tmp = mktemp(c"/tmp/lm.tmp.XXXXXX" as U8[]) as CString;
let cmd = c"cpp /dev/null -o " + tmp;
cmd = cmd + c" -U__USE_MISC";
cmd = cmd + c" -D__STRICT_ANSI__";
cmd = cmd + c" -D__LM__";
cmd = cmd + c" -include \"" + fp + c"\"";

if system(untern(cmd) as U8[]) != 0 {
fail("cpp failed. command: \"" + cmd + "\"");
if system(cmd) != 0 {
fail(c"cpp failed. command: \"" + cmd + c"\"");
};

let file-contents = read-file(untern(tmp));
let file-contents = read-file(tmp);
let tokens = std-c-tokenize-string(fp, file-contents);
std-c-parse(tokens);
);
Expand Down
Loading
Loading