Skip to content

Commit

Permalink
fix: minor fixes for C backend on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
serkonda7 committed Jan 4, 2024
1 parent 6a3aa82 commit fe3754f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ _unreleased_
### Type Checks
- Ensure function parameter type exists

### C Backend
- builder: Fixes for using the C backend on windows
- Fix string interpolation C error with tcc

### General Fixes
- Fix integer division assign that could result in a float
- _[JS]_ Fix integer division assign that could result in a float

### CLI and Tooling
- `build`: Add `-cc` option to use a custom C compiler
Expand Down
8 changes: 4 additions & 4 deletions lib/bait/builder/builder.bt
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,10 @@ fun (mut b Builder) code_gen_c() i32 {
res := cgen.gen(b.parsed_files, b.parser.table, b.prefs) + '\n'
timers.show('GEN')

if os.exists_dir(b.prefs.out_name) {
if os.exists_dir(b.prefs.out_name) or os.platform() == 'win32' {
b.prefs.out_name += '.exe'
} else {
ensure_dir_exists(os.dir(b.prefs.out_name))
}
ensure_dir_exists(os.dir(b.prefs.out_name))

tmp_c_path := os.join_path(os.tmp_dir(), [os.file_name(b.prefs.out_name) + '.c'])
os.write_file(tmp_c_path, res)
Expand All @@ -228,7 +227,8 @@ fun (mut b Builder) code_gen_c() i32 {

if b.prefs.should_run{
argstr := b.prefs.user_args.join(' ')
run_res := os.system('./${b.prefs.out_name} ${argstr}')
run_cmd := './${b.prefs.out_name} ${argstr}'.replace('/', os.PATH_SEP)
run_res := os.system(run_cmd)
if not b.prefs.keep_exe {
os.rm(b.prefs.out_name)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/bait/gen/c/expr.bt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fun (mut g Gen) string_literal(node ast.StringLiteral) {

fun (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
len := node.vals.length + node.exprs.length
g.write('interpolate(new_array_from_c(${len}, ${len}, sizeof(string), (string[]){')
g.write('interpolate(new_array_from_c(${len}, ${len}, sizeof(string), (string[${len}]){')
for i, val in node.vals {
esc_val := util.escape_char(val.replace('\n', '\\n'), `\"`)
g.write('from_c_string("${esc_val}")')
Expand Down
3 changes: 0 additions & 3 deletions lib/builtin/decls.c.bt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'stdio.h' as #C._
import 'string.h' as #C._
import 'stdlib.h' as #C._
import 'stdbool.h' as #C._
import 'unistd.h' as #C._

pub interface #C.int8_t {}
pub interface #C.int16_t {}
Expand Down Expand Up @@ -45,8 +44,6 @@ pub fun #C.calloc(n i32, size i32) &u8

pub fun #C.malloc(size i32) &u8

pub fun #C.access(path &u8, mode i32) i32

pub fun #C.memcpy(dest &void, src &void, size i32)

pub fun #C.memmove(dest &void, src &void, size i32)
7 changes: 7 additions & 0 deletions lib/os/decls.c.bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2024-present Lukas Neubert <[email protected]>
// SPDX-License-Identifier: MPL-2.0
package os

import 'unistd.h' as #C._

pub fun #C.access(path &u8, mode i32) i32

0 comments on commit fe3754f

Please sign in to comment.