Fixup more kwargs stuff, need to pop values for defaults

This commit is contained in:
K. Lange 2021-01-05 19:01:26 +09:00
parent 2f78ae8770
commit a4a4da70df
6 changed files with 22 additions and 3 deletions

View File

@ -773,6 +773,7 @@ static void function(FunctionType type, size_t blockWidth) {
namedVariable(synth, 0);
emitBytes(OP_CALL, 0);
EMIT_CONSTANT_OP(OP_SET_LOCAL, myLocal);
emitByte(OP_POP); /* local value */
endScope();
/* Otherwise pop the comparison. */
patchJump(jumpIndex);
@ -799,6 +800,7 @@ static void function(FunctionType type, size_t blockWidth) {
beginScope();
expression(); /* Read expression */
EMIT_CONSTANT_OP(OP_SET_LOCAL, myLocal);
emitByte(OP_POP); /* local value */
endScope();
patchJump(jumpIndex);
emitByte(OP_POP);

View File

@ -1,15 +1,21 @@
def anything(*args, **kwargs):
def foo():
print("hi")
print("Positionals:", args)
print("Keywords:", kwargs)
return foo
anything(1,2,3,"a","b",foo="bar",biz=42)
anything(1,2,3,"a","b",foo="bar",biz=42)()
anything()()
def func(a,b,*args,**kwargs):
print(a, b, args)
let x = 'hello'
print(x)
return x
func(1,2,3,4,5,6,foo="bar")
print(func(1,2,3,4,5,6,foo="bar"))
def last(a,b,c=1,d=2,**kwargs):
print("Main:", a, b, c, d)

View File

@ -1,7 +1,12 @@
Positionals: [1, 2, 3, 'a', 'b']
Keywords: {'biz': 42, 'foo': 'bar'}
hi
Positionals: []
Keywords: {}
hi
1 2 [3, 4, 5, 6]
hello
hello
Main: 1 2 1 2
Keyword: {}
Main: 1 2 7 3

View File

@ -1,7 +1,10 @@
def foo(default="bacon"):
print("You like",default,"right?")
def test():
print("hello")
return test
foo()
print(foo())
foo("sports")
def fillValues(a=1,b=2,c="c",d=None,e=2.71828):

View File

@ -1,4 +1,5 @@
You like bacon right?
<function test>
You like sports right?
1 True c None 2.71828
one 2 test None <type 'object'>

View File

@ -111,6 +111,8 @@ int krk_valuesEqual(KrkValue a, KrkValue b) {
}
}
if (IS_KWARGS(a) || IS_KWARGS(b)) return 0;
if (!IS_OBJECT(a) && !IS_OBJECT(b)) {
switch (a.type) {
case VAL_INTEGER: {