Skip to content

Commit

Permalink
Fix unique_name being duplicates across modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Sep 15, 2022
1 parent 4207ee6 commit c281f2e
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 24 deletions.
4 changes: 2 additions & 2 deletions include/gencstd.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(self, args: List[Type], ret: Type):

def to_string(self, file: File) -> str:
args = ', '.join(map(lambda x: x.to_string(file), filter(lambda x: x != void, self.args)))
return f"({args}) -> ({self.ret.to_string(file) if self.ret != void else ''})"
return f"def ({args}) -> ({self.ret.to_string(file) if self.ret != void else ''})"

class Pointer(Type):
def __init__(self, tpe: Type):
Expand Down Expand Up @@ -338,7 +338,7 @@ def to_declaration(self, file: File) -> str:
def to_symbol(self, n: int, file: File) -> str:
function = ""
if not self.dllimport:
function = f", function = *{self.name} !() -> ()"
function = f", function = *{self.name} !def () -> ()"

ret = f"__SYMBOLS[{n}] = {{ kind = symbol::SymbolKind::FUNCTION, dllimport = {'true' if self.dllimport else 'false'}, name = \"{self.name}\"{function}}} !symbol::Symbol"
return ret
Expand Down
4 changes: 2 additions & 2 deletions include/preload.pr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export def load_library(name: string) {
}
}

