face-hh / bussin

An esolang in TypeScript, for heaven's sake.
Apache License 2.0
566 stars 37 forks source link

Objects are immutable? #28

Closed etherealxx closed 11 months ago

etherealxx commented 11 months ago

I don't know if this is a 'design choice' (like how loops doesn't have break), because this example from the readme doesn't work.

lit x be cap rn
lit obj be { key: nocap, x } rn

obj.key be cap
waffle(obj.key)

it will output

D:\Github\bussin\src\runtime\environment.ts:167
        if (value) pastVal.properties.set(prop, value);
                                      ^
TypeError: Cannot read properties of undefined (reading 'set')
    at Environment.lookupOrMutObject (D:\Github\bussin\src\runtime\environment.ts:167:39)
    at eval_member_expr (D:\Github\bussin\src\runtime\eval\expressions.ts:145:30)
    at eval_assignment (D:\Github\bussin\src\runtime\eval\expressions.ts:83:52)
    at evaluate (D:\Github\bussin\src\runtime\interpreter.ts:21:35)
    at eval_program (D:\Github\bussin\src\runtime\eval\statements.ts:11:33)
    at evaluate (D:\Github\bussin\src\runtime\interpreter.ts:25:32)
    at D:\Github\bussin\src\main.ts:31:28
    at step (D:\Github\bussin\src\main.ts:33:23)
    at Object.next (D:\Github\bussin\src\main.ts:14:53)
    at D:\Github\bussin\src\main.ts:8:71

no matter if it's bs or bsx. i tried current commit, previous commit, and the earliest commit. The issue seems persistent.

Symmettry commented 11 months ago

objects apparently don't work, the properties aren't assigned and in fact the property value itself is undefined.

Symmettry commented 11 months ago

Found the issue. The code was assigning the temp object to a value before assigning its value.

Function "lookupOrMutObject()" in environment.ts should be replaced with

` public lookupOrMutObject(expr: MemberExpr, value?: RuntimeVal, property?: Identifier): RuntimeVal { if (expr.object.kind === 'MemberExpr') return this.lookupOrMutObject(expr.object as MemberExpr, value, expr.property as Identifier);

    const varname = (expr.object as Identifier).symbol;
    const env = this.resolve(varname);

    let pastVal = env.variables.get(varname) as ObjectVal;

    const prop = property
        ? property.symbol
        : (expr.property as Identifier).symbol;
    const currentProp = (expr.property as Identifier).symbol;

    if (value) pastVal.properties.set(prop, value);

    if (currentProp) pastVal = (pastVal.properties.get(currentProp) as ObjectVal);

    return pastVal;
}`

To fix the issue.
Symmettry commented 11 months ago

Github code formatting sucks balls.

face-hh commented 11 months ago

Fixed in v1.2.1