Commit Graph
25 Commits
Author SHA1 Message Date
kichikuou 0911103949 Update libsys4
And add tests for https://github.com/nunuhara/libsys4/pull/26.
2023-11-18 16:35:58 +09:00
kichikuou 0b4eb92e95 Fix S_MOD for bool and long int
* The "type" argument of S_MOD is 48 for bool, 56 for long int
* %b, %c, %d can consume any integer types (int, bool, or long int)
* If the value cannot be consumed, S_MOD should return the format
  string instead of an empty string
2023-09-02 11:36:54 +09:00
Nunuhara Cabbage 842d712a31 Fix bug in S_MOD
The 3rd argument to the instruction indicates the type of the second
argument. If there are multiple specifiers in the format string, the
first specifier matching the given type is substituted (NOT the first
specifier encountered when processing the format string).
2023-01-10 18:47:03 -08:00
kichikuou f78013b70b Implement R_NOTE instruction
It corresponds to the !== operator.
2022-12-04 17:14:19 +09:00
kichikuou a0d833649a Fix vm_copy() for reference types
This fixes a use-after-free bug in the first battle of Rance VI.
2021-05-01 19:50:09 +09:00
kichikuou bd61781fde Math: Implement RandF, RandTableInit and RandTable
These are used in Big Bang Age.
2021-02-14 12:26:59 +09:00
kichikuou f54cc239a5 Add tests for #8 2021-02-13 17:44:12 +09:00
Nunuhara Cabbage 15cdb10ee0 Implement NEW instruction 2020-04-05 13:44:37 -07:00
Nunuhara Cabbage c135c4cde7 Implement system.GetFuncStackName() 2019-12-01 22:04:09 -08:00
Nunuhara Cabbage 80ff1902e6 Implement MSG instruction 2019-11-19 20:34:31 -08:00
Nunuhara Cabbage 00c4e7bf1f Fix bug in S_MOD 2019-11-18 21:53:51 -08:00
Nunuhara Cabbage c370e3eeaf Implement S_MOD (format strings)
Mostly relying on sprintf to do the work.
2019-11-10 13:44:01 -08:00
Nunuhara Cabbage edffc0ad76 Initial CALLHLL and Math.dll implementation
HLL libraries are compiled into the executable rather than dynamically
loaded as in early versions of System 4. These days AliceSoft does the
same thing.
2019-11-04 20:35:42 -08:00
Nunuhara Cabbage 9db69f8012 Implement DUP_U2, SP_INC, DELETE, R_ASSIGN
Reference assignment.
2019-10-31 21:37:47 -07:00
Nunuhara Cabbage 84e531b9ab Implement SWITCH, STRSWITCH 2019-10-31 17:27:03 -07:00
Nunuhara Cabbage 3ff406cb58 SR_POP, SR_ASSIGN, C_REF, C_ASSIGN 2019-10-29 19:58:26 -07:00
Nunuhara Cabbage 470c051124 Implement full suite of array instructions
All array instructions supported by the SDK compiler, anyway. There are
a few instructions that were added in later versions, like A_FIND and
A_REVERSE.
2019-10-28 20:31:50 -07:00
Nunuhara Cabbage 2bf800d77e Implement CALLSYS2 instruction (function types)
Also the SWAP instruction since the compiler generates it for indirect
function calls.
2019-10-22 19:02:20 -07:00
Nunuhara Cabbage 33ec7a34e1 Basic arrays implementation
Just .Alloc() and .Free() for now.
2019-10-22 17:33:26 -07:00
Nunuhara Cabbage e5ef9f4d2d Implement constructors and methods
Implement CALLMETHOD, SH_STRUCTREF and PUSHSTRUCTPAGE instructions.

Constructors are a bit tricky since SH_LOCALCREATE has to implicitly
call an arbitrary number of functions before it returns (just changing
the instruction pointer only allows for calling a single function).

To get around this, there is now a vm_call() function which is used to
call a function synchronously, before returning from the current
instruction.

Methods are implemented as functions, except that they get a struct page
as local variable -1.

Destructors are still not implemented.
2019-10-20 17:33:22 -07:00
Nunuhara Cabbage 2210696f93 Implement S_REF (struct pass-by-value) 2019-10-20 11:51:16 -07:00
Nunuhara Cabbage d37de6c23a Add tests for some basic language features 2019-10-19 22:53:05 -07:00
Nunuhara Cabbage 49586506d0 Fix memory managment of objects on stack
A few things.

The S_REF instruction creates a _copy_ of the referenced string. Proof:

    FUNC foo
    // string local_string = "foo"
    SH_LOCALREF local_string
    S_PUSH "foo"
    S_ASSIGN
    S_POP

    // prepare argument for bar()
    PUSHLOCALPAGE
    PUSH local_string
    S_REF

    // stealthily alter local_string
    SH_LOCALREF local_string
    S_PUSH "bar"
    S_ASSIGN
    S_POP

    // bar(local_string)
    CALLFUNC bar // local_string is still "foo" in the body of bar()!

Thus, it is not CALLFUNC's responsibility to copy by-value string
arguments. CALLFUNC need only copy the index from the stack into the
local page.

Objects pushed to the stack with SH_LOCALREF, SH_GLOBALREF and REF do
not gain a reference. They are already referenced by the page they
belong to.

I believe the implementation of S_REF is still not quite right. What
I've noticed is that System40.exe is able to distinguish between strings
pushed with S_REF/S_PUSH and strings pushed with
SH_LOCALREF/SH_GLOBALREF/REF. It seems the former are r-values and the
latter are l-values (i.e. the latter can be assigned to, but not the
former), and the VM will throw an error if you try to assign to an
r-value.
The underlying implementation is not clear to me. Both types appear to
be indices into the heap, which suggests that the distinguishing factor
must be stored either in the object itself, or as part of the pointer to
an object. Perhaps its as simple as a flag marking an object as an
r-value?
2019-10-19 21:36:52 -07:00
Nunuhara Cabbage 7ba5626675 Support simple struct/class usage
No constructors, destructors or methods--just simple data structures.
2019-10-19 08:18:22 -07:00
Nunuhara Cabbage 82c3f81d52 Add rudimentary unit testing via AIN file
Building 'test/test.pje' with the SDK compiler produces a file at
'test/Run/test.ain' which can be run with xsystem4 to test various
features.

Not the greatest testing method, but it works.
2019-10-16 20:16:19 -07:00