Skip to content

Commit f56eba3

Browse files
committed
Made 32-bit ints assumption the default, and made it so string literals can be used inside of pragma directives instead of cstring literals
1 parent 404a700 commit f56eba3

File tree

9 files changed

+62
-24
lines changed

9 files changed

+62
-24
lines changed

Diff for: src/ast/workspace/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ impl<'a> AstWorkspace<'a> {
5151
let settings = AppendOnlyVec::new();
5252

5353
assert_eq!(
54-
settings.push(Settings {
55-
adept_version: AdeptVersion::CURRENT,
56-
debug_skip_merging_helper_exprs: false,
57-
imported_namespaces: vec![],
58-
assume_int_at_least_32_bits: false,
59-
}),
54+
settings.push(Settings::default()),
6055
Self::DEFAULT_SETTINGS_ID.0
6156
);
6257

@@ -120,6 +115,17 @@ pub struct Settings {
120115
pub assume_int_at_least_32_bits: bool,
121116
}
122117

118+
impl Default for Settings {
119+
fn default() -> Settings {
120+
Settings {
121+
adept_version: AdeptVersion::CURRENT,
122+
debug_skip_merging_helper_exprs: false,
123+
imported_namespaces: vec![],
124+
assume_int_at_least_32_bits: true,
125+
}
126+
}
127+
}
128+
123129
impl Settings {
124130
pub fn c_integer_assumptions(&self) -> CIntegerAssumptions {
125131
CIntegerAssumptions {

Diff for: src/interpreter/syscall_handler.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub enum ProjectKind {
2828
WindowedApp = 1,
2929
}
3030

31-
#[derive(Debug, Default)]
31+
#[derive(Debug)]
3232
pub struct BuildSystemSyscallHandler {
3333
pub projects: Vec<Project>,
3434
pub version: Option<AdeptVersion>,
@@ -39,6 +39,20 @@ pub struct BuildSystemSyscallHandler {
3939
pub assume_int_at_least_32_bits: bool,
4040
}
4141

42+
impl Default for BuildSystemSyscallHandler {
43+
fn default() -> Self {
44+
Self {
45+
projects: vec![],
46+
version: None,
47+
link_filenames: HashSet::new(),
48+
link_frameworks: HashSet::new(),
49+
debug_skip_merging_helper_exprs: false,
50+
imported_namespaces: vec![],
51+
assume_int_at_least_32_bits: true,
52+
}
53+
}
54+
}
55+
4256
fn read_cstring(memory: &Memory, value: &Value) -> String {
4357
let mut string = String::new();
4458
let mut address = value.as_u64().unwrap();
@@ -125,9 +139,9 @@ impl SyscallHandler for BuildSystemSyscallHandler {
125139
.push(read_cstring(memory, &args[0]).into_boxed_str());
126140
Value::Literal(ir::Literal::Void)
127141
}
128-
ir::InterpreterSyscallKind::AssumeIntAtLeast32Bits => {
142+
ir::InterpreterSyscallKind::DontAssumeIntAtLeast32Bits => {
129143
assert_eq!(args.len(), 0);
130-
self.assume_int_at_least_32_bits = true;
144+
self.assume_int_at_least_32_bits = false;
131145
Value::Literal(ir::Literal::Void)
132146
}
133147
}

Diff for: src/interpreter_env/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) {
180180
));
181181

182182
file.functions.push(thin_void_function(
183-
"assumeIntAtLeast32Bits",
184-
InterpreterSyscallKind::AssumeIntAtLeast32Bits,
183+
"dontAssumeIntAtLeast32Bits",
184+
InterpreterSyscallKind::DontAssumeIntAtLeast32Bits,
185185
));
186186

187187
file.functions.push(Function {

Diff for: src/ir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub enum InterpreterSyscallKind {
146146
BuildLinkFrameworkName,
147147
Experimental,
148148
ImportNamespace,
149-
AssumeIntAtLeast32Bits,
149+
DontAssumeIntAtLeast32Bits,
150150
}
151151

152152
#[derive(Clone, Debug)]

Diff for: src/parser/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,22 @@ pub fn parse(
3737

3838
pub struct Parser<'a, I: Inflow<Token>> {
3939
pub input: Input<'a, I>,
40+
pub treat_string_literals_as_cstring_literals: bool,
4041
}
4142

4243
impl<'a, I: Inflow<Token>> Parser<'a, I> {
4344
pub fn new(input: Input<'a, I>) -> Self {
44-
Self { input }
45+
Self {
46+
input,
47+
treat_string_literals_as_cstring_literals: false,
48+
}
49+
}
50+
51+
pub fn new_for_pragma(input: Input<'a, I>) -> Self {
52+
Self {
53+
input,
54+
treat_string_literals_as_cstring_literals: true,
55+
}
4556
}
4657

4758
pub fn parse(&mut self) -> Result<AstFile, ParseError> {

Diff for: src/parser/parse_expr/primary/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
5757
modifier: StringModifier::Normal,
5858
..
5959
}) => Ok(Expr::new(
60-
ExprKind::String(self.input.advance().kind.unwrap_string().value),
60+
if self.treat_string_literals_as_cstring_literals {
61+
ExprKind::NullTerminatedString(
62+
CString::new(self.input.advance().kind.unwrap_string().value)
63+
.expect("valid null-terminated string"),
64+
)
65+
} else {
66+
ExprKind::String(self.input.advance().kind.unwrap_string().value)
67+
},
6168
source,
6269
)),
6370
TokenKind::OpenParen => {

Diff for: src/pragma_section/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl PragmaSection {
2929

3030
input.ignore_newlines();
3131

32-
let mut parser = parser::Parser::new(input);
32+
let mut parser = parser::Parser::new_for_pragma(input);
3333
let mut ast_file = AstFile::new();
3434

3535
if parser.input.eat(TokenKind::OpenCurly) {

Diff for: tests/raylib/_.adept

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
pragma => {
3-
adept(c"3.0")
4-
link(c"libraylib.a")
5-
linkFramework(c"OpenGL")
6-
linkFramework(c"Cocoa")
7-
linkFramework(c"IOKit")
8-
linkFramework(c"Foundation")
9-
linkFramework(c"CoreFoundation")
3+
adept("3.0")
4+
link("libraylib.a")
5+
linkFramework("OpenGL")
6+
linkFramework("Cocoa")
7+
linkFramework("IOKit")
8+
linkFramework("Foundation")
9+
linkFramework("CoreFoundation")
1010
}
1111

Diff for: tests/raylib/main.adept

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
func main {
3-
screen_width int = 800
4-
screen_height int = 450
3+
screen_width := 800
4+
screen_height := 450
55

66
InitWindow(screen_width, screen_height, c"Example Window!")
77

0 commit comments

Comments
 (0)