Skip to content

Commit

Permalink
remove from for-each syntax in favor of
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaquraish committed Nov 24, 2024
1 parent f23c94b commit 920297f
Show file tree
Hide file tree
Showing 29 changed files with 1,819 additions and 1,824 deletions.
3,250 changes: 1,623 additions & 1,627 deletions bootstrap/stage0.c

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions compiler/ast/nodes.oc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ enum ASTType {
BoolLiteral
Break
Call
Constant
Continue
Error
Identifier
Expand All @@ -38,7 +37,6 @@ enum ASTType {
FormatStringLiteral
Cast
Null
MethodCall
Match
Defer
Specialization
Expand Down Expand Up @@ -94,7 +92,7 @@ def Structure::new(): &Structure {
}

def Structure::get_field(&this, name: str): &Variable {
for field : .fields.iter() {
for field in .fields.iter() {
if field.sym.name.eq(name) {
return field
}
Expand All @@ -119,7 +117,7 @@ struct Enum {
}

def Enum::get_variant(&this, name: str): &EnumVariant {
for variant : .variants.iter() {
for variant in .variants.iter() {
if variant.sym.name.eq(name) return variant
}
return null
Expand Down
14 changes: 7 additions & 7 deletions compiler/ast/program.oc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def Namespace::new(parent: &Namespace, path: str): &Namespace {
def Namespace::dump(&this) {
println(f"============= NS: {.sym.display} {.path} ==============")
println(" Functions:")
for func : .functions.iter() {
for func in .functions.iter() {
println(f" - {func.sym.display}")
}
println(f" Structs:")
Expand Down Expand Up @@ -110,26 +110,26 @@ def Namespace::find_importable_symbol(&this, name: str): &Symbol {
let item = .namespaces.get(name, null)
if item? then return item.sym
for node : .constants.iter() {
for node in .constants.iter() {
let var = node.u.var_decl
if var.sym.name.eq(name) return var.sym
}
for node : .variables.iter() {
for node in .variables.iter() {
let var = node.u.var_decl
if var.sym.name.eq(name) return var.sym
}
for func : .functions.iter() {
for func in .functions.iter() {
if func.kind == Method then continue
if func.sym.name.eq(name) return func.sym
}
for struc : .structs.iter() {
for struc in .structs.iter() {
if struc.sym.name.eq(name) return struc.sym
}
for enom : .enums.iter() {
for enom in .enums.iter() {
if enom.sym.name.eq(name) return enom.sym
}
Expand Down Expand Up @@ -383,7 +383,7 @@ struct NSIterator {
def NSIterator::has_value(&this): bool => .curr?

def NSIterator::next(&this) {
for ns : .curr.namespaces.iter_values() {
for ns in .curr.namespaces.iter_values() {
.stack.push(ns)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/attributes.oc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def Attribute::validate(&this, parser_for_errors: &Parser): bool {
// object itself, which will be replaced with the object's name at codegen
if .args.size == 2 {
let found_dollar = false
for c : .args.at(1).chars() {
for c in .args.at(1).chars() {
if c == '$' then found_dollar = true
}
if not found_dollar {
Expand Down
32 changes: 16 additions & 16 deletions compiler/docgen.oc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def DocGenerator::gen_enum(&this, enom: &Enum): &Value {
}

let shared_fields_doc = Value::new(List)
for field : enom.shared_fields.iter() {
for field in enom.shared_fields.iter() {
let field_doc = Value::new(Dictionary)
field_doc["name"] = field.sym.name
field_doc["type"] = .gen_typename(field.type)
Expand All @@ -48,7 +48,7 @@ def DocGenerator::gen_enum(&this, enom: &Enum): &Value {
enum_doc["shared_fields"] = shared_fields_doc

let variants_doc = Value::new(List)
for variant : enom.variants.iter() {
for variant in enom.variants.iter() {
// TODO: Add values for the variants if needed
let variant_doc = Value::new(Dictionary)
variant_doc["name"] = variant.sym.name
Expand All @@ -59,7 +59,7 @@ def DocGenerator::gen_enum(&this, enom: &Enum): &Value {
variant_doc["extern"] = variant.sym.out_name()
}
let fields_doc = Value::new(List)
for field : variant.specific_fields.iter() {
for field in variant.specific_fields.iter() {
fields_doc.push(.gen_typename(field.type))
}
variant_doc["fields"] = fields_doc
Expand Down Expand Up @@ -93,7 +93,7 @@ def DocGenerator::gen_templated_type(&this, base: &Type, args: &Vector<&Type>):
buf += base_name
buf += "<"
let first = true
for arg_type : args.iter() {
for arg_type in args.iter() {
if not first then buf += ", "
first = false

Expand Down Expand Up @@ -144,7 +144,7 @@ def DocGenerator::gen_typename_str(&this, type: &Type): str {
let buf = Buffer::make()
buf += "fn("
let first = true
for param : type.u.func.params.iter() {
for param in type.u.func.params.iter() {
if not first then buf += ", "
first = false

Expand Down Expand Up @@ -188,7 +188,7 @@ def DocGenerator::gen_methods(&this, type: &Type): &Value {
assert type.can_have_methods(), "gen_methods called with type that can't have methods"

let methods_doc = Value::new(Dictionary)
for it : type.methods.iter() {
for it in type.methods.iter() {
let method = it.value
methods_doc[method.sym.name] = .gen_function(method)
}
Expand Down Expand Up @@ -221,7 +221,7 @@ def DocGenerator::gen_function(&this, func: &Function): &Value {
return_doc["type"] = .gen_typename(ret_type)

let params_doc = Value::new(List)
for param : func.params.iter() {
for param in func.params.iter() {
let param_doc = Value::new(Dictionary)
param_doc["name"] = `{param.sym.name}`
if param.sym.comment? {
Expand Down Expand Up @@ -259,7 +259,7 @@ def DocGenerator::gen_struct(&this, struc: &Structure): &Value {

if struc.sym.is_templated() {
let params_doc = Value::new(List)
for sym : struc.sym.template.params.iter() {
for sym in struc.sym.template.params.iter() {
params_doc.push(Value::new_str(sym.name))
}
struc_doc["template_params"] = params_doc
Expand All @@ -271,7 +271,7 @@ def DocGenerator::gen_struct(&this, struc: &Structure): &Value {
}

let fields_doc = Value::new(List)
for field : struc.fields.iter() {
for field in struc.fields.iter() {
let field_doc = Value::new(Dictionary)
field_doc["name"] = field.sym.name
field_doc["type"] = .gen_typename(field.type)
Expand Down Expand Up @@ -305,7 +305,7 @@ def DocGenerator::gen_ns(&this, ns: &Namespace): &Value {

if not ns.enums.is_empty() {
let enums_doc = Value::new(Dictionary)
for enom : ns.enums.iter() {
for enom in ns.enums.iter() {
enums_doc[enom.sym.name] = .gen_enum(enom)
}
ns_doc["enums"] = enums_doc
Expand All @@ -314,7 +314,7 @@ def DocGenerator::gen_ns(&this, ns: &Namespace): &Value {
if not ns.structs.is_empty() {
let structs_doc = Value::new(Dictionary)
let unions_doc = Value::new(Dictionary)
for struc : ns.structs.iter() {
for struc in ns.structs.iter() {
let struct_doc = .gen_struct(struc)
if not struc.is_union {
structs_doc[struc.sym.name] = struct_doc
Expand All @@ -333,7 +333,7 @@ def DocGenerator::gen_ns(&this, ns: &Namespace): &Value {

if not ns.variables.is_empty() {
let vars_doc = Value::new(Dictionary)
for node : ns.variables.iter() {
for node in ns.variables.iter() {
let var = node.u.var_decl
let var_doc = Value::new(Dictionary)
var_doc["id"] = `{var:x}`
Expand All @@ -354,7 +354,7 @@ def DocGenerator::gen_ns(&this, ns: &Namespace): &Value {

if not ns.constants.is_empty() {
let consts_doc = Value::new(Dictionary)
for node : ns.constants.iter() {
for node in ns.constants.iter() {
let var = node.u.var_decl
let const_doc = Value::new(Dictionary)
const_doc["id"] = `{var:x}`
Expand All @@ -375,7 +375,7 @@ def DocGenerator::gen_ns(&this, ns: &Namespace): &Value {

if not ns.functions.is_empty() {
let funcs_doc = Value::new(Dictionary)
for func : ns.functions.iter() {
for func in ns.functions.iter() {
if func.kind == Method {
continue
}
Expand All @@ -387,7 +387,7 @@ def DocGenerator::gen_ns(&this, ns: &Namespace): &Value {

if not ns.typedefs.is_empty() {
let typedefs_doc = Value::new(Dictionary)
for it : ns.typedefs.iter() {
for it in ns.typedefs.iter() {
let typedef_doc = Value::new(Dictionary)
typedef_doc["kind"] = "typedef"
typedef_doc["name"] = it.key.copy()
Expand All @@ -399,7 +399,7 @@ def DocGenerator::gen_ns(&this, ns: &Namespace): &Value {

if not ns.namespaces.is_empty() {
let namespaces_doc = Value::new(Dictionary)
for it : ns.namespaces.iter() {
for it in ns.namespaces.iter() {
let ns_doc = .gen_ns(it.value)
namespaces_doc[it.key] = ns_doc
}
Expand Down
1 change: 1 addition & 0 deletions compiler/lexer.oc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def Lexer::lex_numeric_literal(&this) {
let token = .lex_numeric_literal_helper()

if .cur() == 'u' or .cur() == 'i' or .cur() == 'f' {
let initial_char = .cur()
let start_loc = .loc
let start = .i
.inc()
Expand Down
28 changes: 14 additions & 14 deletions compiler/lsp/finder.oc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def Finder::find_in_expression(&this, node: &AST): bool {
Specialization => {
let spec = &node.u.spec
if .find_in_expression(spec.base) return true
for ty : spec.parsed_template_args.iter() {
for ty in spec.parsed_template_args.iter() {
if .find_in_type(ty) return true
}
}
Expand Down Expand Up @@ -295,9 +295,9 @@ def Finder::find_in_import_part(&this, base: &Symbol, part: &ImportPart, node: &
}
Multiple => {
let multi = &part.u.multiple
for subpath : multi.paths.iter() {
for subpath in multi.paths.iter() {
let prev = base
for subpart : subpath.iter() {
for subpart in subpath.iter() {
if .find_in_import_part(prev, subpart, node) {
if prev? and prev.type == Namespace {
.found_import_ns = prev.u.ns
Expand Down Expand Up @@ -339,7 +339,7 @@ def Finder::find_in_statement(&this, node: &AST): bool {
Import => {
let path = node.u.import_path
let prev = path.root_sym
for part : path.parts.iter() {
for part in path.parts.iter() {
if .find_in_import_part(prev, part, node) {
if prev? and prev.type == Namespace {
.found_import_ns = prev.u.ns
Expand Down Expand Up @@ -383,13 +383,13 @@ def Finder::find_in_type(&this, type: &Type): bool {
UnresolvedTemplate => {
let spec = type.u.unresolved_spec
if .find_in_type(spec.base) return true
for ty : spec.args.iter() {
for ty in spec.args.iter() {
if .find_in_type(ty) return true
}
}
FunctionPtr | Closure => {
let func = type.u.func
for param : func.params.iter() {
for param in func.params.iter() {
if .find_in_var(param, node: null) return true
}
if func.return_type? and .find_in_type(func.return_type) return true
Expand Down Expand Up @@ -419,7 +419,7 @@ def Finder::find_in_function(&this, func: &Function): bool {
if .find_in_expression(func.name_ast) return true

.scopes.push(func.scope)
for param : func.params.iter() {
for param in func.params.iter() {
if .find_in_var(param, node: null) return true
}

Expand All @@ -435,39 +435,39 @@ def Finder::find_in_function(&this, func: &Function): bool {
def Finder::find_in_program(&this, ns: &Namespace): bool {
.scopes.push(ns.scope)

for struc : ns.structs.iter() {
for struc in ns.structs.iter() {
// If this is a template instance, we skip checking it at all.
// The original template (which should be checked separately) will
// have the same span as this instance, and is what we are looking for.
if struc.type? and struc.type.template_instance? continue

if struc.sym.span.contains_loc(.loc) return .set_usage(struc.sym, node: null)
for field : struc.fields.iter() {
for field in struc.fields.iter() {
if .find_in_var(field, node: null) return true
}
}

for enom : ns.enums.iter() {
for enom in ns.enums.iter() {
if enom.sym.span.contains_loc(.loc) return .set_usage(enom.sym, node: null)
for field in enom.shared_fields.iter() {
if .find_in_var(field, node: null) return true
}
for variant in enom.variants.iter() {
if variant.sym.span.contains_loc(.loc) return .set_usage(variant.sym, node: null)
if variant.specific_fields? {
for field : variant.specific_fields.iter() {
for field in variant.specific_fields.iter() {
if .find_in_var(field, node: null) return true
}
}
}
}

for func : ns.functions.iter() {
for func in ns.functions.iter() {
if func.sym.span.contains_loc(.loc) return .set_usage(func.sym, node: null)
if .find_in_function(func) return true
}

for import_ : ns.imports.iter() {
for import_ in ns.imports.iter() {
if .find_in_statement(import_) return true
}

Expand All @@ -489,7 +489,7 @@ def Finder::find_in_program(&this, ns: &Namespace): bool {

.scopes.pop()

for child : ns.namespaces.iter_values() {
for child in ns.namespaces.iter_values() {
if child.sym.span.contains_loc(.loc) return .set_usage(child.sym, node: null)
if .find_in_program(child) return true
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/lsp/mod.oc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def typecheck_and_log_errors(program: &Program, path: str) {
return
}

for err : program.errors.iter() {
for err in program.errors.iter() {
let start = err.span1.start
let end = err.span1.end
if verbose then println("[-] ERROR: %s:%d:%d - %d:%d :: %s", start.filename, start.line, start.col, end.line, end.col, err.msg1)
Expand All @@ -51,7 +51,7 @@ def typecheck_and_log_errors(program: &Program, path: str) {

def handle_validate(program: &Program, path: str) {
typecheck_and_log_errors(program, path)
for err : program.errors.iter() {
for err in program.errors.iter() {
if not err.span1.start.filename? continue
if not (err.span1.start.filename == path) continue

Expand Down Expand Up @@ -105,7 +105,7 @@ def handle_document_symbols(program: &Program, path: str) {
typecheck_and_log_errors(program, path)

let doc_ns: &Namespace = null
for ns : program.iter_namespaces() {
for ns in program.iter_namespaces() {
let ns_filename = ns.span.start.filename
if ns_filename? and ns_filename.eq(path) {
doc_ns = ns
Expand Down
Loading

0 comments on commit 920297f

Please sign in to comment.