diff --git a/analyzer/argument.go b/analyzer/argument.go index 85b78af..aa333df 100644 --- a/analyzer/argument.go +++ b/analyzer/argument.go @@ -7,10 +7,8 @@ import "git.tebibyte.media/arf/arf/parser" // allows things like phrases being arguments to other phrases. type Argument interface { // Phrase + // List // Dereference - // Subscript - // Object - // Array // Variable // IntLiteral // UIntLiteral @@ -21,6 +19,35 @@ type Argument interface { canBePassedAs (what Type) (allowed bool) } +// phrase +// is what +// list +// is what +// dereference +// if length is greater than 1 +// length is 1 +// is what (ignore length) +// else +// is points of reduced of what +// variable +// is what +// int +// primitive is basic signed | float +// length is 1 +// uint +// primitive is basic signed | unsigned | float +// length is 1 +// float +// primitive is basic float +// length is 1 +// string +// primitive is basic signed | unsigned | float +// length is equal +// or +// reduced is variable array +// reduced points to signed | unsigned | float +// length is 1 + // analyzeArgument analyzes an argument func (analyzer AnalysisOperation) analyzeArgument ( inputArgument parser.Argument, @@ -38,9 +65,6 @@ func (analyzer AnalysisOperation) analyzeArgument ( case parser.ArgumentKindDereference: // TODO - case parser.ArgumentKindSubscript: - // TODO - case parser.ArgumentKindList: // TODO diff --git a/analyzer/list.go b/analyzer/list.go new file mode 100644 index 0000000..1453077 --- /dev/null +++ b/analyzer/list.go @@ -0,0 +1,22 @@ +package analyzer + +// import "git.tebibyte.media/arf/arf/parser" +// import "git.tebibyte.media/arf/arf/infoerr" + +type List struct { + // TODO: length of what must be set to length of arguments + what Type + arguments []Argument +} + +func (list List) ToString (indent int) (output string) { + // TODO + panic("TODO") + return +} + +func (list List) canBePassedAs (what Type) (allowed bool) { + // TODO + panic("TODO") + return +} diff --git a/analyzer/literals.go b/analyzer/literals.go index 0c56755..e92543a 100644 --- a/analyzer/literals.go +++ b/analyzer/literals.go @@ -104,7 +104,18 @@ func (literal StringLiteral) ToString (indent int) (output string) { // canBePassedAs returns true if this literal can be implicitly cast to the // specified type, and false if it can't. func (literal StringLiteral) canBePassedAs (what Type) (allowed bool) { - // can be passed to types that are numbers at a primitive level. + // can be passed to types that are numbers at a primitive level, or + // types that can be reduced to a variable array pointing to numbers at + // a primitive level. + + what, worked := what.reduce() + if worked { + // TODO: make some method to check the total length of a type + if what.length != 1 { return } + + if what.kind != TypeKindVariableArray { return } + } + primitive := what.underlyingPrimitive() switch primitive { case diff --git a/analyzer/type-section.go b/analyzer/type-section.go index 39f027f..eaa09b0 100644 --- a/analyzer/type-section.go +++ b/analyzer/type-section.go @@ -80,6 +80,9 @@ func (analyzer AnalysisOperation) analyzeTypeSection () ( outputSection.argument, err = analyzer.analyzeArgument(inputSection.Argument()) if err != nil { return } + if !outputSection.argument.canBePassedAs(outputSection.what) { + + } // TODO: type check default value. possibly add a method to // Argument that takes in a type and determines whether the // argument can fit to it. diff --git a/analyzer/type.go b/analyzer/type.go index be73c4e..676f8aa 100644 --- a/analyzer/type.go +++ b/analyzer/type.go @@ -68,7 +68,7 @@ func (what Type) ToString (indent int) (output string) { } // underlyingPrimitive returns the primitive that this type eventually inherits -// from. +// from. If the type ends up pointing to something, this returns nil. func (what Type) underlyingPrimitive () (underlying *TypeSection) { // if we have already done this operation, return the cahced result. if what.primitiveCache != nil {