This commit is contained in:
nora 2023-05-27 17:46:52 +02:00
parent db219d3d74
commit 3a282ffb89
15 changed files with 159 additions and 83 deletions

26
flake.lock generated Normal file
View file

@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1685199731,
"narHash": "sha256-t8I2oEFetISWpY4NUydCNcDJLSBGGyMCeozzVborlZA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3580ac6c65ec97ebccb02c166af8d19045d4d291",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

39
flake.nix Normal file
View file

@ -0,0 +1,39 @@
{
description = "the uwucc c compiler";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs"; # also valid: "nixpkgs"
};
outputs = { self, nixpkgs }:
let
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
"aarch64-linux" # 64-bit ARM Linux
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
# Helper to provide system-specific attributes
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
in
{
devShells = forAllSystems ({ pkgs }: {
default = pkgs.mkShell {
buildInputs = with pkgs; [
clang
llvmPackages_16.bintools
rustup
cargo-insta
];
shellHook = ''
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
'';
};
});
};
}

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -32,7 +32,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -31,13 +31,13 @@ expression: "(parsed_pretty, pretty_printed_source)"
(
If {
cond: (Atom(Int(1)), 22..23),
then: [(Expr(Atom(String("a"))), 35..37)],
then: [(Expr(Atom(String([97]))), 35..37)],
otherwise: Some([
(
If {
cond: (Atom(Int(2)), 55..56),
then: [(Expr(Atom(String("b"))), 68..70)],
otherwise: Some([(Expr(Atom(String("c"))), 94..96)]),
then: [(Expr(Atom(String([98]))), 68..70)],
otherwise: Some([(Expr(Atom(String([99]))), 94..96)]),
},
51..70,
),

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -21,7 +21,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionParamDecl {
decl_spec: (
DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Long }),
ty: Integer(IntTy(Signed, Long)),
attrs: "(empty)",
},
9..13,
@ -37,7 +37,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionParamDecl {
decl_spec: (
DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
19..22,

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "EXTERN | THREAD_LOCAL",
},
init_declarators: [

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -38,7 +38,27 @@ expression: "(parsed_pretty, pretty_printed_source)"
),
18..23,
),
(Expr(Atom(String("hello world!"))), 29..42),
(
Expr(
Atom(
String([
104,
101,
108,
108,
111,
32,
119,
111,
114,
108,
100,
33,
]),
),
),
29..42,
),
],
}),
1..46,

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -64,7 +64,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -32,7 +32,28 @@ expression: "(parsed_pretty, pretty_printed_source)"
Expr(
Postfix(ExprPostfix {
lhs: (Atom(Ident((puts, 18..22))), 18..22),
op: Call([(Atom(String("Hello, world!")), 23..37)]),
op: Call([
(
Atom(
String([
72,
101,
108,
108,
111,
44,
32,
119,
111,
114,
108,
100,
33,
]),
),
23..37,
),
]),
}),
),
22..39,

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -31,8 +31,8 @@ expression: "(parsed_pretty, pretty_printed_source)"
(
If {
cond: (Atom(Int(1)), 22..23),
then: [(Expr(Atom(String("a"))), 35..37)],
otherwise: Some([(Expr(Atom(String("b"))), 61..63)]),
then: [(Expr(Atom(String([97]))), 35..37)],
otherwise: Some([(Expr(Atom(String([98]))), 61..63)]),
},
18..37,
),

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -31,8 +31,8 @@ expression: "(parsed_pretty, pretty_printed_source)"
(
If {
cond: (Atom(Int(1)), 22..23),
then: [(Expr(Atom(String("a"))), 33..35)],
otherwise: Some([(Expr(Atom(String("b"))), 55..57)]),
then: [(Expr(Atom(String([97]))), 33..35)],
otherwise: Some([(Expr(Atom(String([98]))), 55..57)]),
},
18..35,
),

View file

