|
@ -121,9 +121,9 @@ oop printOn(oop buf, oop obj, int indent); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if PRIMCLOSURE |
|
|
#if PRIMCLOSURE |
|
|
#define doProtos(_) _(Object) _(RefLocal) _(GetLocal) _(SetLocal) _(RefGlobal) _(GetGlobal) _(SetGlobal) _(RefVar) _(GetVar) _(SetVar) _(RefProp) _(GetProp) _(SetProp) _(RefArray) _(GetArray) _(SetArray) _(GetSlice) _(Call) _(Invoke) _(Super) _(Continue) _(Break) _(Return) _(TryCatch) _(TryEnsure)_(Raise)_(Binop) _(Unyop) _(If) _(While) _(Block) _(For) _(ForIn) _(ForFromTo) _(Literal) |
|
|
|
|
|
|
|
|
#define doProtos(_) _(Object) _(RefLocal) _(GetLocal) _(SetLocal) _(RefGlobal) _(GetGlobal) _(SetGlobal) _(RefVar) _(GetVar) _(SetVar) _(RefProp) _(GetProp) _(SetProp) _(RefArray) _(GetArray) _(SetArray) _(GetSlice) _(Call) _(Invoke) _(Super) _(Continue) _(Break) _(Return) _(TryCatch) _(TryEnsure)_(Raise)_(Binop) _(Unyop) _(If) _(While) _(Block) _(For) _(ForIn) _(ForFromTo) _(Literal) _(Stream) |
|
|
#else |
|
|
#else |
|
|
#define doProtos(_) _(Object) _(RefLocal) _(GetLocal) _(SetLocal) _(RefGlobal) _(GetGlobal) _(SetGlobal) _(RefVar) _(GetVar) _(SetVar) _(RefProp) _(GetProp) _(SetProp) _(RefArray) _(GetArray) _(SetArray) _(GetSlice) _(Call) _(Invoke) _(Super) _(Continue) _(Break) _(Return) _(TryCatch) _(TryEnsure) _(Raise) _(Binop) _(Unyop) _(If) _(While) _(Block) _(For) _(ForIn) _(ForFromTo) _(Literal) _(Lambda) _(Closure) |
|
|
|
|
|
|
|
|
#define doProtos(_) _(Object) _(RefLocal) _(GetLocal) _(SetLocal) _(RefGlobal) _(GetGlobal) _(SetGlobal) _(RefVar) _(GetVar) _(SetVar) _(RefProp) _(GetProp) _(SetProp) _(RefArray) _(GetArray) _(SetArray) _(GetSlice) _(Call) _(Invoke) _(Super) _(Continue) _(Break) _(Return) _(TryCatch) _(TryEnsure) _(Raise) _(Binop) _(Unyop) _(If) _(While) _(Block) _(For) _(ForIn) _(ForFromTo) _(Literal) _(Lambda) _(Closure) _(Stream) |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#define declareProto(NAME) oop p##NAME = 0; |
|
|
#define declareProto(NAME) oop p##NAME = 0; |
|
@ -147,7 +147,7 @@ doTypes(makeProto); |
|
|
doProperties(declareProp); |
|
|
doProperties(declareProp); |
|
|
#undef declareProp |
|
|
#undef declareProp |
|
|
|
|
|
|
|
|
#define doSymbols(_) _(t) _(name) _(expr) _(function) _(arguments) _(object) _(index) _(key) _(value) _(self) _(method) _(parameters) _(body) _(lambda) _(environment) _(operation) _(full) _(condition) _(consequent) _(alternate) _(expression) _(identifier) _(initialise) _(update) _(first) _(last) _(fixed) _(keyvals) _(__namespaces__) _(O) _(d) _(p) _(v) _(statement) _(handler) _(kind) _(message) _(operand1) _(operand2) _(profile) _(parent) _(count) _(stamp) _(time) _(start) _(stop) _($$) _(yytext) _(yyleng) |
|
|
|
|
|
|
|
|
#define doSymbols(_) _(t) _(name) _(expr) _(function) _(arguments) _(object) _(index) _(key) _(value) _(self) _(method) _(parameters) _(body) _(lambda) _(environment) _(operation) _(full) _(condition) _(consequent) _(alternate) _(expression) _(identifier) _(initialise) _(update) _(first) _(last) _(fixed) _(keyvals) _(__namespaces__) _(O) _(d) _(p) _(v) _(statement) _(handler) _(kind) _(message) _(operand1) _(operand2) _(profile) _(parent) _(count) _(stamp) _(time) _(start) _(stop) _($$) _(yytext) _(yyleng) _(env) _(content) _(position) _(limit) _(lastBegin) |
|
|
|
|
|
|
|
|
#define declareSym(NAME) oop sym_##NAME = 0; |
|
|
#define declareSym(NAME) oop sym_##NAME = 0; |
|
|
doSymbols(declareSym); |
|
|
doSymbols(declareSym); |
|
@ -501,6 +501,8 @@ oop newStringUnescaped(char *string) |
|
|
case 'r' : c = '\r'; break; |
|
|
case 'r' : c = '\r'; break; |
|
|
case 't' : c = '\t'; break; |
|
|
case 't' : c = '\t'; break; |
|
|
case 'v' : c = '\v'; break; |
|
|
case 'v' : c = '\v'; break; |
|
|
|
|
|
case '[' : c = '[' ; break; |
|
|
|
|
|
case ']' : c = ']' ; break; |
|
|
case 'X' : |
|
|
case 'X' : |
|
|
case 'x' : c = readCharValue(&string, 16, -1); break; |
|
|
case 'x' : c = readCharValue(&string, 16, -1); break; |
|
|
case '0'...'7': --string; c = readCharValue(&string, 8, 3); break; |
|
|
case '0'...'7': --string; c = readCharValue(&string, 8, 3); break; |
|
@ -3340,6 +3342,26 @@ void Literal_codeOn(oop exp, oop str, oop env) |
|
|
# endif |
|
|
# endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop newStream(oop content) |
|
|
|
|
|
{ |
|
|
|
|
|
oop o = new(pStream); |
|
|
|
|
|
Object_put(o, sym_content , content); |
|
|
|
|
|
Object_put(o, sym_position , newInteger(0)); |
|
|
|
|
|
Object_put(o, sym_limit , newInteger(_get(content, String, length))); |
|
|
|
|
|
Object_put(o, sym_lastBegin, newInteger(0)); |
|
|
|
|
|
return o; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop Stream_eval(oop exp, oop env) |
|
|
|
|
|
{ |
|
|
|
|
|
return exp; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Stream_codeOn(oop exp, oop str, oop env) |
|
|
|
|
|
{ |
|
|
|
|
|
Object_codeOn(exp, str, env); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
oop lvalue(oop rval) |
|
|
oop lvalue(oop rval) |
|
|
{ |
|
|
{ |
|
|
if (!is(Object,rval)) valueError("=", "non-assignable value", rval); |
|
|
if (!is(Object,rval)) valueError("=", "non-assignable value", rval); |
|
@ -3372,10 +3394,12 @@ void expected(char *what, char *where) |
|
|
fatal("syntax error: %s expected near: %s", what, where); |
|
|
fatal("syntax error: %s expected near: %s", what, where); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define global |
|
|
|
|
|
|
|
|
%} |
|
|
%} |
|
|
|
|
|
|
|
|
start = - ( s:stmt { yysval = s } |
|
|
|
|
|
| !. { yysval = 0 } |
|
|
|
|
|
|
|
|
start = - ( s:stmt { global yysval = s } |
|
|
|
|
|
| !. { global yysval = 0 } |
|
|
| < (!EOL .)* > { syntaxError(yytext) } |
|
|
| < (!EOL .)* > { syntaxError(yytext) } |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -3461,10 +3485,10 @@ sum = l:prod ( PLUS r:prod { l = newBinop(opAdd, l, r) } |
|
|
| MINUS r:prod { l = newBinop(opSub, l, r) } |
|
|
| MINUS r:prod { l = newBinop(opSub, l, r) } |
|
|
)* { $$ = l } |
|
|
)* { $$ = l } |
|
|
|
|
|
|
|
|
prod = l:prefix ( STAR r:prefix { l = newBinop(opMul, l, r) } |
|
|
|
|
|
| SLASH r:prefix { l = newBinop(opDiv, l, r) } |
|
|
|
|
|
| PCENT r:prefix { l = newBinop(opMod, l, r) } |
|
|
|
|
|
)* { $$ = l } |
|
|
|
|
|
|
|
|
prod = l:prefix ( STAR r:prefix { l = newBinop(opMul, l, r) } |
|
|
|
|
|
| SLASH r:prefix { l = newBinop(opDiv, l, r) } |
|
|
|
|
|
| PCENT r:prefix { l = newBinop(opMod, l, r) } |
|
|
|
|
|
) * { $$ = l } |
|
|
|
|
|
|
|
|
prefix = PPLUS p:prefix { $$ = newBinop(opPreAdd, lvalue(p), newInteger(1)) } |
|
|
prefix = PPLUS p:prefix { $$ = newBinop(opPreAdd, lvalue(p), newInteger(1)) } |
|
|
| MMINUS p:prefix { $$ = newBinop(opPreSub, lvalue(p), newInteger(1)) } |
|
|
| MMINUS p:prefix { $$ = newBinop(opPreSub, lvalue(p), newInteger(1)) } |
|
@ -3515,7 +3539,7 @@ params = LPAREN p:mkobj |
|
|
) |
|
|
) |
|
|
)* RPAREN ) { $$ = p } |
|
|
)* RPAREN ) { $$ = p } |
|
|
|
|
|
|
|
|
mkobj = { $$ = new(pObject) } |
|
|
|
|
|
|
|
|
mkobj = { $$ = (global new)(pObject) } |
|
|
|
|
|
|
|
|
primary = nil | number | string | symbol | var | lambda | subexpr | literal # | regex |
|
|
primary = nil | number | string | symbol | var | lambda | subexpr | literal # | regex |
|
|
|
|
|
|
|
@ -3544,8 +3568,7 @@ number = "-" n:unsign { $$ = neg(n) } |
|
|
| "+" n:number { $$ = n } |
|
|
| "+" n:number { $$ = n } |
|
|
| n:unsign { $$ = n } |
|
|
| n:unsign { $$ = n } |
|
|
|
|
|
|
|
|
unsign = < DIGIT+ '.' DIGIT* EXP? > - { $$ = newFloat(strtod(yytext, 0)) } |
|
|
|
|
|
| < DIGIT* '.' DIGIT+ EXP? > - { $$ = newFloat(strtod(yytext, 0)) } |
|
|
|
|
|
|
|
|
unsign = < DIGIT* '.' DIGIT+ EXP? > - { $$ = newFloat(strtod(yytext, 0)) } |
|
|
| "0" [bB] < BIGIT+ > - { $$ = newInteger(strtol(yytext, 0, 2)) } |
|
|
| "0" [bB] < BIGIT+ > - { $$ = newInteger(strtol(yytext, 0, 2)) } |
|
|
| "0" [xX] < HIGIT+ > - { $$ = newInteger(strtol(yytext, 0, 16)) } |
|
|
| "0" [xX] < HIGIT+ > - { $$ = newInteger(strtol(yytext, 0, 16)) } |
|
|
| "0" < OIGIT* > - { $$ = newInteger(strtol(yytext, 0, 8)) } |
|
|
| "0" < OIGIT* > - { $$ = newInteger(strtol(yytext, 0, 8)) } |
|
@ -3554,11 +3577,16 @@ unsign = < DIGIT+ '.' DIGIT* EXP? > - { $$ = newFloat(strtod(yytext, 0 |
|
|
|
|
|
|
|
|
string = '"' < ( !'"' char )* > '"' - { $$ = newStringUnescaped(yytext) } |
|
|
string = '"' < ( !'"' char )* > '"' - { $$ = newStringUnescaped(yytext) } |
|
|
|
|
|
|
|
|
char = "\\" ( ["'\\abfnrtv] |
|
|
|
|
|
| [xX] HIGIT* |
|
|
|
|
|
| [0-7][0-7]?[0-7]? |
|
|
|
|
|
) |
|
|
|
|
|
| . |
|
|
|
|
|
|
|
|
char = '\\' [abefnrtv'"\[\]\\] |
|
|
|
|
|
| '\\' [0-3][0-7][0-7] |
|
|
|
|
|
| '\\' [xX] HIGIT* |
|
|
|
|
|
| '\\' [0-7][0-7]? |
|
|
|
|
|
| !'\\' . |
|
|
|
|
|
# char = "\\" ( ["'\\abfnrtv] |
|
|
|
|
|
# | [xX] HIGIT* |
|
|
|
|
|
# | [0-7][0-7]?[0-7]? |
|
|
|
|
|
# ) |
|
|
|
|
|
# | . |
|
|
|
|
|
|
|
|
symbol = HASH i:id { $$ = i } |
|
|
symbol = HASH i:id { $$ = i } |
|
|
|
|
|
|
|
@ -3673,7 +3701,7 @@ SLASH = "/" ![/=] - |
|
|
SLASHEQ = "/=" - |
|
|
SLASHEQ = "/=" - |
|
|
PCENT = "%" ![=] - |
|
|
PCENT = "%" ![=] - |
|
|
PCENTEQ = "%=" - |
|
|
PCENTEQ = "%=" - |
|
|
DOT = "." - |
|
|
|
|
|
|
|
|
DOT = "." ![.] - |
|
|
PLING = "!" ![=] - |
|
|
PLING = "!" ![=] - |
|
|
TILDE = "~" - |
|
|
TILDE = "~" - |
|
|
|
|
|
|
|
@ -3683,6 +3711,7 @@ xexpr = expr | error @{ expected("expression", yytext) } |
|
|
|
|
|
|
|
|
%% |
|
|
%% |
|
|
; |
|
|
; |
|
|
|
|
|
#undef global |
|
|
|
|
|
|
|
|
#if PROFILE |
|
|
#if PROFILE |
|
|
|
|
|
|
|
@ -3955,6 +3984,22 @@ oop prim_Object_initialise(oop func, oop self, oop args, oop env) |
|
|
return self; |
|
|
return self; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_newBinop(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ assert(is(Object, args)); |
|
|
|
|
|
int argc = _get(args, Object,isize); |
|
|
|
|
|
if (argc != 3) fatal("newBinop: Expected 3 arguments, got %d\n", argc); |
|
|
|
|
|
oop *indexed = _get(args, Object,indexed); |
|
|
|
|
|
return newBinop(integerValue(indexed[0], "prim_newBinop"), indexed[1], indexed[2]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_newApply(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ assert(is(Object, args)); |
|
|
|
|
|
int argc = _get(args, Object,isize); |
|
|
|
|
|
if (argc != 2) fatal("newApply: Expected 2 arguments, got %d\n", argc); |
|
|
|
|
|
oop *indexed = _get(args, Object,indexed); |
|
|
|
|
|
return newApply(indexed[0], indexed[1]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
oop prim_Object_push(oop func, oop self, oop args, oop env) |
|
|
oop prim_Object_push(oop func, oop self, oop args, oop env) |
|
|
{ assert(is(Object, args)); |
|
|
{ assert(is(Object, args)); |
|
|
int argc = _get(args, Object,isize); assert(is(Object, self)); |
|
|
int argc = _get(args, Object,isize); assert(is(Object, self)); |
|
@ -4008,10 +4053,21 @@ oop prim_String_pop(oop func, oop self, oop args, oop env) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
oop prim_String_asInteger(oop func, oop self, oop args, oop env) |
|
|
oop prim_String_asInteger(oop func, oop self, oop args, oop env) |
|
|
{ assert(is(String, self)); |
|
|
|
|
|
|
|
|
{ assert(is(Object, args)); |
|
|
|
|
|
int argc = _get(args, Object,isize); assert(is(String, self)); |
|
|
|
|
|
if (argc > 1) fatal("String.asInteger: expected either 0 or 1 arguments, got %d\n", argc); |
|
|
|
|
|
|
|
|
char *str = String_content(self); // ensure nul terminator |
|
|
char *str = String_content(self); // ensure nul terminator |
|
|
char *end = 0; |
|
|
char *end = 0; |
|
|
long value = strtol(str, &end, 0); |
|
|
|
|
|
|
|
|
long value; |
|
|
|
|
|
|
|
|
|
|
|
if (argc == 1) { |
|
|
|
|
|
oop base = _get(args, Object,indexed)[0]; |
|
|
|
|
|
value = strtol(str, &end, integerValue(base, "String.asInteger")); |
|
|
|
|
|
} else { |
|
|
|
|
|
value = strtol(str, &end, 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (*end) return nil; |
|
|
if (*end) return nil; |
|
|
return newInteger(value); |
|
|
return newInteger(value); |
|
|
} |
|
|
} |
|
@ -4243,6 +4299,47 @@ oop prim_Symbol_asString(oop func, oop self, oop args, oop env) |
|
|
return newString(_get(self, Symbol,name)); |
|
|
return newString(_get(self, Symbol,name)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
oop prim_newStream(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ assert(is(Object, args)); |
|
|
|
|
|
int argc = _get(args, Object,isize); |
|
|
|
|
|
if (argc != 1) fatal("newStream: Expected 1 argument, got %d\n", argc); |
|
|
|
|
|
oop arg = _get(args, Object, indexed)[0]; |
|
|
|
|
|
if (!is(String, arg)) fatal("newStream: expected an argument of type String, got type %s instead\n", getType(arg)); |
|
|
|
|
|
return newStream(arg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_Stream_atEnd(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ |
|
|
|
|
|
return newBoolean(_integerValue(Object_get(self, sym_position)) >= _integerValue(Object_get(self, sym_limit))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_Stream_inc(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ |
|
|
|
|
|
if (_integerValue(Object_get(self, sym_position)) < _integerValue(Object_get(self, sym_limit))) { |
|
|
|
|
|
// There has to be a better way of just adding 1 |
|
|
|
|
|
Object_put(self, sym_position, newInteger(_integerValue(Object_get(self, sym_position)) + 1)); |
|
|
|
|
|
} |
|
|
|
|
|
return Object_get(self, sym_position); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_Stream_setLastBegin(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ |
|
|
|
|
|
return Object_put(self, sym_lastBegin, newInteger(_integerValue(Object_get(self, sym_position)))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_Stream_match(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ assert(is(Object, args)); |
|
|
|
|
|
int argc = _get(args, Object,isize); |
|
|
|
|
|
if (argc != 1) fatal("Stream.match: Expected 1 argument, got %d\n", argc); |
|
|
|
|
|
oop arg = _get(args, Object, indexed)[0]; assert(is(String, arg)); |
|
|
|
|
|
return newBoolean(strncmp( |
|
|
|
|
|
String_content(Object_get(self, sym_content)) + _integerValue(Object_get(self, sym_position)), |
|
|
|
|
|
String_content(arg), |
|
|
|
|
|
strlen(String_content(arg)) |
|
|
|
|
|
) == 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
oop prim_length(oop func, oop self, oop args, oop env) |
|
|
oop prim_length(oop func, oop self, oop args, oop env) |
|
|
{ assert(is(Object, args)); |
|
|
{ assert(is(Object, args)); |
|
|
if (!is(Object, self)) valueError("length", "not an object", self); |
|
|
if (!is(Object, self)) valueError("length", "not an object", self); |
|
@ -4298,6 +4395,12 @@ oop prim_eval(oop func, oop self, oop args, oop env) |
|
|
int argc = _get(args, Object,isize); |
|
|
int argc = _get(args, Object,isize); |
|
|
oop *indexed = _get(args, Object,indexed); |
|
|
oop *indexed = _get(args, Object,indexed); |
|
|
oop result = nil; |
|
|
oop result = nil; |
|
|
|
|
|
|
|
|
|
|
|
//if (nil != Object_getLocal(args, sym_env)) { |
|
|
|
|
|
if (Object_find(args, sym_env) >= 0) { |
|
|
|
|
|
env = Object_getLocal(args, sym_env); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) result = eval(indexed[i], env); |
|
|
for (int i = 0; i < argc; ++i) result = eval(indexed[i], env); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
@ -4307,6 +4410,22 @@ oop prim___eval__(oop func, oop self, oop args, oop env) |
|
|
return self; |
|
|
return self; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_intern(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ |
|
|
|
|
|
int argc = _get(args, Object,isize); |
|
|
|
|
|
oop *indexed = _get(args, Object,indexed); |
|
|
|
|
|
oop result = nil; |
|
|
|
|
|
|
|
|
|
|
|
if (argc != 1) { |
|
|
|
|
|
fatal("intern: invalid number of arguments"); |
|
|
|
|
|
} |
|
|
|
|
|
if (getType(indexed[0]) != String) { |
|
|
|
|
|
fatal("intern: argument is not of type String, got %s instead", getTypeName(indexed[0])); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return intern(String_content(indexed[0])); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
oop prim_print(oop func, oop self, oop args, oop env) |
|
|
oop prim_print(oop func, oop self, oop args, oop env) |
|
|
{ |
|
|
{ |
|
|
int argc = _get(args, Object,isize); |
|
|
int argc = _get(args, Object,isize); |
|
@ -4797,7 +4916,7 @@ typedef struct vmState |
|
|
oop variables; |
|
|
oop variables; |
|
|
} vmState; |
|
|
} vmState; |
|
|
|
|
|
|
|
|
#define VM_STATE_INITIALISER { nil, nil } |
|
|
|
|
|
|
|
|
#define VM_STATE_INITIALISER { nil, new(pObject) } |
|
|
|
|
|
|
|
|
void vmEnter(vmState *state, oop obj, char *yytext, int yyleng) |
|
|
void vmEnter(vmState *state, oop obj, char *yytext, int yyleng) |
|
|
{ |
|
|
{ |
|
@ -4812,7 +4931,7 @@ void vmSet(vmState *state, oop obj, char *yytext, int yyleng) |
|
|
|
|
|
|
|
|
void vmAction(vmState *state, oop obj, char *yytext, int yyleng) |
|
|
void vmAction(vmState *state, oop obj, char *yytext, int yyleng) |
|
|
{ |
|
|
{ |
|
|
oop text = yyleng ? newStringLen(yytext, yyleng) : nil; |
|
|
|
|
|
|
|
|
oop text = yyleng >= 0 ? newStringLen(yytext, yyleng) : nil; |
|
|
Object_put(state->variables, sym_yytext, text); |
|
|
Object_put(state->variables, sym_yytext, text); |
|
|
Object_put(state->variables, sym_yyleng, newInteger(yyleng)); |
|
|
Object_put(state->variables, sym_yyleng, newInteger(yyleng)); |
|
|
applyThunkIn(obj, state->variables); |
|
|
applyThunkIn(obj, state->variables); |
|
@ -4822,6 +4941,7 @@ void vmLeave(vmState *state, oop obj, char *yytext, int yyleng) |
|
|
{ |
|
|
{ |
|
|
state->result = Object_getLocal(state->variables, sym_$$); |
|
|
state->result = Object_getLocal(state->variables, sym_$$); |
|
|
state->variables = _getDelegate(state->variables); |
|
|
state->variables = _getDelegate(state->variables); |
|
|
|
|
|
Object_put(state->variables, sym_$$, state->result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void vmDisassemble(vmInsn *code, int pc) |
|
|
void vmDisassemble(vmInsn *code, int pc) |
|
@ -5019,6 +5139,8 @@ int vmRun(oop grammar0, oop symbol, char *text, int start, int length) |
|
|
C##stack[--C##sp]; \ |
|
|
C##stack[--C##sp]; \ |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
saveAction(vmEnter, nil, 0, 0); |
|
|
|
|
|
|
|
|
for (;;) { |
|
|
for (;;) { |
|
|
if (opt_d) vmDisassemble(frame.code, frame.pc); |
|
|
if (opt_d) vmDisassemble(frame.code, frame.pc); |
|
|
vmInsn *i = frame.code + frame.pc++; |
|
|
vmInsn *i = frame.code + frame.pc++; |
|
@ -5167,8 +5289,6 @@ int vmRun(oop grammar0, oop symbol, char *text, int start, int length) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
saveAction(vmLeave, nil, 0, 0); |
|
|
|
|
|
|
|
|
|
|
|
#undef pop |
|
|
#undef pop |
|
|
#undef drop |
|
|
#undef drop |
|
|
#undef push |
|
|
#undef push |
|
@ -5205,6 +5325,20 @@ oop prim_match(oop func, oop self, oop args, oop env) |
|
|
|
|
|
|
|
|
#endif // PEGVM |
|
|
#endif // PEGVM |
|
|
|
|
|
|
|
|
|
|
|
oop prim_lvalue(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ assert(is(Object, args)); |
|
|
|
|
|
int argc = _get(args, Object,isize); |
|
|
|
|
|
if (argc != 1) fatal("lvalue: one argument expected\n"); |
|
|
|
|
|
return lvalue(_get(args, Object,indexed)[0]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_assign(oop func, oop self, oop args, oop env) |
|
|
|
|
|
{ assert(is(Object, args)); |
|
|
|
|
|
int argc = _get(args, Object,isize); |
|
|
|
|
|
if (argc != 2) fatal("assign: 2 arguments expected\n"); |
|
|
|
|
|
return assign(_get(args, Object,indexed)[0], _get(args, Object,indexed)[1]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
oop replFile(FILE *in) |
|
|
oop replFile(FILE *in) |
|
|
{ |
|
|
{ |
|
|
int oldline = lineno; |
|
|
int oldline = lineno; |
|
@ -5330,6 +5464,18 @@ int main(int argc, char **argv) |
|
|
|
|
|
|
|
|
Object_put(pObject, prop_eval, newPrimitive(prim___eval__, newString("Object.__eval__"))); // inherited by all objects |
|
|
Object_put(pObject, prop_eval, newPrimitive(prim___eval__, newString("Object.__eval__"))); // inherited by all objects |
|
|
|
|
|
|
|
|
|
|
|
#define stringify(x) #x |
|
|
|
|
|
|
|
|
|
|
|
#define declareOp(NAME, OP) _set(intern(stringify(op##NAME)), Symbol,value, newInteger(op##NAME)); |
|
|
|
|
|
doBinops(declareOp) |
|
|
|
|
|
#undef declareOp |
|
|
|
|
|
|
|
|
|
|
|
#undef stringify |
|
|
|
|
|
|
|
|
|
|
|
#define declareOp(NAME, OP) _set(intern(#NAME), Symbol,value, newInteger(NAME)); |
|
|
|
|
|
doUnyops(declareOp) |
|
|
|
|
|
#undef declareOp |
|
|
|
|
|
|
|
|
#if TYPECODES |
|
|
#if TYPECODES |
|
|
|
|
|
|
|
|
# define defineEvaluator(NAME) \ |
|
|
# define defineEvaluator(NAME) \ |
|
@ -5375,6 +5521,12 @@ int main(int argc, char **argv) |
|
|
prim(defined , prim_defined); |
|
|
prim(defined , prim_defined); |
|
|
prim(__extern__ , prim_extern); |
|
|
prim(__extern__ , prim_extern); |
|
|
prim(__match__ , prim_match); |
|
|
prim(__match__ , prim_match); |
|
|
|
|
|
prim(intern , prim_intern); |
|
|
|
|
|
prim(newBinop , prim_newBinop); |
|
|
|
|
|
prim(newApply , prim_newApply); |
|
|
|
|
|
prim(lvalue , prim_lvalue); |
|
|
|
|
|
prim(assign , prim_assign); |
|
|
|
|
|
prim(newStream , prim_newStream); |
|
|
|
|
|
|
|
|
# undef prim |
|
|
# undef prim |
|
|
|
|
|
|
|
@ -5417,6 +5569,10 @@ int main(int argc, char **argv) |
|
|
method(Symbol,define, prim_Symbol_define ); |
|
|
method(Symbol,define, prim_Symbol_define ); |
|
|
method(Symbol,value, prim_Symbol_value ); |
|
|
method(Symbol,value, prim_Symbol_value ); |
|
|
method(Symbol,allInstances, prim_Symbol_allInstances); |
|
|
method(Symbol,allInstances, prim_Symbol_allInstances); |
|
|
|
|
|
method(Stream,atEnd, prim_Stream_atEnd ); |
|
|
|
|
|
method(Stream,inc, prim_Stream_inc ); |
|
|
|
|
|
method(Stream,setLastBegin, prim_Stream_setLastBegin); |
|
|
|
|
|
method(Stream,match, prim_Stream_match ); |
|
|
|
|
|
|
|
|
# undef method |
|
|
# undef method |
|
|
|
|
|
|
|
|