Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
peachpit-site committed Jan 31, 2025
1 parent 75f17de commit c6bc93f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion source/checkerr.pf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const

// Things that have the right format to be error codes but aren't.
FALSE_POSITIVES = set(`"database/sql"`, `"encoding/json"`, `"math/rand"`, `"net/http"`,
.. `"os/exec"`, `"path/filepath"`, `html/template`)
.. `"os/exec"`, `"path/filepath"`, `"html/template"`)

cmd

Expand Down
2 changes: 1 addition & 1 deletion source/compiler/compfcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func (cp *Compiler) seekFunctionCall(b *bindle) AlternateType {
// It could have a Golang body.
if F.HasGo {
cp.cmP("Emitting Go function call.", b.tok)
convErrorLoc := cp.reserveError("go/conv/x", b.tok)
convErrorLoc := cp.reserveError("golang/conv/x", b.tok)
args := append([]uint32{b.outLoc, convErrorLoc, F.GoNumber}, b.valLocs...)
cp.Emit(vm.Gofn, args...)
if len(branch.Node.Fn.NameRets) == 0 {
Expand Down
19 changes: 8 additions & 11 deletions source/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var TestFolder embed.FS

type Compiler struct {
// Permanent state, i.e. it is unchanged after initialization.
Vm *vm.Vm // The vm we're compiling to.
Vm *vm.Vm // The vm we're compiling to.
P *parser.Parser // The parser the compiler's using to parse with..
EnumElements map[string]values.Value // Map from the names of the enum elements the compiler knows about to their values.
GlobalConsts *Environment // The global constants of the module.
Expand All @@ -40,7 +40,7 @@ type Compiler struct {
TypeToCloneGroup map[values.ValueType]AlternateType // A map from any clonable or clone type to an alt type containing the parent type and its clones.
labelResolvingCompilers []*Compiler // We use this to resolve the meaning of labels and enums.
TupleType uint32 // Location of a constant saying {TYPE, <type number of tuples>}, so that 'type (x tuple)' in the builtins has something to return. Query, why not just define 'type (x tuple) : tuple' ?
Common *CommonCompilerBindle // Struct to hold info shared by the compilers.
Common *CommonCompilerBindle // Struct to hold info shared by the compilers.

// Temporary state.
ThunkList []ThunkData // Records what thunks we made so we know what to unthunk at the top of the function.
Expand All @@ -63,7 +63,7 @@ func NewCompiler(p *parser.Parser, ccb *CommonCompilerBindle) *Compiler {
CallHandlerNumbersByName: make(map[string]uint32),
TypeToCloneGroup: make(map[values.ValueType]AlternateType),
TypeNameToTypeScheme: INITIAL_TYPE_SCHEMES,
Common: ccb,
Common: ccb,
}
newC.pushRCompiler(newC)
return newC
Expand All @@ -84,8 +84,8 @@ func NewCommonCompilerBindle() *CommonCompilerBindle {
"any": AltType(values.INT, values.BOOL, values.STRING, values.RUNE, values.TYPE, values.FUNC, values.PAIR, values.LIST, values.MAP, values.SET, values.LABEL),
"any?": AltType(values.NULL, values.INT, values.BOOL, values.STRING, values.RUNE, values.FLOAT, values.TYPE, values.FUNC, values.PAIR, values.LIST, values.MAP, values.SET, values.LABEL),
},
AnyTypeScheme: AlternateType{},
AnyTuple: AlternateType{},
AnyTypeScheme: AlternateType{},
AnyTuple: AlternateType{},
CodeGeneratingTypes: (make(dtypes.Set[values.ValueType])).Add(values.FUNC),
}
for _, name := range parser.AbstractTypesOtherThanSingle {
Expand Down Expand Up @@ -1248,7 +1248,7 @@ func (cp *Compiler) compileForExpression(node *ast.ForExpression, ctxt Context)

if node.BoundVariables == nil {
if ctxt.Access != CMD && ctxt.Access != REPL {
cp.P.Throw("cp/for/bound/a", &node.Token)
cp.P.Throw("comp/for/bound/a", &node.Token)
return altType(values.COMPILE_TIME_ERROR)
}
cp.Reserve(values.UNDEFINED_TYPE, nil, node.GetToken()) // If we don't have any bound variables, then this is presumptively an imperative loop and we'll need somewhere to put OK/break/error still.
Expand All @@ -1257,7 +1257,7 @@ func (cp *Compiler) compileForExpression(node *ast.ForExpression, ctxt Context)
hasBoundVariables = true
// We set up the bound variables. Note that type checking happens *inside* the 'for' loop, not up here.
if node.BoundVariables.GetToken().Type != token.ASSIGN {
cp.P.Throw("cp/for/assign", &node.Token)
cp.P.Throw("comp/for/assign", &node.Token)
return altType(values.COMPILE_TIME_ERROR)
}
lhsOfBoundVariables := node.BoundVariables.(*ast.AssignmentExpression).Left
Expand Down Expand Up @@ -1302,7 +1302,7 @@ func (cp *Compiler) compileForExpression(node *ast.ForExpression, ctxt Context)
// For the initializer we have to do something very un-DRYly like what we just did with the bound variables; TODO ---
// is there any way to DRY it up that doesn't obfuscate the code?
if node.Initializer.GetToken().Type != token.ASSIGN {
cp.P.Throw("cp/for/init/a", &node.Token)
cp.P.Throw("comp/for/init/a", &node.Token)
return altType(values.COMPILE_TIME_ERROR)
}
lhsOfInitVariables := node.Initializer.(*ast.AssignmentExpression).Left
Expand Down Expand Up @@ -1859,7 +1859,6 @@ func (cp *Compiler) getLambdaStart() uint32 {

// A function for making snippet factories.


func (cp *Compiler) reserveSnippetFactory(t string, env *Environment, fnNode *ast.SuffixExpression, ctxt Context) uint32 {
cp.Cm("Reserving snippet factory.", &fnNode.Token)
snF := &vm.SnippetFactory{SnippetType: cp.ConcreteTypeNow(t), SourceString: fnNode.Token.Literal}
Expand Down Expand Up @@ -2771,5 +2770,3 @@ func (cp *Compiler) ReturnErrors() string {
func altType(t ...values.ValueType) AlternateType {
return AltType(t...)
}


2 changes: 1 addition & 1 deletion source/initializer/gohandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (iz *initializer) compileGo() {
for i, pair := range function.NameSig {
if text.Head(pair.VarType, "...") {
if i < function.NameSig.Len()-1 {
iz.Throw("go/variadic", function.Tok)
iz.Throw("golang/variadic", function.Tok)
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions source/vm/descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ func (vm *Vm) toString(v values.Value, flavor descriptionFlavor) string {
return "nil error"
}
ob := v.V.(*err.Error)
if ob.ErrorId != "eval/user" {
ob = err.CreateErr(ob.ErrorId, ob.Token, ob.Args...)
}
ob = err.CreateErr(ob.ErrorId, ob.Token, ob.Args...)
return text.Pretty(text.RT_ERROR+ob.Message+text.DescribePos(ob.Token)+".", 0, 80)
case values.FLOAT:
return strconv.FormatFloat(v.V.(float64), 'f', 8, 64)
Expand Down

0 comments on commit c6bc93f

Please sign in to comment.