Commit Graph

166 Commits (88e5608298005a271c8c9f1db4a6e8e17a7def1c)

Author SHA1 Message Date
Günther Brammer 64e258f814 Use the bytecode parameter for operators as result modifier flag
Previously, the parameter stored the operator number, but that was
only used for the purpose of optimizing unnecessary inc/dec away.
2014-04-19 19:02:22 +02:00
Günther Brammer 082a85228c Script: Constant expressions can access properties of constant proplists 2014-04-19 19:02:22 +02:00
Günther Brammer 4c9f3777c5 Make the script parser a bit more concise
Factor the common if (TokenType != t) UnexpectedToken() into a function.
Write the end-of-list-or-comma as one if and one Match instead of a long
switch-case-statement.
2014-04-19 19:02:22 +02:00
Nicolas Hake e0dc30c59a Update copyright notices
As discussed in http://forum.openclonk.org/topic_show.pl?tid=2917, I
have merged all copyright notices into a single file and referenced that
merged file from each source file.

For the updated source files, the timeline has been split into three
parts:
 1. Pre-RWD code (before 2001)
 2. RWD code (2001 through 2009)
 3. OpenClonk code (2009 and later)
All pre-RWD copyright notices have been left intact, as have RWD-era
copyright notices where the file did not have a RedWolf design copyright
notice but only individual author ones. All copyright notices of the
OpenClonk era have been replaced by a single notice ranging from the
first recorded year to the current year (2013). Mape code did not get a
OpenClonk Team copyright notice because it is somewhat separate from the
main OpenClonk codebase and has only been touched by Armin Burgmeier.
2013-12-23 13:03:19 +01:00
Nicolas Hake 1204d7d2d9 C4Aul: Fix broken reload from incorrect par count
When reloading a function, C4AulParse didn't reset the parameter count.
This resulted in the function's ParCount to eventually increase above
C4AUL_MAX_Par, at which point parameter type checking would access
invalid memory.
2013-11-02 13:40:33 +01:00
Martin Plicht 91f8d32d69 debugger: Make it work again (some issues remaining, setting breakpoints on included scripts is questionable and listener socket setup sometimes hangs..) 2013-10-13 23:03:25 +02:00
Sven Eberhardt 6250ff1766 Silence a few MSVC warnings 2013-04-01 12:48:02 +02:00
Sven Eberhardt 57e63a5275 Added support for scripted maps (Map.c) and documentation. 2013-03-19 00:36:06 +01:00
Günther Brammer 6b097a49c5 Some slight parser cleanups 2013-03-10 17:37:30 +01:00
Günther Brammer a384e1bdbd Make most of C4AulParse private
This finishes the transformation from a struct to share some variables
when the parser was first split into multiple functions to a C++ class.
2013-03-10 17:37:30 +01:00
Günther Brammer 1cf1be1c6d Hold a reference to the temporary proplist used in case of script errors
The parser does not know whether the constant proplist it is about to fill
is missing because it was overwritten by a later local/constant, or because
the preparser was interrupted by a script error and didn't store its
proplist. Thus, the parser cannot simply give up at that point, and in
order to keep things simple it creates a throwaway proplist. This proplist
was thrown away too soon, though.

Thanks to Zapper for the testcase.
2013-02-12 01:11:31 +01:00
Günther Brammer f38670abc3 Script: Functions can shadow global variables
Previously, declaring a global variable could break another script that had
a function with the same name.
2013-01-23 21:36:21 +01:00
Günther Brammer 42608c5209 Remove C4DirectExecScript, use an existing scripthost for the eval function
Since the scripthost isn't used to store the bytecode anymore,
Parse_Expression doesn't modify it anymore. So there is no need for a
temporary one.
2013-01-23 21:36:21 +01:00
Günther Brammer 57c01ac537 Rename C4AulParse::a to C4AulParse::Host and add C4AulParse::Engine
C4AulParse::Host is now only used for local variables and named functions.

Global directexec functions have neither, so they won't need a scripthost
at all anymore.
2013-01-23 21:36:21 +01:00
Günther Brammer ce87faaf9e Fix #including a definition that has local variables with proplists
The missing break meant that the freshly created copy of the proplist would
get overwritten by the original, which was thankfully caught and announced
with "internal error: constant proplist has the wrong parent".

