Skip to content

Commit

Permalink
Merge pull request #2 from Princess-org/leakfix
Browse files Browse the repository at this point in the history
Leakfix
  • Loading branch information
Victorious3 committed Aug 2, 2022
2 parents c739313 + 32046f2 commit 23f26f2
Show file tree
Hide file tree
Showing 32 changed files with 4,578 additions and 4,607 deletions.
29 changes: 13 additions & 16 deletions include/preload.pr
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,47 @@ export type FfiGlobal = struct {
}

// Map of FfiVariable
export var FFI_GLOBALS: *map::Map
export var FFI_GLOBALS: &SMap(&FfiGlobal)
// Map of FfiFunction
export var FFI_FUNCTIONS: *map::Map
export var FFI_FUNCTIONS: &SMap(&FfiFunction)

export def load_ffi(def_names: [string], defs: [type () -> ()], var_names: [string], vars: [*]) {
// We are getting called from before the module's main function so
// we must do some setup here
if not FFI_GLOBALS {
FFI_GLOBALS = map::make()
FFI_GLOBALS = map::make(type &FfiGlobal)
}
if not FFI_FUNCTIONS {
FFI_FUNCTIONS = map::make()
FFI_FUNCTIONS = map::make(type &FfiFunction)
}

assert(def_names.size == defs.size)
for var i in 0..def_names.size {
let name = def_names[i]
let value = defs[i]
let ffi_function = allocate(FfiFunction)
@ffi_function = {
let ffi_function = {
name = name,
ptr = value,
initialized = false
} !FfiFunction
map::put(FFI_FUNCTIONS, name, ffi_function)
} !&FfiFunction
FFI_FUNCTIONS[name] = ffi_function

let ffi_global = allocate(FfiGlobal)
@ffi_global = {
let ffi_global = {
name = name,
ptr = value !*
} !FfiGlobal
map::put(FFI_GLOBALS, name, ffi_global)
} !&FfiGlobal
FFI_GLOBALS[name] = ffi_global
}

assert(var_names.size == vars.size)
for var i in 0..var_names.size {
let name = var_names[i]
let value = vars[i]
let ffi_global = allocate(FfiGlobal)
@ffi_global = {
let ffi_global = {
name = name,
ptr = value
} !FfiGlobal
map::put(FFI_GLOBALS, name, ffi_global)
} !&FfiGlobal
FFI_GLOBALS[name] = ffi_global
}
}

Expand Down
31 changes: 14 additions & 17 deletions src/builtins.pr
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import compiler

export let builtins = scope::enter_scope(null, null)

def create_int_type(name: string, size: size_t, unsig: bool) -> *typechecking::Type {
let ident = parser::make_identifier([name])
def create_int_type(name: &string, size: size_t, unsig: bool) -> &typechecking::Type {
let ident = parser::make_identifier(name)
var tpe = typechecking::make_type(typechecking::TypeKind::WORD, ident)
(@tpe).size = size
(@tpe).align = size
Expand All @@ -17,8 +17,8 @@ def create_int_type(name: string, size: size_t, unsig: bool) -> *typechecking::T
return tpe
}

def create_float_type(name: string, size: size_t) -> *typechecking::Type {
let ident = parser::make_identifier([name])
def create_float_type(name: &string, size: size_t) -> &typechecking::Type {
let ident = parser::make_identifier(name)
var tpe = typechecking::make_type(typechecking::TypeKind::FLOAT, ident)
(@tpe).size = size
(@tpe).align = size
Expand All @@ -29,27 +29,23 @@ def create_float_type(name: string, size: size_t) -> *typechecking::Type {

export let type_ = typechecking::make_type_raw(typechecking::TypeKind::TYPE)

let char_ident = parser::make_identifier(["char"])
let char_ident = parser::make_identifier("char")
export let char_ = typechecking::make_type(typechecking::TypeKind::CHAR, char_ident)
char_.size = size_of char
char_.align = align_of char
char_.unsig = true
scope::create_type(builtins, char_ident, parser::ShareMarker::NONE, char_)

let bool_ident = parser::make_identifier(["bool"])
let bool_ident = parser::make_identifier("bool")
export let bool_ = typechecking::make_type(typechecking::TypeKind::BOOL, bool_ident)
(@bool_).size = (size_of bool)
(@bool_).align = (align_of bool)
// This isn't very well defined, but I guess we need this for treating bool as an arithmetic type
(@bool_).unsig = true
scope::create_type(builtins, bool_ident, parser::ShareMarker::NONE, bool_)

let str_ident = parser::make_identifier(["string"])
export let string_ = typechecking::make_type(typechecking::TypeKind::ARRAY, str_ident)
(@string_).size = (size_of string)
(@string_).align = (align_of string)
(@string_).tpe = char_
scope::create_type(builtins, str_ident, parser::ShareMarker::NONE, string_)
export let string_ = typechecking::array(char_)
scope::create_type(builtins, parser::make_identifier("string"), parser::ShareMarker::NONE, string_)

export let float_ = create_float_type("float", size_of float)
export let double_ = create_float_type("double", size_of double)
Expand Down Expand Up @@ -80,13 +76,14 @@ export let uint64_ = create_int_type("uint64", size_of uint64, true)
export let size_t_ = create_int_type("size_t", size_of size_t, true)

#if not defined WIN32 {
let va_list_ident = parser::make_identifier(["__va_list_tag"])
let va_list_ident = parser::make_identifier("__va_list_tag")
export let __va_list_tag_ = typechecking::make_type(typechecking::TypeKind::STRUCT, va_list_ident)
__va_list_tag_.fields = allocate_ref(typechecking::StructMember, 0)
scope::create_type(builtins, va_list_ident, parser::ShareMarker::NONE, __va_list_tag_)
}

// These get set from toolchain
export var File_: *typechecking::Type = null
export var Type_: *typechecking::Type = null
export var Ref_ : *typechecking::Type = null
export var Function_: *typechecking::Type = null
export var File_: &typechecking::Type = null
export var Type_: &typechecking::Type = null
export var Ref_ : &typechecking::Type = null
export var Function_: &typechecking::Type = null
Loading

0 comments on commit 23f26f2

Please sign in to comment.