Skip to content

Commit

Permalink
fixed some bugs, small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Dec 10, 2023
1 parent 9f853d6 commit aecbbd4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
25 changes: 23 additions & 2 deletions src/ast/base_language.nim
Original file line number Diff line number Diff line change
Expand Up @@ -997,8 +997,7 @@ validationComputers[varDeclClass.id] = proc(ctx: ModelComputationContextBase, no
if not ctx.validateChildType(node, IdVarDeclValue, expectedType):
return false

else:
let valueNode = node.firstChild(IdVarDeclValue).get
elif node.firstChild(IdVarDeclValue).getSome(valueNode):
let valueType = ctx.computeType(valueNode)
if ctx.typesMatch(metaTypeInstance, valueType):
ctx.addDiagnostic(node, "Var decl can't be of type meta type")
Expand Down Expand Up @@ -1256,6 +1255,7 @@ validationComputers[nodeReferenceClass.id] = proc(ctx: ModelComputationContextBa

let targetNode = node.resolveReference(IdNodeReferenceTarget).getOr:
ctx.addDiagnostic(node, "Could not resolve node reference")
ctx.dependOnCurrentRevision()
return false

let scope = ctx.getScope(node)
Expand Down Expand Up @@ -1452,6 +1452,7 @@ var functionInstances* = initTable[FunctionInstantiation, tuple[node: AstNode, r

proc instantiateFunction*(ctx: ModelComputationContextBase, genericFunction: AstNode, arguments: openArray[AstNode]): AstNode =
# debugf"instantiateFunction, args {arguments}, {`$`(genericFunction, true)}"
assert genericFunction.isNotNil

let model = genericFunction.model
let depGraph = ctx.ModelComputationContext.state.depGraph
Expand All @@ -1470,6 +1471,9 @@ proc instantiateFunction*(ctx: ModelComputationContextBase, genericFunction: Ast
# debugf"{i}: generic param type {`$`(genericParamType, true)}"
if genericParamType.class == IdType:
let value = ctx.getValue(arg)
if value.isNil:
log lvlError, fmt"Could not compute value for argument {arg}"
continue
# debugf"{i}: value {value}"
actualArguments.add value
map[genericParam.id] = value
Expand Down Expand Up @@ -1785,6 +1789,23 @@ typeComputers[structMemberAccessClass.id] = proc(ctx: ModelComputationContextBas
else:
return ctx.computeType(memberNode)

validationComputers[structMemberAccessClass.id] = proc(ctx: ModelComputationContextBase, node: AstNode): bool =
# debugf"validate assignment {node}"

if not ctx.validateHasChild(node, IdStructMemberAccessValue):
return false
# if not ctx.validateHasChild(node, IdStructMemberAccessMember):
# return false

let structType = ctx.computeType(node.firstChild(IdStructMemberAccessValue).get)
# let valueType = ctx.computeType(node.firstChild(IdAssignmentValue).get)

if structType.class != IdStructDefinition:
ctx.addDiagnostic(node, fmt"Expected struct type, got {structType}")
return false

return true

typeComputers[structMemberDefinitionClass.id] = proc(ctx: ModelComputationContextBase, node: AstNode): AstNode =
# debugf"compute type for struct member definition {node}"

Expand Down
7 changes: 6 additions & 1 deletion src/ast/base_language_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ proc genNodeBlock(self: BaseLanguageWasmCompiler, node: AstNode, dest: Destinati
else:
WasmLocalIdx.none

self.genBlock(WasmBlockType(kind: ValType, typ: wasmValueType)):
let blockType = if dest.kind == Discard:
WasmBlockType(kind: ValType, typ: WasmValueType.none)
else:
WasmBlockType(kind: ValType, typ: wasmValueType)

self.genBlock(blockType):
if tempIdx.getSome(tempIdx):
self.instr(LocalGet, localIdx: tempIdx)

Expand Down
1 change: 1 addition & 0 deletions src/ast/model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ method getValue*(self: ModelComputationContextBase, node: AstNode): AstNode {.ba
method getScope*(self: ModelComputationContextBase, node: AstNode): seq[AstNode] {.base.} = discard
method validateNode*(self: ModelComputationContextBase, node: AstNode): bool {.base.} = discard
method dependOn*(self: ModelComputationContextBase, node: AstNode) {.base.} = discard
method dependOnCurrentRevision*(self: ModelComputationContextBase) {.base.} = discard
method addDiagnostic*(self: ModelComputationContextBase, node: AstNode, msg: string) {.base.} = discard
method getDiagnostics*(self: ModelComputationContextBase, node: NodeId): seq[string] {.base.} = discard

Expand Down
3 changes: 3 additions & 0 deletions src/ast/model_state.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ method getDiagnostics*(self: ModelComputationContext, node: NodeId): seq[string]
method dependOn*(self: ModelComputationContext, node: AstNode) =
self.state.recordDependency(node.getItem)

method dependOnCurrentRevision*(self: ModelComputationContext) =
self.state.dependOnCurrentRevision()

func fingerprint*(node: AstNode): Fingerprint =
if node.isNil:
return @[]
Expand Down
19 changes: 11 additions & 8 deletions src/platform/widget_builder_model_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,11 @@ method createUI*(self: ModelDocumentEditor, builder: UINodeBuilder, app: App): s

var scrollOffset = uiNode.transformBounds(overlapPanel).y

discard self.document.ctx.validateNode(node)
if node.parent.isNotNil: discard self.document.ctx.validateNode(node.parent)
try:
discard self.document.ctx.validateNode(node)
if node.parent.isNotNil: discard self.document.ctx.validateNode(node.parent)
except CatchableError:
log lvlError, fmt"failed to validate node {node.dump}"
var errors = self.document.ctx.getDiagnostics(node.id)
if node.parent.isNotNil: errors.add self.document.ctx.getDiagnostics(node.parent.id)

Expand All @@ -1136,12 +1139,6 @@ method createUI*(self: ModelDocumentEditor, builder: UINodeBuilder, app: App): s
builder.panel(&{FillX, SizeToContentY, LayoutVertical}, y = scrollOffset):
# builder.panel(&{FillY}, pivot = vec2(1, 0), w = builder.charWidth)

builder.panel(&{FillX, SizeToContentY, LayoutHorizontalReverse}):
builder.panel(&{FillY}, pivot = vec2(1, 0), w = builder.charWidth)
builder.panel(&{SizeToContentX, SizeToContentY, LayoutVertical}, pivot = vec2(1, 0)):
for err in errors:
builder.panel(&{SizeToContentX, SizeToContentY, FillBackground, DrawText, TextAlignHorizontalRight}, text = err, textColor = errorColor, backgroundColor = backgroundColor)

if typ.isNotNil:
builder.panel(&{FillX, SizeToContentY, LayoutHorizontalReverse}):
builder.panel(&{FillY}, pivot = vec2(1, 0), w = builder.charWidth)
Expand All @@ -1159,6 +1156,12 @@ method createUI*(self: ModelDocumentEditor, builder: UINodeBuilder, app: App): s
)
self.createNodeUI(builder, app, currentNode, updateContext, remainingHeightUp=0, remainingHeightDown=h, typ, @[0], 0)

builder.panel(&{FillX, SizeToContentY, LayoutHorizontalReverse}):
builder.panel(&{FillY}, pivot = vec2(1, 0), w = builder.charWidth)
builder.panel(&{SizeToContentX, SizeToContentY, LayoutVertical}, pivot = vec2(1, 0)):
for err in errors:
builder.panel(&{SizeToContentX, SizeToContentY, FillBackground, DrawText, TextAlignHorizontalRight}, text = err, textColor = errorColor, backgroundColor = backgroundColor)

if value.isNotNil:
if typ.isNotNil:
# builder.panel(&{FillY}, pivot = vec2(1, 0), w = builder.charWidth)
Expand Down

0 comments on commit aecbbd4

Please sign in to comment.