Thanks to Zapper for the testcase.
2013-01-18 01:45:06 +01:00
Günther Brammer 864c5c7ea8 copyright notices update 2012 2013-01-12 16:31:40 +01:00
Günther Brammer 08f86c2038 Script: continue in a do-while loop jumps to test instead of start of loop
This matches C and other languages.
2013-01-08 21:21:11 +01:00
Günther Brammer af62ab7931 Move script bytecode from C4ScriptHost into C4AulScriptFunc
This makes functions independent of their "Code Owner"s, which removes the
necessity to maintain that connection and carefully reset functions when
their scripthost is cleared.
2012-10-21 18:14:32 +02:00
Peter Wortmann 95ad163c29 Fixed warning 2012-11-05 17:17:51 +00:00
Günther Brammer cd147525eb Script: Warn when redefining a global constant 2012-10-23 02:05:33 +02:00
Günther Brammer e0aa23c8ba Rename C4PropList::NewAnon to C4PropList::NewStatic
"Anon" referred to the fact that these proplists have neither a number,
like simple proplists, objects and effects, nor an ID like Definitions.

However, they now store the names of the global constant or property they
are in, so "Anon" is no longer appropriate.

There are now three classes of proplists:
- ordinary proplists (C4PropListScript) have a number only in the savegame
- objects and effects (C4PropListNumbered) always have a number
- proplists created during initialization (C4PropListStatic) have a path

So the function could be called NewNamed, but the source of the proplist
has been far more stable than the method used for serialization, and Static
somewhat describes the source.
2012-08-15 19:43:02 +02:00
Günther Brammer fb9309ec2c Use a pointer to the operator definition instead of an array index
"op->" is a lot shorter than "C4ScriptOpMap[OpID]." Local variables. Use
them.
2012-10-21 16:13:53 +02:00
Günther Brammer a5ac8b341d Remove some superfluous {} from switch-case-constructs
To reduce and unify the indentation levels and reduce the number of lines.
2012-09-04 02:11:16 +02:00
Günther Brammer dc4f3766fe Script: Par(n) needs exactly one parameter, this() exactly zero
Mostly so that Parse_Params doesn't get used for things that are not
functions.
2012-08-13 19:07:56 +02:00
Günther Brammer 791484eb5a Bytecode debug output uses GetDataString for array and proplist constants 2012-10-21 15:51:34 +02:00
Philipp Kern 4f67f73df2 Fix format string use
C4Aul's Warn uses the format attribute to check for format string correctness.
Passing a dynamic string buffer from FormatString to it will break the build
with -Werror=format-string. Given that Warn already does the formatting itself,
just drop the use of FormatString
2012-10-21 11:21:49 +02:00
Günther Brammer 576edc1e23 Fix crash when including a script that nests proplists in a local variable
Previously, only the outer proplist would be copied, but the parser expects
the inner proplists to also be present. Copy proplists deeply instead, as
is already done for functions, and in the linking step.
2012-08-09 01:21:54 +02:00
Günther Brammer bfdc02900c Change C4AulScript::GetPropList() return type to C4PropListStatic*
This doesn't actually change the type of any object, but shifts some casts
around.
2012-08-09 01:17:26 +02:00
Günther Brammer 7f9ab9ac19 Script: this returns nil after RemoveObject instead of throwing
Because the interpreter throws for every function that is called with a
this parameter that has been removed, this() isn't a function anymore.
The function could stay around so that Call("this") or foo->this()
would still work, but I doubt any script ever did that.
2012-06-18 04:07:36 +02:00
Günther Brammer 23d1246be1 Script: Add === and !== operators
These operators have a stricter definition of equality than the == and !=
operators. Those are already stricter than in some other languages, so the
new ones are probably not needed very often. But if the need does arise,
there's no workaround short of modifying the data structures and checking
whether they are still the same.
2012-06-11 00:47:28 +02:00
Günther Brammer cdeabedf77 Simplify C4AulFuncMap a bit
The map is currently only used in the parser for some warning heuristics.
Since it uses a hash table with separate chaining and the amount of
functions is fairly predictable, the hash table doesn't have to be
resizable.
2012-05-28 00:53:41 +02:00
Günther Brammer c6fe23729b Replace function list from C4AulScript with proplist enumeration
This finally makes the function list in C4AulScript unnecessary.
2012-05-28 00:50:13 +02:00
Günther Brammer 487a0ea38f Store a copy of the proplist the preparser created for include/appendto
The parser now copies the contents of the proplists in the order of their
source scripts into the final proplist. This way, local variable contents
get properly included, and the list of functions has one user less.
2012-05-28 00:31:55 +02:00
Günther Brammer 7e00f3b5ad Use printf format instead of two strings for script warnings and errors 2012-05-26 00:22:22 +02:00
Günther Brammer 034ca7d894 Script: constant expressions can use local variables
For example:
local foo = { bar = baz };
local baz = 27;
2012-05-18 17:40:46 +02:00
Günther Brammer 26a470b30f The preparser creates static proplists, the parser looks them up by name
Constant expressions for global constants and for Definition properties are
now treated the same way. The preparser creates the structure that
the parser will fill in. Since the structure will not move, the parser can
refer to it before it is filled in, just like functions can call siblings
defined further down in the script. This will also allow proplists (and later
functions) to refer to each other.
2012-05-27 18:00:45 +02:00
Günther Brammer 3a3ed01c89 Savegames: Save readonly proplists by their name
For example, the proplist in Clonk.ActMap.Walk is saved as DClonk.ActMap.Walk.
Should the script defining the proplist change while the savegame is stored,
the proplist will have the new contents instead of the old ones after savegame
load.

