Skip to content

Commit

Permalink
Merge pull request #69 from dekarrin/ghi016-selfhosting
Browse files Browse the repository at this point in the history
Ghi016 selfhosting
  • Loading branch information
dekarrin committed Apr 15, 2023
2 parents 45f6bba + f56ecb6 commit 9516b06
Show file tree
Hide file tree
Showing 23 changed files with 1,552 additions and 578 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# vim
*.swp

/testout
/.testout
/ictcc
/.sim
/.gen
/diag
/fishic

# mac
.DS_Store
Expand Down
625 changes: 356 additions & 269 deletions cmd/ictcc/main.go

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions cmd/ictcc/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package main

import (
"fmt"
"os"

"github.com/dekarrin/ictiobus/types"
)

const (
// ExitSuccess is the exit code for a successful run.
ExitSuccess = iota

// ExitErrNoFiles is the code returned as exit status when no files are
// provided to the invocation.
ExitErrNoFiles

// ExitErrInvalidFlags is used if the combination of flags specified is
// invalid.
ExitErrInvalidFlags

// ExitErrSyntax is the code returned as exit status when a syntax error
// occurs.
ExitErrSyntax

// ExitErrParser is the code returned as exit status when there is an error
// generating the parser.
ExitErrParser

// ExitErrGeneration is the code returned as exit status when there is an
// error creating the generated files.
ExitErrGeneration

// ExitErrOther is a generic error code for any other error.
ExitErrOther
)

var (
exitStatus = ExitSuccess
)

// errNoFiles sets the exit status to ExitErrNoFiles and prints the given error
// message to stderr by calling exitErr.
//
// Caller is responsible for exiting main immediately after this function
// returns.
func errNoFiles(msg string) {
exitErr(ExitErrNoFiles, msg)
}

// errInvalidFlags sets the exit status to ExitErrInvalidFlags and prints the
// given error message to stderr by calling exitErr.
//
// Caller is responsible for exiting main immediately after this function
// returns.
func errInvalidFlags(msg string) {
exitErr(ExitErrInvalidFlags, msg)
}

// errSyntax sets the exit status to ExitErrSyntax and prints an error message
// given by the syntax error to stderr.
//
// Caller is responsible for exiting main immediately after this function
// returns.
func errSyntax(filename string, synErr *types.SyntaxError) {
if filename == "" {
filename = "<INPUT>"
}
fmt.Fprintf(os.Stderr, "%s\n", synErr.MessageForFile(filename))
exitStatus = ExitErrSyntax
}

// errParser sets the exit status to ExitErrParser and prints the given error
// message to stderr by calling exitErr.
//
// Caller is responsible for exiting main immediately after this function
// returns.
func errParser(msg string) {
exitErr(ExitErrParser, msg)
}

// errGeneration sets the exit status to ExitErrGeneration and prints the given
// error message to stderr by calling exitErr.
//
// Caller is responsible for exiting main immediately after this function
// returns.
func errGeneration(msg string) {
exitErr(ExitErrGeneration, msg)
}

// errOther sets the exit status to ExitErrOther and prints the given error
// message to stderr by calling exitErr.
//
// Caller is responsible for exiting main immediately after this function
// returns.
func errOther(msg string) {
exitErr(ExitErrOther, msg)
}

// exitErr sets the exit status and prints "ERROR: " followed by the given
// error message to stderr. Automatically ends printed message with a newline.
//
// Caller is responsible for exiting main immediately after this function
// returns.
func exitErr(statusCode int, msg string) {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", msg)
exitStatus = statusCode
}

// basic function to check if panic is happening and recover it while also
// preserving possibly-set exit code. Immediately call this as defered as first
// statement in main.
func preservePanicOrExitWithStatus() {
if panicErr := recover(); panicErr != nil {
// we are panicking, make sure we dont lose the panic just because
// we checked
panic("unrecoverable panic occured")
} else {
os.Exit(exitStatus)
}
}
2 changes: 1 addition & 1 deletion cmd/ictcc/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

const (
Version = "0.6.0"
Version = "0.6.1"
)

func GetVersionString() string {
Expand Down
7 changes: 7 additions & 0 deletions defexample.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Example Language
################

*NOTE: this document is being kept for historical purproses, and some content
may be correct, but it was the first attempt to standardize the fishi language
and is heavily out of date. Refer to fishi.md instead of this file for an
example; the correct parts of this file will eventually be worked into the manual
for FISHI.*

This is a complete example of a language specified in the special ictiobus
format. It is a markdown based format that uses specially named sections to
allow both specificiation of a language and freeform text to co-exist.
Expand Down
4 changes: 2 additions & 2 deletions fishi.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ For tokens state:
%!%[Tt][Oo][Kk][Ee][Nn] %token dir-token
%human %!%token directive
%!%![Dd][Ii][Ss][Cc][Aa][Rr][Dd] %token dir-discard
%!%[Dd][Ii][Ss][Cc][Aa][Rr][Dd] %token dir-discard
%human %!%discard directive
%!%[Pp][Rr][Ii][Oo][Rr][Ii][Tt][Yy] %token dir-priority
Expand Down Expand Up @@ -279,7 +279,7 @@ For actions state:
\s+ %discard
(?:{(?:&|\.)(?:[0-9]+)?}|{[0-9]+}|{\^}|{[A-Za-z][^{}]*}|[\s{}]+)\.[\$A-Za-z][\$A-Za-z0-9_]*
(?:{(?:&|\.)(?:[0-9]+)?}|{[0-9]+}|{\^}|{[A-Za-z][^{}]*}|[^\s{}]+)\.[\$A-Za-z][\$A-Za-z0-9_]*
%token attr-ref %human attribute reference literal
[0-9]+
Expand Down
52 changes: 52 additions & 0 deletions fishi/cgstructs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package fishi

import "github.com/dekarrin/ictiobus"

// File cgstructs.go contains structs used as part of code generation.

// TODO: move most structs from codegen to here.

// MainBinaryParams is paramters for generating a main.go file for a binary.
// Unless otherwise specified, all fields are required.
type MainBinaryParams struct {
// Parser is the parser to use for the generated compiler.
Parser ictiobus.Parser

// HooksPkgDir is the path to the directory containing the hooks package.
HooksPkgDir string

// HooksExpr is the expression to use to get the hooks map. This can be a
// function call, constant name, or var name.
HooksExpr string

// FormatPkgDir is the path to the directory containing the format package.
// It is completely optional; if not set, the generated main will not
// contain any pre-formatting code and will assume files are directly ready
// to be fed into the frontend. Must be set if FormatCall is set.
FormatPkgDir string

// FormatCall is the name of a function within the package specified by
// FormatPkgDir that gets an io.Reader that will run any required
// pre-formatting on an input io.Reader to get code that can be analyzed by
// the frontend. Is is optional; if not set, the generated main will not
// contain any pre-formatting code and will assume files are directly ready
// to be fed into the frontend. Must be set if FormatPkgDir is set.
FormatCall string

// FrontendPkgName is the name of the package to place generated frontend
// code in.
FrontendPkgName string

// GenPath is the path to a directory to generate code in. If it does not
// exist, it will be created. If it does exist, any existing files in it
// will be removed will be emptied before code is generated.
GenPath string

// BinName is the name of the binary being generated. This will be used
// within code for showing help output and other messages.
BinName string

// Opts are options for code generation. This must be set and its IRType
// field is required to be set, but all other fields within it are optional.
Opts CodegenOptions
}

0 comments on commit 9516b06

Please sign in to comment.