export def get_function(sym: &symbol::Symbol) -> () -> () {
export def get_function(sym: &symbol::Symbol) -> def () -> () {
assert sym.kind == symbol::SymbolKind::FUNCTION
let name = sym.name
if sym.function { return sym.function }
Expand All @@ -59,7 +59,7 @@ export def get_function(sym: &symbol::Symbol) -> () -> () {
proc = linux::dlsym(dll.handle, name.value)
}
if proc {
sym.function = proc !() -> ()
sym.function = proc !def () -> ()
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/symbol.pr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type Symbol = struct {
kind: SymbolKind
name: string
dllimport: bool
function: ->
function: def ->
variable: *
initialized: bool
ffi_cif: ffi::ffi_cif
Expand Down
6 changes: 3 additions & 3 deletions src/compiler.pr
Original file line number Diff line number Diff line change
Expand Up @@ -5567,7 +5567,7 @@ def di_function_type(tpe: &typechecking::Type, state: &State) -> &Value {
name = "baseType", value = meta_to_debug_value(diftpe)
} !DebugParam
debug_values[2] = {
name = "size", value = { kind = DebugValueKind::INT, i = (size_of type () -> ()) * 8 } !DebugValue
name = "size", value = { kind = DebugValueKind::INT, i = (size_of type def () -> ()) * 8 } !DebugValue
} !DebugParam

let di = {
Expand Down Expand Up @@ -5763,8 +5763,8 @@ def generate_defer_types(state: &State) {
tpe = typechecking::pointer(env)
} !typechecking::NamedParameter)
defer_function.return_t = vector::make(type &typechecking::Type)
defer_function.align = align_of type ->
defer_function.size = size_of type ->
defer_function.align = align_of type def ->
defer_function.size = size_of type def ->

let defer_functionp = typechecking::pointer(defer_function)
defers_fields[1] = {
Expand Down
2 changes: 1 addition & 1 deletion src/eval.pr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type State = struct {
export type FunctionPtr = struct {
is_fp: bool
struct #union {
fp: ->
fp: def ->
function: &compiler::Function
}
}
Expand Down
25 changes: 17 additions & 8 deletions src/parser.pr
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export type NodeKind = enum {
STRUCT_T
UNION_T
FUNCTION_T
CLOSURE_T
UNSIGNED_T
WORD_T
PTR_T
Expand Down Expand Up @@ -450,7 +451,7 @@ export def destruct(node: *Node) {
__destruct__(*node.value.id_decl_enum)
case NodeKind::ENUM_T:
__destruct__(*node.value.t_enum)
case NodeKind::FUNCTION_T:
case NodeKind::FUNCTION_T, NodeKind::CLOSURE_T:
__destruct__(*node.value.t_func)
case NodeKind::REF_T, NodeKind::PTR_T, NodeKind::ARRAY_T, NodeKind::WEAK_REF_T:
__destruct__(*node.value.t_parr)
Expand Down Expand Up @@ -559,7 +560,7 @@ export def construct(copy: *Node, node: *Node) {
copy.value.id_decl_enum = node.value.id_decl_enum
case NodeKind::ENUM_T:
copy.value.t_enum = node.value.t_enum
case NodeKind::FUNCTION_T:
case NodeKind::FUNCTION_T, NodeKind::CLOSURE_T:
copy.value.t_func = node.value.t_func
case NodeKind::REF_T, NodeKind::PTR_T, NodeKind::ARRAY_T, NodeKind::WEAK_REF_T:
copy.value.t_parr = node.value.t_parr
Expand Down Expand Up @@ -733,7 +734,7 @@ export def deep_copy_node(node: &Node, clear_svalue: bool = true) -> &Node {
case NodeKind::ENUM_T:
copy.value.t_enum.tpe = deep_copy_node(node.value.t_enum.tpe, clear_svalue)
copy.value.t_enum.body = deep_copy_vector_of_nodes(node.value.t_enum.body, clear_svalue)
case NodeKind::FUNCTION_T:
case NodeKind::FUNCTION_T, NodeKind::CLOSURE_T:
copy.value.t_func.args = deep_copy_vector_of_nodes(node.value.t_func.args, clear_svalue)
copy.value.t_func.ret = deep_copy_vector_of_nodes(node.value.t_func.ret, clear_svalue)
case NodeKind::REF_T, NodeKind::PTR_T, NodeKind::ARRAY_T, NodeKind::WEAK_REF_T:
Expand Down Expand Up @@ -1568,25 +1569,33 @@ def parse_type_list(parse_state: &ParseState, sw: bool, inline_types: bool) -> &

// TODO Allow things like (A, B) -> (C, D) -> (E, F)
def parse_type(parse_state: &ParseState, inline_types: bool = true) -> &Node {
let args = parse_type_list(parse_state, false, inline_types)
var is_def = false
var token = peek(parse_state)
if token.tpe == lexer::TokenType::K_DEF {
pop(parse_state)
is_def = true
}
let args = parse_type_list(parse_state, false, inline_types)
token = peek(parse_state)
if token.tpe == lexer::TokenType::ARROW {
pop(parse_state)
let ret = parse_type_list(parse_state, true, inline_types)
var node = make_node(NodeKind::FUNCTION_T, token.line, token.column, parse_state)
var node = make_node(NodeKind::FUNCTION_T if is_def else NodeKind::CLOSURE_T, token.line, token.column, parse_state)
(@node).value.t_func = {
args = args,
ret = ret
} !NodeFunctionT
return node
} else if is_def {
errors::errort(token, parse_state, "Expected ->")
return null
} else if vector::length(args) > 1 {
errors::errort(token, parse_state, "Expected single type, got multiple")
return null
} else if vector::length(args) == 1 {
return args[0]
} else {
return null
}
}
return null
}

// inline_types is a flag to wrap type expressions in Type
Expand Down
4 changes: 2 additions & 2 deletions src/runtime.pr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import cstd
import optional

export type Generator(type T) = struct {
implementation: (*) -> optional::Optional(T)
implementation: def (*) -> optional::Optional(T)
context: *
free_context: (*) -> ()
free_context: def (*) -> ()
}

export def destruct(this: *Generator(type T)) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/testsuite.pr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export def tassert(cond: bool) {
cstd::fflush(stream)
}

export def run_test(desc: &string, function: () -> (), expected_out: &string, expected_err: &string) {
export def run_test(desc: &string, function: def () -> (), expected_out: &string, expected_err: &string) {
if not util::match(match_string, desc) {
return
}
Expand Down Expand Up @@ -183,7 +183,7 @@ export def run_test(desc: &string, function: () -> (), expected_out: &string, ex
}
}

export def run_test(desc: string, function: () -> ()) {
export def run_test(desc: string, function: def () -> ()) {
run_test(desc, function, "", "")
}

Expand Down
4 changes: 2 additions & 2 deletions src/typechecking.pr
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ export def make_type(kind: TypeKind, node: &parser::Node) -> &Type {

export def make_function_type() -> &Type {
let tpe = make_type_raw(TypeKind::FUNCTION)
tpe.size = size_of type () -> ()
tpe.align = align_of type () -> ()
tpe.size = size_of type def () -> ()
tpe.align = align_of type def () -> ()
tpe.imported = false
return tpe
}
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=0.3.1
VERSION=0.3.2

0 comments on commit c281f2e

Please sign in to comment.