Also, save functions as DFlint.Hit instead of fDFlint.Hit. Loading uses the same
code as static proplist loading.

Curiously, this makes g++ 4.4 use the C4RefCntPointer move constructor,
which was broken until now. Fix it to take a mutable rvalue reference.
2012-06-01 17:27:59 +02:00
Günther Brammer 9c3f949142 Point to the beginning of the current token in script error messages 2012-05-16 23:24:40 +02:00
Günther Brammer 065b100dad Script: eval throws an exception when the script does not end after the expression 2012-05-08 01:03:29 +02:00
Günther Brammer ceb9c45984 Fix Script runtime reload
Just removing the right amount of functions from the proplists is
somewhat tricky, unfortunately.
2012-05-25 17:25:53 +02:00
Nicolas Hake 7efd9a9b9a Aul: Add new nil-coalescing operator ??
This short-circuiting operator will evaluate to its first operand if the operand
is not nil, or to its second operand otherwise. Its intended use is to simplify
defaulting expressions that may evaluate to nil to a valid value.
2012-04-15 15:44:01 +02:00
Günther Brammer f89f19b2cb Script: No #appendto in Defs or global functions in #appendtos (#734)
So the only thing #appendtos may contain are lokal functions and variables,
which are only reachable via the Definition the script is appended to, and
global constants and variables, which only need to be parsed once. Thus,
#appendto scripts can skip being parsed without a definition, and the
errors that sometimes produces are gone.
2012-04-13 21:43:43 +02:00
Günther Brammer f245af8972 Rename C4AulParseState to C4AulParse 2012-04-12 21:03:14 +02:00
Günther Brammer 6486ea9e19 Script: Disallow "new Clonk {}" for now
Eventually, "new Clonk {}" will create a C4Object. Prevent anyone from
using it before then.
2012-02-25 22:10:03 +01:00
Günther Brammer 67d8ac47e9 Keep functions across script reloads
For functions that are not appended/included, this is done by reusing them.
Functions that are not in the new script version are left with their code
raising and error. Appended/included functions are handled by a reference count.
2012-02-02 01:16:14 +01:00
Günther Brammer 8091dff419 Clean up C4AulScriptFunc API 2012-02-01 03:49:50 +01:00
Günther Brammer 65801a5188 Remove C4AulFunc::LinkedTo
The parser doesn't need it to find the functions it has to parse anymore.

And the global proplist can be cleared before removing the functions,
instead of having engine functions deregister themselves and script
functions being deregistered when their linked function is removed.
2012-02-13 22:20:10 +01:00
Günther Brammer 42679e48fb Script: Inherit local variable initialization from #included scripts
This is done by creating their values in the parser. Global constants are
still created in the preparser so that they are available to the parser.
2012-01-25 00:36:11 +01:00
Günther Brammer 378e502c85 C4Script parser goes through the entire script instead of only functions
This should not change anything about which functions are created
by include/appendto and what inherited calls.
2012-01-27 00:42:41 +01:00
Günther Brammer 18038f45d3 Implement the function overload tree using the proplists
Instead of carefully inserting functions at the start or end of the list,
build the list just before the parser runs, at the same time as filling
the proplist where the functions are looked up.

This way, the overloaded function is simply the one that was previously in
the proplist, is not needed outside of the overloading function, and can thus
be replaced in the proplist.
2012-01-27 00:20:55 +01:00