@ -31,7 +31,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: SChar,
ty: Integer(IntTy(Signed, Char)),
attrs: "(empty)",
},
init_declarators: [
@ -54,7 +54,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: UChar,
ty: Integer(IntTy(Unsigned, Char)),
attrs: "(empty)",
},
init_declarators: [
@ -77,7 +77,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Short }),
ty: Integer(IntTy(Signed, Short)),
attrs: "(empty)",
},
init_declarators: [
@ -100,7 +100,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Short }),
ty: Integer(IntTy(Signed, Short)),
attrs: "(empty)",
},
init_declarators: [
@ -123,7 +123,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Short }),
ty: Integer(IntTy(Signed, Short)),
attrs: "(empty)",
},
init_declarators: [
@ -146,7 +146,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Short }),
ty: Integer(IntTy(Signed, Short)),
attrs: "(empty)",
},
init_declarators: [
@ -169,10 +169,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Unsigned,
kind: Short,
}),
ty: Integer(IntTy(Unsigned, Short)),
attrs: "(empty)",
},
init_declarators: [
@ -195,10 +192,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Unsigned,
kind: Short,
}),
ty: Integer(IntTy(Unsigned, Short)),
attrs: "(empty)",
},
init_declarators: [
@ -221,7 +215,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -244,7 +238,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -267,7 +261,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -290,7 +284,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Unsigned, kind: Int }),
ty: Integer(IntTy(Unsigned, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -313,7 +307,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Unsigned, kind: Int }),
ty: Integer(IntTy(Unsigned, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -336,7 +330,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Long }),
ty: Integer(IntTy(Signed, Long)),
attrs: "(empty)",
},
init_declarators: [
@ -359,7 +353,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Long }),
ty: Integer(IntTy(Signed, Long)),
attrs: "(empty)",
},
init_declarators: [
@ -382,7 +376,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Long }),
ty: Integer(IntTy(Signed, Long)),
attrs: "(empty)",
},
init_declarators: [
@ -405,7 +399,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Long }),
ty: Integer(IntTy(Signed, Long)),
attrs: "(empty)",
},
init_declarators: [
@ -428,10 +422,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Unsigned,
kind: Long,
}),
ty: Integer(IntTy(Unsigned, Long)),
attrs: "(empty)",
},
init_declarators: [
@ -454,10 +445,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Unsigned,
kind: Long,
}),
ty: Integer(IntTy(Unsigned, Long)),
attrs: "(empty)",
},
init_declarators: [
@ -480,10 +468,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Signed,
kind: LongLong,
}),
ty: Integer(IntTy(Signed, LongLong)),
attrs: "(empty)",
},
init_declarators: [
@ -506,10 +491,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Signed,
kind: LongLong,
}),
ty: Integer(IntTy(Signed, LongLong)),
attrs: "(empty)",
},
init_declarators: [
@ -532,10 +514,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Signed,
kind: LongLong,
}),
ty: Integer(IntTy(Signed, LongLong)),
attrs: "(empty)",
},
init_declarators: [
@ -558,10 +537,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Signed,
kind: LongLong,
}),
ty: Integer(IntTy(Signed, LongLong)),
attrs: "(empty)",
},
init_declarators: [
@ -584,10 +560,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Unsigned,
kind: LongLong,
}),
ty: Integer(IntTy(Unsigned, LongLong)),
attrs: "(empty)",
},
init_declarators: [
@ -610,10 +583,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy {
sign: Unsigned,
kind: LongLong,
}),
ty: Integer(IntTy(Unsigned, LongLong)),
attrs: "(empty)",
},
init_declarators: [
@ -633,5 +603,5 @@ expression: "(parsed_pretty, pretty_printed_source)"
771..795,
),
]),
"char a = 1;\nsigned char b = 2;\nunsigned char c = 3;\nshort d = 4;\nshort e = 6;\nshort f = 5;\nshort g = 7;\nunsigned short h = 8;\nunsigned short i = 9;\nint j = 10;\nint k = 11;\nint l = 12;\nunsigned int m = 13;\nunsigned int n = 14;\nlong o = 15;\nlong p = 16;\nlong q = 17;\nlong r = 18;\nunsigned long s = 19;\nunsigned long t = 20;\nlong long u = 21;\nlong long v = 22;\nlong long w = 23;\nlong long x = 24;\nunsigned long long y = 25;\nunsigned long long z = 26;\n",
"char a = 1;\nchar b = 2;\nunsigned char c = 3;\nshort d = 4;\nshort e = 6;\nshort f = 5;\nshort g = 7;\nunsigned short h = 8;\nunsigned short i = 9;\nint j = 10;\nint k = 11;\nint l = 12;\nunsigned int m = 13;\nunsigned int n = 14;\nlong o = 15;\nlong p = 16;\nlong q = 17;\nlong r = 18;\nunsigned long s = 19;\nunsigned long t = 20;\nlong long u = 21;\nlong long v = 22;\nlong long w = 23;\nlong long x = 24;\nunsigned long long y = 25;\nunsigned long long z = 26;\n",
)

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
FunctionDef(FunctionDef {
decl: Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [

View file

@ -8,7 +8,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -38,7 +38,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [
@ -75,7 +75,7 @@ expression: "(parsed_pretty, pretty_printed_source)"
Decl(
Normal(NormalDecl {
decl_spec: DeclSpec {
ty: Integer(IntTy { sign: Signed, kind: Int }),
ty: Integer(IntTy(Signed, Int)),
attrs: "(empty)",
},
init_declarators: [