├── .gitattributes ├── .github └── workflows │ └── dotnet.yml ├── .gitignore ├── AUTHORS ├── LICENSE ├── README.md └── src ├── README.md ├── Tutorial └── Tutorials │ ├── App.config │ ├── Chapters │ ├── Chapter1.cs │ ├── Chapter10.cs │ ├── Chapter11.cs │ ├── Chapter12.cs │ ├── Chapter2.cs │ ├── Chapter3.cs │ ├── Chapter4.cs │ ├── Chapter5.cs │ ├── Chapter6.cs │ ├── Chapter7.cs │ ├── Chapter8.cs │ ├── Chapter9.cs │ └── X1.cs │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Scripts │ └── Test.lua │ ├── TutorialAttribute.cs │ ├── Tutorials.csproj │ └── readme.md ├── WattleScript.Hardwire ├── Generators │ ├── ArrayMemberDescriptorGenerator.cs │ ├── Base │ │ └── AssignableMemberDescriptorGeneratorBase.cs │ ├── DynValueMemberDescriptorGenerator.cs │ ├── FieldMemberDescriptorGenerator.cs │ ├── MethodMemberDescriptorGenerator.cs │ ├── NullGenerator.cs │ ├── OverloadedMethodMemberDescriptorGenerator.cs │ ├── PropertyMemberDescriptorGenerator.cs │ ├── StandardUserDataDescriptorGenerator.cs │ └── ValueTypeDefaultCtorMemberDescriptorGenerator.cs ├── HardwireCodeGenerationContext.cs ├── HardwireGenerator.cs ├── HardwireGeneratorRegistry.cs ├── ICodeGenerationLogger.cs ├── IHardwireGenerator.cs ├── IdGen.cs ├── Languages │ ├── CSharpHardwireCodeGenerationLanguage.cs │ ├── HardwireCodeGenerationLanguage.cs │ └── VbHardwireCodeGenerationLanguage.cs ├── Utils │ ├── GeneratorUtilities.cs │ └── HardwireParameterDescriptor.cs └── WattleScript.Hardwire.csproj ├── WattleScript.HardwireGen.Test ├── ExtraHardwire.xml ├── GenericExtra.cs ├── MyWattleData.cs ├── SanityTest.cs ├── WattleScript.HardwireGen.Test.csproj └── WithProperty.cs ├── WattleScript.HardwireGen ├── ClassNames.cs ├── ExtraClassListXml.cs ├── HardwireInterop.cs ├── HardwireModel.cs ├── HardwireSourceGenerator.cs ├── IdGen.cs ├── Properties │ └── launchSettings.json ├── StringUtils.cs ├── SymbolUtils.cs ├── Utilities │ ├── EquatableArray.cs │ ├── Polyfill.cs │ └── TabbedWriter.cs └── WattleScript.HardwireGen.csproj ├── WattleScript.Interpreter.Tests ├── EndToEnd │ ├── AsyncTests.cs │ ├── BinaryDumpTests.cs │ ├── CLike │ │ ├── SyntaxCLike │ │ │ ├── Access │ │ │ │ ├── 01-private-field.lua │ │ │ │ ├── 01-private-field.txt │ │ │ │ ├── 02-private-nowrite-invalid.lua │ │ │ │ ├── 03-private-thisaccess.lua │ │ │ │ ├── 03-private-thisaccess.txt │ │ │ │ ├── 04-private-base.lua │ │ │ │ ├── 04-private-base.txt │ │ │ │ ├── 05-private-mixin.lua │ │ │ │ ├── 05-private-mixin.txt │ │ │ │ ├── 06-privatestatic-invalid.lua │ │ │ │ ├── 07-public.lua │ │ │ │ ├── 07-public.txt │ │ │ │ └── 08-conflicting-access-invalid.lua │ │ │ ├── Aliases │ │ │ │ ├── 1-null.lua │ │ │ │ ├── 1-null.txt │ │ │ │ ├── 2-this.lua │ │ │ │ └── 2-this.txt │ │ │ ├── Annotations │ │ │ │ ├── 1-annotation.lua │ │ │ │ ├── 1-annotation.txt │ │ │ │ ├── 2-annotation.lua │ │ │ │ ├── 2-annotation.txt │ │ │ │ ├── 3-annotation.lua │ │ │ │ ├── 3-annotation.txt │ │ │ │ ├── 4-annotation.lua │ │ │ │ ├── 4-annotation.txt │ │ │ │ ├── 5-annotation.lua │ │ │ │ └── 5-annotation.txt │ │ │ ├── Classes │ │ │ │ ├── 0-new.lua │ │ │ │ ├── 0-new.txt │ │ │ │ ├── 1-classloop.lua │ │ │ │ ├── 1-classloop.txt │ │ │ │ ├── 10-static-field-ref.lua │ │ │ │ ├── 10-static-field-ref.txt │ │ │ │ ├── 11-duplicate-function-invalid.lua │ │ │ │ ├── 11-duplicate-function-invalid.txt │ │ │ │ ├── 12-duplicate-field-invalid.lua │ │ │ │ ├── 12-duplicate-field-invalid.txt │ │ │ │ ├── 13-reserved-field-invalid.lua │ │ │ │ ├── 13-reserved-field-invalid.txt │ │ │ │ ├── 14-static-math.lua │ │ │ │ ├── 14-static-math.txt │ │ │ │ ├── 15-static-class-empty.lua │ │ │ │ ├── 15-static-class-empty.txt │ │ │ │ ├── 16-static-class-empty-invalid.lua │ │ │ │ ├── 17-static-class-non-static-field-invalid.lua │ │ │ │ ├── 18-static-class-non-static-function-invalid.lua │ │ │ │ ├── 19-static-class-non-static-function-arrow-invalid.lua │ │ │ │ ├── 2-mixin.lua │ │ │ │ ├── 2-mixin.txt │ │ │ │ ├── 20-static-class-ctor-invalid.lua │ │ │ │ ├── 21-static-class-ctor-static-invalid.lua │ │ │ │ ├── 22-class-lhs-new.lua │ │ │ │ ├── 22-class-lhs-new.txt │ │ │ │ ├── 23-static-class-instantiate-invalid.lua │ │ │ │ ├── 24-static-class-base-invalid.lua │ │ │ │ ├── 25-static-class-static-field-function-ref.lua │ │ │ │ ├── 25-static-class-static-field-function-ref.txt │ │ │ │ ├── 26-class-field-thiscall.lua │ │ │ │ ├── 26-class-field-thiscall.txt │ │ │ │ ├── 27-class-field-thiscall-function.lua │ │ │ │ ├── 27-class-field-thiscall-function.txt │ │ │ │ ├── 28-class-sealed-invalid.lua │ │ │ │ ├── 29-class-sealed.lua │ │ │ │ ├── 29-class-sealed.txt │ │ │ │ ├── 3-basecall.lua │ │ │ │ ├── 3-basecall.txt │ │ │ │ ├── 4-baseconstruct.lua │ │ │ │ ├── 4-baseconstruct.txt │ │ │ │ ├── 5-baseconstruct-default.lua │ │ │ │ ├── 5-baseconstruct-default.txt │ │ │ │ ├── 6-baseclass-invalid.lua │ │ │ │ ├── 6-baseclass-invalid.txt │ │ │ │ ├── 7-static.lua │ │ │ │ ├── 7-static.txt │ │ │ │ ├── 8-static-local-ref.lua │ │ │ │ ├── 8-static-local-ref.txt │ │ │ │ ├── 9-static-field.lua │ │ │ │ └── 9-static-field.txt │ │ │ ├── Enums │ │ │ │ ├── 0-enum.lua │ │ │ │ ├── 0-enum.txt │ │ │ │ ├── 1-selfref.lua │ │ │ │ ├── 1-selfref.txt │ │ │ │ ├── 2-annotsyntax.lua │ │ │ │ └── 2-annotsyntax.txt │ │ │ ├── Errors │ │ │ │ ├── 1-common-invalid.lua │ │ │ │ ├── 1-common-invalid.txt │ │ │ │ ├── 2-resync-invalid.lua │ │ │ │ └── 2-resync-invalid.txt │ │ │ ├── Functions │ │ │ │ ├── 1-call.lua │ │ │ │ ├── 1-call.txt │ │ │ │ ├── 10-call-default-scope-local-3.lua │ │ │ │ ├── 10-call-default-scope-local-3.txt │ │ │ │ ├── 11-call-default-scope-arrow.lua │ │ │ │ ├── 11-call-default-scope-arrow.txt │ │ │ │ ├── 12-call-default-scope-arrow-invalid.lua │ │ │ │ ├── 12-call-default-scope-arrow-invalid.txt │ │ │ │ ├── 13-call-default-scope-arrow-arrow.lua │ │ │ │ ├── 13-call-default-scope-arrow-arrow.txt │ │ │ │ ├── 14-call-default-scope-arrow-arrow-default.lua │ │ │ │ ├── 14-call-default-scope-arrow-arrow-default.txt │ │ │ │ ├── 15-call-default-scope-arrow-arrow-default-2.lua │ │ │ │ ├── 15-call-default-scope-arrow-arrow-default-2.txt │ │ │ │ ├── 16-default-call-closure.lua │ │ │ │ ├── 16-default-call-closure.txt │ │ │ │ ├── 17-call-hoisted.lua │ │ │ │ ├── 17-call-hoisted.txt │ │ │ │ ├── 18-assign-lambda.lua │ │ │ │ ├── 18-assign-lambda.txt │ │ │ │ ├── 2-call-default.lua │ │ │ │ ├── 2-call-default.txt │ │ │ │ ├── 3-call-default-invalid.lua │ │ │ │ ├── 3-call-default-invalid.txt │ │ │ │ ├── 4-call-default-2.lua │ │ │ │ ├── 4-call-default-2.txt │ │ │ │ ├── 5-call-default-3.lua │ │ │ │ ├── 5-call-default-3.txt │ │ │ │ ├── 6-call-default-local.lua │ │ │ │ ├── 6-call-default-local.txt │ │ │ │ ├── 7-call-default-scope.lua │ │ │ │ ├── 7-call-default-scope.txt │ │ │ │ ├── 8-call-default-scope-local.lua │ │ │ │ ├── 8-call-default-scope-local.txt │ │ │ │ ├── 9-call-default-scope-local-2.lua │ │ │ │ └── 9-call-default-scope-local-2.txt │ │ │ ├── Meta │ │ │ │ ├── 0-string.lua │ │ │ │ ├── 0-string.txt │ │ │ │ ├── 1-number.lua │ │ │ │ ├── 1-number.txt │ │ │ │ ├── 2-boolean.lua │ │ │ │ ├── 2-boolean.txt │ │ │ │ ├── 3-table.lua │ │ │ │ ├── 3-table.txt │ │ │ │ ├── 4-range.lua │ │ │ │ └── 4-range.txt │ │ │ ├── Operators │ │ │ │ ├── 0-null-coalescing-assignment-min.lua │ │ │ │ ├── 0-null-coalescing-assignment-min.txt │ │ │ │ ├── 1-null-coalescing-assignment-check.lua │ │ │ │ ├── 1-null-coalescing-assignment-check.txt │ │ │ │ ├── 10-relax-ternary-chain-2.lua │ │ │ │ ├── 10-relax-ternary-chain-2.txt │ │ │ │ ├── 11-nill-coalescing-inverse.lua │ │ │ │ ├── 11-nill-coalescing-inverse.txt │ │ │ │ ├── 12-nill-coalescing-assignment-inverse.lua │ │ │ │ ├── 12-nill-coalescing-assignment-inverse.txt │ │ │ │ ├── 13-nill-coalescing-assignment-inverse-ok.lua │ │ │ │ ├── 13-nill-coalescing-assignment-inverse-ok.txt │ │ │ │ ├── 14-length.lua │ │ │ │ ├── 14-length.txt │ │ │ │ ├── 16-for-range-exclusive.lua │ │ │ │ ├── 16-for-range-exclusive.txt │ │ │ │ ├── 17-for-range-tbl-one-side.lua │ │ │ │ ├── 17-for-range-tbl-one-side.txt │ │ │ │ ├── 18-range-var.lua │ │ │ │ ├── 18-range-var.txt │ │ │ │ ├── 19-range-var-print.lua │ │ │ │ ├── 19-range-var-print.txt │ │ │ │ ├── 2-null-coalescing-assignment-scope.lua │ │ │ │ ├── 2-null-coalescing-assignment-scope.txt │ │ │ │ ├── 20-range-var-set.lua │ │ │ │ ├── 20-range-var-set.txt │ │ │ │ ├── 3-null-coalescing-assignment-local.lua │ │ │ │ ├── 3-null-coalescing-assignment-local.txt │ │ │ │ ├── 4-null-coalescing-assignment-local-scope.lua │ │ │ │ ├── 4-null-coalescing-assignment-local-scope.txt │ │ │ │ ├── 5-null-coalescing-assignment-ternary-skip.lua │ │ │ │ ├── 5-null-coalescing-assignment-ternary-skip.txt │ │ │ │ ├── 6-null-coalescing-assignment-ternary-exec.lua │ │ │ │ ├── 6-null-coalescing-assignment-ternary-exec.txt │ │ │ │ ├── 7-relax-ternary.lua │ │ │ │ ├── 7-relax-ternary.txt │ │ │ │ ├── 8-relax-ternary-cmp.lua │ │ │ │ ├── 8-relax-ternary-cmp.txt │ │ │ │ ├── 9-relax-ternary-chain.lua │ │ │ │ └── 9-relax-ternary-chain.txt │ │ │ ├── Preprocessor │ │ │ │ ├── 0-linesanity.lua │ │ │ │ ├── 0-linesanity.txt │ │ │ │ ├── 1-ifdef.lua │ │ │ │ ├── 1-ifdef.txt │ │ │ │ ├── 10-isdefined.lua │ │ │ │ ├── 10-isdefined.txt │ │ │ │ ├── 11-coloffset.lua │ │ │ │ ├── 11-coloffset.txt │ │ │ │ ├── 2-ifndef.lua │ │ │ │ ├── 2-ifndef.txt │ │ │ │ ├── 3-in-string.lua │ │ │ │ ├── 3-in-string.txt │ │ │ │ ├── 4-and.lua │ │ │ │ ├── 4-and.txt │ │ │ │ ├── 5-ops.lua │ │ │ │ ├── 5-ops.txt │ │ │ │ ├── 6-simpleline.lua │ │ │ │ ├── 6-simpleline.txt │ │ │ │ ├── 7-values.lua │ │ │ │ ├── 7-values.txt │ │ │ │ ├── 9-multidef.lua │ │ │ │ └── 9-multidef.txt │ │ │ ├── Ranges │ │ │ │ ├── 1-for-range-inclusive.lua │ │ │ │ ├── 1-for-range-inclusive.txt │ │ │ │ ├── 10-range-tbl-index.lua │ │ │ │ ├── 10-range-tbl-index.txt │ │ │ │ ├── 11-range-tbl-index-mixed.lua │ │ │ │ ├── 11-range-tbl-index-mixed.txt │ │ │ │ ├── 12-range-concat-invalid.lua │ │ │ │ ├── 12-range-concat-invalid.txt │ │ │ │ ├── 13-range-tbl-add.lua │ │ │ │ ├── 13-range-tbl-add.txt │ │ │ │ ├── 14-range-inline-add-invalid.lua │ │ │ │ ├── 14-range-inline-add-invalid.txt │ │ │ │ ├── 15-range-multiple-vars.lua │ │ │ │ ├── 15-range-multiple-vars.txt │ │ │ │ ├── 16-range-iter-ref.lua │ │ │ │ ├── 16-range-iter-ref.txt │ │ │ │ ├── 17-range-vstack.lua │ │ │ │ ├── 17-range-vstack.txt │ │ │ │ ├── 18-range-tuple.lua │ │ │ │ ├── 18-range-tuple.txt │ │ │ │ ├── 19-range-numval-low.lua │ │ │ │ ├── 19-range-numval-low.txt │ │ │ │ ├── 2-for-range-left-exclusive.lua │ │ │ │ ├── 2-for-range-left-exclusive.txt │ │ │ │ ├── 20-range-var.lua │ │ │ │ ├── 20-range-var.txt │ │ │ │ ├── 21-range-string.lua │ │ │ │ ├── 21-range-string.txt │ │ │ │ ├── 22-range-string-direct.lua │ │ │ │ ├── 22-range-string-direct.txt │ │ │ │ ├── 23-range-bool-invalid.lua │ │ │ │ ├── 23-range-bool-invalid.txt │ │ │ │ ├── 24-range-string-invalid.lua │ │ │ │ ├── 24-range-string-invalid.txt │ │ │ │ ├── 3-for-range-right-exclusive.lua │ │ │ │ ├── 3-for-range-right-exclusive.txt │ │ │ │ ├── 4-for-range-exclusive.lua │ │ │ │ ├── 4-for-range-exclusive.txt │ │ │ │ ├── 5-range-var.lua │ │ │ │ ├── 5-range-var.txt │ │ │ │ ├── 6-range-set.lua │ │ │ │ ├── 6-range-set.txt │ │ │ │ ├── 7-range-get.lua │ │ │ │ ├── 7-range-get.txt │ │ │ │ ├── 8-range-chain.lua │ │ │ │ ├── 8-range-chain.txt │ │ │ │ ├── 9-range-ref.lua │ │ │ │ └── 9-range-ref.txt │ │ │ ├── Strings │ │ │ │ ├── 1-interpolated-string.lua │ │ │ │ ├── 1-interpolated-string.txt │ │ │ │ ├── 10-unicode-auto.lua │ │ │ │ ├── 10-unicode-auto.txt │ │ │ │ ├── 11-unicode-transition-multiple.lua │ │ │ │ ├── 11-unicode-transition-multiple.txt │ │ │ │ ├── 11-unicode-transition.lua │ │ │ │ ├── 11-unicode-transition.txt │ │ │ │ ├── 12-unicode-auto-hex.lua │ │ │ │ ├── 12-unicode-auto-hex.txt │ │ │ │ ├── 13-unicode-auto-two-sequences.lua │ │ │ │ ├── 13-unicode-auto-two-sequences.txt │ │ │ │ ├── 14-unicode-auto-two-sequences-2.lua │ │ │ │ ├── 14-unicode-auto-two-sequences-2.txt │ │ │ │ ├── 15-unicode-mixed.lua │ │ │ │ ├── 15-unicode-mixed.txt │ │ │ │ ├── 2-interpolated-string-escape.lua │ │ │ │ ├── 2-interpolated-string-escape.txt │ │ │ │ ├── 3-interpolated-string-escape-backtick.lua │ │ │ │ ├── 3-interpolated-string-escape-backtick.txt │ │ │ │ ├── 4-interpolated-string-expr.lua │ │ │ │ ├── 4-interpolated-string-expr.txt │ │ │ │ ├── 5-interpolated-string-multiline.lua │ │ │ │ ├── 5-interpolated-string-multiline.txt │ │ │ │ ├── 6-interpolated-string-double.lua │ │ │ │ ├── 6-interpolated-string-double.txt │ │ │ │ ├── 7-interpolated-string-multiple.lua │ │ │ │ ├── 7-interpolated-string-multiple.txt │ │ │ │ ├── 8-unicode.lua │ │ │ │ ├── 8-unicode.txt │ │ │ │ ├── 9-unicode-brk.lua │ │ │ │ └── 9-unicode-brk.txt │ │ │ ├── Switch │ │ │ │ ├── 0-switchbreak.lua │ │ │ │ ├── 0-switchbreak.txt │ │ │ │ ├── 1-multicaseswitch.lua │ │ │ │ ├── 1-multicaseswitch.txt │ │ │ │ ├── 2-gotocase.lua │ │ │ │ ├── 2-gotocase.txt │ │ │ │ ├── 3-gotodefault.lua │ │ │ │ ├── 3-gotodefault.txt │ │ │ │ ├── 4-multicaseswitch-brks.lua │ │ │ │ └── 4-multicaseswitch-brks.txt │ │ │ └── Tables │ │ │ │ ├── 1-double-square-brk.lua │ │ │ │ └── 1-double-square-brk.txt │ │ └── SyntaxLua │ │ │ └── Tables │ │ │ ├── 0-set.lua │ │ │ ├── 0-set.txt │ │ │ ├── 01-set-double.lua │ │ │ ├── 01-set-double.txt │ │ │ ├── 1-iterate.lua │ │ │ ├── 1-iterate.txt │ │ │ ├── 10-concat-from-to.lua │ │ │ ├── 10-concat-from-to.txt │ │ │ ├── 2-insert.lua │ │ │ ├── 2-insert.txt │ │ │ ├── 3-sort-simple.lua │ │ │ ├── 3-sort-simple.txt │ │ │ ├── 4-remove.lua │ │ │ ├── 4-remove.txt │ │ │ ├── 5-remove-index.lua │ │ │ ├── 5-remove-index.txt │ │ │ ├── 6-remove-index-multiple.lua │ │ │ ├── 6-remove-index-multiple.txt │ │ │ ├── 7-concat.lua │ │ │ ├── 7-concat.txt │ │ │ ├── 8-concat-from.lua │ │ │ └── 8-concat-from.txt │ ├── CLikeTestRunner.cs │ ├── CSyntaxTests.cs │ ├── ClosureTests.cs │ ├── CollectionsBaseGenRegisteredTests.cs │ ├── CollectionsBaseInterfGenRegisteredTests.cs │ ├── CollectionsRegisteredTests.cs │ ├── ConfigPropertyAssignerTests.cs │ ├── CoroutineTests.cs │ ├── DynamicTests.cs │ ├── ErrorHandlingTests.cs │ ├── FunctionTests.cs │ ├── GotoTests.cs │ ├── JsonSerializationTests.cs │ ├── LocalRedefTest.cs │ ├── LuaTestSuiteExtract.cs │ ├── MetatableTests.cs │ ├── ProxyObjectsTests.cs │ ├── SimpleTests.cs │ ├── StringLibTests.cs │ ├── StructAssignmentTechnique.cs │ ├── TableTests.cs │ ├── TailCallTests.cs │ ├── UserDataEnumsTest.cs │ ├── UserDataEventsTests.cs │ ├── UserDataFieldsTests.cs │ ├── UserDataIndexerTests.cs │ ├── UserDataMetaTests.cs │ ├── UserDataMethodsTests.cs │ ├── UserDataNestedTypesTests.cs │ ├── UserDataOverloadsTests.cs │ ├── UserDataPropertiesTests.cs │ ├── Utils.cs │ ├── VarargsTupleTests.cs │ ├── VtUserDataFieldsTests.cs │ ├── VtUserDataIndexerTests.cs │ ├── VtUserDataMetaTests.cs │ ├── VtUserDataMethodsTests.cs │ ├── VtUserDataOverloadsTests.cs │ └── VtUserDataPropertiesTests.cs ├── TapRunner.cs ├── TestMore │ ├── 000-sanity.t │ ├── 001-if.t │ ├── 002-table.t │ ├── 011-while.t │ ├── 012-repeat.t │ ├── 014-fornum.t │ ├── 015-forlist.t │ ├── 101-boolean.t │ ├── 102-function.t │ ├── 103-nil.t │ ├── 104-number.t │ ├── 105-string.t │ ├── 106-table.t │ ├── 107-thread.t │ ├── 108-userdata.t │ ├── 200-examples.t │ ├── 201-assign.t │ ├── 202-expr.t │ ├── 203-lexico.t │ ├── 204-grammar.t │ ├── 211-scope.t │ ├── 212-function.t │ ├── 213-closure.t │ ├── 214-coroutine.t │ ├── 221-table.t │ ├── 222-constructor.t │ ├── 223-iterator.t │ ├── 231-metatable.t │ ├── 232-object.t │ ├── 301-basic.t │ ├── 304-string.t │ ├── 305-table.t │ ├── 306-math.t │ ├── 307-bit.t │ ├── 308-io.t │ ├── 309-os.t │ ├── 310-debug.t │ ├── 314-regex.t │ ├── 320-stdin.t │ ├── Makefile │ ├── Modules │ │ └── Test │ │ │ ├── Builder.lua │ │ │ └── More.lua │ └── makefile.mak ├── TestMoreTests.cs ├── TestRunner.cs ├── TestScript.cs └── WattleScript.Interpreter.Tests.csproj ├── WattleScript.Interpreter ├── CoreLib │ ├── BasicModule.cs │ ├── Bit32Module.cs │ ├── CoroutineModule.cs │ ├── DebugModule.cs │ ├── DynamicModule.cs │ ├── ErrorHandlingModule.cs │ ├── IO │ │ ├── BinaryEncoding.cs │ │ ├── FileUserData.cs │ │ ├── FileUserDataBase.cs │ │ ├── StandardIOFileUserDataBase.cs │ │ └── StreamFileUserDataBase.cs │ ├── IoModule.cs │ ├── JsonModule.cs │ ├── LoadModule.cs │ ├── MathModule.cs │ ├── MetaTableModule.cs │ ├── OsSystemModule.cs │ ├── OsTimeModule.cs │ ├── PrototypeModule.cs │ ├── StringLib │ │ ├── KopiLua_sprintf.cs │ │ ├── PatternRegex.cs │ │ └── StringRange.cs │ ├── StringModule.cs │ ├── TableIteratorsModule.cs │ └── TableModule.cs ├── DataStructs │ ├── Extension_Methods.cs │ ├── FastStack.cs │ ├── MultiDictionary.cs │ ├── ReferenceEqualityComparer.cs │ └── Slice.cs ├── DataTypes │ ├── Annotation.cs │ ├── CallbackArguments.cs │ ├── CallbackFunction.cs │ ├── Closure.cs │ ├── Coroutine.cs │ ├── CoroutineState.cs │ ├── DataType.cs │ ├── DynValue.cs │ ├── IScriptPrivateResource.cs │ ├── MemberModifierFlags.cs │ ├── PreprocessorDefine.cs │ ├── PreprocessorDefineType.cs │ ├── Range.cs │ ├── RefIdObject.cs │ ├── ScriptFunctionDelegate.cs │ ├── SymbolRef.cs │ ├── SymbolRefType.cs │ ├── Table.cs │ ├── TableKind.cs │ ├── TablePair.cs │ ├── TailCallData.cs │ ├── TypeValidationFlags.cs │ ├── UserData.cs │ ├── WattleMemberInfo.cs │ ├── WattleMemberType.cs │ ├── WattleMembersInfo.cs │ ├── WellKnownSymbols.cs │ └── YieldRequest.cs ├── Debugging │ ├── DebugService.cs │ ├── DebuggerAction.cs │ ├── DebuggerCaps.cs │ ├── IDebugger.cs │ ├── SourceCode.cs │ ├── SourceRef.cs │ ├── WatchItem.cs │ └── WatchType.cs ├── Diagnostics │ ├── PerformanceCounter.cs │ ├── PerformanceCounterType.cs │ ├── PerformanceCounters │ │ ├── DummyPerformanceStopwatch.cs │ │ ├── GlobalPerformanceStopwatch.cs │ │ ├── IPerformanceStopwatch.cs │ │ └── PerformanceStopwatch.cs │ ├── PerformanceResult.cs │ └── PerformanceStatistics.cs ├── Errors │ ├── DynamicExpressionException.cs │ ├── InternalErrorException.cs │ ├── InterpreterException.cs │ ├── ScriptRuntimeException.cs │ └── SyntaxErrorException.cs ├── Execution │ ├── DynamicExpression.cs │ ├── InstructionFieldUsage.cs │ ├── Scopes │ │ ├── BuildTimeScope.cs │ │ ├── BuildTimeScopeBlock.cs │ │ ├── BuildTimeScopeFrame.cs │ │ ├── ClosureContext.cs │ │ ├── IClosureBuilder.cs │ │ ├── LoopTracker.cs │ │ ├── RuntimeScopeBlock.cs │ │ ├── RuntimeScopeFrame.cs │ │ └── Upvalue.cs │ ├── ScriptExecutionContext.cs │ ├── ScriptLoadingContext.cs │ └── VM │ │ ├── CallStackItem.cs │ │ ├── CallStackItemFlags.cs │ │ ├── ExecutionState.cs │ │ ├── FunctionBuilder.cs │ │ ├── FunctionProto.cs │ │ ├── Instruction.cs │ │ ├── OpCode.cs │ │ └── Processor │ │ ├── DebugContext.cs │ │ ├── Processor.cs │ │ ├── Processor_BinaryDump.cs │ │ ├── Processor_Coroutines.cs │ │ ├── Processor_Debugger.cs │ │ ├── Processor_Errors.cs │ │ ├── Processor_IExecutionContext.cs │ │ ├── Processor_InstructionLoop.cs │ │ ├── Processor_Scope.cs │ │ └── Processor_UtilityFunctions.cs ├── Extensions.cs ├── IAnnotationPolicy.cs ├── IO │ ├── BinDumpReader.cs │ └── BinDumpWriter.cs ├── Interop │ ├── Attributes │ │ ├── WattleScriptHiddenAttribute.cs │ │ ├── WattleScriptHideMemberAttribute.cs │ │ ├── WattleScriptPropertyAttribute.cs │ │ ├── WattleScriptUserDataAttribute.cs │ │ ├── WattleScriptUserDataMetamethodAttribute.cs │ │ └── WattleScriptVisibleAttribute.cs │ ├── BasicDescriptors │ │ ├── DispatchingUserDataDescriptor.cs │ │ ├── IMemberDescriptor.cs │ │ ├── IOptimizableDescriptor.cs │ │ ├── IOverloadableMemberDescriptor.cs │ │ ├── MemberDescriptorAccess.cs │ │ └── ParameterDescriptor.cs │ ├── Converters │ │ ├── ClrToScriptConversions.cs │ │ ├── NumericConversions.cs │ │ ├── ScriptToClrConversions.cs │ │ ├── StringConversions.cs │ │ └── TableConversions.cs │ ├── CustomConvertersCollection.cs │ ├── DescriptorHelpers.cs │ ├── IGeneratorUserDataDescriptor.cs │ ├── IUserDataDescriptor.cs │ ├── IUserDataMemberDescriptor.cs │ ├── IUserDataType.cs │ ├── IWireableDescriptor.cs │ ├── InteropAccessMode.cs │ ├── InteropRegistrationPolicy.cs │ ├── PredefinedUserData │ │ ├── AnonWrapper.cs │ │ ├── EnumerableWrapper.cs │ │ └── TaskWrapper.cs │ ├── PropertyTableAssigner.cs │ ├── ProxyObjects │ │ ├── DelegateProxyFactory.cs │ │ └── IProxyFactory.cs │ ├── ReflectionExtensions.cs │ ├── ReflectionSpecialNames.cs │ ├── RegistrationPolicies │ │ ├── AutomaticRegistrationPolicy.cs │ │ ├── DefaultRegistrationPolicy.cs │ │ ├── IRegistrationPolicy.cs │ │ └── PermanentRegistrationPolicy.cs │ ├── StandardDescriptors │ │ ├── AutoDescribingUserDataDescriptor.cs │ │ ├── CompositeUserDataDescriptor.cs │ │ ├── EventFacade.cs │ │ ├── HardwiredDescriptors │ │ │ ├── DefaultValue.cs │ │ │ ├── HardwiredMemberDescriptor.cs │ │ │ ├── HardwiredMethodMemberDescriptor.cs │ │ │ └── HardwiredUserDataDescriptor.cs │ │ ├── MemberDescriptors │ │ │ ├── ArrayMemberDescriptor.cs │ │ │ ├── DynValueMemberDescriptor.cs │ │ │ ├── FunctionMemberDescriptorBase.cs │ │ │ └── ObjectCallbackMemberDescriptor.cs │ │ ├── ProxyUserDataDescriptor.cs │ │ ├── ReflectionMemberDescriptors │ │ │ ├── EventMemberDescriptor.cs │ │ │ ├── FieldMemberDescriptor.cs │ │ │ ├── MethodMemberDescriptor.cs │ │ │ ├── OverloadedMethodMemberDescriptor.cs │ │ │ ├── PropertyMemberDescriptor.cs │ │ │ └── ValueTypeDefaultCtorMemberDescriptor.cs │ │ ├── StandardEnumUserDataDescriptor.cs │ │ ├── StandardGenericsUserDataDescriptor.cs │ │ └── StandardUserDataDescriptor.cs │ ├── UserDataMemberType.cs │ └── UserDataRegistries │ │ ├── ExtensionMethodsRegistry.cs │ │ └── TypeDescriptorRegistry.cs ├── LinqHelpers.cs ├── Loaders │ ├── EmbeddedResourcesScriptLoader.cs │ ├── FileSystemScriptLoader.cs │ ├── IScriptLoader.cs │ ├── InvalidScriptLoader.cs │ ├── ScriptLoaderBase.cs │ └── UnityAssetsScriptLoader.cs ├── Modules │ ├── CoreModules.cs │ ├── ModuleRegister.cs │ ├── WattleScriptModuleAttribute.cs │ ├── WattleScriptModuleConstantAttribute.cs │ └── WattleScriptModuleMethodAttribute.cs ├── NameSpace_XmlHelp.cs ├── Options │ ├── ColonOperatorBehaviour.cs │ ├── FuzzySymbolMatchingBehavior.cs │ └── ScriptSyntax.cs ├── Platforms │ ├── IPlatformAccessor.cs │ ├── LimitedPlatformAccessor.cs │ ├── PlatformAccessorBase.cs │ ├── PlatformAutoDetector.cs │ ├── StandardFileType.cs │ └── StandardPlatformAccessor.cs ├── REPL │ ├── ReplHistoryNavigator.cs │ ├── ReplInterpreter.cs │ └── ReplInterpreterScriptLoader.cs ├── Script.cs ├── ScriptGlobalOptions.cs ├── ScriptOptions.cs ├── Serialization │ ├── Json │ │ ├── JsonNull.cs │ │ └── JsonTableConverter.cs │ ├── ObjectValueConverter.cs │ └── SerializationExtensions.cs ├── Tree │ ├── Expression_.cs │ ├── Expressions │ │ ├── AdjustmentExpression.cs │ │ ├── BinaryOperatorExpression.cs │ │ ├── DynamicExprExpression.cs │ │ ├── ExprListExpression.cs │ │ ├── FunctionCallExpression.cs │ │ ├── FunctionDefinitionExpression.cs │ │ ├── IndexExpression.cs │ │ ├── LiteralExpression.cs │ │ ├── NewExpression.cs │ │ ├── SymbolRefExpression.cs │ │ ├── TableConstructor.cs │ │ ├── TemplatedStringExpression.cs │ │ ├── TernaryExpression.cs │ │ └── UnaryOperatorExpression.cs │ ├── Fast_Interface │ │ └── Loader_Fast.cs │ ├── GeneratedClosure.cs │ ├── IVariable.cs │ ├── Lexer │ │ ├── Lexer.cs │ │ ├── LexerUtils.cs │ │ ├── Token.cs │ │ └── TokenType.cs │ ├── Loop.cs │ ├── MemberCollection.cs │ ├── MemberUtilities.cs │ ├── NodeBase.cs │ ├── Preprocessor │ │ ├── DefineNode.cs │ │ ├── DirectiveLexer.cs │ │ ├── Preprocessor.cs │ │ └── PreprocessorExpression.cs │ ├── Statement.cs │ ├── Statements │ │ ├── AssignmentStatement.cs │ │ ├── BreakStatement.cs │ │ ├── CStyleForStatement.cs │ │ ├── ChunkStatement.cs │ │ ├── ClassDefinitionStatement.cs │ │ ├── CompositeStatement.cs │ │ ├── ContinueStatement.cs │ │ ├── DoBlockStatement.cs │ │ ├── EmptyStatement.cs │ │ ├── EnumDefinitionStatement.cs │ │ ├── ForEachLoopStatement.cs │ │ ├── ForLoopStatement.cs │ │ ├── FunctionCallStatement.cs │ │ ├── FunctionDefinitionStatement.cs │ │ ├── GotoStatement.cs │ │ ├── IBlockStatement.cs │ │ ├── IfStatement.cs │ │ ├── LabelStatement.cs │ │ ├── MixinDefinitionStatement.cs │ │ ├── NewCallStatement.cs │ │ ├── RepeatStatement.cs │ │ ├── ReturnStatement.cs │ │ ├── ScopeStatement.cs │ │ ├── SwitchStatement.cs │ │ └── WhileStatement.cs │ └── TextCursor.cs └── WattleScript.Interpreter.csproj ├── WattleScript.sln └── WattleScript ├── Commands ├── CommandManager.cs ├── ICommand.cs └── Implementations │ ├── CompileCommand.cs │ ├── DumpBytecodeCommand.cs │ ├── ExitCommand.cs │ ├── HardWireCommand.cs │ ├── HelpCommand.cs │ ├── RegisterCommand.cs │ └── RunCommand.cs ├── Mono.Options.cs ├── Program.cs ├── WattleScript.csproj └── wattlescript.ico /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | name: .NET 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v2 18 | with: 19 | dotnet-version: | 20 | 6.0.x 21 | 8.0.x 22 | - name: Restore dependencies 23 | working-directory: ./src 24 | run: dotnet restore 25 | - name: Build 26 | working-directory: ./src 27 | run: dotnet build --no-restore 28 | - name: Test 29 | working-directory: ./src 30 | run: dotnet test --no-build --verbosity normal 31 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | # This is the list of WattleScript's significant contributors. 3 | # 4 | # This does not necessarily list everyone who has contributed code, 5 | # especially since many employees of one corporation may be contributing. 6 | # To see the full list of contributors, see the revision history in 7 | # source control. 8 | 9 | Marco Mastropaolo 10 | wledfor2 11 | NullShock78 12 | doritsugita 13 | Pedro Fanha 14 | Benjamin Dobell 15 | Kevin Morgan 16 | Callum McGing 17 | Matěj Štágl 18 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | | File/Dir | Contents | 2 | | -------- | -------- | 3 | | WattleScript.Interpreter | The core project - the interpreter engine is here. | 4 | | WattleScript.Interpreter.Tests | Test suite, mostly end to end tests of various kinds | 5 | | WattleScript | Sources for the REPL interpreter | 6 | | WattleScriptTests | Tests runner to run the tests suite outside of Visual Studio (mainly, to test in Mono). | 7 | | WattleScript.sln | The solution containing everything | 8 | | README.md | This file | 9 | 10 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/Chapters/Chapter1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using WattleScript.Interpreter; 7 | 8 | namespace Tutorials.Chapters 9 | { 10 | [Tutorial] 11 | static class Chapter01 12 | { 13 | [Tutorial] 14 | public static double WattleScriptFactorial() 15 | { 16 | string script = @" 17 | -- defines a factorial function 18 | function fact (n) 19 | if (n == 0) then 20 | return 1 21 | else 22 | return n*fact(n - 1) 23 | end 24 | end 25 | 26 | return fact(5)"; 27 | 28 | DynValue res = Script.RunString(script); 29 | return res.Number; 30 | } 31 | 32 | 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/Chapters/Chapter10.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WattleScript.Interpreter; 8 | using WattleScript.Interpreter.Loaders; 9 | using WattleScript.Interpreter.Platforms; 10 | 11 | namespace Tutorials.Chapters 12 | { 13 | [Tutorial] 14 | static class Chapter10 15 | { 16 | [Tutorial] 17 | static void OverriddenPrint() 18 | { 19 | // redefine print to print in lowercase, for all new scripts 20 | Script.DefaultOptions.DebugPrint = s => Console.WriteLine(s.ToLower()); 21 | 22 | Script script = new Script(); 23 | 24 | DynValue fn = script.LoadString("print 'Hello, World!'"); 25 | 26 | fn.Function.Call(); // this prints "hello, world!" 27 | 28 | // redefine print to print in UPPERCASE, for this script only 29 | script.Options.DebugPrint = s => Console.WriteLine(s.ToUpper()); 30 | 31 | fn.Function.Call(); // this prints "HELLO, WORLD!" 32 | } 33 | 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/Chapters/Chapter2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using WattleScript.Interpreter; 7 | 8 | namespace Tutorials.Chapters 9 | { 10 | [Tutorial] 11 | static class Chapter02 12 | { 13 | public static double WattleScriptFactorial() 14 | { 15 | string scriptCode = @" 16 | -- defines a factorial function 17 | function fact (n) 18 | if (n == 0) then 19 | return 1 20 | else 21 | return n*fact(n - 1) 22 | end 23 | end 24 | 25 | return fact(mynumber)"; 26 | 27 | Script script = new Script(); 28 | 29 | script.Globals["mynumber"] = 7; 30 | 31 | DynValue res = script.DoString(scriptCode); 32 | return res.Number; 33 | } 34 | 35 | 36 | 37 | [Tutorial] 38 | public static double WattleScriptFactorial2() 39 | { 40 | string scriptCode = @" 41 | -- defines a factorial function 42 | function fact (n) 43 | if (n == 0) then 44 | return 1 45 | else 46 | return n*fact(n - 1) 47 | end 48 | end"; 49 | 50 | Script script = new Script(); 51 | 52 | script.DoString(scriptCode); 53 | 54 | DynValue res = script.Call(script.Globals["fact"], 4); 55 | 56 | return res.Number; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/Chapters/Chapter3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using WattleScript.Interpreter; 7 | 8 | namespace Tutorials.Chapters 9 | { 10 | [Tutorial] 11 | static class Chapter03 12 | { 13 | [Tutorial] 14 | public static double WattleScriptFactorial() 15 | { 16 | string scriptCode = @" 17 | -- defines a factorial function 18 | function fact (n) 19 | if (n == 0) then 20 | return 1 21 | else 22 | return n*fact(n - 1) 23 | end 24 | end"; 25 | 26 | Script script = new Script(); 27 | 28 | script.DoString(scriptCode); 29 | 30 | DynValue luaFactFunction = script.Globals.Get("fact"); 31 | 32 | DynValue res = script.Call(luaFactFunction, 4); 33 | 34 | return res.Number; 35 | } 36 | 37 | [Tutorial] 38 | public static double WattleScriptFactorial2() 39 | { 40 | string scriptCode = @" 41 | -- defines a factorial function 42 | function fact (n) 43 | if (n == 0) then 44 | return 1 45 | else 46 | return n*fact(n - 1) 47 | end 48 | end"; 49 | 50 | Script script = new Script(); 51 | 52 | script.DoString(scriptCode); 53 | 54 | DynValue luaFactFunction = script.Globals.Get("fact"); 55 | 56 | DynValue res = script.Call(luaFactFunction, DynValue.NewNumber(4)); 57 | 58 | return res.Number; 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/Chapters/Chapter5.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using WattleScript.Interpreter; 7 | 8 | namespace Tutorials.Chapters 9 | { 10 | [Tutorial] 11 | static class Chapter05 12 | { 13 | static StringBuilder GetString() 14 | { 15 | return new StringBuilder("myString!"); 16 | } 17 | 18 | [Tutorial] 19 | public static void StringBuilderCustomConverter() 20 | { 21 | Script script = new Script(); 22 | 23 | script.Globals["getstr"] = (Func)GetString; 24 | 25 | DynValue fn = script.LoadString("print(getstr())"); 26 | 27 | fn.Function.Call(); 28 | 29 | Script.GlobalOptions.CustomConverters.SetClrToScriptCustomConversion( 30 | v => DynValue.NewString(v.ToString().ToUpper())); 31 | 32 | fn.Function.Call(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/Chapters/Chapter7.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using WattleScript.Interpreter; 7 | 8 | namespace Tutorials.Chapters 9 | { 10 | [Tutorial] 11 | static class Chapter07 12 | { 13 | [Tutorial] 14 | static void ErrorHandling() 15 | { 16 | try 17 | { 18 | string scriptCode = @" 19 | return obj.calcHypotenuse(3, 4); 20 | "; 21 | 22 | Script script = new Script(); 23 | DynValue res = script.DoString(scriptCode); 24 | } 25 | catch (ScriptRuntimeException ex) 26 | { 27 | Console.WriteLine("Doh! An error occured! {0}", ex.DecoratedMessage); 28 | } 29 | } 30 | 31 | static void DoError() 32 | { 33 | throw new ScriptRuntimeException("This is an exceptional message, no pun intended."); 34 | } 35 | 36 | [Tutorial] 37 | static string ErrorGen() 38 | { 39 | string scriptCode = @" 40 | local _, msg = pcall(DoError); 41 | return msg; 42 | "; 43 | 44 | Script script = new Script(); 45 | script.Globals["DoError"] = (Action)DoError; 46 | DynValue res = script.DoString(scriptCode); 47 | return res.String; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/Chapters/Chapter8.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WattleScript.Interpreter; 8 | using WattleScript.Interpreter.Loaders; 9 | 10 | namespace Tutorials.Chapters 11 | { 12 | [Tutorial] 13 | static class Chapter08 14 | { 15 | [Tutorial] 16 | static void EmbeddedResourceScriptLoader() 17 | { 18 | Script script = new Script(); 19 | script.Options.ScriptLoader = new EmbeddedResourcesScriptLoader(Assembly.GetExecutingAssembly()); 20 | script.DoFile("Scripts/Test.lua"); 21 | } 22 | 23 | private class MyCustomScriptLoader : ScriptLoaderBase 24 | { 25 | public override object LoadFile(string file, Table globalContext) 26 | { 27 | return string.Format("print ([[A request to load '{0}' has been made]])", file); 28 | } 29 | 30 | public override bool ScriptFileExists(string name) 31 | { 32 | return true; 33 | } 34 | } 35 | 36 | [Tutorial] 37 | static void CustomScriptLoader() 38 | { 39 | Script script = new Script(); 40 | 41 | script.Options.ScriptLoader = new MyCustomScriptLoader() 42 | { 43 | ModulePaths = new string[] { "?_module.lua" } 44 | }; 45 | 46 | script.DoString(@" 47 | require 'somemodule' 48 | f = loadfile 'someothermodule.lua' 49 | f() 50 | "); 51 | } 52 | 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/Chapters/Chapter9.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WattleScript.Interpreter; 8 | using WattleScript.Interpreter.Loaders; 9 | using WattleScript.Interpreter.Platforms; 10 | 11 | namespace Tutorials.Chapters 12 | { 13 | [Tutorial] 14 | static class Chapter09 15 | { 16 | [Tutorial] 17 | static void ChangePlatform() 18 | { 19 | // This prints "function" 20 | Console.WriteLine(Script.RunString("return type(os.exit);").ToPrintString()); 21 | 22 | // Save the old platform 23 | var oldplatform = Script.GlobalOptions.Platform; 24 | 25 | // Changing platform after a script has been created is not recommended.. do not do it. 26 | // We are doing it for the purpose of the walkthrough.. 27 | Script.GlobalOptions.Platform = new LimitedPlatformAccessor(); 28 | 29 | // This time, this prints "nil" 30 | Console.WriteLine(Script.RunString("return type(os.exit);").ToPrintString()); 31 | 32 | // Restore the old platform 33 | Script.GlobalOptions.Platform = oldplatform; 34 | } 35 | 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/Scripts/Test.lua: -------------------------------------------------------------------------------- 1 | -- Sample script embedded as a resource. 2 | 3 | for i = 1, 5 do 4 | print "Hello world!" 5 | end 6 | 7 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/TutorialAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Tutorials 8 | { 9 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false, AllowMultiple = false)] 10 | public sealed class TutorialAttribute : Attribute 11 | { 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Tutorial/Tutorials/readme.md: -------------------------------------------------------------------------------- 1 | WattleScript Tutorials 2 | =================== 3 | 4 | 5 | These are sources for the tutorials contained at http://www.moonsharp.org/getting_started.html and following pages. 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/Generators/FieldMemberDescriptorGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using WattleScript.Interpreter; 7 | using WattleScript.Interpreter.Interop; 8 | using WattleScript.Interpreter.Interop.BasicDescriptors; 9 | using WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors; 10 | 11 | namespace WattleScript.Hardwire.Generators 12 | { 13 | class FieldMemberDescriptorGenerator : AssignableMemberDescriptorGeneratorBase 14 | { 15 | public override string ManagedType 16 | { 17 | get { return "WattleScript.Interpreter.Interop.FieldMemberDescriptor"; } 18 | } 19 | 20 | protected override CodeExpression GetMemberAccessExpression(CodeExpression thisObj, string name) 21 | { 22 | return new CodeFieldReferenceExpression(thisObj, name); 23 | } 24 | 25 | protected override string GetPrefix() 26 | { 27 | return "FLDV"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/Generators/NullGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using WattleScript.Interpreter; 7 | 8 | namespace WattleScript.Hardwire.Generators 9 | { 10 | internal class NullGenerator : IHardwireGenerator 11 | { 12 | public NullGenerator() 13 | { 14 | ManagedType = ""; 15 | } 16 | 17 | public NullGenerator(string type) 18 | { 19 | ManagedType = type; 20 | } 21 | 22 | public string ManagedType 23 | { 24 | get; 25 | private set; 26 | } 27 | 28 | public CodeExpression[] Generate(string parent, Table table, HardwireCodeGenerationContext generator, CodeTypeMemberCollection members) 29 | { 30 | generator.Error("Missing code generator for '{0}'.", ManagedType); 31 | 32 | return new CodeExpression[0]; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/Generators/OverloadedMethodMemberDescriptorGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using WattleScript.Interpreter; 7 | using WattleScript.Interpreter.Interop; 8 | using WattleScript.Interpreter.Interop.BasicDescriptors; 9 | 10 | namespace WattleScript.Hardwire.Generators 11 | { 12 | class OverloadedMethodMemberDescriptorGenerator : IHardwireGenerator 13 | { 14 | public string ManagedType 15 | { 16 | get { return "WattleScript.Interpreter.Interop.OverloadedMethodMemberDescriptor"; } 17 | } 18 | 19 | public CodeExpression[] Generate(string parent, Table table, HardwireCodeGenerationContext generator, 20 | CodeTypeMemberCollection members) 21 | { 22 | List initializers = new List(); 23 | 24 | generator.DispatchTablePairs(parent + (table["name"] as string), table.Get("overloads").Table, members, exp => 25 | { 26 | initializers.Add(exp); 27 | }); 28 | 29 | var name = new CodePrimitiveExpression((table["name"] as string)); 30 | var type = new CodeTypeOfExpression(table["decltype"] as string); 31 | 32 | var array = new CodeArrayCreateExpression(typeof(IOverloadableMemberDescriptor), initializers.ToArray()); 33 | 34 | return new CodeExpression[] { 35 | new CodeObjectCreateExpression(typeof(OverloadedMethodMemberDescriptor), name, type, array) 36 | }; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/Generators/PropertyMemberDescriptorGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using WattleScript.Interpreter; 7 | using WattleScript.Interpreter.Interop; 8 | using WattleScript.Interpreter.Interop.BasicDescriptors; 9 | using WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors; 10 | 11 | namespace WattleScript.Hardwire.Generators 12 | { 13 | class PropertyMemberDescriptorGenerator : AssignableMemberDescriptorGeneratorBase 14 | { 15 | public override string ManagedType 16 | { 17 | get { return "WattleScript.Interpreter.Interop.PropertyMemberDescriptor"; } 18 | } 19 | 20 | protected override CodeExpression GetMemberAccessExpression(CodeExpression thisObj, string name) 21 | { 22 | return new CodePropertyReferenceExpression(thisObj, name); 23 | } 24 | 25 | protected override string GetPrefix() 26 | { 27 | return "PROP"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/Generators/ValueTypeDefaultCtorMemberDescriptorGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using WattleScript.Interpreter; 7 | using WattleScript.Interpreter.Interop.BasicDescriptors; 8 | using WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors; 9 | 10 | namespace WattleScript.Hardwire.Generators 11 | { 12 | class ValueTypeDefaultCtorMemberDescriptorGenerator : IHardwireGenerator 13 | { 14 | public string ManagedType 15 | { 16 | get { return "WattleScript.Interpreter.Interop.ValueTypeDefaultCtorMemberDescriptor"; } 17 | } 18 | 19 | public CodeExpression[] Generate(string parent, Table table, HardwireCodeGenerationContext generator, CodeTypeMemberCollection members) 20 | { 21 | MethodMemberDescriptorGenerator mgen = new MethodMemberDescriptorGenerator("VTDC"); 22 | 23 | Table mt = new Table(null); 24 | 25 | mt["params"] = new Table(null); 26 | mt["name"] = "__new"; 27 | mt["type"] = table["type"]; 28 | mt["ctor"] = true; 29 | mt["extension"] = false; 30 | mt["decltype"] = table["type"]; 31 | mt["ret"] = table["type"]; 32 | mt["special"] = false; 33 | 34 | 35 | return mgen.Generate(parent, mt, generator, members); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/HardwireGeneratorRegistry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using WattleScript.Hardwire.Generators; 7 | using WattleScript.Interpreter; 8 | 9 | namespace WattleScript.Hardwire 10 | { 11 | public static class HardwireGeneratorRegistry 12 | { 13 | static Dictionary m_Generators = new Dictionary(); 14 | 15 | public static void Register(IHardwireGenerator g) 16 | { 17 | m_Generators[g.ManagedType] = g; 18 | } 19 | 20 | public static IHardwireGenerator GetGenerator(string type) 21 | { 22 | if (m_Generators.ContainsKey(type)) 23 | return m_Generators[type]; 24 | else 25 | return new NullGenerator(type); 26 | } 27 | 28 | public static void RegisterPredefined() 29 | { 30 | DiscoverFromAssembly(Assembly.GetExecutingAssembly()); 31 | } 32 | 33 | 34 | public static void DiscoverFromAssembly(Assembly asm = null) 35 | { 36 | if (asm == null) 37 | asm = Assembly.GetCallingAssembly(); 38 | 39 | foreach (Type type in asm.GetTypes() 40 | .Where(t => !(t.IsAbstract || t.IsGenericTypeDefinition || t.IsGenericType)) 41 | .Where(t => (typeof(IHardwireGenerator)).IsAssignableFrom(t))) 42 | { 43 | IHardwireGenerator g = (IHardwireGenerator)Activator.CreateInstance(type); 44 | Register(g); 45 | } 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/ICodeGenerationLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WattleScript.Hardwire 7 | { 8 | public interface ICodeGenerationLogger 9 | { 10 | void LogError(string message); 11 | void LogWarning(string message); 12 | void LogMinor(string message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/IHardwireGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using WattleScript.Interpreter; 6 | 7 | namespace WattleScript.Hardwire 8 | { 9 | /// 10 | /// Interface to be implemented by all hardwire code generators 11 | /// 12 | public interface IHardwireGenerator 13 | { 14 | /// 15 | /// Gets the type which is managed by this generator. Should be an exact match with the 'class' entry in the 16 | /// codegen table. 17 | /// 18 | string ManagedType { get; } 19 | 20 | /// 21 | /// Generates code from a dump of the type. 22 | /// 23 | /// The table containing the data to be parsed. 24 | /// The generator context. 25 | /// The CodeTypeMemberCollection which can be used to add newly defined types. 26 | /// Zero or more expressions which can be used by the parent generator to use the generated code. 27 | CodeExpression[] Generate(string parent, Table table, HardwireCodeGenerationContext generatorContext, CodeTypeMemberCollection members); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/Utils/GeneratorUtilities.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using WattleScript.Interpreter; 7 | using WattleScript.Interpreter.Interop.BasicDescriptors; 8 | using WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors; 9 | 10 | namespace WattleScript.Hardwire.Utils 11 | { 12 | public class GeneratorUtilities 13 | { 14 | 15 | 16 | 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/WattleScript.Hardwire/WattleScript.Hardwire.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/WattleScript.HardwireGen.Test/ExtraHardwire.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ]]> 4 | -------------------------------------------------------------------------------- /src/WattleScript.HardwireGen.Test/GenericExtra.cs: -------------------------------------------------------------------------------- 1 | namespace WattleScript.HardwireGen.Test; 2 | 3 | public class GenericExtra 4 | { 5 | public T? Value; 6 | 7 | public int DoThing() 8 | { 9 | return 1234; 10 | } 11 | } -------------------------------------------------------------------------------- /src/WattleScript.HardwireGen.Test/MyWattleData.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter; 2 | 3 | namespace WattleScript.HardwireGen.Test; 4 | 5 | [WattleScriptUserData] 6 | public class MyWattleData 7 | { 8 | public string Value = ""; 9 | 10 | public int Add4(int a) 11 | { 12 | return a + 4; 13 | } 14 | 15 | public MyWattleData() 16 | { 17 | } 18 | 19 | public MyWattleData(string value) 20 | { 21 | Value = value; 22 | } 23 | } -------------------------------------------------------------------------------- /src/WattleScript.HardwireGen.Test/WattleScript.HardwireGen.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/WattleScript.HardwireGen.Test/WithProperty.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter; 2 | 3 | namespace WattleScript.HardwireGen.Test; 4 | 5 | [WattleScriptUserData] 6 | public class WithProperty 7 | { 8 | public int Property { get; set; } 9 | } -------------------------------------------------------------------------------- /src/WattleScript.HardwireGen/ClassNames.cs: -------------------------------------------------------------------------------- 1 | namespace WattleScript.HardwireGen 2 | { 3 | public static class ClassNames 4 | { 5 | public const string CLS_USERDATA = 6 | "WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors.HardwiredUserDataDescriptor"; 7 | 8 | public const string CLS_OVERLOAD = "WattleScript.Interpreter.Interop.OverloadedMethodMemberDescriptor"; 9 | 10 | public const string CLS_OVERLOAD_MEMBER = 11 | "WattleScript.Interpreter.Interop.BasicDescriptors.IOverloadableMemberDescriptor"; 12 | 13 | public const string CLS_PROP_FIELD = 14 | "WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors.HardwiredMemberDescriptor"; 15 | 16 | public const string CLS_METHOD = 17 | "WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors.HardwiredMethodMemberDescriptor"; 18 | 19 | public const string CLS_PARAMETER = "WattleScript.Interpreter.Interop.BasicDescriptors.ParameterDescriptor"; 20 | 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /src/WattleScript.HardwireGen/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "profiles": { 4 | "Generators": { 5 | "commandName": "DebugRoslynComponent", 6 | "targetProject": "../WattleScript.HardwireGen.Test/WattleScript.HardwireGen.Test.csproj" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/WattleScript.HardwireGen/StringUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.CodeAnalysis.CSharp; 3 | 4 | namespace WattleScript.HardwireGen 5 | { 6 | public static class StringUtils 7 | { 8 | public static string ToLiteral(this string input) 9 | { 10 | return SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(input)).ToFullString(); 11 | } 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/01-private-field.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | private x = 7; 4 | } 5 | 6 | print(new A().x) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/01-private-field.txt: -------------------------------------------------------------------------------- 1 | nil -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/02-private-nowrite-invalid.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | private x = 7; 4 | } 5 | 6 | var i = new A(); 7 | i.x = 3; -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/03-private-thisaccess.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | private x = 7; 4 | printx() 5 | { 6 | print(this.x); 7 | } 8 | } 9 | 10 | new A().printx(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/03-private-thisaccess.txt: -------------------------------------------------------------------------------- 1 | 7 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/04-private-base.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | private x = 7; 4 | } 5 | 6 | class B : A 7 | { 8 | printx() 9 | { 10 | print(this.x); 11 | } 12 | } 13 | 14 | var i = new B(); 15 | print(i.x); 16 | i.printx(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/04-private-base.txt: -------------------------------------------------------------------------------- 1 | nil 2 | 7 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/05-private-mixin.lua: -------------------------------------------------------------------------------- 1 | mixin A 2 | { 3 | private x = 7; 4 | } 5 | 6 | class B with A 7 | { 8 | printx() 9 | { 10 | print(this.x); 11 | } 12 | } 13 | 14 | var i = new B(); 15 | print(i.x); 16 | i.printx(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/05-private-mixin.txt: -------------------------------------------------------------------------------- 1 | nil 2 | 7 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/06-privatestatic-invalid.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | private static x = 7; 4 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/07-public.lua: -------------------------------------------------------------------------------- 1 | mixin B 2 | { 3 | public y = 9; 4 | } 5 | class A with B 6 | { 7 | public x = 8; 8 | } 9 | 10 | print(new A().x) 11 | print(new A().y) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/07-public.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 9 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Access/08-conflicting-access-invalid.lua: -------------------------------------------------------------------------------- 1 | class X 2 | { 3 | public private Z = 9; 4 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Aliases/1-null.lua: -------------------------------------------------------------------------------- 1 | x = null 2 | print(x) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Aliases/1-null.txt: -------------------------------------------------------------------------------- 1 | nil -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Aliases/2-this.lua: -------------------------------------------------------------------------------- 1 | Account = {balance = 100} 2 | function Account:withdraw (v) 3 | this.balance = this.balance - v 4 | end 5 | 6 | Account::withdraw(60) 7 | print(Account.balance) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Aliases/2-this.txt: -------------------------------------------------------------------------------- 1 | 40 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/1-annotation.lua: -------------------------------------------------------------------------------- 1 | @bind("html-name", "cool") 2 | function f() { 3 | 4 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/1-annotation.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/1-annotation.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/2-annotation.lua: -------------------------------------------------------------------------------- 1 | @bind("html-name") 2 | function f() { 3 | 4 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/2-annotation.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/2-annotation.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/3-annotation.lua: -------------------------------------------------------------------------------- 1 | @bind 2 | function f() { 3 | 4 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/3-annotation.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/3-annotation.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/4-annotation.lua: -------------------------------------------------------------------------------- 1 | @bind("tbl1") 2 | @bind2({"tbl2", "tbl3"}) 3 | @bind3("tbl4", "tbl6") 4 | function f() { 5 | 6 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/4-annotation.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/4-annotation.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/5-annotation.lua: -------------------------------------------------------------------------------- 1 | @bind2({"tbl2", "tbl3"}) 2 | function f() { 3 | 4 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/5-annotation.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Annotations/5-annotation.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/0-new.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | A(value) 4 | { 5 | this.value = value; 6 | } 7 | 8 | printvalue() => print(this.value); 9 | } 10 | 11 | new A("hello").printvalue(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/0-new.txt: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/1-classloop.lua: -------------------------------------------------------------------------------- 1 | function errprint(code) { 2 | local status, err = pcall(code) 3 | print(err) 4 | } 5 | 6 | class A : B { } 7 | class B : A { printthing() => print("hello"); } 8 | 9 | errprint(() => { new B().printthing(); }); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/1-classloop.txt: -------------------------------------------------------------------------------- 1 | chunk_0:(7,6-11): class hierarchy contains cyclic reference (B) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/10-static-field-ref.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | static MyProp = "test" 4 | static MyProp2 = this.MyProp + "2" 5 | } 6 | 7 | print(A.MyProp2) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/10-static-field-ref.txt: -------------------------------------------------------------------------------- 1 | test2 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/11-duplicate-function-invalid.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | function f() { 4 | 5 | } 6 | 7 | function f() { 8 | 9 | } 10 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/11-duplicate-function-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/11-duplicate-function-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/12-duplicate-field-invalid.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | bar = 10 4 | bar = 20 5 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/12-duplicate-field-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/12-duplicate-field-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/13-reserved-field-invalid.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | static function __ctor() { 4 | 5 | } 6 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/13-reserved-field-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/13-reserved-field-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/14-static-math.lua: -------------------------------------------------------------------------------- 1 | static class Math { 2 | static PI = 3.1415926535 3 | 4 | static function Sum(a, b) { 5 | return a + b 6 | } 7 | 8 | static CircleArea = (r) => { 9 | return this.PI * r ** 2 10 | } 11 | } 12 | 13 | print(Math.Sum(5, 1)) 14 | print(Math.CircleArea(10)) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/14-static-math.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 314.15926535 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/15-static-class-empty.lua: -------------------------------------------------------------------------------- 1 | static class Math { 2 | 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/15-static-class-empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/15-static-class-empty.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/16-static-class-empty-invalid.lua: -------------------------------------------------------------------------------- 1 | static static class Math { 2 | 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/17-static-class-non-static-field-invalid.lua: -------------------------------------------------------------------------------- 1 | static class Math { 2 | PI = 3.14 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/18-static-class-non-static-function-invalid.lua: -------------------------------------------------------------------------------- 1 | static class Math { 2 | function PI() { 3 | return 3.14 4 | } 5 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/19-static-class-non-static-function-arrow-invalid.lua: -------------------------------------------------------------------------------- 1 | static class Math { 2 | PI = () => { 3 | return 3.14 4 | } 5 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/2-mixin.lua: -------------------------------------------------------------------------------- 1 | mixin MixA { 2 | printvalue() => print(this.value); 3 | } 4 | 5 | class A with MixA { 6 | A(value) { 7 | this.value = value; 8 | } 9 | } 10 | 11 | new A("hello").printvalue(); 12 | 13 | mixin MixB { 14 | printvalue() => print("not ok hello"); 15 | } 16 | 17 | class B with MixB { 18 | B(value) { 19 | this.value = value; 20 | } 21 | printvalue() => print(this.value); 22 | } 23 | 24 | new B("hello").printvalue(); //class function defs override mixin defs 25 | 26 | mixin MixinValue { 27 | value = "hello!! :)" 28 | } 29 | 30 | class C with MixinValue, MixA { } //mixins also add data. multiple mixin usage 31 | 32 | new C().printvalue(); 33 | 34 | //mixins cannot define constructors 35 | mixin M { 36 | M2(value) { this.value = value } 37 | } 38 | 39 | class M2 with M { } 40 | 41 | print(new M2("hello").value == nil); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/2-mixin.txt: -------------------------------------------------------------------------------- 1 | hello 2 | hello 3 | hello!! :) 4 | true -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/20-static-class-ctor-invalid.lua: -------------------------------------------------------------------------------- 1 | static class Math { 2 | Math() { 3 | 4 | } 5 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/21-static-class-ctor-static-invalid.lua: -------------------------------------------------------------------------------- 1 | static class Math { 2 | static Math() { 3 | 4 | } 5 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/22-class-lhs-new.lua: -------------------------------------------------------------------------------- 1 | class C { 2 | C() { 3 | print("ctor side effect") 4 | } 5 | 6 | f() { 7 | print("something") 8 | } 9 | } 10 | 11 | new C() 12 | new C().f() -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/22-class-lhs-new.txt: -------------------------------------------------------------------------------- 1 | ctor side effect 2 | ctor side effect 3 | something -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/23-static-class-instantiate-invalid.lua: -------------------------------------------------------------------------------- 1 | static class Math { 2 | 3 | } 4 | 5 | new Math() -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/24-static-class-base-invalid.lua: -------------------------------------------------------------------------------- 1 | class Math2 : Math { 2 | 3 | } 4 | 5 | static class Math { 6 | 7 | } 8 | 9 | new Math2() -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/25-static-class-static-field-function-ref.lua: -------------------------------------------------------------------------------- 1 | static class X { 2 | static function Y() { print(10) } 3 | static T = this.Y 4 | static function Z() { print(this.T()) } 5 | } 6 | 7 | X.Z() -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/25-static-class-static-field-function-ref.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/26-class-field-thiscall.lua: -------------------------------------------------------------------------------- 1 | class A { 2 | Y = "hello" 3 | X = this.Y 4 | Z = 10 5 | X2 = this.X + this.Z 6 | } 7 | 8 | a = new A() 9 | print(a.X) 10 | print(a.X2) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/26-class-field-thiscall.txt: -------------------------------------------------------------------------------- 1 | hello 2 | hello10 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/27-class-field-thiscall-function.lua: -------------------------------------------------------------------------------- 1 | class A { 2 | Y = () => { print("hello") } 3 | } 4 | 5 | new A().Y() 6 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/27-class-field-thiscall-function.txt: -------------------------------------------------------------------------------- 1 | hello -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/28-class-sealed-invalid.lua: -------------------------------------------------------------------------------- 1 | class B : A {} 2 | sealed class A {} 3 | 4 | new B() 5 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/29-class-sealed.lua: -------------------------------------------------------------------------------- 1 | sealed class A { 2 | public a = 0 3 | } 4 | print(new A().a) 5 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/29-class-sealed.txt: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/3-basecall.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | printx() => print("x"); 4 | } 5 | 6 | class B : A 7 | { 8 | printx2() => base.printx(); 9 | } 10 | 11 | new B().printx2(); 12 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/3-basecall.txt: -------------------------------------------------------------------------------- 1 | x 2 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/4-baseconstruct.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | A(value) 4 | { 5 | this.value = value; 6 | } 7 | } 8 | 9 | class B : A 10 | { 11 | B(value) 12 | { 13 | base(value); 14 | this.value2 = value; 15 | } 16 | } 17 | 18 | var x = new B("hello"); 19 | print(x.value2 == x.value); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/4-baseconstruct.txt: -------------------------------------------------------------------------------- 1 | true 2 | 3 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/5-baseconstruct-default.lua: -------------------------------------------------------------------------------- 1 | // Testing that an empty __ctor is generated on base classes 2 | // That have ctor 3 | 4 | class A { } 5 | class B : A { 6 | B() { base() } 7 | printval() => print("yes"); 8 | } 9 | 10 | new B().printval(); 11 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/5-baseconstruct-default.txt: -------------------------------------------------------------------------------- 1 | yes 2 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/6-baseclass-invalid.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | } 4 | 5 | class B : A 6 | { 7 | dothing() => { 8 | base = 7; //Cannot write to base, compiler error. 9 | print("hello"); 10 | } 11 | } 12 | 13 | new B().dothing(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/6-baseclass-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/6-baseclass-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/7-static.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | function f3() { 4 | return 8 5 | } 6 | 7 | static function f() { 8 | return 10 9 | } 10 | 11 | static function f2() { 12 | return 12 13 | } 14 | } 15 | 16 | function g() { 17 | return 6 18 | } 19 | 20 | print(A.f()); 21 | print(A.f2()); 22 | print(A.f()); 23 | print(new A().f3()); 24 | print(g()) 25 | print(A.f()); 26 | print(A.f2()); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/7-static.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 12 3 | 10 4 | 8 5 | 6 6 | 10 7 | 12 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/8-static-local-ref.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | static bar = "bar" 4 | 5 | static function f1() { 6 | return 2 7 | } 8 | 9 | static function f2() { 10 | return this.f1() + 3 + this.bar 11 | } 12 | } 13 | 14 | print(A.f2()) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/8-static-local-ref.txt: -------------------------------------------------------------------------------- 1 | 5bar -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/9-static-field.lua: -------------------------------------------------------------------------------- 1 | class A 2 | { 3 | static MyProp = "test" 4 | static function F1() { 5 | return this.MyProp + "2" 6 | } 7 | } 8 | 9 | function F1() { 10 | return "error" 11 | } 12 | 13 | print(A.MyProp) 14 | print(A.F1()) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Classes/9-static-field.txt: -------------------------------------------------------------------------------- 1 | test 2 | test2 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Enums/0-enum.lua: -------------------------------------------------------------------------------- 1 | function errprint(code) { 2 | local status, err = pcall(code) 3 | print(err) 4 | } 5 | 6 | enum Colors { 7 | Red, 8 | Green, 9 | Blue, 10 | Orange = 4, 11 | Purple, 12 | Pink = 4, 13 | Grey, 14 | Aquamarine = (1 << 4), 15 | } 16 | 17 | print(Colors.Red) 18 | print(Colors.Green) 19 | print(Colors.Blue) 20 | print(Colors.Orange) 21 | print(Colors.Purple) 22 | print(Colors.Pink) 23 | print(Colors.Grey) 24 | print(Colors.Aquamarine) 25 | 26 | errprint(() => { Colors.Red = 2 }) 27 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Enums/0-enum.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 4 5 | 5 6 | 4 7 | 5 8 | 16 9 | chunk_0:(26,17-31): table is readonly -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Enums/1-selfref.lua: -------------------------------------------------------------------------------- 1 | enum Flags { 2 | A = (1 << 1), 3 | B = (1 << 2), 4 | AB = A | B 5 | } 6 | 7 | print(Flags.A); 8 | print(Flags.B); 9 | print(Flags.AB); 10 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Enums/1-selfref.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 4 3 | 6 4 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Enums/2-annotsyntax.lua: -------------------------------------------------------------------------------- 1 | // Just testing that compile succeeds 2 | @tbl ({ "hello", "world", x = 7}) 3 | enum Hello { 4 | Val1, 5 | Val2, 6 | Val3 7 | } 8 | print("ok") -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Enums/2-annotsyntax.txt: -------------------------------------------------------------------------------- 1 | ok -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Errors/1-common-invalid.lua: -------------------------------------------------------------------------------- 1 | if ( 2 | 3 | x = 0 4 | x1 = [] -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Errors/1-common-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Errors/1-common-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Errors/2-resync-invalid.lua: -------------------------------------------------------------------------------- 1 | if ( 2 | 3 | x = 0 4 | x1 = [] 5 | 6 | local x1 = = = -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Errors/2-resync-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Errors/2-resync-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/1-call.lua: -------------------------------------------------------------------------------- 1 | function f1(a, b, c) {} 2 | 3 | f1(10, 20); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/1-call.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/1-call.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/10-call-default-scope-local-3.lua: -------------------------------------------------------------------------------- 1 | local function f1(a = 500) { 2 | print("a: " + a) 3 | } 4 | 5 | f1() 6 | 7 | if (2 > 1) { 8 | 9 | local function f1(a = 600) { 10 | print("a: " + a) 11 | } 12 | 13 | f1() 14 | } 15 | 16 | f1() -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/10-call-default-scope-local-3.txt: -------------------------------------------------------------------------------- 1 | a: 500 2 | a: 600 3 | a: 500 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/11-call-default-scope-arrow.lua: -------------------------------------------------------------------------------- 1 | f = (x = 500) => { 2 | print(x) 3 | } 4 | 5 | f(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/11-call-default-scope-arrow.txt: -------------------------------------------------------------------------------- 1 | 500 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/12-call-default-scope-arrow-invalid.lua: -------------------------------------------------------------------------------- 1 | f = (x = 500, x2) => { 2 | print(x) 3 | } 4 | 5 | f(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/12-call-default-scope-arrow-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/12-call-default-scope-arrow-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/13-call-default-scope-arrow-arrow.lua: -------------------------------------------------------------------------------- 1 | f = (x) => { 2 | x() 3 | } 4 | 5 | f(() => { 6 | print("yes") 7 | }); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/13-call-default-scope-arrow-arrow.txt: -------------------------------------------------------------------------------- 1 | yes -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/14-call-default-scope-arrow-arrow-default.lua: -------------------------------------------------------------------------------- 1 | f = (x = () => {print("yes")}) => { 2 | x() 3 | } 4 | 5 | f(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/14-call-default-scope-arrow-arrow-default.txt: -------------------------------------------------------------------------------- 1 | yes -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/15-call-default-scope-arrow-arrow-default-2.lua: -------------------------------------------------------------------------------- 1 | f = (x = () => {print("yes")}) => { 2 | x() 3 | } 4 | 5 | f(() => { 6 | print("no") 7 | }); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/15-call-default-scope-arrow-arrow-default-2.txt: -------------------------------------------------------------------------------- 1 | no -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/16-default-call-closure.lua: -------------------------------------------------------------------------------- 1 | local z = 2 2 | 3 | f = (x = () => {print(z)}) => { 4 | x() 5 | } 6 | 7 | z = 3 8 | 9 | f(); 10 | 11 | function test2() { 12 | local z = 2 13 | f = (x = () => {print(z)}) => { 14 | x() 15 | } 16 | z = 7; 17 | return f; 18 | } 19 | 20 | local f2 = test2(); 21 | f2(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/16-default-call-closure.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 7 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/17-call-hoisted.lua: -------------------------------------------------------------------------------- 1 | f(); 2 | //This will be hoisted to the top of the block. 3 | function f() 4 | { 5 | print("hello world!"); 6 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/17-call-hoisted.txt: -------------------------------------------------------------------------------- 1 | hello world! -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/18-assign-lambda.lua: -------------------------------------------------------------------------------- 1 | function assign(value) => globalVar = value; 2 | 3 | assign("hello"); 4 | print(globalVar); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/18-assign-lambda.txt: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/2-call-default.lua: -------------------------------------------------------------------------------- 1 | function f1(a, b, c = 100) { 2 | print("a: " + a) 3 | print("b: " + b) 4 | print("c: " + c) 5 | } 6 | 7 | f1(10, 20); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/2-call-default.txt: -------------------------------------------------------------------------------- 1 | a: 10 2 | b: 20 3 | c: 100 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/3-call-default-invalid.lua: -------------------------------------------------------------------------------- 1 | function f1(a = 50, b, c = 100) { 2 | print("a: " + a) 3 | print("b: " + b) 4 | print("c: " + c) 5 | } 6 | 7 | f1(10, 20); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/3-call-default-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/3-call-default-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/4-call-default-2.lua: -------------------------------------------------------------------------------- 1 | function f1(a = 80) { 2 | print("a: " + a) 3 | } 4 | 5 | f1(10); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/4-call-default-2.txt: -------------------------------------------------------------------------------- 1 | a: 10 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/5-call-default-3.lua: -------------------------------------------------------------------------------- 1 | function f1(a = 80) { 2 | print("a: " + a) 3 | } 4 | 5 | f1(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/5-call-default-3.txt: -------------------------------------------------------------------------------- 1 | a: 80 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/6-call-default-local.lua: -------------------------------------------------------------------------------- 1 | local function f1(a = 80) { 2 | print("a: " + a) 3 | } 4 | 5 | f1(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/6-call-default-local.txt: -------------------------------------------------------------------------------- 1 | a: 80 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/7-call-default-scope.lua: -------------------------------------------------------------------------------- 1 | function f1(a = 500) { 2 | print("global a: " + a) 3 | } 4 | 5 | if (2 > 1) { 6 | f1() 7 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/7-call-default-scope.txt: -------------------------------------------------------------------------------- 1 | global a: 500 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/8-call-default-scope-local.lua: -------------------------------------------------------------------------------- 1 | local function f1(a = 500) { 2 | print("a: " + a) 3 | } 4 | 5 | if (2 > 1) { 6 | f1() 7 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/8-call-default-scope-local.txt: -------------------------------------------------------------------------------- 1 | a: 500 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/9-call-default-scope-local-2.lua: -------------------------------------------------------------------------------- 1 | local function f1(a = 500) { 2 | print("a: " + a) 3 | } 4 | 5 | f1() 6 | 7 | if (2 > 1) { 8 | 9 | function f1(a = 600) { 10 | print("a: " + a) 11 | } 12 | 13 | f1() 14 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Functions/9-call-default-scope-local-2.txt: -------------------------------------------------------------------------------- 1 | a: 500 2 | a: 600 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/0-string.lua: -------------------------------------------------------------------------------- 1 | print("hello".upper()) 2 | print("HELLO".lower()) 3 | print("hello".reverse()) 4 | 5 | function prototype.string.append(s) 6 | { 7 | return this + s; 8 | } 9 | 10 | print("hello".append(" world")); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/0-string.txt: -------------------------------------------------------------------------------- 1 | HELLO 2 | hello 3 | olleh 4 | hello world 5 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/1-number.lua: -------------------------------------------------------------------------------- 1 | print((1.0).tostring()) 2 | print((2.0).tostring()) 3 | 4 | function prototype.number.double() 5 | { 6 | return this * 2; 7 | } 8 | 9 | print((2.0).double()); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/1-number.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 4 4 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/2-boolean.lua: -------------------------------------------------------------------------------- 1 | print((true).tostring()) 2 | print((false).tostring()) 3 | 4 | prototype.boolean.invert = (bool) => !bool; 5 | 6 | print((true).invert()) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/2-boolean.txt: -------------------------------------------------------------------------------- 1 | true 2 | false 3 | false -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/3-table.lua: -------------------------------------------------------------------------------- 1 | function prototype.table.hello() 2 | { 3 | return "hello"; 4 | } 5 | 6 | tbl = {} 7 | print(tbl.hello()); 8 | //special case for tables, we only index the prototype for direct method calls 9 | //this should be nil 10 | print(tbl.hello) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/3-table.txt: -------------------------------------------------------------------------------- 1 | hello 2 | nil -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/4-range.lua: -------------------------------------------------------------------------------- 1 | function prototype.range.toTable() 2 | { 3 | local tbl = {} 4 | for(i in this) { 5 | table.insert(tbl, i); 6 | } 7 | return tbl; 8 | } 9 | 10 | print((1..4).toTable().length); 11 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Meta/4-range.txt: -------------------------------------------------------------------------------- 1 | 4 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/0-null-coalescing-assignment-min.lua: -------------------------------------------------------------------------------- 1 | a ??= 10 2 | 3 | print(a) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/0-null-coalescing-assignment-min.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/1-null-coalescing-assignment-check.lua: -------------------------------------------------------------------------------- 1 | a ??= 10 2 | a ??= 20 3 | 4 | print(a) 5 | 6 | a = nil 7 | 8 | a ??= 50 9 | 10 | print(a) 11 | 12 | b ??= [5, 15, 30] 13 | 14 | print(b[0]) 15 | 16 | b[0] ??= 50 17 | 18 | print(b[0]) 19 | 20 | b["test"] ??= [7, 14] 21 | 22 | print(b["test"][0]) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/1-null-coalescing-assignment-check.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 50 3 | 5 4 | 5 5 | 7 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/10-relax-ternary-chain-2.lua: -------------------------------------------------------------------------------- 1 | b = (1 > 2 && 300 > 5) || 100 == 100 ? 1 : 2 2 | print(b) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/10-relax-ternary-chain-2.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/11-nill-coalescing-inverse.lua: -------------------------------------------------------------------------------- 1 | x = 10 ?! 100 2 | print(x) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/11-nill-coalescing-inverse.txt: -------------------------------------------------------------------------------- 1 | 100 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/12-nill-coalescing-assignment-inverse.lua: -------------------------------------------------------------------------------- 1 | x ?!= 500 2 | print(x) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/12-nill-coalescing-assignment-inverse.txt: -------------------------------------------------------------------------------- 1 | nil -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/13-nill-coalescing-assignment-inverse-ok.lua: -------------------------------------------------------------------------------- 1 | x = 10 2 | x ?!= 500 3 | print(x) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/13-nill-coalescing-assignment-inverse-ok.txt: -------------------------------------------------------------------------------- 1 | 500 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/14-length.lua: -------------------------------------------------------------------------------- 1 | print([1, 2, 3, 4].length) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/14-length.txt: -------------------------------------------------------------------------------- 1 | 4 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/16-for-range-exclusive.lua: -------------------------------------------------------------------------------- 1 | for (i in 1..<5) { 2 | print(i) 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/16-for-range-exclusive.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/17-for-range-tbl-one-side.lua: -------------------------------------------------------------------------------- 1 | a = [1, 2, 3] 2 | 3 | for (i in 1..a[0]) { 4 | print(i) 5 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/17-for-range-tbl-one-side.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/18-range-var.lua: -------------------------------------------------------------------------------- 1 | x = 1..2 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/18-range-var.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/18-range-var.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/19-range-var-print.lua: -------------------------------------------------------------------------------- 1 | x = 1..2 2 | print(x.to) 3 | print(x.from) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/19-range-var-print.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 1 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/2-null-coalescing-assignment-scope.lua: -------------------------------------------------------------------------------- 1 | function f1() { 2 | a ??= 500 3 | print(a) 4 | } 5 | 6 | f1(); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/2-null-coalescing-assignment-scope.txt: -------------------------------------------------------------------------------- 1 | 500 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/20-range-var-set.lua: -------------------------------------------------------------------------------- 1 | x = 1..2 2 | x.to = 3 3 | print(x.to) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/20-range-var-set.txt: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/3-null-coalescing-assignment-local.lua: -------------------------------------------------------------------------------- 1 | local a ??= 500 2 | print(a) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/3-null-coalescing-assignment-local.txt: -------------------------------------------------------------------------------- 1 | 500 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/4-null-coalescing-assignment-local-scope.lua: -------------------------------------------------------------------------------- 1 | f = () => { 2 | local a ??= 600 3 | a ??= 700 4 | print(a) 5 | } 6 | 7 | f(); 8 | print(a) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/4-null-coalescing-assignment-local-scope.txt: -------------------------------------------------------------------------------- 1 | 600 2 | nil -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/5-null-coalescing-assignment-ternary-skip.lua: -------------------------------------------------------------------------------- 1 | b = 1 2 | b ??= (5 > 20) ? 10 : 20 3 | 4 | print(b) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/5-null-coalescing-assignment-ternary-skip.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/6-null-coalescing-assignment-ternary-exec.lua: -------------------------------------------------------------------------------- 1 | b ??= (5 > 20) ? 10 : 20 2 | 3 | print(b) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/6-null-coalescing-assignment-ternary-exec.txt: -------------------------------------------------------------------------------- 1 | 20 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/7-relax-ternary.lua: -------------------------------------------------------------------------------- 1 | b = 5 > 20 ? 1 : 2 2 | print(b) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/7-relax-ternary.txt: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/8-relax-ternary-cmp.lua: -------------------------------------------------------------------------------- 1 | b = (5 > 20) ? 10 : 20 2 | print(b) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/8-relax-ternary-cmp.txt: -------------------------------------------------------------------------------- 1 | 20 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/9-relax-ternary-chain.lua: -------------------------------------------------------------------------------- 1 | b = 5 > 20 && 1 > 0 ? 1 : 2 2 | print(b) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Operators/9-relax-ternary-chain.txt: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/0-linesanity.lua: -------------------------------------------------------------------------------- 1 | print(CurrentLine()) 2 | print(CurrentLine()) 3 | print(CurrentLine()) 4 | //SourceRef for call expressions = the () 5 | //As the previous SourceRef is for the index instructions 6 | print(CurrentColumn()) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/0-linesanity.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 19 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/1-ifdef.lua: -------------------------------------------------------------------------------- 1 | #if VARIABLE 2 | print(CurrentLine()) 3 | #else 4 | print(CurrentLine()) 5 | #endif 6 | 7 | #define VARIABLE 8 | 9 | #if VARIABLE 10 | print(CurrentLine()) 11 | #else 12 | print(CurrentLine()) 13 | #endif -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/1-ifdef.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 10 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/10-isdefined.lua: -------------------------------------------------------------------------------- 1 | #define VAR1 2 | 3 | #if defined(VAR1) 4 | print("ok") 5 | #else 6 | print("not ok VAR1") 7 | #endif 8 | 9 | #if !defined(VAR2) 10 | print("ok") 11 | #else 12 | print("not ok VAR2") 13 | #endif -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/10-isdefined.txt: -------------------------------------------------------------------------------- 1 | ok 2 | ok -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/11-coloffset.lua: -------------------------------------------------------------------------------- 1 | #line 3, 20 2 | /*20 char comment!*/print(CurrentColumn()) 3 | // ^ 4 | //source ref points to here (19) 5 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/11-coloffset.txt: -------------------------------------------------------------------------------- 1 | 19 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/2-ifndef.lua: -------------------------------------------------------------------------------- 1 | #if !VARIABLE 2 | print(CurrentLine()) 3 | #else 4 | print(CurrentLine()) 5 | #endif 6 | 7 | #define VARIABLE 8 | 9 | #if !VARIABLE 10 | print(CurrentLine()) 11 | #else 12 | print(CurrentLine()) 13 | #endif -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/2-ifndef.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 12 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/3-in-string.lua: -------------------------------------------------------------------------------- 1 | //#define inside a string literal won't be processed 2 | //but a #define in the expression will 3 | 4 | l = ` 5 | #define HELLO 6 | { 7 | #define WORLD 8 | } 9 | ` 10 | print(CurrentLine()) 11 | #if HELLO 12 | print("hello") 13 | #endif 14 | #if WORLD 15 | print("world") 16 | #endif -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/3-in-string.txt: -------------------------------------------------------------------------------- 1 | 10 2 | world 3 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/4-and.lua: -------------------------------------------------------------------------------- 1 | #define VAR1 2 | #define VAR2 3 | 4 | #if VAR1 && VAR2 5 | print("ok") 6 | #else 7 | print ("not ok") 8 | #endif 9 | 10 | #if VAR1 && VAR3 11 | print("not ok") 12 | #else 13 | print("ok") 14 | #endif -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/4-and.txt: -------------------------------------------------------------------------------- 1 | ok 2 | ok -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/5-ops.lua: -------------------------------------------------------------------------------- 1 | #define A 5 2 | #define B 3 3 | 4 | #if A > B 5 | print("ok") 6 | #else 7 | print("not ok A > B") 8 | #endif 9 | 10 | #if A >= B 11 | print("ok") 12 | #else 13 | print("not ok A >= B") 14 | #endif 15 | 16 | #if B > A 17 | print("not ok B > A") 18 | #else 19 | print("ok") 20 | #endif 21 | 22 | #if B >= A 23 | print("not ok B >= A") 24 | #else 25 | print("ok") 26 | #endif 27 | 28 | #if A < B 29 | print("not ok A < B") 30 | #else 31 | print("ok") 32 | #endif 33 | 34 | #if A <= B 35 | print("not ok A <= B") 36 | #else 37 | print("ok") 38 | #endif 39 | 40 | #if B < A 41 | print("ok") 42 | #else 43 | print("not ok B < A") 44 | #endif 45 | 46 | #if B <= A 47 | print("ok") 48 | #else 49 | print("not ok B <= A") 50 | #endif 51 | print(CurrentLine()) 52 | 53 | #if 23 > A 54 | print("ok") 55 | #else 56 | print("not ok 23 > A"); 57 | #endif -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/5-ops.txt: -------------------------------------------------------------------------------- 1 | ok 2 | ok 3 | ok 4 | ok 5 | ok 6 | ok 7 | ok 8 | ok 9 | 51 10 | ok -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/6-simpleline.lua: -------------------------------------------------------------------------------- 1 | #line 7 2 | print(CurrentLine()); 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | #line 300 /* Comment 11 | */ 12 | print(CurrentLine()); 13 | 14 | #line default 15 | print(CurrentLine()) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/6-simpleline.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 301 3 | 15 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/7-values.lua: -------------------------------------------------------------------------------- 1 | #define STRING "hello" 2 | #define NUMBER 8.0 3 | #define BOOLEAN true 4 | #define NONE 5 | 6 | // Making sure "//" and '/*' within literals doesn't trigger comments 7 | 8 | #define STRING2 "//" 9 | #define STRING3 '/*' 10 | 11 | print(STRING) 12 | print(STRING2) 13 | print(STRING3) 14 | print(NUMBER) 15 | print(BOOLEAN) 16 | print(NONE) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/7-values.txt: -------------------------------------------------------------------------------- 1 | hello 2 | // 3 | /* 4 | 8 5 | true 6 | nil -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/9-multidef.lua: -------------------------------------------------------------------------------- 1 | #define STRING = "hello", EMPTY, STRING2 = "world" 2 | 3 | print(STRING) 4 | print(STRING2) 5 | print(EMPTY) 6 | #undef STRING, STRING2 7 | 8 | //we didn't undef empty, check it's still there 9 | #if EMPTY 10 | print("ok") 11 | #else 12 | print("not ok - EMPTY") 13 | #endif 14 | 15 | #if !STRING 16 | print("ok") 17 | #else 18 | print("not ok - STRING") 19 | #endif 20 | 21 | #if !STRING2 22 | print("ok") 23 | #else 24 | print("not ok - STRING2") 25 | #endif -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Preprocessor/9-multidef.txt: -------------------------------------------------------------------------------- 1 | hello 2 | world 3 | nil 4 | ok 5 | ok 6 | ok -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/1-for-range-inclusive.lua: -------------------------------------------------------------------------------- 1 | for (i in 1..5) { 2 | print(i) 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/1-for-range-inclusive.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/10-range-tbl-index.lua: -------------------------------------------------------------------------------- 1 | tbl = [1..10] 2 | print(tbl[0].to) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/10-range-tbl-index.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/11-range-tbl-index-mixed.lua: -------------------------------------------------------------------------------- 1 | tbl = ["hello", 10, 1..10, 3..5] 2 | print(tbl.length) 3 | print(tbl[0]) 4 | print(tbl[1]) 5 | print(tbl[2].from) 6 | print(tbl[2].to) 7 | print(tbl[3].from) 8 | print(tbl[3].to) 9 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/11-range-tbl-index-mixed.txt: -------------------------------------------------------------------------------- 1 | 4 2 | hello 3 | 10 4 | 1 5 | 10 6 | 3 7 | 5 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/12-range-concat-invalid.lua: -------------------------------------------------------------------------------- 1 | r1 = 1..10 2 | r2 = 5..5 3 | r3 = r1 + r2; 4 | print(r3.from) 5 | print(r3.to) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/12-range-concat-invalid.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 15 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/13-range-tbl-add.lua: -------------------------------------------------------------------------------- 1 | r1 = 1..10 2 | tbl = []; 3 | table.insert(tbl, r1) 4 | print(tbl[0].to) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/13-range-tbl-add.txt: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/14-range-inline-add-invalid.lua: -------------------------------------------------------------------------------- 1 | r1 = 1..10 + 5..5 2 | print(r1.from) 3 | print(r1.to) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/14-range-inline-add-invalid.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 15 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/15-range-multiple-vars.lua: -------------------------------------------------------------------------------- 1 | for (i, j in 1..2) { 2 | print(i + " " + j) 3 | } 4 | z = 100 5 | print("test stack ok " + z) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/15-range-multiple-vars.txt: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2 2 3 | test stack ok 100 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/16-range-iter-ref.lua: -------------------------------------------------------------------------------- 1 | tbl = [10, 12] 2 | 3 | for (i in tbl[0]..tbl[1]) { 4 | print(i) 5 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/16-range-iter-ref.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 11 3 | 12 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/17-range-vstack.lua: -------------------------------------------------------------------------------- 1 | x = 1..60000 2 | y = 0 3 | for (i in x) { 4 | y++ 5 | } 6 | print(y) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/17-range-vstack.txt: -------------------------------------------------------------------------------- 1 | 60000 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/18-range-tuple.lua: -------------------------------------------------------------------------------- 1 | function mret() { 2 | return 1, 2; 3 | } 4 | print(mret() + mret()); // 2 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/18-range-tuple.txt: -------------------------------------------------------------------------------- 1 | 2 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/19-range-numval-low.lua: -------------------------------------------------------------------------------- 1 | x = 0 2 | for (i in -4095..0) { 3 | x++; 4 | } 5 | print(x) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/19-range-numval-low.txt: -------------------------------------------------------------------------------- 1 | 4096 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/2-for-range-left-exclusive.lua: -------------------------------------------------------------------------------- 1 | for (i in 1>..5) { 2 | print(i) 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/2-for-range-left-exclusive.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/20-range-var.lua: -------------------------------------------------------------------------------- 1 | a = 8 2 | b = 10 3 | for (i in a..b) { 4 | print(i) 5 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/20-range-var.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 9 3 | 10 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/21-range-string.lua: -------------------------------------------------------------------------------- 1 | a = "4" 2 | b = "6" 3 | for (i in a..b) { 4 | print(i) 5 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/21-range-string.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 5 3 | 6 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/22-range-string-direct.lua: -------------------------------------------------------------------------------- 1 | for (i in "4".."6") { 2 | print(i) 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/22-range-string-direct.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 5 3 | 6 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/23-range-bool-invalid.lua: -------------------------------------------------------------------------------- 1 | for (i in 1..true) { 2 | print(i) 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/23-range-bool-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/23-range-bool-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/24-range-string-invalid.lua: -------------------------------------------------------------------------------- 1 | for (i in 1.."hi") { 2 | print(i) 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/24-range-string-invalid.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/24-range-string-invalid.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/3-for-range-right-exclusive.lua: -------------------------------------------------------------------------------- 1 | for (i in 1..<5) { 2 | print(i) 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/3-for-range-right-exclusive.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/4-for-range-exclusive.lua: -------------------------------------------------------------------------------- 1 | for (i in 1>..<5) { 2 | print(i) 3 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/4-for-range-exclusive.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/5-range-var.lua: -------------------------------------------------------------------------------- 1 | myRange = 1 >..< 5 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/5-range-var.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/5-range-var.txt -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/6-range-set.lua: -------------------------------------------------------------------------------- 1 | myRange = 1 >..< 5 2 | myRange.from = 1 3 | myRange.to = 5 4 | 5 | for (i in myRange) { 6 | print(i) 7 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/6-range-set.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/7-range-get.lua: -------------------------------------------------------------------------------- 1 | myRange = 1..5 2 | print(myRange.from) 3 | print(myRange.to) 4 | 5 | myLeftExclusiveRange = 1..<5 6 | print(myLeftExclusiveRange.from) 7 | print(myLeftExclusiveRange.to) 8 | 9 | myRightExclusiveRange = 1>..5 10 | print(myRightExclusiveRange.from) 11 | print(myRightExclusiveRange.to) 12 | 13 | myExclusiveRange = 1>..<5 14 | print(myExclusiveRange.from) 15 | print(myExclusiveRange.to) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/7-range-get.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 5 3 | 1 4 | 4 5 | 2 6 | 5 7 | 2 8 | 4 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/8-range-chain.lua: -------------------------------------------------------------------------------- 1 | myRange = 2*2..2*2+1 2 | print(myRange.from) 3 | print(myRange.to) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/8-range-chain.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 5 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/9-range-ref.lua: -------------------------------------------------------------------------------- 1 | tbl = [10, 20] 2 | myRange = tbl[0]..tbl[1] 3 | print(myRange.from) 4 | print(myRange.to) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Ranges/9-range-ref.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 20 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/1-interpolated-string.lua: -------------------------------------------------------------------------------- 1 | world = 100 2 | x = `hello {world}` 3 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/1-interpolated-string.txt: -------------------------------------------------------------------------------- 1 | hello 100 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/10-unicode-auto.lua: -------------------------------------------------------------------------------- 1 | x = '\u2714aaaaaa' 2 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/10-unicode-auto.txt: -------------------------------------------------------------------------------- 1 | ✔aaaaaa -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/11-unicode-transition-multiple.lua: -------------------------------------------------------------------------------- 1 | x = '\u2714hi\u2714' 2 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/11-unicode-transition-multiple.txt: -------------------------------------------------------------------------------- 1 | ✔hi✔ -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/11-unicode-transition.lua: -------------------------------------------------------------------------------- 1 | x = '\u2714hi' 2 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/11-unicode-transition.txt: -------------------------------------------------------------------------------- 1 | ✔hi -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/12-unicode-auto-hex.lua: -------------------------------------------------------------------------------- 1 | x = 'Click \u201CCustomize\u201D to' 2 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/12-unicode-auto-hex.txt: -------------------------------------------------------------------------------- 1 | Click “Customize” to -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/13-unicode-auto-two-sequences.lua: -------------------------------------------------------------------------------- 1 | x = 'music \uD834\uDD1E' 2 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/13-unicode-auto-two-sequences.txt: -------------------------------------------------------------------------------- 1 | music 𝄞 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/14-unicode-auto-two-sequences-2.lua: -------------------------------------------------------------------------------- 1 | x = 'music \uD834\uDD1E!' 2 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/14-unicode-auto-two-sequences-2.txt: -------------------------------------------------------------------------------- 1 | music 𝄞! -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/15-unicode-mixed.lua: -------------------------------------------------------------------------------- 1 | x = '\u2605\uD83D\uDE00\u2605' 2 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/15-unicode-mixed.txt: -------------------------------------------------------------------------------- 1 | ★😀★ -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/2-interpolated-string-escape.lua: -------------------------------------------------------------------------------- 1 | world = 100 2 | x = `hello \{world\}` 3 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/2-interpolated-string-escape.txt: -------------------------------------------------------------------------------- 1 | hello {world} -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/3-interpolated-string-escape-backtick.lua: -------------------------------------------------------------------------------- 1 | world = 100 2 | x = `hello \`\`` 3 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/3-interpolated-string-escape-backtick.txt: -------------------------------------------------------------------------------- 1 | hello `` -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/4-interpolated-string-expr.lua: -------------------------------------------------------------------------------- 1 | world = 100 2 | x = `hello {world > 50 ? "gt50" : "lt50"}` 3 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/4-interpolated-string-expr.txt: -------------------------------------------------------------------------------- 1 | hello gt50 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/5-interpolated-string-multiline.lua: -------------------------------------------------------------------------------- 1 | world = 100 2 | x = `hello 3 | greetings 4 | hi 5 | ahoj 6 | {world} 7 | \{ 8 | \} 9 | \` 10 | "double quotes" 11 | 'single quotes' 12 | "''" 13 | ` 14 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/5-interpolated-string-multiline.txt: -------------------------------------------------------------------------------- 1 | hello 2 | greetings 3 | hi 4 | ahoj 5 | 100 6 | { 7 | } 8 | ` 9 | "double quotes" 10 | 'single quotes' 11 | "''" -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/6-interpolated-string-double.lua: -------------------------------------------------------------------------------- 1 | x = `unescaped \` in string` 2 | print(x) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/6-interpolated-string-double.txt: -------------------------------------------------------------------------------- 1 | unescaped ` in string -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/7-interpolated-string-multiple.lua: -------------------------------------------------------------------------------- 1 | x1 = 10 2 | x = `{x1}{x1}{x1}test{x1}` 3 | print(x) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/7-interpolated-string-multiple.txt: -------------------------------------------------------------------------------- 1 | 101010test10 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/8-unicode.lua: -------------------------------------------------------------------------------- 1 | x = '\u2714' 2 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/8-unicode.txt: -------------------------------------------------------------------------------- 1 | ✔ -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/9-unicode-brk.lua: -------------------------------------------------------------------------------- 1 | x = '\u{2714}' 2 | print(x); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Strings/9-unicode-brk.txt: -------------------------------------------------------------------------------- 1 | ✔ -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/0-switchbreak.lua: -------------------------------------------------------------------------------- 1 | function s1(a) { 2 | switch(a) { 3 | case 5: 4 | i = 0 5 | while true { 6 | i++ 7 | if i > 3 { 8 | break; 9 | } 10 | } 11 | i = 7 12 | break; 13 | default: 14 | i = 99 15 | } 16 | } 17 | 18 | s1(5); 19 | print(i); 20 | s1(0); 21 | print(i); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/0-switchbreak.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 99 3 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/1-multicaseswitch.lua: -------------------------------------------------------------------------------- 1 | function s1(arg) { 2 | switch(arg) { 3 | case 'd': 4 | case 'f': 5 | case 'e': 6 | print(1); 7 | case 'a': 8 | case 'b': 9 | case 'c': 10 | print(2); 11 | default: 12 | print('error'); 13 | } 14 | } 15 | s1('a'); 16 | s1('b'); 17 | s1('c'); 18 | s1('d'); 19 | s1('e'); 20 | s1('f'); 21 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/1-multicaseswitch.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | 2 4 | 1 5 | 1 6 | 1 7 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/2-gotocase.lua: -------------------------------------------------------------------------------- 1 | function s1(arg) { 2 | switch(arg) { 3 | case 'b': 4 | print('b'); 5 | case 'a': 6 | print('a'); 7 | goto case 'b'; 8 | } 9 | } 10 | 11 | s1('a'); 12 | s1('b'); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/2-gotocase.txt: -------------------------------------------------------------------------------- 1 | a 2 | b 3 | b 4 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/3-gotodefault.lua: -------------------------------------------------------------------------------- 1 | function s1(arg) { 2 | switch(arg) { 3 | case 1: 4 | print('a'); 5 | goto default; 6 | case 2: 7 | print('b'); 8 | default: 9 | print('c'); 10 | } 11 | } 12 | 13 | s1(1); 14 | s1(2); 15 | s1(3); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/3-gotodefault.txt: -------------------------------------------------------------------------------- 1 | a 2 | c 3 | b 4 | c 5 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/4-multicaseswitch-brks.lua: -------------------------------------------------------------------------------- 1 | 2 | function s1(arg) { 3 | switch(arg) { 4 | case 'd': 5 | case 'f': 6 | case 'e': 7 | { 8 | print(1); 9 | } 10 | case 'a': 11 | case 'b': 12 | case 'c': { 13 | print(2); 14 | } 15 | default: 16 | print('error'); 17 | } 18 | } 19 | s1('a'); 20 | s1('b'); 21 | s1('c'); 22 | s1('d'); 23 | s1('e'); 24 | s1('f'); -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Switch/4-multicaseswitch-brks.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | 2 4 | 1 5 | 1 6 | 1 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Tables/1-double-square-brk.lua: -------------------------------------------------------------------------------- 1 | x = [[100]] 2 | print(x[0][0]) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxCLike/Tables/1-double-square-brk.txt: -------------------------------------------------------------------------------- 1 | 100 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/0-set.lua: -------------------------------------------------------------------------------- 1 | local tbl = {} 2 | tbl[0] = 80; 3 | print(tbl[0]) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/0-set.txt: -------------------------------------------------------------------------------- 1 | 80 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/01-set-double.lua: -------------------------------------------------------------------------------- 1 | local tbl = {} 2 | tbl[3] = 50; 3 | tbl[3.14] = 80; 4 | print(tbl[3]) 5 | print(tbl[3.14]) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/01-set-double.txt: -------------------------------------------------------------------------------- 1 | 50 2 | 80 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/1-iterate.lua: -------------------------------------------------------------------------------- 1 | local tbl = {10, 20, 30} 2 | for k, v in ipairs(tbl) do 3 | print(v) 4 | end -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/1-iterate.txt: -------------------------------------------------------------------------------- 1 | 10 2 | 20 3 | 30 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/10-concat-from-to.lua: -------------------------------------------------------------------------------- 1 | local str = table.concat({ 1, 2, "three", 4, "five" }, "-", 0, 2) 2 | print(str) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/10-concat-from-to.txt: -------------------------------------------------------------------------------- 1 | 1-2 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/2-insert.lua: -------------------------------------------------------------------------------- 1 | local tbl = {} 2 | table.insert(tbl, 30) 3 | 4 | print(tbl[0]) 5 | 6 | table.insert(tbl, 50) 7 | 8 | print(tbl[0]) 9 | print(tbl[1]) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/2-insert.txt: -------------------------------------------------------------------------------- 1 | 30 2 | 30 3 | 50 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/3-sort-simple.lua: -------------------------------------------------------------------------------- 1 | local tbl = {90, 500, 0, 5} 2 | table.sort(tbl) 3 | print(tbl[0]) 4 | print(tbl[1]) 5 | print(tbl[2]) 6 | print(tbl[3]) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/3-sort-simple.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 5 3 | 90 4 | 500 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/4-remove.lua: -------------------------------------------------------------------------------- 1 | local tbl = {5, 10, 15, 20} 2 | table.remove(tbl) 3 | print(tbl[0]) 4 | print(tbl[1]) 5 | print(tbl[2]) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/4-remove.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 10 3 | 15 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/5-remove-index.lua: -------------------------------------------------------------------------------- 1 | local tbl = {5, 10, 15, 20} 2 | table.remove(tbl, 1) 3 | print(tbl[0]) 4 | print(tbl[1]) 5 | print(tbl[2]) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/5-remove-index.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 15 3 | 20 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/6-remove-index-multiple.lua: -------------------------------------------------------------------------------- 1 | local tbl = {5, 10, 15, 20} 2 | table.remove(tbl, 1) 3 | table.remove(tbl, 1) 4 | print(tbl[0]) 5 | print(tbl[1]) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/6-remove-index-multiple.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 20 -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/7-concat.lua: -------------------------------------------------------------------------------- 1 | local str = table.concat({ 1, 2, "three", 4, "five" }) 2 | print(str) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/7-concat.txt: -------------------------------------------------------------------------------- 1 | 12three4five -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/8-concat-from.lua: -------------------------------------------------------------------------------- 1 | local str = table.concat({ 1, 2, "three", 4, "five" }, "-", 1) 2 | print(str) -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/CLike/SyntaxLua/Tables/8-concat-from.txt: -------------------------------------------------------------------------------- 1 | 2-three-4-five -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/FunctionTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using NUnit.Framework; 4 | 5 | namespace WattleScript.Interpreter.Tests.EndToEnd 6 | { 7 | [TestFixture] 8 | public class FunctionTests 9 | { 10 | DynValue ListFilter(Script sc, CallbackArguments args) 11 | { 12 | Table tbl = new Table(sc); 13 | DynValue dv = DynValue.NewTable(tbl); 14 | 15 | Table toFilter = args[0].Table; 16 | Closure filterFn = args[1].Function; 17 | 18 | foreach (TablePair pair in toFilter.Pairs) 19 | { 20 | DynValue valPair = pair.Value; 21 | DynValue check = filterFn.Call(valPair); 22 | 23 | if (check.Boolean) 24 | { 25 | tbl.Append(valPair); 26 | } 27 | } 28 | 29 | return dv; 30 | } 31 | 32 | [Test] 33 | public void ListFilter() 34 | { 35 | string script = @" 36 | arr = list_filter({10, 20, 30}, function (x) return x >= 20 end) 37 | return arr[1] 38 | "; 39 | 40 | var sc = new Script(); 41 | sc.Globals["list_filter"] = (Func)ListFilter; 42 | var x = sc.DoString(script); 43 | 44 | Assert.AreEqual(20, x.Number); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/LocalRedefTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using WattleScript.Interpreter.Tests; 3 | 4 | namespace WattleScript.Interpreter.Tests.EndToEnd; 5 | 6 | [TestFixture] 7 | public class LocalRedefTest 8 | { 9 | [Test] 10 | public void RedefinedLocal() 11 | { 12 | TestScript.Run(@" 13 | function appendb(s) 14 | return s .. 'b' 15 | end 16 | 17 | local tbl = { 'a' } 18 | for index, item in ipairs(tbl) do 19 | local item = appendb(item) 20 | global = item 21 | end 22 | assert.areequal('ab', global) 23 | "); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/EndToEnd/ProxyObjectsTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WattleScript.Interpreter.Interop; 6 | using NUnit.Framework; 7 | 8 | namespace WattleScript.Interpreter.Tests.EndToEnd 9 | { 10 | [TestFixture] 11 | public class ProxyObjectsTests 12 | { 13 | public class Proxy 14 | { 15 | [WattleScriptVisible(false)] 16 | public Random random; 17 | 18 | [WattleScriptVisible(false)] 19 | public Proxy(Random r) 20 | { 21 | random = r; 22 | } 23 | 24 | public int GetValue() { return 3; } 25 | } 26 | 27 | [Test] 28 | public void ProxyTest() 29 | { 30 | UserData.RegisterProxyType(r => new Proxy(r)); 31 | 32 | Script S = new Script(); 33 | 34 | S.Globals["R"] = new Random(); 35 | S.Globals["func"] = (Action)(r => { Assert.IsNotNull(r); Assert.IsTrue(r is Random); }); 36 | 37 | S.DoString(@" 38 | x = R.GetValue(); 39 | func(R); 40 | "); 41 | 42 | Assert.AreEqual(3.0, S.Globals.Get("x").Number); 43 | } 44 | 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/TestMore/000-sanity.t: -------------------------------------------------------------------------------- 1 | #! /usr/bin/lua 2 | -- 3 | -- lua-TestMore : 4 | -- 5 | -- Copyright (C) 2009, Perrad Francois 6 | -- 7 | -- This code is licensed under the terms of the MIT/X11 license, 8 | -- like Lua itself. 9 | -- 10 | 11 | --[[ 12 | 13 | =head1 Lua test suite 14 | 15 | =head2 Synopsis 16 | 17 | % prove 000-sanity.t 18 | 19 | =head2 Description 20 | 21 | =cut 22 | 23 | ]] 24 | 25 | function f (n) 26 | return n + 1 27 | end 28 | 29 | function g (m, p) 30 | return m + p 31 | end 32 | 33 | print('1..9') 34 | print("ok 1 -") 35 | print('ok', 2, "- list") 36 | print("ok " .. 3 .. " - concatenation") 37 | i = 4 38 | print("ok " .. i .. " - var") 39 | i = i + 1 40 | print("ok " .. i .. " - var incr") 41 | print("ok " .. i+1 .. " - expr") 42 | j = f(i + 1) 43 | print("ok " .. j .. " - call f") 44 | k = g(i, 3) 45 | print("ok " .. k .. " - call g") 46 | local print = print 47 | print("ok 9 - local") 48 | 49 | -- Local Variables: 50 | -- mode: lua 51 | -- lua-indent-level: 4 52 | -- fill-column: 100 53 | -- End: 54 | -- vim: ft=lua expandtab shiftwidth=4: 55 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/TestMore/002-table.t: -------------------------------------------------------------------------------- 1 | #! /usr/bin/lua 2 | -- 3 | -- lua-TestMore : 4 | -- 5 | -- Copyright (C) 2009, Perrad Francois 6 | -- 7 | -- This code is licensed under the terms of the MIT/X11 license, 8 | -- like Lua itself. 9 | -- 10 | 11 | --[[ 12 | 13 | =head1 Lua table 14 | 15 | =head2 Synopsis 16 | 17 | % prove 002-table.t 18 | 19 | =head2 Description 20 | 21 | See "Programming in Lua", section 2.5 "Tables". 22 | 23 | =cut 24 | 25 | ]] 26 | 27 | print("1..8") 28 | 29 | a = {"ok 1", "ok 2", "ok 3"} 30 | print(a[1]) 31 | i = 2 32 | print(a[i]) 33 | print(a[i+1]) 34 | if #a == 3 then 35 | print("ok 4 - len") 36 | else 37 | print("not ok 4") 38 | end 39 | if a[7] == nil then 40 | print("ok 5") 41 | else 42 | print("not ok 5") 43 | end 44 | 45 | t = {a=10, b=100} 46 | if t['a'] == 10 then 47 | print("ok 6") 48 | else 49 | print("not ok 6") 50 | end 51 | if t.b == 100 then 52 | print("ok 7") 53 | else 54 | print("not ok 7") 55 | end 56 | if t.z == nil then 57 | print("ok 8") 58 | else 59 | print("not ok 8") 60 | end 61 | 62 | -- Local Variables: 63 | -- mode: lua 64 | -- lua-indent-level: 4 65 | -- fill-column: 100 66 | -- End: 67 | -- vim: ft=lua expandtab shiftwidth=4: 68 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/TestRunner.cs: -------------------------------------------------------------------------------- 1 | namespace WattleScript.Interpreter.Tests; 2 | 3 | public class TestRunner 4 | { 5 | public static void Skip() 6 | { 7 | NUnit.Framework.TestContext.WriteLine("Skipping Test"); 8 | } 9 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter.Tests/WattleScript.Interpreter.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | disable 6 | 7 | false 8 | 9 | WattleScript.Tests 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | all 18 | runtime; build; native; contentfiles; analyzers; buildtransitive 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Always 28 | 29 | 30 | Always 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/CoreLib/IO/BinaryEncoding.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace WattleScript.Interpreter.CoreLib.IO 4 | { 5 | class BinaryEncoding : Encoding 6 | { 7 | public BinaryEncoding() 8 | : base() 9 | { 10 | 11 | } 12 | 13 | public override int GetByteCount(char[] chars, int index, int count) 14 | { 15 | return count; 16 | } 17 | 18 | public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) 19 | { 20 | for (int i = 0; i < charCount; i++) 21 | { 22 | bytes[byteIndex + i] = (byte)((int)chars[charIndex + i]); 23 | } 24 | 25 | return charCount; 26 | } 27 | 28 | public override int GetCharCount(byte[] bytes, int index, int count) 29 | { 30 | return count; 31 | } 32 | 33 | public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) 34 | { 35 | for (int i = 0; i < byteCount; i++) 36 | { 37 | chars[charIndex + i] = (char)((int)bytes[byteIndex + i]); 38 | } 39 | 40 | return byteCount; 41 | } 42 | 43 | public override int GetMaxByteCount(int charCount) 44 | { 45 | return charCount; 46 | } 47 | 48 | public override int GetMaxCharCount(int byteCount) 49 | { 50 | return byteCount; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/CoreLib/IO/FileUserData.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Text; 3 | 4 | namespace WattleScript.Interpreter.CoreLib.IO 5 | { 6 | /// 7 | /// Abstract class implementing a file Lua userdata. Methods are meant to be called by Lua code. 8 | /// 9 | internal class FileUserData : StreamFileUserDataBase 10 | { 11 | public FileUserData(Script script, string filename, Encoding encoding, string mode) 12 | { 13 | Stream stream = Script.GlobalOptions.Platform.IO_OpenFile(script, filename, encoding, mode); 14 | 15 | StreamReader reader = (stream.CanRead) ? new StreamReader(stream, encoding) : null; 16 | StreamWriter writer = (stream.CanWrite) ? new StreamWriter(stream, encoding) : null; 17 | 18 | base.Initialize(stream, reader, writer); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/CoreLib/IO/StandardIOFileUserDataBase.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace WattleScript.Interpreter.CoreLib.IO 4 | { 5 | /// 6 | /// Abstract class implementing an unclosable file Lua userdata. Methods are meant to be called by Lua code. 7 | /// 8 | internal class StandardIOFileUserDataBase : StreamFileUserDataBase 9 | { 10 | protected override string Close() 11 | { 12 | return ("cannot close standard file"); 13 | } 14 | 15 | public static StandardIOFileUserDataBase CreateInputStream(Stream stream) 16 | { 17 | var f = new StandardIOFileUserDataBase(); 18 | f.Initialize(stream, new StreamReader(stream), null); 19 | return f; 20 | } 21 | 22 | public static StandardIOFileUserDataBase CreateOutputStream(Stream stream) 23 | { 24 | var f = new StandardIOFileUserDataBase(); 25 | f.Initialize(stream, null, new StreamWriter(stream) { AutoFlush = true }); 26 | return f; 27 | } 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataStructs/ReferenceEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace WattleScript.Interpreter.DataStructs 4 | { 5 | /// 6 | /// Implementation of IEqualityComparer enforcing reference equality 7 | /// 8 | internal class ReferenceEqualityComparer : IEqualityComparer 9 | { 10 | bool IEqualityComparer.Equals(object x, object y) 11 | { 12 | return object.ReferenceEquals(x, y); 13 | } 14 | 15 | int IEqualityComparer.GetHashCode(object obj) 16 | { 17 | return obj.GetHashCode(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/Annotation.cs: -------------------------------------------------------------------------------- 1 | namespace WattleScript.Interpreter 2 | { 3 | public class Annotation 4 | { 5 | public string Name { get; private set; } 6 | public DynValue Value { get; private set; } 7 | 8 | public Annotation(string name, DynValue value) 9 | { 10 | Name = name; 11 | Value = value; 12 | } 13 | 14 | public override string ToString() 15 | { 16 | return $"{Name}: {Value}"; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/CoroutineState.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter 3 | { 4 | /// 5 | /// State of coroutines 6 | /// 7 | public enum CoroutineState 8 | { 9 | /// 10 | /// This is the main coroutine 11 | /// 12 | Main, 13 | /// 14 | /// Coroutine has not started yet 15 | /// 16 | NotStarted, 17 | /// 18 | /// Coroutine is suspended 19 | /// 20 | Suspended, 21 | /// 22 | /// Coroutine has been forcefully suspended (i.e. auto-yielded) 23 | /// 24 | ForceSuspended, 25 | /// 26 | /// Coroutine is running 27 | /// 28 | Running, 29 | /// 30 | /// Coroutine has terminated 31 | /// 32 | Dead 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/MemberModifierFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | [Flags] 6 | public enum MemberModifierFlags 7 | { 8 | None = 0, 9 | Static = 1 << 0, 10 | Private = 1 << 1, 11 | Public = 1 << 2, 12 | Sealed = 1 << 3 13 | } 14 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/PreprocessorDefineType.cs: -------------------------------------------------------------------------------- 1 | namespace WattleScript.Interpreter 2 | { 3 | public enum PreprocessorDefineType 4 | { 5 | Empty, 6 | Boolean, 7 | Number, 8 | String 9 | } 10 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/Range.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace WattleScript.Interpreter 5 | { 6 | public class Range : RefIdObject 7 | { 8 | /// 9 | /// Inclusive start 10 | /// 11 | public int From { get; set; } 12 | 13 | /// 14 | /// Inclusive end 15 | /// 16 | public int To { get; set; } 17 | 18 | public Script OwnerScript { get; } 19 | 20 | public Range(Script ownerScript, int from, int to) 21 | { 22 | OwnerScript = ownerScript; 23 | From = from; 24 | To = to; 25 | } 26 | 27 | public override string ToString() 28 | { 29 | return $"Range ({From} - {To})"; 30 | } 31 | 32 | internal IEnumerable ReversePair 33 | { 34 | get 35 | { 36 | var x = Enumerable.Range(From, To - From + 1).Select(x => DynValue.NewNumber(x)); 37 | return x; 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/RefIdObject.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter 3 | { 4 | /// 5 | /// A base class for many WattleScript objects. 6 | /// Helds a ReferenceID property which gets a different value for every object instance, for debugging 7 | /// purposes. Note that the ID is not assigned in a thread safe manner for speed reason, so the IDs 8 | /// are guaranteed to be unique only if everything is running on one thread at a time. 9 | /// 10 | public class RefIdObject 11 | { 12 | private static int s_RefIDCounter = 0; 13 | private int m_RefID = ++s_RefIDCounter; 14 | 15 | /// 16 | /// Gets the reference identifier. 17 | /// 18 | /// 19 | /// The reference identifier. 20 | /// 21 | public int ReferenceID { get { return m_RefID; } } 22 | 23 | 24 | /// 25 | /// Formats a string with a type name and a ref-id 26 | /// 27 | /// The type name. 28 | /// 29 | public string FormatTypeString(string typeString) 30 | { 31 | return string.Format("{0}: {1:X8}", typeString, m_RefID); 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/ScriptFunctionDelegate.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter 3 | { 4 | /// 5 | /// A Delegate type which can wrap a script function 6 | /// 7 | /// The arguments. 8 | /// The return value of the script function 9 | public delegate object ScriptFunctionDelegate(params object[] args); 10 | /// 11 | /// A Delegate type which can wrap a script function with a generic typed return value 12 | /// 13 | /// 14 | /// The arguments. 15 | /// The return value of the script function 16 | public delegate T ScriptFunctionDelegate(params object[] args); 17 | } 18 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/SymbolRefType.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter 3 | { 4 | /// 5 | /// Enumeration of the types of SymbolRef 6 | /// 7 | public enum SymbolRefType 8 | { 9 | /// 10 | /// The symbol ref of a local variable 11 | /// 12 | Local, 13 | /// 14 | /// The symbol ref of an upvalue variable 15 | /// 16 | Upvalue, 17 | /// 18 | /// The symbol ref of a global variable 19 | /// 20 | Global, 21 | /// 22 | /// The symbol ref of the global environment 23 | /// 24 | DefaultEnv, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/TableKind.cs: -------------------------------------------------------------------------------- 1 | namespace WattleScript.Interpreter 2 | { 3 | public enum TableKind 4 | { 5 | /// 6 | /// Regular Table 7 | /// 8 | Normal, 9 | /// 10 | /// Table initialised as an enum 11 | /// 12 | Enum, 13 | /// 14 | /// Table initialised as a class 15 | /// 16 | Class, 17 | /// 18 | /// Table initialised as a mixin 19 | /// 20 | Mixin 21 | } 22 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/TablePair.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter 3 | { 4 | /// 5 | /// A class representing a key/value pair for Table use 6 | /// 7 | public struct TablePair 8 | { 9 | private static TablePair s_NilNode = new TablePair(DynValue.Nil, DynValue.Nil); 10 | private DynValue key, value; 11 | 12 | /// 13 | /// Gets the key. 14 | /// 15 | public DynValue Key 16 | { 17 | get { return key; } 18 | private set { Key = key; } 19 | } 20 | 21 | /// 22 | /// Gets or sets the value. 23 | /// 24 | public DynValue Value 25 | { 26 | get { return value; } 27 | set { if (key.IsNotNil()) Value = value; } 28 | } 29 | 30 | 31 | /// 32 | /// Initializes a new instance of the struct. 33 | /// 34 | /// The key. 35 | /// The value. 36 | public TablePair(DynValue key, DynValue val) 37 | { 38 | this.key = key; 39 | this.value = val; 40 | } 41 | 42 | /// 43 | /// Gets the nil pair 44 | /// 45 | public static TablePair Nil { get { return s_NilNode; } } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/TailCallData.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter 3 | { 4 | /// 5 | /// Class used to support "tail" continuations - a way for C# / Lua interaction which supports 6 | /// coroutine yielding (at the expense of a LOT of added complexity in calling code). 7 | /// 8 | public class TailCallData 9 | { 10 | /// 11 | /// Gets or sets the function to call 12 | /// 13 | public DynValue Function { get; set; } 14 | /// 15 | /// Gets or sets the arguments to the function 16 | /// 17 | public DynValue[] Args { get; set; } 18 | /// 19 | /// Gets or sets the callback to be used as a continuation. 20 | /// 21 | public CallbackFunction Continuation { get; set; } 22 | /// 23 | /// Gets or sets the callback to be used in case of errors. 24 | /// 25 | public CallbackFunction ErrorHandler { get; set; } 26 | /// 27 | /// Gets or sets the error handler to be called before stack unwinding 28 | /// 29 | public DynValue ErrorHandlerBeforeUnwind { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/TypeValidationFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | /// 6 | /// Flags to alter the way the DynValue.CheckType and other related functions operate on data types for 7 | /// validation. 8 | /// 9 | [Flags] 10 | public enum TypeValidationFlags 11 | { 12 | /// 13 | /// No type validation specific behaviour 14 | /// 15 | None = 0, 16 | /// 17 | /// Nil and Void values are allowed (and returned by the call) 18 | /// 19 | AllowNil = 0x1, 20 | /// 21 | /// Simple autoconversions are attempted: 22 | /// 1) Numbers are convertible to strings 23 | /// 2) Strings are convertible to numbers if they contain a number 24 | /// 3) Everything is convertible to boolean (with void and nil converting to 'false', everything else converting to 'true') 25 | /// Note: if both AutoConvert and AllowNil are specified, nils will NOT be converted to false booleans. 26 | /// 27 | AutoConvert = 0x2, 28 | 29 | /// 30 | /// The default : Autoconverting values, no nils. 31 | /// 32 | Default = AutoConvert 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/WattleMemberInfo.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter.Tree; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | internal class WattleMemberInfo 6 | { 7 | public string Name => Token.Text; 8 | public MemberModifierFlags Flags { get; set; } 9 | public Expression Expr { get; set; } 10 | public Token Token { get; set; } 11 | public bool IsFunction { get; set; } 12 | 13 | public WattleMemberInfo(Token token, Expression expr, MemberModifierFlags flags, bool isFunction) 14 | { 15 | Token = token; 16 | Expr = expr; 17 | Flags = flags; 18 | IsFunction = isFunction; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/WattleMemberType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | [Flags] 6 | internal enum WattleMemberType 7 | { 8 | Enum = 0, 9 | Class = 1 << 0, 10 | Mixin = 1 << 1, 11 | ClassMember = 1 << 2, 12 | MixinMember = 1 << 3, 13 | EnumMember = 1 << 4, 14 | Any = Enum | Class | Mixin | ClassMember | MixinMember | EnumMember 15 | } 16 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/WattleMembersInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace WattleScript.Interpreter 5 | { 6 | public sealed class WattleMembersInfo 7 | { 8 | public IReadOnlyDictionary Modifiers => i_Modifiers; 9 | 10 | internal readonly Dictionary i_Modifiers = new Dictionary(); 11 | 12 | public bool MemberHasModifier(string memberName, MemberModifierFlags modifier) 13 | { 14 | return MemberHasModifier(DynValue.NewString(memberName), modifier); 15 | } 16 | 17 | public bool MemberHasModifier(DynValue memberName, MemberModifierFlags modifier) 18 | { 19 | if (memberName.Type != DataType.String) return false; 20 | return i_Modifiers.TryGetValue(memberName.String, out MemberModifierFlags flags) && flags.HasFlag(modifier); 21 | } 22 | 23 | internal void Merge(WattleMembersInfo parent) 24 | { 25 | parent.i_Modifiers.ToList().ForEach(x => i_Modifiers[x.Key] = x.Value); 26 | } 27 | 28 | internal WattleMembersInfo() { } 29 | } 30 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/WellKnownSymbols.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter 3 | { 4 | /// 5 | /// Constants of well known "symbols" in the WattleScript grammar 6 | /// 7 | public static class WellKnownSymbols 8 | { 9 | /// 10 | /// The variadic argument symbol ("...") 11 | /// 12 | public const string VARARGS = "..."; 13 | 14 | /// 15 | /// The environment symbol ("_ENV") 16 | /// 17 | public const string ENV = "_ENV"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/DataTypes/YieldRequest.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter 3 | { 4 | /// 5 | /// Class wrapping a request to yield a coroutine 6 | /// 7 | public class YieldRequest 8 | { 9 | /// 10 | /// The return values of the coroutine 11 | /// 12 | public DynValue[] ReturnValues; 13 | 14 | /// 15 | /// Gets or sets a value indicating whether this is a forced yield. 16 | /// 17 | public bool Forced { get; internal set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Debugging/DebugService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WattleScript.Interpreter.Execution.VM; 6 | 7 | namespace WattleScript.Interpreter.Debugging 8 | { 9 | /// 10 | /// Class providing services specific to debugger implementations. 11 | /// 12 | /// 13 | public sealed class DebugService : IScriptPrivateResource 14 | { 15 | Processor m_Processor; 16 | 17 | internal DebugService(Script script, Processor processor) 18 | { 19 | OwnerScript = script; 20 | m_Processor = processor; 21 | } 22 | 23 | /// 24 | /// Gets the script owning this resource. 25 | /// 26 | /// 27 | /// The script owning this resource. 28 | /// 29 | public Script OwnerScript { get; private set; } 30 | 31 | /// 32 | /// Resets the break points for a given file. Supports only line-based breakpoints. 33 | /// 34 | /// The source. 35 | /// The lines. 36 | /// The lines for which breakpoints have been set 37 | public HashSet ResetBreakPoints(SourceCode src, HashSet lines) 38 | { 39 | return m_Processor.ResetBreakPoints(src, lines); 40 | } 41 | 42 | 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Debugging/DebuggerCaps.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WattleScript.Interpreter.Debugging 7 | { 8 | /// 9 | /// Enumeration of capabilities for a debugger 10 | /// 11 | [Flags] 12 | public enum DebuggerCaps 13 | { 14 | /// 15 | /// Flag set if the debugger can debug source code 16 | /// 17 | CanDebugSourceCode = 0x1, 18 | /// 19 | /// Flag set if the can debug VM bytecode 20 | /// 21 | CanDebugByteCode = 0x2, 22 | /// 23 | /// Flag set if the debugger uses breakpoints based on lines instead of tokens 24 | /// 25 | HasLineBasedBreakpoints = 0x4 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Debugging/WatchType.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter.Debugging 3 | { 4 | /// 5 | /// Enumeration of the possible watch types 6 | /// 7 | public enum WatchType 8 | { 9 | /// 10 | /// A real variable watch 11 | /// 12 | Watches, 13 | /// 14 | /// The status of the v-stack 15 | /// 16 | VStack, 17 | /// 18 | /// The call stack 19 | /// 20 | CallStack, 21 | /// 22 | /// The list of coroutines 23 | /// 24 | Coroutines, 25 | /// 26 | /// Topmost local variables 27 | /// 28 | Locals, 29 | /// 30 | /// The list of currently active coroutines 31 | /// 32 | Threads, 33 | /// 34 | /// The maximum value of this enum 35 | /// 36 | MaxValue 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Diagnostics/PerformanceCounter.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter.Diagnostics 3 | { 4 | /// 5 | /// Enumeration of the possible performance counters 6 | /// 7 | public enum PerformanceCounter 8 | { 9 | /// 10 | /// Measures the time spent parsing the source creating the AST 11 | /// 12 | AstCreation, 13 | /// 14 | /// Measures the time spent converting ASTs in bytecode 15 | /// 16 | Compilation, 17 | /// 18 | /// Measures the time spent in executing scripts 19 | /// 20 | Execution, 21 | /// 22 | /// Measures the on the fly creation/compilation of functions in userdata descriptors 23 | /// 24 | AdaptersCompilation, 25 | 26 | /// 27 | /// Sentinel value to get the enum size 28 | /// 29 | LastValue 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Diagnostics/PerformanceCounterType.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter.Diagnostics 3 | { 4 | /// 5 | /// Enumeration of unit of measures of the performance counters 6 | /// 7 | public enum PerformanceCounterType 8 | { 9 | /// 10 | /// The performance counter is specified in bytes (of memory) 11 | /// 12 | MemoryBytes, 13 | /// 14 | /// The performance counter is specified in milliseconds 15 | /// 16 | TimeMilliseconds, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Diagnostics/PerformanceCounters/DummyPerformanceStopwatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Diagnostics.PerformanceCounters 4 | { 5 | class DummyPerformanceStopwatch : IPerformanceStopwatch, IDisposable 6 | { 7 | public static DummyPerformanceStopwatch Instance = new DummyPerformanceStopwatch(); 8 | PerformanceResult m_Result; 9 | 10 | private DummyPerformanceStopwatch() 11 | { 12 | m_Result = new PerformanceResult() 13 | { 14 | Counter = 0, 15 | Global = true, 16 | Instances = 0, 17 | Name = "::dummy::", 18 | Type = PerformanceCounterType.TimeMilliseconds 19 | }; 20 | } 21 | 22 | 23 | public IDisposable Start() 24 | { 25 | return this; 26 | } 27 | 28 | public PerformanceResult GetResult() 29 | { 30 | return m_Result; 31 | } 32 | 33 | public void Dispose() 34 | { 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Diagnostics/PerformanceCounters/IPerformanceStopwatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Diagnostics.PerformanceCounters 4 | { 5 | internal interface IPerformanceStopwatch 6 | { 7 | IDisposable Start(); 8 | PerformanceResult GetResult(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Diagnostics/PerformanceCounters/PerformanceStopwatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace WattleScript.Interpreter.Diagnostics.PerformanceCounters 5 | { 6 | /// 7 | /// This class is not *really* IDisposable.. it's just use to have a RAII like pattern. 8 | /// You are free to reuse this instance after calling Dispose. 9 | /// 10 | internal class PerformanceStopwatch : IDisposable, IPerformanceStopwatch 11 | { 12 | Stopwatch m_Stopwatch = new Stopwatch(); 13 | int m_Count = 0; 14 | int m_Reentrant = 0; 15 | PerformanceCounter m_Counter; 16 | 17 | public PerformanceStopwatch(PerformanceCounter perfcounter) 18 | { 19 | m_Counter = perfcounter; 20 | } 21 | 22 | 23 | public IDisposable Start() 24 | { 25 | if (m_Reentrant == 0) 26 | { 27 | m_Count += 1; 28 | m_Stopwatch.Start(); 29 | } 30 | 31 | m_Reentrant += 1; 32 | 33 | return this; 34 | } 35 | 36 | public void Dispose() 37 | { 38 | m_Reentrant -= 1; 39 | 40 | if (m_Reentrant == 0) 41 | { 42 | m_Stopwatch.Stop(); 43 | } 44 | } 45 | 46 | public PerformanceResult GetResult() 47 | { 48 | return new PerformanceResult() 49 | { 50 | Type = PerformanceCounterType.TimeMilliseconds, 51 | Global = false, 52 | Name = m_Counter.ToString(), 53 | Instances = m_Count, 54 | Counter = m_Stopwatch.ElapsedMilliseconds 55 | }; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Errors/DynamicExpressionException.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | 4 | namespace WattleScript.Interpreter 5 | { 6 | /// 7 | /// Exception thrown when a dynamic expression is invalid 8 | /// 9 | [Serializable] 10 | public class DynamicExpressionException : ScriptRuntimeException 11 | { 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// The format. 16 | /// The arguments. 17 | public DynamicExpressionException(string format, params object[] args) 18 | : base(": " + format, args) 19 | { 20 | 21 | } 22 | /// 23 | /// Initializes a new instance of the class. 24 | /// 25 | /// The message. 26 | public DynamicExpressionException(string message) 27 | : base(": " + message) 28 | { 29 | 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Errors/InternalErrorException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | /// 6 | /// Exception thrown when an inconsistent state is reached in the interpreter 7 | /// 8 | [Serializable] 9 | public class InternalErrorException : InterpreterException 10 | { 11 | internal InternalErrorException(string message) 12 | : base(message) 13 | { 14 | 15 | } 16 | 17 | internal InternalErrorException(string format, params object[] args) 18 | : base(format, args) 19 | { 20 | 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/Scopes/ClosureContext.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace WattleScript.Interpreter.Execution 5 | { 6 | /// 7 | /// The scope of a closure (container of upvalues) 8 | /// 9 | internal class ClosureContext : List 10 | { 11 | /// 12 | /// Gets the symbols. 13 | /// 14 | public string[] Symbols { get; private set; } 15 | 16 | internal ClosureContext(SymbolRef[] symbols, IEnumerable values) 17 | { 18 | Symbols = symbols.Select(s => s.i_Name).ToArray(); 19 | this.AddRange(values); 20 | } 21 | 22 | internal ClosureContext() 23 | { 24 | Symbols = new string[0]; 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/Scopes/IClosureBuilder.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter.Execution 3 | { 4 | internal interface IClosureBuilder 5 | { 6 | SymbolRef CreateUpvalue(BuildTimeScope scope, SymbolRef symbol); 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/Scopes/LoopTracker.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter.DataStructs; 2 | using WattleScript.Interpreter.Execution.VM; 3 | 4 | namespace WattleScript.Interpreter.Execution 5 | { 6 | interface ILoop 7 | { 8 | void CompileBreak(FunctionBuilder bc); 9 | void CompileContinue(FunctionBuilder bc); 10 | bool IsBoundary(); 11 | bool IsSwitch(); 12 | } 13 | 14 | 15 | internal class LoopTracker 16 | { 17 | public FastStack Loops = new FastStack(32, 16384); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/Scopes/RuntimeScopeBlock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Execution 4 | { 5 | internal class RuntimeScopeBlock 6 | { 7 | public int From { get; internal set; } 8 | public int To { get; internal set; } 9 | public int ToInclusive { get; internal set; } 10 | 11 | public override string ToString() 12 | { 13 | return String.Format("ScopeBlock : {0} -> {1} --> {2}", From, To, ToInclusive); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/Scopes/RuntimeScopeFrame.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace WattleScript.Interpreter.Execution 4 | { 5 | internal class RuntimeScopeFrame 6 | { 7 | public List DebugSymbols { get; private set; } 8 | public int Count { get { return DebugSymbols.Count; } } 9 | public int ToFirstBlock { get; internal set; } 10 | 11 | public RuntimeScopeFrame() 12 | { 13 | DebugSymbols = new List(); 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return string.Format("ScopeFrame : #{0}", Count); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/Scopes/Upvalue.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using WattleScript.Interpreter.DataStructs; 3 | 4 | namespace WattleScript.Interpreter.Execution 5 | { 6 | /// 7 | /// Holds a reference to a local in another function 8 | /// 9 | internal class Upvalue 10 | { 11 | public FastStack ParentScope; 12 | public int Index; 13 | private DynValue storage; 14 | 15 | private static int s = 1; 16 | private int _refID; 17 | public int ReferenceID { get => _refID; } 18 | 19 | public Upvalue(FastStack parentScope, int index) 20 | { 21 | ParentScope = parentScope; 22 | Index = index; 23 | _refID = Interlocked.Increment(ref s); 24 | } 25 | 26 | protected Upvalue() 27 | { 28 | } 29 | 30 | public void Close() 31 | { 32 | storage = ParentScope[Index]; 33 | ParentScope = null; 34 | } 35 | 36 | public ref DynValue Value() 37 | { 38 | if(ParentScope != null) 39 | return ref ParentScope[Index]; 40 | return ref storage; 41 | } 42 | 43 | public static Upvalue NewNil() => new Upvalue(); 44 | public static Upvalue Create(DynValue obj) => new Upvalue() {storage = obj}; 45 | } 46 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/ScriptLoadingContext.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using WattleScript.Interpreter.Debugging; 3 | using WattleScript.Interpreter.Tree; 4 | 5 | namespace WattleScript.Interpreter.Execution 6 | { 7 | class ScriptLoadingContext 8 | { 9 | public Script Script { get; private set; } 10 | public BuildTimeScope Scope { get; set; } 11 | public SourceCode Source { get; set; } 12 | public bool Anonymous { get; set; } 13 | public bool IsDynamicExpression { get; set; } 14 | public Lexer Lexer { get; set; } 15 | 16 | public ScriptSyntax Syntax { get; set; } 17 | 18 | //Compiler state 19 | internal List ChunkAnnotations { get; set; } = new List(); 20 | internal List FunctionAnnotations { get; set; } = new List(); 21 | 22 | 23 | public ScriptLoadingContext(Script s) 24 | { 25 | Script = s; 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/VM/CallStackItem.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using WattleScript.Interpreter.Debugging; 3 | 4 | namespace WattleScript.Interpreter.Execution.VM 5 | { 6 | internal struct CallStackItem 7 | { 8 | public bool IsNil => BasePointer == 0; 9 | 10 | public FunctionProto Function; 11 | 12 | public SourceRef CallingSourceRef; 13 | 14 | public CallbackFunction ClrFunction; 15 | public CallbackFunction Continuation; 16 | public CallbackFunction ErrorHandler; 17 | public DynValue ErrorHandlerBeforeUnwind; 18 | 19 | public int BasePointer; 20 | public int ReturnAddress; 21 | 22 | public List OpenClosures; 23 | public ClosureContext ClosureScope; 24 | 25 | public CallStackItemFlags Flags; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/VM/CallStackItemFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Execution.VM 4 | { 5 | [Flags] 6 | internal enum CallStackItemFlags 7 | { 8 | None = 0, 9 | 10 | EntryPoint = 1, 11 | ResumeEntryPoint = 3, 12 | CallEntryPoint = 5, 13 | 14 | TailCall = 0x10, 15 | MethodCall = 0x20, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/VM/ExecutionState.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter.DataStructs; 2 | 3 | namespace WattleScript.Interpreter.Execution.VM 4 | { 5 | internal sealed class ExecutionState 6 | { 7 | public FastStack ValueStack = new FastStack(1024, 131072); 8 | public FastStack ExecutionStack = new FastStack(1024, 131072); 9 | public int InstructionPtr = 0; 10 | public CoroutineState State = CoroutineState.NotStarted; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/VM/Processor/DebugContext.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using WattleScript.Interpreter.Debugging; 3 | 4 | namespace WattleScript.Interpreter.Execution.VM 5 | { 6 | sealed partial class Processor 7 | { 8 | private class DebugContext 9 | { 10 | public bool DebuggerEnabled = true; 11 | public IDebugger DebuggerAttached = null; 12 | public DebuggerAction.ActionType DebuggerCurrentAction = DebuggerAction.ActionType.None; 13 | public int DebuggerCurrentActionTarget = -1; 14 | public SourceRef LastHlRef = null; 15 | public int ExStackDepthAtStep = -1; 16 | public List BreakPoints = new List(); 17 | public bool LineBasedBreakPoints = false; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Execution/VM/Processor/Processor_Errors.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter.Debugging; 2 | 3 | namespace WattleScript.Interpreter.Execution.VM 4 | { 5 | sealed partial class Processor 6 | { 7 | private SourceRef GetCurrentSourceRef(int instructionPtr) 8 | { 9 | var code = m_ExecutionStack.Peek().Function?.sourceRefs; 10 | if (code == null) return null; 11 | if (instructionPtr >= 0 && instructionPtr < code.Length) 12 | { 13 | return code[instructionPtr]; 14 | } 15 | return null; 16 | } 17 | 18 | 19 | private void FillDebugData(InterpreterException ex, int ip) 20 | { 21 | // adjust IP 22 | if (ip == YIELD_SPECIAL_TRAP) 23 | ip = m_SavedInstructionPtr; 24 | else 25 | ip -= 1; 26 | 27 | ex.InstructionPtr = ip; 28 | 29 | SourceRef sref = GetCurrentSourceRef(ip); 30 | 31 | ex.DecorateMessage(m_Script, sref, ip); 32 | 33 | ex.CallStack = Debugger_GetCallStack(sref); 34 | } 35 | 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel; 3 | using System.Linq; 4 | using System.Reflection; 5 | using WattleScript.Interpreter.Debugging; 6 | 7 | namespace WattleScript.Interpreter 8 | { 9 | public static class Extensions 10 | { 11 | public static string GetSourceFragment(this SourceRef[] refs, string fullSourceCode) 12 | { 13 | if (refs == null) 14 | { 15 | return ""; 16 | } 17 | 18 | SourceRef firstNotNull = refs.FirstOrDefault(x => x != null); 19 | SourceRef lastNotNull = refs.LastOrDefault(x => x != null); 20 | 21 | if (firstNotNull != null && lastNotNull == null) 22 | { 23 | return fullSourceCode.Substring(firstNotNull.FromCharIndex, firstNotNull.ToCharIndex - firstNotNull.FromCharIndex); 24 | } 25 | 26 | if (firstNotNull == null && lastNotNull != null) 27 | { 28 | return fullSourceCode.Substring(lastNotNull.FromCharIndex, lastNotNull.ToCharIndex - lastNotNull.FromCharIndex); 29 | } 30 | 31 | return fullSourceCode.Substring(firstNotNull?.FromCharIndex ?? 0, lastNotNull?.ToCharIndex - firstNotNull?.FromCharIndex ?? 0); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/Attributes/WattleScriptHiddenAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | /// 6 | /// Forces a class member visibility to scripts. Can be used to hide public members. Equivalent to WattleScriptVisible(false). 7 | /// 8 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field 9 | | AttributeTargets.Constructor | AttributeTargets.Event, Inherited = true, AllowMultiple = false)] 10 | public sealed class WattleScriptHiddenAttribute : Attribute 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/Attributes/WattleScriptHideMemberAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | /// 6 | /// Lists a userdata member not to be exposed to scripts referencing it by name. 7 | /// 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = true, AllowMultiple = true)] 9 | public sealed class WattleScriptHideMemberAttribute : Attribute 10 | { 11 | /// 12 | /// Gets the name of the member to be hidden. 13 | /// 14 | public string MemberName { get; private set; } 15 | 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// Name of the member to hide. 20 | public WattleScriptHideMemberAttribute(string memberName) 21 | { 22 | MemberName = memberName; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/Attributes/WattleScriptPropertyAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | 6 | /// 7 | /// Marks a property as a configruation property 8 | /// 9 | [AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = true)] 10 | public sealed class WattleScriptPropertyAttribute : Attribute 11 | { 12 | /// 13 | /// The metamethod name (like '__div', '__ipairs', etc.) 14 | /// 15 | public string Name { get; private set; } 16 | 17 | 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | public WattleScriptPropertyAttribute() 22 | { 23 | 24 | } 25 | 26 | /// 27 | /// Initializes a new instance of the class. 28 | /// 29 | /// The name for this property 30 | public WattleScriptPropertyAttribute(string name) 31 | { 32 | Name = name; 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/Attributes/WattleScriptUserDataAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | /// 6 | /// Marks a type of automatic registration as userdata (which happens only if UserData.RegisterAssembly is called). 7 | /// 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] 9 | public sealed class WattleScriptUserDataAttribute : Attribute 10 | { 11 | /// 12 | /// The interop access mode 13 | /// 14 | public InteropAccessMode AccessMode { get; set; } 15 | 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | public WattleScriptUserDataAttribute() 20 | { 21 | AccessMode = InteropAccessMode.Default; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/Attributes/WattleScriptUserDataMetamethodAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | /// 6 | /// Marks a method as the handler of metamethods of a userdata type 7 | /// 8 | [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = true)] 9 | public sealed class WattleScriptUserDataMetamethodAttribute : Attribute 10 | { 11 | /// 12 | /// The metamethod name (like '__div', '__ipairs', etc.) 13 | /// 14 | public string Name { get; private set; } 15 | 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// The metamethod name (like '__div', '__ipairs', etc.) 20 | public WattleScriptUserDataMetamethodAttribute(string name) 21 | { 22 | Name = name; 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/Attributes/WattleScriptVisibleAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Interop 4 | { 5 | /// 6 | /// Forces a class member visibility to scripts. Can be used to hide public members or to expose non-public ones. 7 | /// 8 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field 9 | | AttributeTargets.Constructor | AttributeTargets.Event, Inherited = true, AllowMultiple = false)] 10 | public sealed class WattleScriptVisibleAttribute : Attribute 11 | { 12 | /// 13 | /// Gets a value indicating whether this is set to "visible". 14 | /// 15 | public bool Visible { get; private set; } 16 | 17 | /// 18 | /// Initializes a new instance of the class. 19 | /// 20 | /// if set to true the member will be exposed to scripts, if false the member will be hidden. 21 | public WattleScriptVisibleAttribute(bool visible) 22 | { 23 | Visible = visible; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/BasicDescriptors/IOptimizableDescriptor.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter.Interop.BasicDescriptors 3 | { 4 | /// 5 | /// Interface for descriptors of any kind which support optimizations of their implementation according to InteropAccessMode 6 | /// modes. This should seldom - if ever - be implemented in user code. 7 | /// 8 | public interface IOptimizableDescriptor 9 | { 10 | /// 11 | /// Called by standard descriptors when background optimization or preoptimization needs to be performed. 12 | /// 13 | void Optimize(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/BasicDescriptors/MemberDescriptorAccess.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Interop.BasicDescriptors 4 | { 5 | /// 6 | /// Permissions for members access 7 | /// 8 | [Flags] 9 | public enum MemberDescriptorAccess 10 | { 11 | /// 12 | /// The member can be read from 13 | /// 14 | CanRead = 1, 15 | /// 16 | /// The member can be written to 17 | /// 18 | CanWrite = 2, 19 | /// 20 | /// The can be invoked 21 | /// 22 | CanExecute = 4 23 | } 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/Converters/StringConversions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace WattleScript.Interpreter.Interop.Converters 5 | { 6 | internal static class StringConversions 7 | { 8 | internal enum StringSubtype 9 | { 10 | None, 11 | String, 12 | StringBuilder, 13 | Char 14 | } 15 | 16 | internal static StringSubtype GetStringSubtype(Type desiredType) 17 | { 18 | if (desiredType == typeof(string)) 19 | return StringSubtype.String; 20 | else if (desiredType == typeof(StringBuilder)) 21 | return StringSubtype.StringBuilder; 22 | else if (desiredType == typeof(char)) 23 | return StringSubtype.Char; 24 | else 25 | return StringSubtype.None; 26 | } 27 | 28 | 29 | internal static object ConvertString(StringSubtype stringSubType, string str, Type desiredType, DataType dataType) 30 | { 31 | switch (stringSubType) 32 | { 33 | case StringSubtype.String: 34 | return str; 35 | case StringSubtype.StringBuilder: 36 | return new StringBuilder(str); 37 | case StringSubtype.Char: 38 | if (!string.IsNullOrEmpty(str)) 39 | return str[0]; 40 | break; 41 | case StringSubtype.None: 42 | default: 43 | break; 44 | } 45 | 46 | throw ScriptRuntimeException.ConvertObjectFailed(dataType, desiredType); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/IWireableDescriptor.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter.Interop.BasicDescriptors 3 | { 4 | /// 5 | /// Interface for descriptors with the capability of being serialized 6 | /// for later hardwiring. 7 | /// 8 | public interface IWireableDescriptor 9 | { 10 | /// 11 | /// Prepares the descriptor for hard-wiring. 12 | /// The descriptor fills the passed table with all the needed data for hardwire generators to generate the appropriate code. 13 | /// 14 | /// The table to be filled 15 | void PrepareForWiring(Table t); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/PredefinedUserData/AnonWrapper.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter.Interop 3 | { 4 | /// 5 | /// Internal type used by for registration 6 | /// 7 | public class AnonWrapper 8 | { 9 | } 10 | 11 | /// 12 | /// Wrapper which allows for easier management of userdata without registering a new userdata type - useful 13 | /// if a type which is not exposed to scripts but can be managed as a "black box" by scripts is desired. 14 | /// 15 | /// The type to wrap 16 | public class AnonWrapper : AnonWrapper 17 | { 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | public AnonWrapper() 22 | { 23 | } 24 | 25 | /// 26 | /// Initializes a new instance of the class. 27 | /// 28 | /// The o. 29 | public AnonWrapper(T o) 30 | { 31 | Value = o; 32 | } 33 | 34 | /// 35 | /// Gets or sets the value this instance wraps. 36 | /// 37 | public T Value { get; set; } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/ProxyObjects/IProxyFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Interop 4 | { 5 | /// 6 | /// Interface for proxy objects (type unsafe version) 7 | /// 8 | public interface IProxyFactory 9 | { 10 | /// 11 | /// Takes an instance of a target object and returns a proxy object wrapping it 12 | /// 13 | object CreateProxyObject(object o); 14 | /// 15 | /// Gets the proxied type 16 | /// 17 | Type TargetType { get; } 18 | /// 19 | /// Gets the proxy type 20 | /// 21 | Type ProxyType { get; } 22 | } 23 | 24 | /// 25 | /// Interface for proxy objects (type safe version) 26 | /// 27 | /// The type of the proxy. 28 | /// The type of the target. 29 | public interface IProxyFactory : IProxyFactory 30 | where TProxy : class 31 | where TTarget : class 32 | { 33 | /// 34 | /// Takes an instance of a target object and returns a proxy object wrapping it 35 | /// 36 | TProxy CreateProxyObject(TTarget target); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/ReflectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace WattleScript.Interpreter.Interop 5 | { 6 | static class ReflectionExtensions 7 | { 8 | const BindingFlags BINDINGFLAGS_MEMBER = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; 9 | 10 | public static ConstructorInfo[] GetAllConstructors(this Type type) 11 | { 12 | return type.GetConstructors(BINDINGFLAGS_MEMBER); 13 | } 14 | 15 | public static EventInfo[] GetAllEvents(this Type type) 16 | { 17 | return type.GetEvents(BINDINGFLAGS_MEMBER); 18 | } 19 | 20 | public static FieldInfo[] GetAllFields(this Type type) 21 | { 22 | return type.GetFields(BINDINGFLAGS_MEMBER); 23 | } 24 | 25 | public static MethodInfo[] GetAllMethods(this Type type) 26 | { 27 | return type.GetMethods(BINDINGFLAGS_MEMBER); 28 | } 29 | 30 | public static PropertyInfo[] GetAllProperties(this Type type) 31 | { 32 | return type.GetProperties(BINDINGFLAGS_MEMBER); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/RegistrationPolicies/AutomaticRegistrationPolicy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Interop.RegistrationPolicies 4 | { 5 | /// 6 | /// Similar to , but with automatic type registration is disabled. 7 | /// 8 | public class AutomaticRegistrationPolicy : DefaultRegistrationPolicy 9 | { 10 | /// 11 | /// Allows type automatic registration for the specified type. 12 | /// NOTE: automatic type registration is NOT recommended. 13 | /// 14 | /// The type. 15 | /// 16 | /// True to register the type automatically, false otherwise. 17 | /// 18 | public override bool AllowTypeAutoRegistration(Type type) 19 | { 20 | return true; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/RegistrationPolicies/IRegistrationPolicy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Interop.RegistrationPolicies 4 | { 5 | /// 6 | /// Interface for managing how to handle 7 | /// 8 | public interface IRegistrationPolicy 9 | { 10 | /// 11 | /// Called to handle the registration or deregistration of a type descriptor. Must return the type descriptor to be registered, or null to remove the registration. 12 | /// 13 | /// The new descriptor, or null if this is a deregistration. 14 | /// The old descriptor, or null if no descriptor was previously registered for this type. 15 | /// 16 | IUserDataDescriptor HandleRegistration(IUserDataDescriptor newDescriptor, IUserDataDescriptor oldDescriptor); 17 | 18 | /// 19 | /// Allows type automatic registration for the specified type. 20 | /// NOTE: automatic type registration is NOT recommended. 21 | /// 22 | /// The type. 23 | /// True to register the type automatically, false otherwise. 24 | bool AllowTypeAutoRegistration(Type type); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/StandardDescriptors/HardwiredDescriptors/DefaultValue.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors 3 | { 4 | public sealed class DefaultValue 5 | { 6 | public static readonly DefaultValue Instance = new DefaultValue(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/StandardDescriptors/HardwiredDescriptors/HardwiredMethodMemberDescriptor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using WattleScript.Interpreter.Interop.BasicDescriptors; 3 | 4 | namespace WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors 5 | { 6 | public abstract class HardwiredMethodMemberDescriptor : FunctionMemberDescriptorBase 7 | { 8 | public override DynValue Execute(Script script, object obj, ScriptExecutionContext context, CallbackArguments args) 9 | { 10 | this.CheckAccess(MemberDescriptorAccess.CanExecute, obj); 11 | 12 | List outParams = null; 13 | object[] pars = base.BuildArgumentList(script, obj, context, args, out outParams); 14 | object retv = Invoke(script, obj, pars, CalcArgsCount(pars)); 15 | 16 | return DynValue.FromObject(script, retv); 17 | } 18 | 19 | private int CalcArgsCount(object[] pars) 20 | { 21 | int count = pars.Length; 22 | 23 | for(int i = 0; i < pars.Length; i++) 24 | if (Parameters[i].HasDefaultValue && (pars[i] is DefaultValue)) 25 | { 26 | count -= 1; 27 | } 28 | 29 | return count; 30 | } 31 | 32 | protected abstract object Invoke(Script script, object obj, object[] pars, int argscount); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/StandardDescriptors/HardwiredDescriptors/HardwiredUserDataDescriptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using WattleScript.Interpreter.Interop.BasicDescriptors; 3 | 4 | namespace WattleScript.Interpreter.Interop.StandardDescriptors.HardwiredDescriptors 5 | { 6 | public abstract class HardwiredUserDataDescriptor : DispatchingUserDataDescriptor 7 | { 8 | protected HardwiredUserDataDescriptor(Type T) : 9 | base(T, "::hardwired::" + T.Name) 10 | { 11 | 12 | } 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Interop/UserDataMemberType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WattleScript.Interpreter.Interop 7 | { 8 | public enum UserDataMemberType 9 | { 10 | Constructor, 11 | Method, 12 | Property, 13 | Field, 14 | Event 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Loaders/FileSystemScriptLoader.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace WattleScript.Interpreter.Loaders 4 | { 5 | /// 6 | /// A script loader loading scripts directly from the file system (does not go through platform object) 7 | /// 8 | public class FileSystemScriptLoader : ScriptLoaderBase 9 | { 10 | /// 11 | /// Checks if a script file exists. 12 | /// 13 | /// The script filename. 14 | /// 15 | public override bool ScriptFileExists(string name) 16 | { 17 | return File.Exists(name); 18 | } 19 | 20 | /// 21 | /// Opens a file for reading the script code. 22 | /// It can return either a string, a byte[] or a Stream. 23 | /// If a byte[] is returned, the content is assumed to be a serialized (dumped) bytecode. If it's a string, it's 24 | /// assumed to be either a script or the output of a string.dump call. If a Stream, autodetection takes place. 25 | /// 26 | /// The file. 27 | /// The global context. 28 | /// 29 | /// A string, a byte[] or a Stream. 30 | /// 31 | public override object LoadFile(string file, Table globalContext) 32 | { 33 | return new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Loaders/InvalidScriptLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter.Loaders 4 | { 5 | /// 6 | /// A script loader used for platforms we cannot initialize in any better way.. 7 | /// 8 | internal class InvalidScriptLoader : IScriptLoader 9 | { 10 | string m_Error; 11 | 12 | internal InvalidScriptLoader(string frameworkname) 13 | { 14 | m_Error = string.Format( 15 | @"Loading scripts from files is not automatically supported on {0}. 16 | Please implement your own IScriptLoader (possibly, extending ScriptLoaderBase for easier implementation), 17 | use a preexisting loader like EmbeddedResourcesScriptLoader or UnityAssetsScriptLoader or load scripts from strings.", frameworkname); 18 | } 19 | 20 | public object LoadFile(string file, Table globalContext) 21 | { 22 | throw new PlatformNotSupportedException(m_Error); 23 | } 24 | 25 | public string ResolveFileName(string filename, Table globalContext) 26 | { 27 | return filename; 28 | } 29 | 30 | public string ResolveModuleName(string modname, Table globalContext) 31 | { 32 | throw new PlatformNotSupportedException(m_Error); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Modules/WattleScriptModuleAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | /// 6 | /// Marks a CLR type to be a WattleScript module. 7 | /// Modules are the fastest way to bring interop between scripts and CLR code, albeit at the cost of a very increased 8 | /// complexity in writing them. Modules is what's used for the standard library, for maximum efficiency. 9 | /// 10 | /// Modules are basically classes containing only static methods, with the callback function signature. 11 | /// 12 | /// See and for (extension) methods used to register modules to a 13 | /// table. 14 | /// 15 | /// See for information regarding the standard callback signature along with easier ways 16 | /// to marshal methods. 17 | /// 18 | /// See for easier object marshalling. 19 | /// 20 | [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] 21 | public sealed class WattleScriptModuleAttribute : Attribute 22 | { 23 | /// 24 | /// Gets or sets the namespace, that is the name of the table which will contain the defined functions. 25 | /// Can be null to be in the global table. 26 | /// 27 | public string Namespace { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Modules/WattleScriptModuleConstantAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | /// 6 | /// In a module type, mark fields with this attribute to have them exposed as a module constant. 7 | /// 8 | /// See for more information about modules. 9 | /// 10 | [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] 11 | public sealed class WattleScriptModuleConstantAttribute : Attribute 12 | { 13 | /// 14 | /// Gets or sets the name of the constant - if different from the name of the field itself 15 | /// 16 | public string Name { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Modules/WattleScriptModuleMethodAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter 4 | { 5 | /// 6 | /// In a module type, mark methods or fields with this attribute to have them exposed as module functions. 7 | /// Methods must have the signature "public static DynValue ...(ScriptExecutionContextCallbackArguments)". 8 | /// Fields must be static or const strings, with an anonymous Lua function inside. 9 | /// 10 | /// See for more information about modules. 11 | /// 12 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field, Inherited = false, AllowMultiple = false)] 13 | public sealed class WattleScriptModuleMethodAttribute : Attribute 14 | { 15 | /// 16 | /// Gets or sets the name of the function in the module (defaults to member name) 17 | /// 18 | public string Name { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Options/ColonOperatorBehaviour.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WattleScript.Interpreter 7 | { 8 | /// 9 | /// Defines behaviour of the colon ':' operator in CLR callbacks. 10 | /// Default behaviour is for ':' being treated the same as a '.' if the functions is implemented on the CLR side (e.g. in C#). 11 | /// 12 | public enum ColonOperatorBehaviour 13 | { 14 | /// 15 | /// The colon is treated the same as the dot ('.') operator. 16 | /// 17 | TreatAsDot, 18 | /// 19 | /// The colon is treated the same as the dot ('.') operator if the first argument is userdata, as a Lua colon operator otherwise. 20 | /// 21 | TreatAsDotOnUserData, 22 | /// 23 | /// The colon is treated in the same as the Lua colon operator works. 24 | /// 25 | TreatAsColon 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Options/FuzzySymbolMatchingBehavior.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WattleScript.Interpreter { 4 | 5 | /// 6 | /// A flag that controls if/how symbols (method, property, userdata) are fuzzily matched when they do not exist. Flags can be combined for multiple checks. 7 | /// 8 | [Flags] 9 | public enum FuzzySymbolMatchingBehavior { 10 | 11 | /// No fuzzy matching is performed. 12 | None = 0, 13 | 14 | /// The first letter of a symbol will be uppercased (to check for common C# naming conventions). For example, testMethod() becomes TestMethod() 15 | UpperFirstLetter = 1, 16 | 17 | /// Underscores in symbols are converted to camelcase. For example, test_method() becomes testMethod() 18 | Camelify = 2, 19 | 20 | /// 21 | /// Converts a symbol to pascal case. For example, test_Method_two() becomes TestMethodTwo() 22 | /// 23 | PascalCase = 4 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Options/ScriptSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace WattleScript.Interpreter 2 | { 3 | /// 4 | /// Defines the syntax used by the compiler 5 | /// 6 | public enum ScriptSyntax 7 | { 8 | /// 9 | /// Standard Lua syntax + lambdas 10 | /// 11 | Lua, 12 | /// 13 | /// Wattle syntax 14 | /// e.g. ++ and -- operators 15 | /// 16 | Wattle 17 | } 18 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Platforms/StandardFileType.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace WattleScript.Interpreter.Platforms 3 | { 4 | /// 5 | /// Enumeration of standard file handles 6 | /// 7 | public enum StandardFileType 8 | { 9 | /// 10 | /// Standard Input 11 | /// 12 | StdIn, 13 | /// 14 | /// Standard Output 15 | /// 16 | StdOut, 17 | /// 18 | /// Standard Error Output 19 | /// 20 | StdErr 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Serialization/Json/JsonNull.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace WattleScript.Interpreter.Serialization.Json 7 | { 8 | /// 9 | /// UserData representing a null value in a table converted from Json 10 | /// 11 | public sealed class JsonNull 12 | { 13 | public static bool isNull() { return true; } 14 | 15 | [WattleScriptHidden] 16 | public static bool IsJsonNull(DynValue v) 17 | { 18 | return v.Type == DataType.UserData && 19 | v.UserData.Descriptor != null && 20 | v.UserData.Descriptor.Type == typeof(JsonNull); 21 | } 22 | 23 | [WattleScriptHidden] 24 | public static DynValue Create() 25 | { 26 | return UserData.CreateStatic(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Expressions/AdjustmentExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using WattleScript.Interpreter.DataStructs; 3 | using WattleScript.Interpreter.Execution; 4 | 5 | 6 | namespace WattleScript.Interpreter.Tree.Expressions 7 | { 8 | class AdjustmentExpression : Expression 9 | { 10 | private Expression expression; 11 | 12 | public AdjustmentExpression(ScriptLoadingContext lcontext, Expression exp) 13 | : base(lcontext) 14 | { 15 | expression = exp; 16 | } 17 | 18 | public override void Compile(Execution.VM.FunctionBuilder bc) 19 | { 20 | expression.Compile(bc); 21 | //TODO: Add more tests, make sure this opt is 100% correct 22 | if (expression is FunctionCallExpression) 23 | { 24 | bc.Emit_Scalar(); 25 | } 26 | } 27 | 28 | public override DynValue Eval(ScriptExecutionContext context) 29 | { 30 | return expression.Eval(context).ToScalar(); 31 | } 32 | 33 | public override void ResolveScope(ScriptLoadingContext lcontext) 34 | { 35 | expression.ResolveScope(lcontext); 36 | } 37 | 38 | public override bool EvalLiteral(out DynValue dv, IDictionary symbols = null) 39 | { 40 | if (expression.EvalLiteral(out dv, symbols)) 41 | { 42 | dv = dv.ToScalar(); 43 | return true; 44 | } 45 | return false; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Expressions/DynamicExprExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using WattleScript.Interpreter.Execution; 4 | 5 | namespace WattleScript.Interpreter.Tree.Expressions 6 | { 7 | class DynamicExprExpression : Expression 8 | { 9 | Expression m_Exp; 10 | 11 | public DynamicExprExpression(Expression exp, ScriptLoadingContext lcontext) 12 | : base(lcontext) 13 | { 14 | lcontext.Anonymous = true; 15 | m_Exp = exp; 16 | } 17 | 18 | public override void ResolveScope(ScriptLoadingContext lcontext) 19 | { 20 | m_Exp.ResolveScope(lcontext); 21 | } 22 | 23 | public override DynValue Eval(ScriptExecutionContext context) 24 | { 25 | return m_Exp.Eval(context); 26 | } 27 | 28 | public override bool EvalLiteral(out DynValue dv, IDictionary symbols = null) 29 | { 30 | throw new InvalidOperationException(); 31 | } 32 | 33 | public override void Compile(Execution.VM.FunctionBuilder bc) 34 | { 35 | throw new InvalidOperationException(); 36 | } 37 | 38 | public override SymbolRef FindDynamic(ScriptExecutionContext context) 39 | { 40 | return m_Exp.FindDynamic(context); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/IVariable.cs: -------------------------------------------------------------------------------- 1 |  2 | using WattleScript.Interpreter.Tree.Expressions; 3 | 4 | namespace WattleScript.Interpreter.Tree 5 | { 6 | interface IVariable 7 | { 8 | void CompileAssignment(Execution.VM.FunctionBuilder bc, Operator op, int stackofs, int tupleidx); 9 | 10 | bool IsAssignment { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Loop.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using WattleScript.Interpreter.Execution; 4 | using WattleScript.Interpreter.Execution.VM; 5 | 6 | namespace WattleScript.Interpreter.Tree 7 | { 8 | internal class Loop : ILoop 9 | { 10 | public RuntimeScopeBlock Scope; 11 | public List BreakJumps = new List(); 12 | public List ContinueJumps = new List(); 13 | public bool Switch = false; 14 | 15 | public void CompileBreak(FunctionBuilder bc) 16 | { 17 | bc.Emit_Exit(Scope); 18 | BreakJumps.Add(bc.Emit_Jump(OpCode.Jump, -1)); 19 | } 20 | 21 | public void CompileContinue(FunctionBuilder bc) 22 | { 23 | ContinueJumps.Add(bc.Emit_Jump(OpCode.Jump, -1)); 24 | } 25 | 26 | public bool IsBoundary() 27 | { 28 | return false; 29 | } 30 | 31 | public bool IsSwitch() => Switch; 32 | } 33 | 34 | internal class LoopBoundary : ILoop 35 | { 36 | public void CompileBreak(FunctionBuilder bc) 37 | { 38 | throw new InternalErrorException("CompileBreak called on LoopBoundary"); 39 | } 40 | 41 | public void CompileContinue(FunctionBuilder bc) 42 | { 43 | throw new InternalErrorException("CompileBreak called on LoopBoundary"); 44 | } 45 | 46 | public bool IsBoundary() 47 | { 48 | return true; 49 | } 50 | 51 | public bool IsSwitch() => false; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Preprocessor/DefineNode.cs: -------------------------------------------------------------------------------- 1 | namespace WattleScript.Interpreter.Tree 2 | { 3 | class DefineNode 4 | { 5 | public int StartLine; 6 | public int EndLine; 7 | public PreprocessorDefine Define; 8 | public DefineNode Next; 9 | } 10 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Statements/BreakStatement.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter.Debugging; 2 | using WattleScript.Interpreter.Execution; 3 | using WattleScript.Interpreter.Execution.VM; 4 | 5 | 6 | namespace WattleScript.Interpreter.Tree.Statements 7 | { 8 | class BreakStatement : Statement 9 | { 10 | SourceRef m_Ref; 11 | 12 | public BreakStatement(ScriptLoadingContext lcontext) 13 | : base(lcontext) 14 | { 15 | m_Ref = CheckTokenType(lcontext, TokenType.Break).GetSourceRef(); 16 | lcontext.Source.Refs.Add(m_Ref); 17 | } 18 | 19 | public override void ResolveScope(ScriptLoadingContext lcontext) 20 | { 21 | //no-op 22 | } 23 | 24 | 25 | public override void Compile(FunctionBuilder bc) 26 | { 27 | using (bc.EnterSource(m_Ref)) 28 | { 29 | if (bc.LoopTracker.Loops.Count == 0) 30 | throw new SyntaxErrorException(this.Script, m_Ref, " at line {0} not inside a loop", m_Ref.FromLine); 31 | 32 | ILoop loop = bc.LoopTracker.Loops.Peek(); 33 | 34 | if (loop.IsBoundary()) 35 | throw new SyntaxErrorException(this.Script, m_Ref, " at line {0} not inside a loop", m_Ref.FromLine); 36 | 37 | loop.CompileBreak(bc); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Statements/ContinueStatement.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter.Debugging; 2 | using WattleScript.Interpreter.Execution; 3 | using WattleScript.Interpreter.Execution.VM; 4 | 5 | 6 | namespace WattleScript.Interpreter.Tree.Statements 7 | { 8 | class ContinueStatement : Statement 9 | { 10 | SourceRef m_Ref; 11 | 12 | public ContinueStatement(ScriptLoadingContext lcontext) 13 | : base(lcontext) 14 | { 15 | m_Ref = CheckTokenType(lcontext, TokenType.Continue).GetSourceRef(); 16 | lcontext.Source.Refs.Add(m_Ref); 17 | } 18 | 19 | public override void ResolveScope(ScriptLoadingContext lcontext) 20 | { 21 | //No-op 22 | } 23 | 24 | 25 | public override void Compile(FunctionBuilder bc) 26 | { 27 | using (bc.EnterSource(m_Ref)) 28 | { 29 | if (bc.LoopTracker.Loops.Count == 0) 30 | throw new SyntaxErrorException(this.Script, m_Ref, " at line {0} not inside a loop", m_Ref.FromLine); 31 | 32 | ILoop loop = bc.LoopTracker.Loops.Peek(); 33 | 34 | if (loop.IsBoundary() || loop.IsSwitch()) 35 | throw new SyntaxErrorException(this.Script, m_Ref, " at line {0} not inside a loop", m_Ref.FromLine); 36 | 37 | loop.CompileContinue(bc); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Statements/EmptyStatement.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter.Execution; 2 | 3 | namespace WattleScript.Interpreter.Tree.Statements 4 | { 5 | class EmptyStatement : Statement 6 | { 7 | public EmptyStatement(ScriptLoadingContext lcontext) 8 | : base(lcontext) 9 | { 10 | } 11 | 12 | public override void ResolveScope(ScriptLoadingContext lcontext) 13 | { 14 | //No-op 15 | } 16 | 17 | 18 | public override void Compile(Execution.VM.FunctionBuilder bc) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Statements/FunctionCallStatement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using WattleScript.Interpreter.Execution; 3 | using WattleScript.Interpreter.Execution.VM; 4 | using WattleScript.Interpreter.Tree.Expressions; 5 | 6 | namespace WattleScript.Interpreter.Tree.Statements 7 | { 8 | class FunctionCallStatement : Statement 9 | { 10 | FunctionCallExpression m_FunctionCallExpression; 11 | 12 | public FunctionCallStatement(ScriptLoadingContext lcontext, FunctionCallExpression functionCallExpression) 13 | : base(lcontext) 14 | { 15 | m_FunctionCallExpression = functionCallExpression; 16 | lcontext.Source.Refs.Add(m_FunctionCallExpression.SourceRef); 17 | } 18 | 19 | public override void ResolveScope(ScriptLoadingContext lcontext) 20 | { 21 | m_FunctionCallExpression.ResolveScope(lcontext); 22 | } 23 | 24 | 25 | public override void Compile(FunctionBuilder bc) 26 | { 27 | using (bc.EnterSource(m_FunctionCallExpression.SourceRef)) 28 | { 29 | m_FunctionCallExpression.Compile(bc); 30 | bc.Emit_Pop(); 31 | bc.SourceRefs[bc.SourceRefs.Count - 1] = null; //Remove breakpoint stop 32 | } 33 | } 34 | 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Statements/IBlockStatement.cs: -------------------------------------------------------------------------------- 1 | using WattleScript.Interpreter.Debugging; 2 | 3 | namespace WattleScript.Interpreter.Tree.Statements 4 | { 5 | interface IBlockStatement 6 | { 7 | SourceRef End { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/Tree/Statements/NewCallStatement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using WattleScript.Interpreter.Execution; 3 | using WattleScript.Interpreter.Execution.VM; 4 | using WattleScript.Interpreter.Tree.Expressions; 5 | 6 | namespace WattleScript.Interpreter.Tree.Statements 7 | { 8 | class NewCallStatement : Statement 9 | { 10 | NewExpression newExpression; 11 | 12 | public NewCallStatement(ScriptLoadingContext lcontext, NewExpression newExpression) : base(lcontext) 13 | { 14 | this.newExpression = newExpression; 15 | lcontext.Source.Refs.Add(newExpression.SourceRef); 16 | } 17 | 18 | public override void ResolveScope(ScriptLoadingContext lcontext) 19 | { 20 | newExpression.ResolveScope(lcontext); 21 | } 22 | 23 | public override void Compile(FunctionBuilder bc) 24 | { 25 | using (bc.EnterSource(newExpression.SourceRef)) 26 | { 27 | newExpression.Compile(bc); 28 | bc.Emit_Pop(); 29 | bc.SourceRefs[bc.SourceRefs.Count - 1] = null; //Remove breakpoint stop 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/WattleScript.Interpreter/WattleScript.Interpreter.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | 8 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/WattleScript/Commands/CommandManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using WattleScript.Interpreter; 6 | 7 | namespace WattleScript.Commands 8 | { 9 | static class CommandManager 10 | { 11 | static Dictionary m_Registry = new Dictionary(); 12 | 13 | public static void Initialize() 14 | { 15 | foreach (Type t in Assembly.GetExecutingAssembly().GetTypes() 16 | .Where(tt => typeof(ICommand).IsAssignableFrom(tt)) 17 | .Where(tt => tt.IsClass && (!tt.IsAbstract)) 18 | ) 19 | { 20 | object o = Activator.CreateInstance(t); 21 | ICommand cmd = (ICommand)o; 22 | if (cmd != null) 23 | { 24 | m_Registry.Add(cmd.Name, cmd); 25 | } 26 | } 27 | } 28 | 29 | public static void Execute(Script context, string commandLine) 30 | { 31 | 32 | } 33 | 34 | public static IEnumerable GetCommands() 35 | { 36 | yield return m_Registry["help"]; 37 | 38 | foreach (ICommand cmd in m_Registry.Values.Where(c => c is not HelpCommand).OrderBy(c => c.Name)) 39 | { 40 | yield return cmd; 41 | } 42 | } 43 | 44 | public static ICommand Find(string cmd) 45 | { 46 | return m_Registry.ContainsKey(cmd) ? m_Registry[cmd] : null; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/WattleScript/Commands/ICommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WattleScript.Interpreter; 6 | 7 | namespace WattleScript.Commands 8 | { 9 | interface ICommand 10 | { 11 | string Name { get; } 12 | void DisplayShortHelp(Script context); 13 | void DisplayLongHelp(Script context); 14 | void Execute(Script context, string argument); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/WattleScript/Commands/Implementations/CompileCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using WattleScript.Interpreter; 7 | 8 | namespace WattleScript.Commands.Implementations 9 | { 10 | class CompileCommand : ICommand 11 | { 12 | public string Name => "compile"; 13 | 14 | public void DisplayShortHelp(Script context) 15 | { 16 | Console.WriteLine("compile - Compiles the file in a binary format"); 17 | } 18 | 19 | public void DisplayLongHelp(Script context) 20 | { 21 | Console.WriteLine("compile - Compiles the file in a binary format.\nThe destination filename will be appended with '-compiled'."); 22 | } 23 | 24 | public void Execute(Script context, string p) 25 | { 26 | string targetFileName = p + "-compiled"; 27 | 28 | Script s = new Script(CoreModules.None); 29 | s.Options.Syntax = context.Options.Syntax; 30 | DynValue chunk = s.LoadFile(p); 31 | 32 | using Stream stream = new FileStream(targetFileName, FileMode.Create, FileAccess.Write); 33 | s.Dump(chunk, stream); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/WattleScript/Commands/Implementations/DumpBytecodeCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using WattleScript.Interpreter; 7 | 8 | namespace WattleScript.Commands.Implementations 9 | { 10 | class DumpBytecodeCommand : ICommand 11 | { 12 | public string Name => "dumpbc"; 13 | 14 | public void DisplayShortHelp(Script context) 15 | { 16 | Console.WriteLine("dumpbc - Dumps human-readable bytecode for the file"); 17 | } 18 | 19 | public void DisplayLongHelp(Script context) 20 | { 21 | Console.WriteLine("printbc - Dumps human-readable bytecode for the file.\nThe destination filename will be appended with '-bytecode.txt'."); 22 | } 23 | 24 | public void Execute(Script context, string p) 25 | { 26 | string targetFileName = p + "-bytecode.txt"; 27 | 28 | Script s = new Script(CoreModules.None); 29 | s.Options.Syntax = context.Options.Syntax; 30 | DynValue chunk = s.LoadFile(p); 31 | 32 | File.WriteAllText(targetFileName, s.DumpString(chunk)); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/WattleScript/Commands/Implementations/ExitCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WattleScript.Interpreter; 6 | 7 | namespace WattleScript.Commands.Implementations 8 | { 9 | class ExitCommand : ICommand 10 | { 11 | public string Name => "exit"; 12 | 13 | public void DisplayShortHelp(Script context) 14 | { 15 | Console.WriteLine("exit - Exits the interpreter"); 16 | } 17 | 18 | public void DisplayLongHelp(Script context) 19 | { 20 | Console.WriteLine("exit - Exits the interpreter"); 21 | } 22 | 23 | public void Execute(Script context, string arguments) 24 | { 25 | Environment.Exit(0); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/WattleScript/Commands/Implementations/RegisterCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WattleScript.Interpreter; 6 | 7 | namespace WattleScript.Commands.Implementations 8 | { 9 | class RegisterCommand : ICommand 10 | { 11 | public string Name => "register"; 12 | 13 | public void DisplayShortHelp(Script context) 14 | { 15 | Console.WriteLine("register [type] - register a CLR type or prints a list of registered types"); 16 | } 17 | 18 | public void DisplayLongHelp(Script context) 19 | { 20 | Console.WriteLine("register [type] - register a CLR type or prints a list of registered types. Use makestatic('type') to make a static instance."); 21 | } 22 | 23 | public void Execute(Script context, string argument) 24 | { 25 | if (argument.Length > 0) 26 | { 27 | Type t = Type.GetType(argument); 28 | if (t == null) 29 | Console.WriteLine("Type {0} not found.", argument); 30 | else 31 | UserData.RegisterType(t); 32 | } 33 | else 34 | { 35 | foreach (var type in UserData.GetRegisteredTypes()) 36 | { 37 | Console.WriteLine(type.FullName); 38 | } 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/WattleScript/Commands/Implementations/RunCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using WattleScript.Interpreter; 6 | 7 | namespace WattleScript.Commands.Implementations 8 | { 9 | class RunCommand : ICommand 10 | { 11 | public string Name => "run"; 12 | 13 | public void DisplayShortHelp(Script context) 14 | { 15 | Console.WriteLine($"run - Executes the specified {context.Options.Syntax} script"); 16 | } 17 | 18 | public void DisplayLongHelp(Script context) 19 | { 20 | Console.WriteLine($"run - Executes the specified {context.Options.Syntax} script."); 21 | } 22 | 23 | public void Execute(Script context, string arguments) 24 | { 25 | if (arguments.Length == 0) 26 | { 27 | Console.WriteLine("Syntax : !run "); 28 | } 29 | else 30 | { 31 | context.DoFile(arguments); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/WattleScript/WattleScript.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/WattleScript/wattlescript.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WattleScript/wattlescript/90a70a4b0d5d0f314725df2733610cb522827cc8/src/WattleScript/wattlescript.ico --------------------------------------------------------------------------------