Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler #937

Merged
merged 102 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
1679c49
upgrade @rollup to allow node 16 to build
smwhr Jun 29, 2021
4faff1d
bump actions to node 16
smwhr Jun 29, 2021
b3ddb07
add workflow_dispatch
smwhr Jun 29, 2021
31d0f57
compiler imported from furkle/ts-ink
smwhr Jan 28, 2022
61f5e6b
some tests to verify the moving parts
smwhr Feb 1, 2022
84a4de3
entrypoint script
smwhr Feb 1, 2022
c2fc5b5
simple story parsed successfully
smwhr Feb 2, 2022
d824153
fixing a missing callback
smwhr Feb 2, 2022
08c5cdc
remove debugger
smwhr Feb 7, 2022
3ae09cd
fix FindAll and some nulls
smwhr Feb 7, 2022
a3ce047
super function can be call only if defined as methods
smwhr Feb 7, 2022
92ebaf6
remove debugger
smwhr Feb 7, 2022
43236d7
running from top to bottom : wrongly but surely !
smwhr Feb 7, 2022
136c595
add Identifier.ts d213cda4ffa03a447b507e1d395ca3b80ea3b131
smwhr Feb 7, 2022
1e86ce9
migrate to identifiers
smwhr Feb 7, 2022
2ce987c
looking for the extraneous done
smwhr Feb 8, 2022
fcb5a85
restore CheckForNamingCollisions + some nullification
smwhr Feb 8, 2022
b3aeac1
enforce some more nulls
smwhr Feb 8, 2022
7c95ba2
[WIP]
smwhr Feb 8, 2022
20ad53b
compiling helloworld perfectly !
smwhr Feb 8, 2022
67cc8d4
5/135 passing. Choices are not parsed correctly, maths neither
smwhr Feb 8, 2022
c6be050
merge upstream
smwhr Feb 8, 2022
ab7af50
major error in parsedchoice
smwhr Feb 8, 2022
8879e65
replaced all implicit casts to asOrNull
smwhr Feb 9, 2022
b82a175
ToString -> toString
smwhr Feb 9, 2022
373666f
variable assignment ok
smwhr Feb 9, 2022
46ea429
transfixes
smwhr Feb 10, 2022
6852093
rename NumberExpression.ts
smwhr Feb 10, 2022
28f4211
accept bool in NumberExpression
smwhr Feb 10, 2022
c94c612
transfixes on Path
smwhr Feb 10, 2022
21466fb
remove undefined identifiers from name
smwhr Feb 10, 2022
d6549d0
improve number expresion to better deal with floats
smwhr Feb 10, 2022
11dda27
enforce float detection in the bytecode + enforce float write on compile
smwhr Feb 10, 2022
60a09d6
number as bool, comment eliminator fixed
smwhr Feb 10, 2022
24897b2
89 testbeds passing !
smwhr Feb 10, 2022
6303af0
102 passing
smwhr Feb 11, 2022
65d352d
remove debugger
smwhr Feb 11, 2022
2a770c7
only 4 compile error left
smwhr Feb 11, 2022
7380e04
3 more to go
smwhr Feb 11, 2022
28c6c8b
cleanup
smwhr Feb 11, 2022
16dd8aa
remove compiled test bed
smwhr Feb 11, 2022
959be54
134/135
smwhr Feb 11, 2022
27e89d5
house keeping + rollup
smwhr Feb 11, 2022
eb0634e
fix test since inkjs now understands floats
smwhr Feb 11, 2022
f02fe14
Engine -> engine
smwhr Feb 11, 2022
499502c
fix lint
smwhr Feb 11, 2022
c803979
more lint
smwhr Feb 11, 2022
20259bf
down to 5 warnings
smwhr Feb 11, 2022
d04b152
patch from ephread
smwhr Feb 12, 2022
9852ab2
not return bool
smwhr Feb 12, 2022
8f404f9
reduced to single problem
smwhr Feb 12, 2022
52ca47d
Divert is not IWeavePoint, Gather is
smwhr Feb 12, 2022
22a4643
only catch float that are integers
smwhr Feb 12, 2022
16ae252
fix EXTERNAL compiler errors
smwhr Feb 12, 2022
6d33b11
trimEnd wrongly translated
smwhr Feb 12, 2022
30bf116
missed 1 NumberExpression migration
smwhr Feb 12, 2022
d6e37a9
Update src/engine/Object.ts
smwhr Feb 12, 2022
0340a8a
Update src/engine/Container.ts
smwhr Feb 12, 2022
d768552
statements order
smwhr Feb 12, 2022
de1aea2
linter
smwhr Feb 12, 2022
4d1e3c8
the last remaining bug
smwhr Feb 17, 2022
c695136
adding BOM to output of inklecate
smwhr Feb 17, 2022
ac299f3
some null, undefineds and lints
smwhr Feb 17, 2022
448a3ca
lets try that
smwhr Feb 18, 2022
331effd
cleanup exports
smwhr Feb 18, 2022
e9f546a
official error handling
smwhr Feb 18, 2022
6c27516
linting
smwhr Feb 18, 2022
08317d8
Merge pull request #931 from smwhr/compiler
ephread Feb 19, 2022
a336907
refactor: remove ink-proof to simplify PR review
ephread Feb 20, 2022
d8e963e
Merge pull request #938 from ephread/compiler-ink-proof-removal
ephread Feb 20, 2022
500cf6d
feat: port the remaining tests from Test.cs and fix minor issues
ephread Feb 20, 2022
3ec522d
port missing characterInLineIndex in debugMetadata
smwhr Feb 21, 2022
fd5f8c4
Remove float detection
smwhr Feb 21, 2022
255dbfe
restore older test results
smwhr Feb 21, 2022
08ff38f
Merge branch 'remove-float-detection' into compiler
smwhr Feb 21, 2022
85e984a
linting
smwhr Feb 21, 2022
e41cf26
Merge branch 'remove-float-detection' into compiler
smwhr Feb 21, 2022
bcf0868
Give typeName to all classes of the Parsed Hierarchy
smwhr Feb 21, 2022
e2ff19a
Merge pull request #940 from smwhr/port-characterInLineIndex
smwhr Feb 21, 2022
f65ac7d
fix: typos in tests and remove it.only
ephread Feb 21, 2022
7ca7119
Merge branch 'compiler' into compiler-tests
ephread Feb 21, 2022
991f9bd
fix: broken test
ephread Feb 22, 2022
de484d2
Merge pull request #941 from smwhr/remove-float-detection
smwhr Mar 2, 2022
f025ab3
Merge remote-tracking branch 'y-lohse/compiler' into compiler-tests
smwhr Mar 8, 2022
8e93880
allow redefinition of const if equals
smwhr Mar 8, 2022
9bf98b3
Fix : Variables › tests variable naming collision with flow
smwhr Mar 8, 2022
33ad96b
Fix Knot > tests stitch naming collision
smwhr Mar 8, 2022
7bc7cae
Fix Misc > tests return text warning
smwhr Mar 8, 2022
c5c7de2
missing content for : Choices > tests various blank choice warning
smwhr Mar 8, 2022
e537629
fix typo in : Functions > tests argument name collision
smwhr Mar 8, 2022
ca931f9
case + correct message matched
smwhr Mar 8, 2022
9fc4a6a
linter
smwhr Mar 8, 2022
22808d6
fix Optional
smwhr Mar 9, 2022
bd8a6e3
lint
smwhr Mar 9, 2022
cd82c36
fix javascript tests
smwhr Mar 9, 2022
398de79
feat: port the remaining tests from Test.cs and fix minor issues (#939)
ephread Mar 12, 2022
1b47a57
merge upstream
smwhr Mar 13, 2022
7ab0373
docs
smwhr Apr 28, 2022
f25e507
comment on Number
smwhr Apr 28, 2022
2d0605c
more docs
smwhr Apr 28, 2022
8db4e20
Merge pull request #944 from smwhr/compiler-tests
smwhr Apr 28, 2022
b0357f3
merge master in branch compiler
smwhr May 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/engine/
/compiler/
dist/
test/stories/
/tests/specs/
Expand Down
3 changes: 2 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2017 Yannick Lohse
Copyright (c) 2017 Yannick Lohse for the inkjs Player
Copyright (c) 2022 Julien Zamor + Furkle for the inkjs Compiler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,32 @@ var result = EvaluateFunction("my_ink_function", ["arg1", "arg2"], true);
// result.output is the text that was written to the output while the function was evaluated
```

## Compiler

### inklecate.js
```shell
$ node inklecate.js -h

Usage: inklecate <options> <ink file>
-o <filename>: Output file name
-c: Count all visits to knots, stitches and weave points, not
just those referenced by TURNS_SINCE and read counts.
-p: Play mode

```

### online compiler
```javascript
const story = (new inkjs.Compiler(`Hello World`)).Compile()
// story is an inkjs.Story that can be played right away

const jsonBytecode = story.ToJson();
// the generated json can be further re-used
```

### Differences with the C# Compiler
See [Differences with the C# Compiler](docs/compiler-differences.md).

## Compatibility table

| _inklecate_ version | _inkjs_ version |
Expand Down
34 changes: 34 additions & 0 deletions docs/compiler-differences.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Differences with the C# Compiler

## Handling `INCLUDE`s

The C# compiler is intented to always be used on a file system and thus the question of how files are included follow a classic pattern.
Nevertheless, when using the compiler inside a browser, the concept of "file" is a blurry one.
Inkjs provides 2 file handlers :
* A POSIX file handler : similar to the one used in the C# compiler that will look for files in folders
* A JSON file handler : expects a JSON object of the form
```
{
"filename1.ink": "INCLUDE filename2.ink",
"filename2.ink": "This content is included",
}
```

## Float and ints

As the JSON format and javascript in general do not differentiate between float and integers, the inkjs runtime is known to behave differently from the C# runtime when dealing with floating point operations.

The Ink language parser nevertheless enforces this typing and, when played directly from the output of the compiler (as opposed to exporting to JSON and then loading it), the Story object will actually behave like in the C# Runtime.

This may lead to slight differences during play.
This [issue is known](https://github.com/y-lohse/inkjs/issues/934) and will be addressed in subsequent release.

## Named classes/types

As a major difference from the C# compiler, the Parsed Hierarchy classes are not publicly exposed and their name may be obscured when using the minified version of inkjs-full.
You'll have to rely on their `.typeName` property.

Some typename are specific to this library :
* Constant declaration : `CONST` instead of `Constant`
* List declaration : `LIST` instead of `VAR`
* List definition (container) : `ListDefinition` instead of `List definition`
4 changes: 4 additions & 0 deletions ink.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Story, InkList } from './engine/Story'
import { Compiler } from './compiler/Compiler'
import { CompilerOptions } from './compiler/CompilerOptions'

declare interface Inkjs {
Story: typeof Story
InkList: typeof InkList
Compiler: typeof Compiler
CompilerOptions: typeof CompilerOptions
}

declare let inkjs: Inkjs
Expand Down
5 changes: 4 additions & 1 deletion jest.config.javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ module.exports = {
],
testPathIgnorePatterns: [
"<rootDir>/src/"
]
],
setupFilesAfterEnv: [
"<rootDir>/tests/specs/setupTests.js"
],
};
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ module.exports = {
transform: {
"^.+\\.ts$": "ts-jest"
},
setupFilesAfterEnv: [
"<rootDir>/src/tests/specs/setupTests.ts"
],
};
Loading