Skip to content

Commit 1126ae1

Browse files
committed
[Refactor] TODOs and cleanups
1 parent 1ff8ca6 commit 1126ae1

File tree

17 files changed

+68
-39
lines changed

17 files changed

+68
-39
lines changed

library/browser/html.hexa

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License
22
//
3-
// Copyright (C) 2021-2023 Oleh Petrenko
3+
// Copyright (C) 2021-2024 Oleh Petrenko
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy
66
// of this software and associated documentation files (the "Software"), to deal
@@ -20,6 +20,7 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
// THE SOFTWARE.
2222

23+
/// Global browser functions and values
2324
declare let window: {
2425
/// Raw global window object
2526
window: Any

library/c/runtime.hexa

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License
22
//
3-
// Copyright (C) 2022 Oleh Petrenko
3+
// Copyright (C) 2022-2024 Oleh Petrenko
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy
66
// of this software and associated documentation files (the "Software"), to deal
@@ -26,9 +26,10 @@
2626
fun
2727
hexaRuntimeInit(): Void
2828
{
29-
29+
// TODO
3030
}
3131

32+
// TODO description and documentation
3233
@struct class RuntimeAllocated {
3334
}
3435

library/c/string.hexa

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class String {
154154
}
155155

156156
static fun fromUTF8z(string: ConstArrayPointer<UInt8>): String {
157-
// Note: must use own string length implementation cause incompatible with freestanding targets
157+
// NOTE must use own string length implementation cause incompatible with freestanding targets
158158
let size: Int = countUTF8z(string)
159159
// TODO test type check that constructor is private
160160
// TODO use stack allocated array for small strings or .bss 64k one if size < 64k
@@ -307,7 +307,7 @@ class String {
307307

308308
static fun fromInt32(value: Int): String {
309309
// TODO just [0, ..., 0] N times
310-
// Note: reserves 2 bytes for null-terminator
310+
// NOTE reserves 2 bytes for null-terminator
311311
// ^ for some reason required despite being UInt16-array
312312
// TODO ^ test it more, comment/overwrite `bytes[i] = 0` etc
313313
var bytes: ArrayByValue<UInt16, 12> = [0]

library/nodejs/nodejs.hexa

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License
22
//
3-
// Copyright (C) 2021-2023 Oleh Petrenko
3+
// Copyright (C) 2021-2024 Oleh Petrenko
44
// Copyright (C) 2018 Bogdan Danylchenko
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,7 +25,7 @@ declare fun require(package: String): Any
2525
declare let __dirname: String
2626
declare let __filename: String
2727

28-
// TODO reqire(Buffer)?
28+
// TODO reqire(Buffer)? node:Buffer `require('node:buffer').Buffer`
2929
@rename("Buffer")
3030
@native("Buffer")
3131
declare class Buffer {

source/cli/init.hexa

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,6 @@ fun init() {
163163

164164
// Detects `y`, `yes` and empty answer as `true`
165165
fun isYes(answer: String): Bool {
166+
// TODO code gen must cache this array globally for .includes without allocation
166167
return ['y','yes',''].includes(answer.toLowerCase().trim())
167168
}

source/compiler/lexer.hexa

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Lexer {
5858
let meta: [Meta] = []
5959
// ^ try the compressed idea for meta's at least TODO
6060
// TODO no zeroing of this buffer when parser is *non*-look-ahead
61-
let tokens = Buffer.alloc(len + 1) // Note: 1 extra space for Token.Eof
61+
let tokens = Buffer.alloc(len + 1) // NOTE 1 extra space for Token.Eof
6262
// TODO ensure optimizer/typer infers `Array<T>` properly
6363
var lines = []
6464
var columns = []
@@ -245,7 +245,7 @@ class Lexer {
245245

246246
// Identifiers and keywords
247247
// A-z _
248-
// Note: non-ascii identifiers are NOT allowed
248+
// NOTE non-ascii identifiers are NOT allowed
249249
// TODO describe the 95 trick
250250
if ((_8 & 95) >= 65 && (_8 & 95) <= 90) or (_8 == 95) {
251251
let title = _8 <= 90
@@ -254,7 +254,7 @@ class Lexer {
254254

255255
// TODO is table lookup really faster than conditions? Bit mask possible>
256256
do {
257-
// Note: underscore is inside keyword map
257+
// NOTE underscore is inside keyword map
258258
// This excludes numbers
259259
allLowercase = allLowercase and (_8 >= 95) // TODO `'_'.charCodeAt(0)`
260260
p++
@@ -326,6 +326,7 @@ class Lexer {
326326

327327
// >>>
328328
// TODO this may be done in parser
329+
// ^ if lexer called from parser, it may set flag of not-parsing >>> in templates
329330
if _16 == 15934 and (get_8(position + 2) == ">".charCodeAt(0)) {
330331
add(Token.UnsignedRightShift)
331332
position += 3

source/compiler/normalizer.hexa

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,10 +876,12 @@ class Normalizer {
876876
case As(e, kind, t): switch kind {
877877
case Question:
878878
console.log('`as?` is not yet supported by normalizer, only `as!`')
879+
// TODO error/implement
879880
case KNot:
880881
return Expression.UnsafeBitCast(nodeToExpression(e), typer.types.get(t))
881882
case _:
882883
console.log('`as` is not yet supported by normalizer, only `as!`')
884+
// TODO error/implement
883885
}
884886

885887
case Is(e, t):

source/compiler/parser.hexa

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ class Parser {
19021902
let token = tok()
19031903

19041904
if
1905-
// Note: don't do it like that! Some type syntax uses lowercases
1905+
// NOTE don't do it like that! Some type syntax uses lowercases
19061906
//tok() != Token.Assign and
19071907
//tok() != Token.CallClose and
19081908
//tok() != Token.Comma

source/compiler/preprocessor.hexa

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Preprocessor {
4242
private static fun processTokens(tokens: Tokens, i: Int, project: Project): Tokens {
4343
var i = i
4444
var token = tokens.token[0] as! Token
45-
let bytes = tokens.token.slice() // Note: this creates a copy with all tokens
45+
let bytes = tokens.token.slice() // NOTE this creates a copy with all tokens
4646
// TODO Slicing from `i` would cause allocation on ~every array `[to]` insert, any ideas?
4747
// Maybe just allocate Array(len) + copy values upto i, so unused are null
4848
let params = tokens.value.slice()

source/compiler/typer.hexa

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,14 +2240,15 @@ class Typer {
22402240

22412241
addScope(name, node)
22422242

2243-
// `a op b` like `a + b`
2243+
// `a = b` as a statement
22442244
case Binop(a, op, b):
22452245
fillExpression(node)
22462246

22472247
var parent: Node = parents.get(a)
22482248
// `a = b`
22492249
// TODO separate assign node? or just nested pattern...
2250-
if op == Token.Assign { switch parent {
2250+
if op == Token.Assign {
2251+
switch parent {
22512252
case null:
22522253
switch a {
22532254
case Ident(_): // Ok
@@ -2994,26 +2995,26 @@ class Typer {
29942995
// TODO why the heck `.Vname` here gives Ln1, Col 12???
29952996
// type.V here is ok, but is in the string interpolator
29962997
// ^ should be possible to set starting col/line in Lexer
2997-
// Note: `proposeSimilar` is useless for DotUpper over instances
2998+
// NOTE `proposeSimilar` is useless for DotUpper over instances
29982999
fail('Enum `\(type.name)` instance has no field `.\(n)`', node)
29993000
case ClassInstance(type):
30003001
failNonFatal('Type `\(type.name)` is defined here', type.parent)
3001-
// Note: `proposeSimilar` is useless for DotUpper over instances
3002+
// NOTE `proposeSimilar` is useless for DotUpper over instances
30023003
fail('Class `\(type.name)` has no field `.\(n)`\n\nNote that you are trying to access plain `class` instance and not `enum`', node)
30033004
case Class(type):
30043005
failNonFatal('Type `\(type.name)` is defined here', type.parent)
3005-
// Note: `proposeSimilar` is useless for DotUpper over classes
3006+
// NOTE `proposeSimilar` is useless for DotUpper over classes
30063007
fail('Class `\(type.name)` has no field `.\(n)`\n\nNote that you are trying to access `class` and not `enum`', node)
30073008
case Enum(type):
30083009
let index = type.fieldNames.indexOf(n)
30093010
// TODO `@lazy let enumName = getName(type.name)` so no need to place in every failing `if`
30103011
if index < 0 {
30113012
failNonFatal('Type `\(type.name)` is defined here', type.parent)
3012-
// Note: `proposeSimilar` but only constructors (if any)
3013+
// NOTE `proposeSimilar` but only constructors (if any)
30133014
fail('Enum `\(type.name)` has no value constructor `.\(n)`\n' + proposeSimilar(type.fieldNames.filter((element, index) => type.fieldEnumConstructor[index]), n, 'constructors'), node)
30143015
}
30153016
if type.fieldEnumConstructor[index] != true {
3016-
// Note: this case is probably impossible, i.e. .N *not* being constructor (than what?)
3017+
// NOTE this case is probably impossible, i.e. .N *not* being constructor (than what?)
30173018
fail('Enum `\(type.name)` field `.\(n)` is not a value constructor', node)
30183019
}
30193020
if let fieldType = type.fieldType[index] {
@@ -3033,6 +3034,7 @@ class Typer {
30333034
if asValue {
30343035
fail('Cannot use type `\(name)` as a value, use `\(name)()` to call constructor', node)
30353036
}
3037+
30363038
let subj = find(name)
30373039
if subj == null {
30383040
fail('Cannot find type with name `\(name)`', node)
@@ -3050,7 +3052,8 @@ class Typer {
30503052
let mod = currentModule
30513053
registerClassType(subj)
30523054
currentModule = mod
3053-
case Enum(_): registerEnumType(subj)
3055+
case Enum(_):
3056+
registerEnumType(subj)
30543057
}
30553058

30563059
if let type = types.get(subj) {
@@ -3465,6 +3468,7 @@ class Typer {
34653468

34663469
// TODO `null == null` should error cause no sense
34673470
if leftString != 'null', rightString != 'null' {
3471+
// TODO recommend `.address` for pointers
34683472
fail('Operator `a \(tokenString) b` requires `a` and `b` of comparable types, but got `\(leftString)` and `\(rightString)`', b)
34693473
}
34703474
}
@@ -3773,8 +3777,9 @@ class Typer {
37733777
}
37743778

37753779
if thisType == null {
3776-
fail('Cannot access `this` in class method', node)
3780+
fail('Cannot access `this` in the static method', node)
37773781
}
3782+
37783783
types.set(node, thisType)
37793784
parents.set(node, thisNode)
37803785

@@ -3784,6 +3789,7 @@ class Typer {
37843789

37853790
// `return e`
37863791
case Return(e):
3792+
// TODO cannot return from constructor
37873793
switch e {
37883794
case Var(name, _, _, const):
37893795
let prefix = const? 'let' : 'var'

0 commit comments

Comments
 (0)