Git Product home page Git Product logo

fault's Issues

Tighten Up AST with Operand Type

Recently introduced an Operand Type which encompasses both Identifiers and Struct Properties (ParameterCall). This opens up the opportunity to tighten up the AST, which currently allows any Expression node to be inserted into places where clearly only operands would work.

An example:

type ParallelFunctions struct {
	Token        Token
	InferredType *Type
	Expressions  []Expression
}

Areas affected:
ParallelFunctions - Fault specs have run blocks where the logic of what happens in a single loop of the model is defined. Multiple functions can execute in parallel.
IndexExpression - Not yet fully implemented but allows historic values to be accessed in the model. Typically looks like foo[3]
StockLiteral - Pairs are defined as map[Expression]Expression but keys can't be anything other than Identifiers
FlowLiteral - See above
ComponentLiteral - See above

Known bug with indexes and phi values

Need to come back to this later but there's a known bug in indexes when they are using inside any kind of branching logic like so:

increment: func{
        if num.value == 0 {
              num.value = 1;
       else{
              num.value <- num.value[now-1];
       },

index references a variable in the true branch that shouldn't be accessible to the false branch.

Trouble getting it running on Windows

Windows doesn't have make natively. I installed it this way:

New-Item -Type File "fault.Dockerfile"
docker build -t fault-lang/fault-z3 --no-cache -f fault.Dockerfile .

It'll probably crash and burn the moment I try to update to a newer build but that's a future Hillel problem.

At this point I realized I also didn't have bash and couldn't run fault-lang.sh. I tried to copy the docker run to

docker run -v (resolve-path .) fault-lang/fault-z3 -f=(resolve-path .\example.fspec)

But this gave me "must provide path of file to compile".

Remove the homebrew specific path to Antlr java

In order to successfully compile Fault grammar in Java (necessarily for using the antlr gui) make includes the following line:

javac -classpath /usr/local/Cellar/antlr/4.9.3/antlr-4.9.3-complete.jar *.java

docs: initial example not immediately runnable (?)

  • Copy the sandwich model from the home page http://fault.tech/ to sandwich.fsystem.
  • Install Fault using make fault-z3.
  • Run fault -f=sandwich.fsystem.
  • Get Go error shown below.
panic:  [recovered]
	panic: Invalid spec syntax spec on line 1 col 0 in spec sandwich.fsystem [recovered]
	panic: Invalid spec syntax spec on line 1 col 0 in spec sandwich.fsystem
  • Change first line of example file from spec sandwich to system sandwich.
  • Example runs as expected.

I expected the first example to run as-is with a minimal set of command-line options.

Rename "Parameter Call" to something that makes sense

File this under: I don't know why I did this 🤣

Structs (Stocks, Flows, and Components) are basically like objects:

def foo = flow{
		buzz: new bar,
		fizz: func{
			if buzz.a > 2{
				buzz.a -> b;
			}else{
				buzz.a = 10;
			}
			buzz.b -> 1;
		},
	};

def bar = stock{
			a: 10,
			b: 20,
		};

Each has a set of features that are kind of like properties or methods. These features can be accessed via the following construction buzz.a in the parser this construction is called a ParameterCall ... which is a stupid name that doesn't really communicate what it is. These features ARE treated as parameters when represented in LLVM IR, but it's still a pretty confusing name.

A Fault spec works is by connecting Stocks and Flows together to represent resource use in a system (see Thinking In Systems for more about this style of modeling) Struct properties can be static values, instances of connecting structs, or functions. When referenced with the construction [structName].[property] if the feature is a function, Fault will execute the function.

Assuming we can come up with a more sensible name this is basically a find and replace job after that, with the guiding hand of unit tests to help 🤣

Grammar railroad diagram

Using some online tools like https://www.bottlecaps.de/rr/ui and https://www.bottlecaps.de/convert/ we can have a nice navigable railroad diagram.

Copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui on the tab Edit Grammar the click on the tab View Diagram to see/download a navigable railroad diagram.

/* converted on Thu Mar 9, 2023, 07:28 (UTC+01) by antlr_4-to-w3c v0.62 which is Copyright (c) 2011-2022 by Gunther Rademacher <[email protected]> */

sysSpec  ::= sysClause importDecl* globalDecl* componentDecl* ( assertion | assumption )? startBlock? forStmt?
sysClause
         ::= 'system' IDENT ';'
globalDecl
         ::= 'global' IDENT '=' operand ';'
componentDecl
         ::= 'component' IDENT '=' 'states' '{' ( comProperties ',' )* '}' ';'
startBlock
         ::= 'start' '{' ( startPair ',' )* '}' ';'
startPair
         ::= IDENT ':' IDENT
spec     ::= specClause declaration* forStmt?
specClause
         ::= 'spec' IDENT ';'
importDecl
         ::= 'import' ( importSpec | '(' importSpec* ')' ) ';'
importSpec
         ::= ( '.' | IDENT )? importPath ','?
importPath
         ::= string_
declaration
         ::= constDecl
           | structDecl
           | assertion
           | assumption
comparison
         ::= '=='
           | '!='
           | '<'
           | '<='
           | '>'
           | '>='
constDecl
         ::= 'const' ( constSpec | '(' constSpec* ')' ) ';'
constSpec
         ::= identList ( '=' constants )?
identList
         ::= operandName ( ',' operandName )*
constants
         ::= numeric
           | string_
           | bool_
           | solvable
           | 'nil'
expressionList
         ::= expression ( ',' expression )*
structDecl
         ::= 'def' IDENT '=' structType ';'
structType
         ::= ( 'flow' | 'stock' ) '{' ( sfProperties ',' )* '}'
sfProperties
         ::= IDENT ':' functionLit
           | structProperties
comProperties
         ::= IDENT ':' stateLit
           | structProperties
structProperties
         ::= IDENT ( ':' ( numeric | string_ | bool_ | operandName | prefix | solvable ) )?
initDecl ::= 'init' operand ';'
block    ::= '{' statementList? '}'
statementList
         ::= statement+
statement
         ::= constDecl
           | initDecl
           | simpleStmt ';'
           | ( 'if' ( simpleStmt ';' )? expression ( block 'else' 'if' ( simpleStmt ';' )? expression )* ( block 'else' )? )? block
simpleStmt
         ::= expression
           | incDecStmt
           | assignment
           | ';'
incDecStmt
         ::= expression ( '++' | '--' )
stateChange
         ::= ( 'advance' '(' paramCall | 'stay' '(' ) ')'
           | stateChange ( '&&' | '||' ) stateChange
accessHistory
         ::= operandName ( '[' expression ']' )+
assertion
         ::= 'assert' invariant temporal? ';'
assumption
         ::= 'assume' invariant temporal? ';'
temporal ::= 'eventually'
           | 'always'
           | 'eventually-always'
           | ( 'nmt' | 'nft' ) integer
invariant
         ::= ( 'when' expression 'then' )? expression
assignment
         ::= expressionList ( ( '+' | '-' | '^' | '*' | '/' | '%' | '<<' | '>>' | '&' | '&^' )? '=' | '->' | '<-' ) expressionList
forStmt  ::= 'for' rounds 'run' runBlock ';'?
rounds   ::= integer
paramCall
         ::= ( IDENT | 'this' ) ( '.' IDENT )+
stateBlock
         ::= '{' stateStep* '}'
stateStep
         ::= ( paramCall ( '|' paramCall )* | stateChange ) ';'
           | 'if' ( simpleStmt ';' )? expression stateBlock ( 'else' 'if' ( simpleStmt ';' )? expression stateBlock )* ( 'else' stateBlock )?
runBlock ::= '{' runStep* '}'
runStep  ::= ( paramCall ( '|' paramCall )* | IDENT '=' 'new' ( paramCall | IDENT ) | simpleStmt ) ';'
           | 'if' ( simpleStmt ';' )? expression runBlock ( 'else' 'if' ( simpleStmt ';' )? expression runBlock )* ( 'else' runBlock )?
faultType
         ::= 'string'
           | 'bool'
           | 'int'
           | 'float'
           | 'natural'
           | 'uncertain'
           | 'unknown'
solvable ::= faultType '(' operand? ( ',' operand )* ')'
expression
         ::= operand
           | solvable
           | prefix
           | expression ( '**' | '*' | '/' | '%' | '<<' | '>>' | '&' | '&^' | '+' | '-' | '^' | '==' | '!=' | '<' | '<=' | '>' | '>=' | '&&' | '||' ) expression
operand  ::= 'nil'
           | numeric
           | string_
           | bool_
           | operandName
           | accessHistory
           | '(' expression ')'
operandName
         ::= ( 'new' ( IDENT '.' )? )? IDENT
           | paramCall
           | 'this'
           | 'now'
prefix   ::= ( ( '+' | '-' | '!' | '^' | '*' | '&' ) expression )?
numeric  ::= integer
           | negative
           | float_
integer  ::= DECIMAL_LIT
           | OCTAL_LIT
           | HEX_LIT
negative ::= '-' ( integer | float_ )
float_   ::= FLOAT_LIT
string_  ::= RAW_STRING_LIT
           | INTERPRETED_STRING_LIT
bool_    ::= 'true'
           | 'false'
functionLit
         ::= 'func' block
stateLit ::= 'func' stateBlock
_        ::= WS
           | COMMENT
           | TERMINATOR
           | LINE_COMMENT
          /* ws: definition */

<?TOKENS?>

IDENT    ::= LETTER ( LETTER | UNICODE_DIGIT )*
DECIMAL_LIT
         ::= [1-9] [0-9]*
OCTAL_LIT
         ::= '0' OCTAL_DIGIT*
HEX_LIT  ::= '0' [xX] HEX_DIGIT+
FLOAT_LIT
         ::= DECIMALS ( '.' DECIMALS? EXPONENT? | EXPONENT )
           | '.' DECIMALS EXPONENT?
RAW_STRING_LIT
         ::= '`' [^`]* '`'
INTERPRETED_STRING_LIT
         ::= '"' ( [^"\] | ESCAPED_VALUE )* '"'
WS       ::= [ #x9]+
COMMENT? ::= '/*' .* '*/'
TERMINATOR
         ::= [#xd#xa]+
LINE_COMMENT
         ::= '//' [^#xd#xa]*
ESCAPED_VALUE
         ::= '\' ( ( ( 'u' | 'U' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT ) HEX_DIGIT HEX_DIGIT | 'x' ) HEX_DIGIT HEX_DIGIT | [abfnrtv\'"] | OCTAL_DIGIT OCTAL_DIGIT OCTAL_DIGIT )
DECIMALS ::= [0-9]+
OCTAL_DIGIT
         ::= [0-7]
HEX_DIGIT
         ::= [0-9a-fA-F]
EXPONENT ::= [eE] [+#x2D]? DECIMALS
LETTER   ::= UNICODE_LETTER
           | '_'
UNICODE_DIGIT
         ::= [#x0030-#x0039#x0660-#x0669#x06F0-#x06F9#x0966-#x096F#x09E6-#x09EF#x0A66-#x0A6F#x0AE6-#x0AEF#x0B66-#x0B6F#x0BE7-#x0BEF#x0C66-#x0C6F#x0CE6-#x0CEF#x0D66-#x0D6F#x0E50-#x0E59#x0ED0-#x0ED9#x0F20-#x0F29#x1040-#x1049#x1369-#x1371#x17E0-#x17E9#x1810-#x1819#xFF10-#xFF19]
UNICODE_LETTER
         ::= [#x0041-#x005A#x0061-#x007A#x00AA#x00B5#x00BA#x00C0-#x00D6#x00D8-#x00F6#x00F8-#x021F#x0222-#x0233#x0250-#x02AD#x02B0-#x02B8#x02BB-#x02C1#x02D0-#x02D1#x02E0-#x02E4#x02EE#x037A#x0386#x0388-#x038A#x038C#x038E-#x03A1#x03A3-#x03CE#x03D0-#x03D7#x03DA-#x03F3#x0400-#x0481#x048C-#x04C4#x04C7-#x04C8#x04CB-#x04CC#x04D0-#x04F5#x04F8-#x04F9#x0531-#x0556#x0559#x0561-#x0587#x05D0-#x05EA#x05F0-#x05F2#x0621-#x063A#x0640-#x064A#x0671-#x06D3#x06D5#x06E5-#x06E6#x06FA-#x06FC#x0710#x0712-#x072C#x0780-#x07A5#x0905-#x0939#x093D#x0950#x0958-#x0961#x0985-#x098C#x098F-#x0990#x0993-#x09A8#x09AA-#x09B0#x09B2#x09B6-#x09B9#x09DC-#x09DD#x09DF-#x09E1#x09F0-#x09F1#x0A05-#x0A0A#x0A0F-#x0A10#x0A13-#x0A28#x0A2A-#x0A30#x0A32-#x0A33#x0A35-#x0A36#x0A38-#x0A39#x0A59-#x0A5C#x0A5E#x0A72-#x0A74#x0A85-#x0A8B#x0A8D#x0A8F-#x0A91#x0A93-#x0AA8#x0AAA-#x0AB0#x0AB2-#x0AB3#x0AB5-#x0AB9#x0ABD#x0AD0#x0AE0#x0B05-#x0B0C#x0B0F-#x0B10#x0B13-#x0B28#x0B2A-#x0B30#x0B32-#x0B33#x0B36-#x0B39#x0B3D#x0B5C-#x0B5D#x0B5F-#x0B61#x0B85-#x0B8A#x0B8E-#x0B90#x0B92-#x0B95#x0B99-#x0B9A#x0B9C#x0B9E-#x0B9F#x0BA3-#x0BA4#x0BA8-#x0BAA#x0BAE-#x0BB5#x0BB7-#x0BB9#x0C05-#x0C0C#x0C0E-#x0C10#x0C12-#x0C28#x0C2A-#x0C33#x0C35-#x0C39#x0C60-#x0C61#x0C85-#x0C8C#x0C8E-#x0C90#x0C92-#x0CA8#x0CAA-#x0CB3#x0CB5-#x0CB9#x0CDE#x0CE0-#x0CE1#x0D05-#x0D0C#x0D0E-#x0D10#x0D12-#x0D28#x0D2A-#x0D39#x0D60-#x0D61#x0D85-#x0D96#x0D9A-#x0DB1#x0DB3-#x0DBB#x0DBD#x0DC0-#x0DC6#x0E01-#x0E30#x0E32-#x0E33#x0E40-#x0E46#x0E81-#x0E82#x0E84#x0E87-#x0E88#x0E8A#x0E8D#x0E94-#x0E97#x0E99-#x0E9F#x0EA1-#x0EA3#x0EA5#x0EA7#x0EAA-#x0EAB#x0EAD-#x0EB0#x0EB2-#x0EB3#x0EBD-#x0EC4#x0EC6#x0EDC-#x0EDD#x0F00#x0F40-#x0F6A#x0F88-#x0F8B#x1000-#x1021#x1023-#x1027#x1029-#x102A#x1050-#x1055#x10A0-#x10C5#x10D0-#x10F6#x1100-#x1159#x115F-#x11A2#x11A8-#x11F9#x1200-#x1206#x1208-#x1246#x1248#x124A-#x124D#x1250-#x1256#x1258#x125A-#x125D#x1260-#x1286#x1288#x128A-#x128D#x1290-#x12AE#x12B0#x12B2-#x12B5#x12B8-#x12BE#x12C0#x12C2-#x12C5#x12C8-#x12CE#x12D0-#x12D6#x12D8-#x12EE#x12F0-#x130E#x1310#x1312-#x1315#x1318-#x131E#x1320-#x1346#x1348-#x135A#x13A0-#x13B0#x13B1-#x13F4#x1401-#x1676#x1681-#x169A#x16A0-#x16EA#x1780-#x17B3#x1820-#x1877#x1880-#x18A8#x1E00-#x1E9B#x1EA0-#x1EE0#x1EE1-#x1EF9#x1F00-#x1F15#x1F18-#x1F1D#x1F20-#x1F39#x1F3A-#x1F45#x1F48-#x1F4D#x1F50-#x1F57#x1F59#x1F5B#x1F5D#x1F5F-#x1F7D#x1F80-#x1FB4#x1FB6-#x1FBC#x1FBE#x1FC2-#x1FC4#x1FC6-#x1FCC#x1FD0-#x1FD3#x1FD6-#x1FDB#x1FE0-#x1FEC#x1FF2-#x1FF4#x1FF6-#x1FFC#x207F#x2102#x2107#x210A-#x2113#x2115#x2119-#x211D#x2124#x2126#x2128#x212A-#x212D#x212F-#x2131#x2133-#x2139#x2160-#x2183#x3005-#x3007#x3021-#x3029#x3031-#x3035#x3038-#x303A#x3041-#x3094#x309D-#x309E#x30A1-#x30FA#x30FC-#x30FE#x3105-#x312C#x3131-#x318E#x31A0-#x31B7#x3400#x4DB5#x4E00#x9FA5#xA000-#xA48C#xAC00#xD7A3#xF900-#xFA2D#xFB00-#xFB06#xFB13-#xFB17#xFB1D#xFB1F-#xFB28#xFB2A-#xFB36#xFB38-#xFB3C#xFB3E#xFB40-#xFB41#xFB43-#xFB44#xFB46-#xFBB1#xFBD3-#xFD3D#xFD50-#xFD8F#xFD92-#xFDC7#xFDF0-#xFDFB#xFE70-#xFE72#xFE74#xFE76-#xFEFC#xFF21-#xFF3A#xFF41-#xFF5A#xFF66-#xFFBE#xFFC2-#xFFC7#xFFCA-#xFFCF#xFFD2-#xFFD7#xFFDA-#xFFDC]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.