Skip to content

Commit

Permalink
temp disabled member expression evaluation (DEBUGGING)
Browse files Browse the repository at this point in the history
  • Loading branch information
aName2050 committed Mar 28, 2024
1 parent 490cff9 commit 6e5b1bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
37 changes: 20 additions & 17 deletions src/GigaScript/runtime/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Value, DataConstructors, DataType, ObjectValue } from './types';
import * as NativeFunctions from '../native/functions';
import * as NativeValues from '../native/valueKeywords';
import { MemberExpr } from '../ast/expressions.ast';
import { Identifier } from '../ast/literals.ast';
import { Identifier, ObjectLiteral } from '../ast/literals.ast';

export function createGlobalScope(cwd: string): Environment {
const env = new Environment(cwd);
Expand Down Expand Up @@ -109,27 +109,30 @@ export default class Environment {
value?: Value<DataType, any>,
property?: Identifier
): Value<DataType, any> {
if (expr.object.kind === 'MemberExpr')
return this.lookupOrModifyObject(
expr.object as MemberExpr,
value,
expr.property as Identifier
);
// if (expr.object.kind === 'MemberExpr') {
// console.log('complex object!');
// return this.lookupOrModifyObject(
// expr.object as MemberExpr,
// value,
// expr.property as Identifier
// );
// }

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

let oldVal = env.variables.get(varName) as ObjectValue;
// let oldVal = env.variables.get(varName) as ObjectValue;

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

if (value) oldVal.properties.set(prop, value);
// if (value) oldVal.properties.set(prop, value);

if (currProp) oldVal = oldVal.properties.get(currProp) as ObjectValue;
// if (currProp) oldVal = oldVal.properties.get(currProp) as ObjectValue;

return oldVal;
// return oldVal;
return DataConstructors.NULL();
}
}
18 changes: 0 additions & 18 deletions tests/main.g
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
const test = 100;
let string = "hello!";

func add(a, b) {
return a + b;
}

print(add(1, 2))

const obj = {
x: 32,
string,
Expand All @@ -15,14 +7,4 @@ const obj = {
}
};

print(obj.x)
print(obj.string)
print(obj.complex.foo)

try {
print("hello world!")
throw 'test'
} catch (e) {
print('an error was caught!')
print(e)
}

0 comments on commit 6e5b1bc

Please sign in to comment.