Commit Graph

808 Commits (61962fe70abd22a665446cc09fcef163bf0e3862)

Author SHA1 Message Date
Lukas Werling 61962fe70a Add --check/-c parameter to c4script for syntax checking 2016-12-23 17:18:00 +01:00
Nicolas Hake 60829ae5e4 Aul: Don't let exceptions escape from constant resolver
Letting the constant resolver throw exceptions prevented us from doing
checking on later initializers anyway, so instead we'll send them to the
error handler. As a special bonus this makes it so we don't crash when
a global variable initializer has errors. Fixes #1850, #1855.
2016-11-30 13:37:33 +01:00
Sven Eberhardt c5623aa7a2 Fix crash on script error in DirectExec scripts 2016-11-20 13:14:57 -05:00
Nicolas Hake 34bdab6ba5 Aul: Don't force assertions active
Assertions are great for debugging, but in public builds they just kill
apps dead.
2016-11-13 11:07:22 +01:00
Nicolas Hake eda6cc9c7f Aul: Gracefully handle errors in codegen (#1840)
By continuing to generate bytecode even after an error is found, we're
able to find more syntax errors and will also be able to keep the value
stack at the expected height.
2016-11-13 11:07:21 +01:00
Nicolas Hake ff0325dfac Aul: Always reset the current function when a declaration ends (#1839)
When an error occurred during codegen of a function, the current
function pointer would not be reset to 0, leading to spurious warnings
about redeclaration of functions.
2016-11-13 11:07:01 +01:00
Sven Eberhardt 072e1dcde0 Editor graph delegate: Add update callback functionality for graph edits 2016-11-12 22:20:05 -05:00
Sven Eberhardt 91af5a95be Editor graph delegate: Add HorizontalFix, VerticalFix and StructureFix constraints 2016-11-12 22:20:03 -05:00
Lukas Werling 6847e50e79 Implement setting shader uniforms from script (#1206)
Uniform variables are read from the "Uniforms" proplist set on Scenario
or on individual objects. Proplist keys are uniform names. Values can
either be an int or an array of one to four ints in C4Script. In GLSL,
the uniforms then need a matching type (int/ivec2/ivec3/ivec4). There is
no error reporting; uniforms are only set if both name and type match.

The implementation walks the "Uniforms" proplists on each Draw call. We
may need to cache the uniform maps if this turns out to be too slow.
2016-11-12 22:09:23 +01:00
Sven Eberhardt bf9c940aa6 Editor graph delegate: Add edge and vertex properties. Remove graph storage options.
The different storage options weren't really needed and would not work with edge and vertex delegates.
2016-11-10 21:43:43 -05:00
Sven Eberhardt 1e52ed5a74 Remove unused variable ndx in C4AulParse::Parse_Expression 2016-11-10 21:43:41 -05:00
Sven Eberhardt ebda8193ef Replace NULL by nullptr in C++ sources
We don't support pre-C++0x any more, so nullptr should be fine everywhere (except in the plain C source files)
2016-11-02 19:58:02 -04:00
Sven Eberhardt 54e8c14666 Editor: Add graph, polyline and polygon shape delegates 2016-11-02 09:54:31 -04:00
Lukas Werling 9c98227a03 Fix all -Wformat warnings 2016-10-31 23:39:45 +01:00
Nicolas Hake 194e7d709b Aul codegen: Handle errors at codegen time better (#1837)
If a parse error occurs inside a declaration, the codegen should just go
on and deal with the next declaration instead of completely giving up on
the entire script.
2016-10-31 11:17:43 +01:00
Nicolas Hake f0f50ec402 Aul: Don't prepend "ERROR:" to parser error msgs
Further formatting of the error message should be the error handler's
job.
2016-10-31 11:16:14 +01:00
Nicolas Hake 3c13c88f56 Aul: Count errors and warnings properly
9caaf1e introduced an external error handler for easier testing of
error conditions. The default error handler needs to count errors and
warnings if we want to display them, but didn't.
2016-10-31 11:15:19 +01:00
Sven Eberhardt f2231e848e AulCompiler: Fix static parameter type check 2016-10-24 22:00:30 -04:00
Julius Michaelis 376ca5a9df Prevent using USE_CONSOLE in lib{misc,c4script} 2016-10-22 17:42:23 +02:00
Nicolas Hake cada67c097 Prohibit overriding local vars with functions (#1831)
The old parser threw a standard compile error in this case; the
AST-based parser threw an ICE, which is ultimately the same thing but
made it sound like the parser was at fault. And maybe it is, and we
should allow code like "local a; func a() {}" but that seems like it
should be a conscious design decision.
2016-10-21 22:32:24 +02:00
Julius Michaelis 34a9a1de8d Twiddle with header organization: lib{misc,c4script} do no longer include GL/glew.h
(Yes, it is just that complicated.)
2016-10-20 18:46:32 +02:00
Nicolas Hake e2fd7095c1 Merge branch 'ast'
# Conflicts:
#	src/C4Include.h
#	src/script/C4AulCompiler.cpp
#	src/script/C4AulParse.cpp
#	src/script/C4AulParse.h
#	src/script/C4ScriptHost.cpp
#	src/script/C4ScriptHost.h
#	tests/CMakeLists.txt
2016-10-20 17:33:02 +02:00
Nicolas Hake 266feeda4d Aul: Add AST generation tests
Just making sure the parser creates the AST the way we expect before we
hand off the code to the codegen.
2016-10-20 17:20:55 +02:00
Nicolas Hake 118961d0b7 Aul: fix octal escape parsing
Bet you didn't know C4Script supported octal escapes inside strings.
Well, it didn't; or at least not correctly.
2016-10-20 16:53:23 +02:00
Nicolas Hake 5915f79960 Don't entirely recreate global vars in second compile pass
This allows people to properly cross-reference two proplists from each
proplist's initializer.
2016-10-19 14:20:48 +02:00
Nicolas Hake 021a6e89f5 Implement direct execution of whole function definitions
This implements the changes made in c6e4bfd on the AST-based parser.
2016-10-19 14:20:47 +02:00
Nicolas Hake 1a8db9e109 Make C4ScriptHost store C4Value refs to owned functions
C4Value already handles refcounting properly for us, so we don't need to
do it manually. It might still be worth manually refcounting them
to avoid the boxing/unboxing overhead, but it's only needed at load and
unload so it's not a priority at the moment.
2016-10-19 14:20:46 +02:00
Nicolas Hake 5f3dbdd417 Reject function expressions inside proplists inside functions
These aren't supported by the codegen on account of not working in
savegames.
2016-10-19 14:20:45 +02:00
Nicolas Hake 9caaf1e298 Aul: Split out error handling into a separate class for easier testing
By using an extern error handler in the script engine, we can mock that
handler and make sure something that should fail actually does, instead
of having to parse log messages.
2016-10-19 14:20:41 +02:00
Nicolas Hake f7a04624eb Remove references to functions defined in unloading defs (#1776) 2016-10-19 13:45:59 +02:00
Nicolas Hake ab1e6bd5a4 Allow proplist-local funcs to access vars of their owner's prototype
Thanks to JCaesar for providing this test case.
2016-10-19 13:45:35 +02:00
Nicolas Hake 1b32633806 Add C4LangStringTable::system_string_table def'n to standalone stubs 2016-10-16 20:11:13 +02:00
Sven Eberhardt 06a438e05e Editor object list: Remove effects; add Global and Scenario 2016-10-15 10:06:44 -04:00
Nicolas Hake 66d5ef8b08 Reset codegen target after parsing nested function
Parsing a function expression inside another function failed to reset
the code generator target to the containing function, so all following
bytecode would still be appended to the nested function, leaving the
container broken.
2016-10-12 14:56:54 +02:00
Armin Burgmeier 836927d93c Don't leak static proplists with cyclic references
If a local variable in a definition was set to a proplist inside the
Definition() callback, and that proplist contained cyclic references
then those references were leaked. Typically cyclic references for
script-created proplists are broken in
C4PropListScript::ClearScriptPropLists, however definition proplists
are changed to be static proplists in
C4PropList::FreezeAndMakeStaticRecursively.

To fix this, each script host maintains a list of proplists made static
by FreezeAndMakeStaticRecursively, and explicitly deletes all of these
proplists on Clear().

This leak also leads to an assertion failure inside
C4PropListScript::ClearScriptPropLists in debug mode, and can also be
observed by C4PropList::PropLists not being empty after game clear.

The definition in Objects.ocd/Helpers.ocd/UserAction.ocd constructs
cyclic proplists in its Definition() call. A simpler, more minimal way
to provoke the leak is the following (it provokes the leak but not the
assertion failure):

    local bla;

    func Definition(def)
    {
        bla = {};
        bla.test = { Name="Test222" , Options = { Name="Test333" } };
        bla.test.Options.Link = { Name="Test444", Blub=bla.test };
    }
2016-09-30 17:50:41 -10:00
Lukas Werling 8a09fcc1b1 Increase REPL output depth to 10 (from 1)
This makes working with nested arrays and proplists a lot less annoying.
2016-09-26 16:33:24 +02:00
Lukas Werling 880981ad31 Fix build on systems with non-long regex index types 2016-09-18 19:40:32 +02:00
Lukas Werling fbb8ad5d87 Add RegexSplit() 2016-09-18 11:10:19 +02:00
Lukas Werling 219f81f004 Regex: Fix off-by-one error 2016-09-18 10:49:06 +02:00
Lukas Werling 619ad27a91 Regex: Fix infinite loop with zero-length matches 2016-09-18 01:16:06 +02:00
Lukas Werling d7cd224a4f Add functions RegexReplace, RegexSearch and RegexMatch 2016-09-16 23:46:03 +02:00
Sven Eberhardt 2c20204021 Add C4SECT_ReinitScenario flag for LoadScenarioSection
This also resets the script engine and does player init callbacks. Useful to restart the scenario in the editor.
2016-09-07 01:53:53 -04:00
Sven Eberhardt 5523e685fb Fix script engine assertion on game clear 2016-09-06 01:13:53 -04:00
Sven Eberhardt dee6086e1d Fix access violation in proplist-to-static conversion 2016-09-06 01:09:29 -04:00
Sven Eberhardt 31121d682c Rename option default value function property to DefaultValueFunction
It was "Get" and later "Set", which was always a bit confusing.
2016-09-01 18:32:24 -04:00
Sven Eberhardt 6b9df3118c Sort UserAction evaluators and groups by name
Also merge effect group into ambience group.
2016-08-27 16:46:59 -04:00
Sven Eberhardt e4b4246500 Fix freezing and assignment of static names to child proplists created in Definition()-callbacks (#1798)
Also adjust editor props for the change:
1. enum needs to create a copy, not a reference for the default value of an option if it is defined inline
2. Always use proper GetName() resolution on property group names even if a static name would be available
2016-08-27 02:04:03 -04:00
Sven Eberhardt 5d6ecc8dc8 Fix possible hang on effect execution with timer=1
If a timer=1-effect registered another timer=1-effect into the same object, it could cause an endless loop. This happened if the timer in the sequence object was set to 1.
2016-08-18 00:14:19 -04:00
Sven Eberhardt 4581022411 Fix an aul preparser crash on DirectExec functions parsing
GetLastRetType doesn't work because the preparser does not generate code.

The code looks a bit like this line just got lost somehow?
2016-08-08 15:26:25 -04:00
Sven Eberhardt fc24969899 Add EditorPlacementLimit property
Limits the number of object instances that can be placed of a given def.
2016-08-06 02:36:53 -04:00